]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Merge remote-tracking branch 'staging/staging-next'
authorStephen Rothwell <sfr@canb.auug.org.au>
Thu, 5 Nov 2015 03:52:43 +0000 (14:52 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 5 Nov 2015 03:52:43 +0000 (14:52 +1100)
990 files changed:
Documentation/ABI/testing/sysfs-bus-iio
Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 [new file with mode: 0644]
Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x [new file with mode: 0644]
Documentation/ABI/testing/sysfs-bus-iio-humidity-hdc100x [new file with mode: 0644]
Documentation/ABI/testing/sysfs-bus-iio-meas-spec [new file with mode: 0644]
Documentation/ABI/testing/sysfs-bus-iio-trigger-sysfs
Documentation/DocBook/iio.tmpl
Documentation/devicetree/bindings/i2c/trivial-devices.txt
Documentation/devicetree/bindings/iio/accel/mma8452.txt [new file with mode: 0644]
Documentation/devicetree/bindings/iio/adc/hi8435.txt [new file with mode: 0644]
Documentation/devicetree/bindings/iio/light/apds9960.txt [new file with mode: 0644]
Documentation/devicetree/bindings/iio/light/us5182d.txt [new file with mode: 0644]
Documentation/devicetree/bindings/vendor-prefixes.txt
MAINTAINERS
drivers/iio/Kconfig
drivers/iio/Makefile
drivers/iio/accel/Kconfig
drivers/iio/accel/Makefile
drivers/iio/accel/bmc150-accel-core.c [moved from drivers/iio/accel/bmc150-accel.c with 81% similarity]
drivers/iio/accel/bmc150-accel-i2c.c [new file with mode: 0644]
drivers/iio/accel/bmc150-accel-spi.c [new file with mode: 0644]
drivers/iio/accel/bmc150-accel.h [new file with mode: 0644]
drivers/iio/accel/kxcjk-1013.c
drivers/iio/accel/mma8452.c
drivers/iio/accel/mma9553.c
drivers/iio/accel/mxc4005.c [new file with mode: 0644]
drivers/iio/accel/st_accel_core.c
drivers/iio/accel/stk8312.c
drivers/iio/accel/stk8ba50.c
drivers/iio/adc/Kconfig
drivers/iio/adc/Makefile
drivers/iio/adc/ad799x.c
drivers/iio/adc/berlin2-adc.c
drivers/iio/adc/hi8435.c [new file with mode: 0644]
drivers/iio/adc/max1027.c
drivers/iio/adc/max1363.c
drivers/iio/adc/mcp320x.c
drivers/iio/adc/ti-adc128s052.c
drivers/iio/adc/twl6030-gpadc.c
drivers/iio/adc/vf610_adc.c
drivers/iio/adc/xilinx-xadc-core.c
drivers/iio/adc/xilinx-xadc.h
drivers/iio/amplifiers/ad8366.c
drivers/iio/buffer/Kconfig [new file with mode: 0644]
drivers/iio/buffer/Makefile [new file with mode: 0644]
drivers/iio/buffer/industrialio-buffer-cb.c [moved from drivers/iio/buffer_cb.c with 89% similarity]
drivers/iio/buffer/industrialio-triggered-buffer.c [moved from drivers/iio/industrialio-triggered-buffer.c with 100% similarity]
drivers/iio/buffer/kfifo_buf.c [moved from drivers/iio/kfifo_buf.c with 100% similarity]
drivers/iio/chemical/Kconfig [new file with mode: 0644]
drivers/iio/chemical/Makefile [new file with mode: 0644]
drivers/iio/chemical/vz89x.c [new file with mode: 0644]
drivers/iio/common/Kconfig
drivers/iio/common/Makefile
drivers/iio/common/ms_sensors/Kconfig [new file with mode: 0644]
drivers/iio/common/ms_sensors/Makefile [new file with mode: 0644]
drivers/iio/common/ms_sensors/ms_sensors_i2c.c [new file with mode: 0644]
drivers/iio/common/ms_sensors/ms_sensors_i2c.h [new file with mode: 0644]
drivers/iio/common/st_sensors/st_sensors_core.c
drivers/iio/dac/ad5504.c
drivers/iio/dac/ad7303.c
drivers/iio/dac/m62332.c
drivers/iio/dac/max5821.c
drivers/iio/frequency/adf4350.c
drivers/iio/gyro/Kconfig
drivers/iio/gyro/Makefile
drivers/iio/gyro/bmg160.h [new file with mode: 0644]
drivers/iio/gyro/bmg160_core.c [moved from drivers/iio/gyro/bmg160.c with 75% similarity]
drivers/iio/gyro/bmg160_i2c.c [new file with mode: 0644]
drivers/iio/gyro/bmg160_spi.c [new file with mode: 0644]
drivers/iio/gyro/st_gyro_core.c
drivers/iio/humidity/Kconfig
drivers/iio/humidity/Makefile
drivers/iio/humidity/hdc100x.c [new file with mode: 0644]
drivers/iio/humidity/htu21.c [new file with mode: 0644]
drivers/iio/humidity/si7020.c
drivers/iio/imu/kmx61.c
drivers/iio/industrialio-core.c
drivers/iio/industrialio-trigger.c
drivers/iio/industrialio-triggered-event.c [new file with mode: 0644]
drivers/iio/light/Kconfig
drivers/iio/light/Makefile
drivers/iio/light/apds9960.c [new file with mode: 0644]
drivers/iio/light/opt3001.c
drivers/iio/light/stk3310.c
drivers/iio/light/tsl4531.c
drivers/iio/light/us5182d.c [new file with mode: 0644]
drivers/iio/magnetometer/Kconfig
drivers/iio/magnetometer/Makefile
drivers/iio/magnetometer/bmc150_magn.c
drivers/iio/magnetometer/st_magn_core.c
drivers/iio/potentiometer/Kconfig [new file with mode: 0644]
drivers/iio/potentiometer/Makefile [new file with mode: 0644]
drivers/iio/potentiometer/mcp4531.c [new file with mode: 0644]
drivers/iio/pressure/Kconfig
drivers/iio/pressure/Makefile
drivers/iio/pressure/ms5637.c [new file with mode: 0644]
drivers/iio/pressure/st_pressure_core.c
drivers/iio/proximity/Kconfig
drivers/iio/proximity/Makefile
drivers/iio/proximity/as3935.c
drivers/iio/proximity/pulsedlight-lidar-lite-v2.c [new file with mode: 0644]
drivers/iio/proximity/sx9500.c
drivers/iio/temperature/Kconfig
drivers/iio/temperature/Makefile
drivers/iio/temperature/mlx90614.c
drivers/iio/temperature/tsys01.c [new file with mode: 0644]
drivers/iio/temperature/tsys02d.c [new file with mode: 0644]
drivers/staging/Kconfig
drivers/staging/Makefile
drivers/staging/android/Kconfig
drivers/staging/android/ashmem.c
drivers/staging/android/ion/compat_ion.h
drivers/staging/android/ion/ion.c
drivers/staging/android/ion/ion.h
drivers/staging/android/ion/ion_cma_heap.c
drivers/staging/android/ion/ion_heap.c
drivers/staging/android/ion/ion_page_pool.c
drivers/staging/android/ion/ion_priv.h
drivers/staging/android/ion/ion_system_heap.c
drivers/staging/android/ion/tegra/Makefile
drivers/staging/android/lowmemorykiller.c
drivers/staging/android/sw_sync.c
drivers/staging/android/timed_output.c
drivers/staging/android/uapi/ion.h
drivers/staging/board/board.c
drivers/staging/comedi/Kconfig
drivers/staging/comedi/comedi_buf.c
drivers/staging/comedi/comedi_fops.c
drivers/staging/comedi/comedi_internal.h
drivers/staging/comedi/comedi_pci.c
drivers/staging/comedi/comedi_pcmcia.c
drivers/staging/comedi/comedi_usb.c
drivers/staging/comedi/comedidev.h
drivers/staging/comedi/drivers.c
drivers/staging/comedi/drivers/8255.h
drivers/staging/comedi/drivers/8255_pci.c
drivers/staging/comedi/drivers/Makefile
drivers/staging/comedi/drivers/addi_apci_1032.c
drivers/staging/comedi/drivers/addi_apci_2032.c
drivers/staging/comedi/drivers/addi_apci_3120.c
drivers/staging/comedi/drivers/addi_apci_3xxx.c
drivers/staging/comedi/drivers/adl_pci6208.c
drivers/staging/comedi/drivers/adl_pci9111.c
drivers/staging/comedi/drivers/adl_pci9118.c
drivers/staging/comedi/drivers/adq12b.c
drivers/staging/comedi/drivers/adv_pci1710.c
drivers/staging/comedi/drivers/adv_pci1723.c
drivers/staging/comedi/drivers/adv_pci1724.c
drivers/staging/comedi/drivers/aio_aio12_8.c
drivers/staging/comedi/drivers/amplc_pci230.c
drivers/staging/comedi/drivers/cb_das16_cs.c
drivers/staging/comedi/drivers/cb_pcidas.c
drivers/staging/comedi/drivers/comedi_test.c
drivers/staging/comedi/drivers/daqboard2000.c
drivers/staging/comedi/drivers/dt3000.c
drivers/staging/comedi/drivers/dt9812.c
drivers/staging/comedi/drivers/fl512.c
drivers/staging/comedi/drivers/gsc_hpdi.c
drivers/staging/comedi/drivers/icp_multi.c
drivers/staging/comedi/drivers/ii_pci20kc.c
drivers/staging/comedi/drivers/ke_counter.c
drivers/staging/comedi/drivers/me_daq.c
drivers/staging/comedi/drivers/mf6x4.c
drivers/staging/comedi/drivers/mpc624.c
drivers/staging/comedi/drivers/multiq3.c
drivers/staging/comedi/drivers/ni_tio.c
drivers/staging/comedi/drivers/ni_tiocmd.c
drivers/staging/comedi/drivers/ni_usb6501.c
drivers/staging/comedi/drivers/pcl711.c
drivers/staging/comedi/drivers/pcl812.c
drivers/staging/comedi/drivers/pcl816.c
drivers/staging/comedi/drivers/pcl818.c
drivers/staging/comedi/drivers/pcm3724.c
drivers/staging/comedi/drivers/quatech_daqp_cs.c
drivers/staging/comedi/drivers/rtd520.c
drivers/staging/comedi/drivers/rti800.c
drivers/staging/comedi/drivers/s526.c
drivers/staging/comedi/drivers/serial2002.c
drivers/staging/comedi/drivers/ssv_dnp.c
drivers/staging/comedi/drivers/unioxx5.c [deleted file]
drivers/staging/comedi/drivers/usbdux.c
drivers/staging/comedi/drivers/usbduxfast.c
drivers/staging/comedi/drivers/usbduxsigma.c
drivers/staging/comedi/drivers/vmk80xx.c
drivers/staging/comedi/kcomedilib/kcomedilib_main.c
drivers/staging/dgap/dgap.c
drivers/staging/dgap/dgap.h
drivers/staging/dgnc/dgnc_cls.c
drivers/staging/dgnc/dgnc_driver.c
drivers/staging/dgnc/dgnc_driver.h
drivers/staging/dgnc/dgnc_mgmt.c
drivers/staging/dgnc/dgnc_neo.c
drivers/staging/dgnc/dgnc_sysfs.c
drivers/staging/dgnc/dgnc_tty.c
drivers/staging/emxx_udc/emxx_udc.c
drivers/staging/emxx_udc/emxx_udc.h
drivers/staging/fbtft/Kconfig
drivers/staging/fbtft/Makefile
drivers/staging/fbtft/fb_agm1264k-fl.c
drivers/staging/fbtft/fb_bd663474.c
drivers/staging/fbtft/fb_hx8340bn.c
drivers/staging/fbtft/fb_hx8347d.c
drivers/staging/fbtft/fb_hx8353d.c
drivers/staging/fbtft/fb_hx8357d.c
drivers/staging/fbtft/fb_ili9163.c
drivers/staging/fbtft/fb_ili9320.c
drivers/staging/fbtft/fb_ili9325.c
drivers/staging/fbtft/fb_ili9340.c
drivers/staging/fbtft/fb_ili9341.c
drivers/staging/fbtft/fb_ili9481.c
drivers/staging/fbtft/fb_ili9486.c
drivers/staging/fbtft/fb_pcd8544.c
drivers/staging/fbtft/fb_ra8875.c
drivers/staging/fbtft/fb_s6d02a1.c
drivers/staging/fbtft/fb_s6d1121.c
drivers/staging/fbtft/fb_ssd1289.c
drivers/staging/fbtft/fb_ssd1306.c
drivers/staging/fbtft/fb_ssd1331.c
drivers/staging/fbtft/fb_ssd1351.c
drivers/staging/fbtft/fb_st7735r.c
drivers/staging/fbtft/fb_st7789v.c [new file with mode: 0644]
drivers/staging/fbtft/fb_tinylcd.c
drivers/staging/fbtft/fb_tls8204.c
drivers/staging/fbtft/fb_uc1611.c
drivers/staging/fbtft/fb_uc1701.c
drivers/staging/fbtft/fb_upd161704.c
drivers/staging/fbtft/fb_watterott.c
drivers/staging/fbtft/fbtft-bus.c
drivers/staging/fbtft/fbtft-core.c
drivers/staging/fbtft/fbtft-sysfs.c
drivers/staging/fbtft/fbtft.h
drivers/staging/fbtft/fbtft_device.c
drivers/staging/fbtft/flexfb.c
drivers/staging/fsl-mc/bus/dpbp.c
drivers/staging/fsl-mc/bus/dpmcp-cmd.h
drivers/staging/fsl-mc/bus/dpmcp.c
drivers/staging/fsl-mc/bus/dpmcp.h
drivers/staging/fsl-mc/bus/dpmng.c
drivers/staging/fsl-mc/bus/dprc-cmd.h
drivers/staging/fsl-mc/bus/dprc-driver.c
drivers/staging/fsl-mc/bus/dprc.c
drivers/staging/fsl-mc/bus/mc-allocator.c
drivers/staging/fsl-mc/bus/mc-bus.c
drivers/staging/fsl-mc/bus/mc-sys.c
drivers/staging/fsl-mc/include/dpbp-cmd.h
drivers/staging/fsl-mc/include/dpbp.h
drivers/staging/fsl-mc/include/dpcon-cmd.h
drivers/staging/fsl-mc/include/dpmng.h
drivers/staging/fsl-mc/include/dprc.h
drivers/staging/fsl-mc/include/mc-cmd.h
drivers/staging/fsl-mc/include/mc-private.h
drivers/staging/fsl-mc/include/mc-sys.h
drivers/staging/fsl-mc/include/mc.h
drivers/staging/ft1000/Kconfig [deleted file]
drivers/staging/ft1000/Makefile [deleted file]
drivers/staging/ft1000/TODO [deleted file]
drivers/staging/ft1000/ft1000-pcmcia/Makefile [deleted file]
drivers/staging/ft1000/ft1000-pcmcia/boot.h [deleted file]
drivers/staging/ft1000/ft1000-pcmcia/ft1000.h [deleted file]
drivers/staging/ft1000/ft1000-pcmcia/ft1000.img [deleted file]
drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c [deleted file]
drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c [deleted file]
drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c [deleted file]
drivers/staging/ft1000/ft1000-usb/Makefile [deleted file]
drivers/staging/ft1000/ft1000-usb/ft1000_debug.c [deleted file]
drivers/staging/ft1000/ft1000-usb/ft1000_download.c [deleted file]
drivers/staging/ft1000/ft1000-usb/ft1000_hw.c [deleted file]
drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h [deleted file]
drivers/staging/ft1000/ft1000-usb/ft1000_usb.c [deleted file]
drivers/staging/ft1000/ft1000-usb/ft1000_usb.h [deleted file]
drivers/staging/ft1000/ft1000-usb/ft3000.img [deleted file]
drivers/staging/ft1000/ft1000.h [deleted file]
drivers/staging/gdm724x/gdm_lte.c
drivers/staging/gdm724x/gdm_mux.c
drivers/staging/gdm724x/gdm_tty.c
drivers/staging/gdm724x/gdm_usb.c
drivers/staging/gdm724x/netlink_k.c
drivers/staging/gdm72xx/gdm_qos.c
drivers/staging/gdm72xx/gdm_sdio.c
drivers/staging/gdm72xx/gdm_usb.c
drivers/staging/gdm72xx/gdm_wimax.c
drivers/staging/gdm72xx/sdio_boot.c
drivers/staging/gdm72xx/usb_boot.c
drivers/staging/goldfish/goldfish_nand.c
drivers/staging/goldfish/goldfish_nand_reg.h
drivers/staging/iio/accel/lis3l02dq_core.c
drivers/staging/iio/accel/lis3l02dq_ring.c
drivers/staging/iio/accel/sca3000_core.c
drivers/staging/iio/accel/sca3000_ring.c
drivers/staging/iio/adc/ad7192.c
drivers/staging/iio/adc/ad7192.h
drivers/staging/iio/adc/ad7280a.c
drivers/staging/iio/adc/ad7606_core.c
drivers/staging/iio/adc/ad7606_par.c
drivers/staging/iio/adc/ad7606_spi.c
drivers/staging/iio/adc/ad7780.c
drivers/staging/iio/adc/ad7816.c
drivers/staging/iio/adc/lpc32xx_adc.c
drivers/staging/iio/adc/mxs-lradc.c
drivers/staging/iio/adc/spear_adc.c
drivers/staging/iio/addac/adt7316.c
drivers/staging/iio/cdc/ad7150.c
drivers/staging/iio/cdc/ad7152.c
drivers/staging/iio/cdc/ad7746.c
drivers/staging/iio/frequency/ad9834.c
drivers/staging/iio/gyro/adis16060_core.c
drivers/staging/iio/iio_dummy_evgen.c
drivers/staging/iio/iio_simple_dummy.c
drivers/staging/iio/iio_simple_dummy.h
drivers/staging/iio/iio_simple_dummy_buffer.c
drivers/staging/iio/iio_simple_dummy_events.c
drivers/staging/iio/impedance-analyzer/ad5933.c
drivers/staging/iio/light/isl29018.c
drivers/staging/iio/light/isl29028.c
drivers/staging/iio/light/tsl2583.c
drivers/staging/iio/light/tsl2x7x_core.c
drivers/staging/iio/magnetometer/hmc5843.h
drivers/staging/iio/magnetometer/hmc5843_core.c
drivers/staging/iio/magnetometer/hmc5843_i2c.c
drivers/staging/iio/magnetometer/hmc5843_spi.c
drivers/staging/iio/meter/ade7753.c
drivers/staging/iio/meter/ade7754.c
drivers/staging/iio/meter/ade7758_core.c
drivers/staging/iio/meter/ade7759.c
drivers/staging/iio/meter/ade7854-spi.c
drivers/staging/iio/meter/ade7854.c
drivers/staging/iio/resolver/ad2s1210.c
drivers/staging/iio/resolver/ad2s90.c
drivers/staging/iio/trigger/iio-trig-bfin-timer.c
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
drivers/staging/lustre/include/linux/libcfs/libcfs.h
drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h
drivers/staging/lustre/include/linux/libcfs/libcfs_prim.h
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
drivers/staging/lustre/include/linux/libcfs/libcfs_time.h
drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h
drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h
drivers/staging/lustre/include/linux/lnet/lib-lnet.h
drivers/staging/lustre/include/linux/lnet/lib-types.h
drivers/staging/lustre/include/linux/lnet/nidstr.h
drivers/staging/lustre/include/linux/lnet/types.h
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c
drivers/staging/lustre/lnet/lnet/Makefile
drivers/staging/lustre/lnet/lnet/acceptor.c
drivers/staging/lustre/lnet/lnet/api-ni.c
drivers/staging/lustre/lnet/lnet/config.c
drivers/staging/lustre/lnet/lnet/lib-eq.c
drivers/staging/lustre/lnet/lnet/lib-move.c
drivers/staging/lustre/lnet/lnet/lib-ptl.c
drivers/staging/lustre/lnet/lnet/nidstrings.c [new file with mode: 0644]
drivers/staging/lustre/lnet/lnet/router.c
drivers/staging/lustre/lnet/lnet/router_proc.c
drivers/staging/lustre/lnet/selftest/brw_test.c
drivers/staging/lustre/lnet/selftest/conctl.c
drivers/staging/lustre/lnet/selftest/conrpc.c
drivers/staging/lustre/lnet/selftest/conrpc.h
drivers/staging/lustre/lnet/selftest/console.c
drivers/staging/lustre/lnet/selftest/console.h
drivers/staging/lustre/lnet/selftest/framework.c
drivers/staging/lustre/lnet/selftest/module.c
drivers/staging/lustre/lnet/selftest/ping_test.c
drivers/staging/lustre/lnet/selftest/rpc.c
drivers/staging/lustre/lnet/selftest/rpc.h
drivers/staging/lustre/lnet/selftest/selftest.h
drivers/staging/lustre/lnet/selftest/timer.c
drivers/staging/lustre/lnet/selftest/timer.h
drivers/staging/lustre/lustre/fid/fid_request.c
drivers/staging/lustre/lustre/fid/lproc_fid.c
drivers/staging/lustre/lustre/fld/fld_cache.c
drivers/staging/lustre/lustre/fld/fld_internal.h
drivers/staging/lustre/lustre/fld/fld_request.c
drivers/staging/lustre/lustre/fld/lproc_fld.c
drivers/staging/lustre/lustre/include/cl_object.h
drivers/staging/lustre/lustre/include/dt_object.h [deleted file]
drivers/staging/lustre/lustre/include/interval_tree.h
drivers/staging/lustre/lustre/include/lclient.h
drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
drivers/staging/lustre/lustre/include/linux/lustre_lite.h
drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h
drivers/staging/lustre/lustre/include/linux/obd.h
drivers/staging/lustre/lustre/include/lprocfs_status.h
drivers/staging/lustre/lustre/include/lu_object.h
drivers/staging/lustre/lustre/include/lu_ref.h
drivers/staging/lustre/lustre/include/lustre/libiam.h [deleted file]
drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h
drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
drivers/staging/lustre/lustre/include/lustre/lustre_lfsck_user.h [deleted file]
drivers/staging/lustre/lustre/include/lustre/lustre_user.h
drivers/staging/lustre/lustre/include/lustre_capa.h [deleted file]
drivers/staging/lustre/lustre/include/lustre_cfg.h
drivers/staging/lustre/lustre/include/lustre_debug.h
drivers/staging/lustre/lustre/include/lustre_disk.h
drivers/staging/lustre/lustre/include/lustre_dlm.h
drivers/staging/lustre/lustre/include/lustre_dlm_flags.h
drivers/staging/lustre/lustre/include/lustre_eacl.h
drivers/staging/lustre/lustre/include/lustre_export.h
drivers/staging/lustre/lustre/include/lustre_fid.h
drivers/staging/lustre/lustre/include/lustre_fld.h
drivers/staging/lustre/lustre/include/lustre_ha.h
drivers/staging/lustre/lustre/include/lustre_handles.h
drivers/staging/lustre/lustre/include/lustre_import.h
drivers/staging/lustre/lustre/include/lustre_lib.h
drivers/staging/lustre/lustre/include/lustre_lite.h
drivers/staging/lustre/lustre/include/lustre_log.h
drivers/staging/lustre/lustre/include/lustre_mdc.h
drivers/staging/lustre/lustre/include/lustre_mds.h
drivers/staging/lustre/lustre/include/lustre_net.h
drivers/staging/lustre/lustre/include/lustre_param.h
drivers/staging/lustre/lustre/include/lustre_req_layout.h
drivers/staging/lustre/lustre/include/lustre_sec.h
drivers/staging/lustre/lustre/include/obd.h
drivers/staging/lustre/lustre/include/obd_cache.h [deleted file]
drivers/staging/lustre/lustre/include/obd_cksum.h
drivers/staging/lustre/lustre/include/obd_class.h
drivers/staging/lustre/lustre/include/obd_support.h
drivers/staging/lustre/lustre/lclient/glimpse.c
drivers/staging/lustre/lustre/lclient/lcommon_cl.c
drivers/staging/lustre/lustre/lclient/lcommon_misc.c
drivers/staging/lustre/lustre/ldlm/interval_tree.c
drivers/staging/lustre/lustre/ldlm/l_lock.c
drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
drivers/staging/lustre/lustre/ldlm/ldlm_plain.c
drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
drivers/staging/lustre/lustre/ldlm/ldlm_request.c
drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
drivers/staging/lustre/lustre/libcfs/Makefile
drivers/staging/lustre/lustre/libcfs/debug.c
drivers/staging/lustre/lustre/libcfs/fail.c
drivers/staging/lustre/lustre/libcfs/hash.c
drivers/staging/lustre/lustre/libcfs/kernel_user_comm.c
drivers/staging/lustre/lustre/libcfs/libcfs_lock.c
drivers/staging/lustre/lustre/libcfs/libcfs_mem.c
drivers/staging/lustre/lustre/libcfs/libcfs_string.c
drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto-adler.c
drivers/staging/lustre/lustre/libcfs/linux/linux-crypto.c
drivers/staging/lustre/lustre/libcfs/linux/linux-curproc.c
drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c
drivers/staging/lustre/lustre/libcfs/linux/linux-prim.c
drivers/staging/lustre/lustre/libcfs/linux/linux-tracefile.c
drivers/staging/lustre/lustre/libcfs/module.c
drivers/staging/lustre/lustre/libcfs/nidstrings.c [deleted file]
drivers/staging/lustre/lustre/libcfs/tracefile.c
drivers/staging/lustre/lustre/libcfs/tracefile.h
drivers/staging/lustre/lustre/libcfs/workitem.c
drivers/staging/lustre/lustre/llite/Makefile
drivers/staging/lustre/lustre/llite/dcache.c
drivers/staging/lustre/lustre/llite/dir.c
drivers/staging/lustre/lustre/llite/file.c
drivers/staging/lustre/lustre/llite/llite_capa.c [deleted file]
drivers/staging/lustre/lustre/llite/llite_close.c
drivers/staging/lustre/lustre/llite/llite_internal.h
drivers/staging/lustre/lustre/llite/llite_lib.c
drivers/staging/lustre/lustre/llite/llite_mmap.c
drivers/staging/lustre/lustre/llite/llite_nfs.c
drivers/staging/lustre/lustre/llite/llite_rmtacl.c
drivers/staging/lustre/lustre/llite/lloop.c
drivers/staging/lustre/lustre/llite/lproc_llite.c
drivers/staging/lustre/lustre/llite/namei.c
drivers/staging/lustre/lustre/llite/remote_perm.c
drivers/staging/lustre/lustre/llite/rw.c
drivers/staging/lustre/lustre/llite/rw26.c
drivers/staging/lustre/lustre/llite/statahead.c
drivers/staging/lustre/lustre/llite/super25.c
drivers/staging/lustre/lustre/llite/vvp_dev.c
drivers/staging/lustre/lustre/llite/vvp_internal.h
drivers/staging/lustre/lustre/llite/vvp_io.c
drivers/staging/lustre/lustre/llite/vvp_lock.c
drivers/staging/lustre/lustre/llite/vvp_object.c
drivers/staging/lustre/lustre/llite/vvp_page.c
drivers/staging/lustre/lustre/llite/xattr.c
drivers/staging/lustre/lustre/llite/xattr_cache.c
drivers/staging/lustre/lustre/lmv/lmv_obd.c
drivers/staging/lustre/lustre/lmv/lproc_lmv.c
drivers/staging/lustre/lustre/lov/lov_cl_internal.h
drivers/staging/lustre/lustre/lov/lov_dev.c
drivers/staging/lustre/lustre/lov/lov_ea.c
drivers/staging/lustre/lustre/lov/lov_internal.h
drivers/staging/lustre/lustre/lov/lov_io.c
drivers/staging/lustre/lustre/lov/lov_lock.c
drivers/staging/lustre/lustre/lov/lov_obd.c
drivers/staging/lustre/lustre/lov/lov_object.c
drivers/staging/lustre/lustre/lov/lov_pack.c
drivers/staging/lustre/lustre/lov/lov_page.c
drivers/staging/lustre/lustre/lov/lov_pool.c
drivers/staging/lustre/lustre/lov/lov_request.c
drivers/staging/lustre/lustre/lov/lovsub_dev.c
drivers/staging/lustre/lustre/lov/lovsub_lock.c
drivers/staging/lustre/lustre/lov/lovsub_object.c
drivers/staging/lustre/lustre/lov/lproc_lov.c
drivers/staging/lustre/lustre/mdc/mdc_internal.h
drivers/staging/lustre/lustre/mdc/mdc_lib.c
drivers/staging/lustre/lustre/mdc/mdc_locks.c
drivers/staging/lustre/lustre/mdc/mdc_reint.c
drivers/staging/lustre/lustre/mdc/mdc_request.c
drivers/staging/lustre/lustre/mgc/lproc_mgc.c
drivers/staging/lustre/lustre/mgc/mgc_request.c
drivers/staging/lustre/lustre/obdclass/Makefile
drivers/staging/lustre/lustre/obdclass/acl.c
drivers/staging/lustre/lustre/obdclass/capa.c [deleted file]
drivers/staging/lustre/lustre/obdclass/cl_io.c
drivers/staging/lustre/lustre/obdclass/cl_lock.c
drivers/staging/lustre/lustre/obdclass/cl_object.c
drivers/staging/lustre/lustre/obdclass/cl_page.c
drivers/staging/lustre/lustre/obdclass/class_obd.c
drivers/staging/lustre/lustre/obdclass/debug.c
drivers/staging/lustre/lustre/obdclass/dt_object.c [deleted file]
drivers/staging/lustre/lustre/obdclass/genops.c
drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
drivers/staging/lustre/lustre/obdclass/llog.c
drivers/staging/lustre/lustre/obdclass/llog_cat.c
drivers/staging/lustre/lustre/obdclass/llog_internal.h
drivers/staging/lustre/lustre/obdclass/llog_obd.c
drivers/staging/lustre/lustre/obdclass/llog_swab.c
drivers/staging/lustre/lustre/obdclass/lprocfs_counters.c
drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
drivers/staging/lustre/lustre/obdclass/lu_object.c
drivers/staging/lustre/lustre/obdclass/lustre_handles.c
drivers/staging/lustre/lustre/obdclass/obd_config.c
drivers/staging/lustre/lustre/obdclass/obd_mount.c
drivers/staging/lustre/lustre/obdclass/obdo.c
drivers/staging/lustre/lustre/obdclass/statfs_pack.c
drivers/staging/lustre/lustre/obdecho/echo_client.c
drivers/staging/lustre/lustre/obdecho/echo_internal.h
drivers/staging/lustre/lustre/osc/lproc_osc.c
drivers/staging/lustre/lustre/osc/osc_cache.c
drivers/staging/lustre/lustre/osc/osc_cl_internal.h
drivers/staging/lustre/lustre/osc/osc_dev.c
drivers/staging/lustre/lustre/osc/osc_internal.h
drivers/staging/lustre/lustre/osc/osc_io.c
drivers/staging/lustre/lustre/osc/osc_lock.c
drivers/staging/lustre/lustre/osc/osc_object.c
drivers/staging/lustre/lustre/osc/osc_page.c
drivers/staging/lustre/lustre/osc/osc_quota.c
drivers/staging/lustre/lustre/osc/osc_request.c
drivers/staging/lustre/lustre/ptlrpc/client.c
drivers/staging/lustre/lustre/ptlrpc/connection.c
drivers/staging/lustre/lustre/ptlrpc/events.c
drivers/staging/lustre/lustre/ptlrpc/import.c
drivers/staging/lustre/lustre/ptlrpc/layout.c
drivers/staging/lustre/lustre/ptlrpc/llog_client.c
drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
drivers/staging/lustre/lustre/ptlrpc/niobuf.c
drivers/staging/lustre/lustre/ptlrpc/nrs.c
drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
drivers/staging/lustre/lustre/ptlrpc/pers.c
drivers/staging/lustre/lustre/ptlrpc/pinger.c
drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
drivers/staging/lustre/lustre/ptlrpc/sec.c
drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
drivers/staging/lustre/lustre/ptlrpc/sec_config.c
drivers/staging/lustre/lustre/ptlrpc/sec_gc.c
drivers/staging/lustre/lustre/ptlrpc/sec_lproc.c
drivers/staging/lustre/lustre/ptlrpc/sec_null.c
drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
drivers/staging/lustre/lustre/ptlrpc/service.c
drivers/staging/lustre/lustre/ptlrpc/wiretest.c
drivers/staging/media/davinci_vpfe/dm365_ipipe.c
drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
drivers/staging/media/lirc/lirc_sasem.c
drivers/staging/media/omap4iss/iss.c
drivers/staging/media/omap4iss/iss_csi2.c
drivers/staging/media/omap4iss/iss_csi2.h
drivers/staging/media/omap4iss/iss_ipipe.c
drivers/staging/media/omap4iss/iss_ipipe.h
drivers/staging/media/omap4iss/iss_ipipeif.c
drivers/staging/media/omap4iss/iss_ipipeif.h
drivers/staging/media/omap4iss/iss_regs.h
drivers/staging/media/omap4iss/iss_resizer.c
drivers/staging/media/omap4iss/iss_resizer.h
drivers/staging/media/omap4iss/iss_video.c
drivers/staging/most/Documentation/ABI/sysfs-class-most.txt
drivers/staging/most/aim-cdev/cdev.c
drivers/staging/most/aim-network/networking.c
drivers/staging/most/aim-sound/sound.c
drivers/staging/most/aim-v4l2/Makefile
drivers/staging/most/aim-v4l2/video.c
drivers/staging/most/hdm-dim2/Kconfig
drivers/staging/most/hdm-dim2/dim2_hal.c
drivers/staging/most/hdm-dim2/dim2_hal.h
drivers/staging/most/hdm-dim2/dim2_hdm.c
drivers/staging/most/hdm-dim2/dim2_hdm.h
drivers/staging/most/hdm-dim2/dim2_sysfs.c
drivers/staging/most/hdm-i2c/hdm_i2c.c
drivers/staging/most/hdm-usb/hdm_usb.c
drivers/staging/most/mostcore/core.c
drivers/staging/most/mostcore/mostcore.h
drivers/staging/mt29f_spinand/mt29f_spinand.c
drivers/staging/mt29f_spinand/mt29f_spinand.h
drivers/staging/netlogic/platform_net.c
drivers/staging/netlogic/xlr_net.h
drivers/staging/nvec/nvec.c
drivers/staging/octeon-usb/octeon-hcd.c
drivers/staging/octeon/Makefile
drivers/staging/octeon/ethernet-defines.h
drivers/staging/octeon/ethernet-rgmii.c
drivers/staging/octeon/ethernet-rx.c
drivers/staging/octeon/ethernet-sgmii.c
drivers/staging/octeon/ethernet-tx.c
drivers/staging/octeon/ethernet-xaui.c [deleted file]
drivers/staging/octeon/ethernet.c
drivers/staging/octeon/octeon-ethernet.h
drivers/staging/olpc_dcon/olpc_dcon.c
drivers/staging/olpc_dcon/olpc_dcon.h
drivers/staging/panel/panel.c
drivers/staging/rdma/Kconfig
drivers/staging/rdma/amso1100/c2.c
drivers/staging/rdma/amso1100/c2_ae.c
drivers/staging/rdma/amso1100/c2_alloc.c
drivers/staging/rdma/amso1100/c2_cm.c
drivers/staging/rdma/amso1100/c2_cq.c
drivers/staging/rdma/amso1100/c2_intr.c
drivers/staging/rdma/amso1100/c2_mm.c
drivers/staging/rdma/amso1100/c2_mq.c
drivers/staging/rdma/amso1100/c2_provider.c
drivers/staging/rdma/amso1100/c2_qp.c
drivers/staging/rdma/amso1100/c2_rnic.c
drivers/staging/rdma/ehca/ehca_cq.c
drivers/staging/rdma/hfi1/chip.c
drivers/staging/rdma/hfi1/chip.h
drivers/staging/rdma/hfi1/common.h
drivers/staging/rdma/hfi1/device.c
drivers/staging/rdma/hfi1/diag.c
drivers/staging/rdma/hfi1/driver.c
drivers/staging/rdma/hfi1/file_ops.c
drivers/staging/rdma/hfi1/firmware.c
drivers/staging/rdma/hfi1/hfi.h
drivers/staging/rdma/hfi1/init.c
drivers/staging/rdma/hfi1/mad.c
drivers/staging/rdma/hfi1/mr.c
drivers/staging/rdma/hfi1/pcie.c
drivers/staging/rdma/hfi1/pio.c
drivers/staging/rdma/hfi1/qp.h
drivers/staging/rdma/hfi1/qsfp.c
drivers/staging/rdma/hfi1/rc.c
drivers/staging/rdma/hfi1/ruc.c
drivers/staging/rdma/hfi1/sdma.c
drivers/staging/rdma/hfi1/sdma.h
drivers/staging/rdma/hfi1/sysfs.c
drivers/staging/rdma/hfi1/trace.c
drivers/staging/rdma/hfi1/trace.h
drivers/staging/rdma/hfi1/user_sdma.c
drivers/staging/rdma/hfi1/verbs.c
drivers/staging/rdma/hfi1/verbs.h
drivers/staging/rdma/ipath/ipath_driver.c
drivers/staging/rdma/ipath/ipath_eeprom.c
drivers/staging/rdma/ipath/ipath_file_ops.c
drivers/staging/rdma/ipath/ipath_fs.c
drivers/staging/rdma/ipath/ipath_iba6110.c
drivers/staging/rdma/ipath/ipath_init_chip.c
drivers/staging/rdma/ipath/ipath_intr.c
drivers/staging/rdma/ipath/ipath_kernel.h
drivers/staging/rdma/ipath/ipath_qp.c
drivers/staging/rdma/ipath/ipath_ruc.c
drivers/staging/rdma/ipath/ipath_sdma.c
drivers/staging/rdma/ipath/ipath_sysfs.c
drivers/staging/rdma/ipath/ipath_ud.c
drivers/staging/rdma/ipath/ipath_user_pages.c
drivers/staging/rdma/ipath/ipath_user_sdma.c
drivers/staging/rdma/ipath/ipath_verbs.c
drivers/staging/rdma/ipath/ipath_verbs_mcast.c
drivers/staging/rtl8188eu/Kconfig
drivers/staging/rtl8188eu/Makefile
drivers/staging/rtl8188eu/core/rtw_ap.c
drivers/staging/rtl8188eu/core/rtw_cmd.c
drivers/staging/rtl8188eu/core/rtw_debug.c
drivers/staging/rtl8188eu/core/rtw_efuse.c
drivers/staging/rtl8188eu/core/rtw_ieee80211.c
drivers/staging/rtl8188eu/core/rtw_mlme.c
drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
drivers/staging/rtl8188eu/core/rtw_recv.c
drivers/staging/rtl8188eu/core/rtw_rf.c
drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
drivers/staging/rtl8188eu/core/rtw_wlan_util.c
drivers/staging/rtl8188eu/core/rtw_xmit.c
drivers/staging/rtl8188eu/hal/Hal8188ERateAdaptive.c
drivers/staging/rtl8188eu/hal/bb_cfg.c
drivers/staging/rtl8188eu/hal/fw.c
drivers/staging/rtl8188eu/hal/mac_cfg.c
drivers/staging/rtl8188eu/hal/odm.c
drivers/staging/rtl8188eu/hal/odm_HWConfig.c
drivers/staging/rtl8188eu/hal/odm_RTL8188E.c
drivers/staging/rtl8188eu/hal/phy.c
drivers/staging/rtl8188eu/hal/rf_cfg.c
drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c
drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
drivers/staging/rtl8188eu/hal/rtl8188eu_led.c
drivers/staging/rtl8188eu/hal/rtl8188eu_recv.c
drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c
drivers/staging/rtl8188eu/hal/usb_halinit.c
drivers/staging/rtl8188eu/include/Hal8188EPhyCfg.h
drivers/staging/rtl8188eu/include/basic_types.h
drivers/staging/rtl8188eu/include/drv_types.h
drivers/staging/rtl8188eu/include/hal_intf.h
drivers/staging/rtl8188eu/include/ieee80211.h
drivers/staging/rtl8188eu/include/mon.h [new file with mode: 0644]
drivers/staging/rtl8188eu/include/odm.h
drivers/staging/rtl8188eu/include/odm_debug.h
drivers/staging/rtl8188eu/include/odm_reg.h
drivers/staging/rtl8188eu/include/osdep_service.h
drivers/staging/rtl8188eu/include/pwrseq.h
drivers/staging/rtl8188eu/include/rtl8188e_spec.h
drivers/staging/rtl8188eu/include/rtw_security.h
drivers/staging/rtl8188eu/include/rtw_sreset.h
drivers/staging/rtl8188eu/include/wifi.h
drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
drivers/staging/rtl8188eu/os_dep/mlme_linux.c
drivers/staging/rtl8188eu/os_dep/mon.c [new file with mode: 0644]
drivers/staging/rtl8188eu/os_dep/os_intfs.c
drivers/staging/rtl8188eu/os_dep/osdep_service.c
drivers/staging/rtl8188eu/os_dep/recv_linux.c
drivers/staging/rtl8188eu/os_dep/usb_intf.c
drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
drivers/staging/rtl8188eu/os_dep/xmit_linux.c
drivers/staging/rtl8192e/dot11d.c
drivers/staging/rtl8192e/dot11d.h
drivers/staging/rtl8192e/rtl8192e/r8190P_def.h
drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.c
drivers/staging/rtl8192e/rtl8192e/r8190P_rtl8256.h
drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.h
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.h
drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.h
drivers/staging/rtl8192e/rtl8192e/r8192E_hw.h
drivers/staging/rtl8192e/rtl8192e/r8192E_hwimg.c
drivers/staging/rtl8192e/rtl8192e/r8192E_hwimg.h
drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
drivers/staging/rtl8192e/rtl8192e/r8192E_phy.h
drivers/staging/rtl8192e/rtl8192e/r8192E_phyreg.h
drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
drivers/staging/rtl8192e/rtl8192e/rtl_cam.h
drivers/staging/rtl8192e/rtl8192e/rtl_core.c
drivers/staging/rtl8192e/rtl8192e/rtl_core.h
drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
drivers/staging/rtl8192e/rtl8192e/rtl_dm.h
drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.c
drivers/staging/rtl8192e/rtl8192e/rtl_eeprom.h
drivers/staging/rtl8192e/rtl8192e/rtl_ethtool.c
drivers/staging/rtl8192e/rtl8192e/rtl_pci.c
drivers/staging/rtl8192e/rtl8192e/rtl_pci.h
drivers/staging/rtl8192e/rtl8192e/rtl_pm.c
drivers/staging/rtl8192e/rtl8192e/rtl_pm.h
drivers/staging/rtl8192e/rtl8192e/rtl_ps.c
drivers/staging/rtl8192e/rtl8192e/rtl_ps.h
drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
drivers/staging/rtl8192e/rtl8192e/rtl_wx.h
drivers/staging/rtl8192e/rtl819x_BA.h
drivers/staging/rtl8192e/rtl819x_BAProc.c
drivers/staging/rtl8192e/rtl819x_HT.h
drivers/staging/rtl8192e/rtl819x_HTProc.c
drivers/staging/rtl8192e/rtl819x_Qos.h
drivers/staging/rtl8192e/rtl819x_TS.h
drivers/staging/rtl8192e/rtl819x_TSProc.c
drivers/staging/rtl8192e/rtllib_debug.h
drivers/staging/rtl8192e/rtllib_module.c
drivers/staging/rtl8192e/rtllib_rx.c
drivers/staging/rtl8192e/rtllib_softmac.c
drivers/staging/rtl8192e/rtllib_tx.c
drivers/staging/rtl8192e/rtllib_wx.c
drivers/staging/rtl8192u/ieee80211/ieee80211.h
drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
drivers/staging/rtl8192u/r8192U.h
drivers/staging/rtl8192u/r8192U_core.c
drivers/staging/rtl8192u/r8192U_dm.c
drivers/staging/rtl8192u/r8192U_hw.h
drivers/staging/rtl8192u/r8192U_wx.c
drivers/staging/rtl8192u/r819xU_cmdpkt.h
drivers/staging/rtl8192u/r819xU_phy.c
drivers/staging/rtl8712/drv_types.h
drivers/staging/rtl8712/hal_init.c
drivers/staging/rtl8712/ieee80211.c
drivers/staging/rtl8712/ieee80211.h
drivers/staging/rtl8712/mlme_linux.c
drivers/staging/rtl8712/os_intfs.c
drivers/staging/rtl8712/osdep_service.h
drivers/staging/rtl8712/recv_linux.c
drivers/staging/rtl8712/rtl8712_cmd.c
drivers/staging/rtl8712/rtl8712_cmdctrl_bitdef.h
drivers/staging/rtl8712/rtl8712_efuse.c
drivers/staging/rtl8712/rtl8712_gp_bitdef.h
drivers/staging/rtl8712/rtl8712_hal.h
drivers/staging/rtl8712/rtl8712_io.c
drivers/staging/rtl8712/rtl8712_led.c
drivers/staging/rtl8712/rtl8712_recv.c
drivers/staging/rtl8712/rtl8712_xmit.c
drivers/staging/rtl8712/rtl871x_cmd.c
drivers/staging/rtl8712/rtl871x_eeprom.c
drivers/staging/rtl8712/rtl871x_io.c
drivers/staging/rtl8712/rtl871x_io.h
drivers/staging/rtl8712/rtl871x_ioctl_linux.c
drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
drivers/staging/rtl8712/rtl871x_ioctl_set.c
drivers/staging/rtl8712/rtl871x_mlme.c
drivers/staging/rtl8712/rtl871x_mlme.h
drivers/staging/rtl8712/rtl871x_mp.c
drivers/staging/rtl8712/rtl871x_mp.h
drivers/staging/rtl8712/rtl871x_mp_ioctl.c
drivers/staging/rtl8712/rtl871x_pwrctrl.c
drivers/staging/rtl8712/rtl871x_recv.c
drivers/staging/rtl8712/rtl871x_security.c
drivers/staging/rtl8712/rtl871x_sta_mgt.c
drivers/staging/rtl8712/rtl871x_xmit.c
drivers/staging/rtl8712/usb_halinit.c
drivers/staging/rtl8712/usb_intf.c
drivers/staging/rtl8712/usb_ops.c
drivers/staging/rtl8712/usb_ops_linux.c
drivers/staging/rtl8712/wifi.h
drivers/staging/rtl8712/xmit_linux.c
drivers/staging/rtl8723au/core/rtw_ap.c
drivers/staging/rtl8723au/core/rtw_cmd.c
drivers/staging/rtl8723au/core/rtw_efuse.c
drivers/staging/rtl8723au/core/rtw_ieee80211.c
drivers/staging/rtl8723au/core/rtw_mlme_ext.c
drivers/staging/rtl8723au/core/rtw_recv.c
drivers/staging/rtl8723au/core/rtw_security.c
drivers/staging/rtl8723au/core/rtw_wlan_util.c
drivers/staging/rtl8723au/hal/rtl8723a_bt-coexist.c
drivers/staging/rtl8723au/hal/rtl8723a_cmd.c
drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c
drivers/staging/rtl8723au/hal/rtl8723a_phycfg.c
drivers/staging/rtl8723au/hal/rtl8723a_rf6052.c
drivers/staging/rtl8723au/hal/usb_halinit.c
drivers/staging/rtl8723au/include/rtw_cmd.h
drivers/staging/rts5208/rtsx.c
drivers/staging/rts5208/rtsx_chip.c
drivers/staging/skein/skein_api.c
drivers/staging/skein/skein_api.h
drivers/staging/skein/skein_base.c
drivers/staging/skein/skein_block.c
drivers/staging/skein/skein_generic.c
drivers/staging/slicoss/slic.h
drivers/staging/slicoss/slichw.h
drivers/staging/slicoss/slicoss.c
drivers/staging/sm750fb/ddk750_chip.c
drivers/staging/sm750fb/ddk750_chip.h
drivers/staging/sm750fb/ddk750_display.c
drivers/staging/sm750fb/ddk750_display.h
drivers/staging/sm750fb/ddk750_help.h
drivers/staging/sm750fb/ddk750_hwi2c.c
drivers/staging/sm750fb/ddk750_hwi2c.h
drivers/staging/sm750fb/ddk750_mode.c
drivers/staging/sm750fb/ddk750_power.c
drivers/staging/sm750fb/ddk750_power.h
drivers/staging/sm750fb/ddk750_reg.h
drivers/staging/sm750fb/ddk750_sii164.c
drivers/staging/sm750fb/ddk750_swi2c.c
drivers/staging/sm750fb/ddk750_swi2c.h
drivers/staging/sm750fb/sm750.c
drivers/staging/sm750fb/sm750.h
drivers/staging/sm750fb/sm750_accel.c
drivers/staging/sm750fb/sm750_cursor.c
drivers/staging/sm750fb/sm750_help.h
drivers/staging/sm750fb/sm750_hw.c
drivers/staging/sm750fb/sm750_hw.h [deleted file]
drivers/staging/speakup/buffers.c
drivers/staging/speakup/devsynth.c
drivers/staging/speakup/i18n.c
drivers/staging/speakup/kobjects.c
drivers/staging/speakup/serialio.c
drivers/staging/speakup/speakup_audptr.c
drivers/staging/speakup/speakup_dectlk.c
drivers/staging/speakup/speakup_soft.c
drivers/staging/speakup/spk_priv.h
drivers/staging/speakup/spk_priv_keyinfo.h
drivers/staging/speakup/varhandlers.c
drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
drivers/staging/unisys/Documentation/ABI/sysfs-platform-visorchipset
drivers/staging/unisys/Documentation/overview.txt
drivers/staging/unisys/Kconfig
drivers/staging/unisys/Makefile
drivers/staging/unisys/TODO
drivers/staging/unisys/include/channel.h
drivers/staging/unisys/include/diagchannel.h
drivers/staging/unisys/include/iochannel.h
drivers/staging/unisys/include/periodic_work.h
drivers/staging/unisys/visorbus/periodic_work.c
drivers/staging/unisys/visorbus/visorchannel.c
drivers/staging/unisys/visorbus/visorchipset.c
drivers/staging/unisys/visorbus/vmcallinterface.h
drivers/staging/unisys/visorhba/Kconfig [new file with mode: 0644]
drivers/staging/unisys/visorhba/Makefile [new file with mode: 0644]
drivers/staging/unisys/visorhba/visorhba_main.c [new file with mode: 0644]
drivers/staging/unisys/visorinput/Kconfig [new file with mode: 0644]
drivers/staging/unisys/visorinput/Makefile [new file with mode: 0644]
drivers/staging/unisys/visorinput/ultrainputreport.h [new file with mode: 0644]
drivers/staging/unisys/visorinput/visorinput.c [new file with mode: 0644]
drivers/staging/unisys/visornic/visornic_main.c
drivers/staging/vt6655/baseband.c
drivers/staging/vt6655/card.c
drivers/staging/vt6655/desc.h
drivers/staging/vt6655/device.h
drivers/staging/vt6655/device_main.c
drivers/staging/vt6655/dpc.c
drivers/staging/vt6655/dpc.h
drivers/staging/vt6655/mac.c
drivers/staging/vt6655/rf.c
drivers/staging/vt6655/rf.h
drivers/staging/vt6655/rxtx.c
drivers/staging/vt6656/baseband.c
drivers/staging/vt6656/card.c
drivers/staging/vt6656/device.h
drivers/staging/vt6656/int.c
drivers/staging/vt6656/main_usb.c
drivers/staging/vt6656/power.c
drivers/staging/vt6656/rxtx.c
drivers/staging/vt6656/usbpipe.c
drivers/staging/wilc1000/Kconfig
drivers/staging/wilc1000/Makefile
drivers/staging/wilc1000/coreconfigurator.c
drivers/staging/wilc1000/coreconfigurator.h
drivers/staging/wilc1000/host_interface.c
drivers/staging/wilc1000/host_interface.h
drivers/staging/wilc1000/linux_mon.c
drivers/staging/wilc1000/linux_wlan.c
drivers/staging/wilc1000/linux_wlan_common.h
drivers/staging/wilc1000/linux_wlan_sdio.c
drivers/staging/wilc1000/linux_wlan_spi.c
drivers/staging/wilc1000/linux_wlan_spi.h
drivers/staging/wilc1000/wilc_errorsupport.h [deleted file]
drivers/staging/wilc1000/wilc_exported_buf.c [deleted file]
drivers/staging/wilc1000/wilc_memory.c [deleted file]
drivers/staging/wilc1000/wilc_memory.h [deleted file]
drivers/staging/wilc1000/wilc_msgqueue.c
drivers/staging/wilc1000/wilc_msgqueue.h
drivers/staging/wilc1000/wilc_oswrapper.h [deleted file]
drivers/staging/wilc1000/wilc_platform.h [deleted file]
drivers/staging/wilc1000/wilc_sdio.c
drivers/staging/wilc1000/wilc_spi.c
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
drivers/staging/wilc1000/wilc_wfi_cfgoperations.h
drivers/staging/wilc1000/wilc_wfi_netdevice.h
drivers/staging/wilc1000/wilc_wlan.c
drivers/staging/wilc1000/wilc_wlan.h
drivers/staging/wilc1000/wilc_wlan_cfg.c
drivers/staging/wilc1000/wilc_wlan_cfg.h
drivers/staging/wilc1000/wilc_wlan_if.h
drivers/staging/wlan-ng/cfg80211.c
drivers/staging/wlan-ng/hfa384x_usb.c
drivers/staging/wlan-ng/p80211conv.c
drivers/staging/wlan-ng/p80211conv.h
drivers/staging/wlan-ng/p80211meta.h [deleted file]
drivers/staging/wlan-ng/prism2fw.c
drivers/staging/wlan-ng/prism2sta.c
drivers/staging/wlan-ng/prism2usb.c
drivers/staging/xgifb/XGI_main_26.c
drivers/staging/xgifb/vb_init.c
drivers/staging/xgifb/vb_util.h
drivers/vme/bridges/vme_ca91cx42.c
drivers/vme/bridges/vme_tsi148.c
drivers/vme/vme.c
drivers/vme/vme_bridge.h
include/linux/fb.h
include/linux/iio/common/st_sensors.h
include/linux/iio/iio.h
include/linux/iio/triggered_event.h [new file with mode: 0644]
include/uapi/linux/iio/types.h
include/uapi/rdma/hfi/hfi1_user.h
tools/iio/generic_buffer.c
tools/iio/iio_event_monitor.c

index 42d360fe66a5785929c42f2e36c3fcd3d0f6b58b..0439c2aaf7419867c1dce0c223190530eb970d70 100644 (file)
@@ -581,6 +581,7 @@ What:               /sys/.../iio:deviceX/events/in_voltageY_supply_thresh_rising_en
 What:          /sys/.../iio:deviceX/events/in_voltageY_supply_thresh_falling_en
 What:          /sys/.../iio:deviceX/events/in_voltageY_thresh_rising_en
 What:          /sys/.../iio:deviceX/events/in_voltageY_thresh_falling_en
+What:          /sys/.../iio:deviceX/events/in_voltageY_thresh_either_en
 What:          /sys/.../iio:deviceX/events/in_tempY_thresh_rising_en
 What:          /sys/.../iio:deviceX/events/in_tempY_thresh_falling_en
 KernelVersion: 2.6.37
@@ -1459,3 +1460,34 @@ Description:
                measurements and return the average value as output data. Each
                value resulted from <type>[_name]_oversampling_ratio measurements
                is considered as one sample for <type>[_name]_sampling_frequency.
+
+What:          /sys/bus/iio/devices/iio:deviceX/in_concentration_raw
+What:          /sys/bus/iio/devices/iio:deviceX/in_concentrationX_raw
+What:          /sys/bus/iio/devices/iio:deviceX/in_concentration_co2_raw
+What:          /sys/bus/iio/devices/iio:deviceX/in_concentrationX_co2_raw
+What:          /sys/bus/iio/devices/iio:deviceX/in_concentration_voc_raw
+What:          /sys/bus/iio/devices/iio:deviceX/in_concentrationX_voc_raw
+KernelVersion: 4.3
+Contact:       linux-iio@vger.kernel.org
+Description:
+               Raw (unscaled no offset etc.) percentage reading of a substance.
+
+What:          /sys/bus/iio/devices/iio:deviceX/in_resistance_raw
+What:          /sys/bus/iio/devices/iio:deviceX/in_resistanceX_raw
+What:          /sys/bus/iio/devices/iio:deviceX/out_resistance_raw
+What:          /sys/bus/iio/devices/iio:deviceX/out_resistanceX_raw
+KernelVersion: 4.3
+Contact:       linux-iio@vger.kernel.org
+Description:
+               Raw (unscaled no offset etc.) resistance reading that can be processed
+               into an ohm value.
+
+What:          /sys/bus/iio/devices/iio:deviceX/heater_enable
+KernelVersion: 4.1.0
+Contact:       linux-iio@vger.kernel.org
+Description:
+               '1' (enable) or '0' (disable) specifying the enable
+               of heater function. Same reading values apply
+               This ABI is especially applicable for humidity sensors
+               to heatup the device and get rid of any condensation
+               in some humidity environment
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435 b/Documentation/ABI/testing/sysfs-bus-iio-adc-hi8435
new file mode 100644 (file)
index 0000000..f30b4c4
--- /dev/null
@@ -0,0 +1,43 @@
+What:          /sys/bus/iio/devices/iio:deviceX/in_voltageY_sensing_mode
+Date:          August 2015
+KernelVersion: 4.2.0
+Contact:       source@cogentembedded.com
+Description:
+               Program sensor type for threshold detector inputs.
+               Could be either "GND-Open" or "Supply-Open" mode. Y is a
+               threshold detector input channel. Channels 0..7, 8..15, 16..23
+               and 24..31 has common sensor types.
+
+What:          /sys/bus/iio/devices/iio:deviceX/events/in_voltageY_thresh_falling_value
+Date:          August 2015
+KernelVersion: 4.2.0
+Contact:       source@cogentembedded.com
+Description:
+               Channel Y low voltage threshold. If sensor input voltage goes lower then
+               this value then the threshold falling event is pushed.
+               Depending on in_voltageY_sensing_mode the low voltage threshold
+               is separately set for "GND-Open" and "Supply-Open" modes.
+               Channels 0..31 have common low threshold values, but could have different
+               sensing_modes.
+               The low voltage threshold range is between 2..21V.
+               Hysteresis between low and high thresholds can not be lower then 2 and
+               can not be odd.
+               If falling threshold results hysteresis to odd value then rising
+               threshold is automatically subtracted by one.
+
+What:          /sys/bus/iio/devices/iio:deviceX/events/in_voltageY_thresh_rising_value
+Date:          August 2015
+KernelVersion: 4.2.0
+Contact:       source@cogentembedded.com
+Description:
+               Channel Y high voltage threshold. If sensor input voltage goes higher then
+               this value then the threshold rising event is pushed.
+               Depending on in_voltageY_sensing_mode the high voltage threshold
+               is separately set for "GND-Open" and "Supply-Open" modes.
+               Channels 0..31 have common high threshold values, but could have different
+               sensing_modes.
+               The high voltage threshold range is between 3..22V.
+               Hysteresis between low and high thresholds can not be lower then 2 and
+               can not be odd.
+               If rising threshold results hysteresis to odd value then falling
+               threshold is automatically appended by one.
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x b/Documentation/ABI/testing/sysfs-bus-iio-chemical-vz89x
new file mode 100644 (file)
index 0000000..c0c1ea9
--- /dev/null
@@ -0,0 +1,7 @@
+What:          /sys/bus/iio/devices/iio:deviceX/in_concentration_VOC_short_raw
+Date:          September 2015
+KernelVersion: 4.3
+Contact:       Matt Ranostay <mranostay@gmail.com>
+Description:
+               Get the raw calibration VOC value from the sensor.
+               This value has little application outside of calibration.
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-humidity-hdc100x b/Documentation/ABI/testing/sysfs-bus-iio-humidity-hdc100x
new file mode 100644 (file)
index 0000000..b72bb62
--- /dev/null
@@ -0,0 +1,9 @@
+What:          /sys/bus/iio/devices/iio:deviceX/out_current_heater_raw
+What:          /sys/bus/iio/devices/iio:deviceX/out_current_heater_raw_available
+KernelVersion: 4.3
+Contact:       linux-iio@vger.kernel.org
+Description:
+               Controls the heater device within the humidity sensor to get
+               rid of excess condensation.
+
+               Valid control values are 0 = OFF, and 1 = ON.
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-meas-spec b/Documentation/ABI/testing/sysfs-bus-iio-meas-spec
new file mode 100644 (file)
index 0000000..1a6265e
--- /dev/null
@@ -0,0 +1,8 @@
+What:           /sys/bus/iio/devices/iio:deviceX/battery_low
+KernelVersion:  4.1.0
+Contact:        linux-iio@vger.kernel.org
+Description:
+                Reading returns either '1' or '0'. '1' means that the
+                battery level supplied to sensor is below 2.25V.
+                This ABI is available for tsys02d, htu21, ms8607
+               This ABI is available for htu21, ms8607
index bbb039237a2580307d614030ea5013b71f749f6f..04ac62305018558ed04ff8208594521f894a0583 100644 (file)
@@ -18,3 +18,25 @@ Description:
                trigger. In order to associate the trigger with an IIO device
                one should write this name string to
                /sys/bus/iio/devices/iio:deviceY/trigger/current_trigger.
+
+What:          /sys/bus/iio/devices/iio_sysfs_trigger/add_trigger
+KernelVersion: 2.6.39
+Contact:       linux-iio@vger.kernel.org
+Description:
+               This attribute is provided by the iio-trig-sysfs stand-alone
+               driver and it is used to activate the creation of a new trigger.
+               In order to achieve this, one should write a positive integer
+               into the associated file, which will serve as the id of the
+               trigger. If the trigger with the specified id is already present
+               in the system, an invalid argument message will be returned.
+
+What:          /sys/bus/iio/devices/iio_sysfs_trigger/remove_trigger
+KernelVersion: 2.6.39
+Contact:       linux-iio@vger.kernel.org
+Description:
+               This attribute is used to unregister and delete a previously
+               created trigger from the list of available triggers. In order to
+               achieve this, one should write a positive integer into the
+               associated file, representing the id of the trigger that needs
+               to be removed. If the trigger can't be found, an invalid
+               argument message will be returned to the user.
index 06bb53de5a47fa4a6b1decc3a322051a3e4a3ea3..98be322673da75fe23f87dba3da968c308e4f23a 100644 (file)
     work together.
     </para>
     <sect2 id="iiotrigbufsetup"> <title> IIO triggered buffer setup</title>
-!Edrivers/iio/industrialio-triggered-buffer.c
+!Edrivers/iio/buffer/industrialio-triggered-buffer.c
 !Finclude/linux/iio/iio.h iio_buffer_setup_ops
 
 
index d77d412cbc685f5796d0ff6820a34970570cce95..c50cf13c852e518cff4664370eb1a72947e9cca7 100644 (file)
@@ -54,7 +54,6 @@ epson,rx8581          I2C-BUS INTERFACE REAL TIME CLOCK MODULE
 fsl,mag3110            MAG3110: Xtrinsic High Accuracy, 3D Magnetometer
 fsl,mc13892            MC13892: Power Management Integrated Circuit (PMIC) for i.MX35/51
 fsl,mma8450            MMA8450Q: Xtrinsic Low-power, 3-axis Xtrinsic Accelerometer
-fsl,mma8452            MMA8452Q: 3-axis 12-bit / 8-bit Digital Accelerometer
 fsl,mpr121             MPR121: Proximity Capacitive Touch Sensor Controller
 fsl,sgtl5000           SGTL5000: Ultra Low-Power Audio Codec
 gmt,g751               G751: Digital Temperature Sensor and Thermal Watchdog with Two-Wire Interface
@@ -80,6 +79,7 @@ oki,ml86v7667         OKI ML86V7667 video decoder
 ovti,ov5642            OV5642: Color CMOS QSXGA (5-megapixel) Image Sensor with OmniBSI and Embedded TrueFocus
 pericom,pt7c4338       Real-time Clock Module
 plx,pex8648            48-Lane, 12-Port PCI Express Gen 2 (5.0 GT/s) Switch
+pulsedlight,lidar-lite-v2      Pulsedlight LIDAR range-finding sensor
 ramtron,24c64          i2c serial eeprom  (24cxx)
 ricoh,r2025sd          I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
 ricoh,r2221tl          I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
@@ -88,6 +88,7 @@ ricoh,rs5c372b                I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
 ricoh,rv5c386          I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
 ricoh,rv5c387a         I2C bus SERIAL INTERFACE REAL-TIME CLOCK IC
 samsung,24ad0xd1       S524AD0XF1 (128K/256K-bit Serial EEPROM for Low Power)
+sgx,vz89x              SGX Sensortech VZ89X Sensors
 sii,s35390a            2-wire CMOS real-time clock
 skyworks,sky81452      Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
 st-micro,24c256                i2c serial eeprom  (24cxx)
diff --git a/Documentation/devicetree/bindings/iio/accel/mma8452.txt b/Documentation/devicetree/bindings/iio/accel/mma8452.txt
new file mode 100644 (file)
index 0000000..e3c3746
--- /dev/null
@@ -0,0 +1,24 @@
+Freescale MMA8452Q, MMA8453Q, MMA8652FC or MMA8653FC triaxial accelerometer
+
+Required properties:
+
+  - compatible: should contain one of
+    * "fsl,mma8452"
+    * "fsl,mma8453"
+    * "fsl,mma8652"
+    * "fsl,mma8653"
+  - reg: the I2C address of the chip
+
+Optional properties:
+
+  - interrupt-parent: should be the phandle for the interrupt controller
+  - interrupts: interrupt mapping for GPIO IRQ
+
+Example:
+
+       mma8453fc@1d {
+               compatible = "fsl,mma8453";
+               reg = <0x1d>;
+               interrupt-parent = <&gpio1>;
+               interrupts = <5 0>;
+       };
diff --git a/Documentation/devicetree/bindings/iio/adc/hi8435.txt b/Documentation/devicetree/bindings/iio/adc/hi8435.txt
new file mode 100644 (file)
index 0000000..3b0348c
--- /dev/null
@@ -0,0 +1,21 @@
+Holt Integrated Circuits HI-8435 threshold detector bindings
+
+Required properties:
+ - compatible: should be "holt,hi8435"
+ - reg: spi chip select number for the device
+
+Recommended properties:
+ - spi-max-frequency: definition as per
+               Documentation/devicetree/bindings/spi/spi-bus.txt
+
+Optional properties:
+ - gpios: GPIO used for controlling the reset pin
+
+Example:
+sensor@0 {
+       compatible = "holt,hi8435";
+       reg = <0>;
+       gpios = <&gpio6 1 0>;
+
+       spi-max-frequency = <1000000>;
+};
diff --git a/Documentation/devicetree/bindings/iio/light/apds9960.txt b/Documentation/devicetree/bindings/iio/light/apds9960.txt
new file mode 100644 (file)
index 0000000..174b709
--- /dev/null
@@ -0,0 +1,22 @@
+* Avago APDS9960 gesture/RGB/ALS/proximity sensor
+
+http://www.avagotech.com/docs/AV02-4191EN
+
+Required properties:
+
+  - compatible: must be "avago,apds9960"
+  - reg: the I2c address of the sensor
+  - interrupt-parent: should be the phandle for the interrupt controller
+  - interrupts : the sole interrupt generated by the device
+
+  Refer to interrupt-controller/interrupts.txt for generic interrupt client
+  node bindings.
+
+Example:
+
+apds9960@39 {
+       compatible = "avago,apds9960";
+       reg = <0x39>;
+       interrupt-parent = <&gpio1>;
+       interrupts = <16 1>;
+};
diff --git a/Documentation/devicetree/bindings/iio/light/us5182d.txt b/Documentation/devicetree/bindings/iio/light/us5182d.txt
new file mode 100644 (file)
index 0000000..6f0a530
--- /dev/null
@@ -0,0 +1,34 @@
+* UPISEMI us5182d I2C ALS and Proximity sensor
+
+Required properties:
+- compatible: must be "upisemi,usd5182"
+- reg: the I2C address of the device
+
+Optional properties:
+- upisemi,glass-coef: glass attenuation factor - compensation factor of
+                      resolution 1000 for material transmittance.
+- upisemi,dark-ths: array of 8 elements containing 16-bit thresholds (adc
+                    counts) corresponding to every scale.
+- upisemi,upper-dark-gain: 8-bit dark gain compensation factor(4 int and 4
+                           fractional bits - Q4.4) applied when light > threshold
+- upisemi,lower-dark-gain: 8-bit dark gain compensation factor(4 int and 4
+                           fractional bits - Q4.4) applied when light < threshold
+
+If the optional properties are not specified these factors will default to the
+values in the below example.
+The glass-coef defaults to no compensation for the covering material.
+The threshold array defaults to experimental values that work with US5182D
+sensor on evaluation board - roughly between 12-32 lux.
+There will be no dark-gain compensation by default when ALS > thresh
+(0 * dark-gain), and a 1.35 compensation factor when ALS < thresh.
+
+Example:
+
+    usd5182@39 {
+                compatible = "upisemi,usd5182";
+                reg = <0x39>;
+                upisemi,glass-coef = < 1000 >;
+                upisemi,dark-ths = /bits/ 16 <170 200 512 512 800 2000 4000 8000>;
+                upisemi,upper-dark-gain = /bits/ 8 <0x00>;
+                upisemi,lower-dark-gain = /bits/ 8 <0x16>;
+    };
index abc34e3652eaa9cf65c016a37c2da60ea0eaecae..55df1d444e9f82c150ef144c02357d13169ead31 100644 (file)
@@ -104,6 +104,7 @@ himax       Himax Technologies, Inc.
 hisilicon      Hisilicon Limited.
 hit    Hitachi Ltd.
 hitex  Hitex Development Tools
+holt   Holt Integrated Circuits, Inc.
 honeywell      Honeywell
 hp     Hewlett Packard
 i2se   I2SE GmbH
@@ -173,6 +174,7 @@ picochip    Picochip Ltd
 plathome       Plat'Home Co., Ltd.
 plda   PLDA
 pixcir  PIXCIR MICROELECTRONICS Co., Ltd
+pulsedlight    PulsedLight, Inc
 powervr        PowerVR (deprecated, use img)
 qca    Qualcomm Atheros, Inc.
 qcom   Qualcomm Technologies, Inc
@@ -195,6 +197,7 @@ sbs Smart Battery System
 schindler      Schindler
 seagate        Seagate Technology PLC
 semtech        Semtech Corporation
+sgx    SGX Sensortech
 sharp  Sharp Corporation
 sigma  Sigma Designs, Inc.
 sil    Silicon Image
@@ -229,6 +232,7 @@ toumaz      Toumaz
 tplink TP-LINK Technologies Co., Ltd.
 tronfy Tronfy
 truly  Truly Semiconductors Limited
+upisemi        uPI Semiconductor Corp.
 usi    Universal Scientific Industrial Co., Ltd.
 v3     V3 Semiconductor
 variscite      Variscite Ltd.
index e059bae82c07da28d15023dcdcb1922e655edfb8..40423a912f9da749859f3e9de20d9e05fae3f89a 100644 (file)
@@ -6780,6 +6780,12 @@ W:       http://linuxtv.org
 S:     Maintained
 F:     drivers/media/radio/radio-maxiradio*
 
+MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVER
+M:     Peter Rosin <peda@axentia.se>
+L:     linux-iio@vger.kernel.org
+S:     Maintained
+F:     drivers/iio/potentiometer/mcp4531.c
+
 MEDIA DRIVERS FOR RENESAS - VSP1
 M:     Laurent Pinchart <laurent.pinchart@ideasonboard.com>
 L:     linux-media@vger.kernel.org
@@ -7015,6 +7021,13 @@ S:       Supported
 F:     include/linux/mlx5/
 F:     drivers/infiniband/hw/mlx5/
 
+MELEXIS MLX90614 DRIVER
+M:     Crt Mori <cmo@melexis.com>
+L:     linux-iio@vger.kernel.org
+W:     http://www.melexis.com
+S:     Supported
+F:     drivers/iio/temperature/mlx90614.c
+
 MN88472 MEDIA DRIVER
 M:     Antti Palosaari <crope@iki.fi>
 L:     linux-media@vger.kernel.org
@@ -10142,9 +10155,11 @@ F:     drivers/staging/vt665?/
 
 STAGING - WILC1000 WIFI DRIVER
 M:     Johnny Kim <johnny.kim@atmel.com>
-M:     Rachel Kim <rachel.kim@atmel.com>
-M:     Dean Lee <dean.lee@atmel.com>
+M:     Austin Shin <austin.shin@atmel.com>
 M:     Chris Park <chris.park@atmel.com>
+M:     Tony Cho <tony.cho@atmel.com>
+M:     Glen Lee <glen.lee@atmel.com>
+M:     Leo Kim <leo.kim@atmel.com>
 L:     linux-wireless@vger.kernel.org
 S:     Supported
 F:     drivers/staging/wilc1000/
index 4011effe4c05d972959fb8fe9c3db297ee248421..66792e707d74e8d3106a7c908565b5d90d03d79f 100644 (file)
@@ -19,27 +19,7 @@ config IIO_BUFFER
          acquisition methods.
 
 if IIO_BUFFER
-
-config IIO_BUFFER_CB
-       bool "IIO callback buffer used for push in-kernel interfaces"
-       help
-         Should be selected by any drivers that do in-kernel push
-         usage.  That is, those where the data is pushed to the consumer.
-
-config IIO_KFIFO_BUF
-       tristate "Industrial I/O buffering based on kfifo"
-       help
-         A simple fifo based on kfifo.  Note that this currently provides
-         no buffer events so it is up to userspace to work out how
-         often to read from the buffer.
-
-config IIO_TRIGGERED_BUFFER
-       tristate
-       select IIO_TRIGGER
-       select IIO_KFIFO_BUF
-       help
-         Provides helper functions for setting up triggered buffers.
-
+       source "drivers/iio/buffer/Kconfig"
 endif # IIO_BUFFER
 
 config IIO_TRIGGER
@@ -58,9 +38,16 @@ config IIO_CONSUMERS_PER_TRIGGER
        This value controls the maximum number of consumers that a
        given trigger may handle. Default is 2.
 
+config IIO_TRIGGERED_EVENT
+       tristate
+       select IIO_TRIGGER
+       help
+         Provides helper functions for setting up triggered events.
+
 source "drivers/iio/accel/Kconfig"
 source "drivers/iio/adc/Kconfig"
 source "drivers/iio/amplifiers/Kconfig"
+source "drivers/iio/chemical/Kconfig"
 source "drivers/iio/common/Kconfig"
 source "drivers/iio/dac/Kconfig"
 source "drivers/iio/frequency/Kconfig"
@@ -73,6 +60,7 @@ source "drivers/iio/orientation/Kconfig"
 if IIO_TRIGGER
    source "drivers/iio/trigger/Kconfig"
 endif #IIO_TRIGGER
+source "drivers/iio/potentiometer/Kconfig"
 source "drivers/iio/pressure/Kconfig"
 source "drivers/iio/proximity/Kconfig"
 source "drivers/iio/temperature/Kconfig"
index 698afc2d17ce84c62e8e7fea4473558505d11808..aeca7269fe442967bd8704c8f9bf07ca0df3797a 100644 (file)
@@ -6,14 +6,14 @@ obj-$(CONFIG_IIO) += industrialio.o
 industrialio-y := industrialio-core.o industrialio-event.o inkern.o
 industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
 industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
-industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o
 
-obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
-obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
+obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o
 
 obj-y += accel/
 obj-y += adc/
 obj-y += amplifiers/
+obj-y += buffer/
+obj-y += chemical/
 obj-y += common/
 obj-y += dac/
 obj-y += gyro/
@@ -23,6 +23,7 @@ obj-y += imu/
 obj-y += light/
 obj-y += magnetometer/
 obj-y += orientation/
+obj-y += potentiometer/
 obj-y += pressure/
 obj-y += proximity/
 obj-y += temperature/
index a59047d7657eb414999d1f9081d914073a645f19..969428dd63299af04e4200ae309f971463f3f5eb 100644 (file)
@@ -19,19 +19,27 @@ config BMA180
 
 config BMC150_ACCEL
        tristate "Bosch BMC150 Accelerometer Driver"
-       depends on I2C
        select IIO_BUFFER
        select IIO_TRIGGERED_BUFFER
+       select REGMAP
+       select BMC150_ACCEL_I2C if I2C
+       select BMC150_ACCEL_SPI if SPI
        help
          Say yes here to build support for the following Bosch accelerometers:
          BMC150, BMI055, BMA250E, BMA222E, BMA255, BMA280.
 
-         Currently this only supports the device via an i2c interface.
-
          This is a combo module with both accelerometer and magnetometer.
          This driver is only implementing accelerometer part, which has
          its own address and register map.
 
+config BMC150_ACCEL_I2C
+       tristate
+       select REGMAP_I2C
+
+config BMC150_ACCEL_SPI
+       tristate
+       select REGMAP_SPI
+
 config HID_SENSOR_ACCEL_3D
        depends on HID_SENSOR_HUB
        select IIO_BUFFER
@@ -100,13 +108,13 @@ config KXCJK1013
          be called kxcjk-1013.
 
 config MMA8452
-       tristate "Freescale MMA8452Q Accelerometer Driver"
+       tristate "Freescale MMA8452Q and similar Accelerometers Driver"
        depends on I2C
        select IIO_BUFFER
        select IIO_TRIGGERED_BUFFER
        help
-         Say yes here to build support for the Freescale MMA8452Q 3-axis
-         accelerometer.
+         Say yes here to build support for the following Freescale 3-axis
+         accelerometers: MMA8452Q, MMA8453Q, MMA8652FC, MMA8653FC.
 
          To compile this driver as a module, choose M here: the module
          will be called mma8452.
@@ -137,6 +145,19 @@ config MMA9553
          To compile this driver as a module, choose M here: the module
          will be called mma9553.
 
+config MXC4005
+       tristate "Memsic MXC4005XC 3-Axis Accelerometer Driver"
+       depends on I2C
+       select IIO_BUFFER
+       select IIO_TRIGGERED_BUFFER
+       select REGMAP_I2C
+       help
+         Say yes here to build support for the Memsic MXC4005XC 3-axis
+         accelerometer.
+
+         To compile this driver as a module, choose M. The module will be
+         called mxc4005.
+
 config STK8312
        tristate "Sensortek STK8312 3-Axis Accelerometer Driver"
        depends on I2C
index ebd2675b2a0230d6aa07a7be8bec36bfd9a379aa..7925f166e6e957c76cf7acc9862ea603f23d9ea0 100644 (file)
@@ -4,7 +4,9 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_BMA180) += bma180.o
-obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel.o
+obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
+obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o
+obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
 obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
 obj-$(CONFIG_KXCJK1013) += kxcjk-1013.o
 obj-$(CONFIG_KXSD9)    += kxsd9.o
@@ -14,6 +16,8 @@ obj-$(CONFIG_MMA9551_CORE)    += mma9551_core.o
 obj-$(CONFIG_MMA9551)          += mma9551.o
 obj-$(CONFIG_MMA9553)          += mma9553.o
 
+obj-$(CONFIG_MXC4005)          += mxc4005.o
+
 obj-$(CONFIG_STK8312)          += stk8312.o
 obj-$(CONFIG_STK8BA50)         += stk8ba50.o
 
similarity index 81%
rename from drivers/iio/accel/bmc150-accel.c
rename to drivers/iio/accel/bmc150-accel-core.c
index 0104cdef8709b0dd05be6a337f2396a80629816a..2d33f1e821db0098a0d774e6c5d0fd44ba596675 100644 (file)
 #include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
+#include <linux/regmap.h>
+
+#include "bmc150-accel.h"
 
 #define BMC150_ACCEL_DRV_NAME                  "bmc150_accel"
 #define BMC150_ACCEL_IRQ_NAME                  "bmc150_accel_event"
-#define BMC150_ACCEL_GPIO_NAME                 "bmc150_accel_int"
 
 #define BMC150_ACCEL_REG_CHIP_ID               0x00
 
@@ -185,7 +187,9 @@ enum bmc150_accel_trigger_id {
 };
 
 struct bmc150_accel_data {
-       struct i2c_client *client;
+       struct regmap *regmap;
+       struct device *dev;
+       int irq;
        struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
        atomic_t active_intr;
        struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
@@ -242,6 +246,12 @@ static const struct {
                                       {500000, BMC150_ACCEL_SLEEP_500_MS},
                                       {1000000, BMC150_ACCEL_SLEEP_1_SEC} };
 
+static const struct regmap_config bmc150_i2c_regmap_conf = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0x3f,
+};
+
 static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
                                 enum bmc150_power_modes mode,
                                 int dur_us)
@@ -269,12 +279,11 @@ static int bmc150_accel_set_mode(struct bmc150_accel_data *data,
        lpw_bits = mode << BMC150_ACCEL_PMU_MODE_SHIFT;
        lpw_bits |= (dur_val << BMC150_ACCEL_PMU_BIT_SLEEP_DUR_SHIFT);
 
-       dev_dbg(&data->client->dev, "Set Mode bits %x\n", lpw_bits);
+       dev_dbg(data->dev, "Set Mode bits %x\n", lpw_bits);
 
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMC150_ACCEL_REG_PMU_LPW, lpw_bits);
+       ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_LPW, lpw_bits);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
+               dev_err(data->dev, "Error writing reg_pmu_lpw\n");
                return ret;
        }
 
@@ -290,8 +299,7 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
        for (i = 0; i < ARRAY_SIZE(bmc150_accel_samp_freq_table); ++i) {
                if (bmc150_accel_samp_freq_table[i].val == val &&
                    bmc150_accel_samp_freq_table[i].val2 == val2) {
-                       ret = i2c_smbus_write_byte_data(
-                               data->client,
+                       ret = regmap_write(data->regmap,
                                BMC150_ACCEL_REG_PMU_BW,
                                bmc150_accel_samp_freq_table[i].bw_bits);
                        if (ret < 0)
@@ -308,30 +316,23 @@ static int bmc150_accel_set_bw(struct bmc150_accel_data *data, int val,
 
 static int bmc150_accel_update_slope(struct bmc150_accel_data *data)
 {
-       int ret, val;
+       int ret;
 
-       ret = i2c_smbus_write_byte_data(data->client, BMC150_ACCEL_REG_INT_6,
+       ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_6,
                                        data->slope_thres);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_6\n");
-               return ret;
-       }
-
-       ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_INT_5);
-       if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_5\n");
+               dev_err(data->dev, "Error writing reg_int_6\n");
                return ret;
        }
 
-       val = (ret & ~BMC150_ACCEL_SLOPE_DUR_MASK) | data->slope_dur;
-       ret = i2c_smbus_write_byte_data(data->client, BMC150_ACCEL_REG_INT_5,
-                                       val);
+       ret = regmap_update_bits(data->regmap, BMC150_ACCEL_REG_INT_5,
+                                BMC150_ACCEL_SLOPE_DUR_MASK, data->slope_dur);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error write reg_int_5\n");
+               dev_err(data->dev, "Error updating reg_int_5\n");
                return ret;
        }
 
-       dev_dbg(&data->client->dev, "%s: %x %x\n", __func__, data->slope_thres,
+       dev_dbg(data->dev, "%s: %x %x\n", __func__, data->slope_thres,
                data->slope_dur);
 
        return ret;
@@ -380,17 +381,17 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
        int ret;
 
        if (on) {
-               ret = pm_runtime_get_sync(&data->client->dev);
+               ret = pm_runtime_get_sync(data->dev);
        } else {
-               pm_runtime_mark_last_busy(&data->client->dev);
-               ret = pm_runtime_put_autosuspend(&data->client->dev);
+               pm_runtime_mark_last_busy(data->dev);
+               ret = pm_runtime_put_autosuspend(data->dev);
        }
 
        if (ret < 0) {
-               dev_err(&data->client->dev,
+               dev_err(data->dev,
                        "Failed: bmc150_accel_set_power_state for %d\n", on);
                if (on)
-                       pm_runtime_put_noidle(&data->client->dev);
+                       pm_runtime_put_noidle(data->dev);
 
                return ret;
        }
@@ -470,38 +471,18 @@ static int bmc150_accel_set_interrupt(struct bmc150_accel_data *data, int i,
                return ret;
 
        /* map the interrupt to the appropriate pins */
-       ret = i2c_smbus_read_byte_data(data->client, info->map_reg);
-       if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_map\n");
-               goto out_fix_power_state;
-       }
-       if (state)
-               ret |= info->map_bitmask;
-       else
-               ret &= ~info->map_bitmask;
-
-       ret = i2c_smbus_write_byte_data(data->client, info->map_reg,
-                                       ret);
+       ret = regmap_update_bits(data->regmap, info->map_reg, info->map_bitmask,
+                                (state ? info->map_bitmask : 0));
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_map\n");
+               dev_err(data->dev, "Error updating reg_int_map\n");
                goto out_fix_power_state;
        }
 
        /* enable/disable the interrupt */
-       ret = i2c_smbus_read_byte_data(data->client, info->en_reg);
-       if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_en\n");
-               goto out_fix_power_state;
-       }
-
-       if (state)
-               ret |= info->en_bitmask;
-       else
-               ret &= ~info->en_bitmask;
-
-       ret = i2c_smbus_write_byte_data(data->client, info->en_reg, ret);
+       ret = regmap_update_bits(data->regmap, info->en_reg, info->en_bitmask,
+                                (state ? info->en_bitmask : 0));
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_en\n");
+               dev_err(data->dev, "Error updating reg_int_en\n");
                goto out_fix_power_state;
        }
 
@@ -523,12 +504,11 @@ static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
 
        for (i = 0; i < ARRAY_SIZE(data->chip_info->scale_table); ++i) {
                if (data->chip_info->scale_table[i].scale == val) {
-                       ret = i2c_smbus_write_byte_data(
-                                    data->client,
+                       ret = regmap_write(data->regmap,
                                     BMC150_ACCEL_REG_PMU_RANGE,
                                     data->chip_info->scale_table[i].reg_range);
                        if (ret < 0) {
-                               dev_err(&data->client->dev,
+                               dev_err(data->dev,
                                        "Error writing pmu_range\n");
                                return ret;
                        }
@@ -544,16 +524,17 @@ static int bmc150_accel_set_scale(struct bmc150_accel_data *data, int val)
 static int bmc150_accel_get_temp(struct bmc150_accel_data *data, int *val)
 {
        int ret;
+       unsigned int value;
 
        mutex_lock(&data->mutex);
 
-       ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_TEMP);
+       ret = regmap_read(data->regmap, BMC150_ACCEL_REG_TEMP, &value);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_temp\n");
+               dev_err(data->dev, "Error reading reg_temp\n");
                mutex_unlock(&data->mutex);
                return ret;
        }
-       *val = sign_extend32(ret, 7);
+       *val = sign_extend32(value, 7);
 
        mutex_unlock(&data->mutex);
 
@@ -566,6 +547,7 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
 {
        int ret;
        int axis = chan->scan_index;
+       unsigned int raw_val;
 
        mutex_lock(&data->mutex);
        ret = bmc150_accel_set_power_state(data, true);
@@ -574,15 +556,15 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data,
                return ret;
        }
 
-       ret = i2c_smbus_read_word_data(data->client,
-                                      BMC150_ACCEL_AXIS_TO_REG(axis));
+       ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_AXIS_TO_REG(axis),
+                              &raw_val, 2);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading axis %d\n", axis);
+               dev_err(data->dev, "Error reading axis %d\n", axis);
                bmc150_accel_set_power_state(data, false);
                mutex_unlock(&data->mutex);
                return ret;
        }
-       *val = sign_extend32(ret >> chan->scan_type.shift,
+       *val = sign_extend32(raw_val >> chan->scan_type.shift,
                             chan->scan_type.realbits - 1);
        ret = bmc150_accel_set_power_state(data, false);
        mutex_unlock(&data->mutex);
@@ -846,52 +828,34 @@ static int bmc150_accel_set_watermark(struct iio_dev *indio_dev, unsigned val)
  * We must read at least one full frame in one burst, otherwise the rest of the
  * frame data is discarded.
  */
-static int bmc150_accel_fifo_transfer(const struct i2c_client *client,
+static int bmc150_accel_fifo_transfer(struct bmc150_accel_data *data,
                                      char *buffer, int samples)
 {
        int sample_length = 3 * 2;
-       u8 reg_fifo_data = BMC150_ACCEL_REG_FIFO_DATA;
-       int ret = -EIO;
-
-       if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
-               struct i2c_msg msg[2] = {
-                       {
-                               .addr = client->addr,
-                               .flags = 0,
-                               .buf = &reg_fifo_data,
-                               .len = sizeof(reg_fifo_data),
-                       },
-                       {
-                               .addr = client->addr,
-                               .flags = I2C_M_RD,
-                               .buf = (u8 *)buffer,
-                               .len = samples * sample_length,
-                       }
-               };
+       int ret;
+       int total_length = samples * sample_length;
+       int i;
+       size_t step = regmap_get_raw_read_max(data->regmap);
 
-               ret = i2c_transfer(client->adapter, msg, 2);
-               if (ret != 2)
-                       ret = -EIO;
-               else
-                       ret = 0;
-       } else {
-               int i, step = I2C_SMBUS_BLOCK_MAX / sample_length;
-
-               for (i = 0; i < samples * sample_length; i += step) {
-                       ret = i2c_smbus_read_i2c_block_data(client,
-                                                           reg_fifo_data, step,
-                                                           &buffer[i]);
-                       if (ret != step) {
-                               ret = -EIO;
-                               break;
-                       }
+       if (!step || step > total_length)
+               step = total_length;
+       else if (step < total_length)
+               step = sample_length;
 
-                       ret = 0;
-               }
+       /*
+        * Seems we have a bus with size limitation so we have to execute
+        * multiple reads
+        */
+       for (i = 0; i < total_length; i += step) {
+               ret = regmap_raw_read(data->regmap, BMC150_ACCEL_REG_FIFO_DATA,
+                                     &buffer[i], step);
+               if (ret)
+                       break;
        }
 
        if (ret)
-               dev_err(&client->dev, "Error transferring data from fifo\n");
+               dev_err(data->dev, "Error transferring data from fifo in single steps of %zu\n",
+                       step);
 
        return ret;
 }
@@ -905,15 +869,15 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
        u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
        int64_t tstamp;
        uint64_t sample_period;
+       unsigned int val;
 
-       ret = i2c_smbus_read_byte_data(data->client,
-                                      BMC150_ACCEL_REG_FIFO_STATUS);
+       ret = regmap_read(data->regmap, BMC150_ACCEL_REG_FIFO_STATUS, &val);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_fifo_status\n");
+               dev_err(data->dev, "Error reading reg_fifo_status\n");
                return ret;
        }
 
-       count = ret & 0x7F;
+       count = val & 0x7F;
 
        if (!count)
                return 0;
@@ -952,7 +916,7 @@ static int __bmc150_accel_fifo_flush(struct iio_dev *indio_dev,
        if (samples && count > samples)
                count = samples;
 
-       ret = bmc150_accel_fifo_transfer(data->client, (u8 *)buffer, count);
+       ret = bmc150_accel_fifo_transfer(data, (u8 *)buffer, count);
        if (ret)
                return ret;
 
@@ -1052,15 +1016,6 @@ static const struct iio_chan_spec bmc150_accel_channels[] =
 static const struct iio_chan_spec bma280_accel_channels[] =
        BMC150_ACCEL_CHANNELS(14);
 
-enum {
-       bmc150,
-       bmi055,
-       bma255,
-       bma250e,
-       bma222e,
-       bma280,
-};
-
 static const struct bmc150_accel_chip_info bmc150_accel_chip_info_tbl[] = {
        [bmc150] = {
                .name = "BMC150A",
@@ -1155,17 +1110,19 @@ static irqreturn_t bmc150_accel_trigger_handler(int irq, void *p)
        struct iio_dev *indio_dev = pf->indio_dev;
        struct bmc150_accel_data *data = iio_priv(indio_dev);
        int bit, ret, i = 0;
+       unsigned int raw_val;
 
        mutex_lock(&data->mutex);
        for_each_set_bit(bit, indio_dev->active_scan_mask,
                         indio_dev->masklength) {
-               ret = i2c_smbus_read_word_data(data->client,
-                                              BMC150_ACCEL_AXIS_TO_REG(bit));
+               ret = regmap_bulk_read(data->regmap,
+                                      BMC150_ACCEL_AXIS_TO_REG(bit), &raw_val,
+                                      2);
                if (ret < 0) {
                        mutex_unlock(&data->mutex);
                        goto err_read;
                }
-               data->buffer[i++] = ret;
+               data->buffer[i++] = raw_val;
        }
        mutex_unlock(&data->mutex);
 
@@ -1189,13 +1146,12 @@ static int bmc150_accel_trig_try_reen(struct iio_trigger *trig)
 
        mutex_lock(&data->mutex);
        /* clear any latched interrupt */
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMC150_ACCEL_REG_INT_RST_LATCH,
-                                       BMC150_ACCEL_INT_MODE_LATCH_INT |
-                                       BMC150_ACCEL_INT_MODE_LATCH_RESET);
+       ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
+                          BMC150_ACCEL_INT_MODE_LATCH_INT |
+                          BMC150_ACCEL_INT_MODE_LATCH_RESET);
        mutex_unlock(&data->mutex);
        if (ret < 0) {
-               dev_err(&data->client->dev,
+               dev_err(data->dev,
                        "Error writing reg_int_rst_latch\n");
                return ret;
        }
@@ -1249,20 +1205,20 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
        struct bmc150_accel_data *data = iio_priv(indio_dev);
        int dir;
        int ret;
+       unsigned int val;
 
-       ret = i2c_smbus_read_byte_data(data->client,
-                                      BMC150_ACCEL_REG_INT_STATUS_2);
+       ret = regmap_read(data->regmap, BMC150_ACCEL_REG_INT_STATUS_2, &val);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_status_2\n");
+               dev_err(data->dev, "Error reading reg_int_status_2\n");
                return ret;
        }
 
-       if (ret & BMC150_ACCEL_ANY_MOTION_BIT_SIGN)
+       if (val & BMC150_ACCEL_ANY_MOTION_BIT_SIGN)
                dir = IIO_EV_DIR_FALLING;
        else
                dir = IIO_EV_DIR_RISING;
 
-       if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
+       if (val & BMC150_ACCEL_ANY_MOTION_BIT_X)
                iio_push_event(indio_dev,
                               IIO_MOD_EVENT_CODE(IIO_ACCEL,
                                                  0,
@@ -1271,7 +1227,7 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
                                                  dir),
                               data->timestamp);
 
-       if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
+       if (val & BMC150_ACCEL_ANY_MOTION_BIT_Y)
                iio_push_event(indio_dev,
                               IIO_MOD_EVENT_CODE(IIO_ACCEL,
                                                  0,
@@ -1280,7 +1236,7 @@ static int bmc150_accel_handle_roc_event(struct iio_dev *indio_dev)
                                                  dir),
                               data->timestamp);
 
-       if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
+       if (val & BMC150_ACCEL_ANY_MOTION_BIT_Z)
                iio_push_event(indio_dev,
                               IIO_MOD_EVENT_CODE(IIO_ACCEL,
                                                  0,
@@ -1315,13 +1271,11 @@ static irqreturn_t bmc150_accel_irq_thread_handler(int irq, void *private)
        }
 
        if (ack) {
-               ret = i2c_smbus_write_byte_data(data->client,
-                                       BMC150_ACCEL_REG_INT_RST_LATCH,
-                                       BMC150_ACCEL_INT_MODE_LATCH_INT |
-                                       BMC150_ACCEL_INT_MODE_LATCH_RESET);
+               ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
+                                  BMC150_ACCEL_INT_MODE_LATCH_INT |
+                                  BMC150_ACCEL_INT_MODE_LATCH_RESET);
                if (ret)
-                       dev_err(&data->client->dev,
-                               "Error writing reg_int_rst_latch\n");
+                       dev_err(data->dev, "Error writing reg_int_rst_latch\n");
 
                ret = IRQ_HANDLED;
        } else {
@@ -1360,32 +1314,6 @@ static irqreturn_t bmc150_accel_irq_handler(int irq, void *private)
        return IRQ_NONE;
 }
 
-static int bmc150_accel_gpio_probe(struct i2c_client *client,
-                                  struct bmc150_accel_data *data)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       dev = &client->dev;
-
-       /* data ready gpio interrupt pin */
-       gpio = devm_gpiod_get_index(dev, BMC150_ACCEL_GPIO_NAME, 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "Failed: gpio get index\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-
-       return ret;
-}
-
 static const struct {
        int intr;
        const char *name;
@@ -1423,7 +1351,7 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
        for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) {
                struct bmc150_accel_trigger *t = &data->triggers[i];
 
-               t->indio_trig = devm_iio_trigger_alloc(&data->client->dev,
+               t->indio_trig = devm_iio_trigger_alloc(data->dev,
                                               bmc150_accel_triggers[i].name,
                                                       indio_dev->name,
                                                       indio_dev->id);
@@ -1432,7 +1360,7 @@ static int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
                        break;
                }
 
-               t->indio_trig->dev.parent = &data->client->dev;
+               t->indio_trig->dev.parent = data->dev;
                t->indio_trig->ops = &bmc150_accel_trigger_ops;
                t->intr = bmc150_accel_triggers[i].intr;
                t->data = data;
@@ -1459,20 +1387,19 @@ static int bmc150_accel_fifo_set_mode(struct bmc150_accel_data *data)
        u8 reg = BMC150_ACCEL_REG_FIFO_CONFIG1;
        int ret;
 
-       ret = i2c_smbus_write_byte_data(data->client, reg, data->fifo_mode);
+       ret = regmap_write(data->regmap, reg, data->fifo_mode);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_fifo_config1\n");
+               dev_err(data->dev, "Error writing reg_fifo_config1\n");
                return ret;
        }
 
        if (!data->fifo_mode)
                return 0;
 
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMC150_ACCEL_REG_FIFO_CONFIG0,
-                                       data->watermark);
+       ret = regmap_write(data->regmap, BMC150_ACCEL_REG_FIFO_CONFIG0,
+                          data->watermark);
        if (ret < 0)
-               dev_err(&data->client->dev, "Error writing reg_fifo_config0\n");
+               dev_err(data->dev, "Error writing reg_fifo_config0\n");
 
        return ret;
 }
@@ -1557,23 +1484,25 @@ static const struct iio_buffer_setup_ops bmc150_accel_buffer_ops = {
 static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
 {
        int ret, i;
+       unsigned int val;
 
-       ret = i2c_smbus_read_byte_data(data->client, BMC150_ACCEL_REG_CHIP_ID);
+       ret = regmap_read(data->regmap, BMC150_ACCEL_REG_CHIP_ID, &val);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error: Reading chip id\n");
+               dev_err(data->dev,
+                       "Error: Reading chip id\n");
                return ret;
        }
 
-       dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
+       dev_dbg(data->dev, "Chip Id %x\n", val);
        for (i = 0; i < ARRAY_SIZE(bmc150_accel_chip_info_tbl); i++) {
-               if (bmc150_accel_chip_info_tbl[i].chip_id == ret) {
+               if (bmc150_accel_chip_info_tbl[i].chip_id == val) {
                        data->chip_info = &bmc150_accel_chip_info_tbl[i];
                        break;
                }
        }
 
        if (!data->chip_info) {
-               dev_err(&data->client->dev, "Unsupported chip %x\n", ret);
+               dev_err(data->dev, "Invalid chip %x\n", val);
                return -ENODEV;
        }
 
@@ -1587,11 +1516,11 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
                return ret;
 
        /* Set Default Range */
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMC150_ACCEL_REG_PMU_RANGE,
-                                       BMC150_ACCEL_DEF_RANGE_4G);
+       ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_RANGE,
+                          BMC150_ACCEL_DEF_RANGE_4G);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_pmu_range\n");
+               dev_err(data->dev,
+                                       "Error writing reg_pmu_range\n");
                return ret;
        }
 
@@ -1605,12 +1534,11 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
                return ret;
 
        /* Set default as latched interrupts */
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMC150_ACCEL_REG_INT_RST_LATCH,
-                                       BMC150_ACCEL_INT_MODE_LATCH_INT |
-                                       BMC150_ACCEL_INT_MODE_LATCH_RESET);
+       ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
+                          BMC150_ACCEL_INT_MODE_LATCH_INT |
+                          BMC150_ACCEL_INT_MODE_LATCH_RESET);
        if (ret < 0) {
-               dev_err(&data->client->dev,
+               dev_err(data->dev,
                        "Error writing reg_int_rst_latch\n");
                return ret;
        }
@@ -1618,24 +1546,23 @@ static int bmc150_accel_chip_init(struct bmc150_accel_data *data)
        return 0;
 }
 
-static int bmc150_accel_probe(struct i2c_client *client,
-                             const struct i2c_device_id *id)
+int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
+                           const char *name, bool block_supported)
 {
        struct bmc150_accel_data *data;
        struct iio_dev *indio_dev;
        int ret;
-       const char *name = NULL;
 
-       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
        if (!indio_dev)
                return -ENOMEM;
 
        data = iio_priv(indio_dev);
-       i2c_set_clientdata(client, indio_dev);
-       data->client = client;
+       dev_set_drvdata(dev, indio_dev);
+       data->dev = dev;
+       data->irq = irq;
 
-       if (id)
-               name = id->name;
+       data->regmap = regmap;
 
        ret = bmc150_accel_chip_init(data);
        if (ret < 0)
@@ -1643,7 +1570,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
 
        mutex_init(&data->mutex);
 
-       indio_dev->dev.parent = &client->dev;
+       indio_dev->dev.parent = dev;
        indio_dev->channels = data->chip_info->channels;
        indio_dev->num_channels = data->chip_info->num_channels;
        indio_dev->name = name ? name : data->chip_info->name;
@@ -1655,16 +1582,13 @@ static int bmc150_accel_probe(struct i2c_client *client,
                                         bmc150_accel_trigger_handler,
                                         &bmc150_accel_buffer_ops);
        if (ret < 0) {
-               dev_err(&client->dev, "Failed: iio triggered buffer setup\n");
+               dev_err(data->dev, "Failed: iio triggered buffer setup\n");
                return ret;
        }
 
-       if (client->irq < 0)
-               client->irq = bmc150_accel_gpio_probe(client, data);
-
-       if (client->irq > 0) {
+       if (data->irq > 0) {
                ret = devm_request_threaded_irq(
-                                               &client->dev, client->irq,
+                                               data->dev, data->irq,
                                                bmc150_accel_irq_handler,
                                                bmc150_accel_irq_thread_handler,
                                                IRQF_TRIGGER_RISING,
@@ -1679,11 +1603,10 @@ static int bmc150_accel_probe(struct i2c_client *client,
                 * want to use latch mode when we can to prevent interrupt
                 * flooding.
                 */
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMC150_ACCEL_REG_INT_RST_LATCH,
-                                            BMC150_ACCEL_INT_MODE_LATCH_RESET);
+               ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_RST_LATCH,
+                                  BMC150_ACCEL_INT_MODE_LATCH_RESET);
                if (ret < 0) {
-                       dev_err(&data->client->dev, "Error writing reg_int_rst_latch\n");
+                       dev_err(data->dev, "Error writing reg_int_rst_latch\n");
                        goto err_buffer_cleanup;
                }
 
@@ -1693,9 +1616,7 @@ static int bmc150_accel_probe(struct i2c_client *client,
                if (ret)
                        goto err_buffer_cleanup;
 
-               if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
-                   i2c_check_functionality(client->adapter,
-                                           I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
+               if (block_supported) {
                        indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
                        indio_dev->info = &bmc150_accel_info_fifo;
                        indio_dev->buffer->attrs = bmc150_accel_fifo_attributes;
@@ -1704,18 +1625,17 @@ static int bmc150_accel_probe(struct i2c_client *client,
 
        ret = iio_device_register(indio_dev);
        if (ret < 0) {
-               dev_err(&client->dev, "Unable to register iio device\n");
+               dev_err(dev, "Unable to register iio device\n");
                goto err_trigger_unregister;
        }
 
-       ret = pm_runtime_set_active(&client->dev);
+       ret = pm_runtime_set_active(dev);
        if (ret)
                goto err_iio_unregister;
 
-       pm_runtime_enable(&client->dev);
-       pm_runtime_set_autosuspend_delay(&client->dev,
-                                        BMC150_AUTO_SUSPEND_DELAY_MS);
-       pm_runtime_use_autosuspend(&client->dev);
+       pm_runtime_enable(dev);
+       pm_runtime_set_autosuspend_delay(dev, BMC150_AUTO_SUSPEND_DELAY_MS);
+       pm_runtime_use_autosuspend(dev);
 
        return 0;
 
@@ -1728,15 +1648,16 @@ err_buffer_cleanup:
 
        return ret;
 }
+EXPORT_SYMBOL_GPL(bmc150_accel_core_probe);
 
-static int bmc150_accel_remove(struct i2c_client *client)
+int bmc150_accel_core_remove(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(client);
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmc150_accel_data *data = iio_priv(indio_dev);
 
-       pm_runtime_disable(&client->dev);
-       pm_runtime_set_suspended(&client->dev);
-       pm_runtime_put_noidle(&client->dev);
+       pm_runtime_disable(data->dev);
+       pm_runtime_set_suspended(data->dev);
+       pm_runtime_put_noidle(data->dev);
 
        iio_device_unregister(indio_dev);
 
@@ -1750,11 +1671,12 @@ static int bmc150_accel_remove(struct i2c_client *client)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(bmc150_accel_core_remove);
 
 #ifdef CONFIG_PM_SLEEP
 static int bmc150_accel_suspend(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmc150_accel_data *data = iio_priv(indio_dev);
 
        mutex_lock(&data->mutex);
@@ -1766,7 +1688,7 @@ static int bmc150_accel_suspend(struct device *dev)
 
 static int bmc150_accel_resume(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmc150_accel_data *data = iio_priv(indio_dev);
 
        mutex_lock(&data->mutex);
@@ -1782,11 +1704,11 @@ static int bmc150_accel_resume(struct device *dev)
 #ifdef CONFIG_PM
 static int bmc150_accel_runtime_suspend(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmc150_accel_data *data = iio_priv(indio_dev);
        int ret;
 
-       dev_dbg(&data->client->dev,  __func__);
+       dev_dbg(data->dev,  __func__);
        ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0);
        if (ret < 0)
                return -EAGAIN;
@@ -1796,12 +1718,12 @@ static int bmc150_accel_runtime_suspend(struct device *dev)
 
 static int bmc150_accel_runtime_resume(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmc150_accel_data *data = iio_priv(indio_dev);
        int ret;
        int sleep_val;
 
-       dev_dbg(&data->client->dev,  __func__);
+       dev_dbg(data->dev,  __func__);
 
        ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
        if (ret < 0)
@@ -1820,47 +1742,12 @@ static int bmc150_accel_runtime_resume(struct device *dev)
 }
 #endif
 
-static const struct dev_pm_ops bmc150_accel_pm_ops = {
+const struct dev_pm_ops bmc150_accel_pm_ops = {
        SET_SYSTEM_SLEEP_PM_OPS(bmc150_accel_suspend, bmc150_accel_resume)
        SET_RUNTIME_PM_OPS(bmc150_accel_runtime_suspend,
                           bmc150_accel_runtime_resume, NULL)
 };
-
-static const struct acpi_device_id bmc150_accel_acpi_match[] = {
-       {"BSBA0150",    bmc150},
-       {"BMC150A",     bmc150},
-       {"BMI055A",     bmi055},
-       {"BMA0255",     bma255},
-       {"BMA250E",     bma250e},
-       {"BMA222E",     bma222e},
-       {"BMA0280",     bma280},
-       { },
-};
-MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
-
-static const struct i2c_device_id bmc150_accel_id[] = {
-       {"bmc150_accel",        bmc150},
-       {"bmi055_accel",        bmi055},
-       {"bma255",              bma255},
-       {"bma250e",             bma250e},
-       {"bma222e",             bma222e},
-       {"bma280",              bma280},
-       {}
-};
-
-MODULE_DEVICE_TABLE(i2c, bmc150_accel_id);
-
-static struct i2c_driver bmc150_accel_driver = {
-       .driver = {
-               .name   = BMC150_ACCEL_DRV_NAME,
-               .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
-               .pm     = &bmc150_accel_pm_ops,
-       },
-       .probe          = bmc150_accel_probe,
-       .remove         = bmc150_accel_remove,
-       .id_table       = bmc150_accel_id,
-};
-module_i2c_driver(bmc150_accel_driver);
+EXPORT_SYMBOL_GPL(bmc150_accel_pm_ops);
 
 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/bmc150-accel-i2c.c b/drivers/iio/accel/bmc150-accel-i2c.c
new file mode 100644 (file)
index 0000000..b41404b
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * 3-axis accelerometer driver supporting following I2C Bosch-Sensortec chips:
+ *  - BMC150
+ *  - BMI055
+ *  - BMA255
+ *  - BMA250E
+ *  - BMA222E
+ *  - BMA280
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/regmap.h>
+
+#include "bmc150-accel.h"
+
+static const struct regmap_config bmc150_i2c_regmap_conf = {
+       .reg_bits = 8,
+       .val_bits = 8,
+};
+
+static int bmc150_accel_probe(struct i2c_client *client,
+                             const struct i2c_device_id *id)
+{
+       struct regmap *regmap;
+       const char *name = NULL;
+       bool block_supported =
+               i2c_check_functionality(client->adapter, I2C_FUNC_I2C) ||
+               i2c_check_functionality(client->adapter,
+                                       I2C_FUNC_SMBUS_READ_I2C_BLOCK);
+
+       regmap = devm_regmap_init_i2c(client, &bmc150_i2c_regmap_conf);
+       if (IS_ERR(regmap)) {
+               dev_err(&client->dev, "Failed to initialize i2c regmap\n");
+               return PTR_ERR(regmap);
+       }
+
+       if (id)
+               name = id->name;
+
+       return bmc150_accel_core_probe(&client->dev, regmap, client->irq, name,
+                                      block_supported);
+}
+
+static int bmc150_accel_remove(struct i2c_client *client)
+{
+       return bmc150_accel_core_remove(&client->dev);
+}
+
+static const struct acpi_device_id bmc150_accel_acpi_match[] = {
+       {"BSBA0150",    bmc150},
+       {"BMC150A",     bmc150},
+       {"BMI055A",     bmi055},
+       {"BMA0255",     bma255},
+       {"BMA250E",     bma250e},
+       {"BMA222E",     bma222e},
+       {"BMA0280",     bma280},
+       { },
+};
+MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
+
+static const struct i2c_device_id bmc150_accel_id[] = {
+       {"bmc150_accel",        bmc150},
+       {"bmi055_accel",        bmi055},
+       {"bma255",              bma255},
+       {"bma250e",             bma250e},
+       {"bma222e",             bma222e},
+       {"bma280",              bma280},
+       {}
+};
+
+MODULE_DEVICE_TABLE(i2c, bmc150_accel_id);
+
+static struct i2c_driver bmc150_accel_driver = {
+       .driver = {
+               .name   = "bmc150_accel_i2c",
+               .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
+               .pm     = &bmc150_accel_pm_ops,
+       },
+       .probe          = bmc150_accel_probe,
+       .remove         = bmc150_accel_remove,
+       .id_table       = bmc150_accel_id,
+};
+module_i2c_driver(bmc150_accel_driver);
+
+MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMC150 I2C accelerometer driver");
diff --git a/drivers/iio/accel/bmc150-accel-spi.c b/drivers/iio/accel/bmc150-accel-spi.c
new file mode 100644 (file)
index 0000000..16b66f2
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * 3-axis accelerometer driver supporting SPI Bosch-Sensortec accelerometer chip
+ * Copyright Â© 2015 Pengutronix, Markus Pargmann <mpa@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/device.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+
+#include "bmc150-accel.h"
+
+static const struct regmap_config bmc150_spi_regmap_conf = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0x3f,
+};
+
+static int bmc150_accel_probe(struct spi_device *spi)
+{
+       struct regmap *regmap;
+       const struct spi_device_id *id = spi_get_device_id(spi);
+
+       regmap = devm_regmap_init_spi(spi, &bmc150_spi_regmap_conf);
+       if (IS_ERR(regmap)) {
+               dev_err(&spi->dev, "Failed to initialize spi regmap\n");
+               return PTR_ERR(regmap);
+       }
+
+       return bmc150_accel_core_probe(&spi->dev, regmap, spi->irq, id->name,
+                                      true);
+}
+
+static int bmc150_accel_remove(struct spi_device *spi)
+{
+       return bmc150_accel_core_remove(&spi->dev);
+}
+
+static const struct acpi_device_id bmc150_accel_acpi_match[] = {
+       {"BSBA0150",    bmc150},
+       {"BMC150A",     bmc150},
+       {"BMI055A",     bmi055},
+       {"BMA0255",     bma255},
+       {"BMA250E",     bma250e},
+       {"BMA222E",     bma222e},
+       {"BMA0280",     bma280},
+       { },
+};
+MODULE_DEVICE_TABLE(acpi, bmc150_accel_acpi_match);
+
+static const struct spi_device_id bmc150_accel_id[] = {
+       {"bmc150_accel",        bmc150},
+       {"bmi055_accel",        bmi055},
+       {"bma255",              bma255},
+       {"bma250e",             bma250e},
+       {"bma222e",             bma222e},
+       {"bma280",              bma280},
+       {}
+};
+MODULE_DEVICE_TABLE(spi, bmc150_accel_id);
+
+static struct spi_driver bmc150_accel_driver = {
+       .driver = {
+               .name   = "bmc150_accel_spi",
+               .acpi_match_table = ACPI_PTR(bmc150_accel_acpi_match),
+               .pm     = &bmc150_accel_pm_ops,
+       },
+       .probe          = bmc150_accel_probe,
+       .remove         = bmc150_accel_remove,
+       .id_table       = bmc150_accel_id,
+};
+module_spi_driver(bmc150_accel_driver);
+
+MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMC150 SPI accelerometer driver");
diff --git a/drivers/iio/accel/bmc150-accel.h b/drivers/iio/accel/bmc150-accel.h
new file mode 100644 (file)
index 0000000..ba03359
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _BMC150_ACCEL_H_
+#define _BMC150_ACCEL_H_
+
+struct regmap;
+
+enum {
+       bmc150,
+       bmi055,
+       bma255,
+       bma250e,
+       bma222e,
+       bma280,
+};
+
+int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
+                           const char *name, bool block_supported);
+int bmc150_accel_core_remove(struct device *dev);
+extern const struct dev_pm_ops bmc150_accel_pm_ops;
+
+#endif  /* _BMC150_ACCEL_H_ */
index 3292bc0c1d0ef9ea7595c1a4e02effa2dc5c3248..18c1b06684c1b4cb79d2fcb3812d16646fe62e98 100644 (file)
@@ -1162,35 +1162,6 @@ static const char *kxcjk1013_match_acpi_device(struct device *dev,
        return dev_name(dev);
 }
 
-static int kxcjk1013_gpio_probe(struct i2c_client *client,
-                               struct kxcjk1013_data *data)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       if (data->is_smo8500_device)
-               return -ENOTSUPP;
-
-       dev = &client->dev;
-
-       /* data ready gpio interrupt pin */
-       gpio = devm_gpiod_get_index(dev, "kxcjk1013_int", 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "acpi gpio get index failed\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-
-       return ret;
-}
-
 static int kxcjk1013_probe(struct i2c_client *client,
                           const struct i2c_device_id *id)
 {
@@ -1237,10 +1208,7 @@ static int kxcjk1013_probe(struct i2c_client *client,
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->info = &kxcjk1013_info;
 
-       if (client->irq < 0)
-               client->irq = kxcjk1013_gpio_probe(client, data);
-
-       if (client->irq > 0) {
+       if (client->irq > 0 && !data->is_smo8500_device) {
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                                                kxcjk1013_data_rdy_trig_poll,
                                                kxcjk1013_event_handler,
index b921d84c1be6214097c80e91ccdaacc54963034c..1eccc2dcf14cdcf53c6df1a5c9eb562a8d26db5c 100644 (file)
@@ -1,6 +1,12 @@
 /*
- * mma8452.c - Support for Freescale MMA8452Q 3-axis 12-bit accelerometer
+ * mma8452.c - Support for following Freescale 3-axis accelerometers:
  *
+ * MMA8452Q (12 bit)
+ * MMA8453Q (10 bit)
+ * MMA8652FC (12 bit)
+ * MMA8653FC (10 bit)
+ *
+ * Copyright 2015 Martin Kepplinger <martin.kepplinger@theobroma-systems.com>
  * Copyright 2014 Peter Meerwald <pmeerw@pmeerw.net>
  *
  * This file is subject to the terms and conditions of version 2 of
 #include <linux/iio/triggered_buffer.h>
 #include <linux/iio/events.h>
 #include <linux/delay.h>
+#include <linux/of_device.h>
 
 #define MMA8452_STATUS                         0x00
 #define  MMA8452_STATUS_DRDY                   (BIT(2) | BIT(1) | BIT(0))
-#define MMA8452_OUT_X                          0x01 /* MSB first, 12-bit  */
+#define MMA8452_OUT_X                          0x01 /* MSB first */
 #define MMA8452_OUT_Y                          0x03
 #define MMA8452_OUT_Z                          0x05
 #define MMA8452_INT_SRC                                0x0c
 #define  MMA8452_DATA_CFG_HPF_MASK             BIT(4)
 #define MMA8452_HP_FILTER_CUTOFF               0x0f
 #define  MMA8452_HP_FILTER_CUTOFF_SEL_MASK     GENMASK(1, 0)
+#define MMA8452_FF_MT_CFG                      0x15
+#define  MMA8452_FF_MT_CFG_OAE                 BIT(6)
+#define  MMA8452_FF_MT_CFG_ELE                 BIT(7)
+#define MMA8452_FF_MT_SRC                      0x16
+#define  MMA8452_FF_MT_SRC_XHE                 BIT(1)
+#define  MMA8452_FF_MT_SRC_YHE                 BIT(3)
+#define  MMA8452_FF_MT_SRC_ZHE                 BIT(5)
+#define MMA8452_FF_MT_THS                      0x17
+#define  MMA8452_FF_MT_THS_MASK                        0x7f
+#define MMA8452_FF_MT_COUNT                    0x18
 #define MMA8452_TRANSIENT_CFG                  0x1d
 #define  MMA8452_TRANSIENT_CFG_HPF_BYP         BIT(0)
 #define  MMA8452_TRANSIENT_CFG_CHAN(chan)      BIT(chan + 1)
 #define MMA8452_MAX_REG                                0x31
 
 #define  MMA8452_INT_DRDY                      BIT(0)
+#define  MMA8452_INT_FF_MT                     BIT(2)
 #define  MMA8452_INT_TRANS                     BIT(5)
 
 #define  MMA8452_DEVICE_ID                     0x2a
+#define  MMA8453_DEVICE_ID                     0x3a
+#define MMA8652_DEVICE_ID                      0x4a
+#define MMA8653_DEVICE_ID                      0x5a
 
 struct mma8452_data {
        struct i2c_client *client;
        struct mutex lock;
        u8 ctrl_reg1;
        u8 data_cfg;
+       const struct mma_chip_info *chip_info;
+};
+
+/**
+ * struct mma_chip_info - chip specific data for Freescale's accelerometers
+ * @chip_id:                   WHO_AM_I register's value
+ * @channels:                  struct iio_chan_spec matching the device's
+ *                             capabilities
+ * @num_channels:              number of channels
+ * @mma_scales:                        scale factors for converting register values
+ *                             to m/s^2; 3 modes: 2g, 4g, 8g; 2 integers
+ *                             per mode: m/s^2 and micro m/s^2
+ * @ev_cfg:                    event config register address
+ * @ev_cfg_ele:                        latch bit in event config register
+ * @ev_cfg_chan_shift:         number of the bit to enable events in X
+ *                             direction; in event config register
+ * @ev_src:                    event source register address
+ * @ev_src_xe:                 bit in event source register that indicates
+ *                             an event in X direction
+ * @ev_src_ye:                 bit in event source register that indicates
+ *                             an event in Y direction
+ * @ev_src_ze:                 bit in event source register that indicates
+ *                             an event in Z direction
+ * @ev_ths:                    event threshold register address
+ * @ev_ths_mask:               mask for the threshold value
+ * @ev_count:                  event count (period) register address
+ *
+ * Since not all chips supported by the driver support comparing high pass
+ * filtered data for events (interrupts), different interrupt sources are
+ * used for different chips and the relevant registers are included here.
+ */
+struct mma_chip_info {
+       u8 chip_id;
+       const struct iio_chan_spec *channels;
+       int num_channels;
+       const int mma_scales[3][2];
+       u8 ev_cfg;
+       u8 ev_cfg_ele;
+       u8 ev_cfg_chan_shift;
+       u8 ev_src;
+       u8 ev_src_xe;
+       u8 ev_src_ye;
+       u8 ev_src_ze;
+       u8 ev_ths;
+       u8 ev_ths_mask;
+       u8 ev_count;
 };
 
 static int mma8452_drdy(struct mma8452_data *data)
@@ -143,16 +210,6 @@ static const int mma8452_samp_freq[8][2] = {
        {6, 250000}, {1, 560000}
 };
 
-/*
- * Hardware has fullscale of -2G, -4G, -8G corresponding to raw value -2048
- * The userspace interface uses m/s^2 and we declare micro units
- * So scale factor is given by:
- *     g * N * 1000000 / 2048 for N = 2, 4, 8 and g = 9.80665
- */
-static const int mma8452_scales[3][2] = {
-       {0, 9577}, {0, 19154}, {0, 38307}
-};
-
 /* Datasheet table 35  (step time vs sample frequency) */
 static const int mma8452_transient_time_step_us[8] = {
        1250,
@@ -189,8 +246,11 @@ static ssize_t mma8452_show_scale_avail(struct device *dev,
                                        struct device_attribute *attr,
                                        char *buf)
 {
-       return mma8452_show_int_plus_micros(buf, mma8452_scales,
-                                           ARRAY_SIZE(mma8452_scales));
+       struct mma8452_data *data = iio_priv(i2c_get_clientdata(
+                                            to_i2c_client(dev)));
+
+       return mma8452_show_int_plus_micros(buf, data->chip_info->mma_scales,
+               ARRAY_SIZE(data->chip_info->mma_scales));
 }
 
 static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev,
@@ -221,9 +281,8 @@ static int mma8452_get_samp_freq_index(struct mma8452_data *data,
 
 static int mma8452_get_scale_index(struct mma8452_data *data, int val, int val2)
 {
-       return mma8452_get_int_plus_micros_index(mma8452_scales,
-                                                ARRAY_SIZE(mma8452_scales),
-                                                val, val2);
+       return mma8452_get_int_plus_micros_index(data->chip_info->mma_scales,
+                       ARRAY_SIZE(data->chip_info->mma_scales), val, val2);
 }
 
 static int mma8452_get_hp_filter_index(struct mma8452_data *data,
@@ -270,14 +329,15 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
                if (ret < 0)
                        return ret;
 
-               *val = sign_extend32(be16_to_cpu(buffer[chan->scan_index]) >> 4,
-                                    11);
+               *val = sign_extend32(be16_to_cpu(
+                       buffer[chan->scan_index]) >> chan->scan_type.shift,
+                       chan->scan_type.realbits - 1);
 
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_SCALE:
                i = data->data_cfg & MMA8452_DATA_CFG_FS_MASK;
-               *val = mma8452_scales[i][0];
-               *val2 = mma8452_scales[i][1];
+               *val = data->chip_info->mma_scales[i][0];
+               *val2 = data->chip_info->mma_scales[i][1];
 
                return IIO_VAL_INT_PLUS_MICRO;
        case IIO_CHAN_INFO_SAMP_FREQ:
@@ -439,17 +499,17 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
        switch (info) {
        case IIO_EV_INFO_VALUE:
                ret = i2c_smbus_read_byte_data(data->client,
-                                              MMA8452_TRANSIENT_THS);
+                                              data->chip_info->ev_ths);
                if (ret < 0)
                        return ret;
 
-               *val = ret & MMA8452_TRANSIENT_THS_MASK;
+               *val = ret & data->chip_info->ev_ths_mask;
 
                return IIO_VAL_INT;
 
        case IIO_EV_INFO_PERIOD:
                ret = i2c_smbus_read_byte_data(data->client,
-                                              MMA8452_TRANSIENT_COUNT);
+                                              data->chip_info->ev_count);
                if (ret < 0)
                        return ret;
 
@@ -497,7 +557,8 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
                if (val < 0 || val > MMA8452_TRANSIENT_THS_MASK)
                        return -EINVAL;
 
-               return mma8452_change_config(data, MMA8452_TRANSIENT_THS, val);
+               return mma8452_change_config(data, data->chip_info->ev_ths,
+                                            val);
 
        case IIO_EV_INFO_PERIOD:
                steps = (val * USEC_PER_SEC + val2) /
@@ -507,7 +568,7 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
                if (steps < 0 || steps > 0xff)
                        return -EINVAL;
 
-               return mma8452_change_config(data, MMA8452_TRANSIENT_COUNT,
+               return mma8452_change_config(data, data->chip_info->ev_count,
                                             steps);
 
        case IIO_EV_INFO_HIGH_PASS_FILTER_3DB:
@@ -538,13 +599,15 @@ static int mma8452_read_event_config(struct iio_dev *indio_dev,
                                     enum iio_event_direction dir)
 {
        struct mma8452_data *data = iio_priv(indio_dev);
+       const struct mma_chip_info *chip = data->chip_info;
        int ret;
 
-       ret = i2c_smbus_read_byte_data(data->client, MMA8452_TRANSIENT_CFG);
+       ret = i2c_smbus_read_byte_data(data->client,
+                                      data->chip_info->ev_cfg);
        if (ret < 0)
                return ret;
 
-       return ret & MMA8452_TRANSIENT_CFG_CHAN(chan->scan_index) ? 1 : 0;
+       return !!(ret & BIT(chan->scan_index + chip->ev_cfg_chan_shift));
 }
 
 static int mma8452_write_event_config(struct iio_dev *indio_dev,
@@ -554,20 +617,22 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev,
                                      int state)
 {
        struct mma8452_data *data = iio_priv(indio_dev);
+       const struct mma_chip_info *chip = data->chip_info;
        int val;
 
-       val = i2c_smbus_read_byte_data(data->client, MMA8452_TRANSIENT_CFG);
+       val = i2c_smbus_read_byte_data(data->client, chip->ev_cfg);
        if (val < 0)
                return val;
 
        if (state)
-               val |= MMA8452_TRANSIENT_CFG_CHAN(chan->scan_index);
+               val |= BIT(chan->scan_index + chip->ev_cfg_chan_shift);
        else
-               val &= ~MMA8452_TRANSIENT_CFG_CHAN(chan->scan_index);
+               val &= ~BIT(chan->scan_index + chip->ev_cfg_chan_shift);
 
-       val |= MMA8452_TRANSIENT_CFG_ELE;
+       val |= chip->ev_cfg_ele;
+       val |= MMA8452_FF_MT_CFG_OAE;
 
-       return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, val);
+       return mma8452_change_config(data, chip->ev_cfg, val);
 }
 
 static void mma8452_transient_interrupt(struct iio_dev *indio_dev)
@@ -576,25 +641,25 @@ static void mma8452_transient_interrupt(struct iio_dev *indio_dev)
        s64 ts = iio_get_time_ns();
        int src;
 
-       src = i2c_smbus_read_byte_data(data->client, MMA8452_TRANSIENT_SRC);
+       src = i2c_smbus_read_byte_data(data->client, data->chip_info->ev_src);
        if (src < 0)
                return;
 
-       if (src & MMA8452_TRANSIENT_SRC_XTRANSE)
+       if (src & data->chip_info->ev_src_xe)
                iio_push_event(indio_dev,
                               IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X,
                                                  IIO_EV_TYPE_MAG,
                                                  IIO_EV_DIR_RISING),
                               ts);
 
-       if (src & MMA8452_TRANSIENT_SRC_YTRANSE)
+       if (src & data->chip_info->ev_src_ye)
                iio_push_event(indio_dev,
                               IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_Y,
                                                  IIO_EV_TYPE_MAG,
                                                  IIO_EV_DIR_RISING),
                               ts);
 
-       if (src & MMA8452_TRANSIENT_SRC_ZTRANSE)
+       if (src & data->chip_info->ev_src_ze)
                iio_push_event(indio_dev,
                               IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_Z,
                                                  IIO_EV_TYPE_MAG,
@@ -606,6 +671,7 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)
 {
        struct iio_dev *indio_dev = p;
        struct mma8452_data *data = iio_priv(indio_dev);
+       const struct mma_chip_info *chip = data->chip_info;
        int ret = IRQ_NONE;
        int src;
 
@@ -618,7 +684,10 @@ static irqreturn_t mma8452_interrupt(int irq, void *p)
                ret = IRQ_HANDLED;
        }
 
-       if (src & MMA8452_INT_TRANS) {
+       if ((src & MMA8452_INT_TRANS &&
+            chip->ev_src == MMA8452_TRANSIENT_SRC) ||
+           (src & MMA8452_INT_FF_MT &&
+            chip->ev_src == MMA8452_FF_MT_SRC)) {
                mma8452_transient_interrupt(indio_dev);
                ret = IRQ_HANDLED;
        }
@@ -680,6 +749,16 @@ static const struct iio_event_spec mma8452_transient_event[] = {
        },
 };
 
+static const struct iio_event_spec mma8452_motion_event[] = {
+       {
+               .type = IIO_EV_TYPE_MAG,
+               .dir = IIO_EV_DIR_RISING,
+               .mask_separate = BIT(IIO_EV_INFO_ENABLE),
+               .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
+                                       BIT(IIO_EV_INFO_PERIOD)
+       },
+};
+
 /*
  * Threshold is configured in fixed 8G/127 steps regardless of
  * currently selected scale for measurement.
@@ -693,10 +772,9 @@ static struct attribute *mma8452_event_attributes[] = {
 
 static struct attribute_group mma8452_event_attribute_group = {
        .attrs = mma8452_event_attributes,
-       .name = "events",
 };
 
-#define MMA8452_CHANNEL(axis, idx) { \
+#define MMA8452_CHANNEL(axis, idx, bits) { \
        .type = IIO_ACCEL, \
        .modified = 1, \
        .channel2 = IIO_MOD_##axis, \
@@ -708,22 +786,144 @@ static struct attribute_group mma8452_event_attribute_group = {
        .scan_index = idx, \
        .scan_type = { \
                .sign = 's', \
-               .realbits = 12, \
+               .realbits = (bits), \
                .storagebits = 16, \
-               .shift = 4, \
+               .shift = 16 - (bits), \
                .endianness = IIO_BE, \
        }, \
        .event_spec = mma8452_transient_event, \
        .num_event_specs = ARRAY_SIZE(mma8452_transient_event), \
 }
 
+#define MMA8652_CHANNEL(axis, idx, bits) { \
+       .type = IIO_ACCEL, \
+       .modified = 1, \
+       .channel2 = IIO_MOD_##axis, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+               BIT(IIO_CHAN_INFO_CALIBBIAS), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
+               BIT(IIO_CHAN_INFO_SCALE), \
+       .scan_index = idx, \
+       .scan_type = { \
+               .sign = 's', \
+               .realbits = (bits), \
+               .storagebits = 16, \
+               .shift = 16 - (bits), \
+               .endianness = IIO_BE, \
+       }, \
+       .event_spec = mma8452_motion_event, \
+       .num_event_specs = ARRAY_SIZE(mma8452_motion_event), \
+}
+
 static const struct iio_chan_spec mma8452_channels[] = {
-       MMA8452_CHANNEL(X, 0),
-       MMA8452_CHANNEL(Y, 1),
-       MMA8452_CHANNEL(Z, 2),
+       MMA8452_CHANNEL(X, 0, 12),
+       MMA8452_CHANNEL(Y, 1, 12),
+       MMA8452_CHANNEL(Z, 2, 12),
        IIO_CHAN_SOFT_TIMESTAMP(3),
 };
 
+static const struct iio_chan_spec mma8453_channels[] = {
+       MMA8452_CHANNEL(X, 0, 10),
+       MMA8452_CHANNEL(Y, 1, 10),
+       MMA8452_CHANNEL(Z, 2, 10),
+       IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static const struct iio_chan_spec mma8652_channels[] = {
+       MMA8652_CHANNEL(X, 0, 12),
+       MMA8652_CHANNEL(Y, 1, 12),
+       MMA8652_CHANNEL(Z, 2, 12),
+       IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static const struct iio_chan_spec mma8653_channels[] = {
+       MMA8652_CHANNEL(X, 0, 10),
+       MMA8652_CHANNEL(Y, 1, 10),
+       MMA8652_CHANNEL(Z, 2, 10),
+       IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+enum {
+       mma8452,
+       mma8453,
+       mma8652,
+       mma8653,
+};
+
+static const struct mma_chip_info mma_chip_info_table[] = {
+       [mma8452] = {
+               .chip_id = MMA8452_DEVICE_ID,
+               .channels = mma8452_channels,
+               .num_channels = ARRAY_SIZE(mma8452_channels),
+               /*
+                * Hardware has fullscale of -2G, -4G, -8G corresponding to
+                * raw value -2048 for 12 bit or -512 for 10 bit.
+                * The userspace interface uses m/s^2 and we declare micro units
+                * So scale factor for 12 bit here is given by:
+                *      g * N * 1000000 / 2048 for N = 2, 4, 8 and g=9.80665
+                */
+               .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} },
+               .ev_cfg = MMA8452_TRANSIENT_CFG,
+               .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE,
+               .ev_cfg_chan_shift = 1,
+               .ev_src = MMA8452_TRANSIENT_SRC,
+               .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE,
+               .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE,
+               .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE,
+               .ev_ths = MMA8452_TRANSIENT_THS,
+               .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK,
+               .ev_count = MMA8452_TRANSIENT_COUNT,
+       },
+       [mma8453] = {
+               .chip_id = MMA8453_DEVICE_ID,
+               .channels = mma8453_channels,
+               .num_channels = ARRAY_SIZE(mma8453_channels),
+               .mma_scales = { {0, 38307}, {0, 76614}, {0, 153228} },
+               .ev_cfg = MMA8452_TRANSIENT_CFG,
+               .ev_cfg_ele = MMA8452_TRANSIENT_CFG_ELE,
+               .ev_cfg_chan_shift = 1,
+               .ev_src = MMA8452_TRANSIENT_SRC,
+               .ev_src_xe = MMA8452_TRANSIENT_SRC_XTRANSE,
+               .ev_src_ye = MMA8452_TRANSIENT_SRC_YTRANSE,
+               .ev_src_ze = MMA8452_TRANSIENT_SRC_ZTRANSE,
+               .ev_ths = MMA8452_TRANSIENT_THS,
+               .ev_ths_mask = MMA8452_TRANSIENT_THS_MASK,
+               .ev_count = MMA8452_TRANSIENT_COUNT,
+       },
+       [mma8652] = {
+               .chip_id = MMA8652_DEVICE_ID,
+               .channels = mma8652_channels,
+               .num_channels = ARRAY_SIZE(mma8652_channels),
+               .mma_scales = { {0, 9577}, {0, 19154}, {0, 38307} },
+               .ev_cfg = MMA8452_FF_MT_CFG,
+               .ev_cfg_ele = MMA8452_FF_MT_CFG_ELE,
+               .ev_cfg_chan_shift = 3,
+               .ev_src = MMA8452_FF_MT_SRC,
+               .ev_src_xe = MMA8452_FF_MT_SRC_XHE,
+               .ev_src_ye = MMA8452_FF_MT_SRC_YHE,
+               .ev_src_ze = MMA8452_FF_MT_SRC_ZHE,
+               .ev_ths = MMA8452_FF_MT_THS,
+               .ev_ths_mask = MMA8452_FF_MT_THS_MASK,
+               .ev_count = MMA8452_FF_MT_COUNT,
+       },
+       [mma8653] = {
+               .chip_id = MMA8653_DEVICE_ID,
+               .channels = mma8653_channels,
+               .num_channels = ARRAY_SIZE(mma8653_channels),
+               .mma_scales = { {0, 38307}, {0, 76614}, {0, 153228} },
+               .ev_cfg = MMA8452_FF_MT_CFG,
+               .ev_cfg_ele = MMA8452_FF_MT_CFG_ELE,
+               .ev_cfg_chan_shift = 3,
+               .ev_src = MMA8452_FF_MT_SRC,
+               .ev_src_xe = MMA8452_FF_MT_SRC_XHE,
+               .ev_src_ye = MMA8452_FF_MT_SRC_YHE,
+               .ev_src_ze = MMA8452_FF_MT_SRC_ZHE,
+               .ev_ths = MMA8452_FF_MT_THS,
+               .ev_ths_mask = MMA8452_FF_MT_THS_MASK,
+               .ev_count = MMA8452_FF_MT_COUNT,
+       },
+};
+
 static struct attribute *mma8452_attributes[] = {
        &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
        &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
@@ -841,18 +1041,28 @@ static int mma8452_reset(struct i2c_client *client)
        return -ETIMEDOUT;
 }
 
+static const struct of_device_id mma8452_dt_ids[] = {
+       { .compatible = "fsl,mma8452", .data = &mma_chip_info_table[mma8452] },
+       { .compatible = "fsl,mma8453", .data = &mma_chip_info_table[mma8453] },
+       { .compatible = "fsl,mma8652", .data = &mma_chip_info_table[mma8652] },
+       { .compatible = "fsl,mma8653", .data = &mma_chip_info_table[mma8653] },
+       { }
+};
+MODULE_DEVICE_TABLE(of, mma8452_dt_ids);
+
 static int mma8452_probe(struct i2c_client *client,
                         const struct i2c_device_id *id)
 {
        struct mma8452_data *data;
        struct iio_dev *indio_dev;
        int ret;
+       const struct of_device_id *match;
 
-       ret = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I);
-       if (ret < 0)
-               return ret;
-       if (ret != MMA8452_DEVICE_ID)
+       match = of_match_device(mma8452_dt_ids, &client->dev);
+       if (!match) {
+               dev_err(&client->dev, "unknown device model\n");
                return -ENODEV;
+       }
 
        indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
        if (!indio_dev)
@@ -861,14 +1071,33 @@ static int mma8452_probe(struct i2c_client *client,
        data = iio_priv(indio_dev);
        data->client = client;
        mutex_init(&data->lock);
+       data->chip_info = match->data;
+
+       ret = i2c_smbus_read_byte_data(client, MMA8452_WHO_AM_I);
+       if (ret < 0)
+               return ret;
+
+       switch (ret) {
+       case MMA8452_DEVICE_ID:
+       case MMA8453_DEVICE_ID:
+       case MMA8652_DEVICE_ID:
+       case MMA8653_DEVICE_ID:
+               if (ret == data->chip_info->chip_id)
+                       break;
+       default:
+               return -ENODEV;
+       }
+
+       dev_info(&client->dev, "registering %s accelerometer; ID 0x%x\n",
+                match->compatible, data->chip_info->chip_id);
 
        i2c_set_clientdata(client, indio_dev);
        indio_dev->info = &mma8452_info;
        indio_dev->name = id->name;
        indio_dev->dev.parent = &client->dev;
        indio_dev->modes = INDIO_DIRECT_MODE;
-       indio_dev->channels = mma8452_channels;
-       indio_dev->num_channels = ARRAY_SIZE(mma8452_channels);
+       indio_dev->channels = data->chip_info->channels;
+       indio_dev->num_channels = data->chip_info->num_channels;
        indio_dev->available_scan_masks = mma8452_scan_masks;
 
        ret = mma8452_reset(client);
@@ -892,13 +1121,15 @@ static int mma8452_probe(struct i2c_client *client,
 
        if (client->irq) {
                /*
-                * Although we enable the transient interrupt source once and
-                * for all here the transient event detection itself is not
-                * enabled until userspace asks for it by
-                * mma8452_write_event_config()
+                * Although we enable the interrupt sources once and for
+                * all here the event detection itself is not enabled until
+                * userspace asks for it by mma8452_write_event_config()
                 */
-               int supported_interrupts = MMA8452_INT_DRDY | MMA8452_INT_TRANS;
-               int enabled_interrupts = MMA8452_INT_TRANS;
+               int supported_interrupts = MMA8452_INT_DRDY |
+                                          MMA8452_INT_TRANS |
+                                          MMA8452_INT_FF_MT;
+               int enabled_interrupts = MMA8452_INT_TRANS |
+                                        MMA8452_INT_FF_MT;
 
                /* Assume wired to INT1 pin */
                ret = i2c_smbus_write_byte_data(client,
@@ -987,17 +1218,14 @@ static SIMPLE_DEV_PM_OPS(mma8452_pm_ops, mma8452_suspend, mma8452_resume);
 #endif
 
 static const struct i2c_device_id mma8452_id[] = {
-       { "mma8452", 0 },
+       { "mma8452", mma8452 },
+       { "mma8453", mma8453 },
+       { "mma8652", mma8652 },
+       { "mma8653", mma8653 },
        { }
 };
 MODULE_DEVICE_TABLE(i2c, mma8452_id);
 
-static const struct of_device_id mma8452_dt_ids[] = {
-       { .compatible = "fsl,mma8452" },
-       { }
-};
-MODULE_DEVICE_TABLE(of, mma8452_dt_ids);
-
 static struct i2c_driver mma8452_driver = {
        .driver = {
                .name   = "mma8452",
index 771858cb67a1b57db5472576ecb0656b7d282884..9408ef3add58fbe9cfbcbece029dd8c828c49329 100644 (file)
@@ -26,7 +26,6 @@
 
 #define MMA9553_DRV_NAME                       "mma9553"
 #define MMA9553_IRQ_NAME                       "mma9553_event"
-#define MMA9553_GPIO_NAME                      "mma9553_int"
 
 /* Pedometer configuration registers (R/W) */
 #define MMA9553_REG_CONF_SLEEPMIN              0x00
@@ -1073,31 +1072,6 @@ static irqreturn_t mma9553_event_handler(int irq, void *private)
        return IRQ_HANDLED;
 }
 
-static int mma9553_gpio_probe(struct i2c_client *client)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       dev = &client->dev;
-
-       /* data ready GPIO interrupt pin */
-       gpio = devm_gpiod_get_index(dev, MMA9553_GPIO_NAME, 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "ACPI GPIO get index failed\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-
-       return ret;
-}
-
 static const char *mma9553_match_acpi_device(struct device *dev)
 {
        const struct acpi_device_id *id;
@@ -1146,9 +1120,6 @@ static int mma9553_probe(struct i2c_client *client,
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->info = &mma9553_info;
 
-       if (client->irq < 0)
-               client->irq = mma9553_gpio_probe(client);
-
        if (client->irq > 0) {
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                                                mma9553_irq_handler,
diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
new file mode 100644 (file)
index 0000000..e72e218
--- /dev/null
@@ -0,0 +1,567 @@
+/*
+ * 3-axis accelerometer driver for MXC4005XC Memsic sensor
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/acpi.h>
+#include <linux/gpio/consumer.h>
+#include <linux/regmap.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
+
+#define MXC4005_DRV_NAME               "mxc4005"
+#define MXC4005_IRQ_NAME               "mxc4005_event"
+#define MXC4005_REGMAP_NAME            "mxc4005_regmap"
+
+#define MXC4005_REG_XOUT_UPPER         0x03
+#define MXC4005_REG_XOUT_LOWER         0x04
+#define MXC4005_REG_YOUT_UPPER         0x05
+#define MXC4005_REG_YOUT_LOWER         0x06
+#define MXC4005_REG_ZOUT_UPPER         0x07
+#define MXC4005_REG_ZOUT_LOWER         0x08
+
+#define MXC4005_REG_INT_MASK1          0x0B
+#define MXC4005_REG_INT_MASK1_BIT_DRDYE        0x01
+
+#define MXC4005_REG_INT_CLR1           0x01
+#define MXC4005_REG_INT_CLR1_BIT_DRDYC 0x01
+
+#define MXC4005_REG_CONTROL            0x0D
+#define MXC4005_REG_CONTROL_MASK_FSR   GENMASK(6, 5)
+#define MXC4005_CONTROL_FSR_SHIFT      5
+
+#define MXC4005_REG_DEVICE_ID          0x0E
+
+enum mxc4005_axis {
+       AXIS_X,
+       AXIS_Y,
+       AXIS_Z,
+};
+
+enum mxc4005_range {
+       MXC4005_RANGE_2G,
+       MXC4005_RANGE_4G,
+       MXC4005_RANGE_8G,
+};
+
+struct mxc4005_data {
+       struct device *dev;
+       struct mutex mutex;
+       struct regmap *regmap;
+       struct iio_trigger *dready_trig;
+       __be16 buffer[8];
+       bool trigger_enabled;
+};
+
+/*
+ * MXC4005 can operate in the following ranges:
+ * +/- 2G, 4G, 8G (the default +/-2G)
+ *
+ * (2 + 2) * 9.81 / (2^12 - 1) = 0.009582
+ * (4 + 4) * 9.81 / (2^12 - 1) = 0.019164
+ * (8 + 8) * 9.81 / (2^12 - 1) = 0.038329
+ */
+static const struct {
+       u8 range;
+       int scale;
+} mxc4005_scale_table[] = {
+       {MXC4005_RANGE_2G, 9582},
+       {MXC4005_RANGE_4G, 19164},
+       {MXC4005_RANGE_8G, 38329},
+};
+
+
+static IIO_CONST_ATTR(in_accel_scale_available, "0.009582 0.019164 0.038329");
+
+static struct attribute *mxc4005_attributes[] = {
+       &iio_const_attr_in_accel_scale_available.dev_attr.attr,
+       NULL,
+};
+
+static const struct attribute_group mxc4005_attrs_group = {
+       .attrs = mxc4005_attributes,
+};
+
+static bool mxc4005_is_readable_reg(struct device *dev, unsigned int reg)
+{
+       switch (reg) {
+       case MXC4005_REG_XOUT_UPPER:
+       case MXC4005_REG_XOUT_LOWER:
+       case MXC4005_REG_YOUT_UPPER:
+       case MXC4005_REG_YOUT_LOWER:
+       case MXC4005_REG_ZOUT_UPPER:
+       case MXC4005_REG_ZOUT_LOWER:
+       case MXC4005_REG_DEVICE_ID:
+       case MXC4005_REG_CONTROL:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static bool mxc4005_is_writeable_reg(struct device *dev, unsigned int reg)
+{
+       switch (reg) {
+       case MXC4005_REG_INT_CLR1:
+       case MXC4005_REG_INT_MASK1:
+       case MXC4005_REG_CONTROL:
+               return true;
+       default:
+               return false;
+       }
+}
+
+static const struct regmap_config mxc4005_regmap_config = {
+       .name = MXC4005_REGMAP_NAME,
+
+       .reg_bits = 8,
+       .val_bits = 8,
+
+       .max_register = MXC4005_REG_DEVICE_ID,
+
+       .readable_reg = mxc4005_is_readable_reg,
+       .writeable_reg = mxc4005_is_writeable_reg,
+};
+
+static int mxc4005_read_xyz(struct mxc4005_data *data)
+{
+       int ret;
+
+       ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER,
+                              (u8 *) data->buffer, sizeof(data->buffer));
+       if (ret < 0) {
+               dev_err(data->dev, "failed to read axes\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int mxc4005_read_axis(struct mxc4005_data *data,
+                            unsigned int addr)
+{
+       __be16 reg;
+       int ret;
+
+       ret = regmap_bulk_read(data->regmap, addr, (u8 *) &reg, sizeof(reg));
+       if (ret < 0) {
+               dev_err(data->dev, "failed to read reg %02x\n", addr);
+               return ret;
+       }
+
+       return be16_to_cpu(reg);
+}
+
+static int mxc4005_read_scale(struct mxc4005_data *data)
+{
+       unsigned int reg;
+       int ret;
+       int i;
+
+       ret = regmap_read(data->regmap, MXC4005_REG_CONTROL, &reg);
+       if (ret < 0) {
+               dev_err(data->dev, "failed to read reg_control\n");
+               return ret;
+       }
+
+       i = reg >> MXC4005_CONTROL_FSR_SHIFT;
+
+       if (i < 0 || i >= ARRAY_SIZE(mxc4005_scale_table))
+               return -EINVAL;
+
+       return mxc4005_scale_table[i].scale;
+}
+
+static int mxc4005_set_scale(struct mxc4005_data *data, int val)
+{
+       unsigned int reg;
+       int i;
+       int ret;
+
+       for (i = 0; i < ARRAY_SIZE(mxc4005_scale_table); i++) {
+               if (mxc4005_scale_table[i].scale == val) {
+                       reg = i << MXC4005_CONTROL_FSR_SHIFT;
+                       ret = regmap_update_bits(data->regmap,
+                                                MXC4005_REG_CONTROL,
+                                                MXC4005_REG_CONTROL_MASK_FSR,
+                                                reg);
+                       if (ret < 0)
+                               dev_err(data->dev,
+                                       "failed to write reg_control\n");
+                       return ret;
+               }
+       }
+
+       return -EINVAL;
+}
+
+static int mxc4005_read_raw(struct iio_dev *indio_dev,
+                           struct iio_chan_spec const *chan,
+                           int *val, int *val2, long mask)
+{
+       struct mxc4005_data *data = iio_priv(indio_dev);
+       int ret;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               switch (chan->type) {
+               case IIO_ACCEL:
+                       if (iio_buffer_enabled(indio_dev))
+                               return -EBUSY;
+
+                       ret = mxc4005_read_axis(data, chan->address);
+                       if (ret < 0)
+                               return ret;
+                       *val = sign_extend32(ret >> chan->scan_type.shift,
+                                            chan->scan_type.realbits - 1);
+                       return IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+       case IIO_CHAN_INFO_SCALE:
+               ret = mxc4005_read_scale(data);
+               if (ret < 0)
+                       return ret;
+
+               *val = 0;
+               *val2 = ret;
+               return IIO_VAL_INT_PLUS_MICRO;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int mxc4005_write_raw(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan,
+                            int val, int val2, long mask)
+{
+       struct mxc4005_data *data = iio_priv(indio_dev);
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SCALE:
+               if (val != 0)
+                       return -EINVAL;
+
+               return mxc4005_set_scale(data, val2);
+       default:
+               return -EINVAL;
+       }
+}
+
+static const struct iio_info mxc4005_info = {
+       .driver_module  = THIS_MODULE,
+       .read_raw       = mxc4005_read_raw,
+       .write_raw      = mxc4005_write_raw,
+       .attrs          = &mxc4005_attrs_group,
+};
+
+static const unsigned long mxc4005_scan_masks[] = {
+       BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
+       0
+};
+
+#define MXC4005_CHANNEL(_axis, _addr) {                                \
+       .type = IIO_ACCEL,                                      \
+       .modified = 1,                                          \
+       .channel2 = IIO_MOD_##_axis,                            \
+       .address = _addr,                                       \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
+       .scan_index = AXIS_##_axis,                             \
+       .scan_type = {                                          \
+               .sign = 's',                                    \
+               .realbits = 12,                                 \
+               .storagebits = 16,                              \
+               .shift = 4,                                     \
+               .endianness = IIO_BE,                           \
+       },                                                      \
+}
+
+static const struct iio_chan_spec mxc4005_channels[] = {
+       MXC4005_CHANNEL(X, MXC4005_REG_XOUT_UPPER),
+       MXC4005_CHANNEL(Y, MXC4005_REG_YOUT_UPPER),
+       MXC4005_CHANNEL(Z, MXC4005_REG_ZOUT_UPPER),
+       IIO_CHAN_SOFT_TIMESTAMP(3),
+};
+
+static irqreturn_t mxc4005_trigger_handler(int irq, void *private)
+{
+       struct iio_poll_func *pf = private;
+       struct iio_dev *indio_dev = pf->indio_dev;
+       struct mxc4005_data *data = iio_priv(indio_dev);
+       int ret;
+
+       ret = mxc4005_read_xyz(data);
+       if (ret < 0)
+               goto err;
+
+       iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
+                                          pf->timestamp);
+
+err:
+       iio_trigger_notify_done(indio_dev->trig);
+
+       return IRQ_HANDLED;
+}
+
+static int mxc4005_clr_intr(struct mxc4005_data *data)
+{
+       int ret;
+
+       /* clear interrupt */
+       ret = regmap_write(data->regmap, MXC4005_REG_INT_CLR1,
+                          MXC4005_REG_INT_CLR1_BIT_DRDYC);
+       if (ret < 0) {
+               dev_err(data->dev, "failed to write to reg_int_clr1\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int mxc4005_set_trigger_state(struct iio_trigger *trig,
+                                    bool state)
+{
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
+       struct mxc4005_data *data = iio_priv(indio_dev);
+       int ret;
+
+       mutex_lock(&data->mutex);
+       if (state) {
+               ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1,
+                                  MXC4005_REG_INT_MASK1_BIT_DRDYE);
+       } else {
+               ret = regmap_write(data->regmap, MXC4005_REG_INT_MASK1,
+                                  ~MXC4005_REG_INT_MASK1_BIT_DRDYE);
+       }
+
+       if (ret < 0) {
+               mutex_unlock(&data->mutex);
+               dev_err(data->dev, "failed to update reg_int_mask1");
+               return ret;
+       }
+
+       data->trigger_enabled = state;
+       mutex_unlock(&data->mutex);
+
+       return 0;
+}
+
+static int mxc4005_trigger_try_reen(struct iio_trigger *trig)
+{
+       struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
+       struct mxc4005_data *data = iio_priv(indio_dev);
+
+       if (!data->dready_trig)
+               return 0;
+
+       return mxc4005_clr_intr(data);
+}
+
+static const struct iio_trigger_ops mxc4005_trigger_ops = {
+       .set_trigger_state = mxc4005_set_trigger_state,
+       .try_reenable = mxc4005_trigger_try_reen,
+       .owner = THIS_MODULE,
+};
+
+static int mxc4005_gpio_probe(struct i2c_client *client,
+                             struct mxc4005_data *data)
+{
+       struct device *dev;
+       struct gpio_desc *gpio;
+       int ret;
+
+       if (!client)
+               return -EINVAL;
+
+       dev = &client->dev;
+
+       gpio = devm_gpiod_get_index(dev, "mxc4005_int", 0, GPIOD_IN);
+       if (IS_ERR(gpio)) {
+               dev_err(dev, "failed to get acpi gpio index\n");
+               return PTR_ERR(gpio);
+       }
+
+       ret = gpiod_to_irq(gpio);
+
+       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
+
+       return ret;
+}
+
+static int mxc4005_chip_init(struct mxc4005_data *data)
+{
+       int ret;
+       unsigned int reg;
+
+       ret = regmap_read(data->regmap, MXC4005_REG_DEVICE_ID, &reg);
+       if (ret < 0) {
+               dev_err(data->dev, "failed to read chip id\n");
+               return ret;
+       }
+
+       dev_dbg(data->dev, "MXC4005 chip id %02x\n", reg);
+
+       return 0;
+}
+
+static int mxc4005_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct mxc4005_data *data;
+       struct iio_dev *indio_dev;
+       struct regmap *regmap;
+       int ret;
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       regmap = devm_regmap_init_i2c(client, &mxc4005_regmap_config);
+       if (IS_ERR(regmap)) {
+               dev_err(&client->dev, "failed to initialize regmap\n");
+               return PTR_ERR(regmap);
+       }
+
+       data = iio_priv(indio_dev);
+       i2c_set_clientdata(client, indio_dev);
+       data->dev = &client->dev;
+       data->regmap = regmap;
+
+       ret = mxc4005_chip_init(data);
+       if (ret < 0) {
+               dev_err(&client->dev, "failed to initialize chip\n");
+               return ret;
+       }
+
+       mutex_init(&data->mutex);
+
+       indio_dev->dev.parent = &client->dev;
+       indio_dev->channels = mxc4005_channels;
+       indio_dev->num_channels = ARRAY_SIZE(mxc4005_channels);
+       indio_dev->available_scan_masks = mxc4005_scan_masks;
+       indio_dev->name = MXC4005_DRV_NAME;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->info = &mxc4005_info;
+
+       ret = iio_triggered_buffer_setup(indio_dev,
+                                        iio_pollfunc_store_time,
+                                        mxc4005_trigger_handler,
+                                        NULL);
+       if (ret < 0) {
+               dev_err(&client->dev,
+                       "failed to setup iio triggered buffer\n");
+               return ret;
+       }
+
+       if (client->irq < 0)
+               client->irq = mxc4005_gpio_probe(client, data);
+
+       if (client->irq > 0) {
+               data->dready_trig = devm_iio_trigger_alloc(&client->dev,
+                                                          "%s-dev%d",
+                                                          indio_dev->name,
+                                                          indio_dev->id);
+               if (!data->dready_trig)
+                       return -ENOMEM;
+
+               ret = devm_request_threaded_irq(&client->dev, client->irq,
+                                               iio_trigger_generic_data_rdy_poll,
+                                               NULL,
+                                               IRQF_TRIGGER_FALLING |
+                                               IRQF_ONESHOT,
+                                               MXC4005_IRQ_NAME,
+                                               data->dready_trig);
+               if (ret) {
+                       dev_err(&client->dev,
+                               "failed to init threaded irq\n");
+                       goto err_buffer_cleanup;
+               }
+
+               data->dready_trig->dev.parent = &client->dev;
+               data->dready_trig->ops = &mxc4005_trigger_ops;
+               iio_trigger_set_drvdata(data->dready_trig, indio_dev);
+               indio_dev->trig = data->dready_trig;
+               iio_trigger_get(indio_dev->trig);
+               ret = iio_trigger_register(data->dready_trig);
+               if (ret) {
+                       dev_err(&client->dev,
+                               "failed to register trigger\n");
+                       goto err_trigger_unregister;
+               }
+       }
+
+       ret = iio_device_register(indio_dev);
+       if (ret < 0) {
+               dev_err(&client->dev,
+                       "unable to register iio device %d\n", ret);
+               goto err_buffer_cleanup;
+       }
+
+       return 0;
+
+err_trigger_unregister:
+       iio_trigger_unregister(data->dready_trig);
+err_buffer_cleanup:
+       iio_triggered_buffer_cleanup(indio_dev);
+
+       return ret;
+}
+
+static int mxc4005_remove(struct i2c_client *client)
+{
+       struct iio_dev *indio_dev = i2c_get_clientdata(client);
+       struct mxc4005_data *data = iio_priv(indio_dev);
+
+       iio_device_unregister(indio_dev);
+
+       iio_triggered_buffer_cleanup(indio_dev);
+       if (data->dready_trig)
+               iio_trigger_unregister(data->dready_trig);
+
+       return 0;
+}
+
+static const struct acpi_device_id mxc4005_acpi_match[] = {
+       {"MXC4005",     0},
+       { },
+};
+MODULE_DEVICE_TABLE(acpi, mxc4005_acpi_match);
+
+static const struct i2c_device_id mxc4005_id[] = {
+       {"mxc4005",     0},
+       { },
+};
+MODULE_DEVICE_TABLE(i2c, mxc4005_id);
+
+static struct i2c_driver mxc4005_driver = {
+       .driver = {
+               .name = MXC4005_DRV_NAME,
+               .acpi_match_table = ACPI_PTR(mxc4005_acpi_match),
+       },
+       .probe          = mxc4005_probe,
+       .remove         = mxc4005_remove,
+       .id_table       = mxc4005_id,
+};
+
+module_i2c_driver(mxc4005_driver);
+
+MODULE_AUTHOR("Teodora Baluta <teodora.baluta@intel.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("MXC4005 3-axis accelerometer driver");
index fb93111104249bcc93d390e7492c96f4c211ac27..197a08b4e2f3634ad48af3f246fb855d04f8b12d 100644 (file)
@@ -612,6 +612,7 @@ static const struct iio_info accel_info = {
        .attrs = &st_accel_attribute_group,
        .read_raw = &st_accel_read_raw,
        .write_raw = &st_accel_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index c764af284c947ed103c08ce0e3ecf365e6f80077..85fe7f7247c1d57f01cb37c225467e14a6f75a1e 100644 (file)
@@ -50,7 +50,6 @@
 #define STK8312_ALL_CHANNEL_SIZE       3
 
 #define STK8312_DRIVER_NAME            "stk8312"
-#define STK8312_GPIO                   "stk8312_gpio"
 #define STK8312_IRQ_NAME               "stk8312_event"
 
 /*
@@ -504,30 +503,6 @@ static const struct iio_buffer_setup_ops stk8312_buffer_setup_ops = {
        .postdisable = stk8312_buffer_postdisable,
 };
 
-static int stk8312_gpio_probe(struct i2c_client *client)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       dev = &client->dev;
-
-       /* data ready gpio interrupt pin */
-       gpio = devm_gpiod_get_index(dev, STK8312_GPIO, 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "acpi gpio get index failed\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-
-       return ret;
-}
-
 static int stk8312_probe(struct i2c_client *client,
                         const struct i2c_device_id *id)
 {
@@ -569,10 +544,7 @@ static int stk8312_probe(struct i2c_client *client,
        if (ret < 0)
                return ret;
 
-       if (client->irq < 0)
-               client->irq = stk8312_gpio_probe(client);
-
-       if (client->irq >= 0) {
+       if (client->irq > 0) {
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                                                stk8312_data_rdy_trig_poll,
                                                NULL,
index 80f77d8704b5bf29fdc857a8b5f548a9a24a9f47..5709d9eb8f34ddcecf26f477db6aa09fd424c25f 100644 (file)
@@ -45,7 +45,6 @@
 #define STK8BA50_ALL_CHANNEL_SIZE              6
 
 #define STK8BA50_DRIVER_NAME                   "stk8ba50"
-#define STK8BA50_GPIO                          "stk8ba50_gpio"
 #define STK8BA50_IRQ_NAME                      "stk8ba50_event"
 
 #define STK8BA50_SCALE_AVAIL                   "0.0384 0.0767 0.1534 0.3069"
@@ -388,30 +387,6 @@ static const struct iio_buffer_setup_ops stk8ba50_buffer_setup_ops = {
        .postdisable = stk8ba50_buffer_postdisable,
 };
 
-static int stk8ba50_gpio_probe(struct i2c_client *client)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       dev = &client->dev;
-
-       /* data ready gpio interrupt pin */
-       gpio = devm_gpiod_get_index(dev, STK8BA50_GPIO, 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "acpi gpio get index failed\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-
-       return ret;
-}
-
 static int stk8ba50_probe(struct i2c_client *client,
                          const struct i2c_device_id *id)
 {
@@ -465,10 +440,7 @@ static int stk8ba50_probe(struct i2c_client *client,
                goto err_power_off;
        }
 
-       if (client->irq < 0)
-               client->irq = stk8ba50_gpio_probe(client);
-
-       if (client->irq >= 0) {
+       if (client->irq > 0) {
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                                                stk8ba50_data_rdy_trig_poll,
                                                NULL,
index 50c103d75af90cc86e62d4f77d012954659d2c8e..7868c744fd4bd25cc869f3a8c3d44ab348afbba2 100644 (file)
@@ -149,6 +149,17 @@ config BERLIN2_ADC
          Marvell Berlin2 ADC driver. This ADC has 8 channels, with one used for
          temperature measurement.
 
+config CC10001_ADC
+       tristate "Cosmic Circuits 10001 ADC driver"
+       depends on HAS_IOMEM && HAVE_CLK && REGULATOR
+       select IIO_BUFFER
+       select IIO_TRIGGERED_BUFFER
+       help
+         Say yes here to build support for Cosmic Circuits 10001 ADC.
+
+         This driver can also be built as a module. If so, the module will be
+         called cc10001_adc.
+
 config DA9150_GPADC
        tristate "Dialog DA9150 GPADC driver support"
        depends on MFD_DA9150
@@ -161,17 +172,6 @@ config DA9150_GPADC
          To compile this driver as a module, choose M here: the module will be
          called berlin2-adc.
 
-config CC10001_ADC
-       tristate "Cosmic Circuits 10001 ADC driver"
-       depends on HAS_IOMEM && HAVE_CLK && REGULATOR
-       select IIO_BUFFER
-       select IIO_TRIGGERED_BUFFER
-       help
-         Say yes here to build support for Cosmic Circuits 10001 ADC.
-
-         This driver can also be built as a module. If so, the module will be
-         called cc10001_adc.
-
 config EXYNOS_ADC
        tristate "Exynos ADC driver support"
        depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST)
@@ -183,6 +183,17 @@ config EXYNOS_ADC
          To compile this driver as a module, choose M here: the module will be
          called exynos_adc.
 
+config HI8435
+       tristate "Holt Integrated Circuits HI-8435 threshold detector"
+       select IIO_TRIGGERED_EVENT
+       depends on SPI
+       help
+         If you say yes here you get support for Holt Integrated Circuits
+         HI-8435 chip.
+
+         This driver can also be built as a module. If so, the module will be
+         called hi8435.
+
 config LP8788_ADC
        tristate "LP8788 ADC driver"
        depends on MFD_LP8788
@@ -361,6 +372,8 @@ config TWL6030_GPADC
 config VF610_ADC
        tristate "Freescale vf610 ADC driver"
        depends on OF
+       select IIO_BUFFER
+       select IIO_TRIGGERED_BUFFER
        help
          Say yes here to support for Vybrid board analog-to-digital converter.
          Since the IP is used for i.MX6SLX, the driver also support i.MX6SLX.
index a0962103e8666cba5e4c844a0e36101f3677dc0e..99b37a963a1ef6ce2ee9b1ca981696ad97c76ecd 100644 (file)
@@ -16,9 +16,10 @@ obj-$(CONFIG_AD799X) += ad799x.o
 obj-$(CONFIG_AT91_ADC) += at91_adc.o
 obj-$(CONFIG_AXP288_ADC) += axp288_adc.o
 obj-$(CONFIG_BERLIN2_ADC) += berlin2-adc.o
-obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_CC10001_ADC) += cc10001_adc.o
+obj-$(CONFIG_DA9150_GPADC) += da9150-gpadc.o
 obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
+obj-$(CONFIG_HI8435) += hi8435.o
 obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
 obj-$(CONFIG_MAX1027) += max1027.o
 obj-$(CONFIG_MAX1363) += max1363.o
index b99de00e57b86ce8164eb0b3ad02a8de11b8597e..01d71588d752ae0aa73da6abf4019f35d041939a 100644 (file)
@@ -528,7 +528,6 @@ static struct attribute *ad799x_event_attributes[] = {
 
 static struct attribute_group ad799x_event_attrs_group = {
        .attrs = ad799x_event_attributes,
-       .name = "events",
 };
 
 static const struct iio_info ad7991_info = {
index 4946d9bf1764302d5250a56852115814acc7be32..71c806ecc722864ea6635138d7ecbf6f62038f10 100644 (file)
 #define  BERLIN2_SM_CTRL_SM_SOC_INT            BIT(1)
 #define  BERLIN2_SM_CTRL_SOC_SM_INT            BIT(2)
 #define  BERLIN2_SM_CTRL_ADC_SEL(x)            ((x) << 5)      /* 0-15 */
-#define  BERLIN2_SM_CTRL_ADC_SEL_MASK          (0xf << 5)
+#define  BERLIN2_SM_CTRL_ADC_SEL_MASK          GENMASK(8, 5)
 #define  BERLIN2_SM_CTRL_ADC_POWER             BIT(9)
 #define  BERLIN2_SM_CTRL_ADC_CLKSEL_DIV2       (0x0 << 10)
 #define  BERLIN2_SM_CTRL_ADC_CLKSEL_DIV3       (0x1 << 10)
 #define  BERLIN2_SM_CTRL_ADC_CLKSEL_DIV4       (0x2 << 10)
 #define  BERLIN2_SM_CTRL_ADC_CLKSEL_DIV8       (0x3 << 10)
-#define  BERLIN2_SM_CTRL_ADC_CLKSEL_MASK       (0x3 << 10)
+#define  BERLIN2_SM_CTRL_ADC_CLKSEL_MASK       GENMASK(11, 10)
 #define  BERLIN2_SM_CTRL_ADC_START             BIT(12)
 #define  BERLIN2_SM_CTRL_ADC_RESET             BIT(13)
 #define  BERLIN2_SM_CTRL_ADC_BANDGAP_RDY       BIT(14)
@@ -50,7 +50,7 @@
 #define  BERLIN2_SM_CTRL_TSEN_MODE_10_50       (0x1 << 22)     /* 10-50 C */
 #define  BERLIN2_SM_CTRL_TSEN_RESET            BIT(29)
 #define BERLIN2_SM_ADC_DATA                    0x20
-#define  BERLIN2_SM_ADC_MASK                   0x3ff
+#define  BERLIN2_SM_ADC_MASK                   GENMASK(9, 0)
 #define BERLIN2_SM_ADC_STATUS                  0x1c
 #define  BERLIN2_SM_ADC_STATUS_DATA_RDY(x)     BIT(x)          /* 0-15 */
 #define  BERLIN2_SM_ADC_STATUS_DATA_RDY_MASK   GENMASK(15, 0)
@@ -65,9 +65,9 @@
 #define  BERLIN2_SM_TSEN_CTRL_START            BIT(8)
 #define  BERLIN2_SM_TSEN_CTRL_SETTLING_4       (0x0 << 21)     /* 4 us */
 #define  BERLIN2_SM_TSEN_CTRL_SETTLING_12      (0x1 << 21)     /* 12 us */
-#define  BERLIN2_SM_TSEN_CTRL_SETTLING_MASK    (0x1 << 21)
+#define  BERLIN2_SM_TSEN_CTRL_SETTLING_MASK    BIT(21)
 #define  BERLIN2_SM_TSEN_CTRL_TRIM(x)          ((x) << 22)
-#define  BERLIN2_SM_TSEN_CTRL_TRIM_MASK                (0xf << 22)
+#define  BERLIN2_SM_TSEN_CTRL_TRIM_MASK                GENMASK(25, 22)
 
 struct berlin2_adc_priv {
        struct regmap           *regmap;
@@ -78,13 +78,13 @@ struct berlin2_adc_priv {
 };
 
 #define BERLIN2_ADC_CHANNEL(n, t)                                      \
-               {                                                       \
-                       .channel        = n,                            \
-                       .datasheet_name = "channel"#n,                  \
-                       .type           = t,                            \
-                       .indexed        = 1,                            \
-                       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),   \
-               }
+       {                                                               \
+               .channel                = n,                            \
+               .datasheet_name         = "channel"#n,                  \
+               .type                   = t,                            \
+               .indexed                = 1,                            \
+               .info_mask_separate     = BIT(IIO_CHAN_INFO_RAW),       \
+       }
 
 static const struct iio_chan_spec berlin2_adc_channels[] = {
        BERLIN2_ADC_CHANNEL(0, IIO_VOLTAGE),    /* external input */
@@ -111,18 +111,24 @@ static int berlin2_adc_read(struct iio_dev *indio_dev, int channel)
 
        mutex_lock(&priv->lock);
 
+       /* Enable the interrupts */
+       regmap_write(priv->regmap, BERLIN2_SM_ADC_STATUS,
+                    BERLIN2_SM_ADC_STATUS_INT_EN(channel));
+
        /* Configure the ADC */
        regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL,
-                       BERLIN2_SM_CTRL_ADC_RESET | BERLIN2_SM_CTRL_ADC_SEL_MASK
-                       | BERLIN2_SM_CTRL_ADC_START,
-                       BERLIN2_SM_CTRL_ADC_SEL(channel) | BERLIN2_SM_CTRL_ADC_START);
+                          BERLIN2_SM_CTRL_ADC_RESET |
+                          BERLIN2_SM_CTRL_ADC_SEL_MASK |
+                          BERLIN2_SM_CTRL_ADC_START,
+                          BERLIN2_SM_CTRL_ADC_SEL(channel) |
+                          BERLIN2_SM_CTRL_ADC_START);
 
        ret = wait_event_interruptible_timeout(priv->wq, priv->data_available,
-                       msecs_to_jiffies(1000));
+                                              msecs_to_jiffies(1000));
 
        /* Disable the interrupts */
        regmap_update_bits(priv->regmap, BERLIN2_SM_ADC_STATUS,
-                       BERLIN2_SM_ADC_STATUS_INT_EN(channel), 0);
+                          BERLIN2_SM_ADC_STATUS_INT_EN(channel), 0);
 
        if (ret == 0)
                ret = -ETIMEDOUT;
@@ -132,7 +138,7 @@ static int berlin2_adc_read(struct iio_dev *indio_dev, int channel)
        }
 
        regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL,
-                       BERLIN2_SM_CTRL_ADC_START, 0);
+                          BERLIN2_SM_CTRL_ADC_START, 0);
 
        data = priv->data;
        priv->data_available = false;
@@ -149,24 +155,31 @@ static int berlin2_adc_tsen_read(struct iio_dev *indio_dev)
 
        mutex_lock(&priv->lock);
 
+       /* Enable interrupts */
+       regmap_write(priv->regmap, BERLIN2_SM_TSEN_STATUS,
+                    BERLIN2_SM_TSEN_STATUS_INT_EN);
+
        /* Configure the ADC */
        regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL,
-                       BERLIN2_SM_CTRL_TSEN_RESET | BERLIN2_SM_CTRL_ADC_ROTATE,
-                       BERLIN2_SM_CTRL_ADC_ROTATE);
+                          BERLIN2_SM_CTRL_TSEN_RESET |
+                          BERLIN2_SM_CTRL_ADC_ROTATE,
+                          BERLIN2_SM_CTRL_ADC_ROTATE);
 
        /* Configure the temperature sensor */
        regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_CTRL,
-                       BERLIN2_SM_TSEN_CTRL_TRIM_MASK | BERLIN2_SM_TSEN_CTRL_SETTLING_MASK
-                       | BERLIN2_SM_TSEN_CTRL_START,
-                       BERLIN2_SM_TSEN_CTRL_TRIM(3) | BERLIN2_SM_TSEN_CTRL_SETTLING_12
-                       | BERLIN2_SM_TSEN_CTRL_START);
+                          BERLIN2_SM_TSEN_CTRL_TRIM_MASK |
+                          BERLIN2_SM_TSEN_CTRL_SETTLING_MASK |
+                          BERLIN2_SM_TSEN_CTRL_START,
+                          BERLIN2_SM_TSEN_CTRL_TRIM(3) |
+                          BERLIN2_SM_TSEN_CTRL_SETTLING_12 |
+                          BERLIN2_SM_TSEN_CTRL_START);
 
        ret = wait_event_interruptible_timeout(priv->wq, priv->data_available,
-                       msecs_to_jiffies(1000));
+                                              msecs_to_jiffies(1000));
 
        /* Disable interrupts */
        regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_STATUS,
-                       BERLIN2_SM_TSEN_STATUS_INT_EN, 0);
+                          BERLIN2_SM_TSEN_STATUS_INT_EN, 0);
 
        if (ret == 0)
                ret = -ETIMEDOUT;
@@ -176,7 +189,7 @@ static int berlin2_adc_tsen_read(struct iio_dev *indio_dev)
        }
 
        regmap_update_bits(priv->regmap, BERLIN2_SM_TSEN_CTRL,
-                       BERLIN2_SM_TSEN_CTRL_START, 0);
+                          BERLIN2_SM_TSEN_CTRL_START, 0);
 
        data = priv->data;
        priv->data_available = false;
@@ -187,10 +200,9 @@ static int berlin2_adc_tsen_read(struct iio_dev *indio_dev)
 }
 
 static int berlin2_adc_read_raw(struct iio_dev *indio_dev,
-               struct iio_chan_spec const *chan, int *val, int *val2,
-               long mask)
+                               struct iio_chan_spec const *chan, int *val,
+                               int *val2, long mask)
 {
-       struct berlin2_adc_priv *priv = iio_priv(indio_dev);
        int temp;
 
        switch (mask) {
@@ -198,10 +210,6 @@ static int berlin2_adc_read_raw(struct iio_dev *indio_dev,
                if (chan->type != IIO_VOLTAGE)
                        return -EINVAL;
 
-               /* Enable the interrupts */
-               regmap_write(priv->regmap, BERLIN2_SM_ADC_STATUS,
-                               BERLIN2_SM_ADC_STATUS_INT_EN(chan->channel));
-
                *val = berlin2_adc_read(indio_dev, chan->channel);
                if (*val < 0)
                        return *val;
@@ -211,10 +219,6 @@ static int berlin2_adc_read_raw(struct iio_dev *indio_dev,
                if (chan->type != IIO_TEMP)
                        return -EINVAL;
 
-               /* Enable interrupts */
-               regmap_write(priv->regmap, BERLIN2_SM_TSEN_STATUS,
-                               BERLIN2_SM_TSEN_STATUS_INT_EN);
-
                temp = berlin2_adc_tsen_read(indio_dev);
                if (temp < 0)
                        return temp;
@@ -306,12 +310,12 @@ static int berlin2_adc_probe(struct platform_device *pdev)
                return tsen_irq;
 
        ret = devm_request_irq(&pdev->dev, irq, berlin2_adc_irq, 0,
-                       pdev->dev.driver->name, indio_dev);
+                              pdev->dev.driver->name, indio_dev);
        if (ret)
                return ret;
 
        ret = devm_request_irq(&pdev->dev, tsen_irq, berlin2_adc_tsen_irq,
-                       0, pdev->dev.driver->name, indio_dev);
+                              0, pdev->dev.driver->name, indio_dev);
        if (ret)
                return ret;
 
@@ -328,13 +332,14 @@ static int berlin2_adc_probe(struct platform_device *pdev)
 
        /* Power up the ADC */
        regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL,
-                       BERLIN2_SM_CTRL_ADC_POWER, BERLIN2_SM_CTRL_ADC_POWER);
+                          BERLIN2_SM_CTRL_ADC_POWER,
+                          BERLIN2_SM_CTRL_ADC_POWER);
 
        ret = iio_device_register(indio_dev);
        if (ret) {
                /* Power down the ADC */
                regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL,
-                               BERLIN2_SM_CTRL_ADC_POWER, 0);
+                                  BERLIN2_SM_CTRL_ADC_POWER, 0);
                return ret;
        }
 
@@ -350,7 +355,7 @@ static int berlin2_adc_remove(struct platform_device *pdev)
 
        /* Power down the ADC */
        regmap_update_bits(priv->regmap, BERLIN2_SM_CTRL,
-                       BERLIN2_SM_CTRL_ADC_POWER, 0);
+                          BERLIN2_SM_CTRL_ADC_POWER, 0);
 
        return 0;
 }
diff --git a/drivers/iio/adc/hi8435.c b/drivers/iio/adc/hi8435.c
new file mode 100644 (file)
index 0000000..c73c6c6
--- /dev/null
@@ -0,0 +1,534 @@
+/*
+ * Holt Integrated Circuits HI-8435 threshold detector driver
+ *
+ * Copyright (C) 2015 Zodiac Inflight Innovations
+ * Copyright (C) 2015 Cogent Embedded, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/delay.h>
+#include <linux/iio/events.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_event.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
+#include <linux/spi/spi.h>
+#include <linux/gpio/consumer.h>
+
+#define DRV_NAME "hi8435"
+
+/* Register offsets for HI-8435 */
+#define HI8435_CTRL_REG                0x02
+#define HI8435_PSEN_REG                0x04
+#define HI8435_TMDATA_REG      0x1E
+#define HI8435_GOCENHYS_REG    0x3A
+#define HI8435_SOCENHYS_REG    0x3C
+#define HI8435_SO7_0_REG       0x10
+#define HI8435_SO15_8_REG      0x12
+#define HI8435_SO23_16_REG     0x14
+#define HI8435_SO31_24_REG     0x16
+#define HI8435_SO31_0_REG      0x78
+
+#define HI8435_WRITE_OPCODE    0x00
+#define HI8435_READ_OPCODE     0x80
+
+/* CTRL register bits */
+#define HI8435_CTRL_TEST       0x01
+#define HI8435_CTRL_SRST       0x02
+
+struct hi8435_priv {
+       struct spi_device *spi;
+       struct mutex lock;
+
+       unsigned long event_scan_mask; /* soft mask/unmask channels events */
+       unsigned int event_prev_val;
+
+       unsigned threshold_lo[2]; /* GND-Open and Supply-Open thresholds */
+       unsigned threshold_hi[2]; /* GND-Open and Supply-Open thresholds */
+       u8 reg_buffer[3] ____cacheline_aligned;
+};
+
+static int hi8435_readb(struct hi8435_priv *priv, u8 reg, u8 *val)
+{
+       reg |= HI8435_READ_OPCODE;
+       return spi_write_then_read(priv->spi, &reg, 1, val, 1);
+}
+
+static int hi8435_readw(struct hi8435_priv *priv, u8 reg, u16 *val)
+{
+       int ret;
+       __be16 be_val;
+
+       reg |= HI8435_READ_OPCODE;
+       ret = spi_write_then_read(priv->spi, &reg, 1, &be_val, 2);
+       *val = be16_to_cpu(be_val);
+
+       return ret;
+}
+
+static int hi8435_readl(struct hi8435_priv *priv, u8 reg, u32 *val)
+{
+       int ret;
+       __be32 be_val;
+
+       reg |= HI8435_READ_OPCODE;
+       ret = spi_write_then_read(priv->spi, &reg, 1, &be_val, 4);
+       *val = be32_to_cpu(be_val);
+
+       return ret;
+}
+
+static int hi8435_writeb(struct hi8435_priv *priv, u8 reg, u8 val)
+{
+       priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE;
+       priv->reg_buffer[1] = val;
+
+       return spi_write(priv->spi, priv->reg_buffer, 2);
+}
+
+static int hi8435_writew(struct hi8435_priv *priv, u8 reg, u16 val)
+{
+       priv->reg_buffer[0] = reg | HI8435_WRITE_OPCODE;
+       priv->reg_buffer[1] = (val >> 8) & 0xff;
+       priv->reg_buffer[2] = val & 0xff;
+
+       return spi_write(priv->spi, priv->reg_buffer, 3);
+}
+
+static int hi8435_read_event_config(struct iio_dev *idev,
+                                   const struct iio_chan_spec *chan,
+                                   enum iio_event_type type,
+                                   enum iio_event_direction dir)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+
+       return !!(priv->event_scan_mask & BIT(chan->channel));
+}
+
+static int hi8435_write_event_config(struct iio_dev *idev,
+                                    const struct iio_chan_spec *chan,
+                                    enum iio_event_type type,
+                                    enum iio_event_direction dir, int state)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+
+       priv->event_scan_mask &= ~BIT(chan->channel);
+       if (state)
+               priv->event_scan_mask |= BIT(chan->channel);
+
+       return 0;
+}
+
+static int hi8435_read_event_value(struct iio_dev *idev,
+                                  const struct iio_chan_spec *chan,
+                                  enum iio_event_type type,
+                                  enum iio_event_direction dir,
+                                  enum iio_event_info info,
+                                  int *val, int *val2)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+       int ret;
+       u8 mode, psen;
+       u16 reg;
+
+       ret = hi8435_readb(priv, HI8435_PSEN_REG, &psen);
+       if (ret < 0)
+               return ret;
+
+       /* Supply-Open or GND-Open sensing mode */
+       mode = !!(psen & BIT(chan->channel / 8));
+
+       ret = hi8435_readw(priv, mode ? HI8435_SOCENHYS_REG :
+                                HI8435_GOCENHYS_REG, &reg);
+       if (ret < 0)
+               return ret;
+
+       if (dir == IIO_EV_DIR_FALLING)
+               *val = ((reg & 0xff) - (reg >> 8)) / 2;
+       else if (dir == IIO_EV_DIR_RISING)
+               *val = ((reg & 0xff) + (reg >> 8)) / 2;
+
+       return IIO_VAL_INT;
+}
+
+static int hi8435_write_event_value(struct iio_dev *idev,
+                                   const struct iio_chan_spec *chan,
+                                   enum iio_event_type type,
+                                   enum iio_event_direction dir,
+                                   enum iio_event_info info,
+                                   int val, int val2)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+       int ret;
+       u8 mode, psen;
+       u16 reg;
+
+       ret = hi8435_readb(priv, HI8435_PSEN_REG, &psen);
+       if (ret < 0)
+               return ret;
+
+       /* Supply-Open or GND-Open sensing mode */
+       mode = !!(psen & BIT(chan->channel / 8));
+
+       ret = hi8435_readw(priv, mode ? HI8435_SOCENHYS_REG :
+                                HI8435_GOCENHYS_REG, &reg);
+       if (ret < 0)
+               return ret;
+
+       if (dir == IIO_EV_DIR_FALLING) {
+               /* falling threshold range 2..21V, hysteresis minimum 2V */
+               if (val < 2 || val > 21 || (val + 2) > priv->threshold_hi[mode])
+                       return -EINVAL;
+
+               if (val == priv->threshold_lo[mode])
+                       return 0;
+
+               priv->threshold_lo[mode] = val;
+
+               /* hysteresis must not be odd */
+               if ((priv->threshold_hi[mode] - priv->threshold_lo[mode]) % 2)
+                       priv->threshold_hi[mode]--;
+       } else if (dir == IIO_EV_DIR_RISING) {
+               /* rising threshold range 3..22V, hysteresis minimum 2V */
+               if (val < 3 || val > 22 || val < (priv->threshold_lo[mode] + 2))
+                       return -EINVAL;
+
+               if (val == priv->threshold_hi[mode])
+                       return 0;
+
+               priv->threshold_hi[mode] = val;
+
+               /* hysteresis must not be odd */
+               if ((priv->threshold_hi[mode] - priv->threshold_lo[mode]) % 2)
+                       priv->threshold_lo[mode]++;
+       }
+
+       /* program thresholds */
+       mutex_lock(&priv->lock);
+
+       ret = hi8435_readw(priv, mode ? HI8435_SOCENHYS_REG :
+                                HI8435_GOCENHYS_REG, &reg);
+       if (ret < 0) {
+               mutex_unlock(&priv->lock);
+               return ret;
+       }
+
+       /* hysteresis */
+       reg = priv->threshold_hi[mode] - priv->threshold_lo[mode];
+       reg <<= 8;
+       /* threshold center */
+       reg |= (priv->threshold_hi[mode] + priv->threshold_lo[mode]);
+
+       ret = hi8435_writew(priv, mode ? HI8435_SOCENHYS_REG :
+                                 HI8435_GOCENHYS_REG, reg);
+
+       mutex_unlock(&priv->lock);
+
+       return ret;
+}
+
+static int hi8435_debugfs_reg_access(struct iio_dev *idev,
+                                    unsigned reg, unsigned writeval,
+                                    unsigned *readval)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+       int ret;
+       u8 val;
+
+       if (readval != NULL) {
+               ret = hi8435_readb(priv, reg, &val);
+               *readval = val;
+       } else {
+               val = (u8)writeval;
+               ret = hi8435_writeb(priv, reg, val);
+       }
+
+       return ret;
+}
+
+static const struct iio_event_spec hi8435_events[] = {
+       {
+               .type = IIO_EV_TYPE_THRESH,
+               .dir = IIO_EV_DIR_RISING,
+               .mask_separate = BIT(IIO_EV_INFO_VALUE),
+       }, {
+               .type = IIO_EV_TYPE_THRESH,
+               .dir = IIO_EV_DIR_FALLING,
+               .mask_separate = BIT(IIO_EV_INFO_VALUE),
+       }, {
+               .type = IIO_EV_TYPE_THRESH,
+               .dir = IIO_EV_DIR_EITHER,
+               .mask_separate = BIT(IIO_EV_INFO_ENABLE),
+       },
+};
+
+static int hi8435_get_sensing_mode(struct iio_dev *idev,
+                                  const struct iio_chan_spec *chan)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+       int ret;
+       u8 reg;
+
+       ret = hi8435_readb(priv, HI8435_PSEN_REG, &reg);
+       if (ret < 0)
+               return ret;
+
+       return !!(reg & BIT(chan->channel / 8));
+}
+
+static int hi8435_set_sensing_mode(struct iio_dev *idev,
+                                  const struct iio_chan_spec *chan,
+                                  unsigned int mode)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+       int ret;
+       u8 reg;
+
+       mutex_lock(&priv->lock);
+
+       ret = hi8435_readb(priv, HI8435_PSEN_REG, &reg);
+       if (ret < 0) {
+               mutex_unlock(&priv->lock);
+               return ret;
+       }
+
+       reg &= ~BIT(chan->channel / 8);
+       if (mode)
+               reg |= BIT(chan->channel / 8);
+
+       ret = hi8435_writeb(priv, HI8435_PSEN_REG, reg);
+
+       mutex_unlock(&priv->lock);
+
+       return ret;
+}
+
+static const char * const hi8435_sensing_modes[] = { "GND-Open",
+                                                    "Supply-Open" };
+
+static const struct iio_enum hi8435_sensing_mode = {
+       .items = hi8435_sensing_modes,
+       .num_items = ARRAY_SIZE(hi8435_sensing_modes),
+       .get = hi8435_get_sensing_mode,
+       .set = hi8435_set_sensing_mode,
+};
+
+static const struct iio_chan_spec_ext_info hi8435_ext_info[] = {
+       IIO_ENUM("sensing_mode", IIO_SEPARATE, &hi8435_sensing_mode),
+       {},
+};
+
+#define HI8435_VOLTAGE_CHANNEL(num)                    \
+{                                                      \
+       .type = IIO_VOLTAGE,                            \
+       .indexed = 1,                                   \
+       .channel = num,                                 \
+       .event_spec = hi8435_events,                    \
+       .num_event_specs = ARRAY_SIZE(hi8435_events),   \
+       .ext_info = hi8435_ext_info,                    \
+}
+
+static const struct iio_chan_spec hi8435_channels[] = {
+       HI8435_VOLTAGE_CHANNEL(0),
+       HI8435_VOLTAGE_CHANNEL(1),
+       HI8435_VOLTAGE_CHANNEL(2),
+       HI8435_VOLTAGE_CHANNEL(3),
+       HI8435_VOLTAGE_CHANNEL(4),
+       HI8435_VOLTAGE_CHANNEL(5),
+       HI8435_VOLTAGE_CHANNEL(6),
+       HI8435_VOLTAGE_CHANNEL(7),
+       HI8435_VOLTAGE_CHANNEL(8),
+       HI8435_VOLTAGE_CHANNEL(9),
+       HI8435_VOLTAGE_CHANNEL(10),
+       HI8435_VOLTAGE_CHANNEL(11),
+       HI8435_VOLTAGE_CHANNEL(12),
+       HI8435_VOLTAGE_CHANNEL(13),
+       HI8435_VOLTAGE_CHANNEL(14),
+       HI8435_VOLTAGE_CHANNEL(15),
+       HI8435_VOLTAGE_CHANNEL(16),
+       HI8435_VOLTAGE_CHANNEL(17),
+       HI8435_VOLTAGE_CHANNEL(18),
+       HI8435_VOLTAGE_CHANNEL(19),
+       HI8435_VOLTAGE_CHANNEL(20),
+       HI8435_VOLTAGE_CHANNEL(21),
+       HI8435_VOLTAGE_CHANNEL(22),
+       HI8435_VOLTAGE_CHANNEL(23),
+       HI8435_VOLTAGE_CHANNEL(24),
+       HI8435_VOLTAGE_CHANNEL(25),
+       HI8435_VOLTAGE_CHANNEL(26),
+       HI8435_VOLTAGE_CHANNEL(27),
+       HI8435_VOLTAGE_CHANNEL(28),
+       HI8435_VOLTAGE_CHANNEL(29),
+       HI8435_VOLTAGE_CHANNEL(30),
+       HI8435_VOLTAGE_CHANNEL(31),
+       IIO_CHAN_SOFT_TIMESTAMP(32),
+};
+
+static const struct iio_info hi8435_info = {
+       .driver_module = THIS_MODULE,
+       .read_event_config = &hi8435_read_event_config,
+       .write_event_config = hi8435_write_event_config,
+       .read_event_value = &hi8435_read_event_value,
+       .write_event_value = &hi8435_write_event_value,
+       .debugfs_reg_access = &hi8435_debugfs_reg_access,
+};
+
+static void hi8435_iio_push_event(struct iio_dev *idev, unsigned int val)
+{
+       struct hi8435_priv *priv = iio_priv(idev);
+       enum iio_event_direction dir;
+       unsigned int i;
+       unsigned int status = priv->event_prev_val ^ val;
+
+       if (!status)
+               return;
+
+       for_each_set_bit(i, &priv->event_scan_mask, 32) {
+               if (status & BIT(i)) {
+                       dir = val & BIT(i) ? IIO_EV_DIR_RISING :
+                                            IIO_EV_DIR_FALLING;
+                       iio_push_event(idev,
+                                      IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, i,
+                                                   IIO_EV_TYPE_THRESH, dir),
+                                      iio_get_time_ns());
+               }
+       }
+
+       priv->event_prev_val = val;
+}
+
+static irqreturn_t hi8435_trigger_handler(int irq, void *private)
+{
+       struct iio_poll_func *pf = private;
+       struct iio_dev *idev = pf->indio_dev;
+       struct hi8435_priv *priv = iio_priv(idev);
+       u32 val;
+       int ret;
+
+       ret = hi8435_readl(priv, HI8435_SO31_0_REG, &val);
+       if (ret < 0)
+               goto err_read;
+
+       hi8435_iio_push_event(idev, val);
+
+err_read:
+       iio_trigger_notify_done(idev->trig);
+
+       return IRQ_HANDLED;
+}
+
+static int hi8435_probe(struct spi_device *spi)
+{
+       struct iio_dev *idev;
+       struct hi8435_priv *priv;
+       struct gpio_desc *reset_gpio;
+       int ret;
+
+       idev = devm_iio_device_alloc(&spi->dev, sizeof(*priv));
+       if (!idev)
+               return -ENOMEM;
+
+       priv = iio_priv(idev);
+       priv->spi = spi;
+
+       reset_gpio = devm_gpiod_get(&spi->dev, NULL, GPIOD_OUT_LOW);
+       if (IS_ERR(reset_gpio)) {
+               /* chip s/w reset if h/w reset failed */
+               hi8435_writeb(priv, HI8435_CTRL_REG, HI8435_CTRL_SRST);
+               hi8435_writeb(priv, HI8435_CTRL_REG, 0);
+       } else {
+               udelay(5);
+               gpiod_set_value(reset_gpio, 1);
+       }
+
+       spi_set_drvdata(spi, idev);
+       mutex_init(&priv->lock);
+
+       idev->dev.parent        = &spi->dev;
+       idev->name              = spi_get_device_id(spi)->name;
+       idev->modes             = INDIO_DIRECT_MODE;
+       idev->info              = &hi8435_info;
+       idev->channels          = hi8435_channels;
+       idev->num_channels      = ARRAY_SIZE(hi8435_channels);
+
+       /* unmask all events */
+       priv->event_scan_mask = ~(0);
+       /*
+        * There is a restriction in the chip - the hysteresis can not be odd.
+        * If the hysteresis is set to odd value then chip gets into lock state
+        * and not functional anymore.
+        * After chip reset the thresholds are in undefined state, so we need to
+        * initialize thresholds to some initial values and then prevent
+        * userspace setting odd hysteresis.
+        *
+        * Set threshold low voltage to 2V, threshold high voltage to 4V
+        * for both GND-Open and Supply-Open sensing modes.
+        */
+       priv->threshold_lo[0] = priv->threshold_lo[1] = 2;
+       priv->threshold_hi[0] = priv->threshold_hi[1] = 4;
+       hi8435_writew(priv, HI8435_GOCENHYS_REG, 0x206);
+       hi8435_writew(priv, HI8435_SOCENHYS_REG, 0x206);
+
+       ret = iio_triggered_event_setup(idev, NULL, hi8435_trigger_handler);
+       if (ret)
+               return ret;
+
+       ret = iio_device_register(idev);
+       if (ret < 0) {
+               dev_err(&spi->dev, "unable to register device\n");
+               goto unregister_triggered_event;
+       }
+
+       return 0;
+
+unregister_triggered_event:
+       iio_triggered_event_cleanup(idev);
+       return ret;
+}
+
+static int hi8435_remove(struct spi_device *spi)
+{
+       struct iio_dev *idev = spi_get_drvdata(spi);
+
+       iio_device_unregister(idev);
+       iio_triggered_event_cleanup(idev);
+
+       return 0;
+}
+
+static const struct of_device_id hi8435_dt_ids[] = {
+       { .compatible = "holt,hi8435" },
+       {},
+};
+MODULE_DEVICE_TABLE(of, hi8435_dt_ids);
+
+static const struct spi_device_id hi8435_id[] = {
+       { "hi8435", 0},
+       { }
+};
+MODULE_DEVICE_TABLE(spi, hi8435_id);
+
+static struct spi_driver hi8435_driver = {
+       .driver = {
+               .name           = DRV_NAME,
+               .of_match_table = of_match_ptr(hi8435_dt_ids),
+       },
+       .probe          = hi8435_probe,
+       .remove         = hi8435_remove,
+       .id_table       = hi8435_id,
+};
+module_spi_driver(hi8435_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Vladimir Barinov");
+MODULE_DESCRIPTION("HI-8435 threshold detector");
index 3bc059c698241a46908c9b5047082f0262cdae26..41d495c6035e1a882e03b17ca8066224e767cde6 100644 (file)
@@ -508,6 +508,7 @@ static int max1027_remove(struct spi_device *spi)
 static struct spi_driver max1027_driver = {
        .driver = {
                .name   = "max1027",
+               .of_match_table = of_match_ptr(max1027_adc_dt_ids),
        },
        .probe          = max1027_probe,
        .remove         = max1027_remove,
index 1b3b74be5c2007c821d2a6839fb62f9adc8ddfec..929508e5266c000864d1095860b7b16f87baf51b 100644 (file)
@@ -1007,7 +1007,6 @@ static struct attribute *max1363_event_attributes[] = {
 
 static struct attribute_group max1363_event_attribute_group = {
        .attrs = max1363_event_attributes,
-       .name = "events",
 };
 
 static int max1363_update_scan_mode(struct iio_dev *indio_dev,
index d5d8b4180914d873a673072c5c377e68cd2e603e..8569c8e1f4b276db3e968356626c67fab9b60c16 100644 (file)
@@ -404,6 +404,7 @@ MODULE_DEVICE_TABLE(spi, mcp320x_id);
 static struct spi_driver mcp320x_driver = {
        .driver = {
                .name = "mcp320x",
+               .of_match_table = of_match_ptr(mcp320x_dt_ids),
        },
        .probe = mcp320x_probe,
        .remove = mcp320x_remove,
index 76b619649409a43329719e17668b851b427e3c84..ff6f7f63c8d9b8c2c7e758ce932912663b7fbc3f 100644 (file)
@@ -174,6 +174,13 @@ static int adc128_remove(struct spi_device *spi)
        return 0;
 }
 
+static const struct of_device_id adc128_of_match[] = {
+       { .compatible = "ti,adc128s052", },
+       { .compatible = "ti,adc122s021", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, adc128_of_match);
+
 static const struct spi_device_id adc128_id[] = {
        { "adc128s052", 0},     /* index into adc128_config */
        { "adc122s021", 1},
@@ -184,6 +191,7 @@ MODULE_DEVICE_TABLE(spi, adc128_id);
 static struct spi_driver adc128_driver = {
        .driver = {
                .name = "adc128s052",
+               .of_match_table = of_match_ptr(adc128_of_match),
        },
        .probe = adc128_probe,
        .remove = adc128_remove,
index df12c57e6ce07a700d211b81c9b5d3c9c15ff2d3..becbb0aef232b92f88c9443c3cdeed07308afd05 100644 (file)
@@ -875,6 +875,7 @@ static const struct of_device_id of_twl6030_match_tbl[] = {
        },
        { /* end */ }
 };
+MODULE_DEVICE_TABLE(of, of_twl6030_match_tbl);
 
 static int twl6030_gpadc_probe(struct platform_device *pdev)
 {
index 6bf4c20eb231a40754e578b704c6ea17c87e5a3d..599cde3d03a117358f86defec5dcd10ac25b1ed7 100644 (file)
 #include <linux/err.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
 #include <linux/iio/sysfs.h>
-#include <linux/iio/driver.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 /* This will be the driver name the kernel reports */
 #define DRIVER_NAME "vf610-adc"
@@ -170,6 +173,7 @@ struct vf610_adc {
        u32 sample_freq_avail[5];
 
        struct completion completion;
+       u16 buffer[8];
 };
 
 static const u32 vf610_hw_avgs[] = { 1, 4, 8, 16, 32 };
@@ -505,12 +509,24 @@ static const struct iio_chan_spec_ext_info vf610_ext_info[] = {
        .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |  \
                                BIT(IIO_CHAN_INFO_SAMP_FREQ),   \
        .ext_info = vf610_ext_info,                             \
+       .scan_index = (_idx),                   \
+       .scan_type = {                                  \
+               .sign = 'u',                            \
+               .realbits = 12,                         \
+               .storagebits = 16,                      \
+       },                                              \
 }
 
 #define VF610_ADC_TEMPERATURE_CHAN(_idx, _chan_type) { \
        .type = (_chan_type),   \
        .channel = (_idx),              \
        .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),     \
+       .scan_index = (_idx),                                   \
+       .scan_type = {                                          \
+               .sign = 'u',                                    \
+               .realbits = 12,                                 \
+               .storagebits = 16,                              \
+       },                                                      \
 }
 
 static const struct iio_chan_spec vf610_adc_iio_channels[] = {
@@ -531,6 +547,7 @@ static const struct iio_chan_spec vf610_adc_iio_channels[] = {
        VF610_ADC_CHAN(14, IIO_VOLTAGE),
        VF610_ADC_CHAN(15, IIO_VOLTAGE),
        VF610_ADC_TEMPERATURE_CHAN(26, IIO_TEMP),
+       IIO_CHAN_SOFT_TIMESTAMP(32),
        /* sentinel */
 };
 
@@ -559,13 +576,20 @@ static int vf610_adc_read_data(struct vf610_adc *info)
 
 static irqreturn_t vf610_adc_isr(int irq, void *dev_id)
 {
-       struct vf610_adc *info = (struct vf610_adc *)dev_id;
+       struct iio_dev *indio_dev = (struct iio_dev *)dev_id;
+       struct vf610_adc *info = iio_priv(indio_dev);
        int coco;
 
        coco = readl(info->regs + VF610_REG_ADC_HS);
        if (coco & VF610_ADC_HS_COCO0) {
                info->value = vf610_adc_read_data(info);
-               complete(&info->completion);
+               if (iio_buffer_enabled(indio_dev)) {
+                       info->buffer[0] = info->value;
+                       iio_push_to_buffers_with_timestamp(indio_dev,
+                                       info->buffer, iio_get_time_ns());
+                       iio_trigger_notify_done(indio_dev->trig);
+               } else
+                       complete(&info->completion);
        }
 
        return IRQ_HANDLED;
@@ -613,8 +637,12 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
        case IIO_CHAN_INFO_RAW:
        case IIO_CHAN_INFO_PROCESSED:
                mutex_lock(&indio_dev->mlock);
-               reinit_completion(&info->completion);
+               if (iio_buffer_enabled(indio_dev)) {
+                       mutex_unlock(&indio_dev->mlock);
+                       return -EBUSY;
+               }
 
+               reinit_completion(&info->completion);
                hc_cfg = VF610_ADC_ADCHC(chan->channel);
                hc_cfg |= VF610_ADC_AIEN;
                writel(hc_cfg, info->regs + VF610_REG_ADC_HC0);
@@ -694,6 +722,56 @@ static int vf610_write_raw(struct iio_dev *indio_dev,
        return -EINVAL;
 }
 
+static int vf610_adc_buffer_postenable(struct iio_dev *indio_dev)
+{
+       struct vf610_adc *info = iio_priv(indio_dev);
+       unsigned int channel;
+       int ret;
+       int val;
+
+       ret = iio_triggered_buffer_postenable(indio_dev);
+       if (ret)
+               return ret;
+
+       val = readl(info->regs + VF610_REG_ADC_GC);
+       val |= VF610_ADC_ADCON;
+       writel(val, info->regs + VF610_REG_ADC_GC);
+
+       channel = find_first_bit(indio_dev->active_scan_mask,
+                                               indio_dev->masklength);
+
+       val = VF610_ADC_ADCHC(channel);
+       val |= VF610_ADC_AIEN;
+
+       writel(val, info->regs + VF610_REG_ADC_HC0);
+
+       return 0;
+}
+
+static int vf610_adc_buffer_predisable(struct iio_dev *indio_dev)
+{
+       struct vf610_adc *info = iio_priv(indio_dev);
+       unsigned int hc_cfg = 0;
+       int val;
+
+       val = readl(info->regs + VF610_REG_ADC_GC);
+       val &= ~VF610_ADC_ADCON;
+       writel(val, info->regs + VF610_REG_ADC_GC);
+
+       hc_cfg |= VF610_ADC_CONV_DISABLE;
+       hc_cfg &= ~VF610_ADC_AIEN;
+
+       writel(hc_cfg, info->regs + VF610_REG_ADC_HC0);
+
+       return iio_triggered_buffer_predisable(indio_dev);
+}
+
+static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
+       .postenable = &vf610_adc_buffer_postenable,
+       .predisable = &vf610_adc_buffer_predisable,
+       .validate_scan_mask = &iio_validate_scan_mask_onehot,
+};
+
 static int vf610_adc_reg_access(struct iio_dev *indio_dev,
                        unsigned reg, unsigned writeval,
                        unsigned *readval)
@@ -753,7 +831,7 @@ static int vf610_adc_probe(struct platform_device *pdev)
 
        ret = devm_request_irq(info->dev, irq,
                                vf610_adc_isr, 0,
-                               dev_name(&pdev->dev), info);
+                               dev_name(&pdev->dev), indio_dev);
        if (ret < 0) {
                dev_err(&pdev->dev, "failed requesting irq, irq = %d\n", irq);
                return ret;
@@ -806,15 +884,23 @@ static int vf610_adc_probe(struct platform_device *pdev)
        vf610_adc_cfg_init(info);
        vf610_adc_hw_init(info);
 
+       ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+                                       NULL, &iio_triggered_buffer_setup_ops);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "Couldn't initialise the buffer\n");
+               goto error_iio_device_register;
+       }
+
        ret = iio_device_register(indio_dev);
        if (ret) {
                dev_err(&pdev->dev, "Couldn't register the device.\n");
-               goto error_iio_device_register;
+               goto error_adc_buffer_init;
        }
 
        return 0;
 
-
+error_adc_buffer_init:
+       iio_triggered_buffer_cleanup(indio_dev);
 error_iio_device_register:
        clk_disable_unprepare(info->clk);
 error_adc_clk_enable:
@@ -829,6 +915,7 @@ static int vf610_adc_remove(struct platform_device *pdev)
        struct vf610_adc *info = iio_priv(indio_dev);
 
        iio_device_unregister(indio_dev);
+       iio_triggered_buffer_cleanup(indio_dev);
        regulator_disable(info->vref);
        clk_disable_unprepare(info->clk);
 
index ce93bd8e3f68b82fec81b31f8f1885b908ef0b45..0370624a35db723a6b6089c99398cca36fc10590 100644 (file)
@@ -273,33 +273,13 @@ static void xadc_zynq_unmask_worker(struct work_struct *work)
                schedule_delayed_work(&xadc->zynq_unmask_work,
                                msecs_to_jiffies(XADC_ZYNQ_UNMASK_TIMEOUT));
        }
-}
-
-static irqreturn_t xadc_zynq_threaded_interrupt_handler(int irq, void *devid)
-{
-       struct iio_dev *indio_dev = devid;
-       struct xadc *xadc = iio_priv(indio_dev);
-       unsigned int alarm;
-
-       spin_lock_irq(&xadc->lock);
-       alarm = xadc->zynq_alarm;
-       xadc->zynq_alarm = 0;
-       spin_unlock_irq(&xadc->lock);
-
-       xadc_handle_events(indio_dev, xadc_zynq_transform_alarm(alarm));
 
-       /* unmask the required interrupts in timer. */
-       schedule_delayed_work(&xadc->zynq_unmask_work,
-                       msecs_to_jiffies(XADC_ZYNQ_UNMASK_TIMEOUT));
-
-       return IRQ_HANDLED;
 }
 
 static irqreturn_t xadc_zynq_interrupt_handler(int irq, void *devid)
 {
        struct iio_dev *indio_dev = devid;
        struct xadc *xadc = iio_priv(indio_dev);
-       irqreturn_t ret = IRQ_HANDLED;
        uint32_t status;
 
        xadc_read_reg(xadc, XADC_ZYNQ_REG_INTSTS, &status);
@@ -321,18 +301,23 @@ static irqreturn_t xadc_zynq_interrupt_handler(int irq, void *devid)
 
        status &= XADC_ZYNQ_INT_ALARM_MASK;
        if (status) {
-               xadc->zynq_alarm |= status;
                xadc->zynq_masked_alarm |= status;
                /*
                 * mask the current event interrupt,
                 * unmask it when the interrupt is no more active.
                 */
                xadc_zynq_update_intmsk(xadc, 0, 0);
-               ret = IRQ_WAKE_THREAD;
+
+               xadc_handle_events(indio_dev,
+                               xadc_zynq_transform_alarm(status));
+
+               /* unmask the required interrupts in timer. */
+               schedule_delayed_work(&xadc->zynq_unmask_work,
+                               msecs_to_jiffies(XADC_ZYNQ_UNMASK_TIMEOUT));
        }
        spin_unlock(&xadc->lock);
 
-       return ret;
+       return IRQ_HANDLED;
 }
 
 #define XADC_ZYNQ_TCK_RATE_MAX 50000000
@@ -437,7 +422,6 @@ static const struct xadc_ops xadc_zynq_ops = {
        .setup = xadc_zynq_setup,
        .get_dclk_rate = xadc_zynq_get_dclk_rate,
        .interrupt_handler = xadc_zynq_interrupt_handler,
-       .threaded_interrupt_handler = xadc_zynq_threaded_interrupt_handler,
        .update_alarm = xadc_zynq_update_alarm,
 };
 
@@ -1225,9 +1209,8 @@ static int xadc_probe(struct platform_device *pdev)
        if (ret)
                goto err_free_samplerate_trigger;
 
-       ret = request_threaded_irq(irq, xadc->ops->interrupt_handler,
-                               xadc->ops->threaded_interrupt_handler,
-                               0, dev_name(&pdev->dev), indio_dev);
+       ret = request_irq(irq, xadc->ops->interrupt_handler, 0,
+                       dev_name(&pdev->dev), indio_dev);
        if (ret)
                goto err_clk_disable_unprepare;
 
index 54adc5087210bb173afd62bfa36712e4a014eafb..f6f08196564709f1adc18cf0c683811e85fc2a30 100644 (file)
@@ -60,7 +60,6 @@ struct xadc {
 
        enum xadc_external_mux_mode external_mux_mode;
 
-       unsigned int zynq_alarm;
        unsigned int zynq_masked_alarm;
        unsigned int zynq_intmask;
        struct delayed_work zynq_unmask_work;
@@ -79,7 +78,6 @@ struct xadc_ops {
        void (*update_alarm)(struct xadc *, unsigned int);
        unsigned long (*get_dclk_rate)(struct xadc *);
        irqreturn_t (*interrupt_handler)(int, void *);
-       irqreturn_t (*threaded_interrupt_handler)(int, void *);
 
        unsigned int flags;
 };
index 6da31e4dbdd4833332a6888115eb29f458c4c3de..102c7174da5bf2485cc0fb7343cea2e390c1c8f3 100644 (file)
@@ -195,6 +195,7 @@ static const struct spi_device_id ad8366_id[] = {
        {"ad8366", 0},
        {}
 };
+MODULE_DEVICE_TABLE(spi, ad8366_id);
 
 static struct spi_driver ad8366_driver = {
        .driver = {
diff --git a/drivers/iio/buffer/Kconfig b/drivers/iio/buffer/Kconfig
new file mode 100644 (file)
index 0000000..0a7b2fd
--- /dev/null
@@ -0,0 +1,24 @@
+#
+# Industrial I/O generic buffer implementations
+#
+# When adding new entries keep the list in alphabetical order
+
+config IIO_BUFFER_CB
+       tristate "IIO callback buffer used for push in-kernel interfaces"
+       help
+         Should be selected by any drivers that do in-kernel push
+         usage.  That is, those where the data is pushed to the consumer.
+
+config IIO_KFIFO_BUF
+       tristate "Industrial I/O buffering based on kfifo"
+       help
+         A simple fifo based on kfifo.  Note that this currently provides
+         no buffer events so it is up to userspace to work out how
+         often to read from the buffer.
+
+config IIO_TRIGGERED_BUFFER
+       tristate
+       select IIO_TRIGGER
+       select IIO_KFIFO_BUF
+       help
+         Provides helper functions for setting up triggered buffers.
diff --git a/drivers/iio/buffer/Makefile b/drivers/iio/buffer/Makefile
new file mode 100644 (file)
index 0000000..4d193b9
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the industrial I/O buffer implementations
+#
+
+# When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_IIO_BUFFER_CB) += industrialio-buffer-cb.o
+obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
+obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
similarity index 89%
rename from drivers/iio/buffer_cb.c
rename to drivers/iio/buffer/industrialio-buffer-cb.c
index 1648e6e5a8483bc77ce5c9a8352131d3ff6c99a3..323079c3ccce6677492e0855a2e9e20d2a200217 100644 (file)
@@ -1,4 +1,12 @@
+/* The industrial I/O callback buffer
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/export.h>
@@ -124,3 +132,7 @@ struct iio_channel
        return cb_buffer->channels;
 }
 EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels);
+
+MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
+MODULE_DESCRIPTION("Industrial I/O callback buffer");
+MODULE_LICENSE("GPL");
diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
new file mode 100644 (file)
index 0000000..3061b72
--- /dev/null
@@ -0,0 +1,15 @@
+#
+# Chemical sensors
+#
+
+menu "Chemical Sensors"
+
+config VZ89X
+       tristate "SGX Sensortech MiCS VZ89X VOC sensor"
+       depends on I2C
+       help
+         Say Y here to build I2C interface support for the SGX
+         Sensortech MiCS VZ89X VOC (Volatile Organic Compounds)
+         sensors
+
+endmenu
diff --git a/drivers/iio/chemical/Makefile b/drivers/iio/chemical/Makefile
new file mode 100644 (file)
index 0000000..7292f2d
--- /dev/null
@@ -0,0 +1,6 @@
+#
+# Makefile for IIO chemical sensors
+#
+
+# When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_VZ89X)            += vz89x.o
diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
new file mode 100644 (file)
index 0000000..11e59a5
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+ * vz89x.c - Support for SGX Sensortech MiCS VZ89X VOC sensors
+ *
+ * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#define VZ89X_REG_MEASUREMENT          0x09
+#define VZ89X_REG_MEASUREMENT_SIZE     6
+
+#define VZ89X_VOC_CO2_IDX              0
+#define VZ89X_VOC_SHORT_IDX            1
+#define VZ89X_VOC_TVOC_IDX             2
+#define VZ89X_VOC_RESISTANCE_IDX       3
+
+struct vz89x_data {
+       struct i2c_client *client;
+       struct mutex lock;
+       unsigned long last_update;
+
+       u8 buffer[VZ89X_REG_MEASUREMENT_SIZE];
+};
+
+static const struct iio_chan_spec vz89x_channels[] = {
+       {
+               .type = IIO_CONCENTRATION,
+               .channel2 = IIO_MOD_CO2,
+               .modified = 1,
+               .info_mask_separate =
+                       BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
+               .address = VZ89X_VOC_CO2_IDX,
+       },
+       {
+               .type = IIO_CONCENTRATION,
+               .channel2 = IIO_MOD_VOC,
+               .modified = 1,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .address = VZ89X_VOC_SHORT_IDX,
+               .extend_name = "short",
+       },
+       {
+               .type = IIO_CONCENTRATION,
+               .channel2 = IIO_MOD_VOC,
+               .modified = 1,
+               .info_mask_separate =
+                       BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_RAW),
+               .address = VZ89X_VOC_TVOC_IDX,
+       },
+       {
+               .type = IIO_RESISTANCE,
+               .info_mask_separate =
+                       BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+               .address = VZ89X_VOC_RESISTANCE_IDX,
+       },
+};
+
+static IIO_CONST_ATTR(in_concentration_co2_scale, "0.00000698689");
+static IIO_CONST_ATTR(in_concentration_voc_scale, "0.00000000436681223");
+
+static struct attribute *vz89x_attributes[] = {
+       &iio_const_attr_in_concentration_co2_scale.dev_attr.attr,
+       &iio_const_attr_in_concentration_voc_scale.dev_attr.attr,
+       NULL,
+};
+
+static const struct attribute_group vz89x_attrs_group = {
+       .attrs = vz89x_attributes,
+};
+
+/*
+ * Chipset sometime updates in the middle of a reading causing it to reset the
+ * data pointer, and causing invalid reading of previous data.
+ * We can check for this by reading MSB of the resistance reading that is
+ * always zero, and by also confirming the VOC_short isn't zero.
+ */
+
+static int vz89x_measurement_is_valid(struct vz89x_data *data)
+{
+       if (data->buffer[VZ89X_VOC_SHORT_IDX] == 0)
+               return 1;
+
+       return !!(data->buffer[VZ89X_REG_MEASUREMENT_SIZE - 1] > 0);
+}
+
+static int vz89x_get_measurement(struct vz89x_data *data)
+{
+       int ret;
+       int i;
+
+       /* sensor can only be polled once a second max per datasheet */
+       if (!time_after(jiffies, data->last_update + HZ))
+               return 0;
+
+       ret = i2c_smbus_write_word_data(data->client,
+                                       VZ89X_REG_MEASUREMENT, 0);
+       if (ret < 0)
+               return ret;
+
+       for (i = 0; i < VZ89X_REG_MEASUREMENT_SIZE; i++) {
+               ret = i2c_smbus_read_byte(data->client);
+               if (ret < 0)
+                       return ret;
+               data->buffer[i] = ret;
+       }
+
+       ret = vz89x_measurement_is_valid(data);
+       if (ret)
+               return -EAGAIN;
+
+       data->last_update = jiffies;
+
+       return 0;
+}
+
+static int vz89x_get_resistance_reading(struct vz89x_data *data)
+{
+       u8 *buf = &data->buffer[VZ89X_VOC_RESISTANCE_IDX];
+
+       return buf[0] | (buf[1] << 8);
+}
+
+static int vz89x_read_raw(struct iio_dev *indio_dev,
+                         struct iio_chan_spec const *chan, int *val,
+                         int *val2, long mask)
+{
+       struct vz89x_data *data = iio_priv(indio_dev);
+       int ret = -EINVAL;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               mutex_lock(&data->lock);
+               ret = vz89x_get_measurement(data);
+               mutex_unlock(&data->lock);
+
+               if (ret)
+                       return ret;
+
+               switch (chan->address) {
+               case VZ89X_VOC_CO2_IDX:
+               case VZ89X_VOC_SHORT_IDX:
+               case VZ89X_VOC_TVOC_IDX:
+                       *val = data->buffer[chan->address];
+                       return IIO_VAL_INT;
+               case VZ89X_VOC_RESISTANCE_IDX:
+                       *val = vz89x_get_resistance_reading(data);
+                       return IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       case IIO_CHAN_INFO_SCALE:
+               switch (chan->type) {
+               case IIO_RESISTANCE:
+                       *val = 10;
+                       return IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       case IIO_CHAN_INFO_OFFSET:
+               switch (chan->address) {
+               case VZ89X_VOC_CO2_IDX:
+                       *val = 44;
+                       *val2 = 250000;
+                       return IIO_VAL_INT_PLUS_MICRO;
+               case VZ89X_VOC_TVOC_IDX:
+                       *val = -13;
+                       return IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+       }
+
+       return ret;
+}
+
+static const struct iio_info vz89x_info = {
+       .attrs          = &vz89x_attrs_group,
+       .read_raw       = vz89x_read_raw,
+       .driver_module  = THIS_MODULE,
+};
+
+static int vz89x_probe(struct i2c_client *client,
+                      const struct i2c_device_id *id)
+{
+       struct iio_dev *indio_dev;
+       struct vz89x_data *data;
+
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA |
+                                    I2C_FUNC_SMBUS_BYTE))
+               return -ENODEV;
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       data = iio_priv(indio_dev);
+       i2c_set_clientdata(client, indio_dev);
+       data->client = client;
+       data->last_update = jiffies - HZ;
+       mutex_init(&data->lock);
+
+       indio_dev->dev.parent = &client->dev;
+       indio_dev->info = &vz89x_info,
+       indio_dev->name = dev_name(&client->dev);
+       indio_dev->modes = INDIO_DIRECT_MODE;
+
+       indio_dev->channels = vz89x_channels;
+       indio_dev->num_channels = ARRAY_SIZE(vz89x_channels);
+
+       return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id vz89x_id[] = {
+       { "vz89x", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, vz89x_id);
+
+static const struct of_device_id vz89x_dt_ids[] = {
+       { .compatible = "sgx,vz89x" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, vz89x_dt_ids);
+
+static struct i2c_driver vz89x_driver = {
+       .driver = {
+               .name   = "vz89x",
+               .of_match_table = of_match_ptr(vz89x_dt_ids),
+       },
+       .probe = vz89x_probe,
+       .id_table = vz89x_id,
+};
+module_i2c_driver(vz89x_driver);
+
+MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
+MODULE_DESCRIPTION("SGX Sensortech MiCS VZ89X VOC sensors");
+MODULE_LICENSE("GPL v2");
index 790f106d719ce83eb683442696e669c52ba07b2f..26a6026de6147a90c95da67f54a8cea8ccab86ef 100644 (file)
@@ -3,5 +3,6 @@
 #
 
 source "drivers/iio/common/hid-sensors/Kconfig"
+source "drivers/iio/common/ms_sensors/Kconfig"
 source "drivers/iio/common/ssp_sensors/Kconfig"
 source "drivers/iio/common/st_sensors/Kconfig"
index b1e4d9c9591c742b10dfa64e98f93223b8f8e744..585da6a1b18821048dea803b5b66169683c1b255 100644 (file)
@@ -8,5 +8,6 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-y += hid-sensors/
+obj-y += ms_sensors/
 obj-y += ssp_sensors/
 obj-y += st_sensors/
diff --git a/drivers/iio/common/ms_sensors/Kconfig b/drivers/iio/common/ms_sensors/Kconfig
new file mode 100644 (file)
index 0000000..b28a92b
--- /dev/null
@@ -0,0 +1,6 @@
+#
+# Measurements Specialties sensors common library
+#
+
+config IIO_MS_SENSORS_I2C
+        tristate
diff --git a/drivers/iio/common/ms_sensors/Makefile b/drivers/iio/common/ms_sensors/Makefile
new file mode 100644 (file)
index 0000000..7846428
--- /dev/null
@@ -0,0 +1,5 @@
+#
+# Makefile for the Measurement Specialties sensor common modules.
+#
+
+obj-$(CONFIG_IIO_MS_SENSORS_I2C) += ms_sensors_i2c.o
diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.c b/drivers/iio/common/ms_sensors/ms_sensors_i2c.c
new file mode 100644 (file)
index 0000000..669dc7c
--- /dev/null
@@ -0,0 +1,652 @@
+/*
+ * Measurements Specialties driver common i2c functions
+ *
+ * Copyright (c) 2015 Measurement-Specialties
+ *
+ * Licensed under the GPL-2.
+ */
+
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+
+#include "ms_sensors_i2c.h"
+
+/* Conversion times in us */
+static const u16 ms_sensors_ht_t_conversion_time[] = { 50000, 25000,
+                                                      13000, 7000 };
+static const u16 ms_sensors_ht_h_conversion_time[] = { 16000, 3000,
+                                                      5000, 8000 };
+static const u16 ms_sensors_tp_conversion_time[] = { 500, 1100, 2100,
+                                                    4100, 8220, 16440 };
+
+#define MS_SENSORS_SERIAL_READ_MSB             0xFA0F
+#define MS_SENSORS_SERIAL_READ_LSB             0xFCC9
+#define MS_SENSORS_CONFIG_REG_WRITE            0xE6
+#define MS_SENSORS_CONFIG_REG_READ             0xE7
+#define MS_SENSORS_HT_T_CONVERSION_START       0xF3
+#define MS_SENSORS_HT_H_CONVERSION_START       0xF5
+
+#define MS_SENSORS_TP_PROM_READ                        0xA0
+#define MS_SENSORS_TP_T_CONVERSION_START       0x50
+#define MS_SENSORS_TP_P_CONVERSION_START       0x40
+#define MS_SENSORS_TP_ADC_READ                 0x00
+
+#define MS_SENSORS_NO_READ_CMD                 0xFF
+
+/**
+ * ms_sensors_reset() - Reset function
+ * @cli:       pointer to device client
+ * @cmd:       reset cmd. Depends on device in use
+ * @delay:     usleep minimal delay after reset command is issued
+ *
+ * Generic I2C reset function for Measurement Specialties devices.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_reset(void *cli, u8 cmd, unsigned int delay)
+{
+       int ret;
+       struct i2c_client *client = cli;
+
+       ret = i2c_smbus_write_byte(client, cmd);
+       if (ret) {
+               dev_err(&client->dev, "Failed to reset device\n");
+               return ret;
+       }
+       usleep_range(delay, delay + 1000);
+
+       return 0;
+}
+EXPORT_SYMBOL(ms_sensors_reset);
+
+/**
+ * ms_sensors_read_prom_word() - PROM word read function
+ * @cli:       pointer to device client
+ * @cmd:       PROM read cmd. Depends on device and prom id
+ * @word:      pointer to word destination value
+ *
+ * Generic i2c prom word read function for Measurement Specialties devices.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_read_prom_word(void *cli, int cmd, u16 *word)
+{
+       int ret;
+       struct i2c_client *client = (struct i2c_client *)cli;
+
+       ret = i2c_smbus_read_word_swapped(client, cmd);
+       if (ret < 0) {
+               dev_err(&client->dev, "Failed to read prom word\n");
+               return ret;
+       }
+       *word = ret;
+
+       return 0;
+}
+EXPORT_SYMBOL(ms_sensors_read_prom_word);
+
+/**
+ * ms_sensors_convert_and_read() - ADC conversion & read function
+ * @cli:       pointer to device client
+ * @conv:      ADC conversion command. Depends on device in use
+ * @rd:                ADC read command. Depends on device in use
+ * @delay:     usleep minimal delay after conversion command is issued
+ * @adc:       pointer to ADC destination value
+ *
+ * Generic ADC conversion & read function for Measurement Specialties
+ * devices.
+ * The function will issue conversion command, sleep appopriate delay, and
+ * issue command to read ADC.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_convert_and_read(void *cli, u8 conv, u8 rd,
+                               unsigned int delay, u32 *adc)
+{
+       int ret;
+        __be32 buf = 0;
+       struct i2c_client *client = (struct i2c_client *)cli;
+
+       /* Trigger conversion */
+       ret = i2c_smbus_write_byte(client, conv);
+       if (ret)
+               goto err;
+       usleep_range(delay, delay + 1000);
+
+       /* Retrieve ADC value */
+       if (rd != MS_SENSORS_NO_READ_CMD)
+               ret = i2c_smbus_read_i2c_block_data(client, rd, 3, (u8 *)&buf);
+       else
+               ret = i2c_master_recv(client, (u8 *)&buf, 3);
+       if (ret < 0)
+               goto err;
+
+       dev_dbg(&client->dev, "ADC raw value : %x\n", be32_to_cpu(buf) >> 8);
+       *adc = be32_to_cpu(buf) >> 8;
+
+       return 0;
+err:
+       dev_err(&client->dev, "Unable to make sensor adc conversion\n");
+       return ret;
+}
+EXPORT_SYMBOL(ms_sensors_convert_and_read);
+
+/**
+ * ms_sensors_crc_valid() - CRC check function
+ * @value:     input and CRC compare value
+ *
+ * Cyclic Redundancy Check function used in TSYS02D, HTU21, MS8607.
+ * This function performs a x^8 + x^5 + x^4 + 1 polynomial CRC.
+ * The argument contains CRC value in LSB byte while the bytes 1 and 2
+ * are used for CRC computation.
+ *
+ * Return: 1 if CRC is valid, 0 otherwise.
+ */
+static bool ms_sensors_crc_valid(u32 value)
+{
+       u32 polynom = 0x988000; /* x^8 + x^5 + x^4 + 1 */
+       u32 msb = 0x800000;
+       u32 mask = 0xFF8000;
+       u32 result = value & 0xFFFF00;
+       u8 crc = value & 0xFF;
+
+       while (msb != 0x80) {
+               if (result & msb)
+                       result = ((result ^ polynom) & mask)
+                               | (result & ~mask);
+               msb >>= 1;
+               mask >>= 1;
+               polynom >>= 1;
+       }
+
+       return result == crc;
+}
+
+/**
+ * ms_sensors_read_serial() - Serial number read function
+ * @cli:       pointer to i2c client
+ * @sn:                pointer to 64-bits destination value
+ *
+ * Generic i2c serial number read function for Measurement Specialties devices.
+ * This function is used for TSYS02d, HTU21, MS8607 chipset.
+ * Refer to datasheet:
+ *     http://www.meas-spec.com/downloads/HTU2X_Serial_Number_Reading.pdf
+ *
+ * Sensor raw MSB serial number format is the following :
+ *     [ SNB3, CRC, SNB2, CRC, SNB1, CRC, SNB0, CRC]
+ * Sensor raw LSB serial number format is the following :
+ *     [ X, X, SNC1, SNC0, CRC, SNA1, SNA0, CRC]
+ * The resulting serial number is following :
+ *     [ SNA1, SNA0, SNB3, SNB2, SNB1, SNB0, SNC1, SNC0]
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_read_serial(struct i2c_client *client, u64 *sn)
+{
+       u8 i;
+       __be64 rcv_buf = 0;
+       u64 rcv_val;
+       __be16 send_buf;
+       int ret;
+
+       struct i2c_msg msg[2] = {
+               {
+                .addr = client->addr,
+                .flags = client->flags,
+                .len = 2,
+                .buf = (__u8 *)&send_buf,
+                },
+               {
+                .addr = client->addr,
+                .flags = client->flags | I2C_M_RD,
+                .buf = (__u8 *)&rcv_buf,
+                },
+       };
+
+       /* Read MSB part of serial number */
+       send_buf = cpu_to_be16(MS_SENSORS_SERIAL_READ_MSB);
+       msg[1].len = 8;
+       ret = i2c_transfer(client->adapter, msg, 2);
+       if (ret < 0) {
+               dev_err(&client->dev, "Unable to read device serial number");
+               return ret;
+       }
+
+       rcv_val = be64_to_cpu(rcv_buf);
+       dev_dbg(&client->dev, "Serial MSB raw : %llx\n", rcv_val);
+
+       for (i = 0; i < 64; i += 16) {
+               if (!ms_sensors_crc_valid((rcv_val >> i) & 0xFFFF))
+                       return -ENODEV;
+       }
+
+       *sn = (((rcv_val >> 32) & 0xFF000000) |
+              ((rcv_val >> 24) & 0x00FF0000) |
+              ((rcv_val >> 16) & 0x0000FF00) |
+              ((rcv_val >> 8) & 0x000000FF)) << 16;
+
+       /* Read LSB part of serial number */
+       send_buf = cpu_to_be16(MS_SENSORS_SERIAL_READ_LSB);
+       msg[1].len = 6;
+       rcv_buf = 0;
+       ret = i2c_transfer(client->adapter, msg, 2);
+       if (ret < 0) {
+               dev_err(&client->dev, "Unable to read device serial number");
+               return ret;
+       }
+
+       rcv_val = be64_to_cpu(rcv_buf) >> 16;
+       dev_dbg(&client->dev, "Serial MSB raw : %llx\n", rcv_val);
+
+       for (i = 0; i < 48; i += 24) {
+               if (!ms_sensors_crc_valid((rcv_val >> i) & 0xFFFFFF))
+                       return -ENODEV;
+       }
+
+       *sn |= (rcv_val & 0xFFFF00) << 40 | (rcv_val >> 32);
+
+       return 0;
+}
+EXPORT_SYMBOL(ms_sensors_read_serial);
+
+static int ms_sensors_read_config_reg(struct i2c_client *client,
+                                     u8 *config_reg)
+{
+       int ret;
+
+       ret = i2c_smbus_write_byte(client, MS_SENSORS_CONFIG_REG_READ);
+       if (ret) {
+               dev_err(&client->dev, "Unable to read config register");
+               return ret;
+       }
+
+       ret = i2c_master_recv(client, config_reg, 1);
+       if (ret < 0) {
+               dev_err(&client->dev, "Unable to read config register");
+               return ret;
+       }
+       dev_dbg(&client->dev, "Config register :%x\n", *config_reg);
+
+       return 0;
+}
+
+/**
+ * ms_sensors_write_resolution() - Set resolution function
+ * @dev_data:  pointer to temperature/humidity device data
+ * @i:         resolution index to set
+ *
+ * This function will program the appropriate resolution based on the index
+ * provided when user space will set samp_freq channel.
+ * This function is used for TSYS02D, HTU21 and MS8607 chipsets.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+ssize_t ms_sensors_write_resolution(struct ms_ht_dev *dev_data,
+                                   u8 i)
+{
+       u8 config_reg;
+       int ret;
+
+       ret = ms_sensors_read_config_reg(dev_data->client, &config_reg);
+       if (ret)
+               return ret;
+
+       config_reg &= 0x7E;
+       config_reg |= ((i & 1) << 7) + ((i & 2) >> 1);
+
+       return i2c_smbus_write_byte_data(dev_data->client,
+                                        MS_SENSORS_CONFIG_REG_WRITE,
+                                        config_reg);
+}
+EXPORT_SYMBOL(ms_sensors_write_resolution);
+
+/**
+ * ms_sensors_show_battery_low() - Show device battery low indicator
+ * @dev_data:  pointer to temperature/humidity device data
+ * @buf:       pointer to char buffer to write result
+ *
+ * This function will read battery indicator value in the device and
+ * return 1 if the device voltage is below 2.25V.
+ * This function is used for TSYS02D, HTU21 and MS8607 chipsets.
+ *
+ * Return: length of sprintf on success, negative errno otherwise.
+ */
+ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data,
+                                   char *buf)
+{
+       int ret;
+       u8 config_reg;
+
+       mutex_lock(&dev_data->lock);
+       ret = ms_sensors_read_config_reg(dev_data->client, &config_reg);
+       mutex_unlock(&dev_data->lock);
+       if (ret)
+               return ret;
+
+       return sprintf(buf, "%d\n", (config_reg & 0x40) >> 6);
+}
+EXPORT_SYMBOL(ms_sensors_show_battery_low);
+
+/**
+ * ms_sensors_show_heater() - Show device heater
+ * @dev_data:  pointer to temperature/humidity device data
+ * @buf:       pointer to char buffer to write result
+ *
+ * This function will read heater enable value in the device and
+ * return 1 if the heater is enabled.
+ * This function is used for HTU21 and MS8607 chipsets.
+ *
+ * Return: length of sprintf on success, negative errno otherwise.
+ */
+ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data,
+                              char *buf)
+{
+       u8 config_reg;
+       int ret;
+
+       mutex_lock(&dev_data->lock);
+       ret = ms_sensors_read_config_reg(dev_data->client, &config_reg);
+       mutex_unlock(&dev_data->lock);
+       if (ret)
+               return ret;
+
+       return sprintf(buf, "%d\n", (config_reg & 0x4) >> 2);
+}
+EXPORT_SYMBOL(ms_sensors_show_heater);
+
+/**
+ * ms_sensors_write_heater() - Write device heater
+ * @dev_data:  pointer to temperature/humidity device data
+ * @buf:       pointer to char buffer from user space
+ * @len:       length of buf
+ *
+ * This function will write 1 or 0 value in the device
+ * to enable or disable heater.
+ * This function is used for HTU21 and MS8607 chipsets.
+ *
+ * Return: length of buffer, negative errno otherwise.
+ */
+ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data,
+                               const char *buf, size_t len)
+{
+       u8 val, config_reg;
+       int ret;
+
+       ret = kstrtou8(buf, 10, &val);
+       if (ret)
+               return ret;
+
+       if (val > 1)
+               return -EINVAL;
+
+       mutex_lock(&dev_data->lock);
+       ret = ms_sensors_read_config_reg(dev_data->client, &config_reg);
+       if (ret) {
+               mutex_unlock(&dev_data->lock);
+               return ret;
+       }
+
+       config_reg &= 0xFB;
+       config_reg |= val << 2;
+
+       ret = i2c_smbus_write_byte_data(dev_data->client,
+                                       MS_SENSORS_CONFIG_REG_WRITE,
+                                       config_reg);
+       mutex_unlock(&dev_data->lock);
+       if (ret) {
+               dev_err(&dev_data->client->dev, "Unable to write config register\n");
+               return ret;
+       }
+
+       return len;
+}
+EXPORT_SYMBOL(ms_sensors_write_heater);
+
+/**
+ * ms_sensors_ht_read_temperature() - Read temperature
+ * @dev_data:  pointer to temperature/humidity device data
+ * @temperature:pointer to temperature destination value
+ *
+ * This function will get temperature ADC value from the device,
+ * check the CRC and compute the temperature value.
+ * This function is used for TSYS02D, HTU21 and MS8607 chipsets.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_ht_read_temperature(struct ms_ht_dev *dev_data,
+                                  s32 *temperature)
+{
+       int ret;
+       u32 adc;
+       u16 delay;
+
+       mutex_lock(&dev_data->lock);
+       delay = ms_sensors_ht_t_conversion_time[dev_data->res_index];
+       ret = ms_sensors_convert_and_read(dev_data->client,
+                                         MS_SENSORS_HT_T_CONVERSION_START,
+                                         MS_SENSORS_NO_READ_CMD,
+                                         delay, &adc);
+       mutex_unlock(&dev_data->lock);
+       if (ret)
+               return ret;
+
+       if (!ms_sensors_crc_valid(adc)) {
+               dev_err(&dev_data->client->dev,
+                       "Temperature read crc check error\n");
+               return -ENODEV;
+       }
+
+       /* Temperature algorithm */
+       *temperature = (((s64)(adc >> 8) * 175720) >> 16) - 46850;
+
+       return 0;
+}
+EXPORT_SYMBOL(ms_sensors_ht_read_temperature);
+
+/**
+ * ms_sensors_ht_read_humidity() - Read humidity
+ * @dev_data:  pointer to temperature/humidity device data
+ * @humidity:  pointer to humidity destination value
+ *
+ * This function will get humidity ADC value from the device,
+ * check the CRC and compute the temperature value.
+ * This function is used for HTU21 and MS8607 chipsets.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_ht_read_humidity(struct ms_ht_dev *dev_data,
+                               u32 *humidity)
+{
+       int ret;
+       u32 adc;
+       u16 delay;
+
+       mutex_lock(&dev_data->lock);
+       delay = ms_sensors_ht_h_conversion_time[dev_data->res_index];
+       ret = ms_sensors_convert_and_read(dev_data->client,
+                                         MS_SENSORS_HT_H_CONVERSION_START,
+                                         MS_SENSORS_NO_READ_CMD,
+                                         delay, &adc);
+       mutex_unlock(&dev_data->lock);
+       if (ret)
+               return ret;
+
+       if (!ms_sensors_crc_valid(adc)) {
+               dev_err(&dev_data->client->dev,
+                       "Humidity read crc check error\n");
+               return -ENODEV;
+       }
+
+       /* Humidity algorithm */
+       *humidity = (((s32)(adc >> 8) * 12500) >> 16) * 10 - 6000;
+       if (*humidity >= 100000)
+               *humidity = 100000;
+
+       return 0;
+}
+EXPORT_SYMBOL(ms_sensors_ht_read_humidity);
+
+/**
+ * ms_sensors_tp_crc_valid() - CRC check function for
+ *     Temperature and pressure devices.
+ *     This function is only used when reading PROM coefficients
+ *
+ * @prom:      pointer to PROM coefficients array
+ * @len:       length of PROM coefficients array
+ *
+ * Return: True if CRC is ok.
+ */
+static bool ms_sensors_tp_crc_valid(u16 *prom, u8 len)
+{
+       unsigned int cnt, n_bit;
+       u16 n_rem = 0x0000, crc_read = prom[0], crc = (*prom & 0xF000) >> 12;
+
+       prom[len - 1] = 0;
+       prom[0] &= 0x0FFF;      /* Clear the CRC computation part */
+
+       for (cnt = 0; cnt < len * 2; cnt++) {
+               if (cnt % 2 == 1)
+                       n_rem ^= prom[cnt >> 1] & 0x00FF;
+               else
+                       n_rem ^= prom[cnt >> 1] >> 8;
+
+               for (n_bit = 8; n_bit > 0; n_bit--) {
+                       if (n_rem & 0x8000)
+                               n_rem = (n_rem << 1) ^ 0x3000;
+                       else
+                               n_rem <<= 1;
+               }
+       }
+       n_rem >>= 12;
+       prom[0] = crc_read;
+
+       return n_rem == crc;
+}
+
+/**
+ * ms_sensors_tp_read_prom() - prom coeff read function
+ * @dev_data:  pointer to temperature/pressure device data
+ *
+ * This function will read prom coefficients and check CRC.
+ * This function is used for MS5637 and MS8607 chipsets.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data)
+{
+       int i, ret;
+
+       for (i = 0; i < MS_SENSORS_TP_PROM_WORDS_NB; i++) {
+               ret = ms_sensors_read_prom_word(
+                       dev_data->client,
+                       MS_SENSORS_TP_PROM_READ + (i << 1),
+                       &dev_data->prom[i]);
+
+               if (ret)
+                       return ret;
+       }
+
+       if (!ms_sensors_tp_crc_valid(dev_data->prom,
+                                    MS_SENSORS_TP_PROM_WORDS_NB + 1)) {
+               dev_err(&dev_data->client->dev,
+                       "Calibration coefficients crc check error\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(ms_sensors_tp_read_prom);
+
+/**
+ * ms_sensors_read_temp_and_pressure() - read temp and pressure
+ * @dev_data:  pointer to temperature/pressure device data
+ * @temperature:pointer to temperature destination value
+ * @pressure:  pointer to pressure destination value
+ *
+ * This function will read ADC and compute pressure and temperature value.
+ * This function is used for MS5637 and MS8607 chipsets.
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
+                                     int *temperature,
+                                     unsigned int *pressure)
+{
+       int ret;
+       u32 t_adc, p_adc;
+       s32 dt, temp;
+       s64 off, sens, t2, off2, sens2;
+       u16 *prom = dev_data->prom, delay;
+
+       mutex_lock(&dev_data->lock);
+       delay = ms_sensors_tp_conversion_time[dev_data->res_index];
+
+       ret = ms_sensors_convert_and_read(
+                                       dev_data->client,
+                                       MS_SENSORS_TP_T_CONVERSION_START +
+                                               dev_data->res_index * 2,
+                                       MS_SENSORS_TP_ADC_READ,
+                                       delay, &t_adc);
+       if (ret) {
+               mutex_unlock(&dev_data->lock);
+               return ret;
+       }
+
+       ret = ms_sensors_convert_and_read(
+                                       dev_data->client,
+                                       MS_SENSORS_TP_P_CONVERSION_START +
+                                               dev_data->res_index * 2,
+                                       MS_SENSORS_TP_ADC_READ,
+                                       delay, &p_adc);
+       mutex_unlock(&dev_data->lock);
+       if (ret)
+               return ret;
+
+       dt = (s32)t_adc - (prom[5] << 8);
+
+       /* Actual temperature = 2000 + dT * TEMPSENS */
+       temp = 2000 + (((s64)dt * prom[6]) >> 23);
+
+       /* Second order temperature compensation */
+       if (temp < 2000) {
+               s64 tmp = (s64)temp - 2000;
+
+               t2 = (3 * ((s64)dt * (s64)dt)) >> 33;
+               off2 = (61 * tmp * tmp) >> 4;
+               sens2 = (29 * tmp * tmp) >> 4;
+
+               if (temp < -1500) {
+                       s64 tmp = (s64)temp + 1500;
+
+                       off2 += 17 * tmp * tmp;
+                       sens2 += 9 * tmp * tmp;
+               }
+       } else {
+               t2 = (5 * ((s64)dt * (s64)dt)) >> 38;
+               off2 = 0;
+               sens2 = 0;
+       }
+
+       /* OFF = OFF_T1 + TCO * dT */
+       off = (((s64)prom[2]) << 17) + ((((s64)prom[4]) * (s64)dt) >> 6);
+       off -= off2;
+
+       /* Sensitivity at actual temperature = SENS_T1 + TCS * dT */
+       sens = (((s64)prom[1]) << 16) + (((s64)prom[3] * dt) >> 7);
+       sens -= sens2;
+
+       /* Temperature compensated pressure = D1 * SENS - OFF */
+       *temperature = (temp - t2) * 10;
+       *pressure = (u32)(((((s64)p_adc * sens) >> 21) - off) >> 15);
+
+       return 0;
+}
+EXPORT_SYMBOL(ms_sensors_read_temp_and_pressure);
+
+MODULE_DESCRIPTION("Measurement-Specialties common i2c driver");
+MODULE_AUTHOR("William Markezana <william.markezana@meas-spec.com>");
+MODULE_AUTHOR("Ludovic Tancerel <ludovic.tancerel@maplehightech.com>");
+MODULE_LICENSE("GPL v2");
+
diff --git a/drivers/iio/common/ms_sensors/ms_sensors_i2c.h b/drivers/iio/common/ms_sensors/ms_sensors_i2c.h
new file mode 100644 (file)
index 0000000..7b614ad
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Measurements Specialties common sensor driver
+ *
+ * Copyright (c) 2015 Measurement-Specialties
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _MS_SENSORS_I2C_H
+#define _MS_SENSORS_I2C_H
+
+#include <linux/i2c.h>
+#include <linux/mutex.h>
+
+#define MS_SENSORS_TP_PROM_WORDS_NB            7
+
+/**
+ * struct ms_ht_dev - Humidity/Temperature sensor device structure
+ * @client:    i2c client
+ * @lock:      lock protecting the i2c conversion
+ * @res_index: index to selected sensor resolution
+ */
+struct ms_ht_dev {
+       struct i2c_client *client;
+       struct mutex lock;
+       u8 res_index;
+};
+
+/**
+ * struct ms_tp_dev - Temperature/Pressure sensor device structure
+ * @client:    i2c client
+ * @lock:      lock protecting the i2c conversion
+ * @prom:      array of PROM coefficients used for conversion. Added element
+ *              for CRC computation
+ * @res_index: index to selected sensor resolution
+ */
+struct ms_tp_dev {
+       struct i2c_client *client;
+       struct mutex lock;
+       u16 prom[MS_SENSORS_TP_PROM_WORDS_NB + 1];
+       u8 res_index;
+};
+
+int ms_sensors_reset(void *cli, u8 cmd, unsigned int delay);
+int ms_sensors_read_prom_word(void *cli, int cmd, u16 *word);
+int ms_sensors_convert_and_read(void *cli, u8 conv, u8 rd,
+                               unsigned int delay, u32 *adc);
+int ms_sensors_read_serial(struct i2c_client *client, u64 *sn);
+ssize_t ms_sensors_show_serial(struct ms_ht_dev *dev_data, char *buf);
+ssize_t ms_sensors_write_resolution(struct ms_ht_dev *dev_data, u8 i);
+ssize_t ms_sensors_show_battery_low(struct ms_ht_dev *dev_data, char *buf);
+ssize_t ms_sensors_show_heater(struct ms_ht_dev *dev_data, char *buf);
+ssize_t ms_sensors_write_heater(struct ms_ht_dev *dev_data,
+                               const char *buf, size_t len);
+int ms_sensors_ht_read_temperature(struct ms_ht_dev *dev_data,
+                                  s32 *temperature);
+int ms_sensors_ht_read_humidity(struct ms_ht_dev *dev_data,
+                               u32 *humidity);
+int ms_sensors_tp_read_prom(struct ms_tp_dev *dev_data);
+int ms_sensors_read_temp_and_pressure(struct ms_tp_dev *dev_data,
+                                     int *temperature,
+                                     unsigned int *pressure);
+
+#endif /* _MS_SENSORS_I2C_H */
index 2e7fdb502645b66f7042220c7d06df7166bde5c4..25258e2c1a82dec3958de9dc92e0ee9f60bdfde2 100644 (file)
@@ -44,6 +44,28 @@ st_sensors_write_data_with_mask_error:
        return err;
 }
 
+int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
+                                 unsigned reg, unsigned writeval,
+                                 unsigned *readval)
+{
+       struct st_sensor_data *sdata = iio_priv(indio_dev);
+       u8 readdata;
+       int err;
+
+       if (!readval)
+               return sdata->tf->write_byte(&sdata->tb, sdata->dev,
+                                            (u8)reg, (u8)writeval);
+
+       err = sdata->tf->read_byte(&sdata->tb, sdata->dev, (u8)reg, &readdata);
+       if (err < 0)
+               return err;
+
+       *readval = (unsigned)readdata;
+
+       return 0;
+}
+EXPORT_SYMBOL(st_sensors_debugfs_reg_access);
+
 static int st_sensors_match_odr(struct st_sensor_settings *sensor_settings,
                        unsigned int odr, struct st_sensor_odr_avl *odr_out)
 {
index 88b2c92e243bccdb1cb20e0d038853500f8b3fd0..4e4c20d6d8b57a763bb043eaf47af0d76709204c 100644 (file)
@@ -214,7 +214,6 @@ static struct attribute *ad5504_ev_attributes[] = {
 
 static struct attribute_group ad5504_ev_attribute_group = {
        .attrs = ad5504_ev_attributes,
-       .name = "events",
 };
 
 static irqreturn_t ad5504_event_handler(int irq, void *private)
index 399de2cfeb16b52c75180c88f8435e4102a53be5..e690dd11e99f64fa1270da8132010f34d94d7241 100644 (file)
@@ -281,6 +281,12 @@ static int ad7303_remove(struct spi_device *spi)
        return 0;
 }
 
+static const struct of_device_id ad7303_spi_of_match[] = {
+       { .compatible = "adi,ad7303", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, ad7303_spi_of_match);
+
 static const struct spi_device_id ad7303_spi_ids[] = {
        { "ad7303", 0 },
        {}
@@ -290,6 +296,7 @@ MODULE_DEVICE_TABLE(spi, ad7303_spi_ids);
 static struct spi_driver ad7303_driver = {
        .driver = {
                .name = "ad7303",
+               .of_match_table = of_match_ptr(ad7303_spi_of_match),
        },
        .probe = ad7303_probe,
        .remove = ad7303_remove,
index c23d7fa889ee3fb3a524fd1e7efb144026c7f44e..76e8b044b979702a3fb4925c629484119702a9ff 100644 (file)
@@ -31,7 +31,6 @@
 
 struct m62332_data {
        struct i2c_client       *client;
-       u16                     vref_mv;
        struct regulator        *vcc;
        struct mutex            mutex;
        u8                      raw[M62332_CHANNELS];
@@ -40,8 +39,7 @@ struct m62332_data {
 #endif
 };
 
-static int m62332_set_value(struct iio_dev *indio_dev,
-       u8 val, int channel)
+static int m62332_set_value(struct iio_dev *indio_dev, u8 val, int channel)
 {
        struct m62332_data *data = iio_priv(indio_dev);
        struct i2c_client *client = data->client;
@@ -62,8 +60,8 @@ static int m62332_set_value(struct iio_dev *indio_dev,
                        goto out;
        }
 
-       res = i2c_master_send(client, outbuf, 2);
-       if (res >= 0 && res != 2)
+       res = i2c_master_send(client, outbuf, ARRAY_SIZE(outbuf));
+       if (res >= 0 && res != ARRAY_SIZE(outbuf))
                res = -EIO;
        if (res < 0)
                goto out;
@@ -87,46 +85,52 @@ static int m62332_read_raw(struct iio_dev *indio_dev,
                           struct iio_chan_spec const *chan,
                           int *val,
                           int *val2,
-                          long m)
+                          long mask)
 {
        struct m62332_data *data = iio_priv(indio_dev);
+       int ret;
 
-       switch (m) {
+       switch (mask) {
        case IIO_CHAN_INFO_SCALE:
                /* Corresponds to Vref / 2^(bits) */
-               *val = data->vref_mv;
+               ret = regulator_get_voltage(data->vcc);
+               if (ret < 0)
+                       return ret;
+
+               *val = ret / 1000; /* mV */
                *val2 = 8;
+
                return IIO_VAL_FRACTIONAL_LOG2;
        case IIO_CHAN_INFO_RAW:
                *val = data->raw[chan->channel];
+
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_OFFSET:
                *val = 1;
+
                return IIO_VAL_INT;
        default:
                break;
        }
+
        return -EINVAL;
 }
 
 static int m62332_write_raw(struct iio_dev *indio_dev,
-       struct iio_chan_spec const *chan, int val, int val2, long mask)
+                           struct iio_chan_spec const *chan, int val, int val2,
+                           long mask)
 {
-       int ret;
-
        switch (mask) {
        case IIO_CHAN_INFO_RAW:
                if (val < 0 || val > 255)
                        return -EINVAL;
 
-               ret = m62332_set_value(indio_dev, val, chan->channel);
-               break;
+               return m62332_set_value(indio_dev, val, chan->channel);
        default:
-               ret = -EINVAL;
                break;
        }
 
-       return ret;
+       return -EINVAL;
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -173,15 +177,15 @@ static const struct iio_info m62332_info = {
        .driver_module = THIS_MODULE,
 };
 
-#define M62332_CHANNEL(chan) {                         \
-       .type = IIO_VOLTAGE,                            \
-       .indexed = 1,                                   \
-       .output = 1,                                    \
-       .channel = (chan),                              \
-       .datasheet_name = "CH" #chan,                   \
-       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |  \
-               BIT(IIO_CHAN_INFO_SCALE) |              \
-               BIT(IIO_CHAN_INFO_OFFSET),              \
+#define M62332_CHANNEL(chan) {                                 \
+       .type = IIO_VOLTAGE,                                    \
+       .indexed = 1,                                           \
+       .output = 1,                                            \
+       .channel = (chan),                                      \
+       .datasheet_name = "CH" #chan,                           \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |  \
+                                   BIT(IIO_CHAN_INFO_OFFSET),  \
 }
 
 static const struct iio_chan_spec m62332_channels[M62332_CHANNELS] = {
@@ -199,6 +203,7 @@ static int m62332_probe(struct i2c_client *client,
        indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
        if (!indio_dev)
                return -ENOMEM;
+
        data = iio_priv(indio_dev);
        i2c_set_clientdata(client, indio_dev);
        data->client = client;
@@ -212,16 +217,11 @@ static int m62332_probe(struct i2c_client *client,
        /* establish that the iio_dev is a child of the i2c device */
        indio_dev->dev.parent = &client->dev;
 
-       indio_dev->num_channels = M62332_CHANNELS;
+       indio_dev->num_channels = ARRAY_SIZE(m62332_channels);
        indio_dev->channels = m62332_channels;
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->info = &m62332_info;
 
-       ret = regulator_get_voltage(data->vcc);
-       if (ret < 0)
-               return ret;
-       data->vref_mv = ret / 1000; /* mV */
-
        ret = iio_map_array_register(indio_dev, client->dev.platform_data);
        if (ret < 0)
                return ret;
@@ -234,6 +234,7 @@ static int m62332_probe(struct i2c_client *client,
 
 err:
        iio_map_array_unregister(indio_dev);
+
        return ret;
 }
 
@@ -243,6 +244,8 @@ static int m62332_remove(struct i2c_client *client)
 
        iio_device_unregister(indio_dev);
        iio_map_array_unregister(indio_dev);
+       m62332_set_value(indio_dev, 0, 0);
+       m62332_set_value(indio_dev, 0, 1);
 
        return 0;
 }
index 28b8748ea8242277e0e0a9aff187c23493096e8d..86e9e112f55430fda8bec9d027448d4625a38f82 100644 (file)
@@ -387,6 +387,7 @@ static const struct of_device_id max5821_of_match[] = {
        { .compatible = "maxim,max5821" },
        { }
 };
+MODULE_DEVICE_TABLE(of, max5821_of_match);
 
 static struct i2c_driver max5821_driver = {
        .driver = {
index b83534cc2ab14bde5fb25819e9a6d854275f2895..d2d824b446f5242c09fe8bb9ac276ab8f2fe746f 100644 (file)
@@ -616,15 +616,24 @@ static int adf4350_remove(struct spi_device *spi)
        return 0;
 }
 
+static const struct of_device_id adf4350_of_match[] = {
+       { .compatible = "adi,adf4350", },
+       { .compatible = "adi,adf4351", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, adf4350_of_match);
+
 static const struct spi_device_id adf4350_id[] = {
        {"adf4350", 4350},
        {"adf4351", 4351},
        {}
 };
+MODULE_DEVICE_TABLE(spi, adf4350_id);
 
 static struct spi_driver adf4350_driver = {
        .driver = {
                .name   = "adf4350",
+               .of_match_table = of_match_ptr(adf4350_of_match),
        },
        .probe          = adf4350_probe,
        .remove         = adf4350_remove,
index 8d2439345673989aeac41d40eebf33e00aac9c99..e816d29d6a62353540e2885156a181e9cefa6b41 100644 (file)
@@ -52,15 +52,26 @@ config ADXRS450
 
 config BMG160
        tristate "BOSCH BMG160 Gyro Sensor"
-       depends on I2C
+       depends on (I2C || SPI_MASTER)
        select IIO_BUFFER
        select IIO_TRIGGERED_BUFFER
+       select BMG160_I2C if (I2C)
+       select BMG160_SPI if (SPI)
        help
-         Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
-         driver. This driver also supports BMI055 gyroscope.
+         Say yes here to build support for BOSCH BMG160 Tri-axis Gyro Sensor
+         driver connected via I2C or SPI. This driver also supports BMI055
+         gyroscope.
 
          This driver can also be built as a module.  If so, the module
-         will be called bmg160.
+         will be called bmg160_i2c or bmg160_spi.
+
+config BMG160_I2C
+       tristate
+       select REGMAP_I2C
+
+config BMG160_SPI
+       tristate
+       select REGMAP_SPI
 
 config HID_SENSOR_GYRO_3D
        depends on HID_SENSOR_HUB
index f46341b3913967c5b5a9941f513b88b4361e8909..f866a4be0667c19bb17c138f0e4508bc3bc67aa4 100644 (file)
@@ -8,7 +8,9 @@ obj-$(CONFIG_ADIS16130) += adis16130.o
 obj-$(CONFIG_ADIS16136) += adis16136.o
 obj-$(CONFIG_ADIS16260) += adis16260.o
 obj-$(CONFIG_ADXRS450) += adxrs450.o
-obj-$(CONFIG_BMG160) += bmg160.o
+obj-$(CONFIG_BMG160) += bmg160_core.o
+obj-$(CONFIG_BMG160_I2C) += bmg160_i2c.o
+obj-$(CONFIG_BMG160_SPI) += bmg160_spi.o
 
 obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
 
diff --git a/drivers/iio/gyro/bmg160.h b/drivers/iio/gyro/bmg160.h
new file mode 100644 (file)
index 0000000..72db723
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef BMG160_H_
+#define BMG160_H_
+
+extern const struct dev_pm_ops bmg160_pm_ops;
+
+int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
+                     const char *name);
+void bmg160_core_remove(struct device *dev);
+
+#endif  /* BMG160_H_ */
similarity index 75%
rename from drivers/iio/gyro/bmg160.c
rename to drivers/iio/gyro/bmg160_core.c
index 460bf715d5417d28ce37cfe3463929e006ecd937..02ff789852a05b411d20aaa7b89e92039305e6cd 100644 (file)
@@ -13,7 +13,6 @@
  */
 
 #include <linux/module.h>
-#include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
@@ -28,8 +27,9 @@
 #include <linux/iio/events.h>
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
+#include <linux/regmap.h>
+#include "bmg160.h"
 
-#define BMG160_DRV_NAME                "bmg160"
 #define BMG160_IRQ_NAME                "bmg160_event"
 #define BMG160_GPIO_NAME               "gpio_int"
 
@@ -97,7 +97,8 @@
 #define BMG160_AUTO_SUSPEND_DELAY_MS   2000
 
 struct bmg160_data {
-       struct i2c_client *client;
+       struct device *dev;
+       struct regmap *regmap;
        struct iio_trigger *dready_trig;
        struct iio_trigger *motion_trig;
        struct mutex mutex;
@@ -108,6 +109,7 @@ struct bmg160_data {
        int slope_thres;
        bool dready_trigger_on;
        bool motion_trigger_on;
+       int irq;
 };
 
 enum bmg160_axis {
@@ -138,10 +140,9 @@ static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
 {
        int ret;
 
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_PMU_LPW, mode);
+       ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
+               dev_err(data->dev, "Error writing reg_pmu_lpw\n");
                return ret;
        }
 
@@ -169,10 +170,9 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
        if (bw_bits < 0)
                return bw_bits;
 
-       ret = i2c_smbus_write_byte_data(data->client, BMG160_REG_PMU_BW,
-                                       bw_bits);
+       ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, bw_bits);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_pmu_bw\n");
+               dev_err(data->dev, "Error writing reg_pmu_bw\n");
                return ret;
        }
 
@@ -184,16 +184,17 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
 static int bmg160_chip_init(struct bmg160_data *data)
 {
        int ret;
+       unsigned int val;
 
-       ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_CHIP_ID);
+       ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_chip_id\n");
+               dev_err(data->dev, "Error reading reg_chip_id\n");
                return ret;
        }
 
-       dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
-       if (ret != BMG160_CHIP_ID_VAL) {
-               dev_err(&data->client->dev, "invalid chip %x\n", ret);
+       dev_dbg(data->dev, "Chip Id %x\n", val);
+       if (val != BMG160_CHIP_ID_VAL) {
+               dev_err(data->dev, "invalid chip %x\n", val);
                return -ENODEV;
        }
 
@@ -210,42 +211,33 @@ static int bmg160_chip_init(struct bmg160_data *data)
                return ret;
 
        /* Set Default Range */
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_RANGE,
-                                       BMG160_RANGE_500DPS);
+       ret = regmap_write(data->regmap, BMG160_REG_RANGE, BMG160_RANGE_500DPS);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_range\n");
+               dev_err(data->dev, "Error writing reg_range\n");
                return ret;
        }
        data->dps_range = BMG160_RANGE_500DPS;
 
-       ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_SLOPE_THRES);
+       ret = regmap_read(data->regmap, BMG160_REG_SLOPE_THRES, &val);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_slope_thres\n");
+               dev_err(data->dev, "Error reading reg_slope_thres\n");
                return ret;
        }
-       data->slope_thres = ret;
+       data->slope_thres = val;
 
        /* Set default interrupt mode */
-       ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1);
+       ret = regmap_update_bits(data->regmap, BMG160_REG_INT_EN_1,
+                                BMG160_INT1_BIT_OD, 0);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_en_1\n");
-               return ret;
-       }
-       ret &= ~BMG160_INT1_BIT_OD;
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_INT_EN_1, ret);
-       if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_en_1\n");
+               dev_err(data->dev, "Error updating bits in reg_int_en_1\n");
                return ret;
        }
 
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_INT_RST_LATCH,
-                                       BMG160_INT_MODE_LATCH_INT |
-                                       BMG160_INT_MODE_LATCH_RESET);
+       ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+                          BMG160_INT_MODE_LATCH_INT |
+                          BMG160_INT_MODE_LATCH_RESET);
        if (ret < 0) {
-               dev_err(&data->client->dev,
+               dev_err(data->dev,
                        "Error writing reg_motion_intr\n");
                return ret;
        }
@@ -259,17 +251,17 @@ static int bmg160_set_power_state(struct bmg160_data *data, bool on)
        int ret;
 
        if (on)
-               ret = pm_runtime_get_sync(&data->client->dev);
+               ret = pm_runtime_get_sync(data->dev);
        else {
-               pm_runtime_mark_last_busy(&data->client->dev);
-               ret = pm_runtime_put_autosuspend(&data->client->dev);
+               pm_runtime_mark_last_busy(data->dev);
+               ret = pm_runtime_put_autosuspend(data->dev);
        }
 
        if (ret < 0) {
-               dev_err(&data->client->dev,
+               dev_err(data->dev,
                        "Failed: bmg160_set_power_state for %d\n", on);
                if (on)
-                       pm_runtime_put_noidle(&data->client->dev);
+                       pm_runtime_put_noidle(data->dev);
 
                return ret;
        }
@@ -284,43 +276,30 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
        int ret;
 
        /* Enable/Disable INT_MAP0 mapping */
-       ret = i2c_smbus_read_byte_data(data->client,  BMG160_REG_INT_MAP_0);
-       if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_map0\n");
-               return ret;
-       }
-       if (status)
-               ret |= BMG160_INT_MAP_0_BIT_ANY;
-       else
-               ret &= ~BMG160_INT_MAP_0_BIT_ANY;
-
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_INT_MAP_0,
-                                       ret);
+       ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_0,
+                                BMG160_INT_MAP_0_BIT_ANY,
+                                (status ? BMG160_INT_MAP_0_BIT_ANY : 0));
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_map0\n");
+               dev_err(data->dev, "Error updating bits reg_int_map0\n");
                return ret;
        }
 
        /* Enable/Disable slope interrupts */
        if (status) {
                /* Update slope thres */
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_SLOPE_THRES,
-                                               data->slope_thres);
+               ret = regmap_write(data->regmap, BMG160_REG_SLOPE_THRES,
+                                  data->slope_thres);
                if (ret < 0) {
-                       dev_err(&data->client->dev,
+                       dev_err(data->dev,
                                "Error writing reg_slope_thres\n");
                        return ret;
                }
 
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_MOTION_INTR,
-                                               BMG160_INT_MOTION_X |
-                                               BMG160_INT_MOTION_Y |
-                                               BMG160_INT_MOTION_Z);
+               ret = regmap_write(data->regmap, BMG160_REG_MOTION_INTR,
+                                  BMG160_INT_MOTION_X | BMG160_INT_MOTION_Y |
+                                  BMG160_INT_MOTION_Z);
                if (ret < 0) {
-                       dev_err(&data->client->dev,
+                       dev_err(data->dev,
                                "Error writing reg_motion_intr\n");
                        return ret;
                }
@@ -331,28 +310,26 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
                 * to set latched mode, we will be flooded anyway with INTR
                 */
                if (!data->dready_trigger_on) {
-                       ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_INT_RST_LATCH,
-                                               BMG160_INT_MODE_LATCH_INT |
-                                               BMG160_INT_MODE_LATCH_RESET);
+                       ret = regmap_write(data->regmap,
+                                          BMG160_REG_INT_RST_LATCH,
+                                          BMG160_INT_MODE_LATCH_INT |
+                                          BMG160_INT_MODE_LATCH_RESET);
                        if (ret < 0) {
-                               dev_err(&data->client->dev,
+                               dev_err(data->dev,
                                        "Error writing reg_rst_latch\n");
                                return ret;
                        }
                }
 
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_INT_EN_0,
-                                               BMG160_DATA_ENABLE_INT);
+               ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
+                                  BMG160_DATA_ENABLE_INT);
 
-       } else
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_INT_EN_0,
-                                               0);
+       } else {
+               ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
+       }
 
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_en0\n");
+               dev_err(data->dev, "Error writing reg_int_en0\n");
                return ret;
        }
 
@@ -365,59 +342,43 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
        int ret;
 
        /* Enable/Disable INT_MAP1 mapping */
-       ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_1);
-       if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_map1\n");
-               return ret;
-       }
-
-       if (status)
-               ret |= BMG160_INT_MAP_1_BIT_NEW_DATA;
-       else
-               ret &= ~BMG160_INT_MAP_1_BIT_NEW_DATA;
-
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_INT_MAP_1,
-                                       ret);
+       ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_1,
+                                BMG160_INT_MAP_1_BIT_NEW_DATA,
+                                (status ? BMG160_INT_MAP_1_BIT_NEW_DATA : 0));
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_map1\n");
+               dev_err(data->dev, "Error updating bits in reg_int_map1\n");
                return ret;
        }
 
        if (status) {
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_INT_RST_LATCH,
-                                               BMG160_INT_MODE_NON_LATCH_INT |
-                                               BMG160_INT_MODE_LATCH_RESET);
+               ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+                                  BMG160_INT_MODE_NON_LATCH_INT |
+                                  BMG160_INT_MODE_LATCH_RESET);
                if (ret < 0) {
-                       dev_err(&data->client->dev,
+                       dev_err(data->dev,
                                "Error writing reg_rst_latch\n");
                                return ret;
                }
 
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_INT_EN_0,
-                                               BMG160_DATA_ENABLE_INT);
+               ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
+                                  BMG160_DATA_ENABLE_INT);
 
        } else {
                /* Restore interrupt mode */
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_INT_RST_LATCH,
-                                               BMG160_INT_MODE_LATCH_INT |
-                                               BMG160_INT_MODE_LATCH_RESET);
+               ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+                                  BMG160_INT_MODE_LATCH_INT |
+                                  BMG160_INT_MODE_LATCH_RESET);
                if (ret < 0) {
-                       dev_err(&data->client->dev,
+                       dev_err(data->dev,
                                "Error writing reg_rst_latch\n");
                                return ret;
                }
 
-               ret = i2c_smbus_write_byte_data(data->client,
-                                               BMG160_REG_INT_EN_0,
-                                               0);
+               ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
        }
 
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_int_en0\n");
+               dev_err(data->dev, "Error writing reg_int_en0\n");
                return ret;
        }
 
@@ -444,12 +405,10 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
 
        for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) {
                if (bmg160_scale_table[i].scale == val) {
-                       ret = i2c_smbus_write_byte_data(
-                                       data->client,
-                                       BMG160_REG_RANGE,
-                                       bmg160_scale_table[i].dps_range);
+                       ret = regmap_write(data->regmap, BMG160_REG_RANGE,
+                                          bmg160_scale_table[i].dps_range);
                        if (ret < 0) {
-                               dev_err(&data->client->dev,
+                               dev_err(data->dev,
                                        "Error writing reg_range\n");
                                return ret;
                        }
@@ -464,6 +423,7 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
 static int bmg160_get_temp(struct bmg160_data *data, int *val)
 {
        int ret;
+       unsigned int raw_val;
 
        mutex_lock(&data->mutex);
        ret = bmg160_set_power_state(data, true);
@@ -472,15 +432,15 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
                return ret;
        }
 
-       ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_TEMP);
+       ret = regmap_read(data->regmap, BMG160_REG_TEMP, &raw_val);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_temp\n");
+               dev_err(data->dev, "Error reading reg_temp\n");
                bmg160_set_power_state(data, false);
                mutex_unlock(&data->mutex);
                return ret;
        }
 
-       *val = sign_extend32(ret, 7);
+       *val = sign_extend32(raw_val, 7);
        ret = bmg160_set_power_state(data, false);
        mutex_unlock(&data->mutex);
        if (ret < 0)
@@ -492,6 +452,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
 static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
 {
        int ret;
+       unsigned int raw_val;
 
        mutex_lock(&data->mutex);
        ret = bmg160_set_power_state(data, true);
@@ -500,15 +461,16 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
                return ret;
        }
 
-       ret = i2c_smbus_read_word_data(data->client, BMG160_AXIS_TO_REG(axis));
+       ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(axis), &raw_val,
+                              2);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading axis %d\n", axis);
+               dev_err(data->dev, "Error reading axis %d\n", axis);
                bmg160_set_power_state(data, false);
                mutex_unlock(&data->mutex);
                return ret;
        }
 
-       *val = sign_extend32(ret, 15);
+       *val = sign_extend32(raw_val, 15);
        ret = bmg160_set_power_state(data, false);
        mutex_unlock(&data->mutex);
        if (ret < 0)
@@ -807,12 +769,13 @@ static irqreturn_t bmg160_trigger_handler(int irq, void *p)
        struct iio_dev *indio_dev = pf->indio_dev;
        struct bmg160_data *data = iio_priv(indio_dev);
        int bit, ret, i = 0;
+       unsigned int val;
 
        mutex_lock(&data->mutex);
        for_each_set_bit(bit, indio_dev->active_scan_mask,
                         indio_dev->masklength) {
-               ret = i2c_smbus_read_word_data(data->client,
-                                              BMG160_AXIS_TO_REG(bit));
+               ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(bit),
+                                      &val, 2);
                if (ret < 0) {
                        mutex_unlock(&data->mutex);
                        goto err;
@@ -840,12 +803,11 @@ static int bmg160_trig_try_reen(struct iio_trigger *trig)
                return 0;
 
        /* Set latched mode interrupt and clear any latched interrupt */
-       ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_INT_RST_LATCH,
-                                       BMG160_INT_MODE_LATCH_INT |
-                                       BMG160_INT_MODE_LATCH_RESET);
+       ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+                          BMG160_INT_MODE_LATCH_INT |
+                          BMG160_INT_MODE_LATCH_RESET);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error writing reg_rst_latch\n");
+               dev_err(data->dev, "Error writing reg_rst_latch\n");
                return ret;
        }
 
@@ -907,33 +869,34 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
        struct bmg160_data *data = iio_priv(indio_dev);
        int ret;
        int dir;
+       unsigned int val;
 
-       ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_STATUS_2);
+       ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
        if (ret < 0) {
-               dev_err(&data->client->dev, "Error reading reg_int_status2\n");
+               dev_err(data->dev, "Error reading reg_int_status2\n");
                goto ack_intr_status;
        }
 
-       if (ret & 0x08)
+       if (val & 0x08)
                dir = IIO_EV_DIR_RISING;
        else
                dir = IIO_EV_DIR_FALLING;
 
-       if (ret & BMG160_ANY_MOTION_BIT_X)
+       if (val & BMG160_ANY_MOTION_BIT_X)
                iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
                                                        0,
                                                        IIO_MOD_X,
                                                        IIO_EV_TYPE_ROC,
                                                        dir),
                                                        iio_get_time_ns());
-       if (ret & BMG160_ANY_MOTION_BIT_Y)
+       if (val & BMG160_ANY_MOTION_BIT_Y)
                iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
                                                        0,
                                                        IIO_MOD_Y,
                                                        IIO_EV_TYPE_ROC,
                                                        dir),
                                                        iio_get_time_ns());
-       if (ret & BMG160_ANY_MOTION_BIT_Z)
+       if (val & BMG160_ANY_MOTION_BIT_Z)
                iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
                                                        0,
                                                        IIO_MOD_Z,
@@ -943,12 +906,11 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
 
 ack_intr_status:
        if (!data->dready_trigger_on) {
-               ret = i2c_smbus_write_byte_data(data->client,
-                                       BMG160_REG_INT_RST_LATCH,
-                                       BMG160_INT_MODE_LATCH_INT |
-                                       BMG160_INT_MODE_LATCH_RESET);
+               ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+                                  BMG160_INT_MODE_LATCH_INT |
+                                  BMG160_INT_MODE_LATCH_RESET);
                if (ret < 0)
-                       dev_err(&data->client->dev,
+                       dev_err(data->dev,
                                "Error writing reg_rst_latch\n");
        }
 
@@ -993,18 +955,13 @@ static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
        .postdisable = bmg160_buffer_postdisable,
 };
 
-static int bmg160_gpio_probe(struct i2c_client *client,
-                            struct bmg160_data *data)
+static int bmg160_gpio_probe(struct bmg160_data *data)
 
 {
        struct device *dev;
        struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
 
-       dev = &client->dev;
+       dev = data->dev;
 
        /* data ready gpio interrupt pin */
        gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0, GPIOD_IN);
@@ -1013,11 +970,12 @@ static int bmg160_gpio_probe(struct i2c_client *client,
                return PTR_ERR(gpio);
        }
 
-       ret = gpiod_to_irq(gpio);
+       data->irq = gpiod_to_irq(gpio);
 
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
+       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio),
+               data->irq);
 
-       return ret;
+       return 0;
 }
 
 static const char *bmg160_match_acpi_device(struct device *dev)
@@ -1031,21 +989,22 @@ static const char *bmg160_match_acpi_device(struct device *dev)
        return dev_name(dev);
 }
 
-static int bmg160_probe(struct i2c_client *client,
-                       const struct i2c_device_id *id)
+int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
+                     const char *name)
 {
        struct bmg160_data *data;
        struct iio_dev *indio_dev;
        int ret;
-       const char *name = NULL;
 
-       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
        if (!indio_dev)
                return -ENOMEM;
 
        data = iio_priv(indio_dev);
-       i2c_set_clientdata(client, indio_dev);
-       data->client = client;
+       dev_set_drvdata(dev, indio_dev);
+       data->dev = dev;
+       data->irq = irq;
+       data->regmap = regmap;
 
        ret = bmg160_chip_init(data);
        if (ret < 0)
@@ -1053,25 +1012,22 @@ static int bmg160_probe(struct i2c_client *client,
 
        mutex_init(&data->mutex);
 
-       if (id)
-               name = id->name;
+       if (ACPI_HANDLE(dev))
+               name = bmg160_match_acpi_device(dev);
 
-       if (ACPI_HANDLE(&client->dev))
-               name = bmg160_match_acpi_device(&client->dev);
-
-       indio_dev->dev.parent = &client->dev;
+       indio_dev->dev.parent = dev;
        indio_dev->channels = bmg160_channels;
        indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
        indio_dev->name = name;
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->info = &bmg160_info;
 
-       if (client->irq <= 0)
-               client->irq = bmg160_gpio_probe(client, data);
+       if (data->irq <= 0)
+               bmg160_gpio_probe(data);
 
-       if (client->irq > 0) {
-               ret = devm_request_threaded_irq(&client->dev,
-                                               client->irq,
+       if (data->irq > 0) {
+               ret = devm_request_threaded_irq(dev,
+                                               data->irq,
                                                bmg160_data_rdy_trig_poll,
                                                bmg160_event_handler,
                                                IRQF_TRIGGER_RISING,
@@ -1080,28 +1036,28 @@ static int bmg160_probe(struct i2c_client *client,
                if (ret)
                        return ret;
 
-               data->dready_trig = devm_iio_trigger_alloc(&client->dev,
+               data->dready_trig = devm_iio_trigger_alloc(dev,
                                                           "%s-dev%d",
                                                           indio_dev->name,
                                                           indio_dev->id);
                if (!data->dready_trig)
                        return -ENOMEM;
 
-               data->motion_trig = devm_iio_trigger_alloc(&client->dev,
+               data->motion_trig = devm_iio_trigger_alloc(dev,
                                                          "%s-any-motion-dev%d",
                                                          indio_dev->name,
                                                          indio_dev->id);
                if (!data->motion_trig)
                        return -ENOMEM;
 
-               data->dready_trig->dev.parent = &client->dev;
+               data->dready_trig->dev.parent = dev;
                data->dready_trig->ops = &bmg160_trigger_ops;
                iio_trigger_set_drvdata(data->dready_trig, indio_dev);
                ret = iio_trigger_register(data->dready_trig);
                if (ret)
                        return ret;
 
-               data->motion_trig->dev.parent = &client->dev;
+               data->motion_trig->dev.parent = dev;
                data->motion_trig->ops = &bmg160_trigger_ops;
                iio_trigger_set_drvdata(data->motion_trig, indio_dev);
                ret = iio_trigger_register(data->motion_trig);
@@ -1116,25 +1072,25 @@ static int bmg160_probe(struct i2c_client *client,
                                         bmg160_trigger_handler,
                                         &bmg160_buffer_setup_ops);
        if (ret < 0) {
-               dev_err(&client->dev,
+               dev_err(dev,
                        "iio triggered buffer setup failed\n");
                goto err_trigger_unregister;
        }
 
        ret = iio_device_register(indio_dev);
        if (ret < 0) {
-               dev_err(&client->dev, "unable to register iio device\n");
+               dev_err(dev, "unable to register iio device\n");
                goto err_buffer_cleanup;
        }
 
-       ret = pm_runtime_set_active(&client->dev);
+       ret = pm_runtime_set_active(dev);
        if (ret)
                goto err_iio_unregister;
 
-       pm_runtime_enable(&client->dev);
-       pm_runtime_set_autosuspend_delay(&client->dev,
+       pm_runtime_enable(dev);
+       pm_runtime_set_autosuspend_delay(dev,
                                         BMG160_AUTO_SUSPEND_DELAY_MS);
-       pm_runtime_use_autosuspend(&client->dev);
+       pm_runtime_use_autosuspend(dev);
 
        return 0;
 
@@ -1150,15 +1106,16 @@ err_trigger_unregister:
 
        return ret;
 }
+EXPORT_SYMBOL_GPL(bmg160_core_probe);
 
-static int bmg160_remove(struct i2c_client *client)
+void bmg160_core_remove(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(client);
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmg160_data *data = iio_priv(indio_dev);
 
-       pm_runtime_disable(&client->dev);
-       pm_runtime_set_suspended(&client->dev);
-       pm_runtime_put_noidle(&client->dev);
+       pm_runtime_disable(dev);
+       pm_runtime_set_suspended(dev);
+       pm_runtime_put_noidle(dev);
 
        iio_device_unregister(indio_dev);
        iio_triggered_buffer_cleanup(indio_dev);
@@ -1171,14 +1128,13 @@ static int bmg160_remove(struct i2c_client *client)
        mutex_lock(&data->mutex);
        bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND);
        mutex_unlock(&data->mutex);
-
-       return 0;
 }
+EXPORT_SYMBOL_GPL(bmg160_core_remove);
 
 #ifdef CONFIG_PM_SLEEP
 static int bmg160_suspend(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmg160_data *data = iio_priv(indio_dev);
 
        mutex_lock(&data->mutex);
@@ -1190,7 +1146,7 @@ static int bmg160_suspend(struct device *dev)
 
 static int bmg160_resume(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmg160_data *data = iio_priv(indio_dev);
 
        mutex_lock(&data->mutex);
@@ -1206,13 +1162,13 @@ static int bmg160_resume(struct device *dev)
 #ifdef CONFIG_PM
 static int bmg160_runtime_suspend(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmg160_data *data = iio_priv(indio_dev);
        int ret;
 
        ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND);
        if (ret < 0) {
-               dev_err(&data->client->dev, "set mode failed\n");
+               dev_err(data->dev, "set mode failed\n");
                return -EAGAIN;
        }
 
@@ -1221,7 +1177,7 @@ static int bmg160_runtime_suspend(struct device *dev)
 
 static int bmg160_runtime_resume(struct device *dev)
 {
-       struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+       struct iio_dev *indio_dev = dev_get_drvdata(dev);
        struct bmg160_data *data = iio_priv(indio_dev);
        int ret;
 
@@ -1235,39 +1191,12 @@ static int bmg160_runtime_resume(struct device *dev)
 }
 #endif
 
-static const struct dev_pm_ops bmg160_pm_ops = {
+const struct dev_pm_ops bmg160_pm_ops = {
        SET_SYSTEM_SLEEP_PM_OPS(bmg160_suspend, bmg160_resume)
        SET_RUNTIME_PM_OPS(bmg160_runtime_suspend,
                           bmg160_runtime_resume, NULL)
 };
-
-static const struct acpi_device_id bmg160_acpi_match[] = {
-       {"BMG0160", 0},
-       {"BMI055B", 0},
-       {},
-};
-
-MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
-
-static const struct i2c_device_id bmg160_id[] = {
-       {"bmg160", 0},
-       {"bmi055_gyro", 0},
-       {}
-};
-
-MODULE_DEVICE_TABLE(i2c, bmg160_id);
-
-static struct i2c_driver bmg160_driver = {
-       .driver = {
-               .name   = BMG160_DRV_NAME,
-               .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
-               .pm     = &bmg160_pm_ops,
-       },
-       .probe          = bmg160_probe,
-       .remove         = bmg160_remove,
-       .id_table       = bmg160_id,
-};
-module_i2c_driver(bmg160_driver);
+EXPORT_SYMBOL_GPL(bmg160_pm_ops);
 
 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c
new file mode 100644 (file)
index 0000000..90126a5
--- /dev/null
@@ -0,0 +1,71 @@
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/iio/iio.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+
+#include "bmg160.h"
+
+static const struct regmap_config bmg160_regmap_i2c_conf = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0x3f
+};
+
+static int bmg160_i2c_probe(struct i2c_client *client,
+                           const struct i2c_device_id *id)
+{
+       struct regmap *regmap;
+       const char *name = NULL;
+
+       regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
+       if (IS_ERR(regmap)) {
+               dev_err(&client->dev, "Failed to register i2c regmap %d\n",
+                       (int)PTR_ERR(regmap));
+               return PTR_ERR(regmap);
+       }
+
+       if (id)
+               name = id->name;
+
+       return bmg160_core_probe(&client->dev, regmap, client->irq, name);
+}
+
+static int bmg160_i2c_remove(struct i2c_client *client)
+{
+       bmg160_core_remove(&client->dev);
+
+       return 0;
+}
+
+static const struct acpi_device_id bmg160_acpi_match[] = {
+       {"BMG0160", 0},
+       {"BMI055B", 0},
+       {},
+};
+
+MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
+
+static const struct i2c_device_id bmg160_i2c_id[] = {
+       {"bmg160", 0},
+       {"bmi055_gyro", 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id);
+
+static struct i2c_driver bmg160_i2c_driver = {
+       .driver = {
+               .name   = "bmg160_i2c",
+               .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
+               .pm     = &bmg160_pm_ops,
+       },
+       .probe          = bmg160_i2c_probe,
+       .remove         = bmg160_i2c_remove,
+       .id_table       = bmg160_i2c_id,
+};
+module_i2c_driver(bmg160_i2c_driver);
+
+MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMG160 I2C Gyro driver");
diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c
new file mode 100644 (file)
index 0000000..021ea5f
--- /dev/null
@@ -0,0 +1,57 @@
+#include <linux/spi/spi.h>
+#include <linux/regmap.h>
+#include <linux/iio/iio.h>
+#include <linux/module.h>
+
+#include "bmg160.h"
+
+static const struct regmap_config bmg160_regmap_spi_conf = {
+       .reg_bits = 8,
+       .val_bits = 8,
+       .max_register = 0x3f,
+};
+
+static int bmg160_spi_probe(struct spi_device *spi)
+{
+       struct regmap *regmap;
+       const struct spi_device_id *id = spi_get_device_id(spi);
+
+       regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
+       if (IS_ERR(regmap)) {
+               dev_err(&spi->dev, "Failed to register spi regmap %d\n",
+                       (int)PTR_ERR(regmap));
+               return PTR_ERR(regmap);
+       }
+
+       return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
+}
+
+static int bmg160_spi_remove(struct spi_device *spi)
+{
+       bmg160_core_remove(&spi->dev);
+
+       return 0;
+}
+
+static const struct spi_device_id bmg160_spi_id[] = {
+       {"bmg160", 0},
+       {"bmi055_gyro", 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
+
+static struct spi_driver bmg160_spi_driver = {
+       .driver = {
+               .name   = "bmg160_spi",
+               .pm     = &bmg160_pm_ops,
+       },
+       .probe          = bmg160_spi_probe,
+       .remove         = bmg160_spi_remove,
+       .id_table       = bmg160_spi_id,
+};
+module_spi_driver(bmg160_spi_driver);
+
+MODULE_AUTHOR("Markus Pargmann <mpa@pengutronix.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMG160 SPI Gyro driver");
index 4b993a5bc9a1196dab5ff91bfa6084ed006ed89b..02eddcebeea3e97fd38c5a9bfa60e427bd9f1ac9 100644 (file)
@@ -383,6 +383,7 @@ static const struct iio_info gyro_info = {
        .attrs = &st_gyro_attribute_group,
        .read_raw = &st_gyro_read_raw,
        .write_raw = &st_gyro_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index 688c0d1cb47dea363df8b5dcc395797a575e9445..6a23698d347c24c8e2a776ad09d42a0792d07309 100644 (file)
@@ -12,6 +12,29 @@ config DHT11
          Other sensors should work as well as long as they speak the
          same protocol.
 
+config HDC100X
+       tristate "TI HDC100x relative humidity and temperature sensor"
+       depends on I2C
+       help
+        Say yes here to build support for the TI HDC100x series of
+        relative humidity and temperature sensors.
+
+        To compile this driver as a module, choose M here: the module
+        will be called hdc100x.
+
+config HTU21
+       tristate "Measurement Specialties HTU21 humidity & temperature sensor"
+       depends on I2C
+        select IIO_MS_SENSORS_I2C
+       help
+         If you say yes here you get support for the Measurement Specialties
+         HTU21 humidity and temperature sensor.
+         This driver is also used for MS8607 temperature, pressure & humidity
+         sensor
+
+         This driver can also be built as a module. If so, the module will
+         be called htu21.
+
 config SI7005
        tristate "SI7005 relative humidity and temperature sensor"
        depends on I2C
index 86e2d26e9f4dd8edbfcaa3e4c3b24f5651dcfc91..c9f089a9a6b82886ac1640c29e7957b452d523ed 100644 (file)
@@ -3,5 +3,7 @@
 #
 
 obj-$(CONFIG_DHT11) += dht11.o
+obj-$(CONFIG_HDC100X) += hdc100x.o
+obj-$(CONFIG_HTU21) += htu21.o
 obj-$(CONFIG_SI7005) += si7005.o
 obj-$(CONFIG_SI7020) += si7020.o
diff --git a/drivers/iio/humidity/hdc100x.c b/drivers/iio/humidity/hdc100x.c
new file mode 100644 (file)
index 0000000..a7f61e8
--- /dev/null
@@ -0,0 +1,320 @@
+/*
+ * hdc100x.c - Support for the TI HDC100x temperature + humidity sensors
+ *
+ * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#define HDC100X_REG_TEMP                       0x00
+#define HDC100X_REG_HUMIDITY                   0x01
+
+#define HDC100X_REG_CONFIG                     0x02
+#define HDC100X_REG_CONFIG_HEATER_EN           BIT(13)
+
+struct hdc100x_data {
+       struct i2c_client *client;
+       struct mutex lock;
+       u16 config;
+
+       /* integration time of the sensor */
+       int adc_int_us[2];
+};
+
+/* integration time in us */
+static const int hdc100x_int_time[][3] = {
+       { 6350, 3650, 0 },      /* IIO_TEMP channel*/
+       { 6500, 3850, 2500 },   /* IIO_HUMIDITYRELATIVE channel */
+};
+
+/* HDC100X_REG_CONFIG shift and mask values */
+static const struct {
+       int shift;
+       int mask;
+} hdc100x_resolution_shift[2] = {
+       { /* IIO_TEMP channel */
+               .shift = 10,
+               .mask = 1
+       },
+       { /* IIO_HUMIDITYRELATIVE channel */
+               .shift = 8,
+               .mask = 2,
+       },
+};
+
+static IIO_CONST_ATTR(temp_integration_time_available,
+               "0.00365 0.00635");
+
+static IIO_CONST_ATTR(humidityrelative_integration_time_available,
+               "0.0025 0.00385 0.0065");
+
+static IIO_CONST_ATTR(out_current_heater_raw_available,
+               "0 1");
+
+static struct attribute *hdc100x_attributes[] = {
+       &iio_const_attr_temp_integration_time_available.dev_attr.attr,
+       &iio_const_attr_humidityrelative_integration_time_available.dev_attr.attr,
+       &iio_const_attr_out_current_heater_raw_available.dev_attr.attr,
+       NULL
+};
+
+static struct attribute_group hdc100x_attribute_group = {
+       .attrs = hdc100x_attributes,
+};
+
+static const struct iio_chan_spec hdc100x_channels[] = {
+       {
+               .type = IIO_TEMP,
+               .address = HDC100X_REG_TEMP,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_INT_TIME) |
+                       BIT(IIO_CHAN_INFO_OFFSET),
+       },
+       {
+               .type = IIO_HUMIDITYRELATIVE,
+               .address = HDC100X_REG_HUMIDITY,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                       BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_INT_TIME)
+       },
+       {
+               .type = IIO_CURRENT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .extend_name = "heater",
+               .output = 1,
+       },
+};
+
+static int hdc100x_update_config(struct hdc100x_data *data, int mask, int val)
+{
+       int tmp = (~mask & data->config) | val;
+       int ret;
+
+       ret = i2c_smbus_write_word_swapped(data->client,
+                                               HDC100X_REG_CONFIG, tmp);
+       if (!ret)
+               data->config = tmp;
+
+       return ret;
+}
+
+static int hdc100x_set_it_time(struct hdc100x_data *data, int chan, int val2)
+{
+       int shift = hdc100x_resolution_shift[chan].shift;
+       int ret = -EINVAL;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(hdc100x_int_time[chan]); i++) {
+               if (val2 && val2 == hdc100x_int_time[chan][i]) {
+                       ret = hdc100x_update_config(data,
+                               hdc100x_resolution_shift[chan].mask << shift,
+                               i << shift);
+                       if (!ret)
+                               data->adc_int_us[chan] = val2;
+                       break;
+               }
+       }
+
+       return ret;
+}
+
+static int hdc100x_get_measurement(struct hdc100x_data *data,
+                                  struct iio_chan_spec const *chan)
+{
+       struct i2c_client *client = data->client;
+       int delay = data->adc_int_us[chan->address];
+       int ret;
+       int val;
+
+       /* start measurement */
+       ret = i2c_smbus_write_byte(client, chan->address);
+       if (ret < 0) {
+               dev_err(&client->dev, "cannot start measurement");
+               return ret;
+       }
+
+       /* wait for integration time to pass */
+       usleep_range(delay, delay + 1000);
+
+       /*
+        * i2c_smbus_read_word_data cannot() be used here due to the command
+        * value not being understood and causes NAKs preventing any reading
+        * from being accessed.
+        */
+       ret = i2c_smbus_read_byte(client);
+       if (ret < 0) {
+               dev_err(&client->dev, "cannot read high byte measurement");
+               return ret;
+       }
+       val = ret << 6;
+
+       ret = i2c_smbus_read_byte(client);
+       if (ret < 0) {
+               dev_err(&client->dev, "cannot read low byte measurement");
+               return ret;
+       }
+       val |= ret >> 2;
+
+       return val;
+}
+
+static int hdc100x_get_heater_status(struct hdc100x_data *data)
+{
+       return !!(data->config & HDC100X_REG_CONFIG_HEATER_EN);
+}
+
+static int hdc100x_read_raw(struct iio_dev *indio_dev,
+                           struct iio_chan_spec const *chan, int *val,
+                           int *val2, long mask)
+{
+       struct hdc100x_data *data = iio_priv(indio_dev);
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW: {
+               int ret;
+
+               mutex_lock(&data->lock);
+               if (chan->type == IIO_CURRENT) {
+                       *val = hdc100x_get_heater_status(data);
+                       ret = IIO_VAL_INT;
+               } else {
+                       ret = hdc100x_get_measurement(data, chan);
+                       if (ret >= 0) {
+                               *val = ret;
+                               ret = IIO_VAL_INT;
+                       }
+               }
+               mutex_unlock(&data->lock);
+               return ret;
+       }
+       case IIO_CHAN_INFO_INT_TIME:
+               *val = 0;
+               *val2 = data->adc_int_us[chan->address];
+               return IIO_VAL_INT_PLUS_MICRO;
+       case IIO_CHAN_INFO_SCALE:
+               if (chan->type == IIO_TEMP) {
+                       *val = 165;
+                       *val2 = 65536 >> 2;
+                       return IIO_VAL_FRACTIONAL;
+               } else {
+                       *val = 0;
+                       *val2 = 10000;
+                       return IIO_VAL_INT_PLUS_MICRO;
+               }
+               break;
+       case IIO_CHAN_INFO_OFFSET:
+               *val = -3971;
+               *val2 = 879096;
+               return IIO_VAL_INT_PLUS_MICRO;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int hdc100x_write_raw(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan,
+                            int val, int val2, long mask)
+{
+       struct hdc100x_data *data = iio_priv(indio_dev);
+       int ret = -EINVAL;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_INT_TIME:
+               if (val != 0)
+                       return -EINVAL;
+
+               mutex_lock(&data->lock);
+               ret = hdc100x_set_it_time(data, chan->address, val2);
+               mutex_unlock(&data->lock);
+               return ret;
+       case IIO_CHAN_INFO_RAW:
+               if (chan->type != IIO_CURRENT || val2 != 0)
+                       return -EINVAL;
+
+               mutex_lock(&data->lock);
+               ret = hdc100x_update_config(data, HDC100X_REG_CONFIG_HEATER_EN,
+                                       val ? HDC100X_REG_CONFIG_HEATER_EN : 0);
+               mutex_unlock(&data->lock);
+               return ret;
+       default:
+               return -EINVAL;
+       }
+}
+
+static const struct iio_info hdc100x_info = {
+       .read_raw = hdc100x_read_raw,
+       .write_raw = hdc100x_write_raw,
+       .attrs = &hdc100x_attribute_group,
+       .driver_module = THIS_MODULE,
+};
+
+static int hdc100x_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct iio_dev *indio_dev;
+       struct hdc100x_data *data;
+
+       if (!i2c_check_functionality(client->adapter,
+                               I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BYTE))
+               return -ENODEV;
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       data = iio_priv(indio_dev);
+       i2c_set_clientdata(client, indio_dev);
+       data->client = client;
+       mutex_init(&data->lock);
+
+       indio_dev->dev.parent = &client->dev;
+       indio_dev->name = dev_name(&client->dev);
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->info = &hdc100x_info;
+
+       indio_dev->channels = hdc100x_channels;
+       indio_dev->num_channels = ARRAY_SIZE(hdc100x_channels);
+
+       /* be sure we are in a known state */
+       hdc100x_set_it_time(data, 0, hdc100x_int_time[0][0]);
+       hdc100x_set_it_time(data, 1, hdc100x_int_time[1][0]);
+
+       return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id hdc100x_id[] = {
+       { "hdc100x", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, hdc100x_id);
+
+static struct i2c_driver hdc100x_driver = {
+       .driver = {
+               .name   = "hdc100x",
+       },
+       .probe = hdc100x_probe,
+       .id_table = hdc100x_id,
+};
+module_i2c_driver(hdc100x_driver);
+
+MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
+MODULE_DESCRIPTION("TI HDC100x humidity and temperature sensor driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/iio/humidity/htu21.c b/drivers/iio/humidity/htu21.c
new file mode 100644 (file)
index 0000000..d1636a7
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * htu21.c - Support for Measurement-Specialties
+ *           htu21 temperature & humidity sensor
+ *          and humidity part of MS8607 sensor
+ *
+ * Copyright (c) 2014 Measurement-Specialties
+ *
+ * Licensed under the GPL-2.
+ *
+ * (7-bit I2C slave address 0x40)
+ *
+ * Datasheet:
+ *  http://www.meas-spec.com/downloads/HTU21D.pdf
+ * Datasheet:
+ *  http://www.meas-spec.com/downloads/MS8607-02BA01.pdf
+ */
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/stat.h>
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#include "../common/ms_sensors/ms_sensors_i2c.h"
+
+#define HTU21_RESET                            0xFE
+
+enum {
+       HTU21,
+       MS8607
+};
+
+static const int htu21_samp_freq[4] = { 20, 40, 70, 120 };
+/* String copy of the above const for readability purpose */
+static const char htu21_show_samp_freq[] = "20 40 70 120";
+
+static int htu21_read_raw(struct iio_dev *indio_dev,
+                         struct iio_chan_spec const *channel, int *val,
+                         int *val2, long mask)
+{
+       int ret, temperature;
+       unsigned int humidity;
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+
+       switch (mask) {
+       case IIO_CHAN_INFO_PROCESSED:
+               switch (channel->type) {
+               case IIO_TEMP:  /* in milli Â°C */
+                       ret = ms_sensors_ht_read_temperature(dev_data,
+                                                            &temperature);
+                       if (ret)
+                               return ret;
+                       *val = temperature;
+
+                       return IIO_VAL_INT;
+               case IIO_HUMIDITYRELATIVE:      /* in milli %RH */
+                       ret = ms_sensors_ht_read_humidity(dev_data,
+                                                         &humidity);
+                       if (ret)
+                               return ret;
+                       *val = humidity;
+
+                       return IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = htu21_samp_freq[dev_data->res_index];
+
+               return IIO_VAL_INT;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int htu21_write_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *chan,
+                          int val, int val2, long mask)
+{
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+       int i, ret;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               i = ARRAY_SIZE(htu21_samp_freq);
+               while (i-- > 0)
+                       if (val == htu21_samp_freq[i])
+                               break;
+               if (i < 0)
+                       return -EINVAL;
+               mutex_lock(&dev_data->lock);
+               dev_data->res_index = i;
+               ret = ms_sensors_write_resolution(dev_data, i);
+               mutex_unlock(&dev_data->lock);
+
+               return ret;
+       default:
+               return -EINVAL;
+       }
+}
+
+static const struct iio_chan_spec htu21_channels[] = {
+       {
+               .type = IIO_TEMP,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+        },
+       {
+               .type = IIO_HUMIDITYRELATIVE,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+        }
+};
+
+/*
+ * Meas Spec recommendation is to not read temperature
+ * on this driver part for MS8607
+ */
+static const struct iio_chan_spec ms8607_channels[] = {
+       {
+               .type = IIO_HUMIDITYRELATIVE,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+        }
+};
+
+static ssize_t htu21_show_battery_low(struct device *dev,
+                                     struct device_attribute *attr, char *buf)
+{
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+
+       return ms_sensors_show_battery_low(dev_data, buf);
+}
+
+static ssize_t htu21_show_heater(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+
+       return ms_sensors_show_heater(dev_data, buf);
+}
+
+static ssize_t htu21_write_heater(struct device *dev,
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t len)
+{
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+
+       return ms_sensors_write_heater(dev_data, buf, len);
+}
+
+static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(htu21_show_samp_freq);
+static IIO_DEVICE_ATTR(battery_low, S_IRUGO,
+                      htu21_show_battery_low, NULL, 0);
+static IIO_DEVICE_ATTR(heater_enable, S_IRUGO | S_IWUSR,
+                      htu21_show_heater, htu21_write_heater, 0);
+
+static struct attribute *htu21_attributes[] = {
+       &iio_const_attr_sampling_frequency_available.dev_attr.attr,
+       &iio_dev_attr_battery_low.dev_attr.attr,
+       &iio_dev_attr_heater_enable.dev_attr.attr,
+       NULL,
+};
+
+static const struct attribute_group htu21_attribute_group = {
+       .attrs = htu21_attributes,
+};
+
+static const struct iio_info htu21_info = {
+       .read_raw = htu21_read_raw,
+       .write_raw = htu21_write_raw,
+       .attrs = &htu21_attribute_group,
+       .driver_module = THIS_MODULE,
+};
+
+static int htu21_probe(struct i2c_client *client,
+                      const struct i2c_device_id *id)
+{
+       struct ms_ht_dev *dev_data;
+       struct iio_dev *indio_dev;
+       int ret;
+       u64 serial_number;
+
+       if (!i2c_check_functionality(client->adapter,
+                                    I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
+                                    I2C_FUNC_SMBUS_WRITE_BYTE |
+                                    I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
+               dev_err(&client->dev,
+                       "Adapter does not support some i2c transaction\n");
+               return -ENODEV;
+       }
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       dev_data = iio_priv(indio_dev);
+       dev_data->client = client;
+       dev_data->res_index = 0;
+       mutex_init(&dev_data->lock);
+
+       indio_dev->info = &htu21_info;
+       indio_dev->name = id->name;
+       indio_dev->dev.parent = &client->dev;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+
+       if (id->driver_data == MS8607) {
+               indio_dev->channels = ms8607_channels;
+               indio_dev->num_channels = ARRAY_SIZE(ms8607_channels);
+       } else {
+               indio_dev->channels = htu21_channels;
+               indio_dev->num_channels = ARRAY_SIZE(htu21_channels);
+       }
+
+       i2c_set_clientdata(client, indio_dev);
+
+       ret = ms_sensors_reset(client, HTU21_RESET, 15000);
+       if (ret)
+               return ret;
+
+       ret = ms_sensors_read_serial(client, &serial_number);
+       if (ret)
+               return ret;
+       dev_info(&client->dev, "Serial number : %llx", serial_number);
+
+       return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id htu21_id[] = {
+       {"htu21", HTU21},
+       {"ms8607-humidity", MS8607},
+       {}
+};
+
+static struct i2c_driver htu21_driver = {
+       .probe = htu21_probe,
+       .id_table = htu21_id,
+       .driver = {
+                  .name = "htu21",
+                  },
+};
+
+module_i2c_driver(htu21_driver);
+
+MODULE_DESCRIPTION("Measurement-Specialties htu21 temperature and humidity driver");
+MODULE_AUTHOR("William Markezana <william.markezana@meas-spec.com>");
+MODULE_AUTHOR("Ludovic Tancerel <ludovic.tancerel@maplehightech.com>");
+MODULE_LICENSE("GPL v2");
index fa3b809aff5efd425ce96031aec1c066b644feb2..12128d1ca570fc4dd93461219628b6ab6461d95d 100644 (file)
@@ -57,8 +57,12 @@ static int si7020_read_raw(struct iio_dev *indio_dev,
                if (ret < 0)
                        return ret;
                *val = ret >> 2;
+               /*
+                * Humidity values can slightly exceed the 0-100%RH
+                * range and should be corrected by software
+                */
                if (chan->type == IIO_HUMIDITYRELATIVE)
-                       *val &= GENMASK(11, 0);
+                       *val = clamp_val(*val, 786, 13893);
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_SCALE:
                if (chan->type == IIO_TEMP)
index 82cdf5090fa776b1bd0bea6ce570416782d996a9..dbf5e99366358815cd3d840440d6d8cc3adf8b54 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/iio/trigger_consumer.h>
 
 #define KMX61_DRV_NAME "kmx61"
-#define KMX61_GPIO_NAME "kmx61_int"
 #define KMX61_IRQ_NAME "kmx61_event"
 
 #define KMX61_REG_WHO_AM_I     0x00
@@ -1243,30 +1242,6 @@ static const char *kmx61_match_acpi_device(struct device *dev)
        return dev_name(dev);
 }
 
-static int kmx61_gpio_probe(struct i2c_client *client, struct kmx61_data *data)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       dev = &client->dev;
-
-       /* data ready gpio interrupt pin */
-       gpio = devm_gpiod_get_index(dev, KMX61_GPIO_NAME, 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "acpi gpio get index failed\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-       return ret;
-}
-
 static struct iio_dev *kmx61_indiodev_setup(struct kmx61_data *data,
                                            const struct iio_info *info,
                                            const struct iio_chan_spec *chan,
@@ -1360,9 +1335,6 @@ static int kmx61_probe(struct i2c_client *client,
        if (ret < 0)
                return ret;
 
-       if (client->irq < 0)
-               client->irq = kmx61_gpio_probe(client, data);
-
        if (client->irq > 0) {
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                                                kmx61_data_rdy_trig_poll,
index b3fcc2c449d80e2cb1fdfe95dc6ca200d36931e3..208358f9e7e36582152cad8c4f4924d9667a58cc 100644 (file)
@@ -75,6 +75,8 @@ static const char * const iio_chan_type_name_spec[] = {
        [IIO_ENERGY] = "energy",
        [IIO_DISTANCE] = "distance",
        [IIO_VELOCITY] = "velocity",
+       [IIO_CONCENTRATION] = "concentration",
+       [IIO_RESISTANCE] = "resistance",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -111,6 +113,8 @@ static const char * const iio_modifier_names[] = {
        [IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z] = "sqrt(x^2+y^2+z^2)",
        [IIO_MOD_I] = "i",
        [IIO_MOD_Q] = "q",
+       [IIO_MOD_CO2] = "co2",
+       [IIO_MOD_VOC] = "voc",
 };
 
 /* relies on pairs of these shared then separate */
@@ -962,7 +966,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
 static void iio_dev_release(struct device *device)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(device);
-       if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
+       if (indio_dev->modes & (INDIO_BUFFER_TRIGGERED | INDIO_EVENT_TRIGGERED))
                iio_device_unregister_trigger_consumer(indio_dev);
        iio_device_unregister_eventset(indio_dev);
        iio_device_unregister_sysfs(indio_dev);
@@ -1153,6 +1157,8 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
        if (cmd == IIO_GET_EVENT_FD_IOCTL) {
                fd = iio_event_getfd(indio_dev);
+               if (fd < 0)
+                       return fd;
                if (copy_to_user(ip, &fd, sizeof(fd)))
                        return -EFAULT;
                return 0;
@@ -1241,7 +1247,7 @@ int iio_device_register(struct iio_dev *indio_dev)
                        "Failed to register event set\n");
                goto error_free_sysfs;
        }
-       if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
+       if (indio_dev->modes & (INDIO_BUFFER_TRIGGERED | INDIO_EVENT_TRIGGERED))
                iio_device_register_trigger_consumer(indio_dev);
 
        if ((indio_dev->modes & INDIO_ALL_BUFFER_MODES) &&
index 570606c2adbd8ccd7167ae0cd4105c9d2744230b..ae2806aafb7267c474f54ffac8bc33232739c469 100644 (file)
@@ -366,10 +366,18 @@ static ssize_t iio_trigger_write_current(struct device *dev,
 
        indio_dev->trig = trig;
 
-       if (oldtrig)
+       if (oldtrig) {
+               if (indio_dev->modes & INDIO_EVENT_TRIGGERED)
+                       iio_trigger_detach_poll_func(oldtrig,
+                                                    indio_dev->pollfunc_event);
                iio_trigger_put(oldtrig);
-       if (indio_dev->trig)
+       }
+       if (indio_dev->trig) {
                iio_trigger_get(indio_dev->trig);
+               if (indio_dev->modes & INDIO_EVENT_TRIGGERED)
+                       iio_trigger_attach_poll_func(indio_dev->trig,
+                                                    indio_dev->pollfunc_event);
+       }
 
        return len;
 }
diff --git a/drivers/iio/industrialio-triggered-event.c b/drivers/iio/industrialio-triggered-event.c
new file mode 100644 (file)
index 0000000..8cc254f
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2015 Cogent Embedded, Inc.
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/export.h>
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/triggered_event.h>
+#include <linux/iio/trigger_consumer.h>
+
+/**
+ * iio_triggered_event_setup() - Setup pollfunc_event for triggered event
+ * @indio_dev: IIO device structure
+ * @h:         Function which will be used as pollfunc_event top half
+ * @thread:    Function which will be used as pollfunc_event bottom half
+ *
+ * This function combines some common tasks which will normally be performed
+ * when setting up a triggered event. It will allocate the pollfunc_event and
+ * set mode to use it for triggered event.
+ *
+ * Before calling this function the indio_dev structure should already be
+ * completely initialized, but not yet registered. In practice this means that
+ * this function should be called right before iio_device_register().
+ *
+ * To free the resources allocated by this function call
+ * iio_triggered_event_cleanup().
+ */
+int iio_triggered_event_setup(struct iio_dev *indio_dev,
+                             irqreturn_t (*h)(int irq, void *p),
+                             irqreturn_t (*thread)(int irq, void *p))
+{
+       indio_dev->pollfunc_event = iio_alloc_pollfunc(h,
+                                                      thread,
+                                                      IRQF_ONESHOT,
+                                                      indio_dev,
+                                                      "%s_consumer%d",
+                                                      indio_dev->name,
+                                                      indio_dev->id);
+       if (indio_dev->pollfunc_event == NULL)
+               return -ENOMEM;
+
+       /* Flag that events polling is possible */
+       indio_dev->modes |= INDIO_EVENT_TRIGGERED;
+
+       return 0;
+}
+EXPORT_SYMBOL(iio_triggered_event_setup);
+
+/**
+ * iio_triggered_event_cleanup() - Free resources allocated by iio_triggered_event_setup()
+ * @indio_dev: IIO device structure
+ */
+void iio_triggered_event_cleanup(struct iio_dev *indio_dev)
+{
+       indio_dev->modes &= ~INDIO_EVENT_TRIGGERED;
+       iio_dealloc_pollfunc(indio_dev->pollfunc_event);
+}
+EXPORT_SYMBOL(iio_triggered_event_cleanup);
+
+MODULE_AUTHOR("Vladimir Barinov");
+MODULE_DESCRIPTION("IIO helper functions for setting up triggered events");
+MODULE_LICENSE("GPL");
index 7ed859a700c4758c05c2872e34c90e7a3e1b7837..cfd3df8416bbeaa91c9ae5d2c439a3dfac07e444 100644 (file)
@@ -50,6 +50,19 @@ config APDS9300
         To compile this driver as a module, choose M here: the
         module will be called apds9300.
 
+config APDS9960
+       tristate "Avago APDS9960 gesture/RGB/ALS/proximity sensor"
+       select REGMAP_I2C
+       select IIO_BUFFER
+       select IIO_KFIFO_BUF
+       depends on I2C
+       help
+         Say Y here to build I2C interface support for the Avago
+         APDS9960 gesture/RGB/ALS/proximity sensor.
+
+         To compile this driver as a module, choose M here: the
+         module will be called apds9960
+
 config BH1750
        tristate "ROHM BH1750 ambient light sensor"
        depends on I2C
@@ -287,6 +300,16 @@ config TSL4531
         To compile this driver as a module, choose M here: the
         module will be called tsl4531.
 
+config US5182D
+       tristate "UPISEMI light and proximity sensor"
+       depends on I2C
+       help
+        If you say yes here you get support for the UPISEMI US5182D
+        ambient light and proximity sensor.
+
+        This driver can also be built as a module.  If so, the module
+        will be called us5182d.
+
 config VCNL4000
        tristate "VCNL4000 combined ALS and proximity sensor"
        depends on I2C
index 91c74c014b6f7869787a977c68a084267cf54dc5..b2c31053db0cd0fadc914f3837f27cb4e931e518 100644 (file)
@@ -7,6 +7,7 @@ obj-$(CONFIG_ACPI_ALS)          += acpi-als.o
 obj-$(CONFIG_ADJD_S311)                += adjd_s311.o
 obj-$(CONFIG_AL3320A)          += al3320a.o
 obj-$(CONFIG_APDS9300)         += apds9300.o
+obj-$(CONFIG_APDS9960)         += apds9960.o
 obj-$(CONFIG_BH1750)           += bh1750.o
 obj-$(CONFIG_CM32181)          += cm32181.o
 obj-$(CONFIG_CM3232)           += cm3232.o
@@ -27,4 +28,5 @@ obj-$(CONFIG_STK3310)          += stk3310.o
 obj-$(CONFIG_TCS3414)          += tcs3414.o
 obj-$(CONFIG_TCS3472)          += tcs3472.o
 obj-$(CONFIG_TSL4531)          += tsl4531.o
+obj-$(CONFIG_US5182D)          += us5182d.o
 obj-$(CONFIG_VCNL4000)         += vcnl4000.o
diff --git a/drivers/iio/light/apds9960.c b/drivers/iio/light/apds9960.c
new file mode 100644 (file)
index 0000000..7d269ef
--- /dev/null
@@ -0,0 +1,1130 @@
+/*
+ * apds9960.c - Support for Avago APDS9960 gesture/RGB/ALS/proximity sensor
+ *
+ * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * TODO: gesture + proximity calib offsets
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/mutex.h>
+#include <linux/err.h>
+#include <linux/irq.h>
+#include <linux/gpio.h>
+#include <linux/i2c.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/events.h>
+#include <linux/iio/kfifo_buf.h>
+#include <linux/iio/sysfs.h>
+#include <linux/of_gpio.h>
+
+#define APDS9960_REGMAP_NAME   "apds9960_regmap"
+#define APDS9960_DRV_NAME      "apds9960"
+
+#define APDS9960_REG_RAM_START 0x00
+#define APDS9960_REG_RAM_END   0x7f
+
+#define APDS9960_REG_ENABLE    0x80
+#define APDS9960_REG_ATIME     0x81
+#define APDS9960_REG_WTIME     0x83
+
+#define APDS9960_REG_AILTL     0x84
+#define APDS9960_REG_AILTH     0x85
+#define APDS9960_REG_AIHTL     0x86
+#define APDS9960_REG_AIHTH     0x87
+
+#define APDS9960_REG_PILT      0x89
+#define APDS9960_REG_PIHT      0x8b
+#define APDS9960_REG_PERS      0x8c
+
+#define APDS9960_REG_CONFIG_1  0x8d
+#define APDS9960_REG_PPULSE    0x8e
+
+#define APDS9960_REG_CONTROL   0x8f
+#define APDS9960_REG_CONTROL_AGAIN_MASK                0x03
+#define APDS9960_REG_CONTROL_PGAIN_MASK                0x0c
+#define APDS9960_REG_CONTROL_AGAIN_MASK_SHIFT  0
+#define APDS9960_REG_CONTROL_PGAIN_MASK_SHIFT  2
+
+#define APDS9960_REG_CONFIG_2  0x90
+#define APDS9960_REG_CONFIG_2_GGAIN_MASK       0x60
+#define APDS9960_REG_CONFIG_2_GGAIN_MASK_SHIFT 5
+
+#define APDS9960_REG_ID                0x92
+
+#define APDS9960_REG_STATUS    0x93
+#define APDS9960_REG_STATUS_PS_INT     BIT(5)
+#define APDS9960_REG_STATUS_ALS_INT    BIT(4)
+#define APDS9960_REG_STATUS_GINT       BIT(2)
+
+#define APDS9960_REG_PDATA     0x9c
+#define APDS9960_REG_POFFSET_UR        0x9d
+#define APDS9960_REG_POFFSET_DL 0x9e
+#define APDS9960_REG_CONFIG_3  0x9f
+
+#define APDS9960_REG_GPENTH    0xa0
+#define APDS9960_REG_GEXTH     0xa1
+
+#define APDS9960_REG_GCONF_1   0xa2
+#define APDS9960_REG_GCONF_1_GFIFO_THRES_MASK          0xc0
+#define APDS9960_REG_GCONF_1_GFIFO_THRES_MASK_SHIFT    6
+
+#define APDS9960_REG_GCONF_2   0xa3
+#define APDS9960_REG_GOFFSET_U 0xa4
+#define APDS9960_REG_GOFFSET_D 0xa5
+#define APDS9960_REG_GPULSE    0xa6
+#define APDS9960_REG_GOFFSET_L 0xa7
+#define APDS9960_REG_GOFFSET_R 0xa9
+#define APDS9960_REG_GCONF_3   0xaa
+
+#define APDS9960_REG_GCONF_4   0xab
+#define APDS9960_REG_GFLVL     0xae
+#define APDS9960_REG_GSTATUS   0xaf
+
+#define APDS9960_REG_IFORCE    0xe4
+#define APDS9960_REG_PICLEAR   0xe5
+#define APDS9960_REG_CICLEAR   0xe6
+#define APDS9960_REG_AICLEAR   0xe7
+
+#define APDS9960_DEFAULT_PERS  0x33
+#define APDS9960_DEFAULT_GPENTH        0x50
+#define APDS9960_DEFAULT_GEXTH 0x40
+
+#define APDS9960_MAX_PXS_THRES_VAL     255
+#define APDS9960_MAX_ALS_THRES_VAL     0xffff
+#define APDS9960_MAX_INT_TIME_IN_US    1000000
+
+enum apds9960_als_channel_idx {
+       IDX_ALS_CLEAR, IDX_ALS_RED, IDX_ALS_GREEN, IDX_ALS_BLUE,
+};
+
+#define APDS9960_REG_ALS_BASE  0x94
+#define APDS9960_REG_ALS_CHANNEL(_colour) \
+       (APDS9960_REG_ALS_BASE + (IDX_ALS_##_colour * 2))
+
+enum apds9960_gesture_channel_idx {
+       IDX_DIR_UP, IDX_DIR_DOWN, IDX_DIR_LEFT, IDX_DIR_RIGHT,
+};
+
+#define APDS9960_REG_GFIFO_BASE        0xfc
+#define APDS9960_REG_GFIFO_DIR(_dir) \
+       (APDS9960_REG_GFIFO_BASE + IDX_DIR_##_dir)
+
+struct apds9960_data {
+       struct i2c_client *client;
+       struct iio_dev *indio_dev;
+       struct mutex lock;
+
+       /* regmap fields */
+       struct regmap *regmap;
+       struct regmap_field *reg_int_als;
+       struct regmap_field *reg_int_ges;
+       struct regmap_field *reg_int_pxs;
+
+       struct regmap_field *reg_enable_als;
+       struct regmap_field *reg_enable_ges;
+       struct regmap_field *reg_enable_pxs;
+
+       /* state */
+       int als_int;
+       int pxs_int;
+       int gesture_mode_running;
+
+       /* gain values */
+       int als_gain;
+       int pxs_gain;
+
+       /* integration time value in us */
+       int als_adc_int_us;
+
+       /* gesture buffer */
+       u8 buffer[4]; /* 4 8-bit channels */
+};
+
+static const struct reg_default apds9960_reg_defaults[] = {
+       /* Default ALS integration time = 2.48ms */
+       { APDS9960_REG_ATIME, 0xff },
+};
+
+static const struct regmap_range apds9960_volatile_ranges[] = {
+       regmap_reg_range(APDS9960_REG_STATUS,
+                               APDS9960_REG_PDATA),
+       regmap_reg_range(APDS9960_REG_GFLVL,
+                               APDS9960_REG_GSTATUS),
+       regmap_reg_range(APDS9960_REG_GFIFO_DIR(UP),
+                               APDS9960_REG_GFIFO_DIR(RIGHT)),
+       regmap_reg_range(APDS9960_REG_IFORCE,
+                               APDS9960_REG_AICLEAR),
+};
+
+static const struct regmap_access_table apds9960_volatile_table = {
+       .yes_ranges     = apds9960_volatile_ranges,
+       .n_yes_ranges   = ARRAY_SIZE(apds9960_volatile_ranges),
+};
+
+static const struct regmap_range apds9960_precious_ranges[] = {
+       regmap_reg_range(APDS9960_REG_RAM_START, APDS9960_REG_RAM_END),
+};
+
+static const struct regmap_access_table apds9960_precious_table = {
+       .yes_ranges     = apds9960_precious_ranges,
+       .n_yes_ranges   = ARRAY_SIZE(apds9960_precious_ranges),
+};
+
+static const struct regmap_range apds9960_readable_ranges[] = {
+       regmap_reg_range(APDS9960_REG_ENABLE,
+                               APDS9960_REG_GSTATUS),
+       regmap_reg_range(APDS9960_REG_GFIFO_DIR(UP),
+                               APDS9960_REG_GFIFO_DIR(RIGHT)),
+};
+
+static const struct regmap_access_table apds9960_readable_table = {
+       .yes_ranges     = apds9960_readable_ranges,
+       .n_yes_ranges   = ARRAY_SIZE(apds9960_readable_ranges),
+};
+
+static const struct regmap_range apds9960_writeable_ranges[] = {
+       regmap_reg_range(APDS9960_REG_ENABLE, APDS9960_REG_CONFIG_2),
+       regmap_reg_range(APDS9960_REG_POFFSET_UR, APDS9960_REG_GCONF_4),
+       regmap_reg_range(APDS9960_REG_IFORCE, APDS9960_REG_AICLEAR),
+};
+
+static const struct regmap_access_table apds9960_writeable_table = {
+       .yes_ranges     = apds9960_writeable_ranges,
+       .n_yes_ranges   = ARRAY_SIZE(apds9960_writeable_ranges),
+};
+
+static const struct regmap_config apds9960_regmap_config = {
+       .name = APDS9960_REGMAP_NAME,
+       .reg_bits = 8,
+       .val_bits = 8,
+       .use_single_rw = 1,
+
+       .volatile_table = &apds9960_volatile_table,
+       .precious_table = &apds9960_precious_table,
+       .rd_table = &apds9960_readable_table,
+       .wr_table = &apds9960_writeable_table,
+
+       .reg_defaults = apds9960_reg_defaults,
+       .num_reg_defaults = ARRAY_SIZE(apds9960_reg_defaults),
+       .max_register = APDS9960_REG_GFIFO_DIR(RIGHT),
+       .cache_type = REGCACHE_RBTREE,
+};
+
+static const struct iio_event_spec apds9960_pxs_event_spec[] = {
+       {
+               .type = IIO_EV_TYPE_THRESH,
+               .dir = IIO_EV_DIR_RISING,
+               .mask_separate = BIT(IIO_EV_INFO_VALUE) |
+                       BIT(IIO_EV_INFO_ENABLE),
+       },
+       {
+               .type = IIO_EV_TYPE_THRESH,
+               .dir = IIO_EV_DIR_FALLING,
+               .mask_separate = BIT(IIO_EV_INFO_VALUE) |
+                       BIT(IIO_EV_INFO_ENABLE),
+       },
+};
+
+static const struct iio_event_spec apds9960_als_event_spec[] = {
+       {
+               .type = IIO_EV_TYPE_THRESH,
+               .dir = IIO_EV_DIR_RISING,
+               .mask_separate = BIT(IIO_EV_INFO_VALUE) |
+                       BIT(IIO_EV_INFO_ENABLE),
+       },
+       {
+               .type = IIO_EV_TYPE_THRESH,
+               .dir = IIO_EV_DIR_FALLING,
+               .mask_separate = BIT(IIO_EV_INFO_VALUE) |
+                       BIT(IIO_EV_INFO_ENABLE),
+       },
+};
+
+#define APDS9960_GESTURE_CHANNEL(_dir, _si) { \
+       .type = IIO_PROXIMITY, \
+       .channel = _si + 1, \
+       .scan_index = _si, \
+       .indexed = 1, \
+       .scan_type = { \
+               .sign = 'u', \
+               .realbits = 8, \
+               .storagebits = 8, \
+       }, \
+}
+
+#define APDS9960_INTENSITY_CHANNEL(_colour) { \
+       .type = IIO_INTENSITY, \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \
+                       BIT(IIO_CHAN_INFO_INT_TIME), \
+       .channel2 = IIO_MOD_LIGHT_##_colour, \
+       .address = APDS9960_REG_ALS_CHANNEL(_colour), \
+       .modified = 1, \
+       .scan_index = -1, \
+}
+
+static const unsigned long apds9960_scan_masks[] = {0xf, 0};
+
+static const struct iio_chan_spec apds9960_channels[] = {
+       {
+               .type = IIO_PROXIMITY,
+               .address = APDS9960_REG_PDATA,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
+               .channel = 0,
+               .indexed = 0,
+               .scan_index = -1,
+
+               .event_spec = apds9960_pxs_event_spec,
+               .num_event_specs = ARRAY_SIZE(apds9960_pxs_event_spec),
+       },
+       /* Gesture Sensor */
+       APDS9960_GESTURE_CHANNEL(UP, 0),
+       APDS9960_GESTURE_CHANNEL(DOWN, 1),
+       APDS9960_GESTURE_CHANNEL(LEFT, 2),
+       APDS9960_GESTURE_CHANNEL(RIGHT, 3),
+       /* ALS */
+       {
+               .type = IIO_INTENSITY,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
+                       BIT(IIO_CHAN_INFO_INT_TIME),
+               .channel2 = IIO_MOD_LIGHT_CLEAR,
+               .address = APDS9960_REG_ALS_CHANNEL(CLEAR),
+               .modified = 1,
+               .scan_index = -1,
+
+               .event_spec = apds9960_als_event_spec,
+               .num_event_specs = ARRAY_SIZE(apds9960_als_event_spec),
+       },
+       /* RGB Sensor */
+       APDS9960_INTENSITY_CHANNEL(RED),
+       APDS9960_INTENSITY_CHANNEL(GREEN),
+       APDS9960_INTENSITY_CHANNEL(BLUE),
+};
+
+/* integration time in us */
+static const int apds9960_int_time[][2] =
+       { {28000, 246}, {100000, 219}, {200000, 182}, {700000, 0} };
+
+/* gain mapping */
+static const int apds9960_pxs_gain_map[] = {1, 2, 4, 8};
+static const int apds9960_als_gain_map[] = {1, 4, 16, 64};
+
+static IIO_CONST_ATTR(proximity_scale_available, "1 2 4 8");
+static IIO_CONST_ATTR(intensity_scale_available, "1 4 16 64");
+static IIO_CONST_ATTR_INT_TIME_AVAIL("0.028 0.1 0.2 0.7");
+
+static struct attribute *apds9960_attributes[] = {
+       &iio_const_attr_proximity_scale_available.dev_attr.attr,
+       &iio_const_attr_intensity_scale_available.dev_attr.attr,
+       &iio_const_attr_integration_time_available.dev_attr.attr,
+       NULL,
+};
+
+static struct attribute_group apds9960_attribute_group = {
+       .attrs = apds9960_attributes,
+};
+
+static const struct reg_field apds9960_reg_field_int_als =
+                               REG_FIELD(APDS9960_REG_ENABLE, 4, 4);
+
+static const struct reg_field apds9960_reg_field_int_ges =
+                               REG_FIELD(APDS9960_REG_GCONF_4, 1, 1);
+
+static const struct reg_field apds9960_reg_field_int_pxs =
+                               REG_FIELD(APDS9960_REG_ENABLE, 5, 5);
+
+static const struct reg_field apds9960_reg_field_enable_als =
+                               REG_FIELD(APDS9960_REG_ENABLE, 1, 1);
+
+static const struct reg_field apds9960_reg_field_enable_ges =
+                               REG_FIELD(APDS9960_REG_ENABLE, 6, 6);
+
+static const struct reg_field apds9960_reg_field_enable_pxs =
+                               REG_FIELD(APDS9960_REG_ENABLE, 2, 2);
+
+static int apds9960_set_it_time(struct apds9960_data *data, int val2)
+{
+       int ret = -EINVAL;
+       int idx;
+
+       for (idx = 0; idx < ARRAY_SIZE(apds9960_int_time); idx++) {
+               if (apds9960_int_time[idx][0] == val2) {
+                       mutex_lock(&data->lock);
+                       ret = regmap_write(data->regmap, APDS9960_REG_ATIME,
+                                                apds9960_int_time[idx][1]);
+                       if (!ret)
+                               data->als_adc_int_us = val2;
+                       mutex_unlock(&data->lock);
+                       break;
+               }
+       }
+
+       return ret;
+}
+
+static int apds9960_set_pxs_gain(struct apds9960_data *data, int val)
+{
+       int ret = -EINVAL;
+       int idx;
+
+       for (idx = 0; idx < ARRAY_SIZE(apds9960_pxs_gain_map); idx++) {
+               if (apds9960_pxs_gain_map[idx] == val) {
+                       /* pxs + gesture gains are mirrored */
+                       mutex_lock(&data->lock);
+                       ret = regmap_update_bits(data->regmap,
+                               APDS9960_REG_CONTROL,
+                               APDS9960_REG_CONTROL_PGAIN_MASK,
+                               idx << APDS9960_REG_CONTROL_PGAIN_MASK_SHIFT);
+                       if (ret) {
+                               mutex_unlock(&data->lock);
+                               break;
+                       }
+
+                       ret = regmap_update_bits(data->regmap,
+                               APDS9960_REG_CONFIG_2,
+                               APDS9960_REG_CONFIG_2_GGAIN_MASK,
+                               idx << APDS9960_REG_CONFIG_2_GGAIN_MASK_SHIFT);
+                       if (!ret)
+                               data->pxs_gain = idx;
+                       mutex_unlock(&data->lock);
+                       break;
+               }
+       }
+
+       return ret;
+}
+
+static int apds9960_set_als_gain(struct apds9960_data *data, int val)
+{
+       int ret = -EINVAL;
+       int idx;
+
+       for (idx = 0; idx < ARRAY_SIZE(apds9960_als_gain_map); idx++) {
+               if (apds9960_als_gain_map[idx] == val) {
+                       mutex_lock(&data->lock);
+                       ret = regmap_update_bits(data->regmap,
+                                       APDS9960_REG_CONTROL,
+                                       APDS9960_REG_CONTROL_AGAIN_MASK, idx);
+                       if (!ret)
+                               data->als_gain = idx;
+                       mutex_unlock(&data->lock);
+                       break;
+               }
+       }
+
+       return ret;
+}
+
+#ifdef CONFIG_PM
+static int apds9960_set_power_state(struct apds9960_data *data, bool on)
+{
+       struct device *dev = &data->client->dev;
+       int ret = 0;
+
+       mutex_lock(&data->lock);
+
+       if (on) {
+               int suspended;
+
+               suspended = pm_runtime_suspended(dev);
+               ret = pm_runtime_get_sync(dev);
+
+               /* Allow one integration cycle before allowing a reading */
+               if (suspended)
+                       usleep_range(data->als_adc_int_us,
+                                    APDS9960_MAX_INT_TIME_IN_US);
+       } else {
+               ret = pm_runtime_put_autosuspend(dev);
+       }
+
+       mutex_unlock(&data->lock);
+
+       return ret;
+}
+#else
+static int apds9960_set_power_state(struct apds9960_data *data, bool on)
+{
+       return 0;
+}
+#endif
+
+static int apds9960_read_raw(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan,
+                            int *val, int *val2, long mask)
+{
+       struct apds9960_data *data = iio_priv(indio_dev);
+       __le16 buf;
+       int ret = -EINVAL;
+
+       if (data->gesture_mode_running)
+               return -EBUSY;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               apds9960_set_power_state(data, true);
+               switch (chan->type) {
+               case IIO_PROXIMITY:
+                       ret = regmap_read(data->regmap, chan->address, val);
+                       if (!ret)
+                               ret = IIO_VAL_INT;
+                       break;
+               case IIO_INTENSITY:
+                       ret = regmap_bulk_read(data->regmap, chan->address,
+                                              &buf, 2);
+                       if (!ret)
+                               ret = IIO_VAL_INT;
+                       *val = le16_to_cpu(buf);
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               apds9960_set_power_state(data, false);
+               break;
+       case IIO_CHAN_INFO_INT_TIME:
+               /* RGB + ALS sensors only have integration time */
+               mutex_lock(&data->lock);
+               switch (chan->type) {
+               case IIO_INTENSITY:
+                       *val = 0;
+                       *val2 = data->als_adc_int_us;
+                       ret = IIO_VAL_INT_PLUS_MICRO;
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               mutex_unlock(&data->lock);
+               break;
+       case IIO_CHAN_INFO_SCALE:
+               mutex_lock(&data->lock);
+               switch (chan->type) {
+               case IIO_PROXIMITY:
+                       *val = apds9960_pxs_gain_map[data->pxs_gain];
+                       ret = IIO_VAL_INT;
+                       break;
+               case IIO_INTENSITY:
+                       *val = apds9960_als_gain_map[data->als_gain];
+                       ret = IIO_VAL_INT;
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               mutex_unlock(&data->lock);
+               break;
+       }
+
+       return ret;
+};
+
+static int apds9960_write_raw(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan,
+                            int val, int val2, long mask)
+{
+       struct apds9960_data *data = iio_priv(indio_dev);
+
+       switch (mask) {
+       case IIO_CHAN_INFO_INT_TIME:
+               /* RGB + ALS sensors only have int time */
+               switch (chan->type) {
+               case IIO_INTENSITY:
+                       if (val != 0)
+                               return -EINVAL;
+                       return apds9960_set_it_time(data, val2);
+               default:
+                       return -EINVAL;
+               }
+       case IIO_CHAN_INFO_SCALE:
+               if (val2 != 0)
+                       return -EINVAL;
+               switch (chan->type) {
+               case IIO_PROXIMITY:
+                       return apds9960_set_pxs_gain(data, val);
+               case IIO_INTENSITY:
+                       return apds9960_set_als_gain(data, val);
+               default:
+                       return -EINVAL;
+               }
+       default:
+               return -EINVAL;
+       };
+
+       return 0;
+}
+
+static inline int apds9960_get_thres_reg(const struct iio_chan_spec *chan,
+                                        enum iio_event_direction dir,
+                                        u8 *reg)
+{
+       switch (dir) {
+       case IIO_EV_DIR_RISING:
+               switch (chan->type) {
+               case IIO_PROXIMITY:
+                       *reg = APDS9960_REG_PIHT;
+                       break;
+               case IIO_INTENSITY:
+                       *reg = APDS9960_REG_AIHTL;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       case IIO_EV_DIR_FALLING:
+               switch (chan->type) {
+               case IIO_PROXIMITY:
+                       *reg = APDS9960_REG_PILT;
+                       break;
+               case IIO_INTENSITY:
+                       *reg = APDS9960_REG_AILTL;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int apds9960_read_event(struct iio_dev *indio_dev,
+                              const struct iio_chan_spec *chan,
+                              enum iio_event_type type,
+                              enum iio_event_direction dir,
+                              enum iio_event_info info,
+                              int *val, int *val2)
+{
+       u8 reg;
+       __le16 buf;
+       int ret = 0;
+       struct apds9960_data *data = iio_priv(indio_dev);
+
+       if (info != IIO_EV_INFO_VALUE)
+               return -EINVAL;
+
+       ret = apds9960_get_thres_reg(chan, dir, &reg);
+       if (ret < 0)
+               return ret;
+
+       if (chan->type == IIO_PROXIMITY) {
+               ret = regmap_read(data->regmap, reg, val);
+               if (ret < 0)
+                       return ret;
+       } else if (chan->type == IIO_INTENSITY) {
+               ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
+               if (ret < 0)
+                       return ret;
+               *val = le16_to_cpu(buf);
+       } else
+               return -EINVAL;
+
+       *val2 = 0;
+
+       return IIO_VAL_INT;
+}
+
+static int apds9960_write_event(struct iio_dev *indio_dev,
+                               const struct iio_chan_spec *chan,
+                               enum iio_event_type type,
+                               enum iio_event_direction dir,
+                               enum iio_event_info info,
+                               int val, int val2)
+{
+       u8 reg;
+       __le16 buf;
+       int ret = 0;
+       struct apds9960_data *data = iio_priv(indio_dev);
+
+       if (info != IIO_EV_INFO_VALUE)
+               return -EINVAL;
+
+       ret = apds9960_get_thres_reg(chan, dir, &reg);
+       if (ret < 0)
+               return ret;
+
+       if (chan->type == IIO_PROXIMITY) {
+               if (val < 0 || val > APDS9960_MAX_PXS_THRES_VAL)
+                       return -EINVAL;
+               ret = regmap_write(data->regmap, reg, val);
+               if (ret < 0)
+                       return ret;
+       } else if (chan->type == IIO_INTENSITY) {
+               if (val < 0 || val > APDS9960_MAX_ALS_THRES_VAL)
+                       return -EINVAL;
+               buf = cpu_to_le16(val);
+               ret = regmap_bulk_write(data->regmap, reg, &buf, 2);
+               if (ret < 0)
+                       return ret;
+       } else
+               return -EINVAL;
+
+       return 0;
+}
+
+static int apds9960_read_event_config(struct iio_dev *indio_dev,
+                                     const struct iio_chan_spec *chan,
+                                     enum iio_event_type type,
+                                     enum iio_event_direction dir)
+{
+       struct apds9960_data *data = iio_priv(indio_dev);
+
+       switch (chan->type) {
+       case IIO_PROXIMITY:
+               return data->pxs_int;
+       case IIO_INTENSITY:
+               return data->als_int;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int apds9960_write_event_config(struct iio_dev *indio_dev,
+                                      const struct iio_chan_spec *chan,
+                                      enum iio_event_type type,
+                                      enum iio_event_direction dir,
+                                      int state)
+{
+       struct apds9960_data *data = iio_priv(indio_dev);
+       int ret;
+
+       state = !!state;
+
+       switch (chan->type) {
+       case IIO_PROXIMITY:
+               if (data->pxs_int == state)
+                       return -EINVAL;
+
+               ret = regmap_field_write(data->reg_int_pxs, state);
+               if (ret)
+                       return ret;
+               data->pxs_int = state;
+               apds9960_set_power_state(data, state);
+               break;
+       case IIO_INTENSITY:
+               if (data->als_int == state)
+                       return -EINVAL;
+
+               ret = regmap_field_write(data->reg_int_als, state);
+               if (ret)
+                       return ret;
+               data->als_int = state;
+               apds9960_set_power_state(data, state);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static const struct iio_info apds9960_info = {
+       .driver_module = THIS_MODULE,
+       .attrs = &apds9960_attribute_group,
+       .read_raw = apds9960_read_raw,
+       .write_raw = apds9960_write_raw,
+       .read_event_value = apds9960_read_event,
+       .write_event_value = apds9960_write_event,
+       .read_event_config = apds9960_read_event_config,
+       .write_event_config = apds9960_write_event_config,
+
+};
+
+static inline int apds9660_fifo_is_empty(struct apds9960_data *data)
+{
+       int cnt;
+       int ret;
+
+       ret = regmap_read(data->regmap, APDS9960_REG_GFLVL, &cnt);
+       if (ret)
+               return ret;
+
+       return cnt;
+}
+
+static void apds9960_read_gesture_fifo(struct apds9960_data *data)
+{
+       int ret, cnt = 0;
+
+       mutex_lock(&data->lock);
+       data->gesture_mode_running = 1;
+
+       while (cnt-- || (cnt = apds9660_fifo_is_empty(data) > 0)) {
+               ret = regmap_bulk_read(data->regmap, APDS9960_REG_GFIFO_BASE,
+                                     &data->buffer, 4);
+
+               if (ret)
+                       goto err_read;
+
+               iio_push_to_buffers(data->indio_dev, data->buffer);
+       }
+
+err_read:
+       data->gesture_mode_running = 0;
+       mutex_unlock(&data->lock);
+}
+
+static irqreturn_t apds9960_interrupt_handler(int irq, void *private)
+{
+       struct iio_dev *indio_dev = private;
+       struct apds9960_data *data = iio_priv(indio_dev);
+       int ret, status;
+
+       ret = regmap_read(data->regmap, APDS9960_REG_STATUS, &status);
+       if (ret < 0) {
+               dev_err(&data->client->dev, "irq status reg read failed\n");
+               return IRQ_HANDLED;
+       }
+
+       if ((status & APDS9960_REG_STATUS_ALS_INT) && data->als_int) {
+               iio_push_event(indio_dev,
+                              IIO_UNMOD_EVENT_CODE(IIO_INTENSITY, 0,
+                                                   IIO_EV_TYPE_THRESH,
+                                                   IIO_EV_DIR_EITHER),
+                              iio_get_time_ns());
+               regmap_write(data->regmap, APDS9960_REG_CICLEAR, 1);
+       }
+
+       if ((status & APDS9960_REG_STATUS_PS_INT) && data->pxs_int) {
+               iio_push_event(indio_dev,
+                              IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, 0,
+                                                   IIO_EV_TYPE_THRESH,
+                                                   IIO_EV_DIR_EITHER),
+                              iio_get_time_ns());
+               regmap_write(data->regmap, APDS9960_REG_PICLEAR, 1);
+       }
+
+       if (status & APDS9960_REG_STATUS_GINT)
+               apds9960_read_gesture_fifo(data);
+
+       return IRQ_HANDLED;
+}
+
+static int apds9960_set_powermode(struct apds9960_data *data, bool state)
+{
+       return regmap_update_bits(data->regmap, APDS9960_REG_ENABLE, 1, state);
+}
+
+static int apds9960_buffer_postenable(struct iio_dev *indio_dev)
+{
+       struct apds9960_data *data = iio_priv(indio_dev);
+       int ret;
+
+       ret = regmap_field_write(data->reg_int_ges, 1);
+       if (ret)
+               return ret;
+
+       ret = regmap_field_write(data->reg_enable_ges, 1);
+       if (ret)
+               return ret;
+
+       pm_runtime_get_sync(&data->client->dev);
+
+       return 0;
+}
+
+static int apds9960_buffer_predisable(struct iio_dev *indio_dev)
+{
+       struct apds9960_data *data = iio_priv(indio_dev);
+       int ret;
+
+       ret = regmap_field_write(data->reg_enable_ges, 0);
+       if (ret)
+               return ret;
+
+       ret = regmap_field_write(data->reg_int_ges, 0);
+       if (ret)
+               return ret;
+
+       pm_runtime_put_autosuspend(&data->client->dev);
+
+       return 0;
+}
+
+static const struct iio_buffer_setup_ops apds9960_buffer_setup_ops = {
+       .postenable = apds9960_buffer_postenable,
+       .predisable = apds9960_buffer_predisable,
+};
+
+static int apds9960_regfield_init(struct apds9960_data *data)
+{
+       struct device *dev = &data->client->dev;
+       struct regmap *regmap = data->regmap;
+
+       data->reg_int_als = devm_regmap_field_alloc(dev, regmap,
+                                               apds9960_reg_field_int_als);
+       if (IS_ERR(data->reg_int_als)) {
+               dev_err(dev, "INT ALS reg field init failed\n");
+               return PTR_ERR(data->reg_int_als);
+       }
+
+       data->reg_int_ges = devm_regmap_field_alloc(dev, regmap,
+                                               apds9960_reg_field_int_ges);
+       if (IS_ERR(data->reg_int_ges)) {
+               dev_err(dev, "INT gesture reg field init failed\n");
+               return PTR_ERR(data->reg_int_ges);
+       }
+
+       data->reg_int_pxs = devm_regmap_field_alloc(dev, regmap,
+                                               apds9960_reg_field_int_pxs);
+       if (IS_ERR(data->reg_int_pxs)) {
+               dev_err(dev, "INT pxs reg field init failed\n");
+               return PTR_ERR(data->reg_int_pxs);
+       }
+
+       data->reg_enable_als = devm_regmap_field_alloc(dev, regmap,
+                                               apds9960_reg_field_enable_als);
+       if (IS_ERR(data->reg_enable_als)) {
+               dev_err(dev, "Enable ALS reg field init failed\n");
+               return PTR_ERR(data->reg_enable_als);
+       }
+
+       data->reg_enable_ges = devm_regmap_field_alloc(dev, regmap,
+                                               apds9960_reg_field_enable_ges);
+       if (IS_ERR(data->reg_enable_ges)) {
+               dev_err(dev, "Enable gesture reg field init failed\n");
+               return PTR_ERR(data->reg_enable_ges);
+       }
+
+       data->reg_enable_pxs = devm_regmap_field_alloc(dev, regmap,
+                                               apds9960_reg_field_enable_pxs);
+       if (IS_ERR(data->reg_enable_pxs)) {
+               dev_err(dev, "Enable PXS reg field init failed\n");
+               return PTR_ERR(data->reg_enable_pxs);
+       }
+
+       return 0;
+}
+
+static int apds9960_chip_init(struct apds9960_data *data)
+{
+       int ret;
+
+       /* Default IT for ALS of 28 ms */
+       ret = apds9960_set_it_time(data, 28000);
+       if (ret)
+               return ret;
+
+       /* Ensure gesture interrupt is OFF */
+       ret = regmap_field_write(data->reg_int_ges, 0);
+       if (ret)
+               return ret;
+
+       /* Disable gesture sensor, since polling is useless from user-space */
+       ret = regmap_field_write(data->reg_enable_ges, 0);
+       if (ret)
+               return ret;
+
+       /* Ensure proximity interrupt is OFF */
+       ret = regmap_field_write(data->reg_int_pxs, 0);
+       if (ret)
+               return ret;
+
+       /* Enable proximity sensor for polling */
+       ret = regmap_field_write(data->reg_enable_pxs, 1);
+       if (ret)
+               return ret;
+
+       /* Ensure ALS interrupt is OFF */
+       ret = regmap_field_write(data->reg_int_als, 0);
+       if (ret)
+               return ret;
+
+       /* Enable ALS sensor for polling */
+       ret = regmap_field_write(data->reg_enable_als, 1);
+       if (ret)
+               return ret;
+       /*
+        * When enabled trigger an interrupt after 3 readings
+        * outside threshold for ALS + PXS
+        */
+       ret = regmap_write(data->regmap, APDS9960_REG_PERS,
+                          APDS9960_DEFAULT_PERS);
+       if (ret)
+               return ret;
+
+       /*
+        * Wait for 4 event outside gesture threshold to prevent interrupt
+        * flooding.
+        */
+       ret = regmap_update_bits(data->regmap, APDS9960_REG_GCONF_1,
+                       APDS9960_REG_GCONF_1_GFIFO_THRES_MASK,
+                       BIT(0) << APDS9960_REG_GCONF_1_GFIFO_THRES_MASK_SHIFT);
+       if (ret)
+               return ret;
+
+       /* Default ENTER and EXIT thresholds for the GESTURE engine. */
+       ret = regmap_write(data->regmap, APDS9960_REG_GPENTH,
+                          APDS9960_DEFAULT_GPENTH);
+       if (ret)
+               return ret;
+
+       ret = regmap_write(data->regmap, APDS9960_REG_GEXTH,
+                          APDS9960_DEFAULT_GEXTH);
+       if (ret)
+               return ret;
+
+       return apds9960_set_powermode(data, 1);
+}
+
+static int apds9960_probe(struct i2c_client *client,
+                         const struct i2c_device_id *id)
+{
+       struct apds9960_data *data;
+       struct iio_buffer *buffer;
+       struct iio_dev *indio_dev;
+       int ret;
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       buffer = devm_iio_kfifo_allocate(&client->dev);
+       if (!buffer)
+               return -ENOMEM;
+
+       iio_device_attach_buffer(indio_dev, buffer);
+
+       indio_dev->info = &apds9960_info;
+       indio_dev->name = APDS9960_DRV_NAME;
+       indio_dev->channels = apds9960_channels;
+       indio_dev->num_channels = ARRAY_SIZE(apds9960_channels);
+       indio_dev->available_scan_masks = apds9960_scan_masks;
+       indio_dev->modes = (INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE);
+       indio_dev->setup_ops = &apds9960_buffer_setup_ops;
+
+       data = iio_priv(indio_dev);
+       i2c_set_clientdata(client, indio_dev);
+
+       data->regmap = devm_regmap_init_i2c(client, &apds9960_regmap_config);
+       if (IS_ERR(data->regmap)) {
+               dev_err(&client->dev, "regmap initialization failed.\n");
+               return PTR_ERR(data->regmap);
+       }
+
+       data->client = client;
+       data->indio_dev = indio_dev;
+       mutex_init(&data->lock);
+
+       ret = pm_runtime_set_active(&client->dev);
+       if (ret)
+               goto error_power_down;
+
+       pm_runtime_enable(&client->dev);
+       pm_runtime_set_autosuspend_delay(&client->dev, 5000);
+       pm_runtime_use_autosuspend(&client->dev);
+
+       apds9960_set_power_state(data, true);
+
+       ret = apds9960_regfield_init(data);
+       if (ret)
+               goto error_power_down;
+
+       ret = apds9960_chip_init(data);
+       if (ret)
+               goto error_power_down;
+
+       if (client->irq <= 0) {
+               dev_err(&client->dev, "no valid irq defined\n");
+               ret = -EINVAL;
+               goto error_power_down;
+       }
+       ret = devm_request_threaded_irq(&client->dev, client->irq,
+                                       NULL, apds9960_interrupt_handler,
+                                       IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+                                       "apds9960_event",
+                                       indio_dev);
+       if (ret) {
+               dev_err(&client->dev, "request irq (%d) failed\n", client->irq);
+               goto error_power_down;
+       }
+
+       ret = iio_device_register(indio_dev);
+       if (ret)
+               goto error_power_down;
+
+       apds9960_set_power_state(data, false);
+
+       return 0;
+
+error_power_down:
+       apds9960_set_power_state(data, false);
+
+       return ret;
+}
+
+static int apds9960_remove(struct i2c_client *client)
+{
+       struct iio_dev *indio_dev = i2c_get_clientdata(client);
+       struct apds9960_data *data = iio_priv(indio_dev);
+
+       iio_device_unregister(indio_dev);
+       pm_runtime_disable(&client->dev);
+       pm_runtime_set_suspended(&client->dev);
+       apds9960_set_powermode(data, 0);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int apds9960_runtime_suspend(struct device *dev)
+{
+       struct apds9960_data *data =
+                       iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
+
+       return apds9960_set_powermode(data, 0);
+}
+
+static int apds9960_runtime_resume(struct device *dev)
+{
+       struct apds9960_data *data =
+                       iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
+
+       return apds9960_set_powermode(data, 1);
+}
+#endif
+
+static const struct dev_pm_ops apds9960_pm_ops = {
+       SET_RUNTIME_PM_OPS(apds9960_runtime_suspend,
+                          apds9960_runtime_resume, NULL)
+};
+
+static const struct i2c_device_id apds9960_id[] = {
+       { "apds9960", 0 },
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, apds9960_id);
+
+static struct i2c_driver apds9960_driver = {
+       .driver = {
+               .name   = APDS9960_DRV_NAME,
+               .pm     = &apds9960_pm_ops,
+       },
+       .probe          = apds9960_probe,
+       .remove         = apds9960_remove,
+       .id_table       = apds9960_id,
+};
+module_i2c_driver(apds9960_driver);
+
+MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
+MODULE_DESCRIPTION("ADPS9960 Gesture/RGB/ALS/Proximity sensor");
+MODULE_LICENSE("GPL");
index 923aa6aef0edc16a8b25fc93bf04424b64b6c9e0..01e111e72d4bb273c344b409119a134cd2a73a98 100644 (file)
@@ -793,7 +793,6 @@ static struct i2c_driver opt3001_driver = {
        .driver = {
                .name = "opt3001",
                .of_match_table = of_match_ptr(opt3001_of_match),
-               .owner = THIS_MODULE,
        },
 };
 
index 993eb201148e081f1e9092c780fc17ed61c11f0b..42d334ba612ea17797702c1cb485a31af8092660 100644 (file)
@@ -35,8 +35,8 @@
 #define STK3310_REG_ID                         0x3E
 #define STK3310_MAX_REG                                0x80
 
-#define STK3310_STATE_EN_PS                    0x01
-#define STK3310_STATE_EN_ALS                   0x02
+#define STK3310_STATE_EN_PS                    BIT(0)
+#define STK3310_STATE_EN_ALS                   BIT(1)
 #define STK3310_STATE_STANDBY                  0x00
 
 #define STK3310_CHIP_ID_VAL                    0x13
@@ -47,7 +47,6 @@
 #define STK3310_DRIVER_NAME                    "stk3310"
 #define STK3310_REGMAP_NAME                    "stk3310_regmap"
 #define STK3310_EVENT                          "stk3310_event"
-#define STK3310_GPIO                           "stk3310_gpio"
 
 #define STK3310_SCALE_AVAILABLE                        "6.4 1.6 0.4 0.1"
 
@@ -241,8 +240,11 @@ static int stk3310_write_event(struct iio_dev *indio_dev,
        struct stk3310_data *data = iio_priv(indio_dev);
        struct i2c_client *client = data->client;
 
-       regmap_field_read(data->reg_ps_gain, &index);
-       if (val > stk3310_ps_max[index])
+       ret = regmap_field_read(data->reg_ps_gain, &index);
+       if (ret < 0)
+               return ret;
+
+       if (val < 0 || val > stk3310_ps_max[index])
                return -EINVAL;
 
        if (dir == IIO_EV_DIR_RISING)
@@ -266,9 +268,12 @@ static int stk3310_read_event_config(struct iio_dev *indio_dev,
                                     enum iio_event_direction dir)
 {
        unsigned int event_val;
+       int ret;
        struct stk3310_data *data = iio_priv(indio_dev);
 
-       regmap_field_read(data->reg_int_ps, &event_val);
+       ret = regmap_field_read(data->reg_int_ps, &event_val);
+       if (ret < 0)
+               return ret;
 
        return event_val;
 }
@@ -307,14 +312,16 @@ static int stk3310_read_raw(struct iio_dev *indio_dev,
        struct stk3310_data *data = iio_priv(indio_dev);
        struct i2c_client *client = data->client;
 
+       if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY)
+               return -EINVAL;
+
        switch (mask) {
        case IIO_CHAN_INFO_RAW:
                if (chan->type == IIO_LIGHT)
                        reg = STK3310_REG_ALS_DATA_MSB;
-               else if (chan->type == IIO_PROXIMITY)
-                       reg = STK3310_REG_PS_DATA_MSB;
                else
-                       return -EINVAL;
+                       reg = STK3310_REG_PS_DATA_MSB;
+
                mutex_lock(&data->lock);
                ret = regmap_bulk_read(data->regmap, reg, &buf, 2);
                if (ret < 0) {
@@ -327,17 +334,23 @@ static int stk3310_read_raw(struct iio_dev *indio_dev,
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_INT_TIME:
                if (chan->type == IIO_LIGHT)
-                       regmap_field_read(data->reg_als_it, &index);
+                       ret = regmap_field_read(data->reg_als_it, &index);
                else
-                       regmap_field_read(data->reg_ps_it, &index);
+                       ret = regmap_field_read(data->reg_ps_it, &index);
+               if (ret < 0)
+                       return ret;
+
                *val = stk3310_it_table[index][0];
                *val2 = stk3310_it_table[index][1];
                return IIO_VAL_INT_PLUS_MICRO;
        case IIO_CHAN_INFO_SCALE:
                if (chan->type == IIO_LIGHT)
-                       regmap_field_read(data->reg_als_gain, &index);
+                       ret = regmap_field_read(data->reg_als_gain, &index);
                else
-                       regmap_field_read(data->reg_ps_gain, &index);
+                       ret = regmap_field_read(data->reg_ps_gain, &index);
+               if (ret < 0)
+                       return ret;
+
                *val = stk3310_scale_table[index][0];
                *val2 = stk3310_scale_table[index][1];
                return IIO_VAL_INT_PLUS_MICRO;
@@ -354,6 +367,9 @@ static int stk3310_write_raw(struct iio_dev *indio_dev,
        int index;
        struct stk3310_data *data = iio_priv(indio_dev);
 
+       if (chan->type != IIO_LIGHT && chan->type != IIO_PROXIMITY)
+               return -EINVAL;
+
        switch (mask) {
        case IIO_CHAN_INFO_INT_TIME:
                index = stk3310_get_index(stk3310_it_table,
@@ -368,7 +384,7 @@ static int stk3310_write_raw(struct iio_dev *indio_dev,
                        ret = regmap_field_write(data->reg_ps_it, index);
                if (ret < 0)
                        dev_err(&data->client->dev,
-                                       "sensor configuration failed\n");
+                               "sensor configuration failed\n");
                mutex_unlock(&data->lock);
                return ret;
 
@@ -385,7 +401,7 @@ static int stk3310_write_raw(struct iio_dev *indio_dev,
                        ret = regmap_field_write(data->reg_ps_gain, index);
                if (ret < 0)
                        dev_err(&data->client->dev,
-                                       "sensor configuration failed\n");
+                               "sensor configuration failed\n");
                mutex_unlock(&data->lock);
                return ret;
        }
@@ -419,8 +435,8 @@ static int stk3310_set_state(struct stk3310_data *data, u8 state)
                dev_err(&client->dev, "failed to change sensor state\n");
        } else if (state != STK3310_STATE_STANDBY) {
                /* Don't reset the 'enabled' flags if we're going in standby */
-               data->ps_enabled  = !!(state & 0x01);
-               data->als_enabled = !!(state & 0x02);
+               data->ps_enabled  = !!(state & STK3310_STATE_EN_PS);
+               data->als_enabled = !!(state & STK3310_STATE_EN_ALS);
        }
        mutex_unlock(&data->lock);
 
@@ -435,7 +451,10 @@ static int stk3310_init(struct iio_dev *indio_dev)
        struct stk3310_data *data = iio_priv(indio_dev);
        struct i2c_client *client = data->client;
 
-       regmap_read(data->regmap, STK3310_REG_ID, &chipid);
+       ret = regmap_read(data->regmap, STK3310_REG_ID, &chipid);
+       if (ret < 0)
+               return ret;
+
        if (chipid != STK3310_CHIP_ID_VAL &&
            chipid != STK3311_CHIP_ID_VAL) {
                dev_err(&client->dev, "invalid chip id: 0x%x\n", chipid);
@@ -457,30 +476,6 @@ static int stk3310_init(struct iio_dev *indio_dev)
        return ret;
 }
 
-static int stk3310_gpio_probe(struct i2c_client *client)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       dev = &client->dev;
-
-       /* gpio interrupt pin */
-       gpio = devm_gpiod_get_index(dev, STK3310_GPIO, 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "acpi gpio get index failed\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-
-       return ret;
-}
-
 static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg)
 {
        switch (reg) {
@@ -604,27 +599,30 @@ static int stk3310_probe(struct i2c_client *client,
        if (ret < 0)
                return ret;
 
-       if (client->irq < 0)
-               client->irq = stk3310_gpio_probe(client);
-
-       if (client->irq >= 0) {
+       if (client->irq > 0) {
                ret = devm_request_threaded_irq(&client->dev, client->irq,
                                                stk3310_irq_handler,
                                                stk3310_irq_event_handler,
                                                IRQF_TRIGGER_FALLING |
                                                IRQF_ONESHOT,
                                                STK3310_EVENT, indio_dev);
-               if (ret < 0)
+               if (ret < 0) {
                        dev_err(&client->dev, "request irq %d failed\n",
-                                       client->irq);
+                               client->irq);
+                       goto err_standby;
+               }
        }
 
        ret = iio_device_register(indio_dev);
        if (ret < 0) {
                dev_err(&client->dev, "device_register failed\n");
-               stk3310_set_state(data, STK3310_STATE_STANDBY);
+               goto err_standby;
        }
 
+       return 0;
+
+err_standby:
+       stk3310_set_state(data, STK3310_STATE_STANDBY);
        return ret;
 }
 
@@ -648,7 +646,7 @@ static int stk3310_suspend(struct device *dev)
 
 static int stk3310_resume(struct device *dev)
 {
-       int state = 0;
+       u8 state = 0;
        struct stk3310_data *data;
 
        data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
index 26979183d27cf323dc934d799b415e3a2b666980..cf94ec72b181fb756e32502b5c83059c1f9388b4 100644 (file)
@@ -158,9 +158,9 @@ static int tsl4531_check_id(struct i2c_client *client)
        case TSL45313_ID:
        case TSL45315_ID:
        case TSL45317_ID:
-               return 1;
-       default:
                return 0;
+       default:
+               return -ENODEV;
        }
 }
 
@@ -180,9 +180,10 @@ static int tsl4531_probe(struct i2c_client *client,
        data->client = client;
        mutex_init(&data->lock);
 
-       if (!tsl4531_check_id(client)) {
+       ret = tsl4531_check_id(client);
+       if (ret) {
                dev_err(&client->dev, "no TSL4531 sensor\n");
-               return -ENODEV;
+               return ret;
        }
 
        ret = i2c_smbus_write_byte_data(data->client, TSL4531_CONTROL,
diff --git a/drivers/iio/light/us5182d.c b/drivers/iio/light/us5182d.c
new file mode 100644 (file)
index 0000000..49dab3c
--- /dev/null
@@ -0,0 +1,507 @@
+/*
+ * Copyright (c) 2015 Intel Corporation
+ *
+ * Driver for UPISEMI us5182d Proximity and Ambient Light Sensor.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * To do: Interrupt support.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/mutex.h>
+
+#define US5182D_REG_CFG0                               0x00
+#define US5182D_CFG0_ONESHOT_EN                                BIT(6)
+#define US5182D_CFG0_SHUTDOWN_EN                       BIT(7)
+#define US5182D_CFG0_WORD_ENABLE                       BIT(0)
+
+#define US5182D_REG_CFG1                               0x01
+#define US5182D_CFG1_ALS_RES16                         BIT(4)
+#define US5182D_CFG1_AGAIN_DEFAULT                     0x00
+
+#define US5182D_REG_CFG2                               0x02
+#define US5182D_CFG2_PX_RES16                          BIT(4)
+#define US5182D_CFG2_PXGAIN_DEFAULT                    BIT(2)
+
+#define US5182D_REG_CFG3                               0x03
+#define US5182D_CFG3_LED_CURRENT100                    (BIT(4) | BIT(5))
+
+#define US5182D_REG_CFG4                               0x10
+
+/*
+ * Registers for tuning the auto dark current cancelling feature.
+ * DARK_TH(reg 0x27,0x28) - threshold (counts) for auto dark cancelling.
+ * when ALS  > DARK_TH --> ALS_Code = ALS - Upper(0x2A) * Dark
+ * when ALS < DARK_TH --> ALS_Code = ALS - Lower(0x29) * Dark
+ */
+#define US5182D_REG_UDARK_TH                   0x27
+#define US5182D_REG_DARK_AUTO_EN               0x2b
+#define US5182D_REG_AUTO_LDARK_GAIN            0x29
+#define US5182D_REG_AUTO_HDARK_GAIN            0x2a
+
+#define US5182D_OPMODE_ALS                     0x01
+#define US5182D_OPMODE_PX                      0x02
+#define US5182D_OPMODE_SHIFT                   4
+
+#define US5182D_REG_DARK_AUTO_EN_DEFAULT       0x80
+#define US5182D_REG_AUTO_LDARK_GAIN_DEFAULT    0x16
+#define US5182D_REG_AUTO_HDARK_GAIN_DEFAULT    0x00
+
+#define US5182D_REG_ADL                                0x0c
+#define US5182D_REG_PDL                                0x0e
+
+#define US5182D_REG_MODE_STORE                 0x21
+#define US5182D_STORE_MODE                     0x01
+
+#define US5182D_REG_CHIPID                     0xb2
+
+#define US5182D_OPMODE_MASK                    GENMASK(5, 4)
+#define US5182D_AGAIN_MASK                     0x07
+#define US5182D_RESET_CHIP                     0x01
+
+#define US5182D_CHIPID                         0x26
+#define US5182D_DRV_NAME                       "us5182d"
+
+#define US5182D_GA_RESOLUTION                  1000
+
+#define US5182D_READ_BYTE                      1
+#define US5182D_READ_WORD                      2
+#define US5182D_OPSTORE_SLEEP_TIME             20 /* ms */
+
+/* Available ranges: [12354, 7065, 3998, 2202, 1285, 498, 256, 138] lux */
+static const int us5182d_scales[] = {188500, 107800, 61000, 33600, 19600, 7600,
+                                    3900, 2100};
+
+/*
+ * Experimental thresholds that work with US5182D sensor on evaluation board
+ * roughly between 12-32 lux
+ */
+static u16 us5182d_dark_ths_vals[] = {170, 200, 512, 512, 800, 2000, 4000,
+                                     8000};
+
+enum mode {
+       US5182D_ALS_PX,
+       US5182D_ALS_ONLY,
+       US5182D_PX_ONLY
+};
+
+struct us5182d_data {
+       struct i2c_client *client;
+       struct mutex lock;
+
+       /* Glass attenuation factor */
+       u32 ga;
+
+       /* Dark gain tuning */
+       u8 lower_dark_gain;
+       u8 upper_dark_gain;
+       u16 *us5182d_dark_ths;
+
+       u8 opmode;
+};
+
+static IIO_CONST_ATTR(in_illuminance_scale_available,
+                     "0.0021 0.0039 0.0076 0.0196 0.0336 0.061 0.1078 0.1885");
+
+static struct attribute *us5182d_attrs[] = {
+       &iio_const_attr_in_illuminance_scale_available.dev_attr.attr,
+       NULL
+};
+
+static const struct attribute_group us5182d_attr_group = {
+       .attrs = us5182d_attrs,
+};
+
+static const struct {
+       u8 reg;
+       u8 val;
+} us5182d_regvals[] = {
+       {US5182D_REG_CFG0, (US5182D_CFG0_SHUTDOWN_EN |
+                           US5182D_CFG0_WORD_ENABLE)},
+       {US5182D_REG_CFG1, US5182D_CFG1_ALS_RES16},
+       {US5182D_REG_CFG2, (US5182D_CFG2_PX_RES16 |
+                           US5182D_CFG2_PXGAIN_DEFAULT)},
+       {US5182D_REG_CFG3, US5182D_CFG3_LED_CURRENT100},
+       {US5182D_REG_MODE_STORE, US5182D_STORE_MODE},
+       {US5182D_REG_CFG4, 0x00},
+};
+
+static const struct iio_chan_spec us5182d_channels[] = {
+       {
+               .type = IIO_LIGHT,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+                                     BIT(IIO_CHAN_INFO_SCALE),
+       },
+       {
+               .type = IIO_PROXIMITY,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
+       }
+};
+
+static int us5182d_get_als(struct us5182d_data *data)
+{
+       int ret;
+       unsigned long result;
+
+       ret = i2c_smbus_read_word_data(data->client,
+                                      US5182D_REG_ADL);
+       if (ret < 0)
+               return ret;
+
+       result = ret * data->ga / US5182D_GA_RESOLUTION;
+       if (result > 0xffff)
+               result = 0xffff;
+
+       return result;
+}
+
+static int us5182d_set_opmode(struct us5182d_data *data, u8 mode)
+{
+       int ret;
+
+       ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG0);
+       if (ret < 0)
+               return ret;
+
+       /*
+        * In oneshot mode the chip will power itself down after taking the
+        * required measurement.
+        */
+       ret = ret | US5182D_CFG0_ONESHOT_EN;
+
+       /* update mode */
+       ret = ret & ~US5182D_OPMODE_MASK;
+       ret = ret | (mode << US5182D_OPMODE_SHIFT);
+
+       /*
+        * After updating the operating mode, the chip requires that
+        * the operation is stored, by writing 1 in the STORE_MODE
+        * register (auto-clearing).
+        */
+       ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret);
+       if (ret < 0)
+               return ret;
+
+       if (mode == data->opmode)
+               return 0;
+
+       ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_MODE_STORE,
+                                       US5182D_STORE_MODE);
+       if (ret < 0)
+               return ret;
+
+       data->opmode = mode;
+       msleep(US5182D_OPSTORE_SLEEP_TIME);
+
+       return 0;
+}
+
+static int us5182d_read_raw(struct iio_dev *indio_dev,
+                           struct iio_chan_spec const *chan, int *val,
+                           int *val2, long mask)
+{
+       struct us5182d_data *data = iio_priv(indio_dev);
+       int ret;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               switch (chan->type) {
+               case IIO_LIGHT:
+                       mutex_lock(&data->lock);
+                       ret = us5182d_set_opmode(data, US5182D_OPMODE_ALS);
+                       if (ret < 0)
+                               goto out_err;
+
+                       ret = us5182d_get_als(data);
+                       if (ret < 0)
+                               goto out_err;
+                       mutex_unlock(&data->lock);
+                       *val = ret;
+                       return IIO_VAL_INT;
+               case IIO_PROXIMITY:
+                       mutex_lock(&data->lock);
+                       ret = us5182d_set_opmode(data, US5182D_OPMODE_PX);
+                       if (ret < 0)
+                               goto out_err;
+
+                       ret = i2c_smbus_read_word_data(data->client,
+                                                      US5182D_REG_PDL);
+                       if (ret < 0)
+                               goto out_err;
+                       mutex_unlock(&data->lock);
+                       *val = ret;
+                       return  IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+
+       case IIO_CHAN_INFO_SCALE:
+               ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG1);
+               if (ret < 0)
+                       return ret;
+
+               *val = 0;
+               *val2 = us5182d_scales[ret & US5182D_AGAIN_MASK];
+
+               return IIO_VAL_INT_PLUS_MICRO;
+       default:
+               return -EINVAL;
+       }
+
+       return -EINVAL;
+out_err:
+       mutex_unlock(&data->lock);
+       return ret;
+}
+
+/**
+ * us5182d_update_dark_th - update Darh_Th registers
+ * @data       us5182d_data structure
+ * @index      index in us5182d_dark_ths array to use for the updated value
+ *
+ * Function needs to be called with a lock held because it needs two i2c write
+ * byte operations as these registers (0x27 0x28) don't work in word mode
+ * accessing.
+ */
+static int us5182d_update_dark_th(struct us5182d_data *data, int index)
+{
+       __be16 dark_th = cpu_to_be16(data->us5182d_dark_ths[index]);
+       int ret;
+
+       ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_UDARK_TH,
+                                       ((u8 *)&dark_th)[0]);
+       if (ret < 0)
+               return ret;
+
+       return i2c_smbus_write_byte_data(data->client, US5182D_REG_UDARK_TH + 1,
+                                       ((u8 *)&dark_th)[1]);
+}
+
+/**
+ * us5182d_apply_scale - update the ALS scale
+ * @data       us5182d_data structure
+ * @index      index in us5182d_scales array to use for the updated value
+ *
+ * Function needs to be called with a lock held as we're having more than one
+ * i2c operation.
+ */
+static int us5182d_apply_scale(struct us5182d_data *data, int index)
+{
+       int ret;
+
+       ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CFG1);
+       if (ret < 0)
+               return ret;
+
+       ret = ret & (~US5182D_AGAIN_MASK);
+       ret |= index;
+
+       ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG1, ret);
+       if (ret < 0)
+               return ret;
+
+       return us5182d_update_dark_th(data, index);
+}
+
+static int us5182d_write_raw(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan, int val,
+                            int val2, long mask)
+{
+       struct us5182d_data *data = iio_priv(indio_dev);
+       int ret, i;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SCALE:
+               if (val != 0)
+                       return -EINVAL;
+               for (i = 0; i < ARRAY_SIZE(us5182d_scales); i++)
+                       if (val2 == us5182d_scales[i]) {
+                               mutex_lock(&data->lock);
+                               ret = us5182d_apply_scale(data, i);
+                               mutex_unlock(&data->lock);
+                               return ret;
+                       }
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return -EINVAL;
+}
+
+static const struct iio_info us5182d_info = {
+       .driver_module  = THIS_MODULE,
+       .read_raw = us5182d_read_raw,
+       .write_raw = us5182d_write_raw,
+       .attrs = &us5182d_attr_group,
+};
+
+static int us5182d_reset(struct iio_dev *indio_dev)
+{
+       struct us5182d_data *data = iio_priv(indio_dev);
+
+       return i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG3,
+                                        US5182D_RESET_CHIP);
+}
+
+static int us5182d_init(struct iio_dev *indio_dev)
+{
+       struct us5182d_data *data = iio_priv(indio_dev);
+       int i, ret;
+
+       ret = us5182d_reset(indio_dev);
+       if (ret < 0)
+               return ret;
+
+       data->opmode = 0;
+       for (i = 0; i < ARRAY_SIZE(us5182d_regvals); i++) {
+               ret = i2c_smbus_write_byte_data(data->client,
+                                               us5182d_regvals[i].reg,
+                                               us5182d_regvals[i].val);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static void us5182d_get_platform_data(struct iio_dev *indio_dev)
+{
+       struct us5182d_data *data = iio_priv(indio_dev);
+
+       if (device_property_read_u32(&data->client->dev, "upisemi,glass-coef",
+                                    &data->ga))
+               data->ga = US5182D_GA_RESOLUTION;
+       if (device_property_read_u16_array(&data->client->dev,
+                                          "upisemi,dark-ths",
+                                          data->us5182d_dark_ths,
+                                          ARRAY_SIZE(us5182d_dark_ths_vals)))
+               data->us5182d_dark_ths = us5182d_dark_ths_vals;
+       if (device_property_read_u8(&data->client->dev,
+                                   "upisemi,upper-dark-gain",
+                                   &data->upper_dark_gain))
+               data->upper_dark_gain = US5182D_REG_AUTO_HDARK_GAIN_DEFAULT;
+       if (device_property_read_u8(&data->client->dev,
+                                   "upisemi,lower-dark-gain",
+                                   &data->lower_dark_gain))
+               data->lower_dark_gain = US5182D_REG_AUTO_LDARK_GAIN_DEFAULT;
+}
+
+static int  us5182d_dark_gain_config(struct iio_dev *indio_dev)
+{
+       struct us5182d_data *data = iio_priv(indio_dev);
+       int ret;
+
+       ret = us5182d_update_dark_th(data, US5182D_CFG1_AGAIN_DEFAULT);
+       if (ret < 0)
+               return ret;
+
+       ret = i2c_smbus_write_byte_data(data->client,
+                                       US5182D_REG_AUTO_LDARK_GAIN,
+                                       data->lower_dark_gain);
+       if (ret < 0)
+               return ret;
+
+       ret = i2c_smbus_write_byte_data(data->client,
+                                       US5182D_REG_AUTO_HDARK_GAIN,
+                                       data->upper_dark_gain);
+       if (ret < 0)
+               return ret;
+
+       return i2c_smbus_write_byte_data(data->client, US5182D_REG_DARK_AUTO_EN,
+                                        US5182D_REG_DARK_AUTO_EN_DEFAULT);
+}
+
+static int us5182d_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct us5182d_data *data;
+       struct iio_dev *indio_dev;
+       int ret;
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       data = iio_priv(indio_dev);
+       i2c_set_clientdata(client, indio_dev);
+       data->client = client;
+
+       mutex_init(&data->lock);
+
+       indio_dev->dev.parent = &client->dev;
+       indio_dev->info = &us5182d_info;
+       indio_dev->name = US5182D_DRV_NAME;
+       indio_dev->channels = us5182d_channels;
+       indio_dev->num_channels = ARRAY_SIZE(us5182d_channels);
+       indio_dev->modes = INDIO_DIRECT_MODE;
+
+       ret = i2c_smbus_read_byte_data(data->client, US5182D_REG_CHIPID);
+       if (ret != US5182D_CHIPID) {
+               dev_err(&data->client->dev,
+                       "Failed to detect US5182 light chip\n");
+               return (ret < 0) ? ret : -ENODEV;
+       }
+
+       us5182d_get_platform_data(indio_dev);
+       ret = us5182d_init(indio_dev);
+       if (ret < 0)
+               return ret;
+
+       ret = us5182d_dark_gain_config(indio_dev);
+       if (ret < 0)
+               return ret;
+
+       return iio_device_register(indio_dev);
+}
+
+static int us5182d_remove(struct i2c_client *client)
+{
+       iio_device_unregister(i2c_get_clientdata(client));
+       return i2c_smbus_write_byte_data(client, US5182D_REG_CFG0,
+                                        US5182D_CFG0_SHUTDOWN_EN);
+}
+
+static const struct acpi_device_id us5182d_acpi_match[] = {
+       { "USD5182", 0},
+       {}
+};
+
+MODULE_DEVICE_TABLE(acpi, us5182d_acpi_match);
+
+static const struct i2c_device_id us5182d_id[] = {
+               {"usd5182", 0},
+               {}
+};
+
+MODULE_DEVICE_TABLE(i2c, us5182d_id);
+
+static struct i2c_driver us5182d_driver = {
+       .driver = {
+               .name = US5182D_DRV_NAME,
+               .acpi_match_table = ACPI_PTR(us5182d_acpi_match),
+       },
+       .probe = us5182d_probe,
+       .remove = us5182d_remove,
+       .id_table = us5182d_id,
+
+};
+module_i2c_driver(us5182d_driver);
+
+MODULE_AUTHOR("Adriana Reus <adriana.reus@intel.com>");
+MODULE_DESCRIPTION("Driver for us5182d Proximity and Light Sensor");
+MODULE_LICENSE("GPL v2");
index efb9350b0d766a0915a2c091c04b9bdea15c5d4e..868abada34096c872f8e169fedef41a3285d2df1 100644 (file)
@@ -24,6 +24,24 @@ config AK09911
        help
          Deprecated: AK09911 is now supported by AK8975 driver.
 
+config BMC150_MAGN
+       tristate "Bosch BMC150 Magnetometer Driver"
+       depends on I2C
+       select REGMAP_I2C
+       select IIO_BUFFER
+       select IIO_TRIGGERED_BUFFER
+       help
+         Say yes here to build support for the BMC150 magnetometer.
+
+         Currently this only supports the device via an i2c interface.
+
+         This is a combo module with both accelerometer and magnetometer.
+         This driver is only implementing magnetometer part, which has
+         its own address and register map.
+
+         To compile this driver as a module, choose M here: the module will be
+         called bmc150_magn.
+
 config MAG3110
        tristate "Freescale MAG3110 3-Axis Magnetometer"
        depends on I2C
@@ -87,19 +105,4 @@ config IIO_ST_MAGN_SPI_3AXIS
        depends on IIO_ST_MAGN_3AXIS
        depends on IIO_ST_SENSORS_SPI
 
-config BMC150_MAGN
-       tristate "Bosch BMC150 Magnetometer Driver"
-       depends on I2C
-       select REGMAP_I2C
-       select IIO_BUFFER
-       select IIO_TRIGGERED_BUFFER
-       help
-         Say yes here to build support for the BMC150 magnetometer.
-
-         Currently this only supports the device via an i2c interface.
-
-         This is a combo module with both accelerometer and magnetometer.
-         This driver is only implementing magnetometer part, which has
-         its own address and register map.
-
 endmenu
index 33b1d4d54ee70a6b064c1c3aabed171e9a0b7892..2c72df458ec28bb6622da13897d789f8e73a6a91 100644 (file)
@@ -4,6 +4,7 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AK8975)   += ak8975.o
+obj-$(CONFIG_BMC150_MAGN) += bmc150_magn.o
 obj-$(CONFIG_MAG3110)  += mag3110.o
 obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o
 obj-$(CONFIG_MMC35240) += mmc35240.o
@@ -14,5 +15,3 @@ st_magn-$(CONFIG_IIO_BUFFER) += st_magn_buffer.o
 
 obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o
 obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o
-
-obj-$(CONFIG_BMC150_MAGN) += bmc150_magn.o
index d8e614ca069fe7e3d55da67464be889a64e8af64..1615b23d7b2a64019c474ac566b5713bf587e29b 100644 (file)
@@ -37,7 +37,6 @@
 
 #define BMC150_MAGN_DRV_NAME                   "bmc150_magn"
 #define BMC150_MAGN_IRQ_NAME                   "bmc150_magn_event"
-#define BMC150_MAGN_GPIO_INT                   "interrupt"
 
 #define BMC150_MAGN_REG_CHIP_ID                        0x40
 #define BMC150_MAGN_CHIP_ID_VAL                        0x32
@@ -833,31 +832,6 @@ static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = {
        .postdisable = bmc150_magn_buffer_postdisable,
 };
 
-static int bmc150_magn_gpio_probe(struct i2c_client *client)
-{
-       struct device *dev;
-       struct gpio_desc *gpio;
-       int ret;
-
-       if (!client)
-               return -EINVAL;
-
-       dev = &client->dev;
-
-       /* data ready GPIO interrupt pin */
-       gpio = devm_gpiod_get_index(dev, BMC150_MAGN_GPIO_INT, 0, GPIOD_IN);
-       if (IS_ERR(gpio)) {
-               dev_err(dev, "ACPI GPIO get index failed\n");
-               return PTR_ERR(gpio);
-       }
-
-       ret = gpiod_to_irq(gpio);
-
-       dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
-
-       return ret;
-}
-
 static const char *bmc150_magn_match_acpi_device(struct device *dev)
 {
        const struct acpi_device_id *id;
@@ -911,9 +885,6 @@ static int bmc150_magn_probe(struct i2c_client *client,
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->info = &bmc150_magn_info;
 
-       if (client->irq <= 0)
-               client->irq = bmc150_magn_gpio_probe(client);
-
        if (client->irq > 0) {
                data->dready_trig = devm_iio_trigger_alloc(&client->dev,
                                                           "%s-dev%d",
index f8dc4b85d70c60858f26b18aba3e3be8ffe43c92..b27f0146647bb14996dda61d0a11bd31fc2de6cc 100644 (file)
@@ -560,6 +560,7 @@ static const struct iio_info magn_info = {
        .attrs = &st_magn_attribute_group,
        .read_raw = &st_magn_read_raw,
        .write_raw = &st_magn_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig
new file mode 100644 (file)
index 0000000..fd75db7
--- /dev/null
@@ -0,0 +1,20 @@
+#
+# Potentiometer drivers
+#
+# When adding new entries keep the list in alphabetical order
+
+menu "Digital potentiometers"
+
+config MCP4531
+       tristate "Microchip MCP45xx/MCP46xx Digital Potentiometer driver"
+       depends on I2C
+       help
+         Say yes here to build support for the Microchip
+         MCP4531, MCP4532, MCP4551, MCP4552,
+         MCP4631, MCP4632, MCP4651, MCP4652
+         digital potentiomenter chips.
+
+         To compile this driver as a module, choose M here: the
+         module will be called mcp4531.
+
+endmenu
diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile
new file mode 100644 (file)
index 0000000..8afe492
--- /dev/null
@@ -0,0 +1,6 @@
+#
+# Makefile for industrial I/O potentiometer drivers
+#
+
+# When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_MCP4531) += mcp4531.o
diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
new file mode 100644 (file)
index 0000000..a3f6687
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * Industrial I/O driver for Microchip digital potentiometers
+ * Copyright (c) 2015  Axentia Technologies AB
+ * Author: Peter Rosin <peda@axentia.se>
+ *
+ * Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22096b.pdf
+ *
+ * DEVID       #Wipers #Positions      Resistor Opts (kOhm)    i2c address
+ * mcp4531     1       129             5, 10, 50, 100          010111x
+ * mcp4532     1       129             5, 10, 50, 100          01011xx
+ * mcp4551     1       257             5, 10, 50, 100          010111x
+ * mcp4552     1       257             5, 10, 50, 100          01011xx
+ * mcp4631     2       129             5, 10, 50, 100          0101xxx
+ * mcp4632     2       129             5, 10, 50, 100          01011xx
+ * mcp4651     2       257             5, 10, 50, 100          0101xxx
+ * mcp4652     2       257             5, 10, 50, 100          01011xx
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/err.h>
+
+#include <linux/iio/iio.h>
+
+struct mcp4531_cfg {
+       int wipers;
+       int max_pos;
+       int kohms;
+};
+
+enum mcp4531_type {
+       MCP453x_502,
+       MCP453x_103,
+       MCP453x_503,
+       MCP453x_104,
+       MCP455x_502,
+       MCP455x_103,
+       MCP455x_503,
+       MCP455x_104,
+       MCP463x_502,
+       MCP463x_103,
+       MCP463x_503,
+       MCP463x_104,
+       MCP465x_502,
+       MCP465x_103,
+       MCP465x_503,
+       MCP465x_104,
+};
+
+static const struct mcp4531_cfg mcp4531_cfg[] = {
+       [MCP453x_502] = { .wipers = 1, .max_pos = 128, .kohms =   5, },
+       [MCP453x_103] = { .wipers = 1, .max_pos = 128, .kohms =  10, },
+       [MCP453x_503] = { .wipers = 1, .max_pos = 128, .kohms =  50, },
+       [MCP453x_104] = { .wipers = 1, .max_pos = 128, .kohms = 100, },
+       [MCP455x_502] = { .wipers = 1, .max_pos = 256, .kohms =   5, },
+       [MCP455x_103] = { .wipers = 1, .max_pos = 256, .kohms =  10, },
+       [MCP455x_503] = { .wipers = 1, .max_pos = 256, .kohms =  50, },
+       [MCP455x_104] = { .wipers = 1, .max_pos = 256, .kohms = 100, },
+       [MCP463x_502] = { .wipers = 2, .max_pos = 128, .kohms =   5, },
+       [MCP463x_103] = { .wipers = 2, .max_pos = 128, .kohms =  10, },
+       [MCP463x_503] = { .wipers = 2, .max_pos = 128, .kohms =  50, },
+       [MCP463x_104] = { .wipers = 2, .max_pos = 128, .kohms = 100, },
+       [MCP465x_502] = { .wipers = 2, .max_pos = 256, .kohms =   5, },
+       [MCP465x_103] = { .wipers = 2, .max_pos = 256, .kohms =  10, },
+       [MCP465x_503] = { .wipers = 2, .max_pos = 256, .kohms =  50, },
+       [MCP465x_104] = { .wipers = 2, .max_pos = 256, .kohms = 100, },
+};
+
+#define MCP4531_WRITE (0 << 2)
+#define MCP4531_INCR  (1 << 2)
+#define MCP4531_DECR  (2 << 2)
+#define MCP4531_READ  (3 << 2)
+
+#define MCP4531_WIPER_SHIFT (4)
+
+struct mcp4531_data {
+       struct i2c_client *client;
+       unsigned long devid;
+};
+
+#define MCP4531_CHANNEL(ch) {                                  \
+       .type = IIO_RESISTANCE,                                 \
+       .indexed = 1,                                           \
+       .output = 1,                                            \
+       .channel = (ch),                                        \
+       .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),           \
+       .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),   \
+}
+
+static const struct iio_chan_spec mcp4531_channels[] = {
+       MCP4531_CHANNEL(0),
+       MCP4531_CHANNEL(1),
+};
+
+static int mcp4531_read_raw(struct iio_dev *indio_dev,
+                           struct iio_chan_spec const *chan,
+                           int *val, int *val2, long mask)
+{
+       struct mcp4531_data *data = iio_priv(indio_dev);
+       int address = chan->channel << MCP4531_WIPER_SHIFT;
+       s32 ret;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               ret = i2c_smbus_read_word_swapped(data->client,
+                                                 MCP4531_READ | address);
+               if (ret < 0)
+                       return ret;
+               *val = ret;
+               return IIO_VAL_INT;
+       case IIO_CHAN_INFO_SCALE:
+               *val = 1000 * mcp4531_cfg[data->devid].kohms;
+               *val2 = mcp4531_cfg[data->devid].max_pos;
+               return IIO_VAL_FRACTIONAL;
+       }
+
+       return -EINVAL;
+}
+
+static int mcp4531_write_raw(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan,
+                            int val, int val2, long mask)
+{
+       struct mcp4531_data *data = iio_priv(indio_dev);
+       int address = chan->channel << MCP4531_WIPER_SHIFT;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW:
+               if (val > mcp4531_cfg[data->devid].max_pos || val < 0)
+                       return -EINVAL;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return i2c_smbus_write_byte_data(data->client,
+                                        MCP4531_WRITE | address | (val >> 8),
+                                        val & 0xff);
+}
+
+static const struct iio_info mcp4531_info = {
+       .read_raw = mcp4531_read_raw,
+       .write_raw = mcp4531_write_raw,
+       .driver_module = THIS_MODULE,
+};
+
+static int mcp4531_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct device *dev = &client->dev;
+       unsigned long devid = id->driver_data;
+       struct mcp4531_data *data;
+       struct iio_dev *indio_dev;
+
+       if (!i2c_check_functionality(client->adapter,
+                                    I2C_FUNC_SMBUS_WORD_DATA)) {
+               dev_err(dev, "SMBUS Word Data not supported\n");
+               return -EIO;
+       }
+
+       indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+       if (!indio_dev)
+               return -ENOMEM;
+       data = iio_priv(indio_dev);
+       i2c_set_clientdata(client, indio_dev);
+       data->client = client;
+       data->devid = devid;
+
+       indio_dev->dev.parent = dev;
+       indio_dev->info = &mcp4531_info;
+       indio_dev->channels = mcp4531_channels;
+       indio_dev->num_channels = mcp4531_cfg[devid].wipers;
+       indio_dev->name = client->name;
+
+       return devm_iio_device_register(dev, indio_dev);
+}
+
+static const struct i2c_device_id mcp4531_id[] = {
+       { "mcp4531-502", MCP453x_502 },
+       { "mcp4531-103", MCP453x_103 },
+       { "mcp4531-503", MCP453x_503 },
+       { "mcp4531-104", MCP453x_104 },
+       { "mcp4532-502", MCP453x_502 },
+       { "mcp4532-103", MCP453x_103 },
+       { "mcp4532-503", MCP453x_503 },
+       { "mcp4532-104", MCP453x_104 },
+       { "mcp4551-502", MCP455x_502 },
+       { "mcp4551-103", MCP455x_103 },
+       { "mcp4551-503", MCP455x_503 },
+       { "mcp4551-104", MCP455x_104 },
+       { "mcp4552-502", MCP455x_502 },
+       { "mcp4552-103", MCP455x_103 },
+       { "mcp4552-503", MCP455x_503 },
+       { "mcp4552-104", MCP455x_104 },
+       { "mcp4631-502", MCP463x_502 },
+       { "mcp4631-103", MCP463x_103 },
+       { "mcp4631-503", MCP463x_503 },
+       { "mcp4631-104", MCP463x_104 },
+       { "mcp4632-502", MCP463x_502 },
+       { "mcp4632-103", MCP463x_103 },
+       { "mcp4632-503", MCP463x_503 },
+       { "mcp4632-104", MCP463x_104 },
+       { "mcp4651-502", MCP465x_502 },
+       { "mcp4651-103", MCP465x_103 },
+       { "mcp4651-503", MCP465x_503 },
+       { "mcp4651-104", MCP465x_104 },
+       { "mcp4652-502", MCP465x_502 },
+       { "mcp4652-103", MCP465x_103 },
+       { "mcp4652-503", MCP465x_503 },
+       { "mcp4652-104", MCP465x_104 },
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, mcp4531_id);
+
+static struct i2c_driver mcp4531_driver = {
+       .driver = {
+               .name   = "mcp4531",
+       },
+       .probe          = mcp4531_probe,
+       .id_table       = mcp4531_id,
+};
+
+module_i2c_driver(mcp4531_driver);
+
+MODULE_AUTHOR("Peter Rosin <peda@axentia.se>");
+MODULE_DESCRIPTION("MCP4531 digital potentiometer");
+MODULE_LICENSE("GPL");
index 4745179ff64b4b6afee6f237555dec5294e0fdf1..6f2e7c9ac23e33c557ecfd0517dca15dce91807e 100644 (file)
@@ -79,6 +79,19 @@ config MS5611_SPI
          To compile this driver as a module, choose M here: the module will
          be called ms5611_spi.
 
+config MS5637
+       tristate "Measurement Specialties MS5637 pressure & temperature sensor"
+       depends on I2C
+        select IIO_MS_SENSORS_I2C
+       help
+         If you say yes here you get support for the Measurement Specialties
+         MS5637 pressure and temperature sensor.
+         This driver is also used for MS8607 temperature, pressure & humidity
+         sensor
+
+         This driver can also be built as a module. If so, the module will
+         be called ms5637.
+
 config IIO_ST_PRESS
        tristate "STMicroelectronics pressure sensor Driver"
        depends on (I2C || SPI_MASTER) && SYSFS
index a4f98f8d90ed0c33d9023feb64d7fb8d5cddc389..46571c96823fce17c6eed8d3b9ef369371078eca 100644 (file)
@@ -10,6 +10,7 @@ obj-$(CONFIG_MPL3115) += mpl3115.o
 obj-$(CONFIG_MS5611) += ms5611_core.o
 obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o
 obj-$(CONFIG_MS5611_SPI) += ms5611_spi.o
+obj-$(CONFIG_MS5637) += ms5637.o
 obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o
 st_pressure-y := st_pressure_core.o
 st_pressure-$(CONFIG_IIO_BUFFER) += st_pressure_buffer.o
diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c
new file mode 100644 (file)
index 0000000..e8d0e0d
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * ms5637.c - Support for Measurement-Specialties ms5637 and ms8607
+ *            pressure & temperature sensor
+ *
+ * Copyright (c) 2015 Measurement-Specialties
+ *
+ * Licensed under the GPL-2.
+ *
+ * (7-bit I2C slave address 0x76)
+ *
+ * Datasheet:
+ *  http://www.meas-spec.com/downloads/MS5637-02BA03.pdf
+ * Datasheet:
+ *  http://www.meas-spec.com/downloads/MS8607-02BA01.pdf
+ */
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/stat.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/mutex.h>
+
+#include "../common/ms_sensors/ms_sensors_i2c.h"
+
+static const int ms5637_samp_freq[6] = { 960, 480, 240, 120, 60, 30 };
+/* String copy of the above const for readability purpose */
+static const char ms5637_show_samp_freq[] = "960 480 240 120 60 30";
+
+static int ms5637_read_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *channel, int *val,
+                          int *val2, long mask)
+{
+       int ret;
+       int temperature;
+       unsigned int pressure;
+       struct ms_tp_dev *dev_data = iio_priv(indio_dev);
+
+       switch (mask) {
+       case IIO_CHAN_INFO_PROCESSED:
+               ret = ms_sensors_read_temp_and_pressure(dev_data,
+                                                       &temperature,
+                                                       &pressure);
+               if (ret)
+                       return ret;
+
+               switch (channel->type) {
+               case IIO_TEMP:  /* in milli Â°C */
+                       *val = temperature;
+
+                       return IIO_VAL_INT;
+               case IIO_PRESSURE:      /* in kPa */
+                       *val = pressure / 1000;
+                       *val2 = (pressure % 1000) * 1000;
+
+                       return IIO_VAL_INT_PLUS_MICRO;
+               default:
+                       return -EINVAL;
+               }
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = ms5637_samp_freq[dev_data->res_index];
+
+               return IIO_VAL_INT;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int ms5637_write_raw(struct iio_dev *indio_dev,
+                           struct iio_chan_spec const *chan,
+                           int val, int val2, long mask)
+{
+       struct ms_tp_dev *dev_data = iio_priv(indio_dev);
+       int i;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               i = ARRAY_SIZE(ms5637_samp_freq);
+               while (i-- > 0)
+                       if (val == ms5637_samp_freq[i])
+                               break;
+               if (i < 0)
+                       return -EINVAL;
+               dev_data->res_index = i;
+
+               return 0;
+       default:
+               return -EINVAL;
+       }
+}
+
+static const struct iio_chan_spec ms5637_channels[] = {
+       {
+               .type = IIO_TEMP,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+       },
+       {
+               .type = IIO_PRESSURE,
+               .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+       }
+};
+
+static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(ms5637_show_samp_freq);
+
+static struct attribute *ms5637_attributes[] = {
+       &iio_const_attr_sampling_frequency_available.dev_attr.attr,
+       NULL,
+};
+
+static const struct attribute_group ms5637_attribute_group = {
+       .attrs = ms5637_attributes,
+};
+
+static const struct iio_info ms5637_info = {
+       .read_raw = ms5637_read_raw,
+       .write_raw = ms5637_write_raw,
+       .attrs = &ms5637_attribute_group,
+       .driver_module = THIS_MODULE,
+};
+
+static int ms5637_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       struct ms_tp_dev *dev_data;
+       struct iio_dev *indio_dev;
+       int ret;
+
+       if (!i2c_check_functionality(client->adapter,
+                                    I2C_FUNC_SMBUS_READ_WORD_DATA |
+                                    I2C_FUNC_SMBUS_WRITE_BYTE |
+                                    I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
+               dev_err(&client->dev,
+                       "Adapter does not support some i2c transaction\n");
+               return -ENODEV;
+       }
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       dev_data = iio_priv(indio_dev);
+       dev_data->client = client;
+       dev_data->res_index = 5;
+       mutex_init(&dev_data->lock);
+
+       indio_dev->info = &ms5637_info;
+       indio_dev->name = id->name;
+       indio_dev->dev.parent = &client->dev;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->channels = ms5637_channels;
+       indio_dev->num_channels = ARRAY_SIZE(ms5637_channels);
+
+       i2c_set_clientdata(client, indio_dev);
+
+       ret = ms_sensors_reset(client, 0x1E, 3000);
+       if (ret)
+               return ret;
+
+       ret = ms_sensors_tp_read_prom(dev_data);
+       if (ret)
+               return ret;
+
+       return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id ms5637_id[] = {
+       {"ms5637", 0},
+       {"ms8607-temppressure", 1},
+       {}
+};
+
+static struct i2c_driver ms5637_driver = {
+       .probe = ms5637_probe,
+       .id_table = ms5637_id,
+       .driver = {
+                  .name = "ms5637"
+                  },
+};
+
+module_i2c_driver(ms5637_driver);
+
+MODULE_DESCRIPTION("Measurement-Specialties ms5637 temperature & pressure driver");
+MODULE_AUTHOR("William Markezana <william.markezana@meas-spec.com>");
+MODULE_AUTHOR("Ludovic Tancerel <ludovic.tancerel@maplehightech.com>");
+MODULE_LICENSE("GPL v2");
index eb41d2b92c24048ce2c65918bc7d42e03640f19d..b39a2fb0671cd15638c0db19c2f068a52a02f8b6 100644 (file)
@@ -400,6 +400,7 @@ static const struct iio_info press_info = {
        .attrs = &st_press_attribute_group,
        .read_raw = &st_press_read_raw,
        .write_raw = &st_press_write_raw,
+       .debugfs_reg_access = &st_sensors_debugfs_reg_access,
 };
 
 #ifdef CONFIG_IIO_TRIGGER
index 41a8d8ffa0de47c00d444a0f24f5c60208db9614..ef4c73db5b53fb88d00985c80950add9363de671 100644 (file)
@@ -20,6 +20,18 @@ endmenu
 
 menu "Proximity sensors"
 
+config LIDAR_LITE_V2
+       tristate "PulsedLight LIDAR sensor"
+       select IIO_BUFFER
+       select IIO_TRIGGERED_BUFFER
+       depends on I2C
+       help
+         Say Y to build a driver for PulsedLight LIDAR range finding
+         sensor.
+
+         To compile this driver as a module, choose M here: the
+         module will be called pulsedlight-lite-v2
+
 config SX9500
        tristate "SX9500 Semtech proximity sensor"
        select IIO_BUFFER
index 9818dc562abdc5706c94d47db805b3091e1f31db..9aadd9a8ee99854a2679a40f491f835eef8a9a98 100644 (file)
@@ -4,4 +4,5 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_AS3935)           += as3935.o
+obj-$(CONFIG_LIDAR_LITE_V2)    += pulsedlight-lidar-lite-v2.o
 obj-$(CONFIG_SX9500)           += sx9500.o
index 2865aa63f4f1de9cf4900700663bbbf617c49e2c..f4d29d5dbd5f88d6e5edffef142e86db30076d44 100644 (file)
@@ -434,6 +434,12 @@ static int as3935_remove(struct spi_device *spi)
        return 0;
 }
 
+static const struct of_device_id as3935_of_match[] = {
+       { .compatible = "ams,as3935", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, as3935_of_match);
+
 static const struct spi_device_id as3935_id[] = {
        {"as3935", 0},
        {},
@@ -443,6 +449,7 @@ MODULE_DEVICE_TABLE(spi, as3935_id);
 static struct spi_driver as3935_driver = {
        .driver = {
                .name   = "as3935",
+               .of_match_table = of_match_ptr(as3935_of_match),
                .pm     = AS3935_PM_OPS,
        },
        .probe          = as3935_probe,
diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
new file mode 100644 (file)
index 0000000..961f9f9
--- /dev/null
@@ -0,0 +1,289 @@
+/*
+ * pulsedlight-lidar-lite-v2.c - Support for PulsedLight LIDAR sensor
+ *
+ * Copyright (C) 2015 Matt Ranostay <mranostay@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * TODO: runtime pm, interrupt mode, and signal strength reporting
+ */
+
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
+
+#define LIDAR_REG_CONTROL              0x00
+#define LIDAR_REG_CONTROL_ACQUIRE      BIT(2)
+
+#define LIDAR_REG_STATUS               0x01
+#define LIDAR_REG_STATUS_INVALID       BIT(3)
+#define LIDAR_REG_STATUS_READY         BIT(0)
+
+#define LIDAR_REG_DATA_HBYTE   0x0f
+#define LIDAR_REG_DATA_LBYTE   0x10
+
+#define LIDAR_DRV_NAME "lidar"
+
+struct lidar_data {
+       struct iio_dev *indio_dev;
+       struct i2c_client *client;
+
+       u16 buffer[8]; /* 2 byte distance + 8 byte timestamp */
+};
+
+static const struct iio_chan_spec lidar_channels[] = {
+       {
+               .type = IIO_DISTANCE,
+               .info_mask_separate =
+                       BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
+               .scan_index = 0,
+               .scan_type = {
+                       .sign = 'u',
+                       .realbits = 16,
+                       .storagebits = 16,
+               },
+       },
+       IIO_CHAN_SOFT_TIMESTAMP(1),
+};
+
+static int lidar_read_byte(struct lidar_data *data, int reg)
+{
+       struct i2c_client *client = data->client;
+       int ret;
+
+       /*
+        * Device needs a STOP condition between address write, and data read
+        * so in turn i2c_smbus_read_byte_data cannot be used
+        */
+
+       ret = i2c_smbus_write_byte(client, reg);
+       if (ret < 0) {
+               dev_err(&client->dev, "cannot write addr value");
+               return ret;
+       }
+
+       ret = i2c_smbus_read_byte(client);
+       if (ret < 0)
+               dev_err(&client->dev, "cannot read data value");
+
+       return ret;
+}
+
+static inline int lidar_write_control(struct lidar_data *data, int val)
+{
+       return i2c_smbus_write_byte_data(data->client, LIDAR_REG_CONTROL, val);
+}
+
+static int lidar_read_measurement(struct lidar_data *data, u16 *reg)
+{
+       int ret;
+       int val;
+
+       ret = lidar_read_byte(data, LIDAR_REG_DATA_HBYTE);
+       if (ret < 0)
+               return ret;
+       val = ret << 8;
+
+       ret = lidar_read_byte(data, LIDAR_REG_DATA_LBYTE);
+       if (ret < 0)
+               return ret;
+
+       val |= ret;
+       *reg = val;
+
+       return 0;
+}
+
+static int lidar_get_measurement(struct lidar_data *data, u16 *reg)
+{
+       struct i2c_client *client = data->client;
+       int tries = 10;
+       int ret;
+
+       /* start sample */
+       ret = lidar_write_control(data, LIDAR_REG_CONTROL_ACQUIRE);
+       if (ret < 0) {
+               dev_err(&client->dev, "cannot send start measurement command");
+               return ret;
+       }
+
+       while (tries--) {
+               usleep_range(1000, 2000);
+
+               ret = lidar_read_byte(data, LIDAR_REG_STATUS);
+               if (ret < 0)
+                       break;
+
+               /* return 0 since laser is likely pointed out of range */
+               if (ret & LIDAR_REG_STATUS_INVALID) {
+                       *reg = 0;
+                       ret = 0;
+                       break;
+               }
+
+               /* sample ready to read */
+               if (!(ret & LIDAR_REG_STATUS_READY)) {
+                       ret = lidar_read_measurement(data, reg);
+                       break;
+               }
+               ret = -EIO;
+       }
+
+       return ret;
+}
+
+static int lidar_read_raw(struct iio_dev *indio_dev,
+                         struct iio_chan_spec const *chan,
+                         int *val, int *val2, long mask)
+{
+       struct lidar_data *data = iio_priv(indio_dev);
+       int ret = -EINVAL;
+
+       mutex_lock(&indio_dev->mlock);
+
+       if (iio_buffer_enabled(indio_dev) && mask == IIO_CHAN_INFO_RAW) {
+               ret = -EBUSY;
+               goto error_busy;
+       }
+
+       switch (mask) {
+       case IIO_CHAN_INFO_RAW: {
+               u16 reg;
+
+               ret = lidar_get_measurement(data, &reg);
+               if (!ret) {
+                       *val = reg;
+                       ret = IIO_VAL_INT;
+               }
+               break;
+       }
+       case IIO_CHAN_INFO_SCALE:
+               *val = 0;
+               *val2 = 10000;
+               ret = IIO_VAL_INT_PLUS_MICRO;
+               break;
+       }
+
+error_busy:
+       mutex_unlock(&indio_dev->mlock);
+
+       return ret;
+}
+
+static irqreturn_t lidar_trigger_handler(int irq, void *private)
+{
+       struct iio_poll_func *pf = private;
+       struct iio_dev *indio_dev = pf->indio_dev;
+       struct lidar_data *data = iio_priv(indio_dev);
+       int ret;
+
+       ret = lidar_get_measurement(data, data->buffer);
+       if (!ret) {
+               iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
+                                                  iio_get_time_ns());
+       } else {
+               dev_err(&data->client->dev, "cannot read LIDAR measurement");
+       }
+
+       iio_trigger_notify_done(indio_dev->trig);
+
+       return IRQ_HANDLED;
+}
+
+static const struct iio_info lidar_info = {
+       .driver_module = THIS_MODULE,
+       .read_raw = lidar_read_raw,
+};
+
+static int lidar_probe(struct i2c_client *client,
+                      const struct i2c_device_id *id)
+{
+       struct lidar_data *data;
+       struct iio_dev *indio_dev;
+       int ret;
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       indio_dev->info = &lidar_info;
+       indio_dev->name = LIDAR_DRV_NAME;
+       indio_dev->channels = lidar_channels;
+       indio_dev->num_channels = ARRAY_SIZE(lidar_channels);
+       indio_dev->modes = INDIO_DIRECT_MODE;
+
+       data = iio_priv(indio_dev);
+       i2c_set_clientdata(client, indio_dev);
+
+       data->client = client;
+       data->indio_dev = indio_dev;
+
+       ret = iio_triggered_buffer_setup(indio_dev, NULL,
+                                        lidar_trigger_handler, NULL);
+       if (ret)
+               return ret;
+
+       ret = iio_device_register(indio_dev);
+       if (ret)
+               goto error_unreg_buffer;
+
+       return 0;
+
+error_unreg_buffer:
+       iio_triggered_buffer_cleanup(indio_dev);
+
+       return ret;
+}
+
+static int lidar_remove(struct i2c_client *client)
+{
+       struct iio_dev *indio_dev = i2c_get_clientdata(client);
+
+       iio_device_unregister(indio_dev);
+       iio_triggered_buffer_cleanup(indio_dev);
+
+       return 0;
+}
+
+static const struct i2c_device_id lidar_id[] = {
+       {"lidar-lite-v2", 0},
+       { },
+};
+MODULE_DEVICE_TABLE(i2c, lidar_id);
+
+static const struct of_device_id lidar_dt_ids[] = {
+       { .compatible = "pulsedlight,lidar-lite-v2" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, lidar_dt_ids);
+
+static struct i2c_driver lidar_driver = {
+       .driver = {
+               .name   = LIDAR_DRV_NAME,
+               .of_match_table = of_match_ptr(lidar_dt_ids),
+       },
+       .probe          = lidar_probe,
+       .remove         = lidar_remove,
+       .id_table       = lidar_id,
+};
+module_i2c_driver(lidar_driver);
+
+MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
+MODULE_DESCRIPTION("PulsedLight LIDAR sensor");
+MODULE_LICENSE("GPL");
index 3d756bd8c703230bfc93f530d03399f9f5e1413f..66cd09a18786a9123c7eeeb82c0e503ae9dee5e6 100644 (file)
@@ -868,21 +868,12 @@ static void sx9500_gpio_probe(struct i2c_client *client,
                              struct sx9500_data *data)
 {
        struct device *dev;
-       struct gpio_desc *gpio;
 
        if (!client)
                return;
 
        dev = &client->dev;
 
-       if (client->irq <= 0) {
-               gpio = devm_gpiod_get_index(dev, SX9500_GPIO_INT, 0, GPIOD_IN);
-               if (IS_ERR(gpio))
-                       dev_err(dev, "gpio get irq failed\n");
-               else
-                       client->irq = gpiod_to_irq(gpio);
-       }
-
        data->gpiod_rst = devm_gpiod_get_index(dev, SX9500_GPIO_RESET,
                                               0, GPIOD_OUT_HIGH);
        if (IS_ERR(data->gpiod_rst)) {
index 21feaa4661b4672425fad790b1d64af61fa084d2..c4664e5de791577e117a00f2fa276897d343e7a7 100644 (file)
@@ -23,4 +23,26 @@ config TMP006
          This driver can also be built as a module. If so, the module will
          be called tmp006.
 
+config TSYS01
+       tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection"
+       depends on I2C
+       select IIO_MS_SENSORS_I2C
+       help
+         If you say yes here you get support for the Measurement Specialties
+         TSYS01 I2C temperature sensor.
+
+         This driver can also be built as a module. If so, the module will
+         be called tsys01.
+
+config TSYS02D
+       tristate "Measurement Specialties TSYS02D temperature sensor"
+       depends on I2C
+       select IIO_MS_SENSORS_I2C
+       help
+         If you say yes here you get support for the Measurement Specialties
+         TSYS02D temperature sensor.
+
+         This driver can also be built as a module. If so, the module will
+         be called tsys02d.
+
 endmenu
index 40710a81158e1c770cf05f00546093fd5cdbef9f..02bc79d49b24cf83bb284b36d23bf18f7ebbbfa8 100644 (file)
@@ -4,3 +4,5 @@
 
 obj-$(CONFIG_MLX90614) += mlx90614.o
 obj-$(CONFIG_TMP006) += tmp006.o
+obj-$(CONFIG_TSYS01) += tsys01.o
+obj-$(CONFIG_TSYS02D) += tsys02d.o
index 5d033a5af615429c8f3eb38c6986dc5a728c123b..a570c2e2aac3e42998eabdba95c619f8615d7ce6 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (c) 2014 Peter Meerwald <pmeerw@pmeerw.net>
  * Copyright (c) 2015 Essensium NV
+ * Copyright (c) 2015 Melexis
  *
  * This file is subject to the terms and conditions of version 2 of
  * the GNU General Public License.  See the file COPYING in the main
@@ -20,7 +21,6 @@
  * always has a pull-up so we do not need an extra GPIO to drive it high.  If
  * the "wakeup" GPIO is not given, power management will be disabled.
  *
- * TODO: filter configuration
  */
 
 #include <linux/err.h>
@@ -32,6 +32,7 @@
 #include <linux/pm_runtime.h>
 
 #include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
 
 #define MLX90614_OP_RAM                0x00
 #define MLX90614_OP_EEPROM     0x20
@@ -71,6 +72,7 @@
 #define MLX90614_CONST_SCALE 20 /* Scale in milliKelvin (0.02 * 1000) */
 #define MLX90614_CONST_RAW_EMISSIVITY_MAX 65535 /* max value for emissivity */
 #define MLX90614_CONST_EMISSIVITY_RESOLUTION 15259 /* 1/65535 ~ 0.000015259 */
+#define MLX90614_CONST_FIR 0x7 /* Fixed value for FIR part of low pass filter */
 
 struct mlx90614_data {
        struct i2c_client *client;
@@ -79,6 +81,20 @@ struct mlx90614_data {
        unsigned long ready_timestamp; /* in jiffies */
 };
 
+/* Bandwidth values for IIR filtering */
+static const int mlx90614_iir_values[] = {77, 31, 20, 15, 723, 153, 110, 86};
+static IIO_CONST_ATTR(in_temp_object_filter_low_pass_3db_frequency_available,
+                     "0.15 0.20 0.31 0.77 0.86 1.10 1.53 7.23");
+
+static struct attribute *mlx90614_attributes[] = {
+       &iio_const_attr_in_temp_object_filter_low_pass_3db_frequency_available.dev_attr.attr,
+       NULL,
+};
+
+static const struct attribute_group mlx90614_attr_group = {
+       .attrs = mlx90614_attributes,
+};
+
 /*
  * Erase an address and write word.
  * The mutex must be locked before calling.
@@ -117,6 +133,43 @@ static s32 mlx90614_write_word(const struct i2c_client *client, u8 command,
        return ret;
 }
 
+/*
+ * Find the IIR value inside mlx90614_iir_values array and return its position
+ * which is equivalent to the bit value in sensor register
+ */
+static inline s32 mlx90614_iir_search(const struct i2c_client *client,
+                                     int value)
+{
+       int i;
+       s32 ret;
+
+       for (i = 0; i < ARRAY_SIZE(mlx90614_iir_values); ++i) {
+               if (value == mlx90614_iir_values[i])
+                       break;
+       }
+
+       if (i == ARRAY_SIZE(mlx90614_iir_values))
+               return -EINVAL;
+
+       /*
+        * CONFIG register values must not be changed so
+        * we must read them before we actually write
+        * changes
+        */
+       ret = i2c_smbus_read_word_data(client, MLX90614_CONFIG);
+       if (ret < 0)
+               return ret;
+
+       ret &= ~MLX90614_CONFIG_FIR_MASK;
+       ret |= MLX90614_CONST_FIR << MLX90614_CONFIG_FIR_SHIFT;
+       ret &= ~MLX90614_CONFIG_IIR_MASK;
+       ret |= i << MLX90614_CONFIG_IIR_SHIFT;
+
+       /* Write changed values */
+       ret = mlx90614_write_word(client, MLX90614_CONFIG, ret);
+       return ret;
+}
+
 #ifdef CONFIG_PM
 /*
  * If @startup is true, make sure MLX90614_TIMING_STARTUP ms have elapsed since
@@ -236,6 +289,21 @@ static int mlx90614_read_raw(struct iio_dev *indio_dev,
                        *val2 = ret * MLX90614_CONST_EMISSIVITY_RESOLUTION;
                }
                return IIO_VAL_INT_PLUS_NANO;
+       case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR setting with
+                                                            FIR = 1024 */
+               mlx90614_power_get(data, false);
+               mutex_lock(&data->lock);
+               ret = i2c_smbus_read_word_data(data->client, MLX90614_CONFIG);
+               mutex_unlock(&data->lock);
+               mlx90614_power_put(data);
+
+               if (ret < 0)
+                       return ret;
+
+               *val = mlx90614_iir_values[ret & MLX90614_CONFIG_IIR_MASK] / 100;
+               *val2 = (mlx90614_iir_values[ret & MLX90614_CONFIG_IIR_MASK] % 100) *
+                       10000;
+               return IIO_VAL_INT_PLUS_MICRO;
        default:
                return -EINVAL;
        }
@@ -262,6 +330,18 @@ static int mlx90614_write_raw(struct iio_dev *indio_dev,
                mutex_unlock(&data->lock);
                mlx90614_power_put(data);
 
+               return ret;
+       case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY: /* IIR Filter setting */
+               if (val < 0 || val2 < 0)
+                       return -EINVAL;
+
+               mlx90614_power_get(data, false);
+               mutex_lock(&data->lock);
+               ret = mlx90614_iir_search(data->client,
+                                         val * 100 + val2 / 10000);
+               mutex_unlock(&data->lock);
+               mlx90614_power_put(data);
+
                return ret;
        default:
                return -EINVAL;
@@ -275,6 +355,8 @@ static int mlx90614_write_raw_get_fmt(struct iio_dev *indio_dev,
        switch (mask) {
        case IIO_CHAN_INFO_CALIBEMISSIVITY:
                return IIO_VAL_INT_PLUS_NANO;
+       case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+               return IIO_VAL_INT_PLUS_MICRO;
        default:
                return -EINVAL;
        }
@@ -294,7 +376,8 @@ static const struct iio_chan_spec mlx90614_channels[] = {
                .modified = 1,
                .channel2 = IIO_MOD_TEMP_OBJECT,
                .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-                   BIT(IIO_CHAN_INFO_CALIBEMISSIVITY),
+                   BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) |
+                       BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
                .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
                    BIT(IIO_CHAN_INFO_SCALE),
        },
@@ -305,7 +388,8 @@ static const struct iio_chan_spec mlx90614_channels[] = {
                .channel = 1,
                .channel2 = IIO_MOD_TEMP_OBJECT,
                .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
-                   BIT(IIO_CHAN_INFO_CALIBEMISSIVITY),
+                   BIT(IIO_CHAN_INFO_CALIBEMISSIVITY) |
+                       BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY),
                .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
                    BIT(IIO_CHAN_INFO_SCALE),
        },
@@ -315,6 +399,7 @@ static const struct iio_info mlx90614_info = {
        .read_raw = mlx90614_read_raw,
        .write_raw = mlx90614_write_raw,
        .write_raw_get_fmt = mlx90614_write_raw_get_fmt,
+       .attrs = &mlx90614_attr_group,
        .driver_module = THIS_MODULE,
 };
 
@@ -569,5 +654,6 @@ module_i2c_driver(mlx90614_driver);
 
 MODULE_AUTHOR("Peter Meerwald <pmeerw@pmeerw.net>");
 MODULE_AUTHOR("Vianney le Clément de Saint-Marcq <vianney.leclement@essensium.com>");
+MODULE_AUTHOR("Crt Mori <cmo@melexis.com>");
 MODULE_DESCRIPTION("Melexis MLX90614 contactless IR temperature sensor driver");
 MODULE_LICENSE("GPL");
diff --git a/drivers/iio/temperature/tsys01.c b/drivers/iio/temperature/tsys01.c
new file mode 100644 (file)
index 0000000..05c1206
--- /dev/null
@@ -0,0 +1,230 @@
+/*
+ * tsys01.c - Support for Measurement-Specialties tsys01 temperature sensor
+ *
+ * Copyright (c) 2015 Measurement-Specialties
+ *
+ * Licensed under the GPL-2.
+ *
+ * Datasheet:
+ *  http://www.meas-spec.com/downloads/TSYS01_Digital_Temperature_Sensor.pdf
+ */
+
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/device.h>
+#include <linux/mutex.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/stat.h>
+#include "../common/ms_sensors/ms_sensors_i2c.h"
+
+/* TSYS01 Commands */
+#define TSYS01_RESET                           0x1E
+#define TSYS01_CONVERSION_START                        0x48
+#define TSYS01_ADC_READ                                0x00
+#define TSYS01_PROM_READ                       0xA0
+
+#define TSYS01_PROM_WORDS_NB                   8
+
+struct tsys01_dev {
+       void *client;
+       struct mutex lock; /* lock during conversion */
+
+       int (*reset)(void *cli, u8 cmd, unsigned int delay);
+       int (*convert_and_read)(void *cli, u8 conv, u8 rd,
+                               unsigned int delay, u32 *adc);
+       int (*read_prom_word)(void *cli, int cmd, u16 *word);
+
+       u16 prom[TSYS01_PROM_WORDS_NB];
+};
+
+/* Multiplication coefficients for temperature computation */
+static const int coeff_mul[] = { -1500000, 1000000, -2000000,
+                                4000000, -2000000 };
+
+static int tsys01_read_temperature(struct iio_dev *indio_dev,
+                                  s32 *temperature)
+{
+       int ret, i;
+       u32 adc;
+       s64 temp = 0;
+       struct tsys01_dev *dev_data = iio_priv(indio_dev);
+
+       mutex_lock(&dev_data->lock);
+       ret = dev_data->convert_and_read(dev_data->client,
+                                        TSYS01_CONVERSION_START,
+                                        TSYS01_ADC_READ, 9000, &adc);
+       mutex_unlock(&dev_data->lock);
+       if (ret)
+               return ret;
+
+       adc >>= 8;
+
+       /* Temperature algorithm */
+       for (i = 4; i > 0; i--) {
+               temp += coeff_mul[i] *
+                       (s64)dev_data->prom[5 - i];
+               temp *= (s64)adc;
+               temp = div64_s64(temp, 100000);
+       }
+       temp *= 10;
+       temp += coeff_mul[0] * (s64)dev_data->prom[5];
+       temp = div64_s64(temp, 100000);
+
+       *temperature = temp;
+
+       return 0;
+}
+
+static int tsys01_read_raw(struct iio_dev *indio_dev,
+                          struct iio_chan_spec const *channel, int *val,
+                          int *val2, long mask)
+{
+       int ret;
+       s32 temperature;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_PROCESSED:
+               switch (channel->type) {
+               case IIO_TEMP:  /* in milli Â°C */
+                       ret = tsys01_read_temperature(indio_dev, &temperature);
+                       if (ret)
+                               return ret;
+                       *val = temperature;
+
+                       return IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+       default:
+               return -EINVAL;
+       }
+}
+
+static const struct iio_chan_spec tsys01_channels[] = {
+       {
+               .type = IIO_TEMP,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
+       }
+};
+
+static const struct iio_info tsys01_info = {
+       .read_raw = tsys01_read_raw,
+       .driver_module = THIS_MODULE,
+};
+
+static bool tsys01_crc_valid(u16 *n_prom)
+{
+       u8 cnt;
+       u8 sum = 0;
+
+       for (cnt = 0; cnt < TSYS01_PROM_WORDS_NB; cnt++)
+               sum += ((n_prom[0] >> 8) + (n_prom[0] & 0xFF));
+
+       return (sum == 0);
+}
+
+static int tsys01_read_prom(struct iio_dev *indio_dev)
+{
+       int i, ret;
+       struct tsys01_dev *dev_data = iio_priv(indio_dev);
+       char buf[7 * TSYS01_PROM_WORDS_NB + 1];
+       char *ptr = buf;
+
+       for (i = 0; i < TSYS01_PROM_WORDS_NB; i++) {
+               ret = dev_data->read_prom_word(dev_data->client,
+                                              TSYS01_PROM_READ + (i << 1),
+                                              &dev_data->prom[i]);
+               if (ret)
+                       return ret;
+
+               ret = sprintf(ptr, "0x%04x ", dev_data->prom[i]);
+               ptr += ret;
+       }
+
+       if (!tsys01_crc_valid(dev_data->prom)) {
+               dev_err(&indio_dev->dev, "prom crc check error\n");
+               return -ENODEV;
+       }
+       *ptr = 0;
+       dev_info(&indio_dev->dev, "PROM coefficients : %s\n", buf);
+
+       return 0;
+}
+
+static int tsys01_probe(struct iio_dev *indio_dev, struct device *dev)
+{
+       int ret;
+       struct tsys01_dev *dev_data = iio_priv(indio_dev);
+
+       mutex_init(&dev_data->lock);
+
+       indio_dev->info = &tsys01_info;
+       indio_dev->name = dev->driver->name;
+       indio_dev->dev.parent = dev;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->channels = tsys01_channels;
+       indio_dev->num_channels = ARRAY_SIZE(tsys01_channels);
+
+       ret = dev_data->reset(dev_data->client, TSYS01_RESET, 3000);
+       if (ret)
+               return ret;
+
+       ret = tsys01_read_prom(indio_dev);
+       if (ret)
+               return ret;
+
+       return devm_iio_device_register(dev, indio_dev);
+}
+
+static int tsys01_i2c_probe(struct i2c_client *client,
+                           const struct i2c_device_id *id)
+{
+       struct tsys01_dev *dev_data;
+       struct iio_dev *indio_dev;
+
+       if (!i2c_check_functionality(client->adapter,
+                                    I2C_FUNC_SMBUS_WORD_DATA |
+                                    I2C_FUNC_SMBUS_WRITE_BYTE |
+                                    I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
+               dev_err(&client->dev,
+                       "Adapter does not support some i2c transaction\n");
+               return -ENODEV;
+       }
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       dev_data = iio_priv(indio_dev);
+       dev_data->client = client;
+       dev_data->reset = ms_sensors_reset;
+       dev_data->read_prom_word = ms_sensors_read_prom_word;
+       dev_data->convert_and_read = ms_sensors_convert_and_read;
+
+       i2c_set_clientdata(client, indio_dev);
+
+       return tsys01_probe(indio_dev, &client->dev);
+}
+
+static const struct i2c_device_id tsys01_id[] = {
+       {"tsys01", 0},
+       {}
+};
+MODULE_DEVICE_TABLE(i2c, tsys01_id);
+
+static struct i2c_driver tsys01_driver = {
+       .probe = tsys01_i2c_probe,
+       .id_table = tsys01_id,
+       .driver = {
+                  .name = "tsys01",
+                  },
+};
+
+module_i2c_driver(tsys01_driver);
+
+MODULE_DESCRIPTION("Measurement-Specialties tsys01 temperature driver");
+MODULE_AUTHOR("William Markezana <william.markezana@meas-spec.com>");
+MODULE_AUTHOR("Ludovic Tancerel <ludovic.tancerel@maplehightech.com>");
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/temperature/tsys02d.c b/drivers/iio/temperature/tsys02d.c
new file mode 100644 (file)
index 0000000..4c1fbd5
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * tsys02d.c - Support for Measurement-Specialties tsys02d temperature sensor
+ *
+ * Copyright (c) 2015 Measurement-Specialties
+ *
+ * Licensed under the GPL-2.
+ *
+ * (7-bit I2C slave address 0x40)
+ *
+ * Datasheet:
+ *  http://www.meas-spec.com/downloads/Digital_Sensor_TSYS02D.pdf
+ */
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/stat.h>
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+
+#include "../common/ms_sensors/ms_sensors_i2c.h"
+
+#define TSYS02D_RESET                          0xFE
+
+static const int tsys02d_samp_freq[4] = { 20, 40, 70, 140 };
+/* String copy of the above const for readability purpose */
+static const char tsys02d_show_samp_freq[] = "20 40 70 140";
+
+static int tsys02d_read_raw(struct iio_dev *indio_dev,
+                           struct iio_chan_spec const *channel, int *val,
+                           int *val2, long mask)
+{
+       int ret;
+       s32 temperature;
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+
+       switch (mask) {
+       case IIO_CHAN_INFO_PROCESSED:
+               switch (channel->type) {
+               case IIO_TEMP:  /* in milli Â°C */
+                       ret = ms_sensors_ht_read_temperature(dev_data,
+                                                            &temperature);
+                       if (ret)
+                               return ret;
+                       *val = temperature;
+
+                       return IIO_VAL_INT;
+               default:
+                       return -EINVAL;
+               }
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               *val = tsys02d_samp_freq[dev_data->res_index];
+
+               return IIO_VAL_INT;
+       default:
+               return -EINVAL;
+       }
+}
+
+static int tsys02d_write_raw(struct iio_dev *indio_dev,
+                            struct iio_chan_spec const *chan,
+                            int val, int val2, long mask)
+{
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+       int i, ret;
+
+       switch (mask) {
+       case IIO_CHAN_INFO_SAMP_FREQ:
+               i = ARRAY_SIZE(tsys02d_samp_freq);
+               while (i-- > 0)
+                       if (val == tsys02d_samp_freq[i])
+                               break;
+               if (i < 0)
+                       return -EINVAL;
+               mutex_lock(&dev_data->lock);
+               dev_data->res_index = i;
+               ret = ms_sensors_write_resolution(dev_data, i);
+               mutex_unlock(&dev_data->lock);
+
+               return ret;
+       default:
+               return -EINVAL;
+       }
+}
+
+static const struct iio_chan_spec tsys02d_channels[] = {
+       {
+               .type = IIO_TEMP,
+               .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_PROCESSED),
+               .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+       }
+};
+
+static ssize_t tsys02_read_battery_low(struct device *dev,
+                                      struct device_attribute *attr,
+                                      char *buf)
+{
+       struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+       struct ms_ht_dev *dev_data = iio_priv(indio_dev);
+
+       return ms_sensors_show_battery_low(dev_data, buf);
+}
+
+static IIO_CONST_ATTR_SAMP_FREQ_AVAIL(tsys02d_show_samp_freq);
+static IIO_DEVICE_ATTR(battery_low, S_IRUGO,
+                      tsys02_read_battery_low, NULL, 0);
+
+static struct attribute *tsys02d_attributes[] = {
+       &iio_const_attr_sampling_frequency_available.dev_attr.attr,
+       &iio_dev_attr_battery_low.dev_attr.attr,
+       NULL,
+};
+
+static const struct attribute_group tsys02d_attribute_group = {
+       .attrs = tsys02d_attributes,
+};
+
+static const struct iio_info tsys02d_info = {
+       .read_raw = tsys02d_read_raw,
+       .write_raw = tsys02d_write_raw,
+       .attrs = &tsys02d_attribute_group,
+       .driver_module = THIS_MODULE,
+};
+
+static int tsys02d_probe(struct i2c_client *client,
+                        const struct i2c_device_id *id)
+{
+       struct ms_ht_dev *dev_data;
+       struct iio_dev *indio_dev;
+       int ret;
+       u64 serial_number;
+
+       if (!i2c_check_functionality(client->adapter,
+                                    I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
+                                    I2C_FUNC_SMBUS_WRITE_BYTE |
+                                    I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
+               dev_err(&client->dev,
+                       "Adapter does not support some i2c transaction\n");
+               return -ENODEV;
+       }
+
+       indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*dev_data));
+       if (!indio_dev)
+               return -ENOMEM;
+
+       dev_data = iio_priv(indio_dev);
+       dev_data->client = client;
+       dev_data->res_index = 0;
+       mutex_init(&dev_data->lock);
+
+       indio_dev->info = &tsys02d_info;
+       indio_dev->name = id->name;
+       indio_dev->dev.parent = &client->dev;
+       indio_dev->modes = INDIO_DIRECT_MODE;
+       indio_dev->channels = tsys02d_channels;
+       indio_dev->num_channels = ARRAY_SIZE(tsys02d_channels);
+
+       i2c_set_clientdata(client, indio_dev);
+
+       ret = ms_sensors_reset(client, TSYS02D_RESET, 15000);
+       if (ret)
+               return ret;
+
+       ret = ms_sensors_read_serial(client, &serial_number);
+       if (ret)
+               return ret;
+       dev_info(&client->dev, "Serial number : %llx", serial_number);
+
+       return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id tsys02d_id[] = {
+       {"tsys02d", 0},
+       {}
+};
+
+static struct i2c_driver tsys02d_driver = {
+       .probe = tsys02d_probe,
+       .id_table = tsys02d_id,
+       .driver = {
+                  .name = "tsys02d",
+                  },
+};
+
+module_i2c_driver(tsys02d_driver);
+
+MODULE_DESCRIPTION("Measurement-Specialties tsys02d temperature driver");
+MODULE_AUTHOR("William Markezana <william.markezana@meas-spec.com>");
+MODULE_AUTHOR("Ludovic Tancerel <ludovic.tancerel@maplehightech.com>");
+MODULE_LICENSE("GPL v2");
index 39d950584c9ffe585bfe40e20ee94a806c8d5be8..5d3b86a3385704d798ec207b381091f60c2fd759 100644 (file)
@@ -62,8 +62,6 @@ source "drivers/staging/xgifb/Kconfig"
 
 source "drivers/staging/emxx_udc/Kconfig"
 
-source "drivers/staging/ft1000/Kconfig"
-
 source "drivers/staging/speakup/Kconfig"
 
 source "drivers/staging/ste_rmi4/Kconfig"
index e4f33d91872b54920879bb5d3d586dfeb743665e..30918edef5e3c21baf700b14e1aba74dacc5ca1a 100644 (file)
@@ -25,7 +25,6 @@ obj-$(CONFIG_IIO)             += iio/
 obj-$(CONFIG_FB_SM750)         += sm750fb/
 obj-$(CONFIG_FB_XGI)           += xgifb/
 obj-$(CONFIG_USB_EMXX)         += emxx_udc/
-obj-$(CONFIG_FT1000)           += ft1000/
 obj-$(CONFIG_SPEAKUP)          += speakup/
 obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4)   += ste_rmi4/
 obj-$(CONFIG_MFD_NVEC)         += nvec/
index 68307121c9c18830ed88477ad152e5188cec0537..42b15126aa06bc0828405b0b6fe65b733f7eb871 100644 (file)
@@ -54,7 +54,7 @@ config SW_SYNC
        depends on SYNC
        ---help---
          A sync object driver that uses a 32bit counter to coordinate
-         syncrhronization.  Useful when there is no hardware primitive backing
+         synchronization.  Useful when there is no hardware primitive backing
          the synchronization.
 
 config SW_SYNC_USER
index 60200a3da82103c1501673e2c3b51ebe2fb283d0..3f2a3d611e4bea033b7943085f4fef747112be89 100644 (file)
@@ -18,7 +18,8 @@
 
 #define pr_fmt(fmt) "ashmem: " fmt
 
-#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/export.h>
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/falloc.h>
@@ -43,7 +44,7 @@
  * @unpinned_list:     The list of all ashmem areas
  * @file:              The shmem-based backing file
  * @size:              The size of the mapping, in bytes
- * @prot_masks:                The allowed protection bits, as vm_flags
+ * @prot_mask:         The allowed protection bits, as vm_flags
  *
  * The lifecycle of this structure is from our parent file's open() until
  * its release(). It is also protected by 'ashmem_mutex'
@@ -82,14 +83,14 @@ struct ashmem_range {
 /* LRU list of unpinned pages, protected by ashmem_mutex */
 static LIST_HEAD(ashmem_lru_list);
 
-/**
+/*
  * long lru_count - The count of pages on our LRU list.
  *
  * This is protected by ashmem_mutex.
  */
 static unsigned long lru_count;
 
-/**
+/*
  * ashmem_mutex - protects the list of and each individual ashmem_area
  *
  * Lock Ordering: ashmex_mutex -> i_mutex -> i_alloc_sem
@@ -311,10 +312,9 @@ static ssize_t ashmem_read(struct file *file, char __user *buf,
         * ashmem_release is called.
         */
        ret = __vfs_read(asma->file, buf, len, pos);
-       if (ret >= 0) {
+       if (ret >= 0)
                /** Update backing file pos, since f_ops->read() doesn't */
                asma->file->f_pos = *pos;
-       }
        return ret;
 
 out_unlock:
@@ -618,7 +618,8 @@ static int ashmem_pin(struct ashmem_area *asma, size_t pgstart, size_t pgend)
 
                        /* Case #3: We overlap from the rear, so adjust it */
                        if (range->pgend <= pgend) {
-                               range_shrink(range, range->pgstart, pgstart-1);
+                               range_shrink(range, range->pgstart,
+                                            pgstart - 1);
                                continue;
                        }
 
@@ -715,7 +716,7 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
        if (unlikely((pin.offset | pin.len) & ~PAGE_MASK))
                return -EINVAL;
 
-       if (unlikely(((__u32) -1) - pin.offset < pin.len))
+       if (unlikely(((__u32)-1) - pin.offset < pin.len))
                return -EINVAL;
 
        if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len))
@@ -759,7 +760,7 @@ static long ashmem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                ret = -EINVAL;
                if (!asma->file) {
                        ret = 0;
-                       asma->size = (size_t) arg;
+                       asma->size = (size_t)arg;
                }
                break;
        case ASHMEM_GET_SIZE:
@@ -833,16 +834,16 @@ static int __init ashmem_init(void)
        int ret;
 
        ashmem_area_cachep = kmem_cache_create("ashmem_area_cache",
-                                         sizeof(struct ashmem_area),
-                                         0, 0, NULL);
+                                              sizeof(struct ashmem_area),
+                                              0, 0, NULL);
        if (unlikely(!ashmem_area_cachep)) {
                pr_err("failed to create slab cache\n");
                return -ENOMEM;
        }
 
        ashmem_range_cachep = kmem_cache_create("ashmem_range_cache",
-                                         sizeof(struct ashmem_range),
-                                         0, 0, NULL);
+                                               sizeof(struct ashmem_range),
+                                               0, 0, NULL);
        if (unlikely(!ashmem_range_cachep)) {
                pr_err("failed to create slab cache\n");
                return -ENOMEM;
@@ -860,19 +861,4 @@ static int __init ashmem_init(void)
 
        return 0;
 }
-
-static void __exit ashmem_exit(void)
-{
-       unregister_shrinker(&ashmem_shrinker);
-
-       misc_deregister(&ashmem_misc);
-       kmem_cache_destroy(ashmem_range_cachep);
-       kmem_cache_destroy(ashmem_area_cachep);
-
-       pr_info("unloaded\n");
-}
-
-module_init(ashmem_init);
-module_exit(ashmem_exit);
-
-MODULE_LICENSE("GPL");
+device_initcall(ashmem_init);
index c2ad5893dfdadcdaf255f06b73b727465fc3620d..9da8f917670b53f042bb983cb0c9a01a109402ea 100644 (file)
@@ -1,5 +1,4 @@
 /*
-
  * drivers/staging/android/ion/compat_ion.h
  *
  * Copyright (C) 2013 Google, Inc.
index 6e8d8392ca386e8ddd76e705ac8364a2555c178f..e237e9f3312d6b99e5d2eac4a07f534ce03690c2 100644 (file)
@@ -1,5 +1,5 @@
 /*
-
+ *
  * drivers/staging/android/ion/ion.c
  *
  * Copyright (C) 2011 Google, Inc.
@@ -213,10 +213,10 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
                        "heap->ops->map_dma should return ERR_PTR on error"))
                table = ERR_PTR(-EINVAL);
        if (IS_ERR(table)) {
-               heap->ops->free(buffer);
-               kfree(buffer);
-               return ERR_CAST(table);
+               ret = -EINVAL;
+               goto err1;
        }
+
        buffer->sg_table = table;
        if (ion_buffer_fault_user_mappings(buffer)) {
                int num_pages = PAGE_ALIGN(buffer->size) / PAGE_SIZE;
@@ -226,7 +226,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
                buffer->pages = vmalloc(sizeof(struct page *) * num_pages);
                if (!buffer->pages) {
                        ret = -ENOMEM;
-                       goto err1;
+                       goto err;
                }
 
                for_each_sg(table->sgl, sg, table->nents, i) {
@@ -235,23 +235,22 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
                        for (j = 0; j < sg->length / PAGE_SIZE; j++)
                                buffer->pages[k++] = page++;
                }
-
-               if (ret)
-                       goto err;
        }
 
        buffer->dev = dev;
        buffer->size = len;
        INIT_LIST_HEAD(&buffer->vmas);
        mutex_init(&buffer->lock);
-       /* this will set up dma addresses for the sglist -- it is not
-          technically correct as per the dma api -- a specific
-          device isn't really taking ownership here.  However, in practice on
-          our systems the only dma_address space is physical addresses.
-          Additionally, we can't afford the overhead of invalidating every
-          allocation via dma_map_sg. The implicit contract here is that
-          memory coming from the heaps is ready for dma, ie if it has a
-          cached mapping that mapping has been invalidated */
+       /*
+        * this will set up dma addresses for the sglist -- it is not
+        * technically correct as per the dma api -- a specific
+        * device isn't really taking ownership here.  However, in practice on
+        * our systems the only dma_address space is physical addresses.
+        * Additionally, we can't afford the overhead of invalidating every
+        * allocation via dma_map_sg. The implicit contract here is that
+        * memory coming from the heaps is ready for dma, ie if it has a
+        * cached mapping that mapping has been invalidated
+        */
        for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i)
                sg_dma_address(sg) = sg_phys(sg);
        mutex_lock(&dev->buffer_lock);
@@ -261,9 +260,8 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
 
 err:
        heap->ops->unmap_dma(heap, buffer);
-       heap->ops->free(buffer);
 err1:
-       vfree(buffer->pages);
+       heap->ops->free(buffer);
 err2:
        kfree(buffer);
        return ERR_PTR(ret);
@@ -753,8 +751,10 @@ struct ion_client *ion_client_create(struct ion_device *dev,
        get_task_struct(current->group_leader);
        task_lock(current->group_leader);
        pid = task_pid_nr(current->group_leader);
-       /* don't bother to store task struct for kernel threads,
-          they can't be killed anyway */
+       /*
+        * don't bother to store task struct for kernel threads,
+        * they can't be killed anyway
+        */
        if (current->group_leader->flags & PF_KTHREAD) {
                put_task_struct(current->group_leader);
                task = NULL;
@@ -1521,8 +1521,10 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
 
        heap->dev = dev;
        down_write(&dev->lock);
-       /* use negative heap->id to reverse the priority -- when traversing
-          the list later attempt higher id numbers first */
+       /*
+        * use negative heap->id to reverse the priority -- when traversing
+        * the list later attempt higher id numbers first
+        */
        plist_node_init(&heap->node, -heap->id);
        plist_add(&heap->node, &dev->heaps);
        debug_file = debugfs_create_file(heap->name, 0664,
@@ -1555,6 +1557,7 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap)
 
        up_write(&dev->lock);
 }
+EXPORT_SYMBOL(ion_device_add_heap);
 
 struct ion_device *ion_device_create(long (*custom_ioctl)
                                     (struct ion_client *client,
@@ -1604,6 +1607,7 @@ debugfs_done:
        idev->clients = RB_ROOT;
        return idev;
 }
+EXPORT_SYMBOL(ion_device_create);
 
 void ion_device_destroy(struct ion_device *dev)
 {
@@ -1612,6 +1616,7 @@ void ion_device_destroy(struct ion_device *dev)
        /* XXX need to free the heaps and clients ? */
        kfree(dev);
 }
+EXPORT_SYMBOL(ion_device_destroy);
 
 void __init ion_reserve(struct ion_platform_data *data)
 {
index 443db8459a9e738884af8f2f73675508a043869f..b860c5f579f57b6067ca987a9dfa94590bc7d1c1 100644 (file)
@@ -28,10 +28,12 @@ struct ion_mapper;
 struct ion_client;
 struct ion_buffer;
 
-/* This should be removed some day when phys_addr_t's are fully
-   plumbed in the kernel, and all instances of ion_phys_addr_t should
-   be converted to phys_addr_t.  For the time being many kernel interfaces
-   do not accept phys_addr_t's that would have to */
+/*
+ * This should be removed some day when phys_addr_t's are fully
+ * plumbed in the kernel, and all instances of ion_phys_addr_t should
+ * be converted to phys_addr_t.  For the time being many kernel interfaces
+ * do not accept phys_addr_t's that would have to
+ */
 #define ion_phys_addr_t unsigned long
 
 /**
index 0b2448c32495094739283edc4bae031f999bdb8e..a3446da4fdc2a6b70a8fb95a8686895156c781c4 100644 (file)
@@ -180,8 +180,10 @@ struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data)
                return ERR_PTR(-ENOMEM);
 
        cma_heap->heap.ops = &ion_cma_ops;
-       /* get device from private heaps data, later it will be
-        * used to make the link with reserved CMA memory */
+       /*
+        * get device from private heaps data, later it will be
+        * used to make the link with reserved CMA memory
+        */
        cma_heap->dev = data->priv;
        cma_heap->heap.type = ION_HEAP_TYPE_DMA;
        return &cma_heap->heap;
index fd13d05b538a665344893a750c673d52a608d0c4..ca15a87f6fd3d7bd0bee4ca7a77ea488bb8656c8 100644 (file)
@@ -56,7 +56,7 @@ void *ion_heap_map_kernel(struct ion_heap *heap,
        vaddr = vmap(pages, npages, VM_MAP, pgprot);
        vfree(pages);
 
-       if (vaddr == NULL)
+       if (!vaddr)
                return ERR_PTR(-ENOMEM);
 
        return vaddr;
@@ -352,6 +352,7 @@ struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data)
        heap->id = heap_data->id;
        return heap;
 }
+EXPORT_SYMBOL(ion_heap_create);
 
 void ion_heap_destroy(struct ion_heap *heap)
 {
@@ -379,3 +380,4 @@ void ion_heap_destroy(struct ion_heap *heap)
                       heap->type);
        }
 }
+EXPORT_SYMBOL(ion_heap_destroy);
index 19ad3aba499ae579889892e6c6168833f4c0851f..fd7e23e0c06e9bcc47659e4d692819d6b61fe1a5 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/err.h>
 #include <linux/fs.h>
 #include <linux/list.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/swap.h>
 #include "ion_priv.h"
@@ -174,10 +174,4 @@ static int __init ion_page_pool_init(void)
 {
        return 0;
 }
-
-static void __exit ion_page_pool_exit(void)
-{
-}
-
-module_init(ion_page_pool_init);
-module_exit(ion_page_pool_exit);
+device_initcall(ion_page_pool_init);
index 52f1cd1a67ed7ce9243538ad9de6c781d8fca7d1..0239883bffb72a82c0ffb05bc9aaaf0ee52f32aa 100644 (file)
@@ -346,7 +346,8 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr,
  * to keep a pool of pre allocated memory to use from your heap.  Keeping
  * a pool of memory that is ready for dma, ie any cached mapping have been
  * invalidated from the cache, provides a significant performance benefit on
- * many systems */
+ * many systems
+ */
 
 /**
  * struct ion_page_pool - pagepool struct
index 7a7a9a047230889a8d0883e68364609968c875a0..ada724aab3d586ebb81193909a2518a1e68872fb 100644 (file)
@@ -185,8 +185,11 @@ static void ion_system_heap_free(struct ion_buffer *buffer)
        struct scatterlist *sg;
        int i;
 
-       /* uncached pages come from the page pools, zero them before returning
-          for security purposes (other allocations are zerod at alloc time */
+       /*
+        *  uncached pages come from the page pools, zero them before returning
+        *  for security purposes (other allocations are zerod at
+        *  alloc time
+        */
        if (!cached && !(buffer->private_flags & ION_PRIV_FLAG_SHRINKER_FREE))
                ion_heap_buffer_zero(buffer);
 
index 11cd003fb08f08e946cc283006a795a16c14628c..808f1f53f11adc3a623721e6e2173e15a6c3bb61 100644 (file)
@@ -1 +1 @@
-obj-y += tegra_ion.o
+obj-$(CONFIG_ION_TEGRA) += tegra_ion.o
index 872bd603fd0d8b8ae207be9e2d67e71c5b5e04ed..e679d8432810bf8bad5cdb83ab8cb9abe59df503 100644 (file)
@@ -32,7 +32,8 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/moduleparam.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/oom.h>
@@ -157,26 +158,22 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
        }
        if (selected) {
                task_lock(selected);
-               if (!selected->mm) {
-                       /* Already exited, cannot do mark_tsk_oom_victim() */
-                       task_unlock(selected);
-                       goto out;
-               }
+               send_sig(SIGKILL, selected, 0);
                /*
                 * FIXME: lowmemorykiller shouldn't abuse global OOM killer
                 * infrastructure. There is no real reason why the selected
                 * task should have access to the memory reserves.
                 */
-               mark_oom_victim(selected);
+               if (selected->mm)
+                       mark_oom_victim(selected);
                task_unlock(selected);
                lowmem_print(1, "send sigkill to %d (%s), adj %hd, size %d\n",
                             selected->pid, selected->comm,
                             selected_oom_score_adj, selected_tasksize);
                lowmem_deathpending_timeout = jiffies + HZ;
-               send_sig(SIGKILL, selected, 0);
                rem += selected_tasksize;
        }
-out:
+
        lowmem_print(4, "lowmem_scan %lu, %x, return %lu\n",
                     sc->nr_to_scan, sc->gfp_mask, rem);
        rcu_read_unlock();
@@ -194,12 +191,12 @@ static int __init lowmem_init(void)
        register_shrinker(&lowmem_shrinker);
        return 0;
 }
+device_initcall(lowmem_init);
 
-static void __exit lowmem_exit(void)
-{
-       unregister_shrinker(&lowmem_shrinker);
-}
-
+/*
+ * not really modular, but the easiest way to keep compat with existing
+ * bootargs behaviour is to continue using module_param here.
+ */
 module_param_named(cost, lowmem_shrinker.seeks, int, S_IRUGO | S_IWUSR);
 module_param_array_named(adj, lowmem_adj, short, &lowmem_adj_size,
                         S_IRUGO | S_IWUSR);
@@ -207,8 +204,3 @@ module_param_array_named(minfree, lowmem_minfree, uint, &lowmem_minfree_size,
                         S_IRUGO | S_IWUSR);
 module_param_named(debug_level, lowmem_debug_level, uint, S_IRUGO | S_IWUSR);
 
-module_init(lowmem_init);
-module_exit(lowmem_exit);
-
-MODULE_LICENSE("GPL");
-
index c90838d369534c864b641b87209fe421c604cbb6..c4ff1679ebbce2d3594c232e736a19c37a626ae1 100644 (file)
  */
 
 #include <linux/kernel.h>
+#include <linux/init.h>
 #include <linux/export.h>
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/miscdevice.h>
-#include <linux/module.h>
 #include <linux/syscalls.h>
 #include <linux/uaccess.h>
 
@@ -145,7 +145,7 @@ static int sw_sync_open(struct inode *inode, struct file *file)
        get_task_comm(task_comm, current);
 
        obj = sw_sync_timeline_create(task_comm);
-       if (obj == NULL)
+       if (!obj)
                return -ENOMEM;
 
        file->private_data = obj;
@@ -179,14 +179,14 @@ static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj,
        }
 
        pt = sw_sync_pt_create(obj, data.value);
-       if (pt == NULL) {
+       if (!pt) {
                err = -ENOMEM;
                goto err;
        }
 
        data.name[sizeof(data.name) - 1] = '\0';
        fence = sync_fence_create(data.name, pt);
-       if (fence == NULL) {
+       if (!fence) {
                sync_pt_free(pt);
                err = -ENOMEM;
                goto err;
@@ -255,13 +255,6 @@ static int __init sw_sync_device_init(void)
 {
        return misc_register(&sw_sync_dev);
 }
-
-static void __exit sw_sync_device_remove(void)
-{
-       misc_deregister(&sw_sync_dev);
-}
-
-module_init(sw_sync_device_init);
-module_exit(sw_sync_device_remove);
+device_initcall(sw_sync_device_init);
 
 #endif /* CONFIG_SW_SYNC_USER */
index b41429f379fef46555fa4cf7426cbc5190b5f93a..aff9cdb007e5b71f35b9f2495571dcdb0c895acd 100644 (file)
@@ -16,7 +16,8 @@
 
 #define pr_fmt(fmt) "timed_output: " fmt
 
-#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/export.h>
 #include <linux/types.h>
 #include <linux/device.h>
 #include <linux/fs.h>
@@ -106,15 +107,4 @@ static int __init timed_output_init(void)
 {
        return create_timed_output_class();
 }
-
-static void __exit timed_output_exit(void)
-{
-       class_destroy(timed_output_class);
-}
-
-module_init(timed_output_init);
-module_exit(timed_output_exit);
-
-MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
-MODULE_DESCRIPTION("timed output class driver");
-MODULE_LICENSE("GPL");
+device_initcall(timed_output_init);
index 68a14b4e21cb3eb7653e0cb9ab15555d7cad73dd..0a8e40f92cd70097e0d9c9d96908b04f6c1e4b7a 100644 (file)
@@ -40,8 +40,10 @@ enum ion_heap_type {
        ION_HEAP_TYPE_CARVEOUT,
        ION_HEAP_TYPE_CHUNK,
        ION_HEAP_TYPE_DMA,
-       ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always
-                                are at the end of this enum */
+       ION_HEAP_TYPE_CUSTOM, /*
+                              * must be last so device specific heaps always
+                              * are at the end of this enum
+                              */
        ION_NUM_HEAPS = 16,
 };
 
@@ -56,13 +58,18 @@ enum ion_heap_type {
  * allocation flags - the lower 16 bits are used by core ion, the upper 16
  * bits are reserved for use by the heaps themselves.
  */
-#define ION_FLAG_CACHED 1              /* mappings of this buffer should be
-                                          cached, ion will do cache
-                                          maintenance when the buffer is
-                                          mapped for dma */
-#define ION_FLAG_CACHED_NEEDS_SYNC 2   /* mappings of this buffer will created
-                                          at mmap time, if this is set
-                                          caches must be managed manually */
+#define ION_FLAG_CACHED 1              /*
+                                        * mappings of this buffer should be
+                                        * cached, ion will do cache
+                                        * maintenance when the buffer is
+                                        * mapped for dma
+                                       */
+#define ION_FLAG_CACHED_NEEDS_SYNC 2   /*
+                                        * mappings of this buffer will created
+                                        * at mmap time, if this is set
+                                        * caches must be managed
+                                        * manually
+                                        */
 
 /**
  * DOC: Ion Userspace API
index 3eb5eb8f069c236da870eb4b13a677eb560a1a1f..965afc79aadd8001a0c8afa4ae12c43f49bf9d86 100644 (file)
@@ -187,6 +187,9 @@ int __init board_staging_register_device(const struct board_staging_dev *dev)
        for (i = 0; i < dev->nclocks; i++)
                board_staging_register_clock(&dev->clocks[i]);
 
+       if (dev->domain)
+               board_staging_add_dev_domain(pdev, dev->domain);
+
        error = platform_device_register(pdev);
        if (error) {
                pr_err("Failed to register device %s (%d)\n", pdev->name,
@@ -194,9 +197,6 @@ int __init board_staging_register_device(const struct board_staging_dev *dev)
                return error;
        }
 
-       if (dev->domain)
-               board_staging_add_dev_domain(pdev, dev->domain);
-
        return error;
 }
 
index 57e71f9f14a2385bf8537b6d94dce5de164d4f4a..ac0f01007abd83825b4405ea46ba010d3a1efa6e 100644 (file)
@@ -400,14 +400,6 @@ config COMEDI_DMM32AT
          To compile this driver as a module, choose M here: the module will be
          called dmm32at.
 
-config COMEDI_UNIOXX5
-       tristate "Fastwel UNIOxx-5 analog and digital io board support"
-       ---help---
-         Enable support for Fastwel UNIOxx-5 (analog and digital i/o) boards
-
-         To compile this driver as a module, choose M here: the module will be
-         called unioxx5.
-
 config COMEDI_FL512
        tristate "FL512 ISA card support"
        ---help---
@@ -418,6 +410,7 @@ config COMEDI_FL512
 
 config COMEDI_AIO_AIO12_8
        tristate "I/O Products PC/104 AIO12-8 Analog I/O Board support"
+       select COMEDI_8254
        select COMEDI_8255
        ---help---
          Enable support for I/O Products PC/104 AIO12-8 Analog I/O Board
@@ -1072,6 +1065,7 @@ config COMEDI_NI_PCIMIO
 
 config COMEDI_RTD520
        tristate "Real Time Devices PCI4520/DM7520 support"
+       select COMEDI_8254
        ---help---
          Enable support for Real Time Devices PCI4520/DM7520
 
index 19e7b229d15e538954549f52796dd932dfea64dc..90c28016c6c13a51b16a2d9a889a8b4e6563209e 100644 (file)
@@ -245,7 +245,7 @@ void comedi_buf_reset(struct comedi_subdevice *s)
        async->events = 0;
 }
 
-static unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s)
+static unsigned int comedi_buf_write_n_unalloc(struct comedi_subdevice *s)
 {
        struct comedi_async *async = s->async;
        unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
@@ -253,15 +253,33 @@ static unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s)
        return free_end - async->buf_write_alloc_count;
 }
 
-/* allocates chunk for the writer from free buffer space */
+unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s)
+{
+       struct comedi_async *async = s->async;
+       unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
+
+       return free_end - async->buf_write_count;
+}
+
+/**
+ * comedi_buf_write_alloc() - Reserve buffer space for writing
+ * @s: COMEDI subdevice.
+ * @nbytes: Maximum space to reserve in bytes.
+ *
+ * Reserve up to @nbytes bytes of space to be written in the COMEDI acquisition
+ * data buffer associated with the subdevice.  The amount reserved is limited
+ * by the space available.
+ *
+ * Return: The amount of space reserved in bytes.
+ */
 unsigned int comedi_buf_write_alloc(struct comedi_subdevice *s,
                                    unsigned int nbytes)
 {
        struct comedi_async *async = s->async;
-       unsigned int available = comedi_buf_write_n_available(s);
+       unsigned int unalloc = comedi_buf_write_n_unalloc(s);
 
-       if (nbytes > available)
-               nbytes = available;
+       if (nbytes > unalloc)
+               nbytes = unalloc;
 
        async->buf_write_alloc_count += nbytes;
 
@@ -329,7 +347,21 @@ unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s)
        return async->buf_write_alloc_count - async->buf_write_count;
 }
 
-/* transfers a chunk from writer to filled buffer space */
+/**
+ * comedi_buf_write_free() - Free buffer space after it is written
+ * @s: COMEDI subdevice.
+ * @nbytes: Maximum space to free in bytes.
+ *
+ * Free up to @nbytes bytes of space previously reserved for writing in the
+ * COMEDI acquisition data buffer associated with the subdevice.  The amount of
+ * space freed is limited to the amount that was reserved.  The freed space is
+ * assumed to have been filled with sample data by the writer.
+ *
+ * If the samples in the freed space need to be "munged", do so here.  The
+ * freed space becomes available for allocation by the reader.
+ *
+ * Return: The amount of space freed in bytes.
+ */
 unsigned int comedi_buf_write_free(struct comedi_subdevice *s,
                                   unsigned int nbytes)
 {
@@ -349,6 +381,17 @@ unsigned int comedi_buf_write_free(struct comedi_subdevice *s,
 }
 EXPORT_SYMBOL_GPL(comedi_buf_write_free);
 
+/**
+ * comedi_buf_read_n_available() - Determine amount of readable buffer space
+ * @s: COMEDI subdevice.
+ *
+ * Determine the amount of readable buffer space in the COMEDI acquisition data
+ * buffer associated with the subdevice.  The readable buffer space is that
+ * which has been freed by the writer and "munged" to the sample data format
+ * expected by COMEDI if necessary.
+ *
+ * Return: The amount of readable buffer space.
+ */
 unsigned int comedi_buf_read_n_available(struct comedi_subdevice *s)
 {
        struct comedi_async *async = s->async;
@@ -369,7 +412,21 @@ unsigned int comedi_buf_read_n_available(struct comedi_subdevice *s)
 }
 EXPORT_SYMBOL_GPL(comedi_buf_read_n_available);
 
-/* allocates a chunk for the reader from filled (and munged) buffer space */
+/**
+ * comedi_buf_read_alloc() - Reserve buffer space for reading
+ * @s: COMEDI subdevice.
+ * @nbytes: Maximum space to reserve in bytes.
+ *
+ * Reserve up to @nbytes bytes of previously written and "munged" buffer space
+ * for reading in the COMEDI acquisition data buffer associated with the
+ * subdevice.  The amount reserved is limited to the space available.  The
+ * reader can read from the reserved space and then free it.  A reader is also
+ * allowed to read from the space before reserving it as long as it determines
+ * the amount of readable data available, but the space needs to be marked as
+ * reserved before it can be freed.
+ *
+ * Return: The amount of space reserved in bytes.
+ */
 unsigned int comedi_buf_read_alloc(struct comedi_subdevice *s,
                                   unsigned int nbytes)
 {
@@ -397,7 +454,19 @@ static unsigned int comedi_buf_read_n_allocated(struct comedi_async *async)
        return async->buf_read_alloc_count - async->buf_read_count;
 }
 
-/* transfers control of a chunk from reader to free buffer space */
+/**
+ * comedi_buf_read_free() - Free buffer space after it has been read
+ * @s: COMEDI subdevice.
+ * @nbytes: Maximum space to free in bytes.
+ *
+ * Free up to @nbytes bytes of buffer space previously reserved for reading in
+ * the COMEDI acquisition data buffer associated with the subdevice.  The
+ * amount of space freed is limited to the amount that was reserved.
+ *
+ * The freed space becomes available for allocation by the writer.
+ *
+ * Return: The amount of space freed in bytes.
+ */
 unsigned int comedi_buf_read_free(struct comedi_subdevice *s,
                                  unsigned int nbytes)
 {
@@ -469,15 +538,21 @@ static void comedi_buf_memcpy_from(struct comedi_subdevice *s,
 }
 
 /**
- * comedi_buf_write_samples - write sample data to comedi buffer
- * @s: comedi_subdevice struct
- * @data: samples
- * @nsamples: number of samples
+ * comedi_buf_write_samples() - Write sample data to COMEDI buffer
+ * @s: COMEDI subdevice.
+ * @data: Pointer to source samples.
+ * @nsamples: Number of samples to write.
  *
- * Writes nsamples to the comedi buffer associated with the subdevice, marks
- * it as written and updates the acquisition scan progress.
+ * Write up to @nsamples samples to the COMEDI acquisition data buffer
+ * associated with the subdevice, mark it as written and update the
+ * acquisition scan progress.  If there is not enough room for the specified
+ * number of samples, the number of samples written is limited to the number
+ * that will fit and the %COMEDI_CB_OVERFLOW event flag is set to cause the
+ * acquisition to terminate with an overrun error.  Set the %COMEDI_CB_BLOCK
+ * event flag if any samples are written to cause waiting tasks to be woken
+ * when the event flags are processed.
  *
- * Returns the amount of data written in bytes.
+ * Return: The amount of data written in bytes.
  */
 unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
                                      const void *data, unsigned int nsamples)
@@ -490,8 +565,7 @@ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
         * If not, clamp the nsamples to the number that will fit, flag the
         * buffer overrun and add the samples that fit.
         */
-       max_samples = comedi_bytes_to_samples(s,
-                                             comedi_buf_write_n_available(s));
+       max_samples = comedi_bytes_to_samples(s, comedi_buf_write_n_unalloc(s));
        if (nsamples > max_samples) {
                dev_warn(s->device->class_dev, "buffer overrun\n");
                s->async->events |= COMEDI_CB_OVERFLOW;
@@ -513,15 +587,18 @@ unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
 EXPORT_SYMBOL_GPL(comedi_buf_write_samples);
 
 /**
- * comedi_buf_read_samples - read sample data from comedi buffer
- * @s: comedi_subdevice struct
- * @data: destination
- * @nsamples: maximum number of samples to read
+ * comedi_buf_read_samples() - Read sample data from COMEDI buffer
+ * @s: COMEDI subdevice.
+ * @data: Pointer to destination.
+ * @nsamples: Maximum number of samples to read.
  *
- * Reads up to nsamples from the comedi buffer associated with the subdevice,
- * marks it as read and updates the acquisition scan progress.
+ * Read up to @nsamples samples from the COMEDI acquisition data buffer
+ * associated with the subdevice, mark it as read and update the acquisition
+ * scan progress.  Limit the number of samples read to the number available.
+ * Set the %COMEDI_CB_BLOCK event flag if any samples are read to cause waiting
+ * tasks to be woken when the event flags are processed.
  *
- * Returns the amount of data read in bytes.
+ * Return: The amount of data read in bytes.
  */
 unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
                                     void *data, unsigned int nsamples)
index 0e8a45102933ea0c0a103581959ad54c01918abc..7b4af519e17e1a92e9b6d594ea95fad753af5a36 100644 (file)
 
 #include "comedi_internal.h"
 
-/**
+/*
  * comedi_subdevice "runflags"
- * @COMEDI_SRF_RT:             DEPRECATED: command is running real-time
- * @COMEDI_SRF_ERROR:          indicates an COMEDI_CB_ERROR event has occurred
+ * COMEDI_SRF_RT:              DEPRECATED: command is running real-time
+ * COMEDI_SRF_ERROR:           indicates an COMEDI_CB_ERROR event has occurred
  *                             since the last command was started
- * @COMEDI_SRF_RUNNING:                command is running
- * @COMEDI_SRF_FREE_SPRIV:     free s->private on detach
+ * COMEDI_SRF_RUNNING:         command is running
+ * COMEDI_SRF_FREE_SPRIV:      free s->private on detach
  *
- * @COMEDI_SRF_BUSY_MASK:      runflags that indicate the subdevice is "busy"
+ * COMEDI_SRF_BUSY_MASK:       runflags that indicate the subdevice is "busy"
  */
 #define COMEDI_SRF_RT          BIT(1)
 #define COMEDI_SRF_ERROR       BIT(2)
 #define COMEDI_SRF_BUSY_MASK   (COMEDI_SRF_ERROR | COMEDI_SRF_RUNNING)
 
 /**
- * struct comedi_file - per-file private data for comedi device
- * @dev: comedi_device struct
- * @read_subdev: current "read" subdevice
- * @write_subdev: current "write" subdevice
- * @last_detach_count: last known detach count
- * @last_attached: last known attached/detached state
+ * struct comedi_file - Per-file private data for COMEDI device
+ * @dev: COMEDI device.
+ * @read_subdev: Current "read" subdevice.
+ * @write_subdev: Current "write" subdevice.
+ * @last_detach_count: Last known detach count.
+ * @last_attached: Last known attached/detached state.
  */
 struct comedi_file {
        struct comedi_device *dev;
@@ -131,15 +131,15 @@ static void comedi_dev_kref_release(struct kref *kref)
 }
 
 /**
- * comedi_dev_put - release a use of a comedi device structure
- * @dev: comedi_device struct
+ * comedi_dev_put() - Release a use of a COMEDI device
+ * @dev: COMEDI device.
  *
- * Must be called when a user of a comedi device is finished with it.
- * When the last user of the comedi device calls this function, the
- * comedi device is destroyed.
+ * Must be called when a user of a COMEDI device is finished with it.
+ * When the last user of the COMEDI device calls this function, the
+ * COMEDI device is destroyed.
  *
- * Return 1 if the comedi device is destroyed by this call or dev is
- * NULL, otherwise return 0.  Callers must not assume the comedi
+ * Return: 1 if the COMEDI device is destroyed by this call or @dev is
+ * NULL, otherwise return 0.  Callers must not assume the COMEDI
  * device is still valid if this function returns 0.
  */
 int comedi_dev_put(struct comedi_device *dev)
@@ -247,15 +247,15 @@ static struct comedi_device *comedi_dev_get_from_subdevice_minor(unsigned minor)
 }
 
 /**
- * comedi_dev_get_from_minor - get comedi device by minor device number
- * @minor: minor device number
+ * comedi_dev_get_from_minor() - Get COMEDI device by minor device number
+ * @minor: Minor device number.
  *
- * Finds the comedi device associated by the minor device number, if any,
- * and increments its reference count.  The comedi device is prevented from
+ * Finds the COMEDI device associated with the minor device number, if any,
+ * and increments its reference count.  The COMEDI device is prevented from
  * being freed until a matching call is made to comedi_dev_put().
  *
- * Return a pointer to the comedi device if it exists, with its usage
- * reference incremented.  Return NULL if no comedi device exists with the
+ * Return: A pointer to the COMEDI device if it exists, with its usage
+ * reference incremented.  Return NULL if no COMEDI device exists with the
  * specified minor device number.
  */
 struct comedi_device *comedi_dev_get_from_minor(unsigned minor)
@@ -665,11 +665,11 @@ static bool comedi_is_runflags_in_error(unsigned runflags)
 }
 
 /**
- * comedi_is_subdevice_running - check if async command running on subdevice
- * @s: comedi_subdevice struct
+ * comedi_is_subdevice_running() - Check if async command running on subdevice
+ * @s: COMEDI subdevice.
  *
- * Return true if an asynchronous comedi command is active on the comedi
- * subdevice, else return false.
+ * Return: %true if an asynchronous COMEDI command is active on the
+ * subdevice, else %false.
  */
 bool comedi_is_subdevice_running(struct comedi_subdevice *s)
 {
@@ -701,11 +701,12 @@ bool comedi_can_auto_free_spriv(struct comedi_subdevice *s)
 }
 
 /**
- * comedi_set_spriv_auto_free - mark subdevice private data as freeable
- * @s: comedi_subdevice struct
+ * comedi_set_spriv_auto_free() - Mark subdevice private data as freeable
+ * @s: COMEDI subdevice.
  *
  * Mark the subdevice as having a pointer to private data that can be
- * automatically freed by the comedi core during the detach.
+ * automatically freed when the COMEDI device is detached from the low-level
+ * driver.
  */
 void comedi_set_spriv_auto_free(struct comedi_subdevice *s)
 {
@@ -714,12 +715,16 @@ void comedi_set_spriv_auto_free(struct comedi_subdevice *s)
 EXPORT_SYMBOL_GPL(comedi_set_spriv_auto_free);
 
 /**
- * comedi_alloc_spriv - Allocate memory for the subdevice private data.
- * @s: comedi_subdevice struct
- * @size: size of the memory to allocate
+ * comedi_alloc_spriv - Allocate memory for the subdevice private data
+ * @s: COMEDI subdevice.
+ * @size: Size of the memory to allocate.
+ *
+ * Allocate memory for the subdevice private data and point @s->private
+ * to it.  The memory will be freed automatically when the COMEDI device
+ * is detached from the low-level driver.
  *
- * This also sets the subdevice runflags to allow the core to automatically
- * free the private data during the detach.
+ * Return: A pointer to the allocated memory @s->private on success.
+ * Return NULL on failure.
  */
 void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size)
 {
@@ -1141,7 +1146,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
                comedi_buf_read_free(s, bi.bytes_read);
 
                if (comedi_is_subdevice_idle(s) &&
-                   comedi_buf_n_bytes_ready(s) == 0) {
+                   comedi_buf_read_n_available(s) == 0) {
                        do_become_nonbusy(dev, s);
                }
        }
@@ -1336,7 +1341,7 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
                        goto out;
                }
                /* This looks arbitrary.  It is. */
-               s->busy = &parse_insn;
+               s->busy = parse_insn;
                switch (insn->insn) {
                case INSN_READ:
                        ret = s->insn_read(dev, s, insn, data);
@@ -2257,9 +2262,9 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
        unsigned int mask = 0;
        struct comedi_file *cfp = file->private_data;
        struct comedi_device *dev = cfp->dev;
-       struct comedi_subdevice *s;
+       struct comedi_subdevice *s, *s_read;
 
-       mutex_lock(&dev->mutex);
+       down_read(&dev->attach_lock);
 
        if (!dev->attached) {
                dev_dbg(dev->class_dev, "no driver attached\n");
@@ -2267,9 +2272,10 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
        }
 
        s = comedi_file_read_subdevice(file);
+       s_read = s;
        if (s && s->async) {
                poll_wait(file, &s->async->wait_head, wait);
-               if (!s->busy || !comedi_is_subdevice_running(s) ||
+               if (s->busy != file || !comedi_is_subdevice_running(s) ||
                    (s->async->cmd.flags & CMDF_WRITE) ||
                    comedi_buf_read_n_available(s) > 0)
                        mask |= POLLIN | POLLRDNORM;
@@ -2279,16 +2285,16 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
        if (s && s->async) {
                unsigned int bps = comedi_bytes_per_sample(s);
 
-               poll_wait(file, &s->async->wait_head, wait);
-               comedi_buf_write_alloc(s, s->async->prealloc_bufsz);
-               if (!s->busy || !comedi_is_subdevice_running(s) ||
+               if (s != s_read)
+                       poll_wait(file, &s->async->wait_head, wait);
+               if (s->busy != file || !comedi_is_subdevice_running(s) ||
                    !(s->async->cmd.flags & CMDF_WRITE) ||
-                   comedi_buf_write_n_allocated(s) >= bps)
+                   comedi_buf_write_n_available(s) >= bps)
                        mask |= POLLOUT | POLLWRNORM;
        }
 
 done:
-       mutex_unlock(&dev->mutex);
+       up_read(&dev->attach_lock);
        return mask;
 }
 
@@ -2444,7 +2450,9 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
 {
        struct comedi_subdevice *s;
        struct comedi_async *async;
-       int n, m, count = 0, retval = 0;
+       unsigned int n, m;
+       ssize_t count = 0;
+       int retval = 0;
        DECLARE_WAITQUEUE(wait, current);
        struct comedi_file *cfp = file->private_data;
        struct comedi_device *dev = cfp->dev;
@@ -2470,28 +2478,19 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
        }
 
        async = s->async;
-       if (!s->busy || !nbytes)
-               goto out;
-       if (s->busy != file) {
-               retval = -EACCES;
-               goto out;
-       }
-       if (async->cmd.flags & CMDF_WRITE) {
+       if (s->busy != file || (async->cmd.flags & CMDF_WRITE)) {
                retval = -EINVAL;
                goto out;
        }
 
        add_wait_queue(&async->wait_head, &wait);
-       while (nbytes > 0 && !retval) {
-               set_current_state(TASK_INTERRUPTIBLE);
+       while (count == 0 && !retval) {
+               unsigned int rp, n1, n2;
 
-               n = nbytes;
+               set_current_state(TASK_INTERRUPTIBLE);
 
                m = comedi_buf_read_n_available(s);
-               if (async->buf_read_ptr + m > async->prealloc_bufsz)
-                       m = async->prealloc_bufsz - async->buf_read_ptr;
-               if (m < n)
-                       n = m;
+               n = min_t(size_t, m, nbytes);
 
                if (n == 0) {
                        unsigned runflags = comedi_get_subdevice_runflags(s);
@@ -2499,11 +2498,12 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
                        if (!comedi_is_runflags_running(runflags)) {
                                if (comedi_is_runflags_in_error(runflags))
                                        retval = -EPIPE;
-                               else
-                                       retval = 0;
-                               become_nonbusy = true;
+                               if (retval || nbytes)
+                                       become_nonbusy = true;
                                break;
                        }
+                       if (nbytes == 0)
+                               break;
                        if (file->f_flags & O_NONBLOCK) {
                                retval = -EAGAIN;
                                break;
@@ -2513,22 +2513,21 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
                                retval = -ERESTARTSYS;
                                break;
                        }
-                       if (!s->busy) {
-                               retval = 0;
-                               break;
-                       }
-                       if (s->busy != file) {
-                               retval = -EACCES;
-                               break;
-                       }
-                       if (async->cmd.flags & CMDF_WRITE) {
+                       if (s->busy != file ||
+                           (async->cmd.flags & CMDF_WRITE)) {
                                retval = -EINVAL;
                                break;
                        }
                        continue;
                }
-               m = copy_to_user(buf, async->prealloc_buf +
-                                async->buf_read_ptr, n);
+               rp = async->buf_read_ptr;
+               n1 = min(n, async->prealloc_bufsz - rp);
+               n2 = n - n1;
+               m = copy_to_user(buf, async->prealloc_buf + rp, n1);
+               if (m)
+                       m += n2;
+               else if (n2)
+                       m = copy_to_user(buf + n1, async->prealloc_buf, n2);
                if (m) {
                        n -= m;
                        retval = -EFAULT;
@@ -2541,11 +2540,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
                nbytes -= n;
 
                buf += n;
-               break;          /* makes device work like a pipe */
        }
        remove_wait_queue(&async->wait_head, &wait);
        set_current_state(TASK_RUNNING);
-       if (become_nonbusy || comedi_is_subdevice_idle(s)) {
+       if (become_nonbusy && count == 0) {
                struct comedi_subdevice *new_s;
 
                /*
@@ -2561,13 +2559,17 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
                 * sufficient (unless there have been 2**32 detaches in the
                 * meantime!), but check the subdevice pointer as well just in
                 * case.
+                *
+                * Also check the subdevice is still in a suitable state to
+                * become non-busy in case it changed behind our back.
                 */
                new_s = comedi_file_read_subdevice(file);
                if (dev->attached && old_detach_count == dev->detach_count &&
-                   s == new_s && new_s->async == async) {
-                       if (become_nonbusy || comedi_buf_n_bytes_ready(s) == 0)
-                               do_become_nonbusy(dev, s);
-               }
+                   s == new_s && new_s->async == async && s->busy == file &&
+                   !(async->cmd.flags & CMDF_WRITE) &&
+                   !comedi_is_subdevice_running(s) &&
+                   comedi_buf_read_n_available(s) == 0)
+                       do_become_nonbusy(dev, s);
                mutex_unlock(&dev->mutex);
        }
 out:
@@ -2686,15 +2688,15 @@ static const struct file_operations comedi_fops = {
 };
 
 /**
- * comedi_event - handle events for asynchronous comedi command
- * @dev: comedi_device struct
- * @s: comedi_subdevice struct associated with dev
- * Context: interrupt (usually), s->spin_lock spin-lock not held
+ * comedi_event() - Handle events for asynchronous COMEDI command
+ * @dev: COMEDI device.
+ * @s: COMEDI subdevice.
+ * Context: in_interrupt() (usually), @s->spin_lock spin-lock not held.
  *
- * If an asynchronous comedi command is active on the subdevice, process
- * any COMEDI_CB_... event flags that have been set, usually by an
+ * If an asynchronous COMEDI command is active on the subdevice, process
+ * any %COMEDI_CB_... event flags that have been set, usually by an
  * interrupt handler.  These may change the run state of the asynchronous
- * command, wake a task, and/or send a SIGIO signal.
+ * command, wake a task, and/or send a %SIGIO signal.
  */
 void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s)
 {
index cd9437f72c3535aafcef28417c74e155e6fac2bf..3f2c88ae6470d0a5151f92c799cd4186cb02ed72 100644 (file)
@@ -31,6 +31,7 @@ void comedi_buf_map_get(struct comedi_buf_map *bm);
 int comedi_buf_map_put(struct comedi_buf_map *bm);
 struct comedi_buf_map *comedi_buf_map_from_subdev_get(
                struct comedi_subdevice *s);
+unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s);
 unsigned int comedi_buf_write_n_allocated(struct comedi_subdevice *s);
 void comedi_device_cancel_all(struct comedi_device *dev);
 bool comedi_can_auto_free_spriv(struct comedi_subdevice *s);
index 027f0f4e59c15a35d3190df836b01969666739d1..51e023a1c0eecf16bb7da1c235a2a2119157b57b 100644 (file)
 #include "comedi_pci.h"
 
 /**
- * comedi_to_pci_dev() - comedi_device pointer to pci_dev pointer.
- * @dev: comedi_device struct
+ * comedi_to_pci_dev() - Return PCI device attached to COMEDI device
+ * @dev: COMEDI device.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
+ * a &struct device embedded in a &struct pci_dev.
+ *
+ * Return: Attached PCI device if @dev->hw_dev is non-%NULL.
+ * Return %NULL if @dev->hw_dev is %NULL.
  */
 struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
 {
@@ -32,8 +38,22 @@ struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
 EXPORT_SYMBOL_GPL(comedi_to_pci_dev);
 
 /**
- * comedi_pci_enable() - Enable the PCI device and request the regions.
- * @dev: comedi_device struct
+ * comedi_pci_enable() - Enable the PCI device and request the regions
+ * @dev: COMEDI device.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
+ * a &struct device embedded in a &struct pci_dev.  Enable the PCI device
+ * and request its regions.  Set @dev->ioenabled to %true if successful,
+ * otherwise undo what was done.
+ *
+ * Calls to comedi_pci_enable() and comedi_pci_disable() cannot be nested.
+ *
+ * Return:
+ *     0 on success,
+ *     -%ENODEV if @dev->hw_dev is %NULL,
+ *     -%EBUSY if regions busy,
+ *     or some negative error number if failed to enable PCI device.
+ *
  */
 int comedi_pci_enable(struct comedi_device *dev)
 {
@@ -58,8 +78,13 @@ int comedi_pci_enable(struct comedi_device *dev)
 EXPORT_SYMBOL_GPL(comedi_pci_enable);
 
 /**
- * comedi_pci_disable() - Release the regions and disable the PCI device.
- * @dev: comedi_device struct
+ * comedi_pci_disable() - Release the regions and disable the PCI device
+ * @dev: COMEDI device.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
+ * a &struct device embedded in a &struct pci_dev.  If the earlier call
+ * to comedi_pci_enable() was successful, release the PCI device's regions
+ * and disable it.  Reset @dev->ioenabled back to %false.
  */
 void comedi_pci_disable(struct comedi_device *dev)
 {
@@ -74,8 +99,18 @@ void comedi_pci_disable(struct comedi_device *dev)
 EXPORT_SYMBOL_GPL(comedi_pci_disable);
 
 /**
- * comedi_pci_detach() - A generic (*detach) function for PCI drivers.
- * @dev: comedi_device struct
+ * comedi_pci_detach() - A generic "detach" handler for PCI COMEDI drivers
+ * @dev: COMEDI device.
+ *
+ * COMEDI drivers for PCI devices that need no special clean-up of private data
+ * and have no ioremapped regions other than that pointed to by @dev->mmio may
+ * use this function as its "detach" handler called by the COMEDI core when a
+ * COMEDI device is being detached from the low-level driver.  It may be also
+ * called from a more specific "detach" handler that does additional clean-up.
+ *
+ * Free the IRQ if @dev->irq is non-zero, iounmap @dev->mmio if it is
+ * non-%NULL, and call comedi_pci_disable() to release the PCI device's regions
+ * and disable it.
  */
 void comedi_pci_detach(struct comedi_device *dev)
 {
@@ -97,12 +132,19 @@ void comedi_pci_detach(struct comedi_device *dev)
 EXPORT_SYMBOL_GPL(comedi_pci_detach);
 
 /**
- * comedi_pci_auto_config() - Configure/probe a comedi PCI driver.
- * @pcidev: pci_dev struct
- * @driver: comedi_driver struct
- * @context: driver specific data, passed to comedi_auto_config()
+ * comedi_pci_auto_config() - Configure/probe a PCI COMEDI device
+ * @pcidev: PCI device.
+ * @driver: Registered COMEDI driver.
+ * @context: Driver specific data, passed to comedi_auto_config().
  *
- * Typically called from the pci_driver (*probe) function.
+ * Typically called from the pci_driver (*probe) function.  Auto-configure
+ * a COMEDI device, using the &struct device embedded in *@pcidev as the
+ * hardware device.  The @context value gets passed through to @driver's
+ * "auto_attach" handler.  The "auto_attach" handler may call
+ * comedi_to_pci_dev() on the passed in COMEDI device to recover @pcidev.
+ *
+ * Return: The result of calling comedi_auto_config() (0 on success, or
+ * a negative error number on failure).
  */
 int comedi_pci_auto_config(struct pci_dev *pcidev,
                           struct comedi_driver *driver,
@@ -113,10 +155,18 @@ int comedi_pci_auto_config(struct pci_dev *pcidev,
 EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
 
 /**
- * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver.
- * @pcidev: pci_dev struct
+ * comedi_pci_auto_unconfig() - Unconfigure/remove a PCI COMEDI device
+ * @pcidev: PCI device.
+ *
+ * Typically called from the pci_driver (*remove) function.  Auto-unconfigure
+ * a COMEDI device attached to this PCI device, using a pointer to the
+ * &struct device embedded in *@pcidev as the hardware device.  The COMEDI
+ * driver's "detach" handler will be called during unconfiguration of the
+ * COMEDI device.
  *
- * Typically called from the pci_driver (*remove) function.
+ * Note that the COMEDI device may have already been unconfigured using the
+ * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it
+ * again should be ignored.
  */
 void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
 {
@@ -125,13 +175,15 @@ void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
 EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig);
 
 /**
- * comedi_pci_driver_register() - Register a comedi PCI driver.
- * @comedi_driver: comedi_driver struct
- * @pci_driver: pci_driver struct
+ * comedi_pci_driver_register() - Register a PCI COMEDI driver
+ * @comedi_driver: COMEDI driver to be registered.
+ * @pci_driver: PCI driver to be registered.
+ *
+ * This function is called from the module_init() of PCI COMEDI driver modules
+ * to register the COMEDI driver and the PCI driver.  Do not call it directly,
+ * use the module_comedi_pci_driver() helper macro instead.
  *
- * This function is used for the module_init() of comedi PCI drivers.
- * Do not call it directly, use the module_comedi_pci_driver() helper
- * macro instead.
+ * Return: 0 on success, or a negative error number on failure.
  */
 int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
                               struct pci_driver *pci_driver)
@@ -153,13 +205,13 @@ int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
 EXPORT_SYMBOL_GPL(comedi_pci_driver_register);
 
 /**
- * comedi_pci_driver_unregister() - Unregister a comedi PCI driver.
- * @comedi_driver: comedi_driver struct
- * @pci_driver: pci_driver struct
+ * comedi_pci_driver_unregister() - Unregister a PCI COMEDI driver
+ * @comedi_driver: COMEDI driver to be unregistered.
+ * @pci_driver: PCI driver to be unregistered.
  *
- * This function is used for the module_exit() of comedi PCI drivers.
- * Do not call it directly, use the module_comedi_pci_driver() helper
- * macro instead.
+ * This function is called from the module_exit() of PCI COMEDI driver modules
+ * to unregister the PCI driver and the COMEDI driver.  Do not call it
+ * directly, use the module_comedi_pci_driver() helper macro instead.
  */
 void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver,
                                  struct pci_driver *pci_driver)
index 7e784399a16febcfdacef3abe2c4132d78f0992b..d7072a5c164785a5f621babdd4b451cffe10bdc1 100644 (file)
 #include "comedi_pcmcia.h"
 
 /**
- * comedi_to_pcmcia_dev() - comedi_device pointer to pcmcia_device pointer.
- * @dev: comedi_device struct
+ * comedi_to_pcmcia_dev() - Return PCMCIA device attached to COMEDI device
+ * @dev: COMEDI device.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
+ * a &struct device embedded in a &struct pcmcia_device.
+ *
+ * Return: Attached PCMCIA device if @dev->hw_dev is non-%NULL.
+ * Return %NULL if @dev->hw_dev is %NULL.
  */
 struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev)
 {
@@ -41,13 +47,35 @@ static int comedi_pcmcia_conf_check(struct pcmcia_device *link,
 }
 
 /**
- * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device.
- * @dev: comedi_device struct
- * @conf_check: optional callback to check the pcmcia_device configuration
+ * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device
+ * @dev: COMEDI device.
+ * @conf_check: Optional callback to check each configuration option of the
+ *     PCMCIA device and request I/O regions.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a a
+ * &struct device embedded in a &struct pcmcia_device.  The comedi PCMCIA
+ * driver needs to set the 'config_flags' member in the &struct pcmcia_device,
+ * as appropriate for that driver, before calling this function in order to
+ * allow pcmcia_loop_config() to do its internal autoconfiguration.
+ *
+ * If @conf_check is %NULL it is set to a default function.  If is
+ * passed to pcmcia_loop_config() and should return %0 if the configuration
+ * is valid and I/O regions requested successfully, otherwise it should return
+ * a negative error value.  The default function returns -%EINVAL if the
+ * 'config_index' member is %0, otherwise it calls pcmcia_request_io() and
+ * returns the result.
+ *
+ * If the above configuration check passes, pcmcia_enable_device() is called
+ * to set up and activate the PCMCIA device.
  *
- * The comedi PCMCIA driver needs to set the link->config_flags, as
- * appropriate for that driver, before calling this function in order
- * to allow pcmcia_loop_config() to do its internal autoconfiguration.
+ * If this function returns an error, comedi_pcmcia_disable() should be called
+ * to release requested resources.
+ *
+ * Return:
+ *     0 on success,
+ *     -%ENODEV id @dev->hw_dev is %NULL,
+ *     a negative error number from pcmcia_loop_config() if it fails,
+ *     or a negative error number from pcmcia_enable_device() if it fails.
  */
 int comedi_pcmcia_enable(struct comedi_device *dev,
                         int (*conf_check)(struct pcmcia_device *, void *))
@@ -70,8 +98,12 @@ int comedi_pcmcia_enable(struct comedi_device *dev,
 EXPORT_SYMBOL_GPL(comedi_pcmcia_enable);
 
 /**
- * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions.
- * @dev: comedi_device struct
+ * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions
+ * @dev: COMEDI device.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
+ * a &struct device embedded in a &struct pcmcia_device.  Call
+ * pcmcia_disable_device() to disable and clean up the PCMCIA device.
  */
 void comedi_pcmcia_disable(struct comedi_device *dev)
 {
@@ -83,11 +115,17 @@ void comedi_pcmcia_disable(struct comedi_device *dev)
 EXPORT_SYMBOL_GPL(comedi_pcmcia_disable);
 
 /**
- * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver.
- * @link: pcmcia_device struct
- * @driver: comedi_driver struct
+ * comedi_pcmcia_auto_config() - Configure/probe a PCMCIA COMEDI device
+ * @link: PCMCIA device.
+ * @driver: Registered COMEDI driver.
+ *
+ * Typically called from the pcmcia_driver (*probe) function.  Auto-configure
+ * a COMEDI device, using a pointer to the &struct device embedded in *@link
+ * as the hardware device.  The @driver's "auto_attach" handler may call
+ * comedi_to_pcmcia_dev() on the passed in COMEDI device to recover @link.
  *
- * Typically called from the pcmcia_driver (*probe) function.
+ * Return: The result of calling comedi_auto_config() (0 on success, or a
+ * negative error number on failure).
  */
 int comedi_pcmcia_auto_config(struct pcmcia_device *link,
                              struct comedi_driver *driver)
@@ -97,10 +135,18 @@ int comedi_pcmcia_auto_config(struct pcmcia_device *link,
 EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config);
 
 /**
- * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a comedi PCMCIA driver.
- * @link: pcmcia_device struct
+ * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a PCMCIA COMEDI device
+ * @link: PCMCIA device.
  *
  * Typically called from the pcmcia_driver (*remove) function.
+ * Auto-unconfigure a COMEDI device attached to this PCMCIA device, using a
+ * pointer to the &struct device embedded in *@link as the hardware device.
+ * The COMEDI driver's "detach" handler will be called during unconfiguration
+ * of the COMEDI device.
+ *
+ * Note that the COMEDI device may have already been unconfigured using the
+ * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it
+ * again should be ignored.
  */
 void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link)
 {
@@ -109,13 +155,15 @@ void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link)
 EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig);
 
 /**
- * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver.
- * @comedi_driver: comedi_driver struct
- * @pcmcia_driver: pcmcia_driver struct
+ * comedi_pcmcia_driver_register() - Register a PCMCIA COMEDI driver
+ * @comedi_driver: COMEDI driver to be registered.
+ * @pcmcia_driver: PCMCIA driver to be registered.
+ *
+ * This function is used for the module_init() of PCMCIA COMEDI driver modules
+ * to register the COMEDI driver and the PCMCIA driver.  Do not call it
+ * directly, use the module_comedi_pcmcia_driver() helper macro instead.
  *
- * This function is used for the module_init() of comedi USB drivers.
- * Do not call it directly, use the module_comedi_pcmcia_driver() helper
- * macro instead.
+ * Return: 0 on success, or a negative error number on failure.
  */
 int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver,
                                  struct pcmcia_driver *pcmcia_driver)
@@ -137,13 +185,13 @@ int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver,
 EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register);
 
 /**
- * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver.
- * @comedi_driver: comedi_driver struct
- * @pcmcia_driver: pcmcia_driver struct
+ * comedi_pcmcia_driver_unregister() - Unregister a PCMCIA COMEDI driver
+ * @comedi_driver: COMEDI driver to be registered.
+ * @pcmcia_driver: PCMCIA driver to be registered.
  *
- * This function is used for the module_exit() of comedi PCMCIA drivers.
- * Do not call it directly, use the module_comedi_pcmcia_driver() helper
- * macro instead.
+ * This function is called from the module_exit() of PCMCIA COMEDI driver
+ * modules to unregister the PCMCIA driver and the COMEDI driver.  Do not call
+ * it directly, use the module_comedi_pcmcia_driver() helper macro instead.
  */
 void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
                                     struct pcmcia_driver *pcmcia_driver)
index 68b75e8feec0d7ba2ae6cb25dbfbf426218a7297..9c946d40b8944b56ae3ba7d99e16492623934ee0 100644 (file)
 #include "comedi_usb.h"
 
 /**
- * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer.
- * @dev: comedi_device struct
+ * comedi_to_usb_interface() - Return USB interface attached to COMEDI device
+ * @dev: COMEDI device.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
+ * a &struct device embedded in a &struct usb_interface.
+ *
+ * Return: Attached USB interface if @dev->hw_dev is non-%NULL.
+ * Return %NULL if @dev->hw_dev is %NULL.
  */
 struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
 {
@@ -31,8 +37,14 @@ struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
 EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
 
 /**
- * comedi_to_usb_dev() - comedi_device pointer to usb_device pointer.
- * @dev: comedi_device struct
+ * comedi_to_usb_dev() - Return USB device attached to COMEDI device
+ * @dev: COMEDI device.
+ *
+ * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
+ * a &struct device embedded in a &struct usb_interface.
+ *
+ * Return: USB device to which the USB interface belongs if @dev->hw_dev is
+ * non-%NULL.  Return %NULL if @dev->hw_dev is %NULL.
  */
 struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
 {
@@ -43,12 +55,19 @@ struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
 EXPORT_SYMBOL_GPL(comedi_to_usb_dev);
 
 /**
- * comedi_usb_auto_config() - Configure/probe a comedi USB driver.
- * @intf: usb_interface struct
- * @driver: comedi_driver struct
- * @context: driver specific data, passed to comedi_auto_config()
+ * comedi_usb_auto_config() - Configure/probe a USB COMEDI driver
+ * @intf: USB interface.
+ * @driver: Registered COMEDI driver.
+ * @context: Driver specific data, passed to comedi_auto_config().
  *
- * Typically called from the usb_driver (*probe) function.
+ * Typically called from the usb_driver (*probe) function.  Auto-configure a
+ * COMEDI device, using a pointer to the &struct device embedded in *@intf as
+ * the hardware device.  The @context value gets passed through to @driver's
+ * "auto_attach" handler.  The "auto_attach" handler may call
+ * comedi_to_usb_interface() on the passed in COMEDI device to recover @intf.
+ *
+ * Return: The result of calling comedi_auto_config() (%0 on success, or
+ * a negative error number on failure).
  */
 int comedi_usb_auto_config(struct usb_interface *intf,
                           struct comedi_driver *driver,
@@ -59,10 +78,18 @@ int comedi_usb_auto_config(struct usb_interface *intf,
 EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
 
 /**
- * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver.
- * @intf: usb_interface struct
+ * comedi_usb_auto_unconfig() - Unconfigure/disconnect a USB COMEDI device
+ * @intf: USB interface.
  *
  * Typically called from the usb_driver (*disconnect) function.
+ * Auto-unconfigure a COMEDI device attached to this USB interface, using a
+ * pointer to the &struct device embedded in *@intf as the hardware device.
+ * The COMEDI driver's "detach" handler will be called during unconfiguration
+ * of the COMEDI device.
+ *
+ * Note that the COMEDI device may have already been unconfigured using the
+ * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it
+ * again should be ignored.
  */
 void comedi_usb_auto_unconfig(struct usb_interface *intf)
 {
@@ -71,13 +98,15 @@ void comedi_usb_auto_unconfig(struct usb_interface *intf)
 EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
 
 /**
- * comedi_usb_driver_register() - Register a comedi USB driver.
- * @comedi_driver: comedi_driver struct
- * @usb_driver: usb_driver struct
+ * comedi_usb_driver_register() - Register a USB COMEDI driver
+ * @comedi_driver: COMEDI driver to be registered.
+ * @usb_driver: USB driver to be registered.
+ *
+ * This function is called from the module_init() of USB COMEDI driver modules
+ * to register the COMEDI driver and the USB driver.  Do not call it directly,
+ * use the module_comedi_usb_driver() helper macro instead.
  *
- * This function is used for the module_init() of comedi USB drivers.
- * Do not call it directly, use the module_comedi_usb_driver() helper
- * macro instead.
+ * Return: %0 on success, or a negative error number on failure.
  */
 int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
                               struct usb_driver *usb_driver)
@@ -99,13 +128,13 @@ int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
 EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
 
 /**
- * comedi_usb_driver_unregister() - Unregister a comedi USB driver.
- * @comedi_driver: comedi_driver struct
- * @usb_driver: usb_driver struct
+ * comedi_usb_driver_unregister() - Unregister a USB COMEDI driver
+ * @comedi_driver: COMEDI driver to be registered.
+ * @usb_driver: USB driver to be registered.
  *
- * This function is used for the module_exit() of comedi USB drivers.
- * Do not call it directly, use the module_comedi_usb_driver() helper
- * macro instead.
+ * This function is called from the module_exit() of USB COMEDI driver modules
+ * to unregister the USB driver and the COMEDI driver.  Do not call it
+ * directly, use the module_comedi_usb_driver() helper macro instead.
  */
 void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
                                  struct usb_driver *usb_driver)
index 28a5d3a037a107b03c37a67dbf030c0c91ba6851..115807215484747a9ee05785f89580316cadba29 100644 (file)
@@ -1,20 +1,20 @@
 /*
   include/linux/comedidev.h
   header file for kernel-only structures, variables, and constants
-
   COMEDI - Linux Control and Measurement Device Interface
   Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
-
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-*/
comedidev.h
* header file for kernel-only structures, variables, and constants
+ *
* COMEDI - Linux Control and Measurement Device Interface
* Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
+ */
 
 #ifndef _COMEDIDEV_H
 #define _COMEDIDEV_H
 
 #define COMEDI_NUM_BOARD_MINORS 0x30
 
+/**
+ * struct comedi_subdevice - Working data for a COMEDI subdevice
+ * @device: COMEDI device to which this subdevice belongs.  (Initialized by
+ *     comedi_alloc_subdevices().)
+ * @index: Index of this subdevice within device's array of subdevices.
+ *     (Initialized by comedi_alloc_subdevices().)
+ * @type: Type of subdevice from &enum comedi_subdevice_type.  (Initialized by
+ *     the low-level driver.)
+ * @n_chan: Number of channels the subdevice supports.  (Initialized by the
+ *     low-level driver.)
+ * @subdev_flags: Various "SDF" flags indicating aspects of the subdevice to
+ *     the COMEDI core and user application.  (Initialized by the low-level
+ *     driver.)
+ * @len_chanlist: Maximum length of a channel list if the subdevice supports
+ *     asynchronous acquisition commands.  (Optionally initialized by the
+ *     low-level driver, or changed from 0 to 1 during post-configuration.)
+ * @private: Private data pointer which is either set by the low-level driver
+ *     itself, or by a call to comedi_alloc_spriv() which allocates storage.
+ *     In the latter case, the storage is automatically freed after the
+ *     low-level driver's "detach" handler is called for the device.
+ *     (Initialized by the low-level driver.)
+ * @async: Pointer to &struct comedi_async id the subdevice supports
+ *     asynchronous acquisition commands.  (Allocated and initialized during
+ *     post-configuration if needed.)
+ * @lock: Pointer to a file object that performed a %COMEDI_LOCK ioctl on the
+ *     subdevice.  (Initially NULL.)
+ * @busy: Pointer to a file object that is performing an asynchronous
+ *     acquisition command on the subdevice.  (Initially NULL.)
+ * @runflags: Internal flags for use by COMEDI core, mostly indicating whether
+ *     an asynchronous acquisition command is running.
+ * @spin_lock: Generic spin-lock for use by the COMEDI core and the low-level
+ *     driver.  (Initialized by comedi_alloc_subdevices().)
+ * @io_bits: Bit-mask indicating the channel directions for a DIO subdevice
+ *     with no more than 32 channels.  A '1' at a bit position indicates the
+ *     corresponding channel is configured as an output.  (Initialized by the
+ *     low-level driver for a DIO subdevice.  Forced to all-outputs during
+ *     post-configuration for a digital output subdevice.)
+ * @maxdata: If non-zero, this is the maximum raw data value of each channel.
+ *     If zero, the maximum data value is channel-specific.  (Initialized by
+ *     the low-level driver.)
+ * @maxdata_list: If the maximum data value is channel-specific, this points
+ *     to an array of maximum data values indexed by channel index.
+ *     (Initialized by the low-level driver.)
+ * @range_table: If non-NULL, this points to a COMEDI range table for the
+ *     subdevice.  If NULL, the range table is channel-specific.  (Initialized
+ *     by the low-level driver, will be set to an "invalid" range table during
+ *     post-configuration if @range_table and @range_table_list are both
+ *     NULL.)
+ * @range_table_list: If the COMEDI range table is channel-specific, this
+ *     points to an array of pointers to COMEDI range tables indexed by
+ *     channel number.  (Initialized by the low-level driver.)
+ * @chanlist: Not used.
+ * @insn_read: Optional pointer to a handler for the %INSN_READ instruction.
+ *     (Initialized by the low-level driver, or set to a default handler
+ *     during post-configuration.)
+ * @insn_write: Optional pointer to a handler for the %INSN_WRITE instruction.
+ *     (Initialized by the low-level driver, or set to a default handler
+ *     during post-configuration.)
+ * @insn_bits: Optional pointer to a handler for the %INSN_BITS instruction
+ *     for a digital input, digital output or digital input/output subdevice.
+ *     (Initialized by the low-level driver, or set to a default handler
+ *     during post-configuration.)
+ * @insn_config: Optional pointer to a handler for the %INSN_CONFIG
+ *     instruction.  (Initialized by the low-level driver, or set to a default
+ *     handler during post-configuration.)
+ * @do_cmd: If the subdevice supports asynchronous acquisition commands, this
+ *     points to a handler to set it up in hardware.  (Initialized by the
+ *     low-level driver.)
+ * @do_cmdtest: If the subdevice supports asynchronous acquisition commands,
+ *     this points to a handler used to check and possibly tweak a prospective
+ *     acquisition command without setting it up in hardware.  (Initialized by
+ *     the low-level driver.)
+ * @poll: If the subdevice supports asynchronous acquisition commands, this
+ *     is an optional pointer to a handler for the %COMEDI_POLL ioctl which
+ *     instructs the low-level driver to synchronize buffers.  (Initialized by
+ *     the low-level driver if needed.)
+ * @cancel: If the subdevice supports asynchronous acquisition commands, this
+ *     points to a handler used to terminate a running command.  (Initialized
+ *     by the low-level driver.)
+ * @buf_change: If the subdevice supports asynchronous acquisition commands,
+ *     this is an optional pointer to a handler that is called when the data
+ *     buffer for handling asynchronous commands is allocated or reallocated.
+ *     (Initialized by the low-level driver if needed.)
+ * @munge: If the subdevice supports asynchronous acquisition commands and
+ *     uses DMA to transfer data from the hardware to the acquisition buffer,
+ *     this points to a function used to "munge" the data values from the
+ *     hardware into the format expected by COMEDI.  (Initialized by the
+ *     low-level driver if needed.)
+ * @async_dma_dir: If the subdevice supports asynchronous acquisition commands
+ *     and uses DMA to transfer data from the hardware to the acquisition
+ *     buffer, this sets the DMA direction for the buffer. (initialized to
+ *     %DMA_NONE by comedi_alloc_subdevices() and changed by the low-level
+ *     driver if necessary.)
+ * @state: Handy bit-mask indicating the output states for a DIO or digital
+ *     output subdevice with no more than 32 channels. (Initialized by the
+ *     low-level driver.)
+ * @class_dev: If the subdevice supports asynchronous acquisition commands,
+ *     this points to a sysfs comediX_subdY device where X is the minor device
+ *     number of the COMEDI device and Y is the subdevice number.  The minor
+ *     device number for the sysfs device is allocated dynamically in the
+ *     range 48 to 255.  This is used to allow the COMEDI device to be opened
+ *     with a different default read or write subdevice.  (Allocated during
+ *     post-configuration if needed.)
+ * @minor: If @class_dev is set, this is its dynamically allocated minor
+ *     device number.  (Set during post-configuration if necessary.)
+ * @readback: Optional pointer to memory allocated by
+ *     comedi_alloc_subdev_readback() used to hold the values written to
+ *     analog output channels so they can be read back.  The storage is
+ *     automatically freed after the low-level driver's "detach" handler is
+ *     called for the device.  (Initialized by the low-level driver.)
+ *
+ * This is the main control structure for a COMEDI subdevice.  If the subdevice
+ * supports asynchronous acquisition commands, additional information is stored
+ * in the &struct comedi_async pointed to by @async.
+ *
+ * Most of the subdevice is initialized by the low-level driver's "attach" or
+ * "auto_attach" handlers but parts of it are initialized by
+ * comedi_alloc_subdevices(), and other parts are initialized during
+ * post-configuration on return from that handler.
+ *
+ * A low-level driver that sets @insn_bits for a digital input, digital output,
+ * or DIO subdevice may leave @insn_read and @insn_write uninitialized, in
+ * which case they will be set to a default handler during post-configuration
+ * that uses @insn_bits to emulate the %INSN_READ and %INSN_WRITE instructions.
+ */
 struct comedi_subdevice {
        struct comedi_device *device;
        int index;
@@ -49,7 +174,7 @@ struct comedi_subdevice {
        void *lock;
        void *busy;
        unsigned runflags;
-       spinlock_t spin_lock;
+       spinlock_t spin_lock;   /* generic spin-lock for COMEDI and drivers */
 
        unsigned int io_bits;
 
@@ -92,11 +217,40 @@ struct comedi_subdevice {
        unsigned int *readback;
 };
 
+/**
+ * struct comedi_buf_page - Describe a page of a COMEDI buffer
+ * @virt_addr: Kernel address of page.
+ * @dma_addr: DMA address of page if in DMA coherent memory.
+ */
 struct comedi_buf_page {
        void *virt_addr;
        dma_addr_t dma_addr;
 };
 
+/**
+ * struct comedi_buf_map - Describe pages in a COMEDI buffer
+ * @dma_hw_dev: Low-level hardware &struct device pointer copied from the
+ *     COMEDI device's hw_dev member.
+ * @page_list: Pointer to array of &struct comedi_buf_page, one for each
+ *     page in the buffer.
+ * @n_pages: Number of pages in the buffer.
+ * @dma_dir: DMA direction used to allocate pages of DMA coherent memory,
+ *     or %DMA_NONE if pages allocated from regular memory.
+ * @refcount: &struct kref reference counter used to free the buffer.
+ *
+ * A COMEDI data buffer is allocated as individual pages, either in
+ * conventional memory or DMA coherent memory, depending on the attached,
+ * low-level hardware device.  (The buffer pages also get mapped into the
+ * kernel's contiguous virtual address space pointed to by the 'prealloc_buf'
+ * member of &struct comedi_async.)
+ *
+ * The buffer is normally freed when the COMEDI device is detached from the
+ * low-level driver (which may happen due to device removal), but if it happens
+ * to be mmapped at the time, the pages cannot be freed until the buffer has
+ * been munmapped.  That is what the reference counter is for.  (The virtual
+ * address space pointed by 'prealloc_buf' is freed when the COMEDI device is
+ * detached.)
+ */
 struct comedi_buf_map {
        struct device *dma_hw_dev;
        struct comedi_buf_page *page_list;
@@ -106,61 +260,66 @@ struct comedi_buf_map {
 };
 
 /**
- * struct comedi_async - control data for asynchronous comedi commands
- * @prealloc_buf:      preallocated buffer
- * @prealloc_bufsz:    buffer size (in bytes)
- * @buf_map:           map of buffer pages
- * @max_bufsize:       maximum buffer size (in bytes)
- * @buf_write_count:   "write completed" count (in bytes, modulo 2**32)
- * @buf_write_alloc_count: "allocated for writing" count (in bytes,
- *                     modulo 2**32)
- * @buf_read_count:    "read completed" count (in bytes, modulo 2**32)
- * @buf_read_alloc_count: "allocated for reading" count (in bytes,
- *                     modulo 2**32)
- * @buf_write_ptr:     buffer position for writer
- * @buf_read_ptr:      buffer position for reader
- * @cur_chan:          current position in chanlist for scan (for those
- *                     drivers that use it)
- * @scans_done:                the number of scans completed (COMEDI_CB_EOS)
- * @scan_progress:     amount received or sent for current scan (in bytes)
- * @munge_chan:                current position in chanlist for "munging"
- * @munge_count:       "munge" count (in bytes, modulo 2**32)
- * @munge_ptr:         buffer position for "munging"
- * @events:            bit-vector of events that have occurred
- * @cmd:               details of comedi command in progress
- * @wait_head:         task wait queue for file reader or writer
- * @cb_mask:           bit-vector of events that should wake waiting tasks
- * @inttrig:           software trigger function for command, or NULL
+ * struct comedi_async - Control data for asynchronous COMEDI commands
+ * @prealloc_buf: Kernel virtual address of allocated acquisition buffer.
+ * @prealloc_bufsz: Buffer size (in bytes).
+ * @buf_map: Map of buffer pages.
+ * @max_bufsize: Maximum allowed buffer size (in bytes).
+ * @buf_write_count: "Write completed" count (in bytes, modulo 2**32).
+ * @buf_write_alloc_count: "Allocated for writing" count (in bytes,
+ *     modulo 2**32).
+ * @buf_read_count: "Read completed" count (in bytes, modulo 2**32).
+ * @buf_read_alloc_count: "Allocated for reading" count (in bytes,
+ *     modulo 2**32).
+ * @buf_write_ptr: Buffer position for writer.
+ * @buf_read_ptr: Buffer position for reader.
+ * @cur_chan: Current position in chanlist for scan (for those drivers that
+ *     use it).
+ * @scans_done: The number of scans completed.
+ * @scan_progress: Amount received or sent for current scan (in bytes).
+ * @munge_chan: Current position in chanlist for "munging".
+ * @munge_count: "Munge" count (in bytes, modulo 2**32).
+ * @munge_ptr: Buffer position for "munging".
+ * @events: Bit-vector of events that have occurred.
+ * @cmd: Details of comedi command in progress.
+ * @wait_head: Task wait queue for file reader or writer.
+ * @cb_mask: Bit-vector of events that should wake waiting tasks.
+ * @inttrig: Software trigger function for command, or NULL.
  *
  * Note about the ..._count and ..._ptr members:
  *
  * Think of the _Count values being integers of unlimited size, indexing
  * into a buffer of infinite length (though only an advancing portion
- * of the buffer of fixed length prealloc_bufsz is accessible at any time).
- * Then:
+ * of the buffer of fixed length prealloc_bufsz is accessible at any
+ * time).  Then:
  *
  *   Buf_Read_Count <= Buf_Read_Alloc_Count <= Munge_Count <=
  *   Buf_Write_Count <= Buf_Write_Alloc_Count <=
  *   (Buf_Read_Count + prealloc_bufsz)
  *
- * (Those aren't the actual members, apart from prealloc_bufsz.) When
- * the buffer is reset, those _Count values start at 0 and only increase
- * in value, maintaining the above inequalities until the next time the
- * buffer is reset.  The buffer is divided into the following regions by
- * the inequalities:
+ * (Those aren't the actual members, apart from prealloc_bufsz.) When the
+ * buffer is reset, those _Count values start at 0 and only increase in value,
+ * maintaining the above inequalities until the next time the buffer is
+ * reset.  The buffer is divided into the following regions by the inequalities:
  *
  *   [0, Buf_Read_Count):
  *     old region no longer accessible
+ *
  *   [Buf_Read_Count, Buf_Read_Alloc_Count):
  *     filled and munged region allocated for reading but not yet read
+ *
  *   [Buf_Read_Alloc_Count, Munge_Count):
  *     filled and munged region not yet allocated for reading
+ *
  *   [Munge_Count, Buf_Write_Count):
  *     filled region not yet munged
+ *
  *   [Buf_Write_Count, Buf_Write_Alloc_Count):
  *     unfilled region allocated for writing but not yet written
+ *
  *   [Buf_Write_Alloc_Count, Buf_Read_Count + prealloc_bufsz):
  *     unfilled region not yet allocated for writing
+ *
  *   [Buf_Read_Count + prealloc_bufsz, infinity):
  *     unfilled region not yet accessible
  *
@@ -216,43 +375,153 @@ struct comedi_async {
 };
 
 /**
- * comedi_async callback "events"
+ * enum comedi_cb - &struct comedi_async callback "events"
  * @COMEDI_CB_EOS:             end-of-scan
  * @COMEDI_CB_EOA:             end-of-acquisition/output
  * @COMEDI_CB_BLOCK:           data has arrived, wakes up read() / write()
  * @COMEDI_CB_EOBUF:           DEPRECATED: end of buffer
  * @COMEDI_CB_ERROR:           card error during acquisition
  * @COMEDI_CB_OVERFLOW:                buffer overflow/underflow
- *
  * @COMEDI_CB_ERROR_MASK:      events that indicate an error has occurred
  * @COMEDI_CB_CANCEL_MASK:     events that will cancel an async command
  */
-#define COMEDI_CB_EOS          BIT(0)
-#define COMEDI_CB_EOA          BIT(1)
-#define COMEDI_CB_BLOCK                BIT(2)
-#define COMEDI_CB_EOBUF                BIT(3)
-#define COMEDI_CB_ERROR                BIT(4)
-#define COMEDI_CB_OVERFLOW     BIT(5)
-
-#define COMEDI_CB_ERROR_MASK   (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)
-#define COMEDI_CB_CANCEL_MASK  (COMEDI_CB_EOA | COMEDI_CB_ERROR_MASK)
+enum comedi_cb {
+       COMEDI_CB_EOS           = BIT(0),
+       COMEDI_CB_EOA           = BIT(1),
+       COMEDI_CB_BLOCK         = BIT(2),
+       COMEDI_CB_EOBUF         = BIT(3),
+       COMEDI_CB_ERROR         = BIT(4),
+       COMEDI_CB_OVERFLOW      = BIT(5),
+       /* masks */
+       COMEDI_CB_ERROR_MASK    = (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW),
+       COMEDI_CB_CANCEL_MASK   = (COMEDI_CB_EOA | COMEDI_CB_ERROR_MASK)
+};
 
+/**
+ * struct comedi_driver - COMEDI driver registration
+ * @driver_name: Name of driver.
+ * @module: Owning module.
+ * @attach: The optional "attach" handler for manually configured COMEDI
+ *     devices.
+ * @detach: The "detach" handler for deconfiguring COMEDI devices.
+ * @auto_attach: The optional "auto_attach" handler for automatically
+ *     configured COMEDI devices.
+ * @num_names: Optional number of "board names" supported.
+ * @board_name: Optional pointer to a pointer to a board name.  The pointer
+ *     to a board name is embedded in an element of a driver-defined array
+ *     of static, read-only board type information.
+ * @offset: Optional size of each element of the driver-defined array of
+ *     static, read-only board type information, i.e. the offset between each
+ *     pointer to a board name.
+ *
+ * This is used with comedi_driver_register() and comedi_driver_unregister() to
+ * register and unregister a low-level COMEDI driver with the COMEDI core.
+ *
+ * If @num_names is non-zero, @board_name should be non-NULL, and @offset
+ * should be at least sizeof(*board_name).  These are used by the handler for
+ * the %COMEDI_DEVCONFIG ioctl to match a hardware device and its driver by
+ * board name.  If @num_names is zero, the %COMEDI_DEVCONFIG ioctl matches a
+ * hardware device and its driver by driver name.  This is only useful if the
+ * @attach handler is set.  If @num_names is non-zero, the driver's @attach
+ * handler will be called with the COMEDI device structure's board_ptr member
+ * pointing to the matched pointer to a board name within the driver's private
+ * array of static, read-only board type information.
+ */
 struct comedi_driver {
-       struct comedi_driver *next;
-
+       /* private: */
+       struct comedi_driver *next;     /* Next in list of COMEDI drivers. */
+       /* public: */
        const char *driver_name;
        struct module *module;
        int (*attach)(struct comedi_device *, struct comedi_devconfig *);
        void (*detach)(struct comedi_device *);
        int (*auto_attach)(struct comedi_device *, unsigned long);
-
-       /* number of elements in board_name and board_id arrays */
        unsigned int num_names;
        const char *const *board_name;
-       /* offset in bytes from one board name pointer to the next */
        int offset;
 };
 
+/**
+ * struct comedi_device - Working data for a COMEDI device
+ * @use_count: Number of open file objects.
+ * @driver: Low-level COMEDI driver attached to this COMEDI device.
+ * @pacer: Optional pointer to a dynamically allocated acquisition pacer
+ *     control.  It is freed automatically after the COMEDI device is
+ *     detached from the low-level driver.
+ * @private: Optional pointer to private data allocated by the low-level
+ *     driver.  It is freed automatically after the COMEDI device is
+ *     detached from the low-level driver.
+ * @class_dev: Sysfs comediX device.
+ * @minor: Minor device number of COMEDI char device (0-47).
+ * @detach_count: Counter incremented every time the COMEDI device is detached.
+ *     Used for checking a previous attachment is still valid.
+ * @hw_dev: Optional pointer to the low-level hardware &struct device.  It is
+ *     required for automatically configured COMEDI devices and optional for
+ *     COMEDI devices configured by the %COMEDI_DEVCONFIG ioctl, although
+ *     the bus-specific COMEDI functions only work if it is set correctly.
+ *     It is also passed to dma_alloc_coherent() for COMEDI subdevices that
+ *     have their 'async_dma_dir' member set to something other than
+ *     %DMA_NONE.
+ * @board_name: Pointer to a COMEDI board name or a COMEDI driver name.  When
+ *     the low-level driver's "attach" handler is called by the handler for
+ *     the %COMEDI_DEVCONFIG ioctl, it either points to a matched board name
+ *     string if the 'num_names' member of the &struct comedi_driver is
+ *     non-zero, otherwise it points to the low-level driver name string.
+ *     When the low-lever driver's "auto_attach" handler is called for an
+ *     automatically configured COMEDI device, it points to the low-level
+ *     driver name string.  The low-level driver is free to change it in its
+ *     "attach" or "auto_attach" handler if it wishes.
+ * @board_ptr: Optional pointer to private, read-only board type information in
+ *     the low-level driver.  If the 'num_names' member of the &struct
+ *     comedi_driver is non-zero, the handler for the %COMEDI_DEVCONFIG ioctl
+ *     will point it to a pointer to a matched board name string within the
+ *     driver's private array of static, read-only board type information when
+ *     calling the driver's "attach" handler.  The low-level driver is free to
+ *     change it.
+ * @attached: Flag indicating that the COMEDI device is attached to a low-level
+ *     driver.
+ * @ioenabled: Flag used to indicate that a PCI device has been enabled and
+ *     its regions requested.
+ * @spinlock: Generic spin-lock for use by the low-level driver.
+ * @mutex: Generic mutex for use by the COMEDI core module.
+ * @attach_lock: &struct rw_semaphore used to guard against the COMEDI device
+ *     being detached while an operation is in progress.  The down_write()
+ *     operation is only allowed while @mutex is held and is used when
+ *     changing @attached and @detach_count and calling the low-level driver's
+ *     "detach" handler.  The down_read() operation is generally used without
+ *     holding @mutex.
+ * @refcount: &struct kref reference counter for freeing COMEDI device.
+ * @n_subdevices: Number of COMEDI subdevices allocated by the low-level
+ *     driver for this device.
+ * @subdevices: Dynamically allocated array of COMEDI subdevices.
+ * @mmio: Optional pointer to a remapped MMIO region set by the low-level
+ *     driver.
+ * @iobase: Optional base of an I/O port region requested by the low-level
+ *     driver.
+ * @iolen: Length of I/O port region requested at @iobase.
+ * @irq: Optional IRQ number requested by the low-level driver.
+ * @read_subdev: Optional pointer to a default COMEDI subdevice operated on by
+ *     the read() file operation.  Set by the low-level driver.
+ * @write_subdev: Optional pointer to a default COMEDI subdevice operated on by
+ *     the write() file operation.  Set by the low-level driver.
+ * @async_queue: Storage for fasync_helper().
+ * @open: Optional pointer to a function set by the low-level driver to be
+ *     called when @use_count changes from 0 to 1.
+ * @close: Optional pointer to a function set by the low-level driver to be
+ *     called when @use_count changed from 1 to 0.
+ *
+ * This is the main control data structure for a COMEDI device (as far as the
+ * COMEDI core is concerned).  There are two groups of COMEDI devices -
+ * "legacy" devices that are configured by the handler for the
+ * %COMEDI_DEVCONFIG ioctl, and automatically configured devices resulting
+ * from a call to comedi_auto_config() as a result of a bus driver probe in
+ * a low-level COMEDI driver.  The "legacy" COMEDI devices are allocated
+ * during module initialization if the "comedi_num_legacy_minors" module
+ * parameter is non-zero and use minor device numbers from 0 to
+ * comedi_num_legacy_minors minus one.  The automatically configured COMEDI
+ * devices are allocated on demand and use minor device numbers from
+ * comedi_num_legacy_minors to 47.
+ */
 struct comedi_device {
        int use_count;
        struct comedi_driver *driver;
@@ -262,17 +531,14 @@ struct comedi_device {
        struct device *class_dev;
        int minor;
        unsigned int detach_count;
-       /* hw_dev is passed to dma_alloc_coherent when allocating async buffers
-        * for subdevices that have async_dma_dir set to something other than
-        * DMA_NONE */
        struct device *hw_dev;
 
        const char *board_name;
        const void *board_ptr;
        bool attached:1;
        bool ioenabled:1;
-       spinlock_t spinlock;
-       struct mutex mutex;
+       spinlock_t spinlock;    /* generic spin-lock for low-level driver */
+       struct mutex mutex;     /* generic mutex for COMEDI core */
        struct rw_semaphore attach_lock;
        struct kref refcount;
 
@@ -314,12 +580,12 @@ int comedi_check_chanlist(struct comedi_subdevice *s,
 
 /* range stuff */
 
-#define RANGE(a, b)            {(a)*1e6, (b)*1e6, 0}
-#define RANGE_ext(a, b)                {(a)*1e6, (b)*1e6, RF_EXTERNAL}
-#define RANGE_mA(a, b)         {(a)*1e6, (b)*1e6, UNIT_mA}
-#define RANGE_unitless(a, b)   {(a)*1e6, (b)*1e6, 0}
-#define BIP_RANGE(a)           {-(a)*1e6, (a)*1e6, 0}
-#define UNI_RANGE(a)           {0, (a)*1e6, 0}
+#define RANGE(a, b)            {(a) * 1e6, (b) * 1e6, 0}
+#define RANGE_ext(a, b)                {(a) * 1e6, (b) * 1e6, RF_EXTERNAL}
+#define RANGE_mA(a, b)         {(a) * 1e6, (b) * 1e6, UNIT_mA}
+#define RANGE_unitless(a, b)   {(a) * 1e6, (b) * 1e6, 0}
+#define BIP_RANGE(a)           {-(a) * 1e6, (a) * 1e6, 0}
+#define UNI_RANGE(a)           {0, (a) * 1e6, 0}
 
 extern const struct comedi_lrange range_bipolar10;
 extern const struct comedi_lrange range_bipolar5;
@@ -340,29 +606,101 @@ extern const struct comedi_lrange range_unknown;
 #define GCC_ZERO_LENGTH_ARRAY 0
 #endif
 
+/**
+ * struct comedi_lrange - Describes a COMEDI range table
+ * @length: Number of entries in the range table.
+ * @range: Array of &struct comedi_krange, one for each range.
+ *
+ * Each element of @range[] describes the minimum and maximum physical range
+ * range and the type of units.  Typically, the type of unit is %UNIT_volt
+ * (i.e. volts) and the minimum and maximum are in millionths of a volt.
+ * There may also be a flag that indicates the minimum and maximum are merely
+ * scale factors for an unknown, external reference.
+ */
 struct comedi_lrange {
        int length;
        struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY];
 };
 
+/**
+ * comedi_range_is_bipolar() - Test if subdevice range is bipolar
+ * @s: COMEDI subdevice.
+ * @range: Index of range within a range table.
+ *
+ * Tests whether a range is bipolar by checking whether its minimum value
+ * is negative.
+ *
+ * Assumes @range is valid.  Does not work for subdevices using a
+ * channel-specific range table list.
+ *
+ * Return:
+ *     %true if the range is bipolar.
+ *     %false if the range is unipolar.
+ */
 static inline bool comedi_range_is_bipolar(struct comedi_subdevice *s,
                                           unsigned int range)
 {
        return s->range_table->range[range].min < 0;
 }
 
+/**
+ * comedi_range_is_unipolar() - Test if subdevice range is unipolar
+ * @s: COMEDI subdevice.
+ * @range: Index of range within a range table.
+ *
+ * Tests whether a range is unipolar by checking whether its minimum value
+ * is at least 0.
+ *
+ * Assumes @range is valid.  Does not work for subdevices using a
+ * channel-specific range table list.
+ *
+ * Return:
+ *     %true if the range is unipolar.
+ *     %false if the range is bipolar.
+ */
 static inline bool comedi_range_is_unipolar(struct comedi_subdevice *s,
                                            unsigned int range)
 {
        return s->range_table->range[range].min >= 0;
 }
 
+/**
+ * comedi_range_is_external() - Test if subdevice range is external
+ * @s: COMEDI subdevice.
+ * @range: Index of range within a range table.
+ *
+ * Tests whether a range is externally reference by checking whether its
+ * %RF_EXTERNAL flag is set.
+ *
+ * Assumes @range is valid.  Does not work for subdevices using a
+ * channel-specific range table list.
+ *
+ * Return:
+ *     %true if the range is external.
+ *     %false if the range is internal.
+ */
 static inline bool comedi_range_is_external(struct comedi_subdevice *s,
                                            unsigned int range)
 {
        return !!(s->range_table->range[range].flags & RF_EXTERNAL);
 }
 
+/**
+ * comedi_chan_range_is_bipolar() - Test if channel-specific range is bipolar
+ * @s: COMEDI subdevice.
+ * @chan: The channel number.
+ * @range: Index of range within a range table.
+ *
+ * Tests whether a range is bipolar by checking whether its minimum value
+ * is negative.
+ *
+ * Assumes @chan and @range are valid.  Only works for subdevices with a
+ * channel-specific range table list.
+ *
+ * Return:
+ *     %true if the range is bipolar.
+ *     %false if the range is unipolar.
+ */
 static inline bool comedi_chan_range_is_bipolar(struct comedi_subdevice *s,
                                                unsigned int chan,
                                                unsigned int range)
@@ -370,6 +708,22 @@ static inline bool comedi_chan_range_is_bipolar(struct comedi_subdevice *s,
        return s->range_table_list[chan]->range[range].min < 0;
 }
 
+/**
+ * comedi_chan_range_is_unipolar() - Test if channel-specific range is unipolar
+ * @s: COMEDI subdevice.
+ * @chan: The channel number.
+ * @range: Index of range within a range table.
+ *
+ * Tests whether a range is unipolar by checking whether its minimum value
+ * is at least 0.
+ *
+ * Assumes @chan and @range are valid.  Only works for subdevices with a
+ * channel-specific range table list.
+ *
+ * Return:
+ *     %true if the range is unipolar.
+ *     %false if the range is bipolar.
+ */
 static inline bool comedi_chan_range_is_unipolar(struct comedi_subdevice *s,
                                                 unsigned int chan,
                                                 unsigned int range)
@@ -377,6 +731,22 @@ static inline bool comedi_chan_range_is_unipolar(struct comedi_subdevice *s,
        return s->range_table_list[chan]->range[range].min >= 0;
 }
 
+/**
+ * comedi_chan_range_is_external() - Test if channel-specific range is external
+ * @s: COMEDI subdevice.
+ * @chan: The channel number.
+ * @range: Index of range within a range table.
+ *
+ * Tests whether a range is externally reference by checking whether its
+ * %RF_EXTERNAL flag is set.
+ *
+ * Assumes @chan and @range are valid.  Only works for subdevices with a
+ * channel-specific range table list.
+ *
+ * Return:
+ *     %true if the range is bipolar.
+ *     %false if the range is unipolar.
+ */
 static inline bool comedi_chan_range_is_external(struct comedi_subdevice *s,
                                                 unsigned int chan,
                                                 unsigned int range)
@@ -384,7 +754,16 @@ static inline bool comedi_chan_range_is_external(struct comedi_subdevice *s,
        return !!(s->range_table_list[chan]->range[range].flags & RF_EXTERNAL);
 }
 
-/* munge between offset binary and two's complement values */
+/**
+ * comedi_offset_munge() - Convert between offset binary and 2's complement
+ * @s: COMEDI subdevice.
+ * @val: Value to be converted.
+ *
+ * Toggles the highest bit of a sample value to toggle between offset binary
+ * and 2's complement.  Assumes that @s->maxdata is a power of 2 minus 1.
+ *
+ * Return: The converted value.
+ */
 static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s,
                                               unsigned int val)
 {
@@ -392,13 +771,13 @@ static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s,
 }
 
 /**
- * comedi_bytes_per_sample - determine subdevice sample size
- * @s:         comedi_subdevice struct
+ * comedi_bytes_per_sample() - Determine subdevice sample size
+ * @s: COMEDI subdevice.
  *
  * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on
- * whether the SDF_LSAMPL subdevice flag is set or not.
+ * whether the %SDF_LSAMPL subdevice flag is set or not.
  *
- * Returns the subdevice sample size.
+ * Return: The subdevice sample size.
  */
 static inline unsigned int comedi_bytes_per_sample(struct comedi_subdevice *s)
 {
@@ -406,15 +785,15 @@ static inline unsigned int comedi_bytes_per_sample(struct comedi_subdevice *s)
 }
 
 /**
- * comedi_sample_shift - determine log2 of subdevice sample size
- * @s:         comedi_subdevice struct
+ * comedi_sample_shift() - Determine log2 of subdevice sample size
+ * @s: COMEDI subdevice.
  *
  * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on
- * whether the SDF_LSAMPL subdevice flag is set or not.  The log2 of the
+ * whether the %SDF_LSAMPL subdevice flag is set or not.  The log2 of the
  * sample size will be 2 or 1 and can be used as the right operand of a
  * bit-shift operator to multiply or divide something by the sample size.
  *
- * Returns log2 of the subdevice sample size.
+ * Return: log2 of the subdevice sample size.
  */
 static inline unsigned int comedi_sample_shift(struct comedi_subdevice *s)
 {
@@ -422,11 +801,11 @@ static inline unsigned int comedi_sample_shift(struct comedi_subdevice *s)
 }
 
 /**
- * comedi_bytes_to_samples - converts a number of bytes to a number of samples
- * @s:         comedi_subdevice struct
- * @nbytes:    number of bytes
+ * comedi_bytes_to_samples() - Convert a number of bytes to a number of samples
+ * @s: COMEDI subdevice.
+ * @nbytes: Number of bytes
  *
- * Returns the number of bytes divided by the subdevice sample size.
+ * Return: The number of bytes divided by the subdevice sample size.
  */
 static inline unsigned int comedi_bytes_to_samples(struct comedi_subdevice *s,
                                                   unsigned int nbytes)
@@ -435,12 +814,12 @@ static inline unsigned int comedi_bytes_to_samples(struct comedi_subdevice *s,
 }
 
 /**
- * comedi_samples_to_bytes - converts a number of samples to a number of bytes
- * @s:         comedi_subdevice struct
- * @nsamples:  number of samples
+ * comedi_samples_to_bytes() - Convert a number of samples to a number of bytes
+ * @s: COMEDI subdevice.
+ * @nsamples: Number of samples.
  *
- * Returns the number of samples multiplied by the subdevice sample size.
- * Does not check for arithmetic overflow.
+ * Return: The number of samples multiplied by the subdevice sample size.
+ * (Does not check for arithmetic overflow.)
  */
 static inline unsigned int comedi_samples_to_bytes(struct comedi_subdevice *s,
                                                   unsigned int nsamples)
@@ -449,14 +828,18 @@ static inline unsigned int comedi_samples_to_bytes(struct comedi_subdevice *s,
 }
 
 /**
- * comedi_check_trigger_src() - trivially validate a comedi_cmd trigger source
- * @src: pointer to the trigger source to validate
- * @flags: bitmask of valid TRIG_* for the trigger
+ * comedi_check_trigger_src() - Trivially validate a comedi_cmd trigger source
+ * @src: Pointer to the trigger source to validate.
+ * @flags: Bitmask of valid %TRIG_* for the trigger.
  *
  * This is used in "step 1" of the do_cmdtest functions of comedi drivers
- * to vaildate the comedi_cmd triggers. The mask of the @src against the
+ * to validate the comedi_cmd triggers. The mask of the @src against the
  * @flags allows the userspace comedilib to pass all the comedi_cmd
- * triggers as TRIG_ANY and get back a bitmask of the valid trigger sources.
+ * triggers as %TRIG_ANY and get back a bitmask of the valid trigger sources.
+ *
+ * Return:
+ *     0 if trigger sources in *@src are all supported.
+ *     -EINVAL if any trigger source in *@src is unsupported.
  */
 static inline int comedi_check_trigger_src(unsigned int *src,
                                           unsigned int flags)
@@ -470,8 +853,12 @@ static inline int comedi_check_trigger_src(unsigned int *src,
 }
 
 /**
- * comedi_check_trigger_is_unique() - make sure a trigger source is unique
- * @src: the trigger source to check
+ * comedi_check_trigger_is_unique() - Make sure a trigger source is unique
+ * @src: The trigger source to check.
+ *
+ * Return:
+ *     0 if no more than one trigger source is set.
+ *     -EINVAL if more than one trigger source is set.
  */
 static inline int comedi_check_trigger_is_unique(unsigned int src)
 {
@@ -482,9 +869,15 @@ static inline int comedi_check_trigger_is_unique(unsigned int src)
 }
 
 /**
- * comedi_check_trigger_arg_is() - trivially validate a trigger argument
- * @arg: pointer to the trigger arg to validate
- * @val: the value the argument should be
+ * comedi_check_trigger_arg_is() - Trivially validate a trigger argument
+ * @arg: Pointer to the trigger arg to validate.
+ * @val: The value the argument should be.
+ *
+ * Forces *@arg to be @val.
+ *
+ * Return:
+ *     0 if *@arg was already @val.
+ *     -EINVAL if *@arg differed from @val.
  */
 static inline int comedi_check_trigger_arg_is(unsigned int *arg,
                                              unsigned int val)
@@ -497,9 +890,15 @@ static inline int comedi_check_trigger_arg_is(unsigned int *arg,
 }
 
 /**
- * comedi_check_trigger_arg_min() - trivially validate a trigger argument
- * @arg: pointer to the trigger arg to validate
- * @val: the minimum value the argument should be
+ * comedi_check_trigger_arg_min() - Trivially validate a trigger argument min
+ * @arg: Pointer to the trigger arg to validate.
+ * @val: The minimum value the argument should be.
+ *
+ * Forces *@arg to be at least @val, setting it to @val if necessary.
+ *
+ * Return:
+ *     0 if *@arg was already at least @val.
+ *     -EINVAL if *@arg was less than @val.
  */
 static inline int comedi_check_trigger_arg_min(unsigned int *arg,
                                               unsigned int val)
@@ -512,9 +911,15 @@ static inline int comedi_check_trigger_arg_min(unsigned int *arg,
 }
 
 /**
- * comedi_check_trigger_arg_max() - trivially validate a trigger argument
- * @arg: pointer to the trigger arg to validate
- * @val: the maximum value the argument should be
+ * comedi_check_trigger_arg_max() - Trivially validate a trigger argument max
+ * @arg: Pointer to the trigger arg to validate.
+ * @val: The maximum value the argument should be.
+ *
+ * Forces *@arg to be no more than @val, setting it to @val if necessary.
+ *
+ * Return:
+ *     0 if*@arg was already no more than @val.
+ *     -EINVAL if *@arg was greater than @val.
  */
 static inline int comedi_check_trigger_arg_max(unsigned int *arg,
                                               unsigned int val)
@@ -534,6 +939,16 @@ static inline int comedi_check_trigger_arg_max(unsigned int *arg,
  */
 int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev);
 
+/**
+ * comedi_buf_n_bytes_ready - Determine amount of unread data in buffer
+ * @s: COMEDI subdevice.
+ *
+ * Determines the number of bytes of unread data in the asynchronous
+ * acquisition data buffer for a subdevice.  The data in question might not
+ * have been fully "munged" yet.
+ *
+ * Returns: The amount of unread data in bytes.
+ */
 static inline unsigned int comedi_buf_n_bytes_ready(struct comedi_subdevice *s)
 {
        return s->async->buf_write_count - s->async->buf_read_count;
index b03bc6639f79478fe3034c4e98fd42178a3467bc..b63dd2ef78b5584bf725d952422446085b893a20 100644 (file)
@@ -1,37 +1,29 @@
 /*
   module/drivers.c
   functions for manipulating drivers
-
   COMEDI - Linux Control and Measurement Device Interface
   Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
   Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
-
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
*  module/drivers.c
*  functions for manipulating drivers
+ *
*  COMEDI - Linux Control and Measurement Device Interface
*  Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
*  Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
+ *
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License, or
*  (at your option) any later version.
+ *
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
 */
 
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/errno.h>
-#include <linux/kconfig.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/fcntl.h>
 #include <linux/ioport.h>
-#include <linux/mm.h>
 #include <linux/slab.h>
-#include <linux/highmem.h>     /* for SuSE brokenness */
-#include <linux/vmalloc.h>
-#include <linux/cdev.h>
-#include <linux/dma-mapping.h>
-#include <linux/io.h>
+#include <linux/dma-direction.h>
 #include <linux/interrupt.h>
 #include <linux/firmware.h>
 
@@ -42,6 +34,28 @@ struct comedi_driver *comedi_drivers;
 /* protects access to comedi_drivers */
 DEFINE_MUTEX(comedi_drivers_list_lock);
 
+/**
+ * comedi_set_hw_dev() - Set hardware device associated with COMEDI device
+ * @dev: COMEDI device.
+ * @hw_dev: Hardware device.
+ *
+ * For automatically configured COMEDI devices (resulting from a call to
+ * comedi_auto_config() or one of its wrappers from the low-level COMEDI
+ * driver), comedi_set_hw_dev() is called automatically by the COMEDI core
+ * to associate the COMEDI device with the hardware device.  It can also be
+ * called directly by "legacy" low-level COMEDI drivers that rely on the
+ * %COMEDI_DEVCONFIG ioctl to configure the hardware as long as the hardware
+ * has a &struct device.
+ *
+ * If @dev->hw_dev is NULL, it gets a reference to @hw_dev and sets
+ * @dev->hw_dev, otherwise, it does nothing.  Calling it multiple times
+ * with the same hardware device is not considered an error.  If it gets
+ * a reference to the hardware device, it will be automatically 'put' when
+ * the device is detached from COMEDI.
+ *
+ * Returns 0 if @dev->hw_dev was NULL or the same as @hw_dev, otherwise
+ * returns -EEXIST.
+ */
 int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev)
 {
        if (hw_dev == dev->hw_dev)
@@ -60,9 +74,15 @@ static void comedi_clear_hw_dev(struct comedi_device *dev)
 }
 
 /**
- * comedi_alloc_devpriv() - Allocate memory for the device private data.
- * @dev: comedi_device struct
- * @size: size of the memory to allocate
+ * comedi_alloc_devpriv() - Allocate memory for the device private data
+ * @dev: COMEDI device.
+ * @size: Size of the memory to allocate.
+ *
+ * The allocated memory is zero-filled.  @dev->private points to it on
+ * return.  The memory will be automatically freed when the COMEDI device is
+ * "detached".
+ *
+ * Returns a pointer to the allocated memory, or NULL on failure.
  */
 void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size)
 {
@@ -71,6 +91,18 @@ void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size)
 }
 EXPORT_SYMBOL_GPL(comedi_alloc_devpriv);
 
+/**
+ * comedi_alloc_subdevices() - Allocate subdevices for COMEDI device
+ * @dev: COMEDI device.
+ * @num_subdevices: Number of subdevices to allocate.
+ *
+ * Allocates and initializes an array of &struct comedi_subdevice for the
+ * COMEDI device.  If successful, sets @dev->subdevices to point to the
+ * first one and @dev->n_subdevices to the number.
+ *
+ * Returns 0 on success, -EINVAL if @num_subdevices is < 1, or -ENOMEM if
+ * failed to allocate the memory.
+ */
 int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
 {
        struct comedi_subdevice *s;
@@ -98,8 +130,22 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
 EXPORT_SYMBOL_GPL(comedi_alloc_subdevices);
 
 /**
- * comedi_alloc_subdev_readback() - Allocate memory for the subdevice readback.
- * @s: comedi_subdevice struct
+ * comedi_alloc_subdev_readback() - Allocate memory for the subdevice readback
+ * @s: COMEDI subdevice.
+ *
+ * This is called by low-level COMEDI drivers to allocate an array to record
+ * the last values written to a subdevice's analog output channels (at least
+ * by the %INSN_WRITE instruction), to allow them to be read back by an
+ * %INSN_READ instruction.  It also provides a default handler for the
+ * %INSN_READ instruction unless one has already been set.
+ *
+ * On success, @s->readback points to the first element of the array, which
+ * is zero-filled.  The low-level driver is responsible for updating its
+ * contents.  @s->insn_read will be set to comedi_readback_insn_read()
+ * unless it is already non-NULL.
+ *
+ * Returns 0 on success, -EINVAL if the subdevice has no channels, or
+ * -ENOMEM on allocation failure.
  */
 int comedi_alloc_subdev_readback(struct comedi_subdevice *s)
 {
@@ -182,10 +228,20 @@ int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
 
 /**
  * comedi_readback_insn_read() - A generic (*insn_read) for subdevice readback.
- * @dev: comedi_device struct
- * @s: comedi_subdevice struct
- * @insn: comedi_insn struct
- * @data: pointer to return the readback data
+ * @dev: COMEDI device.
+ * @s: COMEDI subdevice.
+ * @insn: COMEDI instruction.
+ * @data: Pointer to return the readback data.
+ *
+ * Handles the %INSN_READ instruction for subdevices that use the readback
+ * array allocated by comedi_alloc_subdev_readback().  It may be used
+ * directly as the subdevice's handler (@s->insn_read) or called via a
+ * wrapper.
+ *
+ * @insn->n is normally 1, which will read a single value.  If higher, the
+ * same element of the readback array will be read multiple times.
+ *
+ * Returns @insn->n on success, or -EINVAL if @s->readback is NULL.
  */
 int comedi_readback_insn_read(struct comedi_device *dev,
                              struct comedi_subdevice *s,
@@ -206,12 +262,21 @@ int comedi_readback_insn_read(struct comedi_device *dev,
 EXPORT_SYMBOL_GPL(comedi_readback_insn_read);
 
 /**
- * comedi_timeout() - busy-wait for a driver condition to occur.
- * @dev: comedi_device struct
- * @s: comedi_subdevice struct
- * @insn: comedi_insn struct
- * @cb: callback to check for the condition
- * @context: private context from the driver
+ * comedi_timeout() - Busy-wait for a driver condition to occur
+ * @dev: COMEDI device.
+ * @s: COMEDI subdevice.
+ * @insn: COMEDI instruction.
+ * @cb: Callback to check for the condition.
+ * @context: Private context from the driver.
+ *
+ * Busy-waits for up to a second (%COMEDI_TIMEOUT_MS) for the condition or
+ * some error (other than -EBUSY) to occur.  The parameters @dev, @s, @insn,
+ * and @context are passed to the callback function, which returns -EBUSY to
+ * continue waiting or some other value to stop waiting (generally 0 if the
+ * condition occurred, or some error value).
+ *
+ * Returns -ETIMEDOUT if timed out, otherwise the return value from the
+ * callback function.
  */
 int comedi_timeout(struct comedi_device *dev,
                   struct comedi_subdevice *s,
@@ -236,12 +301,30 @@ int comedi_timeout(struct comedi_device *dev,
 EXPORT_SYMBOL_GPL(comedi_timeout);
 
 /**
- * comedi_dio_insn_config() - boilerplate (*insn_config) for DIO subdevices.
- * @dev: comedi_device struct
- * @s: comedi_subdevice struct
- * @insn: comedi_insn struct
- * @data: parameters for the @insn
- * @mask: io_bits mask for grouped channels
+ * comedi_dio_insn_config() - Boilerplate (*insn_config) for DIO subdevices
+ * @dev: COMEDI device.
+ * @s: COMEDI subdevice.
+ * @insn: COMEDI instruction.
+ * @data: Instruction parameters and return data.
+ * @mask: io_bits mask for grouped channels, or 0 for single channel.
+ *
+ * If @mask is 0, it is replaced with a single-bit mask corresponding to the
+ * channel number specified by @insn->chanspec.  Otherwise, @mask
+ * corresponds to a group of channels (which should include the specified
+ * channel) that are always configured together as inputs or outputs.
+ *
+ * Partially handles the %INSN_CONFIG_DIO_INPUT, %INSN_CONFIG_DIO_OUTPUTS,
+ * and %INSN_CONFIG_DIO_QUERY instructions.  The first two update
+ * @s->io_bits to record the directions of the masked channels.  The last
+ * one sets @data[1] to the current direction of the group of channels
+ * (%COMEDI_INPUT) or %COMEDI_OUTPUT) as recorded in @s->io_bits.
+ *
+ * The caller is responsible for updating the DIO direction in the hardware
+ * registers if this function returns 0.
+ *
+ * Returns 0 for a %INSN_CONFIG_DIO_INPUT or %INSN_CONFIG_DIO_OUTPUT
+ * instruction, @insn->n (> 0) for a %INSN_CONFIG_DIO_QUERY instruction, or
+ * -EINVAL for some other instruction.
  */
 int comedi_dio_insn_config(struct comedi_device *dev,
                           struct comedi_subdevice *s,
@@ -276,9 +359,18 @@ int comedi_dio_insn_config(struct comedi_device *dev,
 EXPORT_SYMBOL_GPL(comedi_dio_insn_config);
 
 /**
- * comedi_dio_update_state() - update the internal state of DIO subdevices.
- * @s: comedi_subdevice struct
- * @data: the channel mask and bits to update
+ * comedi_dio_update_state() - Update the internal state of DIO subdevices
+ * @s: COMEDI subdevice.
+ * @data: The channel mask and bits to update.
+ *
+ * Updates @s->state which holds the internal state of the outputs for DIO
+ * or DO subdevices (up to 32 channels).  @data[0] contains a bit-mask of
+ * the channels to be updated.  @data[1] contains a bit-mask of those
+ * channels to be set to '1'.  The caller is responsible for updating the
+ * outputs in hardware according to @s->state.  As a minimum, the channels
+ * in the returned bit-mask need to be updated.
+ *
+ * Returns @mask with non-existent channels removed.
  */
 unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
                                     unsigned int *data)
@@ -298,17 +390,17 @@ unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
 EXPORT_SYMBOL_GPL(comedi_dio_update_state);
 
 /**
- * comedi_bytes_per_scan - get length of asynchronous command "scan" in bytes
- * @s: comedi_subdevice struct
+ * comedi_bytes_per_scan() - Get length of asynchronous command "scan" in bytes
+ * @s: COMEDI subdevice.
  *
  * Determines the overall scan length according to the subdevice type and the
  * number of channels in the scan.
  *
- * For digital input, output or input/output subdevices, samples for multiple
- * channels are assumed to be packed into one or more unsigned short or
- * unsigned int values according to the subdevice's SDF_LSAMPL flag.  For other
- * types of subdevice, samples are assumed to occupy a whole unsigned short or
- * unsigned int according to the SDF_LSAMPL flag.
+ * For digital input, output or input/output subdevices, samples for
+ * multiple channels are assumed to be packed into one or more unsigned
+ * short or unsigned int values according to the subdevice's %SDF_LSAMPL
+ * flag.  For other types of subdevice, samples are assumed to occupy a
+ * whole unsigned short or unsigned int according to the %SDF_LSAMPL flag.
  *
  * Returns the overall scan length in bytes.
  */
@@ -333,32 +425,12 @@ unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s)
 }
 EXPORT_SYMBOL_GPL(comedi_bytes_per_scan);
 
-/**
- * comedi_nscans_left - return the number of scans left in the command
- * @s: comedi_subdevice struct
- * @nscans: the expected number of scans
- *
- * If nscans is 0, the number of scans available in the async buffer will be
- * used. Otherwise the expected number of scans will be used.
- *
- * If the async command has a stop_src of TRIG_COUNT, the nscans will be
- * checked against the number of scans left in the command.
- *
- * The return value will then be either the expected number of scans or the
- * number of scans remaining in the command.
- */
-unsigned int comedi_nscans_left(struct comedi_subdevice *s,
-                               unsigned int nscans)
+static unsigned int __comedi_nscans_left(struct comedi_subdevice *s,
+                                        unsigned int nscans)
 {
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
 
-       if (nscans == 0) {
-               unsigned int nbytes = comedi_buf_read_n_available(s);
-
-               nscans = nbytes / comedi_bytes_per_scan(s);
-       }
-
        if (cmd->stop_src == TRIG_COUNT) {
                unsigned int scans_left = 0;
 
@@ -370,15 +442,40 @@ unsigned int comedi_nscans_left(struct comedi_subdevice *s,
        }
        return nscans;
 }
+
+/**
+ * comedi_nscans_left() - Return the number of scans left in the command
+ * @s: COMEDI subdevice.
+ * @nscans: The expected number of scans or 0 for all available scans.
+ *
+ * If @nscans is 0, it is set to the number of scans available in the
+ * async buffer.
+ *
+ * If the async command has a stop_src of %TRIG_COUNT, the @nscans will be
+ * checked against the number of scans remaining to complete the command.
+ *
+ * The return value will then be either the expected number of scans or the
+ * number of scans remaining to complete the command, whichever is fewer.
+ */
+unsigned int comedi_nscans_left(struct comedi_subdevice *s,
+                               unsigned int nscans)
+{
+       if (nscans == 0) {
+               unsigned int nbytes = comedi_buf_read_n_available(s);
+
+               nscans = nbytes / comedi_bytes_per_scan(s);
+       }
+       return __comedi_nscans_left(s, nscans);
+}
 EXPORT_SYMBOL_GPL(comedi_nscans_left);
 
 /**
- * comedi_nsamples_left - return the number of samples left in the command
- * @s: comedi_subdevice struct
- * @nsamples: the expected number of samples
+ * comedi_nsamples_left() - Return the number of samples left in the command
+ * @s: COMEDI subdevice.
+ * @nsamples: The expected number of samples.
  *
- * Returns the expected number of samples of the number of samples remaining
- * in the command.
+ * Returns the number of samples remaining to complete the command, or the
+ * specified expected number of samples (@nsamples), whichever is fewer.
  */
 unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
                                  unsigned int nsamples)
@@ -387,9 +484,8 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
        struct comedi_cmd *cmd = &async->cmd;
 
        if (cmd->stop_src == TRIG_COUNT) {
-               /* +1 to force comedi_nscans_left() to return the scans left */
-               unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1;
-               unsigned int scans_left = comedi_nscans_left(s, nscans);
+               unsigned int nscans = nsamples / cmd->scan_end_arg;
+               unsigned int scans_left = __comedi_nscans_left(s, nscans);
                unsigned int scan_pos =
                    comedi_bytes_to_samples(s, async->scan_progress);
                unsigned long long samples_left = 0;
@@ -407,14 +503,14 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
 EXPORT_SYMBOL_GPL(comedi_nsamples_left);
 
 /**
- * comedi_inc_scan_progress - update scan progress in asynchronous command
- * @s: comedi_subdevice struct
- * @num_bytes: amount of data in bytes to increment scan progress
+ * comedi_inc_scan_progress() - Update scan progress in asynchronous command
+ * @s: COMEDI subdevice.
+ * @num_bytes: Amount of data in bytes to increment scan progress.
  *
- * Increments the scan progress by the number of bytes specified by num_bytes.
+ * Increments the scan progress by the number of bytes specified by @num_bytes.
  * If the scan progress reaches or exceeds the scan length in bytes, reduce
  * it modulo the scan length in bytes and set the "end of scan" asynchronous
- * event flag to be processed later.
+ * event flag (%COMEDI_CB_EOS) to be processed later.
  */
 void comedi_inc_scan_progress(struct comedi_subdevice *s,
                              unsigned int num_bytes)
@@ -445,12 +541,12 @@ void comedi_inc_scan_progress(struct comedi_subdevice *s,
 EXPORT_SYMBOL_GPL(comedi_inc_scan_progress);
 
 /**
- * comedi_handle_events - handle events and possibly stop acquisition
- * @dev: comedi_device struct
- * @s: comedi_subdevice struct
+ * comedi_handle_events() - Handle events and possibly stop acquisition
+ * @dev: COMEDI device.
+ * @s: COMEDI subdevice.
  *
  * Handles outstanding asynchronous acquisition event flags associated
- * with the subdevice.  Call the subdevice's "->cancel()" handler if the
+ * with the subdevice.  Call the subdevice's @s->cancel() handler if the
  * "end of acquisition", "error" or "overflow" event flags are set in order
  * to stop the acquisition at the driver level.
  *
@@ -685,12 +781,19 @@ static void comedi_report_boards(struct comedi_driver *driv)
 }
 
 /**
- * comedi_load_firmware() - Request and load firmware for a device.
- * @dev: comedi_device struct
- * @hw_device: device struct for the comedi_device
- * @name: the name of the firmware image
- * @cb: callback to the upload the firmware image
- * @context: private context from the driver
+ * comedi_load_firmware() - Request and load firmware for a device
+ * @dev: COMEDI device.
+ * @device: Hardware device.
+ * @name: The name of the firmware image.
+ * @cb: Callback to the upload the firmware image.
+ * @context: Private context from the driver.
+ *
+ * Sends a firmware request for the hardware device and waits for it.  Calls
+ * the callback function to upload the firmware to the device, them releases
+ * the firmware.
+ *
+ * Returns 0 on success, -EINVAL if @cb is NULL, or a negative error number
+ * from the firmware request or the callback function.
  */
 int comedi_load_firmware(struct comedi_device *dev,
                         struct device *device,
@@ -717,10 +820,16 @@ int comedi_load_firmware(struct comedi_device *dev,
 EXPORT_SYMBOL_GPL(comedi_load_firmware);
 
 /**
- * __comedi_request_region() - Request an I/O reqion for a legacy driver.
- * @dev: comedi_device struct
- * @start: base address of the I/O reqion
- * @len: length of the I/O region
+ * __comedi_request_region() - Request an I/O region for a legacy driver
+ * @dev: COMEDI device.
+ * @start: Base address of the I/O region.
+ * @len: Length of the I/O region.
+ *
+ * Requests the specified I/O port region which must start at a non-zero
+ * address.
+ *
+ * Returns 0 on success, -EINVAL if @start is 0, or -EIO if the request
+ * fails.
  */
 int __comedi_request_region(struct comedi_device *dev,
                            unsigned long start, unsigned long len)
@@ -743,10 +852,19 @@ int __comedi_request_region(struct comedi_device *dev,
 EXPORT_SYMBOL_GPL(__comedi_request_region);
 
 /**
- * comedi_request_region() - Request an I/O reqion for a legacy driver.
- * @dev: comedi_device struct
- * @start: base address of the I/O reqion
- * @len: length of the I/O region
+ * comedi_request_region() - Request an I/O region for a legacy driver
+ * @dev: COMEDI device.
+ * @start: Base address of the I/O region.
+ * @len: Length of the I/O region.
+ *
+ * Requests the specified I/O port region which must start at a non-zero
+ * address.
+ *
+ * On success, @dev->iobase is set to the base address of the region and
+ * @dev->iolen is set to its length.
+ *
+ * Returns 0 on success, -EINVAL if @start is 0, or -EIO if the request
+ * fails.
  */
 int comedi_request_region(struct comedi_device *dev,
                          unsigned long start, unsigned long len)
@@ -764,8 +882,16 @@ int comedi_request_region(struct comedi_device *dev,
 EXPORT_SYMBOL_GPL(comedi_request_region);
 
 /**
- * comedi_legacy_detach() - A generic (*detach) function for legacy drivers.
- * @dev: comedi_device struct
+ * comedi_legacy_detach() - A generic (*detach) function for legacy drivers
+ * @dev: COMEDI device.
+ *
+ * This is a simple, generic 'detach' handler for legacy COMEDI devices that
+ * just use a single I/O port region and possibly an IRQ and that don't need
+ * any special clean-up for their private device or subdevice storage.  It
+ * can also be called by a driver-specific 'detach' handler.
+ *
+ * If @dev->irq is non-zero, the IRQ will be freed.  If @dev->iobase and
+ * @dev->iolen are both non-zero, the I/O port region will be released.
  */
 void comedi_legacy_detach(struct comedi_device *dev)
 {
@@ -839,6 +965,29 @@ out:
        return ret;
 }
 
+/**
+ * comedi_auto_config() - Create a COMEDI device for a hardware device
+ * @hardware_device: Hardware device.
+ * @driver: COMEDI low-level driver for the hardware device.
+ * @context: Driver context for the auto_attach handler.
+ *
+ * Allocates a new COMEDI device for the hardware device and calls the
+ * low-level driver's 'auto_attach' handler to set-up the hardware and
+ * allocate the COMEDI subdevices.  Additional "post-configuration" setting
+ * up is performed on successful return from the 'auto_attach' handler.
+ * If the 'auto_attach' handler fails, the low-level driver's 'detach'
+ * handler will be called as part of the clean-up.
+ *
+ * This is usually called from a wrapper function in a bus-specific COMEDI
+ * module, which in turn is usually called from a bus device 'probe'
+ * function in the low-level driver.
+ *
+ * Returns 0 on success, -EINVAL if the parameters are invalid or the
+ * post-configuration determines the driver has set the COMEDI device up
+ * incorrectly, -ENOMEM if failed to allocate memory, -EBUSY if run out of
+ * COMEDI minor device numbers, or some negative error number returned by
+ * the driver's 'auto_attach' handler.
+ */
 int comedi_auto_config(struct device *hardware_device,
                       struct comedi_driver *driver, unsigned long context)
 {
@@ -896,6 +1045,22 @@ int comedi_auto_config(struct device *hardware_device,
 }
 EXPORT_SYMBOL_GPL(comedi_auto_config);
 
+/**
+ * comedi_auto_unconfig() - Unconfigure auto-allocated COMEDI device
+ * @hardware_device: Hardware device previously passed to
+ *                   comedi_auto_config().
+ *
+ * Cleans up and eventually destroys the COMEDI device allocated by
+ * comedi_auto_config() for the same hardware device.  As part of this
+ * clean-up, the low-level COMEDI driver's 'detach' handler will be called.
+ * (The COMEDI device itself will persist in an unattached state if it is
+ * still open, until it is released, and any mmapped buffers will persist
+ * until they are munmapped.)
+ *
+ * This is usually called from a wrapper module in a bus-specific COMEDI
+ * module, which in turn is usually set as the bus device 'remove' function
+ * in the low-level COMEDI driver.
+ */
 void comedi_auto_unconfig(struct device *hardware_device)
 {
        if (!hardware_device)
@@ -904,6 +1069,17 @@ void comedi_auto_unconfig(struct device *hardware_device)
 }
 EXPORT_SYMBOL_GPL(comedi_auto_unconfig);
 
+/**
+ * comedi_driver_register() - Register a low-level COMEDI driver
+ * @driver: Low-level COMEDI driver.
+ *
+ * The low-level COMEDI driver is added to the list of registered COMEDI
+ * drivers.  This is used by the handler for the "/proc/comedi" file and is
+ * also used by the handler for the %COMEDI_DEVCONFIG ioctl to configure
+ * "legacy" COMEDI devices (for those low-level drivers that support it).
+ *
+ * Returns 0.
+ */
 int comedi_driver_register(struct comedi_driver *driver)
 {
        mutex_lock(&comedi_drivers_list_lock);
@@ -915,6 +1091,15 @@ int comedi_driver_register(struct comedi_driver *driver)
 }
 EXPORT_SYMBOL_GPL(comedi_driver_register);
 
+/**
+ * comedi_driver_unregister() - Unregister a low-level COMEDI driver
+ * @driver: Low-level COMEDI driver.
+ *
+ * The low-level COMEDI driver is removed from the list of registered COMEDI
+ * drivers.  Detaches any COMEDI devices attached to the driver, which will
+ * result in the low-level driver's 'detach' handler being called for those
+ * devices before this function returns.
+ */
 void comedi_driver_unregister(struct comedi_driver *driver)
 {
        struct comedi_driver *prev;
index 41823de69b77c1fb988b356a664e70550b66bd50..55a67af5152d1368e3d0500615519e15e39d8356 100644 (file)
 #define I8255_DATA_B_REG       0x01
 #define I8255_DATA_C_REG       0x02
 #define I8255_CTRL_REG         0x03
-#define I8255_CTRL_C_LO_IO     (1 << 0)
-#define I8255_CTRL_B_IO                (1 << 1)
-#define I8255_CTRL_B_MODE      (1 << 2)
-#define I8255_CTRL_C_HI_IO     (1 << 3)
-#define I8255_CTRL_A_IO                (1 << 4)
+#define I8255_CTRL_C_LO_IO     BIT(0)
+#define I8255_CTRL_B_IO                BIT(1)
+#define I8255_CTRL_B_MODE      BIT(2)
+#define I8255_CTRL_C_HI_IO     BIT(3)
+#define I8255_CTRL_A_IO                BIT(4)
 #define I8255_CTRL_A_MODE(x)   ((x) << 5)
-#define I8255_CTRL_CW          (1 << 7)
+#define I8255_CTRL_CW          BIT(7)
 
 struct comedi_device;
 struct comedi_subdevice;
index bb9854b568077b80f5203c3861e70ab6c1eb71b9..38c05d1ec6475a742cbac8b6e4c5a61353e4afdb 100644 (file)
@@ -178,8 +178,8 @@ static const struct pci_8255_boardinfo pci_8255_boards[] = {
 };
 
 /* ripped from mite.h and mite_setup2() to avoid mite dependency */
-#define MITE_IODWBSR   0xc0     /* IO Device Window Base Size Register */
-#define WENAB          (1 << 7) /* window enable */
+#define MITE_IODWBSR   0xc0    /* IO Device Window Base Size Register */
+#define WENAB          BIT(7)  /* window enable */
 
 static int pci_8255_mite_init(struct pci_dev *pcidev)
 {
index 5764dc9a68933a790305d96dc49a6af09eae4225..c3b8f2d7611b9fb0f5159b8034609cb9cce2e308 100644 (file)
@@ -90,7 +90,6 @@ obj-$(CONFIG_COMEDI_CONTEC_PCI_DIO)   += contec_pci_dio.o
 obj-$(CONFIG_COMEDI_DAS08_PCI)         += das08_pci.o
 obj-$(CONFIG_COMEDI_DT3000)            += dt3000.o
 obj-$(CONFIG_COMEDI_DYNA_PCI10XX)      += dyna_pci10xx.o
-obj-$(CONFIG_COMEDI_UNIOXX5)           += unioxx5.o
 obj-$(CONFIG_COMEDI_GSC_HPDI)          += gsc_hpdi.o
 obj-$(CONFIG_COMEDI_ICP_MULTI)         += icp_multi.o
 obj-$(CONFIG_COMEDI_DAQBOARD2000)      += daqboard2000.o
index b37166d57b64cd277e7484b2be22afe72ba20c54..ccd1a91290bf9a27cc4471d5efdc6d1cebb6a22f 100644 (file)
 #define APCI1032_MODE2_REG             0x08
 #define APCI1032_STATUS_REG            0x0c
 #define APCI1032_CTRL_REG              0x10
-#define APCI1032_CTRL_INT_OR           (0 << 1)
-#define APCI1032_CTRL_INT_AND          (1 << 1)
-#define APCI1032_CTRL_INT_ENA          (1 << 2)
+#define APCI1032_CTRL_INT_MODE(x)      (((x) & 0x1) << 1)
+#define APCI1032_CTRL_INT_OR           APCI1032_CTRL_INT_MODE(0)
+#define APCI1032_CTRL_INT_AND          APCI1032_CTRL_INT_MODE(1)
+#define APCI1032_CTRL_INT_ENA          BIT(2)
 
 struct apci1032_private {
        unsigned long amcc_iobase;      /* base of AMCC I/O registers */
index ad715253bdccdfdbeb04993c5ad9ee264ce5f615..50f9eb25d7cbd55d6dee07b73392c5ca7ba8ebd9 100644 (file)
  */
 #define APCI2032_DO_REG                        0x00
 #define APCI2032_INT_CTRL_REG          0x04
-#define APCI2032_INT_CTRL_VCC_ENA      (1 << 0)
-#define APCI2032_INT_CTRL_CC_ENA       (1 << 1)
+#define APCI2032_INT_CTRL_VCC_ENA      BIT(0)
+#define APCI2032_INT_CTRL_CC_ENA       BIT(1)
 #define APCI2032_INT_STATUS_REG                0x08
-#define APCI2032_INT_STATUS_VCC                (1 << 0)
-#define APCI2032_INT_STATUS_CC         (1 << 1)
+#define APCI2032_INT_STATUS_VCC                BIT(0)
+#define APCI2032_INT_STATUS_CC         BIT(1)
 #define APCI2032_STATUS_REG            0x0c
-#define APCI2032_STATUS_IRQ            (1 << 0)
+#define APCI2032_STATUS_IRQ            BIT(0)
 #define APCI2032_WDOG_REG              0x10
 
 struct apci2032_int_private {
-       spinlock_t spinlock;
-       bool active;
-       unsigned char enabled_isns;
+       spinlock_t spinlock;            /* protects the following members */
+       bool active;                    /* an async command is running */
+       unsigned char enabled_isns;     /* mask of enabled interrupt channels */
 };
 
 static int apci2032_do_insn_bits(struct comedi_device *dev,
index 5bfd43d5c8893f43f319356e36a90bc8ff6d2149..3630d75e36e85255a33c877b8eb647c548ed4a40 100644 (file)
  * PCI BAR 0 register map (devpriv->amcc)
  * see amcc_s5933.h for register and bit defines
  */
-#define APCI3120_FIFO_ADVANCE_ON_BYTE_2                (1 << 29)
+#define APCI3120_FIFO_ADVANCE_ON_BYTE_2                BIT(29)
 
 /*
  * PCI BAR 1 register map (dev->iobase)
  */
 #define APCI3120_AI_FIFO_REG                   0x00
 #define APCI3120_CTRL_REG                      0x00
-#define APCI3120_CTRL_EXT_TRIG                 (1 << 15)
-#define APCI3120_CTRL_GATE(x)                  (1 << (12 + (x)))
+#define APCI3120_CTRL_EXT_TRIG                 BIT(15)
+#define APCI3120_CTRL_GATE(x)                  BIT(12 + (x))
 #define APCI3120_CTRL_PR(x)                    (((x) & 0xf) << 8)
 #define APCI3120_CTRL_PA(x)                    (((x) & 0xf) << 0)
 #define APCI3120_AI_SOFTTRIG_REG               0x02
 #define APCI3120_STATUS_REG                    0x02
-#define APCI3120_STATUS_EOC_INT                        (1 << 15)
-#define APCI3120_STATUS_AMCC_INT               (1 << 14)
-#define APCI3120_STATUS_EOS_INT                        (1 << 13)
-#define APCI3120_STATUS_TIMER2_INT             (1 << 12)
+#define APCI3120_STATUS_EOC_INT                        BIT(15)
+#define APCI3120_STATUS_AMCC_INT               BIT(14)
+#define APCI3120_STATUS_EOS_INT                        BIT(13)
+#define APCI3120_STATUS_TIMER2_INT             BIT(12)
 #define APCI3120_STATUS_INT_MASK               (0xf << 12)
 #define APCI3120_STATUS_TO_DI_BITS(x)          (((x) >> 8) & 0xf)
 #define APCI3120_STATUS_TO_VERSION(x)          (((x) >> 4) & 0xf)
-#define APCI3120_STATUS_FIFO_FULL              (1 << 2)
-#define APCI3120_STATUS_FIFO_EMPTY             (1 << 1)
-#define APCI3120_STATUS_DA_READY               (1 << 0)
+#define APCI3120_STATUS_FIFO_FULL              BIT(2)
+#define APCI3120_STATUS_FIFO_EMPTY             BIT(1)
+#define APCI3120_STATUS_DA_READY               BIT(0)
 #define APCI3120_TIMER_REG                     0x04
 #define APCI3120_CHANLIST_REG                  0x06
 #define APCI3120_CHANLIST_INDEX(x)             (((x) & 0xf) << 8)
-#define APCI3120_CHANLIST_UNIPOLAR             (1 << 7)
+#define APCI3120_CHANLIST_UNIPOLAR             BIT(7)
 #define APCI3120_CHANLIST_GAIN(x)              (((x) & 0x3) << 4)
 #define APCI3120_CHANLIST_MUX(x)               (((x) & 0xf) << 0)
 #define APCI3120_AO_REG(x)                     (0x08 + (((x) / 4) * 2))
 #define APCI3120_CTR0_DO_BITS(x)               ((x) << 4)
 #define APCI3120_CTR0_TIMER_SEL(x)             ((x) << 0)
 #define APCI3120_MODE_REG                      0x0e
-#define APCI3120_MODE_TIMER2_CLK_OSC           (0 << 6)
-#define APCI3120_MODE_TIMER2_CLK_OUT1          (1 << 6)
-#define APCI3120_MODE_TIMER2_CLK_EOC           (2 << 6)
-#define APCI3120_MODE_TIMER2_CLK_EOS           (3 << 6)
-#define APCI3120_MODE_TIMER2_CLK_MASK          (3 << 6)
-#define APCI3120_MODE_TIMER2_AS_TIMER          (0 << 4)
-#define APCI3120_MODE_TIMER2_AS_COUNTER                (1 << 4)
-#define APCI3120_MODE_TIMER2_AS_WDOG           (2 << 4)
-#define APCI3120_MODE_TIMER2_AS_MASK           (3 << 4)  /* sets AS_TIMER */
-#define APCI3120_MODE_SCAN_ENA                 (1 << 3)
-#define APCI3120_MODE_TIMER2_IRQ_ENA           (1 << 2)
-#define APCI3120_MODE_EOS_IRQ_ENA              (1 << 1)
-#define APCI3120_MODE_EOC_IRQ_ENA              (1 << 0)
+#define APCI3120_MODE_TIMER2_CLK(x)            (((x) & 0x3) << 6)
+#define APCI3120_MODE_TIMER2_CLK_OSC           APCI3120_MODE_TIMER2_CLK(0)
+#define APCI3120_MODE_TIMER2_CLK_OUT1          APCI3120_MODE_TIMER2_CLK(1)
+#define APCI3120_MODE_TIMER2_CLK_EOC           APCI3120_MODE_TIMER2_CLK(2)
+#define APCI3120_MODE_TIMER2_CLK_EOS           APCI3120_MODE_TIMER2_CLK(3)
+#define APCI3120_MODE_TIMER2_CLK_MASK          APCI3120_MODE_TIMER2_CLK(3)
+#define APCI3120_MODE_TIMER2_AS(x)             (((x) & 0x3) << 4)
+#define APCI3120_MODE_TIMER2_AS_TIMER          APCI3120_MODE_TIMER2_AS(0)
+#define APCI3120_MODE_TIMER2_AS_COUNTER                APCI3120_MODE_TIMER2_AS(1)
+#define APCI3120_MODE_TIMER2_AS_WDOG           APCI3120_MODE_TIMER2_AS(2)
+#define APCI3120_MODE_TIMER2_AS_MASK           APCI3120_MODE_TIMER2_AS(3)
+#define APCI3120_MODE_SCAN_ENA                 BIT(3)
+#define APCI3120_MODE_TIMER2_IRQ_ENA           BIT(2)
+#define APCI3120_MODE_EOS_IRQ_ENA              BIT(1)
+#define APCI3120_MODE_EOC_IRQ_ENA              BIT(0)
 
 /*
  * PCI BAR 2 register map (devpriv->addon)
@@ -94,8 +96,8 @@
 #define APCI3120_ADDON_ADDR_REG                        0x00
 #define APCI3120_ADDON_DATA_REG                        0x02
 #define APCI3120_ADDON_CTRL_REG                        0x04
-#define APCI3120_ADDON_CTRL_AMWEN_ENA          (1 << 1)
-#define APCI3120_ADDON_CTRL_A2P_FIFO_ENA       (1 << 0)
+#define APCI3120_ADDON_CTRL_AMWEN_ENA          BIT(1)
+#define APCI3120_ADDON_CTRL_A2P_FIFO_ENA       BIT(0)
 
 /*
  * Board revisions
@@ -502,11 +504,6 @@ static irqreturn_t apci3120_interrupt(int irq, void *d)
        if (int_amcc & TARGET_ABORT_INT)
                dev_err(dev->class_dev, "AMCC IRQ - TARGET DMA ABORT!\n");
 
-       if ((status & APCI3120_STATUS_EOC_INT) == 0 &&
-           (devpriv->mode & APCI3120_MODE_EOC_IRQ_ENA)) {
-               /* nothing to do... EOC mode is not currently used */
-       }
-
        if ((status & APCI3120_STATUS_EOS_INT) &&
            (devpriv->mode & APCI3120_MODE_EOS_IRQ_ENA)) {
                unsigned short val;
index bef6efc84efde1c9a83596a7eaa48fc584e09ea8..995096c78844f3a8199145251b05dfdc8695bab9 100644 (file)
@@ -27,9 +27,9 @@
 
 #include "../comedi_pci.h"
 
-#define CONV_UNIT_NS           (1 << 0)
-#define CONV_UNIT_US           (1 << 1)
-#define CONV_UNIT_MS           (1 << 2)
+#define CONV_UNIT_NS           BIT(0)
+#define CONV_UNIT_US           BIT(1)
+#define CONV_UNIT_MS           BIT(2)
 
 static const struct comedi_lrange apci3xxx_ai_range = {
        8, {
index 7ed3fd6fbd3ec24ceb1f321c13b23aaebf8071de..ad7e7c4a5232fb6eeb4aa03dd5ca368c95c53e27 100644 (file)
@@ -41,7 +41,7 @@
  */
 #define PCI6208_AO_CONTROL(x)          (0x00 + (2 * (x)))
 #define PCI6208_AO_STATUS              0x00
-#define PCI6208_AO_STATUS_DATA_SEND    (1 << 0)
+#define PCI6208_AO_STATUS_DATA_SEND    BIT(0)
 #define PCI6208_DIO                    0x40
 #define PCI6208_DIO_DO_MASK            (0x0f)
 #define PCI6208_DIO_DO_SHIFT           (0)
index c9df3afe97f6f60d2309a935771966bcbc75a5f5..01d2ee931b28eedb9a1c4aa073b71720d88cbfae 100644 (file)
@@ -1,68 +1,52 @@
 /*
-
-comedi/drivers/adl_pci9111.c
-
-Hardware driver for PCI9111 ADLink cards:
-
-PCI-9111HR
-
-Copyright (C) 2002-2005 Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-*/
+ * adl_pci9111.c
+ * Hardware driver for PCI9111 ADLink cards: PCI-9111HR
+ * Copyright (C) 2002-2005 Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
 /*
-Driver: adl_pci9111
-Description: Adlink PCI-9111HR
-Author: Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
-Devices: [ADLink] PCI-9111HR (adl_pci9111)
-Status: experimental
-
-Supports:
-
-       - ai_insn read
-       - ao_insn read/write
-       - di_insn read
-       - do_insn read/write
-       - ai_do_cmd mode with the following sources:
-
-       - start_src             TRIG_NOW
-       - scan_begin_src        TRIG_FOLLOW     TRIG_TIMER      TRIG_EXT
-       - convert_src                           TRIG_TIMER      TRIG_EXT
-       - scan_end_src          TRIG_COUNT
-       - stop_src              TRIG_COUNT      TRIG_NONE
-
-The scanned channels must be consecutive and start from 0. They must
-all have the same range and aref.
-
-Configuration options: not applicable, uses PCI auto config
-*/
+ * Driver: adl_pci9111
+ * Description: Adlink PCI-9111HR
+ * Devices: [ADLink] PCI-9111HR (adl_pci9111)
+ * Author: Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
+ * Status: experimental
+ *
+ * Configuration options: not applicable, uses PCI auto config
+ *
+ * Supports:
+ * - ai_insn read
+ * - ao_insn read/write
+ * - di_insn read
+ * - do_insn read/write
+ * - ai_do_cmd mode with the following sources:
+ *     - start_src             TRIG_NOW
+ *     - scan_begin_src        TRIG_FOLLOW     TRIG_TIMER      TRIG_EXT
+ *     - convert_src                           TRIG_TIMER      TRIG_EXT
+ *     - scan_end_src          TRIG_COUNT
+ *     - stop_src              TRIG_COUNT      TRIG_NONE
+ *
+ * The scanned channels must be consecutive and start from 0. They must
+ * all have the same range and aref.
+ */
 
 /*
-CHANGELOG:
-
-2005/02/17 Extend AI streaming capabilities. Now, scan_begin_arg can be
-a multiple of chanlist_len*convert_arg.
-2002/02/19 Fixed the two's complement conversion in pci9111_(hr_)ai_get_data.
-2002/02/18 Added external trigger support for analog input.
-
-TODO:
-
-       - Really test implemented functionality.
-       - Add support for the PCI-9111DG with a probe routine to identify
-         the card type (perhaps with the help of the channel number readback
-         of the A/D Data register).
-       - Add external multiplexer support.
-
-*/
+ * TODO:
+ * - Really test implemented functionality.
+ * - Add support for the PCI-9111DG with a probe routine to identify
+ *   the card type (perhaps with the help of the channel number readback
+ *   of the A/D Data register).
+ * - Add external multiplexer support.
+ */
 
 #include <linux/module.h>
 #include <linux/delay.h>
@@ -89,23 +73,24 @@ TODO:
 #define PCI9111_EDIO_REG               0x04
 #define PCI9111_AI_CHANNEL_REG         0x06
 #define PCI9111_AI_RANGE_STAT_REG      0x08
-#define PCI9111_AI_STAT_AD_BUSY                (1 << 7)
-#define PCI9111_AI_STAT_FF_FF          (1 << 6)
-#define PCI9111_AI_STAT_FF_HF          (1 << 5)
-#define PCI9111_AI_STAT_FF_EF          (1 << 4)
-#define PCI9111_AI_RANGE_MASK          (7 << 0)
+#define PCI9111_AI_STAT_AD_BUSY                BIT(7)
+#define PCI9111_AI_STAT_FF_FF          BIT(6)
+#define PCI9111_AI_STAT_FF_HF          BIT(5)
+#define PCI9111_AI_STAT_FF_EF          BIT(4)
+#define PCI9111_AI_RANGE(x)            (((x) & 0x7) << 0)
+#define PCI9111_AI_RANGE_MASK          PCI9111_AI_RANGE(7)
 #define PCI9111_AI_TRIG_CTRL_REG       0x0a
-#define PCI9111_AI_TRIG_CTRL_TRGEVENT  (1 << 5)
-#define PCI9111_AI_TRIG_CTRL_POTRG     (1 << 4)
-#define PCI9111_AI_TRIG_CTRL_PTRG      (1 << 3)
-#define PCI9111_AI_TRIG_CTRL_ETIS      (1 << 2)
-#define PCI9111_AI_TRIG_CTRL_TPST      (1 << 1)
-#define PCI9111_AI_TRIG_CTRL_ASCAN     (1 << 0)
+#define PCI9111_AI_TRIG_CTRL_TRGEVENT  BIT(5)
+#define PCI9111_AI_TRIG_CTRL_POTRG     BIT(4)
+#define PCI9111_AI_TRIG_CTRL_PTRG      BIT(3)
+#define PCI9111_AI_TRIG_CTRL_ETIS      BIT(2)
+#define PCI9111_AI_TRIG_CTRL_TPST      BIT(1)
+#define PCI9111_AI_TRIG_CTRL_ASCAN     BIT(0)
 #define PCI9111_INT_CTRL_REG           0x0c
-#define PCI9111_INT_CTRL_ISC2          (1 << 3)
-#define PCI9111_INT_CTRL_FFEN          (1 << 2)
-#define PCI9111_INT_CTRL_ISC1          (1 << 1)
-#define PCI9111_INT_CTRL_ISC0          (1 << 0)
+#define PCI9111_INT_CTRL_ISC2          BIT(3)
+#define PCI9111_INT_CTRL_FFEN          BIT(2)
+#define PCI9111_INT_CTRL_ISC1          BIT(1)
+#define PCI9111_INT_CTRL_ISC0          BIT(0)
 #define PCI9111_SOFT_TRIG_REG          0x0e
 #define PCI9111_8254_BASE_REG          0x40
 #define PCI9111_INT_CLR_REG            0x48
@@ -139,21 +124,21 @@ struct pci9111_private_data {
 };
 
 static void plx9050_interrupt_control(unsigned long io_base,
-                                     bool LINTi1_enable,
-                                     bool LINTi1_active_high,
-                                     bool LINTi2_enable,
-                                     bool LINTi2_active_high,
+                                     bool int1_enable,
+                                     bool int1_active_high,
+                                     bool int2_enable,
+                                     bool int2_active_high,
                                      bool interrupt_enable)
 {
        int flags = 0;
 
-       if (LINTi1_enable)
+       if (int1_enable)
                flags |= PLX9052_INTCSR_LI1ENAB;
-       if (LINTi1_active_high)
+       if (int1_active_high)
                flags |= PLX9052_INTCSR_LI1POL;
-       if (LINTi2_enable)
+       if (int2_enable)
                flags |= PLX9052_INTCSR_LI2ENAB;
-       if (LINTi2_active_high)
+       if (int2_active_high)
                flags |= PLX9052_INTCSR_LI2POL;
 
        if (interrupt_enable)
@@ -363,6 +348,7 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
        struct pci9111_private_data *dev_private = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
        unsigned int last_chan = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]);
+       unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
        unsigned int trig = 0;
 
        /*  Set channel scan limit */
@@ -374,11 +360,8 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
 
        outb(last_chan, dev->iobase + PCI9111_AI_CHANNEL_REG);
 
-       /*  Set gain */
-       /*  This is the same gain on every channel */
-
-       outb(CR_RANGE(cmd->chanlist[0]) & PCI9111_AI_RANGE_MASK,
-            dev->iobase + PCI9111_AI_RANGE_STAT_REG);
+       /*  Set gain - all channels use the same range */
+       outb(PCI9111_AI_RANGE(range0), dev->iobase + PCI9111_AI_RANGE_STAT_REG);
 
        /*  Set timer pacer */
        dev_private->scan_delay = 0;
@@ -434,14 +417,14 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
 {
        struct pci9111_private_data *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
+       unsigned short *buf = devpriv->ai_bounce_buffer;
        unsigned int samples;
 
        samples = comedi_nsamples_left(s, PCI9111_FIFO_HALF_SIZE);
-       insw(dev->iobase + PCI9111_AI_FIFO_REG,
-            devpriv->ai_bounce_buffer, samples);
+       insw(dev->iobase + PCI9111_AI_FIFO_REG, buf, samples);
 
        if (devpriv->scan_delay < 1) {
-               comedi_buf_write_samples(s, devpriv->ai_bounce_buffer, samples);
+               comedi_buf_write_samples(s, buf, samples);
        } else {
                unsigned int pos = 0;
                unsigned int to_read;
@@ -454,9 +437,7 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
                                if (to_read > samples - pos)
                                        to_read = samples - pos;
 
-                               comedi_buf_write_samples(s,
-                                               devpriv->ai_bounce_buffer + pos,
-                                               to_read);
+                               comedi_buf_write_samples(s, buf + pos, to_read);
                        } else {
                                to_read = devpriv->chunk_num_samples -
                                          devpriv->chunk_counter;
@@ -571,7 +552,7 @@ static int pci9111_ai_insn_read(struct comedi_device *dev,
 
        status = inb(dev->iobase + PCI9111_AI_RANGE_STAT_REG);
        if ((status & PCI9111_AI_RANGE_MASK) != range) {
-               outb(range & PCI9111_AI_RANGE_MASK,
+               outb(PCI9111_AI_RANGE(range),
                     dev->iobase + PCI9111_AI_RANGE_STAT_REG);
        }
 
index fb3043dcfff1e62b9cc318df55e82c3dceea308c..0dff1dbb53fbff396482e857e8bcbbfcdf6bfdef 100644 (file)
 #include "amcc_s5933.h"
 #include "comedi_8254.h"
 
-#define IORANGE_9118   64      /* I hope */
-#define PCI9118_CHANLEN        255     /*
-                                * len of chanlist, some source say 256,
-                                * but reality looks like 255 :-(
-                                */
-
 /*
  * PCI BAR2 Register map (dev->iobase)
  */
 #define PCI9118_AI_FIFO_REG            0x10
 #define PCI9118_AO_REG(x)              (0x10 + ((x) * 4))
 #define PCI9118_AI_STATUS_REG          0x18
-#define PCI9118_AI_STATUS_NFULL                (1 << 8)  /* 0=FIFO full (fatal) */
-#define PCI9118_AI_STATUS_NHFULL       (1 << 7)  /* 0=FIFO half full */
-#define PCI9118_AI_STATUS_NEPTY                (1 << 6)  /* 0=FIFO empty */
-#define PCI9118_AI_STATUS_ACMP         (1 << 5)  /* 1=about trigger complete */
-#define PCI9118_AI_STATUS_DTH          (1 << 4)  /* 1=ext. digital trigger */
-#define PCI9118_AI_STATUS_BOVER                (1 << 3)  /* 1=burst overrun (fatal) */
-#define PCI9118_AI_STATUS_ADOS         (1 << 2)  /* 1=A/D over speed (warn) */
-#define PCI9118_AI_STATUS_ADOR         (1 << 1)  /* 1=A/D overrun (fatal) */
-#define PCI9118_AI_STATUS_ADRDY                (1 << 0)  /* 1=A/D ready */
+#define PCI9118_AI_STATUS_NFULL                BIT(8)  /* 0=FIFO full (fatal) */
+#define PCI9118_AI_STATUS_NHFULL       BIT(7)  /* 0=FIFO half full */
+#define PCI9118_AI_STATUS_NEPTY                BIT(6)  /* 0=FIFO empty */
+#define PCI9118_AI_STATUS_ACMP         BIT(5)  /* 1=about trigger complete */
+#define PCI9118_AI_STATUS_DTH          BIT(4)  /* 1=ext. digital trigger */
+#define PCI9118_AI_STATUS_BOVER                BIT(3)  /* 1=burst overrun (fatal) */
+#define PCI9118_AI_STATUS_ADOS         BIT(2)  /* 1=A/D over speed (warn) */
+#define PCI9118_AI_STATUS_ADOR         BIT(1)  /* 1=A/D overrun (fatal) */
+#define PCI9118_AI_STATUS_ADRDY                BIT(0)  /* 1=A/D ready */
 #define PCI9118_AI_CTRL_REG            0x18
-#define PCI9118_AI_CTRL_UNIP           (1 << 7)  /* 1=unipolar */
-#define PCI9118_AI_CTRL_DIFF           (1 << 6)  /* 1=differential inputs */
-#define PCI9118_AI_CTRL_SOFTG          (1 << 5)  /* 1=8254 software gate */
-#define PCI9118_AI_CTRL_EXTG           (1 << 4)  /* 1=8254 TGIN(pin 46) gate */
-#define PCI9118_AI_CTRL_EXTM           (1 << 3)  /* 1=ext. trigger (pin 44) */
-#define PCI9118_AI_CTRL_TMRTR          (1 << 2)  /* 1=8254 is trigger source */
-#define PCI9118_AI_CTRL_INT            (1 << 1)  /* 1=enable interrupt */
-#define PCI9118_AI_CTRL_DMA            (1 << 0)  /* 1=enable DMA */
+#define PCI9118_AI_CTRL_UNIP           BIT(7)  /* 1=unipolar */
+#define PCI9118_AI_CTRL_DIFF           BIT(6)  /* 1=differential inputs */
+#define PCI9118_AI_CTRL_SOFTG          BIT(5)  /* 1=8254 software gate */
+#define PCI9118_AI_CTRL_EXTG           BIT(4)  /* 1=8254 TGIN(pin 46) gate */
+#define PCI9118_AI_CTRL_EXTM           BIT(3)  /* 1=ext. trigger (pin 44) */
+#define PCI9118_AI_CTRL_TMRTR          BIT(2)  /* 1=8254 is trigger source */
+#define PCI9118_AI_CTRL_INT            BIT(1)  /* 1=enable interrupt */
+#define PCI9118_AI_CTRL_DMA            BIT(0)  /* 1=enable DMA */
 #define PCI9118_DIO_REG                        0x1c
 #define PCI9118_SOFTTRG_REG            0x20
 #define PCI9118_AI_CHANLIST_REG                0x24
 #define PCI9118_AI_BURST_NUM_REG       0x28
 #define PCI9118_AI_AUTOSCAN_MODE_REG   0x2c
 #define PCI9118_AI_CFG_REG             0x30
-#define PCI9118_AI_CFG_PDTRG           (1 << 7)  /* 1=positive trigger */
-#define PCI9118_AI_CFG_PETRG           (1 << 6)  /* 1=positive ext. trigger */
-#define PCI9118_AI_CFG_BSSH            (1 << 5)  /* 1=with sample & hold */
-#define PCI9118_AI_CFG_BM              (1 << 4)  /* 1=burst mode */
-#define PCI9118_AI_CFG_BS              (1 << 3)  /* 1=burst mode start */
-#define PCI9118_AI_CFG_PM              (1 << 2)  /* 1=post trigger */
-#define PCI9118_AI_CFG_AM              (1 << 1)  /* 1=about trigger */
-#define PCI9118_AI_CFG_START           (1 << 0)  /* 1=trigger start */
+#define PCI9118_AI_CFG_PDTRG           BIT(7)  /* 1=positive trigger */
+#define PCI9118_AI_CFG_PETRG           BIT(6)  /* 1=positive ext. trigger */
+#define PCI9118_AI_CFG_BSSH            BIT(5)  /* 1=with sample & hold */
+#define PCI9118_AI_CFG_BM              BIT(4)  /* 1=burst mode */
+#define PCI9118_AI_CFG_BS              BIT(3)  /* 1=burst mode start */
+#define PCI9118_AI_CFG_PM              BIT(2)  /* 1=post trigger */
+#define PCI9118_AI_CFG_AM              BIT(1)  /* 1=about trigger */
+#define PCI9118_AI_CFG_START           BIT(0)  /* 1=trigger start */
 #define PCI9118_FIFO_RESET_REG         0x34
 #define PCI9118_INT_CTRL_REG           0x38
-#define PCI9118_INT_CTRL_TIMER         (1 << 3)  /* timer interrupt */
-#define PCI9118_INT_CTRL_ABOUT         (1 << 2)  /* about trigger complete */
-#define PCI9118_INT_CTRL_HFULL         (1 << 1)  /* A/D FIFO half full */
-#define PCI9118_INT_CTRL_DTRG          (1 << 0)  /* ext. digital trigger */
+#define PCI9118_INT_CTRL_TIMER         BIT(3)  /* timer interrupt */
+#define PCI9118_INT_CTRL_ABOUT         BIT(2)  /* about trigger complete */
+#define PCI9118_INT_CTRL_HFULL         BIT(1)  /* A/D FIFO half full */
+#define PCI9118_INT_CTRL_DTRG          BIT(0)  /* ext. digital trigger */
 
 #define START_AI_EXT   0x01    /* start measure on external trigger */
 #define STOP_AI_EXT    0x02    /* stop measure on external trigger */
 #define STOP_AI_INT    0x08    /* stop measure on internal trigger */
 
-#define PCI9118_HALF_FIFO_SZ   (1024 / 2)
-
 static const struct comedi_lrange pci9118_ai_range = {
        8, {
                BIP_RANGE(5),
@@ -169,11 +161,6 @@ static const struct comedi_lrange pci9118hg_ai_range = {
        }
 };
 
-#define PCI9118_BIPOLAR_RANGES 4       /*
-                                        * used for test on mixture
-                                        * of BIP/UNI ranges
-                                        */
-
 enum pci9118_boardid {
        BOARD_PCI9118DG,
        BOARD_PCI9118HG,
@@ -296,51 +283,44 @@ static void pci9118_ai_reset_fifo(struct comedi_device *dev)
        outl(0, dev->iobase + PCI9118_FIFO_RESET_REG);
 }
 
-static int check_channel_list(struct comedi_device *dev,
-                             struct comedi_subdevice *s, int n_chan,
-                             unsigned int *chanlist, int frontadd, int backadd)
+static int pci9118_ai_check_chanlist(struct comedi_device *dev,
+                                    struct comedi_subdevice *s,
+                                    struct comedi_cmd *cmd)
 {
        struct pci9118_private *devpriv = dev->private;
-       unsigned int i, differencial = 0, bipolar = 0;
+       unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
+       unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
+       int i;
 
-       /* correct channel and range number check itself comedi/range.c */
-       if (n_chan < 1) {
-               dev_err(dev->class_dev, "range/channel list is empty!\n");
+       /* single channel scans are always ok */
+       if (cmd->chanlist_len == 1)
                return 0;
-       }
-       if ((frontadd + n_chan + backadd) > s->len_chanlist) {
-               dev_err(dev->class_dev,
-                       "range/channel list is too long for actual configuration!\n");
-               return 0;
-       }
 
-       if (CR_AREF(chanlist[0]) == AREF_DIFF)
-               differencial = 1;       /* all input must be diff */
-       if (CR_RANGE(chanlist[0]) < PCI9118_BIPOLAR_RANGES)
-               bipolar = 1;    /* all input must be bipolar */
-       if (n_chan > 1)
-               for (i = 1; i < n_chan; i++) {  /* check S.E/diff */
-                       if ((CR_AREF(chanlist[i]) == AREF_DIFF) !=
-                           (differencial)) {
-                               dev_err(dev->class_dev,
-                                       "Differential and single ended inputs can't be mixed!\n");
-                               return 0;
-                       }
-                       if ((CR_RANGE(chanlist[i]) < PCI9118_BIPOLAR_RANGES) !=
-                           (bipolar)) {
-                               dev_err(dev->class_dev,
-                                       "Bipolar and unipolar ranges can't be mixed!\n");
-                               return 0;
-                       }
-                       if (!devpriv->usemux && differencial &&
-                           (CR_CHAN(chanlist[i]) >= (s->n_chan / 2))) {
-                               dev_err(dev->class_dev,
-                                       "AREF_DIFF is only available for the first 8 channels!\n");
-                               return 0;
-                       }
+       for (i = 1; i < cmd->chanlist_len; i++) {
+               unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+               unsigned int range = CR_RANGE(cmd->chanlist[i]);
+               unsigned int aref = CR_AREF(cmd->chanlist[i]);
+
+               if (aref != aref0) {
+                       dev_err(dev->class_dev,
+                               "Differential and single ended inputs can't be mixed!\n");
+                       return -EINVAL;
+               }
+               if (comedi_range_is_bipolar(s, range) !=
+                   comedi_range_is_bipolar(s, range0)) {
+                       dev_err(dev->class_dev,
+                               "Bipolar and unipolar ranges can't be mixed!\n");
+                       return -EINVAL;
                }
+               if (!devpriv->usemux && aref == AREF_DIFF &&
+                   (chan >= (s->n_chan / 2))) {
+                       dev_err(dev->class_dev,
+                               "AREF_DIFF is only available for the first 8 channels!\n");
+                       return -EINVAL;
+               }
+       }
 
-       return 1;
+       return 0;
 }
 
 static void pci9118_set_chanlist(struct comedi_device *dev,
@@ -406,8 +386,8 @@ static void pci9118_set_chanlist(struct comedi_device *dev,
        /* udelay(100); important delay, or first sample will be crippled */
 }
 
-static void interrupt_pci9118_ai_mode4_switch(struct comedi_device *dev,
-                                             unsigned int next_buf)
+static void pci9118_ai_mode4_switch(struct comedi_device *dev,
+                                   unsigned int next_buf)
 {
        struct pci9118_private *devpriv = dev->private;
        struct pci9118_dmabuf *dmabuf = &devpriv->dmabuf[next_buf];
@@ -421,9 +401,9 @@ static void interrupt_pci9118_ai_mode4_switch(struct comedi_device *dev,
        outl(devpriv->ai_cfg, dev->iobase + PCI9118_AI_CFG_REG);
 }
 
-static unsigned int valid_samples_in_act_dma_buf(struct comedi_device *dev,
-                                                struct comedi_subdevice *s,
-                                                unsigned int n_raw_samples)
+static unsigned int pci9118_ai_samples_ready(struct comedi_device *dev,
+                                            struct comedi_subdevice *s,
+                                            unsigned int n_raw_samples)
 {
        struct pci9118_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
@@ -477,7 +457,7 @@ static unsigned int valid_samples_in_act_dma_buf(struct comedi_device *dev,
        return n_samples;
 }
 
-static void move_block_from_dma(struct comedi_device *dev,
+static void pci9118_ai_dma_xfer(struct comedi_device *dev,
                                struct comedi_subdevice *s,
                                unsigned short *dma_buffer,
                                unsigned int n_raw_samples)
@@ -634,8 +614,8 @@ static void pci9118_ai_munge(struct comedi_device *dev,
        }
 }
 
-static void interrupt_pci9118_ai_onesample(struct comedi_device *dev,
-                                          struct comedi_subdevice *s)
+static void pci9118_ai_get_onesample(struct comedi_device *dev,
+                                    struct comedi_subdevice *s)
 {
        struct pci9118_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
@@ -651,8 +631,8 @@ static void interrupt_pci9118_ai_onesample(struct comedi_device *dev,
        }
 }
 
-static void interrupt_pci9118_ai_dma(struct comedi_device *dev,
-                                    struct comedi_subdevice *s)
+static void pci9118_ai_get_dma(struct comedi_device *dev,
+                              struct comedi_subdevice *s)
 {
        struct pci9118_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
@@ -662,21 +642,19 @@ static void interrupt_pci9118_ai_dma(struct comedi_device *dev,
        bool more_dma;
 
        /* determine whether more DMA buffers to do after this one */
-       n_valid = valid_samples_in_act_dma_buf(dev, s, n_all);
+       n_valid = pci9118_ai_samples_ready(dev, s, n_all);
        more_dma = n_valid < comedi_nsamples_left(s, n_valid + 1);
 
        /* switch DMA buffers and restart DMA if double buffering */
        if (more_dma && devpriv->dma_doublebuf) {
                devpriv->dma_actbuf = 1 - devpriv->dma_actbuf;
                pci9118_amcc_setup_dma(dev, devpriv->dma_actbuf);
-               if (devpriv->ai_do == 4) {
-                       interrupt_pci9118_ai_mode4_switch(dev,
-                                                         devpriv->dma_actbuf);
-               }
+               if (devpriv->ai_do == 4)
+                       pci9118_ai_mode4_switch(dev, devpriv->dma_actbuf);
        }
 
        if (n_all)
-               move_block_from_dma(dev, s, dmabuf->virt, n_all);
+               pci9118_ai_dma_xfer(dev, s, dmabuf->virt, n_all);
 
        if (!devpriv->ai_neverending) {
                if (s->async->scans_done >= cmd->stop_arg)
@@ -690,7 +668,7 @@ static void interrupt_pci9118_ai_dma(struct comedi_device *dev,
        if (more_dma && !devpriv->dma_doublebuf) {
                pci9118_amcc_setup_dma(dev, 0);
                if (devpriv->ai_do == 4)
-                       interrupt_pci9118_ai_mode4_switch(dev, 0);
+                       pci9118_ai_mode4_switch(dev, 0);
        }
 }
 
@@ -779,9 +757,9 @@ static irqreturn_t pci9118_interrupt(int irq, void *d)
        }
 
        if (devpriv->usedma)
-               interrupt_pci9118_ai_dma(dev, s);
+               pci9118_ai_get_dma(dev, s);
        else
-               interrupt_pci9118_ai_onesample(dev, s);
+               pci9118_ai_get_onesample(dev, s);
 
 interrupt_exit:
        comedi_handle_events(dev, s);
@@ -816,17 +794,18 @@ static int pci9118_ai_inttrig(struct comedi_device *dev,
        return 1;
 }
 
-static int Compute_and_setup_dma(struct comedi_device *dev,
-                                struct comedi_subdevice *s)
+static int pci9118_ai_setup_dma(struct comedi_device *dev,
+                               struct comedi_subdevice *s)
 {
        struct pci9118_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
        struct pci9118_dmabuf *dmabuf0 = &devpriv->dmabuf[0];
        struct pci9118_dmabuf *dmabuf1 = &devpriv->dmabuf[1];
-       unsigned int dmalen0, dmalen1, i;
+       unsigned int dmalen0 = dmabuf0->size;
+       unsigned int dmalen1 = dmabuf1->size;
+       unsigned int scan_bytes = devpriv->ai_n_realscanlen *
+                                 comedi_bytes_per_sample(s);
 
-       dmalen0 = dmabuf0->size;
-       dmalen1 = dmabuf1->size;
        /* isn't output buff smaller that our DMA buff? */
        if (dmalen0 > s->async->prealloc_bufsz) {
                /* align to 32bit down */
@@ -839,15 +818,15 @@ static int Compute_and_setup_dma(struct comedi_device *dev,
 
        /* we want wake up every scan? */
        if (devpriv->ai_flags & CMDF_WAKE_EOS) {
-               if (dmalen0 < (devpriv->ai_n_realscanlen << 1)) {
+               if (dmalen0 < scan_bytes) {
                        /* uff, too short DMA buffer, disable EOS support! */
                        devpriv->ai_flags &= (~CMDF_WAKE_EOS);
                        dev_info(dev->class_dev,
                                 "WAR: DMA0 buf too short, can't support CMDF_WAKE_EOS (%d<%d)\n",
-                                 dmalen0, devpriv->ai_n_realscanlen << 1);
+                                 dmalen0, scan_bytes);
                } else {
                        /* short first DMA buffer to one scan */
-                       dmalen0 = devpriv->ai_n_realscanlen << 1;
+                       dmalen0 = scan_bytes;
                        if (dmalen0 < 4) {
                                dev_info(dev->class_dev,
                                         "ERR: DMA0 buf len bug? (%d<4)\n",
@@ -857,15 +836,15 @@ static int Compute_and_setup_dma(struct comedi_device *dev,
                }
        }
        if (devpriv->ai_flags & CMDF_WAKE_EOS) {
-               if (dmalen1 < (devpriv->ai_n_realscanlen << 1)) {
+               if (dmalen1 < scan_bytes) {
                        /* uff, too short DMA buffer, disable EOS support! */
                        devpriv->ai_flags &= (~CMDF_WAKE_EOS);
                        dev_info(dev->class_dev,
                                 "WAR: DMA1 buf too short, can't support CMDF_WAKE_EOS (%d<%d)\n",
-                                dmalen1, devpriv->ai_n_realscanlen << 1);
+                                dmalen1, scan_bytes);
                } else {
                        /* short second DMA buffer to one scan */
-                       dmalen1 = devpriv->ai_n_realscanlen << 1;
+                       dmalen1 = scan_bytes;
                        if (dmalen1 < 4) {
                                dev_info(dev->class_dev,
                                         "ERR: DMA1 buf len bug? (%d<4)\n",
@@ -877,45 +856,39 @@ static int Compute_and_setup_dma(struct comedi_device *dev,
 
        /* transfer without CMDF_WAKE_EOS */
        if (!(devpriv->ai_flags & CMDF_WAKE_EOS)) {
+               unsigned int tmp;
+
                /* if it's possible then align DMA buffers to length of scan */
-               i = dmalen0;
-               dmalen0 =
-                   (dmalen0 / (devpriv->ai_n_realscanlen << 1)) *
-                   (devpriv->ai_n_realscanlen << 1);
+               tmp = dmalen0;
+               dmalen0 = (dmalen0 / scan_bytes) * scan_bytes;
                dmalen0 &= ~3L;
                if (!dmalen0)
-                       dmalen0 = i;    /* uff. very long scan? */
-               i = dmalen1;
-               dmalen1 =
-                   (dmalen1 / (devpriv->ai_n_realscanlen << 1)) *
-                   (devpriv->ai_n_realscanlen << 1);
+                       dmalen0 = tmp;  /* uff. very long scan? */
+               tmp = dmalen1;
+               dmalen1 = (dmalen1 / scan_bytes) * scan_bytes;
                dmalen1 &= ~3L;
                if (!dmalen1)
-                       dmalen1 = i;    /* uff. very long scan? */
+                       dmalen1 = tmp;  /* uff. very long scan? */
                /*
                 * if measure isn't neverending then test, if it fits whole
                 * into one or two DMA buffers
                 */
                if (!devpriv->ai_neverending) {
+                       unsigned long long scanlen;
+
+                       scanlen = (unsigned long long)scan_bytes *
+                                 cmd->stop_arg;
+
                        /* fits whole measure into one DMA buffer? */
-                       if (dmalen0 >
-                           ((devpriv->ai_n_realscanlen << 1) *
-                            cmd->stop_arg)) {
-                               dmalen0 =
-                                   (devpriv->ai_n_realscanlen << 1) *
-                                   cmd->stop_arg;
+                       if (dmalen0 > scanlen) {
+                               dmalen0 = scanlen;
                                dmalen0 &= ~3L;
-                       } else {        /*
-                                        * fits whole measure into
-                                        * two DMA buffer?
-                                        */
-                               if (dmalen1 >
-                                   ((devpriv->ai_n_realscanlen << 1) *
-                                    cmd->stop_arg - dmalen0))
-                                       dmalen1 =
-                                           (devpriv->ai_n_realscanlen << 1) *
-                                           cmd->stop_arg - dmalen0;
-                               dmalen1 &= ~3L;
+                       } else {
+                               /* fits whole measure into two DMA buffer? */
+                               if (dmalen1 > (scanlen - dmalen0)) {
+                                       dmalen1 = scanlen - dmalen0;
+                                       dmalen1 &= ~3L;
+                               }
                        }
                }
        }
@@ -945,6 +918,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        struct comedi_8254 *pacer = dev->pacer;
        struct comedi_cmd *cmd = &s->async->cmd;
        unsigned int addchans = 0;
+       unsigned int scanlen;
 
        devpriv->ai12_startstop = 0;
        devpriv->ai_flags = cmd->flags;
@@ -1030,19 +1004,20 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                }
        }
        /* well, we now know what must be all added */
-       devpriv->ai_n_realscanlen =     /*
-                                        * what we must take from card in real
-                                        * to have cmd->scan_end_arg on output?
-                                        */
-           (devpriv->ai_add_front + cmd->chanlist_len +
-            devpriv->ai_add_back) * (cmd->scan_end_arg /
-                                     cmd->chanlist_len);
-
-       /* check and setup channel list */
-       if (!check_channel_list(dev, s, cmd->chanlist_len,
-                               cmd->chanlist, devpriv->ai_add_front,
-                               devpriv->ai_add_back))
+       scanlen = devpriv->ai_add_front + cmd->chanlist_len +
+                 devpriv->ai_add_back;
+       /*
+        * what we must take from card in real to have cmd->scan_end_arg
+        * on output?
+        */
+       devpriv->ai_n_realscanlen = scanlen *
+                                   (cmd->scan_end_arg / cmd->chanlist_len);
+
+       if (scanlen > s->len_chanlist) {
+               dev_err(dev->class_dev,
+                       "range/channel list is too long for actual configuration!\n");
                return -EINVAL;
+       }
 
        /*
         * Configure analog input and load the chanlist.
@@ -1141,7 +1116,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        devpriv->ai_act_dmapos = 0;
 
        if (devpriv->usedma) {
-               Compute_and_setup_dma(dev, s);
+               pci9118_ai_setup_dma(dev, s);
 
                outl(0x02000000 | AINT_WRITE_COMPL,
                     devpriv->iobase_a + AMCC_OP_REG_INTCSR);
@@ -1205,9 +1180,6 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
        if (cmd->start_src == TRIG_EXT && cmd->scan_begin_src == TRIG_EXT)
                err |= -EINVAL;
 
-       if (cmd->start_src == TRIG_INT && cmd->scan_begin_src == TRIG_INT)
-               err |= -EINVAL;
-
        if ((cmd->scan_begin_src & (TRIG_TIMER | TRIG_EXT)) &&
            (!(cmd->convert_src & (TRIG_TIMER | TRIG_NOW))))
                err |= -EINVAL;
@@ -1315,10 +1287,13 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
        if (err)
                return 4;
 
+       /* Step 5: check channel list if it exists */
+
        if (cmd->chanlist)
-               if (!check_channel_list(dev, s, cmd->chanlist_len,
-                                       cmd->chanlist, 0, 0))
-                       return 5;       /* incorrect channels list */
+               err |= pci9118_ai_check_chanlist(dev, s, cmd);
+
+       if (err)
+               return 5;
 
        return 0;
 }
@@ -1608,7 +1583,7 @@ static int pci9118_common_attach(struct comedi_device *dev,
        if (dev->irq) {
                dev->read_subdev = s;
                s->subdev_flags |= SDF_CMD_READ;
-               s->len_chanlist = PCI9118_CHANLEN;
+               s->len_chanlist = 255;
                s->do_cmdtest   = pci9118_ai_cmdtest;
                s->do_cmd       = pci9118_ai_cmd;
                s->cancel       = pci9118_ai_cancel;
index bc5f97f50f9a478b6af4aed56137c64252b310a3..315050454c26cb7a1337a2e94ab709c8c367780d 100644 (file)
@@ -1,75 +1,59 @@
 /*
-    comedi/drivers/adq12b.c
-    driver for MicroAxial ADQ12-B data acquisition and control card
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
-/*
-Driver: adq12b
-Description: driver for MicroAxial ADQ12-B data acquisition and control card
-Devices: [MicroAxial] ADQ12-B (adq12b)
-Author: jeremy theler <thelerg@ib.cnea.gov.ar>
-Updated: Thu, 21 Feb 2008 02:56:27 -0300
-Status: works
-
-Driver for the acquisition card ADQ12-B (without any add-on).
-
- - Analog input is subdevice 0 (16 channels single-ended or 8 differential)
- - Digital input is subdevice 1 (5 channels)
- - Digital output is subdevice 1 (8 channels)
- - The PACER is not supported in this version
-
-If you do not specify any options, they will default to
-
-  # comedi_config /dev/comedi0 adq12b 0x300,0,0
-
-  option 1: I/O base address. The following table is provided as a help
-   of the hardware jumpers.
-
-        address            jumper JADR
-         0x300                 1 (factory default)
-         0x320                 2
-         0x340                 3
-         0x360                 4
-         0x380                 5
-         0x3A0                 6
-
-  option 2: unipolar/bipolar ADC selection: 0 -> bipolar, 1 -> unipolar
+ * adq12b.c
+ * Driver for MicroAxial ADQ12-B data acquisition and control card
+ * written by jeremy theler <thelerg@ib.cnea.gov.ar>
+ *     instituto balseiro
+ *     commission nacional de energia atomica
+ *     universidad nacional de cuyo
+ *     argentina
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
-       selection         comedi_config option            JUB
-        bipolar                0                         2-3 (factory default)
-        unipolar               1                         1-2
-
-  option 3: single-ended/differential AI selection: 0 -> SE, 1 -> differential
-
-       selection         comedi_config option     JCHA    JCHB
-       single-ended             0                  1-2     1-2 (factory default)
-       differential             1                  2-3     2-3
-
-   written by jeremy theler <thelerg@ib.cnea.gov.ar>
-
-   instituto balseiro
-   commission nacional de energia atomica
-   universidad nacional de cuyo
-   argentina
-
-   21-feb-2008
-     + changed supported devices string (missused the [] and ())
-
-   13-oct-2007
-     + first try
-*/
+/*
+ * Driver: adq12b
+ * Description: Driver for MicroAxial ADQ12-B data acquisition and control card
+ * Devices: [MicroAxial] ADQ12-B (adq12b)
+ * Author: jeremy theler <thelerg@ib.cnea.gov.ar>
+ * Updated: Thu, 21 Feb 2008 02:56:27 -0300
+ * Status: works
+ *
+ * Configuration options:
+ *   [0] - I/O base address (set with hardware jumpers)
+ *             address         jumper JADR
+ *             0x300           1 (factory default)
+ *             0x320           2
+ *             0x340           3
+ *             0x360           4
+ *             0x380           5
+ *             0x3A0           6
+ *   [1] - Analog Input unipolar/bipolar selection
+ *             selection       option  JUB
+ *             bipolar         0       2-3 (factory default)
+ *             unipolar        1       1-2
+ *   [2] - Analog Input single-ended/differential selection
+ *             selection       option  JCHA    JCHB
+ *             single-ended    0       1-2     1-2 (factory default)
+ *             differential    1       2-3     2-3
+ *
+ * Driver for the acquisition card ADQ12-B (without any add-on).
+ *
+ * - Analog input is subdevice 0 (16 channels single-ended or 8 differential)
+ * - Digital input is subdevice 1 (5 channels)
+ * - Digital output is subdevice 1 (8 channels)
+ * - The PACER is not supported in this version
+ */
 
 #include <linux/module.h>
 #include <linux/delay.h>
@@ -78,14 +62,14 @@ If you do not specify any options, they will default to
 
 /* address scheme (page 2.17 of the manual) */
 #define ADQ12B_CTREG           0x00
-#define ADQ12B_CTREG_MSKP      (1 << 7)        /* enable pacer interrupt */
-#define ADQ12B_CTREG_GTP       (1 << 6)        /* enable pacer */
+#define ADQ12B_CTREG_MSKP      BIT(7)  /* enable pacer interrupt */
+#define ADQ12B_CTREG_GTP       BIT(6)  /* enable pacer */
 #define ADQ12B_CTREG_RANGE(x)  ((x) << 4)
 #define ADQ12B_CTREG_CHAN(x)   ((x) << 0)
 #define ADQ12B_STINR           0x00
-#define ADQ12B_STINR_OUT2      (1 << 7)        /* timer 2 output state */
-#define ADQ12B_STINR_OUTP      (1 << 6)        /* pacer output state */
-#define ADQ12B_STINR_EOC       (1 << 5)        /* A/D end-of-conversion */
+#define ADQ12B_STINR_OUT2      BIT(7)  /* timer 2 output state */
+#define ADQ12B_STINR_OUTP      BIT(6)  /* pacer output state */
+#define ADQ12B_STINR_EOC       BIT(5)  /* A/D end-of-conversion */
 #define ADQ12B_STINR_IN_MASK   (0x1f << 0)
 #define ADQ12B_OUTBR           0x04
 #define ADQ12B_ADLOW           0x08
@@ -145,7 +129,7 @@ static int adq12b_ai_insn_read(struct comedi_device *dev,
        if (val != devpriv->last_ctreg) {
                outb(val, dev->iobase + ADQ12B_CTREG);
                devpriv->last_ctreg = val;
-               udelay(50);     /* wait for the mux to settle */
+               usleep_range(50, 100);  /* wait for the mux to settle */
        }
 
        val = inb(dev->iobase + ADQ12B_ADLOW);  /* trigger A/D */
index 0c6aa964c884f274de3cd0e194ffe0f90edc630f..399c511cfe0aba3b1e2714610512af05a6e049a8 100644 (file)
@@ -1,45 +1,30 @@
 /*
- * comedi/drivers/adv_pci1710.c
- *
+ * adv_pci1710.c
+ * Comedi driver for Advantech PCI-1710 series boards
  * Author: Michal Dobes <dobes@tesnet.cz>
  *
  * Thanks to ZhenGang Shang <ZhenGang.Shang@Advantech.com.cn>
  * for testing and information.
+ */
+
+/*
+ * Driver: adv_pci1710
+ * Description: Comedi driver for Advantech PCI-1710 series boards
+ * Devices: [Advantech] PCI-1710 (adv_pci1710), PCI-1710HG, PCI-1711,
+ *   PCI-1713, PCI-1720, PCI-1731
+ * Author: Michal Dobes <dobes@tesnet.cz>
+ * Status: works
  *
- *  hardware driver for Advantech cards:
- *   card:   PCI-1710, PCI-1710HG, PCI-1711, PCI-1713, PCI-1720, PCI-1731
- *   driver: pci1710,  pci1710hg,  pci1711,  pci1713,  pci1720,  pci1731
+ * Configuration options: not applicable, uses PCI auto config
  *
- * Options:
- *  [0] - PCI bus number - if bus number and slot number are 0,
- *                         then driver search for first unused card
- *  [1] - PCI slot number
+ * This driver supports AI, AO, DI and DO subdevices.
+ * AI subdevice supports cmd and insn interface,
+ * other subdevices support only insn interface.
  *
-*/
-/*
-Driver: adv_pci1710
-Description: Advantech PCI-1710, PCI-1710HG, PCI-1711, PCI-1713,
-            Advantech PCI-1720, PCI-1731
-Author: Michal Dobes <dobes@tesnet.cz>
-Devices: [Advantech] PCI-1710 (adv_pci1710), PCI-1710HG (pci1710hg),
-  PCI-1711 (adv_pci1710), PCI-1713, PCI-1720,
-  PCI-1731
-Status: works
-
-This driver supports AI, AO, DI and DO subdevices.
-AI subdevice supports cmd and insn interface,
-other subdevices support only insn interface.
-
-The PCI-1710 and PCI-1710HG have the same PCI device ID, so the
-driver cannot distinguish between them, as would be normal for a
-PCI driver.
-
-Configuration options:
-  [0] - PCI bus of device (optional)
-  [1] - PCI slot of device (optional)
-       If bus/slot is not specified, the first available PCI
-       device will be used.
-*/
+ * The PCI-1710 and PCI-1710HG have the same PCI device ID, so the
+ * driver cannot distinguish between them, as would be normal for a
+ * PCI driver.
+ */
 
 #include <linux/module.h>
 #include <linux/interrupt.h>
@@ -49,48 +34,43 @@ Configuration options:
 #include "comedi_8254.h"
 #include "amcc_s5933.h"
 
-#define PCI171x_AD_DATA         0      /* R:   A/D data */
-#define PCI171x_SOFTTRG         0      /* W:   soft trigger for A/D */
-#define PCI171x_RANGE   2      /* W:   A/D gain/range register */
-#define PCI171x_MUX     4      /* W:   A/D multiplexor control */
-#define PCI171x_STATUS  6      /* R:   status register */
-#define PCI171x_CONTROL         6      /* W:   control register */
-#define PCI171x_CLRINT  8      /* W:   clear interrupts request */
-#define PCI171x_CLRFIFO         9      /* W:   clear FIFO */
-#define PCI171x_DA1    10      /* W:   D/A register */
-#define PCI171x_DA2    12      /* W:   D/A register */
-#define PCI171x_DAREF  14      /* W:   D/A reference control */
-#define PCI171x_DI     16      /* R:   digi inputs */
-#define PCI171x_DO     16      /* R:   digi inputs */
-
-#define PCI171X_TIMER_BASE     0x18
-
-/* upper bits from status register (PCI171x_STATUS) (lower is same with control
- * reg) */
-#define        Status_FE       0x0100  /* 1=FIFO is empty */
-#define Status_FH      0x0200  /* 1=FIFO is half full */
-#define Status_FF      0x0400  /* 1=FIFO is full, fatal error */
-#define Status_IRQ     0x0800  /* 1=IRQ occurred */
-/* bits from control register (PCI171x_CONTROL) */
-#define Control_CNT0   0x0040  /* 1=CNT0 have external source,
-                                * 0=have internal 100kHz source */
-#define Control_ONEFH  0x0020  /* 1=IRQ on FIFO is half full, 0=every sample */
-#define Control_IRQEN  0x0010  /* 1=enable IRQ */
-#define Control_GATE   0x0008  /* 1=enable external trigger GATE (8254?) */
-#define Control_EXT    0x0004  /* 1=external trigger source */
-#define Control_PACER  0x0002  /* 1=enable internal 8254 trigger source */
-#define Control_SW     0x0001  /* 1=enable software trigger source */
-
-#define PCI1720_DA0     0      /* W:   D/A register 0 */
-#define PCI1720_DA1     2      /* W:   D/A register 1 */
-#define PCI1720_DA2     4      /* W:   D/A register 2 */
-#define PCI1720_DA3     6      /* W:   D/A register 3 */
-#define PCI1720_RANGE   8      /* R/W: D/A range register */
-#define PCI1720_SYNCOUT         9      /* W:   D/A synchronized output register */
-#define PCI1720_SYNCONT        15      /* R/W: D/A synchronized control */
-
-/* D/A synchronized control (PCI1720_SYNCONT) */
-#define Syncont_SC0     1      /* set synchronous output mode */
+/*
+ * PCI BAR2 Register map (dev->iobase)
+ */
+#define PCI171X_AD_DATA_REG    0x00    /* R:   A/D data */
+#define PCI171X_SOFTTRG_REG    0x00    /* W:   soft trigger for A/D */
+#define PCI171X_RANGE_REG      0x02    /* W:   A/D gain/range register */
+#define PCI171X_MUX_REG                0x04    /* W:   A/D multiplexor control */
+#define PCI171X_STATUS_REG     0x06    /* R:   status register */
+#define PCI171X_STATUS_IRQ     BIT(11) /* 1=IRQ occurred */
+#define PCI171X_STATUS_FF      BIT(10) /* 1=FIFO is full, fatal error */
+#define PCI171X_STATUS_FH      BIT(9)  /* 1=FIFO is half full */
+#define PCI171X_STATUS_FE      BIT(8)  /* 1=FIFO is empty */
+#define PCI171X_CTRL_REG       0x06    /* W:   control register */
+#define PCI171X_CTRL_CNT0      BIT(6)  /* 1=ext. clk, 0=int. 100kHz clk */
+#define PCI171X_CTRL_ONEFH     BIT(5)  /* 1=on FIFO half full, 0=on sample */
+#define PCI171X_CTRL_IRQEN     BIT(4)  /* 1=enable IRQ */
+#define PCI171X_CTRL_GATE      BIT(3)  /* 1=enable ext. trigger GATE (8254?) */
+#define PCI171X_CTRL_EXT       BIT(2)  /* 1=enable ext. trigger source */
+#define PCI171X_CTRL_PACER     BIT(1)  /* 1=enable int. 8254 trigger source */
+#define PCI171X_CTRL_SW                BIT(0)  /* 1=enable software trigger source */
+#define PCI171X_CLRINT_REG     0x08    /* W:   clear interrupts request */
+#define PCI171X_CLRFIFO_REG    0x09    /* W:   clear FIFO */
+#define PCI171X_DA_REG(x)      (0x0a + ((x) * 2)) /* W:   D/A register */
+#define PCI171X_DAREF_REG      0x0e    /* W:   D/A reference control */
+#define PCI171X_DI_REG         0x10    /* R:   digital inputs */
+#define PCI171X_DO_REG         0x10    /* W:   digital outputs */
+#define PCI171X_TIMER_BASE     0x18    /* R/W: 8254 timer */
+
+/*
+ * PCI-1720 only has analog outputs and has a different
+ * register map (dev->iobase)
+ */
+#define PCI1720_DA_REG(x)      (0x00 + ((x) * 2)) /* W:   D/A registers */
+#define PCI1720_RANGE_REG      0x08    /* R/W: D/A range register */
+#define PCI1720_SYNC_REG       0x09    /* W:   D/A synchronized output */
+#define PCI1720_SYNC_CTRL_REG  0x0f    /* R/W: D/A synchronized control */
+#define PCI1720_SYNC_CTRL_SC0  BIT(0)  /* set synchronous output mode */
 
 static const struct comedi_lrange range_pci1710_3 = {
        9, {
@@ -244,10 +224,10 @@ static const struct boardtype boardtypes[] = {
 
 struct pci1710_private {
        unsigned int max_samples;
-       unsigned int CntrlReg;  /*  Control register */
+       unsigned int ctrl;      /* control register value */
+       unsigned int ctrl_ext;  /* used to switch from TRIG_EXT to TRIG_xxx */
+       unsigned int mux_ext;   /* used to set the channel interval to scan */
        unsigned char ai_et;
-       unsigned int ai_et_CntrlReg;
-       unsigned int ai_et_MuxVal;
        unsigned int act_chanlist[32];  /*  list of scanned channel */
        unsigned char saved_seglen;     /* len of the non-repeating chanlist */
        unsigned char da_ranges;        /*  copy of D/A outpit range register */
@@ -342,8 +322,8 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev,
                        rangeval |= 0x0020;
 
                /* select channel and set range */
-               outw(chan | (chan << 8), dev->iobase + PCI171x_MUX);
-               outw(rangeval, dev->iobase + PCI171x_RANGE);
+               outw(chan | (chan << 8), dev->iobase + PCI171X_MUX_REG);
+               outw(rangeval, dev->iobase + PCI171X_RANGE_REG);
 
                devpriv->act_chanlist[i] = chan;
        }
@@ -351,8 +331,8 @@ static void pci171x_ai_setup_chanlist(struct comedi_device *dev,
                devpriv->act_chanlist[i] = CR_CHAN(chanlist[i]);
 
        /* select channel interval to scan */
-       devpriv->ai_et_MuxVal = first_chan | (last_chan << 8);
-       outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX);
+       devpriv->mux_ext = first_chan | (last_chan << 8);
+       outw(devpriv->mux_ext, dev->iobase + PCI171X_MUX_REG);
 }
 
 static int pci171x_ai_eoc(struct comedi_device *dev,
@@ -362,8 +342,8 @@ static int pci171x_ai_eoc(struct comedi_device *dev,
 {
        unsigned int status;
 
-       status = inw(dev->iobase + PCI171x_STATUS);
-       if ((status & Status_FE) == 0)
+       status = inw(dev->iobase + PCI171X_STATUS_REG);
+       if ((status & PCI171X_STATUS_FE) == 0)
                return 0;
        return -EBUSY;
 }
@@ -378,7 +358,7 @@ static int pci171x_ai_read_sample(struct comedi_device *dev,
        unsigned int sample;
        unsigned int chan;
 
-       sample = inw(dev->iobase + PCI171x_AD_DATA);
+       sample = inw(dev->iobase + PCI171X_AD_DATA_REG);
        if (!board->is_pci1713) {
                /*
                 * The upper 4 bits of the 16-bit sample are the channel number
@@ -406,18 +386,19 @@ static int pci171x_ai_insn_read(struct comedi_device *dev,
        int ret = 0;
        int i;
 
-       devpriv->CntrlReg &= Control_CNT0;
-       devpriv->CntrlReg |= Control_SW;        /*  set software trigger */
-       outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
-       outb(0, dev->iobase + PCI171x_CLRFIFO);
-       outb(0, dev->iobase + PCI171x_CLRINT);
+       devpriv->ctrl &= PCI171X_CTRL_CNT0;
+       devpriv->ctrl |= PCI171X_CTRL_SW;       /*  set software trigger */
+       outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG);
+       outb(0, dev->iobase + PCI171X_CLRFIFO_REG);
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 
        pci171x_ai_setup_chanlist(dev, s, &insn->chanspec, 1, 1);
 
        for (i = 0; i < insn->n; i++) {
                unsigned int val;
 
-               outw(0, dev->iobase + PCI171x_SOFTTRG); /* start conversion */
+               /* start conversion */
+               outw(0, dev->iobase + PCI171X_SOFTTRG_REG);
 
                ret = comedi_timeout(dev, s, insn, pci171x_ai_eoc, 0);
                if (ret)
@@ -430,8 +411,8 @@ static int pci171x_ai_insn_read(struct comedi_device *dev,
                data[i] = val;
        }
 
-       outb(0, dev->iobase + PCI171x_CLRFIFO);
-       outb(0, dev->iobase + PCI171x_CLRINT);
+       outb(0, dev->iobase + PCI171X_CLRFIFO_REG);
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 
        return ret ? ret : insn->n;
 }
@@ -444,17 +425,16 @@ static int pci171x_ao_insn_write(struct comedi_device *dev,
        struct pci1710_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
-       unsigned int reg = chan ? PCI171x_DA2 : PCI171x_DA1;
        unsigned int val = s->readback[chan];
        int i;
 
        devpriv->da_ranges &= ~(1 << (chan << 1));
        devpriv->da_ranges |= (range << (chan << 1));
-       outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF);
+       outw(devpriv->da_ranges, dev->iobase + PCI171X_DAREF_REG);
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               outw(val, dev->iobase + reg);
+               outw(val, dev->iobase + PCI171X_DA_REG(chan));
        }
 
        s->readback[chan] = val;
@@ -467,7 +447,7 @@ static int pci171x_di_insn_bits(struct comedi_device *dev,
                                struct comedi_insn *insn,
                                unsigned int *data)
 {
-       data[1] = inw(dev->iobase + PCI171x_DI);
+       data[1] = inw(dev->iobase + PCI171X_DI_REG);
 
        return insn->n;
 }
@@ -478,7 +458,7 @@ static int pci171x_do_insn_bits(struct comedi_device *dev,
                                unsigned int *data)
 {
        if (comedi_dio_update_state(s, data))
-               outw(s->state, dev->iobase + PCI171x_DO);
+               outw(s->state, dev->iobase + PCI171X_DO_REG);
 
        data[1] = s->state;
 
@@ -499,15 +479,15 @@ static int pci1720_ao_insn_write(struct comedi_device *dev,
        val = devpriv->da_ranges & (~(0x03 << (chan << 1)));
        val |= (range << (chan << 1));
        if (val != devpriv->da_ranges) {
-               outb(val, dev->iobase + PCI1720_RANGE);
+               outb(val, dev->iobase + PCI1720_RANGE_REG);
                devpriv->da_ranges = val;
        }
 
        val = s->readback[chan];
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               outw(val, dev->iobase + PCI1720_DA0 + (chan << 1));
-               outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */
+               outw(val, dev->iobase + PCI1720_DA_REG(chan));
+               outb(0, dev->iobase + PCI1720_SYNC_REG); /* update outputs */
        }
 
        s->readback[chan] = val;
@@ -520,13 +500,13 @@ static int pci171x_ai_cancel(struct comedi_device *dev,
 {
        struct pci1710_private *devpriv = dev->private;
 
-       devpriv->CntrlReg &= Control_CNT0;
-       devpriv->CntrlReg |= Control_SW;
+       devpriv->ctrl &= PCI171X_CTRL_CNT0;
+       devpriv->ctrl |= PCI171X_CTRL_SW;
        /* reset any operations */
-       outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
+       outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG);
        comedi_8254_pacer_enable(dev->pacer, 1, 2, false);
-       outb(0, dev->iobase + PCI171x_CLRFIFO);
-       outb(0, dev->iobase + PCI171x_CLRINT);
+       outb(0, dev->iobase + PCI171X_CLRFIFO_REG);
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 
        return 0;
 }
@@ -539,22 +519,22 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
        unsigned int val;
        int ret;
 
-       status = inw(dev->iobase + PCI171x_STATUS);
-       if (status & Status_FE) {
+       status = inw(dev->iobase + PCI171X_STATUS_REG);
+       if (status & PCI171X_STATUS_FE) {
                dev_dbg(dev->class_dev, "A/D FIFO empty (%4x)\n", status);
                s->async->events |= COMEDI_CB_ERROR;
                return;
        }
-       if (status & Status_FF) {
+       if (status & PCI171X_STATUS_FF) {
                dev_dbg(dev->class_dev,
                        "A/D FIFO Full status (Fatal Error!) (%4x)\n", status);
                s->async->events |= COMEDI_CB_ERROR;
                return;
        }
 
-       outb(0, dev->iobase + PCI171x_CLRINT);  /*  clear our INT request */
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 
-       for (; !(inw(dev->iobase + PCI171x_STATUS) & Status_FE);) {
+       for (; !(inw(dev->iobase + PCI171X_STATUS_REG) & PCI171X_STATUS_FE);) {
                ret = pci171x_ai_read_sample(dev, s, s->async->cur_chan, &val);
                if (ret) {
                        s->async->events |= COMEDI_CB_ERROR;
@@ -570,7 +550,7 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
                }
        }
 
-       outb(0, dev->iobase + PCI171x_CLRINT);  /*  clear our INT request */
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 }
 
 static void pci1710_handle_fifo(struct comedi_device *dev,
@@ -582,13 +562,13 @@ static void pci1710_handle_fifo(struct comedi_device *dev,
        unsigned int status;
        int i;
 
-       status = inw(dev->iobase + PCI171x_STATUS);
-       if (!(status & Status_FH)) {
+       status = inw(dev->iobase + PCI171X_STATUS_REG);
+       if (!(status & PCI171X_STATUS_FH)) {
                dev_dbg(dev->class_dev, "A/D FIFO not half full!\n");
                async->events |= COMEDI_CB_ERROR;
                return;
        }
-       if (status & Status_FF) {
+       if (status & PCI171X_STATUS_FF) {
                dev_dbg(dev->class_dev,
                        "A/D FIFO Full status (Fatal Error!)\n");
                async->events |= COMEDI_CB_ERROR;
@@ -615,7 +595,7 @@ static void pci1710_handle_fifo(struct comedi_device *dev,
                }
        }
 
-       outb(0, dev->iobase + PCI171x_CLRINT);  /*  clear our INT request */
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 }
 
 static irqreturn_t interrupt_service_pci1710(int irq, void *d)
@@ -632,19 +612,20 @@ static irqreturn_t interrupt_service_pci1710(int irq, void *d)
        cmd = &s->async->cmd;
 
        /*  is this interrupt from our board? */
-       if (!(inw(dev->iobase + PCI171x_STATUS) & Status_IRQ))
+       if (!(inw(dev->iobase + PCI171X_STATUS_REG) & PCI171X_STATUS_IRQ))
                return IRQ_NONE;        /*  no, exit */
 
        if (devpriv->ai_et) {   /*  Switch from initial TRIG_EXT to TRIG_xxx. */
                devpriv->ai_et = 0;
-               devpriv->CntrlReg &= Control_CNT0;
-               devpriv->CntrlReg |= Control_SW; /* set software trigger */
-               outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
-               devpriv->CntrlReg = devpriv->ai_et_CntrlReg;
-               outb(0, dev->iobase + PCI171x_CLRFIFO);
-               outb(0, dev->iobase + PCI171x_CLRINT);
-               outw(devpriv->ai_et_MuxVal, dev->iobase + PCI171x_MUX);
-               outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
+               devpriv->ctrl &= PCI171X_CTRL_CNT0;
+               devpriv->ctrl |= PCI171X_CTRL_SW; /* set software trigger */
+               outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG);
+               devpriv->ctrl = devpriv->ctrl_ext;
+               outb(0, dev->iobase + PCI171X_CLRFIFO_REG);
+               outb(0, dev->iobase + PCI171X_CLRINT_REG);
+               /* no sample on this interrupt; reset the channel interval */
+               outw(devpriv->mux_ext, dev->iobase + PCI171X_MUX_REG);
+               outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG);
                comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
                return IRQ_HANDLED;
        }
@@ -667,33 +648,34 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        pci171x_ai_setup_chanlist(dev, s, cmd->chanlist, cmd->chanlist_len,
                                  devpriv->saved_seglen);
 
-       outb(0, dev->iobase + PCI171x_CLRFIFO);
-       outb(0, dev->iobase + PCI171x_CLRINT);
+       outb(0, dev->iobase + PCI171X_CLRFIFO_REG);
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 
-       devpriv->CntrlReg &= Control_CNT0;
+       devpriv->ctrl &= PCI171X_CTRL_CNT0;
        if ((cmd->flags & CMDF_WAKE_EOS) == 0)
-               devpriv->CntrlReg |= Control_ONEFH;
+               devpriv->ctrl |= PCI171X_CTRL_ONEFH;
 
        if (cmd->convert_src == TRIG_TIMER) {
                comedi_8254_update_divisors(dev->pacer);
 
-               devpriv->CntrlReg |= Control_PACER | Control_IRQEN;
+               devpriv->ctrl |= PCI171X_CTRL_PACER | PCI171X_CTRL_IRQEN;
                if (cmd->start_src == TRIG_EXT) {
-                       devpriv->ai_et_CntrlReg = devpriv->CntrlReg;
-                       devpriv->CntrlReg &=
-                           ~(Control_PACER | Control_ONEFH | Control_GATE);
-                       devpriv->CntrlReg |= Control_EXT;
+                       devpriv->ctrl_ext = devpriv->ctrl;
+                       devpriv->ctrl &= ~(PCI171X_CTRL_PACER |
+                                          PCI171X_CTRL_ONEFH |
+                                          PCI171X_CTRL_GATE);
+                       devpriv->ctrl |= PCI171X_CTRL_EXT;
                        devpriv->ai_et = 1;
                } else {        /* TRIG_NOW */
                        devpriv->ai_et = 0;
                }
-               outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
+               outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG);
 
                if (cmd->start_src == TRIG_NOW)
                        comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
        } else {        /* TRIG_EXT */
-               devpriv->CntrlReg |= Control_EXT | Control_IRQEN;
-               outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
+               devpriv->ctrl |= PCI171X_CTRL_EXT | PCI171X_CTRL_IRQEN;
+               outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG);
        }
 
        return 0;
@@ -782,18 +764,18 @@ static int pci171x_insn_counter_config(struct comedi_device *dev,
        case INSN_CONFIG_SET_CLOCK_SRC:
                switch (data[1]) {
                case 0: /* internal */
-                       devpriv->ai_et_CntrlReg &= ~Control_CNT0;
+                       devpriv->ctrl_ext &= ~PCI171X_CTRL_CNT0;
                        break;
                case 1: /* external */
-                       devpriv->ai_et_CntrlReg |= Control_CNT0;
+                       devpriv->ctrl_ext |= PCI171X_CTRL_CNT0;
                        break;
                default:
                        return -EINVAL;
                }
-               outw(devpriv->ai_et_CntrlReg, dev->iobase + PCI171x_CONTROL);
+               outw(devpriv->ctrl_ext, dev->iobase + PCI171X_CTRL_REG);
                break;
        case INSN_CONFIG_GET_CLOCK_SRC:
-               if (devpriv->ai_et_CntrlReg & Control_CNT0) {
+               if (devpriv->ctrl_ext & PCI171X_CTRL_CNT0) {
                        data[1] = 1;
                        data[2] = 0;
                } else {
@@ -814,21 +796,21 @@ static int pci171x_reset(struct comedi_device *dev)
        struct pci1710_private *devpriv = dev->private;
 
        /* Software trigger, CNT0=external */
-       devpriv->CntrlReg = Control_SW | Control_CNT0;
+       devpriv->ctrl = PCI171X_CTRL_SW | PCI171X_CTRL_CNT0;
        /* reset any operations */
-       outw(devpriv->CntrlReg, dev->iobase + PCI171x_CONTROL);
-       outb(0, dev->iobase + PCI171x_CLRFIFO); /*  clear FIFO */
-       outb(0, dev->iobase + PCI171x_CLRINT);  /*  clear INT request */
+       outw(devpriv->ctrl, dev->iobase + PCI171X_CTRL_REG);
+       outb(0, dev->iobase + PCI171X_CLRFIFO_REG);
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
        devpriv->da_ranges = 0;
        if (board->has_ao) {
-               /* set DACs to 0..5V */
-               outb(devpriv->da_ranges, dev->iobase + PCI171x_DAREF);
-               outw(0, dev->iobase + PCI171x_DA1); /* set DA outputs to 0V */
-               outw(0, dev->iobase + PCI171x_DA2);
+               /* set DACs to 0..5V and outputs to 0V */
+               outb(devpriv->da_ranges, dev->iobase + PCI171X_DAREF_REG);
+               outw(0, dev->iobase + PCI171X_DA_REG(0));
+               outw(0, dev->iobase + PCI171X_DA_REG(1));
        }
-       outw(0, dev->iobase + PCI171x_DO);      /*  digital outputs to 0 */
-       outb(0, dev->iobase + PCI171x_CLRFIFO); /*  clear FIFO */
-       outb(0, dev->iobase + PCI171x_CLRINT);  /*  clear INT request */
+       outw(0, dev->iobase + PCI171X_DO_REG);  /*  digital outputs to 0 */
+       outb(0, dev->iobase + PCI171X_CLRFIFO_REG);
+       outb(0, dev->iobase + PCI171X_CLRINT_REG);
 
        return 0;
 }
@@ -837,15 +819,15 @@ static int pci1720_reset(struct comedi_device *dev)
 {
        struct pci1710_private *devpriv = dev->private;
        /* set synchronous output mode */
-       outb(Syncont_SC0, dev->iobase + PCI1720_SYNCONT);
+       outb(PCI1720_SYNC_CTRL_SC0, dev->iobase + PCI1720_SYNC_CTRL_REG);
        devpriv->da_ranges = 0xAA;
-       /* set all ranges to +/-5V */
-       outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE);
-       outw(0x0800, dev->iobase + PCI1720_DA0);        /*  set outputs to 0V */
-       outw(0x0800, dev->iobase + PCI1720_DA1);
-       outw(0x0800, dev->iobase + PCI1720_DA2);
-       outw(0x0800, dev->iobase + PCI1720_DA3);
-       outb(0, dev->iobase + PCI1720_SYNCOUT); /*  update outputs */
+       /* set all ranges to +/-5V and outputs to 0V */
+       outb(devpriv->da_ranges, dev->iobase + PCI1720_RANGE_REG);
+       outw(0x0800, dev->iobase + PCI1720_DA_REG(0));
+       outw(0x0800, dev->iobase + PCI1720_DA_REG(1));
+       outw(0x0800, dev->iobase + PCI1720_DA_REG(2));
+       outw(0x0800, dev->iobase + PCI1720_DA_REG(3));
+       outb(0, dev->iobase + PCI1720_SYNC_REG);        /* update outputs */
 
        return 0;
 }
index 1921a97cc5ca3b7d18c26dd1bbe8bd717cf189b2..f82afd94731017442494a688e70d00a9fb02e9aa 100644 (file)
 #define PCI1723_BOARD_ID_REG           0x10
 #define PCI1723_BOARD_ID_MASK          (0xf << 0)
 #define PCI1723_SYNC_CTRL_REG          0x12
-#define PCI1723_SYNC_CTRL_ASYNC                (0 << 0)
-#define PCI1723_SYNC_CTRL_SYNC         (1 << 0)
+#define PCI1723_SYNC_CTRL(x)           (((x) & 0x1) << 0)
+#define PCI1723_SYNC_CTRL_ASYNC                PCI1723_SYNC_CTRL(0)
+#define PCI1723_SYNC_CTRL_SYNC         PCI1723_SYNC_CTRL(1)
 #define PCI1723_CTRL_REG               0x14
-#define PCI1723_CTRL_BUSY              (1 << 15)
-#define PCI1723_CTRL_INIT              (1 << 14)
-#define PCI1723_CTRL_SELF              (1 << 8)
+#define PCI1723_CTRL_BUSY              BIT(15)
+#define PCI1723_CTRL_INIT              BIT(14)
+#define PCI1723_CTRL_SELF              BIT(8)
 #define PCI1723_CTRL_IDX(x)            (((x) & 0x3) << 6)
 #define PCI1723_CTRL_RANGE(x)          (((x) & 0x3) << 4)
-#define PCI1723_CTRL_GAIN              (0 << 3)
-#define PCI1723_CTRL_OFFSET            (1 << 3)
+#define PCI1723_CTRL_SEL(x)            (((x) & 0x1) << 3)
+#define PCI1723_CTRL_GAIN              PCI1723_CTRL_SEL(0)
+#define PCI1723_CTRL_OFFSET            PCI1723_CTRL_SEL(1)
 #define PCI1723_CTRL_CHAN(x)           (((x) & 0x7) << 0)
 #define PCI1723_CALIB_CTRL_REG         0x16
-#define PCI1723_CALIB_CTRL_CS          (1 << 2)
-#define PCI1723_CALIB_CTRL_DAT         (1 << 1)
-#define PCI1723_CALIB_CTRL_CLK         (1 << 0)
+#define PCI1723_CALIB_CTRL_CS          BIT(2)
+#define PCI1723_CALIB_CTRL_DAT         BIT(1)
+#define PCI1723_CALIB_CTRL_CLK         BIT(0)
 #define PCI1723_CALIB_STROBE_REG       0x18
 #define PCI1723_DIO_CTRL_REG           0x1a
-#define PCI1723_DIO_CTRL_HDIO          (1 << 1)
-#define PCI1723_DIO_CTRL_LDIO          (1 << 0)
+#define PCI1723_DIO_CTRL_HDIO          BIT(1)
+#define PCI1723_DIO_CTRL_LDIO          BIT(0)
 #define PCI1723_DIO_DATA_REG           0x1c
 #define PCI1723_CALIB_DATA_REG         0x1e
 #define PCI1723_SYNC_STROBE_REG                0x20
 #define PCI1723_RESET_CALIB_STROBE_REG 0x24
 #define PCI1723_RANGE_STROBE_REG       0x26
 #define PCI1723_VREF_REG               0x28
-#define PCI1723_VREF_NEG10V            (0 << 0)
-#define PCI1723_VREF_0V                        (1 << 0)
-#define PCI1723_VREF_POS10V            (3 << 0)
+#define PCI1723_VREF(x)                        (((x) & 0x3) << 0)
+#define PCI1723_VREF_NEG10V            PCI1723_VREF(0)
+#define PCI1723_VREF_0V                        PCI1723_VREF(1)
+#define PCI1723_VREF_POS10V            PCI1723_VREF(3)
 
 static int pci1723_ao_insn_write(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
index 9677111f9ab24b67f3063d40d08b12b7c24ee8e2..bf6a8f10118c9e9aef2f6454cbcb54d638a45450 100644 (file)
  * PCI bar 2 Register I/O map (dev->iobase)
  */
 #define PCI1724_DAC_CTRL_REG           0x00
-#define PCI1724_DAC_CTRL_GX(x)         (1 << (20 + ((x) / 8)))
+#define PCI1724_DAC_CTRL_GX(x)         BIT(20 + ((x) / 8))
 #define PCI1724_DAC_CTRL_CX(x)         (((x) % 8) << 16)
-#define PCI1724_DAC_CTRL_MODE_GAIN     (1 << 14)
-#define PCI1724_DAC_CTRL_MODE_OFFSET   (2 << 14)
-#define PCI1724_DAC_CTRL_MODE_NORMAL   (3 << 14)
-#define PCI1724_DAC_CTRL_MODE_MASK     (3 << 14)
+#define PCI1724_DAC_CTRL_MODE(x)       (((x) & 0x3) << 14)
+#define PCI1724_DAC_CTRL_MODE_GAIN     PCI1724_DAC_CTRL_MODE(1)
+#define PCI1724_DAC_CTRL_MODE_OFFSET   PCI1724_DAC_CTRL_MODE(2)
+#define PCI1724_DAC_CTRL_MODE_NORMAL   PCI1724_DAC_CTRL_MODE(3)
+#define PCI1724_DAC_CTRL_MODE_MASK     PCI1724_DAC_CTRL_MODE(3)
 #define PCI1724_DAC_CTRL_DATA(x)       (((x) & 0x3fff) << 0)
 #define PCI1724_SYNC_CTRL_REG          0x04
-#define PCI1724_SYNC_CTRL_DACSTAT      (1 << 1)
-#define PCI1724_SYNC_CTRL_SYN          (1 << 0)
+#define PCI1724_SYNC_CTRL_DACSTAT      BIT(1)
+#define PCI1724_SYNC_CTRL_SYN          BIT(0)
 #define PCI1724_EEPROM_CTRL_REG                0x08
 #define PCI1724_SYNC_TRIG_REG          0x0c  /* any value works */
 #define PCI1724_BOARD_ID_REG           0x10
index fbc3e5aa94cb908e6b5964a95dbc36e3864a78f4..43a0ce5721d3a3e6a8f7cf943848b567b46ed6e4 100644 (file)
 /*
-
-    comedi/drivers/aio_aio12_8.c
-
-    Driver for Access I/O Products PC-104 AIO12-8 Analog I/O Board
-    Copyright (C) 2006 C&C Technologies, Inc.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
+ * aio_aio12_8.c
+ * Driver for Access I/O Products PC-104 AIO12-8 Analog I/O Board
+ * Copyright (C) 2006 C&C Technologies, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
 /*
-
-Driver: aio_aio12_8
-Description: Access I/O Products PC-104 AIO12-8 Analog I/O Board
-Author: Pablo Mejia <pablo.mejia@cctechnol.com>
-Devices: [Access I/O] PC-104 AIO12-8 (aio_aio12_8)
-        [Access I/O] PC-104 AI12-8 (aio_ai12_8)
-        [Access I/O] PC-104 AO12-8 (aio_ao12_8)
-Status: experimental
-
-Configuration Options:
-  [0] - I/O port base address
-
-Notes:
-
-  Only synchronous operations are supported.
-
-*/
+ * Driver: aio_aio12_8
+ * Description: Access I/O Products PC-104 AIO12-8 Analog I/O Board
+ * Author: Pablo Mejia <pablo.mejia@cctechnol.com>
+ * Devices: [Access I/O] PC-104 AIO12-8 (aio_aio12_8),
+ *   [Access I/O] PC-104 AI12-8 (aio_ai12_8),
+ *   [Access I/O] PC-104 AO12-4 (aio_ao12_4)
+ * Status: experimental
+ *
+ * Configuration Options:
+ *   [0] - I/O port base address
+ *
+ * Notes:
+ * Only synchronous operations are supported.
+ */
 
 #include <linux/module.h>
 #include "../comedidev.h"
+
+#include "comedi_8254.h"
 #include "8255.h"
 
 /*
  * Register map
  */
 #define AIO12_8_STATUS_REG             0x00
-#define AIO12_8_STATUS_ADC_EOC         (1 << 7)
-#define AIO12_8_STATUS_PORT_C_COS      (1 << 6)
-#define AIO12_8_STATUS_IRQ_ENA         (1 << 2)
+#define AIO12_8_STATUS_ADC_EOC         BIT(7)
+#define AIO12_8_STATUS_PORT_C_COS      BIT(6)
+#define AIO12_8_STATUS_IRQ_ENA         BIT(2)
 #define AIO12_8_INTERRUPT_REG          0x01
-#define AIO12_8_INTERRUPT_ADC          (1 << 7)
-#define AIO12_8_INTERRUPT_COS          (1 << 6)
-#define AIO12_8_INTERRUPT_COUNTER1     (1 << 5)
-#define AIO12_8_INTERRUPT_PORT_C3      (1 << 4)
-#define AIO12_8_INTERRUPT_PORT_C0      (1 << 3)
-#define AIO12_8_INTERRUPT_ENA          (1 << 2)
+#define AIO12_8_INTERRUPT_ADC          BIT(7)
+#define AIO12_8_INTERRUPT_COS          BIT(6)
+#define AIO12_8_INTERRUPT_COUNTER1     BIT(5)
+#define AIO12_8_INTERRUPT_PORT_C3      BIT(4)
+#define AIO12_8_INTERRUPT_PORT_C0      BIT(3)
+#define AIO12_8_INTERRUPT_ENA          BIT(2)
 #define AIO12_8_ADC_REG                        0x02
-#define AIO12_8_ADC_MODE_NORMAL                (0 << 6)
-#define AIO12_8_ADC_MODE_INT_CLK       (1 << 6)
-#define AIO12_8_ADC_MODE_STANDBY       (2 << 6)
-#define AIO12_8_ADC_MODE_POWERDOWN     (3 << 6)
-#define AIO12_8_ADC_ACQ_3USEC          (0 << 5)
-#define AIO12_8_ADC_ACQ_PROGRAM                (1 << 5)
+#define AIO12_8_ADC_MODE(x)            (((x) & 0x3) << 6)
+#define AIO12_8_ADC_MODE_NORMAL                AIO12_8_ADC_MODE(0)
+#define AIO12_8_ADC_MODE_INT_CLK       AIO12_8_ADC_MODE(1)
+#define AIO12_8_ADC_MODE_STANDBY       AIO12_8_ADC_MODE(2)
+#define AIO12_8_ADC_MODE_POWERDOWN     AIO12_8_ADC_MODE(3)
+#define AIO12_8_ADC_ACQ(x)             (((x) & 0x1) << 5)
+#define AIO12_8_ADC_ACQ_3USEC          AIO12_8_ADC_ACQ(0)
+#define AIO12_8_ADC_ACQ_PROGRAM                AIO12_8_ADC_ACQ(1)
 #define AIO12_8_ADC_RANGE(x)           ((x) << 3)
 #define AIO12_8_ADC_CHAN(x)            ((x) << 0)
 #define AIO12_8_DAC_REG(x)             (0x04 + (x) * 2)
 #define AIO12_8_8254_BASE_REG          0x0c
 #define AIO12_8_8255_BASE_REG          0x10
 #define AIO12_8_DIO_CONTROL_REG                0x14
-#define AIO12_8_DIO_CONTROL_TST                (1 << 0)
+#define AIO12_8_DIO_CONTROL_TST                BIT(0)
 #define AIO12_8_ADC_TRIGGER_REG                0x15
 #define AIO12_8_ADC_TRIGGER_RANGE(x)   ((x) << 3)
 #define AIO12_8_ADC_TRIGGER_CHAN(x)    ((x) << 0)
 #define AIO12_8_TRIGGER_REG            0x16
-#define AIO12_8_TRIGGER_ADTRIG         (1 << 1)
-#define AIO12_8_TRIGGER_DACTRIG                (1 << 0)
+#define AIO12_8_TRIGGER_ADTRIG         BIT(1)
+#define AIO12_8_TRIGGER_DACTRIG                BIT(0)
 #define AIO12_8_COS_REG                        0x17
 #define AIO12_8_DAC_ENABLE_REG         0x18
-#define AIO12_8_DAC_ENABLE_REF_ENA     (1 << 0)
+#define AIO12_8_DAC_ENABLE_REF_ENA     BIT(0)
+
+static const struct comedi_lrange aio_aio12_8_range = {
+       4, {
+               UNI_RANGE(5),
+               BIP_RANGE(5),
+               UNI_RANGE(10),
+               BIP_RANGE(10)
+       }
+};
 
 struct aio12_8_boardtype {
        const char *name;
-       int ai_nchan;
-       int ao_nchan;
+       unsigned int has_ai:1;
+       unsigned int has_ao:1;
 };
 
 static const struct aio12_8_boardtype board_types[] = {
        {
                .name           = "aio_aio12_8",
-               .ai_nchan       = 8,
-               .ao_nchan       = 4,
+               .has_ai         = 1,
+               .has_ao         = 1,
        }, {
                .name           = "aio_ai12_8",
-               .ai_nchan       = 8,
+               .has_ai         = 1,
        }, {
-               .name           = "aio_ao12_8",
-               .ao_nchan       = 4,
+               .name           = "aio_ao12_4",
+               .has_ao         = 1,
        },
 };
 
@@ -112,13 +120,15 @@ static int aio_aio12_8_ai_eoc(struct comedi_device *dev,
 
 static int aio_aio12_8_ai_read(struct comedi_device *dev,
                               struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
+                              struct comedi_insn *insn,
+                              unsigned int *data)
 {
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
+       unsigned int val;
        unsigned char control;
        int ret;
-       int n;
+       int i;
 
        /*
         * Setup the control byte for internal 2MHz clock, 3uS conversion,
@@ -130,7 +140,7 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev,
        /* Read status to clear EOC latch */
        inb(dev->iobase + AIO12_8_STATUS_REG);
 
-       for (n = 0; n < insn->n; n++) {
+       for (i = 0; i < insn->n; i++) {
                /*  Setup and start conversion */
                outb(control, dev->iobase + AIO12_8_ADC_REG);
 
@@ -139,7 +149,13 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev,
                if (ret)
                        return ret;
 
-               data[n] = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata;
+               val = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata;
+
+               /* munge bipolar 2's complement data to offset binary */
+               if (comedi_range_is_bipolar(s, range))
+                       val = comedi_offset_munge(s, val);
+
+               data[i] = val;
        }
 
        return insn->n;
@@ -166,14 +182,28 @@ static int aio_aio12_8_ao_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-static const struct comedi_lrange range_aio_aio12_8 = {
-       4, {
-               UNI_RANGE(5),
-               BIP_RANGE(5),
-               UNI_RANGE(10),
-               BIP_RANGE(10)
+static int aio_aio12_8_counter_insn_config(struct comedi_device *dev,
+                                          struct comedi_subdevice *s,
+                                          struct comedi_insn *insn,
+                                          unsigned int *data)
+{
+       unsigned int chan = CR_CHAN(insn->chanspec);
+
+       switch (data[0]) {
+       case INSN_CONFIG_GET_CLOCK_SRC:
+               /*
+                * Channels 0 and 2 have external clock sources.
+                * Channel 1 has a fixed 1 MHz clock source.
+                */
+               data[0] = 0;
+               data[1] = (chan == 1) ? I8254_OSC_BASE_1MHZ : 0;
+               break;
+       default:
+               return -EINVAL;
        }
-};
+
+       return insn->n;
+}
 
 static int aio_aio12_8_attach(struct comedi_device *dev,
                              struct comedi_devconfig *it)
@@ -186,31 +216,36 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
+       dev->pacer = comedi_8254_init(dev->iobase + AIO12_8_8254_BASE_REG,
+                                     0, I8254_IO8, 0);
+       if (!dev->pacer)
+               return -ENOMEM;
+
        ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;
 
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       if (board->ai_nchan) {
-               /* Analog input subdevice */
+       if (board->has_ai) {
                s->type         = COMEDI_SUBD_AI;
                s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
-               s->n_chan       = board->ai_nchan;
+               s->n_chan       = 8;
                s->maxdata      = 0x0fff;
-               s->range_table  = &range_aio_aio12_8;
+               s->range_table  = &aio_aio12_8_range;
                s->insn_read    = aio_aio12_8_ai_read;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }
 
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       if (board->ao_nchan) {
-               /* Analog output subdevice */
+       if (board->has_ao) {
                s->type         = COMEDI_SUBD_AO;
-               s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_DIFF;
+               s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
                s->n_chan       = 4;
                s->maxdata      = 0x0fff;
-               s->range_table  = &range_aio_aio12_8;
+               s->range_table  = &aio_aio12_8_range;
                s->insn_write   = aio_aio12_8_ao_insn_write;
 
                ret = comedi_alloc_subdev_readback(s);
@@ -220,15 +255,17 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
                s->type = COMEDI_SUBD_UNUSED;
        }
 
+       /* Digital I/O subdevice (8255) */
        s = &dev->subdevices[2];
-       /* 8255 Digital i/o subdevice */
        ret = subdev_8255_init(dev, s, NULL, AIO12_8_8255_BASE_REG);
        if (ret)
                return ret;
 
+       /* Counter subdevice (8254) */
        s = &dev->subdevices[3];
-       /* 8254 counter/timer subdevice */
-       s->type         = COMEDI_SUBD_UNUSED;
+       comedi_8254_subdevice_init(s, dev->pacer);
+
+       dev->pacer->insn_config = aio_aio12_8_counter_insn_config;
 
        return 0;
 }
@@ -245,5 +282,5 @@ static struct comedi_driver aio_aio12_8_driver = {
 module_comedi_driver(aio_aio12_8_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Access I/O AIO12-8 Analog I/O Board");
 MODULE_LICENSE("GPL");
index 5c5c4e2ec3d5ede539277e28a62efd3a26ed829e..4b39f6960c0a6fba15ca00ecdf6003e8aac321f9 100644 (file)
@@ -2275,7 +2275,7 @@ static int pci230_ai_cancel(struct comedi_device *dev,
 static irqreturn_t pci230_interrupt(int irq, void *d)
 {
        unsigned char status_int, valid_status_int, temp_ier;
-       struct comedi_device *dev = (struct comedi_device *)d;
+       struct comedi_device *dev = d;
        struct pci230_private *devpriv = dev->private;
        struct comedi_subdevice *s_ao = dev->write_subdev;
        struct comedi_subdevice *s_ai = dev->read_subdev;
index ae84f2c0cc9c3bd2569b36e1e29bed9fc9055de5..78d098f9e1f2540ca300b3d44d7d4c6d00c4d78d 100644 (file)
@@ -1,36 +1,37 @@
 /*
-    comedi/drivers/das16cs.c
-    Driver for Computer Boards PC-CARD DAS16/16.
+ * cb_das16_cs.c
+ * Driver for Computer Boards PC-CARD DAS16/16.
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000, 2001, 2002 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * PCMCIA support code for this driver is adapted from the dummy_cs.c
+ * driver of the Linux PCMCIA Card Services package.
+ *
+ * The initial developer of the original code is David A. Hinds
+ * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+ */
 
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2000, 2001, 2002 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    PCMCIA support code for this driver is adapted from the dummy_cs.c
-    driver of the Linux PCMCIA Card Services package.
-
-    The initial developer of the original code is David A. Hinds
-    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
-    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
-
-*/
 /*
-Driver: cb_das16_cs
-Description: Computer Boards PC-CARD DAS16/16
-Devices: [ComputerBoards] PC-CARD DAS16/16 (cb_das16_cs), PC-CARD DAS16/16-AO
-Author: ds
-Updated: Mon, 04 Nov 2002 20:04:21 -0800
-Status: experimental
-*/
+ * Driver: cb_das16_cs
+ * Description: Computer Boards PC-CARD DAS16/16
+ * Devices: [ComputerBoards] PC-CARD DAS16/16 (cb_das16_cs),
+ *   PC-CARD DAS16/16-AO
+ * Author: ds
+ * Updated: Mon, 04 Nov 2002 20:04:21 -0800
+ * Status: experimental
+ */
 
 #include <linux/module.h>
 #include <linux/interrupt.h>
@@ -40,38 +41,86 @@ Status: experimental
 
 #include "comedi_8254.h"
 
-#define DAS16CS_ADC_DATA               0
-#define DAS16CS_DIO_MUX                        2
-#define DAS16CS_MISC1                  4
-#define DAS16CS_MISC2                  6
-#define DAS16CS_TIMER_BASE             8
-#define DAS16CS_DIO                    16
+/*
+ * Register I/O map
+ */
+#define DAS16CS_AI_DATA_REG            0x00
+#define DAS16CS_AI_MUX_REG             0x02
+#define DAS16CS_AI_MUX_HI_CHAN(x)      (((x) & 0xf) << 4)
+#define DAS16CS_AI_MUX_LO_CHAN(x)      (((x) & 0xf) << 0)
+#define DAS16CS_AI_MUX_SINGLE_CHAN(x)  (DAS16CS_AI_MUX_HI_CHAN(x) |    \
+                                        DAS16CS_AI_MUX_LO_CHAN(x))
+#define DAS16CS_MISC1_REG              0x04
+#define DAS16CS_MISC1_INTE             BIT(15) /* 1=enable; 0=disable */
+#define DAS16CS_MISC1_INT_SRC(x)       (((x) & 0x7) << 12) /* interrupt src */
+#define DAS16CS_MISC1_INT_SRC_NONE     DAS16CS_MISC1_INT_SRC(0)
+#define DAS16CS_MISC1_INT_SRC_PACER    DAS16CS_MISC1_INT_SRC(1)
+#define DAS16CS_MISC1_INT_SRC_EXT      DAS16CS_MISC1_INT_SRC(2)
+#define DAS16CS_MISC1_INT_SRC_FNE      DAS16CS_MISC1_INT_SRC(3)
+#define DAS16CS_MISC1_INT_SRC_FHF      DAS16CS_MISC1_INT_SRC(4)
+#define DAS16CS_MISC1_INT_SRC_EOS      DAS16CS_MISC1_INT_SRC(5)
+#define DAS16CS_MISC1_INT_SRC_MASK     DAS16CS_MISC1_INT_SRC(7)
+#define DAS16CS_MISC1_OVR              BIT(10) /* ro - 1=FIFO overflow */
+#define DAS16CS_MISC1_AI_CONV(x)       (((x) & 0x3) << 8) /* AI convert src */
+#define DAS16CS_MISC1_AI_CONV_SW       DAS16CS_MISC1_AI_CONV(0)
+#define DAS16CS_MISC1_AI_CONV_EXT_NEG  DAS16CS_MISC1_AI_CONV(1)
+#define DAS16CS_MISC1_AI_CONV_EXT_POS  DAS16CS_MISC1_AI_CONV(2)
+#define DAS16CS_MISC1_AI_CONV_PACER    DAS16CS_MISC1_AI_CONV(3)
+#define DAS16CS_MISC1_AI_CONV_MASK     DAS16CS_MISC1_AI_CONV(3)
+#define DAS16CS_MISC1_EOC              BIT(7)  /* ro - 0=busy; 1=ready */
+#define DAS16CS_MISC1_SEDIFF           BIT(5)  /* 0=diff; 1=se */
+#define DAS16CS_MISC1_INTB             BIT(4)  /* ro - 0=latched; 1=cleared */
+#define DAS16CS_MISC1_MA_MASK          (0xf << 0) /* ro - current ai mux */
+#define DAS16CS_MISC1_DAC1CS           BIT(3)  /* wo - DAC1 chip select */
+#define DAS16CS_MISC1_DACCLK           BIT(2)  /* wo - Serial DAC clock */
+#define DAS16CS_MISC1_DACSD            BIT(1)  /* wo - Serial DAC data */
+#define DAS16CS_MISC1_DAC0CS           BIT(0)  /* wo - DAC0 chip select */
+#define DAS16CS_MISC1_DAC_MASK         (0x0f << 0)
+#define DAS16CS_MISC2_REG              0x06
+#define DAS16CS_MISC2_BME              BIT(14) /* 1=burst enable; 0=disable */
+#define DAS16CS_MISC2_AI_GAIN(x)       (((x) & 0xf) << 8) /* AI gain */
+#define DAS16CS_MISC2_AI_GAIN_1                DAS16CS_MISC2_AI_GAIN(4) /* +/-10V */
+#define DAS16CS_MISC2_AI_GAIN_2                DAS16CS_MISC2_AI_GAIN(0) /* +/-5V */
+#define DAS16CS_MISC2_AI_GAIN_4                DAS16CS_MISC2_AI_GAIN(1) /* +/-2.5V */
+#define DAS16CS_MISC2_AI_GAIN_8                DAS16CS_MISC2_AI_GAIN(2) /* +-1.25V */
+#define DAS16CS_MISC2_AI_GAIN_MASK     DAS16CS_MISC2_AI_GAIN(0xf)
+#define DAS16CS_MISC2_UDIR             BIT(7)  /* 1=dio7:4 output; 0=input */
+#define DAS16CS_MISC2_LDIR             BIT(6)  /* 1=dio3:0 output; 0=input */
+#define DAS16CS_MISC2_TRGPOL           BIT(5)  /* 1=active lo; 0=hi */
+#define DAS16CS_MISC2_TRGSEL           BIT(4)  /* 1=edge; 0=level */
+#define DAS16CS_MISC2_FFNE             BIT(3)  /* ro - 1=FIFO not empty */
+#define DAS16CS_MISC2_TRGCLR           BIT(3)  /* wo - 1=clr (monstable) */
+#define DAS16CS_MISC2_CLK2             BIT(2)  /* 1=10 MHz; 0=1 MHz */
+#define DAS16CS_MISC2_CTR1             BIT(1)  /* 1=int. 100 kHz; 0=ext. clk */
+#define DAS16CS_MISC2_TRG0             BIT(0)  /* 1=enable; 0=disable */
+#define DAS16CS_TIMER_BASE             0x08
+#define DAS16CS_DIO_REG                        0x10
 
 struct das16cs_board {
        const char *name;
        int device_id;
-       int n_ao_chans;
+       unsigned int has_ao:1;
+       unsigned int has_4dio:1;
 };
 
 static const struct das16cs_board das16cs_boards[] = {
        {
                .name           = "PC-CARD DAS16/16-AO",
                .device_id      = 0x0039,
-               .n_ao_chans     = 2,
+               .has_ao         = 1,
+               .has_4dio       = 1,
        }, {
                .name           = "PCM-DAS16s/16",
                .device_id      = 0x4009,
-               .n_ao_chans     = 0,
        }, {
                .name           = "PC-CARD DAS16/16",
                .device_id      = 0x0000,       /* unknown */
-               .n_ao_chans     = 0,
        },
 };
 
 struct das16cs_private {
-       unsigned short status1;
-       unsigned short status2;
+       unsigned short misc1;
+       unsigned short misc2;
 };
 
 static const struct comedi_lrange das16cs_ai_range = {
@@ -90,15 +139,16 @@ static int das16cs_ai_eoc(struct comedi_device *dev,
 {
        unsigned int status;
 
-       status = inw(dev->iobase + DAS16CS_MISC1);
-       if (status & 0x0080)
+       status = inw(dev->iobase + DAS16CS_MISC1_REG);
+       if (status & DAS16CS_MISC1_EOC)
                return 0;
        return -EBUSY;
 }
 
-static int das16cs_ai_rinsn(struct comedi_device *dev,
-                           struct comedi_subdevice *s,
-                           struct comedi_insn *insn, unsigned int *data)
+static int das16cs_ai_insn_read(struct comedi_device *dev,
+                               struct comedi_subdevice *s,
+                               struct comedi_insn *insn,
+                               unsigned int *data)
 {
        struct das16cs_private *devpriv = dev->private;
        int chan = CR_CHAN(insn->chanspec);
@@ -107,37 +157,43 @@ static int das16cs_ai_rinsn(struct comedi_device *dev,
        int ret;
        int i;
 
-       outw(chan, dev->iobase + DAS16CS_DIO_MUX);
+       outw(DAS16CS_AI_MUX_SINGLE_CHAN(chan),
+            dev->iobase + DAS16CS_AI_MUX_REG);
 
-       devpriv->status1 &= ~0xf320;
-       devpriv->status1 |= (aref == AREF_DIFF) ? 0 : 0x0020;
-       outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
+       /* disable interrupts, software convert */
+       devpriv->misc1 &= ~(DAS16CS_MISC1_INTE | DAS16CS_MISC1_INT_SRC_MASK |
+                             DAS16CS_MISC1_AI_CONV_MASK);
+       if (aref == AREF_DIFF)
+               devpriv->misc1 &= ~DAS16CS_MISC1_SEDIFF;
+       else
+               devpriv->misc1 |= DAS16CS_MISC1_SEDIFF;
+       outw(devpriv->misc1, dev->iobase + DAS16CS_MISC1_REG);
 
-       devpriv->status2 &= ~0xff00;
+       devpriv->misc2 &= ~(DAS16CS_MISC2_BME | DAS16CS_MISC2_AI_GAIN_MASK);
        switch (range) {
        case 0:
-               devpriv->status2 |= 0x800;
+               devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_1;
                break;
        case 1:
-               devpriv->status2 |= 0x000;
+               devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_2;
                break;
        case 2:
-               devpriv->status2 |= 0x100;
+               devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_4;
                break;
        case 3:
-               devpriv->status2 |= 0x200;
+               devpriv->misc2 |= DAS16CS_MISC2_AI_GAIN_8;
                break;
        }
-       outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
+       outw(devpriv->misc2, dev->iobase + DAS16CS_MISC2_REG);
 
        for (i = 0; i < insn->n; i++) {
-               outw(0, dev->iobase + DAS16CS_ADC_DATA);
+               outw(0, dev->iobase + DAS16CS_AI_DATA_REG);
 
                ret = comedi_timeout(dev, s, insn, das16cs_ai_eoc, 0);
                if (ret)
                        return ret;
 
-               data[i] = inw(dev->iobase + DAS16CS_ADC_DATA);
+               data[i] = inw(dev->iobase + DAS16CS_AI_DATA_REG);
        }
 
        return i;
@@ -151,39 +207,43 @@ static int das16cs_ao_insn_write(struct comedi_device *dev,
        struct das16cs_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int val = s->readback[chan];
-       unsigned short status1;
+       unsigned short misc1;
        int bit;
        int i;
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
 
-               outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
+               outw(devpriv->misc1, dev->iobase + DAS16CS_MISC1_REG);
                udelay(1);
 
-               status1 = devpriv->status1 & ~0xf;
+               /* raise the DACxCS line for the non-selected channel */
+               misc1 = devpriv->misc1 & ~DAS16CS_MISC1_DAC_MASK;
                if (chan)
-                       status1 |= 0x0001;
+                       misc1 |= DAS16CS_MISC1_DAC0CS;
                else
-                       status1 |= 0x0008;
+                       misc1 |= DAS16CS_MISC1_DAC1CS;
 
-               outw(status1, dev->iobase + DAS16CS_MISC1);
+               outw(misc1, dev->iobase + DAS16CS_MISC1_REG);
                udelay(1);
 
                for (bit = 15; bit >= 0; bit--) {
-                       int b = (val >> bit) & 0x1;
-
-                       b <<= 1;
-                       outw(status1 | b | 0x0000, dev->iobase + DAS16CS_MISC1);
+                       if ((val >> bit) & 0x1)
+                               misc1 |= DAS16CS_MISC1_DACSD;
+                       else
+                               misc1 &= ~DAS16CS_MISC1_DACSD;
+                       outw(misc1, dev->iobase + DAS16CS_MISC1_REG);
                        udelay(1);
-                       outw(status1 | b | 0x0004, dev->iobase + DAS16CS_MISC1);
+                       outw(misc1 | DAS16CS_MISC1_DACCLK,
+                            dev->iobase + DAS16CS_MISC1_REG);
                        udelay(1);
                }
                /*
                 * Make both DAC0CS and DAC1CS high to load
                 * the new data and update analog the output
                 */
-               outw(status1 | 0x9, dev->iobase + DAS16CS_MISC1);
+               outw(misc1 | DAS16CS_MISC1_DAC0CS | DAS16CS_MISC1_DAC1CS,
+                    dev->iobase + DAS16CS_MISC1_REG);
        }
        s->readback[chan] = val;
 
@@ -196,9 +256,9 @@ static int das16cs_dio_insn_bits(struct comedi_device *dev,
                                 unsigned int *data)
 {
        if (comedi_dio_update_state(s, data))
-               outw(s->state, dev->iobase + DAS16CS_DIO);
+               outw(s->state, dev->iobase + DAS16CS_DIO_REG);
 
-       data[1] = inw(dev->iobase + DAS16CS_DIO);
+       data[1] = inw(dev->iobase + DAS16CS_DIO_REG);
 
        return insn->n;
 }
@@ -222,11 +282,52 @@ static int das16cs_dio_insn_config(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       devpriv->status2 &= ~0x00c0;
-       devpriv->status2 |= (s->io_bits & 0xf0) ? 0x0080 : 0;
-       devpriv->status2 |= (s->io_bits & 0x0f) ? 0x0040 : 0;
+       if (s->io_bits & 0xf0)
+               devpriv->misc2 |= DAS16CS_MISC2_UDIR;
+       else
+               devpriv->misc2 &= ~DAS16CS_MISC2_UDIR;
+       if (s->io_bits & 0x0f)
+               devpriv->misc2 |= DAS16CS_MISC2_LDIR;
+       else
+               devpriv->misc2 &= ~DAS16CS_MISC2_LDIR;
+       outw(devpriv->misc2, dev->iobase + DAS16CS_MISC2_REG);
+
+       return insn->n;
+}
+
+static int das16cs_counter_insn_config(struct comedi_device *dev,
+                                      struct comedi_subdevice *s,
+                                      struct comedi_insn *insn,
+                                      unsigned int *data)
+{
+       struct das16cs_private *devpriv = dev->private;
 
-       outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
+       switch (data[0]) {
+       case INSN_CONFIG_SET_CLOCK_SRC:
+               switch (data[1]) {
+               case 0: /* internal 100 kHz */
+                       devpriv->misc2 |= DAS16CS_MISC2_CTR1;
+                       break;
+               case 1: /* external */
+                       devpriv->misc2 &= ~DAS16CS_MISC2_CTR1;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               outw(devpriv->misc2, dev->iobase + DAS16CS_MISC2_REG);
+               break;
+       case INSN_CONFIG_GET_CLOCK_SRC:
+               if (devpriv->misc2 & DAS16CS_MISC2_CTR1) {
+                       data[1] = 0;
+                       data[2] = I8254_OSC_BASE_100KHZ;
+               } else {
+                       data[1] = 1;
+                       data[2] = 0;    /* unknown */
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
 
        return insn->n;
 }
@@ -278,26 +379,25 @@ static int das16cs_auto_attach(struct comedi_device *dev,
        if (!dev->pacer)
                return -ENOMEM;
 
-       ret = comedi_alloc_subdevices(dev, 3);
+       ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;
 
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       /* analog input subdevice */
        s->type         = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
        s->n_chan       = 16;
        s->maxdata      = 0xffff;
        s->range_table  = &das16cs_ai_range;
-       s->len_chanlist = 16;
-       s->insn_read    = das16cs_ai_rinsn;
+       s->insn_read    = das16cs_ai_insn_read;
 
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       /* analog output subdevice */
-       if (board->n_ao_chans) {
+       if (board->has_ao) {
                s->type         = COMEDI_SUBD_AO;
                s->subdev_flags = SDF_WRITABLE;
-               s->n_chan       = board->n_ao_chans;
+               s->n_chan       = 2;
                s->maxdata      = 0xffff;
                s->range_table  = &range_bipolar10;
                s->insn_write   = &das16cs_ao_insn_write;
@@ -309,16 +409,26 @@ static int das16cs_auto_attach(struct comedi_device *dev,
                s->type         = COMEDI_SUBD_UNUSED;
        }
 
+       /* Digital I/O subdevice */
        s = &dev->subdevices[2];
-       /* digital i/o subdevice */
        s->type         = COMEDI_SUBD_DIO;
        s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan       = 8;
+       s->n_chan       = board->has_4dio ? 4 : 8;
        s->maxdata      = 1;
        s->range_table  = &range_digital;
        s->insn_bits    = das16cs_dio_insn_bits;
        s->insn_config  = das16cs_dio_insn_config;
 
+       /* Counter subdevice (8254) */
+       s = &dev->subdevices[3];
+       comedi_8254_subdevice_init(s, dev->pacer);
+
+       dev->pacer->insn_config = das16cs_counter_insn_config;
+
+       /* counters 1 and 2 are used internally for the pacer */
+       comedi_8254_set_busy(dev->pacer, 1, true);
+       comedi_8254_set_busy(dev->pacer, 2, true);
+
        return 0;
 }
 
index b43e836575fd10b9ae8b175875c0d7f8e959108c..3cd008acb657a5d735628fd49614f5c742a93564 100644 (file)
@@ -1,65 +1,64 @@
 /*
-    comedi/drivers/cb_pcidas.c
+ * cb_pcidas.c
+ * Developed by Ivan Martinez and Frank Mori Hess, with valuable help from
+ * David Schleef and the rest of the Comedi developers comunity.
+ *
+ * Copyright (C) 2001-2003 Ivan Martinez <imr@oersted.dtu.dk>
+ * Copyright (C) 2001,2002 Frank Mori Hess <fmhess@users.sourceforge.net>
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
-    Developed by Ivan Martinez and Frank Mori Hess, with valuable help from
-    David Schleef and the rest of the Comedi developers comunity.
-
-    Copyright (C) 2001-2003 Ivan Martinez <imr@oersted.dtu.dk>
-    Copyright (C) 2001,2002 Frank Mori Hess <fmhess@users.sourceforge.net>
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
-/*
-Driver: cb_pcidas
-Description: MeasurementComputing PCI-DAS series
-  with the AMCC S5933 PCI controller
-Author: Ivan Martinez <imr@oersted.dtu.dk>,
-  Frank Mori Hess <fmhess@users.sourceforge.net>
-Updated: 2003-3-11
-Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas),
-  PCI-DAS1602/16jr, PCI-DAS1602/12, PCI-DAS1200, PCI-DAS1200jr,
-  PCI-DAS1000, PCI-DAS1001, PCI_DAS1002
-
-Status:
-  There are many reports of the driver being used with most of the
-  supported cards. Despite no detailed log is maintained, it can
-  be said that the driver is quite tested and stable.
-
-  The boards may be autocalibrated using the comedi_calibrate
-  utility.
-
-Configuration options: not applicable, uses PCI auto config
-
-For commands, the scanned channels must be consecutive
-(i.e. 4-5-6-7, 2-3-4,...), and must all have the same
-range and aref.
-
-AI Triggering:
-   For start_src == TRIG_EXT, the A/D EXTERNAL TRIGGER IN (pin 45) is used.
-   For 1602 series, the start_arg is interpreted as follows:
-     start_arg == 0                   => gated trigger (level high)
-     start_arg == CR_INVERT           => gated trigger (level low)
-     start_arg == CR_EDGE             => Rising edge
-     start_arg == CR_EDGE | CR_INVERT => Falling edge
-   For the other boards the trigger will be done on rising edge
-*/
 /*
+ * Driver: cb_pcidas
+ * Description: MeasurementComputing PCI-DAS series
+ *   with the AMCC S5933 PCI controller
+ * Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas),
+ *   PCI-DAS1602/16jr, PCI-DAS1602/12, PCI-DAS1200, PCI-DAS1200jr,
+ *   PCI-DAS1000, PCI-DAS1001, PCI_DAS1002
+ * Author: Ivan Martinez <imr@oersted.dtu.dk>,
+ *   Frank Mori Hess <fmhess@users.sourceforge.net>
+ * Updated: 2003-3-11
+ *
+ * Status:
+ * There are many reports of the driver being used with most of the
+ * supported cards. Despite no detailed log is maintained, it can
+ * be said that the driver is quite tested and stable.
+ *
+ * The boards may be autocalibrated using the comedi_calibrate
+ * utility.
+ *
+ * Configuration options: not applicable, uses PCI auto config
+ *
+ * For commands, the scanned channels must be consecutive
+ * (i.e. 4-5-6-7, 2-3-4,...), and must all have the same
+ * range and aref.
+ *
+ * AI Triggering:
+ * For start_src == TRIG_EXT, the A/D EXTERNAL TRIGGER IN (pin 45) is used.
+ * For 1602 series, the start_arg is interpreted as follows:
+ *     start_arg == 0                   => gated trigger (level high)
+ *     start_arg == CR_INVERT           => gated trigger (level low)
+ *     start_arg == CR_EDGE             => Rising edge
+ *     start_arg == CR_EDGE | CR_INVERT => Falling edge
+ * For the other boards the trigger will be done on rising edge
+ */
 
-TODO:
-
-analog triggering on 1602 series
-*/
+/*
+ * TODO:
+ * analog triggering on 1602 series
+ */
 
 #include <linux/module.h>
 #include <linux/delay.h>
@@ -73,109 +72,107 @@ analog triggering on 1602 series
 
 #define AI_BUFFER_SIZE         1024    /* max ai fifo size */
 #define AO_BUFFER_SIZE         1024    /* max ao fifo size */
-#define NUM_CHANNELS_8800      8
-#define NUM_CHANNELS_7376      1
-#define NUM_CHANNELS_8402      2
-#define NUM_CHANNELS_DAC08     1
-
-/* Control/Status registers */
-#define INT_ADCFIFO            0       /* INTERRUPT / ADC FIFO register */
-#define   INT_EOS              0x1     /* int end of scan */
-#define   INT_FHF              0x2     /* int fifo half full */
-#define   INT_FNE              0x3     /* int fifo not empty */
-#define   INT_MASK             0x3     /* mask of int select bits */
-#define   INTE                 0x4     /* int enable */
-#define   DAHFIE               0x8     /* dac half full int enable */
-#define   EOAIE                        0x10    /* end of acq. int enable */
-#define   DAHFI                        0x20    /* dac half full status / clear */
-#define   EOAI                 0x40    /* end of acq. int status / clear */
-#define   INT                  0x80    /* int status / clear */
-#define   EOBI                 0x200   /* end of burst int status */
-#define   ADHFI                        0x400   /* half-full int status */
-#define   ADNEI                        0x800   /* fifo not empty int status (latch) */
-#define   ADNE                 0x1000  /* fifo not empty status (realtime) */
-#define   DAEMIE               0x1000  /* dac empty int enable */
-#define   LADFUL               0x2000  /* fifo overflow / clear */
-#define   DAEMI                        0x4000  /* dac fifo empty int status / clear */
-
-#define ADCMUX_CONT            2       /* ADC CHANNEL MUX AND CONTROL reg */
-#define   BEGIN_SCAN(x)                ((x) & 0xf)
-#define   END_SCAN(x)          (((x) & 0xf) << 4)
-#define   GAIN_BITS(x)         (((x) & 0x3) << 8)
-#define   UNIP                 0x800   /* Analog front-end unipolar mode */
-#define   SE                   0x400   /* Inputs in single-ended mode */
-#define   PACER_MASK           0x3000  /* pacer source bits */
-#define   PACER_INT            0x1000  /* int. pacer */
-#define   PACER_EXT_FALL       0x2000  /* ext. falling edge */
-#define   PACER_EXT_RISE       0x3000  /* ext. rising edge */
-#define   EOC                  0x4000  /* adc not busy */
-
-#define TRIG_CONTSTAT           4      /* TRIGGER CONTROL/STATUS register */
-#define   SW_TRIGGER           0x1     /* software start trigger */
-#define   EXT_TRIGGER          0x2     /* ext. start trigger */
-#define   ANALOG_TRIGGER       0x3     /* ext. analog trigger */
-#define   TRIGGER_MASK         0x3     /* start trigger mask */
-#define   TGPOL                        0x04    /* invert trigger (1602 only) */
-#define   TGSEL                        0x08    /* edge/level trigerred (1602 only) */
-#define   TGEN                 0x10    /* enable external start trigger */
-#define   BURSTE               0x20    /* burst mode enable */
-#define   XTRCL                        0x80    /* clear external trigger */
-
-#define CALIBRATION_REG                6       /* CALIBRATION register */
-#define   SELECT_8800_BIT      0x100   /* select 8800 caldac */
-#define   SELECT_TRIMPOT_BIT   0x200   /* select ad7376 trim pot */
-#define   SELECT_DAC08_BIT     0x400   /* select dac08 caldac */
-#define   CAL_SRC_BITS(x)      (((x) & 0x7) << 11)
-#define   CAL_EN_BIT           0x4000  /* calibration source enable */
-#define   SERIAL_DATA_IN_BIT   0x8000  /* serial data bit going to caldac */
-
-#define DAC_CSR                        0x8     /* dac control and status register */
-#define   DACEN                        0x02    /* dac enable */
-#define   DAC_MODE_UPDATE_BOTH 0x80    /* update both dacs */
-
-static inline unsigned int DAC_RANGE(unsigned int channel, unsigned int range)
-{
-       return (range & 0x3) << (8 + 2 * (channel & 0x1));
-}
-
-static inline unsigned int DAC_RANGE_MASK(unsigned int channel)
-{
-       return 0x3 << (8 + 2 * (channel & 0x1));
-};
-
-/* bits for 1602 series only */
-#define   DAC_EMPTY            0x1     /* fifo empty, read, write clear */
-#define   DAC_START            0x4     /* start/arm fifo operations */
-#define   DAC_PACER_MASK       0x18    /* bits that set pacer source */
-#define   DAC_PACER_INT                0x8     /* int. pacing */
-#define   DAC_PACER_EXT_FALL   0x10    /* ext. pacing, falling edge */
-#define   DAC_PACER_EXT_RISE   0x18    /* ext. pacing, rising edge */
-
-static inline unsigned int DAC_CHAN_EN(unsigned int channel)
-{
-       return 1 << (5 + (channel & 0x1));      /*  enable channel 0 or 1 */
-};
-
-/* analog input fifo */
-#define ADCDATA                        0       /* ADC DATA register */
-#define ADCFIFOCLR             2       /* ADC FIFO CLEAR */
 
-/* pacer, counter, dio registers */
-#define ADC8254                        0
-#define DIO_8255               4
-#define DAC8254                        8
+/*
+ * PCI BAR1 Register map (devpriv->pcibar1)
+ */
+#define PCIDAS_CTRL_REG                0x00    /* INTERRUPT / ADC FIFO register */
+#define PCIDAS_CTRL_INT(x)     (((x) & 0x3) << 0)
+#define PCIDAS_CTRL_INT_NONE   PCIDAS_CTRL_INT(0) /* no int selected */
+#define PCIDAS_CTRL_INT_EOS    PCIDAS_CTRL_INT(1) /* int on end of scan */
+#define PCIDAS_CTRL_INT_FHF    PCIDAS_CTRL_INT(2) /* int on fifo half full */
+#define PCIDAS_CTRL_INT_FNE    PCIDAS_CTRL_INT(3) /* int on fifo not empty */
+#define PCIDAS_CTRL_INT_MASK   PCIDAS_CTRL_INT(3) /* mask of int select bits */
+#define PCIDAS_CTRL_INTE       BIT(2)  /* int enable */
+#define PCIDAS_CTRL_DAHFIE     BIT(3)  /* dac half full int enable */
+#define PCIDAS_CTRL_EOAIE      BIT(4)  /* end of acq. int enable */
+#define PCIDAS_CTRL_DAHFI      BIT(5)  /* dac half full status / clear */
+#define PCIDAS_CTRL_EOAI       BIT(6)  /* end of acq. int status / clear */
+#define PCIDAS_CTRL_INT_CLR    BIT(7)  /* int status / clear */
+#define PCIDAS_CTRL_EOBI       BIT(9)  /* end of burst int status */
+#define PCIDAS_CTRL_ADHFI      BIT(10) /* half-full int status */
+#define PCIDAS_CTRL_ADNEI      BIT(11) /* fifo not empty int status (latch) */
+#define PCIDAS_CTRL_ADNE       BIT(12) /* fifo not empty status (realtime) */
+#define PCIDAS_CTRL_DAEMIE     BIT(12) /* dac empty int enable */
+#define PCIDAS_CTRL_LADFUL     BIT(13) /* fifo overflow / clear */
+#define PCIDAS_CTRL_DAEMI      BIT(14) /* dac fifo empty int status / clear */
+
+#define PCIDAS_CTRL_AI_INT     (PCIDAS_CTRL_EOAI | PCIDAS_CTRL_EOBI |   \
+                                PCIDAS_CTRL_ADHFI | PCIDAS_CTRL_ADNEI | \
+                                PCIDAS_CTRL_LADFUL)
+#define PCIDAS_CTRL_AO_INT     (PCIDAS_CTRL_DAHFI | PCIDAS_CTRL_DAEMI)
+
+#define PCIDAS_AI_REG          0x02    /* ADC CHANNEL MUX AND CONTROL reg */
+#define PCIDAS_AI_FIRST(x)     ((x) & 0xf)
+#define PCIDAS_AI_LAST(x)      (((x) & 0xf) << 4)
+#define PCIDAS_AI_CHAN(x)      (PCIDAS_AI_FIRST(x) | PCIDAS_AI_LAST(x))
+#define PCIDAS_AI_GAIN(x)      (((x) & 0x3) << 8)
+#define PCIDAS_AI_SE           BIT(10) /* Inputs in single-ended mode */
+#define PCIDAS_AI_UNIP         BIT(11) /* Analog front-end unipolar mode */
+#define PCIDAS_AI_PACER(x)     (((x) & 0x3) << 12)
+#define PCIDAS_AI_PACER_SW     PCIDAS_AI_PACER(0) /* software pacer */
+#define PCIDAS_AI_PACER_INT    PCIDAS_AI_PACER(1) /* int. pacer */
+#define PCIDAS_AI_PACER_EXTN   PCIDAS_AI_PACER(2) /* ext. falling edge */
+#define PCIDAS_AI_PACER_EXTP   PCIDAS_AI_PACER(3) /* ext. rising edge */
+#define PCIDAS_AI_PACER_MASK   PCIDAS_AI_PACER(3) /* pacer source bits */
+#define PCIDAS_AI_EOC          BIT(14) /* adc not busy */
+
+#define PCIDAS_TRIG_REG                0x04    /* TRIGGER CONTROL/STATUS register */
+#define PCIDAS_TRIG_SEL(x)     (((x) & 0x3) << 0)
+#define PCIDAS_TRIG_SEL_NONE   PCIDAS_TRIG_SEL(0) /* no start trigger */
+#define PCIDAS_TRIG_SEL_SW     PCIDAS_TRIG_SEL(1) /* software start trigger */
+#define PCIDAS_TRIG_SEL_EXT    PCIDAS_TRIG_SEL(2) /* ext. start trigger */
+#define PCIDAS_TRIG_SEL_ANALOG PCIDAS_TRIG_SEL(3) /* ext. analog trigger */
+#define PCIDAS_TRIG_SEL_MASK   PCIDAS_TRIG_SEL(3) /* start trigger mask */
+#define PCIDAS_TRIG_POL                BIT(2)  /* invert trigger (1602 only) */
+#define PCIDAS_TRIG_MODE       BIT(3)  /* edge/level trigerred (1602 only) */
+#define PCIDAS_TRIG_EN         BIT(4)  /* enable external start trigger */
+#define PCIDAS_TRIG_BURSTE     BIT(5)  /* burst mode enable */
+#define PCIDAS_TRIG_CLR                BIT(7)  /* clear external trigger */
+
+#define PCIDAS_CALIB_REG       0x06    /* CALIBRATION register */
+#define PCIDAS_CALIB_8800_SEL  BIT(8)  /* select 8800 caldac */
+#define PCIDAS_CALIB_TRIM_SEL  BIT(9)  /* select ad7376 trim pot */
+#define PCIDAS_CALIB_DAC08_SEL BIT(10) /* select dac08 caldac */
+#define PCIDAS_CALIB_SRC(x)    (((x) & 0x7) << 11)
+#define PCIDAS_CALIB_EN                BIT(14) /* calibration source enable */
+#define PCIDAS_CALIB_DATA      BIT(15) /* serial data bit going to caldac */
+
+#define PCIDAS_AO_REG          0x08    /* dac control and status register */
+#define PCIDAS_AO_EMPTY                BIT(0)  /* fifo empty, write clear (1602) */
+#define PCIDAS_AO_DACEN                BIT(1)  /* dac enable */
+#define PCIDAS_AO_START                BIT(2)  /* start/arm fifo (1602) */
+#define PCIDAS_AO_PACER(x)     (((x) & 0x3) << 3) /* (1602) */
+#define PCIDAS_AO_PACER_SW     PCIDAS_AO_PACER(0) /* software pacer */
+#define PCIDAS_AO_PACER_INT    PCIDAS_AO_PACER(1) /* int. pacer */
+#define PCIDAS_AO_PACER_EXTN   PCIDAS_AO_PACER(2) /* ext. falling edge */
+#define PCIDAS_AO_PACER_EXTP   PCIDAS_AO_PACER(3) /* ext. rising edge */
+#define PCIDAS_AO_PACER_MASK   PCIDAS_AO_PACER(3) /* pacer source bits */
+#define PCIDAS_AO_CHAN_EN(c)   BIT(5 + ((c) & 0x1))
+#define PCIDAS_AO_CHAN_MASK    (PCIDAS_AO_CHAN_EN(0) | PCIDAS_AO_CHAN_EN(1))
+#define PCIDAS_AO_UPDATE_BOTH  BIT(7)  /* update both dacs */
+#define PCIDAS_AO_RANGE(c, r)  (((r) & 0x3) << (8 + 2 * ((c) & 0x1)))
+#define PCIDAS_AO_RANGE_MASK(c)        PCIDAS_AO_RANGE((c), 0x3)
 
-/* analog output registers for 100x, 1200 series */
-static inline unsigned int DAC_DATA_REG(unsigned int channel)
-{
-       return 2 * (channel & 0x1);
-}
+/*
+ * PCI BAR2 Register map (devpriv->pcibar2)
+ */
+#define PCIDAS_AI_DATA_REG     0x00
+#define PCIDAS_AI_FIFO_CLR_REG 0x02
 
-/* analog output registers for 1602 series*/
-#define DACDATA                        0       /* DAC DATA register */
-#define DACFIFOCLR             2       /* DAC FIFO CLEAR */
+/*
+ * PCI BAR3 Register map (dev->iobase)
+ */
+#define PCIDAS_AI_8254_BASE    0x00
+#define PCIDAS_8255_BASE       0x04
+#define PCIDAS_AO_8254_BASE    0x08
 
-#define IS_UNIPOLAR            0x4     /* unipolar range mask */
+/*
+ * PCI BAR4 Register map (devpriv->pcibar4)
+ */
+#define PCIDAS_AO_DATA_REG(x)  (0x00 + ((x) * 2))
+#define PCIDAS_AO_FIFO_REG     0x00
+#define PCIDAS_AO_FIFO_CLR_REG 0x02
 
 /* analog input ranges for most boards */
 static const struct comedi_lrange cb_pcidas_ranges = {
@@ -215,11 +212,6 @@ static const struct comedi_lrange cb_pcidas_ao_ranges = {
        }
 };
 
-enum trimpot_model {
-       AD7376,
-       AD8402,
-};
-
 enum cb_pcidas_boardid {
        BOARD_PCIDAS1602_16,
        BOARD_PCIDAS1200,
@@ -233,132 +225,97 @@ enum cb_pcidas_boardid {
 
 struct cb_pcidas_board {
        const char *name;
-       int ai_nchan;           /*  Inputs in single-ended mode */
-       int ai_bits;            /*  analog input resolution */
        int ai_speed;           /*  fastest conversion period in ns */
-       int ao_nchan;           /*  number of analog out channels */
-       int has_ao_fifo;        /*  analog output has fifo */
        int ao_scan_speed;      /*  analog output scan speed for 1602 series */
        int fifo_size;          /*  number of samples fifo can hold */
-       const struct comedi_lrange *ranges;
-       enum trimpot_model trimpot;
-       unsigned has_dac08:1;
-       unsigned is_1602:1;
+       unsigned int is_16bit;          /* ai/ao is 1=16-bit; 0=12-bit */
+       unsigned int use_alt_range:1;   /* use alternate ai range table */
+       unsigned int has_ao:1;          /* has 2 analog output channels */
+       unsigned int has_ao_fifo:1;     /* analog output has fifo */
+       unsigned int has_ad8402:1;      /* trimpot type 1=AD8402; 0=AD7376 */
+       unsigned int has_dac08:1;
+       unsigned int is_1602:1;
 };
 
 static const struct cb_pcidas_board cb_pcidas_boards[] = {
        [BOARD_PCIDAS1602_16] = {
                .name           = "pci-das1602/16",
-               .ai_nchan       = 16,
-               .ai_bits        = 16,
                .ai_speed       = 5000,
-               .ao_nchan       = 2,
-               .has_ao_fifo    = 1,
                .ao_scan_speed  = 10000,
                .fifo_size      = 512,
-               .ranges         = &cb_pcidas_ranges,
-               .trimpot        = AD8402,
+               .is_16bit       = 1,
+               .has_ao         = 1,
+               .has_ao_fifo    = 1,
+               .has_ad8402     = 1,
                .has_dac08      = 1,
                .is_1602        = 1,
        },
        [BOARD_PCIDAS1200] = {
                .name           = "pci-das1200",
-               .ai_nchan       = 16,
-               .ai_bits        = 12,
                .ai_speed       = 3200,
-               .ao_nchan       = 2,
                .fifo_size      = 1024,
-               .ranges         = &cb_pcidas_ranges,
-               .trimpot        = AD7376,
+               .has_ao         = 1,
        },
        [BOARD_PCIDAS1602_12] = {
                .name           = "pci-das1602/12",
-               .ai_nchan       = 16,
-               .ai_bits        = 12,
                .ai_speed       = 3200,
-               .ao_nchan       = 2,
-               .has_ao_fifo    = 1,
                .ao_scan_speed  = 4000,
                .fifo_size      = 1024,
-               .ranges         = &cb_pcidas_ranges,
-               .trimpot        = AD7376,
+               .has_ao         = 1,
+               .has_ao_fifo    = 1,
                .is_1602        = 1,
        },
        [BOARD_PCIDAS1200_JR] = {
                .name           = "pci-das1200/jr",
-               .ai_nchan       = 16,
-               .ai_bits        = 12,
                .ai_speed       = 3200,
                .fifo_size      = 1024,
-               .ranges         = &cb_pcidas_ranges,
-               .trimpot        = AD7376,
        },
        [BOARD_PCIDAS1602_16_JR] = {
                .name           = "pci-das1602/16/jr",
-               .ai_nchan       = 16,
-               .ai_bits        = 16,
                .ai_speed       = 5000,
                .fifo_size      = 512,
-               .ranges         = &cb_pcidas_ranges,
-               .trimpot        = AD8402,
+               .is_16bit       = 1,
+               .has_ad8402     = 1,
                .has_dac08      = 1,
                .is_1602        = 1,
        },
        [BOARD_PCIDAS1000] = {
                .name           = "pci-das1000",
-               .ai_nchan       = 16,
-               .ai_bits        = 12,
                .ai_speed       = 4000,
                .fifo_size      = 1024,
-               .ranges         = &cb_pcidas_ranges,
-               .trimpot        = AD7376,
        },
        [BOARD_PCIDAS1001] = {
                .name           = "pci-das1001",
-               .ai_nchan       = 16,
-               .ai_bits        = 12,
                .ai_speed       = 6800,
-               .ao_nchan       = 2,
                .fifo_size      = 1024,
-               .ranges         = &cb_pcidas_alt_ranges,
-               .trimpot        = AD7376,
+               .use_alt_range  = 1,
+               .has_ao         = 1,
        },
        [BOARD_PCIDAS1002] = {
                .name           = "pci-das1002",
-               .ai_nchan       = 16,
-               .ai_bits        = 12,
                .ai_speed       = 6800,
-               .ao_nchan       = 2,
                .fifo_size      = 1024,
-               .ranges         = &cb_pcidas_ranges,
-               .trimpot        = AD7376,
+               .has_ao         = 1,
        },
 };
 
 struct cb_pcidas_private {
        struct comedi_8254 *ao_pacer;
        /* base addresses */
-       unsigned long s5933_config;
-       unsigned long control_status;
-       unsigned long adc_fifo;
-       unsigned long ao_registers;
+       unsigned long amcc;     /* pcibar0 */
+       unsigned long pcibar1;
+       unsigned long pcibar2;
+       unsigned long pcibar4;
        /* bits to write to registers */
-       unsigned int adc_fifo_bits;
-       unsigned int s5933_intcsr_bits;
-       unsigned int ao_control_bits;
+       unsigned int ctrl;
+       unsigned int amcc_intcsr;
+       unsigned int ao_ctrl;
        /* fifo buffers */
        unsigned short ai_buffer[AI_BUFFER_SIZE];
        unsigned short ao_buffer[AO_BUFFER_SIZE];
-       unsigned int calibration_source;
+       unsigned int calib_src;
 };
 
-static inline unsigned int cal_enable_bits(struct comedi_device *dev)
-{
-       struct cb_pcidas_private *devpriv = dev->private;
-
-       return CAL_EN_BIT | CAL_SRC_BITS(devpriv->calibration_source);
-}
-
 static int cb_pcidas_ai_eoc(struct comedi_device *dev,
                            struct comedi_subdevice *s,
                            struct comedi_insn *insn,
@@ -367,15 +324,16 @@ static int cb_pcidas_ai_eoc(struct comedi_device *dev,
        struct cb_pcidas_private *devpriv = dev->private;
        unsigned int status;
 
-       status = inw(devpriv->control_status + ADCMUX_CONT);
-       if (status & EOC)
+       status = inw(devpriv->pcibar1 + PCIDAS_AI_REG);
+       if (status & PCIDAS_AI_EOC)
                return 0;
        return -EBUSY;
 }
 
-static int cb_pcidas_ai_rinsn(struct comedi_device *dev,
-                             struct comedi_subdevice *s,
-                             struct comedi_insn *insn, unsigned int *data)
+static int cb_pcidas_ai_insn_read(struct comedi_device *dev,
+                                 struct comedi_subdevice *s,
+                                 struct comedi_insn *insn,
+                                 unsigned int *data)
 {
        struct cb_pcidas_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
@@ -387,30 +345,30 @@ static int cb_pcidas_ai_rinsn(struct comedi_device *dev,
 
        /* enable calibration input if appropriate */
        if (insn->chanspec & CR_ALT_SOURCE) {
-               outw(cal_enable_bits(dev),
-                    devpriv->control_status + CALIBRATION_REG);
+               outw(PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src),
+                    devpriv->pcibar1 + PCIDAS_CALIB_REG);
                chan = 0;
        } else {
-               outw(0, devpriv->control_status + CALIBRATION_REG);
+               outw(0, devpriv->pcibar1 + PCIDAS_CALIB_REG);
        }
 
        /* set mux limits and gain */
-       bits = BEGIN_SCAN(chan) | END_SCAN(chan) | GAIN_BITS(range);
+       bits = PCIDAS_AI_CHAN(chan) | PCIDAS_AI_GAIN(range);
        /* set unipolar/bipolar */
-       if (range & IS_UNIPOLAR)
-               bits |= UNIP;
+       if (comedi_range_is_unipolar(s, range))
+               bits |= PCIDAS_AI_UNIP;
        /* set single-ended/differential */
        if (aref != AREF_DIFF)
-               bits |= SE;
-       outw(bits, devpriv->control_status + ADCMUX_CONT);
+               bits |= PCIDAS_AI_SE;
+       outw(bits, devpriv->pcibar1 + PCIDAS_AI_REG);
 
        /* clear fifo */
-       outw(0, devpriv->adc_fifo + ADCFIFOCLR);
+       outw(0, devpriv->pcibar2 + PCIDAS_AI_FIFO_CLR_REG);
 
        /* convert n samples */
        for (n = 0; n < insn->n; n++) {
                /* trigger conversion */
-               outw(0, devpriv->adc_fifo + ADCDATA);
+               outw(0, devpriv->pcibar2 + PCIDAS_AI_DATA_REG);
 
                /* wait for conversion to end */
                ret = comedi_timeout(dev, s, insn, cb_pcidas_ai_eoc, 0);
@@ -418,15 +376,17 @@ static int cb_pcidas_ai_rinsn(struct comedi_device *dev,
                        return ret;
 
                /* read data */
-               data[n] = inw(devpriv->adc_fifo + ADCDATA);
+               data[n] = inw(devpriv->pcibar2 + PCIDAS_AI_DATA_REG);
        }
 
        /* return the number of samples read/written */
        return n;
 }
 
-static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data)
+static int cb_pcidas_ai_insn_config(struct comedi_device *dev,
+                                   struct comedi_subdevice *s,
+                                   struct comedi_insn *insn,
+                                   unsigned int *data)
 {
        struct cb_pcidas_private *devpriv = dev->private;
        int id = data[0];
@@ -440,7 +400,7 @@ static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s,
                                source);
                        return -EINVAL;
                }
-               devpriv->calibration_source = source;
+               devpriv->calib_src = source;
                break;
        default:
                return -EINVAL;
@@ -449,155 +409,160 @@ static int ai_config_insn(struct comedi_device *dev, struct comedi_subdevice *s,
 }
 
 /* analog output insn for pcidas-1000 and 1200 series */
-static int cb_pcidas_ao_nofifo_winsn(struct comedi_device *dev,
-                                    struct comedi_subdevice *s,
-                                    struct comedi_insn *insn,
-                                    unsigned int *data)
+static int cb_pcidas_ao_nofifo_insn_write(struct comedi_device *dev,
+                                         struct comedi_subdevice *s,
+                                         struct comedi_insn *insn,
+                                         unsigned int *data)
 {
        struct cb_pcidas_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
+       unsigned int val = s->readback[chan];
        unsigned long flags;
+       int i;
 
        /* set channel and range */
        spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->ao_control_bits &= (~DAC_MODE_UPDATE_BOTH &
-                                    ~DAC_RANGE_MASK(chan));
-       devpriv->ao_control_bits |= (DACEN | DAC_RANGE(chan, range));
-       outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR);
+       devpriv->ao_ctrl &= ~(PCIDAS_AO_UPDATE_BOTH |
+                             PCIDAS_AO_RANGE_MASK(chan));
+       devpriv->ao_ctrl |= PCIDAS_AO_DACEN | PCIDAS_AO_RANGE(chan, range);
+       outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
-       /* remember value for readback */
-       s->readback[chan] = data[0];
+       for (i = 0; i < insn->n; i++) {
+               val = data[i];
+               outw(val, devpriv->pcibar4 + PCIDAS_AO_DATA_REG(chan));
+       }
 
-       /* send data */
-       outw(data[0], devpriv->ao_registers + DAC_DATA_REG(chan));
+       s->readback[chan] = val;
 
        return insn->n;
 }
 
 /* analog output insn for pcidas-1602 series */
-static int cb_pcidas_ao_fifo_winsn(struct comedi_device *dev,
-                                  struct comedi_subdevice *s,
-                                  struct comedi_insn *insn, unsigned int *data)
+static int cb_pcidas_ao_fifo_insn_write(struct comedi_device *dev,
+                                       struct comedi_subdevice *s,
+                                       struct comedi_insn *insn,
+                                       unsigned int *data)
 {
        struct cb_pcidas_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
+       unsigned int val = s->readback[chan];
        unsigned long flags;
+       int i;
 
        /* clear dac fifo */
-       outw(0, devpriv->ao_registers + DACFIFOCLR);
+       outw(0, devpriv->pcibar4 + PCIDAS_AO_FIFO_CLR_REG);
 
        /* set channel and range */
        spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->ao_control_bits &= (~DAC_CHAN_EN(0) & ~DAC_CHAN_EN(1) &
-                                    ~DAC_RANGE_MASK(chan) & ~DAC_PACER_MASK);
-       devpriv->ao_control_bits |= (DACEN | DAC_RANGE(chan, range) |
-                                    DAC_CHAN_EN(chan) | DAC_START);
-       outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR);
+       devpriv->ao_ctrl &= ~(PCIDAS_AO_CHAN_MASK | PCIDAS_AO_RANGE_MASK(chan) |
+                             PCIDAS_AO_PACER_MASK);
+       devpriv->ao_ctrl |= PCIDAS_AO_DACEN | PCIDAS_AO_RANGE(chan, range) |
+                           PCIDAS_AO_CHAN_EN(chan) | PCIDAS_AO_START;
+       outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
-       /* remember value for readback */
-       s->readback[chan] = data[0];
+       for (i = 0; i < insn->n; i++) {
+               val = data[i];
+               outw(val, devpriv->pcibar4 + PCIDAS_AO_FIFO_REG);
+       }
 
-       /* send data */
-       outw(data[0], devpriv->ao_registers + DACDATA);
+       s->readback[chan] = val;
 
        return insn->n;
 }
 
-static int wait_for_nvram_ready(unsigned long s5933_base_addr)
+static int cb_pcidas_eeprom_ready(struct comedi_device *dev,
+                                 struct comedi_subdevice *s,
+                                 struct comedi_insn *insn,
+                                 unsigned long context)
 {
-       static const int timeout = 1000;
-       unsigned int i;
+       struct cb_pcidas_private *devpriv = dev->private;
+       unsigned int status;
 
-       for (i = 0; i < timeout; i++) {
-               if ((inb(s5933_base_addr +
-                        AMCC_OP_REG_MCSR_NVCMD) & MCSR_NV_BUSY)
-                   == 0)
-                       return 0;
-               udelay(1);
-       }
-       return -1;
+       status = inb(devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD);
+       if ((status & MCSR_NV_BUSY) == 0)
+               return 0;
+       return -EBUSY;
 }
 
-static int nvram_read(struct comedi_device *dev, unsigned int address,
-                     uint8_t *data)
+static int cb_pcidas_eeprom_insn_read(struct comedi_device *dev,
+                                     struct comedi_subdevice *s,
+                                     struct comedi_insn *insn,
+                                     unsigned int *data)
 {
        struct cb_pcidas_private *devpriv = dev->private;
-       unsigned long iobase = devpriv->s5933_config;
-
-       if (wait_for_nvram_ready(iobase) < 0)
-               return -ETIMEDOUT;
-
-       outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR,
-            iobase + AMCC_OP_REG_MCSR_NVCMD);
-       outb(address & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA);
-       outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR,
-            iobase + AMCC_OP_REG_MCSR_NVCMD);
-       outb((address >> 8) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA);
-       outb(MCSR_NV_ENABLE | MCSR_NV_READ, iobase + AMCC_OP_REG_MCSR_NVCMD);
-
-       if (wait_for_nvram_ready(iobase) < 0)
-               return -ETIMEDOUT;
-
-       *data = inb(iobase + AMCC_OP_REG_MCSR_NVDATA);
-
-       return 0;
-}
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       int ret;
+       int i;
 
-static int eeprom_read_insn(struct comedi_device *dev,
-                           struct comedi_subdevice *s,
-                           struct comedi_insn *insn, unsigned int *data)
-{
-       uint8_t nvram_data;
-       int retval;
+       for (i = 0; i < insn->n; i++) {
+               /* make sure eeprom is ready */
+               ret = comedi_timeout(dev, s, insn, cb_pcidas_eeprom_ready, 0);
+               if (ret)
+                       return ret;
 
-       retval = nvram_read(dev, CR_CHAN(insn->chanspec), &nvram_data);
-       if (retval < 0)
-               return retval;
+               /* set address (chan) and read operation */
+               outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_LOW_ADDR,
+                    devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD);
+               outb(chan & 0xff, devpriv->amcc + AMCC_OP_REG_MCSR_NVDATA);
+               outb(MCSR_NV_ENABLE | MCSR_NV_LOAD_HIGH_ADDR,
+                    devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD);
+               outb((chan >> 8) & 0xff,
+                    devpriv->amcc + AMCC_OP_REG_MCSR_NVDATA);
+               outb(MCSR_NV_ENABLE | MCSR_NV_READ,
+                    devpriv->amcc + AMCC_OP_REG_MCSR_NVCMD);
+
+               /* wait for data to be returned */
+               ret = comedi_timeout(dev, s, insn, cb_pcidas_eeprom_ready, 0);
+               if (ret)
+                       return ret;
 
-       data[0] = nvram_data;
+               data[i] = inb(devpriv->amcc + AMCC_OP_REG_MCSR_NVDATA);
+       }
 
-       return 1;
+       return insn->n;
 }
 
-static void write_calibration_bitstream(struct comedi_device *dev,
-                                       unsigned int register_bits,
-                                       unsigned int bitstream,
-                                       unsigned int bitstream_length)
+static void cb_pcidas_calib_write(struct comedi_device *dev,
+                                 unsigned int val, unsigned int len,
+                                 bool trimpot)
 {
        struct cb_pcidas_private *devpriv = dev->private;
-       static const int write_delay = 1;
+       unsigned int calib_bits;
        unsigned int bit;
 
-       for (bit = 1 << (bitstream_length - 1); bit; bit >>= 1) {
-               if (bitstream & bit)
-                       register_bits |= SERIAL_DATA_IN_BIT;
+       calib_bits = PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src);
+       if (trimpot) {
+               /* select trimpot */
+               calib_bits |= PCIDAS_CALIB_TRIM_SEL;
+               outw(calib_bits, devpriv->pcibar1 + PCIDAS_CALIB_REG);
+       }
+
+       /* write bitstream to calibration device */
+       for (bit = 1 << (len - 1); bit; bit >>= 1) {
+               if (val & bit)
+                       calib_bits |= PCIDAS_CALIB_DATA;
                else
-                       register_bits &= ~SERIAL_DATA_IN_BIT;
-               udelay(write_delay);
-               outw(register_bits, devpriv->control_status + CALIBRATION_REG);
+                       calib_bits &= ~PCIDAS_CALIB_DATA;
+               udelay(1);
+               outw(calib_bits, devpriv->pcibar1 + PCIDAS_CALIB_REG);
        }
-}
+       udelay(1);
 
-static void caldac_8800_write(struct comedi_device *dev,
-                             unsigned int chan, uint8_t val)
-{
-       struct cb_pcidas_private *devpriv = dev->private;
-       static const int bitstream_length = 11;
-       unsigned int bitstream = ((chan & 0x7) << 8) | val;
-       static const int caldac_8800_udelay = 1;
-
-       write_calibration_bitstream(dev, cal_enable_bits(dev), bitstream,
-                                   bitstream_length);
-
-       udelay(caldac_8800_udelay);
-       outw(cal_enable_bits(dev) | SELECT_8800_BIT,
-            devpriv->control_status + CALIBRATION_REG);
-       udelay(caldac_8800_udelay);
-       outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG);
+       calib_bits = PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src);
+
+       if (!trimpot) {
+               /* select caldac */
+               outw(calib_bits | PCIDAS_CALIB_8800_SEL,
+                    devpriv->pcibar1 + PCIDAS_CALIB_REG);
+               udelay(1);
+       }
+
+       /* latch value to trimpot/caldac */
+       outw(calib_bits, devpriv->pcibar1 + PCIDAS_CALIB_REG);
 }
 
 static int cb_pcidas_caldac_insn_write(struct comedi_device *dev,
@@ -611,7 +576,9 @@ static int cb_pcidas_caldac_insn_write(struct comedi_device *dev,
                unsigned int val = data[insn->n - 1];
 
                if (s->readback[chan] != val) {
-                       caldac_8800_write(dev, chan, val);
+                       /* write 11-bit channel/value to caldac */
+                       cb_pcidas_calib_write(dev, (chan << 8) | val, 11,
+                                             false);
                        s->readback[chan] = val;
                }
        }
@@ -619,21 +586,19 @@ static int cb_pcidas_caldac_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-/* 1602/16 pregain offset */
-static void dac08_write(struct comedi_device *dev, unsigned int value)
+static void cb_pcidas_dac08_write(struct comedi_device *dev, unsigned int val)
 {
        struct cb_pcidas_private *devpriv = dev->private;
 
-       value &= 0xff;
-       value |= cal_enable_bits(dev);
+       val |= PCIDAS_CALIB_EN | PCIDAS_CALIB_SRC(devpriv->calib_src);
 
        /* latch the new value into the caldac */
-       outw(value, devpriv->control_status + CALIBRATION_REG);
+       outw(val, devpriv->pcibar1 + PCIDAS_CALIB_REG);
        udelay(1);
-       outw(value | SELECT_DAC08_BIT,
-            devpriv->control_status + CALIBRATION_REG);
+       outw(val | PCIDAS_CALIB_DAC08_SEL,
+            devpriv->pcibar1 + PCIDAS_CALIB_REG);
        udelay(1);
-       outw(value, devpriv->control_status + CALIBRATION_REG);
+       outw(val, devpriv->pcibar1 + PCIDAS_CALIB_REG);
        udelay(1);
 }
 
@@ -648,7 +613,7 @@ static int cb_pcidas_dac08_insn_write(struct comedi_device *dev,
                unsigned int val = data[insn->n - 1];
 
                if (s->readback[chan] != val) {
-                       dac08_write(dev, val);
+                       cb_pcidas_dac08_write(dev, val);
                        s->readback[chan] = val;
                }
        }
@@ -656,67 +621,17 @@ static int cb_pcidas_dac08_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-static int trimpot_7376_write(struct comedi_device *dev, uint8_t value)
-{
-       struct cb_pcidas_private *devpriv = dev->private;
-       static const int bitstream_length = 7;
-       unsigned int bitstream = value & 0x7f;
-       unsigned int register_bits;
-       static const int ad7376_udelay = 1;
-
-       register_bits = cal_enable_bits(dev) | SELECT_TRIMPOT_BIT;
-       udelay(ad7376_udelay);
-       outw(register_bits, devpriv->control_status + CALIBRATION_REG);
-
-       write_calibration_bitstream(dev, register_bits, bitstream,
-                                   bitstream_length);
-
-       udelay(ad7376_udelay);
-       outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG);
-
-       return 0;
-}
-
-/* For 1602/16 only
- * ch 0 : adc gain
- * ch 1 : adc postgain offset */
-static int trimpot_8402_write(struct comedi_device *dev, unsigned int channel,
-                             uint8_t value)
-{
-       struct cb_pcidas_private *devpriv = dev->private;
-       static const int bitstream_length = 10;
-       unsigned int bitstream = ((channel & 0x3) << 8) | (value & 0xff);
-       unsigned int register_bits;
-       static const int ad8402_udelay = 1;
-
-       register_bits = cal_enable_bits(dev) | SELECT_TRIMPOT_BIT;
-       udelay(ad8402_udelay);
-       outw(register_bits, devpriv->control_status + CALIBRATION_REG);
-
-       write_calibration_bitstream(dev, register_bits, bitstream,
-                                   bitstream_length);
-
-       udelay(ad8402_udelay);
-       outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG);
-
-       return 0;
-}
-
 static void cb_pcidas_trimpot_write(struct comedi_device *dev,
                                    unsigned int chan, unsigned int val)
 {
        const struct cb_pcidas_board *board = dev->board_ptr;
 
-       switch (board->trimpot) {
-       case AD7376:
-               trimpot_7376_write(dev, val);
-               break;
-       case AD8402:
-               trimpot_8402_write(dev, chan, val);
-               break;
-       default:
-               dev_err(dev->class_dev, "driver bug?\n");
-               break;
+       if (board->has_ad8402) {
+               /* write 10-bit channel/value to AD8402 trimpot */
+               cb_pcidas_calib_write(dev, (chan << 8) | val, 10, true);
+       } else {
+               /* write 7-bit value to AD7376 trimpot */
+               cb_pcidas_calib_write(dev, val, 7, true);
        }
 }
 
@@ -883,32 +798,33 @@ static int cb_pcidas_ai_cmd(struct comedi_device *dev,
        struct cb_pcidas_private *devpriv = dev->private;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
+       unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
        unsigned int bits;
        unsigned long flags;
 
-       /*  make sure CAL_EN_BIT is disabled */
-       outw(0, devpriv->control_status + CALIBRATION_REG);
+       /*  make sure PCIDAS_CALIB_EN is disabled */
+       outw(0, devpriv->pcibar1 + PCIDAS_CALIB_REG);
        /*  initialize before settings pacer source and count values */
-       outw(0, devpriv->control_status + TRIG_CONTSTAT);
+       outw(PCIDAS_TRIG_SEL_NONE, devpriv->pcibar1 + PCIDAS_TRIG_REG);
        /*  clear fifo */
-       outw(0, devpriv->adc_fifo + ADCFIFOCLR);
+       outw(0, devpriv->pcibar2 + PCIDAS_AI_FIFO_CLR_REG);
 
        /*  set mux limits, gain and pacer source */
-       bits = BEGIN_SCAN(CR_CHAN(cmd->chanlist[0])) |
-           END_SCAN(CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1])) |
-           GAIN_BITS(CR_RANGE(cmd->chanlist[0]));
+       bits = PCIDAS_AI_FIRST(CR_CHAN(cmd->chanlist[0])) |
+              PCIDAS_AI_LAST(CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1])) |
+              PCIDAS_AI_GAIN(range0);
        /*  set unipolar/bipolar */
-       if (CR_RANGE(cmd->chanlist[0]) & IS_UNIPOLAR)
-               bits |= UNIP;
+       if (comedi_range_is_unipolar(s, range0))
+               bits |= PCIDAS_AI_UNIP;
        /*  set singleended/differential */
        if (CR_AREF(cmd->chanlist[0]) != AREF_DIFF)
-               bits |= SE;
+               bits |= PCIDAS_AI_SE;
        /*  set pacer source */
        if (cmd->convert_src == TRIG_EXT || cmd->scan_begin_src == TRIG_EXT)
-               bits |= PACER_EXT_RISE;
+               bits |= PCIDAS_AI_PACER_EXTP;
        else
-               bits |= PACER_INT;
-       outw(bits, devpriv->control_status + ADCMUX_CONT);
+               bits |= PCIDAS_AI_PACER_INT;
+       outw(bits, devpriv->pcibar1 + PCIDAS_AI_REG);
 
        /*  load counters */
        if (cmd->scan_begin_src == TRIG_TIMER ||
@@ -919,42 +835,43 @@ static int cb_pcidas_ai_cmd(struct comedi_device *dev,
 
        /*  enable interrupts */
        spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->adc_fifo_bits |= INTE;
-       devpriv->adc_fifo_bits &= ~INT_MASK;
+       devpriv->ctrl |= PCIDAS_CTRL_INTE;
+       devpriv->ctrl &= ~PCIDAS_CTRL_INT_MASK;
        if (cmd->flags & CMDF_WAKE_EOS) {
                if (cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1) {
                        /* interrupt end of burst */
-                       devpriv->adc_fifo_bits |= INT_EOS;
+                       devpriv->ctrl |= PCIDAS_CTRL_INT_EOS;
                } else {
                        /* interrupt fifo not empty */
-                       devpriv->adc_fifo_bits |= INT_FNE;
+                       devpriv->ctrl |= PCIDAS_CTRL_INT_FNE;
                }
        } else {
                /* interrupt fifo half full */
-               devpriv->adc_fifo_bits |= INT_FHF;
+               devpriv->ctrl |= PCIDAS_CTRL_INT_FHF;
        }
 
        /*  enable (and clear) interrupts */
-       outw(devpriv->adc_fifo_bits | EOAI | INT | LADFUL,
-            devpriv->control_status + INT_ADCFIFO);
+       outw(devpriv->ctrl |
+            PCIDAS_CTRL_EOAI | PCIDAS_CTRL_INT_CLR | PCIDAS_CTRL_LADFUL,
+            devpriv->pcibar1 + PCIDAS_CTRL_REG);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        /*  set start trigger and burst mode */
        bits = 0;
        if (cmd->start_src == TRIG_NOW) {
-               bits |= SW_TRIGGER;
+               bits |= PCIDAS_TRIG_SEL_SW;
        } else {        /* TRIG_EXT */
-               bits |= EXT_TRIGGER | TGEN | XTRCL;
+               bits |= PCIDAS_TRIG_SEL_EXT | PCIDAS_TRIG_EN | PCIDAS_TRIG_CLR;
                if (board->is_1602) {
                        if (cmd->start_arg & CR_INVERT)
-                               bits |= TGPOL;
+                               bits |= PCIDAS_TRIG_POL;
                        if (cmd->start_arg & CR_EDGE)
-                               bits |= TGSEL;
+                               bits |= PCIDAS_TRIG_MODE;
                }
        }
        if (cmd->convert_src == TRIG_NOW && cmd->chanlist_len > 1)
-               bits |= BURSTE;
-       outw(bits, devpriv->control_status + TRIG_CONTSTAT);
+               bits |= PCIDAS_TRIG_BURSTE;
+       outw(bits, devpriv->pcibar1 + PCIDAS_TRIG_REG);
 
        return 0;
 }
@@ -1051,23 +968,21 @@ static int cb_pcidas_ao_cmdtest(struct comedi_device *dev,
        return 0;
 }
 
-/* cancel analog input command */
-static int cb_pcidas_cancel(struct comedi_device *dev,
-                           struct comedi_subdevice *s)
+static int cb_pcidas_ai_cancel(struct comedi_device *dev,
+                              struct comedi_subdevice *s)
 {
        struct cb_pcidas_private *devpriv = dev->private;
        unsigned long flags;
 
        spin_lock_irqsave(&dev->spinlock, flags);
        /*  disable interrupts */
-       devpriv->adc_fifo_bits &= ~INTE & ~EOAIE;
-       outw(devpriv->adc_fifo_bits, devpriv->control_status + INT_ADCFIFO);
+       devpriv->ctrl &= ~(PCIDAS_CTRL_INTE | PCIDAS_CTRL_EOAIE);
+       outw(devpriv->ctrl, devpriv->pcibar1 + PCIDAS_CTRL_REG);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        /*  disable start trigger source and burst mode */
-       outw(0, devpriv->control_status + TRIG_CONTSTAT);
-       /*  software pacer source */
-       outw(0, devpriv->control_status + ADCMUX_CONT);
+       outw(PCIDAS_TRIG_SEL_NONE, devpriv->pcibar1 + PCIDAS_TRIG_REG);
+       outw(PCIDAS_AI_PACER_SW, devpriv->pcibar1 + PCIDAS_AI_REG);
 
        return 0;
 }
@@ -1083,7 +998,8 @@ static void cb_pcidas_ao_load_fifo(struct comedi_device *dev,
        nbytes = comedi_buf_read_samples(s, devpriv->ao_buffer, nsamples);
 
        nsamples = comedi_bytes_to_samples(s, nbytes);
-       outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer, nsamples);
+       outsw(devpriv->pcibar4 + PCIDAS_AO_FIFO_REG,
+             devpriv->ao_buffer, nsamples);
 }
 
 static int cb_pcidas_ao_inttrig(struct comedi_device *dev,
@@ -1103,15 +1019,15 @@ static int cb_pcidas_ao_inttrig(struct comedi_device *dev,
 
        /*  enable dac half-full and empty interrupts */
        spin_lock_irqsave(&dev->spinlock, flags);
-       devpriv->adc_fifo_bits |= DAEMIE | DAHFIE;
+       devpriv->ctrl |= PCIDAS_CTRL_DAEMIE | PCIDAS_CTRL_DAHFIE;
 
        /*  enable and clear interrupts */
-       outw(devpriv->adc_fifo_bits | DAEMI | DAHFI,
-            devpriv->control_status + INT_ADCFIFO);
+       outw(devpriv->ctrl | PCIDAS_CTRL_DAEMI | PCIDAS_CTRL_DAHFI,
+            devpriv->pcibar1 + PCIDAS_CTRL_REG);
 
        /*  start dac */
-       devpriv->ao_control_bits |= DAC_START | DACEN | DAC_EMPTY;
-       outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR);
+       devpriv->ao_ctrl |= PCIDAS_AO_START | PCIDAS_AO_DACEN | PCIDAS_AO_EMPTY;
+       outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG);
 
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
@@ -1132,21 +1048,21 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev,
        /*  set channel limits, gain */
        spin_lock_irqsave(&dev->spinlock, flags);
        for (i = 0; i < cmd->chanlist_len; i++) {
+               unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+               unsigned int range = CR_RANGE(cmd->chanlist[i]);
+
                /*  enable channel */
-               devpriv->ao_control_bits |=
-                   DAC_CHAN_EN(CR_CHAN(cmd->chanlist[i]));
+               devpriv->ao_ctrl |= PCIDAS_AO_CHAN_EN(chan);
                /*  set range */
-               devpriv->ao_control_bits |= DAC_RANGE(CR_CHAN(cmd->chanlist[i]),
-                                                     CR_RANGE(cmd->
-                                                              chanlist[i]));
+               devpriv->ao_ctrl |= PCIDAS_AO_RANGE(chan, range);
        }
 
        /*  disable analog out before settings pacer source and count values */
-       outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR);
+       outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        /*  clear fifo */
-       outw(0, devpriv->ao_registers + DACFIFOCLR);
+       outw(0, devpriv->pcibar4 + PCIDAS_AO_FIFO_CLR_REG);
 
        /*  load counters */
        if (cmd->scan_begin_src == TRIG_TIMER) {
@@ -1158,10 +1074,10 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev,
        spin_lock_irqsave(&dev->spinlock, flags);
        switch (cmd->scan_begin_src) {
        case TRIG_TIMER:
-               devpriv->ao_control_bits |= DAC_PACER_INT;
+               devpriv->ao_ctrl |= PCIDAS_AO_PACER_INT;
                break;
        case TRIG_EXT:
-               devpriv->ao_control_bits |= DAC_PACER_EXT_RISE;
+               devpriv->ao_ctrl |= PCIDAS_AO_PACER_EXTP;
                break;
        default:
                spin_unlock_irqrestore(&dev->spinlock, flags);
@@ -1175,7 +1091,6 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev,
        return 0;
 }
 
-/* cancel analog output command */
 static int cb_pcidas_ao_cancel(struct comedi_device *dev,
                               struct comedi_subdevice *s)
 {
@@ -1184,33 +1099,31 @@ static int cb_pcidas_ao_cancel(struct comedi_device *dev,
 
        spin_lock_irqsave(&dev->spinlock, flags);
        /*  disable interrupts */
-       devpriv->adc_fifo_bits &= ~DAHFIE & ~DAEMIE;
-       outw(devpriv->adc_fifo_bits, devpriv->control_status + INT_ADCFIFO);
+       devpriv->ctrl &= ~(PCIDAS_CTRL_DAHFIE | PCIDAS_CTRL_DAEMIE);
+       outw(devpriv->ctrl, devpriv->pcibar1 + PCIDAS_CTRL_REG);
 
        /*  disable output */
-       devpriv->ao_control_bits &= ~DACEN & ~DAC_PACER_MASK;
-       outw(devpriv->ao_control_bits, devpriv->control_status + DAC_CSR);
+       devpriv->ao_ctrl &= ~(PCIDAS_AO_DACEN | PCIDAS_AO_PACER_MASK);
+       outw(devpriv->ao_ctrl, devpriv->pcibar1 + PCIDAS_AO_REG);
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        return 0;
 }
 
-static void handle_ao_interrupt(struct comedi_device *dev, unsigned int status)
+static unsigned int cb_pcidas_ao_interrupt(struct comedi_device *dev,
+                                          unsigned int status)
 {
        const struct cb_pcidas_board *board = dev->board_ptr;
        struct cb_pcidas_private *devpriv = dev->private;
        struct comedi_subdevice *s = dev->write_subdev;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
-       unsigned long flags;
+       unsigned int irq_clr = 0;
 
-       if (status & DAEMI) {
-               /*  clear dac empty interrupt latch */
-               spin_lock_irqsave(&dev->spinlock, flags);
-               outw(devpriv->adc_fifo_bits | DAEMI,
-                    devpriv->control_status + INT_ADCFIFO);
-               spin_unlock_irqrestore(&dev->spinlock, flags);
-               if (inw(devpriv->ao_registers + DAC_CSR) & DAC_EMPTY) {
+       if (status & PCIDAS_CTRL_DAEMI) {
+               irq_clr |= PCIDAS_CTRL_DAEMI;
+
+               if (inw(devpriv->pcibar4 + PCIDAS_AO_REG) & PCIDAS_AO_EMPTY) {
                        if (cmd->stop_src == TRIG_COUNT &&
                            async->scans_done >= cmd->stop_arg) {
                                async->events |= COMEDI_CB_EOA;
@@ -1219,83 +1132,55 @@ static void handle_ao_interrupt(struct comedi_device *dev, unsigned int status)
                                async->events |= COMEDI_CB_ERROR;
                        }
                }
-       } else if (status & DAHFI) {
-               cb_pcidas_ao_load_fifo(dev, s, board->fifo_size / 2);
+       } else if (status & PCIDAS_CTRL_DAHFI) {
+               irq_clr |= PCIDAS_CTRL_DAHFI;
 
-               /*  clear half-full interrupt latch */
-               spin_lock_irqsave(&dev->spinlock, flags);
-               outw(devpriv->adc_fifo_bits | DAHFI,
-                    devpriv->control_status + INT_ADCFIFO);
-               spin_unlock_irqrestore(&dev->spinlock, flags);
+               cb_pcidas_ao_load_fifo(dev, s, board->fifo_size / 2);
        }
 
        comedi_handle_events(dev, s);
+
+       return irq_clr;
 }
 
-static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
+static unsigned int cb_pcidas_ai_interrupt(struct comedi_device *dev,
+                                          unsigned int status)
 {
-       struct comedi_device *dev = (struct comedi_device *)d;
        const struct cb_pcidas_board *board = dev->board_ptr;
        struct cb_pcidas_private *devpriv = dev->private;
        struct comedi_subdevice *s = dev->read_subdev;
-       struct comedi_async *async;
-       struct comedi_cmd *cmd;
-       int status, s5933_status;
-       int half_fifo = board->fifo_size / 2;
-       unsigned int num_samples, i;
-       static const int timeout = 10000;
-       unsigned long flags;
-
-       if (!dev->attached)
-               return IRQ_NONE;
-
-       async = s->async;
-       cmd = &async->cmd;
+       struct comedi_async *async = s->async;
+       struct comedi_cmd *cmd = &async->cmd;
+       unsigned int irq_clr = 0;
 
-       s5933_status = inl(devpriv->s5933_config + AMCC_OP_REG_INTCSR);
+       if (status & PCIDAS_CTRL_ADHFI) {
+               unsigned int num_samples;
 
-       if ((INTCSR_INTR_ASSERTED & s5933_status) == 0)
-               return IRQ_NONE;
+               irq_clr |= PCIDAS_CTRL_INT_CLR;
 
-       /*  make sure mailbox 4 is empty */
-       inl_p(devpriv->s5933_config + AMCC_OP_REG_IMB4);
-       /*  clear interrupt on amcc s5933 */
-       outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS,
-            devpriv->s5933_config + AMCC_OP_REG_INTCSR);
-
-       status = inw(devpriv->control_status + INT_ADCFIFO);
-
-       /*  check for analog output interrupt */
-       if (status & (DAHFI | DAEMI))
-               handle_ao_interrupt(dev, status);
-       /*  check for analog input interrupts */
-       /*  if fifo half-full */
-       if (status & ADHFI) {
-               /*  read data */
-               num_samples = comedi_nsamples_left(s, half_fifo);
-               insw(devpriv->adc_fifo + ADCDATA, devpriv->ai_buffer,
-                    num_samples);
+               /* FIFO is half-full - read data */
+               num_samples = comedi_nsamples_left(s, board->fifo_size / 2);
+               insw(devpriv->pcibar2 + PCIDAS_AI_DATA_REG,
+                    devpriv->ai_buffer, num_samples);
                comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples);
 
                if (cmd->stop_src == TRIG_COUNT &&
                    async->scans_done >= cmd->stop_arg)
                        async->events |= COMEDI_CB_EOA;
+       } else if (status & (PCIDAS_CTRL_ADNEI | PCIDAS_CTRL_EOBI)) {
+               unsigned int i;
 
-               /*  clear half-full interrupt latch */
-               spin_lock_irqsave(&dev->spinlock, flags);
-               outw(devpriv->adc_fifo_bits | INT,
-                    devpriv->control_status + INT_ADCFIFO);
-               spin_unlock_irqrestore(&dev->spinlock, flags);
-               /*  else if fifo not empty */
-       } else if (status & (ADNEI | EOBI)) {
-               for (i = 0; i < timeout; i++) {
+               irq_clr |= PCIDAS_CTRL_INT_CLR;
+
+               /* FIFO is not empty - read data until empty or timeoout */
+               for (i = 0; i < 10000; i++) {
                        unsigned short val;
 
                        /*  break if fifo is empty */
-                       if ((ADNE & inw(devpriv->control_status +
-                                       INT_ADCFIFO)) == 0)
+                       if ((inw(devpriv->pcibar1 + PCIDAS_CTRL_REG) &
+                           PCIDAS_CTRL_ADNE) == 0)
                                break;
-                       val = inw(devpriv->adc_fifo);
+                       val = inw(devpriv->pcibar2 + PCIDAS_AI_DATA_REG);
                        comedi_buf_write_samples(s, &val, 1);
 
                        if (cmd->stop_src == TRIG_COUNT &&
@@ -1304,33 +1189,67 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
                                break;
                        }
                }
-               /*  clear not-empty interrupt latch */
-               spin_lock_irqsave(&dev->spinlock, flags);
-               outw(devpriv->adc_fifo_bits | INT,
-                    devpriv->control_status + INT_ADCFIFO);
-               spin_unlock_irqrestore(&dev->spinlock, flags);
-       } else if (status & EOAI) {
+       } else if (status & PCIDAS_CTRL_EOAI) {
+               irq_clr |= PCIDAS_CTRL_EOAI;
+
                dev_err(dev->class_dev,
                        "bug! encountered end of acquisition interrupt?\n");
-               /*  clear EOA interrupt latch */
-               spin_lock_irqsave(&dev->spinlock, flags);
-               outw(devpriv->adc_fifo_bits | EOAI,
-                    devpriv->control_status + INT_ADCFIFO);
-               spin_unlock_irqrestore(&dev->spinlock, flags);
        }
+
        /* check for fifo overflow */
-       if (status & LADFUL) {
+       if (status & PCIDAS_CTRL_LADFUL) {
+               irq_clr |= PCIDAS_CTRL_LADFUL;
+
                dev_err(dev->class_dev, "fifo overflow\n");
-               /*  clear overflow interrupt latch */
-               spin_lock_irqsave(&dev->spinlock, flags);
-               outw(devpriv->adc_fifo_bits | LADFUL,
-                    devpriv->control_status + INT_ADCFIFO);
-               spin_unlock_irqrestore(&dev->spinlock, flags);
                async->events |= COMEDI_CB_ERROR;
        }
 
        comedi_handle_events(dev, s);
 
+       return irq_clr;
+}
+
+static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
+{
+       struct comedi_device *dev = d;
+       struct cb_pcidas_private *devpriv = dev->private;
+       unsigned int irq_clr = 0;
+       unsigned int amcc_status;
+       unsigned int status;
+
+       if (!dev->attached)
+               return IRQ_NONE;
+
+       amcc_status = inl(devpriv->amcc + AMCC_OP_REG_INTCSR);
+
+       if ((INTCSR_INTR_ASSERTED & amcc_status) == 0)
+               return IRQ_NONE;
+
+       /*  make sure mailbox 4 is empty */
+       inl_p(devpriv->amcc + AMCC_OP_REG_IMB4);
+       /*  clear interrupt on amcc s5933 */
+       outl(devpriv->amcc_intcsr | INTCSR_INBOX_INTR_STATUS,
+            devpriv->amcc + AMCC_OP_REG_INTCSR);
+
+       status = inw(devpriv->pcibar1 + PCIDAS_CTRL_REG);
+
+       /* handle analog output interrupts */
+       if (status & PCIDAS_CTRL_AO_INT)
+               irq_clr |= cb_pcidas_ao_interrupt(dev, status);
+
+       /* handle analog input interrupts */
+       if (status & PCIDAS_CTRL_AI_INT)
+               irq_clr |= cb_pcidas_ai_interrupt(dev, status);
+
+       if (irq_clr) {
+               unsigned long flags;
+
+               spin_lock_irqsave(&dev->spinlock, flags);
+               outw(devpriv->ctrl | irq_clr,
+                    devpriv->pcibar1 + PCIDAS_CTRL_REG);
+               spin_unlock_irqrestore(&dev->spinlock, flags);
+       }
+
        return IRQ_HANDLED;
 }
 
@@ -1359,16 +1278,16 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       devpriv->s5933_config = pci_resource_start(pcidev, 0);
-       devpriv->control_status = pci_resource_start(pcidev, 1);
-       devpriv->adc_fifo = pci_resource_start(pcidev, 2);
+       devpriv->amcc = pci_resource_start(pcidev, 0);
+       devpriv->pcibar1 = pci_resource_start(pcidev, 1);
+       devpriv->pcibar2 = pci_resource_start(pcidev, 2);
        dev->iobase = pci_resource_start(pcidev, 3);
-       if (board->ao_nchan)
-               devpriv->ao_registers = pci_resource_start(pcidev, 4);
+       if (board->has_ao)
+               devpriv->pcibar4 = pci_resource_start(pcidev, 4);
 
        /*  disable and clear interrupts on amcc s5933 */
        outl(INTCSR_INBOX_INTR_STATUS,
-            devpriv->s5933_config + AMCC_OP_REG_INTCSR);
+            devpriv->amcc + AMCC_OP_REG_INTCSR);
 
        ret = request_irq(pcidev->irq, cb_pcidas_interrupt, IRQF_SHARED,
                          dev->board_name, dev);
@@ -1379,12 +1298,12 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
        }
        dev->irq = pcidev->irq;
 
-       dev->pacer = comedi_8254_init(dev->iobase + ADC8254,
+       dev->pacer = comedi_8254_init(dev->iobase + PCIDAS_AI_8254_BASE,
                                      I8254_OSC_BASE_10MHZ, I8254_IO8, 0);
        if (!dev->pacer)
                return -ENOMEM;
 
-       devpriv->ao_pacer = comedi_8254_init(dev->iobase + DAC8254,
+       devpriv->ao_pacer = comedi_8254_init(dev->iobase + PCIDAS_AO_8254_BASE,
                                             I8254_OSC_BASE_10MHZ,
                                             I8254_IO8, 0);
        if (!devpriv->ao_pacer)
@@ -1394,97 +1313,104 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       /* analog input subdevice */
-       dev->read_subdev = s;
-       s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
-       /* WARNING: Number of inputs in differential mode is ignored */
-       s->n_chan = board->ai_nchan;
-       s->len_chanlist = board->ai_nchan;
-       s->maxdata = (1 << board->ai_bits) - 1;
-       s->range_table = board->ranges;
-       s->insn_read = cb_pcidas_ai_rinsn;
-       s->insn_config = ai_config_insn;
-       s->do_cmd = cb_pcidas_ai_cmd;
-       s->do_cmdtest = cb_pcidas_ai_cmdtest;
-       s->cancel = cb_pcidas_cancel;
-
-       /* analog output subdevice */
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
+       s->n_chan       = 16;
+       s->maxdata      = board->is_16bit ? 0xffff : 0x0fff;
+       s->range_table  = board->use_alt_range ? &cb_pcidas_alt_ranges
+                                              : &cb_pcidas_ranges;
+       s->insn_read    = cb_pcidas_ai_insn_read;
+       s->insn_config  = cb_pcidas_ai_insn_config;
+       if (dev->irq) {
+               dev->read_subdev = s;
+               s->subdev_flags |= SDF_CMD_READ;
+               s->len_chanlist = s->n_chan;
+               s->do_cmd       = cb_pcidas_ai_cmd;
+               s->do_cmdtest   = cb_pcidas_ai_cmdtest;
+               s->cancel       = cb_pcidas_ai_cancel;
+       }
+
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       if (board->ao_nchan) {
-               s->type = COMEDI_SUBD_AO;
-               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
-               s->n_chan = board->ao_nchan;
-               /*
-                * analog out resolution is the same as
-                * analog input resolution, so use ai_bits
-                */
-               s->maxdata = (1 << board->ai_bits) - 1;
-               s->range_table = &cb_pcidas_ao_ranges;
-               /* default to no fifo (*insn_write) */
-               s->insn_write = cb_pcidas_ao_nofifo_winsn;
+       if (board->has_ao) {
+               s->type         = COMEDI_SUBD_AO;
+               s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
+               s->n_chan       = 2;
+               s->maxdata      = board->is_16bit ? 0xffff : 0x0fff;
+               s->range_table  = &cb_pcidas_ao_ranges;
+               s->insn_write   = (board->has_ao_fifo)
+                                       ? cb_pcidas_ao_fifo_insn_write
+                                       : cb_pcidas_ao_nofifo_insn_write;
 
                ret = comedi_alloc_subdev_readback(s);
                if (ret)
                        return ret;
 
-               if (board->has_ao_fifo) {
+               if (dev->irq && board->has_ao_fifo) {
                        dev->write_subdev = s;
-                       s->subdev_flags |= SDF_CMD_WRITE;
-                       /* use fifo (*insn_write) instead */
-                       s->insn_write = cb_pcidas_ao_fifo_winsn;
-                       s->do_cmdtest = cb_pcidas_ao_cmdtest;
-                       s->do_cmd = cb_pcidas_ao_cmd;
-                       s->cancel = cb_pcidas_ao_cancel;
+                       s->subdev_flags |= SDF_CMD_WRITE;
+                       s->do_cmdtest   = cb_pcidas_ao_cmdtest;
+                       s->do_cmd       = cb_pcidas_ao_cmd;
+                       s->cancel       = cb_pcidas_ao_cancel;
                }
        } else {
-               s->type = COMEDI_SUBD_UNUSED;
+               s->type         = COMEDI_SUBD_UNUSED;
        }
 
        /* 8255 */
        s = &dev->subdevices[2];
-       ret = subdev_8255_init(dev, s, NULL, DIO_8255);
+       ret = subdev_8255_init(dev, s, NULL, PCIDAS_8255_BASE);
        if (ret)
                return ret;
 
-       /*  serial EEPROM, */
+       /* Memory subdevice - serial EEPROM */
        s = &dev->subdevices[3];
-       s->type = COMEDI_SUBD_MEMORY;
-       s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
-       s->n_chan = 256;
-       s->maxdata = 0xff;
-       s->insn_read = eeprom_read_insn;
+       s->type         = COMEDI_SUBD_MEMORY;
+       s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
+       s->n_chan       = 256;
+       s->maxdata      = 0xff;
+       s->insn_read    = cb_pcidas_eeprom_insn_read;
 
-       /*  8800 caldac */
+       /* Calibration subdevice - 8800 caldac */
        s = &dev->subdevices[4];
-       s->type = COMEDI_SUBD_CALIB;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-       s->n_chan = NUM_CHANNELS_8800;
-       s->maxdata = 0xff;
-       s->insn_write = cb_pcidas_caldac_insn_write;
+       s->type         = COMEDI_SUBD_CALIB;
+       s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
+       s->n_chan       = 8;
+       s->maxdata      = 0xff;
+       s->insn_write   = cb_pcidas_caldac_insn_write;
 
        ret = comedi_alloc_subdev_readback(s);
        if (ret)
                return ret;
 
        for (i = 0; i < s->n_chan; i++) {
-               caldac_8800_write(dev, i, s->maxdata / 2);
-               s->readback[i] = s->maxdata / 2;
+               unsigned int val = s->maxdata / 2;
+
+               /* write 11-bit channel/value to caldac */
+               cb_pcidas_calib_write(dev, (i << 8) | val, 11, false);
+               s->readback[i] = val;
        }
 
-       /*  trim potentiometer */
+       /* Calibration subdevice - trim potentiometer */
        s = &dev->subdevices[5];
-       s->type = COMEDI_SUBD_CALIB;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-       if (board->trimpot == AD7376) {
-               s->n_chan = NUM_CHANNELS_7376;
-               s->maxdata = 0x7f;
+       s->type         = COMEDI_SUBD_CALIB;
+       s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
+       if (board->has_ad8402) {
+               /*
+                * pci-das1602/16 have an AD8402 trimpot:
+                *   chan 0 : adc gain
+                *   chan 1 : adc postgain offset
+                */
+               s->n_chan       = 2;
+               s->maxdata      = 0xff;
        } else {
-               s->n_chan = NUM_CHANNELS_8402;
-               s->maxdata = 0xff;
+               /* all other boards have an AD7376 trimpot */
+               s->n_chan       = 1;
+               s->maxdata      = 0x7f;
        }
-       s->insn_write = cb_pcidas_trimpot_insn_write;
+       s->insn_write   = cb_pcidas_trimpot_insn_write;
 
        ret = comedi_alloc_subdev_readback(s);
        if (ret)
@@ -1495,36 +1421,35 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
                s->readback[i] = s->maxdata / 2;
        }
 
-       /*  dac08 caldac */
+       /* Calibration subdevice - pci-das1602/16 pregain offset (dac08) */
        s = &dev->subdevices[6];
        if (board->has_dac08) {
-               s->type = COMEDI_SUBD_CALIB;
-               s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-               s->n_chan = NUM_CHANNELS_DAC08;
-               s->maxdata = 0xff;
-               s->insn_write = cb_pcidas_dac08_insn_write;
+               s->type         = COMEDI_SUBD_CALIB;
+               s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
+               s->n_chan       = 1;
+               s->maxdata      = 0xff;
+               s->insn_write   = cb_pcidas_dac08_insn_write;
 
                ret = comedi_alloc_subdev_readback(s);
                if (ret)
                        return ret;
 
                for (i = 0; i < s->n_chan; i++) {
-                       dac08_write(dev, s->maxdata / 2);
+                       cb_pcidas_dac08_write(dev, s->maxdata / 2);
                        s->readback[i] = s->maxdata / 2;
                }
        } else {
-               s->type = COMEDI_SUBD_UNUSED;
+               s->type         = COMEDI_SUBD_UNUSED;
        }
 
        /*  make sure mailbox 4 is empty */
-       inl(devpriv->s5933_config + AMCC_OP_REG_IMB4);
+       inl(devpriv->amcc + AMCC_OP_REG_IMB4);
        /* Set bits to enable incoming mailbox interrupts on amcc s5933. */
-       devpriv->s5933_intcsr_bits =
-           INTCSR_INBOX_BYTE(3) | INTCSR_INBOX_SELECT(3) |
-           INTCSR_INBOX_FULL_INT;
+       devpriv->amcc_intcsr = INTCSR_INBOX_BYTE(3) | INTCSR_INBOX_SELECT(3) |
+                              INTCSR_INBOX_FULL_INT;
        /*  clear and enable interrupt on amcc s5933 */
-       outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS,
-            devpriv->s5933_config + AMCC_OP_REG_INTCSR);
+       outl(devpriv->amcc_intcsr | INTCSR_INBOX_INTR_STATUS,
+            devpriv->amcc + AMCC_OP_REG_INTCSR);
 
        return 0;
 }
@@ -1534,9 +1459,9 @@ static void cb_pcidas_detach(struct comedi_device *dev)
        struct cb_pcidas_private *devpriv = dev->private;
 
        if (devpriv) {
-               if (devpriv->s5933_config)
+               if (devpriv->amcc)
                        outl(INTCSR_INBOX_INTR_STATUS,
-                            devpriv->s5933_config + AMCC_OP_REG_INTCSR);
+                            devpriv->amcc + AMCC_OP_REG_INTCSR);
                kfree(devpriv->ao_pacer);
        }
        comedi_pci_detach(dev);
@@ -1578,5 +1503,5 @@ static struct pci_driver cb_pcidas_pci_driver = {
 module_comedi_pci_driver(cb_pcidas_driver, cb_pcidas_pci_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for MeasurementComputing PCI-DAS series");
 MODULE_LICENSE("GPL");
index 80d613c0fbc65b85477460f388bcc337ddafed1c..4ab186669f0c27d503a3e33b6e3bdd5fb0e12c7d 100644 (file)
@@ -1,49 +1,49 @@
 /*
-    comedi/drivers/comedi_test.c
+ * comedi/drivers/comedi_test.c
+ *
+ * Generates fake waveform signals that can be read through
+ * the command interface.  It does _not_ read from any board;
+ * it just generates deterministic waveforms.
+ * Useful for various testing purposes.
+ *
+ * Copyright (C) 2002 Joachim Wuttke <Joachim.Wuttke@icn.siemens.de>
+ * Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
-    Generates fake waveform signals that can be read through
-    the command interface.  It does _not_ read from any board;
-    it just generates deterministic waveforms.
-    Useful for various testing purposes.
-
-    Copyright (C) 2002 Joachim Wuttke <Joachim.Wuttke@icn.siemens.de>
-    Copyright (C) 2002 Frank Mori Hess <fmhess@users.sourceforge.net>
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
 /*
-Driver: comedi_test
-Description: generates fake waveforms
-Author: Joachim Wuttke <Joachim.Wuttke@icn.siemens.de>, Frank Mori Hess
-  <fmhess@users.sourceforge.net>, ds
-Devices:
-Status: works
-Updated: Sat, 16 Mar 2002 17:34:48 -0800
-
-This driver is mainly for testing purposes, but can also be used to
-generate sample waveforms on systems that don't have data acquisition
-hardware.
-
-Configuration options:
-  [0] - Amplitude in microvolts for fake waveforms (default 1 volt)
-  [1] - Period in microseconds for fake waveforms (default 0.1 sec)
-
-Generates a sawtooth wave on channel 0, square wave on channel 1, additional
-waveforms could be added to other channels (currently they return flatline
-zero volts).
-
-*/
+ * Driver: comedi_test
+ * Description: generates fake waveforms
+ * Author: Joachim Wuttke <Joachim.Wuttke@icn.siemens.de>, Frank Mori Hess
+ *   <fmhess@users.sourceforge.net>, ds
+ * Devices:
+ * Status: works
+ * Updated: Sat, 16 Mar 2002 17:34:48 -0800
+ *
+ * This driver is mainly for testing purposes, but can also be used to
+ * generate sample waveforms on systems that don't have data acquisition
+ * hardware.
+ *
+ * Configuration options:
+ *   [0] - Amplitude in microvolts for fake waveforms (default 1 volt)
+ *   [1] - Period in microseconds for fake waveforms (default 0.1 sec)
+ *
+ * Generates a sawtooth wave on channel 0, square wave on channel 1, additional
+ * waveforms could be added to other channels (currently they return flatline
+ * zero volts).
+ */
 
 #include <linux/module.h>
 #include "../comedidev.h"
@@ -52,30 +52,31 @@ zero volts).
 
 #include <linux/timer.h>
 #include <linux/ktime.h>
+#include <linux/jiffies.h>
 
 #define N_CHANS 8
 
 enum waveform_state_bits {
-       WAVEFORM_AI_RUNNING = 0
+       WAVEFORM_AI_RUNNING,
+       WAVEFORM_AO_RUNNING
 };
 
 /* Data unique to this driver */
 struct waveform_private {
-       struct timer_list timer;
-       ktime_t last;   /* time last timer interrupt occurred */
-       unsigned int uvolt_amplitude;   /* waveform amplitude in microvolts */
-       unsigned long usec_period;      /* waveform period in microseconds */
-       unsigned long usec_current;     /* current time (mod waveform period) */
-       unsigned long usec_remainder;   /* usec since last scan */
+       struct timer_list ai_timer;     /* timer for AI commands */
+       u64 ai_convert_time;            /* time of next AI conversion in usec */
+       unsigned int wf_amplitude;      /* waveform amplitude in microvolts */
+       unsigned int wf_period;         /* waveform period in microseconds */
+       unsigned int wf_current;        /* current time in waveform period */
        unsigned long state_bits;
-       unsigned int scan_period;       /* scan period in usec */
-       unsigned int convert_period;    /* conversion period in usec */
-       unsigned int ao_loopbacks[N_CHANS];
+       unsigned int ai_scan_period;    /* AI scan period in usec */
+       unsigned int ai_convert_period; /* AI conversion period in usec */
+       struct timer_list ao_timer;     /* timer for AO commands */
+       u64 ao_last_scan_time;          /* time of previous AO scan in usec */
+       unsigned int ao_scan_period;    /* AO scan period in usec */
+       unsigned short ao_loopbacks[N_CHANS];
 };
 
-/* 1000 nanosec in a microsec */
-static const int nano_per_micro = 1000;
-
 /* fake analog input ranges */
 static const struct comedi_lrange waveform_ai_ranges = {
        2, {
@@ -86,7 +87,7 @@ static const struct comedi_lrange waveform_ai_ranges = {
 
 static unsigned short fake_sawtooth(struct comedi_device *dev,
                                    unsigned int range_index,
-                                   unsigned long current_time)
+                                   unsigned int current_time)
 {
        struct waveform_private *devpriv = dev->private;
        struct comedi_subdevice *s = dev->read_subdev;
@@ -97,21 +98,28 @@ static unsigned short fake_sawtooth(struct comedi_device *dev,
        u64 binary_amplitude;
 
        binary_amplitude = s->maxdata;
-       binary_amplitude *= devpriv->uvolt_amplitude;
+       binary_amplitude *= devpriv->wf_amplitude;
        do_div(binary_amplitude, krange->max - krange->min);
 
-       current_time %= devpriv->usec_period;
        value = current_time;
        value *= binary_amplitude * 2;
-       do_div(value, devpriv->usec_period);
-       value -= binary_amplitude;      /* get rid of sawtooth's dc offset */
+       do_div(value, devpriv->wf_period);
+       value += offset;
+       /* get rid of sawtooth's dc offset and clamp value */
+       if (value < binary_amplitude) {
+               value = 0;                      /* negative saturation */
+       } else {
+               value -= binary_amplitude;
+               if (value > s->maxdata)
+                       value = s->maxdata;     /* positive saturation */
+       }
 
-       return offset + value;
+       return value;
 }
 
 static unsigned short fake_squarewave(struct comedi_device *dev,
                                      unsigned int range_index,
-                                     unsigned long current_time)
+                                     unsigned int current_time)
 {
        struct waveform_private *devpriv = dev->private;
        struct comedi_subdevice *s = dev->read_subdev;
@@ -119,21 +127,29 @@ static unsigned short fake_squarewave(struct comedi_device *dev,
        u64 value;
        const struct comedi_krange *krange =
            &s->range_table->range[range_index];
-       current_time %= devpriv->usec_period;
 
        value = s->maxdata;
-       value *= devpriv->uvolt_amplitude;
+       value *= devpriv->wf_amplitude;
        do_div(value, krange->max - krange->min);
 
-       if (current_time < devpriv->usec_period / 2)
-               value *= -1;
+       /* get one of two values for square-wave and clamp */
+       if (current_time < devpriv->wf_period / 2) {
+               if (offset < value)
+                       value = 0;              /* negative saturation */
+               else
+                       value = offset - value;
+       } else {
+               value += offset;
+               if (value > s->maxdata)
+                       value = s->maxdata;     /* positive saturation */
+       }
 
-       return offset + value;
+       return value;
 }
 
 static unsigned short fake_flatline(struct comedi_device *dev,
                                    unsigned int range_index,
-                                   unsigned long current_time)
+                                   unsigned int current_time)
 {
        return dev->read_subdev->maxdata / 2;
 }
@@ -141,7 +157,7 @@ static unsigned short fake_flatline(struct comedi_device *dev,
 /* generates a different waveform depending on what channel is read */
 static unsigned short fake_waveform(struct comedi_device *dev,
                                    unsigned int channel, unsigned int range,
-                                   unsigned long current_time)
+                                   unsigned int current_time)
 {
        enum {
                SAWTOOTH_CHAN,
@@ -160,58 +176,62 @@ static unsigned short fake_waveform(struct comedi_device *dev,
 }
 
 /*
  This is the background routine used to generate arbitrary data.
  It should run in the background; therefore it is scheduled by
  a timer mechanism.
-*/
-static void waveform_ai_interrupt(unsigned long arg)
* This is the background routine used to generate arbitrary data.
* It should run in the background; therefore it is scheduled by
* a timer mechanism.
+ */
+static void waveform_ai_timer(unsigned long arg)
 {
        struct comedi_device *dev = (struct comedi_device *)arg;
        struct waveform_private *devpriv = dev->private;
        struct comedi_subdevice *s = dev->read_subdev;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
-       unsigned int i, j;
-       /* all times in microsec */
-       unsigned long elapsed_time;
-       unsigned int num_scans;
-       ktime_t now;
+       u64 now;
+       unsigned int nsamples;
+       unsigned int time_increment;
 
        /* check command is still active */
        if (!test_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits))
                return;
 
-       now = ktime_get();
-
-       elapsed_time = ktime_to_us(ktime_sub(now, devpriv->last));
-       devpriv->last = now;
-       num_scans =
-           (devpriv->usec_remainder + elapsed_time) / devpriv->scan_period;
-       devpriv->usec_remainder =
-           (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period;
-
-       num_scans = comedi_nscans_left(s, num_scans);
-       for (i = 0; i < num_scans; i++) {
-               for (j = 0; j < cmd->chanlist_len; j++) {
-                       unsigned short sample;
-
-                       sample = fake_waveform(dev, CR_CHAN(cmd->chanlist[j]),
-                                              CR_RANGE(cmd->chanlist[j]),
-                                              devpriv->usec_current +
-                                                  i * devpriv->scan_period +
-                                                  j * devpriv->convert_period);
-                       comedi_buf_write_samples(s, &sample, 1);
+       now = ktime_to_us(ktime_get());
+       nsamples = comedi_nsamples_left(s, UINT_MAX);
+
+       while (nsamples && devpriv->ai_convert_time < now) {
+               unsigned int chanspec = cmd->chanlist[async->cur_chan];
+               unsigned short sample;
+
+               sample = fake_waveform(dev, CR_CHAN(chanspec),
+                                      CR_RANGE(chanspec), devpriv->wf_current);
+               if (comedi_buf_write_samples(s, &sample, 1) == 0)
+                       goto overrun;
+               time_increment = devpriv->ai_convert_period;
+               if (async->scan_progress == 0) {
+                       /* done last conversion in scan, so add dead time */
+                       time_increment += devpriv->ai_scan_period -
+                                         devpriv->ai_convert_period *
+                                         cmd->scan_end_arg;
                }
+               devpriv->wf_current += time_increment;
+               if (devpriv->wf_current >= devpriv->wf_period)
+                       devpriv->wf_current %= devpriv->wf_period;
+               devpriv->ai_convert_time += time_increment;
+               nsamples--;
        }
 
-       devpriv->usec_current += elapsed_time;
-       devpriv->usec_current %= devpriv->usec_period;
-
-       if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
+       if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) {
                async->events |= COMEDI_CB_EOA;
-       else
-               mod_timer(&devpriv->timer, jiffies + 1);
+       } else {
+               if (devpriv->ai_convert_time > now)
+                       time_increment = devpriv->ai_convert_time - now;
+               else
+                       time_increment = 1;
+               mod_timer(&devpriv->ai_timer,
+                         jiffies + usecs_to_jiffies(time_increment));
+       }
 
+overrun:
        comedi_handle_events(dev, s);
 }
 
@@ -220,12 +240,13 @@ static int waveform_ai_cmdtest(struct comedi_device *dev,
                               struct comedi_cmd *cmd)
 {
        int err = 0;
-       unsigned int arg;
+       unsigned int arg, limit;
 
        /* Step 1 : check if triggers are trivially valid */
 
        err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW);
-       err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= comedi_check_trigger_src(&cmd->scan_begin_src,
+                                       TRIG_FOLLOW | TRIG_TIMER);
        err |= comedi_check_trigger_src(&cmd->convert_src,
                                        TRIG_NOW | TRIG_TIMER);
        err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
@@ -241,6 +262,9 @@ static int waveform_ai_cmdtest(struct comedi_device *dev,
 
        /* Step 2b : and mutually compatible */
 
+       if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW)
+               err |= -EINVAL;         /* scan period would be 0 */
+
        if (err)
                return 2;
 
@@ -248,18 +272,20 @@ static int waveform_ai_cmdtest(struct comedi_device *dev,
 
        err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
 
-       if (cmd->convert_src == TRIG_NOW)
+       if (cmd->convert_src == TRIG_NOW) {
                err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
+       } else {        /* cmd->convert_src == TRIG_TIMER */
+               if (cmd->scan_begin_src == TRIG_FOLLOW) {
+                       err |= comedi_check_trigger_arg_min(&cmd->convert_arg,
+                                                           NSEC_PER_USEC);
+               }
+       }
 
-       if (cmd->scan_begin_src == TRIG_TIMER) {
+       if (cmd->scan_begin_src == TRIG_FOLLOW) {
+               err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
+       } else {        /* cmd->scan_begin_src == TRIG_TIMER */
                err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
-                                                   nano_per_micro);
-               if (cmd->convert_src == TRIG_TIMER) {
-                       err |= comedi_check_trigger_arg_min(&cmd->
-                                                           scan_begin_arg,
-                                                           cmd->convert_arg *
-                                                           cmd->chanlist_len);
-               }
+                                                   NSEC_PER_USEC);
        }
 
        err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1);
@@ -268,7 +294,7 @@ static int waveform_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->stop_src == TRIG_COUNT)
                err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
-       else    /* TRIG_NONE */
+       else    /* cmd->stop_src == TRIG_NONE */
                err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
 
        if (err)
@@ -276,21 +302,34 @@ static int waveform_ai_cmdtest(struct comedi_device *dev,
 
        /* step 4: fix up any arguments */
 
-       if (cmd->scan_begin_src == TRIG_TIMER) {
-               arg = cmd->scan_begin_arg;
-               /* round to nearest microsec */
-               arg = nano_per_micro *
-                     ((arg + (nano_per_micro / 2)) / nano_per_micro);
-               err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
-       }
        if (cmd->convert_src == TRIG_TIMER) {
+               /* round convert_arg to nearest microsecond */
                arg = cmd->convert_arg;
-               /* round to nearest microsec */
-               arg = nano_per_micro *
-                     ((arg + (nano_per_micro / 2)) / nano_per_micro);
+               arg = min(arg,
+                         rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC));
+               arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC);
+               if (cmd->scan_begin_arg == TRIG_TIMER) {
+                       /* limit convert_arg to keep scan_begin_arg in range */
+                       limit = UINT_MAX / cmd->scan_end_arg;
+                       limit = rounddown(limit, (unsigned int)NSEC_PER_SEC);
+                       arg = min(arg, limit);
+               }
                err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
        }
 
+       if (cmd->scan_begin_src == TRIG_TIMER) {
+               /* round scan_begin_arg to nearest microsecond */
+               arg = cmd->scan_begin_arg;
+               arg = min(arg,
+                         rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC));
+               arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC);
+               if (cmd->convert_src == TRIG_TIMER) {
+                       /* but ensure scan_begin_arg is large enough */
+                       arg = max(arg, cmd->convert_arg * cmd->scan_end_arg);
+               }
+               err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
+       }
+
        if (err)
                return 4;
 
@@ -302,6 +341,8 @@ static int waveform_ai_cmd(struct comedi_device *dev,
 {
        struct waveform_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
+       unsigned int first_convert_time;
+       u64 wf_current;
 
        if (cmd->flags & CMDF_PRIORITY) {
                dev_err(dev->class_dev,
@@ -309,24 +350,48 @@ static int waveform_ai_cmd(struct comedi_device *dev,
                return -1;
        }
 
-       devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro;
-
        if (cmd->convert_src == TRIG_NOW)
-               devpriv->convert_period = 0;
-       else    /* TRIG_TIMER */
-               devpriv->convert_period = cmd->convert_arg / nano_per_micro;
+               devpriv->ai_convert_period = 0;
+       else            /* cmd->convert_src == TRIG_TIMER */
+               devpriv->ai_convert_period = cmd->convert_arg / NSEC_PER_USEC;
+
+       if (cmd->scan_begin_src == TRIG_FOLLOW) {
+               devpriv->ai_scan_period = devpriv->ai_convert_period *
+                                         cmd->scan_end_arg;
+       } else {        /* cmd->scan_begin_src == TRIG_TIMER */
+               devpriv->ai_scan_period = cmd->scan_begin_arg / NSEC_PER_USEC;
+       }
 
-       devpriv->last = ktime_get();
-       devpriv->usec_current =
-               ((u32)ktime_to_us(devpriv->last)) % devpriv->usec_period;
-       devpriv->usec_remainder = 0;
+       /*
+        * Simulate first conversion to occur at convert period after
+        * conversion timer starts.  If scan_begin_src is TRIG_FOLLOW, assume
+        * the conversion timer starts immediately.  If scan_begin_src is
+        * TRIG_TIMER, assume the conversion timer starts after the scan
+        * period.
+        */
+       first_convert_time = devpriv->ai_convert_period;
+       if (cmd->scan_begin_src == TRIG_TIMER)
+               first_convert_time += devpriv->ai_scan_period;
+       devpriv->ai_convert_time = ktime_to_us(ktime_get()) +
+                                  first_convert_time;
+
+       /* Determine time within waveform period at time of conversion. */
+       wf_current = devpriv->ai_convert_time;
+       devpriv->wf_current = do_div(wf_current, devpriv->wf_period);
+
+       /*
+        * Schedule timer to expire just after first conversion time.
+        * Seem to need an extra jiffy here, otherwise timer expires slightly
+        * early!
+        */
+       devpriv->ai_timer.expires =
+               jiffies + usecs_to_jiffies(devpriv->ai_convert_period) + 1;
 
-       devpriv->timer.expires = jiffies + 1;
        /* mark command as active */
        smp_mb__before_atomic();
        set_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits);
        smp_mb__after_atomic();
-       add_timer(&devpriv->timer);
+       add_timer(&devpriv->ai_timer);
        return 0;
 }
 
@@ -339,7 +404,7 @@ static int waveform_ai_cancel(struct comedi_device *dev,
        clear_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits);
        smp_mb__after_atomic();
        /* cannot call del_timer_sync() as may be called from timer routine */
-       del_timer(&devpriv->timer);
+       del_timer(&devpriv->ai_timer);
        return 0;
 }
 
@@ -356,6 +421,201 @@ static int waveform_ai_insn_read(struct comedi_device *dev,
        return insn->n;
 }
 
+/*
+ * This is the background routine to handle AO commands, scheduled by
+ * a timer mechanism.
+ */
+static void waveform_ao_timer(unsigned long arg)
+{
+       struct comedi_device *dev = (struct comedi_device *)arg;
+       struct waveform_private *devpriv = dev->private;
+       struct comedi_subdevice *s = dev->write_subdev;
+       struct comedi_async *async = s->async;
+       struct comedi_cmd *cmd = &async->cmd;
+       u64 now;
+       u64 scans_since;
+       unsigned int scans_avail = 0;
+
+       /* check command is still active */
+       if (!test_bit(WAVEFORM_AO_RUNNING, &devpriv->state_bits))
+               return;
+
+       /* determine number of scan periods since last time */
+       now = ktime_to_us(ktime_get());
+       scans_since = now - devpriv->ao_last_scan_time;
+       do_div(scans_since, devpriv->ao_scan_period);
+       if (scans_since) {
+               unsigned int i;
+
+               /* determine scans in buffer, limit to scans to do this time */
+               scans_avail = comedi_nscans_left(s, 0);
+               if (scans_avail > scans_since)
+                       scans_avail = scans_since;
+               if (scans_avail) {
+                       /* skip all but the last scan to save processing time */
+                       if (scans_avail > 1) {
+                               unsigned int skip_bytes, nbytes;
+
+                               skip_bytes =
+                               comedi_samples_to_bytes(s, cmd->scan_end_arg *
+                                                          (scans_avail - 1));
+                               nbytes = comedi_buf_read_alloc(s, skip_bytes);
+                               comedi_buf_read_free(s, nbytes);
+                               comedi_inc_scan_progress(s, nbytes);
+                               if (nbytes < skip_bytes) {
+                                       /* unexpected underrun! (cancelled?) */
+                                       async->events |= COMEDI_CB_OVERFLOW;
+                                       goto underrun;
+                               }
+                       }
+                       /* output the last scan */
+                       for (i = 0; i < cmd->scan_end_arg; i++) {
+                               unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+
+                               if (comedi_buf_read_samples(s,
+                                                           &devpriv->
+                                                            ao_loopbacks[chan],
+                                                           1) == 0) {
+                                       /* unexpected underrun! (cancelled?) */
+                                       async->events |= COMEDI_CB_OVERFLOW;
+                                       goto underrun;
+                               }
+                       }
+                       /* advance time of last scan */
+                       devpriv->ao_last_scan_time +=
+                               (u64)scans_avail * devpriv->ao_scan_period;
+               }
+       }
+       if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg) {
+               async->events |= COMEDI_CB_EOA;
+       } else if (scans_avail < scans_since) {
+               async->events |= COMEDI_CB_OVERFLOW;
+       } else {
+               unsigned int time_inc = devpriv->ao_last_scan_time +
+                                       devpriv->ao_scan_period - now;
+
+               mod_timer(&devpriv->ao_timer,
+                         jiffies + usecs_to_jiffies(time_inc));
+       }
+
+underrun:
+       comedi_handle_events(dev, s);
+}
+
+static int waveform_ao_inttrig_start(struct comedi_device *dev,
+                                    struct comedi_subdevice *s,
+                                    unsigned int trig_num)
+{
+       struct waveform_private *devpriv = dev->private;
+       struct comedi_async *async = s->async;
+       struct comedi_cmd *cmd = &async->cmd;
+
+       if (trig_num != cmd->start_arg)
+               return -EINVAL;
+
+       async->inttrig = NULL;
+
+       devpriv->ao_last_scan_time = ktime_to_us(ktime_get());
+       devpriv->ao_timer.expires =
+               jiffies + usecs_to_jiffies(devpriv->ao_scan_period);
+
+       /* mark command as active */
+       smp_mb__before_atomic();
+       set_bit(WAVEFORM_AO_RUNNING, &devpriv->state_bits);
+       smp_mb__after_atomic();
+       add_timer(&devpriv->ao_timer);
+
+       return 1;
+}
+
+static int waveform_ao_cmdtest(struct comedi_device *dev,
+                              struct comedi_subdevice *s,
+                              struct comedi_cmd *cmd)
+{
+       int err = 0;
+       unsigned int arg;
+
+       /* Step 1 : check if triggers are trivially valid */
+
+       err |= comedi_check_trigger_src(&cmd->start_src, TRIG_INT);
+       err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
+       err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_NOW);
+       err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
+       err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
+
+       if (err)
+               return 1;
+
+       /* Step 2a : make sure trigger sources are unique */
+
+       err |= comedi_check_trigger_is_unique(cmd->stop_src);
+
+       /* Step 2b : and mutually compatible */
+
+       if (err)
+               return 2;
+
+       /* Step 3: check if arguments are trivially valid */
+
+       err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
+                                           NSEC_PER_USEC);
+       err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
+       err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1);
+       err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
+                                          cmd->chanlist_len);
+       if (cmd->stop_src == TRIG_COUNT)
+               err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
+       else    /* cmd->stop_src == TRIG_NONE */
+               err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
+
+       if (err)
+               return 3;
+
+       /* step 4: fix up any arguments */
+
+       /* round scan_begin_arg to nearest microsecond */
+       arg = cmd->scan_begin_arg;
+       arg = min(arg, rounddown(UINT_MAX, (unsigned int)NSEC_PER_USEC));
+       arg = NSEC_PER_USEC * DIV_ROUND_CLOSEST(arg, NSEC_PER_USEC);
+       err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
+
+       if (err)
+               return 4;
+
+       return 0;
+}
+
+static int waveform_ao_cmd(struct comedi_device *dev,
+                          struct comedi_subdevice *s)
+{
+       struct waveform_private *devpriv = dev->private;
+       struct comedi_cmd *cmd = &s->async->cmd;
+
+       if (cmd->flags & CMDF_PRIORITY) {
+               dev_err(dev->class_dev,
+                       "commands at RT priority not supported in this driver\n");
+               return -1;
+       }
+
+       devpriv->ao_scan_period = cmd->scan_begin_arg / NSEC_PER_USEC;
+       s->async->inttrig = waveform_ao_inttrig_start;
+       return 0;
+}
+
+static int waveform_ao_cancel(struct comedi_device *dev,
+                             struct comedi_subdevice *s)
+{
+       struct waveform_private *devpriv = dev->private;
+
+       s->async->inttrig = NULL;
+       /* mark command as no longer active */
+       clear_bit(WAVEFORM_AO_RUNNING, &devpriv->state_bits);
+       smp_mb__after_atomic();
+       /* cannot call del_timer_sync() as may be called from timer routine */
+       del_timer(&devpriv->ao_timer);
+       return 0;
+}
+
 static int waveform_ao_insn_write(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
                                  struct comedi_insn *insn, unsigned int *data)
@@ -389,8 +649,8 @@ static int waveform_attach(struct comedi_device *dev,
        if (period <= 0)
                period = 100000;        /* 0.1 sec */
 
-       devpriv->uvolt_amplitude = amplitude;
-       devpriv->usec_period = period;
+       devpriv->wf_amplitude = amplitude;
+       devpriv->wf_period = period;
 
        ret = comedi_alloc_subdevices(dev, 2);
        if (ret)
@@ -414,23 +674,28 @@ static int waveform_attach(struct comedi_device *dev,
        dev->write_subdev = s;
        /* analog output subdevice (loopback) */
        s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
+       s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_CMD_WRITE;
        s->n_chan = N_CHANS;
        s->maxdata = 0xffff;
        s->range_table = &waveform_ai_ranges;
+       s->len_chanlist = s->n_chan;
        s->insn_write = waveform_ao_insn_write;
+       s->insn_read = waveform_ai_insn_read;   /* do same as AI insn_read */
+       s->do_cmd = waveform_ao_cmd;
+       s->do_cmdtest = waveform_ao_cmdtest;
+       s->cancel = waveform_ao_cancel;
 
        /* Our default loopback value is just a 0V flatline */
        for (i = 0; i < s->n_chan; i++)
                devpriv->ao_loopbacks[i] = s->maxdata / 2;
 
-       setup_timer(&devpriv->timer, waveform_ai_interrupt,
-                   (unsigned long)dev);
+       setup_timer(&devpriv->ai_timer, waveform_ai_timer, (unsigned long)dev);
+       setup_timer(&devpriv->ao_timer, waveform_ao_timer, (unsigned long)dev);
 
        dev_info(dev->class_dev,
-                "%s: %i microvolt, %li microsecond waveform attached\n",
+                "%s: %u microvolt, %u microsecond waveform attached\n",
                 dev->board_name,
-                devpriv->uvolt_amplitude, devpriv->usec_period);
+                devpriv->wf_amplitude, devpriv->wf_period);
 
        return 0;
 }
@@ -439,8 +704,10 @@ static void waveform_detach(struct comedi_device *dev)
 {
        struct waveform_private *devpriv = dev->private;
 
-       if (devpriv)
-               del_timer_sync(&devpriv->timer);
+       if (devpriv) {
+               del_timer_sync(&devpriv->ai_timer);
+               del_timer_sync(&devpriv->ao_timer);
+       }
 }
 
 static struct comedi_driver waveform_driver = {
index 611b0a3ef5d7587b3962308cf4bbe1af843d9bc5..57ab6680e3aed4c1375820b652ca0938470adcc5 100644 (file)
@@ -713,12 +713,8 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
                return result;
 
        s = &dev->subdevices[2];
-       result = subdev_8255_init(dev, s, daqboard2000_8255_cb,
-                                 dioP2ExpansionIO8Bit);
-       if (result)
-               return result;
-
-       return 0;
+       return subdev_8255_init(dev, s, daqboard2000_8255_cb,
+                               dioP2ExpansionIO8Bit);
 }
 
 static void daqboard2000_detach(struct comedi_device *dev)
index 8c4f284d1919c6ac188db9a544109f538a291f75..ab7a332fbcc46c7109472905ef613020d5c32f7c 100644 (file)
@@ -1,52 +1,53 @@
 /*
-    comedi/drivers/dt3000.c
-    Data Translation DT3000 series driver
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 1999 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
-/*
-Driver: dt3000
-Description: Data Translation DT3000 series
-Author: ds
-Devices: [Data Translation] DT3001 (dt3000), DT3001-PGL, DT3002, DT3003,
-  DT3003-PGL, DT3004, DT3005, DT3004-200
-Updated: Mon, 14 Apr 2008 15:41:24 +0100
-Status: works
-
-Configuration Options: not applicable, uses PCI auto config
-
-There is code to support AI commands, but it may not work.
+ * dt3000.c
+ * Data Translation DT3000 series driver
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 1999 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
-AO commands are not supported.
-*/
+/*
+ * Driver: dt3000
+ * Description: Data Translation DT3000 series
+ * Devices: [Data Translation] DT3001 (dt3000), DT3001-PGL, DT3002, DT3003,
+ *   DT3003-PGL, DT3004, DT3005, DT3004-200
+ * Author: ds
+ * Updated: Mon, 14 Apr 2008 15:41:24 +0100
+ * Status: works
+ *
+ * Configuration Options: not applicable, uses PCI auto config
+ *
+ * There is code to support AI commands, but it may not work.
+ *
+ * AO commands are not supported.
+ */
 
 /*
  The DT3000 series is Data Translation's attempt to make a PCI
  data acquisition board.  The design of this series is very nice,
  since each board has an on-board DSP (Texas Instruments TMS320C52).
  However, a few details are a little annoying.  The boards lack
  bus-mastering DMA, which eliminates them from serious work.
  They also are not capable of autocalibration, which is a common
  feature in modern hardware.  The default firmware is pretty bad,
  making it nearly impossible to write an RT compatible driver.
  It would make an interesting project to write a decent firmware
  for these boards.
-
  Data Translation originally wanted an NDA for the documentation
  for the 3k series.  However, if you ask nicely, they might send
  you the docs without one, also.
-*/
* The DT3000 series is Data Translation's attempt to make a PCI
* data acquisition board.  The design of this series is very nice,
* since each board has an on-board DSP (Texas Instruments TMS320C52).
* However, a few details are a little annoying.  The boards lack
* bus-mastering DMA, which eliminates them from serious work.
* They also are not capable of autocalibration, which is a common
* feature in modern hardware.  The default firmware is pretty bad,
* making it nearly impossible to write an RT compatible driver.
* It would make an interesting project to write a decent firmware
* for these boards.
+ *
* Data Translation originally wanted an NDA for the documentation
* for the 3k series.  However, if you ask nicely, they might send
* you the docs without one, also.
+ */
 
 #include <linux/module.h>
 #include <linux/delay.h>
@@ -54,6 +55,88 @@ AO commands are not supported.
 
 #include "../comedi_pci.h"
 
+/*
+ * PCI BAR0 - dual-ported RAM location definitions (dev->mmio)
+ */
+#define DPR_DAC_BUFFER         (4 * 0x000)
+#define DPR_ADC_BUFFER         (4 * 0x800)
+#define DPR_COMMAND            (4 * 0xfd3)
+#define DPR_SUBSYS             (4 * 0xfd3)
+#define DPR_SUBSYS_AI          0
+#define DPR_SUBSYS_AO          1
+#define DPR_SUBSYS_DIN         2
+#define DPR_SUBSYS_DOUT                3
+#define DPR_SUBSYS_MEM         4
+#define DPR_SUBSYS_CT          5
+#define DPR_ENCODE             (4 * 0xfd4)
+#define DPR_PARAMS(x)          (4 * (0xfd5 + (x)))
+#define DPR_TICK_REG_LO                (4 * 0xff5)
+#define DPR_TICK_REG_HI                (4 * 0xff6)
+#define DPR_DA_BUF_FRONT       (4 * 0xff7)
+#define DPR_DA_BUF_REAR                (4 * 0xff8)
+#define DPR_AD_BUF_FRONT       (4 * 0xff9)
+#define DPR_AD_BUF_REAR                (4 * 0xffa)
+#define DPR_INT_MASK           (4 * 0xffb)
+#define DPR_INTR_FLAG          (4 * 0xffc)
+#define DPR_INTR_CMDONE                BIT(7)
+#define DPR_INTR_CTDONE                BIT(6)
+#define DPR_INTR_DAHWERR       BIT(5)
+#define DPR_INTR_DASWERR       BIT(4)
+#define DPR_INTR_DAEMPTY       BIT(3)
+#define DPR_INTR_ADHWERR       BIT(2)
+#define DPR_INTR_ADSWERR       BIT(1)
+#define DPR_INTR_ADFULL                BIT(0)
+#define DPR_RESPONSE_MBX       (4 * 0xffe)
+#define DPR_CMD_MBX            (4 * 0xfff)
+#define DPR_CMD_COMPLETION(x)  ((x) << 8)
+#define DPR_CMD_NOTPROCESSED   DPR_CMD_COMPLETION(0x00)
+#define DPR_CMD_NOERROR                DPR_CMD_COMPLETION(0x55)
+#define DPR_CMD_ERROR          DPR_CMD_COMPLETION(0xaa)
+#define DPR_CMD_NOTSUPPORTED   DPR_CMD_COMPLETION(0xff)
+#define DPR_CMD_COMPLETION_MASK        DPR_CMD_COMPLETION(0xff)
+#define DPR_CMD(x)             ((x) << 0)
+#define DPR_CMD_GETBRDINFO     DPR_CMD(0)
+#define DPR_CMD_CONFIG         DPR_CMD(1)
+#define DPR_CMD_GETCONFIG      DPR_CMD(2)
+#define DPR_CMD_START          DPR_CMD(3)
+#define DPR_CMD_STOP           DPR_CMD(4)
+#define DPR_CMD_READSINGLE     DPR_CMD(5)
+#define DPR_CMD_WRITESINGLE    DPR_CMD(6)
+#define DPR_CMD_CALCCLOCK      DPR_CMD(7)
+#define DPR_CMD_READEVENTS     DPR_CMD(8)
+#define DPR_CMD_WRITECTCTRL    DPR_CMD(16)
+#define DPR_CMD_READCTCTRL     DPR_CMD(17)
+#define DPR_CMD_WRITECT                DPR_CMD(18)
+#define DPR_CMD_READCT         DPR_CMD(19)
+#define DPR_CMD_WRITEDATA      DPR_CMD(32)
+#define DPR_CMD_READDATA       DPR_CMD(33)
+#define DPR_CMD_WRITEIO                DPR_CMD(34)
+#define DPR_CMD_READIO         DPR_CMD(35)
+#define DPR_CMD_WRITECODE      DPR_CMD(36)
+#define DPR_CMD_READCODE       DPR_CMD(37)
+#define DPR_CMD_EXECUTE                DPR_CMD(38)
+#define DPR_CMD_HALT           DPR_CMD(48)
+#define DPR_CMD_MASK           DPR_CMD(0xff)
+
+#define DPR_PARAM5_AD_TRIG(x)          (((x) & 0x7) << 2)
+#define DPR_PARAM5_AD_TRIG_INT         DPR_PARAM5_AD_TRIG(0)
+#define DPR_PARAM5_AD_TRIG_EXT         DPR_PARAM5_AD_TRIG(1)
+#define DPR_PARAM5_AD_TRIG_INT_RETRIG  DPR_PARAM5_AD_TRIG(2)
+#define DPR_PARAM5_AD_TRIG_EXT_RETRIG  DPR_PARAM5_AD_TRIG(3)
+#define DPR_PARAM5_AD_TRIG_INT_RETRIG2 DPR_PARAM5_AD_TRIG(4)
+
+#define DPR_PARAM6_AD_DIFF             BIT(0)
+
+#define DPR_AI_FIFO_DEPTH              2003
+#define DPR_AO_FIFO_DEPTH              2048
+
+#define DPR_EXTERNAL_CLOCK             1
+#define DPR_RISING_EDGE                        2
+
+#define DPR_TMODE_MASK                 0x1c
+
+#define DPR_CMD_TIMEOUT                        100
+
 static const struct comedi_lrange range_dt3000_ai = {
        4, {
                BIP_RANGE(10),
@@ -85,184 +168,87 @@ enum dt3k_boardid {
 struct dt3k_boardtype {
        const char *name;
        int adchan;
-       int adbits;
        int ai_speed;
        const struct comedi_lrange *adrange;
-       int dachan;
-       int dabits;
+       unsigned int ai_is_16bit:1;
+       unsigned int has_ao:1;
 };
 
 static const struct dt3k_boardtype dt3k_boardtypes[] = {
        [BOARD_DT3001] = {
                .name           = "dt3001",
                .adchan         = 16,
-               .adbits         = 12,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 3000,
-               .dachan         = 2,
-               .dabits         = 12,
+               .has_ao         = 1,
        },
        [BOARD_DT3001_PGL] = {
                .name           = "dt3001-pgl",
                .adchan         = 16,
-               .adbits         = 12,
                .adrange        = &range_dt3000_ai_pgl,
                .ai_speed       = 3000,
-               .dachan         = 2,
-               .dabits         = 12,
+               .has_ao         = 1,
        },
        [BOARD_DT3002] = {
                .name           = "dt3002",
                .adchan         = 32,
-               .adbits         = 12,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 3000,
        },
        [BOARD_DT3003] = {
                .name           = "dt3003",
                .adchan         = 64,
-               .adbits         = 12,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 3000,
-               .dachan         = 2,
-               .dabits         = 12,
+               .has_ao         = 1,
        },
        [BOARD_DT3003_PGL] = {
                .name           = "dt3003-pgl",
                .adchan         = 64,
-               .adbits         = 12,
                .adrange        = &range_dt3000_ai_pgl,
                .ai_speed       = 3000,
-               .dachan         = 2,
-               .dabits         = 12,
+               .has_ao         = 1,
        },
        [BOARD_DT3004] = {
                .name           = "dt3004",
                .adchan         = 16,
-               .adbits         = 16,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 10000,
-               .dachan         = 2,
-               .dabits         = 12,
+               .ai_is_16bit    = 1,
+               .has_ao         = 1,
        },
        [BOARD_DT3005] = {
                .name           = "dt3005",     /* a.k.a. 3004-200 */
                .adchan         = 16,
-               .adbits         = 16,
                .adrange        = &range_dt3000_ai,
                .ai_speed       = 5000,
-               .dachan         = 2,
-               .dabits         = 12,
+               .ai_is_16bit    = 1,
+               .has_ao         = 1,
        },
 };
 
-/* dual-ported RAM location definitions */
-
-#define DPR_DAC_buffer         (4*0x000)
-#define DPR_ADC_buffer         (4*0x800)
-#define DPR_Command            (4*0xfd3)
-#define DPR_SubSys             (4*0xfd3)
-#define DPR_Encode             (4*0xfd4)
-#define DPR_Params(a)          (4*(0xfd5+(a)))
-#define DPR_Tick_Reg_Lo                (4*0xff5)
-#define DPR_Tick_Reg_Hi                (4*0xff6)
-#define DPR_DA_Buf_Front       (4*0xff7)
-#define DPR_DA_Buf_Rear                (4*0xff8)
-#define DPR_AD_Buf_Front       (4*0xff9)
-#define DPR_AD_Buf_Rear                (4*0xffa)
-#define DPR_Int_Mask           (4*0xffb)
-#define DPR_Intr_Flag          (4*0xffc)
-#define DPR_Response_Mbx       (4*0xffe)
-#define DPR_Command_Mbx                (4*0xfff)
-
-#define AI_FIFO_DEPTH  2003
-#define AO_FIFO_DEPTH  2048
-
-/* command list */
-
-#define CMD_GETBRDINFO         0
-#define CMD_CONFIG             1
-#define CMD_GETCONFIG          2
-#define CMD_START              3
-#define CMD_STOP               4
-#define CMD_READSINGLE         5
-#define CMD_WRITESINGLE                6
-#define CMD_CALCCLOCK          7
-#define CMD_READEVENTS         8
-#define CMD_WRITECTCTRL                16
-#define CMD_READCTCTRL         17
-#define CMD_WRITECT            18
-#define CMD_READCT             19
-#define CMD_WRITEDATA          32
-#define CMD_READDATA           33
-#define CMD_WRITEIO            34
-#define CMD_READIO             35
-#define CMD_WRITECODE          36
-#define CMD_READCODE           37
-#define CMD_EXECUTE            38
-#define CMD_HALT               48
-
-#define SUBS_AI                0
-#define SUBS_AO                1
-#define SUBS_DIN       2
-#define SUBS_DOUT      3
-#define SUBS_MEM       4
-#define SUBS_CT                5
-
-/* interrupt flags */
-#define DT3000_CMDONE          0x80
-#define DT3000_CTDONE          0x40
-#define DT3000_DAHWERR         0x20
-#define DT3000_DASWERR         0x10
-#define DT3000_DAEMPTY         0x08
-#define DT3000_ADHWERR         0x04
-#define DT3000_ADSWERR         0x02
-#define DT3000_ADFULL          0x01
-
-#define DT3000_COMPLETION_MASK 0xff00
-#define DT3000_COMMAND_MASK    0x00ff
-#define DT3000_NOTPROCESSED    0x0000
-#define DT3000_NOERROR         0x5500
-#define DT3000_ERROR           0xaa00
-#define DT3000_NOTSUPPORTED    0xff00
-
-#define DT3000_EXTERNAL_CLOCK  1
-#define DT3000_RISING_EDGE     2
-
-#define TMODE_MASK             0x1c
-
-#define DT3000_AD_TRIG_INTERNAL                (0<<2)
-#define DT3000_AD_TRIG_EXTERNAL                (1<<2)
-#define DT3000_AD_RETRIG_INTERNAL      (2<<2)
-#define DT3000_AD_RETRIG_EXTERNAL      (3<<2)
-#define DT3000_AD_EXTRETRIG            (4<<2)
-
-#define DT3000_CHANNEL_MODE_SE         0
-#define DT3000_CHANNEL_MODE_DI         1
-
 struct dt3k_private {
        unsigned int lock;
        unsigned int ai_front;
        unsigned int ai_rear;
 };
 
-#define TIMEOUT 100
-
 static void dt3k_send_cmd(struct comedi_device *dev, unsigned int cmd)
 {
        int i;
        unsigned int status = 0;
 
-       writew(cmd, dev->mmio + DPR_Command_Mbx);
+       writew(cmd, dev->mmio + DPR_CMD_MBX);
 
-       for (i = 0; i < TIMEOUT; i++) {
-               status = readw(dev->mmio + DPR_Command_Mbx);
-               if ((status & DT3000_COMPLETION_MASK) != DT3000_NOTPROCESSED)
+       for (i = 0; i < DPR_CMD_TIMEOUT; i++) {
+               status = readw(dev->mmio + DPR_CMD_MBX);
+               status &= DPR_CMD_COMPLETION_MASK;
+               if (status != DPR_CMD_NOTPROCESSED)
                        break;
                udelay(1);
        }
 
-       if ((status & DT3000_COMPLETION_MASK) != DT3000_NOERROR)
+       if (status != DPR_CMD_NOERROR)
                dev_dbg(dev->class_dev, "%s: timeout/error status=0x%04x\n",
                        __func__, status);
 }
@@ -271,26 +257,26 @@ static unsigned int dt3k_readsingle(struct comedi_device *dev,
                                    unsigned int subsys, unsigned int chan,
                                    unsigned int gain)
 {
-       writew(subsys, dev->mmio + DPR_SubSys);
+       writew(subsys, dev->mmio + DPR_SUBSYS);
 
-       writew(chan, dev->mmio + DPR_Params(0));
-       writew(gain, dev->mmio + DPR_Params(1));
+       writew(chan, dev->mmio + DPR_PARAMS(0));
+       writew(gain, dev->mmio + DPR_PARAMS(1));
 
-       dt3k_send_cmd(dev, CMD_READSINGLE);
+       dt3k_send_cmd(dev, DPR_CMD_READSINGLE);
 
-       return readw(dev->mmio + DPR_Params(2));
+       return readw(dev->mmio + DPR_PARAMS(2));
 }
 
 static void dt3k_writesingle(struct comedi_device *dev, unsigned int subsys,
                             unsigned int chan, unsigned int data)
 {
-       writew(subsys, dev->mmio + DPR_SubSys);
+       writew(subsys, dev->mmio + DPR_SUBSYS);
 
-       writew(chan, dev->mmio + DPR_Params(0));
-       writew(0, dev->mmio + DPR_Params(1));
-       writew(data, dev->mmio + DPR_Params(2));
+       writew(chan, dev->mmio + DPR_PARAMS(0));
+       writew(0, dev->mmio + DPR_PARAMS(1));
+       writew(data, dev->mmio + DPR_PARAMS(2));
 
-       dt3k_send_cmd(dev, CMD_WRITESINGLE);
+       dt3k_send_cmd(dev, DPR_CMD_WRITESINGLE);
 }
 
 static void dt3k_ai_empty_fifo(struct comedi_device *dev,
@@ -303,32 +289,32 @@ static void dt3k_ai_empty_fifo(struct comedi_device *dev,
        int i;
        unsigned short data;
 
-       front = readw(dev->mmio + DPR_AD_Buf_Front);
+       front = readw(dev->mmio + DPR_AD_BUF_FRONT);
        count = front - devpriv->ai_front;
        if (count < 0)
-               count += AI_FIFO_DEPTH;
+               count += DPR_AI_FIFO_DEPTH;
 
        rear = devpriv->ai_rear;
 
        for (i = 0; i < count; i++) {
-               data = readw(dev->mmio + DPR_ADC_buffer + rear);
+               data = readw(dev->mmio + DPR_ADC_BUFFER + rear);
                comedi_buf_write_samples(s, &data, 1);
                rear++;
-               if (rear >= AI_FIFO_DEPTH)
+               if (rear >= DPR_AI_FIFO_DEPTH)
                        rear = 0;
        }
 
        devpriv->ai_rear = rear;
-       writew(rear, dev->mmio + DPR_AD_Buf_Rear);
+       writew(rear, dev->mmio + DPR_AD_BUF_REAR);
 }
 
 static int dt3k_ai_cancel(struct comedi_device *dev,
                          struct comedi_subdevice *s)
 {
-       writew(SUBS_AI, dev->mmio + DPR_SubSys);
-       dt3k_send_cmd(dev, CMD_STOP);
+       writew(DPR_SUBSYS_AI, dev->mmio + DPR_SUBSYS);
+       dt3k_send_cmd(dev, DPR_CMD_STOP);
 
-       writew(0, dev->mmio + DPR_Int_Mask);
+       writew(0, dev->mmio + DPR_INT_MASK);
 
        return 0;
 }
@@ -346,12 +332,12 @@ static irqreturn_t dt3k_interrupt(int irq, void *d)
        if (!dev->attached)
                return IRQ_NONE;
 
-       status = readw(dev->mmio + DPR_Intr_Flag);
+       status = readw(dev->mmio + DPR_INTR_FLAG);
 
-       if (status & DT3000_ADFULL)
+       if (status & DPR_INTR_ADFULL)
                dt3k_ai_empty_fifo(dev, s);
 
-       if (status & (DT3000_ADSWERR | DT3000_ADHWERR))
+       if (status & (DPR_INTR_ADSWERR | DPR_INTR_ADHWERR))
                s->async->events |= COMEDI_CB_ERROR;
 
        debug_n_ints++;
@@ -486,46 +472,49 @@ static int dt3k_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
                chan = CR_CHAN(cmd->chanlist[i]);
                range = CR_RANGE(cmd->chanlist[i]);
 
-               writew((range << 6) | chan, dev->mmio + DPR_ADC_buffer + i);
+               writew((range << 6) | chan, dev->mmio + DPR_ADC_BUFFER + i);
        }
        aref = CR_AREF(cmd->chanlist[0]);
 
-       writew(cmd->scan_end_arg, dev->mmio + DPR_Params(0));
+       writew(cmd->scan_end_arg, dev->mmio + DPR_PARAMS(0));
 
        if (cmd->convert_src == TRIG_TIMER) {
                divider = dt3k_ns_to_timer(50, &cmd->convert_arg, cmd->flags);
-               writew((divider >> 16), dev->mmio + DPR_Params(1));
-               writew((divider & 0xffff), dev->mmio + DPR_Params(2));
+               writew((divider >> 16), dev->mmio + DPR_PARAMS(1));
+               writew((divider & 0xffff), dev->mmio + DPR_PARAMS(2));
        }
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                tscandiv = dt3k_ns_to_timer(100, &cmd->scan_begin_arg,
                                            cmd->flags);
-               writew((tscandiv >> 16), dev->mmio + DPR_Params(3));
-               writew((tscandiv & 0xffff), dev->mmio + DPR_Params(4));
+               writew((tscandiv >> 16), dev->mmio + DPR_PARAMS(3));
+               writew((tscandiv & 0xffff), dev->mmio + DPR_PARAMS(4));
        }
 
-       writew(DT3000_AD_RETRIG_INTERNAL, dev->mmio + DPR_Params(5));
-       writew(aref == AREF_DIFF, dev->mmio + DPR_Params(6));
+       writew(DPR_PARAM5_AD_TRIG_INT_RETRIG, dev->mmio + DPR_PARAMS(5));
+       writew((aref == AREF_DIFF) ? DPR_PARAM6_AD_DIFF : 0,
+              dev->mmio + DPR_PARAMS(6));
 
-       writew(AI_FIFO_DEPTH / 2, dev->mmio + DPR_Params(7));
+       writew(DPR_AI_FIFO_DEPTH / 2, dev->mmio + DPR_PARAMS(7));
 
-       writew(SUBS_AI, dev->mmio + DPR_SubSys);
-       dt3k_send_cmd(dev, CMD_CONFIG);
+       writew(DPR_SUBSYS_AI, dev->mmio + DPR_SUBSYS);
+       dt3k_send_cmd(dev, DPR_CMD_CONFIG);
 
-       writew(DT3000_ADFULL | DT3000_ADSWERR | DT3000_ADHWERR,
-              dev->mmio + DPR_Int_Mask);
+       writew(DPR_INTR_ADFULL | DPR_INTR_ADSWERR | DPR_INTR_ADHWERR,
+              dev->mmio + DPR_INT_MASK);
 
        debug_n_ints = 0;
 
-       writew(SUBS_AI, dev->mmio + DPR_SubSys);
-       dt3k_send_cmd(dev, CMD_START);
+       writew(DPR_SUBSYS_AI, dev->mmio + DPR_SUBSYS);
+       dt3k_send_cmd(dev, DPR_CMD_START);
 
        return 0;
 }
 
-static int dt3k_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
-                       struct comedi_insn *insn, unsigned int *data)
+static int dt3k_ai_insn_read(struct comedi_device *dev,
+                            struct comedi_subdevice *s,
+                            struct comedi_insn *insn,
+                            unsigned int *data)
 {
        int i;
        unsigned int chan, gain, aref;
@@ -536,7 +525,7 @@ static int dt3k_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s,
        aref = CR_AREF(insn->chanspec);
 
        for (i = 0; i < insn->n; i++)
-               data[i] = dt3k_readsingle(dev, SUBS_AI, chan, gain);
+               data[i] = dt3k_readsingle(dev, DPR_SUBSYS_AI, chan, gain);
 
        return i;
 }
@@ -552,7 +541,7 @@ static int dt3k_ao_insn_write(struct comedi_device *dev,
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               dt3k_writesingle(dev, SUBS_AO, chan, val);
+               dt3k_writesingle(dev, DPR_SUBSYS_AO, chan, val);
        }
        s->readback[chan] = val;
 
@@ -562,16 +551,13 @@ static int dt3k_ao_insn_write(struct comedi_device *dev,
 static void dt3k_dio_config(struct comedi_device *dev, int bits)
 {
        /* XXX */
-       writew(SUBS_DOUT, dev->mmio + DPR_SubSys);
+       writew(DPR_SUBSYS_DOUT, dev->mmio + DPR_SUBSYS);
 
-       writew(bits, dev->mmio + DPR_Params(0));
-#if 0
-       /* don't know */
-       writew(0, dev->mmio + DPR_Params(1));
-       writew(0, dev->mmio + DPR_Params(2));
-#endif
+       writew(bits, dev->mmio + DPR_PARAMS(0));
 
-       dt3k_send_cmd(dev, CMD_CONFIG);
+       /* XXX write 0 to DPR_PARAMS(1) and DPR_PARAMS(2) ? */
+
+       dt3k_send_cmd(dev, DPR_CMD_CONFIG);
 }
 
 static int dt3k_dio_insn_config(struct comedi_device *dev,
@@ -603,9 +589,9 @@ static int dt3k_dio_insn_bits(struct comedi_device *dev,
                              unsigned int *data)
 {
        if (comedi_dio_update_state(s, data))
-               dt3k_writesingle(dev, SUBS_DOUT, 0, s->state);
+               dt3k_writesingle(dev, DPR_SUBSYS_DOUT, 0, s->state);
 
-       data[1] = dt3k_readsingle(dev, SUBS_DIN, 0, 0);
+       data[1] = dt3k_readsingle(dev, DPR_SUBSYS_DIN, 0, 0);
 
        return insn->n;
 }
@@ -619,13 +605,13 @@ static int dt3k_mem_insn_read(struct comedi_device *dev,
        int i;
 
        for (i = 0; i < insn->n; i++) {
-               writew(SUBS_MEM, dev->mmio + DPR_SubSys);
-               writew(addr, dev->mmio + DPR_Params(0));
-               writew(1, dev->mmio + DPR_Params(1));
+               writew(DPR_SUBSYS_MEM, dev->mmio + DPR_SUBSYS);
+               writew(addr, dev->mmio + DPR_PARAMS(0));
+               writew(1, dev->mmio + DPR_PARAMS(1));
 
-               dt3k_send_cmd(dev, CMD_READCODE);
+               dt3k_send_cmd(dev, DPR_CMD_READCODE);
 
-               data[i] = readw(dev->mmio + DPR_Params(2));
+               data[i] = readw(dev->mmio + DPR_PARAMS(2));
        }
 
        return i;
@@ -670,14 +656,14 @@ static int dt3000_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       /* ai subdevice */
        s->type         = COMEDI_SUBD_AI;
        s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
        s->n_chan       = board->adchan;
-       s->insn_read    = dt3k_ai_insn;
-       s->maxdata      = (1 << board->adbits) - 1;
+       s->maxdata      = board->ai_is_16bit ? 0xffff : 0x0fff;
        s->range_table  = &range_dt3000_ai;     /* XXX */
+       s->insn_read    = dt3k_ai_insn_read;
        if (dev->irq) {
                dev->read_subdev = s;
                s->subdev_flags |= SDF_CMD_READ;
@@ -687,46 +673,42 @@ static int dt3000_auto_attach(struct comedi_device *dev,
                s->cancel       = dt3k_ai_cancel;
        }
 
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       /* ao subsystem */
-       s->type         = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan       = 2;
-       s->maxdata      = (1 << board->dabits) - 1;
-       s->len_chanlist = 1;
-       s->range_table  = &range_bipolar10;
-       s->insn_write   = dt3k_ao_insn_write;
-
-       ret = comedi_alloc_subdev_readback(s);
-       if (ret)
-               return ret;
+       if (board->has_ao) {
+               s->type         = COMEDI_SUBD_AO;
+               s->subdev_flags = SDF_WRITABLE;
+               s->n_chan       = 2;
+               s->maxdata      = 0x0fff;
+               s->range_table  = &range_bipolar10;
+               s->insn_write   = dt3k_ao_insn_write;
+
+               ret = comedi_alloc_subdev_readback(s);
+               if (ret)
+                       return ret;
+
+       } else {
+               s->type         = COMEDI_SUBD_UNUSED;
+       }
 
+       /* Digital I/O subdevice */
        s = &dev->subdevices[2];
-       /* dio subsystem */
        s->type         = COMEDI_SUBD_DIO;
        s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
        s->n_chan       = 8;
-       s->insn_config  = dt3k_dio_insn_config;
-       s->insn_bits    = dt3k_dio_insn_bits;
        s->maxdata      = 1;
-       s->len_chanlist = 8;
        s->range_table  = &range_digital;
+       s->insn_config  = dt3k_dio_insn_config;
+       s->insn_bits    = dt3k_dio_insn_bits;
 
+       /* Memory subdevice */
        s = &dev->subdevices[3];
-       /* mem subsystem */
        s->type         = COMEDI_SUBD_MEMORY;
        s->subdev_flags = SDF_READABLE;
        s->n_chan       = 0x1000;
-       s->insn_read    = dt3k_mem_insn_read;
        s->maxdata      = 0xff;
-       s->len_chanlist = 1;
        s->range_table  = &range_unknown;
-
-#if 0
-       s = &dev->subdevices[4];
-       /* proc subsystem */
-       s->type = COMEDI_SUBD_PROC;
-#endif
+       s->insn_read    = dt3k_mem_insn_read;
 
        return 0;
 }
@@ -765,5 +747,5 @@ static struct pci_driver dt3000_pci_driver = {
 module_comedi_pci_driver(dt3000_driver, dt3000_pci_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Data Translation DT3000 series boards");
 MODULE_LICENSE("GPL");
index e11c216a4c853f6246a7122e1db1ba9b2d199584..3295bb4ac8c4cf5a45606569bbfd940b9ab0da3c 100644 (file)
  */
 
 /*
-Driver: dt9812
-Description: Data Translation DT9812 USB module
-Author: anders.blomdell@control.lth.se (Anders Blomdell)
-Status: in development
-Devices: [Data Translation] DT9812 (dt9812)
-Updated: Sun Nov 20 20:18:34 EST 2005
-
-This driver works, but bulk transfers not implemented. Might be a starting point
-for someone else. I found out too late that USB has too high latencies (>1 ms)
-for my needs.
-*/
+ * Driver: dt9812
+ * Description: Data Translation DT9812 USB module
+ * Devices: [Data Translation] DT9812 (dt9812)
+ * Author: anders.blomdell@control.lth.se (Anders Blomdell)
+ * Status: in development
+ * Updated: Sun Nov 20 20:18:34 EST 2005
+ *
+ * This driver works, but bulk transfers not implemented. Might be a
+ * starting point for someone else. I found out too late that USB has
+ * too high latencies (>1 ms) for my needs.
+ */
 
 /*
  * Nota Bene:
@@ -80,7 +80,7 @@ for my needs.
 #define F020_MASK_ADC0CN_AD0INT                0x20
 #define F020_MASK_ADC0CN_AD0BUSY       0x10
 
-#define F020_MASK_DACxCN_DACxEN                0x80
+#define F020_MASK_DACXCN_DACXEN                0x80
 
 enum {
                                        /* A/D  D/A  DI  DO  CT */
@@ -233,7 +233,7 @@ struct dt9812_usb_cmd {
 };
 
 struct dt9812_private {
-       struct semaphore sem;
+       struct mutex mut;
        struct {
                __u8 addr;
                size_t size;
@@ -335,7 +335,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits)
        u8 value[2];
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        ret = dt9812_read_multiple_registers(dev, 2, reg, value);
        if (ret == 0) {
                /*
@@ -345,7 +345,7 @@ static int dt9812_digital_in(struct comedi_device *dev, u8 *bits)
                 */
                *bits = (value[0] & 0x7f) | ((value[1] & 0x08) << 4);
        }
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -357,9 +357,9 @@ static int dt9812_digital_out(struct comedi_device *dev, u8 bits)
        u8 value[1] = { bits };
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        ret = dt9812_write_multiple_registers(dev, 1, reg, value);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -444,7 +444,7 @@ static int dt9812_analog_in(struct comedi_device *dev,
        u8 val[3];
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        /* 1 select the gain */
        dt9812_configure_gain(dev, &rmw[0], gain);
@@ -493,7 +493,7 @@ static int dt9812_analog_in(struct comedi_device *dev,
        }
 
 exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -504,22 +504,21 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
        struct dt9812_rmw_byte rmw[3];
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        switch (channel) {
        case 0:
                /* 1. Set DAC mode */
                rmw[0].address = F020_SFR_DAC0CN;
                rmw[0].and_mask = 0xff;
-               rmw[0].or_value = F020_MASK_DACxCN_DACxEN;
+               rmw[0].or_value = F020_MASK_DACXCN_DACXEN;
 
-               /* 2 load low byte of DAC value first */
+               /* 2. load lsb of DAC value first */
                rmw[1].address = F020_SFR_DAC0L;
                rmw[1].and_mask = 0xff;
                rmw[1].or_value = value & 0xff;
 
-               /* 3 load high byte of DAC value next to latch the
-                       12-bit value */
+               /* 3. load msb of DAC value next to latch the 12-bit value */
                rmw[2].address = F020_SFR_DAC0H;
                rmw[2].and_mask = 0xff;
                rmw[2].or_value = (value >> 8) & 0xf;
@@ -529,15 +528,14 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
                /* 1. Set DAC mode */
                rmw[0].address = F020_SFR_DAC1CN;
                rmw[0].and_mask = 0xff;
-               rmw[0].or_value = F020_MASK_DACxCN_DACxEN;
+               rmw[0].or_value = F020_MASK_DACXCN_DACXEN;
 
-               /* 2 load low byte of DAC value first */
+               /* 2. load lsb of DAC value first */
                rmw[1].address = F020_SFR_DAC1L;
                rmw[1].and_mask = 0xff;
                rmw[1].or_value = value & 0xff;
 
-               /* 3 load high byte of DAC value next to latch the
-                       12-bit value */
+               /* 3. load msb of DAC value next to latch the 12-bit value */
                rmw[2].address = F020_SFR_DAC1H;
                rmw[2].and_mask = 0xff;
                rmw[2].or_value = (value >> 8) & 0xf;
@@ -545,7 +543,7 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
        }
        ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -608,9 +606,9 @@ static int dt9812_ao_insn_read(struct comedi_device *dev,
        struct dt9812_private *devpriv = dev->private;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        ret = comedi_readback_insn_read(dev, s, insn, data);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -774,7 +772,7 @@ static int dt9812_auto_attach(struct comedi_device *dev,
        if (!devpriv)
                return -ENOMEM;
 
-       sema_init(&devpriv->sem, 1);
+       mutex_init(&devpriv->mut);
        usb_set_intfdata(intf, devpriv);
 
        ret = dt9812_find_endpoints(dev);
@@ -846,11 +844,11 @@ static void dt9812_detach(struct comedi_device *dev)
        if (!devpriv)
                return;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        usb_set_intfdata(intf, NULL);
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 }
 
 static struct comedi_driver dt9812_driver = {
index 55cae61458cb975a2d3b3f5abf98e04611e021cb..0f278ffdad76b70294d91089b7aebc5db3c733ee 100644 (file)
@@ -71,7 +71,7 @@ static int fl512_ai_insn_read(struct comedi_device *dev,
                outb(0, dev->iobase + FL512_AI_START_CONV_REG);
 
                /* XXX should test "done" flag instead of delay */
-               udelay(30);
+               usleep_range(30, 100);
 
                val = inb(dev->iobase + FL512_AI_LSB_REG);
                val |= (inb(dev->iobase + FL512_AI_MSB_REG) << 8);
index e9296182236e852a69035c9fb0e192e134e52d70..46ca5d938d5b62f00d5d18de5a534338dc2664d9 100644 (file)
 
 struct hpdi_private {
        void __iomem *plx9080_mmio;
-       uint32_t *dio_buffer[NUM_DMA_BUFFERS];  /* dma buffers */
+       u32 *dio_buffer[NUM_DMA_BUFFERS];       /* dma buffers */
        /* physical addresses of dma buffers */
        dma_addr_t dio_buffer_phys_addr[NUM_DMA_BUFFERS];
        /*
@@ -137,7 +137,7 @@ struct hpdi_private {
        dma_addr_t dma_desc_phys_addr;
        unsigned int num_dma_descriptors;
        /* pointer to start of buffers indexed by descriptor */
-       uint32_t *desc_dio_buffer[NUM_DMA_DESCRIPTORS];
+       u32 *desc_dio_buffer[NUM_DMA_DESCRIPTORS];
        /* index of the dma descriptor that is currently being used */
        unsigned int dma_desc_index;
        unsigned int tx_fifo_size;
@@ -169,7 +169,7 @@ static void gsc_hpdi_drain_dma(struct comedi_device *dev, unsigned int channel)
        for (desc = 0; (next < start || next >= start + devpriv->block_size) &&
             desc < devpriv->num_dma_descriptors; desc++) {
                /* transfer data from dma buffer to comedi buffer */
-               size = devpriv->block_size / sizeof(uint32_t);
+               size = devpriv->block_size / sizeof(u32);
                if (cmd->stop_src == TRIG_COUNT) {
                        if (size > devpriv->dio_count)
                                size = devpriv->dio_count;
@@ -192,10 +192,10 @@ static irqreturn_t gsc_hpdi_interrupt(int irq, void *d)
        struct hpdi_private *devpriv = dev->private;
        struct comedi_subdevice *s = dev->read_subdev;
        struct comedi_async *async = s->async;
-       uint32_t hpdi_intr_status, hpdi_board_status;
-       uint32_t plx_status;
-       uint32_t plx_bits;
-       uint8_t dma0_status, dma1_status;
+       u32 hpdi_intr_status, hpdi_board_status;
+       u32 plx_status;
+       u32 plx_bits;
+       u8 dma0_status, dma1_status;
        unsigned long flags;
 
        if (!dev->attached)
@@ -290,7 +290,7 @@ static int gsc_hpdi_cmd(struct comedi_device *dev,
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
        unsigned long flags;
-       uint32_t bits;
+       u32 bits;
 
        if (s->io_bits)
                return -EINVAL;
@@ -424,15 +424,15 @@ static int gsc_hpdi_setup_dma_descriptors(struct comedi_device *dev,
 {
        struct hpdi_private *devpriv = dev->private;
        dma_addr_t phys_addr = devpriv->dma_desc_phys_addr;
-       uint32_t next_bits = PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT |
-                            PLX_XFER_LOCAL_TO_PCI;
+       u32 next_bits = PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT |
+                       PLX_XFER_LOCAL_TO_PCI;
        unsigned int offset = 0;
        unsigned int idx = 0;
        unsigned int i;
 
        if (len > DMA_BUFFER_SIZE)
                len = DMA_BUFFER_SIZE;
-       len -= len % sizeof(uint32_t);
+       len -= len % sizeof(u32);
        if (len == 0)
                return -EINVAL;
 
@@ -445,7 +445,7 @@ static int gsc_hpdi_setup_dma_descriptors(struct comedi_device *dev,
                        (i + 1) * sizeof(devpriv->dma_desc[0])) | next_bits);
 
                devpriv->desc_dio_buffer[i] = devpriv->dio_buffer[idx] +
-                                             (offset / sizeof(uint32_t));
+                                             (offset / sizeof(u32));
 
                offset += len;
                if (len + offset > DMA_BUFFER_SIZE) {
@@ -516,7 +516,7 @@ static void gsc_hpdi_free_dma(struct comedi_device *dev)
 static int gsc_hpdi_init(struct comedi_device *dev)
 {
        struct hpdi_private *devpriv = dev->private;
-       uint32_t plx_intcsr_bits;
+       u32 plx_intcsr_bits;
 
        /* wait 10usec after reset before accessing fifos */
        writel(BOARD_RESET_BIT, dev->mmio + BOARD_CONTROL_REG);
@@ -546,7 +546,7 @@ static int gsc_hpdi_init(struct comedi_device *dev)
 static void gsc_hpdi_init_plx9080(struct comedi_device *dev)
 {
        struct hpdi_private *devpriv = dev->private;
-       uint32_t bits;
+       u32 bits;
        void __iomem *plx_iobase = devpriv->plx9080_mmio;
 
 #ifdef __BIG_ENDIAN
index 1e104ebf80576e472f3792666c8756a54fa1e32c..28cf53e48b8d88a68b610f002dab6009a6ef3100 100644 (file)
@@ -1,94 +1,89 @@
 /*
-    comedi/drivers/icp_multi.c
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 1997-2002 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
+ * icp_multi.c
+ * Comedi driver for Inova ICP_MULTI board
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 1997-2002 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
 /*
-Driver: icp_multi
-Description: Inova ICP_MULTI
-Author: Anne Smorthit <anne.smorthit@sfwte.ch>
-Devices: [Inova] ICP_MULTI (icp_multi)
-Status: works
-
-The driver works for analog input and output and digital input and output.
-It does not work with interrupts or with the counters.  Currently no support
-for DMA.
-
-It has 16 single-ended or 8 differential Analogue Input channels with 12-bit
-resolution.  Ranges : 5V, 10V, +/-5V, +/-10V, 0..20mA and 4..20mA.  Input
-ranges can be individually programmed for each channel.  Voltage or current
-measurement is selected by jumper.
-
-There are 4 x 12-bit Analogue Outputs.  Ranges : 5V, 10V, +/-5V, +/-10V
-
-16 x Digital Inputs, 24V
-
-8 x Digital Outputs, 24V, 1A
-
-4 x 16-bit counters
-
-Configuration options: not applicable, uses PCI auto config
-*/
+ * Driver: icp_multi
+ * Description: Inova ICP_MULTI
+ * Devices: [Inova] ICP_MULTI (icp_multi)
+ * Author: Anne Smorthit <anne.smorthit@sfwte.ch>
+ * Status: works
+ *
+ * Configuration options: not applicable, uses PCI auto config
+ *
+ * The driver works for analog input and output and digital input and
+ * output. It does not work with interrupts or with the counters. Currently
+ * no support for DMA.
+ *
+ * It has 16 single-ended or 8 differential Analogue Input channels with
+ * 12-bit resolution.  Ranges : 5V, 10V, +/-5V, +/-10V, 0..20mA and 4..20mA.
+ * Input ranges can be individually programmed for each channel.  Voltage or
+ * current measurement is selected by jumper.
+ *
+ * There are 4 x 12-bit Analogue Outputs.  Ranges : 5V, 10V, +/-5V, +/-10V
+ *
+ * 16 x Digital Inputs, 24V
+ *
+ * 8 x Digital Outputs, 24V, 1A
+ *
+ * 4 x 16-bit counters - not implemented
+ */
 
 #include <linux/module.h>
 #include <linux/delay.h>
-#include <linux/interrupt.h>
 
 #include "../comedi_pci.h"
 
-#define ICP_MULTI_ADC_CSR      0       /* R/W: ADC command/status register */
+#define ICP_MULTI_ADC_CSR      0x00    /* R/W: ADC command/status register */
+#define ICP_MULTI_ADC_CSR_ST   BIT(0)  /* Start ADC */
+#define ICP_MULTI_ADC_CSR_BSY  BIT(0)  /* ADC busy */
+#define ICP_MULTI_ADC_CSR_BI   BIT(4)  /* Bipolar input range */
+#define ICP_MULTI_ADC_CSR_RA   BIT(5)  /* Input range 0 = 5V, 1 = 10V */
+#define ICP_MULTI_ADC_CSR_DI   BIT(6)  /* Input mode 1 = differential */
+#define ICP_MULTI_ADC_CSR_DI_CHAN(x) (((x) & 0x7) << 9)
+#define ICP_MULTI_ADC_CSR_SE_CHAN(x) (((x) & 0xf) << 8)
 #define ICP_MULTI_AI           2       /* R:   Analogue input data */
-#define ICP_MULTI_DAC_CSR      4       /* R/W: DAC command/status register */
+#define ICP_MULTI_DAC_CSR      0x04    /* R/W: DAC command/status register */
+#define ICP_MULTI_DAC_CSR_ST   BIT(0)  /* Start DAC */
+#define ICP_MULTI_DAC_CSR_BSY  BIT(0)  /* DAC busy */
+#define ICP_MULTI_DAC_CSR_BI   BIT(4)  /* Bipolar output range */
+#define ICP_MULTI_DAC_CSR_RA   BIT(5)  /* Output range 0 = 5V, 1 = 10V */
+#define ICP_MULTI_DAC_CSR_CHAN(x) (((x) & 0x3) << 8)
 #define ICP_MULTI_AO           6       /* R/W: Analogue output data */
 #define ICP_MULTI_DI           8       /* R/W: Digital inputs */
 #define ICP_MULTI_DO           0x0A    /* R/W: Digital outputs */
-#define ICP_MULTI_INT_EN       0x0C    /* R/W: Interrupt enable register */
-#define ICP_MULTI_INT_STAT     0x0E    /* R/W: Interrupt status register */
+#define ICP_MULTI_INT_EN       0x0c    /* R/W: Interrupt enable register */
+#define ICP_MULTI_INT_STAT     0x0e    /* R/W: Interrupt status register */
+#define ICP_MULTI_INT_ADC_RDY  BIT(0)  /* A/D conversion ready interrupt */
+#define ICP_MULTI_INT_DAC_RDY  BIT(1)  /* D/A conversion ready interrupt */
+#define ICP_MULTI_INT_DOUT_ERR BIT(2)  /* Digital output error interrupt */
+#define ICP_MULTI_INT_DIN_STAT BIT(3)  /* Digital input status change int. */
+#define ICP_MULTI_INT_CIE0     BIT(4)  /* Counter 0 overrun interrupt */
+#define ICP_MULTI_INT_CIE1     BIT(5)  /* Counter 1 overrun interrupt */
+#define ICP_MULTI_INT_CIE2     BIT(6)  /* Counter 2 overrun interrupt */
+#define ICP_MULTI_INT_CIE3     BIT(7)  /* Counter 3 overrun interrupt */
+#define ICP_MULTI_INT_MASK     0xff    /* All interrupts */
 #define ICP_MULTI_CNTR0                0x10    /* R/W: Counter 0 */
 #define ICP_MULTI_CNTR1                0x12    /* R/W: counter 1 */
 #define ICP_MULTI_CNTR2                0x14    /* R/W: Counter 2 */
 #define ICP_MULTI_CNTR3                0x16    /* R/W: Counter 3 */
 
-/*  Define bits from ADC command/status register */
-#define        ADC_ST          0x0001  /* Start ADC */
-#define        ADC_BSY         0x0001  /* ADC busy */
-#define ADC_BI         0x0010  /* Bipolar input range 1 = bipolar */
-#define ADC_RA         0x0020  /* Input range 0 = 5V, 1 = 10V */
-#define        ADC_DI          0x0040  /* Differential input mode 1 = differential */
-
-/*  Define bits from DAC command/status register */
-#define        DAC_ST          0x0001  /* Start DAC */
-#define DAC_BSY                0x0001  /* DAC busy */
-#define        DAC_BI          0x0010  /* Bipolar input range 1 = bipolar */
-#define        DAC_RA          0x0020  /* Input range 0 = 5V, 1 = 10V */
-
-/*  Define bits from interrupt enable/status registers */
-#define        ADC_READY       0x0001  /* A/d conversion ready interrupt */
-#define        DAC_READY       0x0002  /* D/a conversion ready interrupt */
-#define        DOUT_ERROR      0x0004  /* Digital output error interrupt */
-#define        DIN_STATUS      0x0008  /* Digital input status change interrupt */
-#define        CIE0            0x0010  /* Counter 0 overrun interrupt */
-#define        CIE1            0x0020  /* Counter 1 overrun interrupt */
-#define        CIE2            0x0040  /* Counter 2 overrun interrupt */
-#define        CIE3            0x0080  /* Counter 3 overrun interrupt */
-
-/*  Useful definitions */
-#define        Status_IRQ      0x00ff  /*  All interrupts */
-
-/*  Define analogue range */
-static const struct comedi_lrange range_analog = {
+/* analog input and output have the same range options */
+static const struct comedi_lrange icp_multi_ranges = {
        4, {
                UNI_RANGE(5),
                UNI_RANGE(10),
@@ -99,71 +94,6 @@ static const struct comedi_lrange range_analog = {
 
 static const char range_codes_analog[] = { 0x00, 0x20, 0x10, 0x30 };
 
-/*
-==============================================================================
-       Data & Structure declarations
-==============================================================================
-*/
-
-struct icp_multi_private {
-       unsigned int AdcCmdStatus;      /*  ADC Command/Status register */
-       unsigned int DacCmdStatus;      /*  DAC Command/Status register */
-       unsigned int IntEnable; /*  Interrupt Enable register */
-       unsigned int IntStatus; /*  Interrupt Status register */
-       unsigned int act_chanlist[32];  /*  list of scanned channel */
-       unsigned char act_chanlist_len; /*  len of scanlist */
-       unsigned char act_chanlist_pos; /*  actual position in MUX list */
-       unsigned int *ai_chanlist;      /*  actaul chanlist */
-       unsigned int do_data;   /*  Remember digital output data */
-};
-
-static void setup_channel_list(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              unsigned int *chanlist, unsigned int n_chan)
-{
-       struct icp_multi_private *devpriv = dev->private;
-       unsigned int i, range, chanprog;
-       unsigned int diff;
-
-       devpriv->act_chanlist_len = n_chan;
-       devpriv->act_chanlist_pos = 0;
-
-       for (i = 0; i < n_chan; i++) {
-               /*  Get channel */
-               chanprog = CR_CHAN(chanlist[i]);
-
-               /*  Determine if it is a differential channel (Bit 15  = 1) */
-               if (CR_AREF(chanlist[i]) == AREF_DIFF) {
-                       diff = 1;
-                       chanprog &= 0x0007;
-               } else {
-                       diff = 0;
-                       chanprog &= 0x000f;
-               }
-
-               /*  Clear channel, range and input mode bits
-                *  in A/D command/status register */
-               devpriv->AdcCmdStatus &= 0xf00f;
-
-               /*  Set channel number and differential mode status bit */
-               if (diff) {
-                       /*  Set channel number, bits 9-11 & mode, bit 6 */
-                       devpriv->AdcCmdStatus |= (chanprog << 9);
-                       devpriv->AdcCmdStatus |= ADC_DI;
-               } else
-                       /*  Set channel number, bits 8-11 */
-                       devpriv->AdcCmdStatus |= (chanprog << 8);
-
-               /*  Get range for current channel */
-               range = range_codes_analog[CR_RANGE(chanlist[i])];
-               /*  Set range. bits 4-5 */
-               devpriv->AdcCmdStatus |= range;
-
-               /* Output channel, range, mode to ICP Multi */
-               writew(devpriv->AdcCmdStatus, dev->mmio + ICP_MULTI_ADC_CSR);
-       }
-}
-
 static int icp_multi_ai_eoc(struct comedi_device *dev,
                            struct comedi_subdevice *s,
                            struct comedi_insn *insn,
@@ -172,36 +102,37 @@ static int icp_multi_ai_eoc(struct comedi_device *dev,
        unsigned int status;
 
        status = readw(dev->mmio + ICP_MULTI_ADC_CSR);
-       if ((status & ADC_BSY) == 0)
+       if ((status & ICP_MULTI_ADC_CSR_BSY) == 0)
                return 0;
        return -EBUSY;
 }
 
-static int icp_multi_insn_read_ai(struct comedi_device *dev,
+static int icp_multi_ai_insn_read(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
                                  struct comedi_insn *insn,
                                  unsigned int *data)
 {
-       struct icp_multi_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int range = CR_RANGE(insn->chanspec);
+       unsigned int aref = CR_AREF(insn->chanspec);
+       unsigned int adc_csr;
        int ret = 0;
        int n;
 
-       /*  Disable A/D conversion ready interrupt */
-       devpriv->IntEnable &= ~ADC_READY;
-       writew(devpriv->IntEnable, dev->mmio + ICP_MULTI_INT_EN);
-
-       /*  Clear interrupt status */
-       devpriv->IntStatus |= ADC_READY;
-       writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT);
-
-       /*  Set up appropriate channel, mode and range data, for specified ch */
-       setup_channel_list(dev, s, &insn->chanspec, 1);
+       /* Set mode and range data for specified channel */
+       if (aref == AREF_DIFF) {
+               adc_csr = ICP_MULTI_ADC_CSR_DI_CHAN(chan) |
+                         ICP_MULTI_ADC_CSR_DI;
+       } else {
+               adc_csr = ICP_MULTI_ADC_CSR_SE_CHAN(chan);
+       }
+       adc_csr |= range_codes_analog[range];
+       writew(adc_csr, dev->mmio + ICP_MULTI_ADC_CSR);
 
        for (n = 0; n < insn->n; n++) {
                /*  Set start ADC bit */
-               devpriv->AdcCmdStatus |= ADC_ST;
-               writew(devpriv->AdcCmdStatus, dev->mmio + ICP_MULTI_ADC_CSR);
-               devpriv->AdcCmdStatus &= ~ADC_ST;
+               writew(adc_csr | ICP_MULTI_ADC_CSR_ST,
+                      dev->mmio + ICP_MULTI_ADC_CSR);
 
                udelay(1);
 
@@ -213,26 +144,18 @@ static int icp_multi_insn_read_ai(struct comedi_device *dev,
                data[n] = (readw(dev->mmio + ICP_MULTI_AI) >> 4) & 0x0fff;
        }
 
-       /*  Disable interrupt */
-       devpriv->IntEnable &= ~ADC_READY;
-       writew(devpriv->IntEnable, dev->mmio + ICP_MULTI_INT_EN);
-
-       /*  Clear interrupt status */
-       devpriv->IntStatus |= ADC_READY;
-       writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT);
-
        return ret ? ret : n;
 }
 
-static int icp_multi_ao_eoc(struct comedi_device *dev,
-                           struct comedi_subdevice *s,
-                           struct comedi_insn *insn,
-                           unsigned long context)
+static int icp_multi_ao_ready(struct comedi_device *dev,
+                             struct comedi_subdevice *s,
+                             struct comedi_insn *insn,
+                             unsigned long context)
 {
        unsigned int status;
 
        status = readw(dev->mmio + ICP_MULTI_DAC_CSR);
-       if ((status & DAC_BSY) == 0)
+       if ((status & ICP_MULTI_DAC_CSR_BSY) == 0)
                return 0;
        return -EBUSY;
 }
@@ -242,57 +165,30 @@ static int icp_multi_ao_insn_write(struct comedi_device *dev,
                                   struct comedi_insn *insn,
                                   unsigned int *data)
 {
-       struct icp_multi_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
+       unsigned int dac_csr;
        int i;
 
-       /*  Disable D/A conversion ready interrupt */
-       devpriv->IntEnable &= ~DAC_READY;
-       writew(devpriv->IntEnable, dev->mmio + ICP_MULTI_INT_EN);
-
-       /*  Clear interrupt status */
-       devpriv->IntStatus |= DAC_READY;
-       writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT);
-
-       /*  Set up range and channel data */
-       /*  Bit 4 = 1 : Bipolar */
-       /*  Bit 5 = 0 : 5V */
-       /*  Bit 5 = 1 : 10V */
-       /*  Bits 8-9 : Channel number */
-       devpriv->DacCmdStatus &= 0xfccf;
-       devpriv->DacCmdStatus |= range_codes_analog[range];
-       devpriv->DacCmdStatus |= (chan << 8);
-
-       writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR);
+       /* Select channel and range */
+       dac_csr = ICP_MULTI_DAC_CSR_CHAN(chan);
+       dac_csr |= range_codes_analog[range];
+       writew(dac_csr, dev->mmio + ICP_MULTI_DAC_CSR);
 
        for (i = 0; i < insn->n; i++) {
                unsigned int val = data[i];
                int ret;
 
-               /*  Wait for analogue output data register to be
-                *  ready for new data, or get fed up waiting */
-               ret = comedi_timeout(dev, s, insn, icp_multi_ao_eoc, 0);
-               if (ret) {
-                       /*  Disable interrupt */
-                       devpriv->IntEnable &= ~DAC_READY;
-                       writew(devpriv->IntEnable,
-                              dev->mmio + ICP_MULTI_INT_EN);
-
-                       /*  Clear interrupt status */
-                       devpriv->IntStatus |= DAC_READY;
-                       writew(devpriv->IntStatus,
-                              dev->mmio + ICP_MULTI_INT_STAT);
-
+               /* Wait for analog output to be ready for new data */
+               ret = comedi_timeout(dev, s, insn, icp_multi_ao_ready, 0);
+               if (ret)
                        return ret;
-               }
 
                writew(val, dev->mmio + ICP_MULTI_AO);
 
-               /*  Set DAC_ST bit to write the data to selected channel */
-               devpriv->DacCmdStatus |= DAC_ST;
-               writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR);
-               devpriv->DacCmdStatus &= ~DAC_ST;
+               /* Set start conversion bit to write data to channel */
+               writew(dac_csr | ICP_MULTI_DAC_CSR_ST,
+                      dev->mmio + ICP_MULTI_DAC_CSR);
 
                s->readback[chan] = val;
        }
@@ -300,7 +196,7 @@ static int icp_multi_ao_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-static int icp_multi_insn_bits_di(struct comedi_device *dev,
+static int icp_multi_di_insn_bits(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
                                  struct comedi_insn *insn,
                                  unsigned int *data)
@@ -310,7 +206,7 @@ static int icp_multi_insn_bits_di(struct comedi_device *dev,
        return insn->n;
 }
 
-static int icp_multi_insn_bits_do(struct comedi_device *dev,
+static int icp_multi_do_insn_bits(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
                                  struct comedi_insn *insn,
                                  unsigned int *data)
@@ -323,116 +219,27 @@ static int icp_multi_insn_bits_do(struct comedi_device *dev,
        return insn->n;
 }
 
-static int icp_multi_insn_read_ctr(struct comedi_device *dev,
-                                  struct comedi_subdevice *s,
-                                  struct comedi_insn *insn, unsigned int *data)
-{
-       return 0;
-}
-
-static int icp_multi_insn_write_ctr(struct comedi_device *dev,
-                                   struct comedi_subdevice *s,
-                                   struct comedi_insn *insn,
-                                   unsigned int *data)
-{
-       return 0;
-}
-
-static irqreturn_t interrupt_service_icp_multi(int irq, void *d)
-{
-       struct comedi_device *dev = d;
-       int int_no;
-
-       /*  Is this interrupt from our board? */
-       int_no = readw(dev->mmio + ICP_MULTI_INT_STAT) & Status_IRQ;
-       if (!int_no)
-               /*  No, exit */
-               return IRQ_NONE;
-
-       /*  Determine which interrupt is active & handle it */
-       switch (int_no) {
-       case ADC_READY:
-               break;
-       case DAC_READY:
-               break;
-       case DOUT_ERROR:
-               break;
-       case DIN_STATUS:
-               break;
-       case CIE0:
-               break;
-       case CIE1:
-               break;
-       case CIE2:
-               break;
-       case CIE3:
-               break;
-       default:
-               break;
-       }
-
-       return IRQ_HANDLED;
-}
-
-#if 0
-static int check_channel_list(struct comedi_device *dev,
-                             struct comedi_subdevice *s,
-                             unsigned int *chanlist, unsigned int n_chan)
-{
-       unsigned int i;
-
-       /*  Check that we at least have one channel to check */
-       if (n_chan < 1) {
-               dev_err(dev->class_dev, "range/channel list is empty!\n");
-               return 0;
-       }
-       /*  Check all channels */
-       for (i = 0; i < n_chan; i++) {
-               /*  Check that channel number is < maximum */
-               if (CR_AREF(chanlist[i]) == AREF_DIFF) {
-                       if (CR_CHAN(chanlist[i]) > (s->nchan / 2)) {
-                               dev_err(dev->class_dev,
-                                       "Incorrect differential ai ch-nr\n");
-                               return 0;
-                       }
-               } else {
-                       if (CR_CHAN(chanlist[i]) > s->n_chan) {
-                               dev_err(dev->class_dev,
-                                       "Incorrect ai channel number\n");
-                               return 0;
-                       }
-               }
-       }
-       return 1;
-}
-#endif
-
 static int icp_multi_reset(struct comedi_device *dev)
 {
-       struct icp_multi_private *devpriv = dev->private;
-       unsigned int i;
+       int i;
 
-       /*  Clear INT enables and requests */
+       /* Disable all interrupts and clear any requests */
        writew(0, dev->mmio + ICP_MULTI_INT_EN);
-       writew(0x00ff, dev->mmio + ICP_MULTI_INT_STAT);
+       writew(ICP_MULTI_INT_MASK, dev->mmio + ICP_MULTI_INT_STAT);
 
-       /* Set DACs to 0..5V range and 0V output */
+       /* Reset the analog output channels to 0V */
        for (i = 0; i < 4; i++) {
-               devpriv->DacCmdStatus &= 0xfcce;
+               unsigned int dac_csr = ICP_MULTI_DAC_CSR_CHAN(i);
 
-               /*  Set channel number */
-               devpriv->DacCmdStatus |= (i << 8);
+               /* Select channel and 0..5V range */
+               writew(dac_csr, dev->mmio + ICP_MULTI_DAC_CSR);
 
-               /*  Output 0V */
+               /* Output 0V */
                writew(0, dev->mmio + ICP_MULTI_AO);
 
-               /*  Set start conversion bit */
-               devpriv->DacCmdStatus |= DAC_ST;
-
-               /*  Output to command / status register */
-               writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR);
-
-               /*  Delay to allow DAC time to recover */
+               /* Set start conversion bit to write data to channel */
+               writew(dac_csr | ICP_MULTI_DAC_CSR_ST,
+                      dev->mmio + ICP_MULTI_DAC_CSR);
                udelay(1);
        }
 
@@ -446,14 +253,9 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
                                 unsigned long context_unused)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       struct icp_multi_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
-       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-       if (!devpriv)
-               return -ENOMEM;
-
        ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
@@ -462,85 +264,60 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
        if (!dev->mmio)
                return -ENOMEM;
 
-       ret = comedi_alloc_subdevices(dev, 5);
+       ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;
 
        icp_multi_reset(dev);
 
-       if (pcidev->irq) {
-               ret = request_irq(pcidev->irq, interrupt_service_icp_multi,
-                                 IRQF_SHARED, dev->board_name, dev);
-               if (ret == 0)
-                       dev->irq = pcidev->irq;
-       }
-
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       dev->read_subdev = s;
-       s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF;
-       s->n_chan = 16;
-       s->maxdata = 0x0fff;
-       s->len_chanlist = 16;
-       s->range_table = &range_analog;
-       s->insn_read = icp_multi_insn_read_ai;
-
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF;
+       s->n_chan       = 16;
+       s->maxdata      = 0x0fff;
+       s->range_table  = &icp_multi_ranges;
+       s->insn_read    = icp_multi_ai_insn_read;
+
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
-       s->n_chan = 4;
-       s->maxdata = 0x0fff;
-       s->len_chanlist = 4;
-       s->range_table = &range_analog;
-       s->insn_write = icp_multi_ao_insn_write;
+       s->type         = COMEDI_SUBD_AO;
+       s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
+       s->n_chan       = 4;
+       s->maxdata      = 0x0fff;
+       s->range_table  = &icp_multi_ranges;
+       s->insn_write   = icp_multi_ao_insn_write;
 
        ret = comedi_alloc_subdev_readback(s);
        if (ret)
                return ret;
 
+       /* Digital Input subdevice */
        s = &dev->subdevices[2];
-       s->type = COMEDI_SUBD_DI;
-       s->subdev_flags = SDF_READABLE;
-       s->n_chan = 16;
-       s->maxdata = 1;
-       s->len_chanlist = 16;
-       s->range_table = &range_digital;
-       s->insn_bits = icp_multi_insn_bits_di;
-
+       s->type         = COMEDI_SUBD_DI;
+       s->subdev_flags = SDF_READABLE;
+       s->n_chan       = 16;
+       s->maxdata      = 1;
+       s->range_table  = &range_digital;
+       s->insn_bits    = icp_multi_di_insn_bits;
+
+       /* Digital Output subdevice */
        s = &dev->subdevices[3];
-       s->type = COMEDI_SUBD_DO;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan = 8;
-       s->maxdata = 1;
-       s->len_chanlist = 8;
-       s->range_table = &range_digital;
-       s->insn_bits = icp_multi_insn_bits_do;
-
-       s = &dev->subdevices[4];
-       s->type = COMEDI_SUBD_COUNTER;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan = 4;
-       s->maxdata = 0xffff;
-       s->len_chanlist = 4;
-       s->state = 0;
-       s->insn_read = icp_multi_insn_read_ctr;
-       s->insn_write = icp_multi_insn_write_ctr;
+       s->type         = COMEDI_SUBD_DO;
+       s->subdev_flags = SDF_WRITABLE;
+       s->n_chan       = 8;
+       s->maxdata      = 1;
+       s->range_table  = &range_digital;
+       s->insn_bits    = icp_multi_do_insn_bits;
 
        return 0;
 }
 
-static void icp_multi_detach(struct comedi_device *dev)
-{
-       if (dev->mmio)
-               icp_multi_reset(dev);
-       comedi_pci_detach(dev);
-}
-
 static struct comedi_driver icp_multi_driver = {
        .driver_name    = "icp_multi",
        .module         = THIS_MODULE,
        .auto_attach    = icp_multi_auto_attach,
-       .detach         = icp_multi_detach,
+       .detach         = comedi_pci_detach,
 };
 
 static int icp_multi_pci_probe(struct pci_dev *dev,
@@ -564,5 +341,5 @@ static struct pci_driver icp_multi_pci_driver = {
 module_comedi_pci_driver(icp_multi_driver, icp_multi_pci_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Inova ICP_MULTI board");
 MODULE_LICENSE("GPL");
index 14ef1f67dd420bb66d8a2ff90851a3544a277cf8..77e1d891f23218fc53615c41df221c714dee8905 100644 (file)
 #define II20K_SIZE                     0x400
 #define II20K_MOD_OFFSET               0x100
 #define II20K_ID_REG                   0x00
-#define II20K_ID_MOD1_EMPTY            (1 << 7)
-#define II20K_ID_MOD2_EMPTY            (1 << 6)
-#define II20K_ID_MOD3_EMPTY            (1 << 5)
+#define II20K_ID_MOD1_EMPTY            BIT(7)
+#define II20K_ID_MOD2_EMPTY            BIT(6)
+#define II20K_ID_MOD3_EMPTY            BIT(5)
 #define II20K_ID_MASK                  0x1f
 #define II20K_ID_PCI20001C_1A          0x1b    /* no on-board DIO */
 #define II20K_ID_PCI20001C_2A          0x1d    /* on-board DIO */
 #define II20K_MOD_STATUS_REG           0x40
-#define II20K_MOD_STATUS_IRQ_MOD1      (1 << 7)
-#define II20K_MOD_STATUS_IRQ_MOD2      (1 << 6)
-#define II20K_MOD_STATUS_IRQ_MOD3      (1 << 5)
+#define II20K_MOD_STATUS_IRQ_MOD1      BIT(7)
+#define II20K_MOD_STATUS_IRQ_MOD2      BIT(6)
+#define II20K_MOD_STATUS_IRQ_MOD3      BIT(5)
 #define II20K_DIO0_REG                 0x80
 #define II20K_DIO1_REG                 0x81
 #define II20K_DIR_ENA_REG              0x82
-#define II20K_DIR_DIO3_OUT             (1 << 7)
-#define II20K_DIR_DIO2_OUT             (1 << 6)
-#define II20K_BUF_DISAB_DIO3           (1 << 5)
-#define II20K_BUF_DISAB_DIO2           (1 << 4)
-#define II20K_DIR_DIO1_OUT             (1 << 3)
-#define II20K_DIR_DIO0_OUT             (1 << 2)
-#define II20K_BUF_DISAB_DIO1           (1 << 1)
-#define II20K_BUF_DISAB_DIO0           (1 << 0)
+#define II20K_DIR_DIO3_OUT             BIT(7)
+#define II20K_DIR_DIO2_OUT             BIT(6)
+#define II20K_BUF_DISAB_DIO3           BIT(5)
+#define II20K_BUF_DISAB_DIO2           BIT(4)
+#define II20K_DIR_DIO1_OUT             BIT(3)
+#define II20K_DIR_DIO0_OUT             BIT(2)
+#define II20K_BUF_DISAB_DIO1           BIT(1)
+#define II20K_BUF_DISAB_DIO0           BIT(0)
 #define II20K_CTRL01_REG               0x83
-#define II20K_CTRL01_SET               (1 << 7)
-#define II20K_CTRL01_DIO0_IN           (1 << 4)
-#define II20K_CTRL01_DIO1_IN           (1 << 1)
+#define II20K_CTRL01_SET               BIT(7)
+#define II20K_CTRL01_DIO0_IN           BIT(4)
+#define II20K_CTRL01_DIO1_IN           BIT(1)
 #define II20K_DIO2_REG                 0xc0
 #define II20K_DIO3_REG                 0xc1
 #define II20K_CTRL23_REG               0xc3
-#define II20K_CTRL23_SET               (1 << 7)
-#define II20K_CTRL23_DIO2_IN           (1 << 4)
-#define II20K_CTRL23_DIO3_IN           (1 << 1)
+#define II20K_CTRL23_SET               BIT(7)
+#define II20K_CTRL23_DIO2_IN           BIT(4)
+#define II20K_CTRL23_DIO3_IN           BIT(1)
 
 #define II20K_ID_PCI20006M_1           0xe2    /* 1 AO channels */
 #define II20K_ID_PCI20006M_2           0xe3    /* 2 AO channels */
 
 #define II20K_ID_PCI20341M_1           0x77    /* 4 AI channels */
 #define II20K_AI_STATUS_CMD_REG                0x01
-#define II20K_AI_STATUS_CMD_BUSY       (1 << 7)
-#define II20K_AI_STATUS_CMD_HW_ENA     (1 << 1)
-#define II20K_AI_STATUS_CMD_EXT_START  (1 << 0)
+#define II20K_AI_STATUS_CMD_BUSY       BIT(7)
+#define II20K_AI_STATUS_CMD_HW_ENA     BIT(1)
+#define II20K_AI_STATUS_CMD_EXT_START  BIT(0)
 #define II20K_AI_LSB_REG               0x02
 #define II20K_AI_MSB_REG               0x03
 #define II20K_AI_PACER_RESET_REG       0x04
 #define II20K_AI_16BIT_DATA_REG                0x06
 #define II20K_AI_CONF_REG              0x10
-#define II20K_AI_CONF_ENA              (1 << 2)
+#define II20K_AI_CONF_ENA              BIT(2)
 #define II20K_AI_OPT_REG               0x11
-#define II20K_AI_OPT_TRIG_ENA          (1 << 5)
-#define II20K_AI_OPT_TRIG_INV          (1 << 4)
+#define II20K_AI_OPT_TRIG_ENA          BIT(5)
+#define II20K_AI_OPT_TRIG_INV          BIT(4)
 #define II20K_AI_OPT_TIMEBASE(x)       (((x) & 0x3) << 1)
-#define II20K_AI_OPT_BURST_MODE                (1 << 0)
+#define II20K_AI_OPT_BURST_MODE                BIT(0)
 #define II20K_AI_STATUS_REG            0x12
-#define II20K_AI_STATUS_INT            (1 << 7)
-#define II20K_AI_STATUS_TRIG           (1 << 6)
-#define II20K_AI_STATUS_TRIG_ENA       (1 << 5)
-#define II20K_AI_STATUS_PACER_ERR      (1 << 2)
-#define II20K_AI_STATUS_DATA_ERR       (1 << 1)
-#define II20K_AI_STATUS_SET_TIME_ERR   (1 << 0)
+#define II20K_AI_STATUS_INT            BIT(7)
+#define II20K_AI_STATUS_TRIG           BIT(6)
+#define II20K_AI_STATUS_TRIG_ENA       BIT(5)
+#define II20K_AI_STATUS_PACER_ERR      BIT(2)
+#define II20K_AI_STATUS_DATA_ERR       BIT(1)
+#define II20K_AI_STATUS_SET_TIME_ERR   BIT(0)
 #define II20K_AI_LAST_CHAN_ADDR_REG    0x13
 #define II20K_AI_CUR_ADDR_REG          0x14
 #define II20K_AI_SET_TIME_REG          0x15
 #define II20K_AI_START_TRIG_REG                0x1a
 #define II20K_AI_COUNT_RESET_REG       0x1b
 #define II20K_AI_CHANLIST_REG          0x80
-#define II20K_AI_CHANLIST_ONBOARD_ONLY (1 << 5)
+#define II20K_AI_CHANLIST_ONBOARD_ONLY BIT(5)
 #define II20K_AI_CHANLIST_GAIN(x)      (((x) & 0x3) << 3)
-#define II20K_AI_CHANLIST_MUX_ENA      (1 << 2)
+#define II20K_AI_CHANLIST_MUX_ENA      BIT(2)
 #define II20K_AI_CHANLIST_CHAN(x)      (((x) & 0x3) << 0)
 #define II20K_AI_CHANLIST_LEN          0x80
 
@@ -153,9 +153,8 @@ static int ii20k_ao_insn_write(struct comedi_device *dev,
 
                s->readback[chan] = val;
 
-               /* munge data */
-               val += ((s->maxdata + 1) >> 1);
-               val &= s->maxdata;
+               /* munge the offset binary data to 2's complement */
+               val = comedi_offset_munge(s, val);
 
                writeb(val & 0xff, iobase + II20K_AO_LSB_REG(chan));
                writeb((val >> 8) & 0xff, iobase + II20K_AO_MSB_REG(chan));
@@ -243,11 +242,8 @@ static int ii20k_ai_insn_read(struct comedi_device *dev,
                val = readb(iobase + II20K_AI_LSB_REG);
                val |= (readb(iobase + II20K_AI_MSB_REG) << 8);
 
-               /* munge two's complement data */
-               val += ((s->maxdata + 1) >> 1);
-               val &= s->maxdata;
-
-               data[i] = val;
+               /* munge the 2's complement data to offset binary */
+               data[i] = comedi_offset_munge(s, val);
        }
 
        return insn->n;
@@ -523,5 +519,5 @@ static struct comedi_driver ii20k_driver = {
 module_comedi_driver(ii20k_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Intelligent Instruments PCI-20001C");
 MODULE_LICENSE("GPL");
index dc642edf4f655c7ae7eeee6473c937445dcda901..93198abf0ee54293ca3098948cb5d64324ae6ef0 100644 (file)
 #define KE_MSB_REG(x)                  (0x0c + ((x) * 0x20))
 #define KE_SIGN_REG(x)                 (0x10 + ((x) * 0x20))
 #define KE_OSC_SEL_REG                 0xf8
-#define KE_OSC_SEL_EXT                 (1 << 0)
-#define KE_OSC_SEL_4MHZ                        (2 << 0)
-#define KE_OSC_SEL_20MHZ               (3 << 0)
+#define KE_OSC_SEL_CLK(x)              (((x) & 0x3) << 0)
+#define KE_OSC_SEL_EXT                 KE_OSC_SEL_CLK(1)
+#define KE_OSC_SEL_4MHZ                        KE_OSC_SEL_CLK(2)
+#define KE_OSC_SEL_20MHZ               KE_OSC_SEL_CLK(3)
 #define KE_DO_REG                      0xfc
 
 static int ke_counter_insn_write(struct comedi_device *dev,
index 9ea1ba4b1b6fe8b8b4bca29f6367d1e273d0e44f..3bf0caa18ab04a7af4046a74deba09252b82dbca 100644 (file)
 
 #define XILINX_DOWNLOAD_RESET  0x42    /* Xilinx registers */
 
-#define ME_CONTROL_1                   0x0000  /* - | W */
-#define   INTERRUPT_ENABLE             (1<<15)
-#define   COUNTER_B_IRQ                        (1<<12)
-#define   COUNTER_A_IRQ                        (1<<11)
-#define   CHANLIST_READY_IRQ           (1<<10)
-#define   EXT_IRQ                      (1<<9)
-#define   ADFIFO_HALFFULL_IRQ          (1<<8)
-#define   SCAN_COUNT_ENABLE            (1<<5)
-#define   SIMULTANEOUS_ENABLE          (1<<4)
-#define   TRIGGER_FALLING_EDGE         (1<<3)
-#define   CONTINUOUS_MODE              (1<<2)
-#define   DISABLE_ADC                  (0<<0)
-#define   SOFTWARE_TRIGGERED_ADC       (1<<0)
-#define   SCAN_TRIGGERED_ADC           (2<<0)
-#define   EXT_TRIGGERED_ADC            (3<<0)
-#define ME_ADC_START                   0x0000  /* R | - */
-#define ME_CONTROL_2                   0x0002  /* - | W */
-#define   ENABLE_ADFIFO                        (1<<10)
-#define   ENABLE_CHANLIST              (1<<9)
-#define   ENABLE_PORT_B                        (1<<7)
-#define   ENABLE_PORT_A                        (1<<6)
-#define   ENABLE_COUNTER_B             (1<<4)
-#define   ENABLE_COUNTER_A             (1<<3)
-#define   ENABLE_DAC                   (1<<1)
-#define   BUFFERED_DAC                 (1<<0)
-#define ME_DAC_UPDATE                  0x0002  /* R | - */
-#define ME_STATUS                      0x0004  /* R | - */
-#define   COUNTER_B_IRQ_PENDING                (1<<12)
-#define   COUNTER_A_IRQ_PENDING                (1<<11)
-#define   CHANLIST_READY_IRQ_PENDING   (1<<10)
-#define   EXT_IRQ_PENDING              (1<<9)
-#define   ADFIFO_HALFFULL_IRQ_PENDING  (1<<8)
-#define   ADFIFO_FULL                  (1<<4)
-#define   ADFIFO_HALFFULL              (1<<3)
-#define   ADFIFO_EMPTY                 (1<<2)
-#define   CHANLIST_FULL                        (1<<1)
-#define   FST_ACTIVE                   (1<<0)
-#define ME_RESET_INTERRUPT             0x0004  /* - | W */
-#define ME_DIO_PORT_A                  0x0006  /* R | W */
-#define ME_DIO_PORT_B                  0x0008  /* R | W */
-#define ME_TIMER_DATA_0                        0x000A  /* - | W */
-#define ME_TIMER_DATA_1                        0x000C  /* - | W */
-#define ME_TIMER_DATA_2                        0x000E  /* - | W */
-#define ME_CHANNEL_LIST                        0x0010  /* - | W */
-#define   ADC_UNIPOLAR                 (1<<6)
-#define   ADC_GAIN_0                   (0<<4)
-#define   ADC_GAIN_1                   (1<<4)
-#define   ADC_GAIN_2                   (2<<4)
-#define   ADC_GAIN_3                   (3<<4)
-#define ME_READ_AD_FIFO                        0x0010  /* R | - */
-#define ME_DAC_CONTROL                 0x0012  /* - | W */
-#define   DAC_UNIPOLAR_D               (0<<4)
-#define   DAC_BIPOLAR_D                        (1<<4)
-#define   DAC_UNIPOLAR_C               (0<<5)
-#define   DAC_BIPOLAR_C                        (1<<5)
-#define   DAC_UNIPOLAR_B               (0<<6)
-#define   DAC_BIPOLAR_B                        (1<<6)
-#define   DAC_UNIPOLAR_A               (0<<7)
-#define   DAC_BIPOLAR_A                        (1<<7)
-#define   DAC_GAIN_0_D                 (0<<8)
-#define   DAC_GAIN_1_D                 (1<<8)
-#define   DAC_GAIN_0_C                 (0<<9)
-#define   DAC_GAIN_1_C                 (1<<9)
-#define   DAC_GAIN_0_B                 (0<<10)
-#define   DAC_GAIN_1_B                 (1<<10)
-#define   DAC_GAIN_0_A                 (0<<11)
-#define   DAC_GAIN_1_A                 (1<<11)
-#define ME_DAC_CONTROL_UPDATE          0x0012  /* R | - */
-#define ME_DAC_DATA_A                  0x0014  /* - | W */
-#define ME_DAC_DATA_B                  0x0016  /* - | W */
-#define ME_DAC_DATA_C                  0x0018  /* - | W */
-#define ME_DAC_DATA_D                  0x001A  /* - | W */
-#define ME_COUNTER_ENDDATA_A           0x001C  /* - | W */
-#define ME_COUNTER_ENDDATA_B           0x001E  /* - | W */
-#define ME_COUNTER_STARTDATA_A         0x0020  /* - | W */
-#define ME_COUNTER_VALUE_A             0x0020  /* R | - */
-#define ME_COUNTER_STARTDATA_B         0x0022  /* - | W */
-#define ME_COUNTER_VALUE_B             0x0022  /* R | - */
+/*
+ * PCI BAR2 Memory map (dev->mmio)
+ */
+#define ME_CTRL1_REG                   0x00    /* R (ai start) | W */
+#define   ME_CTRL1_INT_ENA             BIT(15)
+#define   ME_CTRL1_COUNTER_B_IRQ       BIT(12)
+#define   ME_CTRL1_COUNTER_A_IRQ       BIT(11)
+#define   ME_CTRL1_CHANLIST_READY_IRQ  BIT(10)
+#define   ME_CTRL1_EXT_IRQ             BIT(9)
+#define   ME_CTRL1_ADFIFO_HALFFULL_IRQ BIT(8)
+#define   ME_CTRL1_SCAN_COUNT_ENA      BIT(5)
+#define   ME_CTRL1_SIMULTANEOUS_ENA    BIT(4)
+#define   ME_CTRL1_TRIGGER_FALLING_EDGE        BIT(3)
+#define   ME_CTRL1_CONTINUOUS_MODE     BIT(2)
+#define   ME_CTRL1_ADC_MODE(x)         (((x) & 0x3) << 0)
+#define   ME_CTRL1_ADC_MODE_DISABLE    ME_CTRL1_ADC_MODE(0)
+#define   ME_CTRL1_ADC_MODE_SOFT_TRIG  ME_CTRL1_ADC_MODE(1)
+#define   ME_CTRL1_ADC_MODE_SCAN_TRIG  ME_CTRL1_ADC_MODE(2)
+#define   ME_CTRL1_ADC_MODE_EXT_TRIG   ME_CTRL1_ADC_MODE(3)
+#define   ME_CTRL1_ADC_MODE_MASK       ME_CTRL1_ADC_MODE(3)
+#define ME_CTRL2_REG                   0x02    /* R (dac update) | W */
+#define   ME_CTRL2_ADFIFO_ENA          BIT(10)
+#define   ME_CTRL2_CHANLIST_ENA                BIT(9)
+#define   ME_CTRL2_PORT_B_ENA          BIT(7)
+#define   ME_CTRL2_PORT_A_ENA          BIT(6)
+#define   ME_CTRL2_COUNTER_B_ENA       BIT(4)
+#define   ME_CTRL2_COUNTER_A_ENA       BIT(3)
+#define   ME_CTRL2_DAC_ENA             BIT(1)
+#define   ME_CTRL2_BUFFERED_DAC                BIT(0)
+#define ME_STATUS_REG                  0x04    /* R | W (clears interrupts) */
+#define   ME_STATUS_COUNTER_B_IRQ      BIT(12)
+#define   ME_STATUS_COUNTER_A_IRQ      BIT(11)
+#define   ME_STATUS_CHANLIST_READY_IRQ BIT(10)
+#define   ME_STATUS_EXT_IRQ            BIT(9)
+#define   ME_STATUS_ADFIFO_HALFFULL_IRQ        BIT(8)
+#define   ME_STATUS_ADFIFO_FULL                BIT(4)
+#define   ME_STATUS_ADFIFO_HALFFULL    BIT(3)
+#define   ME_STATUS_ADFIFO_EMPTY       BIT(2)
+#define   ME_STATUS_CHANLIST_FULL      BIT(1)
+#define   ME_STATUS_FST_ACTIVE         BIT(0)
+#define ME_DIO_PORT_A_REG              0x06    /* R | W */
+#define ME_DIO_PORT_B_REG              0x08    /* R | W */
+#define ME_TIMER_DATA_REG(x)           (0x0a + ((x) * 2))      /* - | W */
+#define ME_AI_FIFO_REG                 0x10    /* R (fifo) | W (chanlist) */
+#define   ME_AI_FIFO_CHANLIST_DIFF     BIT(7)
+#define   ME_AI_FIFO_CHANLIST_UNIPOLAR BIT(6)
+#define   ME_AI_FIFO_CHANLIST_GAIN(x)  (((x) & 0x3) << 4)
+#define   ME_AI_FIFO_CHANLIST_CHAN(x)  (((x) & 0xf) << 0)
+#define ME_DAC_CTRL_REG                        0x12    /* R (updates) | W */
+#define   ME_DAC_CTRL_BIPOLAR(x)       BIT(7 - ((x) & 0x3))
+#define   ME_DAC_CTRL_GAIN(x)          BIT(11 - ((x) & 0x3))
+#define   ME_DAC_CTRL_MASK(x)          (ME_DAC_CTRL_BIPOLAR(x) |       \
+                                        ME_DAC_CTRL_GAIN(x))
+#define ME_AO_DATA_REG(x)              (0x14 + ((x) * 2))      /* - | W */
+#define ME_COUNTER_ENDDATA_REG(x)      (0x1c + ((x) * 2))      /* - | W */
+#define ME_COUNTER_STARTDATA_REG(x)    (0x20 + ((x) * 2))      /* - | W */
+#define ME_COUNTER_VALUE_REG(x)                (0x20 + ((x) * 2))      /* R | - */
 
 static const struct comedi_lrange me_ai_range = {
        8, {
@@ -166,9 +145,9 @@ static const struct me_board me_boards[] = {
 struct me_private_data {
        void __iomem *plx_regbase;      /* PLX configuration base address */
 
-       unsigned short control_1;       /* Mirror of CONTROL_1 register */
-       unsigned short control_2;       /* Mirror of CONTROL_2 register */
-       unsigned short dac_control;     /* Mirror of the DAC_CONTROL register */
+       unsigned short ctrl1;           /* Mirror of CONTROL_1 register */
+       unsigned short ctrl2;           /* Mirror of CONTROL_2 register */
+       unsigned short dac_ctrl;        /* Mirror of the DAC_CONTROL register */
 };
 
 static inline void sleep(unsigned sec)
@@ -196,15 +175,15 @@ static int me_dio_insn_config(struct comedi_device *dev,
                return ret;
 
        if (s->io_bits & 0x0000ffff)
-               devpriv->control_2 |= ENABLE_PORT_A;
+               devpriv->ctrl2 |= ME_CTRL2_PORT_A_ENA;
        else
-               devpriv->control_2 &= ~ENABLE_PORT_A;
+               devpriv->ctrl2 &= ~ME_CTRL2_PORT_A_ENA;
        if (s->io_bits & 0xffff0000)
-               devpriv->control_2 |= ENABLE_PORT_B;
+               devpriv->ctrl2 |= ME_CTRL2_PORT_B_ENA;
        else
-               devpriv->control_2 &= ~ENABLE_PORT_B;
+               devpriv->ctrl2 &= ~ME_CTRL2_PORT_B_ENA;
 
-       writew(devpriv->control_2, dev->mmio + ME_CONTROL_2);
+       writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG);
 
        return insn->n;
 }
@@ -214,8 +193,8 @@ static int me_dio_insn_bits(struct comedi_device *dev,
                            struct comedi_insn *insn,
                            unsigned int *data)
 {
-       void __iomem *mmio_porta = dev->mmio + ME_DIO_PORT_A;
-       void __iomem *mmio_portb = dev->mmio + ME_DIO_PORT_B;
+       void __iomem *mmio_porta = dev->mmio + ME_DIO_PORT_A_REG;
+       void __iomem *mmio_portb = dev->mmio + ME_DIO_PORT_B_REG;
        unsigned int mask;
        unsigned int val;
 
@@ -249,8 +228,8 @@ static int me_ai_eoc(struct comedi_device *dev,
 {
        unsigned int status;
 
-       status = readw(dev->mmio + ME_STATUS);
-       if ((status & 0x0004) == 0)
+       status = readw(dev->mmio + ME_STATUS_REG);
+       if ((status & ME_STATUS_ADFIFO_EMPTY) == 0)
                return 0;
        return -EBUSY;
 }
@@ -260,57 +239,66 @@ static int me_ai_insn_read(struct comedi_device *dev,
                           struct comedi_insn *insn,
                           unsigned int *data)
 {
-       struct me_private_data *dev_private = dev->private;
+       struct me_private_data *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int rang = CR_RANGE(insn->chanspec);
+       unsigned int range = CR_RANGE(insn->chanspec);
        unsigned int aref = CR_AREF(insn->chanspec);
-       unsigned short val;
-       int ret;
+       unsigned int val;
+       int ret = 0;
+       int i;
 
-       /* stop any running conversion */
-       dev_private->control_1 &= 0xFFFC;
-       writew(dev_private->control_1, dev->mmio + ME_CONTROL_1);
+       /*
+        * For differential operation, there are only 8 input channels
+        * and only bipolar ranges are available.
+        */
+       if (aref & AREF_DIFF) {
+               if (chan > 7 || comedi_range_is_unipolar(s, range))
+                       return -EINVAL;
+       }
 
        /* clear chanlist and ad fifo */
-       dev_private->control_2 &= ~(ENABLE_ADFIFO | ENABLE_CHANLIST);
-       writew(dev_private->control_2, dev->mmio + ME_CONTROL_2);
+       devpriv->ctrl2 &= ~(ME_CTRL2_ADFIFO_ENA | ME_CTRL2_CHANLIST_ENA);
+       writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG);
 
-       /* reset any pending interrupt */
-       writew(0x00, dev->mmio + ME_RESET_INTERRUPT);
+       writew(0x00, dev->mmio + ME_STATUS_REG);        /* clear interrupts */
 
        /* enable the chanlist and ADC fifo */
-       dev_private->control_2 |= (ENABLE_ADFIFO | ENABLE_CHANLIST);
-       writew(dev_private->control_2, dev->mmio + ME_CONTROL_2);
+       devpriv->ctrl2 |= (ME_CTRL2_ADFIFO_ENA | ME_CTRL2_CHANLIST_ENA);
+       writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG);
 
        /* write to channel list fifo */
-       val = chan & 0x0f;                      /* b3:b0 channel */
-       val |= (rang & 0x03) << 4;              /* b5:b4 gain */
-       val |= (rang & 0x04) << 4;              /* b6 polarity */
-       val |= ((aref & AREF_DIFF) ? 0x80 : 0); /* b7 differential */
-       writew(val & 0xff, dev->mmio + ME_CHANNEL_LIST);
+       val = ME_AI_FIFO_CHANLIST_CHAN(chan) | ME_AI_FIFO_CHANLIST_GAIN(range);
+       if (comedi_range_is_unipolar(s, range))
+               val |= ME_AI_FIFO_CHANLIST_UNIPOLAR;
+       if (aref & AREF_DIFF)
+               val |= ME_AI_FIFO_CHANLIST_DIFF;
+       writew(val, dev->mmio + ME_AI_FIFO_REG);
 
        /* set ADC mode to software trigger */
-       dev_private->control_1 |= SOFTWARE_TRIGGERED_ADC;
-       writew(dev_private->control_1, dev->mmio + ME_CONTROL_1);
+       devpriv->ctrl1 |= ME_CTRL1_ADC_MODE_SOFT_TRIG;
+       writew(devpriv->ctrl1, dev->mmio + ME_CTRL1_REG);
+
+       for (i = 0; i < insn->n; i++) {
+               /* start ai conversion */
+               readw(dev->mmio + ME_CTRL1_REG);
 
-       /* start conversion by reading from ADC_START */
-       readw(dev->mmio + ME_ADC_START);
+               /* wait for ADC fifo not empty flag */
+               ret = comedi_timeout(dev, s, insn, me_ai_eoc, 0);
+               if (ret)
+                       break;
 
-       /* wait for ADC fifo not empty flag */
-       ret = comedi_timeout(dev, s, insn, me_ai_eoc, 0);
-       if (ret)
-               return ret;
+               /* get value from ADC fifo */
+               val = readw(dev->mmio + ME_AI_FIFO_REG) & s->maxdata;
 
-       /* get value from ADC fifo */
-       val = readw(dev->mmio + ME_READ_AD_FIFO);
-       val = (val ^ 0x800) & 0x0fff;
-       data[0] = val;
+               /* munge 2's complement value to offset binary */
+               data[i] = comedi_offset_munge(s, val);
+       }
 
        /* stop any running conversion */
-       dev_private->control_1 &= 0xFFFC;
-       writew(dev_private->control_1, dev->mmio + ME_CONTROL_1);
+       devpriv->ctrl1 &= ~ME_CTRL1_ADC_MODE_MASK;
+       writew(devpriv->ctrl1, dev->mmio + ME_CTRL1_REG);
 
-       return 1;
+       return ret ? ret : insn->n;
 }
 
 static int me_ao_insn_write(struct comedi_device *dev,
@@ -318,46 +306,41 @@ static int me_ao_insn_write(struct comedi_device *dev,
                            struct comedi_insn *insn,
                            unsigned int *data)
 {
-       struct me_private_data *dev_private = dev->private;
+       struct me_private_data *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int rang = CR_RANGE(insn->chanspec);
+       unsigned int range = CR_RANGE(insn->chanspec);
        unsigned int val = s->readback[chan];
        int i;
 
        /* Enable all DAC */
-       dev_private->control_2 |= ENABLE_DAC;
-       writew(dev_private->control_2, dev->mmio + ME_CONTROL_2);
+       devpriv->ctrl2 |= ME_CTRL2_DAC_ENA;
+       writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG);
 
        /* and set DAC to "buffered" mode */
-       dev_private->control_2 |= BUFFERED_DAC;
-       writew(dev_private->control_2, dev->mmio + ME_CONTROL_2);
+       devpriv->ctrl2 |= ME_CTRL2_BUFFERED_DAC;
+       writew(devpriv->ctrl2, dev->mmio + ME_CTRL2_REG);
 
        /* Set dac-control register */
-       for (i = 0; i < insn->n; i++) {
-               /* clear bits for this channel */
-               dev_private->dac_control &= ~(0x0880 >> chan);
-               if (rang == 0)
-                       dev_private->dac_control |=
-                           ((DAC_BIPOLAR_A | DAC_GAIN_1_A) >> chan);
-               else if (rang == 1)
-                       dev_private->dac_control |=
-                           ((DAC_BIPOLAR_A | DAC_GAIN_0_A) >> chan);
-       }
-       writew(dev_private->dac_control, dev->mmio + ME_DAC_CONTROL);
+       devpriv->dac_ctrl &= ~ME_DAC_CTRL_MASK(chan);
+       if (range == 0)
+               devpriv->dac_ctrl |= ME_DAC_CTRL_GAIN(chan);
+       if (comedi_range_is_bipolar(s, range))
+               devpriv->dac_ctrl |= ME_DAC_CTRL_BIPOLAR(chan);
+       writew(devpriv->dac_ctrl, dev->mmio + ME_DAC_CTRL_REG);
 
        /* Update dac-control register */
-       readw(dev->mmio + ME_DAC_CONTROL_UPDATE);
+       readw(dev->mmio + ME_DAC_CTRL_REG);
 
        /* Set data register */
        for (i = 0; i < insn->n; i++) {
                val = data[i];
 
-               writew(val, dev->mmio + ME_DAC_DATA_A + (chan << 1));
+               writew(val, dev->mmio + ME_AO_DATA_REG(chan));
        }
        s->readback[chan] = val;
 
        /* Update dac with data registers */
-       readw(dev->mmio + ME_DAC_UPDATE);
+       readw(dev->mmio + ME_CTRL2_REG);
 
        return insn->n;
 }
@@ -366,13 +349,13 @@ static int me2600_xilinx_download(struct comedi_device *dev,
                                  const u8 *data, size_t size,
                                  unsigned long context)
 {
-       struct me_private_data *dev_private = dev->private;
+       struct me_private_data *devpriv = dev->private;
        unsigned int value;
        unsigned int file_length;
        unsigned int i;
 
        /* disable irq's on PLX */
-       writel(0x00, dev_private->plx_regbase + PLX9052_INTCSR);
+       writel(0x00, devpriv->plx_regbase + PLX9052_INTCSR);
 
        /* First, make a dummy read to reset xilinx */
        value = readw(dev->mmio + XILINX_DOWNLOAD_RESET);
@@ -412,10 +395,10 @@ static int me2600_xilinx_download(struct comedi_device *dev,
                writeb(0x00, dev->mmio + 0x0);
 
        /* Test if there was an error during download -> INTB was thrown */
-       value = readl(dev_private->plx_regbase + PLX9052_INTCSR);
+       value = readl(devpriv->plx_regbase + PLX9052_INTCSR);
        if (value & PLX9052_INTCSR_LI2STAT) {
                /* Disable interrupt */
-               writel(0x00, dev_private->plx_regbase + PLX9052_INTCSR);
+               writel(0x00, devpriv->plx_regbase + PLX9052_INTCSR);
                dev_err(dev->class_dev, "Xilinx download failed\n");
                return -EIO;
        }
@@ -427,25 +410,25 @@ static int me2600_xilinx_download(struct comedi_device *dev,
        writel(PLX9052_INTCSR_LI1ENAB |
               PLX9052_INTCSR_LI1POL |
               PLX9052_INTCSR_PCIENAB,
-              dev_private->plx_regbase + PLX9052_INTCSR);
+              devpriv->plx_regbase + PLX9052_INTCSR);
 
        return 0;
 }
 
 static int me_reset(struct comedi_device *dev)
 {
-       struct me_private_data *dev_private = dev->private;
+       struct me_private_data *devpriv = dev->private;
 
        /* Reset board */
-       writew(0x00, dev->mmio + ME_CONTROL_1);
-       writew(0x00, dev->mmio + ME_CONTROL_2);
-       writew(0x00, dev->mmio + ME_RESET_INTERRUPT);
-       writew(0x00, dev->mmio + ME_DAC_CONTROL);
+       writew(0x00, dev->mmio + ME_CTRL1_REG);
+       writew(0x00, dev->mmio + ME_CTRL2_REG);
+       writew(0x00, dev->mmio + ME_STATUS_REG);        /* clear interrupts */
+       writew(0x00, dev->mmio + ME_DAC_CTRL_REG);
 
        /* Save values in the board context */
-       dev_private->dac_control = 0;
-       dev_private->control_1 = 0;
-       dev_private->control_2 = 0;
+       devpriv->dac_ctrl = 0;
+       devpriv->ctrl1 = 0;
+       devpriv->ctrl2 = 0;
 
        return 0;
 }
@@ -455,7 +438,7 @@ static int me_auto_attach(struct comedi_device *dev,
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        const struct me_board *board = NULL;
-       struct me_private_data *dev_private;
+       struct me_private_data *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
@@ -466,16 +449,16 @@ static int me_auto_attach(struct comedi_device *dev,
        dev->board_ptr = board;
        dev->board_name = board->name;
 
-       dev_private = comedi_alloc_devpriv(dev, sizeof(*dev_private));
-       if (!dev_private)
+       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
+       if (!devpriv)
                return -ENOMEM;
 
        ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
-       dev_private->plx_regbase = pci_ioremap_bar(pcidev, 0);
-       if (!dev_private->plx_regbase)
+       devpriv->plx_regbase = pci_ioremap_bar(pcidev, 0);
+       if (!devpriv->plx_regbase)
                return -ENOMEM;
 
        dev->mmio = pci_ioremap_bar(pcidev, 2);
@@ -498,7 +481,7 @@ static int me_auto_attach(struct comedi_device *dev,
 
        s = &dev->subdevices[0];
        s->type         = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_COMMON;
+       s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_DIFF;
        s->n_chan       = 16;
        s->maxdata      = 0x0fff;
        s->len_chanlist = 16;
@@ -537,13 +520,13 @@ static int me_auto_attach(struct comedi_device *dev,
 
 static void me_detach(struct comedi_device *dev)
 {
-       struct me_private_data *dev_private = dev->private;
+       struct me_private_data *devpriv = dev->private;
 
-       if (dev_private) {
+       if (devpriv) {
                if (dev->mmio)
                        me_reset(dev);
-               if (dev_private->plx_regbase)
-                       iounmap(dev_private->plx_regbase);
+               if (devpriv->plx_regbase)
+                       iounmap(devpriv->plx_regbase);
        }
        comedi_pci_detach(dev);
 }
index a675e2ef9b4553e4ba950a06d22f0d61040002a6..fbdf181d8ccccc228c131346a9e9ec9dc403d11b 100644 (file)
 #include "../comedi_pci.h"
 
 /* Registers present in BAR0 memory region */
-#define MF624_GPIOC_R                                  0x54
+#define MF624_GPIOC_REG                0x54
 
-#define MF6X4_GPIOC_EOLC /* End Of Last Conversion */  (1 << 17)
-#define MF6X4_GPIOC_LDAC /* Load DACs */               (1 << 23)
-#define MF6X4_GPIOC_DACEN                              (1 << 26)
+#define MF6X4_GPIOC_EOLC       BIT(17) /* End Of Last Conversion */
+#define MF6X4_GPIOC_LDAC       BIT(23) /* Load DACs */
+#define MF6X4_GPIOC_DACEN      BIT(26)
 
 /* BAR1 registers */
-#define MF6X4_DIN_R                                    0x10
-#define MF6X4_DIN_M                                    0xff
-#define MF6X4_DOUT_R                                   0x10
-#define MF6X4_DOUT_M                                   0xff
-
-#define MF6X4_ADSTART_R                                        0x20
-#define MF6X4_ADDATA_R                                 0x00
-#define MF6X4_ADCTRL_R                                 0x00
-#define MF6X4_ADCTRL_M                                 0xff
-
-#define MF6X4_DA0_R                                    0x20
-#define MF6X4_DA1_R                                    0x22
-#define MF6X4_DA2_R                                    0x24
-#define MF6X4_DA3_R                                    0x26
-#define MF6X4_DA4_R                                    0x28
-#define MF6X4_DA5_R                                    0x2a
-#define MF6X4_DA6_R                                    0x2c
-#define MF6X4_DA7_R                                    0x2e
-/* Map DAC cahnnel id to real HW-dependent offset value */
-#define MF6X4_DAC_R(x)                                 (0x20 + ((x) * 2))
+#define MF6X4_ADDATA_REG       0x00
+#define MF6X4_ADCTRL_REG       0x00
+#define MF6X4_ADCTRL_CHAN(x)   BIT(chan)
+#define MF6X4_DIN_REG          0x10
+#define MF6X4_DIN_MASK         0xff
+#define MF6X4_DOUT_REG         0x10
+#define MF6X4_ADSTART_REG      0x20
+#define MF6X4_DAC_REG(x)       (0x20 + ((x) * 2))
 
 /* BAR2 registers */
-#define MF634_GPIOC_R                                  0x68
+#define MF634_GPIOC_REG                0x68
 
 enum mf6x4_boardid {
        BOARD_MF634,
@@ -69,8 +57,8 @@ enum mf6x4_boardid {
 
 struct mf6x4_board {
        const char *name;
-       unsigned int bar_nums[3]; /* We need to keep track of the
-                                    order of BARs used by the cards */
+       /* We need to keep track of the order of BARs used by the cards */
+       unsigned int bar_nums[3];
 };
 
 static const struct mf6x4_board mf6x4_boards[] = {
@@ -99,7 +87,7 @@ struct mf6x4_private {
         * for both cards however it lies in different BARs on different
         * offsets -- this variable makes the access easier
         */
-       void __iomem *gpioc_R;
+       void __iomem *gpioc_reg;
 };
 
 static int mf6x4_di_insn_bits(struct comedi_device *dev,
@@ -107,7 +95,7 @@ static int mf6x4_di_insn_bits(struct comedi_device *dev,
                              struct comedi_insn *insn,
                              unsigned int *data)
 {
-       data[1] = ioread16(dev->mmio + MF6X4_DIN_R) & MF6X4_DIN_M;
+       data[1] = ioread16(dev->mmio + MF6X4_DIN_REG) & MF6X4_DIN_MASK;
 
        return insn->n;
 }
@@ -118,7 +106,7 @@ static int mf6x4_do_insn_bits(struct comedi_device *dev,
                              unsigned int *data)
 {
        if (comedi_dio_update_state(s, data))
-               iowrite16(s->state & MF6X4_DOUT_M, dev->mmio + MF6X4_DOUT_R);
+               iowrite16(s->state, dev->mmio + MF6X4_DOUT_REG);
 
        data[1] = s->state;
 
@@ -133,7 +121,7 @@ static int mf6x4_ai_eoc(struct comedi_device *dev,
        struct mf6x4_private *devpriv = dev->private;
        unsigned int status;
 
-       status = ioread32(devpriv->gpioc_R);
+       status = ioread32(devpriv->gpioc_reg);
        if (status & MF6X4_GPIOC_EOLC)
                return 0;
        return -EBUSY;
@@ -144,29 +132,30 @@ static int mf6x4_ai_insn_read(struct comedi_device *dev,
                              struct comedi_insn *insn,
                              unsigned int *data)
 {
-       int chan = CR_CHAN(insn->chanspec);
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int d;
        int ret;
        int i;
-       int d;
 
        /* Set the ADC channel number in the scan list */
-       iowrite16((1 << chan) & MF6X4_ADCTRL_M, dev->mmio + MF6X4_ADCTRL_R);
+       iowrite16(MF6X4_ADCTRL_CHAN(chan), dev->mmio + MF6X4_ADCTRL_REG);
 
        for (i = 0; i < insn->n; i++) {
                /* Trigger ADC conversion by reading ADSTART */
-               ioread16(dev->mmio + MF6X4_ADSTART_R);
+               ioread16(dev->mmio + MF6X4_ADSTART_REG);
 
                ret = comedi_timeout(dev, s, insn, mf6x4_ai_eoc, 0);
                if (ret)
                        return ret;
 
                /* Read the actual value */
-               d = ioread16(dev->mmio + MF6X4_ADDATA_R);
+               d = ioread16(dev->mmio + MF6X4_ADDATA_REG);
                d &= s->maxdata;
-               data[i] = d;
+               /* munge the 2's complement data to offset binary */
+               data[i] = comedi_offset_munge(s, d);
        }
 
-       iowrite16(0x0, dev->mmio + MF6X4_ADCTRL_R);
+       iowrite16(0x0, dev->mmio + MF6X4_ADCTRL_REG);
 
        return insn->n;
 }
@@ -179,17 +168,17 @@ static int mf6x4_ao_insn_write(struct comedi_device *dev,
        struct mf6x4_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int val = s->readback[chan];
-       uint32_t gpioc;
+       unsigned int gpioc;
        int i;
 
        /* Enable instantaneous update of converters outputs + Enable DACs */
-       gpioc = ioread32(devpriv->gpioc_R);
+       gpioc = ioread32(devpriv->gpioc_reg);
        iowrite32((gpioc & ~MF6X4_GPIOC_LDAC) | MF6X4_GPIOC_DACEN,
-                 devpriv->gpioc_R);
+                 devpriv->gpioc_reg);
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               iowrite16(val, dev->mmio + MF6X4_DAC_R(chan));
+               iowrite16(val, dev->mmio + MF6X4_DAC_REG(chan));
        }
        s->readback[chan] = val;
 
@@ -233,53 +222,53 @@ static int mf6x4_auto_attach(struct comedi_device *dev, unsigned long context)
                return -ENODEV;
 
        if (board == &mf6x4_boards[BOARD_MF634])
-               devpriv->gpioc_R = devpriv->bar2_mem + MF634_GPIOC_R;
+               devpriv->gpioc_reg = devpriv->bar2_mem + MF634_GPIOC_REG;
        else
-               devpriv->gpioc_R = devpriv->bar0_mem + MF624_GPIOC_R;
+               devpriv->gpioc_reg = devpriv->bar0_mem + MF624_GPIOC_REG;
 
        ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;
 
-       /* ADC */
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_GROUND;
-       s->n_chan = 8;
-       s->maxdata = 0x3fff; /* 14 bits ADC */
-       s->range_table = &range_bipolar10;
-       s->insn_read = mf6x4_ai_insn_read;
-
-       /* DAC */
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND;
+       s->n_chan       = 8;
+       s->maxdata      = 0x3fff;
+       s->range_table  = &range_bipolar10;
+       s->insn_read    = mf6x4_ai_insn_read;
+
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan = 8;
-       s->maxdata = 0x3fff; /* 14 bits DAC */
-       s->range_table = &range_bipolar10;
-       s->insn_write = mf6x4_ao_insn_write;
+       s->type         = COMEDI_SUBD_AO;
+       s->subdev_flags = SDF_WRITABLE;
+       s->n_chan       = 8;
+       s->maxdata      = 0x3fff;
+       s->range_table  = &range_bipolar10;
+       s->insn_write   = mf6x4_ao_insn_write;
 
        ret = comedi_alloc_subdev_readback(s);
        if (ret)
                return ret;
 
-       /* DIN */
+       /* Digital Input subdevice */
        s = &dev->subdevices[2];
-       s->type = COMEDI_SUBD_DI;
-       s->subdev_flags = SDF_READABLE;
-       s->n_chan = 8;
-       s->maxdata = 1;
-       s->range_table = &range_digital;
-       s->insn_bits = mf6x4_di_insn_bits;
-
-       /* DOUT */
+       s->type         = COMEDI_SUBD_DI;
+       s->subdev_flags = SDF_READABLE;
+       s->n_chan       = 8;
+       s->maxdata      = 1;
+       s->range_table  = &range_digital;
+       s->insn_bits    = mf6x4_di_insn_bits;
+
+       /* Digital Output subdevice */
        s = &dev->subdevices[3];
-       s->type = COMEDI_SUBD_DO;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan = 8;
-       s->maxdata = 1;
-       s->range_table = &range_digital;
-       s->insn_bits = mf6x4_do_insn_bits;
+       s->type         = COMEDI_SUBD_DO;
+       s->subdev_flags = SDF_WRITABLE;
+       s->n_chan       = 8;
+       s->maxdata      = 1;
+       s->range_table  = &range_digital;
+       s->insn_bits    = mf6x4_do_insn_bits;
 
        return 0;
 }
index 0207b8edfcb4534f8742ba840de1bd196c950c30..826e4399c87ee0e2dc28835038f80c1640fa2771 100644 (file)
@@ -1,55 +1,56 @@
 /*
-    comedi/drivers/mpc624.c
-    Hardware driver for a Micro/sys inc. MPC-624 PC/104 board
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
+ * mpc624.c
+ * Hardware driver for a Micro/sys inc. MPC-624 PC/104 board
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
 /*
-Driver: mpc624
-Description: Micro/sys MPC-624 PC/104 board
-Devices: [Micro/sys] MPC-624 (mpc624)
-Author: Stanislaw Raczynski <sraczynski@op.pl>
-Updated: Thu, 15 Sep 2005 12:01:18 +0200
-Status: working
-
   The Micro/sys MPC-624 board is based on the LTC2440 24-bit sigma-delta
   ADC chip.
-
   Subdevices supported by the driver:
   - Analog In:   supported
   - Digital I/O: not supported
   - LEDs:        not supported
   - EEPROM:      not supported
-
-Configuration Options:
-  [0] - I/O base address
-  [1] - conversion rate
      Conversion rate  RMS noise  Effective Number Of Bits
      0      3.52kHz        23uV                17
      1      1.76kHz       3.5uV                20
      2       880Hz         2uV                21.3
      3       440Hz        1.4uV               21.8
      4       220Hz         1uV                22.4
      5       110Hz        750uV               22.9
      6       55Hz         510nV               23.4
      7      27.5Hz        375nV                24
      8      13.75Hz       250nV               24.4
      9      6.875Hz       200nV               24.6
-  [2] - voltage range
      0      -1.01V .. +1.01V
      1      -10.1V .. +10.1V
-*/
+ * Driver: mpc624
+ * Description: Micro/sys MPC-624 PC/104 board
+ * Devices: [Micro/sys] MPC-624 (mpc624)
+ * Author: Stanislaw Raczynski <sraczynski@op.pl>
+ * Updated: Thu, 15 Sep 2005 12:01:18 +0200
+ * Status: working
+ *
* The Micro/sys MPC-624 board is based on the LTC2440 24-bit sigma-delta
* ADC chip.
+ *
* Subdevices supported by the driver:
* - Analog In:   supported
* - Digital I/O: not supported
* - LEDs:        not supported
* - EEPROM:      not supported
+ *
+ * Configuration Options:
*   [0] - I/O base address
*   [1] - conversion rate
*        Conversion rate   RMS noise  Effective Number Of Bits
*        0    3.52kHz         23uV            17
*        1    1.76kHz         3.5uV           20
*        2    880Hz           2uV             21.3
*        3    440Hz           1.4uV           21.8
*        4    220Hz           1uV             22.4
*        5    110Hz           750uV           22.9
*        6    55Hz            510nV           23.4
*        7    27.5Hz          375nV           24
*        8    13.75Hz         250nV           24.4
*        9    6.875Hz         200nV           24.6
*   [2] - voltage range
*        0    -1.01V .. +1.01V
*        1    -10.1V .. +10.1V
+ */
 
 #include <linux/module.h>
 #include "../comedidev.h"
@@ -58,65 +59,41 @@ Configuration Options:
 
 /* Offsets of different ports */
 #define MPC624_MASTER_CONTROL  0 /* not used */
-#define MPC624_GNMUXCH          1 /* Gain, Mux, Channel of ADC */
-#define MPC624_ADC              2 /* read/write to/from ADC */
-#define MPC624_EE               3 /* read/write to/from serial EEPROM via I2C */
-#define MPC624_LEDS             4 /* write to LEDs */
-#define MPC624_DIO              5 /* read/write to/from digital I/O ports */
-#define MPC624_IRQ_MASK         6 /* IRQ masking enable/disable */
+#define MPC624_GNMUXCH         1 /* Gain, Mux, Channel of ADC */
+#define MPC624_ADC             2 /* read/write to/from ADC */
+#define MPC624_EE              3 /* read/write to/from serial EEPROM via I2C */
+#define MPC624_LEDS            4 /* write to LEDs */
+#define MPC624_DIO             5 /* read/write to/from digital I/O ports */
+#define MPC624_IRQ_MASK                6 /* IRQ masking enable/disable */
 
 /* Register bits' names */
-#define MPC624_ADBUSY           (1<<5)
-#define MPC624_ADSDO            (1<<4)
-#define MPC624_ADFO             (1<<3)
-#define MPC624_ADCS             (1<<2)
-#define MPC624_ADSCK            (1<<1)
-#define MPC624_ADSDI            (1<<0)
-
-/* SDI Speed/Resolution Programming bits */
-#define MPC624_OSR4             (1<<31)
-#define MPC624_OSR3             (1<<30)
-#define MPC624_OSR2             (1<<29)
-#define MPC624_OSR1             (1<<28)
-#define MPC624_OSR0             (1<<27)
+#define MPC624_ADBUSY          BIT(5)
+#define MPC624_ADSDO           BIT(4)
+#define MPC624_ADFO            BIT(3)
+#define MPC624_ADCS            BIT(2)
+#define MPC624_ADSCK           BIT(1)
+#define MPC624_ADSDI           BIT(0)
 
 /* 32-bit output value bits' names */
-#define MPC624_EOC_BIT          (1<<31)
-#define MPC624_DMY_BIT          (1<<30)
-#define MPC624_SGN_BIT          (1<<29)
-
-/* Conversion speeds */
-/* OSR4 OSR3 OSR2 OSR1 OSR0  Conversion rate  RMS noise  ENOB^
- *  X    0    0    0    1        3.52kHz        23uV      17
- *  X    0    0    1    0        1.76kHz       3.5uV      20
- *  X    0    0    1    1         880Hz         2uV      21.3
- *  X    0    1    0    0         440Hz        1.4uV     21.8
- *  X    0    1    0    1         220Hz         1uV      22.4
- *  X    0    1    1    0         110Hz        750uV     22.9
- *  X    0    1    1    1          55Hz        510nV     23.4
- *  X    1    0    0    0         27.5Hz       375nV      24
- *  X    1    0    0    1        13.75Hz       250nV     24.4
- *  X    1    1    1    1        6.875Hz       200nV     24.6
- *
- * ^ - Effective Number Of Bits
- */
+#define MPC624_EOC_BIT         BIT(31)
+#define MPC624_DMY_BIT         BIT(30)
+#define MPC624_SGN_BIT         BIT(29)
+
+/* SDI Speed/Resolution Programming bits */
+#define MPC624_OSR(x)          (((x) & 0x1f) << 27)
+#define MPC624_SPEED_3_52_KHZ  MPC624_OSR(0x11)
+#define MPC624_SPEED_1_76_KHZ  MPC624_OSR(0x12)
+#define MPC624_SPEED_880_HZ    MPC624_OSR(0x13)
+#define MPC624_SPEED_440_HZ    MPC624_OSR(0x14)
+#define MPC624_SPEED_220_HZ    MPC624_OSR(0x15)
+#define MPC624_SPEED_110_HZ    MPC624_OSR(0x16)
+#define MPC624_SPEED_55_HZ     MPC624_OSR(0x17)
+#define MPC624_SPEED_27_5_HZ   MPC624_OSR(0x18)
+#define MPC624_SPEED_13_75_HZ  MPC624_OSR(0x19)
+#define MPC624_SPEED_6_875_HZ  MPC624_OSR(0x1f)
 
-#define MPC624_SPEED_3_52_kHz (MPC624_OSR4 | MPC624_OSR0)
-#define MPC624_SPEED_1_76_kHz (MPC624_OSR4 | MPC624_OSR1)
-#define MPC624_SPEED_880_Hz   (MPC624_OSR4 | MPC624_OSR1 | MPC624_OSR0)
-#define MPC624_SPEED_440_Hz   (MPC624_OSR4 | MPC624_OSR2)
-#define MPC624_SPEED_220_Hz   (MPC624_OSR4 | MPC624_OSR2 | MPC624_OSR0)
-#define MPC624_SPEED_110_Hz   (MPC624_OSR4 | MPC624_OSR2 | MPC624_OSR1)
-#define MPC624_SPEED_55_Hz \
-       (MPC624_OSR4 | MPC624_OSR2 | MPC624_OSR1 | MPC624_OSR0)
-#define MPC624_SPEED_27_5_Hz  (MPC624_OSR4 | MPC624_OSR3)
-#define MPC624_SPEED_13_75_Hz (MPC624_OSR4 | MPC624_OSR3 | MPC624_OSR0)
-#define MPC624_SPEED_6_875_Hz \
-       (MPC624_OSR4 | MPC624_OSR3 | MPC624_OSR2 | MPC624_OSR1 | MPC624_OSR0)
-/* -------------------------------------------------------------------------- */
 struct mpc624_private {
-       /*  set by mpc624_attach() from driver's parameters */
-       unsigned long int ulConvertionRate;
+       unsigned int ai_speed;
 };
 
 /* -------------------------------------------------------------------------- */
@@ -138,6 +115,85 @@ static const struct comedi_lrange range_mpc624_bipolar10 = {
         }
 };
 
+static unsigned int mpc624_ai_get_sample(struct comedi_device *dev,
+                                        struct comedi_subdevice *s)
+{
+       struct mpc624_private *devpriv = dev->private;
+       unsigned int data_out = devpriv->ai_speed;
+       unsigned int data_in = 0;
+       unsigned int bit;
+       int i;
+
+       /* Start reading data */
+       udelay(1);
+       for (i = 0; i < 32; i++) {
+               /* Set the clock low */
+               outb(0, dev->iobase + MPC624_ADC);
+               udelay(1);
+
+               /* Set the ADSDI line for the next bit (send to MPC624) */
+               bit = (data_out & BIT(31)) ? MPC624_ADSDI : 0;
+               outb(bit, dev->iobase + MPC624_ADC);
+               udelay(1);
+
+               /* Set the clock high */
+               outb(MPC624_ADSCK | bit, dev->iobase + MPC624_ADC);
+               udelay(1);
+
+               /* Read ADSDO on high clock (receive from MPC624) */
+               data_in <<= 1;
+               data_in |= (inb(dev->iobase + MPC624_ADC) & MPC624_ADSDO) >> 4;
+               udelay(1);
+
+               data_out <<= 1;
+       }
+
+       /*
+        * Received 32-bit long value consist of:
+        *      31: EOC - (End Of Transmission) bit - should be 0
+        *      30: DMY - (Dummy) bit - should be 0
+        *      29: SIG - (Sign) bit - 1 if positive, 0 if negative
+        *      28: MSB - (Most Significant Bit) - the first bit of the
+        *                                         conversion result
+        *      ....
+        *      05: LSB - (Least Significant Bit)- the last bit of the
+        *                                         conversion result
+        *      04-00: sub-LSB - sub-LSBs are basically noise, but when
+        *                       averaged properly, they can increase
+        *                       conversion precision up to 29 bits;
+        *                       they can be discarded without loss of
+        *                       resolution.
+        */
+       if (data_in & MPC624_EOC_BIT)
+               dev_dbg(dev->class_dev, "EOC bit is set!");
+       if (data_in & MPC624_DMY_BIT)
+               dev_dbg(dev->class_dev, "DMY bit is set!");
+
+       if (data_in & MPC624_SGN_BIT) {
+               /*
+                * Voltage is positive
+                *
+                * comedi operates on unsigned numbers, so mask off EOC
+                * and DMY and don't clear the SGN bit
+                */
+               data_in &= 0x3fffffff;
+       } else {
+               /*
+                * The voltage is negative
+                *
+                * data_in contains a number in 30-bit two's complement
+                * code and we must deal with it
+                */
+               data_in |= MPC624_SGN_BIT;
+               data_in = ~data_in;
+               data_in += 1;
+               /* clear EOC and DMY bits */
+               data_in &= ~(MPC624_EOC_BIT | MPC624_DMY_BIT);
+               data_in = 0x20000000 - data_in;
+       }
+       return data_in;
+}
+
 static int mpc624_ai_eoc(struct comedi_device *dev,
                         struct comedi_subdevice *s,
                         struct comedi_insn *insn,
@@ -151,14 +207,13 @@ static int mpc624_ai_eoc(struct comedi_device *dev,
        return -EBUSY;
 }
 
-static int mpc624_ai_rinsn(struct comedi_device *dev,
-                          struct comedi_subdevice *s, struct comedi_insn *insn,
-                          unsigned int *data)
+static int mpc624_ai_insn_read(struct comedi_device *dev,
+                              struct comedi_subdevice *s,
+                              struct comedi_insn *insn,
+                              unsigned int *data)
 {
-       struct mpc624_private *devpriv = dev->private;
-       int n, i;
-       unsigned long int data_in, data_out;
        int ret;
+       int i;
 
        /*
         *  WARNING:
@@ -166,7 +221,7 @@ static int mpc624_ai_rinsn(struct comedi_device *dev,
         */
        outb(insn->chanspec, dev->iobase + MPC624_GNMUXCH);
 
-       for (n = 0; n < insn->n; n++) {
+       for (i = 0; i < insn->n; i++) {
                /*  Trigger the conversion */
                outb(MPC624_ADSCK, dev->iobase + MPC624_ADC);
                udelay(1);
@@ -180,93 +235,10 @@ static int mpc624_ai_rinsn(struct comedi_device *dev,
                if (ret)
                        return ret;
 
-               /*  Start reading data */
-               data_in = 0;
-               data_out = devpriv->ulConvertionRate;
-               udelay(1);
-               for (i = 0; i < 32; i++) {
-                       /*  Set the clock low */
-                       outb(0, dev->iobase + MPC624_ADC);
-                       udelay(1);
-
-                       if (data_out & (1 << 31)) { /*  the next bit is a 1 */
-                               /*  Set the ADSDI line (send to MPC624) */
-                               outb(MPC624_ADSDI, dev->iobase + MPC624_ADC);
-                               udelay(1);
-                               /*  Set the clock high */
-                               outb(MPC624_ADSCK | MPC624_ADSDI,
-                                    dev->iobase + MPC624_ADC);
-                       } else {        /*  the next bit is a 0 */
-
-                               /*  Set the ADSDI line (send to MPC624) */
-                               outb(0, dev->iobase + MPC624_ADC);
-                               udelay(1);
-                               /*  Set the clock high */
-                               outb(MPC624_ADSCK, dev->iobase + MPC624_ADC);
-                       }
-                       /*  Read ADSDO on high clock (receive from MPC624) */
-                       udelay(1);
-                       data_in <<= 1;
-                       data_in |=
-                           (inb(dev->iobase + MPC624_ADC) & MPC624_ADSDO) >> 4;
-                       udelay(1);
-
-                       data_out <<= 1;
-               }
-
-               /*
-                *  Received 32-bit long value consist of:
-                *    31: EOC -
-                *          (End Of Transmission) bit - should be 0
-                *    30: DMY
-                *          (Dummy) bit - should be 0
-                *    29: SIG
-                *          (Sign) bit- 1 if the voltage is positive,
-                *                      0 if negative
-                *    28: MSB
-                *          (Most Significant Bit) - the first bit of
-                *                                   the conversion result
-                *    ....
-                *    05: LSB
-                *          (Least Significant Bit)- the last bit of the
-                *                                   conversion result
-                *    04-00: sub-LSB
-                *          - sub-LSBs are basically noise, but when
-                *            averaged properly, they can increase conversion
-                *            precision up to 29 bits; they can be discarded
-                *            without loss of resolution.
-                */
-
-               if (data_in & MPC624_EOC_BIT)
-                       dev_dbg(dev->class_dev,
-                               "EOC bit is set (data_in=%lu)!", data_in);
-               if (data_in & MPC624_DMY_BIT)
-                       dev_dbg(dev->class_dev,
-                               "DMY bit is set (data_in=%lu)!", data_in);
-               if (data_in & MPC624_SGN_BIT) { /* Volatge is positive */
-                       /*
-                        * comedi operates on unsigned numbers, so mask off EOC
-                        * and DMY and don't clear the SGN bit
-                        */
-                       data_in &= 0x3FFFFFFF;
-                       data[n] = data_in;
-               } else { /*  The voltage is negative */
-                       /*
-                        * data_in contains a number in 30-bit two's complement
-                        * code and we must deal with it
-                        */
-                       data_in |= MPC624_SGN_BIT;
-                       data_in = ~data_in;
-                       data_in += 1;
-                       data_in &= ~(MPC624_EOC_BIT | MPC624_DMY_BIT);
-                       /*  clear EOC and DMY bits */
-                       data_in = 0x20000000 - data_in;
-                       data[n] = data_in;
-               }
+               data[i] = mpc624_ai_get_sample(dev, s);
        }
 
-       /*  Return the number of samples read/written */
-       return n;
+       return insn->n;
 }
 
 static int mpc624_attach(struct comedi_device *dev, struct comedi_devconfig *it)
@@ -285,61 +257,52 @@ static int mpc624_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 
        switch (it->options[1]) {
        case 0:
-               devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz;
+               devpriv->ai_speed = MPC624_SPEED_3_52_KHZ;
                break;
        case 1:
-               devpriv->ulConvertionRate = MPC624_SPEED_1_76_kHz;
+               devpriv->ai_speed = MPC624_SPEED_1_76_KHZ;
                break;
        case 2:
-               devpriv->ulConvertionRate = MPC624_SPEED_880_Hz;
+               devpriv->ai_speed = MPC624_SPEED_880_HZ;
                break;
        case 3:
-               devpriv->ulConvertionRate = MPC624_SPEED_440_Hz;
+               devpriv->ai_speed = MPC624_SPEED_440_HZ;
                break;
        case 4:
-               devpriv->ulConvertionRate = MPC624_SPEED_220_Hz;
+               devpriv->ai_speed = MPC624_SPEED_220_HZ;
                break;
        case 5:
-               devpriv->ulConvertionRate = MPC624_SPEED_110_Hz;
+               devpriv->ai_speed = MPC624_SPEED_110_HZ;
                break;
        case 6:
-               devpriv->ulConvertionRate = MPC624_SPEED_55_Hz;
+               devpriv->ai_speed = MPC624_SPEED_55_HZ;
                break;
        case 7:
-               devpriv->ulConvertionRate = MPC624_SPEED_27_5_Hz;
+               devpriv->ai_speed = MPC624_SPEED_27_5_HZ;
                break;
        case 8:
-               devpriv->ulConvertionRate = MPC624_SPEED_13_75_Hz;
+               devpriv->ai_speed = MPC624_SPEED_13_75_HZ;
                break;
        case 9:
-               devpriv->ulConvertionRate = MPC624_SPEED_6_875_Hz;
+               devpriv->ai_speed = MPC624_SPEED_6_875_HZ;
                break;
        default:
-               devpriv->ulConvertionRate = MPC624_SPEED_3_52_kHz;
+               devpriv->ai_speed = MPC624_SPEED_3_52_KHZ;
        }
 
        ret = comedi_alloc_subdevices(dev, 1);
        if (ret)
                return ret;
 
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_DIFF;
-       s->n_chan = 8;
-       switch (it->options[1]) {
-       default:
-               s->maxdata = 0x3FFFFFFF;
-       }
-
-       switch (it->options[1]) {
-       case 0:
-               s->range_table = &range_mpc624_bipolar1;
-               break;
-       default:
-               s->range_table = &range_mpc624_bipolar10;
-       }
-       s->len_chanlist = 1;
-       s->insn_read = mpc624_ai_rinsn;
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_DIFF;
+       s->n_chan       = 4;
+       s->maxdata      = 0x3fffffff;
+       s->range_table  = (it->options[1] == 0) ? &range_mpc624_bipolar1
+                                               : &range_mpc624_bipolar10;
+       s->insn_read    = mpc624_ai_insn_read;
 
        return 0;
 }
@@ -353,5 +316,5 @@ static struct comedi_driver mpc624_driver = {
 module_comedi_driver(mpc624_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Micro/sys MPC-624 PC/104 board");
 MODULE_LICENSE("GPL");
index 8471219210b65ecfddb7c6e723ce204b4a2f14bf..b5a26f7b4332857513e599164e018bf0e13ef08a 100644 (file)
@@ -1,79 +1,91 @@
 /*
  comedi/drivers/multiq3.c
  Hardware driver for Quanser Consulting MultiQ-3 board
-
  COMEDI - Linux Control and Measurement Device Interface
  Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
-
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
-
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
multiq3.c
* Hardware driver for Quanser Consulting MultiQ-3 board
+ *
* COMEDI - Linux Control and Measurement Device Interface
* Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
  */
-/*
-Driver: multiq3
-Description: Quanser Consulting MultiQ-3
-Author: Anders Blomdell <anders.blomdell@control.lth.se>
-Status: works
-Devices: [Quanser Consulting] MultiQ-3 (multiq3)
-
-*/
-
-#include <linux/module.h>
-#include <linux/interrupt.h>
-#include "../comedidev.h"
 
 /*
- * MULTIQ-3 port offsets
+ * Driver: multiq3
+ * Description: Quanser Consulting MultiQ-3
+ * Devices: [Quanser Consulting] MultiQ-3 (multiq3)
+ * Author: Anders Blomdell <anders.blomdell@control.lth.se>
+ * Status: works
+ *
+ * Configuration Options:
+ *  [0] - I/O port base address
+ *  [1] - IRQ (not used)
+ *  [2] - Number of optional encoder chips installed on board
+ *       0 = none
+ *       1 = 2 inputs (Model -2E)
+ *       2 = 4 inputs (Model -4E)
+ *       3 = 6 inputs (Model -6E)
+ *       4 = 8 inputs (Model -8E)
  */
-#define MULTIQ3_DIGIN_PORT 0
-#define MULTIQ3_DIGOUT_PORT 0
-#define MULTIQ3_DAC_DATA 2
-#define MULTIQ3_AD_DATA 4
-#define MULTIQ3_AD_CS 4
-#define MULTIQ3_STATUS 6
-#define MULTIQ3_CONTROL 6
-#define MULTIQ3_CLK_DATA 8
-#define MULTIQ3_ENC_DATA 12
-#define MULTIQ3_ENC_CONTROL 14
 
-/*
- * flags for CONTROL register
- */
-#define MULTIQ3_AD_MUX_EN      0x0040
-#define MULTIQ3_AD_AUTOZ       0x0080
-#define MULTIQ3_AD_AUTOCAL     0x0100
-#define MULTIQ3_AD_SH          0x0200
-#define MULTIQ3_AD_CLOCK_4M    0x0400
-#define MULTIQ3_DA_LOAD                0x1800
+#include <linux/module.h>
 
-#define MULTIQ3_CONTROL_MUST    0x0600
+#include "../comedidev.h"
 
 /*
- * flags for STATUS register
+ * Register map
  */
-#define MULTIQ3_STATUS_EOC      0x008
-#define MULTIQ3_STATUS_EOC_I    0x010
+#define MULTIQ3_DI_REG                 0x00
+#define MULTIQ3_DO_REG                 0x00
+#define MULTIQ3_AO_REG                 0x02
+#define MULTIQ3_AI_REG                 0x04
+#define MULTIQ3_AI_CONV_REG            0x04
+#define MULTIQ3_STATUS_REG             0x06
+#define MULTIQ3_STATUS_EOC             BIT(3)
+#define MULTIQ3_STATUS_EOC_I           BIT(4)
+#define MULTIQ3_CTRL_REG               0x06
+#define MULTIQ3_CTRL_AO_CHAN(x)                (((x) & 0x7) << 0)
+#define MULTIQ3_CTRL_RC(x)             (((x) & 0x3) << 0)
+#define MULTIQ3_CTRL_AI_CHAN(x)                (((x) & 0x7) << 3)
+#define MULTIQ3_CTRL_E_CHAN(x)         (((x) & 0x7) << 3)
+#define MULTIQ3_CTRL_EN                        BIT(6)
+#define MULTIQ3_CTRL_AZ                        BIT(7)
+#define MULTIQ3_CTRL_CAL               BIT(8)
+#define MULTIQ3_CTRL_SH                        BIT(9)
+#define MULTIQ3_CTRL_CLK               BIT(10)
+#define MULTIQ3_CTRL_LD                        (3 << 11)
+#define MULTIQ3_CLK_REG                        0x08
+#define MULTIQ3_ENC_DATA_REG           0x0c
+#define MULTIQ3_ENC_CTRL_REG           0x0e
 
 /*
- * flags for encoder control
+ * Encoder chip commands (from the programming manual)
  */
-#define MULTIQ3_CLOCK_DATA      0x00
-#define MULTIQ3_CLOCK_SETUP     0x18
-#define MULTIQ3_INPUT_SETUP     0x41
-#define MULTIQ3_QUAD_X4         0x38
-#define MULTIQ3_BP_RESET        0x01
-#define MULTIQ3_CNTR_RESET      0x02
-#define MULTIQ3_TRSFRPR_CTR     0x08
-#define MULTIQ3_TRSFRCNTR_OL    0x10
-#define MULTIQ3_EFLAG_RESET     0x06
-
-#define MULTIQ3_TIMEOUT 30
+#define MULTIQ3_CLOCK_DATA             0x00    /* FCK frequency divider */
+#define MULTIQ3_CLOCK_SETUP            0x18    /* xfer PR0 to PSC */
+#define MULTIQ3_INPUT_SETUP            0x41    /* enable inputs A and B */
+#define MULTIQ3_QUAD_X4                        0x38    /* quadrature */
+#define MULTIQ3_BP_RESET               0x01    /* reset byte pointer */
+#define MULTIQ3_CNTR_RESET             0x02    /* reset counter */
+#define MULTIQ3_TRSFRPR_CTR            0x08    /* xfre preset reg to counter */
+#define MULTIQ3_TRSFRCNTR_OL           0x10    /* xfer CNTR to OL (x and y) */
+#define MULTIQ3_EFLAG_RESET            0x06    /* reset E bit of flag reg */
+
+static void multiq3_set_ctrl(struct comedi_device *dev, unsigned int bits)
+{
+       /*
+        * According to the programming manual, the SH and CLK bits should
+        * be kept high at all times.
+        */
+       outw(MULTIQ3_CTRL_SH | MULTIQ3_CTRL_CLK | bits,
+            dev->iobase + MULTIQ3_CTRL_REG);
+}
 
 static int multiq3_ai_status(struct comedi_device *dev,
                             struct comedi_subdevice *s,
@@ -82,7 +94,7 @@ static int multiq3_ai_status(struct comedi_device *dev,
 {
        unsigned int status;
 
-       status = inw(dev->iobase + MULTIQ3_STATUS);
+       status = inw(dev->iobase + MULTIQ3_STATUS_REG);
        if (status & context)
                return 0;
        return -EBUSY;
@@ -90,36 +102,39 @@ static int multiq3_ai_status(struct comedi_device *dev,
 
 static int multiq3_ai_insn_read(struct comedi_device *dev,
                                struct comedi_subdevice *s,
-                               struct comedi_insn *insn, unsigned int *data)
+                               struct comedi_insn *insn,
+                               unsigned int *data)
 {
-       int n;
-       int chan;
-       unsigned int hi, lo;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val;
        int ret;
+       int i;
 
-       chan = CR_CHAN(insn->chanspec);
-       outw(MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3),
-            dev->iobase + MULTIQ3_CONTROL);
+       multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN | MULTIQ3_CTRL_AI_CHAN(chan));
 
        ret = comedi_timeout(dev, s, insn, multiq3_ai_status,
                             MULTIQ3_STATUS_EOC);
        if (ret)
                return ret;
 
-       for (n = 0; n < insn->n; n++) {
-               outw(0, dev->iobase + MULTIQ3_AD_CS);
+       for (i = 0; i < insn->n; i++) {
+               outw(0, dev->iobase + MULTIQ3_AI_CONV_REG);
 
                ret = comedi_timeout(dev, s, insn, multiq3_ai_status,
                                     MULTIQ3_STATUS_EOC_I);
                if (ret)
                        return ret;
 
-               hi = inb(dev->iobase + MULTIQ3_AD_CS);
-               lo = inb(dev->iobase + MULTIQ3_AD_CS);
-               data[n] = (((hi << 8) | lo) + 0x1000) & 0x1fff;
+               /* get a 16-bit sample; mask it to the subdevice resolution */
+               val = inb(dev->iobase + MULTIQ3_AI_REG) << 8;
+               val |= inb(dev->iobase + MULTIQ3_AI_REG);
+               val &= s->maxdata;
+
+               /* munge the 2's complement value to offset binary */
+               data[i] = comedi_offset_munge(s, val);
        }
 
-       return n;
+       return insn->n;
 }
 
 static int multiq3_ao_insn_write(struct comedi_device *dev,
@@ -133,10 +148,10 @@ static int multiq3_ao_insn_write(struct comedi_device *dev,
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               outw(MULTIQ3_CONTROL_MUST | MULTIQ3_DA_LOAD | chan,
-                    dev->iobase + MULTIQ3_CONTROL);
-               outw(val, dev->iobase + MULTIQ3_DAC_DATA);
-               outw(MULTIQ3_CONTROL_MUST, dev->iobase + MULTIQ3_CONTROL);
+               multiq3_set_ctrl(dev, MULTIQ3_CTRL_LD |
+                                     MULTIQ3_CTRL_AO_CHAN(chan));
+               outw(val, dev->iobase + MULTIQ3_AO_REG);
+               multiq3_set_ctrl(dev, 0);
        }
        s->readback[chan] = val;
 
@@ -147,7 +162,7 @@ static int multiq3_di_insn_bits(struct comedi_device *dev,
                                struct comedi_subdevice *s,
                                struct comedi_insn *insn, unsigned int *data)
 {
-       data[1] = inw(dev->iobase + MULTIQ3_DIGIN_PORT);
+       data[1] = inw(dev->iobase + MULTIQ3_DI_REG);
 
        return insn->n;
 }
@@ -158,7 +173,7 @@ static int multiq3_do_insn_bits(struct comedi_device *dev,
                                unsigned int *data)
 {
        if (comedi_dio_update_state(s, data))
-               outw(s->state, dev->iobase + MULTIQ3_DIGOUT_PORT);
+               outw(s->state, dev->iobase + MULTIQ3_DO_REG);
 
        data[1] = s->state;
 
@@ -170,41 +185,76 @@ static int multiq3_encoder_insn_read(struct comedi_device *dev,
                                     struct comedi_insn *insn,
                                     unsigned int *data)
 {
-       int chan = CR_CHAN(insn->chanspec);
-       int control = MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3);
-       int value;
-       int n;
-
-       for (n = 0; n < insn->n; n++) {
-               outw(control, dev->iobase + MULTIQ3_CONTROL);
-               outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CONTROL);
-               outb(MULTIQ3_TRSFRCNTR_OL, dev->iobase + MULTIQ3_ENC_CONTROL);
-               value = inb(dev->iobase + MULTIQ3_ENC_DATA);
-               value |= (inb(dev->iobase + MULTIQ3_ENC_DATA) << 8);
-               value |= (inb(dev->iobase + MULTIQ3_ENC_DATA) << 16);
-               data[n] = (value + 0x800000) & 0xffffff;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val;
+       int i;
+
+       for (i = 0; i < insn->n; i++) {
+               /* select encoder channel */
+               multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN |
+                                     MULTIQ3_CTRL_E_CHAN(chan));
+
+               /* reset the byte pointer */
+               outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+
+               /* latch the data */
+               outb(MULTIQ3_TRSFRCNTR_OL, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+
+               /* read the 24-bit encoder data (lsb/mid/msb) */
+               val = inb(dev->iobase + MULTIQ3_ENC_DATA_REG);
+               val |= (inb(dev->iobase + MULTIQ3_ENC_DATA_REG) << 8);
+               val |= (inb(dev->iobase + MULTIQ3_ENC_DATA_REG) << 16);
+
+               /*
+                * Munge the data so that the reset value is in the middle
+                * of the maxdata range, i.e.:
+                *
+                * real value   comedi value
+                * 0xffffff     0x7fffff        1 negative count
+                * 0x000000     0x800000        reset value
+                * 0x000001     0x800001        1 positive count
+                *
+                * It's possible for the 24-bit counter to overflow but it
+                * would normally take _quite_ a few turns. A 2000 line
+                * encoder in quadrature results in 8000 counts/rev. So about
+                * 1048 turns in either direction can be measured without
+                * an overflow.
+                */
+               data[i] = (val + ((s->maxdata + 1) >> 1)) & s->maxdata;
        }
 
-       return n;
+       return insn->n;
 }
 
-static void encoder_reset(struct comedi_device *dev)
+static void multiq3_encoder_reset(struct comedi_device *dev,
+                                 unsigned int chan)
 {
-       struct comedi_subdevice *s = &dev->subdevices[4];
-       int chan;
-
-       for (chan = 0; chan < s->n_chan; chan++) {
-               int control =
-                   MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3);
-               outw(control, dev->iobase + MULTIQ3_CONTROL);
-               outb(MULTIQ3_EFLAG_RESET, dev->iobase + MULTIQ3_ENC_CONTROL);
-               outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CONTROL);
-               outb(MULTIQ3_CLOCK_DATA, dev->iobase + MULTIQ3_ENC_DATA);
-               outb(MULTIQ3_CLOCK_SETUP, dev->iobase + MULTIQ3_ENC_CONTROL);
-               outb(MULTIQ3_INPUT_SETUP, dev->iobase + MULTIQ3_ENC_CONTROL);
-               outb(MULTIQ3_QUAD_X4, dev->iobase + MULTIQ3_ENC_CONTROL);
-               outb(MULTIQ3_CNTR_RESET, dev->iobase + MULTIQ3_ENC_CONTROL);
+       multiq3_set_ctrl(dev, MULTIQ3_CTRL_EN | MULTIQ3_CTRL_E_CHAN(chan));
+       outb(MULTIQ3_EFLAG_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_BP_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_CLOCK_DATA, dev->iobase + MULTIQ3_ENC_DATA_REG);
+       outb(MULTIQ3_CLOCK_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_INPUT_SETUP, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_QUAD_X4, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+       outb(MULTIQ3_CNTR_RESET, dev->iobase + MULTIQ3_ENC_CTRL_REG);
+}
+
+static int multiq3_encoder_insn_config(struct comedi_device *dev,
+                                      struct comedi_subdevice *s,
+                                      struct comedi_insn *insn,
+                                      unsigned int *data)
+{
+       unsigned int chan = CR_CHAN(insn->chanspec);
+
+       switch (data[0]) {
+       case INSN_CONFIG_RESET:
+               multiq3_encoder_reset(dev, chan);
+               break;
+       default:
+               return -EINVAL;
        }
+
+       return insn->n;
 }
 
 static int multiq3_attach(struct comedi_device *dev,
@@ -212,6 +262,7 @@ static int multiq3_attach(struct comedi_device *dev,
 {
        struct comedi_subdevice *s;
        int ret;
+       int i;
 
        ret = comedi_request_region(dev, it->options[0], 0x10);
        if (ret)
@@ -221,57 +272,58 @@ static int multiq3_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       /* ai subdevice */
-       s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_GROUND;
-       s->n_chan = 8;
-       s->insn_read = multiq3_ai_insn_read;
-       s->maxdata = 0x1fff;
-       s->range_table = &range_bipolar5;
-
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND;
+       s->n_chan       = 8;
+       s->maxdata      = 0x1fff;
+       s->range_table  = &range_bipolar5;
+       s->insn_read    = multiq3_ai_insn_read;
+
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       /* ao subdevice */
-       s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan = 8;
-       s->maxdata = 0xfff;
-       s->range_table = &range_bipolar5;
-       s->insn_write = multiq3_ao_insn_write;
+       s->type         = COMEDI_SUBD_AO;
+       s->subdev_flags = SDF_WRITABLE;
+       s->n_chan       = 8;
+       s->maxdata      = 0x0fff;
+       s->range_table  = &range_bipolar5;
+       s->insn_write   = multiq3_ao_insn_write;
 
        ret = comedi_alloc_subdev_readback(s);
        if (ret)
                return ret;
 
+       /* Digital Input subdevice */
        s = &dev->subdevices[2];
-       /* di subdevice */
-       s->type = COMEDI_SUBD_DI;
-       s->subdev_flags = SDF_READABLE;
-       s->n_chan = 16;
-       s->insn_bits = multiq3_di_insn_bits;
-       s->maxdata = 1;
-       s->range_table = &range_digital;
-
+       s->type         = COMEDI_SUBD_DI;
+       s->subdev_flags = SDF_READABLE;
+       s->n_chan       = 16;
+       s->maxdata      = 1;
+       s->range_table  = &range_digital;
+       s->insn_bits    = multiq3_di_insn_bits;
+
+       /* Digital Output subdevice */
        s = &dev->subdevices[3];
-       /* do subdevice */
-       s->type = COMEDI_SUBD_DO;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan = 16;
-       s->insn_bits = multiq3_do_insn_bits;
-       s->maxdata = 1;
-       s->range_table = &range_digital;
-       s->state = 0;
-
+       s->type         = COMEDI_SUBD_DO;
+       s->subdev_flags = SDF_WRITABLE;
+       s->n_chan       = 16;
+       s->maxdata      = 1;
+       s->range_table  = &range_digital;
+       s->insn_bits    = multiq3_do_insn_bits;
+
+       /* Encoder (Counter) subdevice */
        s = &dev->subdevices[4];
-       /* encoder (counter) subdevice */
-       s->type = COMEDI_SUBD_COUNTER;
-       s->subdev_flags = SDF_READABLE | SDF_LSAMPL;
-       s->n_chan = it->options[2] * 2;
-       s->insn_read = multiq3_encoder_insn_read;
-       s->maxdata = 0xffffff;
-       s->range_table = &range_unknown;
+       s->type         = COMEDI_SUBD_COUNTER;
+       s->subdev_flags = SDF_READABLE | SDF_LSAMPL;
+       s->n_chan       = it->options[2] * 2;
+       s->maxdata      = 0x00ffffff;
+       s->range_table  = &range_unknown;
+       s->insn_read    = multiq3_encoder_insn_read;
+       s->insn_config  = multiq3_encoder_insn_config;
 
-       encoder_reset(dev);
+       for (i = 0; i < s->n_chan; i++)
+               multiq3_encoder_reset(dev, i);
 
        return 0;
 }
@@ -285,5 +337,5 @@ static struct comedi_driver multiq3_driver = {
 module_comedi_driver(multiq3_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Quanser Consulting MultiQ-3 board");
 MODULE_LICENSE("GPL");
index c20c51bef3e7d543f39fffc9e53060742291cfe2..b74e44ec521a494887b79bb6bb16f10c99558c5f 100644 (file)
@@ -167,15 +167,15 @@ static inline unsigned GI_HW_ARM_SEL_MASK(enum ni_gpct_variant variant)
        }
 }
 
-static int ni_tio_has_gate2_registers(const struct ni_gpct_device *counter_dev)
+static bool ni_tio_has_gate2_registers(const struct ni_gpct_device *counter_dev)
 {
        switch (counter_dev->variant) {
        case ni_gpct_variant_e_series:
        default:
-               return 0;
+               return false;
        case ni_gpct_variant_m_series:
        case ni_gpct_variant_660x:
-               return 1;
+               return true;
        }
 }
 
index 9b124b09e9140aee5cad69aa9ab75a542acd0436..437f723bb34d536600f8805100dcb4b455c01844 100644 (file)
@@ -157,12 +157,6 @@ static int ni_tio_output_cmd(struct comedi_subdevice *s)
        dev_err(counter->counter_dev->dev->class_dev,
                "output commands not yet implemented.\n");
        return -ENOTSUPP;
-
-       counter->mite_chan->dir = COMEDI_OUTPUT;
-       mite_prep_dma(counter->mite_chan, 32, 32);
-       ni_tio_configure_dma(counter, true, false);
-       mite_dma_arm(counter->mite_chan);
-       return ni_tio_arm(counter, 1, NI_GPCT_ARM_IMMEDIATE);
 }
 
 static int ni_tio_cmd_setup(struct comedi_subdevice *s)
index 88de8da3eff3f272669f23a0b1d11929bb31daf7..95b537a8ecdb13b17e9d753f22a6c0dd04c60f99 100644 (file)
@@ -166,7 +166,7 @@ enum commands {
 struct ni6501_private {
        struct usb_endpoint_descriptor *ep_rx;
        struct usb_endpoint_descriptor *ep_tx;
-       struct semaphore sem;
+       struct mutex mut;
        u8 *usb_rx_buf;
        u8 *usb_tx_buf;
 };
@@ -183,7 +183,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
        if (command != SET_PORT_DIR && !bitmap)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        switch (command) {
        case READ_PORT:
@@ -248,7 +248,7 @@ static int ni6501_port_command(struct comedi_device *dev, int command,
                ret = -EINVAL;
        }
 end:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -265,7 +265,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command,
        if ((command == READ_COUNTER || command ==  WRITE_COUNTER) && !val)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        switch (command) {
        case START_COUNTER:
@@ -338,7 +338,7 @@ static int ni6501_counter_command(struct comedi_device *dev, int command,
                ret = -EINVAL;
        }
 end:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -535,7 +535,7 @@ static int ni6501_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       sema_init(&devpriv->sem, 1);
+       mutex_init(&devpriv->mut);
        usb_set_intfdata(intf, devpriv);
 
        ret = comedi_alloc_subdevices(dev, 2);
@@ -573,14 +573,14 @@ static void ni6501_detach(struct comedi_device *dev)
        if (!devpriv)
                return;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        usb_set_intfdata(intf, NULL);
 
        kfree(devpriv->usb_rx_buf);
        kfree(devpriv->usb_tx_buf);
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 }
 
 static struct comedi_driver ni6501_driver = {
index cfc3a627d0ca3673c35cfd975283e692ceffc41e..3774daa9d6615f6f2d70a079b1877d25497e3028 100644 (file)
@@ -49,7 +49,7 @@
 #define PCL711_TIMER_BASE      0x00
 #define PCL711_AI_LSB_REG      0x04
 #define PCL711_AI_MSB_REG      0x05
-#define PCL711_AI_MSB_DRDY     (1 << 4)
+#define PCL711_AI_MSB_DRDY     BIT(4)
 #define PCL711_AO_LSB_REG(x)   (0x04 + ((x) * 2))
 #define PCL711_AO_MSB_REG(x)   (0x05 + ((x) * 2))
 #define PCL711_DI_LSB_REG      0x06
 #define PCL711_AI_GAIN(x)      (((x) & 0xf) << 0)
 #define PCL711_MUX_REG         0x0a
 #define PCL711_MUX_CHAN(x)     (((x) & 0xf) << 0)
-#define PCL711_MUX_CS0         (1 << 4)
-#define PCL711_MUX_CS1         (1 << 5)
+#define PCL711_MUX_CS0         BIT(4)
+#define PCL711_MUX_CS1         BIT(5)
 #define PCL711_MUX_DIFF                (PCL711_MUX_CS0 | PCL711_MUX_CS1)
 #define PCL711_MODE_REG                0x0b
-#define PCL711_MODE_DEFAULT    (0 << 0)
-#define PCL711_MODE_SOFTTRIG   (1 << 0)
-#define PCL711_MODE_EXT                (2 << 0)
-#define PCL711_MODE_EXT_IRQ    (3 << 0)
-#define PCL711_MODE_PACER      (4 << 0)
-#define PCL711_MODE_PACER_IRQ  (6 << 0)
+#define PCL711_MODE(x)         (((x) & 0x7) << 0)
+#define PCL711_MODE_DEFAULT    PCL711_MODE(0)
+#define PCL711_MODE_SOFTTRIG   PCL711_MODE(1)
+#define PCL711_MODE_EXT                PCL711_MODE(2)
+#define PCL711_MODE_EXT_IRQ    PCL711_MODE(3)
+#define PCL711_MODE_PACER      PCL711_MODE(4)
+#define PCL711_MODE_PACER_IRQ  PCL711_MODE(6)
 #define PCL711_MODE_IRQ(x)     (((x) & 0x7) << 4)
 #define PCL711_SOFTTRIG_REG    0x0c
 #define PCL711_SOFTTRIG                (0 << 0)  /* any value will work */
index 48f6cdf440b99135272b24a4067188ae1e7cf6c7..9c75065dd26a34ca4e4cce0fd8ba899a2fb58222 100644 (file)
 #include "comedi_isadma.h"
 #include "comedi_8254.h"
 
-/* hardware types of the cards */
-#define boardPCL812PG        0 /* and ACL-8112PG */
-#define boardPCL813B         1
-#define boardPCL812          2
-#define boardPCL813          3
-#define boardISO813          5
-#define boardACL8113         6
-#define boardACL8112         7 /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */
-#define boardACL8216         8 /* and ICP DAS A-826PG */
-#define boardA821            9 /* PGH, PGL, PGL/NDA versions */
-
 /*
  * Register I/O map
  */
 #define PCL812_TIMER_BASE                      0x00
 #define PCL812_AI_LSB_REG                      0x04
 #define PCL812_AI_MSB_REG                      0x05
-#define PCL812_AI_MSB_DRDY                     (1 << 4)
+#define PCL812_AI_MSB_DRDY                     BIT(4)
 #define PCL812_AO_LSB_REG(x)                   (0x04 + ((x) * 2))
 #define PCL812_AO_MSB_REG(x)                   (0x05 + ((x) * 2))
 #define PCL812_DI_LSB_REG                      0x06
 #define PCL812_DI_MSB_REG                      0x07
 #define PCL812_STATUS_REG                      0x08
-#define PCL812_STATUS_DRDY                     (1 << 5)
+#define PCL812_STATUS_DRDY                     BIT(5)
 #define PCL812_RANGE_REG                       0x09
 #define PCL812_MUX_REG                         0x0a
 #define PCL812_MUX_CHAN(x)                     ((x) << 0)
-#define PCL812_MUX_CS0                         (1 << 4)
-#define PCL812_MUX_CS1                         (1 << 5)
+#define PCL812_MUX_CS0                         BIT(4)
+#define PCL812_MUX_CS1                         BIT(5)
 #define PCL812_CTRL_REG                                0x0b
-#define PCL812_CTRL_DISABLE_TRIG               (0 << 0)
-#define PCL812_CTRL_SOFT_TRIG                  (1 << 0)
-#define PCL812_CTRL_PACER_DMA_TRIG             (2 << 0)
-#define PCL812_CTRL_PACER_EOC_TRIG             (6 << 0)
+#define PCL812_CTRL_TRIG(x)                    (((x) & 0x7) << 0)
+#define PCL812_CTRL_DISABLE_TRIG               PCL812_CTRL_TRIG(0)
+#define PCL812_CTRL_SOFT_TRIG                  PCL812_CTRL_TRIG(1)
+#define PCL812_CTRL_PACER_DMA_TRIG             PCL812_CTRL_TRIG(2)
+#define PCL812_CTRL_PACER_EOC_TRIG             PCL812_CTRL_TRIG(6)
 #define PCL812_SOFTTRIG_REG                    0x0c
 #define PCL812_DO_LSB_REG                      0x0d
 #define PCL812_DO_MSB_REG                      0x0e
@@ -327,14 +317,26 @@ static const struct comedi_lrange range_a821pgh_ai = {
        }
 };
 
+enum pcl812_boardtype {
+       BOARD_PCL812PG  = 0,    /* and ACL-8112PG */
+       BOARD_PCL813B   = 1,
+       BOARD_PCL812    = 2,
+       BOARD_PCL813    = 3,
+       BOARD_ISO813    = 5,
+       BOARD_ACL8113   = 6,
+       BOARD_ACL8112   = 7,    /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */
+       BOARD_ACL8216   = 8,    /* and ICP DAS A-826PG */
+       BOARD_A821      = 9,    /* PGH, PGL, PGL/NDA versions */
+};
+
 struct pcl812_board {
        const char *name;
-       int board_type;
+       enum pcl812_boardtype board_type;
        int n_aichan;
        int n_aochan;
        unsigned int ai_ns_min;
        const struct comedi_lrange *rangelist_ai;
-       unsigned int IRQbits;
+       unsigned int irq_bits;
        unsigned int has_dma:1;
        unsigned int has_16bit_ai:1;
        unsigned int has_mpc508_mux:1;
@@ -344,161 +346,161 @@ struct pcl812_board {
 static const struct pcl812_board boardtypes[] = {
        {
                .name           = "pcl812",
-               .board_type     = boardPCL812,
+               .board_type     = BOARD_PCL812,
                .n_aichan       = 16,
                .n_aochan       = 2,
                .ai_ns_min      = 33000,
                .rangelist_ai   = &range_bipolar10,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_dio        = 1,
        }, {
                .name           = "pcl812pg",
-               .board_type     = boardPCL812PG,
+               .board_type     = BOARD_PCL812PG,
                .n_aichan       = 16,
                .n_aochan       = 2,
                .ai_ns_min      = 33000,
                .rangelist_ai   = &range_pcl812pg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_dio        = 1,
        }, {
                .name           = "acl8112pg",
-               .board_type     = boardPCL812PG,
+               .board_type     = BOARD_PCL812PG,
                .n_aichan       = 16,
                .n_aochan       = 2,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_pcl812pg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_dio        = 1,
        }, {
                .name           = "acl8112dg",
-               .board_type     = boardACL8112,
+               .board_type     = BOARD_ACL8112,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_acl8112dg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_mpc508_mux = 1,
                .has_dio        = 1,
        }, {
                .name           = "acl8112hg",
-               .board_type     = boardACL8112,
+               .board_type     = BOARD_ACL8112,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_acl8112hg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_mpc508_mux = 1,
                .has_dio        = 1,
        }, {
                .name           = "a821pgl",
-               .board_type     = boardA821,
+               .board_type     = BOARD_A821,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 1,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_pcl813b_ai,
-               .IRQbits        = 0x000c,
+               .irq_bits       = 0x000c,
                .has_dio        = 1,
        }, {
                .name           = "a821pglnda",
-               .board_type     = boardA821,
+               .board_type     = BOARD_A821,
                .n_aichan       = 16,   /* 8 differential */
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_pcl813b_ai,
-               .IRQbits        = 0x000c,
+               .irq_bits       = 0x000c,
        }, {
                .name           = "a821pgh",
-               .board_type     = boardA821,
+               .board_type     = BOARD_A821,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 1,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_a821pgh_ai,
-               .IRQbits        = 0x000c,
+               .irq_bits       = 0x000c,
                .has_dio        = 1,
        }, {
                .name           = "a822pgl",
-               .board_type     = boardACL8112,
+               .board_type     = BOARD_ACL8112,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_acl8112dg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_dio        = 1,
        }, {
                .name           = "a822pgh",
-               .board_type     = boardACL8112,
+               .board_type     = BOARD_ACL8112,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_acl8112hg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_dio        = 1,
        }, {
                .name           = "a823pgl",
-               .board_type     = boardACL8112,
+               .board_type     = BOARD_ACL8112,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 8000,
                .rangelist_ai   = &range_acl8112dg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_dio        = 1,
        }, {
                .name           = "a823pgh",
-               .board_type     = boardACL8112,
+               .board_type     = BOARD_ACL8112,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 8000,
                .rangelist_ai   = &range_acl8112hg_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_dio        = 1,
        }, {
                .name           = "pcl813",
-               .board_type     = boardPCL813,
+               .board_type     = BOARD_PCL813,
                .n_aichan       = 32,
                .rangelist_ai   = &range_pcl813b_ai,
        }, {
                .name           = "pcl813b",
-               .board_type     = boardPCL813B,
+               .board_type     = BOARD_PCL813B,
                .n_aichan       = 32,
                .rangelist_ai   = &range_pcl813b_ai,
        }, {
                .name           = "acl8113",
-               .board_type     = boardACL8113,
+               .board_type     = BOARD_ACL8113,
                .n_aichan       = 32,
                .rangelist_ai   = &range_acl8113_1_ai,
        }, {
                .name           = "iso813",
-               .board_type     = boardISO813,
+               .board_type     = BOARD_ISO813,
                .n_aichan       = 32,
                .rangelist_ai   = &range_iso813_1_ai,
        }, {
                .name           = "acl8216",
-               .board_type     = boardACL8216,
+               .board_type     = BOARD_ACL8216,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_pcl813b2_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_16bit_ai   = 1,
                .has_mpc508_mux = 1,
                .has_dio        = 1,
        }, {
                .name           = "a826pg",
-               .board_type     = boardACL8216,
+               .board_type     = BOARD_ACL8216,
                .n_aichan       = 16,   /* 8 differential */
                .n_aochan       = 2,
                .ai_ns_min      = 10000,
                .rangelist_ai   = &range_pcl813b2_ai,
-               .IRQbits        = 0xdcfc,
+               .irq_bits       = 0xdcfc,
                .has_dma        = 1,
                .has_16bit_ai   = 1,
                .has_dio        = 1,
@@ -1017,16 +1019,14 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev,
        const struct pcl812_board *board = dev->board_ptr;
        struct pcl812_private *devpriv = dev->private;
 
-       /* default to the range table from the boardinfo */
-       s->range_table = board->rangelist_ai;
-
-       /* now check the user config option based on the boardtype */
        switch (board->board_type) {
-       case boardPCL812PG:
+       case BOARD_PCL812PG:
                if (it->options[4] == 1)
                        s->range_table = &range_pcl812pg2_ai;
+               else
+                       s->range_table = board->rangelist_ai;
                break;
-       case boardPCL812:
+       case BOARD_PCL812:
                switch (it->options[4]) {
                case 0:
                        s->range_table = &range_bipolar10;
@@ -1051,11 +1051,13 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev,
                        break;
                }
                break;
-       case boardPCL813B:
+       case BOARD_PCL813B:
                if (it->options[1] == 1)
                        s->range_table = &range_pcl813b2_ai;
+               else
+                       s->range_table = board->rangelist_ai;
                break;
-       case boardISO813:
+       case BOARD_ISO813:
                switch (it->options[1]) {
                case 0:
                        s->range_table = &range_iso813_1_ai;
@@ -1076,7 +1078,7 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev,
                        break;
                }
                break;
-       case boardACL8113:
+       case BOARD_ACL8113:
                switch (it->options[1]) {
                case 0:
                        s->range_table = &range_acl8113_1_ai;
@@ -1097,6 +1099,9 @@ static void pcl812_set_ai_range_table(struct comedi_device *dev,
                        break;
                }
                break;
+       default:
+               s->range_table = board->rangelist_ai;
+               break;
        }
 }
 
@@ -1138,14 +1143,14 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        if (ret)
                return ret;
 
-       if (board->IRQbits) {
+       if (board->irq_bits) {
                dev->pacer = comedi_8254_init(dev->iobase + PCL812_TIMER_BASE,
                                              I8254_OSC_BASE_2MHZ,
                                              I8254_IO8, 0);
                if (!dev->pacer)
                        return -ENOMEM;
 
-               if ((1 << it->options[1]) & board->IRQbits) {
+               if ((1 << it->options[1]) & board->irq_bits) {
                        ret = request_irq(it->options[1], pcl812_interrupt, 0,
                                          dev->board_name, dev);
                        if (ret == 0)
@@ -1159,15 +1164,17 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 
        /* differential analog inputs? */
        switch (board->board_type) {
-       case boardA821:
+       case BOARD_A821:
                if (it->options[2] == 1)
                        devpriv->use_diff = 1;
                break;
-       case boardACL8112:
-       case boardACL8216:
+       case BOARD_ACL8112:
+       case BOARD_ACL8216:
                if (it->options[4] == 1)
                        devpriv->use_diff = 1;
                break;
+       default:
+               break;
        }
 
        n_subdevices = 1;               /* all boardtypes have analog inputs */
@@ -1220,20 +1227,31 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
                s->n_chan       = board->n_aochan;
                s->maxdata      = 0xfff;
-               s->range_table  = &range_unipolar5;
                switch (board->board_type) {
-               case boardA821:
+               case BOARD_A821:
                        if (it->options[3] == 1)
                                s->range_table = &range_unipolar10;
+                       else
+                               s->range_table = &range_unipolar5;
                        break;
-               case boardPCL812:
-               case boardACL8112:
-               case boardPCL812PG:
-               case boardACL8216:
-                       if (it->options[5] == 1)
+               case BOARD_PCL812:
+               case BOARD_ACL8112:
+               case BOARD_PCL812PG:
+               case BOARD_ACL8216:
+                       switch (it->options[5]) {
+                       case 1:
                                s->range_table = &range_unipolar10;
-                       if (it->options[5] == 2)
+                               break;
+                       case 2:
                                s->range_table = &range_unknown;
+                               break;
+                       default:
+                               s->range_table = &range_unipolar5;
+                               break;
+                       }
+                       break;
+               default:
+                       s->range_table = &range_unipolar5;
                        break;
                }
                s->insn_write   = pcl812_ao_insn_write;
@@ -1268,23 +1286,23 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        }
 
        switch (board->board_type) {
-       case boardACL8216:
-       case boardPCL812PG:
-       case boardPCL812:
-       case boardACL8112:
+       case BOARD_ACL8216:
+       case BOARD_PCL812PG:
+       case BOARD_PCL812:
+       case BOARD_ACL8112:
                devpriv->max_812_ai_mode0_rangewait = 1;
                if (it->options[3] > 0)
                                                /*  we use external trigger */
                        devpriv->use_ext_trg = 1;
                break;
-       case boardA821:
+       case BOARD_A821:
                devpriv->max_812_ai_mode0_rangewait = 1;
                devpriv->mode_reg_int = (dev->irq << 4) & 0xf0;
                break;
-       case boardPCL813B:
-       case boardPCL813:
-       case boardISO813:
-       case boardACL8113:
+       case BOARD_PCL813B:
+       case BOARD_PCL813:
+       case BOARD_ISO813:
+       case BOARD_ACL8113:
                /* maybe there must by greatest timeout */
                devpriv->max_812_ai_mode0_rangewait = 5;
                break;
index a353d1b155bbd270dec44f6d1dba60384a6c3afd..c00a71f538efc14364ddb757c67f816580f4a694 100644 (file)
@@ -1,36 +1,33 @@
 /*
-   comedi/drivers/pcl816.c
-
-   Author:  Juan Grigera <juan@grigera.com.ar>
-           based on pcl818 by Michal Dobes <dobes@tesnet.cz> and bits of pcl812
+ * pcl816.c
+ * Comedi driver for Advantech PCL-816 cards
+ *
+ * Author:  Juan Grigera <juan@grigera.com.ar>
+ * based on pcl818 by Michal Dobes <dobes@tesnet.cz> and bits of pcl812
+ */
 
-   hardware driver for Advantech cards:
-    card:   PCL-816, PCL814B
-    driver: pcl816
-*/
 /*
-Driver: pcl816
-Description: Advantech PCL-816 cards, PCL-814
-Author: Juan Grigera <juan@grigera.com.ar>
-Devices: [Advantech] PCL-816 (pcl816), PCL-814B (pcl814b)
-Status: works
-Updated: Tue,  2 Apr 2002 23:15:21 -0800
-
-PCL 816 and 814B have 16 SE/DIFF ADCs, 16 DACs, 16 DI and 16 DO.
-Differences are at resolution (16 vs 12 bits).
-
-The driver support AI command mode, other subdevices not written.
-
-Analog output and digital input and output are not supported.
-
-Configuration Options:
-  [0] - IO Base
-  [1] - IRQ    (0=disable, 2, 3, 4, 5, 6, 7)
-  [2] - DMA    (0=disable, 1, 3)
-  [3] - 0, 10=10MHz clock for 8254
-           1= 1MHz clock for 8254
-
-*/
+ * Driver: pcl816
+ * Description: Advantech PCL-816 cards, PCL-814
+ * Devices: [Advantech] PCL-816 (pcl816), PCL-814B (pcl814b)
+ * Author: Juan Grigera <juan@grigera.com.ar>
+ * Status: works
+ * Updated: Tue,  2 Apr 2002 23:15:21 -0800
+ *
+ * PCL 816 and 814B have 16 SE/DIFF ADCs, 16 DACs, 16 DI and 16 DO.
+ * Differences are at resolution (16 vs 12 bits).
+ *
+ * The driver support AI command mode, other subdevices not written.
+ *
+ * Analog output and digital input and output are not supported.
+ *
+ * Configuration Options:
+ *   [0] - IO Base
+ *   [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7)
+ *   [2] - DMA (0=disable, 1, 3)
+ *   [3] - 0, 10=10MHz clock for 8254
+ *            1= 1MHz clock for 8254
+ */
 
 #include <linux/module.h>
 #include <linux/gfp.h>
@@ -56,25 +53,20 @@ Configuration Options:
 #define PCL816_MUX_REG                         0x0b
 #define PCL816_MUX_SCAN(_first, _last)         (((_last) << 4) | (_first))
 #define PCL816_CTRL_REG                                0x0c
-#define PCL816_CTRL_DISABLE_TRIG               (0 << 0)
-#define PCL816_CTRL_SOFT_TRIG                  (1 << 0)
-#define PCL816_CTRL_PACER_TRIG                 (1 << 1)
-#define PCL816_CTRL_EXT_TRIG                   (1 << 2)
-#define PCL816_CTRL_POE                                (1 << 3)
-#define PCL816_CTRL_DMAEN                      (1 << 4)
-#define PCL816_CTRL_INTEN                      (1 << 5)
-#define PCL816_CTRL_DMASRC_SLOT0               (0 << 6)
-#define PCL816_CTRL_DMASRC_SLOT1               (1 << 6)
-#define PCL816_CTRL_DMASRC_SLOT2               (2 << 6)
+#define PCL816_CTRL_SOFT_TRIG                  BIT(0)
+#define PCL816_CTRL_PACER_TRIG                 BIT(1)
+#define PCL816_CTRL_EXT_TRIG                   BIT(2)
+#define PCL816_CTRL_POE                                BIT(3)
+#define PCL816_CTRL_DMAEN                      BIT(4)
+#define PCL816_CTRL_INTEN                      BIT(5)
+#define PCL816_CTRL_DMASRC_SLOT(x)             (((x) & 0x3) << 6)
 #define PCL816_STATUS_REG                      0x0d
 #define PCL816_STATUS_NEXT_CHAN_MASK           (0xf << 0)
-#define PCL816_STATUS_INTSRC_MASK              (3 << 4)
-#define PCL816_STATUS_INTSRC_SLOT0             (0 << 4)
-#define PCL816_STATUS_INTSRC_SLOT1             (1 << 4)
-#define PCL816_STATUS_INTSRC_SLOT2             (2 << 4)
-#define PCL816_STATUS_INTSRC_DMA               (3 << 4)
-#define PCL816_STATUS_INTACT                   (1 << 6)
-#define PCL816_STATUS_DRDY                     (1 << 7)
+#define PCL816_STATUS_INTSRC_SLOT(x)           (((x) & 0x3) << 4)
+#define PCL816_STATUS_INTSRC_DMA               PCL816_STATUS_INTSRC_SLOT(3)
+#define PCL816_STATUS_INTSRC_MASK              PCL816_STATUS_INTSRC_SLOT(3)
+#define PCL816_STATUS_INTACT                   BIT(6)
+#define PCL816_STATUS_DRDY                     BIT(7)
 
 #define MAGIC_DMA_WORD 0x5a5a
 
@@ -94,7 +86,6 @@ static const struct comedi_lrange range_pcl816 = {
 struct pcl816_board {
        const char *name;
        int ai_maxdata;
-       int ao_maxdata;
        int ai_chanlist;
 };
 
@@ -102,12 +93,10 @@ static const struct pcl816_board boardtypes[] = {
        {
                .name           = "pcl816",
                .ai_maxdata     = 0xffff,
-               .ao_maxdata     = 0xffff,
                .ai_chanlist    = 1024,
        }, {
                .name           = "pcl814b",
                .ai_maxdata     = 0x3fff,
-               .ao_maxdata     = 0x3fff,
                .ai_chanlist    = 1024,
        },
 };
@@ -443,7 +432,8 @@ static int pcl816_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        comedi_8254_update_divisors(dev->pacer);
        comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
 
-       ctrl = PCL816_CTRL_INTEN | PCL816_CTRL_DMAEN | PCL816_CTRL_DMASRC_SLOT0;
+       ctrl = PCL816_CTRL_INTEN | PCL816_CTRL_DMAEN |
+              PCL816_CTRL_DMASRC_SLOT(0);
        if (cmd->convert_src == TRIG_TIMER)
                ctrl |= PCL816_CTRL_PACER_TRIG;
        else    /* TRIG_EXT */
@@ -497,7 +487,7 @@ static int pcl816_ai_cancel(struct comedi_device *dev,
        if (!devpriv->ai_cmd_running)
                return 0;
 
-       outb(PCL816_CTRL_DISABLE_TRIG, dev->iobase + PCL816_CTRL_REG);
+       outb(0, dev->iobase + PCL816_CTRL_REG);
        pcl816_ai_clear_eoc(dev);
 
        comedi_8254_pacer_enable(dev->pacer, 1, 2, false);
@@ -533,7 +523,7 @@ static int pcl816_ai_insn_read(struct comedi_device *dev,
 
                data[i] = pcl816_ai_get_sample(dev, s);
        }
-       outb(PCL816_CTRL_DISABLE_TRIG, dev->iobase + PCL816_CTRL_REG);
+       outb(0, dev->iobase + PCL816_CTRL_REG);
        pcl816_ai_clear_eoc(dev);
 
        return ret ? ret : insn->n;
@@ -567,7 +557,7 @@ static int pcl816_do_insn_bits(struct comedi_device *dev,
 
 static void pcl816_reset(struct comedi_device *dev)
 {
-       outb(PCL816_CTRL_DISABLE_TRIG, dev->iobase + PCL816_CTRL_REG);
+       outb(0, dev->iobase + PCL816_CTRL_REG);
        pcl816_ai_set_chan_range(dev, 0, 0);
        pcl816_ai_clear_eoc(dev);
 
@@ -652,16 +642,9 @@ static int pcl816_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                s->cancel       = pcl816_ai_cancel;
        }
 
-       /* Analog OUtput subdevice */
-       s = &dev->subdevices[2];
+       /* Piggyback Slot1 subdevice */
+       s = &dev->subdevices[1];
        s->type         = COMEDI_SUBD_UNUSED;
-#if 0
-       subdevs[1] = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
-       s->n_chan = 1;
-       s->maxdata = board->ao_maxdata;
-       s->range_table = &range_pcl816;
-#endif
 
        /* Digital Input subdevice */
        s = &dev->subdevices[2];
index e1bdde9773023466ab6624fefa190baf302e1b1f..5aeed44dff706787eb75024afd142f1a77e43da6 100644 (file)
 #include "comedi_isadma.h"
 #include "comedi_8254.h"
 
-/* boards constants */
-
-#define boardPCL818L 0
-#define boardPCL818H 1
-#define boardPCL818HD 2
-#define boardPCL818HG 3
-#define boardPCL818 4
-#define boardPCL718 5
-
 /*
  * Register I/O map
  */
 #define PCL818_AO_MSB_REG(x)                   (0x05 + ((x) * 2))
 #define PCL818_STATUS_REG                      0x08
 #define PCL818_STATUS_NEXT_CHAN_MASK           (0xf << 0)
-#define PCL818_STATUS_INT                      (1 << 4)
-#define PCL818_STATUS_MUX                      (1 << 5)
-#define PCL818_STATUS_UNI                      (1 << 6)
-#define PCL818_STATUS_EOC                      (1 << 7)
+#define PCL818_STATUS_INT                      BIT(4)
+#define PCL818_STATUS_MUX                      BIT(5)
+#define PCL818_STATUS_UNI                      BIT(6)
+#define PCL818_STATUS_EOC                      BIT(7)
 #define PCL818_CTRL_REG                                0x09
-#define PCL818_CTRL_DISABLE_TRIG               (0 << 0)
-#define PCL818_CTRL_SOFT_TRIG                  (1 << 0)
-#define PCL818_CTRL_EXT_TRIG                   (2 << 0)
-#define PCL818_CTRL_PACER_TRIG                 (3 << 0)
-#define PCL818_CTRL_DMAE                       (1 << 2)
+#define PCL818_CTRL_TRIG(x)                    (((x) & 0x3) << 0)
+#define PCL818_CTRL_DISABLE_TRIG               PCL818_CTRL_TRIG(0)
+#define PCL818_CTRL_SOFT_TRIG                  PCL818_CTRL_TRIG(1)
+#define PCL818_CTRL_EXT_TRIG                   PCL818_CTRL_TRIG(2)
+#define PCL818_CTRL_PACER_TRIG                 PCL818_CTRL_TRIG(3)
+#define PCL818_CTRL_DMAE                       BIT(2)
 #define PCL818_CTRL_IRQ(x)                     ((x) << 4)
-#define PCL818_CTRL_INTE                       (1 << 7)
+#define PCL818_CTRL_INTE                       BIT(7)
 #define PCL818_CNTENABLE_REG                   0x0a
-#define PCL818_CNTENABLE_PACER_ENA             (0 << 0)
-#define PCL818_CNTENABLE_PACER_TRIG0           (1 << 0)
-#define PCL818_CNTENABLE_CNT0_EXT_CLK          (0 << 1)
-#define PCL818_CNTENABLE_CNT0_INT_CLK          (1 << 1)
+#define PCL818_CNTENABLE_PACER_TRIG0           BIT(0)
+#define PCL818_CNTENABLE_CNT0_INT_CLK          BIT(1)  /* 0=ext clk */
 #define PCL818_DO_DI_MSB_REG                   0x0b
 #define PCL818_TIMER_BASE                      0x0c
 
@@ -740,7 +730,7 @@ static int pcl818_ai_cmd(struct comedi_device *dev,
        else
                ctrl |= PCL818_CTRL_EXT_TRIG;
 
-       outb(PCL818_CNTENABLE_PACER_ENA, dev->iobase + PCL818_CNTENABLE_REG);
+       outb(0, dev->iobase + PCL818_CNTENABLE_REG);
 
        if (dma) {
                /* setup and enable dma for the first buffer */
@@ -902,7 +892,7 @@ static void pcl818_reset(struct comedi_device *dev)
        pcl818_ai_set_chan_range(dev, 0, 0);
 
        /* stop pacer */
-       outb(PCL818_CNTENABLE_PACER_ENA, dev->iobase + PCL818_CNTENABLE_REG);
+       outb(0, dev->iobase + PCL818_CNTENABLE_REG);
 
        /* set analog output channels to 0V */
        for (chan = 0; chan < board->n_aochan; chan++) {
index 6176dfa24801463e10d015e76119b352e43dc9b9..588ae5ecec66e08067aa4bb4fe7308ccd68a6feb 100644 (file)
@@ -1,31 +1,25 @@
 /*
-    comedi/drivers/pcm724.c
-
-    Drew Csillag <drew_csillag@yahoo.com>
-
-    hardware driver for Advantech card:
-     card:   PCM-3724
-     driver: pcm3724
+ * pcm3724.c
+ * Comedi driver for Advantech PCM-3724 Digital I/O board
+ *
+ * Drew Csillag <drew_csillag@yahoo.com>
+ */
 
-    Options for PCM-3724
-     [0] - IO Base
-*/
-/*
-Driver: pcm3724
-Description: Advantech PCM-3724
-Author: Drew Csillag <drew_csillag@yahoo.com>
-Devices: [Advantech] PCM-3724 (pcm724)
-Status: tested
-
-This is driver for digital I/O boards PCM-3724 with 48 DIO.
-It needs 8255.o for operations and only immediate mode is supported.
-See the source for configuration details.
-
-Copy/pasted/hacked from pcm724.c
-*/
 /*
- * check_driver overrides:
- *   struct comedi_insn
+ * Driver: pcm3724
+ * Description: Advantech PCM-3724
+ * Devices: [Advantech] PCM-3724 (pcm3724)
+ * Author: Drew Csillag <drew_csillag@yahoo.com>
+ * Status: tested
+ *
+ * This is driver for digital I/O boards PCM-3724 with 48 DIO.
+ * It needs 8255.o for operations and only immediate mode is supported.
+ * See the source for configuration details.
+ *
+ * Copy/pasted/hacked from pcm724.c
+ *
+ * Configuration Options:
+ *   [0] - I/O port base address
  */
 
 #include <linux/module.h>
@@ -33,19 +27,31 @@ Copy/pasted/hacked from pcm724.c
 
 #include "8255.h"
 
-#define BUF_C0 0x1
-#define BUF_B0 0x2
-#define BUF_A0 0x4
-#define BUF_C1 0x8
-#define BUF_B1 0x10
-#define BUF_A1 0x20
-
-#define GATE_A0 0x4
-#define GATE_B0        0x2
-#define GATE_C0        0x1
-#define GATE_A1        0x20
-#define GATE_B1        0x10
-#define GATE_C1 0x8
+/*
+ * Register I/O Map
+ *
+ * This board has two standard 8255 devices that provide six 8-bit DIO ports
+ * (48 channels total). Six 74HCT245 chips (one for each port) buffer the
+ * I/O lines to increase driving capability. Because the 74HCT245 is a
+ * bidirectional, tri-state line buffer, two additional I/O ports are used
+ * to control the direction of data and the enable of each port.
+ */
+#define PCM3724_8255_0_BASE            0x00
+#define PCM3724_8255_1_BASE            0x04
+#define PCM3724_DIO_DIR_REG            0x08
+#define PCM3724_DIO_DIR_C0_OUT         BIT(0)
+#define PCM3724_DIO_DIR_B0_OUT         BIT(1)
+#define PCM3724_DIO_DIR_A0_OUT         BIT(2)
+#define PCM3724_DIO_DIR_C1_OUT         BIT(3)
+#define PCM3724_DIO_DIR_B1_OUT         BIT(4)
+#define PCM3724_DIO_DIR_A1_OUT         BIT(5)
+#define PCM3724_GATE_CTRL_REG          0x09
+#define PCM3724_GATE_CTRL_C0_ENA       BIT(0)
+#define PCM3724_GATE_CTRL_B0_ENA       BIT(1)
+#define PCM3724_GATE_CTRL_A0_ENA       BIT(2)
+#define PCM3724_GATE_CTRL_C1_ENA       BIT(3)
+#define PCM3724_GATE_CTRL_B1_ENA       BIT(4)
+#define PCM3724_GATE_CTRL_A1_ENA       BIT(5)
 
 /* used to track configured dios */
 struct priv_pcm3724 {
@@ -58,21 +64,21 @@ static int compute_buffer(int config, int devno, struct comedi_subdevice *s)
        /* 1 in io_bits indicates output */
        if (s->io_bits & 0x0000ff) {
                if (devno == 0)
-                       config |= BUF_A0;
+                       config |= PCM3724_DIO_DIR_A0_OUT;
                else
-                       config |= BUF_A1;
+                       config |= PCM3724_DIO_DIR_A1_OUT;
        }
        if (s->io_bits & 0x00ff00) {
                if (devno == 0)
-                       config |= BUF_B0;
+                       config |= PCM3724_DIO_DIR_B0_OUT;
                else
-                       config |= BUF_B1;
+                       config |= PCM3724_DIO_DIR_B1_OUT;
        }
        if (s->io_bits & 0xff0000) {
                if (devno == 0)
-                       config |= BUF_C0;
+                       config |= PCM3724_DIO_DIR_C0_OUT;
                else
-                       config |= BUF_C1;
+                       config |= PCM3724_DIO_DIR_C1_OUT;
        }
        return config;
 }
@@ -107,7 +113,7 @@ static void do_3724_config(struct comedi_device *dev,
        else
                port_8255_cfg = dev->iobase + I8255_SIZE + I8255_CTRL_REG;
 
-       outb(buffer_config, dev->iobase + 8);   /* update buffer register */
+       outb(buffer_config, dev->iobase + PCM3724_DIO_DIR_REG);
 
        outb(config, port_8255_cfg);
 }
@@ -129,24 +135,24 @@ static void enable_chan(struct comedi_device *dev, struct comedi_subdevice *s,
                priv->dio_2 |= mask;
 
        if (priv->dio_1 & 0xff0000)
-               gatecfg |= GATE_C0;
+               gatecfg |= PCM3724_GATE_CTRL_C0_ENA;
 
        if (priv->dio_1 & 0xff00)
-               gatecfg |= GATE_B0;
+               gatecfg |= PCM3724_GATE_CTRL_B0_ENA;
 
        if (priv->dio_1 & 0xff)
-               gatecfg |= GATE_A0;
+               gatecfg |= PCM3724_GATE_CTRL_A0_ENA;
 
        if (priv->dio_2 & 0xff0000)
-               gatecfg |= GATE_C1;
+               gatecfg |= PCM3724_GATE_CTRL_C1_ENA;
 
        if (priv->dio_2 & 0xff00)
-               gatecfg |= GATE_B1;
+               gatecfg |= PCM3724_GATE_CTRL_B1_ENA;
 
        if (priv->dio_2 & 0xff)
-               gatecfg |= GATE_A1;
+               gatecfg |= PCM3724_GATE_CTRL_A1_ENA;
 
-       outb(gatecfg, dev->iobase + 9);
+       outb(gatecfg, dev->iobase + PCM3724_GATE_CTRL_REG);
 }
 
 /* overriding the 8255 insn config */
@@ -216,5 +222,5 @@ static struct comedi_driver pcm3724_driver = {
 module_comedi_driver(pcm3724_driver);
 
 MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
+MODULE_DESCRIPTION("Comedi driver for Advantech PCM-3724 Digital I/O board");
 MODULE_LICENSE("GPL");
index 152cb146fc161fa62cfdd9b194bf9d0cc7edb08a..e9e43139157d93b33d2db89f90adc208972bf177 100644 (file)
-/*======================================================================
-
-    comedi/drivers/quatech_daqp_cs.c
-
-    Quatech DAQP PCMCIA data capture cards COMEDI client driver
-    Copyright (C) 2000, 2003 Brent Baccala <baccala@freesoft.org>
-    The DAQP interface code in this file is released into the public domain.
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 1998 David A. Schleef <ds@schleef.org>
-    http://www.comedi.org/
-
-    quatech_daqp_cs.c 1.10
-
-    Documentation for the DAQP PCMCIA cards can be found on Quatech's site:
-
-               ftp://ftp.quatech.com/Manuals/daqp-208.pdf
-
-    This manual is for both the DAQP-208 and the DAQP-308.
-
-    What works:
-
-       - A/D conversion
-           - 8 channels
-           - 4 gain ranges
-           - ground ref or differential
-           - single-shot and timed both supported
-       - D/A conversion, single-shot
-       - digital I/O
-
-    What doesn't:
-
-       - any kind of triggering - external or D/A channel 1
-       - the card's optional expansion board
-       - the card's timer (for anything other than A/D conversion)
-       - D/A update modes other than immediate (i.e, timed)
-       - fancier timing modes
-       - setting card's FIFO buffer thresholds to anything but default
-
-======================================================================*/
+/*
+ * quatech_daqp_cs.c
+ * Quatech DAQP PCMCIA data capture cards COMEDI client driver
+ * Copyright (C) 2000, 2003 Brent Baccala <baccala@freesoft.org>
+ * The DAQP interface code in this file is released into the public domain.
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
+ * http://www.comedi.org/
+ *
+ * Documentation for the DAQP PCMCIA cards can be found on Quatech's site:
+ *     ftp://ftp.quatech.com/Manuals/daqp-208.pdf
+ *
+ * This manual is for both the DAQP-208 and the DAQP-308.
+ *
+ * What works:
+ * - A/D conversion
+ *     - 8 channels
+ *     - 4 gain ranges
+ *     - ground ref or differential
+ *     - single-shot and timed both supported
+ * - D/A conversion, single-shot
+ * - digital I/O
+ *
+ * What doesn't:
+ * - any kind of triggering - external or D/A channel 1
+ * - the card's optional expansion board
+ * - the card's timer (for anything other than A/D conversion)
+ * - D/A update modes other than immediate (i.e, timed)
+ * - fancier timing modes
+ * - setting card's FIFO buffer thresholds to anything but default
+ */
 
 /*
-Driver: quatech_daqp_cs
-Description: Quatech DAQP PCMCIA data capture cards
-Author: Brent Baccala <baccala@freesoft.org>
-Status: works
-Devices: [Quatech] DAQP-208 (daqp), DAQP-308
-*/
+ * Driver: quatech_daqp_cs
+ * Description: Quatech DAQP PCMCIA data capture cards
+ * Devices: [Quatech] DAQP-208 (daqp), DAQP-308
+ * Author: Brent Baccala <baccala@freesoft.org>
+ * Status: works
+ */
 
 #include <linux/module.h>
-#include <linux/semaphore.h>
-#include <linux/completion.h>
 
 #include "../comedi_pcmcia.h"
 
+/*
+ * Register I/O map
+ *
+ * The D/A and timer registers can be accessed with 16-bit or 8-bit I/O
+ * instructions. All other registers can only use 8-bit instructions.
+ *
+ * The FIFO and scanlist registers require two 8-bit instructions to
+ * access the 16-bit data. Data is transferred LSB then MSB.
+ */
+#define DAQP_AI_FIFO_REG               0x00
+
+#define DAQP_SCANLIST_REG              0x01
+#define DAQP_SCANLIST_DIFFERENTIAL     BIT(14)
+#define DAQP_SCANLIST_GAIN(x)          (((x) & 0x3) << 12)
+#define DAQP_SCANLIST_CHANNEL(x)       (((x) & 0xf) << 8)
+#define DAQP_SCANLIST_START            BIT(7)
+#define DAQP_SCANLIST_EXT_GAIN(x)      (((x) & 0x3) << 4)
+#define DAQP_SCANLIST_EXT_CHANNEL(x)   (((x) & 0xf) << 0)
+
+#define DAQP_CTRL_REG                  0x02
+#define DAQP_CTRL_PACER_CLK(x)         (((x) & 0x3) << 6)
+#define DAQP_CTRL_PACER_CLK_EXT                DAQP_CTRL_PACER_CLK(0)
+#define DAQP_CTRL_PACER_CLK_5MHZ       DAQP_CTRL_PACER_CLK(1)
+#define DAQP_CTRL_PACER_CLK_1MHZ       DAQP_CTRL_PACER_CLK(2)
+#define DAQP_CTRL_PACER_CLK_100KHZ     DAQP_CTRL_PACER_CLK(3)
+#define DAQP_CTRL_EXPANSION            BIT(5)
+#define DAQP_CTRL_EOS_INT_ENA          BIT(4)
+#define DAQP_CTRL_FIFO_INT_ENA         BIT(3)
+#define DAQP_CTRL_TRIG_MODE            BIT(2)  /* 0=one-shot; 1=continuous */
+#define DAQP_CTRL_TRIG_SRC             BIT(1)  /* 0=internal; 1=external */
+#define DAQP_CTRL_TRIG_EDGE            BIT(0)  /* 0=rising; 1=falling */
+
+#define DAQP_STATUS_REG                        0x02
+#define DAQP_STATUS_IDLE               BIT(7)
+#define DAQP_STATUS_RUNNING            BIT(6)
+#define DAQP_STATUS_DATA_LOST          BIT(5)
+#define DAQP_STATUS_END_OF_SCAN                BIT(4)
+#define DAQP_STATUS_FIFO_THRESHOLD     BIT(3)
+#define DAQP_STATUS_FIFO_FULL          BIT(2)
+#define DAQP_STATUS_FIFO_NEARFULL      BIT(1)
+#define DAQP_STATUS_FIFO_EMPTY         BIT(0)
+/* these bits clear when the status register is read */
+#define DAQP_STATUS_EVENTS             (DAQP_STATUS_DATA_LOST |        \
+                                        DAQP_STATUS_END_OF_SCAN |      \
+                                        DAQP_STATUS_FIFO_THRESHOLD)
+
+#define DAQP_DI_REG                    0x03
+#define DAQP_DO_REG                    0x03
+
+#define DAQP_PACER_LOW_REG             0x04
+#define DAQP_PACER_MID_REG             0x05
+#define DAQP_PACER_HIGH_REG            0x06
+
+#define DAQP_CMD_REG                   0x07
+/* the monostable bits are self-clearing after the function is complete */
+#define DAQP_CMD_ARM                   BIT(7)  /* monostable */
+#define DAQP_CMD_RSTF                  BIT(6)  /* monostable */
+#define DAQP_CMD_RSTQ                  BIT(5)  /* monostable */
+#define DAQP_CMD_STOP                  BIT(4)  /* monostable */
+#define DAQP_CMD_LATCH                 BIT(3)  /* monostable */
+#define DAQP_CMD_SCANRATE(x)           (((x) & 0x3) << 1)
+#define DAQP_CMD_SCANRATE_100KHZ       DAQP_CMD_SCANRATE(0)
+#define DAQP_CMD_SCANRATE_50KHZ                DAQP_CMD_SCANRATE(1)
+#define DAQP_CMD_SCANRATE_25KHZ                DAQP_CMD_SCANRATE(2)
+#define DAQP_CMD_FIFO_DATA             BIT(0)
+
+#define DAQP_AO_REG                    0x08    /* and 0x09 (16-bit) */
+
+#define DAQP_TIMER_REG                 0x0a    /* and 0x0b (16-bit) */
+
+#define DAQP_AUX_REG                   0x0f
+/* Auxiliary Control register bits (write) */
+#define DAQP_AUX_EXT_ANALOG_TRIG       BIT(7)
+#define DAQP_AUX_PRETRIG               BIT(6)
+#define DAQP_AUX_TIMER_INT_ENA         BIT(5)
+#define DAQP_AUX_TIMER_MODE(x)         (((x) & 0x3) << 3)
+#define DAQP_AUX_TIMER_MODE_RELOAD     DAQP_AUX_TIMER_MODE(0)
+#define DAQP_AUX_TIMER_MODE_PAUSE      DAQP_AUX_TIMER_MODE(1)
+#define DAQP_AUX_TIMER_MODE_GO         DAQP_AUX_TIMER_MODE(2)
+#define DAQP_AUX_TIMER_MODE_EXT                DAQP_AUX_TIMER_MODE(3)
+#define DAQP_AUX_TIMER_CLK_SRC_EXT     BIT(2)
+#define DAQP_AUX_DA_UPDATE(x)          (((x) & 0x3) << 0)
+#define DAQP_AUX_DA_UPDATE_DIRECT      DAQP_AUX_DA_UPDATE(0)
+#define DAQP_AUX_DA_UPDATE_OVERFLOW    DAQP_AUX_DA_UPDATE(1)
+#define DAQP_AUX_DA_UPDATE_EXTERNAL    DAQP_AUX_DA_UPDATE(2)
+#define DAQP_AUX_DA_UPDATE_PACER       DAQP_AUX_DA_UPDATE(3)
+/* Auxiliary Status register bits (read) */
+#define DAQP_AUX_RUNNING               BIT(7)
+#define DAQP_AUX_TRIGGERED             BIT(6)
+#define DAQP_AUX_DA_BUFFER             BIT(5)
+#define DAQP_AUX_TIMER_OVERFLOW                BIT(4)
+#define DAQP_AUX_CONVERSION            BIT(3)
+#define DAQP_AUX_DATA_LOST             BIT(2)
+#define DAQP_AUX_FIFO_NEARFULL         BIT(1)
+#define DAQP_AUX_FIFO_EMPTY            BIT(0)
+
+#define DAQP_FIFO_SIZE                 4096
+
+#define DAQP_MAX_TIMER_SPEED           10000   /* 100 kHz in nanoseconds */
+
 struct daqp_private {
+       unsigned int pacer_div;
        int stop;
-
-       enum { semaphore, buffer } interrupt_mode;
-
-       struct completion eos;
 };
 
-/* The DAQP communicates with the system through a 16 byte I/O window. */
-
-#define DAQP_FIFO_SIZE         4096
-
-#define DAQP_FIFO              0
-#define DAQP_SCANLIST          1
-#define DAQP_CONTROL           2
-#define DAQP_STATUS            2
-#define DAQP_DIGITAL_IO                3
-#define DAQP_PACER_LOW         4
-#define DAQP_PACER_MID         5
-#define DAQP_PACER_HIGH                6
-#define DAQP_COMMAND           7
-#define DAQP_DA                        8
-#define DAQP_TIMER             10
-#define DAQP_AUX               15
-
-#define DAQP_SCANLIST_DIFFERENTIAL     0x4000
-#define DAQP_SCANLIST_GAIN(x)          ((x)<<12)
-#define DAQP_SCANLIST_CHANNEL(x)       ((x)<<8)
-#define DAQP_SCANLIST_START            0x0080
-#define DAQP_SCANLIST_EXT_GAIN(x)      ((x)<<4)
-#define DAQP_SCANLIST_EXT_CHANNEL(x)   (x)
-
-#define DAQP_CONTROL_PACER_100kHz      0xc0
-#define DAQP_CONTROL_PACER_1MHz                0x80
-#define DAQP_CONTROL_PACER_5MHz                0x40
-#define DAQP_CONTROL_PACER_EXTERNAL    0x00
-#define DAQP_CONTORL_EXPANSION         0x20
-#define DAQP_CONTROL_EOS_INT_ENABLE    0x10
-#define DAQP_CONTROL_FIFO_INT_ENABLE   0x08
-#define DAQP_CONTROL_TRIGGER_ONESHOT   0x00
-#define DAQP_CONTROL_TRIGGER_CONTINUOUS        0x04
-#define DAQP_CONTROL_TRIGGER_INTERNAL  0x00
-#define DAQP_CONTROL_TRIGGER_EXTERNAL  0x02
-#define DAQP_CONTROL_TRIGGER_RISING    0x00
-#define DAQP_CONTROL_TRIGGER_FALLING   0x01
-
-#define DAQP_STATUS_IDLE               0x80
-#define DAQP_STATUS_RUNNING            0x40
-#define DAQP_STATUS_EVENTS             0x38
-#define DAQP_STATUS_DATA_LOST          0x20
-#define DAQP_STATUS_END_OF_SCAN                0x10
-#define DAQP_STATUS_FIFO_THRESHOLD     0x08
-#define DAQP_STATUS_FIFO_FULL          0x04
-#define DAQP_STATUS_FIFO_NEARFULL      0x02
-#define DAQP_STATUS_FIFO_EMPTY         0x01
-
-#define DAQP_COMMAND_ARM               0x80
-#define DAQP_COMMAND_RSTF              0x40
-#define DAQP_COMMAND_RSTQ              0x20
-#define DAQP_COMMAND_STOP              0x10
-#define DAQP_COMMAND_LATCH             0x08
-#define DAQP_COMMAND_100kHz            0x00
-#define DAQP_COMMAND_50kHz             0x02
-#define DAQP_COMMAND_25kHz             0x04
-#define DAQP_COMMAND_FIFO_DATA         0x01
-#define DAQP_COMMAND_FIFO_PROGRAM      0x00
-
-#define DAQP_AUX_TRIGGER_TTL           0x00
-#define DAQP_AUX_TRIGGER_ANALOG                0x80
-#define DAQP_AUX_TRIGGER_PRETRIGGER    0x40
-#define DAQP_AUX_TIMER_INT_ENABLE      0x20
-#define DAQP_AUX_TIMER_RELOAD          0x00
-#define DAQP_AUX_TIMER_PAUSE           0x08
-#define DAQP_AUX_TIMER_GO              0x10
-#define DAQP_AUX_TIMER_GO_EXTERNAL     0x18
-#define DAQP_AUX_TIMER_EXTERNAL_SRC    0x04
-#define DAQP_AUX_TIMER_INTERNAL_SRC    0x00
-#define DAQP_AUX_DA_DIRECT             0x00
-#define DAQP_AUX_DA_OVERFLOW           0x01
-#define DAQP_AUX_DA_EXTERNAL           0x02
-#define DAQP_AUX_DA_PACER              0x03
-
-#define DAQP_AUX_RUNNING               0x80
-#define DAQP_AUX_TRIGGERED             0x40
-#define DAQP_AUX_DA_BUFFER             0x20
-#define DAQP_AUX_TIMER_OVERFLOW                0x10
-#define DAQP_AUX_CONVERSION            0x08
-#define DAQP_AUX_DATA_LOST             0x04
-#define DAQP_AUX_FIFO_NEARFULL         0x02
-#define DAQP_AUX_FIFO_EMPTY            0x01
-
 static const struct comedi_lrange range_daqp_ai = {
        4, {
                BIP_RANGE(10),
@@ -153,38 +157,59 @@ static const struct comedi_lrange range_daqp_ai = {
        }
 };
 
-/* Cancel a running acquisition */
+static int daqp_clear_events(struct comedi_device *dev, int loops)
+{
+       unsigned int status;
 
-static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
+       /*
+        * Reset any pending interrupts (my card has a tendency to require
+        * require multiple reads on the status register to achieve this).
+        */
+       while (--loops) {
+               status = inb(dev->iobase + DAQP_STATUS_REG);
+               if ((status & DAQP_STATUS_EVENTS) == 0)
+                       return 0;
+       }
+       dev_err(dev->class_dev, "couldn't clear events in status register\n");
+       return -EBUSY;
+}
+
+static int daqp_ai_cancel(struct comedi_device *dev,
+                         struct comedi_subdevice *s)
 {
        struct daqp_private *devpriv = dev->private;
 
        if (devpriv->stop)
                return -EIO;
 
-       outb(DAQP_COMMAND_STOP, dev->iobase + DAQP_COMMAND);
+       /*
+        * Stop any conversions, disable interrupts, and clear
+        * the status event flags.
+        */
+       outb(DAQP_CMD_STOP, dev->iobase + DAQP_CMD_REG);
+       outb(0, dev->iobase + DAQP_CTRL_REG);
+       inb(dev->iobase + DAQP_STATUS_REG);
 
-       /* flush any linguring data in FIFO - superfluous here */
-       /* outb(DAQP_COMMAND_RSTF, dev->iobase+DAQP_COMMAND); */
+       return 0;
+}
 
-       devpriv->interrupt_mode = semaphore;
+static unsigned int daqp_ai_get_sample(struct comedi_device *dev,
+                                      struct comedi_subdevice *s)
+{
+       unsigned int val;
 
-       return 0;
+       /*
+        * Get a two's complement sample from the FIFO and
+        * return the munged offset binary value.
+        */
+       val = inb(dev->iobase + DAQP_AI_FIFO_REG);
+       val |= inb(dev->iobase + DAQP_AI_FIFO_REG) << 8;
+       return comedi_offset_munge(s, val);
 }
 
-/* Interrupt handler
- *
- * Operates in one of two modes.  If devpriv->interrupt_mode is
- * 'semaphore', just signal the devpriv->eos completion and return
- * (one-shot mode).  Otherwise (continuous mode), read data in from
- * the card, transfer it to the buffer provided by the higher-level
- * comedi kernel module, and signal various comedi callback routines,
- * which run pretty quick.
- */
-static enum irqreturn daqp_interrupt(int irq, void *dev_id)
+static irqreturn_t daqp_interrupt(int irq, void *dev_id)
 {
        struct comedi_device *dev = dev_id;
-       struct daqp_private *devpriv = dev->private;
        struct comedi_subdevice *s = dev->read_subdev;
        struct comedi_cmd *cmd = &s->async->cmd;
        int loop_limit = 10000;
@@ -193,50 +218,42 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
        if (!dev->attached)
                return IRQ_NONE;
 
-       switch (devpriv->interrupt_mode) {
-       case semaphore:
-               complete(&devpriv->eos);
-               break;
+       status = inb(dev->iobase + DAQP_STATUS_REG);
+       if (!(status & DAQP_STATUS_EVENTS))
+               return IRQ_NONE;
 
-       case buffer:
-               while (!((status = inb(dev->iobase + DAQP_STATUS))
-                        & DAQP_STATUS_FIFO_EMPTY)) {
-                       unsigned short data;
+       while (!(status & DAQP_STATUS_FIFO_EMPTY)) {
+               unsigned short data;
 
-                       if (status & DAQP_STATUS_DATA_LOST) {
-                               s->async->events |= COMEDI_CB_OVERFLOW;
-                               dev_warn(dev->class_dev, "data lost\n");
-                               break;
-                       }
+               if (status & DAQP_STATUS_DATA_LOST) {
+                       s->async->events |= COMEDI_CB_OVERFLOW;
+                       dev_warn(dev->class_dev, "data lost\n");
+                       break;
+               }
 
-                       data = inb(dev->iobase + DAQP_FIFO);
-                       data |= inb(dev->iobase + DAQP_FIFO) << 8;
-                       data ^= 0x8000;
+               data = daqp_ai_get_sample(dev, s);
+               comedi_buf_write_samples(s, &data, 1);
 
-                       comedi_buf_write_samples(s, &data, 1);
+               if (cmd->stop_src == TRIG_COUNT &&
+                   s->async->scans_done >= cmd->stop_arg) {
+                       s->async->events |= COMEDI_CB_EOA;
+                       break;
+               }
 
-                       /* If there's a limit, decrement it
-                        * and stop conversion if zero
-                        */
+               if ((loop_limit--) <= 0)
+                       break;
 
-                       if (cmd->stop_src == TRIG_COUNT &&
-                           s->async->scans_done >= cmd->stop_arg) {
-                               s->async->events |= COMEDI_CB_EOA;
-                               break;
-                       }
+               status = inb(dev->iobase + DAQP_STATUS_REG);
+       }
 
-                       if ((loop_limit--) <= 0)
-                               break;
-               }
+       if (loop_limit <= 0) {
+               dev_warn(dev->class_dev,
+                        "loop_limit reached in daqp_interrupt()\n");
+               s->async->events |= COMEDI_CB_ERROR;
+       }
 
-               if (loop_limit <= 0) {
-                       dev_warn(dev->class_dev,
-                                "loop_limit reached in daqp_interrupt()\n");
-                       s->async->events |= COMEDI_CB_ERROR;
-               }
+       comedi_handle_events(dev, s);
 
-               comedi_handle_events(dev, s);
-       }
        return IRQ_HANDLED;
 }
 
@@ -257,78 +274,73 @@ static void daqp_ai_set_one_scanlist_entry(struct comedi_device *dev,
        if (start)
                val |= DAQP_SCANLIST_START;
 
-       outb(val & 0xff, dev->iobase + DAQP_SCANLIST);
-       outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST);
+       outb(val & 0xff, dev->iobase + DAQP_SCANLIST_REG);
+       outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST_REG);
 }
 
-/* One-shot analog data acquisition routine */
+static int daqp_ai_eos(struct comedi_device *dev,
+                      struct comedi_subdevice *s,
+                      struct comedi_insn *insn,
+                      unsigned long context)
+{
+       unsigned int status;
+
+       status = inb(dev->iobase + DAQP_AUX_REG);
+       if (status & DAQP_AUX_CONVERSION)
+               return 0;
+       return -EBUSY;
+}
 
 static int daqp_ai_insn_read(struct comedi_device *dev,
                             struct comedi_subdevice *s,
-                            struct comedi_insn *insn, unsigned int *data)
+                            struct comedi_insn *insn,
+                            unsigned int *data)
 {
        struct daqp_private *devpriv = dev->private;
+       int ret = 0;
        int i;
-       int v;
-       int counter = 10000;
 
        if (devpriv->stop)
                return -EIO;
 
-       /* Stop any running conversion */
-       daqp_ai_cancel(dev, s);
-
-       outb(0, dev->iobase + DAQP_AUX);
+       outb(0, dev->iobase + DAQP_AUX_REG);
 
        /* Reset scan list queue */
-       outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND);
+       outb(DAQP_CMD_RSTQ, dev->iobase + DAQP_CMD_REG);
 
        /* Program one scan list entry */
        daqp_ai_set_one_scanlist_entry(dev, insn->chanspec, 1);
 
        /* Reset data FIFO (see page 28 of DAQP User's Manual) */
+       outb(DAQP_CMD_RSTF, dev->iobase + DAQP_CMD_REG);
 
-       outb(DAQP_COMMAND_RSTF, dev->iobase + DAQP_COMMAND);
-
-       /* Set trigger */
-
-       v = DAQP_CONTROL_TRIGGER_ONESHOT | DAQP_CONTROL_TRIGGER_INTERNAL
-           | DAQP_CONTROL_PACER_100kHz | DAQP_CONTROL_EOS_INT_ENABLE;
-
-       outb(v, dev->iobase + DAQP_CONTROL);
+       /* Set trigger - one-shot, internal, no interrupts */
+       outb(DAQP_CTRL_PACER_CLK_100KHZ, dev->iobase + DAQP_CTRL_REG);
 
-       /* Reset any pending interrupts (my card has a tendency to require
-        * require multiple reads on the status register to achieve this)
-        */
-
-       while (--counter
-              && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS))
-               ;
-       if (!counter) {
-               dev_err(dev->class_dev,
-                       "couldn't clear interrupts in status register\n");
-               return -1;
-       }
-
-       init_completion(&devpriv->eos);
-       devpriv->interrupt_mode = semaphore;
+       ret = daqp_clear_events(dev, 10000);
+       if (ret)
+               return ret;
 
        for (i = 0; i < insn->n; i++) {
                /* Start conversion */
-               outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA,
-                    dev->iobase + DAQP_COMMAND);
+               outb(DAQP_CMD_ARM | DAQP_CMD_FIFO_DATA,
+                    dev->iobase + DAQP_CMD_REG);
 
-               /* Wait for interrupt service routine to unblock completion */
-               /* Maybe could use a timeout here, but it's interruptible */
-               if (wait_for_completion_interruptible(&devpriv->eos))
-                       return -EINTR;
+               ret = comedi_timeout(dev, s, insn, daqp_ai_eos, 0);
+               if (ret)
+                       break;
 
-               data[i] = inb(dev->iobase + DAQP_FIFO);
-               data[i] |= inb(dev->iobase + DAQP_FIFO) << 8;
-               data[i] ^= 0x8000;
+               /* clear the status event flags */
+               inb(dev->iobase + DAQP_STATUS_REG);
+
+               data[i] = daqp_ai_get_sample(dev, s);
        }
 
-       return insn->n;
+       /* stop any conversions and clear the status event flags */
+       outb(DAQP_CMD_STOP, dev->iobase + DAQP_CMD_REG);
+       inb(dev->iobase + DAQP_STATUS_REG);
+
+       return ret ? ret : insn->n;
 }
 
 /* This function converts ns nanoseconds to a counter value suitable
@@ -348,17 +360,18 @@ static int daqp_ns_to_timer(unsigned int *ns, unsigned int flags)
        return timer;
 }
 
-/* cmdtest tests a particular command to see if it is valid.
- * Using the cmdtest ioctl, a user can create a valid cmd
- * and then have it executed by the cmd ioctl.
- *
- * cmdtest returns 1,2,3,4 or 0, depending on which tests
- * the command passes.
- */
+static void daqp_set_pacer(struct comedi_device *dev, unsigned int val)
+{
+       outb(val & 0xff, dev->iobase + DAQP_PACER_LOW_REG);
+       outb((val >> 8) & 0xff, dev->iobase + DAQP_PACER_MID_REG);
+       outb((val >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH_REG);
+}
 
 static int daqp_ai_cmdtest(struct comedi_device *dev,
-                          struct comedi_subdevice *s, struct comedi_cmd *cmd)
+                          struct comedi_subdevice *s,
+                          struct comedi_cmd *cmd)
 {
+       struct daqp_private *devpriv = dev->private;
        int err = 0;
        unsigned int arg;
 
@@ -383,6 +396,10 @@ static int daqp_ai_cmdtest(struct comedi_device *dev,
 
        /* Step 2b : and mutually compatible */
 
+       /* the async command requires a pacer */
+       if (cmd->scan_begin_src != TRIG_TIMER && cmd->convert_src != TRIG_TIMER)
+               err |= -EINVAL;
+
        if (err)
                return 2;
 
@@ -390,31 +407,31 @@ static int daqp_ai_cmdtest(struct comedi_device *dev,
 
        err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
 
-#define MAX_SPEED      10000   /* 100 kHz - in nanoseconds */
+       err |= comedi_check_trigger_arg_min(&cmd->chanlist_len, 1);
+       err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
+                                          cmd->chanlist_len);
 
-       if (cmd->scan_begin_src == TRIG_TIMER) {
+       if (cmd->scan_begin_src == TRIG_TIMER)
                err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
-                                                   MAX_SPEED);
-       }
-
-       /* If both scan_begin and convert are both timer values, the only
-        * way that can make sense is if the scan time is the number of
-        * conversions times the convert time
-        */
-
-       if (cmd->scan_begin_src == TRIG_TIMER && cmd->convert_src == TRIG_TIMER
-           && cmd->scan_begin_arg != cmd->convert_arg * cmd->scan_end_arg) {
-               err |= -EINVAL;
-       }
+                                                   DAQP_MAX_TIMER_SPEED);
 
        if (cmd->convert_src == TRIG_TIMER) {
                err |= comedi_check_trigger_arg_min(&cmd->convert_arg,
-                                                   MAX_SPEED);
+                                                   DAQP_MAX_TIMER_SPEED);
+
+               if (cmd->scan_begin_src == TRIG_TIMER) {
+                       /*
+                        * If both scan_begin and convert are both timer
+                        * values, the only way that can make sense is if
+                        * the scan time is the number of conversions times
+                        * the convert time.
+                        */
+                       arg = cmd->convert_arg * cmd->scan_end_arg;
+                       err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg,
+                                                          arg);
+               }
        }
 
-       err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
-                                          cmd->chanlist_len);
-
        if (cmd->stop_src == TRIG_COUNT)
                err |= comedi_check_trigger_arg_max(&cmd->stop_arg, 0x00ffffff);
        else    /* TRIG_NONE */
@@ -425,16 +442,14 @@ static int daqp_ai_cmdtest(struct comedi_device *dev,
 
        /* step 4: fix up any arguments */
 
-       if (cmd->scan_begin_src == TRIG_TIMER) {
-               arg = cmd->scan_begin_arg;
-               daqp_ns_to_timer(&arg, cmd->flags);
-               err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
-       }
-
        if (cmd->convert_src == TRIG_TIMER) {
                arg = cmd->convert_arg;
-               daqp_ns_to_timer(&arg, cmd->flags);
+               devpriv->pacer_div = daqp_ns_to_timer(&arg, cmd->flags);
                err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
+       } else if (cmd->scan_begin_src == TRIG_TIMER) {
+               arg = cmd->scan_begin_arg;
+               devpriv->pacer_div = daqp_ns_to_timer(&arg, cmd->flags);
+               err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
        }
 
        if (err)
@@ -447,23 +462,18 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 {
        struct daqp_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
-       int counter;
        int scanlist_start_on_every_entry;
        int threshold;
-
+       int ret;
        int i;
-       int v;
 
        if (devpriv->stop)
                return -EIO;
 
-       /* Stop any running conversion */
-       daqp_ai_cancel(dev, s);
-
-       outb(0, dev->iobase + DAQP_AUX);
+       outb(0, dev->iobase + DAQP_AUX_REG);
 
        /* Reset scan list queue */
-       outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND);
+       outb(DAQP_CMD_RSTQ, dev->iobase + DAQP_CMD_REG);
 
        /* Program pacer clock
         *
@@ -477,20 +487,12 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
         * each scan, so we program the pacer clock to this frequency
         * and only set the SCANLIST_START bit on the first entry.
         */
+       daqp_set_pacer(dev, devpriv->pacer_div);
 
-       if (cmd->convert_src == TRIG_TIMER) {
-               counter = daqp_ns_to_timer(&cmd->convert_arg, cmd->flags);
-               outb(counter & 0xff, dev->iobase + DAQP_PACER_LOW);
-               outb((counter >> 8) & 0xff, dev->iobase + DAQP_PACER_MID);
-               outb((counter >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH);
+       if (cmd->convert_src == TRIG_TIMER)
                scanlist_start_on_every_entry = 1;
-       } else {
-               counter = daqp_ns_to_timer(&cmd->scan_begin_arg, cmd->flags);
-               outb(counter & 0xff, dev->iobase + DAQP_PACER_LOW);
-               outb((counter >> 8) & 0xff, dev->iobase + DAQP_PACER_MID);
-               outb((counter >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH);
+       else
                scanlist_start_on_every_entry = 0;
-       }
 
        /* Program scan list */
        for (i = 0; i < cmd->chanlist_len; i++) {
@@ -581,7 +583,7 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 
        /* Reset data FIFO (see page 28 of DAQP User's Manual) */
 
-       outb(DAQP_COMMAND_RSTF, dev->iobase + DAQP_COMMAND);
+       outb(DAQP_CMD_RSTF, dev->iobase + DAQP_CMD_REG);
 
        /* Set FIFO threshold.  First two bytes are near-empty
         * threshold, which is unused; next two bytes are near-full
@@ -591,41 +593,40 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
         * when the interrupt is to happen.
         */
 
-       outb(0x00, dev->iobase + DAQP_FIFO);
-       outb(0x00, dev->iobase + DAQP_FIFO);
-
-       outb((DAQP_FIFO_SIZE - threshold) & 0xff, dev->iobase + DAQP_FIFO);
-       outb((DAQP_FIFO_SIZE - threshold) >> 8, dev->iobase + DAQP_FIFO);
+       outb(0x00, dev->iobase + DAQP_AI_FIFO_REG);
+       outb(0x00, dev->iobase + DAQP_AI_FIFO_REG);
 
-       /* Set trigger */
+       outb((DAQP_FIFO_SIZE - threshold) & 0xff,
+            dev->iobase + DAQP_AI_FIFO_REG);
+       outb((DAQP_FIFO_SIZE - threshold) >> 8, dev->iobase + DAQP_AI_FIFO_REG);
 
-       v = DAQP_CONTROL_TRIGGER_CONTINUOUS | DAQP_CONTROL_TRIGGER_INTERNAL
-           | DAQP_CONTROL_PACER_5MHz | DAQP_CONTROL_FIFO_INT_ENABLE;
-
-       outb(v, dev->iobase + DAQP_CONTROL);
-
-       /* Reset any pending interrupts (my card has a tendency to require
-        * require multiple reads on the status register to achieve this)
-        */
-       counter = 100;
-       while (--counter
-              && (inb(dev->iobase + DAQP_STATUS) & DAQP_STATUS_EVENTS))
-               ;
-       if (!counter) {
-               dev_err(dev->class_dev,
-                       "couldn't clear interrupts in status register\n");
-               return -1;
-       }
+       /* Set trigger - continuous, internal */
+       outb(DAQP_CTRL_TRIG_MODE | DAQP_CTRL_PACER_CLK_5MHZ |
+            DAQP_CTRL_FIFO_INT_ENA, dev->iobase + DAQP_CTRL_REG);
 
-       devpriv->interrupt_mode = buffer;
+       ret = daqp_clear_events(dev, 100);
+       if (ret)
+               return ret;
 
        /* Start conversion */
-       outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA,
-            dev->iobase + DAQP_COMMAND);
+       outb(DAQP_CMD_ARM | DAQP_CMD_FIFO_DATA, dev->iobase + DAQP_CMD_REG);
 
        return 0;
 }
 
+static int daqp_ao_empty(struct comedi_device *dev,
+                        struct comedi_subdevice *s,
+                        struct comedi_insn *insn,
+                        unsigned long context)
+{
+       unsigned int status;
+
+       status = inb(dev->iobase + DAQP_AUX_REG);
+       if ((status & DAQP_AUX_DA_BUFFER) == 0)
+               return 0;
+       return -EBUSY;
+}
+
 static int daqp_ao_insn_write(struct comedi_device *dev,
                              struct comedi_subdevice *s,
                              struct comedi_insn *insn,
@@ -639,18 +640,22 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
                return -EIO;
 
        /* Make sure D/A update mode is direct update */
-       outb(0, dev->iobase + DAQP_AUX);
+       outb(0, dev->iobase + DAQP_AUX_REG);
 
        for (i = 0; i > insn->n; i++) {
                unsigned val = data[i];
+               int ret;
 
-               s->readback[chan] = val;
+               /* D/A transfer rate is about 8ms */
+               ret = comedi_timeout(dev, s, insn, daqp_ao_empty, 0);
+               if (ret)
+                       return ret;
 
-               val &= 0x0fff;
-               val ^= 0x0800;          /* Flip the sign */
-               val |= (chan << 12);
+               /* write the two's complement value to the channel */
+               outw((chan << 12) | comedi_offset_munge(s, val),
+                    dev->iobase + DAQP_AO_REG);
 
-               outw(val, dev->iobase + DAQP_DA);
+               s->readback[chan] = val;
        }
 
        return insn->n;
@@ -666,7 +671,7 @@ static int daqp_di_insn_bits(struct comedi_device *dev,
        if (devpriv->stop)
                return -EIO;
 
-       data[0] = inb(dev->iobase + DAQP_DIGITAL_IO);
+       data[0] = inb(dev->iobase + DAQP_DI_REG);
 
        return insn->n;
 }
@@ -682,7 +687,7 @@ static int daqp_do_insn_bits(struct comedi_device *dev,
                return -EIO;
 
        if (comedi_dio_update_state(s, data))
-               outb(s->state, dev->iobase + DAQP_DIGITAL_IO);
+               outb(s->state, dev->iobase + DAQP_DO_REG);
 
        data[1] = s->state;
 
@@ -709,25 +714,28 @@ static int daqp_auto_attach(struct comedi_device *dev,
 
        link->priv = dev;
        ret = pcmcia_request_irq(link, daqp_interrupt);
-       if (ret)
-               return ret;
+       if (ret == 0)
+               dev->irq = link->irq;
 
        ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;
 
        s = &dev->subdevices[0];
-       dev->read_subdev = s;
        s->type         = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
        s->n_chan       = 8;
-       s->len_chanlist = 2048;
        s->maxdata      = 0xffff;
        s->range_table  = &range_daqp_ai;
        s->insn_read    = daqp_ai_insn_read;
-       s->do_cmdtest   = daqp_ai_cmdtest;
-       s->do_cmd       = daqp_ai_cmd;
-       s->cancel       = daqp_ai_cancel;
+       if (dev->irq) {
+               dev->read_subdev = s;
+               s->subdev_flags |= SDF_CMD_READ;
+               s->len_chanlist = 2048;
+               s->do_cmdtest   = daqp_ai_cmdtest;
+               s->do_cmd       = daqp_ai_cmd;
+               s->cancel       = daqp_ai_cancel;
+       }
 
        s = &dev->subdevices[1];
        s->type         = COMEDI_SUBD_AO;
@@ -741,17 +749,35 @@ static int daqp_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
+       /*
+        * Digital Input subdevice
+        * NOTE: The digital input lines are shared:
+        *
+        * Chan  Normal Mode        Expansion Mode
+        * ----  -----------------  ----------------------------
+        *  0    DI0, ext. trigger  Same as normal mode
+        *  1    DI1                External gain select, lo bit
+        *  2    DI2, ext. clock    Same as normal mode
+        *  3    DI3                External gain select, hi bit
+        */
        s = &dev->subdevices[2];
        s->type         = COMEDI_SUBD_DI;
        s->subdev_flags = SDF_READABLE;
-       s->n_chan       = 1;
+       s->n_chan       = 4;
        s->maxdata      = 1;
        s->insn_bits    = daqp_di_insn_bits;
 
+       /*
+        * Digital Output subdevice
+        * NOTE: The digital output lines share the same pins on the
+        * interface connector as the four external channel selection
+        * bits. If expansion mode is used the digital outputs do not
+        * work.
+        */
        s = &dev->subdevices[3];
        s->type         = COMEDI_SUBD_DO;
        s->subdev_flags = SDF_WRITABLE;
-       s->n_chan       = 1;
+       s->n_chan       = 4;
        s->maxdata      = 1;
        s->insn_bits    = daqp_do_insn_bits;
 
index 4c13f5eb0c842ec692dbfc580e6820fbeded8ca4..68ac02b68cb23d425cf7bc6bd27b525a09bcb5d1 100644 (file)
@@ -72,8 +72,6 @@
  * As far as I can tell, the About interrupt doesn't work if Sample is
  * also enabled. It turns out that About really isn't needed, since
  * we always count down samples read.
- *
- * There was some timer/counter code, but it didn't follow the right API.
  */
 
 /*
@@ -99,6 +97,7 @@
 
 #include "../comedi_pci.h"
 
+#include "comedi_8254.h"
 #include "plx9080.h"
 
 /*
  */
 #define LAS0_USER_IO           0x0008  /* User I/O */
 #define LAS0_ADC               0x0010  /* FIFO Status/Software A/D Start */
-#define FS_DAC1_NOT_EMPTY      (1 << 0)        /* DAC1 FIFO not empty */
-#define FS_DAC1_HEMPTY         (1 << 1)        /* DAC1 FIFO half empty */
-#define FS_DAC1_NOT_FULL       (1 << 2)        /* DAC1 FIFO not full */
-#define FS_DAC2_NOT_EMPTY      (1 << 4)        /* DAC2 FIFO not empty */
-#define FS_DAC2_HEMPTY         (1 << 5)        /* DAC2 FIFO half empty */
-#define FS_DAC2_NOT_FULL       (1 << 6)        /* DAC2 FIFO not full */
-#define FS_ADC_NOT_EMPTY       (1 << 8)        /* ADC FIFO not empty */
-#define FS_ADC_HEMPTY          (1 << 9)        /* ADC FIFO half empty */
-#define FS_ADC_NOT_FULL                (1 << 10)       /* ADC FIFO not full */
-#define FS_DIN_NOT_EMPTY       (1 << 12)       /* DIN FIFO not empty */
-#define FS_DIN_HEMPTY          (1 << 13)       /* DIN FIFO half empty */
-#define FS_DIN_NOT_FULL                (1 << 14)       /* DIN FIFO not full */
-#define LAS0_DAC1              0x0014  /* Software D/A1 Update (w) */
-#define LAS0_DAC2              0x0018  /* Software D/A2 Update (w) */
+#define FS_DAC1_NOT_EMPTY      BIT(0)  /* DAC1 FIFO not empty */
+#define FS_DAC1_HEMPTY         BIT(1)  /* DAC1 FIFO half empty */
+#define FS_DAC1_NOT_FULL       BIT(2)  /* DAC1 FIFO not full */
+#define FS_DAC2_NOT_EMPTY      BIT(4)  /* DAC2 FIFO not empty */
+#define FS_DAC2_HEMPTY         BIT(5)  /* DAC2 FIFO half empty */
+#define FS_DAC2_NOT_FULL       BIT(6)  /* DAC2 FIFO not full */
+#define FS_ADC_NOT_EMPTY       BIT(8)  /* ADC FIFO not empty */
+#define FS_ADC_HEMPTY          BIT(9)  /* ADC FIFO half empty */
+#define FS_ADC_NOT_FULL                BIT(10) /* ADC FIFO not full */
+#define FS_DIN_NOT_EMPTY       BIT(12) /* DIN FIFO not empty */
+#define FS_DIN_HEMPTY          BIT(13) /* DIN FIFO half empty */
+#define FS_DIN_NOT_FULL                BIT(14) /* DIN FIFO not full */
+#define LAS0_UPDATE_DAC(x)     (0x0014 + ((x) * 0x4))  /* D/Ax Update (w) */
 #define LAS0_DAC               0x0024  /* Software Simultaneous Update (w) */
 #define LAS0_PACER             0x0028  /* Software Pacer Start/Stop */
 #define LAS0_TIMER             0x002c  /* Timer Status/HDIN Software Trig. */
 #define LAS0_IT                        0x0030  /* Interrupt Status/Enable */
-#define IRQM_ADC_FIFO_WRITE    (1 << 0)        /* ADC FIFO Write */
-#define IRQM_CGT_RESET         (1 << 1)        /* Reset CGT */
-#define IRQM_CGT_PAUSE         (1 << 3)        /* Pause CGT */
-#define IRQM_ADC_ABOUT_CNT     (1 << 4)        /* About Counter out */
-#define IRQM_ADC_DELAY_CNT     (1 << 5)        /* Delay Counter out */
-#define IRQM_ADC_SAMPLE_CNT    (1 << 6)        /* ADC Sample Counter */
-#define IRQM_DAC1_UCNT         (1 << 7)        /* DAC1 Update Counter */
-#define IRQM_DAC2_UCNT         (1 << 8)        /* DAC2 Update Counter */
-#define IRQM_UTC1              (1 << 9)        /* User TC1 out */
-#define IRQM_UTC1_INV          (1 << 10)       /* User TC1 out, inverted */
-#define IRQM_UTC2              (1 << 11)       /* User TC2 out */
-#define IRQM_DIGITAL_IT                (1 << 12)       /* Digital Interrupt */
-#define IRQM_EXTERNAL_IT       (1 << 13)       /* External Interrupt */
-#define IRQM_ETRIG_RISING      (1 << 14)       /* Ext Trigger rising-edge */
-#define IRQM_ETRIG_FALLING     (1 << 15)       /* Ext Trigger falling-edge */
+#define IRQM_ADC_FIFO_WRITE    BIT(0)  /* ADC FIFO Write */
+#define IRQM_CGT_RESET         BIT(1)  /* Reset CGT */
+#define IRQM_CGT_PAUSE         BIT(3)  /* Pause CGT */
+#define IRQM_ADC_ABOUT_CNT     BIT(4)  /* About Counter out */
+#define IRQM_ADC_DELAY_CNT     BIT(5)  /* Delay Counter out */
+#define IRQM_ADC_SAMPLE_CNT    BIT(6)  /* ADC Sample Counter */
+#define IRQM_DAC1_UCNT         BIT(7)  /* DAC1 Update Counter */
+#define IRQM_DAC2_UCNT         BIT(8)  /* DAC2 Update Counter */
+#define IRQM_UTC1              BIT(9)  /* User TC1 out */
+#define IRQM_UTC1_INV          BIT(10) /* User TC1 out, inverted */
+#define IRQM_UTC2              BIT(11) /* User TC2 out */
+#define IRQM_DIGITAL_IT                BIT(12) /* Digital Interrupt */
+#define IRQM_EXTERNAL_IT       BIT(13) /* External Interrupt */
+#define IRQM_ETRIG_RISING      BIT(14) /* Ext Trigger rising-edge */
+#define IRQM_ETRIG_FALLING     BIT(15) /* Ext Trigger falling-edge */
 #define LAS0_CLEAR             0x0034  /* Clear/Set Interrupt Clear Mask */
 #define LAS0_OVERRUN           0x0038  /* Pending interrupts/Clear Overrun */
 #define LAS0_PCLK              0x0040  /* Pacer Clock (24bit) */
 #define LAS0_DCNT              0x0054  /* Delay counter (16 bit) */
 #define LAS0_ACNT              0x0058  /* About counter (16 bit) */
 #define LAS0_DAC_CLK           0x005c  /* DAC clock (16bit) */
-#define LAS0_UTC0              0x0060  /* 8254 TC Counter 0 */
-#define LAS0_UTC1              0x0064  /* 8254 TC Counter 1 */
-#define LAS0_UTC2              0x0068  /* 8254 TC Counter 2 */
-#define LAS0_UTC_CTRL          0x006c  /* 8254 TC Control */
+#define LAS0_8254_TIMER_BASE   0x0060  /* 8254 timer/counter base */
 #define LAS0_DIO0              0x0070  /* Digital I/O Port 0 */
 #define LAS0_DIO1              0x0074  /* Digital I/O Port 1 */
 #define LAS0_DIO0_CTRL         0x0078  /* Digital I/O Control */
 #define LAS0_CGT_PAUSE         0x0144  /* Table Pause Enable */
 #define LAS0_CGT_RESET         0x0148  /* Reset Channel Gain Table */
 #define LAS0_CGT_CLEAR         0x014c  /* Clear Channel Gain Table */
-#define LAS0_DAC1_CTRL         0x0150  /* D/A1 output type/range */
-#define LAS0_DAC1_SRC          0x0154  /* D/A1 update source */
-#define LAS0_DAC1_CYCLE                0x0158  /* D/A1 cycle mode */
-#define LAS0_DAC1_RESET                0x015c  /* D/A1 FIFO reset */
-#define LAS0_DAC1_FIFO_CLEAR   0x0160  /* D/A1 FIFO clear */
-#define LAS0_DAC2_CTRL         0x0164  /* D/A2 output type/range */
-#define LAS0_DAC2_SRC          0x0168  /* D/A2 update source */
-#define LAS0_DAC2_CYCLE                0x016c  /* D/A2 cycle mode */
-#define LAS0_DAC2_RESET                0x0170  /* D/A2 FIFO reset */
-#define LAS0_DAC2_FIFO_CLEAR   0x0174  /* D/A2 FIFO clear */
+#define LAS0_DAC_CTRL(x)       (0x0150 + ((x) * 0x14)) /* D/Ax type/range */
+#define LAS0_DAC_SRC(x)                (0x0154 + ((x) * 0x14)) /* D/Ax update source */
+#define LAS0_DAC_CYCLE(x)      (0x0158 + ((x) * 0x14)) /* D/Ax cycle mode */
+#define LAS0_DAC_RESET(x)      (0x015c + ((x) * 0x14)) /* D/Ax FIFO reset */
+#define LAS0_DAC_FIFO_CLEAR(x) (0x0160 + ((x) * 0x14)) /* D/Ax FIFO clear */
 #define LAS0_ADC_SCNT_SRC      0x0178  /* A/D Sample Counter Source select */
 #define LAS0_PACER_SELECT      0x0180  /* Pacer Clock select */
 #define LAS0_SBUS0_SRC         0x0184  /* SyncBus 0 Source select */
 #define LAS0_SBUS2_ENABLE      0x019c  /* SyncBus 2 enable */
 #define LAS0_ETRG_POLARITY     0x01a4  /* Ext. Trigger polarity select */
 #define LAS0_EINT_POLARITY     0x01a8  /* Ext. Interrupt polarity select */
-#define LAS0_UTC0_CLOCK                0x01ac  /* UTC0 Clock select */
-#define LAS0_UTC0_GATE         0x01b0  /* UTC0 Gate select */
-#define LAS0_UTC1_CLOCK                0x01b4  /* UTC1 Clock select */
-#define LAS0_UTC1_GATE         0x01b8  /* UTC1 Gate select */
-#define LAS0_UTC2_CLOCK                0x01bc  /* UTC2 Clock select */
-#define LAS0_UTC2_GATE         0x01c0  /* UTC2 Gate select */
+#define LAS0_8254_CLK_SEL(x)   (0x01ac + ((x) * 0x8))  /* 8254 clock select */
+#define LAS0_8254_GATE_SEL(x)  (0x01b0 + ((x) * 0x8))  /* 8254 gate select */
 #define LAS0_UOUT0_SELECT      0x01c4  /* User Output 0 source select */
 #define LAS0_UOUT1_SELECT      0x01c8  /* User Output 1 source select */
 #define LAS0_DMA0_RESET                0x01cc  /* DMA0 Request state machine reset */
  */
 #define LAS1_ADC_FIFO          0x0000  /* A/D FIFO (16bit) */
 #define LAS1_HDIO_FIFO         0x0004  /* HiSpd DI FIFO (16bit) */
-#define LAS1_DAC1_FIFO         0x0008  /* D/A1 FIFO (16bit) */
-#define LAS1_DAC2_FIFO         0x000c  /* D/A2 FIFO (16bit) */
+#define LAS1_DAC_FIFO(x)       (0x0008 + ((x) * 0x4))  /* D/Ax FIFO (16bit) */
 
-/*======================================================================
-  Driver specific stuff (tunable)
-======================================================================*/
+/*
* Driver specific stuff (tunable)
+ */
 
-/* We really only need 2 buffers.  More than that means being much
-   smarter about knowing which ones are full. */
+/*
+ * We really only need 2 buffers.  More than that means being much
+ * smarter about knowing which ones are full.
+ */
 #define DMA_CHAIN_COUNT 2      /* max DMA segments/buffers in a ring (min 2) */
 
 /* Target period for periodic transfers.  This sets the user read latency. */
 /* The board support a channel list up to the FIFO length (1K or 8K) */
 #define RTD_MAX_CHANLIST       128     /* max channel list that we allow */
 
-/*======================================================================
-  Board specific stuff
-======================================================================*/
+/*
* Board specific stuff
+ */
 
 #define RTD_CLOCK_RATE 8000000 /* 8Mhz onboard clock */
 #define RTD_CLOCK_BASE 125     /* clock period in ns */
 /* interrupt at end of block */ | PLX_INTR_TERM_COUNT \
 /* from board to PCI */                | PLX_XFER_LOCAL_TO_PCI)
 
-/*======================================================================
-  Comedi specific stuff
-======================================================================*/
+/*
* Comedi specific stuff
+ */
 
 /*
  * The board has 3 input modes and the gains of 1,2,4,...32 (, 64, 128)
@@ -352,7 +339,7 @@ struct rtd_boardinfo {
        const struct comedi_lrange *ai_range;
 };
 
-static const struct rtd_boardinfo rtd520Boards[] = {
+static const struct rtd_boardinfo rtd520_boards[] = {
        [BOARD_DM7520] = {
                .name           = "DM7520",
                .range_bip10    = 6,
@@ -376,6 +363,10 @@ struct rtd_private {
        int xfer_count;         /* # to transfer data. 0->1/2FIFO */
        int flags;              /* flag event modes */
        unsigned fifosz;
+
+       /* 8254 Timer/Counter gate and clock sources */
+       unsigned char timer_gate_src[3];
+       unsigned char timer_clk_src[3];
 };
 
 /* bit defines for "flags" */
@@ -384,11 +375,11 @@ struct rtd_private {
 #define DMA1_ACTIVE    0x04    /* DMA1 is active */
 
 /*
-  Given a desired period and the clock period (both in ns),
-  return the proper counter value (divider-1).
 Sets the original period to be the true value.
-  Note: you have to check if the value is larger than the counter range!
-*/
+ * Given a desired period and the clock period (both in ns), return the
+ * proper counter value (divider-1). Sets the original period to be the
* true value.
* Note: you have to check if the value is larger than the counter range!
+ */
 static int rtd_ns_to_timer_base(unsigned int *nanosec,
                                unsigned int flags, int base)
 {
@@ -397,38 +388,38 @@ static int rtd_ns_to_timer_base(unsigned int *nanosec,
        switch (flags & CMDF_ROUND_MASK) {
        case CMDF_ROUND_NEAREST:
        default:
-               divider = (*nanosec + base / 2) / base;
+               divider = DIV_ROUND_CLOSEST(*nanosec, base);
                break;
        case CMDF_ROUND_DOWN:
                divider = (*nanosec) / base;
                break;
        case CMDF_ROUND_UP:
-               divider = (*nanosec + base - 1) / base;
+               divider = DIV_ROUND_UP(*nanosec, base);
                break;
        }
        if (divider < 2)
                divider = 2;    /* min is divide by 2 */
 
-       /* Note: we don't check for max, because different timers
-          have different ranges */
+       /*
+        * Note: we don't check for max, because different timers
+        * have different ranges
+        */
 
        *nanosec = base * divider;
        return divider - 1;     /* countdown is divisor+1 */
 }
 
 /*
-  Given a desired period (in ns),
-  return the proper counter value (divider-1) for the internal clock.
 Sets the original period to be the true value.
-*/
+ * Given a desired period (in ns), return the proper counter value
+ * (divider-1) for the internal clock. Sets the original period to
* be the true value.
+ */
 static int rtd_ns_to_timer(unsigned int *ns, unsigned int flags)
 {
        return rtd_ns_to_timer_base(ns, flags, RTD_CLOCK_BASE);
 }
 
-/*
-  Convert a single comedi channel-gain entry to a RTD520 table entry
-*/
+/* Convert a single comedi channel-gain entry to a RTD520 table entry */
 static unsigned short rtd_convert_chan_gain(struct comedi_device *dev,
                                            unsigned int chanspec, int index)
 {
@@ -473,9 +464,7 @@ static unsigned short rtd_convert_chan_gain(struct comedi_device *dev,
        return r;
 }
 
-/*
-  Setup the channel-gain table from a comedi list
-*/
+/* Setup the channel-gain table from a comedi list */
 static void rtd_load_channelgain_list(struct comedi_device *dev,
                                      unsigned int n_chan, unsigned int *list)
 {
@@ -495,8 +484,10 @@ static void rtd_load_channelgain_list(struct comedi_device *dev,
        }
 }
 
-/* determine fifo size by doing adc conversions until the fifo half
-empty status flag clears */
+/*
+ * Determine fifo size by doing adc conversions until the fifo half
+ * empty status flag clears.
+ */
 static int rtd520_probe_fifo_depth(struct comedi_device *dev)
 {
        unsigned int chanspec = CR_PACK(0, 0, AREF_GROUND);
@@ -513,7 +504,7 @@ static int rtd520_probe_fifo_depth(struct comedi_device *dev)
                unsigned fifo_status;
                /* trigger conversion */
                writew(0, dev->mmio + LAS0_ADC);
-               udelay(1);
+               usleep_range(1, 1000);
                fifo_status = readl(dev->mmio + LAS0_ADC);
                if ((fifo_status & FS_ADC_HEMPTY) == 0) {
                        fifo_size = 2 * i;
@@ -590,12 +581,6 @@ static int rtd_ai_rinsn(struct comedi_device *dev,
        return n;
 }
 
-/*
-  Get what we know is there.... Fast!
-  This uses 1/2 the bus cycles of read_dregs (below).
-
-  The manual claims that we can do a lword read, but it doesn't work here.
-*/
 static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
                     int count)
 {
@@ -608,7 +593,7 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
                unsigned int range = CR_RANGE(cmd->chanlist[async->cur_chan]);
                unsigned short d;
 
-               if (0 == devpriv->ai_count) {   /* done */
+               if (devpriv->ai_count == 0) {   /* done */
                        d = readw(devpriv->las1 + LAS1_ADC_FIFO);
                        continue;
                }
@@ -630,12 +615,6 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
        return 0;
 }
 
-/*
-  Handle all rtd520 interrupts.
-  Runs atomically and is never re-entered.
-  This is a "slow handler";  other interrupts may be active.
-  The data conversion may someday happen in a "bottom half".
-*/
 static irqreturn_t rtd_interrupt(int irq, void *d)
 {
        struct comedi_device *dev = d;
@@ -655,7 +634,7 @@ static irqreturn_t rtd_interrupt(int irq, void *d)
 
        status = readw(dev->mmio + LAS0_IT);
        /* if interrupt was not caused by our board, or handled above */
-       if (0 == status)
+       if (status == 0)
                return IRQ_HANDLED;
 
        if (status & IRQM_ADC_ABOUT_CNT) {      /* sample count -> read FIFO */
@@ -670,7 +649,7 @@ static irqreturn_t rtd_interrupt(int irq, void *d)
                        if (ai_read_n(dev, s, devpriv->fifosz / 2) < 0)
                                goto xfer_abort;
 
-                       if (0 == devpriv->ai_count)
+                       if (devpriv->ai_count == 0)
                                goto xfer_done;
                } else if (devpriv->xfer_count > 0) {
                        if (fifo_status & FS_ADC_NOT_EMPTY) {
@@ -678,7 +657,7 @@ static irqreturn_t rtd_interrupt(int irq, void *d)
                                if (ai_read_n(dev, s, devpriv->xfer_count) < 0)
                                        goto xfer_abort;
 
-                               if (0 == devpriv->ai_count)
+                               if (devpriv->ai_count == 0)
                                        goto xfer_done;
                        }
                }
@@ -715,15 +694,6 @@ xfer_done:
        return IRQ_HANDLED;
 }
 
-/*
-  cmdtest tests a particular command to see if it is valid.
-  Using the cmdtest ioctl, a user can create a valid cmd
-  and then have it executed by the cmd ioctl (asynchronously).
-
-  cmdtest returns 1,2,3,4 or 0, depending on which tests
-  the command passes.
-*/
-
 static int rtd_ai_cmdtest(struct comedi_device *dev,
                          struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
@@ -760,7 +730,7 @@ static int rtd_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                /* Note: these are time periods, not actual rates */
-               if (1 == cmd->chanlist_len) {   /* no scanning */
+               if (cmd->chanlist_len == 1) {   /* no scanning */
                        if (comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
                                                         RTD_MAX_SPEED_1)) {
                                rtd_ns_to_timer(&cmd->scan_begin_arg,
@@ -795,7 +765,7 @@ static int rtd_ai_cmdtest(struct comedi_device *dev,
        }
 
        if (cmd->convert_src == TRIG_TIMER) {
-               if (1 == cmd->chanlist_len) {   /* no scanning */
+               if (cmd->chanlist_len == 1) {   /* no scanning */
                        if (comedi_check_trigger_arg_min(&cmd->convert_arg,
                                                         RTD_MAX_SPEED_1)) {
                                rtd_ns_to_timer(&cmd->convert_arg,
@@ -866,12 +836,6 @@ static int rtd_ai_cmdtest(struct comedi_device *dev,
        return 0;
 }
 
-/*
-  Execute a analog in command with many possible triggering options.
-  The data get stored in the async structure of the subdevice.
-  This is usually done by an interrupt handler.
-  Userland gets to the data using read calls.
-*/
 static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 {
        struct rtd_private *devpriv = dev->private;
@@ -907,7 +871,7 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        }
        writel((devpriv->fifosz / 2 - 1) & 0xffff, dev->mmio + LAS0_ACNT);
 
-       if (TRIG_TIMER == cmd->scan_begin_src) {
+       if (cmd->scan_begin_src == TRIG_TIMER) {
                /* scan_begin_arg is in nanoseconds */
                /* find out how many samples to wait before transferring */
                if (cmd->flags & CMDF_WAKE_EOS) {
@@ -959,8 +923,8 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        switch (cmd->stop_src) {
        case TRIG_COUNT:        /* stop after N scans */
                devpriv->ai_count = cmd->stop_arg * cmd->chanlist_len;
-               if ((devpriv->xfer_count > 0)
-                   && (devpriv->xfer_count > devpriv->ai_count)) {
+               if ((devpriv->xfer_count > 0) &&
+                   (devpriv->xfer_count > devpriv->ai_count)) {
                        devpriv->xfer_count = devpriv->ai_count;
                }
                break;
@@ -1006,8 +970,10 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        }
        /* end configuration */
 
-       /* This doesn't seem to work.  There is no way to clear an interrupt
-          that the priority controller has queued! */
+       /*
+        * This doesn't seem to work.  There is no way to clear an interrupt
+        * that the priority controller has queued!
+        */
        writew(~0, dev->mmio + LAS0_CLEAR);
        readw(dev->mmio + LAS0_CLEAR);
 
@@ -1021,9 +987,6 @@ static int rtd_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        return 0;
 }
 
-/*
-  Stop a running data acquisition.
-*/
 static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
 {
        struct rtd_private *devpriv = dev->private;
@@ -1053,49 +1016,43 @@ static int rtd_ao_eoc(struct comedi_device *dev,
        return -EBUSY;
 }
 
-static int rtd_ao_winsn(struct comedi_device *dev,
-                       struct comedi_subdevice *s, struct comedi_insn *insn,
-                       unsigned int *data)
+static int rtd_ao_insn_write(struct comedi_device *dev,
+                            struct comedi_subdevice *s,
+                            struct comedi_insn *insn,
+                            unsigned int *data)
 {
        struct rtd_private *devpriv = dev->private;
-       int i;
-       int chan = CR_CHAN(insn->chanspec);
-       int range = CR_RANGE(insn->chanspec);
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int range = CR_RANGE(insn->chanspec);
        int ret;
+       int i;
 
        /* Configure the output range (table index matches the range values) */
-       writew(range & 7,
-              dev->mmio + ((chan == 0) ? LAS0_DAC1_CTRL : LAS0_DAC2_CTRL));
+       writew(range & 7, dev->mmio + LAS0_DAC_CTRL(chan));
 
-       /* Writing a list of values to an AO channel is probably not
-        * very useful, but that's how the interface is defined. */
        for (i = 0; i < insn->n; ++i) {
-               int val = data[i] << 3;
+               unsigned int val = data[i];
 
-               /* VERIFY: comedi range and offset conversions */
-
-               if ((range > 1) /* bipolar */
-                   && (data[i] < 2048)) {
-                       /* offset and sign extend */
-                       val = (((int)data[i]) - 2048) << 3;
-               } else {        /* unipolor */
-                       val = data[i] << 3;
+               /* bipolar uses 2's complement values with an extended sign */
+               if (comedi_range_is_bipolar(s, range)) {
+                       val = comedi_offset_munge(s, val);
+                       val |= (val & ((s->maxdata + 1) >> 1)) << 1;
                }
 
-               /* a typical programming sequence */
-               writew(val, devpriv->las1 +
-                       ((chan == 0) ? LAS1_DAC1_FIFO : LAS1_DAC2_FIFO));
-               writew(0, dev->mmio + ((chan == 0) ? LAS0_DAC1 : LAS0_DAC2));
+               /* shift the 12-bit data (+ sign) to match the register */
+               val <<= 3;
 
-               s->readback[chan] = data[i];
+               writew(val, devpriv->las1 + LAS1_DAC_FIFO(chan));
+               writew(0, dev->mmio + LAS0_UPDATE_DAC(chan));
 
                ret = comedi_timeout(dev, s, insn, rtd_ao_eoc, 0);
                if (ret)
                        return ret;
+
+               s->readback[chan] = data[i];
        }
 
-       /* return the number of samples read/written */
-       return i;
+       return insn->n;
 }
 
 static int rtd_dio_insn_bits(struct comedi_device *dev,
@@ -1138,12 +1095,87 @@ static int rtd_dio_insn_config(struct comedi_device *dev,
        return insn->n;
 }
 
+static int rtd_counter_insn_config(struct comedi_device *dev,
+                                  struct comedi_subdevice *s,
+                                  struct comedi_insn *insn,
+                                  unsigned int *data)
+{
+       struct rtd_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int max_src;
+       unsigned int src;
+
+       switch (data[0]) {
+       case INSN_CONFIG_SET_GATE_SRC:
+               /*
+                * 8254 Timer/Counter gate sources:
+                *
+                * 0 = Not gated, free running (reset state)
+                * 1 = Gated, off
+                * 2 = Ext. TC Gate 1
+                * 3 = Ext. TC Gate 2
+                * 4 = Previous TC out (chan 1 and 2 only)
+                */
+               src = data[2];
+               max_src = (chan == 0) ? 3 : 4;
+               if (src > max_src)
+                       return -EINVAL;
+
+               devpriv->timer_gate_src[chan] = src;
+               writeb(src, dev->mmio + LAS0_8254_GATE_SEL(chan));
+               break;
+       case INSN_CONFIG_GET_GATE_SRC:
+               data[2] = devpriv->timer_gate_src[chan];
+               break;
+       case INSN_CONFIG_SET_CLOCK_SRC:
+               /*
+                * 8254 Timer/Counter clock sources:
+                *
+                * 0 = 8 MHz (reset state)
+                * 1 = Ext. TC Clock 1
+                * 2 = Ext. TX Clock 2
+                * 3 = Ext. Pacer Clock
+                * 4 = Previous TC out (chan 1 and 2 only)
+                * 5 = High-Speed Digital Input Sampling signal (chan 1 only)
+                */
+               src = data[1];
+               switch (chan) {
+               case 0:
+                       max_src = 3;
+                       break;
+               case 1:
+                       max_src = 5;
+                       break;
+               case 2:
+                       max_src = 4;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               if (src > max_src)
+                       return -EINVAL;
+
+               devpriv->timer_clk_src[chan] = src;
+               writeb(src, dev->mmio + LAS0_8254_CLK_SEL(chan));
+               break;
+       case INSN_CONFIG_GET_CLOCK_SRC:
+               src = devpriv->timer_clk_src[chan];
+               data[1] = devpriv->timer_clk_src[chan];
+               data[2] = (src == 0) ? RTD_CLOCK_BASE : 0;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return insn->n;
+}
+
 static void rtd_reset(struct comedi_device *dev)
 {
        struct rtd_private *devpriv = dev->private;
 
        writel(0, dev->mmio + LAS0_BOARD_RESET);
-       udelay(100);            /* needed? */
+       usleep_range(100, 1000);        /* needed? */
        writel(0, devpriv->lcfg + PLX_INTRCS_REG);
        writew(0, dev->mmio + LAS0_IT);
        writew(~0, dev->mmio + LAS0_CLEAR);
@@ -1161,14 +1193,10 @@ static void rtd_init_board(struct comedi_device *dev)
        writel(0, dev->mmio + LAS0_OVERRUN);
        writel(0, dev->mmio + LAS0_CGT_CLEAR);
        writel(0, dev->mmio + LAS0_ADC_FIFO_CLEAR);
-       writel(0, dev->mmio + LAS0_DAC1_RESET);
-       writel(0, dev->mmio + LAS0_DAC2_RESET);
+       writel(0, dev->mmio + LAS0_DAC_RESET(0));
+       writel(0, dev->mmio + LAS0_DAC_RESET(1));
        /* clear digital IO fifo */
        writew(0, dev->mmio + LAS0_DIO_STATUS);
-       writeb((0 << 6) | 0x30, dev->mmio + LAS0_UTC_CTRL);
-       writeb((1 << 6) | 0x30, dev->mmio + LAS0_UTC_CTRL);
-       writeb((2 << 6) | 0x30, dev->mmio + LAS0_UTC_CTRL);
-       writeb((3 << 6) | 0x00, dev->mmio + LAS0_UTC_CTRL);
        /* TODO: set user out source ??? */
 }
 
@@ -1196,8 +1224,8 @@ static int rtd_auto_attach(struct comedi_device *dev,
        struct comedi_subdevice *s;
        int ret;
 
-       if (context < ARRAY_SIZE(rtd520Boards))
-               board = &rtd520Boards[context];
+       if (context < ARRAY_SIZE(rtd520_boards))
+               board = &rtd520_boards[context];
        if (!board)
                return -ENODEV;
        dev->board_ptr = board;
@@ -1254,7 +1282,7 @@ static int rtd_auto_attach(struct comedi_device *dev,
        s->n_chan       = 2;
        s->maxdata      = 0x0fff;
        s->range_table  = &rtd_ao_range;
-       s->insn_write   = rtd_ao_winsn;
+       s->insn_write   = rtd_ao_insn_write;
 
        ret = comedi_alloc_subdev_readback(s);
        if (ret)
@@ -1271,12 +1299,15 @@ static int rtd_auto_attach(struct comedi_device *dev,
        s->insn_bits    = rtd_dio_insn_bits;
        s->insn_config  = rtd_dio_insn_config;
 
-       /* timer/counter subdevices (not currently supported) */
+       /* 8254 Timer/Counter subdevice */
        s = &dev->subdevices[3];
-       s->type         = COMEDI_SUBD_COUNTER;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan       = 3;
-       s->maxdata      = 0xffff;
+       dev->pacer = comedi_8254_mm_init(dev->mmio + LAS0_8254_TIMER_BASE,
+                                        RTD_CLOCK_BASE, I8254_IO8, 2);
+       if (!dev->pacer)
+               return -ENOMEM;
+
+       comedi_8254_subdevice_init(s, dev->pacer);
+       dev->pacer->insn_config = rtd_counter_insn_config;
 
        rtd_init_board(dev);
 
index 340ac776e951a6c406584cb8df3498e80cfe6a13..cd61d2645af452f31e314c8232554499bed189ab 100644 (file)
  * Register map
  */
 #define RTI800_CSR             0x00
-#define RTI800_CSR_BUSY                (1 << 7)
-#define RTI800_CSR_DONE                (1 << 6)
-#define RTI800_CSR_OVERRUN     (1 << 5)
-#define RTI800_CSR_TCR         (1 << 4)
-#define RTI800_CSR_DMA_ENAB    (1 << 3)
-#define RTI800_CSR_INTR_TC     (1 << 2)
-#define RTI800_CSR_INTR_EC     (1 << 1)
-#define RTI800_CSR_INTR_OVRN   (1 << 0)
+#define RTI800_CSR_BUSY                BIT(7)
+#define RTI800_CSR_DONE                BIT(6)
+#define RTI800_CSR_OVERRUN     BIT(5)
+#define RTI800_CSR_TCR         BIT(4)
+#define RTI800_CSR_DMA_ENAB    BIT(3)
+#define RTI800_CSR_INTR_TC     BIT(2)
+#define RTI800_CSR_INTR_EC     BIT(1)
+#define RTI800_CSR_INTR_OVRN   BIT(0)
 #define RTI800_MUXGAIN         0x01
 #define RTI800_CONVERT         0x02
 #define RTI800_ADCLO           0x03
@@ -189,17 +189,21 @@ static int rti800_ai_insn_read(struct comedi_device *dev,
        }
 
        for (i = 0; i < insn->n; i++) {
+               unsigned int val;
+
                outb(0, dev->iobase + RTI800_CONVERT);
 
                ret = comedi_timeout(dev, s, insn, rti800_ai_eoc, 0);
                if (ret)
                        return ret;
 
-               data[i] = inb(dev->iobase + RTI800_ADCLO);
-               data[i] |= (inb(dev->iobase + RTI800_ADCHI) & 0xf) << 8;
+               val = inb(dev->iobase + RTI800_ADCLO);
+               val |= (inb(dev->iobase + RTI800_ADCHI) & 0xf) << 8;
 
                if (devpriv->adc_2comp)
-                       data[i] ^= 0x800;
+                       val = comedi_offset_munge(s, val);
+
+               data[i] = val;
        }
 
        return insn->n;
@@ -222,7 +226,7 @@ static int rti800_ao_insn_write(struct comedi_device *dev,
                s->readback[chan] = val;
 
                if (devpriv->dac_2comp[chan])
-                       val ^= 0x800;
+                       val = comedi_offset_munge(s, val);
 
                outb(val & 0xff, dev->iobase + reg_lo);
                outb((val >> 8) & 0xff, dev->iobase + reg_hi);
index 6f3e8a08e75c8c164c95fea7be00a905aefb8dcd..d70c979476274b9195940c8b0ac4ea160d71848f 100644 (file)
@@ -1,79 +1,96 @@
 /*
-    comedi/drivers/s526.c
-    Sensoray s526 Comedi driver
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
-/*
-Driver: s526
-Description: Sensoray 526 driver
-Devices: [Sensoray] 526 (s526)
-Author: Richie
-       Everett Wang <everett.wang@everteq.com>
-Updated: Thu, 14 Sep. 2006
-Status: experimental
-
-Encoder works
-Analog input works
-Analog output works
-PWM output works
-Commands are not supported yet.
-
-Configuration Options:
+ * s526.c
+ * Sensoray s526 Comedi driver
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
-comedi_config /dev/comedi0 s526 0x2C0,0x3
-
-*/
+/*
+ * Driver: s526
+ * Description: Sensoray 526 driver
+ * Devices: [Sensoray] 526 (s526)
+ * Author: Richie
+ *        Everett Wang <everett.wang@everteq.com>
+ * Updated: Thu, 14 Sep. 2006
+ * Status: experimental
+ *
+ * Encoder works
+ * Analog input works
+ * Analog output works
+ * PWM output works
+ * Commands are not supported yet.
+ *
+ * Configuration Options:
+ *   [0] - I/O port base address
+ */
 
 #include <linux/module.h>
 #include "../comedidev.h"
 #include <asm/byteorder.h>
 
-#define S526_START_AI_CONV     0
-#define S526_AI_READ           0
-
-/* Ports */
-#define S526_NUM_PORTS 27
-
-/* registers */
-#define REG_TCR 0x00
-#define REG_WDC 0x02
-#define REG_DAC 0x04
-#define REG_ADC 0x06
-#define REG_ADD 0x08
-#define REG_DIO 0x0A
-#define REG_IER 0x0C
-#define REG_ISR 0x0E
-#define REG_MSC 0x10
-#define REG_C0L 0x12
-#define REG_C0H 0x14
-#define REG_C0M 0x16
-#define REG_C0C 0x18
-#define REG_C1L 0x1A
-#define REG_C1H 0x1C
-#define REG_C1M 0x1E
-#define REG_C1C 0x20
-#define REG_C2L 0x22
-#define REG_C2H 0x24
-#define REG_C2M 0x26
-#define REG_C2C 0x28
-#define REG_C3L 0x2A
-#define REG_C3H 0x2C
-#define REG_C3M 0x2E
-#define REG_C3C 0x30
-#define REG_EED 0x32
-#define REG_EEC 0x34
+/*
+ * Register I/O map
+ */
+#define S526_TIMER_REG         0x00
+#define S526_TIMER_LOAD(x)     (((x) & 0xff) << 8)
+#define S526_TIMER_MODE                ((x) << 1)
+#define S526_TIMER_MANUAL      S526_TIMER_MODE(0)
+#define S526_TIMER_AUTO                S526_TIMER_MODE(1)
+#define S526_TIMER_RESTART     BIT(0)
+#define S526_WDOG_REG          0x02
+#define S526_WDOG_INVERTED     BIT(4)
+#define S526_WDOG_ENA          BIT(3)
+#define S526_WDOG_INTERVAL(x)  (((x) & 0x7) << 0)
+#define S526_AO_CTRL_REG       0x04
+#define S526_AO_CTRL_RESET     BIT(3)
+#define S526_AO_CTRL_CHAN(x)   (((x) & 0x3) << 1)
+#define S526_AO_CTRL_START     BIT(0)
+#define S526_AI_CTRL_REG       0x06
+#define S526_AI_CTRL_DELAY     BIT(15)
+#define S526_AI_CTRL_CONV(x)   (1 << (5 + ((x) & 0x9)))
+#define S526_AI_CTRL_READ(x)   (((x) & 0xf) << 1)
+#define S526_AI_CTRL_START     BIT(0)
+#define S526_AO_REG            0x08
+#define S526_AI_REG            0x08
+#define S526_DIO_CTRL_REG      0x0a
+#define S526_DIO_CTRL_DIO3_NEG BIT(15) /* irq on DIO3 neg/pos edge */
+#define S526_DIO_CTRL_DIO2_NEG BIT(14) /* irq on DIO2 neg/pos edge */
+#define S526_DIO_CTRL_DIO1_NEG BIT(13) /* irq on DIO1 neg/pos edge */
+#define S526_DIO_CTRL_DIO0_NEG BIT(12) /* irq on DIO0 neg/pos edge */
+#define S526_DIO_CTRL_GRP2_OUT BIT(11)
+#define S526_DIO_CTRL_GRP1_OUT BIT(10)
+#define S526_DIO_CTRL_GRP2_NEG BIT(8)  /* irq on DIO[4-7] neg/pos edge */
+#define S526_INT_ENA_REG       0x0c
+#define S526_INT_STATUS_REG    0x0e
+#define S526_INT_DIO(x)                BIT(8 + ((x) & 0x7))
+#define S526_INT_EEPROM                BIT(7)  /* status only */
+#define S526_INT_CNTR(x)       BIT(3 + (3 - ((x) & 0x3)))
+#define S526_INT_AI            BIT(2)
+#define S526_INT_AO            BIT(1)
+#define S526_INT_TIMER         BIT(0)
+#define S526_MISC_REG          0x10
+#define S526_MISC_LED_OFF      BIT(0)
+#define S526_GPCT_LSB_REG(x)   (0x12 + ((x) * 8))
+#define S526_GPCT_MSB_REG(x)   (0x14 + ((x) * 8))
+#define S526_GPCT_MODE_REG(x)  (0x16 + ((x) * 8))
+#define S526_GPCT_CTRL_REG(x)  (0x18 + ((x) * 8))
+#define S526_EEPROM_DATA_REG   0x32
+#define S526_EEPROM_CTRL_REG   0x34
+#define S526_EEPROM_CTRL_ADDR(x) (((x) & 0x3f) << 3)
+#define S526_EEPROM_CTRL(x)    (((x) & 0x3) << 1)
+#define S526_EEPROM_CTRL_READ  S526_EEPROM_CTRL(2)
+#define S526_EEPROM_CTRL_START BIT(0)
 
 struct counter_mode_register_t {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
@@ -112,27 +129,39 @@ union cmReg {
 
 struct s526_private {
        unsigned int gpct_config[4];
-       unsigned short ai_config;
+       unsigned short ai_ctrl;
 };
 
+static void s526_gpct_write(struct comedi_device *dev,
+                           unsigned int chan, unsigned int val)
+{
+       /* write high word then low word */
+       outw((val >> 16) & 0xffff, dev->iobase + S526_GPCT_MSB_REG(chan));
+       outw(val & 0xffff, dev->iobase + S526_GPCT_LSB_REG(chan));
+}
+
+static unsigned int s526_gpct_read(struct comedi_device *dev,
+                                  unsigned int chan)
+{
+       unsigned int val;
+
+       /* read the low word then high word */
+       val = inw(dev->iobase + S526_GPCT_LSB_REG(chan)) & 0xffff;
+       val |= (inw(dev->iobase + S526_GPCT_MSB_REG(chan)) & 0xff) << 16;
+
+       return val;
+}
+
 static int s526_gpct_rinsn(struct comedi_device *dev,
                           struct comedi_subdevice *s,
                           struct comedi_insn *insn,
                           unsigned int *data)
 {
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned long chan_iobase = dev->iobase + chan * 8;
-       unsigned int lo;
-       unsigned int hi;
        int i;
 
-       for (i = 0; i < insn->n; i++) {
-               /* Read the low word first */
-               lo = inw(chan_iobase + REG_C0L) & 0xffff;
-               hi = inw(chan_iobase + REG_C0H) & 0xff;
-
-               data[i] = (hi << 16) | lo;
-       }
+       for (i = 0; i < insn->n; i++)
+               data[i] = s526_gpct_read(dev, chan);
 
        return insn->n;
 }
@@ -144,63 +173,34 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
 {
        struct s526_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned long chan_iobase = dev->iobase + chan * 8;
        unsigned int val;
        union cmReg cmReg;
 
-       /*  Check what type of Counter the user requested, data[0] contains */
-       /*  the Application type */
+       /*
+        * Check what type of Counter the user requested
+        * data[0] contains the Application type
+        */
        switch (data[0]) {
        case INSN_CONFIG_GPCT_QUADRATURE_ENCODER:
                /*
-                  data[0]: Application Type
-                  data[1]: Counter Mode Register Value
-                  data[2]: Pre-load Register Value
-                  data[3]: Conter Control Register
+                * data[0]: Application Type
+                * data[1]: Counter Mode Register Value
+                * data[2]: Pre-load Register Value
+                * data[3]: Conter Control Register
                 */
                devpriv->gpct_config[chan] = data[0];
 
-#if 0
-               /*  Example of Counter Application */
-               /* One-shot (software trigger) */
-               cmReg.reg.coutSource = 0;       /*  out RCAP */
-               cmReg.reg.coutPolarity = 1;     /*  Polarity inverted */
-               cmReg.reg.autoLoadResetRcap = 0;/*  Auto load disabled */
-               cmReg.reg.hwCtEnableSource = 3; /*  NOT RCAP */
-               cmReg.reg.ctEnableCtrl = 2;     /*  Hardware */
-               cmReg.reg.clockSource = 2;      /*  Internal */
-               cmReg.reg.countDir = 1; /*  Down */
-               cmReg.reg.countDirCtrl = 1;     /*  Software */
-               cmReg.reg.outputRegLatchCtrl = 0;       /*  latch on read */
-               cmReg.reg.preloadRegSel = 0;    /*  PR0 */
-               cmReg.reg.reserved = 0;
-
-               outw(cmReg.value, chan_iobase + REG_C0M);
-
-               outw(0x0001, chan_iobase + REG_C0H);
-               outw(0x3C68, chan_iobase + REG_C0L);
-
-               /*  Reset the counter */
-               outw(0x8000, chan_iobase + REG_C0C);
-               /*  Load the counter from PR0 */
-               outw(0x4000, chan_iobase + REG_C0C);
-
-               /*  Reset RCAP (fires one-shot) */
-               outw(0x0008, chan_iobase + REG_C0C);
-
-#endif
-
 #if 1
                /*  Set Counter Mode Register */
                cmReg.value = data[1] & 0xffff;
-               outw(cmReg.value, chan_iobase + REG_C0M);
+               outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan));
 
                /*  Reset the counter if it is software preload */
                if (cmReg.reg.autoLoadResetRcap == 0) {
                        /*  Reset the counter */
-                       outw(0x8000, chan_iobase + REG_C0C);
+                       outw(0x8000, dev->iobase + S526_GPCT_CTRL_REG(chan));
                        /* Load the counter from PR0
-                        * outw(0x4000, chan_iobase + REG_C0C);
+                        * outw(0x4000, dev->iobase + S526_GPCT_CTRL_REG(chan));
                         */
                }
 #else
@@ -216,11 +216,13 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
                        cmReg.reg.clockSource = 0;
 
                /*  When to take into account the indexpulse: */
-               /*if (data[2] == GPCT_IndexPhaseLowLow) {
-               } else if (data[2] == GPCT_IndexPhaseLowHigh) {
-               } else if (data[2] == GPCT_IndexPhaseHighLow) {
-               } else if (data[2] == GPCT_IndexPhaseHighHigh) {
-               }*/
+               /*
+                * if (data[2] == GPCT_IndexPhaseLowLow) {
+                * } else if (data[2] == GPCT_IndexPhaseLowHigh) {
+                * } else if (data[2] == GPCT_IndexPhaseHighLow) {
+                * } else if (data[2] == GPCT_IndexPhaseHighHigh) {
+                * }
+                */
                /*  Take into account the index pulse? */
                if (data[3] == GPCT_RESET_COUNTER_ON_INDEX)
                        /*  Auto load with INDEX^ */
@@ -228,114 +230,89 @@ static int s526_gpct_insn_config(struct comedi_device *dev,
 
                /*  Set Counter Mode Register */
                cmReg.value = data[1] & 0xffff;
-               outw(cmReg.value, chan_iobase + REG_C0M);
-
-               /*  Load the pre-load register high word */
-               val = (data[2] >> 16) & 0xffff;
-               outw(val, chan_iobase + REG_C0H);
+               outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan));
 
-               /*  Load the pre-load register low word */
-               val = data[2] & 0xffff;
-               outw(val, chan_iobase + REG_C0L);
+               /*  Load the pre-load register */
+               s526_gpct_write(dev, chan, data[2]);
 
                /*  Write the Counter Control Register */
-               if (data[3]) {
-                       val = data[3] & 0xffff;
-                       outw(val, chan_iobase + REG_C0C);
-               }
+               if (data[3])
+                       outw(data[3] & 0xffff,
+                            dev->iobase + S526_GPCT_CTRL_REG(chan));
+
                /*  Reset the counter if it is software preload */
                if (cmReg.reg.autoLoadResetRcap == 0) {
                        /*  Reset the counter */
-                       outw(0x8000, chan_iobase + REG_C0C);
+                       outw(0x8000, dev->iobase + S526_GPCT_CTRL_REG(chan));
                        /*  Load the counter from PR0 */
-                       outw(0x4000, chan_iobase + REG_C0C);
+                       outw(0x4000, dev->iobase + S526_GPCT_CTRL_REG(chan));
                }
 #endif
                break;
 
        case INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR:
                /*
-                  data[0]: Application Type
-                  data[1]: Counter Mode Register Value
-                  data[2]: Pre-load Register 0 Value
-                  data[3]: Pre-load Register 1 Value
-                  data[4]: Conter Control Register
+                * data[0]: Application Type
+                * data[1]: Counter Mode Register Value
+                * data[2]: Pre-load Register 0 Value
+                * data[3]: Pre-load Register 1 Value
+                * data[4]: Conter Control Register
                 */
                devpriv->gpct_config[chan] = data[0];
 
                /*  Set Counter Mode Register */
                cmReg.value = data[1] & 0xffff;
                cmReg.reg.preloadRegSel = 0;    /*  PR0 */
-               outw(cmReg.value, chan_iobase + REG_C0M);
+               outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan));
 
-               /*  Load the pre-load register 0 high word */
-               val = (data[2] >> 16) & 0xffff;
-               outw(val, chan_iobase + REG_C0H);
-
-               /*  Load the pre-load register 0 low word */
-               val = data[2] & 0xffff;
-               outw(val, chan_iobase + REG_C0L);
+               /* Load the pre-load register 0 */
+               s526_gpct_write(dev, chan, data[2]);
 
                /*  Set Counter Mode Register */
                cmReg.value = data[1] & 0xffff;
                cmReg.reg.preloadRegSel = 1;    /*  PR1 */
-               outw(cmReg.value, chan_iobase + REG_C0M);
-
-               /*  Load the pre-load register 1 high word */
-               val = (data[3] >> 16) & 0xffff;
-               outw(val, chan_iobase + REG_C0H);
+               outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan));
 
-               /*  Load the pre-load register 1 low word */
-               val = data[3] & 0xffff;
-               outw(val, chan_iobase + REG_C0L);
+               /* Load the pre-load register 1 */
+               s526_gpct_write(dev, chan, data[3]);
 
                /*  Write the Counter Control Register */
                if (data[4]) {
                        val = data[4] & 0xffff;
-                       outw(val, chan_iobase + REG_C0C);
+                       outw(val, dev->iobase + S526_GPCT_CTRL_REG(chan));
                }
                break;
 
        case INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR:
                /*
-                  data[0]: Application Type
-                  data[1]: Counter Mode Register Value
-                  data[2]: Pre-load Register 0 Value
-                  data[3]: Pre-load Register 1 Value
-                  data[4]: Conter Control Register
+                * data[0]: Application Type
+                * data[1]: Counter Mode Register Value
+                * data[2]: Pre-load Register 0 Value
+                * data[3]: Pre-load Register 1 Value
+                * data[4]: Conter Control Register
                 */
                devpriv->gpct_config[chan] = data[0];
 
                /*  Set Counter Mode Register */
                cmReg.value = data[1] & 0xffff;
                cmReg.reg.preloadRegSel = 0;    /*  PR0 */
-               outw(cmReg.value, chan_iobase + REG_C0M);
+               outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan));
 
-               /*  Load the pre-load register 0 high word */
-               val = (data[2] >> 16) & 0xffff;
-               outw(val, chan_iobase + REG_C0H);
-
-               /*  Load the pre-load register 0 low word */
-               val = data[2] & 0xffff;
-               outw(val, chan_iobase + REG_C0L);
+               /* Load the pre-load register 0 */
+               s526_gpct_write(dev, chan, data[2]);
 
                /*  Set Counter Mode Register */
                cmReg.value = data[1] & 0xffff;
                cmReg.reg.preloadRegSel = 1;    /*  PR1 */
-               outw(cmReg.value, chan_iobase + REG_C0M);
-
-               /*  Load the pre-load register 1 high word */
-               val = (data[3] >> 16) & 0xffff;
-               outw(val, chan_iobase + REG_C0H);
+               outw(cmReg.value, dev->iobase + S526_GPCT_MODE_REG(chan));
 
-               /*  Load the pre-load register 1 low word */
-               val = data[3] & 0xffff;
-               outw(val, chan_iobase + REG_C0L);
+               /* Load the pre-load register 1 */
+               s526_gpct_write(dev, chan, data[3]);
 
                /*  Write the Counter Control Register */
                if (data[4]) {
                        val = data[4] & 0xffff;
-                       outw(val, chan_iobase + REG_C0C);
+                       outw(val, dev->iobase + S526_GPCT_CTRL_REG(chan));
                }
                break;
 
@@ -353,18 +330,18 @@ static int s526_gpct_winsn(struct comedi_device *dev,
 {
        struct s526_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned long chan_iobase = dev->iobase + chan * 8;
 
-       inw(chan_iobase + REG_C0M);     /* Is this read required? */
+       inw(dev->iobase + S526_GPCT_MODE_REG(chan));    /* Is this required? */
 
        /*  Check what Application of Counter this channel is configured for */
        switch (devpriv->gpct_config[chan]) {
        case INSN_CONFIG_GPCT_PULSE_TRAIN_GENERATOR:
-               /* data[0] contains the PULSE_WIDTH
-                  data[1] contains the PULSE_PERIOD
-                  @pre PULSE_PERIOD > PULSE_WIDTH > 0
-                  The above periods must be expressed as a multiple of the
-                  pulse frequency on the selected source
+               /*
+                * data[0] contains the PULSE_WIDTH
+                * data[1] contains the PULSE_PERIOD
+                * @pre PULSE_PERIOD > PULSE_WIDTH > 0
+                * The above periods must be expressed as a multiple of the
+                * pulse frequency on the selected source
                 */
                if ((data[1] <= data[0]) || !data[0])
                        return -EINVAL;
@@ -373,8 +350,7 @@ static int s526_gpct_winsn(struct comedi_device *dev,
 
        case INSN_CONFIG_GPCT_QUADRATURE_ENCODER:
        case INSN_CONFIG_GPCT_SINGLE_PULSE_GENERATOR:
-               outw((data[0] >> 16) & 0xffff, chan_iobase + REG_C0H);
-               outw(data[0] & 0xffff, chan_iobase + REG_C0L);
+               s526_gpct_write(dev, chan, data[0]);
                break;
 
        default:
@@ -384,86 +360,60 @@ static int s526_gpct_winsn(struct comedi_device *dev,
        return insn->n;
 }
 
-#define ISR_ADC_DONE 0x4
-static int s526_ai_insn_config(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
-{
-       struct s526_private *devpriv = dev->private;
-       int result = -EINVAL;
-
-       if (insn->n < 1)
-               return result;
-
-       result = insn->n;
-
-       /* data[0] : channels was set in relevant bits.
-          data[1] : delay
-        */
-       /* COMMENT: abbotti 2008-07-24: I don't know why you'd want to
-        * enable channels here.  The channel should be enabled in the
-        * INSN_READ handler. */
-
-       /*  Enable ADC interrupt */
-       outw(ISR_ADC_DONE, dev->iobase + REG_IER);
-       devpriv->ai_config = (data[0] & 0x3ff) << 5;
-       if (data[1] > 0)
-               devpriv->ai_config |= 0x8000;   /* set the delay */
-
-       devpriv->ai_config |= 0x0001;           /* ADC start bit */
-
-       return result;
-}
-
-static int s526_ai_eoc(struct comedi_device *dev,
-                      struct comedi_subdevice *s,
-                      struct comedi_insn *insn,
-                      unsigned long context)
+static int s526_eoc(struct comedi_device *dev,
+                   struct comedi_subdevice *s,
+                   struct comedi_insn *insn,
+                   unsigned long context)
 {
        unsigned int status;
 
-       status = inw(dev->iobase + REG_ISR);
-       if (status & ISR_ADC_DONE)
+       status = inw(dev->iobase + S526_INT_STATUS_REG);
+       if (status & context) {
+               /* we got our eoc event, clear it */
+               outw(context, dev->iobase + S526_INT_STATUS_REG);
                return 0;
+       }
        return -EBUSY;
 }
 
-static int s526_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                        struct comedi_insn *insn, unsigned int *data)
+static int s526_ai_insn_read(struct comedi_device *dev,
+                            struct comedi_subdevice *s,
+                            struct comedi_insn *insn,
+                            unsigned int *data)
 {
        struct s526_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       int n;
-       unsigned short value;
-       unsigned int d;
+       unsigned int ctrl;
+       unsigned int val;
        int ret;
+       int i;
 
-       /* Set configured delay, enable channel for this channel only,
-        * select "ADC read" channel, set "ADC start" bit. */
-       value = (devpriv->ai_config & 0x8000) |
-               ((1 << 5) << chan) | (chan << 1) | 0x0001;
+       ctrl = S526_AI_CTRL_CONV(chan) | S526_AI_CTRL_READ(chan) |
+              S526_AI_CTRL_START;
+       if (ctrl != devpriv->ai_ctrl) {
+               /*
+                * The multiplexor needs to change, enable the 15us
+                * delay for the first sample.
+                */
+               devpriv->ai_ctrl = ctrl;
+               ctrl |= S526_AI_CTRL_DELAY;
+       }
 
-       /* convert n samples */
-       for (n = 0; n < insn->n; n++) {
+       for (i = 0; i < insn->n; i++) {
                /* trigger conversion */
-               outw(value, dev->iobase + REG_ADC);
+               outw(ctrl, dev->iobase + S526_AI_CTRL_REG);
+               ctrl &= ~S526_AI_CTRL_DELAY;
 
                /* wait for conversion to end */
-               ret = comedi_timeout(dev, s, insn, s526_ai_eoc, 0);
+               ret = comedi_timeout(dev, s, insn, s526_eoc, S526_INT_AI);
                if (ret)
                        return ret;
 
-               outw(ISR_ADC_DONE, dev->iobase + REG_ISR);
-
-               /* read data */
-               d = inw(dev->iobase + REG_ADD);
-
-               /* munge data */
-               data[n] = d ^ 0x8000;
+               val = inw(dev->iobase + S526_AI_REG);
+               data[i] = comedi_offset_munge(s, val);
        }
 
-       /* return the number of samples read/written */
-       return n;
+       return insn->n;
 }
 
 static int s526_ao_insn_write(struct comedi_device *dev,
@@ -472,16 +422,23 @@ static int s526_ao_insn_write(struct comedi_device *dev,
                              unsigned int *data)
 {
        unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int ctrl = S526_AO_CTRL_CHAN(chan);
        unsigned int val = s->readback[chan];
+       int ret;
        int i;
 
-       outw(chan << 1, dev->iobase + REG_DAC);
+       outw(ctrl, dev->iobase + S526_AO_CTRL_REG);
+       ctrl |= S526_AO_CTRL_START;
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               outw(val, dev->iobase + REG_ADD);
-               /* starts the D/A conversion */
-               outw((chan << 1) | 1, dev->iobase + REG_DAC);
+               outw(val, dev->iobase + S526_AO_REG);
+               outw(ctrl, dev->iobase + S526_AO_CTRL_REG);
+
+               /* wait for conversion to end */
+               ret = comedi_timeout(dev, s, insn, s526_eoc, S526_INT_AO);
+               if (ret)
+                       return ret;
        }
        s->readback[chan] = val;
 
@@ -494,9 +451,9 @@ static int s526_dio_insn_bits(struct comedi_device *dev,
                              unsigned int *data)
 {
        if (comedi_dio_update_state(s, data))
-               outw(s->state, dev->iobase + REG_DIO);
+               outw(s->state, dev->iobase + S526_DIO_CTRL_REG);
 
-       data[1] = inw(dev->iobase + REG_DIO) & 0xff;
+       data[1] = inw(dev->iobase + S526_DIO_CTRL_REG) & 0xff;
 
        return insn->n;
 }
@@ -510,6 +467,10 @@ static int s526_dio_insn_config(struct comedi_device *dev,
        unsigned int mask;
        int ret;
 
+       /*
+        * Digital I/O can be configured as inputs or outputs in
+        * groups of 4; DIO group 1 (DIO0-3) and DIO group 2 (DIO4-7).
+        */
        if (chan < 4)
                mask = 0x0f;
        else
@@ -519,17 +480,16 @@ static int s526_dio_insn_config(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       /* bit 10/11 set the group 1/2's mode */
        if (s->io_bits & 0x0f)
-               s->state |= (1 << 10);
+               s->state |= S526_DIO_CTRL_GRP1_OUT;
        else
-               s->state &= ~(1 << 10);
+               s->state &= ~S526_DIO_CTRL_GRP1_OUT;
        if (s->io_bits & 0xf0)
-               s->state |= (1 << 11);
+               s->state |= S526_DIO_CTRL_GRP2_OUT;
        else
-               s->state &= ~(1 << 11);
+               s->state &= ~S526_DIO_CTRL_GRP2_OUT;
 
-       outw(s->state, dev->iobase + REG_DIO);
+       outw(s->state, dev->iobase + S526_DIO_CTRL_REG);
 
        return insn->n;
 }
@@ -552,51 +512,53 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        if (ret)
                return ret;
 
+       /* General-Purpose Counter/Timer (GPCT) */
        s = &dev->subdevices[0];
-       /* GENERAL-PURPOSE COUNTER/TIME (GPCT) */
-       s->type = COMEDI_SUBD_COUNTER;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
-       s->n_chan = 4;
-       s->maxdata = 0x00ffffff;        /* 24 bit counter */
-       s->insn_read = s526_gpct_rinsn;
-       s->insn_config = s526_gpct_insn_config;
-       s->insn_write = s526_gpct_winsn;
-
+       s->type         = COMEDI_SUBD_COUNTER;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
+       s->n_chan       = 4;
+       s->maxdata      = 0x00ffffff;
+       s->insn_read    = s526_gpct_rinsn;
+       s->insn_config  = s526_gpct_insn_config;
+       s->insn_write   = s526_gpct_winsn;
+
+       /*
+        * Analog Input subdevice
+        * channels 0 to 7 are the regular differential inputs
+        * channel 8 is "reference 0" (+10V)
+        * channel 9 is "reference 1" (0V)
+        */
        s = &dev->subdevices[1];
-       /* analog input subdevice */
-       s->type = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_DIFF;
-       /* channels 0 to 7 are the regular differential inputs */
-       /* channel 8 is "reference 0" (+10V), channel 9 is "reference 1" (0V) */
-       s->n_chan = 10;
-       s->maxdata = 0xffff;
-       s->range_table = &range_bipolar10;
-       s->len_chanlist = 16;
-       s->insn_read = s526_ai_rinsn;
-       s->insn_config = s526_ai_insn_config;
-
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_DIFF;
+       s->n_chan       = 10;
+       s->maxdata      = 0xffff;
+       s->range_table  = &range_bipolar10;
+       s->len_chanlist = 16;
+       s->insn_read    = s526_ai_insn_read;
+
+       /* Analog Output subdevice */
        s = &dev->subdevices[2];
-       /* analog output subdevice */
-       s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_WRITABLE;
-       s->n_chan = 4;
-       s->maxdata = 0xffff;
-       s->range_table = &range_bipolar10;
-       s->insn_write = s526_ao_insn_write;
+       s->type         = COMEDI_SUBD_AO;
+       s->subdev_flags = SDF_WRITABLE;
+       s->n_chan       = 4;
+       s->maxdata      = 0xffff;
+       s->range_table  = &range_bipolar10;
+       s->insn_write   = s526_ao_insn_write;
 
        ret = comedi_alloc_subdev_readback(s);
        if (ret)
                return ret;
 
+       /* Digital I/O subdevice */
        s = &dev->subdevices[3];
-       /* digital i/o subdevice */
-       s->type = COMEDI_SUBD_DIO;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan = 8;
-       s->maxdata = 1;
-       s->range_table = &range_digital;
-       s->insn_bits = s526_dio_insn_bits;
-       s->insn_config = s526_dio_insn_config;
+       s->type         = COMEDI_SUBD_DIO;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
+       s->n_chan       = 8;
+       s->maxdata      = 1;
+       s->range_table  = &range_digital;
+       s->insn_bits    = s526_dio_insn_bits;
+       s->insn_config  = s526_dio_insn_config;
 
        return 0;
 }
index 5f19374c460de63f4431ca3bd73d241a0ba37c76..7a1defcf210233e7c2d7a03ca290caddb5cc96ed 100644 (file)
@@ -1,30 +1,29 @@
 /*
   comedi/drivers/serial2002.c
-    Skeleton code for a Comedi driver
-
   COMEDI - Linux Control and Measurement Device Interface
   Copyright (C) 2002 Anders Blomdell <anders.blomdell@control.lth.se>
-
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-*/
serial2002.c
+ * Comedi driver for serial connected hardware
+ *
* COMEDI - Linux Control and Measurement Device Interface
* Copyright (C) 2002 Anders Blomdell <anders.blomdell@control.lth.se>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
+ */
 
 /*
-Driver: serial2002
-Description: Driver for serial connected hardware
-Devices:
-Author: Anders Blomdell
-Updated: Fri,  7 Jun 2002 12:56:45 -0700
-Status: in development
-
-*/
+ * Driver: serial2002
+ * Description: Driver for serial connected hardware
+ * Devices:
+ * Author: Anders Blomdell
+ * Updated: Fri,  7 Jun 2002 12:56:45 -0700
+ * Status: in development
+ */
 
 #include <linux/module.h>
 #include "../comedidev.h"
@@ -102,7 +101,7 @@ static long serial2002_tty_ioctl(struct file *f, unsigned op,
        if (f->f_op->unlocked_ioctl)
                return f->f_op->unlocked_ioctl(f, op, param);
 
-       return -ENOSYS;
+       return -ENOTTY;
 }
 
 static int serial2002_tty_write(struct file *f, unsigned char *buf, int count)
@@ -176,7 +175,7 @@ static int serial2002_tty_read(struct file *f, int timeout)
                                        result = ch;
                                        break;
                                }
-                               udelay(100);
+                               usleep_range(100, 1000);
                        }
                }
                set_fs(oldfs);
index acc7f3445c583e426253138f7fba68e36e9c7b98..f9f634fd53cf86fce12ee2fbece4481cdbd74bdd 100644 (file)
@@ -1,28 +1,29 @@
 /*
-    comedi/drivers/ssv_dnp.c
-    generic comedi driver for SSV Embedded Systems' DIL/Net-PCs
-    Copyright (C) 2001 Robert Schwebel <robert@schwebel.de>
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
+ * ssv_dnp.c
+ * generic comedi driver for SSV Embedded Systems' DIL/Net-PCs
+ * Copyright (C) 2001 Robert Schwebel <robert@schwebel.de>
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
 /*
-Driver: ssv_dnp
-Description: SSV Embedded Systems DIL/Net-PC
-Author: Robert Schwebel <robert@schwebel.de>
-Devices: [SSV Embedded Systems] DIL/Net-PC 1486 (dnp-1486)
-Status: unknown
-*/
+ * Driver: ssv_dnp
+ * Description: SSV Embedded Systems DIL/Net-PC
+ * Author: Robert Schwebel <robert@schwebel.de>
+ * Devices: [SSV Embedded Systems] DIL/Net-PC 1486 (dnp-1486)
+ * Status: unknown
+ */
 
 /* include files ----------------------------------------------------------- */
 
@@ -134,6 +135,12 @@ static int dnp_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        struct comedi_subdevice *s;
        int ret;
 
+       /*
+        * We use I/O ports 0x22, 0x23 and 0xa3-0xa9, which are always
+        * allocated for the primary 8259, so we don't need to allocate
+        * them ourselves.
+        */
+
        ret = comedi_alloc_subdevices(dev, 1);
        if (ret)
                return ret;
@@ -148,10 +155,6 @@ static int dnp_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        s->insn_bits = dnp_dio_insn_bits;
        s->insn_config = dnp_dio_insn_config;
 
-       /* We use the I/O ports 0x22,0x23 and 0xa3-0xa9, which are always
-        * allocated for the primary 8259, so we don't need to allocate them
-        * ourselves. */
-
        /* configure all ports as input (default)                            */
        outb(PAMR, CSCIR);
        outb(0x00, CSCDR);
diff --git a/drivers/staging/comedi/drivers/unioxx5.c b/drivers/staging/comedi/drivers/unioxx5.c
deleted file mode 100644 (file)
index 51498b8..0000000
+++ /dev/null
@@ -1,506 +0,0 @@
-/***************************************************************************
- *                                                                         *
- *  comedi/drivers/unioxx5.c                                               *
- *  Driver for Fastwel UNIOxx-5 (analog and digital i/o) boards.           *
- *                                                                         *
- *  Copyright (C) 2006 Kruchinin Daniil (asgard) [asgard@etersoft.ru]      *
- *                                                                         *
- *  COMEDI - Linux Control and Measurement Device Interface                *
- *  Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>              *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
- *  GNU General Public License for more details.                           *
- *                                                                         *
- ***************************************************************************/
-/*
-
-Driver: unioxx5
-Description: Driver for Fastwel UNIOxx-5 (analog and digital i/o) boards.
-Author: Kruchinin Daniil (asgard) <asgard@etersoft.ru>
-Status: unknown
-Updated: 2006-10-09
-Devices: [Fastwel] UNIOxx-5 (unioxx5),
-
- This card supports digital and analog I/O. It written for g01
- subdevices only.
- channels range: 0 .. 23 dio channels
- and 0 .. 11 analog modules range
- During attaching unioxx5 module displays modules identifiers
- (see dmesg after comedi_config) in format:
- | [module_number] module_id |
-
-*/
-
-#include <linux/module.h>
-#include <linux/delay.h>
-#include "../comedidev.h"
-
-#define UNIOXX5_SIZE 0x10
-#define UNIOXX5_SUBDEV_BASE 0xA000     /* base addr of first subdev */
-#define UNIOXX5_SUBDEV_ODDS 0x400
-
-/* modules types */
-#define MODULE_DIGITAL 0
-#define MODULE_OUTPUT_MASK 0x80        /* analog input/output */
-
-/* constants for digital i/o */
-#define UNIOXX5_NUM_OF_CHANS 24
-
-/* constants for analog i/o */
-#define TxBE  0x10             /* transmit buffer enable */
-#define RxCA  0x20             /* 1 receive character available */
-#define Rx2CA 0x40             /* 2 receive character available */
-#define Rx4CA 0x80             /* 4 receive character available */
-
-/* bytes mask errors */
-#define Rx2CA_ERR_MASK 0x04    /* 2 bytes receiving error */
-#define Rx4CA_ERR_MASK 0x08    /* 4 bytes receiving error */
-
-/* channel modes */
-#define ALL_2_INPUT  0         /* config all digital channels to input */
-#define ALL_2_OUTPUT 1         /* config all digital channels to output */
-
-/* 'private' structure for each subdevice */
-struct unioxx5_subd_priv {
-       int usp_iobase;
-       /* 12 modules. each can be 70L or 73L */
-       unsigned char usp_module_type[12];
-       /* for saving previous written value for analog modules */
-       unsigned char usp_extra_data[12][4];
-       unsigned char usp_prev_wr_val[3];       /* previous written value */
-       unsigned char usp_prev_cn_val[3];       /* previous channel value */
-};
-
-static int __unioxx5_define_chan_offset(int chan_num)
-{
-       if (chan_num < 0 || chan_num > 23)
-               return -1;
-
-       return (chan_num >> 3) + 1;
-}
-
-#if 0                          /* not used? */
-static void __unioxx5_digital_config(struct comedi_subdevice *s, int mode)
-{
-       struct unioxx5_subd_priv *usp = s->private;
-       struct device *csdev = s->device->class_dev;
-       int i, mask;
-
-       mask = (mode == ALL_2_OUTPUT) ? 0xFF : 0x00;
-       dev_dbg(csdev, "mode = %d\n", mask);
-
-       outb(1, usp->usp_iobase + 0);
-
-       for (i = 0; i < 3; i++)
-               outb(mask, usp->usp_iobase + i);
-
-       outb(0, usp->usp_iobase + 0);
-}
-#endif
-
-/* configure channels for analog i/o (even to output, odd to input) */
-static void __unioxx5_analog_config(struct unioxx5_subd_priv *usp, int channel)
-{
-       int chan_a, chan_b, conf, channel_offset;
-
-       channel_offset = __unioxx5_define_chan_offset(channel);
-       conf = usp->usp_prev_cn_val[channel_offset - 1];
-       chan_a = chan_b = 1;
-
-       /* setting channel A and channel B mask */
-       if (channel % 2 == 0) {
-               chan_a <<= channel & 0x07;
-               chan_b <<= (channel + 1) & 0x07;
-       } else {
-               chan_a <<= (channel - 1) & 0x07;
-               chan_b <<= channel & 0x07;
-       }
-
-       conf |= chan_a;         /* even channel ot output */
-       conf &= ~chan_b;        /* odd channel to input */
-
-       outb(1, usp->usp_iobase + 0);
-       outb(conf, usp->usp_iobase + channel_offset);
-       outb(0, usp->usp_iobase + 0);
-
-       usp->usp_prev_cn_val[channel_offset - 1] = conf;
-}
-
-static int __unioxx5_digital_read(struct comedi_subdevice *s,
-                                 unsigned int *data, int channel, int minor)
-{
-       struct unioxx5_subd_priv *usp = s->private;
-       struct device *csdev = s->device->class_dev;
-       int channel_offset, mask = 1 << (channel & 0x07);
-
-       channel_offset = __unioxx5_define_chan_offset(channel);
-       if (channel_offset < 0) {
-               dev_err(csdev,
-                       "undefined channel %d. channel range is 0 .. 23\n",
-                       channel);
-               return 0;
-       }
-
-       *data = inb(usp->usp_iobase + channel_offset);
-       *data &= mask;
-
-       /* correct the read value to 0 or 1 */
-       if (channel_offset > 1)
-               channel -= 2 << channel_offset;
-       *data >>= channel;
-       return 1;
-}
-
-static int __unioxx5_analog_read(struct comedi_subdevice *s,
-                                unsigned int *data, int channel, int minor)
-{
-       struct unioxx5_subd_priv *usp = s->private;
-       struct device *csdev = s->device->class_dev;
-       int module_no, read_ch;
-       char control;
-
-       module_no = channel / 2;
-       read_ch = channel % 2;  /* depend on type of channel (A or B) */
-
-       /* defining if given module can work on input */
-       if (usp->usp_module_type[module_no] & MODULE_OUTPUT_MASK) {
-               dev_err(csdev,
-                       "module in position %d with id 0x%02x is for output only",
-                       module_no, usp->usp_module_type[module_no]);
-               return 0;
-       }
-
-       __unioxx5_analog_config(usp, channel);
-       /* sends module number to card(1 .. 12) */
-       outb(module_no + 1, usp->usp_iobase + 5);
-       outb('V', usp->usp_iobase + 6); /* sends to module (V)erify command */
-       control = inb(usp->usp_iobase); /* get control register byte */
-
-       /* waits while reading four bytes will be allowed */
-       while (!((control = inb(usp->usp_iobase + 0)) & Rx4CA))
-               ;
-
-       /* if four bytes readding error occurs - return 0(false) */
-       if ((control & Rx4CA_ERR_MASK)) {
-               dev_err(csdev, "4 bytes error\n");
-               return 0;
-       }
-
-       if (read_ch)
-               *data = inw(usp->usp_iobase + 6);       /* channel B */
-       else
-               *data = inw(usp->usp_iobase + 4);       /* channel A */
-
-       return 1;
-}
-
-static int __unioxx5_digital_write(struct comedi_subdevice *s,
-                                  unsigned int *data, int channel, int minor)
-{
-       struct unioxx5_subd_priv *usp = s->private;
-       struct device *csdev = s->device->class_dev;
-       int channel_offset, val;
-       int mask = 1 << (channel & 0x07);
-
-       channel_offset = __unioxx5_define_chan_offset(channel);
-       if (channel_offset < 0) {
-               dev_err(csdev,
-                       "undefined channel %d. channel range is 0 .. 23\n",
-                       channel);
-               return 0;
-       }
-
-       /* getting previous written value */
-       val = usp->usp_prev_wr_val[channel_offset - 1];
-
-       if (*data)
-               val |= mask;
-       else
-               val &= ~mask;
-
-       outb(val, usp->usp_iobase + channel_offset);
-       /* saving new written value */
-       usp->usp_prev_wr_val[channel_offset - 1] = val;
-
-       return 1;
-}
-
-static int __unioxx5_analog_write(struct comedi_subdevice *s,
-                                 unsigned int *data, int channel, int minor)
-{
-       struct unioxx5_subd_priv *usp = s->private;
-       struct device *csdev = s->device->class_dev;
-       int module, i;
-
-       module = channel / 2;   /* definig module number(0 .. 11) */
-       i = (channel % 2) << 1; /* depends on type of channel (A or B) */
-
-       /* defining if given module can work on output */
-       if (!(usp->usp_module_type[module] & MODULE_OUTPUT_MASK)) {
-               dev_err(csdev,
-                       "module in position %d with id 0x%0x is for input only!\n",
-                       module, usp->usp_module_type[module]);
-               return 0;
-       }
-
-       __unioxx5_analog_config(usp, channel);
-       /* saving minor byte */
-       usp->usp_extra_data[module][i++] = (unsigned char)(*data & 0x00FF);
-       /* saving major byte */
-       usp->usp_extra_data[module][i] = (unsigned char)((*data & 0xFF00) >> 8);
-
-       /* while(!((inb(usp->usp_iobase + 0)) & TxBE)); */
-       /* sending module number to card(1 .. 12) */
-       outb(module + 1, usp->usp_iobase + 5);
-       outb('W', usp->usp_iobase + 6); /* sends (W)rite command to module */
-
-       /* sending for bytes to module(one byte per cycle iteration) */
-       for (i = 0; i < 4; i++) {
-               while (!((inb(usp->usp_iobase + 0)) & TxBE))
-                       ;       /* waits while writing will be allowed */
-               outb(usp->usp_extra_data[module][i], usp->usp_iobase + 6);
-       }
-
-       return 1;
-}
-
-static int unioxx5_subdev_read(struct comedi_device *dev,
-                              struct comedi_subdevice *subdev,
-                              struct comedi_insn *insn, unsigned int *data)
-{
-       struct unioxx5_subd_priv *usp = subdev->private;
-       int channel, type;
-
-       channel = CR_CHAN(insn->chanspec);
-       /* defining module type(analog or digital) */
-       type = usp->usp_module_type[channel / 2];
-
-       if (type == MODULE_DIGITAL) {
-               if (!__unioxx5_digital_read(subdev, data, channel, dev->minor))
-                       return -1;
-       } else {
-               if (!__unioxx5_analog_read(subdev, data, channel, dev->minor))
-                       return -1;
-       }
-
-       return 1;
-}
-
-static int unioxx5_subdev_write(struct comedi_device *dev,
-                               struct comedi_subdevice *subdev,
-                               struct comedi_insn *insn, unsigned int *data)
-{
-       struct unioxx5_subd_priv *usp = subdev->private;
-       int channel, type;
-
-       channel = CR_CHAN(insn->chanspec);
-       /* defining module type(analog or digital) */
-       type = usp->usp_module_type[channel / 2];
-
-       if (type == MODULE_DIGITAL) {
-               if (!__unioxx5_digital_write(subdev, data, channel, dev->minor))
-                       return -1;
-       } else {
-               if (!__unioxx5_analog_write(subdev, data, channel, dev->minor))
-                       return -1;
-       }
-
-       return 1;
-}
-
-/* for digital modules only */
-static int unioxx5_insn_config(struct comedi_device *dev,
-                              struct comedi_subdevice *subdev,
-                              struct comedi_insn *insn, unsigned int *data)
-{
-       int channel_offset, flags, channel = CR_CHAN(insn->chanspec), type;
-       struct unioxx5_subd_priv *usp = subdev->private;
-       int mask = 1 << (channel & 0x07);
-
-       type = usp->usp_module_type[channel / 2];
-
-       if (type != MODULE_DIGITAL) {
-               dev_err(dev->class_dev,
-                       "channel configuration accessible only for digital modules\n");
-               return -1;
-       }
-
-       channel_offset = __unioxx5_define_chan_offset(channel);
-       if (channel_offset < 0) {
-               dev_err(dev->class_dev,
-                       "undefined channel %d. channel range is 0 .. 23\n",
-                       channel);
-               return -1;
-       }
-
-       /* gets previously written value */
-       flags = usp->usp_prev_cn_val[channel_offset - 1];
-
-       switch (*data) {
-       case COMEDI_INPUT:
-               flags &= ~mask;
-               break;
-       case COMEDI_OUTPUT:
-               flags |= mask;
-               break;
-       default:
-               dev_err(dev->class_dev, "unknown flag\n");
-               return -1;
-       }
-
-       /*                                                        *\
-        * sets channels buffer to 1(after this we are allowed to *
-        * change channel type on input or output)                *
-        \*                                                        */
-       outb(1, usp->usp_iobase + 0);
-       /* changes type of _one_ channel */
-       outb(flags, usp->usp_iobase + channel_offset);
-       /* sets channels bank to 0(allows directly input/output) */
-       outb(0, usp->usp_iobase + 0);
-       /* saves written value */
-       usp->usp_prev_cn_val[channel_offset - 1] = flags;
-
-       return 0;
-}
-
-/* initializing subdevice with given address */
-static int __unioxx5_subdev_init(struct comedi_device *dev,
-                                struct comedi_subdevice *s,
-                                int iobase)
-{
-       struct unioxx5_subd_priv *usp;
-       int i, to, ndef_flag = 0;
-       int ret;
-
-       usp = comedi_alloc_spriv(s, sizeof(*usp));
-       if (!usp)
-               return -ENOMEM;
-
-       ret = __comedi_request_region(dev, iobase, UNIOXX5_SIZE);
-       if (ret)
-               return ret;
-       usp->usp_iobase = iobase;
-
-       /* defining modules types */
-       for (i = 0; i < 12; i++) {
-               to = 10000;
-
-               __unioxx5_analog_config(usp, i * 2);
-               /* sends channel number to card */
-               outb(i + 1, iobase + 5);
-               outb('H', iobase + 6);  /* requests EEPROM world */
-               while (!(inb(iobase + 0) & TxBE))
-                       ;       /* waits while writing will be allowed */
-               outb(0, iobase + 6);
-
-               /* waits while reading of two bytes will be allowed */
-               while (!(inb(iobase + 0) & Rx2CA)) {
-                       if (--to <= 0) {
-                               ndef_flag = 1;
-                               break;
-                       }
-               }
-
-               if (ndef_flag) {
-                       usp->usp_module_type[i] = 0;
-                       ndef_flag = 0;
-               } else {
-                       usp->usp_module_type[i] = inb(iobase + 6);
-               }
-
-               udelay(1);
-       }
-
-       /* initial subdevice for digital or analog i/o */
-       s->type = COMEDI_SUBD_DIO;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
-       s->n_chan = UNIOXX5_NUM_OF_CHANS;
-       s->maxdata = 0xFFF;
-       s->range_table = &range_digital;
-       s->insn_read = unioxx5_subdev_read;
-       s->insn_write = unioxx5_subdev_write;
-       /* for digital modules only!!! */
-       s->insn_config = unioxx5_insn_config;
-
-       return 0;
-}
-
-static int unioxx5_attach(struct comedi_device *dev,
-                         struct comedi_devconfig *it)
-{
-       struct comedi_subdevice *s;
-       int iobase, i, n_subd;
-       int id, num, ba;
-       int ret;
-
-       iobase = it->options[0];
-
-       dev->iobase = iobase;
-       iobase += UNIOXX5_SUBDEV_BASE;
-       n_subd = 0;
-
-       /* getting number of subdevices with types 'g01' */
-       for (i = 0, ba = iobase; i < 4; i++, ba += UNIOXX5_SUBDEV_ODDS) {
-               id = inb(ba + 0xE);
-               num = inb(ba + 0xF);
-
-               if (id != 'g' || num != 1)
-                       continue;
-
-               n_subd++;
-       }
-
-       /* unioxx5 can has from two to four subdevices */
-       if (n_subd < 2) {
-               dev_err(dev->class_dev,
-                       "your card must has at least 2 'g01' subdevices\n");
-               return -1;
-       }
-
-       ret = comedi_alloc_subdevices(dev, n_subd);
-       if (ret)
-               return ret;
-
-       /* initializing each of for same subdevices */
-       for (i = 0; i < n_subd; i++, iobase += UNIOXX5_SUBDEV_ODDS) {
-               s = &dev->subdevices[i];
-               ret = __unioxx5_subdev_init(dev, s, iobase);
-               if (ret)
-                       return ret;
-       }
-
-       return 0;
-}
-
-static void unioxx5_detach(struct comedi_device *dev)
-{
-       struct comedi_subdevice *s;
-       struct unioxx5_subd_priv *spriv;
-       int i;
-
-       for (i = 0; i < dev->n_subdevices; i++) {
-               s = &dev->subdevices[i];
-               spriv = s->private;
-               if (spriv && spriv->usp_iobase)
-                       release_region(spriv->usp_iobase, UNIOXX5_SIZE);
-       }
-}
-
-static struct comedi_driver unioxx5_driver = {
-       .driver_name    = "unioxx5",
-       .module         = THIS_MODULE,
-       .attach         = unioxx5_attach,
-       .detach         = unioxx5_detach,
-};
-module_comedi_driver(unioxx5_driver);
-
-MODULE_AUTHOR("Comedi http://www.comedi.org");
-MODULE_DESCRIPTION("Comedi low-level driver");
-MODULE_LICENSE("GPL");
index ced05e581620997646d021005f7cf8629f2131c9..f4f05d29d30d6de689892e9e6e449952bfc675ee 100644 (file)
 #define BULK_TIMEOUT           1000
 
 /* 300Hz max frequ under PWM */
-#define MIN_PWM_PERIOD  ((long)(1E9/300))
+#define MIN_PWM_PERIOD         ((long)(1E9 / 300))
 
 /* Default PWM frequency */
-#define PWM_DEFAULT_PERIOD ((long)(1E9/100))
+#define PWM_DEFAULT_PERIOD     ((long)(1E9 / 100))
 
 /* Size of one A/D value */
-#define SIZEADIN          ((sizeof(uint16_t)))
+#define SIZEADIN               ((sizeof(u16)))
 
 /*
  * Size of the input-buffer IN BYTES
  * Always multiple of 8 for 8 microframes which is needed in the highspeed mode
  */
-#define SIZEINBUF         ((8*SIZEADIN))
+#define SIZEINBUF              (8 * SIZEADIN)
 
 /* 16 bytes. */
-#define SIZEINSNBUF       16
+#define SIZEINSNBUF            16
 
 /* size of one value for the D/A converter: channel and value */
-#define SIZEDAOUT          ((sizeof(uint8_t)+sizeof(uint16_t)))
+#define SIZEDAOUT              ((sizeof(u8) + sizeof(u16)))
 
 /*
  * Size of the output-buffer in bytes
  * Actually only the first 4 triplets are used but for the
  * high speed mode we need to pad it to 8 (microframes).
  */
-#define SIZEOUTBUF         ((8*SIZEDAOUT))
+#define SIZEOUTBUF             (8 * SIZEDAOUT)
 
 /*
  * Size of the buffer for the dux commands: just now max size is determined
  * by the analogue out + command byte + panic bytes...
  */
-#define SIZEOFDUXBUFFER    ((8*SIZEDAOUT+2))
+#define SIZEOFDUXBUFFER                (8 * SIZEDAOUT + 2)
 
 /* Number of in-URBs which receive the data: min=2 */
-#define NUMOFINBUFFERSFULL     5
+#define NUMOFINBUFFERSFULL     5
 
 /* Number of out-URBs which send the data: min=2 */
-#define NUMOFOUTBUFFERSFULL    5
+#define NUMOFOUTBUFFERSFULL    5
 
 /* Number of in-URBs which receive the data: min=5 */
 /* must have more buffers due to buggy USB ctr */
-#define NUMOFINBUFFERSHIGH     10
+#define NUMOFINBUFFERSHIGH     10
 
 /* Number of out-URBs which send the data: min=5 */
 /* must have more buffers due to buggy USB ctr */
-#define NUMOFOUTBUFFERSHIGH    10
+#define NUMOFOUTBUFFERSHIGH    10
 
 /* number of retries to get the right dux command */
-#define RETRIES 10
+#define RETRIES                        10
 
 static const struct comedi_lrange range_usbdux_ai_range = {
        4, {
@@ -187,7 +187,7 @@ struct usbdux_private {
        /* PWM period */
        unsigned int pwm_period;
        /* PWM internal delay for the GPIF in the FX2 */
-       uint8_t pwm_delay;
+       u8 pwm_delay;
        /* size of the PWM buffer which holds the bit pattern */
        int pwm_buf_sz;
        /* input buffer for the ISO-transfer */
@@ -209,8 +209,8 @@ struct usbdux_private {
        /* interval in frames/uframes */
        unsigned int ai_interval;
        /* commands */
-       uint8_t *dux_commands;
-       struct semaphore sem;
+       u8 *dux_commands;
+       struct mutex mut;
 };
 
 static void usbdux_unlink_urbs(struct urb **urbs, int num_urbs)
@@ -237,10 +237,10 @@ static int usbdux_ai_cancel(struct comedi_device *dev,
        struct usbdux_private *devpriv = dev->private;
 
        /* prevent other CPUs from submitting new commands just now */
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        /* unlink only if the urb really has been submitted */
        usbdux_ai_stop(dev, devpriv->ai_cmd_running);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 0;
 }
@@ -262,11 +262,11 @@ static void usbduxsub_ai_handle_urb(struct comedi_device *dev,
                /* get the data from the USB bus and hand it over to comedi */
                for (i = 0; i < cmd->chanlist_len; i++) {
                        unsigned int range = CR_RANGE(cmd->chanlist[i]);
-                       uint16_t val = le16_to_cpu(devpriv->in_buf[i]);
+                       u16 val = le16_to_cpu(devpriv->in_buf[i]);
 
                        /* bipolar data is two's-complement */
                        if (comedi_range_is_bipolar(s, range))
-                               val ^= ((s->maxdata + 1) >> 1);
+                               val = comedi_offset_munge(s, val);
 
                        /* transfer data */
                        if (!comedi_buf_write_samples(s, &val, 1))
@@ -365,10 +365,10 @@ static int usbdux_ao_cancel(struct comedi_device *dev,
        struct usbdux_private *devpriv = dev->private;
 
        /* prevent other CPUs from submitting a command just now */
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        /* unlink only if it is really running */
        usbdux_ao_stop(dev, devpriv->ao_cmd_running);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 0;
 }
@@ -380,7 +380,7 @@ static void usbduxsub_ao_handle_urb(struct comedi_device *dev,
        struct usbdux_private *devpriv = dev->private;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
-       uint8_t *datap;
+       u8 *datap;
        int ret;
        int i;
 
@@ -516,9 +516,8 @@ static int usbdux_submit_urbs(struct comedi_device *dev,
 static int usbdux_ai_cmdtest(struct comedi_device *dev,
                             struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
-       struct usbdux_private *this_usbduxsub = dev->private;
-       int err = 0, i;
-       unsigned int tmp_timer;
+       struct usbdux_private *devpriv = dev->private;
+       int err = 0;
 
        /* Step 1 : check if triggers are trivially valid */
 
@@ -549,40 +548,31 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
                err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
-               if (this_usbduxsub->high_speed) {
+               /* full speed does 1kHz scans every USB frame */
+               unsigned int arg = 1000000;
+               unsigned int min_arg = arg;
+
+               if (devpriv->high_speed) {
                        /*
                         * In high speed mode microframes are possible.
                         * However, during one microframe we can roughly
                         * sample one channel. Thus, the more channels
                         * are in the channel list the more time we need.
                         */
-                       i = 1;
+                       int i = 1;
+
                        /* find a power of 2 for the number of channels */
-                       while (i < (cmd->chanlist_len))
+                       while (i < cmd->chanlist_len)
                                i = i * 2;
 
-                       err |= comedi_check_trigger_arg_min(&cmd->
-                                                           scan_begin_arg,
-                                                           1000000 / 8 * i);
-                       /* now calc the real sampling rate with all the
-                        * rounding errors */
-                       tmp_timer =
-                           ((unsigned int)(cmd->scan_begin_arg / 125000)) *
-                           125000;
-               } else {
-                       /* full speed */
-                       /* 1kHz scans every USB frame */
-                       err |= comedi_check_trigger_arg_min(&cmd->
-                                                           scan_begin_arg,
-                                                           1000000);
-                       /*
-                        * calc the real sampling rate with the rounding errors
-                        */
-                       tmp_timer = ((unsigned int)(cmd->scan_begin_arg /
-                                                  1000000)) * 1000000;
+                       arg /= 8;
+                       min_arg = arg * i;
                }
-               err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg,
-                                                  tmp_timer);
+               err |= comedi_check_trigger_arg_min(&cmd->scan_begin_arg,
+                                                   min_arg);
+               /* calc the real sampling rate with the rounding errors */
+               arg = (cmd->scan_begin_arg / arg) * arg;
+               err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
        }
 
        err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
@@ -603,10 +593,10 @@ static int usbdux_ai_cmdtest(struct comedi_device *dev,
  * creates the ADC command for the MAX1271
  * range is the range value from comedi
  */
-static uint8_t create_adc_command(unsigned int chan, unsigned int range)
+static u8 create_adc_command(unsigned int chan, unsigned int range)
 {
-       uint8_t p = (range <= 1);
-       uint8_t r = ((range % 2) == 0);
+       u8 p = (range <= 1);
+       u8 r = ((range % 2) == 0);
 
        return (chan << 4) | ((p == 1) << 2) | ((r == 1) << 3);
 }
@@ -656,7 +646,7 @@ static int usbdux_ai_inttrig(struct comedi_device *dev,
        if (trig_num != cmd->start_arg)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (!devpriv->ai_cmd_running) {
                devpriv->ai_cmd_running = 1;
@@ -672,7 +662,7 @@ static int usbdux_ai_inttrig(struct comedi_device *dev,
        }
 
 ai_trig_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
        return ret;
 }
 
@@ -685,7 +675,7 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        int i;
 
        /* block other CPUs from starting an ai_cmd */
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (devpriv->ai_cmd_running)
                goto ai_cmd_exit;
@@ -746,7 +736,7 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        }
 
 ai_cmd_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -764,7 +754,7 @@ static int usbdux_ai_insn_read(struct comedi_device *dev,
        int ret = -EBUSY;
        int i;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (devpriv->ai_cmd_running)
                goto ai_read_exit;
@@ -786,13 +776,13 @@ static int usbdux_ai_insn_read(struct comedi_device *dev,
 
                /* bipolar data is two's-complement */
                if (comedi_range_is_bipolar(s, range))
-                       val ^= ((s->maxdata + 1) >> 1);
+                       val = comedi_offset_munge(s, val);
 
                data[i] = val;
        }
 
 ai_read_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret ? ret : insn->n;
 }
@@ -805,9 +795,9 @@ static int usbdux_ao_insn_read(struct comedi_device *dev,
        struct usbdux_private *devpriv = dev->private;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        ret = comedi_readback_insn_read(dev, s, insn, data);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -824,7 +814,7 @@ static int usbdux_ao_insn_write(struct comedi_device *dev,
        int ret = -EBUSY;
        int i;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (devpriv->ao_cmd_running)
                goto ao_write_exit;
@@ -848,7 +838,7 @@ static int usbdux_ao_insn_write(struct comedi_device *dev,
        }
 
 ao_write_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret ? ret : insn->n;
 }
@@ -864,7 +854,7 @@ static int usbdux_ao_inttrig(struct comedi_device *dev,
        if (trig_num != cmd->start_arg)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (!devpriv->ao_cmd_running) {
                devpriv->ao_cmd_running = 1;
@@ -880,25 +870,21 @@ static int usbdux_ao_inttrig(struct comedi_device *dev,
        }
 
 ao_trig_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
        return ret;
 }
 
 static int usbdux_ao_cmdtest(struct comedi_device *dev,
                             struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
-       struct usbdux_private *this_usbduxsub = dev->private;
        int err = 0;
        unsigned int flags;
 
-       if (!this_usbduxsub)
-               return -EFAULT;
-
        /* Step 1 : check if triggers are trivially valid */
 
        err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
 
-       if (0) {                /* (this_usbduxsub->high_speed) */
+       if (0) {                /* (devpriv->high_speed) */
                /* the sampling rate is set by the coversion rate */
                flags = TRIG_FOLLOW;
        } else {
@@ -907,7 +893,7 @@ static int usbdux_ao_cmdtest(struct comedi_device *dev,
        }
        err |= comedi_check_trigger_src(&cmd->scan_begin_src, flags);
 
-       if (0) {                /* (this_usbduxsub->high_speed) */
+       if (0) {                /* (devpriv->high_speed) */
                /*
                 * in usb-2.0 only one conversion it transmitted
                 * but with 8kHz/n
@@ -974,7 +960,7 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        struct comedi_cmd *cmd = &s->async->cmd;
        int ret = -EBUSY;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (devpriv->ao_cmd_running)
                goto ao_cmd_exit;
@@ -1016,7 +1002,7 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
        }
 
 ao_cmd_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -1047,7 +1033,7 @@ static int usbdux_dio_insn_bits(struct comedi_device *dev,
        struct usbdux_private *devpriv = dev->private;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        comedi_dio_update_state(s, data);
 
@@ -1069,7 +1055,7 @@ static int usbdux_dio_insn_bits(struct comedi_device *dev,
        data[1] = le16_to_cpu(devpriv->insn_buf[1]);
 
 dio_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret ? ret : insn->n;
 }
@@ -1084,7 +1070,7 @@ static int usbdux_counter_read(struct comedi_device *dev,
        int ret = 0;
        int i;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        for (i = 0; i < insn->n; i++) {
                ret = send_dux_commands(dev, USBDUX_CMD_TIMER_RD);
@@ -1098,7 +1084,7 @@ static int usbdux_counter_read(struct comedi_device *dev,
        }
 
 counter_read_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret ? ret : insn->n;
 }
@@ -1114,7 +1100,7 @@ static int usbdux_counter_write(struct comedi_device *dev,
        int ret = 0;
        int i;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        devpriv->dux_commands[1] = chan;
 
@@ -1126,7 +1112,7 @@ static int usbdux_counter_write(struct comedi_device *dev,
                        break;
        }
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret ? ret : insn->n;
 }
@@ -1162,11 +1148,11 @@ static int usbdux_pwm_cancel(struct comedi_device *dev,
        struct usbdux_private *devpriv = dev->private;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        /* unlink only if it is really running */
        usbdux_pwm_stop(dev, devpriv->pwm_cmd_running);
        ret = send_dux_commands(dev, USBDUX_CMD_PWM_OFF);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -1271,7 +1257,7 @@ static int usbdux_pwm_start(struct comedi_device *dev,
        struct usbdux_private *devpriv = dev->private;
        int ret = 0;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (devpriv->pwm_cmd_running)
                goto pwm_start_exit;
@@ -1290,7 +1276,7 @@ static int usbdux_pwm_start(struct comedi_device *dev,
                devpriv->pwm_cmd_running = 0;
 
 pwm_start_exit:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -1391,8 +1377,8 @@ static int usbdux_firmware_upload(struct comedi_device *dev,
                                  unsigned long context)
 {
        struct usb_device *usb = comedi_to_usb_dev(dev);
-       uint8_t *buf;
-       uint8_t *tmp;
+       u8 *buf;
+       u8 *tmp;
        int ret;
 
        if (!data)
@@ -1590,7 +1576,7 @@ static int usbdux_auto_attach(struct comedi_device *dev,
        if (!devpriv)
                return -ENOMEM;
 
-       sema_init(&devpriv->sem, 1);
+       mutex_init(&devpriv->mut);
 
        usb_set_intfdata(intf, devpriv);
 
@@ -1705,7 +1691,7 @@ static void usbdux_detach(struct comedi_device *dev)
        if (!devpriv)
                return;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        /* force unlink all urbs */
        usbdux_pwm_stop(dev, 1);
@@ -1714,7 +1700,7 @@ static void usbdux_detach(struct comedi_device *dev)
 
        usbdux_free_usb_buffers(dev);
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 }
 
 static struct comedi_driver usbdux_driver = {
index d90dc59982be6e146d412ac07fa369fcc42f9de1..10f94ec345360681ec11316d5fda6c48581afde8 100644 (file)
@@ -97,7 +97,7 @@
 /*
  * size of one A/D value
  */
-#define SIZEADIN       (sizeof(int16_t))
+#define SIZEADIN       (sizeof(s16))
 
 /*
  * size of the input-buffer IN BYTES
@@ -156,12 +156,11 @@ static const struct comedi_lrange range_usbduxfast_ai_range = {
  */
 struct usbduxfast_private {
        struct urb *urb;        /* BULK-transfer handling: urb */
-       uint8_t *duxbuf;
-       int8_t *inbuf;
+       u8 *duxbuf;
+       s8 *inbuf;
        short int ai_cmd_running;       /* asynchronous command is running */
-       int ignore;             /* counter which ignores the first
-                                  buffers */
-       struct semaphore sem;
+       int ignore;             /* counter which ignores the first buffers */
+       struct mutex mut;
 };
 
 /*
@@ -190,8 +189,7 @@ static int usbduxfast_send_cmd(struct comedi_device *dev, int cmd_type)
 }
 
 static void usbduxfast_cmd_data(struct comedi_device *dev, int index,
-                               uint8_t len, uint8_t op, uint8_t out,
-                               uint8_t log)
+                               u8 len, u8 op, u8 out, u8 log)
 {
        struct usbduxfast_private *devpriv = dev->private;
 
@@ -223,12 +221,9 @@ static int usbduxfast_ai_cancel(struct comedi_device *dev,
        struct usbduxfast_private *devpriv = dev->private;
        int ret;
 
-       if (!devpriv)
-               return -EFAULT;
-
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        ret = usbduxfast_ai_stop(dev, 1);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -317,9 +312,6 @@ static int usbduxfast_submit_urb(struct comedi_device *dev)
        struct usbduxfast_private *devpriv = dev->private;
        int ret;
 
-       if (!devpriv)
-               return -EFAULT;
-
        usb_fill_bulk_urb(devpriv->urb, usb, usb_rcvbulkpipe(usb, BULKINEP),
                          devpriv->inbuf, SIZEINBUF,
                          usbduxfast_ai_interrupt, dev);
@@ -332,22 +324,50 @@ static int usbduxfast_submit_urb(struct comedi_device *dev)
        return 0;
 }
 
+static int usbduxfast_ai_check_chanlist(struct comedi_device *dev,
+                                       struct comedi_subdevice *s,
+                                       struct comedi_cmd *cmd)
+{
+       unsigned int gain0 = CR_RANGE(cmd->chanlist[0]);
+       int i;
+
+       if (cmd->chanlist_len > 3 && cmd->chanlist_len != 16) {
+               dev_err(dev->class_dev, "unsupported combination of channels\n");
+               return -EINVAL;
+       }
+
+       for (i = 0; i < cmd->chanlist_len; ++i) {
+               unsigned int chan = CR_CHAN(cmd->chanlist[i]);
+               unsigned int gain = CR_RANGE(cmd->chanlist[i]);
+
+               if (chan != i) {
+                       dev_err(dev->class_dev,
+                               "channels are not consecutive\n");
+                       return -EINVAL;
+               }
+               if (gain != gain0 && cmd->chanlist_len > 3) {
+                       dev_err(dev->class_dev,
+                               "gain must be the same for all channels\n");
+                       return -EINVAL;
+               }
+       }
+       return 0;
+}
+
 static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
                                 struct comedi_cmd *cmd)
 {
        int err = 0;
-       long int steps, tmp;
-       int min_sample_period;
+       unsigned int steps;
+       unsigned int arg;
 
        /* Step 1 : check if triggers are trivially valid */
 
        err |= comedi_check_trigger_src(&cmd->start_src,
                                        TRIG_NOW | TRIG_EXT | TRIG_INT);
-       err |= comedi_check_trigger_src(&cmd->scan_begin_src,
-                                       TRIG_FOLLOW | TRIG_EXT);
-       err |= comedi_check_trigger_src(&cmd->convert_src,
-                                       TRIG_TIMER | TRIG_EXT);
+       err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
+       err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
        err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
        err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
@@ -357,16 +377,10 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
        /* Step 2a : make sure trigger sources are unique */
 
        err |= comedi_check_trigger_is_unique(cmd->start_src);
-       err |= comedi_check_trigger_is_unique(cmd->scan_begin_src);
-       err |= comedi_check_trigger_is_unique(cmd->convert_src);
        err |= comedi_check_trigger_is_unique(cmd->stop_src);
 
        /* Step 2b : and mutually compatible */
 
-       /* can't have external stop and start triggers at once */
-       if (cmd->start_src == TRIG_EXT && cmd->stop_src == TRIG_EXT)
-               err |= -EINVAL;
-
        if (err)
                return 2;
 
@@ -377,47 +391,44 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
        if (!cmd->chanlist_len)
                err |= -EINVAL;
 
+       /* external start trigger is only valid for 1 or 16 channels */
+       if (cmd->start_src == TRIG_EXT &&
+           cmd->chanlist_len != 1 && cmd->chanlist_len != 16)
+               err |= -EINVAL;
+
        err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
                                           cmd->chanlist_len);
 
-       if (cmd->chanlist_len == 1)
-               min_sample_period = 1;
-       else
-               min_sample_period = MIN_SAMPLING_PERIOD;
-
-       if (cmd->convert_src == TRIG_TIMER) {
-               steps = cmd->convert_arg * 30;
-               if (steps < (min_sample_period * 1000))
-                       steps = min_sample_period * 1000;
-
-               if (steps > (MAX_SAMPLING_PERIOD * 1000))
-                       steps = MAX_SAMPLING_PERIOD * 1000;
-
-               /* calc arg again */
-               tmp = steps / 30;
-               err |= comedi_check_trigger_arg_is(&cmd->convert_arg, tmp);
-       }
-
-       /* stop source */
-       switch (cmd->stop_src) {
-       case TRIG_COUNT:
+       /*
+        * Validate the conversion timing:
+        * for 1 channel the timing in 30MHz "steps" is:
+        *      steps <= MAX_SAMPLING_PERIOD
+        * for all other chanlist_len it is:
+        *      MIN_SAMPLING_PERIOD <= steps <= MAX_SAMPLING_PERIOD
+        */
+       steps = (cmd->convert_arg * 30) / 1000;
+       if (cmd->chanlist_len !=  1)
+               err |= comedi_check_trigger_arg_min(&steps,
+                                                   MIN_SAMPLING_PERIOD);
+       err |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD);
+       arg = (steps * 1000) / 30;
+       err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
+
+       if (cmd->stop_src == TRIG_COUNT)
                err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
-               break;
-       case TRIG_NONE:
+       else    /* TRIG_NONE */
                err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
-               break;
-               /*
-                * TRIG_EXT doesn't care since it doesn't trigger
-                * off a numbered channel
-                */
-       default:
-               break;
-       }
 
        if (err)
                return 3;
 
-       /* step 4: fix up any arguments */
+       /* Step 4: fix up any arguments */
+
+       /* Step 5: check channel list if it exists */
+       if (cmd->chanlist && cmd->chanlist_len > 0)
+               err |= usbduxfast_ai_check_chanlist(dev, s, cmd);
+       if (err)
+               return 5;
 
        return 0;
 }
@@ -430,13 +441,10 @@ static int usbduxfast_ai_inttrig(struct comedi_device *dev,
        struct comedi_cmd *cmd = &s->async->cmd;
        int ret;
 
-       if (!devpriv)
-               return -EFAULT;
-
        if (trig_num != cmd->start_arg)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (!devpriv->ai_cmd_running) {
                devpriv->ai_cmd_running = 1;
@@ -444,14 +452,14 @@ static int usbduxfast_ai_inttrig(struct comedi_device *dev,
                if (ret < 0) {
                        dev_err(dev->class_dev, "urbSubmit: err=%d\n", ret);
                        devpriv->ai_cmd_running = 0;
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
                s->async->inttrig = NULL;
        } else {
                dev_err(dev->class_dev, "ai is already running\n");
        }
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
        return 1;
 }
 
@@ -460,19 +468,14 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
 {
        struct usbduxfast_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
-       unsigned int chan, gain, rngmask = 0xff;
-       int i, j, ret;
-       int result;
+       unsigned int rngmask = 0xff;
+       int j, ret;
        long steps, steps_tmp;
 
-       if (!devpriv)
-               return -EFAULT;
-
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        if (devpriv->ai_cmd_running) {
-               dev_err(dev->class_dev, "ai_cmd not possible\n");
-               up(&devpriv->sem);
-               return -EBUSY;
+               ret = -EBUSY;
+               goto cmd_exit;
        }
 
        /*
@@ -481,50 +484,7 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
         */
        devpriv->ignore = PACKETS_TO_IGNORE;
 
-       gain = CR_RANGE(cmd->chanlist[0]);
-       for (i = 0; i < cmd->chanlist_len; ++i) {
-               chan = CR_CHAN(cmd->chanlist[i]);
-               if (chan != i) {
-                       dev_err(dev->class_dev,
-                               "channels are not consecutive\n");
-                       up(&devpriv->sem);
-                       return -EINVAL;
-               }
-               if ((gain != CR_RANGE(cmd->chanlist[i]))
-                       && (cmd->chanlist_len > 3)) {
-                       dev_err(dev->class_dev,
-                               "gain must be the same for all channels\n");
-                       up(&devpriv->sem);
-                       return -EINVAL;
-               }
-               if (i >= NUMCHANNELS) {
-                       dev_err(dev->class_dev, "chanlist too long\n");
-                       break;
-               }
-       }
-       steps = 0;
-       if (cmd->convert_src == TRIG_TIMER)
-               steps = (cmd->convert_arg * 30) / 1000;
-
-       if ((steps < MIN_SAMPLING_PERIOD) && (cmd->chanlist_len != 1)) {
-               dev_err(dev->class_dev,
-                       "steps=%ld, scan_begin_arg=%d. Not properly tested by cmdtest?\n",
-                       steps, cmd->scan_begin_arg);
-               up(&devpriv->sem);
-               return -EINVAL;
-       }
-       if (steps > MAX_SAMPLING_PERIOD) {
-               dev_err(dev->class_dev, "sampling rate too low\n");
-               up(&devpriv->sem);
-               return -EINVAL;
-       }
-       if ((cmd->start_src == TRIG_EXT) && (cmd->chanlist_len != 1)
-           && (cmd->chanlist_len != 16)) {
-               dev_err(dev->class_dev,
-                       "TRIG_EXT only with 1 or 16 channels possible\n");
-               up(&devpriv->sem);
-               return -EINVAL;
-       }
+       steps = (cmd->convert_arg * 30) / 1000;
 
        switch (cmd->chanlist_len) {
        case 1:
@@ -769,19 +729,12 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
                usbduxfast_cmd_data(dev, 4, 0x09, 0x01, rngmask, 0xff);
 
                break;
-
-       default:
-               dev_err(dev->class_dev, "unsupported combination of channels\n");
-               up(&devpriv->sem);
-               return -EFAULT;
        }
 
        /* 0 means that the AD commands are sent */
-       result = usbduxfast_send_cmd(dev, SENDADCOMMANDS);
-       if (result < 0) {
-               up(&devpriv->sem);
-               return result;
-       }
+       ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS);
+       if (ret < 0)
+               goto cmd_exit;
 
        if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) {
                /* enable this acquisition operation */
@@ -790,16 +743,17 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
                if (ret < 0) {
                        devpriv->ai_cmd_running = 0;
                        /* fixme: unlink here?? */
-                       up(&devpriv->sem);
-                       return ret;
+                       goto cmd_exit;
                }
                s->async->inttrig = NULL;
        } else {        /* TRIG_INT */
                s->async->inttrig = usbduxfast_ai_inttrig;
        }
-       up(&devpriv->sem);
 
-       return 0;
+cmd_exit:
+       mutex_unlock(&devpriv->mut);
+
+       return ret;
 }
 
 /*
@@ -814,16 +768,16 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
        struct usbduxfast_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
-       uint8_t rngmask = range ? (0xff - 0x04) : 0xff;
+       u8 rngmask = range ? (0xff - 0x04) : 0xff;
        int i, j, n, actual_length;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (devpriv->ai_cmd_running) {
                dev_err(dev->class_dev,
                        "ai_insn_read not possible, async cmd is running\n");
-               up(&devpriv->sem);
+               mutex_unlock(&devpriv->mut);
                return -EBUSY;
        }
 
@@ -845,7 +799,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
 
        ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS);
        if (ret < 0) {
-               up(&devpriv->sem);
+               mutex_unlock(&devpriv->mut);
                return ret;
        }
 
@@ -855,7 +809,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
                                   &actual_length, 10000);
                if (ret < 0) {
                        dev_err(dev->class_dev, "insn timeout, no data\n");
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
        }
@@ -866,65 +820,32 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
                                   &actual_length, 10000);
                if (ret < 0) {
                        dev_err(dev->class_dev, "insn data error: %d\n", ret);
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
-               n = actual_length / sizeof(uint16_t);
+               n = actual_length / sizeof(u16);
                if ((n % 16) != 0) {
                        dev_err(dev->class_dev, "insn data packet corrupted\n");
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return -EINVAL;
                }
                for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
-                       data[i] = ((uint16_t *) (devpriv->inbuf))[j];
+                       data[i] = ((u16 *)(devpriv->inbuf))[j];
                        i++;
                }
        }
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return insn->n;
 }
 
-static int usbduxfast_attach_common(struct comedi_device *dev)
-{
-       struct usbduxfast_private *devpriv = dev->private;
-       struct comedi_subdevice *s;
-       int ret;
-
-       down(&devpriv->sem);
-
-       ret = comedi_alloc_subdevices(dev, 1);
-       if (ret) {
-               up(&devpriv->sem);
-               return ret;
-       }
-
-       /* Analog Input subdevice */
-       s = &dev->subdevices[0];
-       dev->read_subdev = s;
-       s->type         = COMEDI_SUBD_AI;
-       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
-       s->n_chan       = 16;
-       s->len_chanlist = 16;
-       s->insn_read    = usbduxfast_ai_insn_read;
-       s->do_cmdtest   = usbduxfast_ai_cmdtest;
-       s->do_cmd       = usbduxfast_ai_cmd;
-       s->cancel       = usbduxfast_ai_cancel;
-       s->maxdata      = 0x1000;
-       s->range_table  = &range_usbduxfast_ai_range;
-
-       up(&devpriv->sem);
-
-       return 0;
-}
-
 static int usbduxfast_upload_firmware(struct comedi_device *dev,
                                      const u8 *data, size_t size,
                                      unsigned long context)
 {
        struct usb_device *usb = comedi_to_usb_dev(dev);
-       uint8_t *buf;
+       u8 *buf;
        unsigned char *tmp;
        int ret;
 
@@ -996,6 +917,7 @@ static int usbduxfast_auto_attach(struct comedi_device *dev,
        struct usb_interface *intf = comedi_to_usb_interface(dev);
        struct usb_device *usb = comedi_to_usb_dev(dev);
        struct usbduxfast_private *devpriv;
+       struct comedi_subdevice *s;
        int ret;
 
        if (usb->speed != USB_SPEED_HIGH) {
@@ -1008,7 +930,7 @@ static int usbduxfast_auto_attach(struct comedi_device *dev,
        if (!devpriv)
                return -ENOMEM;
 
-       sema_init(&devpriv->sem, 1);
+       mutex_init(&devpriv->mut);
        usb_set_intfdata(intf, devpriv);
 
        devpriv->duxbuf = kmalloc(SIZEOFDUXBUF, GFP_KERNEL);
@@ -1038,7 +960,25 @@ static int usbduxfast_auto_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       return usbduxfast_attach_common(dev);
+       ret = comedi_alloc_subdevices(dev, 1);
+       if (ret)
+               return ret;
+
+       /* Analog Input subdevice */
+       s = &dev->subdevices[0];
+       dev->read_subdev = s;
+       s->type         = COMEDI_SUBD_AI;
+       s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_CMD_READ;
+       s->n_chan       = 16;
+       s->maxdata      = 0x1000;       /* 12-bit + 1 overflow bit */
+       s->range_table  = &range_usbduxfast_ai_range;
+       s->insn_read    = usbduxfast_ai_insn_read;
+       s->len_chanlist = s->n_chan;
+       s->do_cmdtest   = usbduxfast_ai_cmdtest;
+       s->do_cmd       = usbduxfast_ai_cmd;
+       s->cancel       = usbduxfast_ai_cancel;
+
+       return 0;
 }
 
 static void usbduxfast_detach(struct comedi_device *dev)
@@ -1049,7 +989,7 @@ static void usbduxfast_detach(struct comedi_device *dev)
        if (!devpriv)
                return;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        usb_set_intfdata(intf, NULL);
 
@@ -1058,18 +998,12 @@ static void usbduxfast_detach(struct comedi_device *dev)
                usb_kill_urb(devpriv->urb);
 
                kfree(devpriv->inbuf);
-               devpriv->inbuf = NULL;
-
                usb_free_urb(devpriv->urb);
-               devpriv->urb = NULL;
        }
 
        kfree(devpriv->duxbuf);
-       devpriv->duxbuf = NULL;
-
-       devpriv->ai_cmd_running = 0;
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 }
 
 static struct comedi_driver usbduxfast_driver = {
index 649cf47184a403241badec00b70164657a7054bd..456e9f13becb828a5da171d318d7cf466d20fa77 100644 (file)
 #define USBDUXSUB_CPUCS 0xE600
 
 /* 300Hz max frequ under PWM */
-#define MIN_PWM_PERIOD  ((long)(1E9/300))
+#define MIN_PWM_PERIOD  ((long)(1E9 / 300))
 
 /* Default PWM frequency */
-#define PWM_DEFAULT_PERIOD ((long)(1E9/100))
+#define PWM_DEFAULT_PERIOD ((long)(1E9 / 100))
 
 /* Number of channels (16 AD and offset)*/
 #define NUMCHANNELS 16
 
 /* Size of one A/D value */
-#define SIZEADIN          ((sizeof(uint32_t)))
+#define SIZEADIN          ((sizeof(u32)))
 
 /*
  * Size of the async input-buffer IN BYTES, the DIO state is transmitted
  * as the first byte.
  */
-#define SIZEINBUF         (((NUMCHANNELS+1)*SIZEADIN))
+#define SIZEINBUF         (((NUMCHANNELS + 1) * SIZEADIN))
 
 /* 16 bytes. */
 #define SIZEINSNBUF       16
 #define NUMOUTCHANNELS    8
 
 /* size of one value for the D/A converter: channel and value */
-#define SIZEDAOUT          ((sizeof(uint8_t)+sizeof(uint16_t)))
+#define SIZEDAOUT          ((sizeof(u8) + sizeof(uint16_t)))
 
 /*
  * Size of the output-buffer in bytes
  * Actually only the first 4 triplets are used but for the
  * high speed mode we need to pad it to 8 (microframes).
  */
-#define SIZEOUTBUF         ((8*SIZEDAOUT))
+#define SIZEOUTBUF         ((8 * SIZEDAOUT))
 
 /*
  * Size of the buffer for the dux commands: just now max size is determined
  * by the analogue out + command byte + panic bytes...
  */
-#define SIZEOFDUXBUFFER    ((8*SIZEDAOUT+2))
+#define SIZEOFDUXBUFFER    ((8 * SIZEDAOUT + 2))
 
 /* Number of in-URBs which receive the data: min=2 */
 #define NUMOFINBUFFERSFULL     5
@@ -150,13 +150,13 @@ struct usbduxsigma_private {
        /* PWM period */
        unsigned int pwm_period;
        /* PWM internal delay for the GPIF in the FX2 */
-       uint8_t pwm_delay;
+       u8 pwm_delay;
        /* size of the PWM buffer which holds the bit pattern */
        int pwm_buf_sz;
        /* input buffer for the ISO-transfer */
        __be32 *in_buf;
        /* input buffer for single insn */
-       uint8_t *insn_buf;
+       u8 *insn_buf;
 
        unsigned high_speed:1;
        unsigned ai_cmd_running:1;
@@ -172,8 +172,8 @@ struct usbduxsigma_private {
        /* interval in frames/uframes */
        unsigned int ai_interval;
        /* commands */
-       uint8_t *dux_commands;
-       struct semaphore sem;
+       u8 *dux_commands;
+       struct mutex mut;
 };
 
 static void usbduxsigma_unlink_urbs(struct urb **urbs, int num_urbs)
@@ -199,10 +199,10 @@ static int usbduxsigma_ai_cancel(struct comedi_device *dev,
 {
        struct usbduxsigma_private *devpriv = dev->private;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        /* unlink only if it is really running */
        usbduxsigma_ai_stop(dev, devpriv->ai_cmd_running);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 0;
 }
@@ -214,7 +214,7 @@ static void usbduxsigma_ai_handle_urb(struct comedi_device *dev,
        struct usbduxsigma_private *devpriv = dev->private;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
-       uint32_t val;
+       u32 val;
        int ret;
        int i;
 
@@ -223,15 +223,14 @@ static void usbduxsigma_ai_handle_urb(struct comedi_device *dev,
                if (devpriv->ai_counter == 0) {
                        devpriv->ai_counter = devpriv->ai_timer;
 
-                       /* get the data from the USB bus
-                          and hand it over to comedi */
+                       /*
+                        * Get the data from the USB bus and hand it over
+                        * to comedi. Note, first byte is the DIO state.
+                        */
                        for (i = 0; i < cmd->chanlist_len; i++) {
-                               /* transfer data,
-                                  note first byte is the DIO state */
-                               val = be32_to_cpu(devpriv->in_buf[i+1]);
+                               val = be32_to_cpu(devpriv->in_buf[i + 1]);
                                val &= 0x00ffffff; /* strip status byte */
-                               val ^= 0x00800000; /* convert to unsigned */
-
+                               val = comedi_offset_munge(s, val);
                                if (!comedi_buf_write_samples(s, &val, 1))
                                        return;
                        }
@@ -326,10 +325,10 @@ static int usbduxsigma_ao_cancel(struct comedi_device *dev,
 {
        struct usbduxsigma_private *devpriv = dev->private;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        /* unlink only if it is really running */
        usbduxsigma_ao_stop(dev, devpriv->ao_cmd_running);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 0;
 }
@@ -341,7 +340,7 @@ static void usbduxsigma_ao_handle_urb(struct comedi_device *dev,
        struct usbduxsigma_private *devpriv = dev->private;
        struct comedi_async *async = s->async;
        struct comedi_cmd *cmd = &async->cmd;
-       uint8_t *datap;
+       u8 *datap;
        int ret;
        int i;
 
@@ -553,13 +552,12 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
  * range is the range value from comedi
  */
 static void create_adc_command(unsigned int chan,
-                              uint8_t *muxsg0,
-                              uint8_t *muxsg1)
+                              u8 *muxsg0, u8 *muxsg1)
 {
        if (chan < 8)
                (*muxsg0) = (*muxsg0) | (1 << chan);
        else if (chan < 16)
-               (*muxsg1) = (*muxsg1) | (1 << (chan-8));
+               (*muxsg1) = (*muxsg1) | (1 << (chan - 8));
 }
 
 static int usbbuxsigma_send_cmd(struct comedi_device *dev, int cmd_type)
@@ -611,19 +609,19 @@ static int usbduxsigma_ai_inttrig(struct comedi_device *dev,
        if (trig_num != cmd->start_arg)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        if (!devpriv->ai_cmd_running) {
                devpriv->ai_cmd_running = 1;
                ret = usbduxsigma_submit_urbs(dev, devpriv->ai_urbs,
                                              devpriv->n_ai_urbs, 1);
                if (ret < 0) {
                        devpriv->ai_cmd_running = 0;
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
                s->async->inttrig = NULL;
        }
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 1;
 }
@@ -634,13 +632,13 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
        struct usbduxsigma_private *devpriv = dev->private;
        struct comedi_cmd *cmd = &s->async->cmd;
        unsigned int len = cmd->chanlist_len;
-       uint8_t muxsg0 = 0;
-       uint8_t muxsg1 = 0;
-       uint8_t sysred = 0;
+       u8 muxsg0 = 0;
+       u8 muxsg1 = 0;
+       u8 sysred = 0;
        int ret;
        int i;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        if (devpriv->high_speed) {
                /*
@@ -675,7 +673,7 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
 
        ret = usbbuxsigma_send_cmd(dev, USBBUXSIGMA_AD_CMD);
        if (ret < 0) {
-               up(&devpriv->sem);
+               mutex_unlock(&devpriv->mut);
                return ret;
        }
 
@@ -688,7 +686,7 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
                                              devpriv->n_ai_urbs, 1);
                if (ret < 0) {
                        devpriv->ai_cmd_running = 0;
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
                s->async->inttrig = NULL;
@@ -696,7 +694,7 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
                s->async->inttrig = usbduxsigma_ai_inttrig;
        }
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 0;
 }
@@ -708,15 +706,15 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev,
 {
        struct usbduxsigma_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       uint8_t muxsg0 = 0;
-       uint8_t muxsg1 = 0;
-       uint8_t sysred = 0;
+       u8 muxsg0 = 0;
+       u8 muxsg1 = 0;
+       u8 sysred = 0;
        int ret;
        int i;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        if (devpriv->ai_cmd_running) {
-               up(&devpriv->sem);
+               mutex_unlock(&devpriv->mut);
                return -EBUSY;
        }
 
@@ -733,16 +731,16 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev,
        /* adc commands */
        ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD);
        if (ret < 0) {
-               up(&devpriv->sem);
+               mutex_unlock(&devpriv->mut);
                return ret;
        }
 
        for (i = 0; i < insn->n; i++) {
-               uint32_t val;
+               u32 val;
 
                ret = usbduxsigma_receive_cmd(dev, USBDUXSIGMA_SINGLE_AD_CMD);
                if (ret < 0) {
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
 
@@ -750,11 +748,9 @@ static int usbduxsigma_ai_insn_read(struct comedi_device *dev,
                val = be32_to_cpu(get_unaligned((__be32
                                                 *)(devpriv->insn_buf + 1)));
                val &= 0x00ffffff;      /* strip status byte */
-               val ^= 0x00800000;      /* convert to unsigned */
-
-               data[i] = val;
+               data[i] = comedi_offset_munge(s, val);
        }
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return insn->n;
 }
@@ -767,9 +763,9 @@ static int usbduxsigma_ao_insn_read(struct comedi_device *dev,
        struct usbduxsigma_private *devpriv = dev->private;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        ret = comedi_readback_insn_read(dev, s, insn, data);
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -784,9 +780,9 @@ static int usbduxsigma_ao_insn_write(struct comedi_device *dev,
        int ret;
        int i;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        if (devpriv->ao_cmd_running) {
-               up(&devpriv->sem);
+               mutex_unlock(&devpriv->mut);
                return -EBUSY;
        }
 
@@ -796,12 +792,12 @@ static int usbduxsigma_ao_insn_write(struct comedi_device *dev,
                devpriv->dux_commands[3] = chan;        /* channel number */
                ret = usbbuxsigma_send_cmd(dev, USBDUXSIGMA_DA_CMD);
                if (ret < 0) {
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
                s->readback[chan] = data[i];
        }
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return insn->n;
 }
@@ -817,19 +813,19 @@ static int usbduxsigma_ao_inttrig(struct comedi_device *dev,
        if (trig_num != cmd->start_arg)
                return -EINVAL;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
        if (!devpriv->ao_cmd_running) {
                devpriv->ao_cmd_running = 1;
                ret = usbduxsigma_submit_urbs(dev, devpriv->ao_urbs,
                                              devpriv->n_ao_urbs, 0);
                if (ret < 0) {
                        devpriv->ao_cmd_running = 0;
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
                s->async->inttrig = NULL;
        }
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 1;
 }
@@ -860,7 +856,7 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
        err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
 
        if (err) {
-               up(&devpriv->sem);
+               mutex_unlock(&devpriv->mut);
                return 1;
        }
 
@@ -909,7 +905,7 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev,
        struct comedi_cmd *cmd = &s->async->cmd;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        /*
         * For now, only "scan" timing is supported.  A future version may
@@ -928,7 +924,7 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev,
                                              devpriv->n_ao_urbs, 0);
                if (ret < 0) {
                        devpriv->ao_cmd_running = 0;
-                       up(&devpriv->sem);
+                       mutex_unlock(&devpriv->mut);
                        return ret;
                }
                s->async->inttrig = NULL;
@@ -936,7 +932,7 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev,
                s->async->inttrig = usbduxsigma_ao_inttrig;
        }
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return 0;
 }
@@ -967,7 +963,7 @@ static int usbduxsigma_dio_insn_bits(struct comedi_device *dev,
        struct usbduxsigma_private *devpriv = dev->private;
        int ret;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        comedi_dio_update_state(s, data);
 
@@ -994,7 +990,7 @@ static int usbduxsigma_dio_insn_bits(struct comedi_device *dev,
        ret = insn->n;
 
 done:
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 
        return ret;
 }
@@ -1220,9 +1216,10 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev,
 
 static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan)
 {
+       struct comedi_subdevice *s = dev->read_subdev;
        struct usbduxsigma_private *devpriv = dev->private;
-       uint8_t sysred;
-       uint32_t val;
+       u8 sysred;
+       u32 val;
        int ret;
 
        switch (chan) {
@@ -1264,9 +1261,8 @@ static int usbduxsigma_getstatusinfo(struct comedi_device *dev, int chan)
        /* 32 bits big endian from the A/D converter */
        val = be32_to_cpu(get_unaligned((__be32 *)(devpriv->insn_buf + 1)));
        val &= 0x00ffffff;      /* strip status byte */
-       val ^= 0x00800000;      /* convert to unsigned */
 
-       return (int)val;
+       return (int)comedi_offset_munge(s, val);
 }
 
 static int usbduxsigma_firmware_upload(struct comedi_device *dev,
@@ -1274,8 +1270,8 @@ static int usbduxsigma_firmware_upload(struct comedi_device *dev,
                                       unsigned long context)
 {
        struct usb_device *usb = comedi_to_usb_dev(dev);
-       uint8_t *buf;
-       uint8_t *tmp;
+       u8 *buf;
+       u8 *tmp;
        int ret;
 
        if (!data)
@@ -1466,7 +1462,7 @@ static int usbduxsigma_auto_attach(struct comedi_device *dev,
        if (!devpriv)
                return -ENOMEM;
 
-       sema_init(&devpriv->sem, 1);
+       mutex_init(&devpriv->mut);
 
        usb_set_intfdata(intf, devpriv);
 
@@ -1580,7 +1576,7 @@ static void usbduxsigma_detach(struct comedi_device *dev)
        if (!devpriv)
                return;
 
-       down(&devpriv->sem);
+       mutex_lock(&devpriv->mut);
 
        /* force unlink all urbs */
        usbduxsigma_ai_stop(dev, 1);
@@ -1589,7 +1585,7 @@ static void usbduxsigma_detach(struct comedi_device *dev)
 
        usbduxsigma_free_usb_buffers(dev);
 
-       up(&devpriv->sem);
+       mutex_unlock(&devpriv->mut);
 }
 
 static struct comedi_driver usbduxsigma_driver = {
index 3af075aa3946bb00a3558736c7381cff528ef636..8c7393ef762d911435d709cb2d74bdf70c156aee 100644 (file)
@@ -1,22 +1,23 @@
 /*
-    comedi/drivers/vmk80xx.c
-    Velleman USB Board Low-Level Driver
-
-    Copyright (C) 2009 Manuel Gebele <forensixs@gmx.de>, Germany
-
-    COMEDI - Linux Control and Measurement Device Interface
-    Copyright (C) 2000 David A. Schleef <ds@schleef.org>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
+ * vmk80xx.c
+ * Velleman USB Board Low-Level Driver
+ *
+ * Copyright (C) 2009 Manuel Gebele <forensixs@gmx.de>, Germany
+ *
+ * COMEDI - Linux Control and Measurement Device Interface
+ * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-*/
 /*
  * Driver: vmk80xx
  * Description: Velleman USB Board Low-Level Driver
@@ -51,52 +52,52 @@ enum {
        DEVICE_VMK8061
 };
 
-#define VMK8055_DI_REG          0x00
-#define VMK8055_DO_REG          0x01
-#define VMK8055_AO1_REG         0x02
-#define VMK8055_AO2_REG         0x03
-#define VMK8055_AI1_REG         0x02
-#define VMK8055_AI2_REG         0x03
-#define VMK8055_CNT1_REG        0x04
-#define VMK8055_CNT2_REG        0x06
-
-#define VMK8061_CH_REG          0x01
-#define VMK8061_DI_REG          0x01
-#define VMK8061_DO_REG          0x01
-#define VMK8061_PWM_REG1        0x01
-#define VMK8061_PWM_REG2        0x02
-#define VMK8061_CNT_REG         0x02
-#define VMK8061_AO_REG          0x02
-#define VMK8061_AI_REG1         0x02
-#define VMK8061_AI_REG2         0x03
-
-#define VMK8055_CMD_RST         0x00
-#define VMK8055_CMD_DEB1_TIME   0x01
-#define VMK8055_CMD_DEB2_TIME   0x02
-#define VMK8055_CMD_RST_CNT1    0x03
-#define VMK8055_CMD_RST_CNT2    0x04
-#define VMK8055_CMD_WRT_AD      0x05
-
-#define VMK8061_CMD_RD_AI       0x00
-#define VMK8061_CMR_RD_ALL_AI   0x01   /* !non-active! */
-#define VMK8061_CMD_SET_AO      0x02
-#define VMK8061_CMD_SET_ALL_AO  0x03   /* !non-active! */
-#define VMK8061_CMD_OUT_PWM     0x04
-#define VMK8061_CMD_RD_DI       0x05
-#define VMK8061_CMD_DO          0x06   /* !non-active! */
-#define VMK8061_CMD_CLR_DO      0x07
-#define VMK8061_CMD_SET_DO      0x08
-#define VMK8061_CMD_RD_CNT      0x09   /* TODO: completely pointless? */
-#define VMK8061_CMD_RST_CNT     0x0a   /* TODO: completely pointless? */
-#define VMK8061_CMD_RD_VERSION  0x0b   /* internal usage */
-#define VMK8061_CMD_RD_JMP_STAT 0x0c   /* TODO: not implemented yet */
-#define VMK8061_CMD_RD_PWR_STAT 0x0d   /* internal usage */
-#define VMK8061_CMD_RD_DO       0x0e
-#define VMK8061_CMD_RD_AO       0x0f
-#define VMK8061_CMD_RD_PWM      0x10
-
-#define IC3_VERSION             (1 << 0)
-#define IC6_VERSION             (1 << 1)
+#define VMK8055_DI_REG         0x00
+#define VMK8055_DO_REG         0x01
+#define VMK8055_AO1_REG                0x02
+#define VMK8055_AO2_REG                0x03
+#define VMK8055_AI1_REG                0x02
+#define VMK8055_AI2_REG                0x03
+#define VMK8055_CNT1_REG       0x04
+#define VMK8055_CNT2_REG       0x06
+
+#define VMK8061_CH_REG         0x01
+#define VMK8061_DI_REG         0x01
+#define VMK8061_DO_REG         0x01
+#define VMK8061_PWM_REG1       0x01
+#define VMK8061_PWM_REG2       0x02
+#define VMK8061_CNT_REG                0x02
+#define VMK8061_AO_REG         0x02
+#define VMK8061_AI_REG1                0x02
+#define VMK8061_AI_REG2                0x03
+
+#define VMK8055_CMD_RST                0x00
+#define VMK8055_CMD_DEB1_TIME  0x01
+#define VMK8055_CMD_DEB2_TIME  0x02
+#define VMK8055_CMD_RST_CNT1   0x03
+#define VMK8055_CMD_RST_CNT2   0x04
+#define VMK8055_CMD_WRT_AD     0x05
+
+#define VMK8061_CMD_RD_AI      0x00
+#define VMK8061_CMR_RD_ALL_AI  0x01    /* !non-active! */
+#define VMK8061_CMD_SET_AO     0x02
+#define VMK8061_CMD_SET_ALL_AO 0x03    /* !non-active! */
+#define VMK8061_CMD_OUT_PWM    0x04
+#define VMK8061_CMD_RD_DI      0x05
+#define VMK8061_CMD_DO         0x06    /* !non-active! */
+#define VMK8061_CMD_CLR_DO     0x07
+#define VMK8061_CMD_SET_DO     0x08
+#define VMK8061_CMD_RD_CNT     0x09    /* TODO: completely pointless? */
+#define VMK8061_CMD_RST_CNT    0x0a    /* TODO: completely pointless? */
+#define VMK8061_CMD_RD_VERSION 0x0b    /* internal usage */
+#define VMK8061_CMD_RD_JMP_STAT        0x0c    /* TODO: not implemented yet */
+#define VMK8061_CMD_RD_PWR_STAT        0x0d    /* internal usage */
+#define VMK8061_CMD_RD_DO      0x0e
+#define VMK8061_CMD_RD_AO      0x0f
+#define VMK8061_CMD_RD_PWM     0x10
+
+#define IC3_VERSION            BIT(0)
+#define IC6_VERSION            BIT(1)
 
 enum vmk80xx_model {
        VMK8055_MODEL,
index 76bf5619fdd522f121793b994331236268298c0b..d0a8a28edd36b29a76f8dd9c559b52557790d75c 100644 (file)
@@ -1,20 +1,20 @@
 /*
   kcomedilib/kcomedilib.c
   a comedlib interface for kernel modules
-
   COMEDI - Linux Control and Measurement Device Interface
   Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
-
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-*/
* kcomedilib/kcomedilib.c
* a comedlib interface for kernel modules
+ *
* COMEDI - Linux Control and Measurement Device Interface
* Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
+ */
 
 #include <linux/module.h>
 
index 9112dd2bf4d7757503ea1b53191d213dcbc93785..bad355100825d569834065a8b6e41aa3d0a2a44b 100644 (file)
@@ -140,21 +140,21 @@ struct board_id {
 };
 
 static struct board_id dgap_ids[] = {
-       { PPCM,        PCI_DEV_XEM_NAME,     64, (T_PCXM|T_PCLITE|T_PCIBUS) },
-       { PCX,         PCI_DEV_CX_NAME,     128, (T_CX|T_PCIBUS)            },
-       { PCX,         PCI_DEV_CX_IBM_NAME, 128, (T_CX|T_PCIBUS)            },
-       { PEPC,        PCI_DEV_EPCJ_NAME,   224, (T_EPC|T_PCIBUS)           },
-       { APORT2_920P, PCI_DEV_920_2_NAME,    2, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { APORT4_920P, PCI_DEV_920_4_NAME,    4, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { APORT8_920P, PCI_DEV_920_8_NAME,    8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { PAPORT8,     PCI_DEV_XR_NAME,       8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { PAPORT8,     PCI_DEV_XRJ_NAME,      8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { PAPORT8,     PCI_DEV_XR_422_NAME,   8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { PAPORT8,     PCI_DEV_XR_IBM_NAME,   8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { PAPORT8,     PCI_DEV_XR_SAIP_NAME,  8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { PAPORT8,     PCI_DEV_XR_BULL_NAME,  8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR|T_PCLITE|T_PCIBUS) },
-       { PPCM,        PCI_DEV_XEM_HP_NAME,  64, (T_PCXM|T_PCLITE|T_PCIBUS) },
+       {PPCM,        PCI_DEV_XEM_NAME,     64, (T_PCXM | T_PCLITE | T_PCIBUS)},
+       {PCX,         PCI_DEV_CX_NAME,     128, (T_CX | T_PCIBUS)            },
+       {PCX,         PCI_DEV_CX_IBM_NAME, 128, (T_CX | T_PCIBUS)            },
+       {PEPC,        PCI_DEV_EPCJ_NAME,   224, (T_EPC | T_PCIBUS)           },
+       {APORT2_920P, PCI_DEV_920_2_NAME,    2, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {APORT4_920P, PCI_DEV_920_4_NAME,    4, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {APORT8_920P, PCI_DEV_920_8_NAME,    8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {PAPORT8,     PCI_DEV_XR_NAME,       8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {PAPORT8,     PCI_DEV_XRJ_NAME,      8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {PAPORT8,     PCI_DEV_XR_422_NAME,   8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {PAPORT8,     PCI_DEV_XR_IBM_NAME,   8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {PAPORT8,     PCI_DEV_XR_SAIP_NAME,  8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {PAPORT8,     PCI_DEV_XR_BULL_NAME,  8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
+       {PPCM,        PCI_DEV_XEM_HP_NAME,  64, (T_PCXM | T_PCLITE | T_PCIBUS)},
        {0,}                                            /* 0 terminated list. */
 };
 
@@ -248,7 +248,6 @@ static struct toklist dgap_tlist[] = {
        { BEGIN,        "config_begin" },
        { END,          "config_end" },
        { BOARD,        "board" },
-       { IO,           "io" },
        { PCIINFO,      "pciinfo" },
        { LINE,         "line" },
        { CONC,         "conc" },
@@ -287,28 +286,6 @@ static struct toklist dgap_tlist[] = {
        { 0,            NULL }
 };
 
-
-/*
- * dgap_sindex: much like index(), but it looks for a match of any character in
- * the group, and returns that position.
- */
-static char *dgap_sindex(char *string, char *group)
-{
-       char *ptr;
-
-       if (!string || !group)
-               return NULL;
-
-       for (; *string; string++) {
-               for (ptr = group; *ptr; ptr++) {
-                       if (*ptr == *string)
-                               return string;
-               }
-       }
-
-       return NULL;
-}
-
 /*
  * get a word from the input stream, also keep track of current line number.
  * words are separated by whitespace.
@@ -317,7 +294,7 @@ static char *dgap_getword(char **in)
 {
        char *ret_ptr = *in;
 
-       char *ptr = dgap_sindex(*in, " \t\n");
+       char *ptr = strpbrk(*in, " \t\n");
 
        /* If no word found, return null */
        if (!ptr)
@@ -349,6 +326,8 @@ static int dgap_gettok(char **in)
 
        if (strstr(dgap_cword, "board")) {
                w = dgap_getword(in);
+               if (!w)
+                       return 0;
                snprintf(dgap_cword, MAXCWORD, "%s", w);
                for (t = dgap_brdtype; t->token != 0; t++) {
                        if (!strcmp(w, t->string))
@@ -535,7 +514,6 @@ static uint dgap_config_get_num_prts(struct board_t *bd)
                return 0;
 
        for (p = bd->bd_config; p; p = p->next) {
-
                switch (p->type) {
                case BNODE:
                        /*
@@ -568,7 +546,6 @@ static char *dgap_create_config_string(struct board_t *bd, char *string)
        }
 
        for (p = bd->bd_config; p; p = p->next) {
-
                switch (p->type) {
                case LNODE:
                        *ptr = '\0';
@@ -662,7 +639,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
 
@@ -682,24 +659,6 @@ static int dgap_parsefile(char **in)
 
                        break;
 
-               case IO:        /* i/o port */
-                       if (p->type != BNODE) {
-                               pr_err("IO port only valid for boards");
-                               return -1;
-                       }
-                       s = dgap_getword(in);
-                       if (!s) {
-                               pr_err("unexpected end of file");
-                               return -1;
-                       }
-                       p->u.board.portstr = kstrdup(s, GFP_KERNEL);
-                       if (kstrtol(s, 0, &p->u.board.port)) {
-                               pr_err("bad number for IO port");
-                               return -1;
-                       }
-                       p->u.board.v_port = 1;
-                       break;
-
                case MEM:       /* memory address */
                        if (p->type != BNODE) {
                                pr_err("memory address only valid for boards");
@@ -710,6 +669,7 @@ static int dgap_parsefile(char **in)
                                pr_err("unexpected end of file");
                                return -1;
                        }
+                       kfree(p->u.board.addrstr);
                        p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
                        if (kstrtoul(s, 0, &p->u.board.addr)) {
                                pr_err("bad number for memory address");
@@ -728,6 +688,7 @@ static int dgap_parsefile(char **in)
                                pr_err("unexpected end of file");
                                return -1;
                        }
+                       kfree(p->u.board.pcibusstr);
                        p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
                        if (kstrtoul(s, 0, &p->u.board.pcibus)) {
                                pr_err("bad number for pci bus");
@@ -739,6 +700,7 @@ static int dgap_parsefile(char **in)
                                pr_err("unexpected end of file");
                                return -1;
                        }
+                       kfree(p->u.board.pcislotstr);
                        p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
                        if (kstrtoul(s, 0, &p->u.board.pcislot)) {
                                pr_err("bad number for pci slot");
@@ -757,6 +719,7 @@ static int dgap_parsefile(char **in)
                                pr_err("unexpected end of file");
                                return -1;
                        }
+                       kfree(p->u.board.method);
                        p->u.board.method = kstrdup(s, GFP_KERNEL);
                        p->u.board.v_method = 1;
                        break;
@@ -771,6 +734,7 @@ static int dgap_parsefile(char **in)
                                pr_err("unexpected end of file");
                                return -1;
                        }
+                       kfree(p->u.board.status);
                        p->u.board.status = kstrdup(s, GFP_KERNEL);
                        break;
 
@@ -820,13 +784,15 @@ static int dgap_parsefile(char **in)
                                pr_err("unexpected end of file");
                                return -1;
                        }
-
+                       kfree(p->u.board.status);
                        p->u.board.status = kstrdup(s, GFP_KERNEL);
 
                        if (p->type == CNODE) {
+                               kfree(p->u.conc.id);
                                p->u.conc.id = kstrdup(s, GFP_KERNEL);
                                p->u.conc.v_id = 1;
                        } else if (p->type == MNODE) {
+                               kfree(p->u.module.id);
                                p->u.module.id = kstrdup(s, GFP_KERNEL);
                                p->u.module.v_id = 1;
                        } else {
@@ -881,7 +847,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = TNODE;
@@ -903,7 +869,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = CUNODE;
@@ -934,7 +900,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = LNODE;
@@ -953,7 +919,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = CNODE;
@@ -965,8 +931,8 @@ static int dgap_parsefile(char **in)
                                brd->u.board.conc1++;
 
                        conc_type = dgap_gettok(in);
-                       if (conc_type == 0 || (conc_type != CX &&
-                           conc_type != EPC)) {
+                       if (conc_type == 0 ||
+                           (conc_type != CX && conc_type != EPC)) {
                                pr_err("failed to set a type of concentratros");
                                return -1;
                        }
@@ -995,7 +961,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = MNODE;
@@ -1006,8 +972,8 @@ static int dgap_parsefile(char **in)
                                brd->u.board.module1++;
 
                        module_type = dgap_gettok(in);
-                       if (module_type == 0 || (module_type != PORTS &&
-                           module_type != MODEM)) {
+                       if (module_type == 0 ||
+                           (module_type != PORTS && module_type != MODEM)) {
                                pr_err("failed to set a type of module");
                                return -1;
                        }
@@ -1023,6 +989,7 @@ static int dgap_parsefile(char **in)
                                        pr_err("unexpected end of file");
                                        return -1;
                                }
+                               kfree(p->u.line.cable);
                                p->u.line.cable = kstrdup(s, GFP_KERNEL);
                                p->u.line.v_cable = 1;
                        }
@@ -1064,6 +1031,7 @@ static int dgap_parsefile(char **in)
                                        pr_err("unexpected end of file");
                                        return -1;
                                }
+                               kfree(p->u.conc.connect);
                                p->u.conc.connect = kstrdup(s, GFP_KERNEL);
                                p->u.conc.v_connect = 1;
                        }
@@ -1074,7 +1042,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = PNODE;
@@ -1096,7 +1064,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = JNODE;
@@ -1118,7 +1086,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = ANODE;
@@ -1140,7 +1108,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = INTRNODE;
@@ -1161,7 +1129,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = TSNODE;
@@ -1183,7 +1151,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = CSNODE;
@@ -1205,7 +1173,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = BSNODE;
@@ -1227,7 +1195,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = USNODE;
@@ -1249,7 +1217,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = FSNODE;
@@ -1271,7 +1239,7 @@ static int dgap_parsefile(char **in)
 
                        p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
                        if (!p->next)
-                               return -1;
+                               return -ENOMEM;
 
                        p = p->next;
                        p->type = VSNODE;
@@ -1306,7 +1274,6 @@ static void dgap_cleanup_nodes(void)
 
                switch (p->type) {
                case BNODE:
-                       kfree(p->u.board.portstr);
                        kfree(p->u.board.addrstr);
                        kfree(p->u.board.pcibusstr);
                        kfree(p->u.board.pcislotstr);
@@ -1384,8 +1351,7 @@ static int dgap_remap(struct board_t *brd)
        if (!request_mem_region(brd->membase, 0x200000, "dgap"))
                return -ENOMEM;
 
-       if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
-                                       "dgap"))
+       if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap"))
                goto err_req_mem;
 
        brd->re_map_membase = ioremap(brd->membase, 0x200000);
@@ -1423,7 +1389,7 @@ static void dgap_unmap(struct board_t *brd)
  * the Linux line discipline way.
  */
 static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
-                               unsigned char *fbuf, int *len)
+                            unsigned char *fbuf, int *len)
 {
        int l = *len;
        int count = 0;
@@ -1446,7 +1412,7 @@ static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
 
                case 0:
                        /* No FF seen yet */
-                       if (c == (unsigned char) '\377')
+                       if (c == (unsigned char)'\377')
                                /* delete this character from stream */
                                ch->pscan_state = 1;
                        else {
@@ -1458,7 +1424,7 @@ static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
 
                case 1:
                        /* first FF seen */
-                       if (c == (unsigned char) '\377') {
+                       if (c == (unsigned char)'\377') {
                                /* doubled ff, transform to single ff */
                                *cout++ = c;
                                *fout++ = TTY_NORMAL;
@@ -1477,7 +1443,6 @@ static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
                        *cout++ = c;
 
                        if (ch->pscan_savechar == 0x0) {
-
                                if (c == 0x0) {
                                        ch->ch_err_break++;
                                        *fout++ = TTY_BREAK;
@@ -1544,15 +1509,15 @@ static void dgap_input(struct channel_t *ch)
 
        rmask = ch->ch_rsize - 1;
 
-       head = readw(&(bs->rx_head));
+       head = readw(&bs->rx_head);
        head &= rmask;
-       tail = readw(&(bs->rx_tail));
+       tail = readw(&bs->rx_tail);
        tail &= rmask;
 
        data_len = (head - tail) & rmask;
 
        if (data_len == 0) {
-               writeb(1, &(bs->idata));
+               writeb(1, &bs->idata);
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
                return;
@@ -1567,9 +1532,8 @@ static void dgap_input(struct channel_t *ch)
            !(ch->ch_tun.un_flags & UN_ISOPEN) ||
            !(tp->termios.c_cflag & CREAD) ||
            (ch->ch_tun.un_flags & UN_CLOSING)) {
-
-               writew(head, &(bs->rx_tail));
-               writeb(1, &(bs->idata));
+               writew(head, &bs->rx_tail);
+               writeb(1, &bs->idata);
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
                return;
@@ -1579,7 +1543,7 @@ static void dgap_input(struct channel_t *ch)
         * If we are throttled, simply don't read any data.
         */
        if (ch->ch_flags & CH_RXBLOCK) {
-               writeb(1, &(bs->idata));
+               writeb(1, &bs->idata);
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
                return;
@@ -1588,10 +1552,10 @@ static void dgap_input(struct channel_t *ch)
        /*
         *      Ignore oruns.
         */
-       tmpchar = readb(&(bs->orun));
+       tmpchar = readb(&bs->orun);
        if (tmpchar) {
                ch->ch_err_overrun++;
-               writeb(0, &(bs->orun));
+               writeb(0, &bs->orun);
        }
 
        /* Decide how much data we can send into the tty layer */
@@ -1626,13 +1590,13 @@ static void dgap_input(struct channel_t *ch)
                 * space to put the data right now.
                 */
                if (!ld->ops->receive_buf) {
-                       writew(head, &(bs->rx_tail));
+                       writew(head, &bs->rx_tail);
                        len = 0;
                }
        }
 
        if (len <= 0) {
-               writeb(1, &(bs->idata));
+               writeb(1, &bs->idata);
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
                if (ld)
@@ -1649,7 +1613,6 @@ static void dgap_input(struct channel_t *ch)
         * of data the card actually has pending...
         */
        while (n) {
-
                s = ((head >= tail) ? head : ch->ch_rsize) - tail;
                s = min(s, n);
 
@@ -1666,8 +1629,8 @@ static void dgap_input(struct channel_t *ch)
                tail &= rmask;
        }
 
-       writew(tail, &(bs->rx_tail));
-       writeb(1, &(bs->idata));
+       writew(tail, &bs->rx_tail);
+       writeb(1, &bs->idata);
        ch->ch_rxcount += len;
 
        /*
@@ -1685,7 +1648,7 @@ static void dgap_input(struct channel_t *ch)
 
                len = tty_buffer_request_room(tp->port, len);
                tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
-                       ch->ch_bd->flipflagbuf, len);
+                                            ch->ch_bd->flipflagbuf, len);
        } else {
                len = tty_buffer_request_room(tp->port, len);
                tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
@@ -1699,7 +1662,6 @@ static void dgap_input(struct channel_t *ch)
 
        if (ld)
                tty_ldisc_deref(ld);
-
 }
 
 static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
@@ -1770,7 +1732,6 @@ static void dgap_carrier(struct channel_t *ch)
         * Test for a VIRTUAL carrier transition to HIGH.
         */
        if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
-
                /*
                 * When carrier rises, wake any threads waiting
                 * for carrier in the open routine.
@@ -1784,7 +1745,6 @@ static void dgap_carrier(struct channel_t *ch)
         * Test for a PHYSICAL carrier transition to HIGH.
         */
        if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
-
                /*
                 * When carrier rises, wake any threads waiting
                 * for carrier in the open routine.
@@ -1806,7 +1766,6 @@ static void dgap_carrier(struct channel_t *ch)
        if ((virt_carrier == 0) &&
            ((ch->ch_flags & CH_CD) != 0) &&
            (phys_carrier == 0)) {
-
                /*
                 *   When carrier drops:
                 *
@@ -1864,7 +1823,6 @@ static int dgap_event(struct board_t *bd)
        int port;
        int reason;
        int modem;
-       int b1;
 
        if (!bd || bd->magic != DGAP_BOARD_MAGIC)
                return -EIO;
@@ -1878,11 +1836,11 @@ static int dgap_event(struct board_t *bd)
                return -EIO;
        }
 
-       eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
+       eaddr = (struct ev_t __iomem *)(vaddr + EVBUF);
 
        /* Get our head and tail */
-       head = readw(&(eaddr->ev_head));
-       tail = readw(&(eaddr->ev_tail));
+       head = readw(&eaddr->ev_head);
+       tail = readw(&eaddr->ev_tail);
 
        /*
         * Forget it if pointers out of range.
@@ -1899,7 +1857,6 @@ static int dgap_event(struct board_t *bd)
         * Loop to process all the events in the buffer.
         */
        while (tail != head) {
-
                /*
                 * Get interrupt information.
                 */
@@ -1909,7 +1866,7 @@ static int dgap_event(struct board_t *bd)
                port   = ioread8(event);
                reason = ioread8(event + 1);
                modem  = ioread8(event + 2);
-               b1     = ioread8(event + 3);
+               ioread8(event + 3);
 
                /*
                 * Make sure the interrupt is valid.
@@ -1942,7 +1899,6 @@ static int dgap_event(struct board_t *bd)
                 * Process received data.
                 */
                if (reason & IFDATA) {
-
                        /*
                         * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
                         * input could send some data to ld, which in turn
@@ -1959,7 +1915,7 @@ static int dgap_event(struct board_t *bd)
                        if (ch->ch_flags & CH_RACTIVE)
                                ch->ch_flags |= CH_RENABLE;
                        else
-                               writeb(1, &(bs->idata));
+                               writeb(1, &bs->idata);
 
                        if (ch->ch_flags & CH_RWAIT) {
                                ch->ch_flags &= ~CH_RWAIT;
@@ -1981,7 +1937,6 @@ static int dgap_event(struct board_t *bd)
                 * Process break.
                 */
                if (reason & IFBREAK) {
-
                        if (ch->ch_tun.un_tty) {
                                /* A break has been indicated */
                                ch->ch_err_break++;
@@ -2027,7 +1982,7 @@ next:
                tail = (tail + 4) & (EVMAX - EVSTART - 4);
        }
 
-       writew(tail, &(eaddr->ev_tail));
+       writew(tail, &eaddr->ev_tail);
        spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
 
        return 0;
@@ -2038,7 +1993,7 @@ next:
  */
 static void dgap_poll_tasklet(unsigned long data)
 {
-       struct board_t *bd = (struct board_t *) data;
+       struct board_t *bd = (struct board_t *)data;
        ulong lock_flags;
        char __iomem *vaddr;
        u16 head, tail;
@@ -2057,7 +2012,6 @@ static void dgap_poll_tasklet(unsigned long data)
         * If board is ready, parse deeper to see if there is anything to do.
         */
        if (bd->state == BOARD_READY) {
-
                struct ev_t __iomem *eaddr;
 
                if (!bd->re_map_membase) {
@@ -2072,11 +2026,11 @@ static void dgap_poll_tasklet(unsigned long data)
                if (!bd->nasync)
                        goto out;
 
-               eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
+               eaddr = (struct ev_t __iomem *)(vaddr + EVBUF);
 
                /* Get our head and tail */
-               head = readw(&(eaddr->ev_head));
-               tail = readw(&(eaddr->ev_tail));
+               head = readw(&eaddr->ev_head);
+               tail = readw(&eaddr->ev_tail);
 
                /*
                 * If there is an event pending. Go service it.
@@ -2091,7 +2045,7 @@ out:
                /*
                 * If board is doing interrupts, ACK the interrupt.
                 */
-               if (bd && bd->intr_running)
+               if (bd->intr_running)
                        readb(bd->re_map_port + 2);
 
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
@@ -2206,7 +2160,7 @@ static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
 
        /* init our poll helper tasklet */
        tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
-                       (unsigned long) brd);
+                    (unsigned long)brd);
 
        ret = dgap_remap(brd);
        if (ret)
@@ -2301,14 +2255,13 @@ static void dgap_poll_handler(ulong dummy)
         */
        if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
                for (i = 0; i < dgap_numboards; i++) {
-
                        brd = dgap_board[i];
 
                        if (brd->state == BOARD_FAILED)
                                continue;
                        if (!brd->intr_running)
                                /* Call the real board poller directly */
-                               dgap_poll_tasklet((unsigned long) brd);
+                               dgap_poll_tasklet((unsigned long)brd);
                }
        } else {
                /*
@@ -2361,7 +2314,7 @@ schedule_poller:
 
        new_time = dgap_poll_time - jiffies;
 
-       if ((ulong) new_time >= 2 * dgap_poll_tick) {
+       if ((ulong)new_time >= 2 * dgap_poll_tick) {
                dgap_poll_time =
                        jiffies +  dgap_jiffies_from_ms(dgap_poll_tick);
        }
@@ -2388,7 +2341,7 @@ schedule_poller:
  *
  *=======================================================================*/
 static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
-                       u8 byte2, uint ncmds)
+                     u8 byte2, uint ncmds)
 {
        char __iomem *vaddr;
        struct __iomem cm_t *cm_addr;
@@ -2415,8 +2368,8 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
        if (!vaddr)
                return;
 
-       cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
-       head = readw(&(cm_addr->cm_head));
+       cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
+       head = readw(&cm_addr->cm_head);
 
        /*
         * Forget it if pointers out of range.
@@ -2430,13 +2383,13 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
         * Put the data in the circular command buffer.
         */
        writeb(cmd, (vaddr + head + CMDSTART + 0));
-       writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
+       writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
        writeb(byte1, (vaddr + head + CMDSTART + 2));
        writeb(byte2, (vaddr + head + CMDSTART + 3));
 
        head = (head + 4) & (CMDMAX - CMDSTART - 4);
 
-       writew(head, &(cm_addr->cm_head));
+       writew(head, &cm_addr->cm_head);
 
        /*
         * Wait if necessary before updating the head
@@ -2445,9 +2398,8 @@ static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
         * is outlandish, declare the FEP dead.
         */
        for (count = dgap_count ;;) {
-
-               head = readw(&(cm_addr->cm_head));
-               tail = readw(&(cm_addr->cm_tail));
+               head = readw(&cm_addr->cm_head);
+               tail = readw(&cm_addr->cm_tail);
 
                n = (head - tail) & (CMDMAX - CMDSTART - 4);
 
@@ -2499,8 +2451,8 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
        if (!vaddr)
                return;
 
-       cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
-       head = readw(&(cm_addr->cm_head));
+       cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
+       head = readw(&cm_addr->cm_head);
 
        /*
         * Forget it if pointers out of range.
@@ -2514,12 +2466,12 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
         * Put the data in the circular command buffer.
         */
        writeb(cmd, (vaddr + head + CMDSTART + 0));
-       writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
-       writew((u16) word, (vaddr + head + CMDSTART + 2));
+       writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
+       writew((u16)word, (vaddr + head + CMDSTART + 2));
 
        head = (head + 4) & (CMDMAX - CMDSTART - 4);
 
-       writew(head, &(cm_addr->cm_head));
+       writew(head, &cm_addr->cm_head);
 
        /*
         * Wait if necessary before updating the head
@@ -2528,9 +2480,8 @@ static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
         * is outlandish, declare the FEP dead.
         */
        for (count = dgap_count ;;) {
-
-               head = readw(&(cm_addr->cm_head));
-               tail = readw(&(cm_addr->cm_tail));
+               head = readw(&cm_addr->cm_head);
+               tail = readw(&cm_addr->cm_tail);
 
                n = (head - tail) & (CMDMAX - CMDSTART - 4);
 
@@ -2582,8 +2533,8 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
        if (!vaddr)
                return;
 
-       cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
-       head = readw(&(cm_addr->cm_head));
+       cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
+       head = readw(&cm_addr->cm_head);
 
        /*
         * Forget it if pointers out of range.
@@ -2598,23 +2549,23 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
         */
 
        /* Write an FF to tell the FEP that we want an extended command */
-       writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
+       writeb((u8)0xff, (vaddr + head + CMDSTART + 0));
 
-       writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
-       writew((u16) cmd, (vaddr + head + CMDSTART + 2));
+       writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
+       writew((u16)cmd, (vaddr + head + CMDSTART + 2));
 
        /*
         * If the second part of the command won't fit,
         * put it at the beginning of the circular buffer.
         */
        if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
-               writew((u16) word, (vaddr + CMDSTART));
+               writew((u16)word, (vaddr + CMDSTART));
        else
-               writew((u16) word, (vaddr + head + CMDSTART + 4));
+               writew((u16)word, (vaddr + head + CMDSTART + 4));
 
        head = (head + 8) & (CMDMAX - CMDSTART - 4);
 
-       writew(head, &(cm_addr->cm_head));
+       writew(head, &cm_addr->cm_head);
 
        /*
         * Wait if necessary before updating the head
@@ -2623,9 +2574,8 @@ static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
         * is outlandish, declare the FEP dead.
         */
        for (count = dgap_count ;;) {
-
-               head = readw(&(cm_addr->cm_head));
-               tail = readw(&(cm_addr->cm_tail));
+               head = readw(&cm_addr->cm_head);
+               tail = readw(&cm_addr->cm_tail);
 
                n = (head - tail) & (CMDMAX - CMDSTART - 4);
 
@@ -2663,7 +2613,7 @@ static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
         * Check parameters.
         */
        bs   = ch->ch_bs;
-       head = readw(&(bs->tx_head));
+       head = readw(&bs->tx_head);
 
        /*
         * If pointers are out of range, just return.
@@ -2695,7 +2645,7 @@ static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
        memcpy_toio(taddr, buf, n);
        head += cnt;
 
-       writew(head, &(bs->tx_head));
+       writew(head, &bs->tx_head);
 }
 
 /*
@@ -2743,19 +2693,18 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
         * If baud rate is zero, flush queues, and set mval to drop DTR.
         */
        if ((ch->ch_c_cflag & (CBAUD)) == 0) {
-
                /* flush rx */
-               head = readw(&(ch->ch_bs->rx_head));
-               writew(head, &(ch->ch_bs->rx_tail));
+               head = readw(&ch->ch_bs->rx_head);
+               writew(head, &ch->ch_bs->rx_tail);
 
                /* flush tx */
-               head = readw(&(ch->ch_bs->tx_head));
-               writew(head, &(ch->ch_bs->tx_tail));
+               head = readw(&ch->ch_bs->tx_head);
+               writew(head, &ch->ch_bs->tx_tail);
 
                ch->ch_flags |= (CH_BAUD0);
 
                /* Drop RTS and DTR */
-               ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
+               ch->ch_mval &= ~(D_RTS(ch) | D_DTR(ch));
                mval = D_DTR(ch) | D_RTS(ch);
                ch->ch_baud_info = 0;
 
@@ -2776,7 +2725,7 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
                /* Handle transition from B0 */
                if (ch->ch_flags & CH_BAUD0) {
                        ch->ch_flags &= ~(CH_BAUD0);
-                       ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
+                       ch->ch_mval |= (D_RTS(ch) | D_DTR(ch));
                }
                mval = D_DTR(ch) | D_RTS(ch);
 
@@ -2910,19 +2859,19 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
                cflag &= 0xffff;
 
                if (cflag != ch->ch_fepcflag) {
-                       ch->ch_fepcflag = (u16) (cflag & 0xffff);
+                       ch->ch_fepcflag = (u16)(cflag & 0xffff);
 
                        /*
                         * Okay to have channel and board
                         * locks held calling this
                         */
-                       dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
+                       dgap_cmdw(ch, SCFLAG, (u16)cflag, 0);
                }
 
                /* Handle transition from B0 */
                if (ch->ch_flags & CH_BAUD0) {
                        ch->ch_flags &= ~(CH_BAUD0);
-                       ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
+                       ch->ch_mval |= (D_RTS(ch) | D_DTR(ch));
                }
                mval = D_DTR(ch) | D_RTS(ch);
        }
@@ -2957,7 +2906,7 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
                ch->ch_fepiflag = iflag;
 
                /* Okay to have channel and board locks held calling this */
-               dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
+               dgap_cmdw(ch, SIFLAG, (u16)ch->ch_fepiflag, 0);
        }
 
        /*
@@ -2982,7 +2931,7 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
                ch->ch_hflow = hflow;
 
                /* Okay to have channel and board locks held calling this */
-               dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
+               dgap_cmdb(ch, SHFLOW, (u8)hflow, 0xff, 0);
        }
 
        /*
@@ -3010,13 +2959,13 @@ static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
                ch->ch_mostat = mval;
 
                /* Okay to have channel and board locks held calling this */
-               dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
+               dgap_cmdb(ch, SMODEM, (u8)mval, D_RTS(ch) | D_DTR(ch), 0);
        }
 
        /*
         * Read modem signals, and then call carrier function.
         */
-       ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
+       ch->ch_mistat = readb(&ch->ch_bs->m_stat);
        dgap_carrier(ch);
 
        /*
@@ -3061,7 +3010,7 @@ static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
        int sleep_on_un_flags;
 
        if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
-               ch->magic != DGAP_CHANNEL_MAGIC)
+           ch->magic != DGAP_CHANNEL_MAGIC)
                return -EIO;
 
        un = tty->driver_data;
@@ -3074,7 +3023,6 @@ static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
 
        /* Loop forever */
        while (1) {
-
                sleep_on_un_flags = 0;
 
                /*
@@ -3101,7 +3049,6 @@ static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
                 */
                if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
                      UN_CLOSING)) {
-
                        /*
                         * Our conditions to leave cleanly and happily:
                         * 1) NONBLOCKING on the tty is set.
@@ -3210,15 +3157,15 @@ static void dgap_tty_flush_buffer(struct tty_struct *tty)
        spin_lock_irqsave(&ch->ch_lock, lock_flags2);
 
        ch->ch_flags &= ~CH_STOP;
-       head = readw(&(ch->ch_bs->tx_head));
-       dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
+       head = readw(&ch->ch_bs->tx_head);
+       dgap_cmdw(ch, FLUSHTX, (u16)head, 0);
        dgap_cmdw(ch, RESUMETX, 0, 0);
-       if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
-               ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
+       if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
+               ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
                wake_up_interruptible(&ch->ch_tun.un_flags_wait);
        }
-       if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
-               ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
+       if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
+               ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
                wake_up_interruptible(&ch->ch_pun.un_flags_wait);
        }
 
@@ -3304,15 +3251,15 @@ static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
        tmask = (ch->ch_tsize - 1);
 
        /* Get Transmit queue pointers */
-       thead = readw(&(bs->tx_head)) & tmask;
-       ttail = readw(&(bs->tx_tail)) & tmask;
+       thead = readw(&bs->tx_head) & tmask;
+       ttail = readw(&bs->tx_tail) & tmask;
 
        /* Get tbusy flag */
-       tbusy = readb(&(bs->tbusy));
+       tbusy = readb(&bs->tbusy);
 
        /* Get Command queue pointers */
-       chead = readw(&(ch->ch_cm->cm_head));
-       ctail = readw(&(ch->ch_cm->cm_tail));
+       chead = readw(&ch->ch_cm->cm_head);
+       ctail = readw(&ch->ch_cm->cm_tail);
 
        spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
        spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
@@ -3348,7 +3295,7 @@ static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
                        if (tbusy != 0) {
                                spin_lock_irqsave(&ch->ch_lock, lock_flags);
                                un->un_flags |= UN_EMPTY;
-                               writeb(1, &(bs->iempty));
+                               writeb(1, &bs->iempty);
                                spin_unlock_irqrestore(&ch->ch_lock,
                                                       lock_flags);
                        }
@@ -3385,7 +3332,6 @@ static int dgap_wait_for_drain(struct tty_struct *tty)
 
        /* Loop until data is drained */
        while (count != 0) {
-
                count = dgap_tty_chars_in_buffer(tty);
 
                if (count == 0)
@@ -3394,7 +3340,7 @@ static int dgap_wait_for_drain(struct tty_struct *tty)
                /* Set flag waiting for drain */
                spin_lock_irqsave(&ch->ch_lock, lock_flags);
                un->un_flags |= UN_EMPTY;
-               writeb(1, &(bs->iempty));
+               writeb(1, &bs->iempty);
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
 
                /* Go to sleep till we get woken up */
@@ -3473,13 +3419,13 @@ static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
        if ((event & UN_LOW) != 0) {
                if ((un->un_flags & UN_LOW) == 0) {
                        un->un_flags |= UN_LOW;
-                       writeb(1, &(bs->ilow));
+                       writeb(1, &bs->ilow);
                }
        }
        if ((event & UN_LOW) != 0) {
                if ((un->un_flags & UN_EMPTY) == 0) {
                        un->un_flags |= UN_EMPTY;
-                       writeb(1, &(bs->iempty));
+                       writeb(1, &bs->iempty);
                }
        }
 }
@@ -3516,8 +3462,8 @@ static int dgap_tty_write_room(struct tty_struct *tty)
        spin_lock_irqsave(&ch->ch_lock, lock_flags);
 
        tmask = ch->ch_tsize - 1;
-       head = readw(&(bs->tx_head)) & tmask;
-       tail = readw(&(bs->tx_tail)) & tmask;
+       head = readw(&bs->tx_head) & tmask;
+       tail = readw(&bs->tx_tail) & tmask;
 
        ret = tail - head - 1;
        if (ret < 0)
@@ -3562,7 +3508,7 @@ static int dgap_tty_write_room(struct tty_struct *tty)
  * In here exists all the Transparent Print magic as well.
  */
 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
-                               int count)
+                         int count)
 {
        struct channel_t *ch;
        struct un_t *un;
@@ -3628,8 +3574,8 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
         */
        if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
                dgap_wmove(ch, ch->ch_digi.digi_onstr,
-                   (int) ch->ch_digi.digi_onlen);
-               head = readw(&(bs->tx_head)) & tmask;
+                          (int)ch->ch_digi.digi_onlen);
+               head = readw(&bs->tx_head) & tmask;
                ch->ch_flags |= CH_PRON;
        }
 
@@ -3639,8 +3585,8 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
         */
        if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
                dgap_wmove(ch, ch->ch_digi.digi_offstr,
-                       (int) ch->ch_digi.digi_offlen);
-               head = readw(&(bs->tx_head)) & tmask;
+                          (int)ch->ch_digi.digi_offlen);
+               head = readw(&bs->tx_head) & tmask;
                ch->ch_flags &= ~CH_PRON;
        }
 
@@ -3657,29 +3603,27 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
                n -= remain;
                vaddr = ch->ch_taddr + head;
 
-               memcpy_toio(vaddr, (u8 *) buf, remain);
+               memcpy_toio(vaddr, (u8 *)buf, remain);
 
                head = ch->ch_tstart;
                buf += remain;
        }
 
        if (n > 0) {
-
                /*
                 * Move rest of data.
                 */
                vaddr = ch->ch_taddr + head;
                remain = n;
 
-               memcpy_toio(vaddr, (u8 *) buf, remain);
+               memcpy_toio(vaddr, (u8 *)buf, remain);
                head += remain;
-
        }
 
        if (count) {
                ch->ch_txcount += count;
                head &= tmask;
-               writew(head, &(bs->tx_head));
+               writew(head, &bs->tx_head);
        }
 
        dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
@@ -3692,15 +3636,15 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
         * Otherwise turn it off right now.
         */
        if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
-               tail = readw(&(bs->tx_tail)) & tmask;
+               tail = readw(&bs->tx_tail) & tmask;
 
                if (tail != head) {
                        un->un_flags |= UN_EMPTY;
-                       writeb(1, &(bs->iempty));
+                       writeb(1, &bs->iempty);
                } else {
                        dgap_wmove(ch, ch->ch_digi.digi_offstr,
-                               (int) ch->ch_digi.digi_offlen);
-                       head = readw(&(bs->tx_head)) & tmask;
+                                  (int)ch->ch_digi.digi_offlen);
+                       head = readw(&bs->tx_head) & tmask;
                        ch->ch_flags &= ~CH_PRON;
                }
        }
@@ -3756,7 +3700,7 @@ static int dgap_tty_tiocmget(struct tty_struct *tty)
 
        spin_lock_irqsave(&ch->ch_lock, lock_flags);
 
-       mstat = readb(&(ch->ch_bs->m_stat));
+       mstat = readb(&ch->ch_bs->m_stat);
        /* Append any outbound signals that might be pending... */
        mstat |= ch->ch_mostat;
 
@@ -3786,7 +3730,7 @@ static int dgap_tty_tiocmget(struct tty_struct *tty)
  * Set modem signals, called by ld.
  */
 static int dgap_tty_tiocmset(struct tty_struct *tty,
-               unsigned int set, unsigned int clear)
+                            unsigned int set, unsigned int clear)
 {
        struct board_t *bd;
        struct channel_t *ch;
@@ -3885,7 +3829,7 @@ static int dgap_tty_send_break(struct tty_struct *tty, int msec)
 #if 0
        dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
 #endif
-       dgap_cmdw(ch, SBREAK, (u16) msec, 0);
+       dgap_cmdw(ch, SBREAK, (u16)msec, 0);
 
        spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
        spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
@@ -3967,7 +3911,7 @@ static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
 
        spin_lock_irqsave(&ch->ch_lock, lock_flags);
 
-       mstat = readb(&(ch->ch_bs->m_stat));
+       mstat = readb(&ch->ch_bs->m_stat);
        /* Append any outbound signals that might be pending... */
        mstat |= ch->ch_mostat;
 
@@ -4037,7 +3981,7 @@ static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
                break;
 
        case TIOCMSET:
-               ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
+               ch->ch_mforce = D_DTR(ch) | D_RTS(ch);
 
                if (arg & TIOCM_RTS)
                        ch->ch_mval |= D_RTS(ch);
@@ -4179,7 +4123,7 @@ static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
        memset(&tmp, 0, sizeof(tmp));
 
        spin_lock_irqsave(&ch->ch_lock, lock_flags);
-       tmp = readw(&(ch->ch_bs->edelay));
+       tmp = readw(&ch->ch_bs->edelay);
        spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
 
        if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
@@ -4207,7 +4151,7 @@ static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
        spin_lock_irqsave(&bd->bd_lock, lock_flags);
        spin_lock_irqsave(&ch->ch_lock, lock_flags2);
 
-       writew((u16) new_digi, &(ch->ch_bs->edelay));
+       writew((u16)new_digi, &ch->ch_bs->edelay);
 
        dgap_param(ch, bd, un->un_type);
 
@@ -4259,7 +4203,6 @@ static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
                return -EFAULT;
 
        if (bd->bd_flags & BD_FEP5PLUS) {
-
                spin_lock_irqsave(&bd->bd_lock, lock_flags);
                spin_lock_irqsave(&ch->ch_lock, lock_flags2);
 
@@ -4278,7 +4221,7 @@ static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
  * dgap_set_termios()
  */
 static void dgap_tty_set_termios(struct tty_struct *tty,
-                               struct ktermios *old_termios)
+                                struct ktermios *old_termios)
 {
        struct board_t *bd;
        struct channel_t *ch;
@@ -4351,7 +4294,6 @@ static void dgap_tty_throttle(struct tty_struct *tty)
 
        spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
        spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
-
 }
 
 static void dgap_tty_unthrottle(struct tty_struct *tty)
@@ -4442,7 +4384,7 @@ static int dgap_tty_open(struct tty_struct *tty, struct file *file)
         * sleep waiting for it to happen or they cancel the open.
         */
        rc = wait_event_interruptible(brd->state_wait,
-               (brd->state & BOARD_READY));
+                                     (brd->state & BOARD_READY));
 
        if (rc)
                return rc;
@@ -4510,15 +4452,14 @@ static int dgap_tty_open(struct tty_struct *tty, struct file *file)
         * Initialize if neither terminal or printer is open.
         */
        if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
-
                ch->ch_mforce = 0;
                ch->ch_mval = 0;
 
                /*
                 * Flush input queue.
                 */
-               head = readw(&(bs->rx_head));
-               writew(head, &(bs->rx_tail));
+               head = readw(&bs->rx_head);
+               writew(head, &bs->rx_tail);
 
                ch->ch_flags = 0;
                ch->pscan_state = 0;
@@ -4568,7 +4509,6 @@ static int dgap_tty_open(struct tty_struct *tty, struct file *file)
  */
 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
 {
-       struct ktermios *ts;
        struct board_t *bd;
        struct channel_t *ch;
        struct un_t *un;
@@ -4589,8 +4529,6 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file)
        if (!bd || bd->magic != DGAP_BOARD_MAGIC)
                return;
 
-       ts = &tty->termios;
-
        spin_lock_irqsave(&ch->ch_lock, lock_flags);
 
        /*
@@ -4630,7 +4568,6 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file)
         */
        if ((ch->ch_open_count == 0) &&
            !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
-
                ch->ch_flags &= ~(CH_RXBLOCK);
 
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
@@ -4651,15 +4588,15 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file)
                 * If we have HUPCL set, lower DTR and RTS
                 */
                if (ch->ch_c_cflag & HUPCL) {
-                       ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
-                       dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
+                       ch->ch_mostat &= ~(D_RTS(ch) | D_DTR(ch));
+                       dgap_cmdb(ch, SMODEM, 0, D_DTR(ch) | D_RTS(ch), 0);
 
                        /*
                         * Go to sleep to ensure RTS/DTR
                         * have been dropped for modems to see it.
                         */
                        spin_unlock_irqrestore(&ch->ch_lock,
-                                       lock_flags);
+                                              lock_flags);
 
                        /* .25 second delay for dropping RTS/DTR */
                        schedule_timeout_interruptible(msecs_to_jiffies(250));
@@ -4670,7 +4607,6 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file)
                ch->pscan_state = 0;
                ch->pscan_savechar = 0;
                ch->ch_baud_info = 0;
-
        }
 
        /*
@@ -4678,7 +4614,7 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file)
         */
        if ((un->un_type == DGAP_PRINT)  && (ch->ch_flags & CH_PRON)) {
                dgap_wmove(ch, ch->ch_digi.digi_offstr,
-                       (int) ch->ch_digi.digi_offlen);
+                          (int)ch->ch_digi.digi_offlen);
                ch->ch_flags &= ~CH_PRON;
        }
 
@@ -4813,7 +4749,7 @@ static void dgap_tty_flush_chars(struct tty_struct *tty)
  * The usual assortment of ioctl's
  */
 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
-               unsigned long arg)
+                         unsigned long arg)
 {
        struct board_t *bd;
        struct channel_t *ch;
@@ -4822,7 +4758,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
        u16 head;
        ulong lock_flags = 0;
        ulong lock_flags2 = 0;
-       void __user *uarg = (void __user *) arg;
+       void __user *uarg = (void __user *)arg;
 
        if (!tty || tty->magic != TTY_MAGIC)
                return -ENODEV;
@@ -4849,9 +4785,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
        }
 
        switch (cmd) {
-
        /* Here are all the standard ioctl's that we MUST implement */
-
        case TCSBRK:
                /*
                 * TCSBRK is SVID version: non-zero arg --> no break
@@ -4876,7 +4810,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                spin_lock_irqsave(&ch->ch_lock, lock_flags2);
 
                if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
-                       dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
+                       dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
 
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
@@ -4903,7 +4837,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                spin_lock_irqsave(&bd->bd_lock, lock_flags);
                spin_lock_irqsave(&ch->ch_lock, lock_flags2);
 
-               dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
+               dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
 
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
@@ -4930,7 +4864,7 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                spin_lock_irqsave(&bd->bd_lock, lock_flags);
                spin_lock_irqsave(&ch->ch_lock, lock_flags2);
 
-               dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
+               dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
 
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
@@ -4954,13 +4888,13 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
 
                return put_user(C_CLOCAL(tty) ? 1 : 0,
-                               (unsigned long __user *) arg);
+                               (unsigned long __user *)arg);
 
        case TIOCSSOFTCAR:
                spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
 
-               rc = get_user(arg, (unsigned long __user *) arg);
+               rc = get_user(arg, (unsigned long __user *)arg);
                if (rc)
                        return rc;
 
@@ -5009,9 +4943,9 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
 
                if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
                        if (!(un->un_type == DGAP_PRINT)) {
-                               head = readw(&(ch->ch_bs->rx_head));
-                               writew(head, &(ch->ch_bs->rx_tail));
-                               writeb(0, &(ch->ch_bs->orun));
+                               head = readw(&ch->ch_bs->rx_head);
+                               writew(head, &ch->ch_bs->rx_tail);
+                               writeb(0, &ch->ch_bs->orun);
                        }
                }
 
@@ -5024,15 +4958,15 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                }
 
                ch->ch_flags &= ~CH_STOP;
-               head = readw(&(ch->ch_bs->tx_head));
-               dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
+               head = readw(&ch->ch_bs->tx_head);
+               dgap_cmdw(ch, FLUSHTX, (u16)head, 0);
                dgap_cmdw(ch, RESUMETX, 0, 0);
-               if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
-                       ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
+               if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
+                       ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
                        wake_up_interruptible(&ch->ch_tun.un_flags_wait);
                }
-               if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
-                       ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
+               if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
+                       ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
                        wake_up_interruptible(&ch->ch_pun.un_flags_wait);
                }
                if (waitqueue_active(&tty->write_wait))
@@ -5060,8 +4994,8 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                if (cmd == TCSETSF) {
                        /* flush rx */
                        ch->ch_flags &= ~CH_STOP;
-                       head = readw(&(ch->ch_bs->rx_head));
-                       writew(head, &(ch->ch_bs->rx_tail));
+                       head = readw(&ch->ch_bs->rx_head);
+                       writew(head, &ch->ch_bs->rx_tail);
                }
 
                /* now wait for all the output to drain */
@@ -5101,7 +5035,6 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                }
 
                switch (arg) {
-
                case TCOON:
                        spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                        spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
@@ -5139,7 +5072,6 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
 
                /* set information for ditty */
                if (cmd == (DIGI_SETAW)) {
-
                        spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
                        spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
                        rc = dgap_wait_for_drain(tty);
@@ -5874,14 +5806,12 @@ static ssize_t dgap_tty_name_show(struct device *d,
        cn = ch->ch_portnum;
 
        for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
-
                if ((cptr->type == BNODE) &&
                    ((cptr->u.board.type == APORT2_920P) ||
                     (cptr->u.board.type == APORT4_920P) ||
                     (cptr->u.board.type == APORT8_920P) ||
                     (cptr->u.board.type == PAPORT4) ||
                     (cptr->u.board.type == PAPORT8))) {
-
                        found = TRUE;
                        if (cptr->u.board.v_start)
                                starto = cptr->u.board.start;
@@ -5910,7 +5840,6 @@ static ssize_t dgap_tty_name_show(struct device *d,
                }
 
                if (cptr->type == CNODE) {
-
                        for (i = 0; i < cptr->u.conc.nport; i++) {
                                if (cn != (i + ncount))
                                        continue;
@@ -5927,7 +5856,6 @@ static ssize_t dgap_tty_name_show(struct device *d,
                }
 
                if (cptr->type == MNODE) {
-
                        for (i = 0; i < cptr->u.module.nport; i++) {
                                if (cn != (i + ncount))
                                        continue;
@@ -5971,31 +5899,31 @@ static struct attribute *dgap_sysfs_tty_entries[] = {
 static void dgap_create_ports_sysfiles(struct board_t *bd)
 {
        dev_set_drvdata(&bd->pdev->dev, bd);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
-       device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_state);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_baud);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_msignals);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_iflag);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_cflag);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_oflag);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_lflag);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
+       device_create_file(&bd->pdev->dev, &dev_attr_ports_txcount);
 }
 
 /* removes all the sys files created for that port */
 static void dgap_remove_ports_sysfiles(struct board_t *bd)
 {
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_state);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_baud);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_msignals);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_iflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_cflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_oflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_lflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_txcount);
 }
 
 /*
@@ -6056,7 +5984,7 @@ static int dgap_test_bios(struct board_t *brd)
        brd->wait_for_bios = 0;
        while (brd->wait_for_bios < 1000) {
                /* Check to see if BIOS thinks board is good. (GD). */
-               if (word == *(u16 *) "GD")
+               if (word == *(u16 *)"GD")
                        return 0;
                msleep_interruptible(10);
                brd->wait_for_bios++;
@@ -6067,7 +5995,7 @@ static int dgap_test_bios(struct board_t *brd)
        err1 = readw(addr + SEQUENCE);
        err2 = readw(addr + ERROR);
        dev_warn(&brd->pdev->dev, "%s failed diagnostics.  Error #(%x,%x).\n",
-               brd->name, err1, err2);
+                brd->name, err1, err2);
        brd->state = BOARD_FAILED;
        brd->dpastatus = BD_NOBIOS;
 
@@ -6117,7 +6045,6 @@ static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
 
        writel(0xbfc01004, (addr + 0xc34));
        writel(0x3, (addr + 0xc30));
-
 }
 
 /*
@@ -6143,12 +6070,12 @@ static int dgap_test_fep(struct board_t *brd)
        brd->wait_for_fep = 0;
        while (brd->wait_for_fep < 500) {
                /* Check to see if FEP is up and running now. */
-               if (word == *(u16 *) "OS") {
+               if (word == *(u16 *)"OS") {
                        /*
                         * Check to see if the board can support FEP5+ commands.
                        */
                        word = readw(addr + FEP5_PLUS);
-                       if (word == *(u16 *) "5A")
+                       if (word == *(u16 *)"5A")
                                brd->bd_flags |= BD_FEP5PLUS;
 
                        return 0;
@@ -6192,7 +6119,6 @@ static void dgap_do_reset_board(struct board_t *brd)
                if (check == FEPRST)
                        break;
                udelay(10);
-
        }
        if (i > 1000) {
                dev_warn(&brd->pdev->dev,
@@ -6235,8 +6161,8 @@ static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
 
        vaddr = brd->re_map_membase;
 
-       offset = readw((u16 *) (vaddr + DOWNREQ));
-       to_dp = (struct downld_t *) (vaddr + (int) offset);
+       offset = readw((u16 *)(vaddr + DOWNREQ));
+       to_dp = (struct downld_t *)(vaddr + (int)offset);
        memcpy_toio(to_dp, uaddr, len);
 
        /* Tell card we have data for it */
@@ -6289,7 +6215,6 @@ static void dgap_get_vpd(struct board_t *brd)
         * the first 2 bytes (header) should be 0x55, 0xAA
         */
        if (byte1 == 0x55 && byte2 == 0xAA) {
-
                base_offset = 0;
 
                /*
@@ -6297,7 +6222,6 @@ static void dgap_get_vpd(struct board_t *brd)
                 * for the VPD offset.
                 */
                while (base_offset <= EXPANSION_ROM_SIZE) {
-
                        /*
                         * Lots of magic numbers here.
                         *
@@ -6441,7 +6365,6 @@ static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
                return;
 
        dev_set_drvdata(c, un);
-
 }
 
 static void dgap_remove_tty_sysfs(struct device *c)
@@ -6477,7 +6400,6 @@ static int dgap_tty_register_ports(struct board_t *brd)
 
        ch = brd->channels[0];
        for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
-
                struct device *classp;
 
                classp = tty_port_register_device(&brd->serial_ports[i],
@@ -6581,7 +6503,6 @@ static int dgap_request_irq(struct board_t *brd)
         * Set up our interrupt handler if we are set to do interrupts.
         */
        if (dgap_config_get_useintr(brd) && brd->irq) {
-
                rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
 
                if (!rc)
@@ -6609,7 +6530,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
 
        if (fw_info[card_type].conf_name) {
                ret = request_firmware(&fw, fw_info[card_type].conf_name,
-                                        &pdev->dev);
+                                      &pdev->dev);
                if (ret) {
                        dev_err(&pdev->dev, "config file %s not found\n",
                                fw_info[card_type].conf_name);
@@ -6662,7 +6583,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
 
        if (fw_info[card_type].bios_name) {
                ret = request_firmware(&fw, fw_info[card_type].bios_name,
-                                       &pdev->dev);
+                                      &pdev->dev);
                if (ret) {
                        dev_err(&pdev->dev, "bios file %s not found\n",
                                fw_info[card_type].bios_name);
@@ -6679,7 +6600,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
 
        if (fw_info[card_type].fep_name) {
                ret = request_firmware(&fw, fw_info[card_type].fep_name,
-                                       &pdev->dev);
+                                      &pdev->dev);
                if (ret) {
                        dev_err(&pdev->dev, "dgap: fep file %s not found\n",
                                fw_info[card_type].fep_name);
@@ -6700,7 +6621,7 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
         * is requesting a concentrator image from us.
         */
        if ((bd->type == PCX) || (bd->type == PEPC)) {
-               chk_addr = (u16 *) (vaddr + DOWNREQ);
+               chk_addr = (u16 *)(vaddr + DOWNREQ);
                /* Nonzero if FEP is requesting concentrator image. */
                check = readw(chk_addr);
                vaddr = brd->re_map_membase;
@@ -6708,14 +6629,14 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
 
        if (fw_info[card_type].con_name && check && vaddr) {
                ret = request_firmware(&fw, fw_info[card_type].con_name,
-                                       &pdev->dev);
+                                      &pdev->dev);
                if (ret) {
                        dev_err(&pdev->dev, "conc file %s not found\n",
                                fw_info[card_type].con_name);
                        return ret;
                }
                /* Put concentrator firmware loading code here */
-               offset = readw((u16 *) (vaddr + DOWNREQ));
+               offset = readw((u16 *)(vaddr + DOWNREQ));
                memcpy_toio(offset, fw->data, fw->size);
 
                dgap_do_conc_load(brd, (char *)fw->data, fw->size)
@@ -6798,14 +6719,13 @@ static int dgap_tty_init(struct board_t *brd)
        ch = brd->channels[0];
        vaddr = brd->re_map_membase;
 
-       bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
-       cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
+       bs = (struct bs_t __iomem *)((ulong)vaddr + CHANBUF);
+       cm = (struct cm_t __iomem *)((ulong)vaddr + CMDBUF);
 
        brd->bd_bs = bs;
 
        /* Set up channel variables */
        for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
-
                spin_lock_init(&ch->ch_lock);
 
                /* Store all our magic numbers */
@@ -6839,12 +6759,12 @@ static int dgap_tty_init(struct board_t *brd)
                        ch->ch_dsr      = DM_DSR;
                }
 
-               ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
-               ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
+               ch->ch_taddr = vaddr + (ioread16(&ch->ch_bs->tx_seg) << 4);
+               ch->ch_raddr = vaddr + (ioread16(&ch->ch_bs->rx_seg) << 4);
                ch->ch_tx_win = 0;
                ch->ch_rx_win = 0;
-               ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
-               ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
+               ch->ch_tsize = readw(&ch->ch_bs->tx_max) + 1;
+               ch->ch_rsize = readw(&ch->ch_bs->rx_max) + 1;
                ch->ch_tstart = 0;
                ch->ch_rstart = 0;
 
@@ -6862,7 +6782,7 @@ static int dgap_tty_init(struct board_t *brd)
 
                dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
 
-               ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
+               ch->ch_mistat = readb(&ch->ch_bs->m_stat);
 
                init_waitqueue_head(&ch->ch_flags_wait);
                init_waitqueue_head(&ch->ch_tun.un_flags_wait);
@@ -6870,18 +6790,18 @@ static int dgap_tty_init(struct board_t *brd)
 
                /* Turn on all modem interrupts for now */
                modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
-               writeb(modem, &(ch->ch_bs->m_int));
+               writeb(modem, &ch->ch_bs->m_int);
 
                /*
                 * Set edelay to 0 if interrupts are turned on,
                 * otherwise set edelay to the usual 100.
                 */
                if (brd->intr_used)
-                       writew(0, &(ch->ch_bs->edelay));
+                       writew(0, &ch->ch_bs->edelay);
                else
-                       writew(100, &(ch->ch_bs->edelay));
+                       writew(100, &ch->ch_bs->edelay);
 
-               writeb(1, &(ch->ch_bs->idata));
+               writeb(1, &ch->ch_bs->idata);
        }
 
        return 0;
@@ -7073,8 +6993,8 @@ static int dgap_start(void)
        }
 
        device = device_create(dgap_class, NULL,
-               MKDEV(DIGI_DGAP_MAJOR, 0),
-               NULL, "dgap_mgmt");
+                              MKDEV(DIGI_DGAP_MAJOR, 0),
+                              NULL, "dgap_mgmt");
        if (IS_ERR(device)) {
                rc = PTR_ERR(device);
                goto failed_device;
index e707ed5fe94937d4eefbe82b646523d4422eacce..c84dbf2a06841cc9e25237073e8a2a400a3983c9 100644 (file)
 #define        ID      76
 #define CABLE  77
 #define CONNECT        78
-#define        IO      79
 #define        MEM     80
 #define DPSZ   81
 
@@ -1152,8 +1151,6 @@ struct cnode {
        union {
                struct {
                        char  type;     /* Board Type           */
-                       long  port;     /* I/O Address          */
-                       char  *portstr; /* I/O Address in string */
                        long  addr;     /* Memory Address       */
                        char  *addrstr; /* Memory Address in string */
                        long  pcibus;   /* PCI BUS              */
@@ -1164,7 +1161,6 @@ struct cnode {
                        char  *id;      /* tty id               */
                        long  start;    /* start of tty counting */
                        char  *method;  /* Install method       */
-                       char  v_port;
                        char  v_addr;
                        char  v_pcibus;
                        char  v_pcislot;
index a629a78964ce0d2f4c4afa59f39fb7403582c547..75040daa40ce8200505817189f39e121059c829a 100644 (file)
@@ -115,7 +115,6 @@ static inline void cls_set_cts_flow_control(struct channel_t *ch)
                &ch->ch_cls_uart->isr_fcr);
 
        ch->ch_t_tlevel = 16;
-
 }
 
 static inline void cls_set_ixon_flow_control(struct channel_t *ch)
@@ -161,7 +160,6 @@ static inline void cls_set_ixon_flow_control(struct channel_t *ch)
        writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
                UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
                &ch->ch_cls_uart->isr_fcr);
-
 }
 
 static inline void cls_set_no_output_flow_control(struct channel_t *ch)
@@ -205,7 +203,6 @@ static inline void cls_set_no_output_flow_control(struct channel_t *ch)
        ch->ch_r_watermark = 0;
        ch->ch_t_tlevel = 16;
        ch->ch_r_tlevel = 16;
-
 }
 
 static inline void cls_set_rts_flow_control(struct channel_t *ch)
@@ -244,7 +241,6 @@ static inline void cls_set_rts_flow_control(struct channel_t *ch)
 
        ch->ch_r_watermark = 4;
        ch->ch_r_tlevel = 8;
-
 }
 
 static inline void cls_set_ixoff_flow_control(struct channel_t *ch)
@@ -286,7 +282,6 @@ static inline void cls_set_ixoff_flow_control(struct channel_t *ch)
        writeb((UART_FCR_ENABLE_FIFO | UART_16654_FCR_RXTRIGGER_16 |
                UART_16654_FCR_TXTRIGGER_16 | UART_FCR_CLEAR_RCVR),
                &ch->ch_cls_uart->isr_fcr);
-
 }
 
 static inline void cls_set_no_input_flow_control(struct channel_t *ch)
@@ -325,7 +320,6 @@ static inline void cls_set_no_input_flow_control(struct channel_t *ch)
 
        ch->ch_t_tlevel = 16;
        ch->ch_r_tlevel = 16;
-
 }
 
 /*
@@ -384,7 +378,6 @@ static inline void cls_parse_isr(struct dgnc_board *brd, uint port)
 
        /* Here we try to figure out what caused the interrupt to happen */
        while (1) {
-
                isr = readb(&ch->ch_cls_uart->isr_fcr);
 
                /* Bail if no pending interrupt on port */
@@ -445,7 +438,7 @@ static void cls_param(struct tty_struct *tty)
        if (!tty || tty->magic != TTY_MAGIC)
                return;
 
-       un = (struct un_t *) tty->driver_data;
+       un = (struct un_t *)tty->driver_data;
        if (!un || un->magic != DGNC_UNIT_MAGIC)
                return;
 
@@ -478,7 +471,6 @@ static void cls_param(struct tty_struct *tty)
                ch->ch_old_baud = 0;
                return;
        } else if (ch->ch_custom_speed) {
-
                baud = ch->ch_custom_speed;
                /* Handle transition from B0 */
                if (ch->ch_flags & CH_BAUD0) {
@@ -526,7 +518,7 @@ static void cls_param(struct tty_struct *tty)
                 * unit is NOT open
                 */
                if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
-                                        (un->un_type == DGNC_PRINT))
+                   (un->un_type == DGNC_PRINT))
                        baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
                else
                        baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
@@ -540,7 +532,7 @@ static void cls_param(struct tty_struct *tty)
                jindex = baud;
 
                if ((iindex >= 0) && (iindex < 4) && (jindex >= 0) &&
-                                                               (jindex < 16)) {
+                   (jindex < 16)) {
                        baud = bauds[iindex][jindex];
                } else {
                        baud = 0;
@@ -628,13 +620,13 @@ static void cls_param(struct tty_struct *tty)
         * we are in hardware flow control mode, or CLOCAL/FORCEDCD is not set.
         */
        if ((ch->ch_digi.digi_flags & CTSPACE) ||
-               (ch->ch_digi.digi_flags & RTSPACE) ||
-               (ch->ch_c_cflag & CRTSCTS) ||
-               !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
-               !(ch->ch_c_cflag & CLOCAL))
-                       ier |= UART_IER_MSI;
+           (ch->ch_digi.digi_flags & RTSPACE) ||
+           (ch->ch_c_cflag & CRTSCTS) ||
+           !(ch->ch_digi.digi_flags & DIGI_FORCEDCD) ||
+           !(ch->ch_c_cflag & CLOCAL))
+               ier |= UART_IER_MSI;
        else
-                       ier &= ~UART_IER_MSI;
+               ier &= ~UART_IER_MSI;
 
        ier |= UART_IER_THRI;
 
@@ -649,7 +641,7 @@ static void cls_param(struct tty_struct *tty)
                 * disable flow control
                 */
                if ((ch->ch_startc == _POSIX_VDISABLE) ||
-                                        (ch->ch_stopc == _POSIX_VDISABLE))
+                   (ch->ch_stopc == _POSIX_VDISABLE))
                        cls_set_no_output_flow_control(ch);
                else
                        cls_set_ixon_flow_control(ch);
@@ -665,7 +657,7 @@ static void cls_param(struct tty_struct *tty)
                 * flow control
                 */
                if ((ch->ch_startc == _POSIX_VDISABLE) ||
-                               (ch->ch_stopc == _POSIX_VDISABLE))
+                   (ch->ch_stopc == _POSIX_VDISABLE))
                        cls_set_no_input_flow_control(ch);
                else
                        cls_set_ixoff_flow_control(ch);
@@ -684,7 +676,7 @@ static void cls_param(struct tty_struct *tty)
  */
 static void cls_tasklet(unsigned long data)
 {
-       struct dgnc_board *bd = (struct dgnc_board *) data;
+       struct dgnc_board *bd = (struct dgnc_board *)data;
        struct channel_t *ch;
        unsigned long flags;
        int i;
@@ -710,7 +702,6 @@ static void cls_tasklet(unsigned long data)
         * If board is ready, parse deeper to see if there is anything to do.
         */
        if ((state == BOARD_READY) && (ports > 0)) {
-
                /* Loop on each port */
                for (i = 0; i < ports; i++) {
                        ch = bd->channels[i];
@@ -746,7 +737,6 @@ static void cls_tasklet(unsigned long data)
        }
 
        spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
-
 }
 
 /*
@@ -854,10 +844,8 @@ static void cls_copy_data_from_uart_to_queue(struct channel_t *ch)
                 * Discard character if we are ignoring the error mask.
                */
                if (linestatus & error_mask)  {
-                       unsigned char discard;
-
                        linestatus = 0;
-                       discard = readb(&ch->ch_cls_uart->txrx);
+                       readb(&ch->ch_cls_uart->txrx);
                        continue;
                }
 
@@ -916,7 +904,7 @@ static int cls_drain(struct tty_struct *tty, uint seconds)
        if (!tty || tty->magic != TTY_MAGIC)
                return -ENXIO;
 
-       un = (struct un_t *) tty->driver_data;
+       un = (struct un_t *)tty->driver_data;
        if (!un || un->magic != DGNC_UNIT_MAGIC)
                return -ENXIO;
 
@@ -945,7 +933,7 @@ static void cls_flush_uart_write(struct channel_t *ch)
                return;
 
        writeb((UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_XMIT),
-                                               &ch->ch_cls_uart->isr_fcr);
+              &ch->ch_cls_uart->isr_fcr);
        udelay(10);
 
        ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
@@ -991,7 +979,7 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
 
        /* If port is "stopped", don't send any data to the UART */
        if ((ch->ch_flags & CH_FORCED_STOP) ||
-                                (ch->ch_flags & CH_BREAK_SENDING))
+           (ch->ch_flags & CH_BREAK_SENDING))
                goto exit_unlock;
 
        if (!(ch->ch_flags & (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM)))
@@ -1008,7 +996,6 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
        n = min(n, qlen);
 
        while (n > 0) {
-
                /*
                 * If RTS Toggle mode is on, turn on RTS now if not already set,
                 * and make sure we get an event when the data transfer has
@@ -1182,7 +1169,7 @@ static void cls_uart_init(struct channel_t *ch)
        readb(&ch->ch_cls_uart->txrx);
 
        writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT),
-                                                &ch->ch_cls_uart->isr_fcr);
+              &ch->ch_cls_uart->isr_fcr);
        udelay(10);
 
        ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
@@ -1309,6 +1296,5 @@ static void cls_vpd(struct dgnc_board *brd)
        }
        pr_info("\n");
 
-       if (re_map_vpdbase)
-               iounmap(re_map_vpdbase);
+       iounmap(re_map_vpdbase);
 }
index 7546aff6500243cda1e9806c4070ec9827c528a6..fc6d2989e28ff01a6195313180f6e601a0ca6a50 100644 (file)
@@ -13,7 +13,6 @@
  * PURPOSE.  See the GNU General Public License for more details.
  */
 
-
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pci.h>
@@ -39,7 +38,6 @@ MODULE_SUPPORTED_DEVICE("dgnc");
  */
 static int             dgnc_start(void);
 static int             dgnc_finalize_board_init(struct dgnc_board *brd);
-static void            dgnc_init_globals(void);
 static int             dgnc_found_board(struct pci_dev *pdev, int id);
 static void            dgnc_cleanup_board(struct dgnc_board *brd);
 static void            dgnc_poll_handler(ulong dummy);
@@ -57,13 +55,13 @@ static const struct file_operations dgnc_BoardFops = {
        .release        =       dgnc_mgmt_close
 };
 
-
 /*
  * Globals
  */
 uint                   dgnc_NumBoards;
 struct dgnc_board              *dgnc_Board[MAXBOARDS];
 DEFINE_SPINLOCK(dgnc_global_lock);
+DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
 uint                   dgnc_Major;
 int                    dgnc_poll_tick = 20;    /* Poll interval - 20 ms */
 
@@ -75,12 +73,10 @@ static struct class *dgnc_class;
 /*
  * Poller stuff
  */
-static DEFINE_SPINLOCK(dgnc_poll_lock); /* Poll scheduling lock */
 static ulong           dgnc_poll_time; /* Time of next poll */
 static uint            dgnc_poll_stop; /* Used to tell poller to stop */
 static struct timer_list dgnc_poll_timer;
 
-
 static const struct pci_device_id dgnc_pci_tbl[] = {
        {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_DID),     .driver_data = 0},
        {PCI_DEVICE(DIGI_VID, PCI_DEVICE_CLASSIC_4_422_DID), .driver_data = 1},
@@ -171,7 +167,7 @@ static void dgnc_cleanup_module(void)
  */
 static int __init dgnc_init_module(void)
 {
-       int rc = 0;
+       int rc;
 
        /*
         * Initialize global stuff
@@ -216,8 +212,8 @@ static int dgnc_start(void)
        unsigned long flags;
        struct device *dev;
 
-       /* make sure that the globals are init'd before we do anything else */
-       dgnc_init_globals();
+       /* make sure timer is initialized before we do anything else */
+       init_timer(&dgnc_poll_timer);
 
        /*
         * Register our base character device into the kernel.
@@ -241,7 +237,7 @@ static int dgnc_start(void)
        }
 
        dev = device_create(dgnc_class, NULL,
-                       MKDEV(dgnc_Major, 0),
+                           MKDEV(dgnc_Major, 0),
                        NULL, "dgnc_mgmt");
        if (IS_ERR(dev)) {
                rc = PTR_ERR(dev);
@@ -355,13 +351,11 @@ static void dgnc_cleanup_board(struct dgnc_board *brd)
                }
        }
 
-
        dgnc_Board[brd->boardnum] = NULL;
 
        kfree(brd);
 }
 
-
 /*
  * dgnc_found_board()
  *
@@ -422,9 +416,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
        pci_irq = pdev->irq;
        brd->irq = pci_irq;
 
-
        switch (brd->device) {
-
        case PCI_DEVICE_CLASSIC_4_DID:
        case PCI_DEVICE_CLASSIC_8_DID:
        case PCI_DEVICE_CLASSIC_4_422_DID:
@@ -442,7 +434,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
                 * 4    Memory Mapped UARTs and Status
                 */
 
-
                /* get the PCI Base Address Registers */
                brd->membase = pci_resource_start(pdev, 4);
 
@@ -461,7 +452,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
                brd->iobase     = pci_resource_start(pdev, 1);
                brd->iobase_end = pci_resource_end(pdev, 1);
-               brd->iobase     = ((unsigned int) (brd->iobase)) & 0xFFFE;
+               brd->iobase     = ((unsigned int)(brd->iobase)) & 0xFFFE;
 
                /* Assign the board_ops struct */
                brd->bd_ops = &dgnc_cls_ops;
@@ -483,7 +474,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
 
                break;
 
-
        case PCI_DEVICE_NEO_4_DID:
        case PCI_DEVICE_NEO_8_DID:
        case PCI_DEVICE_NEO_2DB9_DID:
@@ -525,7 +515,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
                dgnc_do_remap(brd);
 
                if (brd->re_map_membase) {
-
                        /* Read and store the dvid after remapping */
                        brd->dvid = readb(brd->re_map_membase + 0x8D);
 
@@ -538,7 +527,6 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
                dev_err(&brd->pdev->dev,
                        "Didn't find any compatible Neo/Classic PCI boards.\n");
                return -ENXIO;
-
        }
 
        /*
@@ -571,7 +559,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
        /* init our poll helper tasklet */
        tasklet_init(&brd->helper_tasklet,
                     brd->bd_ops->tasklet,
-                    (unsigned long) brd);
+                    (unsigned long)brd);
 
        spin_lock_irqsave(&dgnc_global_lock, flags);
        brd->msgbuf = NULL;
@@ -590,10 +578,8 @@ failed:
        brd->dpastatus = BD_NOFEP;
 
        return -ENXIO;
-
 }
 
-
 static int dgnc_finalize_board_init(struct dgnc_board *brd)
 {
        int rc = 0;
@@ -621,14 +607,12 @@ static int dgnc_finalize_board_init(struct dgnc_board *brd)
  */
 static void dgnc_do_remap(struct dgnc_board *brd)
 {
-
        if (!brd || brd->magic != DGNC_BOARD_MAGIC)
                return;
 
        brd->re_map_membase = ioremap(brd->membase, 0x1000);
 }
 
-
 /*****************************************************************************
 *
 * Function:
@@ -688,7 +672,7 @@ static void dgnc_poll_handler(ulong dummy)
 
        new_time = dgnc_poll_time - jiffies;
 
-       if ((ulong) new_time >= 2 * dgnc_poll_tick)
+       if ((ulong)new_time >= 2 * dgnc_poll_tick)
                dgnc_poll_time = jiffies + dgnc_jiffies_from_ms(dgnc_poll_tick);
 
        setup_timer(&dgnc_poll_timer, dgnc_poll_handler, 0);
@@ -698,23 +682,3 @@ static void dgnc_poll_handler(ulong dummy)
        if (!dgnc_poll_stop)
                add_timer(&dgnc_poll_timer);
 }
-
-/*
- * dgnc_init_globals()
- *
- * This is where we initialize the globals from the static insmod
- * configuration variables.  These are declared near the head of
- * this file.
- */
-static void dgnc_init_globals(void)
-{
-       int i = 0;
-
-       dgnc_NumBoards          = 0;
-
-       for (i = 0; i < MAXBOARDS; i++)
-               dgnc_Board[i] = NULL;
-
-       init_timer(&dgnc_poll_timer);
-}
-
index 06ece5151fe4a170ad04972d5bf3789e7c33ee21..ce7cd9b96542033e2f5063b51f80016962ad5f73 100644 (file)
@@ -61,7 +61,9 @@
 #define PORT_NUM(dev)  ((dev) & 0x7f)
 #define IS_PRINT(dev)  (((dev) & 0xff) >= 0x80)
 
-/* MAX number of stop characters we will send when our read queue is getting full */
+/* MAX number of stop characters we will send
+ * when our read queue is getting full
+ */
 #define MAX_STOPS_SENT 5
 
 /* 4 extra for alignment play space */
@@ -165,12 +167,15 @@ struct dgnc_board {
        uint            maxports;       /* MAX ports this board can handle */
        unsigned char   dvid;           /* Board specific device id */
        unsigned char   vpd[128];       /* VPD of board, if found */
-       unsigned char   serial_num[20]; /* Serial number of board, if found in VPD */
+       unsigned char   serial_num[20]; /* Serial number of board,
+                                        * if found in VPD
+                                        */
 
        spinlock_t      bd_lock;        /* Used to protect board */
 
-       spinlock_t      bd_intr_lock;   /* Used to protect the poller tasklet and
-                                        * the interrupt routine from each other.
+       spinlock_t      bd_intr_lock;   /* Used to protect the poller tasklet
+                                        * and the interrupt routine from each
+                                        * other.
                                         */
 
        uint            state;          /* State of card. */
@@ -189,14 +194,16 @@ struct dgnc_board {
        ulong           membase;        /* Start of base memory of the card */
        ulong           membase_end;    /* End of base memory of the card */
 
-       u8 __iomem              *re_map_membase;/* Remapped memory of the card */
+       u8 __iomem      *re_map_membase; /* Remapped memory of the card */
 
        ulong           iobase;         /* Start of io base of the card */
        ulong           iobase_end;     /* End of io base of the card */
 
        uint            bd_uart_offset; /* Space between each UART */
 
-       struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
+       struct channel_t *channels[MAXPORTS];   /* array of pointers
+                                                * to our channels.
+                                                */
 
        struct tty_driver       SerialDriver;
        char            SerialName[200];
@@ -211,8 +218,12 @@ struct dgnc_board {
 
        uint            TtyRefCnt;
 
-       u16             dpatype;        /* The board "type", as defined by DPA */
-       u16             dpastatus;      /* The board "status", as defined by DPA */
+       u16             dpatype;        /* The board "type",
+                                        * as defined by DPA
+                                        */
+       u16             dpastatus;      /* The board "status",
+                                        * as defined by DPA
+                                        */
 
        /*
         *      Mgmt data.
@@ -304,7 +315,7 @@ struct un_t {
  ************************************************************************/
 struct channel_t {
        int magic;                      /* Channel Magic Number         */
-       struct dgnc_board       *ch_bd;         /* Board structure pointer      */
+       struct dgnc_board       *ch_bd;         /* Board structure pointer */
        struct digi_t   ch_digi;        /* Transparent Print structure  */
        struct un_t     ch_tun;         /* Terminal unit info      */
        struct un_t     ch_pun;         /* Printer unit info        */
@@ -316,7 +327,9 @@ struct channel_t {
        uint            ch_open_count;  /* open count                   */
        uint            ch_flags;       /* Channel flags                */
 
-       ulong           ch_close_delay; /* How long we should drop RTS/DTR for */
+       ulong           ch_close_delay; /* How long we should
+                                        * drop RTS/DTR for
+                                        */
 
        ulong           ch_cpstime;     /* Time for CPS calculations    */
 
@@ -332,11 +345,15 @@ struct channel_t {
 
        uint            ch_wopen;       /* Waiting for open process cnt */
 
-       unsigned char           ch_mostat;      /* FEP output modem status      */
-       unsigned char           ch_mistat;      /* FEP input modem status       */
+       unsigned char           ch_mostat;      /* FEP output modem status */
+       unsigned char           ch_mistat;      /* FEP input modem status */
 
-       struct neo_uart_struct __iomem *ch_neo_uart;    /* Pointer to the "mapped" UART struct */
-       struct cls_uart_struct __iomem *ch_cls_uart;    /* Pointer to the "mapped" UART struct */
+       struct neo_uart_struct __iomem *ch_neo_uart;    /* Pointer to the
+                                                        * "mapped" UART struct
+                                                        */
+       struct cls_uart_struct __iomem *ch_cls_uart;    /* Pointer to the
+                                                        * "mapped" UART struct
+                                                        */
 
        unsigned char   ch_cached_lsr;  /* Cached value of the LSR register */
 
@@ -360,10 +377,13 @@ struct channel_t {
 
        unsigned char           ch_r_watermark; /* Receive Watermark */
 
-       ulong           ch_stop_sending_break;  /* Time we should STOP sending a break */
+       ulong           ch_stop_sending_break;  /* Time we should STOP
+                                                * sending a break
+                                                */
 
-       uint            ch_stops_sent;  /* How many times I have sent a stop character
-                                        * to try to stop the other guy sending.
+       uint            ch_stops_sent;  /* How many times I have sent a stop
+                                        * character to try to stop the other
+                                        * guy sending.
                                         */
        ulong           ch_err_parity;  /* Count of parity errors on channel */
        ulong           ch_err_frame;   /* Count of framing errors on channel */
@@ -390,7 +410,10 @@ struct channel_t {
 extern uint            dgnc_Major;             /* Our driver/mgmt major */
 extern int             dgnc_poll_tick;         /* Poll interval - 20 ms */
 extern spinlock_t      dgnc_global_lock;       /* Driver global spinlock */
+extern spinlock_t      dgnc_poll_lock;         /* Poll scheduling lock */
 extern uint            dgnc_NumBoards;         /* Total number of boards */
-extern struct dgnc_board       *dgnc_Board[MAXBOARDS]; /* Array of board structs */
+extern struct dgnc_board       *dgnc_Board[MAXBOARDS]; /* Array of board
+                                                        * structs
+                                                        */
 
 #endif
index b13318a82fe1970fa64fb8d1856fc65db39539ec..518fbd5e2d0e20159ba4b548b92e418b67c36858 100644 (file)
 #include "dgnc_pci.h"
 #include "dgnc_mgmt.h"
 
-
 /* Our "in use" variables, to enforce 1 open only */
 static int dgnc_mgmt_in_use[MAXMGMTDEVICES];
 
-
 /*
  * dgnc_mgmt_open()
  *
@@ -67,7 +65,6 @@ int dgnc_mgmt_open(struct inode *inode, struct file *file)
        return 0;
 }
 
-
 /*
  * dgnc_mgmt_close()
  *
@@ -90,7 +87,6 @@ int dgnc_mgmt_close(struct inode *inode, struct file *file)
        return 0;
 }
 
-
 /*
  * dgnc_mgmt_ioctl()
  *
@@ -100,10 +96,9 @@ int dgnc_mgmt_close(struct inode *inode, struct file *file)
 long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        unsigned long flags;
-       void __user *uarg = (void __user *) arg;
+       void __user *uarg = (void __user *)arg;
 
        switch (cmd) {
-
        case DIGI_GETDD:
        {
                /*
@@ -115,6 +110,7 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
                spin_lock_irqsave(&dgnc_global_lock, flags);
 
+               memset(&ddi, 0, sizeof(ddi));
                ddi.dinfo_nboards = dgnc_NumBoards;
                sprintf(ddi.dinfo_version, "%s", DG_PART);
 
@@ -147,8 +143,9 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                di.info_bdtype = dgnc_Board[brd]->dpatype;
                di.info_bdstate = dgnc_Board[brd]->dpastatus;
                di.info_ioport = 0;
-               di.info_physaddr = (ulong) dgnc_Board[brd]->membase;
-               di.info_physsize = (ulong) dgnc_Board[brd]->membase - dgnc_Board[brd]->membase_end;
+               di.info_physaddr = (ulong)dgnc_Board[brd]->membase;
+               di.info_physsize = (ulong)dgnc_Board[brd]->membase
+                       - dgnc_Board[brd]->membase_end;
                if (dgnc_Board[brd]->state != BOARD_FAILED)
                        di.info_nports = dgnc_Board[brd]->nasync;
                else
@@ -254,8 +251,6 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
                break;
        }
-
-
        }
 
        return 0;
index 900e3ae55a38fc4bf6dfdfbb32afb0670dddf540..8106f5234bf519e6d79efdd903b8d0dff02a8356 100644 (file)
@@ -13,7 +13,6 @@
  * PURPOSE.  See the GNU General Public License for more details.
  */
 
-
 #include <linux/kernel.h>
 #include <linux/sched.h>       /* For jiffies, task states */
 #include <linux/interrupt.h>    /* For tasklet and interrupt structs/defines */
@@ -57,7 +56,6 @@ static uint neo_get_uart_bytes_left(struct channel_t *ch);
 static void neo_send_immediate_char(struct channel_t *ch, unsigned char c);
 static irqreturn_t neo_intr(int irq, void *voidbrd);
 
-
 struct board_ops dgnc_neo_ops = {
        .tasklet =                      neo_tasklet,
        .intr =                         neo_intr,
@@ -81,7 +79,6 @@ struct board_ops dgnc_neo_ops = {
 
 static uint dgnc_offset_table[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
 
-
 /*
  * This function allows calls to ensure that all outstanding
  * PCI writes have been completed, by doing a PCI read against
@@ -100,7 +97,6 @@ static inline void neo_set_cts_flow_control(struct channel_t *ch)
        unsigned char ier = readb(&ch->ch_neo_uart->ier);
        unsigned char efr = readb(&ch->ch_neo_uart->efr);
 
-
        /* Turn on auto CTS flow control */
 #if 1
        ier |= UART_17158_IER_CTSDSR;
@@ -131,7 +127,6 @@ static inline void neo_set_cts_flow_control(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static inline void neo_set_rts_flow_control(struct channel_t *ch)
 {
        unsigned char ier = readb(&ch->ch_neo_uart->ier);
@@ -174,7 +169,6 @@ static inline void neo_set_rts_flow_control(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static inline void neo_set_ixon_flow_control(struct channel_t *ch)
 {
        unsigned char ier = readb(&ch->ch_neo_uart->ier);
@@ -211,7 +205,6 @@ static inline void neo_set_ixon_flow_control(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static inline void neo_set_ixoff_flow_control(struct channel_t *ch)
 {
        unsigned char ier = readb(&ch->ch_neo_uart->ier);
@@ -249,7 +242,6 @@ static inline void neo_set_ixoff_flow_control(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static inline void neo_set_no_input_flow_control(struct channel_t *ch)
 {
        unsigned char ier = readb(&ch->ch_neo_uart->ier);
@@ -266,7 +258,6 @@ static inline void neo_set_no_input_flow_control(struct channel_t *ch)
        else
                efr &= ~(UART_17158_EFR_ECB | UART_17158_EFR_IXOFF);
 
-
        /* Why? Becuz Exar's spec says we have to zero it out before setting it */
        writeb(0, &ch->ch_neo_uart->efr);
 
@@ -289,7 +280,6 @@ static inline void neo_set_no_input_flow_control(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static inline void neo_set_no_output_flow_control(struct channel_t *ch)
 {
        unsigned char ier = readb(&ch->ch_neo_uart->ier);
@@ -327,11 +317,9 @@ static inline void neo_set_no_output_flow_control(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 /* change UARTs start/stop chars */
 static inline void neo_set_new_start_stop_chars(struct channel_t *ch)
 {
-
        /* if hardware flow control is set, then skip this whole thing */
        if (ch->ch_digi.digi_flags & (CTSPACE | RTSPACE) || ch->ch_c_cflag & CRTSCTS)
                return;
@@ -346,7 +334,6 @@ static inline void neo_set_new_start_stop_chars(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 /*
  * No locks are assumed to be held when calling this function.
  */
@@ -377,7 +364,6 @@ static inline void neo_clear_break(struct channel_t *ch, int force)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 /*
  * Parse the ISR register.
  */
@@ -400,7 +386,6 @@ static inline void neo_parse_isr(struct dgnc_board *brd, uint port)
 
        /* Here we try to figure out what caused the interrupt to happen */
        while (1) {
-
                isr = readb(&ch->ch_neo_uart->isr_fcr);
 
                /* Bail if no pending interrupt */
@@ -507,7 +492,6 @@ static inline void neo_parse_isr(struct dgnc_board *brd, uint port)
        }
 }
 
-
 static inline void neo_parse_lsr(struct dgnc_board *brd, uint port)
 {
        struct channel_t *ch;
@@ -587,7 +571,6 @@ static inline void neo_parse_lsr(struct dgnc_board *brd, uint port)
        }
 }
 
-
 /*
  * neo_param()
  * Send any/all changes to the line to the UART.
@@ -607,7 +590,7 @@ static void neo_param(struct tty_struct *tty)
        if (!tty || tty->magic != TTY_MAGIC)
                return;
 
-       un = (struct un_t *) tty->driver_data;
+       un = (struct un_t *)tty->driver_data;
        if (!un || un->magic != DGNC_UNIT_MAGIC)
                return;
 
@@ -641,7 +624,6 @@ static void neo_param(struct tty_struct *tty)
                return;
 
        } else if (ch->ch_custom_speed) {
-
                baud = ch->ch_custom_speed;
                /* Handle transition from B0 */
                if (ch->ch_flags & CH_BAUD0) {
@@ -841,13 +823,12 @@ static void neo_param(struct tty_struct *tty)
        neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr));
 }
 
-
 /*
  * Our board poller function.
  */
 static void neo_tasklet(unsigned long data)
 {
-       struct dgnc_board *bd = (struct dgnc_board *) data;
+       struct dgnc_board *bd = (struct dgnc_board *)data;
        struct channel_t *ch;
        unsigned long flags;
        int i;
@@ -917,10 +898,8 @@ static void neo_tasklet(unsigned long data)
 
        /* Allow interrupt routine to access the interrupt register again */
        spin_unlock_irqrestore(&bd->bd_intr_lock, flags);
-
 }
 
-
 /*
  * dgnc_neo_intr()
  *
@@ -972,7 +951,6 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
 
        /* Loop on each port */
        while ((uart_poll & 0xff) != 0) {
-
                tmp = uart_poll;
 
                /* Check current port to see if it has interrupt pending */
@@ -995,7 +973,6 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
 
                /* Switch on type of interrupt we have */
                switch (type) {
-
                case UART_17158_RXRDY_TIMEOUT:
                        /*
                         * RXRDY Time-out is cleared by reading data in the
@@ -1067,7 +1044,6 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
        return IRQ_HANDLED;
 }
 
-
 /*
  * Neo specific way of turning off the receiver.
  * Used as a way to enforce queue flow control when in
@@ -1082,7 +1058,6 @@ static void neo_disable_receiver(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 /*
  * Neo specific way of turning on the receiver.
  * Used as a way to un-enforce queue flow control when in
@@ -1097,7 +1072,6 @@ static void neo_enable_receiver(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
 {
        int qleft = 0;
@@ -1153,7 +1127,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
                        total -= 3;
        }
 
-
        /*
         * Finally, bound the copy to make sure we don't overflow
         * our own queue...
@@ -1163,7 +1136,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
        total = min(total, qleft);
 
        while (total > 0) {
-
                /*
                 * Grab the linestatus register, we need to check
                 * to see if there are any errors in the FIFO.
@@ -1179,7 +1151,7 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
                        break;
 
                /* Make sure we don't go over the end of our queue */
-               n = min(((uint) total), (RQUEUESIZE - (uint) head));
+               n = min(((uint)total), (RQUEUESIZE - (uint)head));
 
                /*
                 * Cut down n even further if needed, this is to fix
@@ -1228,7 +1200,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
         * Also deal with any possible queue overflow here as well.
         */
        while (1) {
-
                /*
                 * Its possible we have a linestatus from the loop above
                 * this, so we "OR" on any extra bits.
@@ -1285,7 +1256,7 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
                }
 
                memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
-               ch->ch_equeue[head] = (unsigned char) linestatus;
+               ch->ch_equeue[head] = (unsigned char)linestatus;
 
                /* Ditch any remaining linestatus value. */
                linestatus = 0;
@@ -1306,7 +1277,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 /*
  * This function basically goes to sleep for secs, or until
  * it gets signalled that the port has fully drained.
@@ -1321,7 +1291,7 @@ static int neo_drain(struct tty_struct *tty, uint seconds)
        if (!tty || tty->magic != TTY_MAGIC)
                return -ENXIO;
 
-       un = (struct un_t *) tty->driver_data;
+       un = (struct un_t *)tty->driver_data;
        if (!un || un->magic != DGNC_UNIT_MAGIC)
                return -ENXIO;
 
@@ -1345,7 +1315,6 @@ static int neo_drain(struct tty_struct *tty, uint seconds)
        return rc;
 }
 
-
 /*
  * Flush the WRITE FIFO on the Neo.
  *
@@ -1363,7 +1332,6 @@ static void neo_flush_uart_write(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 
        for (i = 0; i < 10; i++) {
-
                /* Check to see if the UART feels it completely flushed the FIFO. */
                tmp = readb(&ch->ch_neo_uart->isr_fcr);
                if (tmp & 4)
@@ -1375,7 +1343,6 @@ static void neo_flush_uart_write(struct channel_t *ch)
        ch->ch_flags |= (CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
 }
 
-
 /*
  * Flush the READ FIFO on the Neo.
  *
@@ -1393,7 +1360,6 @@ static void neo_flush_uart_read(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 
        for (i = 0; i < 10; i++) {
-
                /* Check to see if the UART feels it completely flushed the FIFO. */
                tmp = readb(&ch->ch_neo_uart->isr_fcr);
                if (tmp & 2)
@@ -1403,7 +1369,6 @@ static void neo_flush_uart_read(struct channel_t *ch)
        }
 }
 
-
 static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
 {
        ushort head;
@@ -1425,7 +1390,7 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
 
        /* If port is "stopped", don't send any data to the UART */
        if ((ch->ch_flags & CH_FORCED_STOP) ||
-                (ch->ch_flags & CH_BREAK_SENDING))
+           (ch->ch_flags & CH_BREAK_SENDING))
                goto exit_unlock;
 
        /*
@@ -1482,7 +1447,7 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
 
                n = readb(&ch->ch_neo_uart->tfifo);
 
-               if ((unsigned int) n > ch->ch_t_tlevel)
+               if ((unsigned int)n > ch->ch_t_tlevel)
                        goto exit_unlock;
 
                n = UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel;
@@ -1499,7 +1464,6 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
        n = min(n, qlen);
 
        while (n > 0) {
-
                s = ((head >= tail) ? head : WQUEUESIZE) - tail;
                s = min(s, n);
 
@@ -1551,7 +1515,6 @@ exit_unlock:
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 static void neo_parse_modem(struct channel_t *ch, unsigned char signals)
 {
        unsigned char msignals = signals;
@@ -1608,7 +1571,6 @@ static void neo_parse_modem(struct channel_t *ch, unsigned char signals)
                ch->ch_mistat &= ~UART_MSR_CTS;
 }
 
-
 /* Make the UART raise any of the output signals we want up */
 static void neo_assert_modem_signals(struct channel_t *ch)
 {
@@ -1629,7 +1591,6 @@ static void neo_assert_modem_signals(struct channel_t *ch)
        udelay(10);
 }
 
-
 static void neo_send_start_character(struct channel_t *ch)
 {
        if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
@@ -1643,7 +1604,6 @@ static void neo_send_start_character(struct channel_t *ch)
        }
 }
 
-
 static void neo_send_stop_character(struct channel_t *ch)
 {
        if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
@@ -1657,18 +1617,15 @@ static void neo_send_stop_character(struct channel_t *ch)
        }
 }
 
-
 /*
  * neo_uart_init
  */
 static void neo_uart_init(struct channel_t *ch)
 {
-
        writeb(0, &ch->ch_neo_uart->ier);
        writeb(0, &ch->ch_neo_uart->efr);
        writeb(UART_EFR_ECB, &ch->ch_neo_uart->efr);
 
-
        /* Clear out UART and FIFO */
        readb(&ch->ch_neo_uart->txrx);
        writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT), &ch->ch_neo_uart->isr_fcr);
@@ -1682,7 +1639,6 @@ static void neo_uart_init(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 /*
  * Make the UART completely turn off.
  */
@@ -1696,7 +1652,6 @@ static void neo_uart_off(struct channel_t *ch)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static uint neo_get_uart_bytes_left(struct channel_t *ch)
 {
        unsigned char left = 0;
@@ -1718,7 +1673,6 @@ static uint neo_get_uart_bytes_left(struct channel_t *ch)
        return left;
 }
 
-
 /* Channel lock MUST be held by the calling function! */
 static void neo_send_break(struct channel_t *ch, int msecs)
 {
@@ -1754,7 +1708,6 @@ static void neo_send_break(struct channel_t *ch, int msecs)
        }
 }
 
-
 /*
  * neo_send_immediate_char.
  *
@@ -1772,7 +1725,6 @@ static void neo_send_immediate_char(struct channel_t *ch, unsigned char c)
        neo_pci_posting_flush(ch->ch_bd);
 }
 
-
 static unsigned int neo_read_eeprom(unsigned char __iomem *base, unsigned int address)
 {
        unsigned int enable;
@@ -1813,7 +1765,6 @@ static unsigned int neo_read_eeprom(unsigned char __iomem *base, unsigned int ad
        return val;
 }
 
-
 static void neo_vpd(struct dgnc_board *brd)
 {
        unsigned int i = 0;
@@ -1841,6 +1792,6 @@ static void neo_vpd(struct dgnc_board *brd)
                /* Search for the serial number */
                for (i = 0; i < NEO_VPD_IMAGEBYTES - 3; i++)
                        if (brd->vpd[i] == 'S' && brd->vpd[i + 1] == 'N')
-                               strncpy(brd->serial_num, &(brd->vpd[i + 3]), 9);
+                               strncpy(brd->serial_num, &brd->vpd[i + 3], 9);
        }
 }
index 44db8703eba47fc40677d39426ba955a0035976f..74a072599126f535471c932d2af00a67cfd57f72 100644 (file)
@@ -13,7 +13,6 @@
  * PURPOSE.  See the GNU General Public License for more details.
  */
 
-
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/ctype.h>
 #include "dgnc_driver.h"
 #include "dgnc_mgmt.h"
 
-
 static ssize_t dgnc_driver_version_show(struct device_driver *ddp, char *buf)
 {
        return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
 }
 static DRIVER_ATTR(version, S_IRUSR, dgnc_driver_version_show, NULL);
 
-
 static ssize_t dgnc_driver_boards_show(struct device_driver *ddp, char *buf)
 {
        return snprintf(buf, PAGE_SIZE, "%d\n", dgnc_NumBoards);
 }
 static DRIVER_ATTR(boards, S_IRUSR, dgnc_driver_boards_show, NULL);
 
-
 static ssize_t dgnc_driver_maxboards_show(struct device_driver *ddp, char *buf)
 {
        return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
 }
 static DRIVER_ATTR(maxboards, S_IRUSR, dgnc_driver_maxboards_show, NULL);
 
-
 static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf)
 {
        return snprintf(buf, PAGE_SIZE, "%dms\n", dgnc_poll_tick);
@@ -56,17 +51,23 @@ static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf)
 static ssize_t dgnc_driver_pollrate_store(struct device_driver *ddp,
                                          const char *buf, size_t count)
 {
+       unsigned long flags;
+       int tick;
        int ret;
 
-       ret = sscanf(buf, "%d\n", &dgnc_poll_tick);
+       ret = sscanf(buf, "%d\n", &tick);
        if (ret != 1)
                return -EINVAL;
+
+       spin_lock_irqsave(&dgnc_poll_lock, flags);
+       dgnc_poll_tick = tick;
+       spin_unlock_irqrestore(&dgnc_poll_lock, flags);
+
        return count;
 }
 static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgnc_driver_pollrate_show,
                   dgnc_driver_pollrate_store);
 
-
 void dgnc_create_driver_sysfiles(struct pci_driver *dgnc_driver)
 {
        int rc = 0;
@@ -80,7 +81,6 @@ void dgnc_create_driver_sysfiles(struct pci_driver *dgnc_driver)
                pr_err("DGNC: sysfs driver_create_file failed!\n");
 }
 
-
 void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
 {
        struct device_driver *driverfs = &dgnc_driver->driver;
@@ -91,7 +91,6 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
        driver_remove_file(driverfs, &driver_attr_pollrate);
 }
 
-
 #define DGNC_VERIFY_BOARD(p, bd)                               \
        do {                                                    \
                if (!p)                                         \
@@ -104,8 +103,6 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
                        return 0;                               \
        } while (0)
 
-
-
 static ssize_t dgnc_vpd_show(struct device *p, struct device_attribute *attr,
                             char *buf)
 {
@@ -145,7 +142,6 @@ static ssize_t dgnc_serial_number_show(struct device *p,
 }
 static DEVICE_ATTR(serial_number, S_IRUSR, dgnc_serial_number_show, NULL);
 
-
 static ssize_t dgnc_ports_state_show(struct device *p,
                                     struct device_attribute *attr, char *buf)
 {
@@ -164,7 +160,6 @@ static ssize_t dgnc_ports_state_show(struct device *p,
 }
 static DEVICE_ATTR(ports_state, S_IRUSR, dgnc_ports_state_show, NULL);
 
-
 static ssize_t dgnc_ports_baud_show(struct device *p,
                                    struct device_attribute *attr, char *buf)
 {
@@ -183,7 +178,6 @@ static ssize_t dgnc_ports_baud_show(struct device *p,
 }
 static DEVICE_ATTR(ports_baud, S_IRUSR, dgnc_ports_baud_show, NULL);
 
-
 static ssize_t dgnc_ports_msignals_show(struct device *p,
                                        struct device_attribute *attr,
                                        char *buf)
@@ -214,7 +208,6 @@ static ssize_t dgnc_ports_msignals_show(struct device *p,
 }
 static DEVICE_ATTR(ports_msignals, S_IRUSR, dgnc_ports_msignals_show, NULL);
 
-
 static ssize_t dgnc_ports_iflag_show(struct device *p,
                                     struct device_attribute *attr, char *buf)
 {
@@ -233,7 +226,6 @@ static ssize_t dgnc_ports_iflag_show(struct device *p,
 }
 static DEVICE_ATTR(ports_iflag, S_IRUSR, dgnc_ports_iflag_show, NULL);
 
-
 static ssize_t dgnc_ports_cflag_show(struct device *p,
                                     struct device_attribute *attr, char *buf)
 {
@@ -252,7 +244,6 @@ static ssize_t dgnc_ports_cflag_show(struct device *p,
 }
 static DEVICE_ATTR(ports_cflag, S_IRUSR, dgnc_ports_cflag_show, NULL);
 
-
 static ssize_t dgnc_ports_oflag_show(struct device *p,
                                     struct device_attribute *attr, char *buf)
 {
@@ -271,7 +262,6 @@ static ssize_t dgnc_ports_oflag_show(struct device *p,
 }
 static DEVICE_ATTR(ports_oflag, S_IRUSR, dgnc_ports_oflag_show, NULL);
 
-
 static ssize_t dgnc_ports_lflag_show(struct device *p,
                                     struct device_attribute *attr, char *buf)
 {
@@ -290,7 +280,6 @@ static ssize_t dgnc_ports_lflag_show(struct device *p,
 }
 static DEVICE_ATTR(ports_lflag, S_IRUSR, dgnc_ports_lflag_show, NULL);
 
-
 static ssize_t dgnc_ports_digi_flag_show(struct device *p,
                                         struct device_attribute *attr,
                                         char *buf)
@@ -310,7 +299,6 @@ static ssize_t dgnc_ports_digi_flag_show(struct device *p,
 }
 static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgnc_ports_digi_flag_show, NULL);
 
-
 static ssize_t dgnc_ports_rxcount_show(struct device *p,
                                       struct device_attribute *attr, char *buf)
 {
@@ -329,7 +317,6 @@ static ssize_t dgnc_ports_rxcount_show(struct device *p,
 }
 static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgnc_ports_rxcount_show, NULL);
 
-
 static ssize_t dgnc_ports_txcount_show(struct device *p,
                                       struct device_attribute *attr, char *buf)
 {
@@ -348,7 +335,6 @@ static ssize_t dgnc_ports_txcount_show(struct device *p,
 }
 static DEVICE_ATTR(ports_txcount, S_IRUSR, dgnc_ports_txcount_show, NULL);
 
-
 /* this function creates the sys files that will export each signal status
  * to sysfs each value will be put in a separate filename
  */
@@ -357,41 +343,39 @@ void dgnc_create_ports_sysfiles(struct dgnc_board *bd)
        int rc = 0;
 
        dev_set_drvdata(&bd->pdev->dev, bd);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_vpd);
-       rc |= device_create_file(&(bd->pdev->dev), &dev_attr_serial_number);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_state);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_baud);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_msignals);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_iflag);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_cflag);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_oflag);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_lflag);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_ports_txcount);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_vpd);
+       rc |= device_create_file(&bd->pdev->dev, &dev_attr_serial_number);
        if (rc)
                dev_err(&bd->pdev->dev, "dgnc: sysfs device_create_file failed!\n");
 }
 
-
 /* removes all the sys files created for that port */
 void dgnc_remove_ports_sysfiles(struct dgnc_board *bd)
 {
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_vpd);
-       device_remove_file(&(bd->pdev->dev), &dev_attr_serial_number);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_state);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_baud);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_msignals);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_iflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_cflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_oflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_lflag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
+       device_remove_file(&bd->pdev->dev, &dev_attr_ports_txcount);
+       device_remove_file(&bd->pdev->dev, &dev_attr_vpd);
+       device_remove_file(&bd->pdev->dev, &dev_attr_serial_number);
 }
 
-
 static ssize_t dgnc_tty_state_show(struct device *d,
                                   struct device_attribute *attr, char *buf)
 {
@@ -418,7 +402,6 @@ static ssize_t dgnc_tty_state_show(struct device *d,
 }
 static DEVICE_ATTR(state, S_IRUSR, dgnc_tty_state_show, NULL);
 
-
 static ssize_t dgnc_tty_baud_show(struct device *d,
                                  struct device_attribute *attr, char *buf)
 {
@@ -444,7 +427,6 @@ static ssize_t dgnc_tty_baud_show(struct device *d,
 }
 static DEVICE_ATTR(baud, S_IRUSR, dgnc_tty_baud_show, NULL);
 
-
 static ssize_t dgnc_tty_msignals_show(struct device *d,
                                      struct device_attribute *attr, char *buf)
 {
@@ -479,7 +461,6 @@ static ssize_t dgnc_tty_msignals_show(struct device *d,
 }
 static DEVICE_ATTR(msignals, S_IRUSR, dgnc_tty_msignals_show, NULL);
 
-
 static ssize_t dgnc_tty_iflag_show(struct device *d,
                                   struct device_attribute *attr, char *buf)
 {
@@ -505,7 +486,6 @@ static ssize_t dgnc_tty_iflag_show(struct device *d,
 }
 static DEVICE_ATTR(iflag, S_IRUSR, dgnc_tty_iflag_show, NULL);
 
-
 static ssize_t dgnc_tty_cflag_show(struct device *d,
                                   struct device_attribute *attr, char *buf)
 {
@@ -531,7 +511,6 @@ static ssize_t dgnc_tty_cflag_show(struct device *d,
 }
 static DEVICE_ATTR(cflag, S_IRUSR, dgnc_tty_cflag_show, NULL);
 
-
 static ssize_t dgnc_tty_oflag_show(struct device *d,
                                   struct device_attribute *attr, char *buf)
 {
@@ -557,7 +536,6 @@ static ssize_t dgnc_tty_oflag_show(struct device *d,
 }
 static DEVICE_ATTR(oflag, S_IRUSR, dgnc_tty_oflag_show, NULL);
 
-
 static ssize_t dgnc_tty_lflag_show(struct device *d,
                                   struct device_attribute *attr, char *buf)
 {
@@ -583,7 +561,6 @@ static ssize_t dgnc_tty_lflag_show(struct device *d,
 }
 static DEVICE_ATTR(lflag, S_IRUSR, dgnc_tty_lflag_show, NULL);
 
-
 static ssize_t dgnc_tty_digi_flag_show(struct device *d,
                                       struct device_attribute *attr, char *buf)
 {
@@ -609,7 +586,6 @@ static ssize_t dgnc_tty_digi_flag_show(struct device *d,
 }
 static DEVICE_ATTR(digi_flag, S_IRUSR, dgnc_tty_digi_flag_show, NULL);
 
-
 static ssize_t dgnc_tty_rxcount_show(struct device *d,
                                     struct device_attribute *attr, char *buf)
 {
@@ -635,7 +611,6 @@ static ssize_t dgnc_tty_rxcount_show(struct device *d,
 }
 static DEVICE_ATTR(rxcount, S_IRUSR, dgnc_tty_rxcount_show, NULL);
 
-
 static ssize_t dgnc_tty_txcount_show(struct device *d,
                                     struct device_attribute *attr, char *buf)
 {
@@ -661,7 +636,6 @@ static ssize_t dgnc_tty_txcount_show(struct device *d,
 }
 static DEVICE_ATTR(txcount, S_IRUSR, dgnc_tty_txcount_show, NULL);
 
-
 static ssize_t dgnc_tty_name_show(struct device *d,
                                  struct device_attribute *attr, char *buf)
 {
@@ -689,7 +663,6 @@ static ssize_t dgnc_tty_name_show(struct device *d,
 }
 static DEVICE_ATTR(custom_name, S_IRUSR, dgnc_tty_name_show, NULL);
 
-
 static struct attribute *dgnc_sysfs_tty_entries[] = {
        &dev_attr_state.attr,
        &dev_attr_baud.attr,
@@ -705,13 +678,11 @@ static struct attribute *dgnc_sysfs_tty_entries[] = {
        NULL
 };
 
-
 static struct attribute_group dgnc_tty_attribute_group = {
        .name = NULL,
        .attrs = dgnc_sysfs_tty_entries,
 };
 
-
 void dgnc_create_tty_sysfs(struct un_t *un, struct device *c)
 {
        int ret;
@@ -724,10 +695,8 @@ void dgnc_create_tty_sysfs(struct un_t *un, struct device *c)
        }
 
        dev_set_drvdata(c, un);
-
 }
 
-
 void dgnc_remove_tty_sysfs(struct device *c)
 {
        sysfs_remove_group(&c->kobj, &dgnc_tty_attribute_group);
index fbfe79a70263a7c81d3059359243395ca77257f5..48e4b90578c17fdb037894d92348d065c4546544 100644 (file)
@@ -63,7 +63,6 @@ static struct digi_t dgnc_digi_init = {
        .digi_term =    "ansi"          /* default terminal type        */
 };
 
-
 /*
  * Define a local default termios struct. All ports will be created
  * with this termios initially.
@@ -80,14 +79,17 @@ static struct ktermios DgncDefaultTermios = {
        .c_line =       0,
 };
 
-
 /* Our function prototypes */
 static int dgnc_tty_open(struct tty_struct *tty, struct file *file);
 static void dgnc_tty_close(struct tty_struct *tty, struct file *file);
-static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
-static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
-static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
-static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
+static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file,
+                               struct channel_t *ch);
+static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
+                         unsigned long arg);
+static int dgnc_tty_digigeta(struct tty_struct *tty,
+                            struct digi_t __user *retinfo);
+static int dgnc_tty_digiseta(struct tty_struct *tty,
+                            struct digi_t __user *new_info);
 static int dgnc_tty_write_room(struct tty_struct *tty);
 static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c);
 static int dgnc_tty_chars_in_buffer(struct tty_struct *tty);
@@ -98,17 +100,21 @@ static void dgnc_tty_unthrottle(struct tty_struct *tty);
 static void dgnc_tty_flush_chars(struct tty_struct *tty);
 static void dgnc_tty_flush_buffer(struct tty_struct *tty);
 static void dgnc_tty_hangup(struct tty_struct *tty);
-static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
-static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value);
+static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command,
+                              unsigned int __user *value);
+static int dgnc_get_modem_info(struct channel_t *ch,
+                              unsigned int __user *value);
 static int dgnc_tty_tiocmget(struct tty_struct *tty);
-static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
+static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set,
+                            unsigned int clear);
 static int dgnc_tty_send_break(struct tty_struct *tty, int msec);
 static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout);
-static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
-static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
+static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf,
+                         int count);
+static void dgnc_tty_set_termios(struct tty_struct *tty,
+                                struct ktermios *old_termios);
 static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
 
-
 static const struct tty_operations dgnc_tty_ops = {
        .open = dgnc_tty_open,
        .close = dgnc_tty_close,
@@ -163,7 +169,6 @@ int dgnc_tty_preinit(void)
        return 0;
 }
 
-
 /*
  * dgnc_tty_register()
  *
@@ -186,18 +191,24 @@ int dgnc_tty_register(struct dgnc_board *brd)
        brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL;
        brd->SerialDriver.init_termios = DgncDefaultTermios;
        brd->SerialDriver.driver_name = DRVSTR;
-       brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
+       brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW |
+                                  TTY_DRIVER_DYNAMIC_DEV |
+                                  TTY_DRIVER_HARDWARE_BREAK);
 
        /*
         * The kernel wants space to store pointers to
         * tty_struct's and termios's.
         */
-       brd->SerialDriver.ttys = kcalloc(brd->maxports, sizeof(*brd->SerialDriver.ttys), GFP_KERNEL);
+       brd->SerialDriver.ttys = kcalloc(brd->maxports,
+                                        sizeof(*brd->SerialDriver.ttys),
+                                        GFP_KERNEL);
        if (!brd->SerialDriver.ttys)
                return -ENOMEM;
 
        kref_init(&brd->SerialDriver.kref);
-       brd->SerialDriver.termios = kcalloc(brd->maxports, sizeof(*brd->SerialDriver.termios), GFP_KERNEL);
+       brd->SerialDriver.termios = kcalloc(brd->maxports,
+                                           sizeof(*brd->SerialDriver.termios),
+                                           GFP_KERNEL);
        if (!brd->SerialDriver.termios)
                return -ENOMEM;
 
@@ -235,18 +246,24 @@ int dgnc_tty_register(struct dgnc_board *brd)
        brd->PrintDriver.subtype = SERIAL_TYPE_NORMAL;
        brd->PrintDriver.init_termios = DgncDefaultTermios;
        brd->PrintDriver.driver_name = DRVSTR;
-       brd->PrintDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
+       brd->PrintDriver.flags = (TTY_DRIVER_REAL_RAW |
+                                 TTY_DRIVER_DYNAMIC_DEV |
+                                 TTY_DRIVER_HARDWARE_BREAK);
 
        /*
         * The kernel wants space to store pointers to
         * tty_struct's and termios's.  Must be separated from
         * the Serial Driver so we don't get confused
         */
-       brd->PrintDriver.ttys = kcalloc(brd->maxports, sizeof(*brd->PrintDriver.ttys), GFP_KERNEL);
+       brd->PrintDriver.ttys = kcalloc(brd->maxports,
+                                       sizeof(*brd->PrintDriver.ttys),
+                                       GFP_KERNEL);
        if (!brd->PrintDriver.ttys)
                return -ENOMEM;
        kref_init(&brd->PrintDriver.kref);
-       brd->PrintDriver.termios = kcalloc(brd->maxports, sizeof(*brd->PrintDriver.termios), GFP_KERNEL);
+       brd->PrintDriver.termios = kcalloc(brd->maxports,
+                                          sizeof(*brd->PrintDriver.termios),
+                                          GFP_KERNEL);
        if (!brd->PrintDriver.termios)
                return -ENOMEM;
 
@@ -275,7 +292,6 @@ int dgnc_tty_register(struct dgnc_board *brd)
        return rc;
 }
 
-
 /*
  * dgnc_tty_init()
  *
@@ -349,16 +365,15 @@ int dgnc_tty_init(struct dgnc_board *brd)
                        struct device *classp;
 
                        classp = tty_register_device(&brd->SerialDriver, i,
-                               &(ch->ch_bd->pdev->dev));
+                                                    &ch->ch_bd->pdev->dev);
                        ch->ch_tun.un_sysfs = classp;
                        dgnc_create_tty_sysfs(&ch->ch_tun, classp);
 
                        classp = tty_register_device(&brd->PrintDriver, i,
-                               &(ch->ch_bd->pdev->dev));
+                                                    &ch->ch_bd->pdev->dev);
                        ch->ch_pun.un_sysfs = classp;
                        dgnc_create_tty_sysfs(&ch->ch_pun, classp);
                }
-
        }
 
        return 0;
@@ -371,7 +386,6 @@ err_free_channels:
        return -ENOMEM;
 }
 
-
 /*
  * dgnc_tty_post_uninit()
  *
@@ -383,7 +397,6 @@ void dgnc_tty_post_uninit(void)
        dgnc_TmpWriteBuf = NULL;
 }
 
-
 /*
  * dgnc_tty_uninit()
  *
@@ -476,9 +489,6 @@ static void dgnc_wmove(struct channel_t *ch, char *buf, uint n)
        ch->ch_w_head = head;
 }
 
-
-
-
 /*=======================================================================
  *
  *      dgnc_input - Process received data.
@@ -529,9 +539,10 @@ void dgnc_input(struct channel_t *ch)
         * If the device is not open, or CREAD is off,
         * flush input data and return immediately.
         */
-       if (!tp || (tp->magic != TTY_MAGIC) || !(ch->ch_tun.un_flags & UN_ISOPEN) ||
-           !(tp->termios.c_cflag & CREAD) || (ch->ch_tun.un_flags & UN_CLOSING)) {
-
+       if (!tp || (tp->magic != TTY_MAGIC) ||
+           !(ch->ch_tun.un_flags & UN_ISOPEN) ||
+           !(tp->termios.c_cflag & CREAD) ||
+           (ch->ch_tun.un_flags & UN_CLOSING)) {
                ch->ch_r_head = tail;
 
                /* Force queue flow control to be released, if needed */
@@ -614,16 +625,28 @@ void dgnc_input(struct channel_t *ch)
                if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
                        for (i = 0; i < s; i++) {
                                if (*(ch->ch_equeue + tail + i) & UART_LSR_BI)
-                                       tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_BREAK);
-                               else if (*(ch->ch_equeue + tail + i) & UART_LSR_PE)
-                                       tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_PARITY);
-                               else if (*(ch->ch_equeue + tail + i) & UART_LSR_FE)
-                                       tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_FRAME);
+                                       tty_insert_flip_char(tp->port,
+                                               *(ch->ch_rqueue + tail + i),
+                                               TTY_BREAK);
+                               else if (*(ch->ch_equeue + tail + i) &
+                                               UART_LSR_PE)
+                                       tty_insert_flip_char(tp->port,
+                                               *(ch->ch_rqueue + tail + i),
+                                               TTY_PARITY);
+                               else if (*(ch->ch_equeue + tail + i) &
+                                               UART_LSR_FE)
+                                       tty_insert_flip_char(tp->port,
+                                               *(ch->ch_rqueue + tail + i),
+                                               TTY_FRAME);
                                else
-                                       tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_NORMAL);
+                                       tty_insert_flip_char(tp->port,
+                                               *(ch->ch_rqueue + tail + i),
+                                               TTY_NORMAL);
                        }
                } else {
-                       tty_insert_flip_string(tp->port, ch->ch_rqueue + tail, s);
+                       tty_insert_flip_string(tp->port,
+                                              ch->ch_rqueue + tail,
+                                              s);
                }
 
                tail += s;
@@ -650,7 +673,6 @@ exit_unlock:
                tty_ldisc_deref(ld);
 }
 
-
 /************************************************************************
  * Determines when CARRIER changes state and takes appropriate
  * action.
@@ -683,13 +705,12 @@ void dgnc_carrier(struct channel_t *ch)
         * Test for a VIRTUAL carrier transition to HIGH.
         */
        if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
-
                /*
                 * When carrier rises, wake any threads waiting
                 * for carrier in the open routine.
                 */
 
-               if (waitqueue_active(&(ch->ch_flags_wait)))
+               if (waitqueue_active(&ch->ch_flags_wait))
                        wake_up_interruptible(&ch->ch_flags_wait);
        }
 
@@ -697,13 +718,12 @@ void dgnc_carrier(struct channel_t *ch)
         * Test for a PHYSICAL carrier transition to HIGH.
         */
        if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
-
                /*
                 * When carrier rises, wake any threads waiting
                 * for carrier in the open routine.
                 */
 
-               if (waitqueue_active(&(ch->ch_flags_wait)))
+               if (waitqueue_active(&ch->ch_flags_wait))
                        wake_up_interruptible(&ch->ch_flags_wait);
        }
 
@@ -718,7 +738,6 @@ void dgnc_carrier(struct channel_t *ch)
         */
        if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
            (phys_carrier == 0)) {
-
                /*
                 *   When carrier drops:
                 *
@@ -731,7 +750,7 @@ void dgnc_carrier(struct channel_t *ch)
                 *
                 *   Enable all select calls.
                 */
-               if (waitqueue_active(&(ch->ch_flags_wait)))
+               if (waitqueue_active(&ch->ch_flags_wait))
                        wake_up_interruptible(&ch->ch_flags_wait);
 
                if (ch->ch_tun.un_open_count > 0)
@@ -801,8 +820,8 @@ static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate)
                 */
                if (testrate_high != newrate) {
                        /*
-                        *  Otherwise, pick the rate that is closer (i.e. whichever rate
-                        *  has a smaller delta).
+                        *  Otherwise, pick the rate that is closer
+                        *  (i.e. whichever rate has a smaller delta).
                         */
                        deltahigh = testrate_high - newrate;
                        deltalow = newrate - testrate_low;
@@ -817,10 +836,9 @@ static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate)
        ch->ch_custom_speed = newrate;
 }
 
-
 void dgnc_check_queue_flow_control(struct channel_t *ch)
 {
-       int qleft = 0;
+       int qleft;
 
        /* Store how much space we have left in the queue */
        qleft = ch->ch_r_tail - ch->ch_r_head - 1;
@@ -844,7 +862,8 @@ void dgnc_check_queue_flow_control(struct channel_t *ch)
         */
        if (qleft < 256) {
                /* HWFLOW */
-               if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
+               if (ch->ch_digi.digi_flags & CTSPACE ||
+                   ch->ch_c_cflag & CRTSCTS) {
                        if (!(ch->ch_flags & CH_RECEIVER_OFF)) {
                                ch->ch_bd->bd_ops->disable_receiver(ch);
                                ch->ch_flags |= (CH_RECEIVER_OFF);
@@ -876,7 +895,8 @@ void dgnc_check_queue_flow_control(struct channel_t *ch)
         */
        if (qleft > (RQUEUESIZE / 2)) {
                /* HWFLOW */
-               if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
+               if (ch->ch_digi.digi_flags & RTSPACE ||
+                   ch->ch_c_cflag & CRTSCTS) {
                        if (ch->ch_flags & CH_RECEIVER_OFF) {
                                ch->ch_bd->bd_ops->enable_receiver(ch);
                                ch->ch_flags &= ~(CH_RECEIVER_OFF);
@@ -890,7 +910,6 @@ void dgnc_check_queue_flow_control(struct channel_t *ch)
        }
 }
 
-
 void dgnc_wakeup_writes(struct channel_t *ch)
 {
        int qlen = 0;
@@ -915,9 +934,9 @@ void dgnc_wakeup_writes(struct channel_t *ch)
 
        if (ch->ch_tun.un_flags & UN_ISOPEN) {
                if ((ch->ch_tun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-                       ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
+                   ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
                        spin_unlock_irqrestore(&ch->ch_lock, flags);
-                       (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
+                       ch->ch_tun.un_tty->ldisc->ops->write_wakeup(ch->ch_tun.un_tty);
                        spin_lock_irqsave(&ch->ch_lock, flags);
                }
 
@@ -928,7 +947,8 @@ void dgnc_wakeup_writes(struct channel_t *ch)
                 * the queue AND FIFO are both empty.
                 */
                if (ch->ch_tun.un_flags & UN_EMPTY) {
-                       if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
+                       if ((qlen == 0) &&
+                           (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
                                ch->ch_tun.un_flags &= ~(UN_EMPTY);
 
                                /*
@@ -956,9 +976,9 @@ void dgnc_wakeup_writes(struct channel_t *ch)
 
        if (ch->ch_pun.un_flags & UN_ISOPEN) {
                if ((ch->ch_pun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
-                       ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
+                   ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
                        spin_unlock_irqrestore(&ch->ch_lock, flags);
-                       (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
+                       ch->ch_pun.un_tty->ldisc->ops->write_wakeup(ch->ch_pun.un_tty);
                        spin_lock_irqsave(&ch->ch_lock, flags);
                }
 
@@ -969,7 +989,8 @@ void dgnc_wakeup_writes(struct channel_t *ch)
                 * the queue AND FIFO are both empty.
                 */
                if (ch->ch_pun.un_flags & UN_EMPTY) {
-                       if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0))
+                       if ((qlen == 0) &&
+                           (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0))
                                ch->ch_pun.un_flags &= ~(UN_EMPTY);
                }
 
@@ -979,8 +1000,6 @@ void dgnc_wakeup_writes(struct channel_t *ch)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
-
 /************************************************************************
  *
  * TTY Entry points and helper functions
@@ -1019,7 +1038,7 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
         * sleep waiting for it to happen or they cancel the open.
         */
        rc = wait_event_interruptible(brd->state_wait,
-               (brd->state & BOARD_READY));
+                                     (brd->state & BOARD_READY));
 
        if (rc)
                return rc;
@@ -1063,7 +1082,8 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
         */
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 
-       rc = wait_event_interruptible(ch->ch_flags_wait, ((ch->ch_flags & CH_OPENING) == 0));
+       rc = wait_event_interruptible(ch->ch_flags_wait,
+                                     ((ch->ch_flags & CH_OPENING) == 0));
 
        /* If ret is non-zero, user ctrl-c'ed us */
        if (rc)
@@ -1077,7 +1097,8 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
         * ch_flags_wait to wake us back up.
         */
        rc = wait_event_interruptible(ch->ch_flags_wait,
-               (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING) == 0));
+               (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
+                 UN_CLOSING) == 0));
 
        /* If ret is non-zero, user ctrl-c'ed us */
        if (rc)
@@ -1085,11 +1106,9 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
 
        spin_lock_irqsave(&ch->ch_lock, flags);
 
-
        /* Store our unit into driver_data, so we always have it available. */
        tty->driver_data = un;
 
-
        /*
         * Initialize tty's
         */
@@ -1100,7 +1119,6 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
                /* Maybe do something here to the TTY struct as well? */
        }
 
-
        /*
         * Allocate channel buffers for read/write/error.
         * Set flag, so we don't get trounced on.
@@ -1126,7 +1144,6 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
         * Initialize if neither terminal or printer is open.
         */
        if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
-
                /*
                 * Flush input queues.
                 */
@@ -1190,13 +1207,14 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
        return rc;
 }
 
-
 /*
  * dgnc_block_til_ready()
  *
  * Wait for DCD, if needed.
  */
-static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
+static int dgnc_block_til_ready(struct tty_struct *tty,
+                               struct file *file,
+                               struct channel_t *ch)
 {
        int retval = 0;
        struct un_t *un = NULL;
@@ -1204,7 +1222,8 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc
        uint    old_flags = 0;
        int     sleep_on_un_flags = 0;
 
-       if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGNC_CHANNEL_MAGIC)
+       if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
+           ch->magic != DGNC_CHANNEL_MAGIC)
                return -ENXIO;
 
        un = tty->driver_data;
@@ -1217,11 +1236,11 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc
 
        /* Loop forever */
        while (1) {
-
                sleep_on_un_flags = 0;
 
                /*
-                * If board has failed somehow during our sleep, bail with error.
+                * If board has failed somehow during our sleep,
+                * bail with error.
                 */
                if (ch->ch_bd->state == BOARD_FAILED) {
                        retval = -ENXIO;
@@ -1241,8 +1260,9 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc
                 * touched safely, the close routine will signal the
                 * ch_wait_flags to wake us back up.
                 */
-               if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
-
+               if (!((ch->ch_tun.un_flags |
+                   ch->ch_pun.un_flags) &
+                   UN_CLOSING)) {
                        /*
                         * Our conditions to leave cleanly and happily:
                         * 1) NONBLOCKING on the tty is set.
@@ -1294,11 +1314,13 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc
                spin_unlock_irqrestore(&ch->ch_lock, flags);
 
                /*
-                * Wait for something in the flags to change from the current value.
+                * Wait for something in the flags to change
+                * from the current value.
                 */
                if (sleep_on_un_flags)
                        retval = wait_event_interruptible(un->un_flags_wait,
-                               (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
+                               (old_flags != (ch->ch_tun.un_flags |
+                                              ch->ch_pun.un_flags)));
                else
                        retval = wait_event_interruptible(ch->ch_flags_wait,
                                (old_flags != ch->ch_flags));
@@ -1314,13 +1336,9 @@ static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struc
 
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 
-       if (retval)
-               return retval;
-
-       return 0;
+       return retval;
 }
 
-
 /*
  * dgnc_tty_hangup()
  *
@@ -1339,22 +1357,18 @@ static void dgnc_tty_hangup(struct tty_struct *tty)
 
        /* flush the transmit queues */
        dgnc_tty_flush_buffer(tty);
-
 }
 
-
 /*
  * dgnc_tty_close()
  *
  */
 static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
 {
-       struct ktermios *ts;
        struct dgnc_board *bd;
        struct channel_t *ch;
        struct un_t *un;
        unsigned long flags;
-       int rc = 0;
 
        if (!tty || tty->magic != TTY_MAGIC)
                return;
@@ -1371,8 +1385,6 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
        if (!bd || bd->magic != DGNC_BOARD_MAGIC)
                return;
 
-       ts = &tty->termios;
-
        spin_lock_irqsave(&ch->ch_lock, flags);
 
        /*
@@ -1412,13 +1424,12 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
 
        tty->closing = 1;
 
-
        /*
         * Only officially close channel if count is 0 and
         * DIGI_PRINTER bit is not set.
         */
-       if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
-
+       if ((ch->ch_open_count == 0) &&
+           !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
                ch->ch_flags &= ~(CH_STOPI | CH_FORCED_STOPI);
 
                /*
@@ -1426,7 +1437,7 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
                 */
                if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
                        dgnc_wmove(ch, ch->ch_digi.digi_offstr,
-                               (int) ch->ch_digi.digi_offlen);
+                                  (int)ch->ch_digi.digi_offlen);
                        ch->ch_flags &= ~CH_PRON;
                }
 
@@ -1434,7 +1445,7 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
                /* wait for output to drain */
                /* This will also return if we take an interrupt */
 
-               rc = bd->bd_ops->drain(tty, 0);
+               bd->bd_ops->drain(tty, 0);
 
                dgnc_tty_flush_buffer(tty);
                tty_ldisc_flush(tty);
@@ -1447,7 +1458,6 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
                 * If we have HUPCL set, lower DTR and RTS
                 */
                if (ch->ch_c_cflag & HUPCL) {
-
                        /* Drop RTS/DTR */
                        ch->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
                        bd->bd_ops->assert_modem_signals(ch);
@@ -1474,7 +1484,7 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
                 */
                if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
                        dgnc_wmove(ch, ch->ch_digi.digi_offstr,
-                               (int) ch->ch_digi.digi_offlen);
+                                  (int)ch->ch_digi.digi_offlen);
                        ch->ch_flags &= ~CH_PRON;
                }
        }
@@ -1488,7 +1498,6 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 /*
  * dgnc_tty_chars_in_buffer()
  *
@@ -1507,7 +1516,7 @@ static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
        uint chars = 0;
        unsigned long flags;
 
-       if (tty == NULL)
+       if (!tty)
                return 0;
 
        un = tty->driver_data;
@@ -1538,7 +1547,6 @@ static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
        return chars;
 }
 
-
 /*
  * dgnc_maxcps_room
  *
@@ -1574,15 +1582,17 @@ static int dgnc_maxcps_room(struct tty_struct *tty, int bytes_available)
                int cps_limit = 0;
                unsigned long current_time = jiffies;
                unsigned long buffer_time = current_time +
-                       (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
+                       (HZ * ch->ch_digi.digi_bufsize) /
+                       ch->ch_digi.digi_maxcps;
 
                if (ch->ch_cpstime < current_time) {
                        /* buffer is empty */
-                       ch->ch_cpstime = current_time;      /* reset ch_cpstime */
+                       ch->ch_cpstime = current_time;  /* reset ch_cpstime */
                        cps_limit = ch->ch_digi.digi_bufsize;
                } else if (ch->ch_cpstime < buffer_time) {
                        /* still room in the buffer */
-                       cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
+                       cps_limit = ((buffer_time - ch->ch_cpstime) *
+                                       ch->ch_digi.digi_maxcps) / HZ;
                } else {
                        /* no room in the buffer */
                        cps_limit = 0;
@@ -1594,7 +1604,6 @@ static int dgnc_maxcps_room(struct tty_struct *tty, int bytes_available)
        return bytes_available;
 }
 
-
 /*
  * dgnc_tty_write_room()
  *
@@ -1610,7 +1619,7 @@ static int dgnc_tty_write_room(struct tty_struct *tty)
        int ret = 0;
        unsigned long flags;
 
-       if (tty == NULL || dgnc_TmpWriteBuf == NULL)
+       if (!tty || !dgnc_TmpWriteBuf)
                return 0;
 
        un = tty->driver_data;
@@ -1655,7 +1664,6 @@ static int dgnc_tty_write_room(struct tty_struct *tty)
        return ret;
 }
 
-
 /*
  * dgnc_tty_put_char()
  *
@@ -1672,7 +1680,6 @@ static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c)
        return 1;
 }
 
-
 /*
  * dgnc_tty_write()
  *
@@ -1680,19 +1687,18 @@ static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c)
  * In here exists all the Transparent Print magic as well.
  */
 static int dgnc_tty_write(struct tty_struct *tty,
-               const unsigned char *buf, int count)
+                         const unsigned char *buf, int count)
 {
        struct channel_t *ch = NULL;
        struct un_t *un = NULL;
        int bufcount = 0, n = 0;
-       int orig_count = 0;
        unsigned long flags;
        ushort head;
        ushort tail;
        ushort tmask;
        uint remain;
 
-       if (tty == NULL || dgnc_TmpWriteBuf == NULL)
+       if (!tty || !dgnc_TmpWriteBuf)
                return 0;
 
        un = tty->driver_data;
@@ -1711,7 +1717,6 @@ static int dgnc_tty_write(struct tty_struct *tty,
         * This helps to figure out if we should ask the FEP
         * to send us an event when it has more space available.
         */
-       orig_count = count;
 
        spin_lock_irqsave(&ch->ch_lock, flags);
 
@@ -1748,7 +1753,7 @@ static int dgnc_tty_write(struct tty_struct *tty,
         */
        if ((un->un_type == DGNC_PRINT) && !(ch->ch_flags & CH_PRON)) {
                dgnc_wmove(ch, ch->ch_digi.digi_onstr,
-                   (int) ch->ch_digi.digi_onlen);
+                          (int)ch->ch_digi.digi_onlen);
                head = (ch->ch_w_head) & tmask;
                ch->ch_flags |= CH_PRON;
        }
@@ -1759,7 +1764,7 @@ static int dgnc_tty_write(struct tty_struct *tty,
         */
        if ((un->un_type != DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
                dgnc_wmove(ch, ch->ch_digi.digi_offstr,
-                       (int) ch->ch_digi.digi_offlen);
+                          (int)ch->ch_digi.digi_offlen);
                head = (ch->ch_w_head) & tmask;
                ch->ch_flags &= ~CH_PRON;
        }
@@ -1818,7 +1823,6 @@ exit_retry:
        return 0;
 }
 
-
 /*
  * Return modem signals to ld.
  */
@@ -1866,7 +1870,6 @@ static int dgnc_tty_tiocmget(struct tty_struct *tty)
        return result;
 }
 
-
 /*
  * dgnc_tty_tiocmset()
  *
@@ -1874,7 +1877,7 @@ static int dgnc_tty_tiocmget(struct tty_struct *tty)
  */
 
 static int dgnc_tty_tiocmset(struct tty_struct *tty,
-               unsigned int set, unsigned int clear)
+                            unsigned int set, unsigned int clear)
 {
        struct dgnc_board *bd;
        struct channel_t *ch;
@@ -1918,7 +1921,6 @@ static int dgnc_tty_tiocmset(struct tty_struct *tty,
        return 0;
 }
 
-
 /*
  * dgnc_tty_send_break()
  *
@@ -1965,10 +1967,8 @@ static int dgnc_tty_send_break(struct tty_struct *tty, int msec)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 
        return 0;
-
 }
 
-
 /*
  * dgnc_tty_wait_until_sent()
  *
@@ -1979,7 +1979,6 @@ static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout)
        struct dgnc_board *bd;
        struct channel_t *ch;
        struct un_t *un;
-       int rc;
 
        if (!tty || tty->magic != TTY_MAGIC)
                return;
@@ -1996,10 +1995,9 @@ static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout)
        if (!bd || bd->magic != DGNC_BOARD_MAGIC)
                return;
 
-       rc = bd->bd_ops->drain(tty, 0);
+       bd->bd_ops->drain(tty, 0);
 }
 
-
 /*
  * dgnc_send_xchar()
  *
@@ -2036,9 +2034,6 @@ static void dgnc_tty_send_xchar(struct tty_struct *tty, char c)
        dev_dbg(tty->dev, "dgnc_tty_send_xchar finish\n");
 }
 
-
-
-
 /*
  * Return modem signals to ld.
  */
@@ -2075,12 +2070,11 @@ static inline int dgnc_get_mstat(struct channel_t *ch)
        return result;
 }
 
-
-
 /*
  * Return modem signals to ld.
  */
-static int dgnc_get_modem_info(struct channel_t *ch, unsigned int  __user *value)
+static int dgnc_get_modem_info(struct channel_t *ch,
+                              unsigned int  __user *value)
 {
        int result;
 
@@ -2095,13 +2089,14 @@ static int dgnc_get_modem_info(struct channel_t *ch, unsigned int  __user *value
        return put_user(result, value);
 }
 
-
 /*
  * dgnc_set_modem_info()
  *
  * Set modem signals, called by ld.
  */
-static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
+static int dgnc_set_modem_info(struct tty_struct *tty,
+                              unsigned int command,
+                              unsigned int __user *value)
 {
        struct dgnc_board *bd;
        struct channel_t *ch;
@@ -2175,7 +2170,6 @@ static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, uns
        return 0;
 }
 
-
 /*
  * dgnc_tty_digigeta()
  *
@@ -2184,7 +2178,8 @@ static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, uns
  *
  *
  */
-static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
+static int dgnc_tty_digigeta(struct tty_struct *tty,
+                            struct digi_t __user *retinfo)
 {
        struct channel_t *ch;
        struct un_t *un;
@@ -2217,7 +2212,6 @@ static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retin
        return 0;
 }
 
-
 /*
  * dgnc_tty_digiseta()
  *
@@ -2226,7 +2220,8 @@ static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retin
  *
  *
  */
-static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
+static int dgnc_tty_digiseta(struct tty_struct *tty,
+                            struct digi_t __user *new_info)
 {
        struct dgnc_board *bd;
        struct channel_t *ch;
@@ -2257,17 +2252,21 @@ static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_i
        /*
         * Handle transistions to and from RTS Toggle.
         */
-       if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && (new_digi.digi_flags & DIGI_RTS_TOGGLE))
+       if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
+           (new_digi.digi_flags & DIGI_RTS_TOGGLE))
                ch->ch_mostat &= ~(UART_MCR_RTS);
-       if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && !(new_digi.digi_flags & DIGI_RTS_TOGGLE))
+       if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
+           !(new_digi.digi_flags & DIGI_RTS_TOGGLE))
                ch->ch_mostat |= (UART_MCR_RTS);
 
        /*
         * Handle transistions to and from DTR Toggle.
         */
-       if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && (new_digi.digi_flags & DIGI_DTR_TOGGLE))
+       if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
+           (new_digi.digi_flags & DIGI_DTR_TOGGLE))
                ch->ch_mostat &= ~(UART_MCR_DTR);
-       if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
+       if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
+           !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
                ch->ch_mostat |= (UART_MCR_DTR);
 
        memcpy(&ch->ch_digi, &new_digi, sizeof(new_digi));
@@ -2300,11 +2299,11 @@ static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_i
        return 0;
 }
 
-
 /*
  * dgnc_set_termios()
  */
-static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
+static void dgnc_tty_set_termios(struct tty_struct *tty,
+                                struct ktermios *old_termios)
 {
        struct dgnc_board *bd;
        struct channel_t *ch;
@@ -2341,7 +2340,6 @@ static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_te
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 static void dgnc_tty_throttle(struct tty_struct *tty)
 {
        struct channel_t *ch;
@@ -2366,7 +2364,6 @@ static void dgnc_tty_throttle(struct tty_struct *tty)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 static void dgnc_tty_unthrottle(struct tty_struct *tty)
 {
        struct channel_t *ch;
@@ -2391,7 +2388,6 @@ static void dgnc_tty_unthrottle(struct tty_struct *tty)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 static void dgnc_tty_start(struct tty_struct *tty)
 {
        struct dgnc_board *bd;
@@ -2421,7 +2417,6 @@ static void dgnc_tty_start(struct tty_struct *tty)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 static void dgnc_tty_stop(struct tty_struct *tty)
 {
        struct dgnc_board *bd;
@@ -2451,7 +2446,6 @@ static void dgnc_tty_stop(struct tty_struct *tty)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
 /*
  * dgnc_tty_flush_chars()
  *
@@ -2494,8 +2488,6 @@ static void dgnc_tty_flush_chars(struct tty_struct *tty)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
-
 /*
  * dgnc_tty_flush_buffer()
  *
@@ -2540,8 +2532,6 @@ static void dgnc_tty_flush_buffer(struct tty_struct *tty)
        spin_unlock_irqrestore(&ch->ch_lock, flags);
 }
 
-
-
 /*****************************************************************************
  *
  * The IOCTL function and all of its helpers
@@ -2554,14 +2544,14 @@ static void dgnc_tty_flush_buffer(struct tty_struct *tty)
  * The usual assortment of ioctl's
  */
 static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
-               unsigned long arg)
+                         unsigned long arg)
 {
        struct dgnc_board *bd;
        struct channel_t *ch;
        struct un_t *un;
        int rc;
        unsigned long flags;
-       void __user *uarg = (void __user *) arg;
+       void __user *uarg = (void __user *)arg;
 
        if (!tty || tty->magic != TTY_MAGIC)
                return -ENODEV;
@@ -2586,7 +2576,6 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
        }
 
        switch (cmd) {
-
        /* Here are all the standard ioctl's that we MUST implement */
 
        case TCSBRK:
@@ -2617,7 +2606,6 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
 
                return 0;
 
-
        case TCSBRKP:
                /* support for POSIX tcsendbreak()
                 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
@@ -2668,18 +2656,20 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
 
                spin_unlock_irqrestore(&ch->ch_lock, flags);
 
-               rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
+               rc = put_user(C_CLOCAL(tty) ? 1 : 0,
+                             (unsigned long __user *)arg);
                return rc;
 
        case TIOCSSOFTCAR:
 
                spin_unlock_irqrestore(&ch->ch_lock, flags);
-               rc = get_user(arg, (unsigned long __user *) arg);
+               rc = get_user(arg, (unsigned long __user *)arg);
                if (rc)
                        return rc;
 
                spin_lock_irqsave(&ch->ch_lock, flags);
-               tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
+               tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
+                                      (arg ? CLOCAL : 0));
                ch->ch_bd->bd_ops->param(tty);
                spin_unlock_irqrestore(&ch->ch_lock, flags);
 
@@ -2728,15 +2718,16 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                                ch->ch_bd->bd_ops->flush_uart_write(ch);
 
                                if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
-                                       ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
+                                       ch->ch_tun.un_flags &=
+                                               ~(UN_LOW|UN_EMPTY);
                                        wake_up_interruptible(&ch->ch_tun.un_flags_wait);
                                }
 
                                if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
-                                       ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
+                                       ch->ch_pun.un_flags &=
+                                               ~(UN_LOW|UN_EMPTY);
                                        wake_up_interruptible(&ch->ch_pun.un_flags_wait);
                                }
-
                        }
                }
 
@@ -2797,7 +2788,6 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
 
                /* set information for ditty */
                if (cmd == (DIGI_SETAW)) {
-
                        spin_unlock_irqrestore(&ch->ch_lock, flags);
                        rc = ch->ch_bd->bd_ops->drain(tty, 0);
 
@@ -2817,9 +2807,11 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
        case DIGI_LOOPBACK:
                {
                        uint loopback = 0;
-                       /* Let go of locks when accessing user space, could sleep */
+                       /* Let go of locks when accessing user space,
+                        * could sleep
+                       */
                        spin_unlock_irqrestore(&ch->ch_lock, flags);
-                       rc = get_user(loopback, (unsigned int __user *) arg);
+                       rc = get_user(loopback, (unsigned int __user *)arg);
                        if (rc)
                                return rc;
                        spin_lock_irqsave(&ch->ch_lock, flags);
@@ -2837,7 +2829,7 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
 
        case DIGI_GETCUSTOMBAUD:
                spin_unlock_irqrestore(&ch->ch_lock, flags);
-               rc = put_user(ch->ch_custom_speed, (unsigned int __user *) arg);
+               rc = put_user(ch->ch_custom_speed, (unsigned int __user *)arg);
                return rc;
 
        case DIGI_SETCUSTOMBAUD:
@@ -2845,7 +2837,7 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                int new_rate;
                /* Let go of locks when accessing user space, could sleep */
                spin_unlock_irqrestore(&ch->ch_lock, flags);
-               rc = get_user(new_rate, (int __user *) arg);
+               rc = get_user(new_rate, (int __user *)arg);
                if (rc)
                        return rc;
                spin_lock_irqsave(&ch->ch_lock, flags);
@@ -2867,7 +2859,7 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                unsigned char c;
 
                spin_unlock_irqrestore(&ch->ch_lock, flags);
-               rc = get_user(c, (unsigned char __user *) arg);
+               rc = get_user(c, (unsigned char __user *)arg);
                if (rc)
                        return rc;
                spin_lock_irqsave(&ch->ch_lock, flags);
@@ -2915,14 +2907,16 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
                /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
                if (ch->ch_flags & CH_BREAK_SENDING)
                        events |= EV_TXB;
-               if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
+               if ((ch->ch_flags & CH_STOP) ||
+                   (ch->ch_flags & CH_FORCED_STOP))
                        events |= (EV_OPU | EV_OPS);
 
-               if ((ch->ch_flags & CH_STOPI) || (ch->ch_flags & CH_FORCED_STOPI))
+               if ((ch->ch_flags & CH_STOPI) ||
+                   (ch->ch_flags & CH_FORCED_STOPI))
                        events |= (EV_IPU | EV_IPS);
 
                spin_unlock_irqrestore(&ch->ch_lock, flags);
-               rc = put_user(events, (unsigned int __user *) arg);
+               rc = put_user(events, (unsigned int __user *)arg);
                return rc;
        }
 
index b6b76ff09657134ee55f07bcce621cb97c1450c4..4e6c16af40fc5f8fa2065dacb946ad2a78adf0e9 100644 (file)
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
  */
 
 #include <linux/kernel.h>
-#include <linux/module.h>
+#include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/ioport.h>
 
 #include "emxx_udc.h"
 
-#define        DRIVER_DESC     "EMXX UDC driver"
 #define        DMA_ADDR_INVALID        (~(dma_addr_t)0)
 
 static const char      driver_name[] = "emxx_udc";
-static const char      driver_desc[] = DRIVER_DESC;
 
 /*===========================================================================*/
 /* Prototype */
@@ -67,12 +61,10 @@ static void _nbu2ss_fifo_flush(struct nbu2ss_udc *, struct nbu2ss_ep *);
 #define        _nbu2ss_zero_len_pkt(udc, epnum)        \
        _nbu2ss_ep_in_end(udc, epnum, 0, 0)
 
-
 /*===========================================================================*/
 /* Global */
 struct nbu2ss_udc udc_controller;
 
-
 /*-------------------------------------------------------------------------*/
 /* Read */
 static inline u32 _nbu2ss_readl(void *address)
@@ -114,7 +106,7 @@ static void _nbu2ss_dump_register(struct nbu2ss_udc *udc)
 
        pr_info("=== %s()\n", __func__);
 
-       if (udc == NULL) {
+       if (!udc) {
                pr_err("%s udc == NULL\n", __func__);
                return;
        }
@@ -155,7 +147,7 @@ static void _nbu2ss_ep0_complete(struct usb_ep *_ep, struct usb_request *_req)
        struct usb_ctrlrequest  *p_ctrl;
        struct nbu2ss_udc *udc;
 
-       if ((_ep == NULL) || (_req == NULL))
+       if ((!_ep) || (!_req))
                return;
 
        udc = (struct nbu2ss_udc *)_req->context;
@@ -219,7 +211,7 @@ static u32 _nbu2ss_get_begin_ram_address(struct nbu2ss_udc *udc)
                }
 
                if ((data >> 16) > last_ram_adr)
-                       last_ram_adr = data>>16;
+                       last_ram_adr = data >> 16;
        }
 
        return last_ram_adr + use_ram_size;
@@ -595,7 +587,7 @@ static int EP0_out_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 length)
        union usb_reg_access  Temp32;
        union usb_reg_access  *pBuf32 = (union usb_reg_access *)pBuf;
 
-       if ((0 < length) && (length < sizeof(u32))) {
+       if ((length > 0) && (length < sizeof(u32))) {
                Temp32.dw = _nbu2ss_readl(&udc->p_regs->EP0_READ);
                for (i = 0 ; i < length ; i++)
                        pBuf32->byte.DATA[i] = Temp32.byte.DATA[i];
@@ -641,7 +633,7 @@ static int EP0_in_OverBytes(struct nbu2ss_udc *udc, u8 *pBuf, u32 iRemainSize)
        union usb_reg_access  Temp32;
        union usb_reg_access  *pBuf32 = (union usb_reg_access *)pBuf;
 
-       if ((0 < iRemainSize) && (iRemainSize < sizeof(u32))) {
+       if ((iRemainSize > 0) && (iRemainSize < sizeof(u32))) {
                for (i = 0 ; i < iRemainSize ; i++)
                        Temp32.byte.DATA[i] = pBuf32->byte.DATA[i];
                _nbu2ss_ep_in_end(udc, 0, Temp32.dw, iRemainSize);
@@ -691,7 +683,6 @@ static int EP0_receive_NULL(struct nbu2ss_udc *udc, bool pid_flag)
 /*-------------------------------------------------------------------------*/
 static int _nbu2ss_ep0_in_transfer(
        struct nbu2ss_udc *udc,
-       struct nbu2ss_ep *ep,
        struct nbu2ss_req *req
 )
 {
@@ -749,7 +740,6 @@ static int _nbu2ss_ep0_in_transfer(
 /*-------------------------------------------------------------------------*/
 static int _nbu2ss_ep0_out_transfer(
        struct nbu2ss_udc *udc,
-       struct nbu2ss_ep *ep,
        struct nbu2ss_req *req
 )
 {
@@ -778,7 +768,7 @@ static int _nbu2ss_ep0_out_transfer(
                req->req.actual += result;
                iRecvLength -= result;
 
-               if ((0 < iRecvLength) && (iRecvLength < sizeof(u32))) {
+               if ((iRecvLength > 0) && (iRecvLength < sizeof(u32))) {
                        pBuffer += result;
                        iRemainSize -= result;
 
@@ -857,11 +847,11 @@ static int _nbu2ss_out_dma(
        dmacnt = (length / mpkt);
        lmpkt = (length % mpkt) & ~(u32)0x03;
 
-       if (DMA_MAX_COUNT < dmacnt) {
+       if (dmacnt > DMA_MAX_COUNT) {
                dmacnt = DMA_MAX_COUNT;
                lmpkt = 0;
-       } else if (0 != lmpkt) {
-               if (0 == dmacnt)
+       } else if (lmpkt != 0) {
+               if (dmacnt == 0)
                        burst = 0;      /* Burst OFF */
                dmacnt++;
        }
@@ -872,7 +862,7 @@ static int _nbu2ss_out_dma(
        data = ((dmacnt & 0xff) << 16) | DCR1_EPn_DIR0 | DCR1_EPn_REQEN;
        _nbu2ss_writel(&preg->EP_DCR[num].EP_DCR1, data);
 
-       if (0 == burst) {
+       if (burst == 0) {
                _nbu2ss_writel(&preg->EP_REGS[num].EP_LEN_DCNT, 0);
                _nbu2ss_bitclr(&preg->EP_REGS[num].EP_DMA_CTRL, EPn_BURST_SET);
        } else {
@@ -1258,11 +1248,11 @@ static int _nbu2ss_start_transfer(
                /* EP0 */
                switch (udc->ep0state) {
                case EP0_IN_DATA_PHASE:
-                       nret = _nbu2ss_ep0_in_transfer(udc, ep, req);
+                       nret = _nbu2ss_ep0_in_transfer(udc, req);
                        break;
 
                case EP0_OUT_DATA_PHASE:
-                       nret = _nbu2ss_ep0_out_transfer(udc, ep, req);
+                       nret = _nbu2ss_ep0_out_transfer(udc, req);
                        break;
 
                case EP0_IN_STATUS_PHASE:
@@ -1277,7 +1267,7 @@ static int _nbu2ss_start_transfer(
                /* EPn */
                if (ep->direct == USB_DIR_OUT) {
                        /* OUT */
-                       if (bflag == FALSE)
+                       if (!bflag)
                                nret = _nbu2ss_epn_out_transfer(udc, ep, req);
                } else {
                        /* IN */
@@ -1300,7 +1290,7 @@ static void _nbu2ss_restert_transfer(struct nbu2ss_ep *ep)
        else
                req = list_entry(ep->queue.next, struct nbu2ss_req, queue);
 
-       if (req == NULL)
+       if (!req)
                return;
 
        if (ep->epnum > 0) {
@@ -1398,7 +1388,6 @@ static void _nbu2ss_set_endpoint_stall(
        }
 }
 
-
 /*-------------------------------------------------------------------------*/
 /* Device Descriptor */
 static struct usb_device_descriptor device_desc = {
@@ -1447,7 +1436,7 @@ static int _nbu2ss_set_feature_device(
 
        switch (selector) {
        case USB_DEVICE_REMOTE_WAKEUP:
-               if (0x0000 == wIndex) {
+               if (wIndex == 0x0000) {
                        udc->remote_wakeup = U2F_ENABLE;
                        result = 0;
                }
@@ -1504,8 +1493,8 @@ static inline int _nbu2ss_req_feature(struct nbu2ss_udc *udc, bool bset)
        u8      ep_adrs;
        int     result = -EOPNOTSUPP;
 
-       if ((0x0000 != udc->ctrl.wLength) ||
-                       (USB_DIR_OUT != direction)) {
+       if ((udc->ctrl.wLength != 0x0000) ||
+                       (direction != USB_DIR_OUT)) {
                return -EINVAL;
        }
 
@@ -1518,9 +1507,9 @@ static inline int _nbu2ss_req_feature(struct nbu2ss_udc *udc, bool bset)
 
        case USB_RECIP_ENDPOINT:
                if (0x0000 == (wIndex & 0xFF70)) {
-                       if (USB_ENDPOINT_HALT == selector) {
+                       if (selector == USB_ENDPOINT_HALT) {
                                ep_adrs = wIndex & 0xFF;
-                               if (bset == FALSE) {
+                               if (!bset) {
                                        _nbu2ss_endpoint_toggle_reset(
                                                udc, ep_adrs);
                                }
@@ -1597,8 +1586,8 @@ static int std_req_get_status(struct nbu2ss_udc *udc)
        u8      ep_adrs;
        int     result = -EINVAL;
 
-       if ((0x0000 != udc->ctrl.wValue)
-               || (USB_DIR_IN != direction)) {
+       if ((udc->ctrl.wValue != 0x0000)
+               || (direction != USB_DIR_IN)) {
 
                return result;
        }
@@ -1635,7 +1624,7 @@ static int std_req_get_status(struct nbu2ss_udc *udc)
        if (result >= 0) {
                memcpy(udc->ep0_buf, &status_data, length);
                _nbu2ss_create_ep0_packet(udc, udc->ep0_buf, length);
-               _nbu2ss_ep0_in_transfer(udc, &udc->ep[0], &udc->ep0_req);
+               _nbu2ss_ep0_in_transfer(udc, &udc->ep0_req);
 
        } else {
                dev_err(udc->dev, " Error GET_STATUS\n");
@@ -1662,9 +1651,9 @@ static int std_req_set_address(struct nbu2ss_udc *udc)
        int             result = 0;
        u32             wValue = udc->ctrl.wValue;
 
-       if ((0x00 != udc->ctrl.bRequestType)    ||
-               (0x0000 != udc->ctrl.wIndex)    ||
-               (0x0000 != udc->ctrl.wLength)) {
+       if ((udc->ctrl.bRequestType != 0x00)    ||
+               (udc->ctrl.wIndex != 0x0000)    ||
+               (udc->ctrl.wLength != 0x0000)) {
                return -EINVAL;
        }
 
@@ -1684,9 +1673,9 @@ static int std_req_set_configuration(struct nbu2ss_udc *udc)
 {
        u32 ConfigValue = (u32)(udc->ctrl.wValue & 0x00ff);
 
-       if ((0x0000 != udc->ctrl.wIndex)        ||
-               (0x0000 != udc->ctrl.wLength)   ||
-               (0x00 != udc->ctrl.bRequestType)) {
+       if ((udc->ctrl.wIndex != 0x0000)        ||
+               (udc->ctrl.wLength != 0x0000)   ||
+               (udc->ctrl.bRequestType != 0x00)) {
                return -EINVAL;
        }
 
@@ -1707,7 +1696,7 @@ static int std_req_set_configuration(struct nbu2ss_udc *udc)
 /*-------------------------------------------------------------------------*/
 static inline void _nbu2ss_read_request_data(struct nbu2ss_udc *udc, u32 *pdata)
 {
-       if ((udc == NULL) && (pdata == NULL))
+       if ((!udc) && (!pdata))
                return;
 
        *pdata = _nbu2ss_readl(&udc->p_regs->SETUP_DATA0);
@@ -1767,7 +1756,7 @@ static inline int _nbu2ss_decode_request(struct nbu2ss_udc *udc)
                }
        }
 
-       if (bcall_back == FALSE) {
+       if (!bcall_back) {
                if (udc->ep0state == EP0_IN_STATUS_PHASE) {
                        if (nret >= 0) {
                                /*--------------------------------------*/
@@ -1800,13 +1789,13 @@ static inline int _nbu2ss_ep0_in_data_stage(struct nbu2ss_udc *udc)
        else
                req = list_entry(ep->queue.next, struct nbu2ss_req, queue);
 
-       if (req == NULL)
+       if (!req)
                req = &udc->ep0_req;
 
        req->req.actual += req->div_len;
        req->div_len = 0;
 
-       nret = _nbu2ss_ep0_in_transfer(udc, ep, req);
+       nret = _nbu2ss_ep0_in_transfer(udc, req);
        if (nret == 0) {
                udc->ep0state = EP0_OUT_STATUS_PAHSE;
                EP0_receive_NULL(udc, TRUE);
@@ -1827,10 +1816,10 @@ static inline int _nbu2ss_ep0_out_data_stage(struct nbu2ss_udc *udc)
        else
                req = list_entry(ep->queue.next, struct nbu2ss_req, queue);
 
-       if (req == NULL)
+       if (!req)
                req = &udc->ep0_req;
 
-       nret = _nbu2ss_ep0_out_transfer(udc, ep, req);
+       nret = _nbu2ss_ep0_out_transfer(udc, req);
        if (nret == 0) {
                udc->ep0state = EP0_IN_STATUS_PHASE;
                EP0_send_NULL(udc, TRUE);
@@ -1854,7 +1843,7 @@ static inline int _nbu2ss_ep0_status_stage(struct nbu2ss_udc *udc)
        else
                req = list_entry(ep->queue.next, struct nbu2ss_req, queue);
 
-       if (req == NULL) {
+       if (!req) {
                req = &udc->ep0_req;
                if (req->req.complete)
                        req->req.complete(&ep->ep, &req->req);
@@ -2055,7 +2044,7 @@ static inline void _nbu2ss_epn_in_dma_int(
 
        preq = &req->req;
 
-       if (req->dma_flag == FALSE)
+       if (!req->dma_flag)
                return;
 
        preq->actual += req->div_len;
@@ -2161,7 +2150,7 @@ static inline void _nbu2ss_epn_int(struct nbu2ss_udc *udc, u32 epnum)
        else
                req = list_entry(ep->queue.next, struct nbu2ss_req, queue);
 
-       if (req == NULL) {
+       if (!req) {
                /* pr_warn("=== %s(%d) req == NULL\n", __func__, epnum); */
                return;
        }
@@ -2199,7 +2188,6 @@ static void _nbu2ss_ep0_enable(struct nbu2ss_udc *udc)
        _nbu2ss_writel(&udc->p_regs->EP0_INT_ENA, EP0_INT_EN_BIT);
 }
 
-
 /*-------------------------------------------------------------------------*/
 static int _nbu2ss_nuke(struct nbu2ss_udc *udc,
                        struct nbu2ss_ep *ep,
@@ -2335,7 +2323,6 @@ static int _nbu2ss_enable_controller(struct nbu2ss_udc *udc)
        return 0;
 }
 
-
 /*-------------------------------------------------------------------------*/
 static void _nbu2ss_reset_controller(struct nbu2ss_udc *udc)
 {
@@ -2568,13 +2555,13 @@ static int nbu2ss_ep_enable(
        struct nbu2ss_ep        *ep;
        struct nbu2ss_udc       *udc;
 
-       if ((_ep == NULL) || (desc == NULL)) {
+       if ((!_ep) || (!desc)) {
                pr_err(" *** %s, bad param\n", __func__);
                return -EINVAL;
        }
 
        ep = container_of(_ep, struct nbu2ss_ep, ep);
-       if ((ep == NULL) || (ep->udc == NULL)) {
+       if ((!ep) || (!ep->udc)) {
                pr_err(" *** %s, ep == NULL !!\n", __func__);
                return -EINVAL;
        }
@@ -2591,7 +2578,7 @@ static int nbu2ss_ep_enable(
        if (udc->vbus_active == 0)
                return -ESHUTDOWN;
 
-       if ((udc->driver == NULL)
+       if ((!udc->driver)
                || (udc->gadget.speed == USB_SPEED_UNKNOWN)) {
 
                dev_err(ep->udc->dev, " *** %s, udc !!\n", __func__);
@@ -2628,13 +2615,13 @@ static int nbu2ss_ep_disable(struct usb_ep *_ep)
        struct nbu2ss_udc       *udc;
        unsigned long           flags;
 
-       if (_ep == NULL) {
+       if (!_ep) {
                pr_err(" *** %s, bad param\n", __func__);
                return -EINVAL;
        }
 
        ep = container_of(_ep, struct nbu2ss_ep, ep);
-       if ((ep == NULL) || (ep->udc == NULL)) {
+       if ((!ep) || (!ep->udc)) {
                pr_err("udc: *** %s, ep == NULL !!\n", __func__);
                return -EINVAL;
        }
@@ -2676,7 +2663,7 @@ static void nbu2ss_ep_free_request(
 {
        struct nbu2ss_req *req;
 
-       if (_req != NULL) {
+       if (_req) {
                req = container_of(_req, struct nbu2ss_req, req);
 
                kfree(req);
@@ -2697,11 +2684,11 @@ static int nbu2ss_ep_queue(
        int                     result = -EINVAL;
 
        /* catch various bogus parameters */
-       if ((_ep == NULL) || (_req == NULL)) {
-               if (_ep == NULL)
+       if ((!_ep) || (!_req)) {
+               if (!_ep)
                        pr_err("udc: %s --- _ep == NULL\n", __func__);
 
-               if (_req == NULL)
+               if (!_req)
                        pr_err("udc: %s --- _req == NULL\n", __func__);
 
                return -EINVAL;
@@ -2747,7 +2734,7 @@ static int nbu2ss_ep_queue(
                req->unaligned = FALSE;
 
        if (req->unaligned) {
-               if (ep->virt_buf == NULL)
+               if (!ep->virt_buf)
                        ep->virt_buf = (u8 *)dma_alloc_coherent(
                                NULL, PAGE_SIZE,
                                &ep->phys_buf, GFP_ATOMIC | GFP_DMA);
@@ -2769,7 +2756,7 @@ static int nbu2ss_ep_queue(
        bflag = list_empty(&ep->queue);
        list_add_tail(&req->queue, &ep->queue);
 
-       if ((bflag != FALSE) && (ep->stalled == FALSE)) {
+       if (bflag && !ep->stalled) {
 
                result = _nbu2ss_start_transfer(udc, ep, req, FALSE);
                if (result < 0) {
@@ -2803,7 +2790,7 @@ static int nbu2ss_ep_dequeue(
        unsigned long flags;
 
        /* catch various bogus parameters */
-       if ((_ep == NULL) || (_req == NULL)) {
+       if ((!_ep) || (!_req)) {
                /* pr_err("%s, bad param(1)\n", __func__); */
                return -EINVAL;
        }
@@ -2815,7 +2802,7 @@ static int nbu2ss_ep_dequeue(
        }
 
        udc = ep->udc;
-       if (udc == NULL)
+       if (!udc)
                return -EINVAL;
 
        spin_lock_irqsave(&udc->lock, flags);
@@ -2989,7 +2976,6 @@ static struct usb_ep_ops nbu2ss_ep_ops = {
        .fifo_flush     = nbu2ss_ep_fifo_flush,
 };
 
-
 /*-------------------------------------------------------------------------*/
 /* usb_gadget_ops */
 
@@ -2999,13 +2985,13 @@ static int nbu2ss_gad_get_frame(struct usb_gadget *pgadget)
        u32                     data;
        struct nbu2ss_udc       *udc;
 
-       if (pgadget == NULL) {
+       if (!pgadget) {
                pr_err("udc: %s, bad param\n", __func__);
                return -EINVAL;
        }
 
        udc = container_of(pgadget, struct nbu2ss_udc, gadget);
-       if (udc == NULL) {
+       if (!udc) {
                dev_err(&pgadget->dev, "%s, udc == NULL\n", __func__);
                return -EINVAL;
        }
@@ -3027,13 +3013,13 @@ static int nbu2ss_gad_wakeup(struct usb_gadget *pgadget)
 
        struct nbu2ss_udc       *udc;
 
-       if (pgadget == NULL) {
+       if (!pgadget) {
                pr_err("%s, bad param\n", __func__);
                return -EINVAL;
        }
 
        udc = container_of(pgadget, struct nbu2ss_udc, gadget);
-       if (udc == NULL) {
+       if (!udc) {
                dev_err(&pgadget->dev, "%s, udc == NULL\n", __func__);
                return -EINVAL;
        }
@@ -3065,7 +3051,7 @@ static int nbu2ss_gad_set_selfpowered(struct usb_gadget *pgadget,
        struct nbu2ss_udc       *udc;
        unsigned long           flags;
 
-       if (pgadget == NULL) {
+       if (!pgadget) {
                pr_err("%s, bad param\n", __func__);
                return -EINVAL;
        }
@@ -3091,7 +3077,7 @@ static int nbu2ss_gad_vbus_draw(struct usb_gadget *pgadget, unsigned mA)
        struct nbu2ss_udc       *udc;
        unsigned long           flags;
 
-       if (pgadget == NULL) {
+       if (!pgadget) {
                pr_err("%s, bad param\n", __func__);
                return -EINVAL;
        }
@@ -3111,14 +3097,14 @@ static int nbu2ss_gad_pullup(struct usb_gadget *pgadget, int is_on)
        struct nbu2ss_udc       *udc;
        unsigned long           flags;
 
-       if (pgadget == NULL) {
+       if (!pgadget) {
                pr_err("%s, bad param\n", __func__);
                return -EINVAL;
        }
 
        udc = container_of(pgadget, struct nbu2ss_udc, gadget);
 
-       if (udc->driver == NULL) {
+       if (!udc->driver) {
                pr_warn("%s, Not Regist Driver\n", __func__);
                return -EINVAL;
        }
@@ -3142,7 +3128,6 @@ static int nbu2ss_gad_ioctl(
        return 0;
 }
 
-
 static const struct usb_gadget_ops nbu2ss_gadget_ops = {
        .get_frame              = nbu2ss_gad_get_frame,
        .wakeup                 = nbu2ss_gad_wakeup,
@@ -3295,14 +3280,14 @@ static int nbu2ss_drv_probe(struct platform_device *pdev)
        /* USB Function Controller Interrupt */
        if (status != 0) {
                dev_err(udc->dev, "request_irq(USB_UDC_IRQ_1) failed\n");
-               goto cleanup1;
+               return status;
        }
 
        /* Driver Initialization */
        status = nbu2ss_drv_contest_init(pdev, udc);
        if (status < 0) {
                /* Error */
-               goto cleanup1;
+               return status;
        }
 
        /* VBUS Interrupt */
@@ -3315,13 +3300,10 @@ static int nbu2ss_drv_probe(struct platform_device *pdev)
 
        if (status != 0) {
                dev_err(udc->dev, "request_irq(INT_VBUS) failed\n");
-               goto cleanup1;
+               return status;
        }
 
        return status;
-
-cleanup1:
-       return status;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -3330,41 +3312,19 @@ static void nbu2ss_drv_shutdown(struct platform_device *pdev)
        struct nbu2ss_udc       *udc;
 
        udc = platform_get_drvdata(pdev);
-       if (udc == NULL)
+       if (!udc)
                return;
 
        _nbu2ss_disable_controller(udc);
 }
 
-/*-------------------------------------------------------------------------*/
-static int __exit nbu2ss_drv_remove(struct platform_device *pdev)
-{
-       struct nbu2ss_udc       *udc;
-       struct nbu2ss_ep        *ep;
-       int     i;
-
-       udc = &udc_controller;
-
-       for (i = 0; i < NUM_ENDPOINTS; i++) {
-               ep = &udc->ep[i];
-               if (ep->virt_buf)
-                       dma_free_coherent(NULL, PAGE_SIZE,
-                               (void *)ep->virt_buf, ep->phys_buf);
-       }
-
-       /* Interrupt Handler - Release */
-       free_irq(INT_VBUS, udc);
-
-       return 0;
-}
-
 /*-------------------------------------------------------------------------*/
 static int nbu2ss_drv_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct nbu2ss_udc       *udc;
 
        udc = platform_get_drvdata(pdev);
-       if (udc == NULL)
+       if (!udc)
                return 0;
 
        if (udc->vbus_active) {
@@ -3391,7 +3351,7 @@ static int nbu2ss_drv_resume(struct platform_device *pdev)
        struct nbu2ss_udc       *udc;
 
        udc = platform_get_drvdata(pdev);
-       if (udc == NULL)
+       if (!udc)
                return 0;
 
        data = gpio_get_value(VBUS_VALUE);
@@ -3407,22 +3367,15 @@ static int nbu2ss_drv_resume(struct platform_device *pdev)
        return 0;
 }
 
-
 static struct platform_driver udc_driver = {
        .probe          = nbu2ss_drv_probe,
        .shutdown       = nbu2ss_drv_shutdown,
-       .remove         = __exit_p(nbu2ss_drv_remove),
        .suspend        = nbu2ss_drv_suspend,
        .resume         = nbu2ss_drv_resume,
        .driver         = {
-               .name   = driver_name,
+               .name                   = driver_name,
+               .suppress_bind_attrs    = true,
        },
 };
 
-module_platform_driver(udc_driver);
-
-MODULE_DESCRIPTION(DRIVER_DESC);
-MODULE_AUTHOR("Renesas Electronics Corporation");
-MODULE_LICENSE("GPL");
-
-
+builtin_platform_driver(udc_driver);
index 0db6b41333ea0fe38e9bb0042e182dc680c05b4c..4a2cc38de7b387e541947be766c2a9f3ec94d016 100644 (file)
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
  */
 
-
-
-
 #ifndef _LINUX_EMXX_H
 #define _LINUX_EMXX_H
 
-
-
 /*---------------------------------------------------------------------------*/
 /*----------------- Default undef */
 #if 0
 #define        USE_DMA 1
 #define USE_SUSPEND_WAIT       1
 
-
-
 #ifndef TRUE
 #define TRUE   1
 #define FALSE  0
 #endif
 
-
 /*------------ Board dependence(Resource) */
 #define        VBUS_VALUE              GPIO_VBUS
 
 /* DMA Abort wait time ms */
 #define DMA_DISABLE_TIME               10
 
-
-
 /*------------ Controller dependence */
 #define NUM_ENDPOINTS          14              /* Endpoint */
 #define REG_EP_NUM             15              /* Endpoint Register */
 #define DMA_MAX_COUNT          256             /* DMA Block */
 
-
-
 #define EPC_RST_DISABLE_TIME           1       /* 1 usec */
 #define EPC_DIRPD_DISABLE_TIME         1       /* 1 msec */
 #define EPC_PLL_LOCK_COUNT             1000    /* 1000 */
 #define CHATGER_TIME                   700     /* 700msec */
 #define USB_SUSPEND_TIME               2000    /* 2 sec */
 
-
 /* U2F FLAG */
 #define U2F_ENABLE             1
 #define U2F_DISABLE            0
 
-
 /*------- BIT */
 #define BIT00          0x00000001
 #define BIT01          0x00000002
 /*------- (0x1118:) EPnTADR Register */
 #define EPn_TADR                       0xFFFFFFFF      /* RW */
 
-
-
 /*===========================================================================*/
 /* Struct */
 /*------- ep_regs */
@@ -526,13 +506,6 @@ struct fc_regs {
        u8 Reserved1200[0x1000-0x200];  /* Reserved */
 } __aligned(32);
 
-
-
-
-
-
-
-
 #define EP0_PACKETSIZE                 64
 #define EP_PACKETSIZE                  1024
 
@@ -543,10 +516,8 @@ struct fc_regs {
 #define D_FS_RAM_SIZE_BULK             64
 #define D_HS_RAM_SIZE_BULK             512
 
-
 struct nbu2ss_udc;
 
-
 enum ep0_state {
        EP0_IDLE,
        EP0_IN_DATA_PHASE,
@@ -591,7 +562,6 @@ struct nbu2ss_ep {
        dma_addr_t      phys_buf;
 };
 
-
 struct nbu2ss_udc {
        struct usb_gadget gadget;
        struct usb_gadget_driver *driver;
index d473010fa4748409d32e3d088679f81310cec0ec..883ff5b8fdab7a28e26205ee766e5e4f6cf451a7 100644 (file)
@@ -141,6 +141,16 @@ config FB_TFT_ST7735R
        help
          Generic Framebuffer support for ST7735R
 
+config FB_TFT_ST7789V
+       tristate "FB driver for the ST7789V LCD Controller"
+       depends on FB_TFT
+       help
+         This enables generic framebuffer support for the Sitronix ST7789V
+         display controller. The controller is intended for small color
+         displays with a resolution of up to 320x240 pixels.
+
+         Say Y if you have such a display that utilizes this controller.
+
 config FB_TFT_TINYLCD
        tristate "FB driver for tinylcd.com display"
        depends on FB_TFT
index b26efdc877756636c329340df8426f90508b8835..4f9071d96d01baefb1f3a31a671ee92d87052255 100644 (file)
@@ -25,6 +25,7 @@ obj-$(CONFIG_FB_TFT_SSD1306)     += fb_ssd1306.o
 obj-$(CONFIG_FB_TFT_SSD1331)     += fb_ssd1331.o
 obj-$(CONFIG_FB_TFT_SSD1351)     += fb_ssd1351.o
 obj-$(CONFIG_FB_TFT_ST7735R)     += fb_st7735r.o
+obj-$(CONFIG_FB_TFT_ST7789V)     += fb_st7789v.o
 obj-$(CONFIG_FB_TFT_TINYLCD)     += fb_tinylcd.o
 obj-$(CONFIG_FB_TFT_TLS8204)     += fb_tls8204.o
 obj-$(CONFIG_FB_TFT_UC1611)      += fb_uc1611.o
index 94dd49ce18deb09cb49b9c9bcacbbebcebe3bb64..2a50cf957101116f27a14b76ee1364f030ec1efb 100644 (file)
@@ -41,8 +41,7 @@
 #define CS0                    gpio.aux[0]
 #define CS1                    gpio.aux[1]
 
-
-/* diffusing error (\93Floyd-Steinberg\94) */
+/* diffusing error (Floyd-Steinberg) */
 #define DIFFUSING_MATRIX_WIDTH 2
 #define DIFFUSING_MATRIX_HEIGHT        2
 
@@ -75,8 +74,6 @@ static int init_display(struct fbtft_par *par)
 {
        u8 i;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        for (i = 0; i < 2; ++i) {
@@ -180,7 +177,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 {
        va_list args;
        int i, ret;
-       u8 *buf = (u8 *)par->buf;
+       u8 *buf = par->buf;
 
        if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
                va_start(args, len);
@@ -245,10 +242,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
        addr_win.ys_page = ys / 8;
        addr_win.xe = xe;
        addr_win.ye_page = ye / 8;
-
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys_page=%d, xe=%d, ye_page=%d)\n", __func__,
-               addr_win.xs, addr_win.ys_page, addr_win.xe, addr_win.ye_page);
 }
 
 static void
@@ -273,7 +266,7 @@ construct_line_bitmap(struct fbtft_par *par, u8 *dest, signed short *src,
 
 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 {
-       u16 *vmem16 = (u16 *)par->info->screen_base;
+       u16 *vmem16 = (u16 *)par->info->screen_buffer;
        u8 *buf = par->txbuf.buf;
        int x, y;
        int ret = 0;
@@ -285,8 +278,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
        if (!convert_buf)
                return -ENOMEM;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
        /* converting to grayscale16 */
        for (x = 0; x < par->info->var.xres; ++x)
                for (y = 0; y < par->info->var.yres; ++y) {
@@ -420,7 +411,6 @@ static int write(struct fbtft_par *par, void *buf, size_t len)
 
        gpio_set_value(par->RW, 0); /* set write mode */
 
-
        while (len--) {
                u8 i, data;
 
@@ -456,6 +446,7 @@ static struct fbtft_display display = {
                .write_vmem = write_vmem,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "displaytronic,fb_agm1264k-fl", &display);
 
 MODULE_ALIAS("platform:" DRVNAME);
index 17a2162a7e5b10f08ab0d29d88fc7f7f23d5a904..6010e6cbbd723d05eab2868d8906b226e17381d5 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -37,8 +33,6 @@
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        if (par->gpio.cs != -1)
                gpio_set_value(par->gpio.cs, 0);  /* Activate chip */
 
@@ -122,8 +116,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
        switch (par->info->var.rotate) {
        /* R200h = Horizontal GRAM Start Address */
        /* R201h = Vertical GRAM Start Address */
@@ -149,8 +141,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        /* AM: GRAM update direction */
        case 0:
@@ -181,6 +171,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "hitachi,bd663474", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 54528aa0c0efe2f5ed130c5869e291cb743eb626..e1ed177f9184a0f538f7d6deb19fbc2a7e1c7766 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
 #define DEFAULT_GAMMA  "1 3 0E 5 0 2 09 0 6 1 7 1 0 2 2\n" \
                        "3 3 17 8 4 7 05 7 6 0 3 1 6 0 0 "
 
-
 static bool emulate;
 module_param(emulate, bool, 0);
 MODULE_PARM_DESC(emulate, "Force emulation in 9-bit mode");
 
-
 static int init_display(struct fbtft_par *par)
 {
        par->fbtftops.reset(par);
@@ -117,9 +111,9 @@ static int set_var(struct fbtft_par *par)
 {
        /* MADCTL - Memory data access control */
        /* RGB/BGR can be set with H/W pin SRGB and MADCTL BGR bit */
-#define MY (1 << 7)
-#define MX (1 << 6)
-#define MV (1 << 5)
+#define MY BIT(7)
+#define MX BIT(6)
+#define MV BIT(5)
        switch (par->info->var.rotate) {
        case 0:
                write_reg(par, 0x36, par->bgr << 3);
@@ -145,7 +139,7 @@ static int set_var(struct fbtft_par *par)
     OP0 OP1 CP0 CP1 CP2 CP3 CP4 MP0 MP1 MP2 MP3 MP4 MP5 CGM0 CGM1
     ON0 ON1 CN0 CN1 CN2 CN3 CN4 MN0 MN1 MN2 MN3 MN4 MN5 XXXX  GC
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long mask[] = {
@@ -192,7 +186,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -208,6 +201,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8340bn", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 03ae95b4f79e80e174ee4a2c9c733e97fd783be6..6ff76e531a37131855f22c7865fd6139b740bf88 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
 #define DEFAULT_GAMMA  "0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" \
                        "0 0 0 0 0 0 0 0 0 0 0 0 0 0"
 
-
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        /* driving ability */
@@ -92,9 +85,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        write_reg(par, 0x02, (xs >> 8) & 0xFF);
        write_reg(par, 0x03, xs & 0xFF);
        write_reg(par, 0x04, (xe >> 8) & 0xFF);
@@ -111,7 +101,7 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
     VRP0 VRP1 VRP2 VRP3 VRP4 VRP5 PRP0 PRP1 PKP0 PKP1 PKP2 PKP3 PKP4 CGM
     VRN0 VRN1 VRN2 VRN3 VRN4 VRN5 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 CGM
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long mask[] = {
@@ -121,8 +111,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        int i, j;
        int acc = 0;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        for (i = 0; i < par->gamma.num_curves; i++)
                for (j = 0; j < par->gamma.num_values; j++) {
@@ -154,7 +142,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -168,6 +155,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8347d", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index d7f4308e124985a5eaaa0622600bc2ad5d07bdbf..8552411695fa8904dd54b77933b9308117ce18e7 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -32,8 +28,6 @@
 static int init_display(struct fbtft_par *par)
 {
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
        mdelay(150);
 
@@ -78,9 +72,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* column address */
        write_reg(par, 0x2a, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
 
@@ -91,13 +82,11 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
        write_reg(par, 0x2c);
 }
 
-#define my (1 << 7)
-#define mx (1 << 6)
-#define mv (1 << 5)
+#define my BIT(7)
+#define mx BIT(6)
+#define mv BIT(5)
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* madctl - memory data access control
             rgb/bgr:
             1. mode selection pin srgb
@@ -127,8 +116,6 @@ static int set_var(struct fbtft_par *par)
 */
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        write_reg(par, 0xE0,
                curves[0], curves[1], curves[2], curves[3],
                curves[4], curves[5], curves[6], curves[7],
@@ -139,7 +126,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = 128,
@@ -154,6 +140,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8353d", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 8c7bb3ac80305075091ba4055d5fdbee4e23cd90..a381dbcf5535bd1f7d9ab2fe6bbd25fd5b6395b1 100644 (file)
@@ -16,9 +16,6 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <linux/module.h>
 #define WIDTH          320
 #define HEIGHT         480
 
-
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        /* Reset things like Gamma */
@@ -145,9 +139,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column addr set */
        write_reg(par, HX8357_CASET,
                xs >> 8, xs & 0xff,  /* XSTART */
@@ -173,8 +164,6 @@ static int set_var(struct fbtft_par *par)
 {
        u8 val;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 270:
                val = HX8357D_MADCTL_MV | HX8357D_MADCTL_MX;
@@ -210,6 +199,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "himax,hx8357d", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index ed92a64306ff2dece1b74e38df087870a00a8bc9..f31b3f4b92757de41698cee516cfd73b01a236e0 100644 (file)
@@ -108,8 +108,6 @@ create setup for different displays.
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        if (par->gpio.cs != -1)
@@ -149,9 +147,6 @@ static int init_display(struct fbtft_par *par)
 static void set_addr_win(struct fbtft_par *par, int xs, int ys,
                                int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        switch (par->info->var.rotate) {
        case 0:
                write_reg(par, CMD_CLMADRS, xs >> 8, xs & 0xff, xe >> 8,
@@ -204,8 +199,6 @@ static int set_var(struct fbtft_par *par)
 {
        u8 mactrl_data = 0; /* Avoid compiler warning */
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 0:
                mactrl_data = 0x08;
@@ -230,7 +223,7 @@ static int set_var(struct fbtft_par *par)
 }
 
 #ifdef GAMMA_ADJ
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int gamma_adj(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long mask[] = {
@@ -239,11 +232,9 @@ static int gamma_adj(struct fbtft_par *par, unsigned long *curves)
                0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
        int i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        for (i = 0; i < GAMMA_NUM; i++)
                for (j = 0; j < GAMMA_LEN; j++)
-                       CURVE(i, j) &= mask[i*par->gamma.num_values + j];
+                       CURVE(i, j) &= mask[i * par->gamma.num_values + j];
 
        write_reg(par, CMD_PGAMMAC,
                                CURVE(0, 0),
index ef4fa6b72c7964b400def0bdf2b4873a76b11349..3ed50febe36f6ba38b55c6f10f5c4324dcb6cdc4 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -33,7 +29,6 @@
 #define DEFAULT_GAMMA  "07 07 6 0 0 0 5 5 4 0\n" \
                        "07 08 4 7 5 1 2 0 7 7"
 
-
 static unsigned read_devicecode(struct fbtft_par *par)
 {
        int ret;
@@ -48,8 +43,6 @@ static int init_display(struct fbtft_par *par)
 {
        unsigned devcode;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        devcode = read_devicecode(par);
@@ -96,7 +89,6 @@ static int init_display(struct fbtft_par *par)
        /* RGB interface polarity */
        write_reg(par, 0x000F, 0x0000);
 
-
        /* ***********Power On sequence *************** */
        /* SAP, BT[3:0], AP, DSTB, SLP, STB */
        write_reg(par, 0x0010, 0x0000);
@@ -181,9 +173,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        switch (par->info->var.rotate) {
        /* R20h = Horizontal GRAM Start Address */
        /* R21h = Vertical GRAM Start Address */
@@ -209,8 +198,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 0:
                write_reg(par, 0x3, (par->bgr << 12) | 0x30);
@@ -233,7 +220,7 @@ static int set_var(struct fbtft_par *par)
     VRP0 VRP1 RP0 RP1 KP0 KP1 KP2 KP3 KP4 KP5
     VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long mask[] = {
@@ -242,12 +229,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        };
        int i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        for (i = 0; i < 2; i++)
                for (j = 0; j < 10; j++)
-                       CURVE(i, j) &= mask[i*par->gamma.num_values + j];
+                       CURVE(i, j) &= mask[i * par->gamma.num_values + j];
 
        write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
        write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
@@ -265,7 +250,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 16,
        .width = WIDTH,
@@ -280,6 +264,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9320", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 19d254e9a4206c729a777cff079318f6ee7cc7e8..3b3a06d8a125fc5bf9b44ca2ec27e7583307641a 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -36,7 +32,6 @@
 #define DEFAULT_GAMMA  "0F 00 7 2 0 0 6 5 4 1\n" \
                        "04 16 2 7 6 3 2 1 7 7"
 
-
 static unsigned bt = 6; /* VGL=Vci*4 , VGH=Vci*4 */
 module_param(bt, uint, 0);
 MODULE_PARM_DESC(bt, "Sets the factor used in the step-up circuits");
@@ -60,7 +55,6 @@ static unsigned vcm = 0x0a; /* VCOMH=VREG1OUT*0.735 */
 module_param(vcm, uint, 0);
 MODULE_PARM_DESC(vcm, "Set the internal VcomH voltage");
 
-
 /*
 Verify that this configuration is within the Voltage limits
 
@@ -101,8 +95,6 @@ VCOMH - VCOML < 6.0   =>  4.79 < 6.0
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        if (par->gpio.cs != -1)
@@ -176,8 +168,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
        switch (par->info->var.rotate) {
        /* R20h = Horizontal GRAM Start Address */
        /* R21h = Vertical GRAM Start Address */
@@ -203,8 +193,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        /* AM: GRAM update direction */
        case 0:
@@ -229,7 +217,7 @@ static int set_var(struct fbtft_par *par)
     VRP0 VRP1 RP0 RP1 KP0 KP1 KP2 KP3 KP4 KP5
     VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long mask[] = {
@@ -238,12 +226,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        };
        int i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        for (i = 0; i < 2; i++)
                for (j = 0; j < 10; j++)
-                       CURVE(i, j) &= mask[i*par->gamma.num_values + j];
+                       CURVE(i, j) &= mask[i * par->gamma.num_values + j];
 
        write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
        write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
@@ -261,7 +247,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 16,
        .width = WIDTH,
@@ -278,6 +263,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9325", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 0f4a42f89e5e2cfb0ba5a94331d3f582fb2352d7..e0e253989271a6ad1aae7da311ae39228697f53e 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
 #define WIDTH          240
 #define HEIGHT         320
 
-
 /* Init sequence taken from: Arduino Library for the Adafruit 2.2" display */
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        write_reg(par, 0xEF, 0x03, 0x80, 0x02);
@@ -98,9 +91,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address */
        write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
 
@@ -118,8 +108,6 @@ static int set_var(struct fbtft_par *par)
 {
        u8 val;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 270:
                val = ILI9340_MADCTL_MV;
@@ -140,7 +128,6 @@ static int set_var(struct fbtft_par *par)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -151,6 +138,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9340", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 709492e560b61b64a52502e360d0fdbcebd05ee2..dcee0aff58756771181c27860ffb8b2f359f25b7 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
 #define DEFAULT_GAMMA  "1F 1A 18 0A 0F 06 45 87 32 0A 07 02 07 05 00\n" \
                        "00 25 27 05 10 09 3A 78 4D 05 18 0D 38 3A 1F"
 
-
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        /* startup sequence for MI0283QT-9A */
@@ -82,9 +75,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address set */
        write_reg(par, 0x2A,
                (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF);
@@ -105,15 +95,13 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 #define MEM_BGR (3) /* RGB-BGR Order */
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 0:
                write_reg(par, 0x36, (1 << MEM_X) | (par->bgr << MEM_BGR));
                break;
        case 270:
                write_reg(par, 0x36,
-                       (1<<MEM_V) | (1 << MEM_L) | (par->bgr << MEM_BGR));
+                       (1 << MEM_V) | (1 << MEM_L) | (par->bgr << MEM_BGR));
                break;
        case 180:
                write_reg(par, 0x36, (1 << MEM_Y) | (par->bgr << MEM_BGR));
@@ -132,13 +120,11 @@ static int set_var(struct fbtft_par *par)
     Positive: Par1 Par2 [...] Par15
     Negative: Par1 Par2 [...] Par15
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        int i;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        for (i = 0; i < par->gamma.num_curves; i++)
                write_reg(par, 0xE0 + i,
                        CURVE(i, 0), CURVE(i, 1), CURVE(i, 2),
@@ -151,7 +137,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -167,6 +152,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9341", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 8bae09c2d5cecdb1bcf2a8d3f84f3bf4512885c3..63684864f3098def78d0adb2261821a8c44b1543 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -57,9 +53,6 @@ static int default_init_sequence[] = {
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* column address */
        write_reg(par, 0x2a, xs >> 8, xs & 0xff, xe >> 8, xe & 0xff);
 
@@ -75,8 +68,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 #define ROWxCOL 0x20
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 270:
                write_reg(par, 0x36, ROWxCOL | HFLIP | VFLIP | (par->bgr << 3));
@@ -105,6 +96,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9481", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index dd4ddca384ad75dd208ec315e374c54b1865603c..d9dfff68159b025f26a9fe4e9c147343f0909bdb 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -28,7 +24,6 @@
 #define WIDTH          320
 #define HEIGHT         480
 
-
 /* this init sequence matches PiScreen */
 static int default_init_sequence[] = {
        /* Interface Mode Control */
@@ -61,9 +56,6 @@ static int default_init_sequence[] = {
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address */
        write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
 
@@ -76,8 +68,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 0:
                write_reg(par, 0x36, 0x80 | (par->bgr << 3));
@@ -98,7 +88,6 @@ static int set_var(struct fbtft_par *par)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -109,6 +98,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "ilitek,ili9486", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 15da0ec77513a464b348c1123a7e57629cc7b0a4..a6b43323f29ac952d98c5812fd1e7cbb9b002ce7 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -33,7 +29,7 @@
 #define DRVNAME               "fb_pcd8544"
 #define WIDTH          84
 #define HEIGHT         48
-#define TXBUFLEN       (84*6)
+#define TXBUFLEN       (84 * 6)
 #define DEFAULT_GAMMA  "40" /* gamma controls the contrast in this driver */
 
 static unsigned tc;
@@ -44,11 +40,8 @@ static unsigned bs = 4;
 module_param(bs, uint, 0);
 MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
 
-
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        /* Function set
@@ -101,9 +94,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
-                     __func__, xs, ys, xe, ye);
-
        /* H=0 Set X address of RAM
         *
         * 7:1  1
@@ -122,25 +112,24 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 {
-       u16 *vmem16 = (u16 *)par->info->screen_base;
+       u16 *vmem16 = (u16 *)par->info->screen_buffer;
        u8 *buf = par->txbuf.buf;
        int x, y, i;
        int ret = 0;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
        for (x = 0; x < 84; x++) {
                for (y = 0; y < 6; y++) {
                        *buf = 0x00;
                        for (i = 0; i < 8; i++)
-                               *buf |= (vmem16[(y*8+i)*84+x] ? 1 : 0) << i;
+                               *buf |= (vmem16[(y * 8 + i) * 84 + x] ?
+                                        1 : 0) << i;
                        buf++;
                }
        }
 
        /* Write data */
        gpio_set_value(par->gpio.dc, 1);
-       ret = par->fbtftops.write(par, par->txbuf.buf, 6*84);
+       ret = par->fbtftops.write(par, par->txbuf.buf, 6 * 84);
        if (ret < 0)
                dev_err(par->info->device, "write failed and returned: %d\n",
                        ret);
@@ -150,8 +139,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        curves[0] &= 0x7F;
 
@@ -162,7 +149,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -179,6 +165,7 @@ static struct fbtft_display display = {
        },
        .backlight = 1,
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "philips,pdc8544", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 54bc566b09fd7a9f481245077ef7b3b152f6a135..b167c50616318a94e98c766c9ef972f05fc60fbc 100644 (file)
@@ -1,19 +1,7 @@
-/******************************************************************************
-
-  ProjectName: FBTFT driver                       ***** *****
-              for the RA8875 LCD Controller     *     *      ************
-                                               *   **   **   *           *
-  Copyright Â© by Pf@nne & NOTRO                *   *   *   *   *   ****           *
-                                               *   *       *   *   *   *   *
-  Last modification by:                        *   *       *   *   ****    *
-  - Pf@nne (pf@nne-mail.de)                     *   *     *****           *
-                                                *   *        *   *******
-                                                 *****      *   *
-  Date    : 10.06.2014                                      *   *
-  Version : V1.13                                          *****
-  Revision : 5
-
-*******************************************************************************
+/*
+ * FBTFT driver for the RA8875 LCD Controller
+ * Copyright by Pf@nne & NOTRO
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -197,18 +181,15 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Set_Active_Window */
        write_reg(par, 0x30, xs & 0x00FF);
        write_reg(par, 0x31, (xs & 0xFF00) >> 8);
        write_reg(par, 0x32, ys & 0x00FF);
        write_reg(par, 0x33, (ys & 0xFF00) >> 8);
-       write_reg(par, 0x34, (xs+xe) & 0x00FF);
-       write_reg(par, 0x35, ((xs+xe) & 0xFF00) >> 8);
-       write_reg(par, 0x36, (ys+ye) & 0x00FF);
-       write_reg(par, 0x37, ((ys+ye) & 0xFF00) >> 8);
+       write_reg(par, 0x34, (xs + xe) & 0x00FF);
+       write_reg(par, 0x35, ((xs + xe) & 0xFF00) >> 8);
+       write_reg(par, 0x36, (ys + ye) & 0x00FF);
+       write_reg(par, 0x37, ((ys + ye) & 0xFF00) >> 8);
 
        /* Set_Memory_Write_Cursor */
        write_reg(par, 0x46,  xs & 0xff);
@@ -223,7 +204,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 {
        va_list args;
        int i, ret;
-       u8 *buf = (u8 *)par->buf;
+       u8 *buf = par->buf;
 
        /* slow down spi-speed for writing registers */
        par->fbtftops.write = write_spi;
@@ -288,7 +269,7 @@ static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
                __func__, offset, len);
 
        remain = len / 2;
-       vmem16 = (u16 *)(par->info->screen_base + offset);
+       vmem16 = (u16 *)(par->info->screen_buffer + offset);
        tx_array_size = par->txbuf.len / 2;
                txbuf16 = (u16 *)(par->txbuf.buf + 1);
                tx_array_size -= 2;
@@ -324,6 +305,7 @@ static struct fbtft_display display = {
                .write = write_spi,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "raio,ra8875", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index f3302525ec0092992e2dc872de7cd143890f0f74..da85057eb3e0bc77927939a17079d95cc53c296e 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -102,9 +98,6 @@ static int default_init_sequence[] = {
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address */
        write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
 
@@ -115,13 +108,11 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
        write_reg(par, 0x2C);
 }
 
-#define MY (1 << 7)
-#define MX (1 << 6)
-#define MV (1 << 5)
+#define MY BIT(7)
+#define MX BIT(6)
+#define MV BIT(5)
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* MADCTL - Memory data access control
             RGB/BGR:
                1. Mode selection pin SRGB
@@ -156,6 +147,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "samsung,s6d02a1", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 2e1b72ad54aa95e408136002442ac3584052df1a..d6ae76b318adf14053da11e3347da79b02ca0b1e 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -40,8 +36,6 @@
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        if (par->gpio.cs != -1)
@@ -86,8 +80,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
        switch (par->info->var.rotate) {
        /* R20h = Horizontal GRAM Start Address */
        /* R21h = Vertical GRAM Start Address */
@@ -113,8 +105,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        /* AM: GRAM update direction */
        case 0:
@@ -139,7 +129,7 @@ static int set_var(struct fbtft_par *par)
     PKP0 PKP1 PKP2 PKP3 PKP4 PKP5 PKP6 PKP7 PKP8 PKP9 PKP10 PKP11 VRP0 VRP1
     PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 PKN6 PKN7 PRN8 PRN9 PRN10 PRN11 VRN0 VRN1
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long mask[] = {
@@ -149,12 +139,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        };
        int i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        for (i = 0; i < 2; i++)
                for (j = 0; j < 14; j++)
-                       CURVE(i, j) &= mask[i*par->gamma.num_values + j];
+                       CURVE(i, j) &= mask[i * par->gamma.num_values + j];
 
        write_reg(par, 0x0030, CURVE(0, 1) << 8 | CURVE(0, 0));
        write_reg(par, 0x0031, CURVE(0, 3) << 8 | CURVE(0, 2));
@@ -177,7 +165,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 16,
        .width = WIDTH,
@@ -194,6 +181,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "samsung,s6d1121", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 17a77e0614987d5ad021dbedab11dce48d6e258b..1162c08613fadef8a4732117d2f91d38ababce8f 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -37,11 +33,8 @@ static unsigned reg11 = 0x6040;
 module_param(reg11, uint, 0);
 MODULE_PARM_DESC(reg11, "Register 11h value");
 
-
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        if (par->gpio.cs != -1)
@@ -84,9 +77,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        switch (par->info->var.rotate) {
        /* R4Eh - Set GDDRAM X address counter */
        /* R4Fh - Set GDDRAM Y address counter */
@@ -114,8 +104,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        if (par->fbtftops.init_display != init_display) {
                /* don't risk messing up register 11h */
                fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
@@ -147,7 +135,7 @@ static int set_var(struct fbtft_par *par)
     VRP0 VRP1 PRP0 PRP1 PKP0 PKP1 PKP2 PKP3 PKP4 PKP5
     VRN0 VRN1 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 PKN5
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long mask[] = {
@@ -156,12 +144,10 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        };
        int i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        for (i = 0; i < 2; i++)
                for (j = 0; j < 10; j++)
-                       CURVE(i, j) &= mask[i*par->gamma.num_values + j];
+                       CURVE(i, j) &= mask[i * par->gamma.num_values + j];
 
        write_reg(par, 0x0030, CURVE(0, 5) << 8 | CURVE(0, 4));
        write_reg(par, 0x0031, CURVE(0, 7) << 8 | CURVE(0, 6));
@@ -178,7 +164,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 16,
        .width = WIDTH,
@@ -193,6 +178,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1289", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 15ee44dd130bddfd282849631964b2cf23ea2d3c..e0b34a42c9c635bd243737291dc8bf02ef831861 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -30,7 +26,6 @@
 #define WIDTH          128
 #define HEIGHT         64
 
-
 /*
   write_reg() caveat:
 
@@ -45,8 +40,6 @@
 /* Init sequence taken from the Adafruit SSD1306 Arduino library */
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        if (par->gamma.curves[0] == 0) {
@@ -132,9 +125,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Set Lower Column Start Address for Page Addressing Mode */
        write_reg(par, 0x00 | 0x0);
        /* Set Higher Column Start Address for Page Addressing Mode */
@@ -158,8 +148,6 @@ static int blank(struct fbtft_par *par, bool on)
 /* Gamma is used to control Contrast */
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        curves[0] &= 0xFF;
 
@@ -172,18 +160,18 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 
 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 {
-       u16 *vmem16 = (u16 *)par->info->screen_base;
+       u16 *vmem16 = (u16 *)par->info->screen_buffer;
        u8 *buf = par->txbuf.buf;
        int x, y, i;
        int ret = 0;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
        for (x = 0; x < par->info->var.xres; x++) {
                for (y = 0; y < par->info->var.yres/8; y++) {
                        *buf = 0x00;
                        for (i = 0; i < 8; i++)
-                               *buf |= (vmem16[(y*8+i)*par->info->var.xres+x] ? 1 : 0) << i;
+                               *buf |= (vmem16[(y * 8 + i) *
+                                               par->info->var.xres + x] ?
+                                        1 : 0) << i;
                        buf++;
                }
        }
@@ -191,7 +179,8 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
        /* Write data */
        gpio_set_value(par->gpio.dc, 1);
        ret = par->fbtftops.write(par, par->txbuf.buf,
-                               par->info->var.xres*par->info->var.yres/8);
+                                 par->info->var.xres * par->info->var.yres /
+                                 8);
        if (ret < 0)
                dev_err(par->info->device, "write failed and returned: %d\n",
                        ret);
@@ -199,7 +188,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
        return ret;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -216,7 +204,6 @@ static struct fbtft_display display = {
        },
 };
 
-
 FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1306", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 5bb741046c85264104c4160f17d2b2be3d3d31e5..bd294f886c5f4f3b42ec4311b3bddbb3ca4a2586 100644 (file)
@@ -23,8 +23,6 @@
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        write_reg(par, 0xae); /* Display Off */
@@ -54,9 +52,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        write_reg(par, 0x15, xs, xe);
        write_reg(par, 0x75, ys, ye);
 }
@@ -65,7 +60,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 {
        va_list args;
        int i, ret;
-       u8 *buf = (u8 *)par->buf;
+       u8 *buf = par->buf;
 
        if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {
                va_start(args, len);
@@ -126,15 +121,12 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
                        :
                        Setting of GS63 has to be > Setting of GS62 +1
 
-
 */
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
        int i, acc = 0;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        for (i = 0; i < 63; i++) {
                if (i > 0 && curves[i] < 2) {
                        dev_err(par->info->device,
@@ -176,7 +168,6 @@ static int blank(struct fbtft_par *par, bool on)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
index 9bcd7a0aeed4b035caac6d00a0e2dc195fc4c834..cef33e439f469c538f8ec2f9acd39ca3f7918637 100644 (file)
@@ -25,8 +25,6 @@ static void register_onboard_backlight(struct fbtft_par *par);
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        if (par->pdata
                && par->pdata->display.backlight == FBTFT_ONBOARD_BACKLIGHT) {
                /* module uses onboard GPIO for panel power */
@@ -61,9 +59,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        write_reg(par, 0x15, xs, xe);
        write_reg(par, 0x75, ys, ye);
        write_reg(par, 0x5c);
@@ -73,8 +68,6 @@ static int set_var(struct fbtft_par *par)
 {
        unsigned remap;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        if (par->fbtftops.init_display != init_display) {
                /* don't risk messing up register A0h */
                fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
@@ -104,34 +97,31 @@ static int set_var(struct fbtft_par *par)
 }
 
 /*
-       Grayscale Lookup Table
-       GS1 - GS63
-       The driver Gamma curve contains the relative values between the entries
-       in the Lookup table.
-
-       From datasheet:
-       8.8 Gray Scale Decoder
-
-               there are total 180 Gamma Settings (Setting 0 to Setting 180)
-               available for the Gray Scale table.
-
-               The gray scale is defined in incremental way, with reference
-               to the length of previous table entry:
-                       Setting of GS1 has to be >= 0
-                       Setting of GS2 has to be > Setting of GS1 +1
-                       Setting of GS3 has to be > Setting of GS2 +1
-                       :
-                       Setting of GS63 has to be > Setting of GS62 +1
-
-
-*/
+ * Grayscale Lookup Table
+ * GS1 - GS63
+ * The driver Gamma curve contains the relative values between the entries
+ * in the Lookup table.
+ *
+ * From datasheet:
+ * 8.8 Gray Scale Decoder
+ *
+ *     there are total 180 Gamma Settings (Setting 0 to Setting 180)
+ *     available for the Gray Scale table.
+ *
+ *     The gray scale is defined in incremental way, with reference
+ *     to the length of previous table entry:
+ *             Setting of GS1 has to be >= 0
+ *             Setting of GS2 has to be > Setting of GS1 +1
+ *             Setting of GS3 has to be > Setting of GS2 +1
+ *             :
+ *             Setting of GS63 has to be > Setting of GS62 +1
+ *
+ */
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
        int i, acc = 0;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        for (i = 0; i < 63; i++) {
                if (i > 0 && curves[i] < 2) {
                        dev_err(par->info->device,
@@ -173,7 +163,6 @@ static int blank(struct fbtft_par *par, bool on)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -208,25 +197,20 @@ static int update_onboard_backlight(struct backlight_device *bd)
        return 0;
 }
 
+static const struct backlight_ops bl_ops = {
+       .update_status = update_onboard_backlight,
+};
+
 static void register_onboard_backlight(struct fbtft_par *par)
 {
        struct backlight_device *bd;
        struct backlight_properties bl_props = { 0, };
-       struct backlight_ops *bl_ops;
 
-       fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
-
-       bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
-                               GFP_KERNEL);
-       if (!bl_ops)
-               return;
-
-       bl_ops->update_status = update_onboard_backlight;
        bl_props.type = BACKLIGHT_RAW;
        bl_props.power = FB_BLANK_POWERDOWN;
 
        bd = backlight_device_register(dev_driver_string(par->info->device),
-                               par->info->device, par, bl_ops, &bl_props);
+                               par->info->device, par, &bl_ops, &bl_props);
        if (IS_ERR(bd)) {
                dev_err(par->info->device,
                        "cannot register backlight device (%ld)\n",
@@ -242,7 +226,6 @@ static void register_onboard_backlight(struct fbtft_par *par)
 static void register_onboard_backlight(struct fbtft_par *par) { };
 #endif
 
-
 FBTFT_REGISTER_DRIVER(DRVNAME, "solomon,ssd1351", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index f65224318610244dda43f83e63c49afbc3f7d779..a92b0d071097f9d75bfb9b3f8c2483d86b90a247 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -28,7 +24,6 @@
 #define DEFAULT_GAMMA   "0F 1A 0F 18 2F 28 20 22 1F 1B 23 37 00 07 02 10\n" \
                        "0F 1B 0F 17 33 2C 29 2E 30 30 39 3F 00 07 03 10"
 
-
 static int default_init_sequence[] = {
        /* SWRESET - Software reset */
        -1, 0x01,
@@ -96,9 +91,6 @@ static int default_init_sequence[] = {
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address */
        write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
 
@@ -109,13 +101,11 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
        write_reg(par, 0x2C);
 }
 
-#define MY (1 << 7)
-#define MX (1 << 6)
-#define MV (1 << 5)
+#define MY BIT(7)
+#define MX BIT(6)
+#define MV BIT(5)
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* MADCTL - Memory data access control
             RGB/BGR:
             1. Mode selection pin SRGB
@@ -145,13 +135,11 @@ static int set_var(struct fbtft_par *par)
     VRF0P VOS0P PK0P PK1P PK2P PK3P PK4P PK5P PK6P PK7P PK8P PK9P SELV0P SELV1P SELV62P SELV63P
     VRF0N VOS0N PK0N PK1N PK2N PK3N PK4N PK5N PK6N PK7N PK8N PK9N SELV0N SELV1N SELV62N SELV63N
 */
-#define CURVE(num, idx)  curves[num*par->gamma.num_values + idx]
+#define CURVE(num, idx)  curves[num * par->gamma.num_values + idx]
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
        int i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        for (i = 0; i < par->gamma.num_curves; i++)
                for (j = 0; j < par->gamma.num_values; j++)
@@ -168,7 +156,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 }
 #undef CURVE
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = 128,
@@ -183,6 +170,7 @@ static struct fbtft_display display = {
                .set_gamma = set_gamma,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7735r", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
diff --git a/drivers/staging/fbtft/fb_st7789v.c b/drivers/staging/fbtft/fb_st7789v.c
new file mode 100644 (file)
index 0000000..085e987
--- /dev/null
@@ -0,0 +1,265 @@
+/*
+ * FB driver for the ST7789V LCD Controller
+ *
+ * Copyright (C) 2015 Dennis Menschel
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <video/mipi_display.h>
+
+#include "fbtft.h"
+
+#define DRVNAME "fb_st7789v"
+
+#define DEFAULT_GAMMA \
+       "70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25\n" \
+       "70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25"
+
+/**
+ * enum st7789v_command - ST7789V display controller commands
+ *
+ * @PORCTRL: porch setting
+ * @GCTRL: gate control
+ * @VCOMS: VCOM setting
+ * @VDVVRHEN: VDV and VRH command enable
+ * @VRHS: VRH set
+ * @VDVS: VDV set
+ * @VCMOFSET: VCOM offset set
+ * @PWCTRL1: power control 1
+ * @PVGAMCTRL: positive voltage gamma control
+ * @NVGAMCTRL: negative voltage gamma control
+ *
+ * The command names are the same as those found in the datasheet to ease
+ * looking up their semantics and usage.
+ *
+ * Note that the ST7789V display controller offers quite a few more commands
+ * which have been omitted from this list as they are not used at the moment.
+ * Furthermore, commands that are compliant with the MIPI DCS have been left
+ * out as well to avoid duplicate entries.
+ */
+enum st7789v_command {
+       PORCTRL = 0xB2,
+       GCTRL = 0xB7,
+       VCOMS = 0xBB,
+       VDVVRHEN = 0xC2,
+       VRHS = 0xC3,
+       VDVS = 0xC4,
+       VCMOFSET = 0xC5,
+       PWCTRL1 = 0xD0,
+       PVGAMCTRL = 0xE0,
+       NVGAMCTRL = 0xE1,
+};
+
+#define MADCTL_BGR BIT(3) /* bitmask for RGB/BGR order */
+#define MADCTL_MV BIT(5) /* bitmask for page/column order */
+#define MADCTL_MX BIT(6) /* bitmask for column address order */
+#define MADCTL_MY BIT(7) /* bitmask for page address order */
+
+/**
+ * init_display() - initialize the display controller
+ *
+ * @par: FBTFT parameter object
+ *
+ * Most of the commands in this init function set their parameters to the
+ * same default values which are already in place after the display has been
+ * powered up. (The main exception to this rule is the pixel format which
+ * would default to 18 instead of 16 bit per pixel.)
+ * Nonetheless, this sequence can be used as a template for concrete
+ * displays which usually need some adjustments.
+ *
+ * Return: 0 on success, < 0 if error occurred.
+ */
+static int init_display(struct fbtft_par *par)
+{
+       /* turn off sleep mode */
+       write_reg(par, MIPI_DCS_EXIT_SLEEP_MODE);
+       mdelay(120);
+
+       /* set pixel format to RGB-565 */
+       write_reg(par, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT);
+
+       write_reg(par, PORCTRL, 0x08, 0x08, 0x00, 0x22, 0x22);
+
+       /*
+        * VGH = 13.26V
+        * VGL = -10.43V
+        */
+       write_reg(par, GCTRL, 0x35);
+
+       /*
+        * VDV and VRH register values come from command write
+        * (instead of NVM)
+        */
+       write_reg(par, VDVVRHEN, 0x01, 0xFF);
+
+       /*
+        * VAP =  4.1V + (VCOM + VCOM offset + 0.5 * VDV)
+        * VAN = -4.1V + (VCOM + VCOM offset + 0.5 * VDV)
+        */
+       write_reg(par, VRHS, 0x0B);
+
+       /* VDV = 0V */
+       write_reg(par, VDVS, 0x20);
+
+       /* VCOM = 0.9V */
+       write_reg(par, VCOMS, 0x20);
+
+       /* VCOM offset = 0V */
+       write_reg(par, VCMOFSET, 0x20);
+
+       /*
+        * AVDD = 6.8V
+        * AVCL = -4.8V
+        * VDS = 2.3V
+        */
+       write_reg(par, PWCTRL1, 0xA4, 0xA1);
+
+       write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
+       return 0;
+}
+
+/**
+ * set_var() - apply LCD properties like rotation and BGR mode
+ *
+ * @par: FBTFT parameter object
+ *
+ * Return: 0 on success, < 0 if error occurred.
+ */
+static int set_var(struct fbtft_par *par)
+{
+       u8 madctl_par = 0;
+
+       if (par->bgr)
+               madctl_par |= MADCTL_BGR;
+       switch (par->info->var.rotate) {
+       case 0:
+               break;
+       case 90:
+               madctl_par |= (MADCTL_MV | MADCTL_MY);
+               break;
+       case 180:
+               madctl_par |= (MADCTL_MX | MADCTL_MY);
+               break;
+       case 270:
+               madctl_par |= (MADCTL_MV | MADCTL_MX);
+               break;
+       default:
+               return -EINVAL;
+       }
+       write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, madctl_par);
+       return 0;
+}
+
+/**
+ * set_gamma() - set gamma curves
+ *
+ * @par: FBTFT parameter object
+ * @curves: gamma curves
+ *
+ * Before the gamma curves are applied, they are preprocessed with a bitmask
+ * to ensure syntactically correct input for the display controller.
+ * This implies that the curves input parameter might be changed by this
+ * function and that illegal gamma values are auto-corrected and not
+ * reported as errors.
+ *
+ * Return: 0 on success, < 0 if error occurred.
+ */
+static int set_gamma(struct fbtft_par *par, unsigned long *curves)
+{
+       int i;
+       int j;
+       int c; /* curve index offset */
+
+       /*
+        * Bitmasks for gamma curve command parameters.
+        * The masks are the same for both positive and negative voltage
+        * gamma curves.
+        */
+       const u8 gamma_par_mask[] = {
+               0xFF, /* V63[3:0], V0[3:0]*/
+               0x3F, /* V1[5:0] */
+               0x3F, /* V2[5:0] */
+               0x1F, /* V4[4:0] */
+               0x1F, /* V6[4:0] */
+               0x3F, /* J0[1:0], V13[3:0] */
+               0x7F, /* V20[6:0] */
+               0x77, /* V36[2:0], V27[2:0] */
+               0x7F, /* V43[6:0] */
+               0x3F, /* J1[1:0], V50[3:0] */
+               0x1F, /* V57[4:0] */
+               0x1F, /* V59[4:0] */
+               0x3F, /* V61[5:0] */
+               0x3F, /* V62[5:0] */
+       };
+
+       for (i = 0; i < par->gamma.num_curves; i++) {
+               c = i * par->gamma.num_values;
+               for (j = 0; j < par->gamma.num_values; j++)
+                       curves[c + j] &= gamma_par_mask[j];
+               write_reg(
+                       par, PVGAMCTRL + i,
+                       curves[c + 0], curves[c + 1], curves[c + 2],
+                       curves[c + 3], curves[c + 4], curves[c + 5],
+                       curves[c + 6], curves[c + 7], curves[c + 8],
+                       curves[c + 9], curves[c + 10], curves[c + 11],
+                       curves[c + 12], curves[c + 13]);
+       }
+       return 0;
+}
+
+/**
+ * blank() - blank the display
+ *
+ * @par: FBTFT parameter object
+ * @on: whether to enable or disable blanking the display
+ *
+ * Return: 0 on success, < 0 if error occurred.
+ */
+static int blank(struct fbtft_par *par, bool on)
+{
+       if (on)
+               write_reg(par, MIPI_DCS_SET_DISPLAY_OFF);
+       else
+               write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
+       return 0;
+}
+
+static struct fbtft_display display = {
+       .regwidth = 8,
+       .width = 240,
+       .height = 320,
+       .gamma_num = 2,
+       .gamma_len = 14,
+       .gamma = DEFAULT_GAMMA,
+       .fbtftops = {
+               .init_display = init_display,
+               .set_var = set_var,
+               .set_gamma = set_gamma,
+               .blank = blank,
+       },
+};
+
+FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);
+
+MODULE_ALIAS("spi:" DRVNAME);
+MODULE_ALIAS("platform:" DRVNAME);
+MODULE_ALIAS("spi:st7789v");
+MODULE_ALIAS("platform:st7789v");
+
+MODULE_DESCRIPTION("FB driver for the ST7789V LCD Controller");
+MODULE_AUTHOR("Dennis Menschel");
+MODULE_LICENSE("GPL");
index 4c740b7e9f53481c19ff2973259b833a50ac50dc..caf263db436afa69f5f7dff9685f808468846b03 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
 #define WIDTH          320
 #define HEIGHT         480
 
-
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        write_reg(par, 0xB0, 0x80);
@@ -64,9 +57,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address */
        write_reg(par, 0x2A, xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
 
@@ -79,8 +69,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        case 270:
                write_reg(par, 0xB6, 0x00, 0x02, 0x3B);
@@ -103,7 +91,6 @@ static int set_var(struct fbtft_par *par)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -114,6 +101,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "neosec,tinylcd", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 3253a25e9184df1cc85154de3c5d66e4cc2511b2..2183f98c831514c9eef828c3ef8bbceabb47fd7a 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -45,8 +41,6 @@ MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        /* Enter extended command mode */
@@ -86,10 +80,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-                     "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
-                     __func__, xs, ys, xe, ye);
-
        /* H=0 Set X address of RAM */
        write_reg(par, 0x80); /* 7:1  1
                                 6-0: X[6:0] - 0x00
@@ -104,13 +94,11 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 {
-       u16 *vmem16 = (u16 *)par->info->screen_base;
+       u16 *vmem16 = (u16 *)par->info->screen_buffer;
        int x, y, i;
        int ret = 0;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
-       for (y = 0; y < HEIGHT/8; y++) {
+       for (y = 0; y < HEIGHT / 8; y++) {
                u8 *buf = par->txbuf.buf;
                /* The display is 102x68 but the LCD is 84x48.  Set
                   the write pointer at the start of each row. */
@@ -121,9 +109,9 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
                for (x = 0; x < WIDTH; x++) {
                        u8 ch = 0;
 
-                       for (i = 0; i < 8*WIDTH; i += WIDTH) {
+                       for (i = 0; i < 8 * WIDTH; i += WIDTH) {
                                ch >>= 1;
-                               if (vmem16[(y*8*WIDTH)+i+x])
+                               if (vmem16[(y * 8 * WIDTH) + i + x])
                                        ch |= 0x80;
                        }
                        *buf++ = ch;
@@ -143,8 +131,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 
 static int set_gamma(struct fbtft_par *par, unsigned long *curves)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* apply mask */
        curves[0] &= 0x7F;
 
@@ -155,7 +141,6 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
        return 0;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -172,6 +157,7 @@ static struct fbtft_display display = {
        },
        .backlight = 1,
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "teralane,tls8204", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 5cafa50d1facee4292916852274f3bfa8aff8281..4e828142058ef6c5e8ae2a714f7aad8c9f41a703 100644 (file)
@@ -72,8 +72,6 @@ static int init_display(struct fbtft_par *par)
 {
        int ret;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* Set CS active high */
        par->spi->mode |= SPI_CS_HIGH;
        ret = spi_setup(par->spi);
@@ -115,10 +113,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-                     "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
-                     __func__, xs, ys, xe, ye);
-
        switch (par->info->var.rotate) {
        case 90:
        case 270:
@@ -156,8 +150,6 @@ static int blank(struct fbtft_par *par, bool on)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* par->info->fix.visual = FB_VISUAL_PSEUDOCOLOR; */
        par->info->var.grayscale = 1;
        par->info->var.red.offset    = 0;
@@ -229,7 +221,7 @@ static int set_var(struct fbtft_par *par)
 
 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 {
-       u8 *vmem8 = (u8 *)(par->info->screen_base);
+       u8 *vmem8 = (u8 *)(par->info->screen_buffer);
        u8 *buf8 = (u8 *)(par->txbuf.buf);
        u16 *buf16 = (u16 *)(par->txbuf.buf);
        int line_length = par->info->fix.line_length;
@@ -238,8 +230,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
        int x, y, i;
        int ret = 0;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
        switch (par->pdata->display.buswidth) {
        case 8:
                switch (par->info->var.rotate) {
index 26d669b57916c659c09c88f8cd1ac6fc0381f02c..212908e3927727badbe5359d8996ce63dcd0f5be 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -33,7 +29,7 @@
 #define DRVNAME        "fb_uc1701"
 #define WIDTH    102
 #define HEIGHT  64
-#define PAGES    (HEIGHT/8)
+#define PAGES    (HEIGHT / 8)
 
 /* 1: Display on/off */
 #define LCD_DISPLAY_ENABLE    0xAE
 /* column offset for bottom view orientation */
 #define SHIFT_ADDR_TOPVIEW    30
 
-
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        /* softreset of LCD */
@@ -121,7 +114,7 @@ static int init_display(struct fbtft_par *par)
 
        /* advanced program control */
        write_reg(par, LCD_ADV_PROG_CTRL);
-       write_reg(par, LCD_ADV_PROG_CTRL2|LCD_TEMPCOMP_HIGH);
+       write_reg(par, LCD_ADV_PROG_CTRL2 | LCD_TEMPCOMP_HIGH);
 
        /* enable display */
        write_reg(par, LCD_DISPLAY_ENABLE | 1);
@@ -131,8 +124,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* goto address */
        /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
         (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
@@ -150,25 +141,25 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 {
-       u16 *vmem16 = (u16 *)par->info->screen_base;
+       u16 *vmem16 = (u16 *)par->info->screen_buffer;
        u8 *buf = par->txbuf.buf;
        int x, y, i;
        int ret = 0;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
        for (y = 0; y < PAGES; y++) {
                buf = par->txbuf.buf;
                for (x = 0; x < WIDTH; x++) {
                        *buf = 0x00;
                        for (i = 0; i < 8; i++)
-                               *buf |= (vmem16[((y*8*WIDTH)+(i*WIDTH))+x] ? 1 : 0) << i;
+                               *buf |= (vmem16[((y * 8 * WIDTH) +
+                                                (i * WIDTH)) + x] ?
+                                        1 : 0) << i;
                        buf++;
                }
                /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
                 (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
                  LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
-               write_reg(par, LCD_PAGE_ADDRESS|(u8)y);
+               write_reg(par, LCD_PAGE_ADDRESS | (u8)y);
                /* LCD_PAGE_ADDRESS | ((page) & 0x1F),
                 (((col)+SHIFT_ADDR_NORMAL) & 0x0F),
                  LCD_COL_ADDRESS | ((((col)+SHIFT_ADDR_NORMAL)>>4) & 0x0F) */
@@ -189,7 +180,6 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
        return ret;
 }
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .width = WIDTH,
@@ -201,6 +191,7 @@ static struct fbtft_display display = {
        },
        .backlight = 1,
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "UltraChip,uc1701", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 176c2106d7245e2e37804393a2d35e3a981c4270..970b8430eccf7d00327793674f7cbce19b70e209 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -37,8 +33,6 @@
 
 static int init_display(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        par->fbtftops.reset(par);
 
        if (par->gpio.cs != -1)
@@ -131,8 +125,6 @@ static int init_display(struct fbtft_par *par)
 
 static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
        switch (par->info->var.rotate) {
        /* R20h = Horizontal GRAM Start Address */
        /* R21h = Vertical GRAM Start Address */
@@ -159,8 +151,6 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
 
 static int set_var(struct fbtft_par *par)
 {
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        switch (par->info->var.rotate) {
        /* AM: GRAM update direction */
        case 0:
@@ -194,6 +184,7 @@ static struct fbtft_display display = {
                .set_var = set_var,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "nec,upd161704", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 8eae6ef25846bfb1c6fe17365af757286e85faf3..f8cb610a7b6984cb3bc977cf52f63966f6748620 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -43,7 +39,6 @@
 #define COLOR_RGB233           10
 #define COLOR_RGB565           16
 
-
 static short mode = 565;
 module_param(mode, short, 0);
 MODULE_PARM_DESC(mode, "RGB color transfer mode: 332, 565 (default)");
@@ -73,14 +68,12 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
 static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 {
        unsigned start_line, end_line;
-       u16 *vmem16 = (u16 *)(par->info->screen_base + offset);
+       u16 *vmem16 = (u16 *)(par->info->screen_buffer + offset);
        u16 *pos = par->txbuf.buf + 1;
        u16 *buf16 = par->txbuf.buf + 10;
        int i, j;
        int ret = 0;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
        start_line = offset / par->info->fix.line_length;
        end_line = start_line + (len / par->info->fix.line_length) - 1;
 
@@ -112,14 +105,12 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
 static int write_vmem_8bit(struct fbtft_par *par, size_t offset, size_t len)
 {
        unsigned start_line, end_line;
-       u16 *vmem16 = (u16 *)(par->info->screen_base + offset);
+       u16 *vmem16 = (u16 *)(par->info->screen_buffer + offset);
        u16 *pos = par->txbuf.buf + 1;
        u8 *buf8 = par->txbuf.buf + 10;
        int i, j;
        int ret = 0;
 
-       fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s()\n", __func__);
-
        start_line = offset / par->info->fix.line_length;
        end_line = start_line + (len / par->info->fix.line_length) - 1;
 
@@ -164,8 +155,6 @@ static int init_display(struct fbtft_par *par)
        unsigned version;
        u8 save_mode;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* enable SPI interface by having CS and MOSI low during reset */
        save_mode = par->spi->mode;
        par->spi->mode |= SPI_CS_HIGH;
@@ -205,8 +194,6 @@ static int set_var(struct fbtft_par *par)
 {
        u8 rotate;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* this controller rotates clock wise */
        switch (par->info->var.rotate) {
        case 90:
@@ -257,31 +244,22 @@ static int backlight_chip_update_status(struct backlight_device *bd)
        return 0;
 }
 
+static const struct backlight_ops bl_ops = {
+       .update_status = backlight_chip_update_status,
+};
+
 static void register_chip_backlight(struct fbtft_par *par)
 {
        struct backlight_device *bd;
        struct backlight_properties bl_props = { 0, };
-       struct backlight_ops *bl_ops;
 
-       fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
-
-       bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
-                               GFP_KERNEL);
-       if (!bl_ops) {
-               dev_err(par->info->device,
-                       "%s: could not allocate memory for backlight operations.\n",
-                       __func__);
-               return;
-       }
-
-       bl_ops->update_status = backlight_chip_update_status;
        bl_props.type = BACKLIGHT_RAW;
        bl_props.power = FB_BLANK_POWERDOWN;
        bl_props.max_brightness = 100;
        bl_props.brightness = DEFAULT_BRIGHTNESS;
 
        bd = backlight_device_register(dev_driver_string(par->info->device),
-                               par->info->device, par, bl_ops, &bl_props);
+                               par->info->device, par, &bl_ops, &bl_props);
        if (IS_ERR(bd)) {
                dev_err(par->info->device,
                        "cannot register backlight device (%ld)\n",
@@ -297,7 +275,6 @@ static void register_chip_backlight(struct fbtft_par *par)
 #define register_chip_backlight NULL
 #endif
 
-
 static struct fbtft_display display = {
        .regwidth = 8,
        .buswidth = 8,
@@ -315,6 +292,7 @@ static struct fbtft_display display = {
                .register_backlight = register_chip_backlight,
        },
 };
+
 FBTFT_REGISTER_DRIVER(DRVNAME, "watterott,openlcd", &display);
 
 MODULE_ALIAS("spi:" DRVNAME);
index 912c6328fb872b2b44e403099f1dc16ece47c988..58449ad84f46c17f842cc32e04ee5c18cf2b58c0 100644 (file)
@@ -4,9 +4,6 @@
 #include <linux/spi/spi.h>
 #include "fbtft.h"
 
-
-
-
 /*****************************************************************************
  *
  *   void (*write_reg)(struct fbtft_par *par, int len, ...);
@@ -41,7 +38,7 @@ void func(struct fbtft_par *par, int len, ...)                                \
        *buf = modifier((type)va_arg(args, unsigned int));                    \
        if (par->gpio.dc != -1)                                               \
                gpio_set_value(par->gpio.dc, 0);                              \
-       ret = par->fbtftops.write(par, par->buf, sizeof(type)+offset);        \
+       ret = par->fbtftops.write(par, par->buf, sizeof(type) + offset);      \
        if (ret < 0) {                                                        \
                va_end(args);                                                 \
                dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
@@ -59,7 +56,8 @@ void func(struct fbtft_par *par, int len, ...)                                \
                }                                                             \
                if (par->gpio.dc != -1)                                       \
                        gpio_set_value(par->gpio.dc, 1);                      \
-               ret = par->fbtftops.write(par, par->buf, len * (sizeof(type)+offset)); \
+               ret = par->fbtftops.write(par, par->buf,                      \
+                                         len * (sizeof(type) + offset));     \
                if (ret < 0) {                                                \
                        va_end(args);                                         \
                        dev_err(par->info->device, "%s: write() failed and returned %d\n", __func__, ret); \
@@ -117,9 +115,6 @@ void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...)
 }
 EXPORT_SYMBOL(fbtft_write_reg8_bus9);
 
-
-
-
 /*****************************************************************************
  *
  *   int (*write_vmem)(struct fbtft_par *par);
@@ -142,7 +137,7 @@ int fbtft_write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
                __func__, offset, len);
 
        remain = len / 2;
-       vmem16 = (u16 *)(par->info->screen_base + offset);
+       vmem16 = (u16 *)(par->info->screen_buffer + offset);
 
        if (par->gpio.dc != -1)
                gpio_set_value(par->gpio.dc, 1);
@@ -184,7 +179,7 @@ EXPORT_SYMBOL(fbtft_write_vmem16_bus8);
 /* 16 bit pixel over 9-bit SPI bus: dc + high byte, dc + low byte */
 int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
 {
-       u8 __iomem *vmem8;
+       u8 *vmem8;
        u16 *txbuf16 = par->txbuf.buf;
        size_t remain;
        size_t to_copy;
@@ -201,7 +196,7 @@ int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
        }
 
        remain = len;
-       vmem8 = par->info->screen_base + offset;
+       vmem8 = par->info->screen_buffer + offset;
 
        tx_array_size = par->txbuf.len / 2;
 
@@ -212,15 +207,15 @@ int fbtft_write_vmem16_bus9(struct fbtft_par *par, size_t offset, size_t len)
 
 #ifdef __LITTLE_ENDIAN
                for (i = 0; i < to_copy; i += 2) {
-                       txbuf16[i]     = 0x0100 | ioread8(vmem8 + i + 1);
-                       txbuf16[i + 1] = 0x0100 | ioread8(vmem8 + i);
+                       txbuf16[i]     = 0x0100 | vmem8[i + 1];
+                       txbuf16[i + 1] = 0x0100 | vmem8[i];
                }
 #else
                for (i = 0; i < to_copy; i++)
-                       txbuf16[i]   = 0x0100 | ioread8(vmem8 + i);
+                       txbuf16[i]   = 0x0100 | vmem8[i];
 #endif
                vmem8 = vmem8 + to_copy;
-               ret = par->fbtftops.write(par, par->txbuf.buf, to_copy*2);
+               ret = par->fbtftops.write(par, par->txbuf.buf, to_copy * 2);
                if (ret < 0)
                        return ret;
                remain -= to_copy;
@@ -245,7 +240,7 @@ int fbtft_write_vmem16_bus16(struct fbtft_par *par, size_t offset, size_t len)
        fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
                __func__, offset, len);
 
-       vmem16 = (u16 *)(par->info->screen_base + offset);
+       vmem16 = (u16 *)(par->info->screen_buffer + offset);
 
        if (par->gpio.dc != -1)
                gpio_set_value(par->gpio.dc, 1);
index 7f5fa3d1cab049fecfeca3bc221536a6c218524b..b1e45161eefcf45cf04e65c1bdab3d2aa52dcf0c 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -53,7 +49,6 @@ module_param(dma, bool, 0);
 MODULE_PARM_DESC(dma, "Use DMA buffer");
 #endif
 
-
 void fbtft_dbg_hex(const struct device *dev, int groupsize,
                        void *buf, size_t len, const char *fmt, ...)
 {
@@ -127,33 +122,34 @@ static int fbtft_request_gpios(struct fbtft_par *par)
        unsigned long flags;
        int ret;
 
-       if (pdata && pdata->gpios) {
-               gpio = pdata->gpios;
-               while (gpio->name[0]) {
-                       flags = FBTFT_GPIO_NO_MATCH;
-                       /* if driver provides match function, try it first,
-                          if no match use our own */
-                       if (par->fbtftops.request_gpios_match)
-                               flags = par->fbtftops.request_gpios_match(par, gpio);
-                       if (flags == FBTFT_GPIO_NO_MATCH)
-                               flags = fbtft_request_gpios_match(par, gpio);
-                       if (flags != FBTFT_GPIO_NO_MATCH) {
-                               ret = devm_gpio_request_one(par->info->device,
-                                               gpio->gpio, flags,
-                                               par->info->device->driver->name);
-                               if (ret < 0) {
-                                       dev_err(par->info->device,
-                                               "%s: gpio_request_one('%s'=%d) failed with %d\n",
-                                               __func__, gpio->name,
-                                               gpio->gpio, ret);
-                                       return ret;
-                               }
-                               fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par,
-                                       "%s: '%s' = GPIO%d\n",
-                                       __func__, gpio->name, gpio->gpio);
+       if (!(pdata && pdata->gpios))
+               return 0;
+
+       gpio = pdata->gpios;
+       while (gpio->name[0]) {
+               flags = FBTFT_GPIO_NO_MATCH;
+               /* if driver provides match function, try it first,
+                  if no match use our own */
+               if (par->fbtftops.request_gpios_match)
+                       flags = par->fbtftops.request_gpios_match(par, gpio);
+               if (flags == FBTFT_GPIO_NO_MATCH)
+                       flags = fbtft_request_gpios_match(par, gpio);
+               if (flags != FBTFT_GPIO_NO_MATCH) {
+                       ret = devm_gpio_request_one(par->info->device,
+                                       gpio->gpio, flags,
+                                       par->info->device->driver->name);
+                       if (ret < 0) {
+                               dev_err(par->info->device,
+                                       "%s: gpio_request_one('%s'=%d) failed with %d\n",
+                                       __func__, gpio->name,
+                                       gpio->gpio, ret);
+                               return ret;
                        }
-                       gpio++;
+                       fbtft_par_dbg(DEBUG_REQUEST_GPIOS, par,
+                               "%s: '%s' = GPIO%d\n",
+                               __func__, gpio->name, gpio->gpio);
                }
+               gpio++;
        }
 
        return 0;
@@ -270,26 +266,23 @@ static int fbtft_backlight_get_brightness(struct backlight_device *bd)
 
 void fbtft_unregister_backlight(struct fbtft_par *par)
 {
-       const struct backlight_ops *bl_ops;
-
-       fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
-
        if (par->info->bl_dev) {
                par->info->bl_dev->props.power = FB_BLANK_POWERDOWN;
                backlight_update_status(par->info->bl_dev);
-               bl_ops = par->info->bl_dev->ops;
                backlight_device_unregister(par->info->bl_dev);
                par->info->bl_dev = NULL;
        }
 }
 
+static const struct backlight_ops fbtft_bl_ops = {
+       .get_brightness = fbtft_backlight_get_brightness,
+       .update_status  = fbtft_backlight_update_status,
+};
+
 void fbtft_register_backlight(struct fbtft_par *par)
 {
        struct backlight_device *bd;
        struct backlight_properties bl_props = { 0, };
-       struct backlight_ops *bl_ops;
-
-       fbtft_par_dbg(DEBUG_BACKLIGHT, par, "%s()\n", __func__);
 
        if (par->gpio.led[0] == -1) {
                fbtft_par_dbg(DEBUG_BACKLIGHT, par,
@@ -297,13 +290,6 @@ void fbtft_register_backlight(struct fbtft_par *par)
                return;
        }
 
-       bl_ops = devm_kzalloc(par->info->device, sizeof(struct backlight_ops),
-                               GFP_KERNEL);
-       if (!bl_ops)
-               return;
-
-       bl_ops->get_brightness = fbtft_backlight_get_brightness;
-       bl_ops->update_status = fbtft_backlight_update_status;
        bl_props.type = BACKLIGHT_RAW;
        /* Assume backlight is off, get polarity from current state of pin */
        bl_props.power = FB_BLANK_POWERDOWN;
@@ -311,7 +297,7 @@ void fbtft_register_backlight(struct fbtft_par *par)
                bl_props.state |= BL_CORE_DRIVER1;
 
        bd = backlight_device_register(dev_driver_string(par->info->device),
-                               par->info->device, par, bl_ops, &bl_props);
+                               par->info->device, par, &fbtft_bl_ops, &bl_props);
        if (IS_ERR(bd)) {
                dev_err(par->info->device,
                        "cannot register backlight device (%ld)\n",
@@ -333,9 +319,6 @@ EXPORT_SYMBOL(fbtft_unregister_backlight);
 static void fbtft_set_addr_win(struct fbtft_par *par, int xs, int ys, int xe,
                               int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
-
        /* Column address set */
        write_reg(par, 0x2A,
                (xs >> 8) & 0xFF, xs & 0xFF, (xe >> 8) & 0xFF, xe & 0xFF);
@@ -348,7 +331,6 @@ static void fbtft_set_addr_win(struct fbtft_par *par, int xs, int ys, int xe,
        write_reg(par, 0x2C);
 }
 
-
 static void fbtft_reset(struct fbtft_par *par)
 {
        if (par->gpio.reset == -1)
@@ -360,13 +342,11 @@ static void fbtft_reset(struct fbtft_par *par)
        mdelay(120);
 }
 
-
 static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
                                 unsigned end_line)
 {
        size_t offset, len;
-       struct timespec ts_start, ts_end, ts_fps, ts_duration;
-       long fps_ms, fps_us, duration_ms, duration_us;
+       ktime_t ts_start, ts_end;
        long fps, throughput;
        bool timeit = false;
        int ret = 0;
@@ -374,7 +354,7 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
        if (unlikely(par->debug & (DEBUG_TIME_FIRST_UPDATE | DEBUG_TIME_EACH_UPDATE))) {
                if ((par->debug & DEBUG_TIME_EACH_UPDATE) ||
                                ((par->debug & DEBUG_TIME_FIRST_UPDATE) && !par->first_update_done)) {
-                       getnstimeofday(&ts_start);
+                       ts_start = ktime_get();
                        timeit = true;
                }
        }
@@ -400,7 +380,7 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
 
        if (par->fbtftops.set_addr_win)
                par->fbtftops.set_addr_win(par, 0, start_line,
-                               par->info->var.xres-1, end_line);
+                               par->info->var.xres - 1, end_line);
 
        offset = start_line * par->info->fix.line_length;
        len = (end_line - start_line + 1) * par->info->fix.line_length;
@@ -411,35 +391,25 @@ static void fbtft_update_display(struct fbtft_par *par, unsigned start_line,
                        __func__);
 
        if (unlikely(timeit)) {
-               getnstimeofday(&ts_end);
-               if (par->update_time.tv_nsec == 0 && par->update_time.tv_sec == 0) {
-                       par->update_time.tv_sec = ts_start.tv_sec;
-                       par->update_time.tv_nsec = ts_start.tv_nsec;
-               }
-               ts_fps = timespec_sub(ts_start, par->update_time);
-               par->update_time.tv_sec = ts_start.tv_sec;
-               par->update_time.tv_nsec = ts_start.tv_nsec;
-               fps_ms = (ts_fps.tv_sec * 1000) + ((ts_fps.tv_nsec / 1000000) % 1000);
-               fps_us = (ts_fps.tv_nsec / 1000) % 1000;
-               fps = fps_ms * 1000 + fps_us;
+               ts_end = ktime_get();
+               if (ktime_to_ns(par->update_time))
+                       par->update_time = ts_start;
+
+               par->update_time = ts_start;
+               fps = ktime_us_delta(ts_start, par->update_time);
                fps = fps ? 1000000 / fps : 0;
 
-               ts_duration = timespec_sub(ts_end, ts_start);
-               duration_ms = (ts_duration.tv_sec * 1000) + ((ts_duration.tv_nsec / 1000000) % 1000);
-               duration_us = (ts_duration.tv_nsec / 1000) % 1000;
-               throughput = duration_ms * 1000 + duration_us;
+               throughput = ktime_us_delta(ts_end, ts_start);
                throughput = throughput ? (len * 1000) / throughput : 0;
                throughput = throughput * 1000 / 1024;
 
                dev_info(par->info->device,
-                       "Display update: %ld kB/s (%ld.%.3ld ms), fps=%ld (%ld.%.3ld ms)\n",
-                       throughput, duration_ms, duration_us,
-                       fps, fps_ms, fps_us);
+                       "Display update: %ld kB/s, fps=%ld\n",
+                       throughput, fps);
                par->first_update_done = true;
        }
 }
 
-
 static void fbtft_mkdirty(struct fb_info *info, int y, int height)
 {
        struct fbtft_par *par = info->par;
@@ -501,7 +471,6 @@ static void fbtft_deferred_io(struct fb_info *info, struct list_head *pagelist)
                                        dirty_lines_start, dirty_lines_end);
 }
 
-
 static void fbtft_fb_fillrect(struct fb_info *info,
                              const struct fb_fillrect *rect)
 {
@@ -779,7 +748,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
        if (!info)
                goto alloc_fail;
 
-       info->screen_base = (u8 __force __iomem *)vmem;
+       info->screen_buffer = vmem;
        info->fbops = fbops;
        info->fbdefio = fbdefio;
 
@@ -802,7 +771,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
        info->fix.xpanstep =       0;
        info->fix.ypanstep =       0;
        info->fix.ywrapstep =      0;
-       info->fix.line_length =    width*bpp/8;
+       info->fix.line_length =    width * bpp / 8;
        info->fix.accel =          FB_ACCEL_NONE;
        info->fix.smem_len =       vmem_size;
 
@@ -919,7 +888,7 @@ EXPORT_SYMBOL(fbtft_framebuffer_alloc);
 void fbtft_framebuffer_release(struct fb_info *info)
 {
        fb_deferred_io_cleanup(info);
-       vfree(info->screen_base);
+       vfree(info->screen_buffer);
        framebuffer_release(info);
 }
 EXPORT_SYMBOL(fbtft_framebuffer_release);
@@ -998,12 +967,12 @@ int fbtft_register_framebuffer(struct fb_info *fb_info)
                        par->txbuf.len >> 10, par->txbuf.dma ? "DMA " : "");
        if (spi)
                sprintf(text2, ", spi%d.%d at %d MHz", spi->master->bus_num,
-                               spi->chip_select, spi->max_speed_hz/1000000);
+                       spi->chip_select, spi->max_speed_hz / 1000000);
        dev_info(fb_info->dev,
                "%s frame buffer, %dx%d, %d KiB video memory%s, fps=%lu%s\n",
                fb_info->fix.id, fb_info->var.xres, fb_info->var.yres,
                fb_info->fix.smem_len >> 10, text1,
-               HZ/fb_info->fbdefio->delay, text2);
+               HZ / fb_info->fbdefio->delay, text2);
 
 #ifdef CONFIG_FB_BACKLIGHT
        /* Turn on backlight if available */
@@ -1067,8 +1036,6 @@ static int fbtft_init_display_dt(struct fbtft_par *par)
        u32 val;
        int buf[64], i, j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        if (!node)
                return -EINVAL;
 
@@ -1151,8 +1118,6 @@ int fbtft_init_display(struct fbtft_par *par)
        int i = 0;
        int j;
 
-       fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);
-
        /* sanity check */
        if (!par->init_sequence) {
                dev_err(par->info->device,
@@ -1185,7 +1150,7 @@ int fbtft_init_display(struct fbtft_par *par)
                                "missing delimiter at position %d\n", i);
                        return -EINVAL;
                }
-               if (par->init_sequence[i+1] < 0) {
+               if (par->init_sequence[i + 1] < 0) {
                        dev_err(par->info->device,
                                "missing value after delimiter %d at position %d\n",
                                par->init_sequence[i], i);
index c4cc452f9f2bf654ba019a71072e65a9ec3cdb28..8d8bd12b90a1d33bcc97fb7f4f6dc3d869078da6 100644 (file)
@@ -103,8 +103,8 @@ sprintf_gamma(struct fbtft_par *par, unsigned long *curves, char *buf)
        for (i = 0; i < par->gamma.num_curves; i++) {
                for (j = 0; j < par->gamma.num_values; j++)
                        len += scnprintf(&buf[len], PAGE_SIZE,
-                               "%04lx ", curves[i*par->gamma.num_values + j]);
-               buf[len-1] = '\n';
+                            "%04lx ", curves[i * par->gamma.num_values + j]);
+               buf[len - 1] = '\n';
        }
        mutex_unlock(&par->gamma.lock);
 
@@ -149,7 +149,6 @@ static struct device_attribute gamma_device_attrs[] = {
        __ATTR(gamma, 0660, show_gamma_curve, store_gamma_curve),
 };
 
-
 void fbtft_expand_debug_value(unsigned long *debug)
 {
        switch (*debug & 0x7) {
@@ -205,7 +204,6 @@ static ssize_t show_debug(struct device *device,
 static struct device_attribute debug_device_attr = \
        __ATTR(debug, 0660, show_debug, store_debug);
 
-
 void fbtft_sysfs_init(struct fbtft_par *par)
 {
        device_create_file(par->info->dev, &debug_device_attr);
index 0d27daf23228adaeee72dac0027ebd2194f77d9c..3ccdec94fee74e60be8652f53bc6043d52cd5432 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #ifndef __LINUX_FBTFT_H
@@ -24,7 +20,6 @@
 #include <linux/spi/spi.h>
 #include <linux/platform_device.h>
 
-
 #define FBTFT_NOP              0x00
 #define FBTFT_SWRESET  0x01
 #define FBTFT_RDDID            0x04
@@ -251,7 +246,7 @@ struct fbtft_par {
        } gamma;
        unsigned long debug;
        bool first_update_done;
-       struct timespec update_time;
+       ktime_t update_time;
        bool bgr;
        void *extra;
 };
@@ -295,7 +290,6 @@ void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...);
 void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...);
 void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...);
 
-
 #define FBTFT_REGISTER_DRIVER(_name, _compatible, _display)                \
                                                                           \
 static int fbtft_driver_probe_spi(struct spi_device *spi)                  \
@@ -368,7 +362,6 @@ static void __exit fbtft_driver_module_exit(void)                          \
 module_init(fbtft_driver_module_init);                                     \
 module_exit(fbtft_driver_module_exit);
 
-
 /* Debug macros */
 
 /* shorthand debug levels */
@@ -414,7 +407,6 @@ module_exit(fbtft_driver_module_exit);
 #define DEBUG_REQUEST_GPIOS_MATCH   (1<<30)
 #define DEBUG_VERIFY_GPIOS          (1<<31)
 
-
 #define fbtft_init_dbg(dev, format, arg...)                  \
 do {                                                         \
        if (unlikely((dev)->platform_data &&                 \
@@ -428,7 +420,6 @@ do {                                                         \
                dev_info(par->info->device, format, ##arg);  \
 } while (0)
 
-
 #define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \
 do {                                                                       \
        if (unlikely(par->debug & level))                                  \
index fa916e88d54937e9e5272a6a0b40f875d1d2c4f9..071f79bd19f321cd7600f2b65b1424e556ea38b3 100644 (file)
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#define pr_fmt(fmt) "fbtft_device: " fmt
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/gpio.h>
 #include <linux/spi/spi.h>
+#include <video/mipi_display.h>
 
 #include "fbtft.h"
 
-#define DRVNAME "fbtft_device"
-
 #define MAX_GPIOS 32
 
 static struct spi_device *spi_device;
@@ -115,7 +111,6 @@ module_param(verbose, uint, 0);
 MODULE_PARM_DESC(verbose,
 "0 silent, >0 show gpios, >1 show devices, >2 show devices before (default=3)");
 
-
 struct fbtft_device_display {
        char *name;
        struct spi_board_info *spi;
@@ -132,6 +127,59 @@ static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
                "02 1c 07 12 37 32 29 2d 29 25 2B 39 00 01 03 10\n" \
                "03 1d 07 06 2E 2C 29 2D 2E 2E 37 3F 00 00 02 10"
 
+#define CBERRY28_GAMMA \
+               "D0 00 14 15 13 2C 42 43 4E 09 16 14 18 21\n" \
+               "D0 00 14 15 13 0B 43 55 53 0C 17 14 23 20"
+
+static int cberry28_init_sequence[] = {
+       /* turn off sleep mode */
+       -1, MIPI_DCS_EXIT_SLEEP_MODE,
+       -2, 120,
+
+       /* set pixel format to RGB-565 */
+       -1, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT,
+
+       -1, 0xB2, 0x0C, 0x0C, 0x00, 0x33, 0x33,
+
+       /*
+        * VGH = 13.26V
+        * VGL = -10.43V
+        */
+       -1, 0xB7, 0x35,
+
+       /*
+        * VDV and VRH register values come from command write
+        * (instead of NVM)
+        */
+       -1, 0xC2, 0x01, 0xFF,
+
+       /*
+        * VAP =  4.7V + (VCOM + VCOM offset + 0.5 * VDV)
+        * VAN = -4.7V + (VCOM + VCOM offset + 0.5 * VDV)
+        */
+       -1, 0xC3, 0x17,
+
+       /* VDV = 0V */
+       -1, 0xC4, 0x20,
+
+       /* VCOM = 0.675V */
+       -1, 0xBB, 0x17,
+
+       /* VCOM offset = 0V */
+       -1, 0xC5, 0x20,
+
+       /*
+        * AVDD = 6.8V
+        * AVCL = -4.8V
+        * VDS = 2.3V
+        */
+       -1, 0xD0, 0xA4, 0xA1,
+
+       -1, MIPI_DCS_SET_DISPLAY_ON,
+
+       -3,
+};
+
 static int hy28b_init_sequence[] = {
        -1, 0x00e7, 0x0010, -1, 0x0000, 0x0001,
        -1, 0x0001, 0x0100, -1, 0x0002, 0x0700,
@@ -318,6 +366,27 @@ static struct fbtft_device_display displays[] = {
                                },
                        }
                }
+       }, {
+               .name = "admatec_c-berry28",
+               .spi = &(struct spi_board_info) {
+                       .modalias = "fb_st7789v",
+                       .max_speed_hz = 48000000,
+                       .mode = SPI_MODE_0,
+                       .platform_data = &(struct fbtft_platform_data) {
+                               .display = {
+                                       .buswidth = 8,
+                                       .backlight = 1,
+                                       .init_sequence = cberry28_init_sequence,
+                               },
+                               .gpios = (const struct fbtft_gpio []) {
+                                       { "reset", 25 },
+                                       { "dc", 22 },
+                                       { "led", 18 },
+                                       {},
+                               },
+                               .gamma = CBERRY28_GAMMA,
+                       }
+               }
        }, {
                .name = "agm1264k-fl",
                .pdev = &(struct platform_device) {
@@ -1201,15 +1270,13 @@ static int write_gpio16_wr_slow(struct fbtft_par *par, void *buf, size_t len)
 static void adafruit18_green_tab_set_addr_win(struct fbtft_par *par,
                                                int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-               "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);
        write_reg(par, 0x2A, 0, xs + 2, 0, xe + 2);
        write_reg(par, 0x2B, 0, ys + 1, 0, ye + 1);
        write_reg(par, 0x2C);
 }
 
 /* used if gpios parameter is present */
-static struct fbtft_gpio fbtft_device_param_gpios[MAX_GPIOS+1] = { };
+static struct fbtft_gpio fbtft_device_param_gpios[MAX_GPIOS + 1] = { };
 
 static void fbtft_device_pdev_release(struct device *dev)
 {
@@ -1222,16 +1289,16 @@ static int spi_device_found(struct device *dev, void *data)
 {
        struct spi_device *spi = container_of(dev, struct spi_device, dev);
 
-       pr_info(DRVNAME":      %s %s %dkHz %d bits mode=0x%02X\n",
-               spi->modalias, dev_name(dev), spi->max_speed_hz/1000,
-               spi->bits_per_word, spi->mode);
+       dev_info(dev, "%s %s %dkHz %d bits mode=0x%02X\n", spi->modalias,
+                dev_name(dev), spi->max_speed_hz / 1000, spi->bits_per_word,
+                spi->mode);
 
        return 0;
 }
 
 static void pr_spi_devices(void)
 {
-       pr_info(DRVNAME":  SPI devices registered:\n");
+       pr_debug("SPI devices registered:\n");
        bus_for_each_dev(&spi_bus_type, NULL, NULL, spi_device_found);
 }
 
@@ -1241,16 +1308,15 @@ static int p_device_found(struct device *dev, void *data)
        *pdev = container_of(dev, struct platform_device, dev);
 
        if (strstr(pdev->name, "fb"))
-               pr_info(DRVNAME":      %s id=%d pdata? %s\n",
-                               pdev->name, pdev->id,
-                               pdev->dev.platform_data ? "yes" : "no");
+               dev_info(dev, "%s id=%d pdata? %s\n", pdev->name, pdev->id,
+                        pdev->dev.platform_data ? "yes" : "no");
 
        return 0;
 }
 
 static void pr_p_devices(void)
 {
-       pr_info(DRVNAME":  'fb' Platform devices registered:\n");
+       pr_debug("'fb' Platform devices registered:\n");
        bus_for_each_dev(&platform_bus_type, NULL, NULL, p_device_found);
 }
 
@@ -1265,7 +1331,7 @@ static void fbtft_device_spi_delete(struct spi_master *master, unsigned cs)
        dev = bus_find_device_by_name(&spi_bus_type, NULL, str);
        if (dev) {
                if (verbose)
-                       pr_info(DRVNAME": Deleting %s\n", str);
+                       dev_info(dev, "Deleting %s\n", str);
                device_del(dev);
        }
 }
@@ -1276,8 +1342,8 @@ static int fbtft_device_spi_device_register(struct spi_board_info *spi)
 
        master = spi_busnum_to_master(spi->bus_num);
        if (!master) {
-               pr_err(DRVNAME ":  spi_busnum_to_master(%d) returned NULL\n",
-                                                               spi->bus_num);
+               pr_err("spi_busnum_to_master(%d) returned NULL\n",
+                      spi->bus_num);
                return -EINVAL;
        }
        /* make sure it's available */
@@ -1285,7 +1351,7 @@ static int fbtft_device_spi_device_register(struct spi_board_info *spi)
        spi_device = spi_new_device(master, spi);
        put_device(&master->dev);
        if (!spi_device) {
-               pr_err(DRVNAME ":    spi_new_device() returned NULL\n");
+               dev_err(&master->dev, "spi_new_device() returned NULL\n");
                return -EPERM;
        }
        return 0;
@@ -1308,11 +1374,9 @@ static int __init fbtft_device_init(void)
        long val;
        int ret = 0;
 
-       pr_debug("\n\n"DRVNAME": init\n");
-
        if (name == NULL) {
 #ifdef MODULE
-               pr_err(DRVNAME":  missing module parameter: 'name'\n");
+               pr_err("missing module parameter: 'name'\n");
                return -EINVAL;
 #else
                return 0;
@@ -1320,41 +1384,37 @@ static int __init fbtft_device_init(void)
        }
 
        if (init_num > FBTFT_MAX_INIT_SEQUENCE) {
-               pr_err(DRVNAME
-                       ":  init parameter: exceeded max array size: %d\n",
-                       FBTFT_MAX_INIT_SEQUENCE);
+               pr_err("init parameter: exceeded max array size: %d\n",
+                      FBTFT_MAX_INIT_SEQUENCE);
                return -EINVAL;
        }
 
        /* parse module parameter: gpios */
        while ((p_gpio = strsep(&gpios, ","))) {
                if (strchr(p_gpio, ':') == NULL) {
-                       pr_err(DRVNAME
-                               ":  error: missing ':' in gpios parameter: %s\n",
-                               p_gpio);
+                       pr_err("error: missing ':' in gpios parameter: %s\n",
+                              p_gpio);
                        return -EINVAL;
                }
                p_num = p_gpio;
                p_name = strsep(&p_num, ":");
                if (p_name == NULL || p_num == NULL) {
-                       pr_err(DRVNAME
-                               ":  something bad happened parsing gpios parameter: %s\n",
-                               p_gpio);
+                       pr_err("something bad happened parsing gpios parameter: %s\n",
+                              p_gpio);
                        return -EINVAL;
                }
                ret = kstrtol(p_num, 10, &val);
                if (ret) {
-                       pr_err(DRVNAME
-                               ":  could not parse number in gpios parameter: %s:%s\n",
-                               p_name, p_num);
+                       pr_err("could not parse number in gpios parameter: %s:%s\n",
+                              p_name, p_num);
                        return -EINVAL;
                }
-               strcpy(fbtft_device_param_gpios[i].name, p_name);
+               strncpy(fbtft_device_param_gpios[i].name, p_name,
+                       FBTFT_GPIO_NAME_SIZE - 1);
                fbtft_device_param_gpios[i++].gpio = (int) val;
                if (i == MAX_GPIOS) {
-                       pr_err(DRVNAME
-                               ":  gpios parameter: exceeded max array size: %d\n",
-                               MAX_GPIOS);
+                       pr_err("gpios parameter: exceeded max array size: %d\n",
+                              MAX_GPIOS);
                        return -EINVAL;
                }
        }
@@ -1367,7 +1427,7 @@ static int __init fbtft_device_init(void)
        if (verbose > 2)
                pr_p_devices(); /* print list of 'fb' platform devices */
 
-       pr_debug(DRVNAME":  name='%s', busnum=%d, cs=%d\n", name, busnum, cs);
+       pr_debug("name='%s', busnum=%d, cs=%d\n", name, busnum, cs);
 
        if (rotate > 0 && rotate < 4) {
                rotate = (4 - rotate) * 90;
@@ -1381,11 +1441,11 @@ static int __init fbtft_device_init(void)
        }
 
        /* name=list lists all supported displays */
-       if (strncmp(name, "list", 32) == 0) {
-               pr_info(DRVNAME":  Supported displays:\n");
+       if (strncmp(name, "list", FBTFT_GPIO_NAME_SIZE) == 0) {
+               pr_info("Supported displays:\n");
 
                for (i = 0; i < ARRAY_SIZE(displays); i++)
-                       pr_info(DRVNAME":      %s\n", displays[i].name);
+                       pr_info("%s\n", displays[i].name);
                return -ECANCELED;
        }
 
@@ -1416,7 +1476,7 @@ static int __init fbtft_device_init(void)
                                p_device = displays[i].pdev;
                                pdata = p_device->dev.platform_data;
                        } else {
-                               pr_err(DRVNAME": broken displays array\n");
+                               pr_err("broken displays array\n");
                                return -EINVAL;
                        }
 
@@ -1448,16 +1508,14 @@ static int __init fbtft_device_init(void)
                        if (displays[i].spi) {
                                ret = fbtft_device_spi_device_register(spi);
                                if (ret) {
-                                       pr_err(DRVNAME
-                                               ": failed to register SPI device\n");
+                                       pr_err("failed to register SPI device\n");
                                        return ret;
                                }
                        } else {
                                ret = platform_device_register(p_device);
                                if (ret < 0) {
-                                       pr_err(DRVNAME
-                                               ":    platform_device_register() returned %d\n",
-                                               ret);
+                                       pr_err("platform_device_register() returned %d\n",
+                                              ret);
                                        return ret;
                                }
                        }
@@ -1467,22 +1525,21 @@ static int __init fbtft_device_init(void)
        }
 
        if (!found) {
-               pr_err(DRVNAME":  display not supported: '%s'\n", name);
+               pr_err("display not supported: '%s'\n", name);
                return -EINVAL;
        }
 
        if (verbose && pdata && pdata->gpios) {
                gpio = pdata->gpios;
-               pr_info(DRVNAME":  GPIOS used by '%s':\n", name);
+               pr_info("GPIOS used by '%s':\n", name);
                found = false;
                while (verbose && gpio->name[0]) {
-                       pr_info(DRVNAME":    '%s' = GPIO%d\n",
-                               gpio->name, gpio->gpio);
+                       pr_info("'%s' = GPIO%d\n", gpio->name, gpio->gpio);
                        gpio++;
                        found = true;
                }
                if (!found)
-                       pr_info(DRVNAME":    (none)\n");
+                       pr_info("(none)\n");
        }
 
        if (spi_device && (verbose > 1))
@@ -1495,8 +1552,6 @@ static int __init fbtft_device_init(void)
 
 static void __exit fbtft_device_exit(void)
 {
-       pr_debug(DRVNAME" - exit\n");
-
        if (spi_device) {
                device_del(&spi_device->dev);
                kfree(spi_device);
index 86d9223e4e0c273abbe195ab44b5d5c96591733f..ce0d254148e4d8a8e3498ef33b68f5313e16ecf8 100644 (file)
@@ -233,8 +233,6 @@ static const struct flexfb_lcd_controller flexfb_chip_table[] = {
 static void flexfb_set_addr_win_1(struct fbtft_par *par,
                                  int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par, "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
-                     __func__, xs, ys, xe, ye);
        switch (par->info->var.rotate) {
        /* R20h = Horizontal GRAM Start Address */
        /* R21h = Vertical GRAM Start Address */
@@ -262,10 +260,6 @@ static void flexfb_set_addr_win_1(struct fbtft_par *par,
 static void flexfb_set_addr_win_2(struct fbtft_par *par,
                                  int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-                     "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n",
-                     __func__, xs, ys, xe, ye);
-
        switch (par->info->var.rotate) {
        /* R4Eh - Set GDDRAM X address counter */
        /* R4Fh - Set GDDRAM Y address counter */
@@ -295,10 +289,6 @@ static void flexfb_set_addr_win_2(struct fbtft_par *par,
 static void set_addr_win_3(struct fbtft_par *par,
                           int xs, int ys, int xe, int ye)
 {
-       fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
-                     "%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__,
-                     xs, ys, xe, ye);
-
        write_reg(par, 0x15, xs, xe);
        write_reg(par, 0x75, ys, ye);
        write_reg(par, 0x5C);
index d99ab6d0bbb14dc81fd861db9e105d2bfdaee6e3..2d97173f8e917abf82e33d0a6bea5f08b540bc33 100644 (file)
 #include "../include/dpbp.h"
 #include "../include/dpbp-cmd.h"
 
-int dpbp_open(struct fsl_mc_io *mc_io, int dpbp_id, uint16_t *token)
+/**
+ * dpbp_open() - Open a control session for the specified object.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @dpbp_id:   DPBP unique ID
+ * @token:     Returned token; use in subsequent API calls
+ *
+ * This function can be used to open a control session for an
+ * already created object; an object may have been declared in
+ * the DPL or by calling the dpbp_create function.
+ * This function returns a unique authentication token,
+ * associated with the specific object ID and the specific MC
+ * portal; this token must be used in all subsequent commands for
+ * this specific object
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpbp_open(struct fsl_mc_io *mc_io,
+             u32 cmd_flags,
+             int dpbp_id,
+             u16 *token)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_OPEN,
-                                         MC_CMD_PRI_LOW, 0);
+                                         cmd_flags, 0);
        cmd.params[0] |= mc_enc(0, 32, dpbp_id);
 
        /* send command to mc*/
@@ -56,12 +76,25 @@ int dpbp_open(struct fsl_mc_io *mc_io, int dpbp_id, uint16_t *token)
 }
 EXPORT_SYMBOL(dpbp_open);
 
-int dpbp_close(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpbp_close() - Close the control session of the object
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ *
+ * After this function is called, no further operations are
+ * allowed on the object without opening a new control session.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpbp_close(struct fsl_mc_io *mc_io,
+              u32 cmd_flags,
+              u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, MC_CMD_PRI_HIGH,
+       cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLOSE, cmd_flags,
                                          token);
 
        /* send command to mc*/
@@ -69,9 +102,31 @@ int dpbp_close(struct fsl_mc_io *mc_io, uint16_t token)
 }
 EXPORT_SYMBOL(dpbp_close);
 
+/**
+ * dpbp_create() - Create the DPBP object.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @cfg:       Configuration structure
+ * @token:     Returned token; use in subsequent API calls
+ *
+ * Create the DPBP object, allocate required resources and
+ * perform required initialization.
+ *
+ * The object can be created either by declaring it in the
+ * DPL file, or by calling this function.
+ * This function returns a unique authentication token,
+ * associated with the specific object ID and the specific MC
+ * portal; this token must be used in all subsequent calls to
+ * this specific object. For objects that are created using the
+ * DPL file, call dpbp_open function to get an authentication
+ * token first.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_create(struct fsl_mc_io *mc_io,
+               u32 cmd_flags,
                const struct dpbp_cfg *cfg,
-               uint16_t *token)
+               u16 *token)
 {
        struct mc_command cmd = { 0 };
        int err;
@@ -80,7 +135,7 @@ int dpbp_create(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
-                                         MC_CMD_PRI_LOW, 0);
+                                         cmd_flags, 0);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
@@ -93,24 +148,44 @@ int dpbp_create(struct fsl_mc_io *mc_io,
        return 0;
 }
 
-int dpbp_destroy(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpbp_destroy() - Destroy the DPBP object and release all its resources.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ *
+ * Return:     '0' on Success; error code otherwise.
+ */
+int dpbp_destroy(struct fsl_mc_io *mc_io,
+                u32 cmd_flags,
+                u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
-int dpbp_enable(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpbp_enable() - Enable the DPBP.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpbp_enable(struct fsl_mc_io *mc_io,
+               u32 cmd_flags,
+               u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, MC_CMD_PRI_LOW,
+       cmd.header = mc_encode_cmd_header(DPBP_CMDID_ENABLE, cmd_flags,
                                          token);
 
        /* send command to mc*/
@@ -118,25 +193,47 @@ int dpbp_enable(struct fsl_mc_io *mc_io, uint16_t token)
 }
 EXPORT_SYMBOL(dpbp_enable);
 
-int dpbp_disable(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpbp_disable() - Disable the DPBP.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpbp_disable(struct fsl_mc_io *mc_io,
+                u32 cmd_flags,
+                u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_DISABLE,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 EXPORT_SYMBOL(dpbp_disable);
 
-int dpbp_is_enabled(struct fsl_mc_io *mc_io, uint16_t token, int *en)
+/**
+ * dpbp_is_enabled() - Check if the DPBP is enabled.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @en:                Returns '1' if object is enabled; '0' otherwise
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpbp_is_enabled(struct fsl_mc_io *mc_io,
+                   u32 cmd_flags,
+                   u16 token,
+                   int *en)
 {
        struct mc_command cmd = { 0 };
        int err;
        /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, MC_CMD_PRI_LOW,
+       cmd.header = mc_encode_cmd_header(DPBP_CMDID_IS_ENABLED, cmd_flags,
                                          token);
 
        /* send command to mc*/
@@ -150,53 +247,83 @@ int dpbp_is_enabled(struct fsl_mc_io *mc_io, uint16_t token, int *en)
        return 0;
 }
 
-int dpbp_reset(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpbp_reset() - Reset the DPBP, returns the object to initial state.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpbp_reset(struct fsl_mc_io *mc_io,
+              u32 cmd_flags,
+              u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_RESET,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpbp_set_irq() - Set IRQ information for the DPBP to trigger an interrupt.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: Identifies the interrupt index to configure
+ * @irq_cfg:   IRQ configuration
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_set_irq(struct fsl_mc_io *mc_io,
-                uint16_t token,
-                uint8_t irq_index,
-                uint64_t irq_paddr,
-                uint32_t irq_val,
-                int user_irq_id)
+                u32 cmd_flags,
+                u16 token,
+                u8 irq_index,
+                struct dpbp_irq_cfg *irq_cfg)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 8, irq_index);
-       cmd.params[0] |= mc_enc(32, 32, irq_val);
-       cmd.params[1] |= mc_enc(0, 64, irq_paddr);
-       cmd.params[2] |= mc_enc(0, 32, user_irq_id);
+       cmd.params[0] |= mc_enc(32, 32, irq_cfg->val);
+       cmd.params[1] |= mc_enc(0, 64, irq_cfg->addr);
+       cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpbp_get_irq() - Get IRQ information from the DPBP.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: The interrupt index to configure
+ * @type:      Interrupt type: 0 represents message interrupt
+ *             type (both irq_addr and irq_val are valid)
+ * @irq_cfg:   IRQ attributes
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_get_irq(struct fsl_mc_io *mc_io,
-                uint16_t token,
-                uint8_t irq_index,
+                u32 cmd_flags,
+                u16 token,
+                u8 irq_index,
                 int *type,
-                uint64_t *irq_paddr,
-                uint32_t *irq_val,
-                int *user_irq_id)
+                struct dpbp_irq_cfg *irq_cfg)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -205,23 +332,39 @@ int dpbp_get_irq(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *irq_val = (uint32_t)mc_dec(cmd.params[0], 0, 32);
-       *irq_paddr = (uint64_t)mc_dec(cmd.params[1], 0, 64);
-       *user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
+       irq_cfg->val = (u32)mc_dec(cmd.params[0], 0, 32);
+       irq_cfg->addr = (u64)mc_dec(cmd.params[1], 0, 64);
+       irq_cfg->user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
        *type = (int)mc_dec(cmd.params[2], 32, 32);
        return 0;
 }
 
+/**
+ * dpbp_set_irq_enable() - Set overall interrupt state.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: The interrupt index to configure
+ * @en:        Interrupt state - enable = 1, disable = 0
+ *
+ * Allows GPP software to control when interrupts are generated.
+ * Each interrupt can have up to 32 causes.  The enable/disable control's the
+ * overall interrupt state. if the interrupt is disabled no causes will cause
+ * an interrupt.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
-                       uint16_t token,
-                       uint8_t irq_index,
-                       uint8_t en)
+                       u32 cmd_flags,
+                       u16 token,
+                       u8 irq_index,
+                       u8 en)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 8, en);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -229,17 +372,28 @@ int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpbp_get_irq_enable() - Get overall interrupt state
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: The interrupt index to configure
+ * @en:                Returned interrupt state - enable = 1, disable = 0
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
-                       uint16_t token,
-                       uint8_t irq_index,
-                       uint8_t *en)
+                       u32 cmd_flags,
+                       u16 token,
+                       u8 irq_index,
+                       u8 *en)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -248,20 +402,37 @@ int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *en = (uint8_t)mc_dec(cmd.params[0], 0, 8);
+       *en = (u8)mc_dec(cmd.params[0], 0, 8);
        return 0;
 }
 
+/**
+ * dpbp_set_irq_mask() - Set interrupt mask.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: The interrupt index to configure
+ * @mask:      Event mask to trigger interrupt;
+ *                     each bit:
+ *                             0 = ignore event
+ *                             1 = consider event for asserting IRQ
+ *
+ * Every interrupt can have up to 32 causes and the interrupt model supports
+ * masking/unmasking each cause independently
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t token,
-                     uint8_t irq_index,
-                     uint32_t mask)
+                     u32 cmd_flags,
+                     u16 token,
+                     u8 irq_index,
+                     u32 mask)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, mask);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -269,17 +440,31 @@ int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpbp_get_irq_mask() - Get interrupt mask.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: The interrupt index to configure
+ * @mask:      Returned event mask to trigger interrupt
+ *
+ * Every interrupt can have up to 32 causes and the interrupt model supports
+ * masking/unmasking each cause independently
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t token,
-                     uint8_t irq_index,
-                     uint32_t *mask)
+                     u32 cmd_flags,
+                     u16 token,
+                     u8 irq_index,
+                     u32 *mask)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -288,21 +473,35 @@ int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *mask = (uint32_t)mc_dec(cmd.params[0], 0, 32);
+       *mask = (u32)mc_dec(cmd.params[0], 0, 32);
        return 0;
 }
 
+/**
+ * dpbp_get_irq_status() - Get the current status of any pending interrupts.
+ *
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: The interrupt index to configure
+ * @status:    Returned interrupts status - one bit per cause:
+ *                     0 = no interrupt pending
+ *                     1 = interrupt pending
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
-                       uint16_t token,
-                       uint8_t irq_index,
-                       uint32_t *status)
+                       u32 cmd_flags,
+                       u16 token,
+                       u8 irq_index,
+                       u32 *status)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -311,20 +510,34 @@ int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *status = (uint32_t)mc_dec(cmd.params[0], 0, 32);
+       *status = (u32)mc_dec(cmd.params[0], 0, 32);
        return 0;
 }
 
+/**
+ * dpbp_clear_irq_status() - Clear a pending interrupt's status
+ *
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @irq_index: The interrupt index to configure
+ * @status:    Bits to clear (W1C) - one bit per cause:
+ *                                     0 = don't change
+ *                                     1 = clear status bit
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
-                         uint16_t token,
-                         uint8_t irq_index,
-                         uint32_t status)
+                         u32 cmd_flags,
+                         u16 token,
+                         u8 irq_index,
+                         u32 status)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, status);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -332,8 +545,19 @@ int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpbp_get_attributes - Retrieve DPBP attributes.
+ *
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPBP object
+ * @attr:      Returned object's attributes
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpbp_get_attributes(struct fsl_mc_io *mc_io,
-                       uint16_t token,
+                       u32 cmd_flags,
+                       u16 token,
                        struct dpbp_attr *attr)
 {
        struct mc_command cmd = { 0 };
@@ -341,7 +565,7 @@ int dpbp_get_attributes(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_ATTR,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
@@ -349,10 +573,10 @@ int dpbp_get_attributes(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       attr->bpid = (uint16_t)mc_dec(cmd.params[0], 16, 16);
+       attr->bpid = (u16)mc_dec(cmd.params[0], 16, 16);
        attr->id = (int)mc_dec(cmd.params[0], 32, 32);
-       attr->version.major = (uint16_t)mc_dec(cmd.params[1], 0, 16);
-       attr->version.minor = (uint16_t)mc_dec(cmd.params[1], 16, 16);
+       attr->version.major = (u16)mc_dec(cmd.params[1], 0, 16);
+       attr->version.minor = (u16)mc_dec(cmd.params[1], 16, 16);
        return 0;
 }
 EXPORT_SYMBOL(dpbp_get_attributes);
index 57f326b60b76f91938ae2b6b4423919d7ee88a51..a87e9f84fa42bd8b3ac128287b00c6eb97ae9619 100644 (file)
@@ -34,7 +34,7 @@
 
 /* DPMCP Version */
 #define DPMCP_VER_MAJOR                                2
-#define DPMCP_VER_MINOR                                0
+#define DPMCP_VER_MINOR                                1
 
 /* Command IDs */
 #define DPMCP_CMDID_CLOSE                              0x800
 #define DPMCP_CMDID_GET_IRQ_STATUS                     0x016
 #define DPMCP_CMDID_CLEAR_IRQ_STATUS                   0x017
 
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_CREATE(cmd, cfg) \
-       MC_CMD_OP(cmd, 0, 0,  32, int,      cfg->portal_id)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_SET_IRQ(cmd, irq_index, irq_addr, irq_val, user_irq_id) \
-do { \
-       MC_CMD_OP(cmd, 0, 0,  8,  uint8_t,  irq_index);\
-       MC_CMD_OP(cmd, 0, 32, 32, uint32_t, irq_val);\
-       MC_CMD_OP(cmd, 1, 0,  64, uint64_t, irq_addr); \
-       MC_CMD_OP(cmd, 2, 0,  32, int,      user_irq_id); \
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ(cmd, irq_index) \
-       MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ(cmd, type, irq_addr, irq_val, user_irq_id) \
-do { \
-       MC_RSP_OP(cmd, 0, 0,  32, uint32_t, irq_val); \
-       MC_RSP_OP(cmd, 1, 0,  64, uint64_t, irq_addr); \
-       MC_RSP_OP(cmd, 2, 0,  32, int,      user_irq_id); \
-       MC_RSP_OP(cmd, 2, 32, 32, int,      type); \
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_SET_IRQ_ENABLE(cmd, irq_index, en) \
-do { \
-       MC_CMD_OP(cmd, 0, 0,  8,  uint8_t,  en); \
-       MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index);\
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ_ENABLE(cmd, irq_index) \
-       MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ_ENABLE(cmd, en) \
-       MC_RSP_OP(cmd, 0, 0,  8,  uint8_t,  en)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_SET_IRQ_MASK(cmd, irq_index, mask) \
-do { \
-       MC_CMD_OP(cmd, 0, 0,  32, uint32_t, mask);\
-       MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index);\
-} while (0)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ_MASK(cmd, irq_index) \
-       MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ_MASK(cmd, mask) \
-       MC_RSP_OP(cmd, 0, 0,  32, uint32_t, mask)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_GET_IRQ_STATUS(cmd, irq_index) \
-       MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_RSP_GET_IRQ_STATUS(cmd, status) \
-       MC_RSP_OP(cmd, 0, 0,  32, uint32_t, status)
-
-/*                cmd, param, offset, width, type, arg_name */
-#define DPMCP_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status) \
-do { \
-       MC_CMD_OP(cmd, 0, 0,  32, uint32_t, status); \
-       MC_CMD_OP(cmd, 0, 32, 8,  uint8_t,  irq_index);\
-} while (0)
-
-/*                cmd, param, offset, width, type,     arg_name */
-#define DPMCP_RSP_GET_ATTRIBUTES(cmd, attr) \
-do { \
-       MC_RSP_OP(cmd, 0, 32, 32, int,      attr->id);\
-       MC_RSP_OP(cmd, 1, 0,  16, uint16_t, attr->version.major);\
-       MC_RSP_OP(cmd, 1, 16, 16, uint16_t, attr->version.minor);\
-} while (0)
-
 #endif /* _FSL_DPMCP_CMD_H */
index 6b9da5b7fd00f3fa5e7d78ea822b1715f1c32890..b0248f574619964b51cabd26a6949aec1fbe0d9e 100644 (file)
 #include "dpmcp.h"
 #include "dpmcp-cmd.h"
 
-int dpmcp_open(struct fsl_mc_io *mc_io, int dpmcp_id, uint16_t *token)
+/**
+ * dpmcp_open() - Open a control session for the specified object.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @dpmcp_id:  DPMCP unique ID
+ * @token:     Returned token; use in subsequent API calls
+ *
+ * This function can be used to open a control session for an
+ * already created object; an object may have been declared in
+ * the DPL or by calling the dpmcp_create function.
+ * This function returns a unique authentication token,
+ * associated with the specific object ID and the specific MC
+ * portal; this token must be used in all subsequent commands for
+ * this specific object
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpmcp_open(struct fsl_mc_io *mc_io,
+              u32 cmd_flags,
+              int dpmcp_id,
+              u16 *token)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
-                                         MC_CMD_PRI_LOW, 0);
+                                         cmd_flags, 0);
        cmd.params[0] |= mc_enc(0, 32, dpmcp_id);
 
        /* send command to mc*/
@@ -55,28 +75,63 @@ int dpmcp_open(struct fsl_mc_io *mc_io, int dpmcp_id, uint16_t *token)
        return err;
 }
 
-int dpmcp_close(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpmcp_close() - Close the control session of the object
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ *
+ * After this function is called, no further operations are
+ * allowed on the object without opening a new control session.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpmcp_close(struct fsl_mc_io *mc_io,
+               u32 cmd_flags,
+               u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE, MC_CMD_PRI_HIGH,
-                                         token);
+       cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
+                                         cmd_flags, token);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpmcp_create() - Create the DPMCP object.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @cfg:       Configuration structure
+ * @token:     Returned token; use in subsequent API calls
+ *
+ * Create the DPMCP object, allocate required resources and
+ * perform required initialization.
+ *
+ * The object can be created either by declaring it in the
+ * DPL file, or by calling this function.
+ * This function returns a unique authentication token,
+ * associated with the specific object ID and the specific MC
+ * portal; this token must be used in all subsequent calls to
+ * this specific object. For objects that are created using the
+ * DPL file, call dpmcp_open function to get an authentication
+ * token first.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_create(struct fsl_mc_io *mc_io,
+                u32 cmd_flags,
                 const struct dpmcp_cfg *cfg,
-               uint16_t *token)
+                u16 *token)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
-                                         MC_CMD_PRI_LOW, 0);
+                                         cmd_flags, 0);
        cmd.params[0] |= mc_enc(0, 32, cfg->portal_id);
 
        /* send command to mc*/
@@ -90,65 +145,105 @@ int dpmcp_create(struct fsl_mc_io *mc_io,
        return 0;
 }
 
-int dpmcp_destroy(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ *
+ * Return:     '0' on Success; error code otherwise.
+ */
+int dpmcp_destroy(struct fsl_mc_io *mc_io,
+                 u32 cmd_flags,
+                 u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
-int dpmcp_reset(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpmcp_reset(struct fsl_mc_io *mc_io,
+               u32 cmd_flags,
+               u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: Identifies the interrupt index to configure
+ * @irq_cfg:   IRQ configuration
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_set_irq(struct fsl_mc_io *mc_io,
-                 uint16_t token,
-                uint8_t irq_index,
-                uint64_t irq_addr,
-                uint32_t irq_val,
-                int user_irq_id)
+                 u32 cmd_flags,
+                 u16 token,
+                 u8 irq_index,
+                 struct dpmcp_irq_cfg  *irq_cfg)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 8, irq_index);
-       cmd.params[0] |= mc_enc(32, 32, irq_val);
-       cmd.params[1] |= mc_enc(0, 64, irq_addr);
-       cmd.params[2] |= mc_enc(0, 32, user_irq_id);
+       cmd.params[0] |= mc_enc(32, 32, irq_cfg->val);
+       cmd.params[1] |= mc_enc(0, 64, irq_cfg->paddr);
+       cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpmcp_get_irq() - Get IRQ information from the DPMCP.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: The interrupt index to configure
+ * @type:      Interrupt type: 0 represents message interrupt
+ *             type (both irq_addr and irq_val are valid)
+ * @irq_cfg:   IRQ attributes
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_get_irq(struct fsl_mc_io *mc_io,
-                 uint16_t token,
-                uint8_t irq_index,
-                int *type,
-                uint64_t *irq_addr,
-                uint32_t *irq_val,
-                int *user_irq_id)
+                 u32 cmd_flags,
+                 u16 token,
+                 u8 irq_index,
+                 int *type,
+                 struct dpmcp_irq_cfg  *irq_cfg)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -157,23 +252,39 @@ int dpmcp_get_irq(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *irq_val = (uint32_t)mc_dec(cmd.params[0], 0, 32);
-       *irq_addr = (uint64_t)mc_dec(cmd.params[1], 0, 64);
-       *user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
+       irq_cfg->val = (u32)mc_dec(cmd.params[0], 0, 32);
+       irq_cfg->paddr = (u64)mc_dec(cmd.params[1], 0, 64);
+       irq_cfg->user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
        *type = (int)mc_dec(cmd.params[2], 32, 32);
        return 0;
 }
 
+/**
+ * dpmcp_set_irq_enable() - Set overall interrupt state.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: The interrupt index to configure
+ * @en:        Interrupt state - enable = 1, disable = 0
+ *
+ * Allows GPP software to control when interrupts are generated.
+ * Each interrupt can have up to 32 causes.  The enable/disable control's the
+ * overall interrupt state. if the interrupt is disabled no causes will cause
+ * an interrupt.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
-                        uint16_t token,
-                       uint8_t irq_index,
-                       uint8_t en)
+                        u32 cmd_flags,
+                        u16 token,
+                        u8 irq_index,
+                        u8 en)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 8, en);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -181,17 +292,28 @@ int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpmcp_get_irq_enable() - Get overall interrupt state
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: The interrupt index to configure
+ * @en:                Returned interrupt state - enable = 1, disable = 0
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
-                        uint16_t token,
-                       uint8_t irq_index,
-                       uint8_t *en)
+                        u32 cmd_flags,
+                        u16 token,
+                        u8 irq_index,
+                        u8 *en)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -200,20 +322,37 @@ int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *en = (uint8_t)mc_dec(cmd.params[0], 0, 8);
+       *en = (u8)mc_dec(cmd.params[0], 0, 8);
        return 0;
 }
 
+/**
+ * dpmcp_set_irq_mask() - Set interrupt mask.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: The interrupt index to configure
+ * @mask:      Event mask to trigger interrupt;
+ *                     each bit:
+ *                             0 = ignore event
+ *                             1 = consider event for asserting IRQ
+ *
+ * Every interrupt can have up to 32 causes and the interrupt model supports
+ * masking/unmasking each cause independently
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
-                      uint16_t token,
-                     uint8_t irq_index,
-                     uint32_t mask)
+                      u32 cmd_flags,
+                      u16 token,
+                      u8 irq_index,
+                      u32 mask)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, mask);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -221,17 +360,31 @@ int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpmcp_get_irq_mask() - Get interrupt mask.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: The interrupt index to configure
+ * @mask:      Returned event mask to trigger interrupt
+ *
+ * Every interrupt can have up to 32 causes and the interrupt model supports
+ * masking/unmasking each cause independently
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
-                      uint16_t token,
-                     uint8_t irq_index,
-                     uint32_t *mask)
+                      u32 cmd_flags,
+                      u16 token,
+                      u8 irq_index,
+                      u32 *mask)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -240,21 +393,35 @@ int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *mask = (uint32_t)mc_dec(cmd.params[0], 0, 32);
+       *mask = (u32)mc_dec(cmd.params[0], 0, 32);
        return 0;
 }
 
+/**
+ * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
+ *
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: The interrupt index to configure
+ * @status:    Returned interrupts status - one bit per cause:
+ *                     0 = no interrupt pending
+ *                     1 = interrupt pending
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
-                        uint16_t token,
-                       uint8_t irq_index,
-                       uint32_t *status)
+                        u32 cmd_flags,
+                        u16 token,
+                        u8 irq_index,
+                        u32 *status)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -263,20 +430,34 @@ int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *status = (uint32_t)mc_dec(cmd.params[0], 0, 32);
+       *status = (u32)mc_dec(cmd.params[0], 0, 32);
        return 0;
 }
 
+/**
+ * dpmcp_clear_irq_status() - Clear a pending interrupt's status
+ *
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @irq_index: The interrupt index to configure
+ * @status:    Bits to clear (W1C) - one bit per cause:
+ *                                     0 = don't change
+ *                                     1 = clear status bit
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_clear_irq_status(struct fsl_mc_io *mc_io,
-                          uint16_t token,
-                         uint8_t irq_index,
-                         uint32_t status)
+                          u32 cmd_flags,
+                          u16 token,
+                          u8 irq_index,
+                          u32 status)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLEAR_IRQ_STATUS,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, status);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -284,16 +465,27 @@ int dpmcp_clear_irq_status(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dpmcp_get_attributes - Retrieve DPMCP attributes.
+ *
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPMCP object
+ * @attr:      Returned object's attributes
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
-                        uint16_t token,
-                       struct dpmcp_attr *attr)
+                        u32 cmd_flags,
+                        u16 token,
+                        struct dpmcp_attr *attr)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
@@ -302,7 +494,7 @@ int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
 
        /* retrieve response parameters */
        attr->id = (int)mc_dec(cmd.params[0], 32, 32);
-       attr->version.major = (uint16_t)mc_dec(cmd.params[1], 0, 16);
-       attr->version.minor = (uint16_t)mc_dec(cmd.params[1], 16, 16);
+       attr->version.major = (u16)mc_dec(cmd.params[1], 0, 16);
+       attr->version.minor = (u16)mc_dec(cmd.params[1], 16, 16);
        return 0;
 }
index 5e7c21952ce549d67986229d21f1d0d2fd7e4832..6df351f0caa502169abcea1ddd955733bc43d720 100644 (file)
 
 struct fsl_mc_io;
 
-/**
- * dpmcp_open() - Open a control session for the specified object.
- * @mc_io:     Pointer to MC portal's I/O object
- * @dpmcp_id:  DPMCP unique ID
- * @token:     Returned token; use in subsequent API calls
- *
- * This function can be used to open a control session for an
- * already created object; an object may have been declared in
- * the DPL or by calling the dpmcp_create function.
- * This function returns a unique authentication token,
- * associated with the specific object ID and the specific MC
- * portal; this token must be used in all subsequent commands for
- * this specific object
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpmcp_open(struct fsl_mc_io *mc_io, int dpmcp_id, uint16_t *token);
+int dpmcp_open(struct fsl_mc_io *mc_io,
+              uint32_t cmd_flags,
+              int dpmcp_id,
+              uint16_t *token);
 
 /* Get portal ID from pool */
 #define DPMCP_GET_PORTAL_ID_FROM_POOL (-1)
 
-/**
- * dpmcp_close() - Close the control session of the object
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- *
- * After this function is called, no further operations are
- * allowed on the object without opening a new control session.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpmcp_close(struct fsl_mc_io *mc_io, uint16_t token);
+int dpmcp_close(struct fsl_mc_io *mc_io,
+               uint32_t cmd_flags,
+               uint16_t token);
 
 /**
- * struct dpmcp_cfg() - Structure representing DPMCP configuration
+ * struct dpmcp_cfg - Structure representing DPMCP configuration
  * @portal_id: Portal ID; 'DPMCP_GET_PORTAL_ID_FROM_POOL' to get the portal ID
  *             from pool
  */
@@ -80,199 +59,82 @@ struct dpmcp_cfg {
        int portal_id;
 };
 
-/**
- * dpmcp_create() - Create the DPMCP object.
- * @mc_io:     Pointer to MC portal's I/O object
- * @cfg:       Configuration structure
- * @token:     Returned token; use in subsequent API calls
- *
- * Create the DPMCP object, allocate required resources and
- * perform required initialization.
- *
- * The object can be created either by declaring it in the
- * DPL file, or by calling this function.
- * This function returns a unique authentication token,
- * associated with the specific object ID and the specific MC
- * portal; this token must be used in all subsequent calls to
- * this specific object. For objects that are created using the
- * DPL file, call dpmcp_open function to get an authentication
- * token first.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_create(struct fsl_mc_io      *mc_io,
+                uint32_t               cmd_flags,
                 const struct dpmcp_cfg *cfg,
                uint16_t                *token);
 
-/**
- * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- *
- * Return:     '0' on Success; error code otherwise.
- */
-int dpmcp_destroy(struct fsl_mc_io *mc_io, uint16_t token);
+int dpmcp_destroy(struct fsl_mc_io *mc_io,
+                 uint32_t cmd_flags,
+                 uint16_t token);
 
-/**
- * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpmcp_reset(struct fsl_mc_io *mc_io, uint16_t token);
+int dpmcp_reset(struct fsl_mc_io *mc_io,
+               uint32_t cmd_flags,
+               uint16_t token);
 
 /* IRQ */
-/*!
- * @name dpmcp IRQ Index and Events
- */
+/* IRQ Index */
 #define DPMCP_IRQ_INDEX                             0
-/*!< Irq index */
+/* irq event - Indicates that the link state changed */
 #define DPMCP_IRQ_EVENT_CMD_DONE                    0x00000001
-/*!< irq event - Indicates that the link state changed */
-/* @} */
 
 /**
- * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: Identifies the interrupt index to configure
- * @irq_addr:  Address that must be written to
- *                             signal a message-based interrupt
- * @irq_val:   Value to write into irq_addr address
+ * struct dpmcp_irq_cfg - IRQ configuration
+ * @paddr:     Address that must be written to signal a message-based interrupt
+ * @val:       Value to write into irq_addr address
  * @user_irq_id: A user defined number associated with this IRQ
- *
- * Return:     '0' on Success; Error code otherwise.
  */
+struct dpmcp_irq_cfg {
+            uint64_t           paddr;
+            uint32_t           val;
+            int                user_irq_id;
+};
+
 int dpmcp_set_irq(struct fsl_mc_io     *mc_io,
+                 uint32_t              cmd_flags,
                  uint16_t              token,
                 uint8_t                irq_index,
-                uint64_t               irq_addr,
-                uint32_t               irq_val,
-                int                    user_irq_id);
+                 struct dpmcp_irq_cfg  *irq_cfg);
 
-/**
- * dpmcp_get_irq() - Get IRQ information from the DPMCP.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: The interrupt index to configure
- * @type:      Interrupt type: 0 represents message interrupt
- *                             type (both irq_addr and irq_val are valid)
- * @irq_addr:  Returned address that must be written to
- *                             signal the message-based interrupt
- * @irq_val:   Value to write into irq_addr address
- * @user_irq_id: A user defined number associated with this IRQ
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_get_irq(struct fsl_mc_io     *mc_io,
+                 uint32_t              cmd_flags,
                  uint16_t              token,
                 uint8_t                irq_index,
                 int                    *type,
-                uint64_t               *irq_addr,
-                uint32_t               *irq_val,
-                int                    *user_irq_id);
+                struct dpmcp_irq_cfg   *irq_cfg);
 
-/**
- * dpmcp_set_irq_enable() - Set overall interrupt state.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: The interrupt index to configure
- * @en:        Interrupt state - enable = 1, disable = 0
- *
- * Allows GPP software to control when interrupts are generated.
- * Each interrupt can have up to 32 causes.  The enable/disable control's the
- * overall interrupt state. if the interrupt is disabled no causes will cause
- * an interrupt.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_set_irq_enable(struct fsl_mc_io      *mc_io,
+                        uint32_t               cmd_flags,
                         uint16_t               token,
                        uint8_t                 irq_index,
                        uint8_t                 en);
 
-/**
- * dpmcp_get_irq_enable() - Get overall interrupt state
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: The interrupt index to configure
- * @en:                Returned interrupt state - enable = 1, disable = 0
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_get_irq_enable(struct fsl_mc_io      *mc_io,
+                        uint32_t               cmd_flags,
                         uint16_t               token,
                        uint8_t                 irq_index,
                        uint8_t                 *en);
 
-/**
- * dpmcp_set_irq_mask() - Set interrupt mask.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: The interrupt index to configure
- * @mask:      Event mask to trigger interrupt;
- *                     each bit:
- *                             0 = ignore event
- *                             1 = consider event for asserting IRQ
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_set_irq_mask(struct fsl_mc_io        *mc_io,
+                      uint32_t cmd_flags,
                       uint16_t         token,
                      uint8_t           irq_index,
                      uint32_t          mask);
 
-/**
- * dpmcp_get_irq_mask() - Get interrupt mask.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: The interrupt index to configure
- * @mask:      Returned event mask to trigger interrupt
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_get_irq_mask(struct fsl_mc_io        *mc_io,
+                      uint32_t cmd_flags,
                       uint16_t         token,
                      uint8_t           irq_index,
                      uint32_t          *mask);
 
-/**
- * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
- *
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: The interrupt index to configure
- * @status:    Returned interrupts status - one bit per cause:
- *                     0 = no interrupt pending
- *                     1 = interrupt pending
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_get_irq_status(struct fsl_mc_io      *mc_io,
+                        uint32_t               cmd_flags,
                         uint16_t               token,
                        uint8_t                 irq_index,
                        uint32_t                *status);
 
-/**
- * dpmcp_clear_irq_status() - Clear a pending interrupt's status
- *
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @irq_index: The interrupt index to configure
- * @status:    Bits to clear (W1C) - one bit per cause:
- *                                     0 = don't change
- *                                     1 = clear status bit
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_clear_irq_status(struct fsl_mc_io    *mc_io,
+                          uint32_t             cmd_flags,
                           uint16_t             token,
                          uint8_t               irq_index,
                          uint32_t              status);
@@ -295,16 +157,8 @@ struct dpmcp_attr {
        } version;
 };
 
-/**
- * dpmcp_get_attributes - Retrieve DPMCP attributes.
- *
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPMCP object
- * @attr:      Returned object's attributes
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpmcp_get_attributes(struct fsl_mc_io      *mc_io,
+                        uint32_t               cmd_flags,
                         uint16_t               token,
                        struct dpmcp_attr       *attr);
 
index 58328e8118e9df4f76bbaeb9dee82c818217f7dd..f633fcd86e51d6973ac0b08bffe8809e0e59fd77 100644 (file)
 #include "../include/dpmng.h"
 #include "dpmng-cmd.h"
 
-int mc_get_version(struct fsl_mc_io *mc_io, struct mc_version *mc_ver_info)
+/**
+ * mc_get_version() - Retrieves the Management Complex firmware
+ *                     version information
+ * @mc_io:             Pointer to opaque I/O object
+ * @cmd_flags:         Command flags; one or more of 'MC_CMD_FLAG_'
+ * @mc_ver_info:       Returned version information structure
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int mc_get_version(struct fsl_mc_io *mc_io,
+                  u32 cmd_flags,
+                  struct mc_version *mc_ver_info)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_VERSION,
-                                         MC_CMD_PRI_LOW, 0);
+                                         cmd_flags,
+                                         0);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
@@ -56,14 +68,25 @@ int mc_get_version(struct fsl_mc_io *mc_io, struct mc_version *mc_ver_info)
        return 0;
 }
 
-int dpmng_get_container_id(struct fsl_mc_io *mc_io, int *container_id)
+/**
+ * dpmng_get_container_id() - Get container ID associated with a given portal.
+ * @mc_io:             Pointer to MC portal's I/O object
+ * @cmd_flags:         Command flags; one or more of 'MC_CMD_FLAG_'
+ * @container_id:      Requested container ID
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dpmng_get_container_id(struct fsl_mc_io *mc_io,
+                          u32 cmd_flags,
+                          int *container_id)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_CONT_ID,
-                                         MC_CMD_PRI_LOW, 0);
+                                         cmd_flags,
+                                         0);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
index 09202489c2b2f8cdd9bd968caced672fc1151ecb..6552c2034947ed5b9e82f70514a8e10c3e230a8c 100644 (file)
@@ -41,7 +41,7 @@
 #define _FSL_DPRC_CMD_H
 
 /* DPRC Version */
-#define DPRC_VER_MAJOR                         3
+#define DPRC_VER_MAJOR                         4
 #define DPRC_VER_MINOR                         0
 
 /* Command IDs */
 #define DPRC_CMDID_GET_RES_COUNT               0x15B
 #define DPRC_CMDID_GET_RES_IDS                 0x15C
 #define DPRC_CMDID_GET_OBJ_REG                 0x15E
+#define DPRC_CMDID_SET_OBJ_IRQ                 0x15F
+#define DPRC_CMDID_GET_OBJ_IRQ                 0x160
+#define DPRC_CMDID_SET_OBJ_LABEL               0x161
+#define DPRC_CMDID_GET_OBJ_DESC                        0x162
 
 #define DPRC_CMDID_CONNECT                     0x167
 #define DPRC_CMDID_DISCONNECT                  0x168
 #define DPRC_CMDID_GET_POOL                    0x169
 #define DPRC_CMDID_GET_POOL_COUNT              0x16A
-#define DPRC_CMDID_GET_PORTAL_PADDR            0x16B
 
 #define DPRC_CMDID_GET_CONNECTION              0x16C
 
index 35c06cff1a06ff8f3bf46e23e668afbb4a5b944b..2c4cd70b4cbb98a5fcb37fabae875cd084635866 100644 (file)
@@ -126,7 +126,7 @@ static void check_plugged_state_change(struct fsl_mc_device *mc_dev,
                                       struct dprc_obj_desc *obj_desc)
 {
        int error;
-       uint32_t plugged_flag_at_mc =
+       u32 plugged_flag_at_mc =
                        (obj_desc->state & DPRC_OBJ_STATE_PLUGGED);
 
        if (plugged_flag_at_mc !=
@@ -262,6 +262,7 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev)
        struct dprc_obj_desc *child_obj_desc_array = NULL;
 
        error = dprc_get_obj_count(mc_bus_dev->mc_io,
+                                  0,
                                   mc_bus_dev->mc_handle,
                                   &num_child_objects);
        if (error < 0) {
@@ -289,6 +290,7 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev)
                            &child_obj_desc_array[i];
 
                        error = dprc_get_obj(mc_bus_dev->mc_io,
+                                            0,
                                             mc_bus_dev->mc_handle,
                                             i, obj_desc);
                        if (error < 0) {
@@ -399,7 +401,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
                        return error;
        }
 
-       error = dprc_open(mc_dev->mc_io, mc_dev->obj_desc.id,
+       error = dprc_open(mc_dev->mc_io, 0, mc_dev->obj_desc.id,
                          &mc_dev->mc_handle);
        if (error < 0) {
                dev_err(&mc_dev->dev, "dprc_open() failed: %d\n", error);
@@ -419,7 +421,7 @@ static int dprc_probe(struct fsl_mc_device *mc_dev)
        return 0;
 
 error_cleanup_open:
-       (void)dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
+       (void)dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
 
 error_cleanup_mc_io:
        fsl_destroy_mc_io(mc_dev->mc_io);
@@ -447,7 +449,7 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)
 
        device_for_each_child(&mc_dev->dev, NULL, __fsl_mc_device_remove);
        dprc_cleanup_all_resource_pools(mc_dev);
-       error = dprc_close(mc_dev->mc_io, mc_dev->mc_handle);
+       error = dprc_close(mc_dev->mc_io, 0, mc_dev->mc_handle);
        if (error < 0)
                dev_err(&mc_dev->dev, "dprc_close() failed: %d\n", error);
 
@@ -480,7 +482,7 @@ int __init dprc_driver_init(void)
        return fsl_mc_driver_register(&dprc_driver);
 }
 
-void __exit dprc_driver_exit(void)
+void dprc_driver_exit(void)
 {
        fsl_mc_driver_unregister(&dprc_driver);
 }
index 19b26e630b627dc9d746c845f2467cc1e09f5dd5..381b9a96a14bd5cb692df987d9362e852eb311b4 100644 (file)
 #include "../include/dprc.h"
 #include "dprc-cmd.h"
 
-int dprc_open(struct fsl_mc_io *mc_io, int container_id, uint16_t *token)
+/**
+ * dprc_open() - Open DPRC object for use
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @container_id: Container ID to open
+ * @token:     Returned token of DPRC object
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ *
+ * @warning    Required before any operation on the object.
+ */
+int dprc_open(struct fsl_mc_io *mc_io,
+             u32 cmd_flags,
+             int container_id,
+             u16 *token)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, MC_CMD_PRI_LOW,
+       cmd.header = mc_encode_cmd_header(DPRC_CMDID_OPEN, cmd_flags,
                                          0);
        cmd.params[0] |= mc_enc(0, 32, container_id);
 
@@ -56,12 +70,25 @@ int dprc_open(struct fsl_mc_io *mc_io, int container_id, uint16_t *token)
 }
 EXPORT_SYMBOL(dprc_open);
 
-int dprc_close(struct fsl_mc_io *mc_io, uint16_t token)
+/**
+ * dprc_close() - Close the control session of the object
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ *
+ * After this function is called, no further operations are
+ * allowed on the object without opening a new control session.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dprc_close(struct fsl_mc_io *mc_io,
+              u32 cmd_flags,
+              u16 token)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, MC_CMD_PRI_HIGH,
+       cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLOSE, cmd_flags,
                                          token);
 
        /* send command to mc*/
@@ -69,11 +96,23 @@ int dprc_close(struct fsl_mc_io *mc_io, uint16_t token)
 }
 EXPORT_SYMBOL(dprc_close);
 
+/**
+ * dprc_create_container() - Create child container
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @cfg:       Child container configuration
+ * @child_container_id:        Returned child container ID
+ * @child_portal_offset: Returned child portal offset from MC portal base
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_create_container(struct fsl_mc_io *mc_io,
-                         uint16_t token,
+                         u32 cmd_flags,
+                         u16 token,
                          struct dprc_cfg *cfg,
                          int *child_container_id,
-                         uint64_t *child_portal_paddr)
+                         u64 *child_portal_offset)
 {
        struct mc_command cmd = { 0 };
        int err;
@@ -82,9 +121,25 @@ int dprc_create_container(struct fsl_mc_io *mc_io,
        cmd.params[0] |= mc_enc(32, 16, cfg->icid);
        cmd.params[0] |= mc_enc(0, 32, cfg->options);
        cmd.params[1] |= mc_enc(32, 32, cfg->portal_id);
+       cmd.params[2] |= mc_enc(0, 8, cfg->label[0]);
+       cmd.params[2] |= mc_enc(8, 8, cfg->label[1]);
+       cmd.params[2] |= mc_enc(16, 8, cfg->label[2]);
+       cmd.params[2] |= mc_enc(24, 8, cfg->label[3]);
+       cmd.params[2] |= mc_enc(32, 8, cfg->label[4]);
+       cmd.params[2] |= mc_enc(40, 8, cfg->label[5]);
+       cmd.params[2] |= mc_enc(48, 8, cfg->label[6]);
+       cmd.params[2] |= mc_enc(56, 8, cfg->label[7]);
+       cmd.params[3] |= mc_enc(0, 8, cfg->label[8]);
+       cmd.params[3] |= mc_enc(8, 8, cfg->label[9]);
+       cmd.params[3] |= mc_enc(16, 8, cfg->label[10]);
+       cmd.params[3] |= mc_enc(24, 8, cfg->label[11]);
+       cmd.params[3] |= mc_enc(32, 8, cfg->label[12]);
+       cmd.params[3] |= mc_enc(40, 8, cfg->label[13]);
+       cmd.params[3] |= mc_enc(48, 8, cfg->label[14]);
+       cmd.params[3] |= mc_enc(56, 8, cfg->label[15]);
 
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
@@ -93,55 +148,112 @@ int dprc_create_container(struct fsl_mc_io *mc_io,
 
        /* retrieve response parameters */
        *child_container_id = mc_dec(cmd.params[1], 0, 32);
-       *child_portal_paddr = mc_dec(cmd.params[2], 0, 64);
+       *child_portal_offset = mc_dec(cmd.params[2], 0, 64);
 
        return 0;
 }
 
+/**
+ * dprc_destroy_container() - Destroy child container.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @child_container_id:        ID of the container to destroy
+ *
+ * This function terminates the child container, so following this call the
+ * child container ID becomes invalid.
+ *
+ * Notes:
+ * - All resources and objects of the destroyed container are returned to the
+ * parent container or destroyed if were created be the destroyed container.
+ * - This function destroy all the child containers of the specified
+ *   container prior to destroying the container itself.
+ *
+ * warning: Only the parent container is allowed to destroy a child policy
+ *             Container 0 can't be destroyed
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ *
+ */
 int dprc_destroy_container(struct fsl_mc_io *mc_io,
-                          uint16_t token,
+                          u32 cmd_flags,
+                          u16 token,
                           int child_container_id)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, child_container_id);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_reset_container - Reset child container.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @child_container_id:        ID of the container to reset
+ *
+ * In case a software context crashes or becomes non-responsive, the parent
+ * may wish to reset its resources container before the software context is
+ * restarted.
+ *
+ * This routine informs all objects assigned to the child container that the
+ * container is being reset, so they may perform any cleanup operations that are
+ * needed. All objects handles that were owned by the child container shall be
+ * closed.
+ *
+ * Note that such request may be submitted even if the child software context
+ * has not crashed, but the resulting object cleanup operations will not be
+ * aware of that.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_reset_container(struct fsl_mc_io *mc_io,
-                        uint16_t token,
+                        u32 cmd_flags,
+                        u16 token,
                         int child_container_id)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, child_container_id);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_get_irq() - Get IRQ information from the DPRC.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index: The interrupt index to configure
+ * @type:      Interrupt type: 0 represents message interrupt
+ *             type (both irq_addr and irq_val are valid)
+ * @irq_cfg:   IRQ attributes
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_irq(struct fsl_mc_io *mc_io,
-                uint16_t token,
-                uint8_t irq_index,
+                u32 cmd_flags,
+                u16 token,
+                u8 irq_index,
                 int *type,
-                uint64_t *irq_paddr,
-                uint32_t *irq_val,
-                int *user_irq_id)
+                struct dprc_irq_cfg *irq_cfg)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -151,47 +263,67 @@ int dprc_get_irq(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       *irq_val = mc_dec(cmd.params[0], 0, 32);
-       *irq_paddr = mc_dec(cmd.params[1], 0, 64);
-       *user_irq_id = mc_dec(cmd.params[2], 0, 32);
+       irq_cfg->val = mc_dec(cmd.params[0], 0, 32);
+       irq_cfg->paddr = mc_dec(cmd.params[1], 0, 64);
+       irq_cfg->user_irq_id = mc_dec(cmd.params[2], 0, 32);
        *type = mc_dec(cmd.params[2], 32, 32);
 
        return 0;
 }
 
+/**
+ * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index: Identifies the interrupt index to configure
+ * @irq_cfg:   IRQ configuration
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_set_irq(struct fsl_mc_io *mc_io,
-                uint16_t token,
-                uint8_t irq_index,
-                uint64_t irq_paddr,
-                uint32_t irq_val,
-                int user_irq_id)
+                u32 cmd_flags,
+                u16 token,
+                u8 irq_index,
+                struct dprc_irq_cfg *irq_cfg)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
-       cmd.params[0] |= mc_enc(0, 32, irq_val);
-       cmd.params[1] |= mc_enc(0, 64, irq_paddr);
-       cmd.params[2] |= mc_enc(0, 32, user_irq_id);
+       cmd.params[0] |= mc_enc(0, 32, irq_cfg->val);
+       cmd.params[1] |= mc_enc(0, 64, irq_cfg->paddr);
+       cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
 
        /* send command to mc*/
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_get_irq_enable() - Get overall interrupt state.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index:  The interrupt index to configure
+ * @en:                Returned interrupt state - enable = 1, disable = 0
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
-                       uint16_t token,
-                       uint8_t irq_index,
-                       uint8_t *en)
+                       u32 cmd_flags,
+                       u16 token,
+                       u8 irq_index,
+                       u8 *en)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_ENABLE,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -205,16 +337,32 @@ int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
        return 0;
 }
 
+/**
+ * dprc_set_irq_enable() - Set overall interrupt state.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index: The interrupt index to configure
+ * @en:                Interrupt state - enable = 1, disable = 0
+ *
+ * Allows GPP software to control when interrupts are generated.
+ * Each interrupt can have up to 32 causes.  The enable/disable control's the
+ * overall interrupt state. if the interrupt is disabled no causes will cause
+ * an interrupt.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
-                       uint16_t token,
-                       uint8_t irq_index,
-                       uint8_t en)
+                       u32 cmd_flags,
+                       u16 token,
+                       u8 irq_index,
+                       u8 en)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_ENABLE,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 8, en);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -222,17 +370,31 @@ int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_get_irq_mask() - Get interrupt mask.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index: The interrupt index to configure
+ * @mask:      Returned event mask to trigger interrupt
+ *
+ * Every interrupt can have up to 32 causes and the interrupt model supports
+ * masking/unmasking each cause independently
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t token,
-                     uint8_t irq_index,
-                     uint32_t *mask)
+                     u32 cmd_flags,
+                     u16 token,
+                     u8 irq_index,
+                     u32 *mask)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_MASK,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -246,16 +408,33 @@ int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
        return 0;
 }
 
+/**
+ * dprc_set_irq_mask() - Set interrupt mask.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index: The interrupt index to configure
+ * @mask:      event mask to trigger interrupt;
+ *                     each bit:
+ *                             0 = ignore event
+ *                             1 = consider event for asserting irq
+ *
+ * Every interrupt can have up to 32 causes and the interrupt model supports
+ * masking/unmasking each cause independently
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t token,
-                     uint8_t irq_index,
-                     uint32_t mask)
+                     u32 cmd_flags,
+                     u16 token,
+                     u8 irq_index,
+                     u32 mask)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_IRQ_MASK,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, mask);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -263,17 +442,30 @@ int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_get_irq_status() - Get the current status of any pending interrupts.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index: The interrupt index to configure
+ * @status:    Returned interrupts status - one bit per cause:
+ *                     0 = no interrupt pending
+ *                     1 = interrupt pending
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_irq_status(struct fsl_mc_io *mc_io,
-                       uint16_t token,
-                       uint8_t irq_index,
-                       uint32_t *status)
+                       u32 cmd_flags,
+                       u16 token,
+                       u8 irq_index,
+                       u32 *status)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_IRQ_STATUS,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
        /* send command to mc*/
@@ -287,16 +479,29 @@ int dprc_get_irq_status(struct fsl_mc_io *mc_io,
        return 0;
 }
 
+/**
+ * dprc_clear_irq_status() - Clear a pending interrupt's status
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @irq_index: The interrupt index to configure
+ * @status:    bits to clear (W1C) - one bit per cause:
+ *                                     0 = don't change
+ *                                     1 = clear status bit
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
-                         uint16_t token,
-                         uint8_t irq_index,
-                         uint32_t status)
+                         u32 cmd_flags,
+                         u16 token,
+                         u8 irq_index,
+                         u32 status)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_CLEAR_IRQ_STATUS,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, status);
        cmd.params[0] |= mc_enc(32, 8, irq_index);
 
@@ -304,8 +509,18 @@ int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_get_attributes() - Obtains container attributes
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @attributes Returned container attributes
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_attributes(struct fsl_mc_io *mc_io,
-                       uint16_t token,
+                       u32 cmd_flags,
+                       u16 token,
                        struct dprc_attributes *attr)
 {
        struct mc_command cmd = { 0 };
@@ -313,7 +528,7 @@ int dprc_get_attributes(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_ATTR,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
 
        /* send command to mc*/
@@ -332,17 +547,43 @@ int dprc_get_attributes(struct fsl_mc_io *mc_io,
        return 0;
 }
 
+/**
+ * dprc_set_res_quota() - Set allocation policy for a specific resource/object
+ *             type in a child container
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @child_container_id:        ID of the child container
+ * @type:      Resource/object type
+ * @quota:     Sets the maximum number of resources of the selected type
+ *             that the child container is allowed to allocate from its parent;
+ *             when quota is set to -1, the policy is the same as container's
+ *             general policy.
+ *
+ * Allocation policy determines whether or not a container may allocate
+ * resources from its parent. Each container has a 'global' allocation policy
+ * that is set when the container is created.
+ *
+ * This function sets allocation policy for a specific resource type.
+ * The default policy for all resource types matches the container's 'global'
+ * allocation policy.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ *
+ * @warning    Only the parent container is allowed to change a child policy.
+ */
 int dprc_set_res_quota(struct fsl_mc_io *mc_io,
-                      uint16_t token,
+                      u32 cmd_flags,
+                      u16 token,
                       int child_container_id,
                       char *type,
-                      uint16_t quota)
+                      u16 quota)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, child_container_id);
        cmd.params[0] |= mc_enc(32, 16, quota);
        cmd.params[1] |= mc_enc(0, 8, type[0]);
@@ -366,18 +607,34 @@ int dprc_set_res_quota(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_get_res_quota() - Gets the allocation policy of a specific
+ *             resource/object type in a child container
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @child_container_id;        ID of the child container
+ * @type:      resource/object type
+ * @quota:     Returnes the maximum number of resources of the selected type
+ *             that the child container is allowed to allocate from the parent;
+ *             when quota is set to -1, the policy is the same as container's
+ *             general policy.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_res_quota(struct fsl_mc_io *mc_io,
-                      uint16_t token,
+                      u32 cmd_flags,
+                      u16 token,
                       int child_container_id,
                       char *type,
-                      uint16_t *quota)
+                      u16 *quota)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, child_container_id);
        cmd.params[1] |= mc_enc(0, 8, type[0]);
        cmd.params[1] |= mc_enc(8, 8, type[1]);
@@ -407,8 +664,41 @@ int dprc_get_res_quota(struct fsl_mc_io *mc_io,
        return 0;
 }
 
+/**
+ * dprc_assign() - Assigns objects or resource to a child container.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @container_id: ID of the child container
+ * @res_req:   Describes the type and amount of resources to
+ *                     assign to the given container
+ *
+ * Assignment is usually done by a parent (this DPRC) to one of its child
+ * containers.
+ *
+ * According to the DPRC allocation policy, the assigned resources may be taken
+ * (allocated) from the container's ancestors, if not enough resources are
+ * available in the container itself.
+ *
+ * The type of assignment depends on the dprc_res_req options, as follows:
+ * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
+ *   the explicit base ID specified at the id_base_align field of res_req.
+ * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
+ *   aligned to the value given at id_base_align field of res_req.
+ * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
+ *   and indicates that the object must be set to the plugged state.
+ *
+ * A container may use this function with its own ID in order to change a
+ * object state to plugged or unplugged.
+ *
+ * If IRQ information has been set in the child DPRC, it will signal an
+ * interrupt following every change in its object assignment.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_assign(struct fsl_mc_io *mc_io,
-               uint16_t token,
+               u32 cmd_flags,
+               u16 token,
                int container_id,
                struct dprc_res_req *res_req)
 {
@@ -416,7 +706,7 @@ int dprc_assign(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, container_id);
        cmd.params[0] |= mc_enc(32, 32, res_req->options);
        cmd.params[1] |= mc_enc(0, 32, res_req->num);
@@ -442,8 +732,24 @@ int dprc_assign(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_unassign() - Un-assigns objects or resources from a child container
+ *             and moves them into this (parent) DPRC.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @child_container_id:        ID of the child container
+ * @res_req:   Describes the type and amount of resources to un-assign from
+ *             the child container
+ *
+ * Un-assignment of objects can succeed only if the object is not in the
+ * plugged or opened state.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_unassign(struct fsl_mc_io *mc_io,
-                 uint16_t token,
+                 u32 cmd_flags,
+                 u16 token,
                  int child_container_id,
                  struct dprc_res_req *res_req)
 {
@@ -451,7 +757,7 @@ int dprc_unassign(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(0, 32, child_container_id);
        cmd.params[0] |= mc_enc(32, 32, res_req->options);
@@ -478,8 +784,18 @@ int dprc_unassign(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_get_pool_count() - Get the number of dprc's pools
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @token:     Token of DPRC object
+ * @pool_count:        Returned number of resource pools in the dprc
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_pool_count(struct fsl_mc_io *mc_io,
-                       uint16_t token,
+                       u32 cmd_flags,
+                       u16 token,
                        int *pool_count)
 {
        struct mc_command cmd = { 0 };
@@ -487,7 +803,7 @@ int dprc_get_pool_count(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
@@ -500,8 +816,24 @@ int dprc_get_pool_count(struct fsl_mc_io *mc_io,
        return 0;
 }
 
+/**
+ * dprc_get_pool() - Get the type (string) of a certain dprc's pool
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @pool_index;        Index of the pool to be queried (< pool_count)
+ * @type:      The type of the pool
+ *
+ * The pool types retrieved one by one by incrementing
+ * pool_index up to (not including) the value of pool_count returned
+ * from dprc_get_pool_count(). dprc_get_pool_count() must
+ * be called prior to dprc_get_pool().
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_pool(struct fsl_mc_io *mc_io,
-                 uint16_t token,
+                 u32 cmd_flags,
+                 u16 token,
                  int pool_index,
                  char *type)
 {
@@ -510,7 +842,7 @@ int dprc_get_pool(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(0, 32, pool_index);
 
@@ -540,14 +872,26 @@ int dprc_get_pool(struct fsl_mc_io *mc_io,
        return 0;
 }
 
-int dprc_get_obj_count(struct fsl_mc_io *mc_io, uint16_t token, int *obj_count)
+/**
+ * dprc_get_obj_count() - Obtains the number of objects in the DPRC
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @obj_count: Number of objects assigned to the DPRC
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dprc_get_obj_count(struct fsl_mc_io *mc_io,
+                      u32 cmd_flags,
+                      u16 token,
+                      int *obj_count)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_COUNT,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
 
        /* send command to mc*/
        err = mc_send_command(mc_io, &cmd);
@@ -561,8 +905,24 @@ int dprc_get_obj_count(struct fsl_mc_io *mc_io, uint16_t token, int *obj_count)
 }
 EXPORT_SYMBOL(dprc_get_obj_count);
 
+/**
+ * dprc_get_obj() - Get general information on an object
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @obj_index: Index of the object to be queried (< obj_count)
+ * @obj_desc:  Returns the requested object descriptor
+ *
+ * The object descriptors are retrieved one by one by incrementing
+ * obj_index up to (not including) the value of obj_count returned
+ * from dprc_get_obj_count(). dprc_get_obj_count() must
+ * be called prior to dprc_get_obj().
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_obj(struct fsl_mc_io *mc_io,
-                uint16_t token,
+                u32 cmd_flags,
+                u16 token,
                 int obj_index,
                 struct dprc_obj_desc *obj_desc)
 {
@@ -571,7 +931,7 @@ int dprc_get_obj(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(0, 32, obj_index);
 
@@ -604,13 +964,253 @@ int dprc_get_obj(struct fsl_mc_io *mc_io,
        obj_desc->type[13] = mc_dec(cmd.params[4], 40, 8);
        obj_desc->type[14] = mc_dec(cmd.params[4], 48, 8);
        obj_desc->type[15] = '\0';
-
+       obj_desc->label[0] = mc_dec(cmd.params[5], 0, 8);
+       obj_desc->label[1] = mc_dec(cmd.params[5], 8, 8);
+       obj_desc->label[2] = mc_dec(cmd.params[5], 16, 8);
+       obj_desc->label[3] = mc_dec(cmd.params[5], 24, 8);
+       obj_desc->label[4] = mc_dec(cmd.params[5], 32, 8);
+       obj_desc->label[5] = mc_dec(cmd.params[5], 40, 8);
+       obj_desc->label[6] = mc_dec(cmd.params[5], 48, 8);
+       obj_desc->label[7] = mc_dec(cmd.params[5], 56, 8);
+       obj_desc->label[8] = mc_dec(cmd.params[6], 0, 8);
+       obj_desc->label[9] = mc_dec(cmd.params[6], 8, 8);
+       obj_desc->label[10] = mc_dec(cmd.params[6], 16, 8);
+       obj_desc->label[11] = mc_dec(cmd.params[6], 24, 8);
+       obj_desc->label[12] = mc_dec(cmd.params[6], 32, 8);
+       obj_desc->label[13] = mc_dec(cmd.params[6], 40, 8);
+       obj_desc->label[14] = mc_dec(cmd.params[6], 48, 8);
+       obj_desc->label[15] = '\0';
        return 0;
 }
 EXPORT_SYMBOL(dprc_get_obj);
 
+/**
+ * dprc_get_obj_desc() - Get object descriptor.
+ *
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @obj_type:  The type of the object to get its descriptor.
+ * @obj_id:    The id of the object to get its descriptor
+ * @obj_desc:  The returned descriptor to fill and return to the user
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ *
+ */
+int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
+                     u32 cmd_flags,
+                     u16 token,
+                     char *obj_type,
+                     int obj_id,
+                     struct dprc_obj_desc *obj_desc)
+{
+       struct mc_command cmd = { 0 };
+       int err;
+
+       /* prepare command */
+       cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
+                                         cmd_flags,
+                                         token);
+       cmd.params[0] |= mc_enc(0, 32, obj_id);
+       cmd.params[1] |= mc_enc(0, 8, obj_type[0]);
+       cmd.params[1] |= mc_enc(8, 8, obj_type[1]);
+       cmd.params[1] |= mc_enc(16, 8, obj_type[2]);
+       cmd.params[1] |= mc_enc(24, 8, obj_type[3]);
+       cmd.params[1] |= mc_enc(32, 8, obj_type[4]);
+       cmd.params[1] |= mc_enc(40, 8, obj_type[5]);
+       cmd.params[1] |= mc_enc(48, 8, obj_type[6]);
+       cmd.params[1] |= mc_enc(56, 8, obj_type[7]);
+       cmd.params[2] |= mc_enc(0, 8, obj_type[8]);
+       cmd.params[2] |= mc_enc(8, 8, obj_type[9]);
+       cmd.params[2] |= mc_enc(16, 8, obj_type[10]);
+       cmd.params[2] |= mc_enc(24, 8, obj_type[11]);
+       cmd.params[2] |= mc_enc(32, 8, obj_type[12]);
+       cmd.params[2] |= mc_enc(40, 8, obj_type[13]);
+       cmd.params[2] |= mc_enc(48, 8, obj_type[14]);
+       cmd.params[2] |= mc_enc(56, 8, obj_type[15]);
+
+       /* send command to mc*/
+       err = mc_send_command(mc_io, &cmd);
+       if (err)
+               return err;
+
+       /* retrieve response parameters */
+       obj_desc->id = (int)mc_dec(cmd.params[0], 32, 32);
+       obj_desc->vendor = (u16)mc_dec(cmd.params[1], 0, 16);
+       obj_desc->vendor = (u8)mc_dec(cmd.params[1], 16, 8);
+       obj_desc->region_count = (u8)mc_dec(cmd.params[1], 24, 8);
+       obj_desc->state = (u32)mc_dec(cmd.params[1], 32, 32);
+       obj_desc->ver_major = (u16)mc_dec(cmd.params[2], 0, 16);
+       obj_desc->ver_minor = (u16)mc_dec(cmd.params[2], 16, 16);
+       obj_desc->type[0] = (char)mc_dec(cmd.params[3], 0, 8);
+       obj_desc->type[1] = (char)mc_dec(cmd.params[3], 8, 8);
+       obj_desc->type[2] = (char)mc_dec(cmd.params[3], 16, 8);
+       obj_desc->type[3] = (char)mc_dec(cmd.params[3], 24, 8);
+       obj_desc->type[4] = (char)mc_dec(cmd.params[3], 32, 8);
+       obj_desc->type[5] = (char)mc_dec(cmd.params[3], 40, 8);
+       obj_desc->type[6] = (char)mc_dec(cmd.params[3], 48, 8);
+       obj_desc->type[7] = (char)mc_dec(cmd.params[3], 56, 8);
+       obj_desc->type[8] = (char)mc_dec(cmd.params[4], 0, 8);
+       obj_desc->type[9] = (char)mc_dec(cmd.params[4], 8, 8);
+       obj_desc->type[10] = (char)mc_dec(cmd.params[4], 16, 8);
+       obj_desc->type[11] = (char)mc_dec(cmd.params[4], 24, 8);
+       obj_desc->type[12] = (char)mc_dec(cmd.params[4], 32, 8);
+       obj_desc->type[13] = (char)mc_dec(cmd.params[4], 40, 8);
+       obj_desc->type[14] = (char)mc_dec(cmd.params[4], 48, 8);
+       obj_desc->type[15] = (char)mc_dec(cmd.params[4], 56, 8);
+       obj_desc->label[0] = (char)mc_dec(cmd.params[5], 0, 8);
+       obj_desc->label[1] = (char)mc_dec(cmd.params[5], 8, 8);
+       obj_desc->label[2] = (char)mc_dec(cmd.params[5], 16, 8);
+       obj_desc->label[3] = (char)mc_dec(cmd.params[5], 24, 8);
+       obj_desc->label[4] = (char)mc_dec(cmd.params[5], 32, 8);
+       obj_desc->label[5] = (char)mc_dec(cmd.params[5], 40, 8);
+       obj_desc->label[6] = (char)mc_dec(cmd.params[5], 48, 8);
+       obj_desc->label[7] = (char)mc_dec(cmd.params[5], 56, 8);
+       obj_desc->label[8] = (char)mc_dec(cmd.params[6], 0, 8);
+       obj_desc->label[9] = (char)mc_dec(cmd.params[6], 8, 8);
+       obj_desc->label[10] = (char)mc_dec(cmd.params[6], 16, 8);
+       obj_desc->label[11] = (char)mc_dec(cmd.params[6], 24, 8);
+       obj_desc->label[12] = (char)mc_dec(cmd.params[6], 32, 8);
+       obj_desc->label[13] = (char)mc_dec(cmd.params[6], 40, 8);
+       obj_desc->label[14] = (char)mc_dec(cmd.params[6], 48, 8);
+       obj_desc->label[15] = (char)mc_dec(cmd.params[6], 56, 8);
+
+       return 0;
+}
+EXPORT_SYMBOL(dprc_get_obj_desc);
+
+/**
+ * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @obj_type:  Type of the object to set its IRQ
+ * @obj_id:    ID of the object to set its IRQ
+ * @irq_index: The interrupt index to configure
+ * @irq_cfg:   IRQ configuration
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
+                    u32 cmd_flags,
+                    u16 token,
+                    char *obj_type,
+                    int obj_id,
+                    u8 irq_index,
+                    struct dprc_irq_cfg *irq_cfg)
+{
+       struct mc_command cmd = { 0 };
+
+       /* prepare command */
+       cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_IRQ,
+                                         cmd_flags,
+                                         token);
+       cmd.params[0] |= mc_enc(32, 8, irq_index);
+       cmd.params[0] |= mc_enc(0, 32, irq_cfg->val);
+       cmd.params[1] |= mc_enc(0, 64, irq_cfg->paddr);
+       cmd.params[2] |= mc_enc(0, 32, irq_cfg->user_irq_id);
+       cmd.params[2] |= mc_enc(32, 32, obj_id);
+       cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
+       cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
+       cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
+       cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
+       cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
+       cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
+       cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
+       cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
+       cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
+       cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
+       cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
+       cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
+       cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
+       cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
+       cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
+       cmd.params[4] |= mc_enc(56, 8, obj_type[15]);
+
+       /* send command to mc*/
+       return mc_send_command(mc_io, &cmd);
+}
+EXPORT_SYMBOL(dprc_set_obj_irq);
+
+/**
+ * dprc_get_obj_irq() - Get IRQ information from object.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @obj_type:  Type od the object to get its IRQ
+ * @obj_id:    ID of the object to get its IRQ
+ * @irq_index: The interrupt index to configure
+ * @type:      Interrupt type: 0 represents message interrupt
+ *             type (both irq_addr and irq_val are valid)
+ * @irq_cfg:   The returned IRQ attributes
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
+                    u32 cmd_flags,
+                    u16 token,
+                    char *obj_type,
+                    int obj_id,
+                    u8 irq_index,
+                    int *type,
+                    struct dprc_irq_cfg *irq_cfg)
+{
+       struct mc_command cmd = { 0 };
+       int err;
+
+       /* prepare command */
+       cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_IRQ,
+                                         cmd_flags,
+                                         token);
+       cmd.params[0] |= mc_enc(0, 32, obj_id);
+       cmd.params[0] |= mc_enc(32, 8, irq_index);
+       cmd.params[1] |= mc_enc(0, 8, obj_type[0]);
+       cmd.params[1] |= mc_enc(8, 8, obj_type[1]);
+       cmd.params[1] |= mc_enc(16, 8, obj_type[2]);
+       cmd.params[1] |= mc_enc(24, 8, obj_type[3]);
+       cmd.params[1] |= mc_enc(32, 8, obj_type[4]);
+       cmd.params[1] |= mc_enc(40, 8, obj_type[5]);
+       cmd.params[1] |= mc_enc(48, 8, obj_type[6]);
+       cmd.params[1] |= mc_enc(56, 8, obj_type[7]);
+       cmd.params[2] |= mc_enc(0, 8, obj_type[8]);
+       cmd.params[2] |= mc_enc(8, 8, obj_type[9]);
+       cmd.params[2] |= mc_enc(16, 8, obj_type[10]);
+       cmd.params[2] |= mc_enc(24, 8, obj_type[11]);
+       cmd.params[2] |= mc_enc(32, 8, obj_type[12]);
+       cmd.params[2] |= mc_enc(40, 8, obj_type[13]);
+       cmd.params[2] |= mc_enc(48, 8, obj_type[14]);
+       cmd.params[2] |= mc_enc(56, 8, obj_type[15]);
+
+       /* send command to mc*/
+       err = mc_send_command(mc_io, &cmd);
+       if (err)
+               return err;
+
+       /* retrieve response parameters */
+       irq_cfg->val = (u32)mc_dec(cmd.params[0], 0, 32);
+       irq_cfg->paddr = (u64)mc_dec(cmd.params[1], 0, 64);
+       irq_cfg->user_irq_id = (int)mc_dec(cmd.params[2], 0, 32);
+       *type = (int)mc_dec(cmd.params[2], 32, 32);
+
+       return 0;
+}
+EXPORT_SYMBOL(dprc_get_obj_irq);
+
+/**
+ * dprc_get_res_count() - Obtains the number of free resources that are assigned
+ *             to this container, by pool type
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @type:      pool type
+ * @res_count: Returned number of free resources of the given
+ *                     resource type that are assigned to this DPRC
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_res_count(struct fsl_mc_io *mc_io,
-                      uint16_t token,
+                      u32 cmd_flags,
+                      u16 token,
                       char *type,
                       int *res_count)
 {
@@ -621,7 +1221,7 @@ int dprc_get_res_count(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_COUNT,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[1] |= mc_enc(0, 8, type[0]);
        cmd.params[1] |= mc_enc(8, 8, type[1]);
        cmd.params[1] |= mc_enc(16, 8, type[2]);
@@ -651,8 +1251,19 @@ int dprc_get_res_count(struct fsl_mc_io *mc_io,
 }
 EXPORT_SYMBOL(dprc_get_res_count);
 
+/**
+ * dprc_get_res_ids() - Obtains IDs of free resources in the container
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @type:      pool type
+ * @range_desc:        range descriptor
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_res_ids(struct fsl_mc_io *mc_io,
-                    uint16_t token,
+                    u32 cmd_flags,
+                    u16 token,
                     char *type,
                     struct dprc_res_ids_range_desc *range_desc)
 {
@@ -661,7 +1272,7 @@ int dprc_get_res_ids(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(42, 7, range_desc->iter_status);
        cmd.params[1] |= mc_enc(0, 32, range_desc->base_id);
        cmd.params[1] |= mc_enc(32, 32, range_desc->last_id);
@@ -696,36 +1307,24 @@ int dprc_get_res_ids(struct fsl_mc_io *mc_io,
 }
 EXPORT_SYMBOL(dprc_get_res_ids);
 
-int dprc_get_portal_paddr(struct fsl_mc_io *mc_io,
-                         uint16_t token,
-                         int portal_id,
-                         uint64_t *portal_addr)
-{
-       struct mc_command cmd = { 0 };
-       int err;
-
-       /* prepare command */
-       cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_PORTAL_PADDR,
-                                         MC_CMD_PRI_LOW, token);
-       cmd.params[0] |= mc_enc(0, 32, portal_id);
-
-       /* send command to mc*/
-       err = mc_send_command(mc_io, &cmd);
-       if (err)
-               return err;
-
-       /* retrieve response parameters */
-       *portal_addr = mc_dec(cmd.params[1], 0, 64);
-
-       return 0;
-}
-EXPORT_SYMBOL(dprc_get_portal_paddr);
-
+/**
+ * dprc_get_obj_region() - Get region information for a specified object.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @obj_type;  Object type as returned in dprc_get_obj()
+ * @obj_id:    Unique object instance as returned in dprc_get_obj()
+ * @region_index: The specific region to query
+ * @region_desc:  Returns the requested region descriptor
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_get_obj_region(struct fsl_mc_io *mc_io,
-                       uint16_t token,
+                       u32 cmd_flags,
+                       u16 token,
                        char *obj_type,
                        int obj_id,
-                       uint8_t region_index,
+                       u8 region_index,
                        struct dprc_region_desc *region_desc)
 {
        struct mc_command cmd = { 0 };
@@ -733,7 +1332,7 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io,
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_REG,
-                                         MC_CMD_PRI_LOW, token);
+                                         cmd_flags, token);
        cmd.params[0] |= mc_enc(0, 32, obj_id);
        cmd.params[0] |= mc_enc(48, 8, region_index);
        cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
@@ -759,28 +1358,113 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io,
                return err;
 
        /* retrieve response parameters */
-       region_desc->base_paddr = mc_dec(cmd.params[1], 0, 64);
+       region_desc->base_offset = mc_dec(cmd.params[1], 0, 64);
        region_desc->size = mc_dec(cmd.params[2], 0, 32);
 
        return 0;
 }
 EXPORT_SYMBOL(dprc_get_obj_region);
 
+/**
+ * dprc_set_obj_label() - Set object label.
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @obj_type:  Object's type
+ * @obj_id:    Object's ID
+ * @label:     The required label. The maximum length is 16 chars.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
+int dprc_set_obj_label(struct fsl_mc_io *mc_io,
+                      u32 cmd_flags,
+                      u16  token,
+                      char *obj_type,
+                      int  obj_id,
+                      char *label)
+{
+       struct mc_command cmd = { 0 };
+
+       /* prepare command */
+       cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
+                                         cmd_flags,
+                                         token);
+
+       cmd.params[0] |= mc_enc(0, 32, obj_id);
+       cmd.params[1] |= mc_enc(0, 8, label[0]);
+       cmd.params[1] |= mc_enc(8, 8, label[1]);
+       cmd.params[1] |= mc_enc(16, 8, label[2]);
+       cmd.params[1] |= mc_enc(24, 8, label[3]);
+       cmd.params[1] |= mc_enc(32, 8, label[4]);
+       cmd.params[1] |= mc_enc(40, 8, label[5]);
+       cmd.params[1] |= mc_enc(48, 8, label[6]);
+       cmd.params[1] |= mc_enc(56, 8, label[7]);
+       cmd.params[2] |= mc_enc(0, 8, label[8]);
+       cmd.params[2] |= mc_enc(8, 8, label[9]);
+       cmd.params[2] |= mc_enc(16, 8, label[10]);
+       cmd.params[2] |= mc_enc(24, 8, label[11]);
+       cmd.params[2] |= mc_enc(32, 8, label[12]);
+       cmd.params[2] |= mc_enc(40, 8, label[13]);
+       cmd.params[2] |= mc_enc(48, 8, label[14]);
+       cmd.params[2] |= mc_enc(56, 8, label[15]);
+       cmd.params[3] |= mc_enc(0, 8, obj_type[0]);
+       cmd.params[3] |= mc_enc(8, 8, obj_type[1]);
+       cmd.params[3] |= mc_enc(16, 8, obj_type[2]);
+       cmd.params[3] |= mc_enc(24, 8, obj_type[3]);
+       cmd.params[3] |= mc_enc(32, 8, obj_type[4]);
+       cmd.params[3] |= mc_enc(40, 8, obj_type[5]);
+       cmd.params[3] |= mc_enc(48, 8, obj_type[6]);
+       cmd.params[3] |= mc_enc(56, 8, obj_type[7]);
+       cmd.params[4] |= mc_enc(0, 8, obj_type[8]);
+       cmd.params[4] |= mc_enc(8, 8, obj_type[9]);
+       cmd.params[4] |= mc_enc(16, 8, obj_type[10]);
+       cmd.params[4] |= mc_enc(24, 8, obj_type[11]);
+       cmd.params[4] |= mc_enc(32, 8, obj_type[12]);
+       cmd.params[4] |= mc_enc(40, 8, obj_type[13]);
+       cmd.params[4] |= mc_enc(48, 8, obj_type[14]);
+       cmd.params[4] |= mc_enc(56, 8, obj_type[15]);
+
+       /* send command to mc*/
+       return mc_send_command(mc_io, &cmd);
+}
+EXPORT_SYMBOL(dprc_set_obj_label);
+
+/**
+ * dprc_connect() - Connect two endpoints to create a network link between them
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @endpoint1: Endpoint 1 configuration parameters
+ * @endpoint2: Endpoint 2 configuration parameters
+ * @cfg: Connection configuration. The connection configuration is ignored for
+ *     connections made to DPMAC objects, where rate is set according to
+ *     MAC configuration.
+ *     The committed rate is the guaranteed rate for the connection.
+ *     The maximum rate is an upper limit allowed for the connection; it is
+ *     expected to be equal or higher than the committed rate.
+ *     When committed and maximum rates are both zero, the connection is set
+ *     to "best effort" mode, having lower priority compared to connections
+ *     with committed or maximum rates.
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_connect(struct fsl_mc_io *mc_io,
-                uint16_t token,
+                u32 cmd_flags,
+                u16 token,
                 const struct dprc_endpoint *endpoint1,
-                const struct dprc_endpoint *endpoint2)
+                const struct dprc_endpoint *endpoint2,
+                const struct dprc_connection_cfg *cfg)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(0, 32, endpoint1->id);
-       cmd.params[0] |= mc_enc(32, 32, endpoint1->interface_id);
+       cmd.params[0] |= mc_enc(32, 32, endpoint1->if_id);
        cmd.params[1] |= mc_enc(0, 32, endpoint2->id);
-       cmd.params[1] |= mc_enc(32, 32, endpoint2->interface_id);
+       cmd.params[1] |= mc_enc(32, 32, endpoint2->if_id);
        cmd.params[2] |= mc_enc(0, 8, endpoint1->type[0]);
        cmd.params[2] |= mc_enc(8, 8, endpoint1->type[1]);
        cmd.params[2] |= mc_enc(16, 8, endpoint1->type[2]);
@@ -797,6 +1481,8 @@ int dprc_connect(struct fsl_mc_io *mc_io,
        cmd.params[3] |= mc_enc(40, 8, endpoint1->type[13]);
        cmd.params[3] |= mc_enc(48, 8, endpoint1->type[14]);
        cmd.params[3] |= mc_enc(56, 8, endpoint1->type[15]);
+       cmd.params[4] |= mc_enc(0, 32, cfg->max_rate);
+       cmd.params[4] |= mc_enc(32, 32, cfg->committed_rate);
        cmd.params[5] |= mc_enc(0, 8, endpoint2->type[0]);
        cmd.params[5] |= mc_enc(8, 8, endpoint2->type[1]);
        cmd.params[5] |= mc_enc(16, 8, endpoint2->type[2]);
@@ -818,18 +1504,28 @@ int dprc_connect(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+ * dprc_disconnect() - Disconnect one endpoint to remove its network connection
+ * @mc_io:     Pointer to MC portal's I/O object
+ * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
+ * @token:     Token of DPRC object
+ * @endpoint:  Endpoint configuration parameters
+ *
+ * Return:     '0' on Success; Error code otherwise.
+ */
 int dprc_disconnect(struct fsl_mc_io *mc_io,
-                   uint16_t token,
+                   u32 cmd_flags,
+                   u16 token,
                    const struct dprc_endpoint *endpoint)
 {
        struct mc_command cmd = { 0 };
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(0, 32, endpoint->id);
-       cmd.params[0] |= mc_enc(32, 32, endpoint->interface_id);
+       cmd.params[0] |= mc_enc(32, 32, endpoint->if_id);
        cmd.params[1] |= mc_enc(0, 8, endpoint->type[0]);
        cmd.params[1] |= mc_enc(8, 8, endpoint->type[1]);
        cmd.params[1] |= mc_enc(16, 8, endpoint->type[2]);
@@ -851,21 +1547,34 @@ int dprc_disconnect(struct fsl_mc_io *mc_io,
        return mc_send_command(mc_io, &cmd);
 }
 
+/**
+* dprc_get_connection() - Get connected endpoint and link status if connection
+*                      exists.
+* @mc_io:      Pointer to MC portal's I/O object
+* @cmd_flags:  Command flags; one or more of 'MC_CMD_FLAG_'
+* @token:      Token of DPRC object
+* @endpoint1:  Endpoint 1 configuration parameters
+* @endpoint2:  Returned endpoint 2 configuration parameters
+* @state:      Returned link state: 1 - link is up, 0 - link is down
+*
+* Return:     '0' on Success; -ENAVAIL if connection does not exist.
+*/
 int dprc_get_connection(struct fsl_mc_io *mc_io,
-                       uint16_t token,
-                                       const struct dprc_endpoint *endpoint1,
-                                       struct dprc_endpoint *endpoint2,
-                                       int *state)
+                       u32 cmd_flags,
+                       u16 token,
+                       const struct dprc_endpoint *endpoint1,
+                       struct dprc_endpoint *endpoint2,
+                       int *state)
 {
        struct mc_command cmd = { 0 };
        int err;
 
        /* prepare command */
        cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
-                                         MC_CMD_PRI_LOW,
+                                         cmd_flags,
                                          token);
        cmd.params[0] |= mc_enc(0, 32, endpoint1->id);
-       cmd.params[0] |= mc_enc(32, 32, endpoint1->interface_id);
+       cmd.params[0] |= mc_enc(32, 32, endpoint1->if_id);
        cmd.params[1] |= mc_enc(0, 8, endpoint1->type[0]);
        cmd.params[1] |= mc_enc(8, 8, endpoint1->type[1]);
        cmd.params[1] |= mc_enc(16, 8, endpoint1->type[2]);
@@ -890,7 +1599,7 @@ int dprc_get_connection(struct fsl_mc_io *mc_io,
 
        /* retrieve response parameters */
        endpoint2->id = mc_dec(cmd.params[3], 0, 32);
-       endpoint2->interface_id = mc_dec(cmd.params[3], 32, 32);
+       endpoint2->if_id = mc_dec(cmd.params[3], 32, 32);
        endpoint2->type[0] = mc_dec(cmd.params[4], 0, 8);
        endpoint2->type[1] = mc_dec(cmd.params[4], 8, 8);
        endpoint2->type[2] = mc_dec(cmd.params[4], 16, 8);
index e36235ddbe3e249985ac863d151b8df1270395f1..88d1857521a530c07e50c626b91a67f0dc86f315 100644 (file)
@@ -111,7 +111,7 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
                goto out;
 
        resource = mc_dev->resource;
-       if (WARN_ON(resource->data != mc_dev))
+       if (WARN_ON(!resource || resource->data != mc_dev))
                goto out;
 
        mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
@@ -277,14 +277,14 @@ EXPORT_SYMBOL_GPL(fsl_mc_resource_free);
  * portal is allocated from its own MC bus.
  */
 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
-                                       uint16_t mc_io_flags,
+                                       u16 mc_io_flags,
                                        struct fsl_mc_io **new_mc_io)
 {
        struct fsl_mc_device *mc_bus_dev;
        struct fsl_mc_bus *mc_bus;
        phys_addr_t mc_portal_phys_addr;
        size_t mc_portal_size;
-       struct fsl_mc_device *mc_adev;
+       struct fsl_mc_device *dpmcp_dev;
        int error = -EINVAL;
        struct fsl_mc_resource *resource = NULL;
        struct fsl_mc_io *mc_io = NULL;
@@ -304,23 +304,23 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
        if (error < 0)
                return error;
 
-       mc_adev = resource->data;
-       if (WARN_ON(!mc_adev))
+       dpmcp_dev = resource->data;
+       if (WARN_ON(!dpmcp_dev))
                goto error_cleanup_resource;
 
-       if (WARN_ON(mc_adev->obj_desc.region_count == 0))
+       if (WARN_ON(dpmcp_dev->obj_desc.region_count == 0))
                goto error_cleanup_resource;
 
-       mc_portal_phys_addr = mc_adev->regions[0].start;
-       mc_portal_size = mc_adev->regions[0].end -
-                        mc_adev->regions[0].start + 1;
+       mc_portal_phys_addr = dpmcp_dev->regions[0].start;
+       mc_portal_size = dpmcp_dev->regions[0].end -
+                        dpmcp_dev->regions[0].start + 1;
 
        if (WARN_ON(mc_portal_size != mc_bus_dev->mc_io->portal_size))
                goto error_cleanup_resource;
 
        error = fsl_create_mc_io(&mc_bus_dev->dev,
                                 mc_portal_phys_addr,
-                                mc_portal_size, resource,
+                                mc_portal_size, dpmcp_dev,
                                 mc_io_flags, &mc_io);
        if (error < 0)
                goto error_cleanup_resource;
@@ -342,12 +342,22 @@ EXPORT_SYMBOL_GPL(fsl_mc_portal_allocate);
  */
 void fsl_mc_portal_free(struct fsl_mc_io *mc_io)
 {
+       struct fsl_mc_device *dpmcp_dev;
        struct fsl_mc_resource *resource;
 
-       resource = mc_io->resource;
-       if (WARN_ON(resource->type != FSL_MC_POOL_DPMCP))
+       /*
+        * Every mc_io obtained by calling fsl_mc_portal_allocate() is supposed
+        * to have a DPMCP object associated with.
+        */
+       dpmcp_dev = mc_io->dpmcp_dev;
+       if (WARN_ON(!dpmcp_dev))
                return;
-       if (WARN_ON(!resource->data))
+
+       resource = dpmcp_dev->resource;
+       if (WARN_ON(!resource || resource->type != FSL_MC_POOL_DPMCP))
+               return;
+
+       if (WARN_ON(resource->data != dpmcp_dev))
                return;
 
        fsl_destroy_mc_io(mc_io);
@@ -363,31 +373,14 @@ EXPORT_SYMBOL_GPL(fsl_mc_portal_free);
 int fsl_mc_portal_reset(struct fsl_mc_io *mc_io)
 {
        int error;
-       uint16_t token;
-       struct fsl_mc_resource *resource = mc_io->resource;
-       struct fsl_mc_device *mc_dev = resource->data;
+       struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
 
-       if (WARN_ON(resource->type != FSL_MC_POOL_DPMCP))
+       if (WARN_ON(!dpmcp_dev))
                return -EINVAL;
 
-       if (WARN_ON(!mc_dev))
-               return -EINVAL;
-
-       error = dpmcp_open(mc_io, mc_dev->obj_desc.id, &token);
-       if (error < 0) {
-               dev_err(&mc_dev->dev, "dpmcp_open() failed: %d\n", error);
-               return error;
-       }
-
-       error = dpmcp_reset(mc_io, token);
+       error = dpmcp_reset(mc_io, 0, dpmcp_dev->mc_handle);
        if (error < 0) {
-               dev_err(&mc_dev->dev, "dpmcp_reset() failed: %d\n", error);
-               return error;
-       }
-
-       error = dpmcp_close(mc_io, token);
-       if (error < 0) {
-               dev_err(&mc_dev->dev, "dpmcp_close() failed: %d\n", error);
+               dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error);
                return error;
        }
 
@@ -481,30 +474,27 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev)
        enum fsl_mc_pool_type pool_type;
        struct fsl_mc_device *mc_bus_dev;
        struct fsl_mc_bus *mc_bus;
-       int error = -EINVAL;
+       int error;
 
        if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type)))
-               goto error;
+               return -EINVAL;
 
        mc_bus_dev = to_fsl_mc_device(mc_dev->dev.parent);
        if (WARN_ON(mc_bus_dev->dev.bus != &fsl_mc_bus_type))
-               goto error;
+               return -EINVAL;
 
        mc_bus = to_fsl_mc_bus(mc_bus_dev);
        error = object_type_to_pool_type(mc_dev->obj_desc.type, &pool_type);
        if (error < 0)
-               goto error;
+               return error;
 
        error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev);
        if (error < 0)
-               goto error;
+               return error;
 
-       dev_info(&mc_dev->dev,
-                "Allocatable MC object device bound to fsl_mc_allocator driver");
+       dev_dbg(&mc_dev->dev,
+               "Allocatable MC object device bound to fsl_mc_allocator driver");
        return 0;
-error:
-
-       return error;
 }
 
 /**
@@ -513,20 +503,20 @@ error:
  */
 static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
 {
-       int error = -EINVAL;
+       int error;
 
        if (WARN_ON(!FSL_MC_IS_ALLOCATABLE(mc_dev->obj_desc.type)))
-               goto out;
+               return -EINVAL;
 
-       error = fsl_mc_resource_pool_remove_device(mc_dev);
-       if (error < 0)
-               goto out;
+       if (mc_dev->resource) {
+               error = fsl_mc_resource_pool_remove_device(mc_dev);
+               if (error < 0)
+                       return error;
+       }
 
-       dev_info(&mc_dev->dev,
-                "Allocatable MC object device unbound from fsl_mc_allocator driver");
-       error = 0;
-out:
-       return error;
+       dev_dbg(&mc_dev->dev,
+               "Allocatable MC object device unbound from fsl_mc_allocator driver");
+       return 0;
 }
 
 static const struct fsl_mc_device_match_id match_id_table[] = {
index 766a65959b011db69fcddafaa25b44d0029b2126..84db55b4dda5fef12f16e7dafbedc0a91581a830 100644 (file)
@@ -22,6 +22,8 @@
 
 static struct kmem_cache *mc_dev_cache;
 
+static bool fsl_mc_is_root_dprc(struct device *dev);
+
 /**
  * fsl_mc_bus_match - device to driver matching callback
  * @dev: the MC object device structure to match against
@@ -39,7 +41,7 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
        bool major_version_mismatch = false;
        bool minor_version_mismatch = false;
 
-       if (WARN_ON(!fsl_mc_bus_type.dev_root))
+       if (WARN_ON(!fsl_mc_bus_exists()))
                goto out;
 
        if (!mc_drv->match_id_table)
@@ -50,7 +52,7 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
         * Only exception is the root DPRC, which is a special case.
         */
        if ((mc_dev->obj_desc.state & DPRC_OBJ_STATE_PLUGGED) == 0 &&
-           &mc_dev->dev != fsl_mc_bus_type.dev_root)
+           !fsl_mc_is_root_dprc(&mc_dev->dev))
                goto out;
 
        /*
@@ -107,6 +109,8 @@ struct bus_type fsl_mc_bus_type = {
 };
 EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
 
+static atomic_t root_dprc_count = ATOMIC_INIT(0);
+
 static int fsl_mc_driver_probe(struct device *dev)
 {
        struct fsl_mc_driver *mc_drv;
@@ -206,21 +210,61 @@ void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver)
 }
 EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister);
 
+/**
+ * fsl_mc_bus_exists - check if a root dprc exists
+ */
+bool fsl_mc_bus_exists(void)
+{
+       return atomic_read(&root_dprc_count) > 0;
+}
+EXPORT_SYMBOL_GPL(fsl_mc_bus_exists);
+
+/**
+* fsl_mc_get_root_dprc - function to traverse to the root dprc
+*/
+static void fsl_mc_get_root_dprc(struct device *dev,
+                                struct device **root_dprc_dev)
+{
+       if (WARN_ON(!dev)) {
+               *root_dprc_dev = NULL;
+       } else if (WARN_ON(dev->bus != &fsl_mc_bus_type)) {
+               *root_dprc_dev = NULL;
+       } else {
+               *root_dprc_dev = dev;
+               while ((*root_dprc_dev)->parent->bus == &fsl_mc_bus_type)
+                       *root_dprc_dev = (*root_dprc_dev)->parent;
+       }
+}
+
+/**
+ * fsl_mc_is_root_dprc - function to check if a given device is a root dprc
+ */
+static bool fsl_mc_is_root_dprc(struct device *dev)
+{
+       struct device *root_dprc_dev;
+
+       fsl_mc_get_root_dprc(dev, &root_dprc_dev);
+       if (!root_dprc_dev)
+               return false;
+       else
+               return dev == root_dprc_dev;
+}
+
 static int get_dprc_icid(struct fsl_mc_io *mc_io,
-                        int container_id, uint16_t *icid)
+                        int container_id, u16 *icid)
 {
-       uint16_t dprc_handle;
+       u16 dprc_handle;
        struct dprc_attributes attr;
        int error;
 
-       error = dprc_open(mc_io, container_id, &dprc_handle);
+       error = dprc_open(mc_io, 0, container_id, &dprc_handle);
        if (error < 0) {
                pr_err("dprc_open() failed: %d\n", error);
                return error;
        }
 
        memset(&attr, 0, sizeof(attr));
-       error = dprc_get_attributes(mc_io, dprc_handle, &attr);
+       error = dprc_get_attributes(mc_io, 0, dprc_handle, &attr);
        if (error < 0) {
                pr_err("dprc_get_attributes() failed: %d\n", error);
                goto common_cleanup;
@@ -230,20 +274,28 @@ static int get_dprc_icid(struct fsl_mc_io *mc_io,
        error = 0;
 
 common_cleanup:
-       (void)dprc_close(mc_io, dprc_handle);
+       (void)dprc_close(mc_io, 0, dprc_handle);
        return error;
 }
 
-static int translate_mc_addr(uint64_t mc_addr, phys_addr_t *phys_addr)
+static int translate_mc_addr(struct fsl_mc_device *mc_dev,
+                            enum dprc_region_type mc_region_type,
+                            u64 mc_offset, phys_addr_t *phys_addr)
 {
        int i;
-       struct fsl_mc *mc = dev_get_drvdata(fsl_mc_bus_type.dev_root->parent);
+       struct device *root_dprc_dev;
+       struct fsl_mc *mc;
+
+       fsl_mc_get_root_dprc(&mc_dev->dev, &root_dprc_dev);
+       if (WARN_ON(!root_dprc_dev))
+               return -EINVAL;
+       mc = dev_get_drvdata(root_dprc_dev->parent);
 
        if (mc->num_translation_ranges == 0) {
                /*
                 * Do identity mapping:
                 */
-               *phys_addr = mc_addr;
+               *phys_addr = mc_offset;
                return 0;
        }
 
@@ -251,10 +303,11 @@ static int translate_mc_addr(uint64_t mc_addr, phys_addr_t *phys_addr)
                struct fsl_mc_addr_translation_range *range =
                        &mc->translation_ranges[i];
 
-               if (mc_addr >= range->start_mc_addr &&
-                   mc_addr < range->end_mc_addr) {
+               if (mc_region_type == range->mc_region_type &&
+                   mc_offset >= range->start_mc_offset &&
+                   mc_offset < range->end_mc_offset) {
                        *phys_addr = range->start_phys_addr +
-                                    (mc_addr - range->start_mc_addr);
+                                    (mc_offset - range->start_mc_offset);
                        return 0;
                }
        }
@@ -270,6 +323,22 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
        struct resource *regions;
        struct dprc_obj_desc *obj_desc = &mc_dev->obj_desc;
        struct device *parent_dev = mc_dev->dev.parent;
+       enum dprc_region_type mc_region_type;
+
+       if (strcmp(obj_desc->type, "dprc") == 0 ||
+           strcmp(obj_desc->type, "dpmcp") == 0) {
+               mc_region_type = DPRC_REGION_TYPE_MC_PORTAL;
+       } else if (strcmp(obj_desc->type, "dpio") == 0) {
+               mc_region_type = DPRC_REGION_TYPE_QBMAN_PORTAL;
+       } else {
+               /*
+                * This function should not have been called for this MC object
+                * type, as this object type is not supposed to have MMIO
+                * regions
+                */
+               WARN_ON(true);
+               return -EINVAL;
+       }
 
        regions = kmalloc_array(obj_desc->region_count,
                                sizeof(regions[0]), GFP_KERNEL);
@@ -280,6 +349,7 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
                struct dprc_region_desc region_desc;
 
                error = dprc_get_obj_region(mc_bus_dev->mc_io,
+                                           0,
                                            mc_bus_dev->mc_handle,
                                            obj_desc->type,
                                            obj_desc->id, i, &region_desc);
@@ -289,14 +359,15 @@ static int fsl_mc_device_get_mmio_regions(struct fsl_mc_device *mc_dev,
                        goto error_cleanup_regions;
                }
 
-               WARN_ON(region_desc.base_paddr == 0x0);
                WARN_ON(region_desc.size == 0);
-               error = translate_mc_addr(region_desc.base_paddr,
+               error = translate_mc_addr(mc_dev, mc_region_type,
+                                         region_desc.base_offset,
                                          &regions[i].start);
                if (error < 0) {
                        dev_err(parent_dev,
-                               "Invalid MC address: %#llx\n",
-                               region_desc.base_paddr);
+                               "Invalid MC offset: %#x (for %s.%d\'s region %d)\n",
+                               region_desc.base_offset,
+                               obj_desc->type, obj_desc->id, i);
                        goto error_cleanup_regions;
                }
 
@@ -387,8 +458,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
 
                        mc_io2 = mc_io;
 
-                       if (!fsl_mc_bus_type.dev_root)
-                               fsl_mc_bus_type.dev_root = &mc_dev->dev;
+                       atomic_inc(&root_dprc_count);
                }
 
                error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid);
@@ -471,8 +541,12 @@ void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
                        mc_dev->mc_io = NULL;
                }
 
-               if (&mc_dev->dev == fsl_mc_bus_type.dev_root)
-                       fsl_mc_bus_type.dev_root = NULL;
+               if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
+                       if (atomic_read(&root_dprc_count) > 0)
+                               atomic_dec(&root_dprc_count);
+                       else
+                               WARN_ON(1);
+               }
        }
 
        if (mc_bus)
@@ -487,7 +561,7 @@ static int parse_mc_ranges(struct device *dev,
                           int *mc_addr_cells,
                           int *mc_size_cells,
                           const __be32 **ranges_start,
-                          uint8_t *num_ranges)
+                          u8 *num_ranges)
 {
        const __be32 *prop;
        int range_tuple_cell_count;
@@ -535,7 +609,7 @@ static int parse_mc_ranges(struct device *dev,
 static int get_mc_addr_translation_ranges(struct device *dev,
                                          struct fsl_mc_addr_translation_range
                                                **ranges,
-                                         uint8_t *num_ranges)
+                                         u8 *num_ranges)
 {
        int error;
        int paddr_cells;
@@ -574,11 +648,13 @@ static int get_mc_addr_translation_ranges(struct device *dev,
        for (i = 0; i < *num_ranges; ++i) {
                struct fsl_mc_addr_translation_range *range = &(*ranges)[i];
 
-               range->start_mc_addr = of_read_number(cell, mc_addr_cells);
+               range->mc_region_type = of_read_number(cell, 1);
+               range->start_mc_offset = of_read_number(cell + 1,
+                                                       mc_addr_cells - 1);
                cell += mc_addr_cells;
                range->start_phys_addr = of_read_number(cell, paddr_cells);
                cell += paddr_cells;
-               range->end_mc_addr = range->start_mc_addr +
+               range->end_mc_offset = range->start_mc_offset +
                                     of_read_number(cell, mc_size_cells);
 
                cell += mc_size_cells;
@@ -600,7 +676,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
        struct fsl_mc_io *mc_io = NULL;
        int container_id;
        phys_addr_t mc_portal_phys_addr;
-       uint32_t mc_portal_size;
+       u32 mc_portal_size;
        struct mc_version mc_version;
        struct resource res;
 
@@ -630,7 +706,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
        if (error < 0)
                return error;
 
-       error = mc_get_version(mc_io, &mc_version);
+       error = mc_get_version(mc_io, 0, &mc_version);
        if (error != 0) {
                dev_err(&pdev->dev,
                        "mc_get_version() failed with error %d\n", error);
@@ -661,7 +737,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
        if (error < 0)
                goto error_cleanup_mc_io;
 
-       error = dpmng_get_container_id(mc_io, &container_id);
+       error = dpmng_get_container_id(mc_io, 0, &container_id);
        if (error < 0) {
                dev_err(&pdev->dev,
                        "dpmng_get_container_id() failed: %d\n", error);
@@ -673,6 +749,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
        obj_desc.id = container_id;
        obj_desc.ver_major = DPRC_VER_MAJOR;
        obj_desc.ver_minor = DPRC_VER_MINOR;
+       obj_desc.irq_count = 1;
        obj_desc.region_count = 0;
 
        error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev);
@@ -695,7 +772,7 @@ static int fsl_mc_bus_remove(struct platform_device *pdev)
 {
        struct fsl_mc *mc = platform_get_drvdata(pdev);
 
-       if (WARN_ON(&mc->root_mc_bus_dev->dev != fsl_mc_bus_type.dev_root))
+       if (WARN_ON(!fsl_mc_is_root_dprc(&mc->root_mc_bus_dev->dev)))
                return -EINVAL;
 
        fsl_mc_device_remove(mc->root_mc_bus_dev);
@@ -713,6 +790,7 @@ MODULE_DEVICE_TABLE(of, fsl_mc_bus_match_table);
 static struct platform_driver fsl_mc_bus_driver = {
        .driver = {
                   .name = "fsl_mc_bus",
+                  .owner = THIS_MODULE,
                   .pm = NULL,
                   .of_match_table = fsl_mc_bus_match_table,
                   },
index 5737f599f0ef266104797025dae513d0e89fd0fc..6e1489246066d8d9092a933f391fd19e3ab62ff9 100644 (file)
 
 #include "../include/mc-sys.h"
 #include "../include/mc-cmd.h"
+#include "../include/mc.h"
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/ioport.h>
 #include <linux/device.h>
+#include "dpmcp.h"
 
 /**
- * Timeout in jiffies to wait for the completion of an MC command
+ * Timeout in milliseconds to wait for the completion of an MC command
  */
-#define MC_CMD_COMPLETION_TIMEOUT_JIFFIES   (HZ / 2)   /* 500 ms */
+#define MC_CMD_COMPLETION_TIMEOUT_MS   500
 
 /*
  * usleep_range() min and max values used to throttle down polling
@@ -52,7 +54,7 @@
 #define MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS    500
 
 #define MC_CMD_HDR_READ_CMDID(_hdr) \
-       ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S))
+       ((u16)mc_dec((_hdr), MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S))
 
 /**
  * Creates an MC I/O object
@@ -60,8 +62,8 @@
  * @dev: device to be associated with the MC I/O object
  * @mc_portal_phys_addr: physical address of the MC portal to use
  * @mc_portal_size: size in bytes of the MC portal
- * @resource: Pointer to MC bus object allocator resource associated
- * with this MC I/O object or NULL if none.
+ * @dpmcp-dev: Pointer to the DPMCP object associated with this MC I/O
+ * object or NULL if none.
  * @flags: flags for the new MC I/O object
  * @new_mc_io: Area to return pointer to newly created MC I/O object
  *
  */
 int __must_check fsl_create_mc_io(struct device *dev,
                                  phys_addr_t mc_portal_phys_addr,
-                                 uint32_t mc_portal_size,
-                                 struct fsl_mc_resource *resource,
-                                 uint32_t flags, struct fsl_mc_io **new_mc_io)
+                                 u32 mc_portal_size,
+                                 struct fsl_mc_device *dpmcp_dev,
+                                 u32 flags, struct fsl_mc_io **new_mc_io)
 {
+       int error;
        struct fsl_mc_io *mc_io;
        void __iomem *mc_portal_virt_addr;
        struct resource *res;
@@ -85,7 +88,11 @@ int __must_check fsl_create_mc_io(struct device *dev,
        mc_io->flags = flags;
        mc_io->portal_phys_addr = mc_portal_phys_addr;
        mc_io->portal_size = mc_portal_size;
-       mc_io->resource = resource;
+       if (flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)
+               spin_lock_init(&mc_io->spinlock);
+       else
+               mutex_init(&mc_io->mutex);
+
        res = devm_request_mem_region(dev,
                                      mc_portal_phys_addr,
                                      mc_portal_size,
@@ -108,8 +115,18 @@ int __must_check fsl_create_mc_io(struct device *dev,
        }
 
        mc_io->portal_virt_addr = mc_portal_virt_addr;
+       if (dpmcp_dev) {
+               error = fsl_mc_io_set_dpmcp(mc_io, dpmcp_dev);
+               if (error < 0)
+                       goto error_destroy_mc_io;
+       }
+
        *new_mc_io = mc_io;
        return 0;
+
+error_destroy_mc_io:
+       fsl_destroy_mc_io(mc_io);
+       return error;
 }
 EXPORT_SYMBOL_GPL(fsl_create_mc_io);
 
@@ -120,6 +137,11 @@ EXPORT_SYMBOL_GPL(fsl_create_mc_io);
  */
 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io)
 {
+       struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
+
+       if (dpmcp_dev)
+               fsl_mc_io_unset_dpmcp(mc_io);
+
        devm_iounmap(mc_io->dev, mc_io->portal_virt_addr);
        devm_release_mem_region(mc_io->dev,
                                mc_io->portal_phys_addr,
@@ -130,6 +152,57 @@ void fsl_destroy_mc_io(struct fsl_mc_io *mc_io)
 }
 EXPORT_SYMBOL_GPL(fsl_destroy_mc_io);
 
+int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io,
+                       struct fsl_mc_device *dpmcp_dev)
+{
+       int error;
+
+       if (WARN_ON(!dpmcp_dev))
+               return -EINVAL;
+
+       if (WARN_ON(mc_io->dpmcp_dev))
+               return -EINVAL;
+
+       if (WARN_ON(dpmcp_dev->mc_io))
+               return -EINVAL;
+
+       error = dpmcp_open(mc_io,
+                          0,
+                          dpmcp_dev->obj_desc.id,
+                          &dpmcp_dev->mc_handle);
+       if (error < 0)
+               return error;
+
+       mc_io->dpmcp_dev = dpmcp_dev;
+       dpmcp_dev->mc_io = mc_io;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(fsl_mc_io_set_dpmcp);
+
+void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io)
+{
+       int error;
+       struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;
+
+       if (WARN_ON(!dpmcp_dev))
+               return;
+
+       if (WARN_ON(dpmcp_dev->mc_io != mc_io))
+               return;
+
+       error = dpmcp_close(mc_io,
+                           0,
+                           dpmcp_dev->mc_handle);
+       if (error < 0) {
+               dev_err(&dpmcp_dev->dev, "dpmcp_close() failed: %d\n",
+                       error);
+       }
+
+       mc_io->dpmcp_dev = NULL;
+       dpmcp_dev->mc_io = NULL;
+}
+EXPORT_SYMBOL_GPL(fsl_mc_io_unset_dpmcp);
+
 static int mc_status_to_error(enum mc_cmd_status status)
 {
        static const int mc_status_to_error_map[] = {
@@ -224,25 +297,20 @@ static inline enum mc_cmd_status mc_read_response(struct mc_command __iomem *
 }
 
 /**
- * Sends an command to the MC device using the given MC I/O object
+ * Waits for the completion of an MC command doing preemptible polling.
+ * uslepp_range() is called between polling iterations.
  *
  * @mc_io: MC I/O object to be used
- * @cmd: command to be sent
- *
- * Returns '0' on Success; Error code otherwise.
- *
- * NOTE: This function cannot be invoked from from atomic contexts.
+ * @cmd: command buffer to receive MC response
+ * @mc_status: MC command completion status
  */
-int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
+static int mc_polling_wait_preemptible(struct fsl_mc_io *mc_io,
+                                      struct mc_command *cmd,
+                                      enum mc_cmd_status *mc_status)
 {
        enum mc_cmd_status status;
        unsigned long jiffies_until_timeout =
-           jiffies + MC_CMD_COMPLETION_TIMEOUT_JIFFIES;
-
-       /*
-        * Send command to the MC hardware:
-        */
-       mc_write_command(mc_io->portal_virt_addr, cmd);
+               jiffies + msecs_to_jiffies(MC_CMD_COMPLETION_TIMEOUT_MS);
 
        /*
         * Wait for response from the MC hardware:
@@ -271,6 +339,90 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
                }
        }
 
+       *mc_status = status;
+       return 0;
+}
+
+/**
+ * Waits for the completion of an MC command doing atomic polling.
+ * udelay() is called between polling iterations.
+ *
+ * @mc_io: MC I/O object to be used
+ * @cmd: command buffer to receive MC response
+ * @mc_status: MC command completion status
+ */
+static int mc_polling_wait_atomic(struct fsl_mc_io *mc_io,
+                                 struct mc_command *cmd,
+                                 enum mc_cmd_status *mc_status)
+{
+       enum mc_cmd_status status;
+       unsigned long timeout_usecs = MC_CMD_COMPLETION_TIMEOUT_MS * 1000;
+
+       BUILD_BUG_ON((MC_CMD_COMPLETION_TIMEOUT_MS * 1000) %
+                    MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS != 0);
+
+       for (;;) {
+               status = mc_read_response(mc_io->portal_virt_addr, cmd);
+               if (status != MC_CMD_STATUS_READY)
+                       break;
+
+               udelay(MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS);
+               timeout_usecs -= MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS;
+               if (timeout_usecs == 0) {
+                       pr_debug("MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
+                                mc_io->portal_phys_addr,
+                                (unsigned int)
+                                       MC_CMD_HDR_READ_TOKEN(cmd->header),
+                                (unsigned int)
+                                       MC_CMD_HDR_READ_CMDID(cmd->header));
+
+                       return -ETIMEDOUT;
+               }
+       }
+
+       *mc_status = status;
+       return 0;
+}
+
+/**
+ * Sends a command to the MC device using the given MC I/O object
+ *
+ * @mc_io: MC I/O object to be used
+ * @cmd: command to be sent
+ *
+ * Returns '0' on Success; Error code otherwise.
+ */
+int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
+{
+       int error;
+       enum mc_cmd_status status;
+       unsigned long irq_flags = 0;
+
+       if (WARN_ON(in_irq() &&
+                   !(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)))
+               return -EINVAL;
+
+       if (mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)
+               spin_lock_irqsave(&mc_io->spinlock, irq_flags);
+       else
+               mutex_lock(&mc_io->mutex);
+
+       /*
+        * Send command to the MC hardware:
+        */
+       mc_write_command(mc_io->portal_virt_addr, cmd);
+
+       /*
+        * Wait for response from the MC hardware:
+        */
+       if (!(mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL))
+               error = mc_polling_wait_preemptible(mc_io, cmd, &status);
+       else
+               error = mc_polling_wait_atomic(mc_io, cmd, &status);
+
+       if (error < 0)
+               goto common_exit;
+
        if (status != MC_CMD_STATUS_OK) {
                pr_debug("MC command failed: portal: %#llx, obj handle: %#x, command: %#x, status: %s (%#x)\n",
                         mc_io->portal_phys_addr,
@@ -279,9 +431,17 @@ int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd)
                         mc_status_to_string(status),
                         (unsigned int)status);
 
-               return mc_status_to_error(status);
+               error = mc_status_to_error(status);
+               goto common_exit;
        }
 
-       return 0;
+       error = 0;
+common_exit:
+       if (mc_io->flags & FSL_MC_IO_ATOMIC_CONTEXT_PORTAL)
+               spin_unlock_irqrestore(&mc_io->spinlock, irq_flags);
+       else
+               mutex_unlock(&mc_io->mutex);
+
+       return error;
 }
 EXPORT_SYMBOL(mc_send_command);
index 1fd70a21519424b9ebc55a2127032e4c8b9b884d..efa9bf33c1a5024f11ed5cca2f5f0d7a10511c6e 100644 (file)
@@ -34,7 +34,7 @@
 
 /* DPBP Version */
 #define DPBP_VER_MAJOR                         2
-#define DPBP_VER_MINOR                         0
+#define DPBP_VER_MINOR                         1
 
 /* Command IDs */
 #define DPBP_CMDID_CLOSE                               0x800
index 5f3c8e74d2ad016fa68a8f1f79664b626249c24e..37ed951436d5df4a81de99b68eb9655df3160d84 100644 (file)
 
 struct fsl_mc_io;
 
-/**
- * dpbp_open() - Open a control session for the specified object.
- * @mc_io:     Pointer to MC portal's I/O object
- * @dpbp_id:   DPBP unique ID
- * @token:     Returned token; use in subsequent API calls
- *
- * This function can be used to open a control session for an
- * already created object; an object may have been declared in
- * the DPL or by calling the dpbp_create function.
- * This function returns a unique authentication token,
- * associated with the specific object ID and the specific MC
- * portal; this token must be used in all subsequent commands for
- * this specific object
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpbp_open(struct fsl_mc_io *mc_io, int dpbp_id, uint16_t *token);
+int dpbp_open(struct fsl_mc_io *mc_io,
+             u32 cmd_flags,
+             int dpbp_id,
+             u16 *token);
 
-/**
- * dpbp_close() - Close the control session of the object
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- *
- * After this function is called, no further operations are
- * allowed on the object without opening a new control session.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpbp_close(struct fsl_mc_io *mc_io, uint16_t token);
+int dpbp_close(struct fsl_mc_io *mc_io,
+              u32              cmd_flags,
+              u16      token);
 
 /**
- * struct dpbp_cfg() - Structure representing DPBP configuration
+ * struct dpbp_cfg - Structure representing DPBP configuration
  * @options:   place holder
  */
 struct dpbp_cfg {
-       uint32_t options;
+       u32 options;
 };
 
-/**
- * dpbp_create() - Create the DPBP object.
- * @mc_io:     Pointer to MC portal's I/O object
- * @cfg:       Configuration structure
- * @token:     Returned token; use in subsequent API calls
- *
- * Create the DPBP object, allocate required resources and
- * perform required initialization.
- *
- * The object can be created either by declaring it in the
- * DPL file, or by calling this function.
- * This function returns a unique authentication token,
- * associated with the specific object ID and the specific MC
- * portal; this token must be used in all subsequent calls to
- * this specific object. For objects that are created using the
- * DPL file, call dpbp_open function to get an authentication
- * token first.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_create(struct fsl_mc_io       *mc_io,
+               u32             cmd_flags,
                const struct dpbp_cfg   *cfg,
-               uint16_t                *token);
+               u16             *token);
 
-/**
- * dpbp_destroy() - Destroy the DPBP object and release all its resources.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- *
- * Return:     '0' on Success; error code otherwise.
- */
-int dpbp_destroy(struct fsl_mc_io *mc_io, uint16_t token);
+int dpbp_destroy(struct fsl_mc_io *mc_io,
+                u32 cmd_flags,
+                u16 token);
 
-/**
- * dpbp_enable() - Enable the DPBP.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpbp_enable(struct fsl_mc_io *mc_io, uint16_t token);
+int dpbp_enable(struct fsl_mc_io *mc_io,
+               u32 cmd_flags,
+               u16 token);
 
-/**
- * dpbp_disable() - Disable the DPBP.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpbp_disable(struct fsl_mc_io *mc_io, uint16_t token);
+int dpbp_disable(struct fsl_mc_io *mc_io,
+                u32 cmd_flags,
+                u16 token);
 
-/**
- * dpbp_is_enabled() - Check if the DPBP is enabled.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @en:                Returns '1' if object is enabled; '0' otherwise
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpbp_is_enabled(struct fsl_mc_io *mc_io, uint16_t token, int *en);
+int dpbp_is_enabled(struct fsl_mc_io *mc_io,
+                   u32 cmd_flags,
+                   u16 token,
+                   int *en);
 
-/**
- * dpbp_reset() - Reset the DPBP, returns the object to initial state.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpbp_reset(struct fsl_mc_io *mc_io, uint16_t token);
+int dpbp_reset(struct fsl_mc_io *mc_io,
+              u32 cmd_flags,
+              u16 token);
 
 /**
- * dpbp_set_irq() - Set IRQ information for the DPBP to trigger an interrupt.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: Identifies the interrupt index to configure
- * @irq_addr:  Address that must be written to
- *                             signal a message-based interrupt
- * @irq_val:   Value to write into irq_addr address
+ * struct dpbp_irq_cfg - IRQ configuration
+ * @addr:      Address that must be written to signal a message-based interrupt
+ * @val:       Value to write into irq_addr address
  * @user_irq_id: A user defined number associated with this IRQ
- *
- * Return:     '0' on Success; Error code otherwise.
  */
+struct dpbp_irq_cfg {
+            u64                addr;
+            u32                val;
+            int                user_irq_id;
+};
+
 int dpbp_set_irq(struct fsl_mc_io      *mc_io,
-                uint16_t               token,
-                uint8_t                irq_index,
-                uint64_t               irq_addr,
-                uint32_t               irq_val,
-                int                    user_irq_id);
+                u32            cmd_flags,
+                u16            token,
+                u8             irq_index,
+                struct dpbp_irq_cfg    *irq_cfg);
 
-/**
- * dpbp_get_irq() - Get IRQ information from the DPBP.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: The interrupt index to configure
- * @type:      Interrupt type: 0 represents message interrupt
- *                             type (both irq_addr and irq_val are valid)
- * @irq_addr:  Returned address that must be written to
- *                             signal the message-based interrupt
- * @irq_val:   Value to write into irq_addr address
- * @user_irq_id: A user defined number associated with this IRQ
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_get_irq(struct fsl_mc_io      *mc_io,
-                uint16_t               token,
-                uint8_t                irq_index,
+                u32            cmd_flags,
+                u16            token,
+                u8             irq_index,
                 int                    *type,
-                uint64_t               *irq_addr,
-                uint32_t               *irq_val,
-                int                    *user_irq_id);
+                struct dpbp_irq_cfg    *irq_cfg);
 
-/**
- * dpbp_set_irq_enable() - Set overall interrupt state.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: The interrupt index to configure
- * @en:        Interrupt state - enable = 1, disable = 0
- *
- * Allows GPP software to control when interrupts are generated.
- * Each interrupt can have up to 32 causes.  The enable/disable control's the
- * overall interrupt state. if the interrupt is disabled no causes will cause
- * an interrupt.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_set_irq_enable(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
-                       uint8_t                 irq_index,
-                       uint8_t                 en);
+                       u32             cmd_flags,
+                       u16             token,
+                       u8                      irq_index,
+                       u8                      en);
 
-/**
- * dpbp_get_irq_enable() - Get overall interrupt state
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: The interrupt index to configure
- * @en:                Returned interrupt state - enable = 1, disable = 0
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_get_irq_enable(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
-                       uint8_t                 irq_index,
-                       uint8_t                 *en);
+                       u32             cmd_flags,
+                       u16             token,
+                       u8                      irq_index,
+                       u8                      *en);
 
-/**
- * dpbp_set_irq_mask() - Set interrupt mask.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: The interrupt index to configure
- * @mask:      Event mask to trigger interrupt;
- *                     each bit:
- *                             0 = ignore event
- *                             1 = consider event for asserting IRQ
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t          token,
-                     uint8_t           irq_index,
-                     uint32_t          mask);
+                     u32               cmd_flags,
+                     u16               token,
+                     u8                irq_index,
+                     u32               mask);
 
-/**
- * dpbp_get_irq_mask() - Get interrupt mask.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: The interrupt index to configure
- * @mask:      Returned event mask to trigger interrupt
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t          token,
-                     uint8_t           irq_index,
-                     uint32_t          *mask);
+                     u32               cmd_flags,
+                     u16               token,
+                     u8                irq_index,
+                     u32               *mask);
 
-/**
- * dpbp_get_irq_status() - Get the current status of any pending interrupts.
- *
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: The interrupt index to configure
- * @status:    Returned interrupts status - one bit per cause:
- *                     0 = no interrupt pending
- *                     1 = interrupt pending
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_get_irq_status(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
-                       uint8_t                 irq_index,
-                       uint32_t                *status);
+                       u32             cmd_flags,
+                       u16             token,
+                       u8                      irq_index,
+                       u32             *status);
 
-/**
- * dpbp_clear_irq_status() - Clear a pending interrupt's status
- *
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @irq_index: The interrupt index to configure
- * @status:    Bits to clear (W1C) - one bit per cause:
- *                                     0 = don't change
- *                                     1 = clear status bit
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_clear_irq_status(struct fsl_mc_io     *mc_io,
-                         uint16_t              token,
-                         uint8_t               irq_index,
-                         uint32_t              status);
+                         u32           cmd_flags,
+                         u16           token,
+                         u8            irq_index,
+                         u32           status);
 
 /**
  * struct dpbp_attr - Structure representing DPBP attributes
@@ -306,23 +157,15 @@ struct dpbp_attr {
         * @minor:      DPBP minor version
         */
        struct {
-               uint16_t major;
-               uint16_t minor;
+               u16 major;
+               u16 minor;
        } version;
-       uint16_t bpid;
+       u16 bpid;
 };
 
-/**
- * dpbp_get_attributes - Retrieve DPBP attributes.
- *
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPBP object
- * @attr:      Returned object's attributes
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dpbp_get_attributes(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
+                       u32     cmd_flags,
+                       u16             token,
                        struct dpbp_attr        *attr);
 
 /** @} */
index c878d33bfd86cb0df81fa4de3988098dd3b1fa39..536b2ef13507819455c83554c1d31a453f32419e 100644 (file)
@@ -1,40 +1,40 @@
 /* Copyright 2013-2015 Freescale Semiconductor Inc.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-* * Redistributions of source code must retain the above copyright
-* notice, this list of conditions and the following disclaimer.
-* * Redistributions in binary form must reproduce the above copyright
-* notice, this list of conditions and the following disclaimer in the
-* documentation and/or other materials provided with the distribution.
-* * Neither the name of the above-listed copyright holders nor the
-* names of any contributors may be used to endorse or promote products
-* derived from this software without specific prior written permission.
-*
-*
-* ALTERNATIVELY, this software may be distributed under the terms of the
-* GNU General Public License ("GPL") as published by the Free Software
-* Foundation, either version 2 of that License or (at your option) any
-* later version.
-*
-* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
-* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-* POSSIBILITY OF SUCH DAMAGE.
-*/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the above-listed copyright holders nor the
+ * names of any contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ *
+ * ALTERNATIVELY, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") as published by the Free Software
+ * Foundation, either version 2 of that License or (at your option) any
+ * later version.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
 #ifndef _FSL_DPCON_CMD_H
 #define _FSL_DPCON_CMD_H
 
 /* DPCON Version */
 #define DPCON_VER_MAJOR                                2
-#define DPCON_VER_MINOR                                0
+#define DPCON_VER_MINOR                                1
 
 /* Command IDs */
 #define DPCON_CMDID_CLOSE                              0x800
index 1b052b83099386f7e7c4894d8287781cb90ce1c2..e5cfd017f9a59038892521b82d0f37b5e83e6fae 100644 (file)
@@ -41,11 +41,11 @@ struct fsl_mc_io;
 /**
  * Management Complex firmware version information
  */
-#define MC_VER_MAJOR 6
+#define MC_VER_MAJOR 8
 #define MC_VER_MINOR 0
 
 /**
- * struct mc_versoin
+ * struct mc_version
  * @major: Major version number: incremented on API compatibility changes
  * @minor: Minor version number: incremented on API additions (that are
  *             backward compatible); reset when major version is incremented
@@ -53,28 +53,17 @@ struct fsl_mc_io;
  *             and/or bug fixes that have no impact on API
  */
 struct mc_version {
-       uint32_t major;
-       uint32_t minor;
-       uint32_t revision;
+       u32 major;
+       u32 minor;
+       u32 revision;
 };
 
-/**
- * mc_get_version() - Retrieves the Management Complex firmware
- *                     version information
- * @mc_io:             Pointer to opaque I/O object
- * @mc_ver_info:       Returned version information structure
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int mc_get_version(struct fsl_mc_io *mc_io, struct mc_version *mc_ver_info);
+int mc_get_version(struct fsl_mc_io    *mc_io,
+                  u32          cmd_flags,
+                  struct mc_version    *mc_ver_info);
 
-/**
- * dpmng_get_container_id() - Get container ID associated with a given portal.
- * @mc_io:             Pointer to MC portal's I/O object
- * @container_id:      Requested container ID
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dpmng_get_container_id(struct fsl_mc_io *mc_io, int *container_id);
+int dpmng_get_container_id(struct fsl_mc_io    *mc_io,
+                          u32          cmd_flags,
+                          int                  *container_id);
 
 #endif /* __FSL_DPMNG_H */
index f1862a78a409b1e7e7b8c0760052f19abd50c487..c3152f677ff1f67638023d2b902747f7c4b5a28a 100644 (file)
@@ -32,6 +32,8 @@
 #ifndef _FSL_DPRC_H
 #define _FSL_DPRC_H
 
+#include "mc-cmd.h"
+
 /* Data Path Resource Container API
  * Contains DPRC API for managing and querying DPAA resources
  */
@@ -43,7 +45,7 @@ struct fsl_mc_io;
  * container, in case the ICID is not selected by the user and should be
  * allocated by the DPRC from the pool of ICIDs.
  */
-#define DPRC_GET_ICID_FROM_POOL                        (uint16_t)(~(0))
+#define DPRC_GET_ICID_FROM_POOL                        (u16)(~(0))
 
 /**
  * Set this value as the portal_id value in dprc_cfg structure when creating a
@@ -52,29 +54,14 @@ struct fsl_mc_io;
  */
 #define DPRC_GET_PORTAL_ID_FROM_POOL   (int)(~(0))
 
-/**
- * dprc_open() - Open DPRC object for use
- * @mc_io:     Pointer to MC portal's I/O object
- * @container_id: Container ID to open
- * @token:     Returned token of DPRC object
- *
- * Return:     '0' on Success; Error code otherwise.
- *
- * @warning    Required before any operation on the object.
- */
-int dprc_open(struct fsl_mc_io *mc_io, int container_id, uint16_t *token);
+int dprc_open(struct fsl_mc_io *mc_io,
+             u32 cmd_flags,
+             int container_id,
+             u16 *token);
 
-/**
- * dprc_close() - Close the control session of the object
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- *
- * After this function is called, no further operations are
- * allowed on the object without opening a new control session.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dprc_close(struct fsl_mc_io *mc_io, uint16_t token);
+int dprc_close(struct fsl_mc_io *mc_io,
+              u32 cmd_flags,
+              u16 token);
 
 /**
  * Container general options
@@ -115,6 +102,9 @@ int dprc_close(struct fsl_mc_io *mc_io, uint16_t token);
 /* AIOP - Indicates that container belongs to AIOP.  */
 #define DPRC_CFG_OPT_AIOP                      0x00000020
 
+/* IRQ Config - Indicates that the container allowed to configure its IRQs.  */
+#define DPRC_CFG_OPT_IRQ_CFG_ALLOWED           0x00000040
+
 /**
  * struct dprc_cfg - Container configuration options
  * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
@@ -122,94 +112,49 @@ int dprc_close(struct fsl_mc_io *mc_io, uint16_t token);
  * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
  *             portal ID is allocated by the DPRC
  * @options: Combination of 'DPRC_CFG_OPT_<X>' options
+ * @label: Object's label
  */
 struct dprc_cfg {
-       uint16_t icid;
+       u16 icid;
        int portal_id;
-       uint64_t options;
+       u64 options;
+       char label[16];
 };
 
-/**
- * dprc_create_container() - Create child container
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @cfg:       Child container configuration
- * @child_container_id:        Returned child container ID
- * @child_portal_paddr:        Returned base physical address of the
- *                                     child portal
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_create_container(struct fsl_mc_io     *mc_io,
-                         uint16_t              token,
+                         u32           cmd_flags,
+                         u16           token,
                          struct dprc_cfg       *cfg,
                          int                   *child_container_id,
-                         uint64_t              *child_portal_paddr);
+                         u64           *child_portal_offset);
 
-/**
- * dprc_destroy_container() - Destroy child container.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @child_container_id:        ID of the container to destroy
- *
- * This function terminates the child container, so following this call the
- * child container ID becomes invalid.
- *
- * Notes:
- * - All resources and objects of the destroyed container are returned to the
- * parent container or destroyed if were created be the destroyed container.
- * - This function destroy all the child containers of the specified
- *   container prior to destroying the container itself.
- *
- * warning: Only the parent container is allowed to destroy a child policy
- *             Container 0 can't be destroyed
- *
- * Return:     '0' on Success; Error code otherwise.
- *
- */
 int dprc_destroy_container(struct fsl_mc_io    *mc_io,
-                          uint16_t             token,
+                          u32          cmd_flags,
+                          u16          token,
                           int                  child_container_id);
 
-/**
- * dprc_reset_container - Reset child container.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @child_container_id:        ID of the container to reset
- *
- * In case a software context crashes or becomes non-responsive, the parent
- * may wish to reset its resources container before the software context is
- * restarted.
- *
- * This routine informs all objects assigned to the child container that the
- * container is being reset, so they may perform any cleanup operations that are
- * needed. All objects handles that were owned by the child container shall be
- * closed.
- *
- * Note that such request may be submitted even if the child software context
- * has not crashed, but the resulting object cleanup operations will not be
- * aware of that.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_reset_container(struct fsl_mc_io *mc_io,
-                        uint16_t token,
+                        u32 cmd_flags,
+                        u16 token,
                         int child_container_id);
 
 /* IRQ */
 
+/* IRQ index */
+#define DPRC_IRQ_INDEX          0
+
 /* Number of dprc's IRQs */
 #define DPRC_NUM_OF_IRQS               1
 
-/* Object irq events */
+/* DPRC IRQ events */
 
-/* IRQ event - Indicates that a new object assigned to the container */
+/* IRQ event - Indicates that a new object added to the container */
 #define DPRC_IRQ_EVENT_OBJ_ADDED               0x00000001
-/* IRQ event - Indicates that an object was unassigned from the container */
+/* IRQ event - Indicates that an object was removed from the container */
 #define DPRC_IRQ_EVENT_OBJ_REMOVED             0x00000002
-/* IRQ event - Indicates that resources assigned to the container */
+/* IRQ event - Indicates that resources added to the container */
 #define DPRC_IRQ_EVENT_RES_ADDED               0x00000004
-/* IRQ event - Indicates that resources unassigned from the container */
+/* IRQ event - Indicates that resources removed from the container */
 #define DPRC_IRQ_EVENT_RES_REMOVED             0x00000008
 /* IRQ event - Indicates that one of the descendant containers that opened by
  * this container is destroyed
@@ -225,147 +170,65 @@ int dprc_reset_container(struct fsl_mc_io *mc_io,
 #define DPRC_IRQ_EVENT_OBJ_CREATED             0x00000040
 
 /**
- * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index: Identifies the interrupt index to configure
- * @irq_addr:  Address that must be written to
- *                     signal a message-based interrupt
- * @irq_val:   Value to write into irq_addr address
- * @user_irq_id: Returned a user defined number associated with this IRQ
- *
- * Return:     '0' on Success; Error code otherwise.
+ * struct dprc_irq_cfg - IRQ configuration
+ * @paddr:     Address that must be written to signal a message-based interrupt
+ * @val:       Value to write into irq_addr address
+ * @user_irq_id: A user defined number associated with this IRQ
  */
+struct dprc_irq_cfg {
+            u64                paddr;
+            u32                val;
+            int                user_irq_id;
+};
+
 int dprc_set_irq(struct fsl_mc_io      *mc_io,
-                uint16_t               token,
-                uint8_t                irq_index,
-                uint64_t               irq_addr,
-                uint32_t               irq_val,
-                int                    user_irq_id);
+                u32            cmd_flags,
+                u16            token,
+                u8             irq_index,
+                struct dprc_irq_cfg    *irq_cfg);
 
-/**
- * dprc_get_irq() - Get IRQ information from the DPRC.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index: The interrupt index to configure
- * @type:      Returned interrupt type: 0 represents message interrupt
- *                     type (both irq_addr and irq_val are valid)
- * @irq_addr:  Returned address that must be written to
- *                     signal the message-based interrupt
- * @irq_val:   Value to write into irq_addr address
- * @user_irq_id: A user defined number associated with this IRQ
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_irq(struct fsl_mc_io      *mc_io,
-                uint16_t               token,
-                uint8_t                irq_index,
+                u32            cmd_flags,
+                u16            token,
+                u8             irq_index,
                 int                    *type,
-                uint64_t               *irq_addr,
-                uint32_t               *irq_val,
-                int                    *user_irq_id);
+                struct dprc_irq_cfg    *irq_cfg);
 
-/**
- * dprc_set_irq_enable() - Set overall interrupt state.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index: The interrupt index to configure
- * @en:                Interrupt state - enable = 1, disable = 0
- *
- * Allows GPP software to control when interrupts are generated.
- * Each interrupt can have up to 32 causes.  The enable/disable control's the
- * overall interrupt state. if the interrupt is disabled no causes will cause
- * an interrupt.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_set_irq_enable(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
-                       uint8_t                 irq_index,
-                       uint8_t                 en);
+                       u32             cmd_flags,
+                       u16             token,
+                       u8                      irq_index,
+                       u8                      en);
 
-/**
- * dprc_get_irq_enable() - Get overall interrupt state.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index:  The interrupt index to configure
- * @en:                Returned interrupt state - enable = 1, disable = 0
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_irq_enable(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
-                       uint8_t                 irq_index,
-                       uint8_t                 *en);
+                       u32             cmd_flags,
+                       u16             token,
+                       u8                      irq_index,
+                       u8                      *en);
 
-/**
- * dprc_set_irq_mask() - Set interrupt mask.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index: The interrupt index to configure
- * @mask:      event mask to trigger interrupt;
- *                     each bit:
- *                             0 = ignore event
- *                             1 = consider event for asserting irq
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t          token,
-                     uint8_t           irq_index,
-                     uint32_t          mask);
+                     u32               cmd_flags,
+                     u16               token,
+                     u8                irq_index,
+                     u32               mask);
 
-/**
- * dprc_get_irq_mask() - Get interrupt mask.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index: The interrupt index to configure
- * @mask:      Returned event mask to trigger interrupt
- *
- * Every interrupt can have up to 32 causes and the interrupt model supports
- * masking/unmasking each cause independently
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
-                     uint16_t          token,
-                     uint8_t           irq_index,
-                     uint32_t          *mask);
+                     u32               cmd_flags,
+                     u16               token,
+                     u8                irq_index,
+                     u32               *mask);
 
-/**
- * dprc_get_irq_status() - Get the current status of any pending interrupts.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index: The interrupt index to configure
- * @status:    Returned interrupts status - one bit per cause:
- *                     0 = no interrupt pending
- *                     1 = interrupt pending
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_irq_status(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
-                       uint8_t                 irq_index,
-                       uint32_t                *status);
+                       u32             cmd_flags,
+                       u16             token,
+                       u8                      irq_index,
+                       u32             *status);
 
-/**
- * dprc_clear_irq_status() - Clear a pending interrupt's status
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @irq_index: The interrupt index to configure
- * @status:    bits to clear (W1C) - one bit per cause:
- *                                     0 = don't change
- *                                     1 = clear status bit
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_clear_irq_status(struct fsl_mc_io     *mc_io,
-                         uint16_t              token,
-                         uint8_t               irq_index,
-                         uint32_t              status);
+                         u32           cmd_flags,
+                         u16           token,
+                         u8            irq_index,
+                         u32           status);
 
 /**
  * struct dprc_attributes - Container attributes
@@ -377,81 +240,38 @@ int dprc_clear_irq_status(struct fsl_mc_io        *mc_io,
  */
 struct dprc_attributes {
        int container_id;
-       uint16_t icid;
+       u16 icid;
        int portal_id;
-       uint64_t options;
+       u64 options;
        /**
         * struct version - DPRC version
         * @major: DPRC major version
         * @minor: DPRC minor version
         */
        struct {
-               uint16_t major;
-               uint16_t minor;
+               u16 major;
+               u16 minor;
        } version;
 };
 
-/**
- * dprc_get_attributes() - Obtains container attributes
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @attributes Returned container attributes
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_attributes(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
+                       u32             cmd_flags,
+                       u16             token,
                        struct dprc_attributes  *attributes);
 
-/**
- * dprc_set_res_quota() - Set allocation policy for a specific resource/object
- *             type in a child container
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @child_container_id:        ID of the child container
- * @type:      Resource/object type
- * @quota:     Sets the maximum number of resources of the selected type
- *             that the child container is allowed to allocate from its parent;
- *             when quota is set to -1, the policy is the same as container's
- *             general policy.
- *
- * Allocation policy determines whether or not a container may allocate
- * resources from its parent. Each container has a 'global' allocation policy
- * that is set when the container is created.
- *
- * This function sets allocation policy for a specific resource type.
- * The default policy for all resource types matches the container's 'global'
- * allocation policy.
- *
- * Return:     '0' on Success; Error code otherwise.
- *
- * @warning    Only the parent container is allowed to change a child policy.
- */
 int dprc_set_res_quota(struct fsl_mc_io        *mc_io,
-                      uint16_t         token,
+                      u32              cmd_flags,
+                      u16              token,
                       int              child_container_id,
                       char             *type,
-                      uint16_t         quota);
+                      u16              quota);
 
-/**
- * dprc_get_res_quota() - Gets the allocation policy of a specific
- *             resource/object type in a child container
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @child_container_id;        ID of the child container
- * @type:      resource/object type
- * @quota:     Returnes the maximum number of resources of the selected type
- *             that the child container is allowed to allocate from the parent;
- *             when quota is set to -1, the policy is the same as container's
- *             general policy.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_res_quota(struct fsl_mc_io        *mc_io,
-                      uint16_t         token,
+                      u32              cmd_flags,
+                      u16              token,
                       int              child_container_id,
                       char             *type,
-                      uint16_t         *quota);
+                      u16              *quota);
 
 /* Resource request options */
 
@@ -492,106 +312,38 @@ int dprc_get_res_quota(struct fsl_mc_io  *mc_io,
  */
 struct dprc_res_req {
        char type[16];
-       uint32_t num;
-       uint32_t options;
+       u32 num;
+       u32 options;
        int id_base_align;
 };
 
-/**
- * dprc_assign() - Assigns objects or resource to a child container.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @container_id: ID of the child container
- * @res_req:   Describes the type and amount of resources to
- *                     assign to the given container
- *
- * Assignment is usually done by a parent (this DPRC) to one of its child
- * containers.
- *
- * According to the DPRC allocation policy, the assigned resources may be taken
- * (allocated) from the container's ancestors, if not enough resources are
- * available in the container itself.
- *
- * The type of assignment depends on the dprc_res_req options, as follows:
- * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
- *   the explicit base ID specified at the id_base_align field of res_req.
- * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
- *   aligned to the value given at id_base_align field of res_req.
- * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
- *   and indicates that the object must be set to the plugged state.
- *
- * A container may use this function with its own ID in order to change a
- * object state to plugged or unplugged.
- *
- * If IRQ information has been set in the child DPRC, it will signal an
- * interrupt following every change in its object assignment.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_assign(struct fsl_mc_io       *mc_io,
-               uint16_t                token,
+               u32             cmd_flags,
+               u16             token,
                int                     container_id,
                struct dprc_res_req     *res_req);
 
-/**
- * dprc_unassign() - Un-assigns objects or resources from a child container
- *             and moves them into this (parent) DPRC.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @child_container_id:        ID of the child container
- * @res_req:   Describes the type and amount of resources to un-assign from
- *             the child container
- *
- * Un-assignment of objects can succeed only if the object is not in the
- * plugged or opened state.
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_unassign(struct fsl_mc_io     *mc_io,
-                 uint16_t              token,
+                 u32           cmd_flags,
+                 u16           token,
                  int                   child_container_id,
                  struct dprc_res_req   *res_req);
 
-/**
- * dprc_get_pool_count() - Get the number of dprc's pools
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @pool_count:        Returned number of resource pools in the dprc
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_pool_count(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
+                       u32             cmd_flags,
+                       u16             token,
                        int                     *pool_count);
 
-/**
- * dprc_get_pool() - Get the type (string) of a certain dprc's pool
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @pool_index;        Index of the pool to be queried (< pool_count)
- * @type:      The type of the pool
- *
- * The pool types retrieved one by one by incrementing
- * pool_index up to (not including) the value of pool_count returned
- * from dprc_get_pool_count(). dprc_get_pool_count() must
- * be called prior to dprc_get_pool().
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_pool(struct fsl_mc_io     *mc_io,
-                 uint16_t              token,
+                 u32           cmd_flags,
+                 u16           token,
                  int                   pool_index,
                  char                  *type);
 
-/**
- * dprc_get_obj_count() - Obtains the number of objects in the DPRC
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @obj_count: Number of objects assigned to the DPRC
- *
- * Return:     '0' on Success; Error code otherwise.
- */
-int dprc_get_obj_count(struct fsl_mc_io *mc_io, uint16_t token, int *obj_count);
+int dprc_get_obj_count(struct fsl_mc_io *mc_io,
+                      u32              cmd_flags,
+                      u16              token,
+                      int              *obj_count);
 
 /* Objects Attributes Flags */
 
@@ -610,50 +362,53 @@ int dprc_get_obj_count(struct fsl_mc_io *mc_io, uint16_t token, int *obj_count);
  * @irq_count: Number of interrupts supported by the object
  * @region_count: Number of mappable regions supported by the object
  * @state: Object state: combination of DPRC_OBJ_STATE_ states
+ * @label: Object label
  */
 struct dprc_obj_desc {
        char type[16];
        int id;
-       uint16_t vendor;
-       uint16_t ver_major;
-       uint16_t ver_minor;
-       uint8_t irq_count;
-       uint8_t region_count;
-       uint32_t state;
+       u16 vendor;
+       u16 ver_major;
+       u16 ver_minor;
+       u8 irq_count;
+       u8 region_count;
+       u32 state;
+       char label[16];
 };
 
-/**
- * dprc_get_obj() - Get general information on an object
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @obj_index: Index of the object to be queried (< obj_count)
- * @obj_desc:  Returns the requested object descriptor
- *
- * The object descriptors are retrieved one by one by incrementing
- * obj_index up to (not including) the value of obj_count returned
- * from dprc_get_obj_count(). dprc_get_obj_count() must
- * be called prior to dprc_get_obj().
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_obj(struct fsl_mc_io      *mc_io,
-                uint16_t               token,
+                u32            cmd_flags,
+                u16            token,
                 int                    obj_index,
                 struct dprc_obj_desc   *obj_desc);
 
-/**
- * dprc_get_res_count() - Obtains the number of free resources that are assigned
- *             to this container, by pool type
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @type:      pool type
- * @res_count: Returned number of free resources of the given
- *                     resource type that are assigned to this DPRC
- *
- * Return:     '0' on Success; Error code otherwise.
- */
+int dprc_get_obj_desc(struct fsl_mc_io         *mc_io,
+                     u32               cmd_flags,
+                       u16             token,
+                       char                    *obj_type,
+                       int                     obj_id,
+                       struct dprc_obj_desc    *obj_desc);
+
+int dprc_set_obj_irq(struct fsl_mc_io          *mc_io,
+                    u32                        cmd_flags,
+                    u16                        token,
+                    char                       *obj_type,
+                    int                        obj_id,
+                    u8                 irq_index,
+                    struct dprc_irq_cfg        *irq_cfg);
+
+int dprc_get_obj_irq(struct fsl_mc_io          *mc_io,
+                    u32                        cmd_flags,
+                    u16                        token,
+                    char                       *obj_type,
+                    int                        obj_id,
+                    u8                 irq_index,
+                    int                        *type,
+                    struct dprc_irq_cfg        *irq_cfg);
+
 int dprc_get_res_count(struct fsl_mc_io        *mc_io,
-                      uint16_t         token,
+                      u32              cmd_flags,
+                      u16              token,
                       char             *type,
                       int              *res_count);
 
@@ -684,115 +439,98 @@ struct dprc_res_ids_range_desc {
        enum dprc_iter_status iter_status;
 };
 
-/**
- * dprc_get_res_ids() - Obtains IDs of free resources in the container
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @type:      pool type
- * @range_desc:        range descriptor
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_res_ids(struct fsl_mc_io                  *mc_io,
-                    uint16_t                           token,
+                    u32                                cmd_flags,
+                    u16                                token,
                     char                               *type,
                     struct dprc_res_ids_range_desc     *range_desc);
 
+/* Region flags */
+/* Cacheable - Indicates that region should be mapped as cacheable */
+#define DPRC_REGION_CACHEABLE  0x00000001
+
 /**
- * dprc_get_portal_paddr() - Get the physical address of MC portals
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @portal_id: MC portal ID
- * @portal_addr: The physical address of the MC portal ID
- *
- * Return:     '0' on Success; Error code otherwise.
+ * enum dprc_region_type - Region type
+ * @DPRC_REGION_TYPE_MC_PORTAL: MC portal region
+ * @DPRC_REGION_TYPE_QBMAN_PORTAL: Qbman portal region
  */
-int dprc_get_portal_paddr(struct fsl_mc_io     *mc_io,
-                         uint16_t              token,
-                         int                   portal_id,
-                         uint64_t              *portal_addr);
+enum dprc_region_type {
+       DPRC_REGION_TYPE_MC_PORTAL,
+       DPRC_REGION_TYPE_QBMAN_PORTAL
+};
 
 /**
  * struct dprc_region_desc - Mappable region descriptor
- * @base_paddr: Region base physical address
+ * @base_offset: Region offset from region's base address.
+ *     For DPMCP and DPRC objects, region base is offset from SoC MC portals
+ *     base address; For DPIO, region base is offset from SoC QMan portals
+ *     base address
  * @size: Region size (in bytes)
+ * @flags: Region attributes
+ * @type: Portal region type
  */
 struct dprc_region_desc {
-       uint64_t base_paddr;
-       uint32_t size;
+       u32 base_offset;
+       u32 size;
+       u32 flags;
+       enum dprc_region_type type;
 };
 
-/**
- * dprc_get_obj_region() - Get region information for a specified object.
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @obj_type;  Object type as returned in dprc_get_obj()
- * @obj_id:    Unique object instance as returned in dprc_get_obj()
- * @region_index: The specific region to query
- * @region_desc:  Returns the requested region descriptor
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_get_obj_region(struct fsl_mc_io       *mc_io,
-                       uint16_t                token,
+                       u32             cmd_flags,
+                       u16             token,
                        char                    *obj_type,
                        int                     obj_id,
-                       uint8_t                 region_index,
+                       u8                      region_index,
                        struct dprc_region_desc *region_desc);
 
+int dprc_set_obj_label(struct fsl_mc_io        *mc_io,
+                      u32              cmd_flags,
+                      u16              token,
+                      char             *obj_type,
+                      int              obj_id,
+                      char             *label);
+
 /**
  * struct dprc_endpoint - Endpoint description for link connect/disconnect
  *                     operations
  * @type: Endpoint object type: NULL terminated string
  * @id: Endpoint object ID
- * @interface_id: Interface ID; should be set for endpoints with multiple
+ * @if_id: Interface ID; should be set for endpoints with multiple
  *             interfaces ("dpsw", "dpdmux"); for others, always set to 0
  */
 struct dprc_endpoint {
        char type[16];
        int id;
-       int interface_id;
+       int if_id;
 };
 
 /**
- * dprc_connect() - Connect two endpoints to create a network link between them
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @endpoint1: Endpoint 1 configuration parameters
- * @endpoint2: Endpoint 2 configuration parameters
- *
- * Return:     '0' on Success; Error code otherwise.
+ * struct dprc_connection_cfg - Connection configuration.
+ *                             Used for virtual connections only
+ * @committed_rate: Committed rate (Mbits/s)
+ * @max_rate: Maximum rate (Mbits/s)
  */
+struct dprc_connection_cfg {
+       u32 committed_rate;
+       u32 max_rate;
+};
+
 int dprc_connect(struct fsl_mc_io              *mc_io,
-                uint16_t                       token,
+                u32                    cmd_flags,
+                u16                    token,
                 const struct dprc_endpoint     *endpoint1,
-                const struct dprc_endpoint     *endpoint2);
+                const struct dprc_endpoint     *endpoint2,
+                const struct dprc_connection_cfg *cfg);
 
-/**
- * dprc_disconnect() - Disconnect one endpoint to remove its network connection
- * @mc_io:     Pointer to MC portal's I/O object
- * @token:     Token of DPRC object
- * @endpoint:  Endpoint configuration parameters
- *
- * Return:     '0' on Success; Error code otherwise.
- */
 int dprc_disconnect(struct fsl_mc_io           *mc_io,
-                   uint16_t                    token,
+                   u32                 cmd_flags,
+                   u16                 token,
                    const struct dprc_endpoint  *endpoint);
 
-/**
-* dprc_get_connection() - Get connected endpoint and link status if connection
-*                      exists.
-* @mc_io               Pointer to MC portal's I/O object
-* @token               Token of DPRC object
-* @endpoint1   Endpoint 1 configuration parameters
-* @endpoint2   Returned endpoint 2 configuration parameters
-* @state:      Returned link state: 1 - link is up, 0 - link is down
-*
-* Return:     '0' on Success; -ENAVAIL if connection does not exist.
-*/
 int dprc_get_connection(struct fsl_mc_io               *mc_io,
-                       uint16_t                        token,
+                       u32                     cmd_flags,
+                       u16                     token,
                        const struct dprc_endpoint      *endpoint1,
                        struct dprc_endpoint            *endpoint2,
                        int                             *state);
index 32501e020054d8a1ba76fe887318f09c7f961993..65277e3de44d537ca51df63f98768374f7884847 100644 (file)
 #define MC_CMD_NUM_OF_PARAMS   7
 
 #define MAKE_UMASK64(_width) \
-       ((uint64_t)((_width) < 64 ? ((uint64_t)1 << (_width)) - 1 : -1))
+       ((u64)((_width) < 64 ? ((u64)1 << (_width)) - 1 : -1))
 
-static inline uint64_t mc_enc(int lsoffset, int width, uint64_t val)
+static inline u64 mc_enc(int lsoffset, int width, u64 val)
 {
-       return (uint64_t)(((uint64_t)val & MAKE_UMASK64(width)) << lsoffset);
+       return (u64)(((u64)val & MAKE_UMASK64(width)) << lsoffset);
 }
 
-static inline uint64_t mc_dec(uint64_t val, int lsoffset, int width)
+static inline u64 mc_dec(u64 val, int lsoffset, int width)
 {
-       return (uint64_t)((val >> lsoffset) & MAKE_UMASK64(width));
+       return (u64)((val >> lsoffset) & MAKE_UMASK64(width));
 }
 
 struct mc_command {
-       uint64_t header;
-       uint64_t params[MC_CMD_NUM_OF_PARAMS];
+       u64 header;
+       u64 params[MC_CMD_NUM_OF_PARAMS];
 };
 
 enum mc_cmd_status {
@@ -67,24 +67,41 @@ enum mc_cmd_status {
        MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */
 };
 
+/*
+ * MC command flags
+ */
+
+/* High priority flag */
+#define MC_CMD_FLAG_PRI                0x00008000
+/* Command completion flag */
+#define MC_CMD_FLAG_INTR_DIS   0x01000000
+
+/*
+ * TODO Remove following two defines after completion of flib 8.0.0
+ * integration
+ */
+#define MC_CMD_PRI_LOW         0 /*!< Low Priority command indication */
+#define MC_CMD_PRI_HIGH                1 /*!< High Priority command indication */
+
 #define MC_CMD_HDR_CMDID_O     52      /* Command ID field offset */
 #define MC_CMD_HDR_CMDID_S     12      /* Command ID field size */
 #define MC_CMD_HDR_TOKEN_O     38      /* Token field offset */
 #define MC_CMD_HDR_TOKEN_S     10      /* Token field size */
 #define MC_CMD_HDR_STATUS_O    16      /* Status field offset */
 #define MC_CMD_HDR_STATUS_S    8       /* Status field size*/
-#define MC_CMD_HDR_PRI_O       15      /* Priority field offset */
-#define MC_CMD_HDR_PRI_S       1       /* Priority field size */
+#define MC_CMD_HDR_FLAGS_O     0       /* Flags field offset */
+#define MC_CMD_HDR_FLAGS_S     32      /* Flags field size*/
+#define MC_CMD_HDR_FLAGS_MASK  0xFF00FF00 /* Command flags mask */
 
 #define MC_CMD_HDR_READ_STATUS(_hdr) \
        ((enum mc_cmd_status)mc_dec((_hdr), \
                MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S))
 
 #define MC_CMD_HDR_READ_TOKEN(_hdr) \
-       ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S))
+       ((u16)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S))
 
-#define MC_CMD_PRI_LOW         0 /* Low Priority command indication */
-#define MC_CMD_PRI_HIGH                1 /* High Priority command indication */
+#define MC_CMD_HDR_READ_FLAGS(_hdr) \
+       ((u32)mc_dec((_hdr), MC_CMD_HDR_FLAGS_O, MC_CMD_HDR_FLAGS_S))
 
 #define MC_EXT_OP(_ext, _param, _offset, _width, _type, _arg) \
        ((_ext)[_param] |= mc_enc((_offset), (_width), _arg))
@@ -95,15 +112,16 @@ enum mc_cmd_status {
 #define MC_RSP_OP(_cmd, _param, _offset, _width, _type, _arg) \
        (_arg = (_type)mc_dec(_cmd.params[_param], (_offset), (_width)))
 
-static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id,
-                                           uint8_t priority,
-                                           uint16_t token)
+static inline u64 mc_encode_cmd_header(u16 cmd_id,
+                                      u32 cmd_flags,
+                                      u16 token)
 {
-       uint64_t hdr;
+       u64 hdr;
 
        hdr = mc_enc(MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S, cmd_id);
+       hdr |= mc_enc(MC_CMD_HDR_FLAGS_O, MC_CMD_HDR_FLAGS_S,
+                      (cmd_flags & MC_CMD_HDR_FLAGS_MASK));
        hdr |= mc_enc(MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S, token);
-       hdr |= mc_enc(MC_CMD_HDR_PRI_O, MC_CMD_HDR_PRI_S, priority);
        hdr |= mc_enc(MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S,
                       MC_CMD_STATUS_READY);
 
index c045f49f227e6a84d85b061a9347d61326d2bfad..c706f778626e7e541dd734121b93b2f72665fadf 100644 (file)
 /**
  * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
  * @root_mc_bus_dev: MC object device representing the root DPRC
- * @addr_translation_ranges: array of bus to system address translation ranges
+ * @num_translation_ranges: number of entries in addr_translation_ranges
+ * @translation_ranges: array of bus to system address translation ranges
  */
 struct fsl_mc {
        struct fsl_mc_device *root_mc_bus_dev;
-       uint8_t num_translation_ranges;
+       u8 num_translation_ranges;
        struct fsl_mc_addr_translation_range *translation_ranges;
 };
 
 /**
  * struct fsl_mc_addr_translation_range - bus to system address translation
  * range
- * @start_mc_addr: Start MC address of the range being translated
- * @end_mc_addr: MC address of the first byte after the range (last MC
- * address of the range is end_mc_addr - 1)
+ * @mc_region_type: Type of MC region for the range being translated
+ * @start_mc_offset: Start MC offset of the range being translated
+ * @end_mc_offset: MC offset of the first byte after the range (last MC
+ * offset of the range is end_mc_offset - 1)
  * @start_phys_addr: system physical address corresponding to start_mc_addr
  */
 struct fsl_mc_addr_translation_range {
-       uint64_t start_mc_addr;
-       uint64_t end_mc_addr;
+       enum dprc_region_type mc_region_type;
+       u64 start_mc_offset;
+       u64 end_mc_offset;
        phys_addr_t start_phys_addr;
 };
 
@@ -100,7 +103,7 @@ int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev);
 
 int __init dprc_driver_init(void);
 
-void __exit dprc_driver_exit(void);
+void dprc_driver_exit(void);
 
 int __init fsl_mc_allocator_driver_init(void);
 
index cb3b5a296615e04a09ece023944ccedfecd69fc2..c5038cc77240667b0c46ff85a0dd4b49d9e603c5 100644 (file)
 #include <linux/errno.h>
 #include <linux/io.h>
 #include <linux/dma-mapping.h>
+#include <linux/mutex.h>
+#include <linux/spinlock.h>
+
+/**
+ * Bit masks for a MC I/O object (struct fsl_mc_io) flags
+ */
+#define FSL_MC_IO_ATOMIC_CONTEXT_PORTAL        0x0001
 
 struct fsl_mc_resource;
 struct mc_command;
@@ -50,27 +57,57 @@ struct mc_command;
  * @portal_size: MC command portal size in bytes
  * @portal_phys_addr: MC command portal physical address
  * @portal_virt_addr: MC command portal virtual address
- * @resource: generic resource associated with the MC portal if
- * the MC portal came from a resource pool, or NULL if the MC portal
- * is permanently bound to a device (e.g., a DPRC)
+ * @dpmcp_dev: pointer to the DPMCP device associated with the MC portal.
+ *
+ * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not
+ * set:
+ * @mutex: Mutex to serialize mc_send_command() calls that use the same MC
+ * portal, if the fsl_mc_io object was created with the
+ * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag off. mc_send_command() calls for this
+ * fsl_mc_io object must be made only from non-atomic context.
+ *
+ * Fields are only meaningful if the FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is
+ * set:
+ * @spinlock: Spinlock to serialize mc_send_command() calls that use the same MC
+ * portal, if the fsl_mc_io object was created with the
+ * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag on. mc_send_command() calls for this
+ * fsl_mc_io object can be made from atomic or non-atomic context.
  */
 struct fsl_mc_io {
        struct device *dev;
-       uint32_t flags;
-       uint32_t portal_size;
+       u16 flags;
+       u16 portal_size;
        phys_addr_t portal_phys_addr;
        void __iomem *portal_virt_addr;
-       struct fsl_mc_resource *resource;
+       struct fsl_mc_device *dpmcp_dev;
+       union {
+               /*
+                * This field is only meaningful if the
+                * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is not set
+                */
+               struct mutex mutex; /* serializes mc_send_command() */
+
+               /*
+                * This field is only meaningful if the
+                * FSL_MC_IO_ATOMIC_CONTEXT_PORTAL flag is set
+                */
+               spinlock_t spinlock;    /* serializes mc_send_command() */
+       };
 };
 
 int __must_check fsl_create_mc_io(struct device *dev,
                                  phys_addr_t mc_portal_phys_addr,
-                                 uint32_t mc_portal_size,
-                                 struct fsl_mc_resource *resource,
-                                 uint32_t flags, struct fsl_mc_io **new_mc_io);
+                                 u32 mc_portal_size,
+                                 struct fsl_mc_device *dpmcp_dev,
+                                 u32 flags, struct fsl_mc_io **new_mc_io);
 
 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
 
+int fsl_mc_io_set_dpmcp(struct fsl_mc_io *mc_io,
+                       struct fsl_mc_device *dpmcp_dev);
+
+void fsl_mc_io_unset_dpmcp(struct fsl_mc_io *mc_io);
+
 int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd);
 
 #endif /* _FSL_MC_SYS_H */
index fa02ef0529e73f6eeaf299193dc9182ff1681a9a..a933291e400ae5e24a8e571373d2e3b5fc7f484b 100644 (file)
@@ -59,10 +59,10 @@ struct fsl_mc_driver {
  * a MC object device driver. The last entry of the table has vendor set to 0x0
  */
 struct fsl_mc_device_match_id {
-       uint16_t vendor;
+       u16 vendor;
        const char obj_type[16];
-       uint32_t ver_major;
-       uint32_t ver_minor;
+       u32 ver_major;
+       u32 ver_minor;
 };
 
 /**
@@ -148,10 +148,10 @@ struct fsl_mc_resource {
  */
 struct fsl_mc_device {
        struct device dev;
-       uint64_t dma_mask;
-       uint16_t flags;
-       uint16_t icid;
-       uint16_t mc_handle;
+       u64 dma_mask;
+       u16 flags;
+       u16 icid;
+       u16 mc_handle;
        struct fsl_mc_io *mc_io;
        struct dprc_obj_desc obj_desc;
        struct resource *regions;
@@ -182,8 +182,10 @@ int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
 
 void fsl_mc_driver_unregister(struct fsl_mc_driver *driver);
 
+bool fsl_mc_bus_exists(void);
+
 int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,
-                                       uint16_t mc_io_flags,
+                                       u16 mc_io_flags,
                                        struct fsl_mc_io **new_mc_io);
 
 void fsl_mc_portal_free(struct fsl_mc_io *mc_io);
diff --git a/drivers/staging/ft1000/Kconfig b/drivers/staging/ft1000/Kconfig
deleted file mode 100644 (file)
index c54b4e8..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-config FT1000
-       tristate "Drivers for Flarion ft1000 devices"
-
-if FT1000
-
-config FT1000_USB
-       tristate "Driver for ft1000 usb devices."
-       depends on USB
-       depends on NET
-       help
-         Say Y if you want to have support for Qleadtek FLASH-OFDM USB Modem [LR7F04],
-         Qleadtek Express Card or Leadtek Multi-band modem HSDPA.
-
-config FT1000_PCMCIA
-       tristate "Driver for ft1000 pcmcia device."
-       depends on PCMCIA
-       depends on NET
-       help
-         Say Y if you want to have support for Flarion card also called
-         Multimedia Net Card.
-
-endif
diff --git a/drivers/staging/ft1000/Makefile b/drivers/staging/ft1000/Makefile
deleted file mode 100644 (file)
index 3e98777..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-obj-$(CONFIG_FT1000_USB)       += ft1000-usb/
-obj-$(CONFIG_FT1000_PCMCIA)    += ft1000-pcmcia/
-
diff --git a/drivers/staging/ft1000/TODO b/drivers/staging/ft1000/TODO
deleted file mode 100644 (file)
index 1d346bc..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-TODO:
-       - checkpatch.pl cleanups
-       - coding style
-       - sparse fixes
-       - adapt to latest usb and pcmcia api changes
-       - change firmware loading for usb driver to proper kernel method (request_firmware)
-
-Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
-Cc: Marek Belisko <marek.belisko@gmail.com>
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/Makefile b/drivers/staging/ft1000/ft1000-pcmcia/Makefile
deleted file mode 100644 (file)
index 715de3f..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-obj-$(CONFIG_FT1000_PCMCIA) = ft1000_pcmcia.o
-ft1000_pcmcia-y := ft1000_hw.o ft1000_dnld.o ft1000_cs.o
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/boot.h b/drivers/staging/ft1000/ft1000-pcmcia/boot.h
deleted file mode 100644 (file)
index e4a6985..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*---------------------------------------------------------------------------
-  FT1000 driver for Flarion Flash OFDM NIC Device
-
-  Copyright (C) 2002 Flarion Technologies, All rights reserved.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the Free
-  Software Foundation; either version 2 of the License, or (at your option) any
-  later version. This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details. You should have received a copy of the GNU General Public
-  License along with this program; if not, write to the
-  Free Software Foundation, Inc., 59 Temple Place -
-  Suite 330, Boston, MA 02111-1307, USA.
-  ---------------------------------------------------------------------------
-
-  File:         boot.h
-
-  Description:    boatloader
-
-  History:
-  1/11/05    Whc                Ported to Linux.
-
-  ---------------------------------------------------------------------------*/
-#ifndef _BOOTH_
-#define _BOOTH_
-
-/* Official bootloader */
-static unsigned char bootimage[] = {
-       0x00, 0x00, 0x01, 0x5E, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x02, 0xD7,
-       0x00, 0x00, 0x01, 0x5E, 0x46, 0xB3,
-       0xE6, 0x02, 0x00, 0x98, 0xE6, 0x8C,
-       0x00, 0x98, 0xFB, 0x92, 0xFF, 0xFF,
-       0x98, 0xFB, 0x94, 0xFF, 0xFF, 0x98,
-       0xFB, 0x06, 0x08, 0x00, 0x98, 0xFB,
-       0x96, 0x84, 0x00, 0x98, 0xFB, 0x08,
-       0x1C, 0x00, 0x98, 0xFB, 0x51, 0x25,
-       0x10, 0x1C, 0x00, 0xE6, 0x51, 0x01,
-       0x07, 0xFD, 0x4C, 0xFF, 0x20, 0xF5,
-       0x51, 0x02, 0x20, 0x08, 0x00, 0x4C,
-       0xFF, 0x20, 0x3C, 0x00, 0xC0, 0x64,
-       0x98, 0xC0, 0x66, 0x98, 0xC0, 0x68,
-       0x98, 0xC0, 0x6A, 0x98, 0xC0, 0x6C,
-       0x98, 0x90, 0x08, 0x90, 0x09, 0x90,
-       0x0A, 0x90, 0x0B, 0x90, 0x0C, 0x90,
-       0x0D, 0x90, 0x0E, 0x90, 0x0F, 0x90,
-       0x04, 0x90, 0x06, 0xFB, 0x51, 0x22,
-       0x16, 0x08, 0x03, 0xFB, 0x51, 0x52,
-       0x16, 0x08, 0x04, 0xFB, 0x51, 0x24,
-       0x2B, 0x08, 0x06, 0xFB, 0x51, 0x54,
-       0x2B, 0x08, 0x07, 0xFB, 0x51, 0x24,
-       0x2B, 0x08, 0x09, 0xFB, 0x51, 0x54,
-       0x2B, 0x08, 0x0A, 0xFB, 0x51, 0x12,
-       0x16, 0x08, 0x0C, 0xFB, 0x51, 0x52,
-       0x16, 0x08, 0x0D, 0x78, 0x00, 0x00,
-       0x00, 0x16, 0x00, 0x00, 0xEC, 0x31,
-       0xAE, 0x00, 0x00, 0x81, 0x4C, 0x0F,
-       0xE6, 0x43, 0xFF, 0xEC, 0x31, 0x4E,
-       0x00, 0x00, 0x91, 0xEC, 0x31, 0xAE,
-       0x00, 0x00, 0x91, 0x4C, 0x0F, 0xE6,
-       0x43, 0xFF, 0xEC, 0x31, 0x5E, 0x00,
-       0x00, 0xA1, 0xEB, 0x31, 0x08, 0x00,
-       0x00, 0xA6, 0xEB, 0x31, 0x08, 0x00,
-       0x00, 0xAC, 0x3C, 0x00, 0xEB, 0x31,
-       0x08, 0x00, 0x00, 0xA8, 0x76, 0xFE,
-       0xFE, 0x08, 0xEB, 0x31, 0x08, 0x20,
-       0x00, 0x00, 0x76, 0xFF, 0xFF, 0x18,
-       0xED, 0x31, 0x08, 0x20, 0x00, 0x00,
-       0x26, 0x10, 0x04, 0x10, 0xF5, 0x3C,
-       0x01, 0x3C, 0x00, 0x08, 0x01, 0x12,
-       0x3C, 0x11, 0x3C, 0x00, 0x08, 0x01,
-       0x0B, 0x08, 0x00, 0x6D, 0xEC, 0x31,
-       0xAE, 0x20, 0x00, 0x06, 0xED, 0x4D,
-       0x08, 0x00, 0x00, 0x67, 0x80, 0x6F,
-       0x00, 0x01, 0x0B, 0x6F, 0x00, 0x02,
-       0x2E, 0x76, 0xEE, 0x01, 0x48, 0x06,
-       0x01, 0x39, 0xED, 0x4D, 0x18, 0x00,
-       0x02, 0xED, 0x4D, 0x08, 0x00, 0x04,
-       0x14, 0x06, 0xA4, 0xED, 0x31, 0x22,
-       0x00, 0x00, 0xAC, 0x76, 0xEE, 0x07,
-       0x48, 0x6D, 0x22, 0x01, 0x1E, 0x08,
-       0x01, 0x58, 0xEB, 0x31, 0x08, 0x00,
-       0x00, 0xAC, 0x06, 0xFF, 0xBA, 0x3C,
-       0x00, 0xEB, 0x31, 0x08, 0x20, 0x00,
-       0x04, 0x3C, 0x30, 0xEB, 0x31, 0x08,
-       0x20, 0x00, 0x02, 0x3C, 0x10, 0xEB,
-       0x31, 0x08, 0x20, 0x00, 0x00, 0xED,
-       0x31, 0x08, 0x20, 0x00, 0x00, 0x04,
-       0x10, 0xF7, 0xED, 0x31, 0x08, 0x00,
-       0x00, 0xA2, 0x91, 0x00, 0x9C, 0x3C,
-       0x80, 0xEB, 0x31, 0x08, 0x20, 0x00,
-       0x04, 0x3C, 0x20, 0xEB, 0x31, 0x08,
-       0x20, 0x00, 0x02, 0x3C, 0x10, 0xEB,
-       0x31, 0x08, 0x20, 0x00, 0x00, 0xED,
-       0x31, 0x08, 0x20, 0x00, 0x00, 0x04,
-       0x10, 0xF7, 0xED, 0x31, 0x08, 0x20,
-       0x00, 0x04, 0x42, 0x10, 0x90, 0x08,
-       0xEC, 0x31, 0xAE, 0x20, 0x00, 0x06,
-       0xA4, 0x41, 0x08, 0x00, 0xB6, 0xED,
-       0x41, 0x28, 0x7D, 0xFF, 0xFF, 0x22,
-       0xB3, 0x40, 0x98, 0x2A, 0x32, 0xEB,
-       0x41, 0x28, 0xB4, 0x43, 0xFC, 0x05,
-       0xFF, 0xE6, 0xA0, 0x31, 0x20, 0x00,
-       0x06, 0xEB, 0x31, 0x08, 0x20, 0x00,
-       0x04, 0x3C, 0x20, 0xEB, 0x31, 0x08,
-       0x20, 0x00, 0x02, 0x3C, 0x10, 0xEB,
-       0x31, 0x08, 0x20, 0x00, 0x00, 0xED,
-       0x31, 0x08, 0x20, 0x00, 0x00, 0x04,
-       0x10, 0xF7, 0xED, 0x31, 0x08, 0x20,
-       0x00, 0x04, 0x42, 0x10, 0x90, 0x08,
-       0xEC, 0x31, 0xAE, 0x20, 0x00, 0x06,
-       0xA4, 0x41, 0x08, 0x00, 0x68, 0xED,
-       0x41, 0x28, 0x7D, 0xFF, 0xFF, 0x22,
-       0xB3, 0x40, 0x98, 0x2A, 0x32, 0xEB,
-       0x41, 0x28, 0xB4, 0x43, 0xFC, 0x05,
-       0xFF, 0xE6, 0x48, 0x04, 0xEB, 0x31,
-       0x08, 0x20, 0x00, 0x04, 0xEB, 0x31,
-       0x18, 0x20, 0x00, 0x02, 0x3C, 0x11,
-       0xEB, 0x31, 0x18, 0x20, 0x00, 0x00,
-       0xED, 0x31, 0x08, 0x20, 0x00, 0x00,
-       0x04, 0x10, 0xF7, 0xED, 0x31, 0x08,
-       0x20, 0x00, 0x02, 0x66, 0x00, 0x6F,
-       0x00, 0x01, 0x16, 0x76, 0xEE, 0x06,
-       0x48, 0x4A, 0x1E, 0x48, 0x04, 0xED,
-       0x31, 0x08, 0x20, 0x00, 0x04, 0xEB,
-       0x31, 0x08, 0x00, 0x00, 0xA4, 0x48,
-       0x04, 0xED, 0x31, 0x08, 0x20, 0x00,
-       0x04, 0xEB, 0x31, 0x08, 0x00, 0x00,
-       0xA2, 0x48, 0x04, 0x20, 0x20, 0x4A,
-       0x7C, 0x46, 0x82, 0x50, 0x05, 0x50,
-       0x15, 0xB5, 0x1E, 0x98, 0xED, 0x31,
-       0x08, 0x00, 0x00, 0xA8, 0x10, 0x47,
-       0x3B, 0x2C, 0x01, 0xDB, 0x40, 0x11,
-       0x98, 0xC1, 0x1E, 0x98, 0x10, 0x07,
-       0x30, 0xF9, 0x40, 0x07, 0x18, 0x98,
-       0x2A, 0x10, 0xEB, 0x31, 0x08, 0x00,
-       0x00, 0xA8, 0xA4, 0x1E, 0x98, 0xBB,
-       0x1E, 0x98, 0x50, 0x14, 0x50, 0x04,
-       0x46, 0x83, 0x48, 0x04, 0x02, 0x01,
-       0x00, 0x50, 0x05, 0x50, 0x15, 0x10,
-       0x87, 0x3F, 0x90, 0x2B, 0x18, 0x01,
-       0x00, 0xC0, 0x31, 0x00, 0x00, 0xAE,
-       0xDF, 0x41, 0x00, 0x08, 0x00, 0x1A,
-       0x42, 0x11, 0x67, 0x01, 0xDF, 0x41,
-       0x02, 0x08, 0x00, 0x10, 0x42, 0x11,
-       0x62, 0x01, 0xB4, 0x43, 0x4A, 0x68,
-       0x50, 0x14, 0x50, 0x04, 0x24, 0x10,
-       0x48, 0x04, 0xF2, 0x31, 0x00, 0x01,
-       0x00, 0x00, 0xAE, 0xF6, 0x31, 0x00,
-       0x01, 0x00, 0x00, 0xAE, 0x62, 0xE4,
-       0xE5, 0x61, 0x04, 0x48, 0x04, 0xE5,
-       0x63, 0x05, 0x48, 0x04, 0x20, 0x20,
-       0x00, 0x00, 0x00, 0x00
-};
-
-#endif
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
deleted file mode 100644 (file)
index e1861cf..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*---------------------------------------------------------------------------
-  FT1000 driver for Flarion Flash OFDM NIC Device
-
-  Copyright (C) 2002 Flarion Technologies, All rights reserved.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the Free
-  Software Foundation; either version 2 of the License, or (at your option) any
-  later version. This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details. You should have received a copy of the GNU General Public
-  License along with this program; if not, write to the
-  Free Software Foundation, Inc., 59 Temple Place -
-  Suite 330, Boston, MA 02111-1307, USA.
-  ---------------------------------------------------------------------------
-  Description:    Common structures and defines
-  ---------------------------------------------------------------------------*/
-#ifndef _FT1000H_
-#define _FT1000H_
-
-#include "../ft1000.h"
-
-#define FT1000_DRV_VER 0x01010300
-
-#define FT1000_DPRAM_BASE      0x0000  /* Dual Port RAM starting offset */
-
-/*
- * Maximum number of occurrence of pseudo header errors before resetting PC
- * Card.
- */
-#define MAX_PH_ERR     300
-
-#define SUCCESS        0x00
-#define FAILURE        0x01
-
-struct ft1000_pcmcia {
-       int PktIntfErr;
-       u16 packetseqnum;
-       void *link;
-};
-
-struct pcmcia_device;
-struct net_device;
-struct net_device *init_ft1000_card(struct pcmcia_device *link,
-                                   void *ft1000_reset);
-void stop_ft1000_card(struct net_device *dev);
-int card_download(struct net_device *dev, const u8 *pFileStart,
-                 size_t FileLength);
-
-u16 ft1000_read_dpram(struct net_device *dev, int offset);
-void card_bootload(struct net_device *dev);
-u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index);
-u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset);
-void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value);
-
-/* Read the value of a given ASIC register. */
-static inline u16 ft1000_read_reg(struct net_device *dev, u16 offset)
-{
-       return inw(dev->base_addr + offset);
-}
-
-/* Set the value of a given ASIC register. */
-static inline void ft1000_write_reg(struct net_device *dev, u16 offset,
-                                   u16 value)
-{
-       outw(value, dev->base_addr + offset);
-}
-
-#endif
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.img b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.img
deleted file mode 100644 (file)
index aad3c80..0000000
Binary files a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.img and /dev/null differ
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c
deleted file mode 100644 (file)
index e5cc5be..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*---------------------------------------------------------------------------
-  FT1000 driver for Flarion Flash OFDM NIC Device
-
-  Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
-  Copyright (C) 2002 Flarion Technologies, All rights reserved.
-  Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
-  Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
-
-  The initial developer of the original code is David A. Hinds
-  <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds.
-
-  This file was modified to support the Flarion Flash OFDM NIC Device
-  by Wai Chan (w.chan@flarion.com).
-
-  Port for kernel 2.6 created by Patrik Ostrihon (patrik.ostrihon@pwc.sk)
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the Free
-  Software Foundation; either version 2 of the License, or (at your option) any
-  later version. This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details. You should have received a copy of the GNU General Public
-  License along with this program; if not, write to the
-  Free Software Foundation, Inc., 59 Temple Place -
-  Suite 330, Boston, MA 02111-1307, USA.
-  -----------------------------------------------------------------------------*/
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/netdevice.h>
-#include <pcmcia/cistpl.h>
-#include <pcmcia/ds.h>
-
-/*====================================================================*/
-
-MODULE_AUTHOR("Wai Chan");
-MODULE_DESCRIPTION("FT1000 PCMCIA driver");
-MODULE_LICENSE("GPL");
-
-/*====================================================================*/
-
-static int ft1000_config(struct pcmcia_device *link);
-static void ft1000_detach(struct pcmcia_device *link);
-static int ft1000_attach(struct pcmcia_device *link);
-
-#include "ft1000.h"
-
-/*====================================================================*/
-
-static void ft1000_reset(struct pcmcia_device *link)
-{
-       pcmcia_reset_card(link->socket);
-}
-
-static int ft1000_attach(struct pcmcia_device *link)
-{
-       link->priv = NULL;
-       link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
-
-       return ft1000_config(link);
-}
-
-static void ft1000_detach(struct pcmcia_device *link)
-{
-       struct net_device *dev = link->priv;
-
-       if (dev)
-               stop_ft1000_card(dev);
-
-       pcmcia_disable_device(link);
-       free_netdev(dev);
-}
-
-static int ft1000_confcheck(struct pcmcia_device *link, void *priv_data)
-{
-       return pcmcia_request_io(link);
-}
-
-/*======================================================================
-
-  ft1000_config() is scheduled to run after a CARD_INSERTION event
-  is received, to configure the PCMCIA socket, and to make the
-  device available to the system.
-
-  ======================================================================*/
-
-static int ft1000_config(struct pcmcia_device *link)
-{
-       int ret;
-
-       dev_dbg(&link->dev, "ft1000_cs: ft1000_config(0x%p)\n", link);
-
-       /* setup IO window */
-       ret = pcmcia_loop_config(link, ft1000_confcheck, NULL);
-       if (ret) {
-               dev_err(&link->dev, "Could not configure pcmcia\n");
-               return -ENODEV;
-       }
-
-       /* configure device */
-       ret = pcmcia_enable_device(link);
-       if (ret) {
-               dev_err(&link->dev, "Could not enable pcmcia\n");
-               goto failed;
-       }
-
-       link->priv = init_ft1000_card(link, &ft1000_reset);
-       if (!link->priv) {
-               dev_err(&link->dev, "Could not register as network device\n");
-               goto failed;
-       }
-
-       /* Finally, report what we've done */
-
-       return 0;
-failed:
-       pcmcia_disable_device(link);
-       return -ENODEV;
-}
-
-static int ft1000_suspend(struct pcmcia_device *link)
-{
-       struct net_device *dev = link->priv;
-
-       if (link->open)
-               netif_device_detach(dev);
-       return 0;
-}
-
-static int ft1000_resume(struct pcmcia_device *link)
-{
-       return 0;
-}
-
-/*====================================================================*/
-
-static const struct pcmcia_device_id ft1000_ids[] = {
-       PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x0100),
-       PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x1000),
-       PCMCIA_DEVICE_MANF_CARD(0x02cc, 0x1300),
-       PCMCIA_DEVICE_NULL,
-};
-
-MODULE_DEVICE_TABLE(pcmcia, ft1000_ids);
-
-static struct pcmcia_driver ft1000_cs_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "ft1000_cs",
-       .probe          = ft1000_attach,
-       .remove         = ft1000_detach,
-       .id_table       = ft1000_ids,
-       .suspend        = ft1000_suspend,
-       .resume         = ft1000_resume,
-};
-
-module_pcmcia_driver(ft1000_cs_driver);
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c
deleted file mode 100644 (file)
index 83683e9..0000000
+++ /dev/null
@@ -1,769 +0,0 @@
-/*---------------------------------------------------------------------------
-  FT1000 driver for Flarion Flash OFDM NIC Device
-
-  Copyright (C) 2002 Flarion Technologies, All rights reserved.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the Free
-  Software Foundation; either version 2 of the License, or (at your option) any
-  later version. This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details. You should have received a copy of the GNU General Public
-  License along with this program; if not, write to the
-  Free Software Foundation, Inc., 59 Temple Place -
-  Suite 330, Boston, MA 02111-1307, USA.
-  --------------------------------------------------------------------------
-
-  Description: This module will handshake with the DSP bootloader to
-  download the DSP runtime image.
-
-  ---------------------------------------------------------------------------*/
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#define __KERNEL_SYSCALLS__
-
-#include <linux/module.h>
-#include <linux/fs.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
-#include <linux/unistd.h>
-#include <linux/netdevice.h>
-#include <linux/timer.h>
-#include <linux/delay.h>
-#include <linux/io.h>
-#include <linux/uaccess.h>
-#include <linux/vmalloc.h>
-
-#include "ft1000.h"
-#include "boot.h"
-
-#define  MAX_DSP_WAIT_LOOPS      100
-#define  DSP_WAIT_SLEEP_TIME     1     /* 1 millisecond */
-
-#define  MAX_LENGTH              0x7f0
-
-#define  DWNLD_MAG_HANDSHAKE_LOC 0x00
-#define  DWNLD_MAG_TYPE_LOC      0x01
-#define  DWNLD_MAG_SIZE_LOC      0x02
-#define  DWNLD_MAG_PS_HDR_LOC    0x03
-
-#define  DWNLD_HANDSHAKE_LOC     0x02
-#define  DWNLD_TYPE_LOC          0x04
-#define  DWNLD_SIZE_MSW_LOC      0x06
-#define  DWNLD_SIZE_LSW_LOC      0x08
-#define  DWNLD_PS_HDR_LOC        0x0A
-
-#define  HANDSHAKE_TIMEOUT_VALUE 0xF1F1
-#define  HANDSHAKE_RESET_VALUE   0xFEFE        /* When DSP requests startover */
-#define  HANDSHAKE_DSP_BL_READY  0xFEFE        /* At start DSP writes this when bootloader ready */
-#define  HANDSHAKE_DRIVER_READY  0xFFFF        /* Driver writes after receiving 0xFEFE */
-#define  HANDSHAKE_SEND_DATA     0x0000        /* DSP writes this when ready for more data */
-
-#define  HANDSHAKE_REQUEST       0x0001        /* Request from DSP */
-#define  HANDSHAKE_RESPONSE      0x0000        /* Satisfied DSP request */
-
-#define  REQUEST_CODE_LENGTH     0x0000
-#define  REQUEST_RUN_ADDRESS     0x0001
-#define  REQUEST_CODE_SEGMENT    0x0002        /* In WORD count */
-#define  REQUEST_DONE_BL         0x0003
-#define  REQUEST_DONE_CL         0x0004
-#define  REQUEST_VERSION_INFO    0x0005
-#define  REQUEST_CODE_BY_VERSION 0x0006
-#define  REQUEST_MAILBOX_DATA    0x0007
-#define  REQUEST_FILE_CHECKSUM   0x0008
-
-#define  STATE_START_DWNLD       0x01
-#define  STATE_BOOT_DWNLD        0x02
-#define  STATE_CODE_DWNLD        0x03
-#define  STATE_DONE_DWNLD        0x04
-#define  STATE_SECTION_PROV      0x05
-#define  STATE_DONE_PROV         0x06
-#define  STATE_DONE_FILE         0x07
-
-u16 get_handshake(struct net_device *dev, u16 expected_value);
-void put_handshake(struct net_device *dev, u16 handshake_value);
-u16 get_request_type(struct net_device *dev);
-long get_request_value(struct net_device *dev);
-void put_request_value(struct net_device *dev, long lvalue);
-u16 hdr_checksum(struct pseudo_hdr *pHdr);
-
-struct dsp_file_hdr {
-       u32  version_id;        /* Version ID of this image format. */
-       u32  package_id;        /* Package ID of code release. */
-       u32  build_date;        /* Date/time stamp when file was built. */
-       u32  commands_offset;   /* Offset to attached commands in Pseudo Hdr format. */
-       u32  loader_offset;     /* Offset to bootloader code. */
-       u32  loader_code_address;       /* Start address of bootloader. */
-       u32  loader_code_end;   /* Where bootloader code ends. */
-       u32  loader_code_size;
-       u32  version_data_offset;       /* Offset were scrambled version data begins. */
-       u32  version_data_size; /* Size, in words, of scrambled version data. */
-       u32  nDspImages;        /* Number of DSP images in file. */
-} __packed;
-
-struct dsp_image_info {
-       u32  coff_date;         /* Date/time when DSP Coff image was built. */
-       u32  begin_offset;      /* Offset in file where image begins. */
-       u32  end_offset;        /* Offset in file where image begins. */
-       u32  run_address;       /* On chip Start address of DSP code. */
-       u32  image_size;        /* Size of image. */
-       u32  version;           /* Embedded version # of DSP code. */
-       unsigned short checksum;        /* Dsp File checksum */
-       unsigned short pad1;
-} __packed;
-
-void card_bootload(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       unsigned long flags;
-       u32 *pdata;
-       u32 size;
-       u32 i;
-       u32 templong;
-
-       netdev_dbg(dev, "card_bootload is called\n");
-
-       pdata = (u32 *)bootimage;
-       size = sizeof(bootimage);
-
-       /* check for odd word */
-       if (size & 0x0003)
-               size += 4;
-
-       /* Provide mutual exclusive access while reading ASIC registers. */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-
-       /* need to set i/o base address initially and hardware will autoincrement */
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, FT1000_DPRAM_BASE);
-       /* write bytes */
-       for (i = 0; i < (size >> 2); i++) {
-               templong = *pdata++;
-               outl(templong, dev->base_addr + FT1000_REG_MAG_DPDATA);
-       }
-
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-}
-
-u16 get_handshake(struct net_device *dev, u16 expected_value)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 handshake;
-       u32 tempx;
-       int loopcnt;
-
-       loopcnt = 0;
-       while (loopcnt < MAX_DSP_WAIT_LOOPS) {
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                        DWNLD_HANDSHAKE_LOC);
-
-                       handshake = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA);
-               } else {
-                       tempx =
-                               ntohl(ft1000_read_dpram_mag_32
-                                     (dev, DWNLD_MAG_HANDSHAKE_LOC));
-                       handshake = (u16)tempx;
-               }
-
-               if ((handshake == expected_value)
-                   || (handshake == HANDSHAKE_RESET_VALUE)) {
-                       return handshake;
-               }
-               loopcnt++;
-               mdelay(DSP_WAIT_SLEEP_TIME);
-
-       }
-
-       return HANDSHAKE_TIMEOUT_VALUE;
-
-}
-
-void put_handshake(struct net_device *dev, u16 handshake_value)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u32 tempx;
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                DWNLD_HANDSHAKE_LOC);
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, handshake_value);  /* Handshake */
-       } else {
-               tempx = (u32)handshake_value;
-               tempx = ntohl(tempx);
-               ft1000_write_dpram_mag_32(dev, DWNLD_MAG_HANDSHAKE_LOC, tempx); /* Handshake */
-       }
-}
-
-u16 get_request_type(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 request_type;
-       u32 tempx;
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, DWNLD_TYPE_LOC);
-               request_type = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA);
-       } else {
-               tempx = ft1000_read_dpram_mag_32(dev, DWNLD_MAG_TYPE_LOC);
-               tempx = ntohl(tempx);
-               request_type = (u16)tempx;
-       }
-
-       return request_type;
-
-}
-
-long get_request_value(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       long value;
-       u16 w_val;
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                DWNLD_SIZE_MSW_LOC);
-
-               w_val = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA);
-
-               value = (long)(w_val << 16);
-
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                DWNLD_SIZE_LSW_LOC);
-
-               w_val = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA);
-
-               value = (long)(value | w_val);
-       } else {
-               value = ft1000_read_dpram_mag_32(dev, DWNLD_MAG_SIZE_LOC);
-               value = ntohl(value);
-       }
-
-       return value;
-
-}
-
-void put_request_value(struct net_device *dev, long lvalue)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 size;
-       u32 tempx;
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               size = (u16) (lvalue >> 16);
-
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                DWNLD_SIZE_MSW_LOC);
-
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, size);
-
-               size = (u16) (lvalue);
-
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                DWNLD_SIZE_LSW_LOC);
-
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, size);
-       } else {
-               tempx = ntohl(lvalue);
-               ft1000_write_dpram_mag_32(dev, DWNLD_MAG_SIZE_LOC, tempx);      /* Handshake */
-       }
-
-}
-
-u16 hdr_checksum(struct pseudo_hdr *pHdr)
-{
-       u16 *usPtr = (u16 *)pHdr;
-       u16 chksum;
-
-       chksum = (((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^
-                   usPtr[4]) ^ usPtr[5]) ^ usPtr[6];
-
-       return chksum;
-}
-
-int card_download(struct net_device *dev, const u8 *pFileStart,
-                 size_t FileLength)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       int Status = SUCCESS;
-       u32 uiState;
-       u16 handshake;
-       struct pseudo_hdr *pHdr;
-       u16 usHdrLength;
-       long word_length;
-       u16 request;
-       u16 temp;
-       struct prov_record *pprov_record;
-       u8 *pbuffer;
-       struct dsp_file_hdr *pFileHdr5;
-       struct dsp_image_info *pDspImageInfoV6 = NULL;
-       long requested_version;
-       bool bGoodVersion = false;
-       struct drv_msg *pMailBoxData;
-       u16 *pUsData = NULL;
-       u16 *pUsFile = NULL;
-       u8 *pUcFile = NULL;
-       u8 *pBootEnd = NULL;
-       u8 *pCodeEnd = NULL;
-       int imageN;
-       long file_version;
-       long loader_code_address = 0;
-       long loader_code_size = 0;
-       long run_address = 0;
-       long run_size = 0;
-       unsigned long flags;
-       unsigned long templong;
-       unsigned long image_chksum = 0;
-
-       file_version = *(long *)pFileStart;
-       if (file_version != 6) {
-               pr_err("unsupported firmware version %ld\n", file_version);
-               Status = FAILURE;
-       }
-
-       uiState = STATE_START_DWNLD;
-
-       pFileHdr5 = (struct dsp_file_hdr *)pFileStart;
-
-       pUsFile = (u16 *) ((long)pFileStart + pFileHdr5->loader_offset);
-       pUcFile = (u8 *) ((long)pFileStart + pFileHdr5->loader_offset);
-       pBootEnd = (u8 *) ((long)pFileStart + pFileHdr5->loader_code_end);
-       loader_code_address = pFileHdr5->loader_code_address;
-       loader_code_size = pFileHdr5->loader_code_size;
-       bGoodVersion = false;
-
-       while ((Status == SUCCESS) && (uiState != STATE_DONE_FILE)) {
-
-               switch (uiState) {
-               case STATE_START_DWNLD:
-
-                       handshake = get_handshake(dev, HANDSHAKE_DSP_BL_READY);
-
-                       if (handshake == HANDSHAKE_DSP_BL_READY)
-                               put_handshake(dev, HANDSHAKE_DRIVER_READY);
-                       else
-                               Status = FAILURE;
-
-                       uiState = STATE_BOOT_DWNLD;
-
-                       break;
-
-               case STATE_BOOT_DWNLD:
-                       handshake = get_handshake(dev, HANDSHAKE_REQUEST);
-                       if (handshake == HANDSHAKE_REQUEST) {
-                               /*
-                                * Get type associated with the request.
-                                */
-                               request = get_request_type(dev);
-                               switch (request) {
-                               case REQUEST_RUN_ADDRESS:
-                                       put_request_value(dev,
-                                                         loader_code_address);
-                                       break;
-                               case REQUEST_CODE_LENGTH:
-                                       put_request_value(dev,
-                                                         loader_code_size);
-                                       break;
-                               case REQUEST_DONE_BL:
-                                       /* Reposition ptrs to beginning of code section */
-                                       pUsFile = (u16 *) ((long)pBootEnd);
-                                       pUcFile = (u8 *) ((long)pBootEnd);
-                                       uiState = STATE_CODE_DWNLD;
-                                       break;
-                               case REQUEST_CODE_SEGMENT:
-                                       word_length = get_request_value(dev);
-                                       if (word_length > MAX_LENGTH) {
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       if ((word_length * 2 + (long)pUcFile) >
-                                           (long)pBootEnd) {
-                                               /*
-                                                * Error, beyond boot code range.
-                                                */
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       /* Provide mutual exclusive access while reading ASIC registers. */
-                                       spin_lock_irqsave(&info->dpram_lock,
-                                                         flags);
-                                       /*
-                                        * Position ASIC DPRAM auto-increment pointer.
-                                        */
-                                       outw(DWNLD_MAG_PS_HDR_LOC,
-                                            dev->base_addr +
-                                            FT1000_REG_DPRAM_ADDR);
-                                       if (word_length & 0x01)
-                                               word_length++;
-                                       word_length = word_length / 2;
-
-                                       for (; word_length > 0; word_length--) {        /* In words */
-                                               templong = *pUsFile++;
-                                               templong |=
-                                                       (*pUsFile++ << 16);
-                                               pUcFile += 4;
-                                               outl(templong,
-                                                    dev->base_addr +
-                                                    FT1000_REG_MAG_DPDATAL);
-                                       }
-                                       spin_unlock_irqrestore(&info->
-                                                              dpram_lock,
-                                                              flags);
-                                       break;
-                               default:
-                                       Status = FAILURE;
-                                       break;
-                               }
-                               put_handshake(dev, HANDSHAKE_RESPONSE);
-                       } else {
-                               Status = FAILURE;
-                       }
-
-                       break;
-
-               case STATE_CODE_DWNLD:
-                       handshake = get_handshake(dev, HANDSHAKE_REQUEST);
-                       if (handshake == HANDSHAKE_REQUEST) {
-                               /*
-                                * Get type associated with the request.
-                                */
-                               request = get_request_type(dev);
-                               switch (request) {
-                               case REQUEST_FILE_CHECKSUM:
-                                       netdev_dbg(dev,
-                                                  "ft1000_dnld: REQUEST_FOR_CHECKSUM\n");
-                                       put_request_value(dev, image_chksum);
-                                       break;
-                               case REQUEST_RUN_ADDRESS:
-                                       if (bGoodVersion) {
-                                               put_request_value(dev,
-                                                                 run_address);
-                                       } else {
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       break;
-                               case REQUEST_CODE_LENGTH:
-                                       if (bGoodVersion) {
-                                               put_request_value(dev,
-                                                                 run_size);
-                                       } else {
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       break;
-                               case REQUEST_DONE_CL:
-                                       /* Reposition ptrs to beginning of provisioning section */
-                                       pUsFile = (u16 *) ((long)pFileStart + pFileHdr5->commands_offset);
-                                       pUcFile = (u8 *) ((long)pFileStart + pFileHdr5->commands_offset);
-                                       uiState = STATE_DONE_DWNLD;
-                                       break;
-                               case REQUEST_CODE_SEGMENT:
-                                       if (!bGoodVersion) {
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       word_length = get_request_value(dev);
-                                       if (word_length > MAX_LENGTH) {
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       if ((word_length * 2 + (long)pUcFile) >
-                                           (long)pCodeEnd) {
-                                               /*
-                                                * Error, beyond boot code range.
-                                                */
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       /*
-                                        * Position ASIC DPRAM auto-increment pointer.
-                                        */
-                                       outw(DWNLD_MAG_PS_HDR_LOC,
-                                            dev->base_addr +
-                                            FT1000_REG_DPRAM_ADDR);
-                                       if (word_length & 0x01)
-                                               word_length++;
-                                       word_length = word_length / 2;
-
-                                       for (; word_length > 0; word_length--) {        /* In words */
-                                               templong = *pUsFile++;
-                                               templong |=
-                                                       (*pUsFile++ << 16);
-                                               pUcFile += 4;
-                                               outl(templong,
-                                                    dev->base_addr +
-                                                    FT1000_REG_MAG_DPDATAL);
-                                       }
-                                       break;
-
-                               case REQUEST_MAILBOX_DATA:
-                                       /* Convert length from byte count to word count. Make sure we round up. */
-                                       word_length =
-                                               (long)(info->DSPInfoBlklen + 1) / 2;
-                                       put_request_value(dev, word_length);
-                                       pMailBoxData =
-                                               (struct drv_msg *)&info->DSPInfoBlk[0];
-                                       pUsData =
-                                               (u16 *)&pMailBoxData->data[0];
-                                       /* Provide mutual exclusive access while reading ASIC registers. */
-                                       spin_lock_irqsave(&info->dpram_lock,
-                                                         flags);
-                                       if (file_version == 5) {
-                                               /*
-                                                * Position ASIC DPRAM auto-increment pointer.
-                                                */
-                                               ft1000_write_reg(dev,
-                                                                FT1000_REG_DPRAM_ADDR,
-                                                                DWNLD_PS_HDR_LOC);
-
-                                               for (; word_length > 0; word_length--) {        /* In words */
-                                                       temp = ntohs(*pUsData);
-                                                       ft1000_write_reg(dev,
-                                                                        FT1000_REG_DPRAM_DATA,
-                                                                        temp);
-                                                       pUsData++;
-                                               }
-                                       } else {
-                                               /*
-                                                * Position ASIC DPRAM auto-increment pointer.
-                                                */
-                                               outw(DWNLD_MAG_PS_HDR_LOC,
-                                                    dev->base_addr +
-                                                    FT1000_REG_DPRAM_ADDR);
-                                               if (word_length & 0x01)
-                                                       word_length++;
-
-                                               word_length = word_length / 2;
-
-                                               for (; word_length > 0; word_length--) {        /* In words */
-                                                       templong = *pUsData++;
-                                                       templong |=
-                                                               (*pUsData++ << 16);
-                                                       outl(templong,
-                                                            dev->base_addr +
-                                                            FT1000_REG_MAG_DPDATAL);
-                                               }
-                                       }
-                                       spin_unlock_irqrestore(&info->
-                                                              dpram_lock,
-                                                              flags);
-                                       break;
-
-                               case REQUEST_VERSION_INFO:
-                                       word_length =
-                                               pFileHdr5->version_data_size;
-                                       put_request_value(dev, word_length);
-                                       pUsFile =
-                                               (u16 *) ((long)pFileStart +
-                                                        pFileHdr5->
-                                                        version_data_offset);
-                                       /* Provide mutual exclusive access while reading ASIC registers. */
-                                       spin_lock_irqsave(&info->dpram_lock,
-                                                         flags);
-                                       /*
-                                        * Position ASIC DPRAM auto-increment pointer.
-                                        */
-                                       outw(DWNLD_MAG_PS_HDR_LOC,
-                                            dev->base_addr +
-                                            FT1000_REG_DPRAM_ADDR);
-                                       if (word_length & 0x01)
-                                               word_length++;
-                                       word_length = word_length / 2;
-
-                                       for (; word_length > 0; word_length--) {        /* In words */
-                                               templong =
-                                                       ntohs(*pUsFile++);
-                                               temp =
-                                                       ntohs(*pUsFile++);
-                                               templong |=
-                                                       (temp << 16);
-                                               outl(templong,
-                                                    dev->base_addr +
-                                                    FT1000_REG_MAG_DPDATAL);
-                                       }
-                                       spin_unlock_irqrestore(&info->
-                                                              dpram_lock,
-                                                              flags);
-                                       break;
-
-                               case REQUEST_CODE_BY_VERSION:
-                                       bGoodVersion = false;
-                                       requested_version =
-                                               get_request_value(dev);
-                                       pDspImageInfoV6 =
-                                               (struct dsp_image_info *) ((long)
-                                                                          pFileStart
-                                                                          +
-                                                                          sizeof
-                                                                          (struct dsp_file_hdr));
-                                       for (imageN = 0;
-                                            imageN <
-                                                    pFileHdr5->nDspImages;
-                                            imageN++) {
-                                               temp = (u16)
-                                                       (pDspImageInfoV6->
-                                                        version);
-                                               templong = temp;
-                                               temp = (u16)
-                                                       (pDspImageInfoV6->
-                                                        version >> 16);
-                                               templong |=
-                                                       (temp << 16);
-                                               if (templong ==
-                                                   requested_version) {
-                                                       bGoodVersion =
-                                                               true;
-                                                       pUsFile =
-                                                               (u16
-                                                                *) ((long)
-                                                                    pFileStart
-                                                                    +
-                                                                    pDspImageInfoV6->
-                                                                    begin_offset);
-                                                       pUcFile =
-                                                               (u8
-                                                                *) ((long)
-                                                                    pFileStart
-                                                                    +
-                                                                    pDspImageInfoV6->
-                                                                    begin_offset);
-                                                       pCodeEnd =
-                                                               (u8
-                                                                *) ((long)
-                                                                    pFileStart
-                                                                    +
-                                                                    pDspImageInfoV6->
-                                                                    end_offset);
-                                                       run_address =
-                                                               pDspImageInfoV6->
-                                                               run_address;
-                                                       run_size =
-                                                               pDspImageInfoV6->
-                                                               image_size;
-                                                       image_chksum =
-                                                               (u32)
-                                                               pDspImageInfoV6->
-                                                               checksum;
-                                                       netdev_dbg(dev,
-                                                                  "ft1000_dnld: image_chksum = 0x%8x\n",
-                                                                  (unsigned
-                                                                   int)
-                                                                  image_chksum);
-                                                       break;
-                                               }
-                                               pDspImageInfoV6++;
-                                       }
-                                       if (!bGoodVersion) {
-                                               /*
-                                                * Error, beyond boot code range.
-                                                */
-                                               Status = FAILURE;
-                                               break;
-                                       }
-                                       break;
-
-                               default:
-                                       Status = FAILURE;
-                                       break;
-                               }
-                               put_handshake(dev, HANDSHAKE_RESPONSE);
-                       } else {
-                               Status = FAILURE;
-                       }
-
-                       break;
-
-               case STATE_DONE_DWNLD:
-                       if (((unsigned long)(pUcFile) - (unsigned long) pFileStart) >=
-                           (unsigned long)FileLength) {
-                               uiState = STATE_DONE_FILE;
-                               break;
-                       }
-
-                       pHdr = (struct pseudo_hdr *)pUsFile;
-
-                       if (pHdr->portdest == 0x80      /* DspOAM */
-                           && (pHdr->portsrc == 0x00   /* Driver */
-                               || pHdr->portsrc == 0x10 /* FMM */)) {
-                               uiState = STATE_SECTION_PROV;
-                       } else {
-                               netdev_dbg(dev,
-                                          "Download error: Bad Port IDs in Pseudo Record\n");
-                               netdev_dbg(dev, "\t Port Source = 0x%2.2x\n",
-                                          pHdr->portsrc);
-                               netdev_dbg(dev, "\t Port Destination = 0x%2.2x\n",
-                                          pHdr->portdest);
-                               Status = FAILURE;
-                       }
-
-                       break;
-
-               case STATE_SECTION_PROV:
-
-                       pHdr = (struct pseudo_hdr *)pUcFile;
-
-                       if (pHdr->checksum == hdr_checksum(pHdr)) {
-                               if (pHdr->portdest != 0x80 /* Dsp OAM */) {
-                                       uiState = STATE_DONE_PROV;
-                                       break;
-                               }
-                               usHdrLength = ntohs(pHdr->length);      /* Byte length for PROV records */
-
-                               /* Get buffer for provisioning data */
-                               pbuffer =
-                                       kmalloc(usHdrLength + sizeof(struct pseudo_hdr),
-                                               GFP_ATOMIC);
-                               if (pbuffer) {
-                                       memcpy(pbuffer, pUcFile,
-                                              (u32) (usHdrLength +
-                                                     sizeof(struct pseudo_hdr)));
-                                       /* link provisioning data */
-                                       pprov_record =
-                                               kmalloc(sizeof(struct prov_record),
-                                                       GFP_ATOMIC);
-                                       if (pprov_record) {
-                                               pprov_record->pprov_data =
-                                                       pbuffer;
-                                               list_add_tail(&pprov_record->
-                                                             list,
-                                                             &info->prov_list);
-                                               /* Move to next entry if available */
-                                               pUcFile =
-                                                       (u8 *)((unsigned long) pUcFile +
-                                                              (unsigned long) ((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
-                                               if ((unsigned long) (pUcFile) -
-                                                   (unsigned long) (pFileStart) >=
-                                                   (unsigned long)FileLength) {
-                                                       uiState =
-                                                               STATE_DONE_FILE;
-                                               }
-                                       } else {
-                                               kfree(pbuffer);
-                                               Status = FAILURE;
-                                       }
-                               } else {
-                                       Status = FAILURE;
-                               }
-                       } else {
-                               /* Checksum did not compute */
-                               Status = FAILURE;
-                       }
-
-                       break;
-
-               case STATE_DONE_PROV:
-                       uiState = STATE_DONE_FILE;
-                       break;
-
-               default:
-                       Status = FAILURE;
-                       break;
-               }               /* End Switch */
-
-       }                       /* End while */
-
-       return Status;
-
-}
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
deleted file mode 100644 (file)
index eecfa37..0000000
+++ /dev/null
@@ -1,2068 +0,0 @@
-/*---------------------------------------------------------------------------
-  FT1000 driver for Flarion Flash OFDM NIC Device
-
-  Copyright (C) 2002 Flarion Technologies, All rights reserved.
-  Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
-  Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
-
-  This program is free software; you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by the Free
-  Software Foundation; either version 2 of the License, or (at your option) any
-  later version. This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
-  more details. You should have received a copy of the GNU General Public
-  License along with this program; if not, write to the
-  Free Software Foundation, Inc., 59 Temple Place -
-  Suite 330, Boston, MA 02111-1307, USA.
-  -------------------------------------------------------------------------*/
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/sched.h>
-#include <linux/ptrace.h>
-#include <linux/slab.h>
-#include <linux/string.h>
-#include <linux/timer.h>
-#include <linux/interrupt.h>
-#include <linux/in.h>
-#include <linux/io.h>
-#include <linux/bitops.h>
-
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/skbuff.h>
-#include <linux/if_arp.h>
-#include <linux/ioport.h>
-#include <linux/wait.h>
-#include <linux/vmalloc.h>
-
-#include <linux/firmware.h>
-#include <linux/ethtool.h>
-
-#include <pcmcia/cistpl.h>
-#include <pcmcia/cisreg.h>
-#include <pcmcia/ds.h>
-
-#include <linux/delay.h>
-#include "ft1000.h"
-
-static const struct firmware *fw_entry;
-
-static void ft1000_hbchk(u_long data);
-static struct timer_list poll_timer = {
-       .function = ft1000_hbchk
-};
-
-static u16 cmdbuffer[1024];
-static u8 tempbuffer[1600];
-static u8 ft1000_card_present;
-static u8 flarion_ft1000_cnt;
-
-static irqreturn_t ft1000_interrupt(int irq, void *dev_id);
-static void ft1000_enable_interrupts(struct net_device *dev);
-static void ft1000_disable_interrupts(struct net_device *dev);
-
-/* new kernel */
-MODULE_AUTHOR("");
-MODULE_DESCRIPTION("Support for Flarion Flash OFDM NIC Device. Support for PCMCIA when used with ft1000_cs.");
-MODULE_LICENSE("GPL");
-MODULE_SUPPORTED_DEVICE("FT1000");
-
-#define MAX_RCV_LOOP   100
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_read_fifo_len
-  Description: This function will read the ASIC Uplink FIFO status register
-  which will return the number of bytes remaining in the Uplink FIFO.
-  Sixteen bytes are subtracted to make sure that the ASIC does not
-  reach its threshold.
-  Input:
-  dev    - network device structure
-  Output:
-  value  - number of bytes available in the ASIC Uplink FIFO.
-
-  -------------------------------------------------------------------------*/
-static inline u16 ft1000_read_fifo_len(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-
-       if (info->AsicID == ELECTRABUZZ_ID)
-               return (ft1000_read_reg(dev, FT1000_REG_UFIFO_STAT) - 16);
-       else
-               return (ft1000_read_reg(dev, FT1000_REG_MAG_UFSR) - 16);
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_read_dpram
-  Description: This function will read the specific area of dpram
-  (Electrabuzz ASIC only)
-  Input:
-  dev    - device structure
-  offset - index of dpram
-  Output:
-  value  - value of dpram
-
-  -------------------------------------------------------------------------*/
-u16 ft1000_read_dpram(struct net_device *dev, int offset)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       unsigned long flags;
-       u16 data;
-
-       /* Provide mutual exclusive access while reading ASIC registers. */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, offset);
-       data = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA);
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-
-       return data;
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_write_dpram
-  Description: This function will write to a specific area of dpram
-  (Electrabuzz ASIC only)
-  Input:
-  dev    - device structure
-  offset - index of dpram
-  value  - value to write
-  Output:
-  none.
-
-  -------------------------------------------------------------------------*/
-static inline void ft1000_write_dpram(struct net_device *dev,
-                                     int offset, u16 value)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       unsigned long flags;
-
-       /* Provide mutual exclusive access while reading ASIC registers. */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, offset);
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, value);
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_read_dpram_mag_16
-  Description: This function will read the specific area of dpram
-  (Magnemite ASIC only)
-  Input:
-  dev    - device structure
-  offset - index of dpram
-  Output:
-  value  - value of dpram
-
-  -------------------------------------------------------------------------*/
-u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       unsigned long flags;
-       u16 data;
-
-       /* Provide mutual exclusive access while reading ASIC registers. */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, offset);
-       /* check if we want to read upper or lower 32-bit word */
-       if (Index)
-               data = ft1000_read_reg(dev, FT1000_REG_MAG_DPDATAL);
-       else
-               data = ft1000_read_reg(dev, FT1000_REG_MAG_DPDATAH);
-
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-
-       return data;
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_write_dpram_mag_16
-  Description: This function will write to a specific area of dpram
-  (Magnemite ASIC only)
-  Input:
-  dev    - device structure
-  offset - index of dpram
-  value  - value to write
-  Output:
-  none.
-
-  -------------------------------------------------------------------------*/
-static inline void ft1000_write_dpram_mag_16(struct net_device *dev,
-                                            int offset, u16 value, int Index)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       unsigned long flags;
-
-       /* Provide mutual exclusive access while reading ASIC registers. */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, offset);
-       if (Index)
-               ft1000_write_reg(dev, FT1000_REG_MAG_DPDATAL, value);
-       else
-               ft1000_write_reg(dev, FT1000_REG_MAG_DPDATAH, value);
-
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_read_dpram_mag_32
-  Description: This function will read the specific area of dpram
-  (Magnemite ASIC only)
-  Input:
-  dev    - device structure
-  offset - index of dpram
-  Output:
-  value  - value of dpram
-
-  -------------------------------------------------------------------------*/
-u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       unsigned long flags;
-       u32 data;
-
-       /* Provide mutual exclusive access while reading ASIC registers. */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, offset);
-       data = inl(dev->base_addr + FT1000_REG_MAG_DPDATAL);
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-
-       return data;
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_write_dpram_mag_32
-  Description: This function will write to a specific area of dpram
-  (Magnemite ASIC only)
-  Input:
-  dev    - device structure
-  offset - index of dpram
-  value  - value to write
-  Output:
-  none.
-
-  -------------------------------------------------------------------------*/
-void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       unsigned long flags;
-
-       /* Provide mutual exclusive access while reading ASIC registers. */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, offset);
-       outl(value, dev->base_addr + FT1000_REG_MAG_DPDATAL);
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_enable_interrupts
-  Description: This function will enable interrupts base on the current
-              interrupt mask.
-  Input:
-  dev    - device structure
-  Output:
-  None.
-
-  -------------------------------------------------------------------------*/
-static void ft1000_enable_interrupts(struct net_device *dev)
-{
-       u16 tempword;
-
-       ft1000_write_reg(dev, FT1000_REG_SUP_IMASK, ISR_DEFAULT_MASK);
-       tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK);
-       pr_debug("current interrupt enable mask = 0x%x\n", tempword);
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_disable_interrupts
-  Description: This function will disable all interrupts.
-  Input:
-  dev    - device structure
-  Output:
-  None.
-
-  -------------------------------------------------------------------------*/
-static void ft1000_disable_interrupts(struct net_device *dev)
-{
-       u16 tempword;
-
-       ft1000_write_reg(dev, FT1000_REG_SUP_IMASK, ISR_MASK_ALL);
-       tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK);
-       pr_debug("current interrupt enable mask = 0x%x\n", tempword);
-}
-
-/*---------------------------------------------------------------------------
-  Function:    ft1000_read_dsp_timer
-  Description: This function reads the DSP timer and stores its value in the
-               DSP_TIME field of the ft1000_info struct passed as argument
-  Input:
-  dev    - device structure
-  info   - ft1000_info structure
-  Output:
-  None.
-
-  -------------------------------------------------------------------------*/
-static void ft1000_read_dsp_timer(struct net_device *dev,
-                                 struct ft1000_info *info)
-{
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               info->DSP_TIME[0] = ft1000_read_dpram(dev, FT1000_DSP_TIMER0);
-               info->DSP_TIME[1] = ft1000_read_dpram(dev, FT1000_DSP_TIMER1);
-               info->DSP_TIME[2] = ft1000_read_dpram(dev, FT1000_DSP_TIMER2);
-               info->DSP_TIME[3] = ft1000_read_dpram(dev, FT1000_DSP_TIMER3);
-       } else {
-               info->DSP_TIME[0] =
-                       ft1000_read_dpram_mag_16(dev, FT1000_MAG_DSP_TIMER0,
-                                                FT1000_MAG_DSP_TIMER0_INDX);
-               info->DSP_TIME[1] =
-                       ft1000_read_dpram_mag_16(dev, FT1000_MAG_DSP_TIMER1,
-                                                FT1000_MAG_DSP_TIMER1_INDX);
-               info->DSP_TIME[2] =
-                       ft1000_read_dpram_mag_16(dev, FT1000_MAG_DSP_TIMER2,
-                                                FT1000_MAG_DSP_TIMER2_INDX);
-               info->DSP_TIME[3] =
-                       ft1000_read_dpram_mag_16(dev, FT1000_MAG_DSP_TIMER3,
-                                                FT1000_MAG_DSP_TIMER3_INDX);
-       }
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_reset_asic
-  Description: This function will call the Card Service function to reset the
-  ASIC.
-  Input:
-  dev    - device structure
-  Output:
-  none
-
-  -------------------------------------------------------------------------*/
-static void ft1000_reset_asic(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       struct ft1000_pcmcia *pcmcia = info->priv;
-       u16 tempword;
-
-       (*info->ft1000_reset) (pcmcia->link);
-
-       /*
-        * Let's use the register provided by the Magnemite ASIC to reset the
-        * ASIC and DSP.
-        */
-       if (info->AsicID == MAGNEMITE_ID) {
-               ft1000_write_reg(dev, FT1000_REG_RESET,
-                                DSP_RESET_BIT | ASIC_RESET_BIT);
-       }
-       mdelay(1);
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               /* set watermark to -1 in order to not generate an interrupt */
-               ft1000_write_reg(dev, FT1000_REG_WATERMARK, 0xffff);
-       } else {
-               /* set watermark to -1 in order to not generate an interrupt */
-               ft1000_write_reg(dev, FT1000_REG_MAG_WATERMARK, 0xffff);
-       }
-       /* clear interrupts */
-       tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
-       pr_debug("interrupt status register = 0x%x\n", tempword);
-       ft1000_write_reg(dev, FT1000_REG_SUP_ISR, tempword);
-       tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
-       pr_debug("interrupt status register = 0x%x\n", tempword);
-
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_reset_card
-  Description: This function will reset the card
-  Input:
-  dev    - device structure
-  Output:
-  status - false (card reset fail)
-  true  (card reset successful)
-
-  -------------------------------------------------------------------------*/
-static int ft1000_reset_card(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 tempword;
-       int i;
-       unsigned long flags;
-       struct prov_record *ptr;
-       struct prov_record *tmp;
-
-       info->CardReady = 0;
-       info->ProgConStat = 0;
-       info->squeseqnum = 0;
-       ft1000_disable_interrupts(dev);
-
-       /* del_timer(&poll_timer); */
-
-       /* Make sure we free any memory reserve for provisioning */
-       list_for_each_entry_safe(ptr, tmp, &info->prov_list, list) {
-               pr_debug("deleting provisioning record\n");
-               list_del(&ptr->list);
-               kfree(ptr->pprov_data);
-               kfree(ptr);
-       }
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               pr_debug("resetting DSP\n");
-               ft1000_write_reg(dev, FT1000_REG_RESET, DSP_RESET_BIT);
-       } else {
-               pr_debug("resetting ASIC and DSP\n");
-               ft1000_write_reg(dev, FT1000_REG_RESET,
-                                DSP_RESET_BIT | ASIC_RESET_BIT);
-       }
-
-       /* Copy DSP session record into info block if this is not a coldstart */
-       if (ft1000_card_present == 1) {
-               spin_lock_irqsave(&info->dpram_lock, flags);
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                        FT1000_DPRAM_RX_BASE);
-                       for (i = 0; i < MAX_DSP_SESS_REC; i++) {
-                               info->DSPSess.Rec[i] =
-                                       ft1000_read_reg(dev,
-                                                       FT1000_REG_DPRAM_DATA);
-                       }
-               } else {
-                       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                        FT1000_DPRAM_MAG_RX_BASE);
-                       for (i = 0; i < MAX_DSP_SESS_REC / 2; i++) {
-                               info->DSPSess.MagRec[i] =
-                                       inl(dev->base_addr
-                                               + FT1000_REG_MAG_DPDATA);
-                       }
-               }
-               spin_unlock_irqrestore(&info->dpram_lock, flags);
-       }
-
-       pr_debug("resetting ASIC\n");
-       mdelay(10);
-       /* reset ASIC */
-       ft1000_reset_asic(dev);
-
-       pr_debug("downloading dsp image\n");
-
-       if (info->AsicID == MAGNEMITE_ID) {
-               /* Put dsp in reset and take ASIC out of reset */
-               pr_debug("Put DSP in reset and take ASIC out of reset\n");
-               ft1000_write_reg(dev, FT1000_REG_RESET, DSP_RESET_BIT);
-
-               /* Setting MAGNEMITE ASIC to big endian mode */
-               ft1000_write_reg(dev, FT1000_REG_SUP_CTRL, HOST_INTF_BE);
-               /* Download bootloader */
-               card_bootload(dev);
-
-               /* Take DSP out of reset */
-               ft1000_write_reg(dev, FT1000_REG_RESET, 0);
-               /* FLARION_DSP_ACTIVE; */
-               mdelay(10);
-               pr_debug("Take DSP out of reset\n");
-
-               /*
-                * Wait for 0xfefe indicating dsp ready before starting
-                * download
-                */
-               for (i = 0; i < 50; i++) {
-                       tempword = ft1000_read_dpram_mag_16(dev,
-                                               FT1000_MAG_DPRAM_FEFE,
-                                               FT1000_MAG_DPRAM_FEFE_INDX);
-                       if (tempword == 0xfefe)
-                               break;
-                       mdelay(20);
-               }
-
-               if (i == 50) {
-                       pr_debug("No FEFE detected from DSP\n");
-                       return false;
-               }
-
-       } else {
-               /* Take DSP out of reset */
-               ft1000_write_reg(dev, FT1000_REG_RESET, ~DSP_RESET_BIT);
-               mdelay(10);
-       }
-
-       if (card_download(dev, fw_entry->data, fw_entry->size)) {
-               pr_debug("card download unsuccessful\n");
-               return false;
-       }
-       pr_debug("card download successful\n");
-
-       mdelay(10);
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               /*
-                * Need to initialize the FIFO length counter to zero in order
-                * to sync up with the DSP
-                */
-               info->fifo_cnt = 0;
-               ft1000_write_dpram(dev, FT1000_FIFO_LEN, info->fifo_cnt);
-               /* Initialize DSP heartbeat area to ho */
-               ft1000_write_dpram(dev, FT1000_HI_HO, ho);
-               tempword = ft1000_read_dpram(dev, FT1000_HI_HO);
-               pr_debug("hi_ho value = 0x%x\n", tempword);
-       } else {
-               /* Initialize DSP heartbeat area to ho */
-               ft1000_write_dpram_mag_16(dev, FT1000_MAG_HI_HO, ho_mag,
-                                         FT1000_MAG_HI_HO_INDX);
-               tempword =
-                       ft1000_read_dpram_mag_16(dev, FT1000_MAG_HI_HO,
-                                                FT1000_MAG_HI_HO_INDX);
-               pr_debug("hi_ho value = 0x%x\n", tempword);
-       }
-
-       info->CardReady = 1;
-       ft1000_enable_interrupts(dev);
-
-       /* Schedule heartbeat process to run every 2 seconds */
-       /* poll_timer.expires = jiffies + (2*HZ); */
-       /* poll_timer.data = (u_long)dev; */
-       /* add_timer(&poll_timer); */
-
-       return true;
-
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_chkcard
-  Description: This function will check if the device is presently available on
-  the system.
-  Input:
-  dev    - device structure
-  Output:
-  status - false (device is not present)
-  true  (device is present)
-
-  -------------------------------------------------------------------------*/
-static int ft1000_chkcard(struct net_device *dev)
-{
-       u16 tempword;
-
-       /*
-        * Mask register is used to check for device presence since it is never
-        * set to zero.
-        */
-       tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK);
-       if (tempword == 0) {
-               pr_debug("IMASK = 0 Card not detected\n");
-               return false;
-       }
-       /*
-        * The system will return the value of 0xffff for the version register
-        * if the device is not present.
-        */
-       tempword = ft1000_read_reg(dev, FT1000_REG_ASIC_ID);
-       if (tempword == 0xffff) {
-               pr_debug("Version = 0xffff Card not detected\n");
-               return false;
-       }
-       return true;
-}
-
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_hbchk
-  Description: This function will perform the heart beat check of the DSP as
-  well as the ASIC.
-  Input:
-  dev    - device structure
-  Output:
-  none
-
-  -------------------------------------------------------------------------*/
-static void ft1000_hbchk(u_long data)
-{
-       struct net_device *dev = (struct net_device *)data;
-
-       struct ft1000_info *info;
-       u16 tempword;
-
-       info = netdev_priv(dev);
-
-       if (info->CardReady == 1) {
-               /* Perform dsp heartbeat check */
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       tempword = ft1000_read_dpram(dev, FT1000_HI_HO);
-               } else {
-                       tempword =
-                               ntohs(ft1000_read_dpram_mag_16
-                                     (dev, FT1000_MAG_HI_HO,
-                                      FT1000_MAG_HI_HO_INDX));
-               }
-               pr_debug("hi_ho value = 0x%x\n", tempword);
-               /* Let's perform another check if ho is not detected */
-               if (tempword != ho) {
-                       if (info->AsicID == ELECTRABUZZ_ID)
-                               tempword = ft1000_read_dpram(dev, FT1000_HI_HO);
-                       else
-                               tempword = ntohs(ft1000_read_dpram_mag_16(dev,
-                                                       FT1000_MAG_HI_HO,
-                                                       FT1000_MAG_HI_HO_INDX));
-               }
-               if (tempword != ho) {
-                       pr_info("heartbeat failed - no ho detected\n");
-                       ft1000_read_dsp_timer(dev, info);
-                       info->DrvErrNum = DSP_HB_INFO;
-                       if (ft1000_reset_card(dev) == 0) {
-                               pr_info("Hardware Failure Detected - PC Card disabled\n");
-                               info->ProgConStat = 0xff;
-                               return;
-                       }
-                       /* Schedule this module to run every 2 seconds */
-                       poll_timer.expires = jiffies + (2*HZ);
-                       poll_timer.data = (u_long)dev;
-                       add_timer(&poll_timer);
-                       return;
-               }
-
-               tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
-               /* Let's check doorbell again if fail */
-               if (tempword & FT1000_DB_HB)
-                       tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
-
-               if (tempword & FT1000_DB_HB) {
-                       pr_info("heartbeat doorbell not clear by firmware\n");
-                       ft1000_read_dsp_timer(dev, info);
-                       info->DrvErrNum = DSP_HB_INFO;
-                       if (ft1000_reset_card(dev) == 0) {
-                               pr_info("Hardware Failure Detected - PC Card disabled\n");
-                               info->ProgConStat = 0xff;
-                               return;
-                       }
-                       /* Schedule this module to run every 2 seconds */
-                       poll_timer.expires = jiffies + (2*HZ);
-                       poll_timer.data = (u_long)dev;
-                       add_timer(&poll_timer);
-                       return;
-               }
-               /*
-                * Set dedicated area to hi and ring appropriate doorbell
-                * according to hi/ho heartbeat protocol
-                */
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       ft1000_write_dpram(dev, FT1000_HI_HO, hi);
-               } else {
-                       ft1000_write_dpram_mag_16(dev, FT1000_MAG_HI_HO, hi_mag,
-                                                 FT1000_MAG_HI_HO_INDX);
-               }
-
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       tempword = ft1000_read_dpram(dev, FT1000_HI_HO);
-               } else {
-                       tempword =
-                               ntohs(ft1000_read_dpram_mag_16
-                                     (dev, FT1000_MAG_HI_HO,
-                                      FT1000_MAG_HI_HO_INDX));
-               }
-               /* Let's write hi again if fail */
-               if (tempword != hi) {
-                       if (info->AsicID == ELECTRABUZZ_ID)
-                               ft1000_write_dpram(dev, FT1000_HI_HO, hi);
-                       else
-                               ft1000_write_dpram_mag_16(dev, FT1000_MAG_HI_HO,
-                                               hi_mag, FT1000_MAG_HI_HO_INDX);
-
-                       if (info->AsicID == ELECTRABUZZ_ID)
-                               tempword = ft1000_read_dpram(dev, FT1000_HI_HO);
-                       else
-                               tempword = ntohs(ft1000_read_dpram_mag_16(dev,
-                                                       FT1000_MAG_HI_HO,
-                                                       FT1000_MAG_HI_HO_INDX));
-               }
-
-               if (tempword != hi) {
-                       pr_info("heartbeat failed - cannot write hi into DPRAM\n");
-                       ft1000_read_dsp_timer(dev, info);
-                       info->DrvErrNum = DSP_HB_INFO;
-                       if (ft1000_reset_card(dev) == 0) {
-                               pr_info("Hardware Failure Detected - PC Card disabled\n");
-                               info->ProgConStat = 0xff;
-                               return;
-                       }
-                       /* Schedule this module to run every 2 seconds */
-                       poll_timer.expires = jiffies + (2*HZ);
-                       poll_timer.data = (u_long)dev;
-                       add_timer(&poll_timer);
-                       return;
-               }
-               ft1000_write_reg(dev, FT1000_REG_DOORBELL, FT1000_DB_HB);
-
-       }
-
-       /* Schedule this module to run every 2 seconds */
-       poll_timer.expires = jiffies + (2 * HZ);
-       poll_timer.data = (u_long)dev;
-       add_timer(&poll_timer);
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_send_cmd
-  Description:
-  Input:
-  Output:
-
-  -------------------------------------------------------------------------*/
-static void ft1000_send_cmd(struct net_device *dev, u16 *ptempbuffer, int size,
-                           u16 qtype)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       int i;
-       u16 tempword;
-       unsigned long flags;
-
-       size += sizeof(struct pseudo_hdr);
-       /* check for odd byte and increment to 16-bit word align value */
-       if ((size & 0x0001))
-               size++;
-       pr_debug("total length = %d\n", size);
-       pr_debug("length = %d\n", ntohs(*ptempbuffer));
-       /*
-        * put message into slow queue area
-        * All messages are in the form total_len + pseudo header + message body
-        */
-       spin_lock_irqsave(&info->dpram_lock, flags);
-
-       /* Make sure SLOWQ doorbell is clear */
-       tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
-       i = 0;
-       while (tempword & FT1000_DB_DPRAM_TX) {
-               mdelay(10);
-               i++;
-               if (i == 10) {
-                       spin_unlock_irqrestore(&info->dpram_lock, flags);
-                       return;
-               }
-               tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
-       }
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                FT1000_DPRAM_TX_BASE);
-               /* Write total length to dpram */
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, size);
-               /* Write pseudo header and messgae body */
-               for (i = 0; i < (size >> 1); i++) {
-                       pr_debug("data %d = 0x%x\n", i, *ptempbuffer);
-                       tempword = htons(*ptempbuffer++);
-                       ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, tempword);
-               }
-       } else {
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                FT1000_DPRAM_MAG_TX_BASE);
-               /* Write total length to dpram */
-               ft1000_write_reg(dev, FT1000_REG_MAG_DPDATAH, htons(size));
-               /* Write pseudo header and messgae body */
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                FT1000_DPRAM_MAG_TX_BASE + 1);
-               for (i = 0; i < (size >> 2); i++) {
-                       pr_debug("data = 0x%x\n", *ptempbuffer);
-                       outw(*ptempbuffer++,
-                            dev->base_addr + FT1000_REG_MAG_DPDATAL);
-                       pr_debug("data = 0x%x\n", *ptempbuffer);
-                       outw(*ptempbuffer++,
-                            dev->base_addr + FT1000_REG_MAG_DPDATAH);
-               }
-               pr_debug("data = 0x%x\n", *ptempbuffer);
-               outw(*ptempbuffer++, dev->base_addr + FT1000_REG_MAG_DPDATAL);
-               pr_debug("data = 0x%x\n", *ptempbuffer);
-               outw(*ptempbuffer++, dev->base_addr + FT1000_REG_MAG_DPDATAH);
-       }
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-
-       /* ring doorbell to notify DSP that we have a message ready */
-       ft1000_write_reg(dev, FT1000_REG_DOORBELL, FT1000_DB_DPRAM_TX);
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_receive_cmd
-  Description: This function will read a message from the dpram area.
-  Input:
-  dev - network device structure
-  pbuffer - caller supply address to buffer
-  pnxtph - pointer to next pseudo header
-  Output:
-  Status = 0 (unsuccessful)
-  = 1 (successful)
-
-  -------------------------------------------------------------------------*/
-static bool ft1000_receive_cmd(struct net_device *dev, u16 *pbuffer,
-                              int maxsz, u16 *pnxtph)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 size;
-       u16 *ppseudohdr;
-       int i;
-       u16 tempword;
-       unsigned long flags;
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               size = ft1000_read_dpram(dev, *pnxtph)
-                       + sizeof(struct pseudo_hdr);
-       } else {
-               size = ntohs(ft1000_read_dpram_mag_16(dev, FT1000_MAG_PH_LEN,
-                                                     FT1000_MAG_PH_LEN_INDX))
-                               + sizeof(struct pseudo_hdr);
-       }
-       if (size > maxsz) {
-               pr_debug("Invalid command length = %d\n", size);
-               return false;
-       }
-       ppseudohdr = (u16 *)pbuffer;
-       spin_lock_irqsave(&info->dpram_lock, flags);
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                FT1000_DPRAM_RX_BASE + 2);
-               for (i = 0; i <= (size >> 1); i++) {
-                       tempword =
-                               ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA);
-                       *pbuffer++ = ntohs(tempword);
-               }
-       } else {
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                FT1000_DPRAM_MAG_RX_BASE);
-               *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAH);
-               pr_debug("received data = 0x%x\n", *pbuffer);
-               pbuffer++;
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                FT1000_DPRAM_MAG_RX_BASE + 1);
-               for (i = 0; i <= (size >> 2); i++) {
-                       *pbuffer =
-                               inw(dev->base_addr +
-                                   FT1000_REG_MAG_DPDATAL);
-                       pbuffer++;
-                       *pbuffer =
-                               inw(dev->base_addr +
-                                   FT1000_REG_MAG_DPDATAH);
-                       pbuffer++;
-               }
-               /* copy odd aligned word */
-               *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAL);
-               pr_debug("received data = 0x%x\n", *pbuffer);
-               pbuffer++;
-               *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAH);
-               pr_debug("received data = 0x%x\n", *pbuffer);
-               pbuffer++;
-       }
-       if (size & 0x0001) {
-               /* copy odd byte from fifo */
-               tempword = ft1000_read_reg(dev, FT1000_REG_DPRAM_DATA);
-               *pbuffer = ntohs(tempword);
-       }
-       spin_unlock_irqrestore(&info->dpram_lock, flags);
-
-       /*
-        * Check if pseudo header checksum is good
-        * Calculate pseudo header checksum
-        */
-       tempword = *ppseudohdr++;
-       for (i = 1; i < 7; i++)
-               tempword ^= *ppseudohdr++;
-       if (tempword != *ppseudohdr) {
-               pr_debug("Pseudo header checksum mismatch\n");
-               /* Drop this message */
-               return false;
-       }
-       return true;
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_proc_drvmsg
-  Description: This function will process the various driver messages.
-  Input:
-  dev    - device structure
-  pnxtph - pointer to next pseudo header
-  Output:
-  none
-
-  -------------------------------------------------------------------------*/
-static void ft1000_proc_drvmsg(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 msgtype;
-       u16 tempword;
-       struct media_msg *pmediamsg;
-       struct dsp_init_msg *pdspinitmsg;
-       struct drv_msg *pdrvmsg;
-       u16 len;
-       u16 i;
-       struct prov_record *ptr;
-       struct pseudo_hdr *ppseudo_hdr;
-       u16 *pmsg;
-       struct timeval tv;
-       union {
-               u8 byte[2];
-               u16 wrd;
-       } convert;
-
-       if (info->AsicID == ELECTRABUZZ_ID)
-               tempword = FT1000_DPRAM_RX_BASE+2;
-       else
-               tempword = FT1000_DPRAM_MAG_RX_BASE;
-
-       if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword)) {
-
-               /*
-                * Get the message type which is total_len + PSEUDO header
-                * + msgtype + message body
-                */
-               pdrvmsg = (struct drv_msg *)&cmdbuffer[0];
-               msgtype = ntohs(pdrvmsg->type);
-               pr_debug("Command message type = 0x%x\n", msgtype);
-               switch (msgtype) {
-               case DSP_PROVISION:
-                       pr_debug("Got a provisioning request message from DSP\n");
-                       mdelay(25);
-                       while (list_empty(&info->prov_list) == 0) {
-                               pr_debug("Sending a provisioning message\n");
-                               /* Make sure SLOWQ doorbell is clear */
-                               tempword = ft1000_read_reg(dev,
-                                                          FT1000_REG_DOORBELL);
-                               i = 0;
-                               while (tempword & FT1000_DB_DPRAM_TX) {
-                                       mdelay(5);
-                                       i++;
-                                       if (i == 10)
-                                               break;
-                               }
-                               ptr = list_entry(info->prov_list.next,
-                                                struct prov_record, list);
-                               len = *(u16 *)ptr->pprov_data;
-                               len = htons(len);
-
-                               pmsg = (u16 *)ptr->pprov_data;
-                               ppseudo_hdr = (struct pseudo_hdr *)pmsg;
-                               /* Insert slow queue sequence number */
-                               ppseudo_hdr->seq_num = info->squeseqnum++;
-                               ppseudo_hdr->portsrc = 0;
-                               /* Calculate new checksum */
-                               ppseudo_hdr->checksum = *pmsg++;
-                               pr_debug("checksum = 0x%x\n",
-                                        ppseudo_hdr->checksum);
-                               for (i = 1; i < 7; i++) {
-                                       ppseudo_hdr->checksum ^= *pmsg++;
-                                       pr_debug("checksum = 0x%x\n",
-                                                ppseudo_hdr->checksum);
-                               }
-
-                               ft1000_send_cmd(dev, (u16 *)ptr->pprov_data,
-                                               len, SLOWQ_TYPE);
-                               list_del(&ptr->list);
-                               kfree(ptr->pprov_data);
-                               kfree(ptr);
-                       }
-                       /*
-                        * Indicate adapter is ready to take application
-                        * messages after all provisioning messages are sent
-                        */
-                       info->CardReady = 1;
-                       break;
-               case MEDIA_STATE:
-                       pmediamsg = (struct media_msg *)&cmdbuffer[0];
-                       if (info->ProgConStat != 0xFF) {
-                               if (pmediamsg->state) {
-                                       pr_debug("Media is up\n");
-                                       if (info->mediastate == 0) {
-                                               netif_carrier_on(dev);
-                                               netif_wake_queue(dev);
-                                               info->mediastate = 1;
-                                               do_gettimeofday(&tv);
-                                               info->ConTm = tv.tv_sec;
-                                       }
-                               } else {
-                                       pr_debug("Media is down\n");
-                                       if (info->mediastate == 1) {
-                                               info->mediastate = 0;
-                                               netif_carrier_off(dev);
-                                               netif_stop_queue(dev);
-                                               info->ConTm = 0;
-                                       }
-                               }
-                       } else {
-                               pr_debug("Media is down\n");
-                               if (info->mediastate == 1) {
-                                       info->mediastate = 0;
-                                       netif_carrier_off(dev);
-                                       netif_stop_queue(dev);
-                                       info->ConTm = 0;
-                               }
-                       }
-                       break;
-               case DSP_INIT_MSG:
-                       pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[0];
-                       memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
-                       pr_debug("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n",
-                                info->DspVer[0], info->DspVer[1],
-                                info->DspVer[2], info->DspVer[3]);
-                       memcpy(info->HwSerNum, pdspinitmsg->HwSerNum,
-                              HWSERNUMSZ);
-                       memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
-                       memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
-                       dev->dev_addr[0] = info->eui64[0];
-                       dev->dev_addr[1] = info->eui64[1];
-                       dev->dev_addr[2] = info->eui64[2];
-                       dev->dev_addr[3] = info->eui64[5];
-                       dev->dev_addr[4] = info->eui64[6];
-                       dev->dev_addr[5] = info->eui64[7];
-
-                       if (ntohs(pdspinitmsg->length) ==
-                           (sizeof(struct dsp_init_msg) - 20)) {
-                               memcpy(info->ProductMode,
-                                      pdspinitmsg->ProductMode, MODESZ);
-                               memcpy(info->RfCalVer, pdspinitmsg->RfCalVer,
-                                      CALVERSZ);
-                               memcpy(info->RfCalDate, pdspinitmsg->RfCalDate,
-                                      CALDATESZ);
-                               pr_debug("RFCalVer = 0x%2x 0x%2x\n",
-                                        info->RfCalVer[0], info->RfCalVer[1]);
-                       }
-
-                       break;
-               case DSP_STORE_INFO:
-                       pr_debug("Got DSP_STORE_INFO\n");
-                       tempword = ntohs(pdrvmsg->length);
-                       info->DSPInfoBlklen = tempword;
-                       if (tempword < (MAX_DSP_SESS_REC - 4)) {
-                               pmsg = (u16 *)&pdrvmsg->data[0];
-                               for (i = 0; i < ((tempword + 1) / 2); i++) {
-                                       pr_debug("dsp info data = 0x%x\n",
-                                                *pmsg);
-                                       info->DSPInfoBlk[i + 10] = *pmsg++;
-                               }
-                       }
-                       break;
-               case DSP_GET_INFO:
-                       pr_debug("Got DSP_GET_INFO\n");
-                       /*
-                        * copy dsp info block to dsp
-                        * allow any outstanding ioctl to finish
-                        */
-                       mdelay(10);
-                       tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
-                       if (tempword & FT1000_DB_DPRAM_TX) {
-                               mdelay(10);
-                               tempword = ft1000_read_reg(dev,
-                                                          FT1000_REG_DOORBELL);
-                               if (tempword & FT1000_DB_DPRAM_TX)
-                                       mdelay(10);
-                       }
-
-                       if ((tempword & FT1000_DB_DPRAM_TX) == 0) {
-                               /*
-                                * Put message into Slow Queue
-                                * Form Pseudo header
-                                */
-                               pmsg = (u16 *)info->DSPInfoBlk;
-                               ppseudo_hdr = (struct pseudo_hdr *)pmsg;
-                               ppseudo_hdr->length =
-                                       htons(info->DSPInfoBlklen + 4);
-                               ppseudo_hdr->source = 0x10;
-                               ppseudo_hdr->destination = 0x20;
-                               ppseudo_hdr->portdest = 0;
-                               ppseudo_hdr->portsrc = 0;
-                               ppseudo_hdr->sh_str_id = 0;
-                               ppseudo_hdr->control = 0;
-                               ppseudo_hdr->rsvd1 = 0;
-                               ppseudo_hdr->rsvd2 = 0;
-                               ppseudo_hdr->qos_class = 0;
-                               /* Insert slow queue sequence number */
-                               ppseudo_hdr->seq_num = info->squeseqnum++;
-                               /* Insert application id */
-                               ppseudo_hdr->portsrc = 0;
-                               /* Calculate new checksum */
-                               ppseudo_hdr->checksum = *pmsg++;
-                               for (i = 1; i < 7; i++)
-                                       ppseudo_hdr->checksum ^= *pmsg++;
-
-                               info->DSPInfoBlk[8] = 0x7200;
-                               info->DSPInfoBlk[9] =
-                                       htons(info->DSPInfoBlklen);
-                               ft1000_send_cmd(dev, info->DSPInfoBlk,
-                                               (u16)(info->DSPInfoBlklen+4),
-                                               0);
-                       }
-
-                       break;
-               case GET_DRV_ERR_RPT_MSG:
-                       pr_debug("Got GET_DRV_ERR_RPT_MSG\n");
-                       /*
-                        * copy driver error message to dsp
-                        * allow any outstanding ioctl to finish
-                        */
-                       mdelay(10);
-                       tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
-                       if (tempword & FT1000_DB_DPRAM_TX) {
-                               mdelay(10);
-                               tempword = ft1000_read_reg(dev,
-                                                          FT1000_REG_DOORBELL);
-                               if (tempword & FT1000_DB_DPRAM_TX)
-                                       mdelay(10);
-                       }
-
-                       if ((tempword & FT1000_DB_DPRAM_TX) == 0) {
-                               /*
-                                * Put message into Slow Queue
-                                * Form Pseudo header
-                                */
-                               pmsg = (u16 *)&tempbuffer[0];
-                               ppseudo_hdr = (struct pseudo_hdr *)pmsg;
-                               ppseudo_hdr->length = htons(0x0012);
-                               ppseudo_hdr->source = 0x10;
-                               ppseudo_hdr->destination = 0x20;
-                               ppseudo_hdr->portdest = 0;
-                               ppseudo_hdr->portsrc = 0;
-                               ppseudo_hdr->sh_str_id = 0;
-                               ppseudo_hdr->control = 0;
-                               ppseudo_hdr->rsvd1 = 0;
-                               ppseudo_hdr->rsvd2 = 0;
-                               ppseudo_hdr->qos_class = 0;
-                               /* Insert slow queue sequence number */
-                               ppseudo_hdr->seq_num = info->squeseqnum++;
-                               /* Insert application id */
-                               ppseudo_hdr->portsrc = 0;
-                               /* Calculate new checksum */
-                               ppseudo_hdr->checksum = *pmsg++;
-                               for (i = 1; i < 7; i++)
-                                       ppseudo_hdr->checksum ^= *pmsg++;
-
-                               pmsg = (u16 *)&tempbuffer[16];
-                               *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
-                               *pmsg++ = htons(0x000e);
-                               *pmsg++ = htons(info->DSP_TIME[0]);
-                               *pmsg++ = htons(info->DSP_TIME[1]);
-                               *pmsg++ = htons(info->DSP_TIME[2]);
-                               *pmsg++ = htons(info->DSP_TIME[3]);
-                               convert.byte[0] = info->DspVer[0];
-                               convert.byte[1] = info->DspVer[1];
-                               *pmsg++ = convert.wrd;
-                               convert.byte[0] = info->DspVer[2];
-                               convert.byte[1] = info->DspVer[3];
-                               *pmsg++ = convert.wrd;
-                               *pmsg++ = htons(info->DrvErrNum);
-
-                               ft1000_send_cmd(dev, (u16 *)&tempbuffer[0],
-                                               (u16)(0x0012), 0);
-                               info->DrvErrNum = 0;
-                       }
-
-                       break;
-               default:
-                       break;
-               }
-       }
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_parse_dpram_msg
-  Description: This function will parse the message received from the DSP
-  via the DPRAM interface.
-  Input:
-  dev    - device structure
-  Output:
-  status - FAILURE
-  SUCCESS
-
-  -------------------------------------------------------------------------*/
-static int ft1000_parse_dpram_msg(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 doorbell;
-       u16 portid;
-       u16 nxtph;
-       u16 total_len;
-       int i = 0;
-       unsigned long flags;
-
-       doorbell = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
-       pr_debug("Doorbell = 0x%x\n", doorbell);
-
-       if (doorbell & FT1000_ASIC_RESET_REQ) {
-               /* Copy DSP session record from info block */
-               spin_lock_irqsave(&info->dpram_lock, flags);
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                        FT1000_DPRAM_RX_BASE);
-                       for (i = 0; i < MAX_DSP_SESS_REC; i++) {
-                               ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA,
-                                                info->DSPSess.Rec[i]);
-                       }
-               } else {
-                       ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
-                                        FT1000_DPRAM_MAG_RX_BASE);
-                       for (i = 0; i < MAX_DSP_SESS_REC / 2; i++) {
-                               outl(info->DSPSess.MagRec[i],
-                                    dev->base_addr + FT1000_REG_MAG_DPDATA);
-                       }
-               }
-               spin_unlock_irqrestore(&info->dpram_lock, flags);
-
-               /* clear ASIC RESET request */
-               ft1000_write_reg(dev, FT1000_REG_DOORBELL,
-                                FT1000_ASIC_RESET_REQ);
-               pr_debug("Got an ASIC RESET Request\n");
-               ft1000_write_reg(dev, FT1000_REG_DOORBELL,
-                                FT1000_ASIC_RESET_DSP);
-
-               if (info->AsicID == MAGNEMITE_ID) {
-                       /* Setting MAGNEMITE ASIC to big endian mode */
-                       ft1000_write_reg(dev, FT1000_REG_SUP_CTRL,
-                                        HOST_INTF_BE);
-               }
-       }
-
-       if (doorbell & FT1000_DSP_ASIC_RESET) {
-               pr_debug("Got a dsp ASIC reset message\n");
-               ft1000_write_reg(dev, FT1000_REG_DOORBELL,
-                                FT1000_DSP_ASIC_RESET);
-               udelay(200);
-               return SUCCESS;
-       }
-
-       if (doorbell & FT1000_DB_DPRAM_RX) {
-               pr_debug("Got a slow queue message\n");
-               nxtph = FT1000_DPRAM_RX_BASE + 2;
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       total_len =
-                               ft1000_read_dpram(dev, FT1000_DPRAM_RX_BASE);
-               } else {
-                       total_len =
-                               ntohs(ft1000_read_dpram_mag_16
-                                     (dev, FT1000_MAG_TOTAL_LEN,
-                                      FT1000_MAG_TOTAL_LEN_INDX));
-               }
-               pr_debug("total length = %d\n", total_len);
-               if ((total_len < MAX_CMD_SQSIZE)
-                               && (total_len > sizeof(struct pseudo_hdr))) {
-                       total_len += nxtph;
-                       /*
-                        * ft1000_read_reg will return a value that needs to be
-                        * byteswap in order to get DSP_QID_OFFSET.
-                        */
-                       if (info->AsicID == ELECTRABUZZ_ID) {
-                               portid = (ft1000_read_dpram(dev, DSP_QID_OFFSET
-                                               + FT1000_DPRAM_RX_BASE + 2)
-                                               >> 8) & 0xff;
-                       } else {
-                               portid =
-                                       ft1000_read_dpram_mag_16
-                                        (dev, FT1000_MAG_PORT_ID,
-                                         FT1000_MAG_PORT_ID_INDX) & 0xff;
-                       }
-                       pr_debug("DSP_QID = 0x%x\n", portid);
-
-                       if (portid == DRIVERID) {
-                               /*
-                                * We are assumming one driver message from the
-                                * DSP at a time.
-                                */
-                               ft1000_proc_drvmsg(dev);
-                       }
-               }
-               ft1000_write_reg(dev, FT1000_REG_DOORBELL, FT1000_DB_DPRAM_RX);
-       }
-
-       if (doorbell & FT1000_DB_COND_RESET) {
-               /* Reset ASIC and DSP */
-               ft1000_read_dsp_timer(dev, info);
-               info->DrvErrNum = DSP_CONDRESET_INFO;
-               pr_debug("DSP conditional reset requested\n");
-               ft1000_reset_card(dev);
-               ft1000_write_reg(dev, FT1000_REG_DOORBELL,
-                                FT1000_DB_COND_RESET);
-       }
-       /* let's clear any unexpected doorbells from DSP */
-       doorbell =
-               doorbell & ~(FT1000_DB_DPRAM_RX | FT1000_ASIC_RESET_REQ |
-                            FT1000_DB_COND_RESET | 0xff00);
-       if (doorbell) {
-               pr_debug("Clearing unexpected doorbell = 0x%x\n", doorbell);
-               ft1000_write_reg(dev, FT1000_REG_DOORBELL, doorbell);
-       }
-
-       return SUCCESS;
-
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_flush_fifo
-  Description: This function will flush one packet from the downlink
-  FIFO.
-  Input:
-  dev      - device structure
-  drv_err  - driver error causing the flush fifo
-  Output:
-  None.
-
-  -------------------------------------------------------------------------*/
-static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       struct ft1000_pcmcia *pcmcia = info->priv;
-       u16 i;
-       u32 templong;
-       u16 tempword;
-
-       if (pcmcia->PktIntfErr > MAX_PH_ERR) {
-               ft1000_read_dsp_timer(dev, info);
-               info->DrvErrNum = DrvErrNum;
-               ft1000_reset_card(dev);
-               return;
-       }
-       /* Flush corrupted pkt from FIFO */
-       i = 0;
-       do {
-               if (info->AsicID == ELECTRABUZZ_ID) {
-                       tempword =
-                               ft1000_read_reg(dev, FT1000_REG_DFIFO);
-                       tempword =
-                               ft1000_read_reg(dev, FT1000_REG_DFIFO_STAT);
-               } else {
-                       templong =
-                               inl(dev->base_addr + FT1000_REG_MAG_DFR);
-                       tempword =
-                               inw(dev->base_addr + FT1000_REG_MAG_DFSR);
-               }
-               i++;
-               /*
-                * This should never happen unless the ASIC is broken.
-                * We must reset to recover.
-                */
-               if ((i > 2048) || (tempword == 0)) {
-                       ft1000_read_dsp_timer(dev, info);
-                       if (tempword == 0) {
-                               /*
-                                * Let's check if ASIC reads are still ok by
-                                * reading the Mask register which is never zero
-                                * at this point of the code.
-                                */
-                               tempword =
-                                       inw(dev->base_addr +
-                                           FT1000_REG_SUP_IMASK);
-                               if (tempword == 0) {
-                                       /*
-                                        * This indicates that we can not
-                                        * communicate with the ASIC
-                                        */
-                                       info->DrvErrNum = FIFO_FLUSH_BADCNT;
-                               } else {
-                                       /*
-                                        * Let's assume that we really flush
-                                        * the FIFO
-                                        */
-                                       pcmcia->PktIntfErr++;
-                                       return;
-                               }
-                       } else {
-                               info->DrvErrNum = FIFO_FLUSH_MAXLIMIT;
-                       }
-                       return;
-               }
-               tempword = inw(dev->base_addr + FT1000_REG_SUP_STAT);
-       } while ((tempword & 0x03) != 0x03);
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               i++;
-               pr_debug("Flushing FIFO complete = %x\n", tempword);
-               /* Flush last word in FIFO. */
-               tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
-               /* Update FIFO counter for DSP */
-               i = i * 2;
-               pr_debug("Flush Data byte count to dsp = %d\n", i);
-               info->fifo_cnt += i;
-               ft1000_write_dpram(dev, FT1000_FIFO_LEN,
-                                  info->fifo_cnt);
-       } else {
-               pr_debug("Flushing FIFO complete = %x\n", tempword);
-               /* Flush last word in FIFO */
-               templong = inl(dev->base_addr + FT1000_REG_MAG_DFR);
-               tempword = inw(dev->base_addr + FT1000_REG_SUP_STAT);
-               pr_debug("FT1000_REG_SUP_STAT = 0x%x\n", tempword);
-               tempword = inw(dev->base_addr + FT1000_REG_MAG_DFSR);
-               pr_debug("FT1000_REG_MAG_DFSR = 0x%x\n", tempword);
-       }
-       if (DrvErrNum)
-               pcmcia->PktIntfErr++;
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_copy_up_pkt
-  Description: This function will pull Flarion packets out of the Downlink
-  FIFO and convert it to an ethernet packet.  The ethernet packet will
-  then be deliver to the TCP/IP stack.
-  Input:
-  dev    - device structure
-  Output:
-  status - FAILURE
-  SUCCESS
-
-  -------------------------------------------------------------------------*/
-static int ft1000_copy_up_pkt(struct net_device *dev)
-{
-       u16 tempword;
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 len;
-       struct sk_buff *skb;
-       u16 i;
-       u8 *pbuffer = NULL;
-       u8 *ptemp = NULL;
-       u16 chksum;
-       u32 *ptemplong;
-       u32 templong;
-
-       /* Read length */
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
-               len = tempword;
-       } else {
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL);
-               len = ntohs(tempword);
-       }
-       chksum = tempword;
-       pr_debug("Number of Bytes in FIFO = %d\n", len);
-
-       if (len > ENET_MAX_SIZE) {
-               pr_debug("size of ethernet packet invalid\n");
-               if (info->AsicID == MAGNEMITE_ID) {
-                       /* Read High word to complete 32 bit access */
-                       tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
-               }
-               ft1000_flush_fifo(dev, DSP_PKTLEN_INFO);
-               info->stats.rx_errors++;
-               return FAILURE;
-       }
-
-       skb = dev_alloc_skb(len + 12 + 2);
-
-       if (skb == NULL) {
-               /* Read High word to complete 32 bit access */
-               if (info->AsicID == MAGNEMITE_ID)
-                       tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
-
-               ft1000_flush_fifo(dev, 0);
-               info->stats.rx_errors++;
-               return FAILURE;
-       }
-       pbuffer = (u8 *)skb_put(skb, len + 12);
-
-       /* Pseudo header */
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               for (i = 1; i < 7; i++) {
-                       tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
-                       chksum ^= tempword;
-               }
-               /* read checksum value */
-               tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
-       } else {
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
-               pr_debug("Pseudo = 0x%x\n", tempword);
-               chksum ^= tempword;
-
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL);
-               pr_debug("Pseudo = 0x%x\n", tempword);
-               chksum ^= tempword;
-
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
-               pr_debug("Pseudo = 0x%x\n", tempword);
-               chksum ^= tempword;
-
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL);
-               pr_debug("Pseudo = 0x%x\n", tempword);
-               chksum ^= tempword;
-
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
-               pr_debug("Pseudo = 0x%x\n", tempword);
-               chksum ^= tempword;
-
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL);
-               pr_debug("Pseudo = 0x%x\n", tempword);
-               chksum ^= tempword;
-
-               /* read checksum value */
-               tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
-               pr_debug("Pseudo = 0x%x\n", tempword);
-       }
-
-       if (chksum != tempword) {
-               pr_debug("Packet checksum mismatch 0x%x 0x%x\n",
-                        chksum, tempword);
-               ft1000_flush_fifo(dev, DSP_PKTPHCKSUM_INFO);
-               info->stats.rx_errors++;
-               kfree_skb(skb);
-               return FAILURE;
-       }
-       /* subtract the number of bytes read already */
-       ptemp = pbuffer;
-
-       /* fake MAC address */
-       *pbuffer++ = dev->dev_addr[0];
-       *pbuffer++ = dev->dev_addr[1];
-       *pbuffer++ = dev->dev_addr[2];
-       *pbuffer++ = dev->dev_addr[3];
-       *pbuffer++ = dev->dev_addr[4];
-       *pbuffer++ = dev->dev_addr[5];
-       *pbuffer++ = 0x00;
-       *pbuffer++ = 0x07;
-       *pbuffer++ = 0x35;
-       *pbuffer++ = 0xff;
-       *pbuffer++ = 0xff;
-       *pbuffer++ = 0xfe;
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               for (i = 0; i < len / 2; i++) {
-                       tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
-                       *pbuffer++ = (u8) (tempword >> 8);
-                       *pbuffer++ = (u8)tempword;
-                       if (ft1000_chkcard(dev) == false) {
-                               kfree_skb(skb);
-                               return FAILURE;
-                       }
-               }
-
-               /* Need to read one more word if odd byte */
-               if (len & 0x0001) {
-                       tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
-                       *pbuffer++ = (u8) (tempword >> 8);
-               }
-       } else {
-               ptemplong = (u32 *)pbuffer;
-               for (i = 0; i < len / 4; i++) {
-                       templong = inl(dev->base_addr + FT1000_REG_MAG_DFR);
-                       pr_debug("Data = 0x%8x\n", templong);
-                       *ptemplong++ = templong;
-               }
-
-               /* Need to read one more word if odd align. */
-               if (len & 0x0003) {
-                       templong = inl(dev->base_addr + FT1000_REG_MAG_DFR);
-                       pr_debug("Data = 0x%8x\n", templong);
-                       *ptemplong++ = templong;
-               }
-
-       }
-
-       pr_debug("Data passed to Protocol layer:\n");
-       for (i = 0; i < len + 12; i++)
-               pr_debug("Protocol Data: 0x%x\n", *ptemp++);
-
-       skb->dev = dev;
-       skb->protocol = eth_type_trans(skb, dev);
-       skb->ip_summed = CHECKSUM_UNNECESSARY;
-       netif_rx(skb);
-
-       info->stats.rx_packets++;
-       /* Add on 12 bytes for MAC address which was removed */
-       info->stats.rx_bytes += (len + 12);
-
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               /* track how many bytes have been read from FIFO - round up to
-                * 16 bit word */
-               tempword = len + 16;
-               if (tempword & 0x01)
-                       tempword++;
-               info->fifo_cnt += tempword;
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, FT1000_FIFO_LEN);
-               ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, info->fifo_cnt);
-       }
-
-       return SUCCESS;
-}
-
-/*---------------------------------------------------------------------------
-
-  Function:   ft1000_copy_down_pkt
-  Description: This function will take an ethernet packet and convert it to
-  a Flarion packet prior to sending it to the ASIC Downlink
-  FIFO.
-  Input:
-  dev    - device structure
-  packet - address of ethernet packet
-  len    - length of IP packet
-  Output:
-  status - FAILURE
-  SUCCESS
-
-  -------------------------------------------------------------------------*/
-static int ft1000_copy_down_pkt(struct net_device *dev, u16 *packet, u16 len)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       struct ft1000_pcmcia *pcmcia = info->priv;
-       union {
-               struct pseudo_hdr blk;
-               u16 buff[sizeof(struct pseudo_hdr) >> 1];
-               u8 buffc[sizeof(struct pseudo_hdr)];
-       } pseudo;
-       int i;
-       u32 *plong;
-
-       /* Check if there is room on the FIFO */
-       if (len > ft1000_read_fifo_len(dev)) {
-               udelay(10);
-               if (len > ft1000_read_fifo_len(dev))
-                       udelay(20);
-               if (len > ft1000_read_fifo_len(dev))
-                       udelay(20);
-               if (len > ft1000_read_fifo_len(dev))
-                       udelay(20);
-               if (len > ft1000_read_fifo_len(dev))
-                       udelay(20);
-               if (len > ft1000_read_fifo_len(dev))
-                       udelay(20);
-               if (len > ft1000_read_fifo_len(dev)) {
-                       pr_debug("Transmit FIFO is full - pkt drop\n");
-                       info->stats.tx_errors++;
-                       return SUCCESS;
-               }
-       }
-       /* Create pseudo header and send pseudo/ip to hardware */
-       if (info->AsicID == ELECTRABUZZ_ID)
-               pseudo.blk.length = len;
-       else
-               pseudo.blk.length = ntohs(len);
-
-       pseudo.blk.source = DSPID;      /* Need to swap to get in correct
-                                          order */
-       pseudo.blk.destination = HOSTID;
-       pseudo.blk.portdest = NETWORKID;        /* Need to swap to get in
-                                                  correct order */
-       pseudo.blk.portsrc = DSPAIRID;
-       pseudo.blk.sh_str_id = 0;
-       pseudo.blk.control = 0;
-       pseudo.blk.rsvd1 = 0;
-       pseudo.blk.seq_num = 0;
-       pseudo.blk.rsvd2 = pcmcia->packetseqnum++;
-       pseudo.blk.qos_class = 0;
-       /* Calculate pseudo header checksum */
-       pseudo.blk.checksum = pseudo.buff[0];
-       for (i = 1; i < 7; i++)
-               pseudo.blk.checksum ^= pseudo.buff[i];
-
-       /* Production Mode */
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               /* copy first word to UFIFO_BEG reg */
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_BEG, pseudo.buff[0]);
-               pr_debug("data 0 BEG = 0x%04x\n", pseudo.buff[0]);
-
-               /* copy subsequent words to UFIFO_MID reg */
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[1]);
-               pr_debug("data 1 MID = 0x%04x\n", pseudo.buff[1]);
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[2]);
-               pr_debug("data 2 MID = 0x%04x\n", pseudo.buff[2]);
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[3]);
-               pr_debug("data 3 MID = 0x%04x\n", pseudo.buff[3]);
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[4]);
-               pr_debug("data 4 MID = 0x%04x\n", pseudo.buff[4]);
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[5]);
-               pr_debug("data 5 MID = 0x%04x\n", pseudo.buff[5]);
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[6]);
-               pr_debug("data 6 MID = 0x%04x\n", pseudo.buff[6]);
-               ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[7]);
-               pr_debug("data 7 MID = 0x%04x\n", pseudo.buff[7]);
-
-               /* Write PPP type + IP Packet into Downlink FIFO */
-               for (i = 0; i < (len >> 1) - 1; i++) {
-                       ft1000_write_reg(dev, FT1000_REG_UFIFO_MID,
-                                        htons(*packet));
-                       pr_debug("data %d MID = 0x%04x\n",
-                                i + 8, htons(*packet));
-                       packet++;
-               }
-
-               /* Check for odd byte */
-               if (len & 0x0001) {
-                       ft1000_write_reg(dev, FT1000_REG_UFIFO_MID,
-                                        htons(*packet));
-                       pr_debug("data MID = 0x%04x\n", htons(*packet));
-                       packet++;
-                       ft1000_write_reg(dev, FT1000_REG_UFIFO_END,
-                                        htons(*packet));
-                       pr_debug("data %d MID = 0x%04x\n",
-                                i + 8, htons(*packet));
-               } else {
-                       ft1000_write_reg(dev, FT1000_REG_UFIFO_END,
-                                        htons(*packet));
-                       pr_debug("data %d MID = 0x%04x\n",
-                                i + 8, htons(*packet));
-               }
-       } else {
-               outl(*(u32 *)&pseudo.buff[0],
-                    dev->base_addr + FT1000_REG_MAG_UFDR);
-               pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[0]);
-               outl(*(u32 *)&pseudo.buff[2],
-                    dev->base_addr + FT1000_REG_MAG_UFDR);
-               pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[2]);
-               outl(*(u32 *)&pseudo.buff[4],
-                    dev->base_addr + FT1000_REG_MAG_UFDR);
-               pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[4]);
-               outl(*(u32 *)&pseudo.buff[6],
-                    dev->base_addr + FT1000_REG_MAG_UFDR);
-               pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[6]);
-
-               plong = (u32 *)packet;
-               /* Write PPP type + IP Packet into Downlink FIFO */
-               for (i = 0; i < (len >> 2); i++)
-                       outl(*plong++, dev->base_addr + FT1000_REG_MAG_UFDR);
-
-               /* Check for odd alignment */
-               if (len & 0x0003) {
-                       pr_debug("data = 0x%8x\n", *plong);
-                       outl(*plong++, dev->base_addr + FT1000_REG_MAG_UFDR);
-               }
-               outl(1, dev->base_addr + FT1000_REG_MAG_UFER);
-       }
-
-       info->stats.tx_packets++;
-       /* Add 14 bytes for MAC address plus ethernet type */
-       info->stats.tx_bytes += (len + 14);
-       return SUCCESS;
-}
-
-static struct net_device_stats *ft1000_stats(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-
-       return &info->stats;
-}
-
-static int ft1000_open(struct net_device *dev)
-{
-       ft1000_reset_card(dev);
-
-       /* schedule ft1000_hbchk to perform periodic heartbeat checks on DSP
-        * and ASIC */
-       init_timer(&poll_timer);
-       poll_timer.expires = jiffies + (2 * HZ);
-       poll_timer.data = (u_long)dev;
-       add_timer(&poll_timer);
-
-       return 0;
-}
-
-static int ft1000_close(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-
-       info->CardReady = 0;
-       del_timer(&poll_timer);
-
-       if (ft1000_card_present == 1) {
-               pr_debug("Media is down\n");
-               netif_stop_queue(dev);
-
-               ft1000_disable_interrupts(dev);
-               ft1000_write_reg(dev, FT1000_REG_RESET, DSP_RESET_BIT);
-
-               /* reset ASIC */
-               ft1000_reset_asic(dev);
-       }
-       return 0;
-}
-
-static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       u8 *pdata;
-
-       if (skb == NULL) {
-               pr_debug("skb == NULL!!!\n");
-               return 0;
-       }
-
-       pr_debug("length of packet = %d\n", skb->len);
-
-       pdata = (u8 *)skb->data;
-
-       if (info->mediastate == 0) {
-               /* Drop packet is mediastate is down */
-               pr_debug("mediastate is down\n");
-               return SUCCESS;
-       }
-
-       if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) {
-               /* Drop packet which has invalid size */
-               pr_debug("invalid ethernet length\n");
-               return SUCCESS;
-       }
-       ft1000_copy_down_pkt(dev, (u16 *) (pdata + ENET_HEADER_SIZE - 2),
-                            skb->len - ENET_HEADER_SIZE + 2);
-
-       dev_kfree_skb(skb);
-
-       return 0;
-}
-
-static irqreturn_t ft1000_interrupt(int irq, void *dev_id)
-{
-       struct net_device *dev = dev_id;
-       struct ft1000_info *info = netdev_priv(dev);
-       u16 tempword;
-       u16 inttype;
-       int cnt;
-
-       if (info->CardReady == 0) {
-               ft1000_disable_interrupts(dev);
-               return IRQ_HANDLED;
-       }
-
-       if (ft1000_chkcard(dev) == false) {
-               ft1000_disable_interrupts(dev);
-               return IRQ_HANDLED;
-       }
-
-       ft1000_disable_interrupts(dev);
-
-       /* Read interrupt type */
-       inttype = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
-
-       /* Make sure we process all interrupt before leaving the ISR due to the
-        * edge trigger interrupt type */
-       while (inttype) {
-               if (inttype & ISR_DOORBELL_PEND)
-                       ft1000_parse_dpram_msg(dev);
-
-               if (inttype & ISR_RCV) {
-                       pr_debug("Data in FIFO\n");
-
-                       cnt = 0;
-                       do {
-                               /* Check if we have packets in the Downlink
-                                * FIFO */
-                               if (info->AsicID == ELECTRABUZZ_ID) {
-                                       tempword = ft1000_read_reg(dev,
-                                                       FT1000_REG_DFIFO_STAT);
-                               } else {
-                                       tempword = ft1000_read_reg(dev,
-                                                       FT1000_REG_MAG_DFSR);
-                               }
-                               if (!(tempword & 0x1f))
-                                       break;
-                               ft1000_copy_up_pkt(dev);
-                               cnt++;
-                       } while (cnt < MAX_RCV_LOOP);
-
-               }
-               /* clear interrupts */
-               tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
-               pr_debug("interrupt status register = 0x%x\n", tempword);
-               ft1000_write_reg(dev, FT1000_REG_SUP_ISR, tempword);
-
-               /* Read interrupt type */
-               inttype = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
-               pr_debug("interrupt status register after clear = 0x%x\n",
-                        inttype);
-       }
-       ft1000_enable_interrupts(dev);
-       return IRQ_HANDLED;
-}
-
-void stop_ft1000_card(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       struct prov_record *ptr;
-       struct prov_record *tmp;
-       /* int cnt; */
-
-       info->CardReady = 0;
-       ft1000_card_present = 0;
-       netif_stop_queue(dev);
-       ft1000_disable_interrupts(dev);
-
-       /* Make sure we free any memory reserve for provisioning */
-       list_for_each_entry_safe(ptr, tmp, &info->prov_list, list) {
-               list_del(&ptr->list);
-               kfree(ptr->pprov_data);
-               kfree(ptr);
-       }
-
-       kfree(info->priv);
-
-       if (info->registered) {
-               unregister_netdev(dev);
-               info->registered = 0;
-       }
-
-       free_irq(dev->irq, dev);
-       release_region(dev->base_addr, 256);
-       release_firmware(fw_entry);
-       flarion_ft1000_cnt--;
-
-}
-
-static void ft1000_get_drvinfo(struct net_device *dev,
-                              struct ethtool_drvinfo *info)
-{
-       struct ft1000_info *ft_info;
-
-       ft_info = netdev_priv(dev);
-
-       strlcpy(info->driver, "ft1000", sizeof(info->driver));
-       snprintf(info->bus_info, sizeof(info->bus_info), "PCMCIA 0x%lx",
-                dev->base_addr);
-       snprintf(info->fw_version, sizeof(info->fw_version), "%d.%d.%d.%d",
-                ft_info->DspVer[0], ft_info->DspVer[1], ft_info->DspVer[2],
-                ft_info->DspVer[3]);
-}
-
-static u32 ft1000_get_link(struct net_device *dev)
-{
-       struct ft1000_info *info;
-
-       info = netdev_priv(dev);
-       return info->mediastate;
-}
-
-static const struct ethtool_ops ops = {
-       .get_drvinfo = ft1000_get_drvinfo,
-       .get_link = ft1000_get_link
-};
-
-struct net_device *init_ft1000_card(struct pcmcia_device *link,
-                                   void *ft1000_reset)
-{
-       struct ft1000_info *info;
-       struct ft1000_pcmcia *pcmcia;
-       struct net_device *dev;
-
-       static const struct net_device_ops ft1000ops = {
-                       .ndo_open = &ft1000_open,
-                       .ndo_stop = &ft1000_close,
-                       .ndo_start_xmit = &ft1000_start_xmit,
-                       .ndo_get_stats = &ft1000_stats,
-               };
-
-       pr_debug("irq = %d, port = 0x%04llx\n",
-                link->irq, (unsigned long long)link->resource[0]->start);
-
-       flarion_ft1000_cnt++;
-
-       if (flarion_ft1000_cnt > 1) {
-               flarion_ft1000_cnt--;
-
-               dev_info(&link->dev,
-                        "This driver can not support more than one instance\n");
-               return NULL;
-       }
-
-       dev = alloc_etherdev(sizeof(struct ft1000_info));
-       if (!dev) {
-               dev_err(&link->dev, "Failed to allocate etherdev\n");
-               return NULL;
-       }
-
-       SET_NETDEV_DEV(dev, &link->dev);
-       info = netdev_priv(dev);
-
-       memset(info, 0, sizeof(struct ft1000_info));
-
-       pr_debug("address of dev = 0x%p\n", dev);
-       pr_debug("address of dev info = 0x%p\n", info);
-       pr_debug("device name = %s\n", dev->name);
-
-       memset(&info->stats, 0, sizeof(struct net_device_stats));
-
-       info->priv = kzalloc(sizeof(struct ft1000_pcmcia), GFP_KERNEL);
-       pcmcia = info->priv;
-       pcmcia->link = link;
-
-       spin_lock_init(&info->dpram_lock);
-       info->DrvErrNum = 0;
-       info->registered = 1;
-       info->ft1000_reset = ft1000_reset;
-       info->mediastate = 0;
-       info->fifo_cnt = 0;
-       info->CardReady = 0;
-       info->DSP_TIME[0] = 0;
-       info->DSP_TIME[1] = 0;
-       info->DSP_TIME[2] = 0;
-       info->DSP_TIME[3] = 0;
-       flarion_ft1000_cnt = 0;
-
-       INIT_LIST_HEAD(&info->prov_list);
-
-       info->squeseqnum = 0;
-
-       /* dev->hard_start_xmit = &ft1000_start_xmit; */
-       /* dev->get_stats = &ft1000_stats; */
-       /* dev->open = &ft1000_open; */
-       /* dev->stop = &ft1000_close; */
-
-       dev->netdev_ops = &ft1000ops;
-
-       pr_debug("device name = %s\n", dev->name);
-
-       dev->irq = link->irq;
-       dev->base_addr = link->resource[0]->start;
-       if (pcmcia_get_mac_from_cis(link, dev)) {
-               netdev_err(dev, "Could not read mac address\n");
-               goto err_dev;
-       }
-
-       if (request_irq(dev->irq, ft1000_interrupt, IRQF_SHARED, dev->name,
-                       dev)) {
-               netdev_err(dev, "Could not request_irq\n");
-               goto err_dev;
-       }
-
-       if (request_region(dev->base_addr, 256, dev->name) == NULL) {
-               netdev_err(dev, "Could not request_region\n");
-               goto err_irq;
-       }
-
-       if (register_netdev(dev)) {
-               pr_debug("Could not register netdev\n");
-               goto err_reg;
-       }
-
-       info->AsicID = ft1000_read_reg(dev, FT1000_REG_ASIC_ID);
-       if (info->AsicID == ELECTRABUZZ_ID) {
-               pr_debug("ELECTRABUZZ ASIC\n");
-               if (request_firmware(&fw_entry, "ft1000.img",
-                                    &link->dev) != 0) {
-                       pr_info("Could not open ft1000.img\n");
-                       goto err_unreg;
-               }
-       } else {
-               pr_debug("MAGNEMITE ASIC\n");
-               if (request_firmware(&fw_entry, "ft2000.img",
-                                    &link->dev) != 0) {
-                       pr_info("Could not open ft2000.img\n");
-                       goto err_unreg;
-               }
-       }
-
-       ft1000_enable_interrupts(dev);
-
-       ft1000_card_present = 1;
-       dev->ethtool_ops = &ops;
-       pr_info("%s: addr 0x%04lx irq %d, MAC addr %pM\n",
-               dev->name, dev->base_addr, dev->irq, dev->dev_addr);
-       return dev;
-
-err_unreg:
-       unregister_netdev(dev);
-err_reg:
-       release_region(dev->base_addr, 256);
-err_irq:
-       free_irq(dev->irq, dev);
-err_dev:
-       free_netdev(dev);
-       return NULL;
-}
diff --git a/drivers/staging/ft1000/ft1000-usb/Makefile b/drivers/staging/ft1000/ft1000-usb/Makefile
deleted file mode 100644 (file)
index 7c4b784..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-obj-$(CONFIG_FT1000_USB) += ft1000.o
-
-ft1000-y := ft1000_debug.o ft1000_download.o ft1000_hw.o ft1000_usb.o
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
deleted file mode 100644 (file)
index f241a3a..0000000
+++ /dev/null
@@ -1,789 +0,0 @@
-/*
- *---------------------------------------------------------------------------
- * FT1000 driver for Flarion Flash OFDM NIC Device
- *
- * Copyright (C) 2006 Flarion Technologies, All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) any
- * later version. This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details. You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place -
- * Suite 330, Boston, MA 02111-1307, USA.
- *---------------------------------------------------------------------------
- *
- * File:         ft1000_chdev.c
- *
- * Description:  Custom character device dispatch routines.
- *
- * History:
- * 8/29/02    Whc                Ported to Linux.
- * 6/05/06    Whc                Porting to Linux 2.6.9
- *
- *---------------------------------------------------------------------------
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/errno.h>
-#include <linux/poll.h>
-#include <linux/netdevice.h>
-#include <linux/delay.h>
-
-#include <linux/ioctl.h>
-#include <linux/debugfs.h>
-#include "ft1000_usb.h"
-
-static int ft1000_flarion_cnt;
-
-static int ft1000_open(struct inode *inode, struct file *file);
-static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait);
-static long ft1000_ioctl(struct file *file, unsigned int command,
-                        unsigned long argument);
-static int ft1000_release(struct inode *inode, struct file *file);
-
-/* List to free receive command buffer pool */
-struct list_head freercvpool;
-
-/* lock to arbitrate free buffer list for receive command data */
-spinlock_t free_buff_lock;
-
-int numofmsgbuf;
-
-/*
- * Table of entry-point routines for char device
- */
-static const struct file_operations ft1000fops = {
-       .unlocked_ioctl = ft1000_ioctl,
-       .poll           = ft1000_poll_dev,
-       .open           = ft1000_open,
-       .release        = ft1000_release,
-       .llseek         = no_llseek,
-};
-
-/*
-  ---------------------------------------------------------------------------
-  * Function:    ft1000_get_buffer
-  *
-  * Parameters:
-  *
-  * Returns:
-  *
-  * Description:
-  *
-  * Notes:
-  *
-  *---------------------------------------------------------------------------
-  */
-struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist)
-{
-       unsigned long flags;
-       struct dpram_blk *ptr;
-
-       spin_lock_irqsave(&free_buff_lock, flags);
-       /* Check if buffer is available */
-       if (list_empty(bufflist)) {
-               pr_debug("No more buffer - %d\n", numofmsgbuf);
-               ptr = NULL;
-       } else {
-               numofmsgbuf--;
-               ptr = list_entry(bufflist->next, struct dpram_blk, list);
-               list_del(&ptr->list);
-               /* pr_debug("number of free msg buffers = %d\n", numofmsgbuf); */
-       }
-       spin_unlock_irqrestore(&free_buff_lock, flags);
-
-       return ptr;
-}
-
-
-
-
-/*
- *---------------------------------------------------------------------------
- * Function:    ft1000_free_buffer
- *
- * Parameters:
- *
- * Returns:
- *
- * Description:
- *
- * Notes:
- *
- *---------------------------------------------------------------------------
- */
-void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist)
-{
-       unsigned long flags;
-
-       spin_lock_irqsave(&free_buff_lock, flags);
-       /* Put memory back to list */
-       list_add_tail(&pdpram_blk->list, plist);
-       numofmsgbuf++;
-       /*pr_debug("number of free msg buffers = %d\n", numofmsgbuf); */
-       spin_unlock_irqrestore(&free_buff_lock, flags);
-}
-
-/*
- *---------------------------------------------------------------------------
- * Function:    ft1000_CreateDevice
- *
- * Parameters:  dev - pointer to adapter object
- *
- * Returns:     0 if successful
- *
- * Description: Creates a private char device.
- *
- * Notes:       Only called by init_module().
- *
- *---------------------------------------------------------------------------
- */
-int ft1000_create_dev(struct ft1000_usb *dev)
-{
-       int result;
-       int i;
-       struct dentry *dir, *file;
-       struct ft1000_debug_dirs *tmp;
-
-       /* make a new device name */
-       sprintf(dev->DeviceName, "%s%d", "FT1000_", dev->CardNumber);
-
-       pr_debug("number of instance = %d\n", ft1000_flarion_cnt);
-       pr_debug("DeviceCreated = %x\n", dev->DeviceCreated);
-
-       if (dev->DeviceCreated) {
-               pr_debug("\"%s\" already registered\n", dev->DeviceName);
-               return -EIO;
-       }
-
-
-       /* register the device */
-       pr_debug("\"%s\" debugfs device registration\n", dev->DeviceName);
-
-       tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL);
-       if (tmp == NULL) {
-               result = -1;
-               goto fail;
-       }
-
-       dir = debugfs_create_dir(dev->DeviceName, NULL);
-       if (IS_ERR(dir)) {
-               result = PTR_ERR(dir);
-               goto debug_dir_fail;
-       }
-
-       file = debugfs_create_file("device", S_IRUGO | S_IWUSR, dir,
-                                  dev, &ft1000fops);
-       if (IS_ERR(file)) {
-               result = PTR_ERR(file);
-               goto debug_file_fail;
-       }
-
-       tmp->dent = dir;
-       tmp->file = file;
-       tmp->int_number = dev->CardNumber;
-       list_add(&tmp->list, &dev->nodes.list);
-
-       pr_debug("registered debugfs directory \"%s\"\n", dev->DeviceName);
-
-       /* initialize application information */
-       dev->appcnt = 0;
-       for (i = 0; i < MAX_NUM_APP; i++) {
-               dev->app_info[i].nTxMsg = 0;
-               dev->app_info[i].nRxMsg = 0;
-               dev->app_info[i].nTxMsgReject = 0;
-               dev->app_info[i].nRxMsgMiss = 0;
-               dev->app_info[i].fileobject = NULL;
-               dev->app_info[i].app_id = i+1;
-               dev->app_info[i].DspBCMsgFlag = 0;
-               dev->app_info[i].NumOfMsg = 0;
-               init_waitqueue_head(&dev->app_info[i].wait_dpram_msg);
-               INIT_LIST_HEAD(&dev->app_info[i].app_sqlist);
-       }
-
-       dev->DeviceCreated = TRUE;
-       ft1000_flarion_cnt++;
-
-       return 0;
-
-debug_file_fail:
-       debugfs_remove(dir);
-debug_dir_fail:
-       kfree(tmp);
-fail:
-       return result;
-}
-
-/*
- *---------------------------------------------------------------------------
- * Function:    ft1000_DestroyDeviceDEBUG
- *
- * Parameters:  dev - pointer to adapter object
- *
- * Description: Destroys a private char device.
- *
- * Notes:       Only called by cleanup_module().
- *
- *---------------------------------------------------------------------------
- */
-void ft1000_destroy_dev(struct net_device *netdev)
-{
-       struct ft1000_info *info = netdev_priv(netdev);
-       struct ft1000_usb *dev = info->priv;
-       int i;
-       struct dpram_blk *pdpram_blk;
-       struct dpram_blk *ptr;
-       struct list_head *pos, *q;
-       struct ft1000_debug_dirs *dir;
-
-       if (dev->DeviceCreated) {
-               ft1000_flarion_cnt--;
-               list_for_each_safe(pos, q, &dev->nodes.list) {
-                       dir = list_entry(pos, struct ft1000_debug_dirs, list);
-                       if (dir->int_number == dev->CardNumber) {
-                               debugfs_remove(dir->file);
-                               debugfs_remove(dir->dent);
-                               list_del(pos);
-                               kfree(dir);
-                       }
-               }
-               pr_debug("unregistered device \"%s\"\n", dev->DeviceName);
-
-               /* Make sure we free any memory reserve for slow Queue */
-               for (i = 0; i < MAX_NUM_APP; i++) {
-                       while (list_empty(&dev->app_info[i].app_sqlist) == 0) {
-                               pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next,
-                                                       struct dpram_blk, list);
-                               list_del(&pdpram_blk->list);
-                               ft1000_free_buffer(pdpram_blk, &freercvpool);
-
-                       }
-                       wake_up_interruptible(&dev->app_info[i].wait_dpram_msg);
-               }
-
-               /* Remove buffer allocated for receive command data */
-               if (ft1000_flarion_cnt == 0) {
-                       while (list_empty(&freercvpool) == 0) {
-                               ptr = list_entry(freercvpool.next, struct dpram_blk, list);
-                               list_del(&ptr->list);
-                               kfree(ptr->pbuffer);
-                               kfree(ptr);
-                       }
-               }
-               dev->DeviceCreated = FALSE;
-       }
-
-
-}
-
-/*
- *---------------------------------------------------------------------------
- * Function:    ft1000_open
- *
- * Parameters:
- *
- * Description:
- *
- * Notes:
- *
- *---------------------------------------------------------------------------
- */
-static int ft1000_open(struct inode *inode, struct file *file)
-{
-       struct ft1000_info *info;
-       struct ft1000_usb *dev = (struct ft1000_usb *)inode->i_private;
-       int i, num;
-
-       num = MINOR(inode->i_rdev) & 0xf;
-       pr_debug("minor number=%d\n", num);
-
-       info = file->private_data = netdev_priv(dev->net);
-
-       pr_debug("f_owner = %p number of application = %d\n",
-                &file->f_owner, dev->appcnt);
-
-       /* Check if maximum number of application exceeded */
-       if (dev->appcnt > MAX_NUM_APP) {
-               pr_debug("Maximum number of application exceeded\n");
-               return -EACCES;
-       }
-
-       /* Search for available application info block */
-       for (i = 0; i < MAX_NUM_APP; i++) {
-               if (dev->app_info[i].fileobject == NULL)
-                       break;
-       }
-
-       /* Fail due to lack of application info block */
-       if (i == MAX_NUM_APP) {
-               pr_debug("Could not find an application info block\n");
-               return -EACCES;
-       }
-
-       dev->appcnt++;
-       dev->app_info[i].fileobject = &file->f_owner;
-       dev->app_info[i].nTxMsg = 0;
-       dev->app_info[i].nRxMsg = 0;
-       dev->app_info[i].nTxMsgReject = 0;
-       dev->app_info[i].nRxMsgMiss = 0;
-
-       nonseekable_open(inode, file);
-       return 0;
-}
-
-
-/*
- *---------------------------------------------------------------------------
- * Function:    ft1000_poll_dev
- *
- * Parameters:
- *
- * Description:
- *
- * Notes:
- *
- *---------------------------------------------------------------------------
- */
-
-static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait)
-{
-       struct net_device *netdev = file->private_data;
-       struct ft1000_info *info = netdev_priv(netdev);
-       struct ft1000_usb *dev = info->priv;
-       int i;
-
-       if (ft1000_flarion_cnt == 0) {
-               pr_debug("called with ft1000_flarion_cnt value zero\n");
-               return -EBADF;
-       }
-
-       /* Search for matching file object */
-       for (i = 0; i < MAX_NUM_APP; i++) {
-               if (dev->app_info[i].fileobject == &file->f_owner) {
-                       /* pr_debug("Message is for AppId = %d\n", dev->app_info[i].app_id); */
-                       break;
-               }
-       }
-
-       /* Could not find application info block */
-       if (i == MAX_NUM_APP) {
-               pr_debug("Could not find application info block\n");
-               return -EACCES;
-       }
-
-       if (list_empty(&dev->app_info[i].app_sqlist) == 0) {
-               pr_debug("Message detected in slow queue\n");
-               return(POLLIN | POLLRDNORM | POLLPRI);
-       }
-
-       poll_wait(file, &dev->app_info[i].wait_dpram_msg, wait);
-       /* pr_debug("Polling for data from DSP\n"); */
-
-       return 0;
-}
-
-/*
- *---------------------------------------------------------------------------
- * Function:    ft1000_ioctl
- *
- * Parameters:
- *
- * Description:
- *
- * Notes:
- *
- *---------------------------------------------------------------------------
- */
-static long ft1000_ioctl(struct file *file, unsigned int command,
-                        unsigned long argument)
-{
-       void __user *argp = (void __user *)argument;
-       struct ft1000_info *info;
-       struct ft1000_usb *ft1000dev;
-       int result = 0;
-       int cmd;
-       int i;
-       u16 tempword;
-       unsigned long flags;
-       struct timeval tv;
-       struct IOCTL_GET_VER get_ver_data;
-       struct IOCTL_GET_DSP_STAT get_stat_data;
-       u8 ConnectionMsg[] = {
-               0x00, 0x44, 0x10, 0x20, 0x80, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x93, 0x64,
-               0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0a,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12,
-               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               0x00, 0x00, 0x02, 0x37, 0x00, 0x00, 0x00, 0x08,
-               0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7f, 0x00,
-               0x00, 0x01, 0x00, 0x00
-       };
-
-       unsigned short ledStat = 0;
-       unsigned short conStat = 0;
-
-       if (ft1000_flarion_cnt == 0) {
-               pr_debug("called with ft1000_flarion_cnt of zero\n");
-               return -EBADF;
-       }
-
-       /* pr_debug("command = 0x%x argument = 0x%8x\n", command, (u32)argument); */
-
-       info = file->private_data;
-       ft1000dev = info->priv;
-       cmd = _IOC_NR(command);
-       /* pr_debug("cmd = 0x%x\n", cmd); */
-
-       /* process the command */
-       switch (cmd) {
-       case IOCTL_REGISTER_CMD:
-               pr_debug("IOCTL_FT1000_REGISTER called\n");
-               result = get_user(tempword, (__u16 __user *)argp);
-               if (result) {
-                       pr_debug("result = %d failed to get_user\n", result);
-                       break;
-               }
-               if (tempword == DSPBCMSGID) {
-                       /* Search for matching file object */
-                       for (i = 0; i < MAX_NUM_APP; i++) {
-                               if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
-                                       ft1000dev->app_info[i].DspBCMsgFlag = 1;
-                                       pr_debug("Registered for broadcast messages\n");
-                                       break;
-                               }
-                       }
-               }
-               break;
-
-       case IOCTL_GET_VER_CMD:
-               pr_debug("IOCTL_FT1000_GET_VER called\n");
-
-               get_ver_data.drv_ver = FT1000_DRV_VER;
-
-               if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data))) {
-                       pr_debug("copy fault occurred\n");
-                       result = -EFAULT;
-                       break;
-               }
-
-               pr_debug("driver version = 0x%x\n",
-                        (unsigned int)get_ver_data.drv_ver);
-
-               break;
-       case IOCTL_CONNECT:
-               /* Connect Message */
-               pr_debug("IOCTL_FT1000_CONNECT\n");
-               ConnectionMsg[79] = 0xfc;
-               result = card_send_command(ft1000dev, ConnectionMsg, 0x4c);
-
-               break;
-       case IOCTL_DISCONNECT:
-               /* Disconnect Message */
-               pr_debug("IOCTL_FT1000_DISCONNECT\n");
-               ConnectionMsg[79] = 0xfd;
-               result = card_send_command(ft1000dev, ConnectionMsg, 0x4c);
-               break;
-       case IOCTL_GET_DSP_STAT_CMD:
-               /* pr_debug("IOCTL_FT1000_GET_DSP_STAT\n"); */
-               memset(&get_stat_data, 0, sizeof(get_stat_data));
-               memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ);
-               memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ);
-               memcpy(get_stat_data.Sku, info->Sku, SKUSZ);
-               memcpy(get_stat_data.eui64, info->eui64, EUISZ);
-
-               if (info->ProgConStat != 0xFF) {
-                       ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED,
-                                           (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
-                       get_stat_data.LedStat = ntohs(ledStat);
-                       pr_debug("LedStat = 0x%x\n", get_stat_data.LedStat);
-                       ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE,
-                                           (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
-                       get_stat_data.ConStat = ntohs(conStat);
-                       pr_debug("ConStat = 0x%x\n", get_stat_data.ConStat);
-               } else {
-                       get_stat_data.ConStat = 0x0f;
-               }
-
-
-               get_stat_data.nTxPkts = info->stats.tx_packets;
-               get_stat_data.nRxPkts = info->stats.rx_packets;
-               get_stat_data.nTxBytes = info->stats.tx_bytes;
-               get_stat_data.nRxBytes = info->stats.rx_bytes;
-               do_gettimeofday(&tv);
-               get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
-               pr_debug("Connection Time = %d\n", (int)get_stat_data.ConTm);
-               if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data))) {
-                       pr_debug("copy fault occurred\n");
-                       result = -EFAULT;
-                       break;
-               }
-               pr_debug("GET_DSP_STAT succeed\n");
-               break;
-       case IOCTL_SET_DPRAM_CMD:
-       {
-               struct IOCTL_DPRAM_BLK *dpram_data = NULL;
-               /* struct IOCTL_DPRAM_COMMAND dpram_command; */
-               u16 qtype;
-               u16 msgsz;
-               struct pseudo_hdr *ppseudo_hdr;
-               u16 *pmsg;
-               u16 total_len;
-               u16 app_index;
-               u16 status;
-
-               /* pr_debug("IOCTL_FT1000_SET_DPRAM called\n");*/
-
-
-               if (ft1000_flarion_cnt == 0)
-                       return -EBADF;
-
-               if (ft1000dev->DrvMsgPend)
-                       return -ENOTTY;
-
-               if (ft1000dev->fProvComplete == 0)
-                       return -EACCES;
-
-               ft1000dev->fAppMsgPend = true;
-
-               if (info->CardReady) {
-
-                       /* pr_debug("try to SET_DPRAM\n"); */
-
-                       /* Get the length field to see how many bytes to copy */
-                       result = get_user(msgsz, (__u16 __user *)argp);
-                       if (result)
-                               break;
-                       msgsz = ntohs(msgsz);
-                       /* pr_debug("length of message = %d\n", msgsz); */
-
-                       if (msgsz > MAX_CMD_SQSIZE) {
-                               pr_debug("bad message length = %d\n", msgsz);
-                               result = -EINVAL;
-                               break;
-                       }
-
-                       result = -ENOMEM;
-                       dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
-                       if (!dpram_data)
-                               break;
-
-                       if (copy_from_user(dpram_data, argp, msgsz+2)) {
-                               pr_debug("copy fault occurred\n");
-                               result = -EFAULT;
-                       } else {
-                               /* Check if this message came from a registered application */
-                               for (i = 0; i < MAX_NUM_APP; i++) {
-                                       if (ft1000dev->app_info[i].fileobject == &file->f_owner)
-                                               break;
-                               }
-                               if (i == MAX_NUM_APP) {
-                                       pr_debug("No matching application fileobject\n");
-                                       result = -EINVAL;
-                                       kfree(dpram_data);
-                                       break;
-                               }
-                               app_index = i;
-
-                               /* Check message qtype type which is the lower byte within qos_class */
-                               qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
-                               /* pr_debug("qtype = %d\n", qtype); */
-                               if (!qtype) {
-                                       /* Put message into Slow Queue */
-                                       /* Only put a message into the DPRAM if msg doorbell is available */
-                                       status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
-                                       /* pr_debug("READ REGISTER tempword=%x\n", tempword); */
-                                       if (tempword & FT1000_DB_DPRAM_TX) {
-                                               /* Suspend for 2ms and try again due to DSP doorbell busy */
-                                               mdelay(2);
-                                               status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
-                                               if (tempword & FT1000_DB_DPRAM_TX) {
-                                                       /* Suspend for 1ms and try again due to DSP doorbell busy */
-                                                       mdelay(1);
-                                                       status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
-                                                       if (tempword & FT1000_DB_DPRAM_TX) {
-                                                               status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
-                                                               if (tempword & FT1000_DB_DPRAM_TX) {
-                                                                       /* Suspend for 3ms and try again due to DSP doorbell busy */
-                                                                       mdelay(3);
-                                                                       status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
-                                                                       if (tempword & FT1000_DB_DPRAM_TX) {
-                                                                               pr_debug("Doorbell not available\n");
-                                                                               result = -ENOTTY;
-                                                                               kfree(dpram_data);
-                                                                               break;
-                                                                       }
-                                                               }
-                                                       }
-                                               }
-                                       }
-
-                                       /*pr_debug("finished reading register\n"); */
-
-                                       /* Make sure we are within the limits of the slow queue memory limitation */
-                                       if ((msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ)) {
-                                               /* Need to put sequence number plus new checksum for message */
-                                               pmsg = (u16 *)&dpram_data->pseudohdr;
-                                               ppseudo_hdr = (struct pseudo_hdr *)pmsg;
-                                               total_len = msgsz+2;
-                                               if (total_len & 0x1)
-                                                       total_len++;
-
-                                               /* Insert slow queue sequence number */
-                                               ppseudo_hdr->seq_num = info->squeseqnum++;
-                                               ppseudo_hdr->portsrc = ft1000dev->app_info[app_index].app_id;
-                                               /* Calculate new checksum */
-                                               ppseudo_hdr->checksum = *pmsg++;
-                                               /* pr_debug("checksum = 0x%x\n", ppseudo_hdr->checksum); */
-                                               for (i = 1; i < 7; i++) {
-                                                       ppseudo_hdr->checksum ^= *pmsg++;
-                                                       /* pr_debug("checksum = 0x%x\n", ppseudo_hdr->checksum); */
-                                               }
-                                               pmsg++;
-                                               ppseudo_hdr = (struct pseudo_hdr *)pmsg;
-                                               result = card_send_command(ft1000dev, dpram_data, total_len+2);
-
-
-                                               ft1000dev->app_info[app_index].nTxMsg++;
-                                       } else {
-                                               result = -EINVAL;
-                                       }
-                               }
-                       }
-               } else {
-                       pr_debug("Card not ready take messages\n");
-                       result = -EACCES;
-               }
-               kfree(dpram_data);
-
-       }
-       break;
-       case IOCTL_GET_DPRAM_CMD:
-       {
-               struct dpram_blk *pdpram_blk;
-               struct IOCTL_DPRAM_BLK __user *pioctl_dpram;
-               int msglen;
-
-               /* pr_debug("IOCTL_FT1000_GET_DPRAM called\n"); */
-
-               if (ft1000_flarion_cnt == 0)
-                       return -EBADF;
-
-               /* Search for matching file object */
-               for (i = 0; i < MAX_NUM_APP; i++) {
-                       if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
-                               /*pr_debug("Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */
-                               break;
-                       }
-               }
-
-               /* Could not find application info block */
-               if (i == MAX_NUM_APP) {
-                       pr_debug("Could not find application info block\n");
-                       result = -EBADF;
-                       break;
-               }
-
-               result = 0;
-               pioctl_dpram = argp;
-               if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) {
-                       /* pr_debug("Message detected in slow queue\n"); */
-                       spin_lock_irqsave(&free_buff_lock, flags);
-                       pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next,
-                                               struct dpram_blk, list);
-                       list_del(&pdpram_blk->list);
-                       ft1000dev->app_info[i].NumOfMsg--;
-                       /* pr_debug("NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); */
-                       spin_unlock_irqrestore(&free_buff_lock, flags);
-                       msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
-                       result = get_user(msglen, &pioctl_dpram->total_len);
-                       if (result)
-                               break;
-                       msglen = htons(msglen);
-                       /* pr_debug("msg length = %x\n", msglen); */
-                       if (copy_to_user(&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen)) {
-                               pr_debug("copy fault occurred\n");
-                               result = -EFAULT;
-                               break;
-                       }
-
-                       ft1000_free_buffer(pdpram_blk, &freercvpool);
-                       result = msglen;
-               }
-               /* pr_debug("IOCTL_FT1000_GET_DPRAM no message\n"); */
-       }
-       break;
-
-       default:
-               pr_debug("unknown command: 0x%x\n", command);
-               result = -ENOTTY;
-               break;
-       }
-       ft1000dev->fAppMsgPend = false;
-       return result;
-}
-
-/*
- *---------------------------------------------------------------------------
- * Function:    ft1000_release
- *
- * Parameters:
- *
- * Description:
- *
- * Notes:
- *
- *---------------------------------------------------------------------------
- */
-static int ft1000_release(struct inode *inode, struct file *file)
-{
-       struct ft1000_info *info;
-       struct net_device *dev;
-       struct ft1000_usb *ft1000dev;
-       int i;
-       struct dpram_blk *pdpram_blk;
-       struct dpram_blk *tmp;
-
-       dev = file->private_data;
-       info = netdev_priv(dev);
-       ft1000dev = info->priv;
-
-       if (ft1000_flarion_cnt == 0) {
-               ft1000dev->appcnt--;
-               return -EBADF;
-       }
-
-       /* Search for matching file object */
-       for (i = 0; i < MAX_NUM_APP; i++) {
-               if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
-                       /* pr_debug("Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */
-                       break;
-               }
-       }
-
-       if (i == MAX_NUM_APP)
-               return 0;
-
-       list_for_each_entry_safe(pdpram_blk, tmp, &ft1000dev->app_info[i].app_sqlist, list) {
-               pr_debug("Remove and free memory queue up on slow queue\n");
-               list_del(&pdpram_blk->list);
-               ft1000_free_buffer(pdpram_blk, &freercvpool);
-       }
-
-       /* initialize application information */
-       ft1000dev->appcnt--;
-       pr_debug("appcnt = %d\n", ft1000dev->appcnt);
-       ft1000dev->app_info[i].fileobject = NULL;
-
-       return 0;
-}
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
deleted file mode 100644 (file)
index 297b7ae..0000000
+++ /dev/null
@@ -1,1058 +0,0 @@
-/*
- * CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
- *
- * This file is part of Express Card USB Driver
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/usb.h>
-#include <linux/vmalloc.h>
-#include "ft1000_usb.h"
-
-
-#define  DWNLD_HANDSHAKE_LOC     0x02
-#define  DWNLD_TYPE_LOC          0x04
-#define  DWNLD_SIZE_MSW_LOC      0x06
-#define  DWNLD_SIZE_LSW_LOC      0x08
-#define  DWNLD_PS_HDR_LOC        0x0A
-
-#define  MAX_DSP_WAIT_LOOPS      40
-#define  DSP_WAIT_SLEEP_TIME     1000       /* 1 millisecond */
-#define  DSP_WAIT_DISPATCH_LVL   50         /* 50 usec */
-
-#define  HANDSHAKE_TIMEOUT_VALUE 0xF1F1
-#define  HANDSHAKE_RESET_VALUE   0xFEFE   /* When DSP requests startover */
-#define  HANDSHAKE_RESET_VALUE_USB   0xFE7E   /* When DSP requests startover */
-#define  HANDSHAKE_DSP_BL_READY  0xFEFE   /* At start DSP writes this when bootloader ready */
-#define  HANDSHAKE_DSP_BL_READY_USB  0xFE7E   /* At start DSP writes this when bootloader ready */
-#define  HANDSHAKE_DRIVER_READY  0xFFFF   /* Driver writes after receiving 0xFEFE */
-#define  HANDSHAKE_SEND_DATA     0x0000   /* DSP writes this when ready for more data */
-
-#define  HANDSHAKE_REQUEST       0x0001   /* Request from DSP */
-#define  HANDSHAKE_RESPONSE      0x0000   /* Satisfied DSP request */
-
-#define  REQUEST_CODE_LENGTH     0x0000
-#define  REQUEST_RUN_ADDRESS     0x0001
-#define  REQUEST_CODE_SEGMENT    0x0002   /* In WORD count */
-#define  REQUEST_DONE_BL         0x0003
-#define  REQUEST_DONE_CL         0x0004
-#define  REQUEST_VERSION_INFO    0x0005
-#define  REQUEST_CODE_BY_VERSION 0x0006
-#define  REQUEST_MAILBOX_DATA    0x0007
-#define  REQUEST_FILE_CHECKSUM   0x0008
-
-#define  STATE_START_DWNLD       0x01
-#define  STATE_BOOT_DWNLD        0x02
-#define  STATE_CODE_DWNLD        0x03
-#define  STATE_DONE_DWNLD        0x04
-#define  STATE_SECTION_PROV      0x05
-#define  STATE_DONE_PROV         0x06
-#define  STATE_DONE_FILE         0x07
-
-#define  MAX_LENGTH              0x7f0
-
-/* Temporary download mechanism for Magnemite */
-#define  DWNLD_MAG_TYPE_LOC          0x00
-#define  DWNLD_MAG_LEN_LOC           0x01
-#define  DWNLD_MAG_ADDR_LOC          0x02
-#define  DWNLD_MAG_CHKSUM_LOC        0x03
-#define  DWNLD_MAG_VAL_LOC           0x04
-
-#define  HANDSHAKE_MAG_DSP_BL_READY  0xFEFE0000   /* At start DSP writes this when bootloader ready */
-#define  HANDSHAKE_MAG_DSP_ENTRY     0x01000000   /* Dsp writes this to request for entry address */
-#define  HANDSHAKE_MAG_DSP_DATA      0x02000000   /* Dsp writes this to request for data block */
-#define  HANDSHAKE_MAG_DSP_DONE      0x03000000   /* Dsp writes this to indicate download done */
-
-#define  HANDSHAKE_MAG_DRV_READY     0xFFFF0000   /* Driver writes this to indicate ready to download */
-#define  HANDSHAKE_MAG_DRV_DATA      0x02FECDAB   /* Driver writes this to indicate data available to DSP */
-#define  HANDSHAKE_MAG_DRV_ENTRY     0x01FECDAB   /* Driver writes this to indicate entry point to DSP */
-
-#define  HANDSHAKE_MAG_TIMEOUT_VALUE 0xF1F1
-
-
-/* New Magnemite downloader */
-#define  DWNLD_MAG1_HANDSHAKE_LOC     0x00
-#define  DWNLD_MAG1_TYPE_LOC          0x01
-#define  DWNLD_MAG1_SIZE_LOC          0x02
-#define  DWNLD_MAG1_PS_HDR_LOC        0x03
-
-struct dsp_file_hdr {
-       long              version_id;          /* Version ID of this image format. */
-       long              package_id;          /* Package ID of code release. */
-       long              build_date;          /* Date/time stamp when file was built. */
-       long              commands_offset;     /* Offset to attached commands in Pseudo Hdr format. */
-       long              loader_offset;       /* Offset to bootloader code. */
-       long              loader_code_address; /* Start address of bootloader. */
-       long              loader_code_end;     /* Where bootloader code ends. */
-       long              loader_code_size;
-       long              version_data_offset; /* Offset were scrambled version data begins. */
-       long              version_data_size;   /* Size, in words, of scrambled version data. */
-       long              nDspImages;          /* Number of DSP images in file. */
-};
-
-struct dsp_image_info {
-       long              coff_date;           /* Date/time when DSP Coff image was built. */
-       long              begin_offset;        /* Offset in file where image begins. */
-       long              end_offset;          /* Offset in file where image begins. */
-       long              run_address;         /* On chip Start address of DSP code. */
-       long              image_size;          /* Size of image. */
-       long              version;             /* Embedded version # of DSP code. */
-       unsigned short    checksum;            /* DSP File checksum */
-       unsigned short    pad1;
-} __packed;
-
-
-/* checks if the doorbell register is cleared */
-static int check_usb_db(struct ft1000_usb *ft1000dev)
-{
-       int loopcnt;
-       u16 temp;
-       int status;
-
-       loopcnt = 0;
-
-       while (loopcnt < 10) {
-               status = ft1000_read_register(ft1000dev, &temp,
-                                             FT1000_REG_DOORBELL);
-               pr_debug("read FT1000_REG_DOORBELL value is %x\n", temp);
-               if (temp & 0x0080) {
-                       pr_debug("Got checkusb doorbell\n");
-                       status = ft1000_write_register(ft1000dev, 0x0080,
-                                                      FT1000_REG_DOORBELL);
-                       status = ft1000_write_register(ft1000dev, 0x0100,
-                                                      FT1000_REG_DOORBELL);
-                       status = ft1000_write_register(ft1000dev,  0x8000,
-                                                      FT1000_REG_DOORBELL);
-                       break;
-               }
-               loopcnt++;
-               msleep(10);
-
-       }
-
-       loopcnt = 0;
-       while (loopcnt < 20) {
-               status = ft1000_read_register(ft1000dev, &temp,
-                                             FT1000_REG_DOORBELL);
-               pr_debug("Doorbell = 0x%x\n", temp);
-               if (temp & 0x8000) {
-                       loopcnt++;
-                       msleep(10);
-               } else  {
-                       pr_debug("door bell is cleared, return 0\n");
-                       return 0;
-               }
-       }
-
-       return -1;
-}
-
-/* gets the handshake and compares it with the expected value */
-static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value)
-{
-       u16 handshake;
-       int loopcnt;
-       int status = 0;
-
-       loopcnt = 0;
-
-       while (loopcnt < 100) {
-               /* Need to clear downloader doorbell if Hartley ASIC */
-               status = ft1000_write_register(ft1000dev,  FT1000_DB_DNLD_RX,
-                                              FT1000_REG_DOORBELL);
-               if (ft1000dev->fcodeldr) {
-                       pr_debug("fcodeldr is %d\n", ft1000dev->fcodeldr);
-                       ft1000dev->fcodeldr = 0;
-                       status = check_usb_db(ft1000dev);
-                       if (status != 0) {
-                               pr_debug("check_usb_db failed\n");
-                               break;
-                       }
-                       status = ft1000_write_register(ft1000dev,
-                                                      FT1000_DB_DNLD_RX,
-                                                      FT1000_REG_DOORBELL);
-               }
-
-               status = ft1000_read_dpram16(ft1000dev,
-                                            DWNLD_MAG1_HANDSHAKE_LOC,
-                                            (u8 *)&handshake, 1);
-               handshake = ntohs(handshake);
-
-               if (status)
-                       return HANDSHAKE_TIMEOUT_VALUE;
-
-               if ((handshake == expected_value) ||
-                   (handshake == HANDSHAKE_RESET_VALUE_USB)) {
-                       return handshake;
-               }
-               loopcnt++;
-               msleep(10);
-       }
-
-       return HANDSHAKE_TIMEOUT_VALUE;
-}
-
-/* write the handshake value to the handshake location */
-static void put_handshake(struct ft1000_usb *ft1000dev, u16 handshake_value)
-{
-       u32 tempx;
-       u16 tempword;
-       int status;
-
-       tempx = (u32)handshake_value;
-       tempx = ntohl(tempx);
-
-       tempword = (u16)(tempx & 0xffff);
-       status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
-                                     tempword, 0);
-       tempword = (u16)(tempx >> 16);
-       status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
-                                     tempword, 1);
-       status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
-                                      FT1000_REG_DOORBELL);
-}
-
-static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value)
-{
-       u16 handshake;
-       int loopcnt;
-       u16 temp;
-       int status = 0;
-
-       loopcnt = 0;
-       handshake = 0;
-
-       while (loopcnt < 100) {
-               if (ft1000dev->usbboot == 2) {
-                       status = ft1000_read_dpram32(ft1000dev, 0,
-                                                    (u8 *)&ft1000dev->tempbuf[0], 64);
-                       for (temp = 0; temp < 16; temp++) {
-                               pr_debug("tempbuf %d = 0x%x\n",
-                                        temp, ft1000dev->tempbuf[temp]);
-                       }
-                       status = ft1000_read_dpram16(ft1000dev,
-                                                    DWNLD_MAG1_HANDSHAKE_LOC,
-                                                    (u8 *)&handshake, 1);
-                       pr_debug("handshake from read_dpram16 = 0x%x\n",
-                                handshake);
-                       if (ft1000dev->dspalive == ft1000dev->tempbuf[6]) {
-                               handshake = 0;
-                       } else {
-                               handshake = ft1000dev->tempbuf[1];
-                               ft1000dev->dspalive =
-                                       ft1000dev->tempbuf[6];
-                       }
-               } else {
-                       status = ft1000_read_dpram16(ft1000dev,
-                                                    DWNLD_MAG1_HANDSHAKE_LOC,
-                                                    (u8 *)&handshake, 1);
-               }
-
-               loopcnt++;
-               msleep(10);
-               handshake = ntohs(handshake);
-               if ((handshake == expected_value) ||
-                   (handshake == HANDSHAKE_RESET_VALUE_USB))
-                       return handshake;
-       }
-
-       return HANDSHAKE_TIMEOUT_VALUE;
-}
-
-static void put_handshake_usb(struct ft1000_usb *ft1000dev, u16 handshake_value)
-{
-       int i;
-
-       for (i = 0; i < 1000; i++)
-               ;
-}
-
-static u16 get_request_type(struct ft1000_usb *ft1000dev)
-{
-       u16 request_type;
-       int status;
-       u16 tempword;
-       u32 tempx;
-
-       if (ft1000dev->bootmode == 1) {
-               status = fix_ft1000_read_dpram32(ft1000dev,
-                                                DWNLD_MAG1_TYPE_LOC,
-                                                (u8 *)&tempx);
-               tempx = ntohl(tempx);
-       } else {
-               tempx = 0;
-               status = ft1000_read_dpram16(ft1000dev,
-                                            DWNLD_MAG1_TYPE_LOC,
-                                            (u8 *)&tempword, 1);
-               tempx |= (tempword << 16);
-               tempx = ntohl(tempx);
-       }
-       request_type = (u16)tempx;
-
-       return request_type;
-}
-
-static u16 get_request_type_usb(struct ft1000_usb *ft1000dev)
-{
-       u16 request_type;
-       int status;
-       u16 tempword;
-       u32 tempx;
-
-       if (ft1000dev->bootmode == 1) {
-               status = fix_ft1000_read_dpram32(ft1000dev,
-                                                DWNLD_MAG1_TYPE_LOC,
-                                                (u8 *)&tempx);
-               tempx = ntohl(tempx);
-       } else {
-               if (ft1000dev->usbboot == 2) {
-                       tempx = ft1000dev->tempbuf[2];
-                       tempword = ft1000dev->tempbuf[3];
-               } else {
-                       tempx = 0;
-                       status = ft1000_read_dpram16(ft1000dev,
-                                                    DWNLD_MAG1_TYPE_LOC,
-                                                    (u8 *)&tempword, 1);
-               }
-               tempx |= (tempword << 16);
-               tempx = ntohl(tempx);
-       }
-       request_type = (u16)tempx;
-
-       return request_type;
-}
-
-static long get_request_value(struct ft1000_usb *ft1000dev)
-{
-       u32 value;
-       u16 tempword;
-       int status;
-
-       if (ft1000dev->bootmode == 1) {
-               status = fix_ft1000_read_dpram32(ft1000dev,
-                                                DWNLD_MAG1_SIZE_LOC,
-                                                (u8 *)&value);
-               value = ntohl(value);
-       } else  {
-               status = ft1000_read_dpram16(ft1000dev,
-                                            DWNLD_MAG1_SIZE_LOC,
-                                            (u8 *)&tempword, 0);
-               value = tempword;
-               status = ft1000_read_dpram16(ft1000dev,
-                                            DWNLD_MAG1_SIZE_LOC,
-                                            (u8 *)&tempword, 1);
-               value |= (tempword << 16);
-               value = ntohl(value);
-       }
-
-       return value;
-}
-
-
-/* writes a value to DWNLD_MAG1_SIZE_LOC */
-static void put_request_value(struct ft1000_usb *ft1000dev, long lvalue)
-{
-       u32    tempx;
-       int    status;
-
-       tempx = ntohl(lvalue);
-       status = fix_ft1000_write_dpram32(ft1000dev, DWNLD_MAG1_SIZE_LOC,
-                                         (u8 *)&tempx);
-}
-
-
-
-/* returns the checksum of the pseudo header */
-static u16 hdr_checksum(struct pseudo_hdr *pHdr)
-{
-       u16   *usPtr = (u16 *)pHdr;
-       u16   chksum;
-
-
-       chksum = (((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^
-                   usPtr[4]) ^ usPtr[5]) ^ usPtr[6];
-
-       return chksum;
-}
-
-static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset)
-{
-       int i;
-
-       for (i = 0; i < len; i++) {
-               if (buff_w[i] != buff_r[i + offset])
-                       return -EREMOTEIO;
-       }
-
-       return 0;
-}
-
-static int write_dpram32_and_check(struct ft1000_usb *ft1000dev,
-                                  u16 tempbuffer[], u16 dpram)
-{
-       int status;
-       u16 resultbuffer[64];
-       int i;
-
-       for (i = 0; i < 10; i++) {
-               status = ft1000_write_dpram32(ft1000dev, dpram,
-                                             (u8 *)&tempbuffer[0], 64);
-               if (status == 0) {
-                       /* Work around for ASIC bit stuffing problem. */
-                       if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
-                               status = ft1000_write_dpram32(ft1000dev,
-                                                             dpram+12, (u8 *)&tempbuffer[24],
-                                                             64);
-                       }
-                       /* Let's check the data written */
-                       status = ft1000_read_dpram32(ft1000dev, dpram,
-                                                    (u8 *)&resultbuffer[0], 64);
-                       if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
-                               if (check_buffers(tempbuffer, resultbuffer, 28,
-                                                 0)) {
-                                       pr_debug("DPRAM write failed 1 during bootloading\n");
-                                       usleep_range(9000, 11000);
-                                       break;
-                               }
-                               status = ft1000_read_dpram32(ft1000dev,
-                                                            dpram+12,
-                                                            (u8 *)&resultbuffer[0], 64);
-
-                               if (check_buffers(tempbuffer, resultbuffer, 16,
-                                                 24)) {
-                                       pr_debug("DPRAM write failed 2 during bootloading\n");
-                                       usleep_range(9000, 11000);
-                                       break;
-                               }
-                       } else {
-                               if (check_buffers(tempbuffer, resultbuffer, 32,
-                                                 0)) {
-                                       pr_debug("DPRAM write failed 3 during bootloading\n");
-                                       usleep_range(9000, 11000);
-                                       break;
-                               }
-                       }
-                       if (status == 0)
-                               break;
-               }
-       }
-       return status;
-}
-
-/* writes a block of DSP image to DPRAM
- * Parameters:  struct ft1000_usb  - device structure
- *              u16 **pUsFile - DSP image file pointer in u16
- *              u8  **pUcFile - DSP image file pointer in u8
- *              long word_length - length of the buffer to be written to DPRAM
- */
-static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
-                    long word_length)
-{
-       int status = 0;
-       u16 dpram;
-       int loopcnt, i;
-       u16 tempword;
-       u16 tempbuffer[64];
-
-       /*pr_debug("start word_length = %d\n",(int)word_length); */
-       dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
-       tempword = *(*pUsFile);
-       (*pUsFile)++;
-       status = ft1000_write_dpram16(ft1000dev, dpram, tempword, 0);
-       tempword = *(*pUsFile);
-       (*pUsFile)++;
-       status = ft1000_write_dpram16(ft1000dev, dpram++, tempword, 1);
-
-       *pUcFile = *pUcFile + 4;
-       word_length--;
-       tempword = (u16)word_length;
-       word_length = (word_length / 16) + 1;
-       for (; word_length > 0; word_length--) { /* In words */
-               loopcnt = 0;
-               for (i = 0; i < 32; i++) {
-                       if (tempword != 0) {
-                               tempbuffer[i++] = *(*pUsFile);
-                               (*pUsFile)++;
-                               tempbuffer[i] = *(*pUsFile);
-                               (*pUsFile)++;
-                               *pUcFile = *pUcFile + 4;
-                               loopcnt++;
-                               tempword--;
-                       } else {
-                               tempbuffer[i++] = 0;
-                               tempbuffer[i] = 0;
-                       }
-               }
-
-               /*pr_debug("loopcnt is %d\n", loopcnt); */
-               /*pr_debug("write_blk: bootmode = %d\n", bootmode); */
-               /*pr_debug("write_blk: dpram = %x\n", dpram); */
-               if (ft1000dev->bootmode == 0) {
-                       if (dpram >= 0x3F4)
-                               status = ft1000_write_dpram32(ft1000dev, dpram,
-                                                             (u8 *)&tempbuffer[0], 8);
-                       else
-                               status = ft1000_write_dpram32(ft1000dev, dpram,
-                                                             (u8 *)&tempbuffer[0], 64);
-               } else {
-                       status = write_dpram32_and_check(ft1000dev, tempbuffer,
-                                                        dpram);
-                       if (status != 0) {
-                               pr_debug("Write failed tempbuffer[31] = 0x%x\n",
-                                        tempbuffer[31]);
-                               break;
-                       }
-               }
-               dpram = dpram + loopcnt;
-       }
-       return status;
-}
-
-static void usb_dnld_complete(struct urb *urb)
-{
-       /* pr_debug("****** usb_dnld_complete\n"); */
-}
-
-/* writes a block of DSP image to DPRAM
- * Parameters:  struct ft1000_usb  - device structure
- *              u16 **pUsFile - DSP image file pointer in u16
- *              u8  **pUcFile - DSP image file pointer in u8
- *              long word_length - length of the buffer to be written to DPRAM
- */
-static int write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile,
-                         u8 **pUcFile, long word_length)
-{
-       int byte_length;
-
-       byte_length = word_length * 4;
-
-       if (byte_length && ((byte_length % 64) == 0))
-               byte_length += 4;
-
-       if (byte_length < 64)
-               byte_length = 68;
-
-       usb_init_urb(ft1000dev->tx_urb);
-       memcpy(ft1000dev->tx_buf, *pUcFile, byte_length);
-       usb_fill_bulk_urb(ft1000dev->tx_urb,
-                         ft1000dev->dev,
-                         usb_sndbulkpipe(ft1000dev->dev,
-                                         ft1000dev->bulk_out_endpointAddr),
-                         ft1000dev->tx_buf, byte_length, usb_dnld_complete,
-                         ft1000dev);
-
-       usb_submit_urb(ft1000dev->tx_urb, GFP_ATOMIC);
-
-       *pUsFile = *pUsFile + (word_length << 1);
-       *pUcFile = *pUcFile + (word_length << 2);
-
-       return 0;
-}
-
-static int scram_start_dwnld(struct ft1000_usb *ft1000dev, u16 *hshake,
-                            u32 *state)
-{
-       int status = 0;
-
-       if (ft1000dev->usbboot)
-               *hshake = get_handshake_usb(ft1000dev, HANDSHAKE_DSP_BL_READY);
-       else
-               *hshake = get_handshake(ft1000dev, HANDSHAKE_DSP_BL_READY);
-       if (*hshake == HANDSHAKE_DSP_BL_READY) {
-               pr_debug("handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n");
-               put_handshake(ft1000dev, HANDSHAKE_DRIVER_READY);
-       } else if (*hshake == HANDSHAKE_TIMEOUT_VALUE) {
-               status = -ETIMEDOUT;
-       } else {
-               pr_debug("Download error: Handshake failed\n");
-               status = -ENETRESET;
-       }
-       *state = STATE_BOOT_DWNLD;
-       return status;
-}
-
-static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file,
-                               u8 **c_file, const u8 *endpoint, bool boot_case)
-{
-       long word_length;
-       int status = 0;
-
-       word_length = get_request_value(ft1000dev);
-       /*pr_debug("word_length = 0x%x\n", (int)word_length); */
-       /*NdisMSleep (100); */
-       if (word_length > MAX_LENGTH) {
-               pr_debug("Download error: Max length exceeded\n");
-               return -1;
-       }
-       if ((word_length * 2 + (long)c_file) > (long)endpoint) {
-               /* Error, beyond boot code range.*/
-               pr_debug("Download error: Requested len=%d exceeds BOOT code boundary\n",
-                        (int)word_length);
-               return -1;
-       }
-       if (word_length & 0x1)
-               word_length++;
-       word_length = word_length / 2;
-
-       if (boot_case) {
-               status = write_blk(ft1000dev, s_file, c_file, word_length);
-               /*pr_debug("write_blk returned %d\n", status); */
-       } else {
-               status = write_blk_fifo(ft1000dev, s_file, c_file, word_length);
-               if (ft1000dev->usbboot == 0)
-                       ft1000dev->usbboot++;
-               if (ft1000dev->usbboot == 1)
-                       status |= ft1000_write_dpram16(ft1000dev,
-                                                      DWNLD_MAG1_PS_HDR_LOC, 0, 0);
-       }
-       return status;
-}
-
-/* Scramble downloader for Harley based ASIC via USB interface */
-int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
-               u32 FileLength)
-{
-       int status = 0;
-       u32 state;
-       u16 handshake;
-       struct pseudo_hdr *pseudo_header;
-       u16 pseudo_header_len;
-       long word_length;
-       u16 request;
-       u16 temp;
-
-       struct dsp_file_hdr *file_hdr;
-       struct dsp_image_info *dsp_img_info = NULL;
-       long requested_version;
-       bool correct_version;
-       struct drv_msg *mailbox_data;
-       u16 *data = NULL;
-       u16 *s_file = NULL;
-       u8 *c_file = NULL;
-       u8 *boot_end = NULL, *code_end = NULL;
-       int image;
-       long loader_code_address, loader_code_size = 0;
-       long run_address = 0, run_size = 0;
-
-       u32 templong;
-       u32 image_chksum = 0;
-
-       u16 dpram = 0;
-       u8 *pbuffer;
-       struct prov_record *pprov_record;
-       struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
-
-       ft1000dev->fcodeldr = 0;
-       ft1000dev->usbboot = 0;
-       ft1000dev->dspalive = 0xffff;
-
-       /*
-        * Get version id of file, at first 4 bytes of file, for newer files.
-        */
-
-       state = STATE_START_DWNLD;
-
-       file_hdr = pFileStart;
-
-       ft1000_write_register(ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK);
-
-       s_file = (u16 *) (pFileStart + file_hdr->loader_offset);
-       c_file = (u8 *) (pFileStart + file_hdr->loader_offset);
-
-       boot_end = (u8 *) (pFileStart + file_hdr->loader_code_end);
-
-       loader_code_address = file_hdr->loader_code_address;
-       loader_code_size = file_hdr->loader_code_size;
-       correct_version = false;
-
-       while ((status == 0) && (state != STATE_DONE_FILE)) {
-               switch (state) {
-               case STATE_START_DWNLD:
-                       status = scram_start_dwnld(ft1000dev, &handshake,
-                                                  &state);
-                       break;
-
-               case STATE_BOOT_DWNLD:
-                       pr_debug("STATE_BOOT_DWNLD\n");
-                       ft1000dev->bootmode = 1;
-                       handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST);
-                       if (handshake == HANDSHAKE_REQUEST) {
-                               /*
-                                * Get type associated with the request.
-                                */
-                               request = get_request_type(ft1000dev);
-                               switch (request) {
-                               case REQUEST_RUN_ADDRESS:
-                                       pr_debug("REQUEST_RUN_ADDRESS\n");
-                                       put_request_value(ft1000dev,
-                                                         loader_code_address);
-                                       break;
-                               case REQUEST_CODE_LENGTH:
-                                       pr_debug("REQUEST_CODE_LENGTH\n");
-                                       put_request_value(ft1000dev,
-                                                         loader_code_size);
-                                       break;
-                               case REQUEST_DONE_BL:
-                                       pr_debug("REQUEST_DONE_BL\n");
-                                       /* Reposition ptrs to beginning of code section */
-                                       s_file = (u16 *) (boot_end);
-                                       c_file = (u8 *) (boot_end);
-                                       /* pr_debug("download:s_file = 0x%8x\n", (int)s_file); */
-                                       /* pr_debug("FT1000:download:c_file = 0x%8x\n", (int)c_file); */
-                                       state = STATE_CODE_DWNLD;
-                                       ft1000dev->fcodeldr = 1;
-                                       break;
-                               case REQUEST_CODE_SEGMENT:
-                                       status = request_code_segment(ft1000dev,
-                                                                     &s_file, &c_file,
-                                                                     boot_end,
-                                                                     true);
-                                       break;
-                               default:
-                                       pr_debug("Download error: Bad request type=%d in BOOT download state\n",
-                                                request);
-                                       status = -1;
-                                       break;
-                               }
-                               if (ft1000dev->usbboot)
-                                       put_handshake_usb(ft1000dev,
-                                                         HANDSHAKE_RESPONSE);
-                               else
-                                       put_handshake(ft1000dev,
-                                                     HANDSHAKE_RESPONSE);
-                       } else {
-                               pr_debug("Download error: Handshake failed\n");
-                               status = -1;
-                       }
-
-                       break;
-
-               case STATE_CODE_DWNLD:
-                       /* pr_debug("STATE_CODE_DWNLD\n"); */
-                       ft1000dev->bootmode = 0;
-                       if (ft1000dev->usbboot)
-                               handshake =
-                                       get_handshake_usb(ft1000dev,
-                                                         HANDSHAKE_REQUEST);
-                       else
-                               handshake =
-                                       get_handshake(ft1000dev, HANDSHAKE_REQUEST);
-                       if (handshake == HANDSHAKE_REQUEST) {
-                               /*
-                                * Get type associated with the request.
-                                */
-                               if (ft1000dev->usbboot)
-                                       request =
-                                               get_request_type_usb(ft1000dev);
-                               else
-                                       request = get_request_type(ft1000dev);
-                               switch (request) {
-                               case REQUEST_FILE_CHECKSUM:
-                                       pr_debug("image_chksum = 0x%8x\n",
-                                                image_chksum);
-                                       put_request_value(ft1000dev,
-                                                         image_chksum);
-                                       break;
-                               case REQUEST_RUN_ADDRESS:
-                                       pr_debug("REQUEST_RUN_ADDRESS\n");
-                                       if (correct_version) {
-                                               pr_debug("run_address = 0x%8x\n",
-                                                        (int)run_address);
-                                               put_request_value(ft1000dev,
-                                                                 run_address);
-                                       } else {
-                                               pr_debug("Download error: Got Run address request before image offset request\n");
-                                               status = -1;
-                                               break;
-                                       }
-                                       break;
-                               case REQUEST_CODE_LENGTH:
-                                       pr_debug("REQUEST_CODE_LENGTH\n");
-                                       if (correct_version) {
-                                               pr_debug("run_size = 0x%8x\n",
-                                                        (int)run_size);
-                                               put_request_value(ft1000dev,
-                                                                 run_size);
-                                       } else {
-                                               pr_debug("Download error: Got Size request before image offset request\n");
-                                               status = -1;
-                                               break;
-                                       }
-                                       break;
-                               case REQUEST_DONE_CL:
-                                       ft1000dev->usbboot = 3;
-                                       /* Reposition ptrs to beginning of provisioning section */
-                                       s_file =
-                                               (u16 *) (pFileStart +
-                                                        file_hdr->commands_offset);
-                                       c_file =
-                                               (u8 *) (pFileStart +
-                                                       file_hdr->commands_offset);
-                                       state = STATE_DONE_DWNLD;
-                                       break;
-                               case REQUEST_CODE_SEGMENT:
-                                       /* pr_debug("REQUEST_CODE_SEGMENT - CODELOADER\n"); */
-                                       if (!correct_version) {
-                                               pr_debug("Download error: Got Code Segment request before image offset request\n");
-                                               status = -1;
-                                               break;
-                                       }
-
-                                       status = request_code_segment(ft1000dev,
-                                                                     &s_file, &c_file,
-                                                                     code_end,
-                                                                     false);
-
-                                       break;
-
-                               case REQUEST_MAILBOX_DATA:
-                                       pr_debug("REQUEST_MAILBOX_DATA\n");
-                                       /* Convert length from byte count to word count. Make sure we round up. */
-                                       word_length =
-                                               (long)(pft1000info->DSPInfoBlklen +
-                                                      1) / 2;
-                                       put_request_value(ft1000dev,
-                                                         word_length);
-                                       mailbox_data =
-                                               (struct drv_msg *)&(pft1000info->
-                                                                   DSPInfoBlk[0]);
-                                       /*
-                                        * Position ASIC DPRAM auto-increment pointer.
-                                        */
-
-                                       data = (u16 *)&mailbox_data->data[0];
-                                       dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
-                                       if (word_length & 0x1)
-                                               word_length++;
-
-                                       word_length = word_length / 2;
-
-                                       for (; word_length > 0; word_length--) {        /* In words */
-
-                                               templong = *data++;
-                                               templong |= (*data++ << 16);
-                                               status =
-                                                       fix_ft1000_write_dpram32
-                                                       (ft1000dev, dpram++,
-                                                        (u8 *)&templong);
-
-                                       }
-                                       break;
-
-                               case REQUEST_VERSION_INFO:
-                                       pr_debug("REQUEST_VERSION_INFO\n");
-                                       word_length =
-                                               file_hdr->version_data_size;
-                                       put_request_value(ft1000dev,
-                                                         word_length);
-                                       /*
-                                        * Position ASIC DPRAM auto-increment pointer.
-                                        */
-
-                                       s_file =
-                                               (u16 *) (pFileStart +
-                                                        file_hdr->
-                                                        version_data_offset);
-
-                                       dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
-                                       if (word_length & 0x1)
-                                               word_length++;
-
-                                       word_length = word_length / 2;
-
-                                       for (; word_length > 0; word_length--) {        /* In words */
-
-                                               templong = ntohs(*s_file++);
-                                               temp = ntohs(*s_file++);
-                                               templong |= (temp << 16);
-                                               status =
-                                                       fix_ft1000_write_dpram32
-                                                       (ft1000dev, dpram++,
-                                                        (u8 *)&templong);
-
-                                       }
-                                       break;
-
-                               case REQUEST_CODE_BY_VERSION:
-                                       pr_debug("REQUEST_CODE_BY_VERSION\n");
-                                       correct_version = false;
-                                       requested_version =
-                                               get_request_value(ft1000dev);
-
-                                       dsp_img_info =
-                                               (struct dsp_image_info *)(pFileStart
-                                                                         +
-                                                                         sizeof
-                                                                         (struct
-                                                                          dsp_file_hdr));
-
-                                       for (image = 0;
-                                            image < file_hdr->nDspImages;
-                                            image++) {
-
-                                               if (dsp_img_info->version ==
-                                                   requested_version) {
-                                                       correct_version = true;
-                                                       pr_debug("correct_version is TRUE\n");
-                                                       s_file =
-                                                               (u16 *) (pFileStart
-                                                                        +
-                                                                        dsp_img_info->
-                                                                        begin_offset);
-                                                       c_file =
-                                                               (u8 *) (pFileStart +
-                                                                       dsp_img_info->
-                                                                       begin_offset);
-                                                       code_end =
-                                                               (u8 *) (pFileStart +
-                                                                       dsp_img_info->
-                                                                       end_offset);
-                                                       run_address =
-                                                               dsp_img_info->
-                                                               run_address;
-                                                       run_size =
-                                                               dsp_img_info->
-                                                               image_size;
-                                                       image_chksum =
-                                                               (u32)dsp_img_info->
-                                                               checksum;
-                                                       break;
-                                               }
-                                               dsp_img_info++;
-
-                                       }       /* end of for */
-
-                                       if (!correct_version) {
-                                               /*
-                                                * Error, beyond boot code range.
-                                                */
-                                               pr_debug("Download error: Bad Version Request = 0x%x.\n",
-                                                        (int)requested_version);
-                                               status = -1;
-                                               break;
-                                       }
-                                       break;
-
-                               default:
-                                       pr_debug("Download error: Bad request type=%d in CODE download state.\n",
-                                                request);
-                                       status = -1;
-                                       break;
-                               }
-                               if (ft1000dev->usbboot)
-                                       put_handshake_usb(ft1000dev,
-                                                         HANDSHAKE_RESPONSE);
-                               else
-                                       put_handshake(ft1000dev,
-                                                     HANDSHAKE_RESPONSE);
-                       } else {
-                               pr_debug("Download error: Handshake failed\n");
-                               status = -1;
-                       }
-
-                       break;
-
-               case STATE_DONE_DWNLD:
-                       pr_debug("Code loader is done...\n");
-                       state = STATE_SECTION_PROV;
-                       break;
-
-               case STATE_SECTION_PROV:
-                       pr_debug("STATE_SECTION_PROV\n");
-                       pseudo_header = (struct pseudo_hdr *)c_file;
-
-                       if (pseudo_header->checksum ==
-                           hdr_checksum(pseudo_header)) {
-                               if (pseudo_header->portdest !=
-                                   0x80 /* Dsp OAM */) {
-                                       state = STATE_DONE_PROV;
-                                       break;
-                               }
-                               pseudo_header_len = ntohs(pseudo_header->length);       /* Byte length for PROV records */
-
-                               /* Get buffer for provisioning data */
-                               pbuffer =
-                                       kmalloc(pseudo_header_len +
-                                                sizeof(struct pseudo_hdr),
-                                               GFP_ATOMIC);
-                               if (pbuffer) {
-                                       memcpy(pbuffer, c_file,
-                                              (u32) (pseudo_header_len +
-                                                     sizeof(struct
-                                                            pseudo_hdr)));
-                                       /* link provisioning data */
-                                       pprov_record =
-                                               kmalloc(sizeof(struct prov_record),
-                                                       GFP_ATOMIC);
-                                       if (pprov_record) {
-                                               pprov_record->pprov_data =
-                                                       pbuffer;
-                                               list_add_tail(&pprov_record->
-                                                             list,
-                                                             &pft1000info->
-                                                             prov_list);
-                                               /* Move to next entry if available */
-                                               c_file =
-                                                       (u8 *) ((unsigned long)
-                                                               c_file +
-                                                               (u32) ((pseudo_header_len + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
-                                               if ((unsigned long)(c_file) -
-                                                   (unsigned long)(pFileStart)
-                                                   >=
-                                                   (unsigned long)FileLength) {
-                                                       state = STATE_DONE_FILE;
-                                               }
-                                       } else {
-                                               kfree(pbuffer);
-                                               status = -1;
-                                       }
-                               } else {
-                                       status = -1;
-                               }
-                       } else {
-                               /* Checksum did not compute */
-                               status = -1;
-                       }
-                       pr_debug("after STATE_SECTION_PROV, state = %d, status= %d\n",
-                                state, status);
-                       break;
-
-               case STATE_DONE_PROV:
-                       pr_debug("STATE_DONE_PROV\n");
-                       state = STATE_DONE_FILE;
-                       break;
-
-               default:
-                       status = -1;
-                       break;
-               }               /* End Switch */
-
-               if (status != 0)
-                       break;
-
-/****
- // Check if Card is present
- status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK);
- if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) {
- break;
- }
-
- status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID);
- if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) {
- break;
- }
-****/
-
-       }                       /* End while */
-
-       pr_debug("Download exiting with status = 0x%8x\n", status);
-       ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
-                             FT1000_REG_DOORBELL);
-
-       return status;
-}
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
deleted file mode 100644 (file)
index 9620970..0000000
+++ /dev/null
@@ -1,1586 +0,0 @@
-/* CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
- *
- *
- * This file is part of Express Card USB Driver
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/usb.h>
-#include "ft1000_usb.h"
-#include <linux/types.h>
-
-#define HARLEY_READ_REGISTER     0x0
-#define HARLEY_WRITE_REGISTER    0x01
-#define HARLEY_READ_DPRAM_32     0x02
-#define HARLEY_READ_DPRAM_LOW    0x03
-#define HARLEY_READ_DPRAM_HIGH   0x04
-#define HARLEY_WRITE_DPRAM_32    0x05
-#define HARLEY_WRITE_DPRAM_LOW   0x06
-#define HARLEY_WRITE_DPRAM_HIGH  0x07
-
-#define HARLEY_READ_OPERATION    0xc1
-#define HARLEY_WRITE_OPERATION   0x41
-
-#if 0
-#define JDEBUG
-#endif
-
-static int ft1000_submit_rx_urb(struct ft1000_info *info);
-
-static u8 tempbuffer[1600];
-
-#define MAX_RCV_LOOP   100
-
-/* send a control message via USB interface synchronously
- *  Parameters:  ft1000_usb  - device structure
- *               pipe - usb control message pipe
- *               request - control request
- *               requesttype - control message request type
- *               value - value to be written or 0
- *               index - register index
- *               data - data buffer to hold the read/write values
- *               size - data size
- *               timeout - control message time out value
- */
-static int ft1000_control(struct ft1000_usb *ft1000dev, unsigned int pipe,
-                         u8 request, u8 requesttype, u16 value, u16 index,
-                         void *data, u16 size, int timeout)
-{
-       int ret;
-
-       if ((ft1000dev == NULL) || (ft1000dev->dev == NULL)) {
-               pr_debug("ft1000dev or ft1000dev->dev == NULL, failure\n");
-               return -ENODEV;
-       }
-
-       ret = usb_control_msg(ft1000dev->dev, pipe, request, requesttype,
-                             value, index, data, size, timeout);
-
-       if (ret > 0)
-               ret = 0;
-
-       return ret;
-}
-
-/* returns the value in a register */
-int ft1000_read_register(struct ft1000_usb *ft1000dev, u16 *Data,
-                        u16 nRegIndx)
-{
-       int ret = 0;
-
-       ret = ft1000_control(ft1000dev,
-                            usb_rcvctrlpipe(ft1000dev->dev, 0),
-                            HARLEY_READ_REGISTER,
-                            HARLEY_READ_OPERATION,
-                            0,
-                            nRegIndx,
-                            Data,
-                            2,
-                            USB_CTRL_GET_TIMEOUT);
-
-       return ret;
-}
-
-/* writes the value in a register */
-int ft1000_write_register(struct ft1000_usb *ft1000dev, u16 value,
-                         u16 nRegIndx)
-{
-       int ret = 0;
-
-       ret = ft1000_control(ft1000dev,
-                            usb_sndctrlpipe(ft1000dev->dev, 0),
-                            HARLEY_WRITE_REGISTER,
-                            HARLEY_WRITE_OPERATION,
-                            value,
-                            nRegIndx,
-                            NULL,
-                            0,
-                            USB_CTRL_SET_TIMEOUT);
-
-       return ret;
-}
-
-/* read a number of bytes from DPRAM */
-int ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer,
-                       u16 cnt)
-{
-       int ret = 0;
-
-       ret = ft1000_control(ft1000dev,
-                            usb_rcvctrlpipe(ft1000dev->dev, 0),
-                            HARLEY_READ_DPRAM_32,
-                            HARLEY_READ_OPERATION,
-                            0,
-                            indx,
-                            buffer,
-                            cnt,
-                            USB_CTRL_GET_TIMEOUT);
-
-       return ret;
-}
-
-/* writes into DPRAM a number of bytes */
-int ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer,
-                        u16 cnt)
-{
-       int ret = 0;
-
-       if (cnt % 4)
-               cnt += cnt - (cnt % 4);
-
-       ret = ft1000_control(ft1000dev,
-                            usb_sndctrlpipe(ft1000dev->dev, 0),
-                            HARLEY_WRITE_DPRAM_32,
-                            HARLEY_WRITE_OPERATION,
-                            0,
-                            indx,
-                            buffer,
-                            cnt,
-                            USB_CTRL_SET_TIMEOUT);
-
-       return ret;
-}
-
-/* read 16 bits from DPRAM */
-int ft1000_read_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer,
-                       u8 highlow)
-{
-       int ret = 0;
-       u8 request;
-
-       if (highlow == 0)
-               request = HARLEY_READ_DPRAM_LOW;
-       else
-               request = HARLEY_READ_DPRAM_HIGH;
-
-       ret = ft1000_control(ft1000dev,
-                            usb_rcvctrlpipe(ft1000dev->dev, 0),
-                            request,
-                            HARLEY_READ_OPERATION,
-                            0,
-                            indx,
-                            buffer,
-                            2,
-                            USB_CTRL_GET_TIMEOUT);
-
-       return ret;
-}
-
-/* write into DPRAM a number of bytes */
-int ft1000_write_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u16 value,
-                        u8 highlow)
-{
-       int ret = 0;
-       u8 request;
-
-       if (highlow == 0)
-               request = HARLEY_WRITE_DPRAM_LOW;
-       else
-               request = HARLEY_WRITE_DPRAM_HIGH;
-
-       ret = ft1000_control(ft1000dev,
-                            usb_sndctrlpipe(ft1000dev->dev, 0),
-                            request,
-                            HARLEY_WRITE_OPERATION,
-                            value,
-                            indx,
-                            NULL,
-                            0,
-                            USB_CTRL_SET_TIMEOUT);
-
-       return ret;
-}
-
-/* read DPRAM 4 words at a time */
-int fix_ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx,
-                           u8 *buffer)
-{
-       u8 buf[16];
-       u16 pos;
-       int ret = 0;
-
-       pos = (indx / 4) * 4;
-       ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
-
-       if (ret == 0) {
-               pos = (indx % 4) * 4;
-               *buffer++ = buf[pos++];
-               *buffer++ = buf[pos++];
-               *buffer++ = buf[pos++];
-               *buffer++ = buf[pos++];
-       } else {
-               pr_debug("DPRAM32 Read failed\n");
-               *buffer++ = 0;
-               *buffer++ = 0;
-               *buffer++ = 0;
-               *buffer++ = 0;
-       }
-
-       return ret;
-}
-
-
-/* Description: This function write to DPRAM 4 words at a time */
-int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer)
-{
-       u16 pos1;
-       u16 pos2;
-       u16 i;
-       u8 buf[32];
-       u8 resultbuffer[32];
-       u8 *pdata;
-       int ret  = 0;
-
-       pos1 = (indx / 4) * 4;
-       pdata = buffer;
-       ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
-
-       if (ret == 0) {
-               pos2 = (indx % 4)*4;
-               buf[pos2++] = *buffer++;
-               buf[pos2++] = *buffer++;
-               buf[pos2++] = *buffer++;
-               buf[pos2++] = *buffer++;
-               ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
-       } else {
-               pr_debug("DPRAM32 Read failed\n");
-               return ret;
-       }
-
-       ret = ft1000_read_dpram32(ft1000dev, pos1, (u8 *)&resultbuffer[0], 16);
-
-       if (ret == 0) {
-               buffer = pdata;
-               for (i = 0; i < 16; i++) {
-                       if (buf[i] != resultbuffer[i])
-                               ret = -1;
-               }
-       }
-
-       if (ret == -1) {
-               ret = ft1000_write_dpram32(ft1000dev, pos1,
-                                          (u8 *)&tempbuffer[0], 16);
-               ret = ft1000_read_dpram32(ft1000dev, pos1,
-                                         (u8 *)&resultbuffer[0], 16);
-               if (ret == 0) {
-                       buffer = pdata;
-                       for (i = 0; i < 16; i++) {
-                               if (tempbuffer[i] != resultbuffer[i]) {
-                                       ret = -1;
-                                       pr_debug("Failed to write\n");
-                               }
-                       }
-               }
-       }
-
-       return ret;
-}
-
-/* reset or activate the DSP */
-static void card_reset_dsp(struct ft1000_usb *ft1000dev, bool value)
-{
-       int status = 0;
-       u16 tempword;
-
-       status = ft1000_write_register(ft1000dev, HOST_INTF_BE,
-                                      FT1000_REG_SUP_CTRL);
-       status = ft1000_read_register(ft1000dev, &tempword,
-                                     FT1000_REG_SUP_CTRL);
-
-       if (value) {
-               pr_debug("Reset DSP\n");
-               status = ft1000_read_register(ft1000dev, &tempword,
-                                             FT1000_REG_RESET);
-               tempword |= DSP_RESET_BIT;
-               status = ft1000_write_register(ft1000dev, tempword,
-                                              FT1000_REG_RESET);
-       } else {
-               pr_debug("Activate DSP\n");
-               status = ft1000_read_register(ft1000dev, &tempword,
-                                             FT1000_REG_RESET);
-               tempword |= DSP_ENCRYPTED;
-               tempword &= ~DSP_UNENCRYPTED;
-               status = ft1000_write_register(ft1000dev, tempword,
-                                              FT1000_REG_RESET);
-               status = ft1000_read_register(ft1000dev, &tempword,
-                                             FT1000_REG_RESET);
-               tempword &= ~EFUSE_MEM_DISABLE;
-               tempword &= ~DSP_RESET_BIT;
-               status = ft1000_write_register(ft1000dev, tempword,
-                                              FT1000_REG_RESET);
-               status = ft1000_read_register(ft1000dev, &tempword,
-                                             FT1000_REG_RESET);
-       }
-}
-
-/* send a command to ASIC
- *  Parameters:  ft1000_usb  - device structure
- *               ptempbuffer - command buffer
- *               size - command buffer size
- */
-int card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer,
-                     int size)
-{
-       int ret;
-       unsigned short temp;
-       unsigned char *commandbuf;
-
-       pr_debug("enter card_send_command... size=%d\n", size);
-
-       ret = ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
-       if (ret)
-               return ret;
-
-       commandbuf = kmalloc(size + 2, GFP_KERNEL);
-       if (!commandbuf)
-               return -ENOMEM;
-       memcpy((void *)commandbuf + 2, ptempbuffer, size);
-
-       if (temp & 0x0100)
-               usleep_range(900, 1100);
-
-       /* check for odd word */
-       size = size + 2;
-
-       /* Must force to be 32 bit aligned */
-       if (size % 4)
-               size += 4 - (size % 4);
-
-       ret = ft1000_write_dpram32(ft1000dev, 0, commandbuf, size);
-       if (ret)
-               return ret;
-       usleep_range(900, 1100);
-       ret = ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX,
-                                   FT1000_REG_DOORBELL);
-       if (ret)
-               return ret;
-       usleep_range(900, 1100);
-
-       ret = ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
-
-#if 0
-       if ((temp & 0x0100) == 0)
-               pr_debug("Message sent\n");
-#endif
-       return ret;
-}
-
-/* load or reload the DSP */
-int dsp_reload(struct ft1000_usb *ft1000dev)
-{
-       int status;
-       u16 tempword;
-       u32 templong;
-
-       struct ft1000_info *pft1000info;
-
-       pft1000info = netdev_priv(ft1000dev->net);
-
-       pft1000info->CardReady = 0;
-
-       /* Program Interrupt Mask register */
-       status = ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
-
-       status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
-       tempword |= ASIC_RESET_BIT;
-       status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
-       msleep(1000);
-       status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
-       pr_debug("Reset Register = 0x%x\n", tempword);
-
-       /* Toggle DSP reset */
-       card_reset_dsp(ft1000dev, 1);
-       msleep(1000);
-       card_reset_dsp(ft1000dev, 0);
-       msleep(1000);
-
-       status = ft1000_write_register(ft1000dev, HOST_INTF_BE,
-                                      FT1000_REG_SUP_CTRL);
-
-       /* Let's check for FEFE */
-       status =
-               ft1000_read_dpram32(ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX,
-                                   (u8 *)&templong, 4);
-       pr_debug("templong (fefe) = 0x%8x\n", templong);
-
-       /* call codeloader */
-       status = scram_dnldr(ft1000dev, pFileStart, FileLength);
-
-       if (status != 0)
-               return -EIO;
-
-       msleep(1000);
-
-       return 0;
-}
-
-/* call the Card Service function to reset the ASIC. */
-static void ft1000_reset_asic(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       struct ft1000_usb *ft1000dev = info->priv;
-       u16 tempword;
-
-       /* Let's use the register provided by the Magnemite ASIC to reset the
-        * ASIC and DSP.
-        */
-       ft1000_write_register(ft1000dev, DSP_RESET_BIT | ASIC_RESET_BIT,
-                             FT1000_REG_RESET);
-
-       mdelay(1);
-
-       /* set watermark to -1 in order to not generate an interrupt */
-       ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
-
-       /* clear interrupts */
-       ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR);
-       pr_debug("interrupt status register = 0x%x\n", tempword);
-       ft1000_write_register(ft1000dev, tempword, FT1000_REG_SUP_ISR);
-       ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR);
-       pr_debug("interrupt status register = 0x%x\n", tempword);
-}
-
-static int ft1000_reset_card(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-       struct ft1000_usb *ft1000dev = info->priv;
-       u16 tempword;
-       struct prov_record *ptr;
-       struct prov_record *tmp;
-
-       ft1000dev->fCondResetPend = true;
-       info->CardReady = 0;
-       ft1000dev->fProvComplete = false;
-
-       /* Make sure we free any memory reserve for provisioning */
-       list_for_each_entry_safe(ptr, tmp, &info->prov_list, list) {
-               pr_debug("deleting provisioning record\n");
-               list_del(&ptr->list);
-               kfree(ptr->pprov_data);
-               kfree(ptr);
-       }
-
-       pr_debug("reset asic\n");
-       ft1000_reset_asic(dev);
-
-       pr_debug("call dsp_reload\n");
-       dsp_reload(ft1000dev);
-
-       pr_debug("dsp reload successful\n");
-
-       mdelay(10);
-
-       /* Initialize DSP heartbeat area */
-       ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag,
-                            FT1000_MAG_HI_HO_INDX);
-       ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (u8 *)&tempword,
-                           FT1000_MAG_HI_HO_INDX);
-       pr_debug("hi_ho value = 0x%x\n", tempword);
-
-       info->CardReady = 1;
-
-       ft1000dev->fCondResetPend = false;
-
-       return TRUE;
-}
-
-/* callback function when a urb is transmitted */
-static void ft1000_usb_transmit_complete(struct urb *urb)
-{
-
-       struct ft1000_usb *ft1000dev = urb->context;
-
-       if (urb->status)
-               pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status);
-
-       netif_wake_queue(ft1000dev->net);
-}
-
-/* take an ethernet packet and convert it to a Flarion
- *  packet prior to sending it to the ASIC Downlink FIFO.
- */
-static int ft1000_copy_down_pkt(struct net_device *netdev, u8 *packet, u16 len)
-{
-       struct ft1000_info *pInfo = netdev_priv(netdev);
-       struct ft1000_usb *pFt1000Dev = pInfo->priv;
-
-       int count, ret;
-       u8 *t;
-       struct pseudo_hdr hdr;
-
-       if (!pInfo->CardReady) {
-               pr_debug("Card Not Ready\n");
-               return -ENODEV;
-       }
-
-       count = sizeof(struct pseudo_hdr) + len;
-       if (count > MAX_BUF_SIZE) {
-               pr_debug("Message Size Overflow! size = %d\n", count);
-               return -EINVAL;
-       }
-
-       if (count % 4)
-               count = count + (4 - (count % 4));
-
-       memset(&hdr, 0, sizeof(struct pseudo_hdr));
-
-       hdr.length = ntohs(count);
-       hdr.source = 0x10;
-       hdr.destination = 0x20;
-       hdr.portdest = 0x20;
-       hdr.portsrc = 0x10;
-       hdr.sh_str_id = 0x91;
-       hdr.control = 0x00;
-
-       hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^
-               hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^ hdr.control;
-
-       memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr));
-       memcpy(&pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)], packet, len);
-
-       netif_stop_queue(netdev);
-
-       usb_fill_bulk_urb(pFt1000Dev->tx_urb,
-                         pFt1000Dev->dev,
-                         usb_sndbulkpipe(pFt1000Dev->dev,
-                                         pFt1000Dev->bulk_out_endpointAddr),
-                         pFt1000Dev->tx_buf, count,
-                         ft1000_usb_transmit_complete, pFt1000Dev);
-
-       t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer;
-
-       ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
-
-       if (ret) {
-               pr_debug("failed tx_urb %d\n", ret);
-               return ret;
-       }
-       pInfo->stats.tx_packets++;
-       pInfo->stats.tx_bytes += (len + 14);
-
-       return 0;
-}
-
-/* transmit an ethernet packet
- *  Parameters:  skb - socket buffer to be sent
- *               dev - network device
- */
-static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
-{
-       struct ft1000_info *pInfo = netdev_priv(dev);
-       struct ft1000_usb *pFt1000Dev = pInfo->priv;
-       u8 *pdata;
-       int maxlen, pipe;
-
-       if (skb == NULL) {
-               pr_debug("skb == NULL!!!\n");
-               return NETDEV_TX_OK;
-       }
-
-       if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
-               pr_debug("network driver is closed, return\n");
-               goto err;
-       }
-
-       pipe = usb_sndbulkpipe(pFt1000Dev->dev,
-                              pFt1000Dev->bulk_out_endpointAddr);
-       maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
-
-       pdata = (u8 *)skb->data;
-
-       if (pInfo->mediastate == 0) {
-               /* Drop packet is mediastate is down */
-               pr_debug("mediastate is down\n");
-               goto err;
-       }
-
-       if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) {
-               /* Drop packet which has invalid size */
-               pr_debug("invalid ethernet length\n");
-               goto err;
-       }
-
-       ft1000_copy_down_pkt(dev, pdata + ENET_HEADER_SIZE - 2,
-                            skb->len - ENET_HEADER_SIZE + 2);
-
-err:
-       dev_kfree_skb(skb);
-
-       return NETDEV_TX_OK;
-}
-
-/* open the network driver */
-static int ft1000_open(struct net_device *dev)
-{
-       struct ft1000_info *pInfo = netdev_priv(dev);
-       struct ft1000_usb *pFt1000Dev = pInfo->priv;
-       struct timeval tv;
-
-       pr_debug("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber);
-
-       pInfo->stats.rx_bytes = 0;
-       pInfo->stats.tx_bytes = 0;
-       pInfo->stats.rx_packets = 0;
-       pInfo->stats.tx_packets = 0;
-       do_gettimeofday(&tv);
-       pInfo->ConTm = tv.tv_sec;
-       pInfo->ProgConStat = 0;
-
-       netif_start_queue(dev);
-
-       netif_carrier_on(dev);
-
-       return ft1000_submit_rx_urb(pInfo);
-}
-
-static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
-{
-       struct ft1000_info *info = netdev_priv(dev);
-
-       return &(info->stats);
-}
-
-static const struct net_device_ops ftnet_ops = {
-       .ndo_open = &ft1000_open,
-       .ndo_stop = &ft1000_close,
-       .ndo_start_xmit = &ft1000_start_xmit,
-       .ndo_get_stats = &ft1000_netdev_stats,
-};
-
-/* initialize the network device */
-static int ft1000_reset(void *dev)
-{
-       ft1000_reset_card(dev);
-       return 0;
-}
-
-int init_ft1000_netdev(struct ft1000_usb *ft1000dev)
-{
-       struct net_device *netdev;
-       struct ft1000_info *pInfo = NULL;
-       struct dpram_blk *pdpram_blk;
-       int i, ret_val;
-       struct list_head *cur, *tmp;
-       char card_nr[2];
-       u8 gCardIndex = 0;
-
-       netdev = alloc_etherdev(sizeof(struct ft1000_info));
-       if (!netdev) {
-               pr_debug("can not allocate network device\n");
-               return -ENOMEM;
-       }
-
-       pInfo = netdev_priv(netdev);
-
-       memset(pInfo, 0, sizeof(struct ft1000_info));
-
-       dev_alloc_name(netdev, netdev->name);
-
-       pr_debug("network device name is %s\n", netdev->name);
-
-       if (strncmp(netdev->name, "eth", 3) == 0) {
-               card_nr[0] = netdev->name[3];
-               card_nr[1] = '\0';
-               ret_val = kstrtou8(card_nr, 10, &gCardIndex);
-               if (ret_val) {
-                       netdev_err(ft1000dev->net, "Can't parse netdev\n");
-                       goto err_net;
-               }
-
-               ft1000dev->CardNumber = gCardIndex;
-               pr_debug("card number = %d\n", ft1000dev->CardNumber);
-       } else {
-               netdev_err(ft1000dev->net, "ft1000: Invalid device name\n");
-               ret_val = -ENXIO;
-               goto err_net;
-       }
-
-       memset(&pInfo->stats, 0, sizeof(struct net_device_stats));
-
-       spin_lock_init(&pInfo->dpram_lock);
-       pInfo->priv = ft1000dev;
-       pInfo->DrvErrNum = 0;
-       pInfo->registered = 1;
-       pInfo->ft1000_reset = ft1000_reset;
-       pInfo->mediastate = 0;
-       pInfo->fifo_cnt = 0;
-       ft1000dev->DeviceCreated = FALSE;
-       pInfo->CardReady = 0;
-       pInfo->DSP_TIME[0] = 0;
-       pInfo->DSP_TIME[1] = 0;
-       pInfo->DSP_TIME[2] = 0;
-       pInfo->DSP_TIME[3] = 0;
-       ft1000dev->fAppMsgPend = false;
-       ft1000dev->fCondResetPend = false;
-       ft1000dev->usbboot = 0;
-       ft1000dev->dspalive = 0;
-       memset(&ft1000dev->tempbuf[0], 0, sizeof(ft1000dev->tempbuf));
-
-       INIT_LIST_HEAD(&pInfo->prov_list);
-
-       INIT_LIST_HEAD(&ft1000dev->nodes.list);
-
-       netdev->netdev_ops = &ftnet_ops;
-
-       ft1000dev->net = netdev;
-
-       pr_debug("Initialize free_buff_lock and freercvpool\n");
-       spin_lock_init(&free_buff_lock);
-
-       /* initialize a list of buffers to be use for queuing
-        * up receive command data
-        */
-       INIT_LIST_HEAD(&freercvpool);
-
-       /* create list of free buffers */
-       for (i = 0; i < NUM_OF_FREE_BUFFERS; i++) {
-               /* Get memory for DPRAM_DATA link list */
-               pdpram_blk = kmalloc(sizeof(struct dpram_blk), GFP_KERNEL);
-               if (pdpram_blk == NULL) {
-                       ret_val = -ENOMEM;
-                       goto err_free;
-               }
-               /* Get a block of memory to store command data */
-               pdpram_blk->pbuffer = kmalloc(MAX_CMD_SQSIZE, GFP_KERNEL);
-               if (pdpram_blk->pbuffer == NULL) {
-                       ret_val = -ENOMEM;
-                       kfree(pdpram_blk);
-                       goto err_free;
-               }
-               /* link provisioning data */
-               list_add_tail(&pdpram_blk->list, &freercvpool);
-       }
-       numofmsgbuf = NUM_OF_FREE_BUFFERS;
-
-       return 0;
-
-err_free:
-       list_for_each_safe(cur, tmp, &freercvpool) {
-               pdpram_blk = list_entry(cur, struct dpram_blk, list);
-               list_del(&pdpram_blk->list);
-               kfree(pdpram_blk->pbuffer);
-               kfree(pdpram_blk);
-       }
-err_net:
-       free_netdev(netdev);
-       return ret_val;
-}
-
-/* register the network driver */
-int reg_ft1000_netdev(struct ft1000_usb *ft1000dev,
-                     struct usb_interface *intf)
-{
-       struct net_device *netdev;
-       struct ft1000_info *pInfo;
-       int rc;
-
-       netdev = ft1000dev->net;
-       pInfo = netdev_priv(ft1000dev->net);
-
-       ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
-
-       usb_set_intfdata(intf, pInfo);
-       SET_NETDEV_DEV(netdev, &intf->dev);
-
-       rc = register_netdev(netdev);
-       if (rc) {
-               pr_debug("could not register network device\n");
-               free_netdev(netdev);
-               return rc;
-       }
-
-       ft1000_create_dev(ft1000dev);
-
-       pInfo->CardReady = 1;
-
-       return 0;
-}
-
-/* take a packet from the FIFO up link and
- *  convert it into an ethernet packet and deliver it to the IP stack
- */
-static int ft1000_copy_up_pkt(struct urb *urb)
-{
-       struct ft1000_info *info = urb->context;
-       struct ft1000_usb *ft1000dev = info->priv;
-       struct net_device *net = ft1000dev->net;
-
-       u16 tempword;
-       u16 len;
-       u16 lena;
-       struct sk_buff *skb;
-       u16 i;
-       u8 *pbuffer = NULL;
-       u8 *ptemp = NULL;
-       u16 *chksum;
-
-       if (ft1000dev->status & FT1000_STATUS_CLOSING) {
-               pr_debug("network driver is closed, return\n");
-               return 0;
-       }
-       /* Read length */
-       len = urb->transfer_buffer_length;
-       lena = urb->actual_length;
-
-       chksum = (u16 *)ft1000dev->rx_buf;
-
-       tempword = *chksum++;
-       for (i = 1; i < 7; i++)
-               tempword ^= *chksum++;
-
-       if (tempword != *chksum) {
-               info->stats.rx_errors++;
-               ft1000_submit_rx_urb(info);
-               return -1;
-       }
-
-       skb = dev_alloc_skb(len + 12 + 2);
-
-       if (skb == NULL) {
-               info->stats.rx_errors++;
-               ft1000_submit_rx_urb(info);
-               return -1;
-       }
-
-       pbuffer = (u8 *)skb_put(skb, len + 12);
-
-       /* subtract the number of bytes read already */
-       ptemp = pbuffer;
-
-       /* fake MAC address */
-       *pbuffer++ = net->dev_addr[0];
-       *pbuffer++ = net->dev_addr[1];
-       *pbuffer++ = net->dev_addr[2];
-       *pbuffer++ = net->dev_addr[3];
-       *pbuffer++ = net->dev_addr[4];
-       *pbuffer++ = net->dev_addr[5];
-       *pbuffer++ = 0x00;
-       *pbuffer++ = 0x07;
-       *pbuffer++ = 0x35;
-       *pbuffer++ = 0xff;
-       *pbuffer++ = 0xff;
-       *pbuffer++ = 0xfe;
-
-       memcpy(pbuffer, ft1000dev->rx_buf + sizeof(struct pseudo_hdr),
-              len - sizeof(struct pseudo_hdr));
-
-       skb->dev = net;
-
-       skb->protocol = eth_type_trans(skb, net);
-       skb->ip_summed = CHECKSUM_UNNECESSARY;
-       netif_rx(skb);
-
-       info->stats.rx_packets++;
-       /* Add on 12 bytes for MAC address which was removed */
-       info->stats.rx_bytes += (lena + 12);
-
-       ft1000_submit_rx_urb(info);
-
-       return 0;
-}
-
-
-/* the receiving function of the network driver */
-static int ft1000_submit_rx_urb(struct ft1000_info *info)
-{
-       int result;
-       struct ft1000_usb *pFt1000Dev = info->priv;
-
-       if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
-               pr_debug("network driver is closed, return\n");
-               return -ENODEV;
-       }
-
-       usb_fill_bulk_urb(pFt1000Dev->rx_urb,
-                         pFt1000Dev->dev,
-                         usb_rcvbulkpipe(pFt1000Dev->dev,
-                                         pFt1000Dev->bulk_in_endpointAddr),
-                         pFt1000Dev->rx_buf, MAX_BUF_SIZE,
-                         (usb_complete_t)ft1000_copy_up_pkt, info);
-
-       result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC);
-
-       if (result) {
-               pr_err("submitting rx_urb %d failed\n", result);
-               return result;
-       }
-
-       return 0;
-}
-
-/* close the network driver */
-int ft1000_close(struct net_device *net)
-{
-       struct ft1000_info *pInfo = netdev_priv(net);
-       struct ft1000_usb *ft1000dev = pInfo->priv;
-
-       ft1000dev->status |= FT1000_STATUS_CLOSING;
-
-       pr_debug("pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
-       netif_carrier_off(net);
-       netif_stop_queue(net);
-       ft1000dev->status &= ~FT1000_STATUS_CLOSING;
-
-       pInfo->ProgConStat = 0xff;
-
-       return 0;
-}
-
-/* check if the device is presently available on the system. */
-static int ft1000_chkcard(struct ft1000_usb *dev)
-{
-       u16 tempword;
-       int status;
-
-       if (dev->fCondResetPend) {
-               pr_debug("Card is being reset, return FALSE\n");
-               return TRUE;
-       }
-       /* Mask register is used to check for device presence since it is never
-        * set to zero.
-        */
-       status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
-       if (tempword == 0) {
-               pr_debug("IMASK = 0 Card not detected\n");
-               return FALSE;
-       }
-       /* The system will return the value of 0xffff for the version register
-        * if the device is not present.
-        */
-       status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
-       if (tempword != 0x1b01) {
-               dev->status |= FT1000_STATUS_CLOSING;
-               pr_debug("Version = 0xffff Card not detected\n");
-               return FALSE;
-       }
-       return TRUE;
-}
-
-/* read a message from the dpram area.
- *  Input:
- *    dev - network device structure
- *    pbuffer - caller supply address to buffer
- */
-static bool ft1000_receive_cmd(struct ft1000_usb *dev, u16 *pbuffer,
-                              int maxsz)
-{
-       u16 size;
-       int ret;
-       u16 *ppseudohdr;
-       int i;
-       u16 tempword;
-
-       ret =
-               ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (u8 *)&size,
-                                   FT1000_MAG_PH_LEN_INDX);
-       size = ntohs(size) + PSEUDOSZ;
-       if (size > maxsz) {
-               pr_debug("Invalid command length = %d\n", size);
-               return FALSE;
-       }
-       ppseudohdr = (u16 *)pbuffer;
-       ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE,
-                             FT1000_REG_DPRAM_ADDR);
-       ret =
-               ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
-       pbuffer++;
-       ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE + 1,
-                             FT1000_REG_DPRAM_ADDR);
-       for (i = 0; i <= (size >> 2); i++) {
-               ret =
-                       ft1000_read_register(dev, pbuffer,
-                                            FT1000_REG_MAG_DPDATAL);
-               pbuffer++;
-               ret =
-                       ft1000_read_register(dev, pbuffer,
-                                            FT1000_REG_MAG_DPDATAH);
-               pbuffer++;
-       }
-       /* copy odd aligned word */
-       ret =
-               ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
-
-       pbuffer++;
-       ret =
-               ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
-
-       pbuffer++;
-       if (size & 0x0001) {
-               /* copy odd byte from fifo */
-               ret =
-                       ft1000_read_register(dev, &tempword,
-                                            FT1000_REG_DPRAM_DATA);
-               *pbuffer = ntohs(tempword);
-       }
-       /* Check if pseudo header checksum is good
-        * Calculate pseudo header checksum
-        */
-       tempword = *ppseudohdr++;
-       for (i = 1; i < 7; i++)
-               tempword ^= *ppseudohdr++;
-
-       if (tempword != *ppseudohdr)
-               return FALSE;
-
-       return TRUE;
-}
-
-static int ft1000_dsp_prov(void *arg)
-{
-       struct ft1000_usb *dev = (struct ft1000_usb *)arg;
-       struct ft1000_info *info = netdev_priv(dev->net);
-       u16 tempword;
-       u16 len;
-       u16 i = 0;
-       struct prov_record *ptr;
-       struct pseudo_hdr *ppseudo_hdr;
-       u16 *pmsg;
-       int status;
-       u16 TempShortBuf[256];
-
-       while (list_empty(&info->prov_list) == 0) {
-               pr_debug("DSP Provisioning List Entry\n");
-
-               /* Check if doorbell is available */
-               pr_debug("check if doorbell is cleared\n");
-               status = ft1000_read_register(dev, &tempword,
-                                             FT1000_REG_DOORBELL);
-               if (status) {
-                       pr_debug("ft1000_read_register error\n");
-                       break;
-               }
-
-               while (tempword & FT1000_DB_DPRAM_TX) {
-                       mdelay(10);
-                       i++;
-                       if (i == 10) {
-                               pr_debug("message drop\n");
-                               return -1;
-                       }
-                       ft1000_read_register(dev, &tempword,
-                                            FT1000_REG_DOORBELL);
-               }
-
-               if (!(tempword & FT1000_DB_DPRAM_TX)) {
-                       pr_debug("*** Provision Data Sent to DSP\n");
-
-                       /* Send provisioning data */
-                       ptr = list_entry(info->prov_list.next,
-                                        struct prov_record, list);
-                       len = *(u16 *)ptr->pprov_data;
-                       len = htons(len);
-                       len += PSEUDOSZ;
-
-                       pmsg = (u16 *)ptr->pprov_data;
-                       ppseudo_hdr = (struct pseudo_hdr *)pmsg;
-                       /* Insert slow queue sequence number */
-                       ppseudo_hdr->seq_num = info->squeseqnum++;
-                       ppseudo_hdr->portsrc = 0;
-                       /* Calculate new checksum */
-                       ppseudo_hdr->checksum = *pmsg++;
-                       for (i = 1; i < 7; i++)
-                               ppseudo_hdr->checksum ^= *pmsg++;
-
-                       TempShortBuf[0] = 0;
-                       TempShortBuf[1] = htons(len);
-                       memcpy(&TempShortBuf[2], ppseudo_hdr, len);
-
-                       status =
-                               ft1000_write_dpram32(dev, 0,
-                                                    (u8 *)&TempShortBuf[0],
-                                                    (unsigned short)(len + 2));
-                       status =
-                               ft1000_write_register(dev, FT1000_DB_DPRAM_TX,
-                                                     FT1000_REG_DOORBELL);
-
-                       list_del(&ptr->list);
-                       kfree(ptr->pprov_data);
-                       kfree(ptr);
-               }
-               usleep_range(9000, 11000);
-       }
-
-       pr_debug("DSP Provisioning List Entry finished\n");
-
-       msleep(100);
-
-       dev->fProvComplete = true;
-       info->CardReady = 1;
-
-       return 0;
-}
-
-static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
-{
-       struct ft1000_info *info = netdev_priv(dev->net);
-       u16 msgtype;
-       u16 tempword;
-       struct media_msg *pmediamsg;
-       struct dsp_init_msg *pdspinitmsg;
-       struct drv_msg *pdrvmsg;
-       u16 i;
-       struct pseudo_hdr *ppseudo_hdr;
-       u16 *pmsg;
-       int status;
-       union {
-               u8 byte[2];
-               u16 wrd;
-       } convert;
-
-       char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
-
-       if (!cmdbuffer)
-               return -ENOMEM;
-
-       status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
-
-#ifdef JDEBUG
-       print_hex_dump_debug("cmdbuffer: ", HEX_DUMP_OFFSET, 16, 1,
-                            cmdbuffer, size, true);
-#endif
-       pdrvmsg = (struct drv_msg *)&cmdbuffer[2];
-       msgtype = ntohs(pdrvmsg->type);
-       pr_debug("Command message type = 0x%x\n", msgtype);
-       switch (msgtype) {
-       case MEDIA_STATE:{
-               pr_debug("Command message type = MEDIA_STATE\n");
-               pmediamsg = (struct media_msg *)&cmdbuffer[0];
-               if (info->ProgConStat != 0xFF) {
-                       if (pmediamsg->state) {
-                               pr_debug("Media is up\n");
-                               if (info->mediastate == 0) {
-                                       if (dev->NetDevRegDone)
-                                               netif_wake_queue(dev->net);
-                                       info->mediastate = 1;
-                               }
-                       } else {
-                               pr_debug("Media is down\n");
-                               if (info->mediastate == 1) {
-                                       info->mediastate = 0;
-                                       if (dev->NetDevRegDone)
-                                               info->ConTm = 0;
-                               }
-                       }
-               } else {
-                       pr_debug("Media is down\n");
-                       if (info->mediastate == 1) {
-                               info->mediastate = 0;
-                               info->ConTm = 0;
-                       }
-               }
-               break;
-       }
-       case DSP_INIT_MSG:{
-               pr_debug("Command message type = DSP_INIT_MSG\n");
-               pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[2];
-               memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
-               pr_debug("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n",
-                        info->DspVer[0], info->DspVer[1], info->DspVer[2],
-                        info->DspVer[3]);
-               memcpy(info->HwSerNum, pdspinitmsg->HwSerNum,
-                      HWSERNUMSZ);
-               memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
-               memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
-               pr_debug("EUI64=%2x.%2x.%2x.%2x.%2x.%2x.%2x.%2x\n",
-                        info->eui64[0], info->eui64[1], info->eui64[2],
-                        info->eui64[3], info->eui64[4], info->eui64[5],
-                        info->eui64[6], info->eui64[7]);
-               dev->net->dev_addr[0] = info->eui64[0];
-               dev->net->dev_addr[1] = info->eui64[1];
-               dev->net->dev_addr[2] = info->eui64[2];
-               dev->net->dev_addr[3] = info->eui64[5];
-               dev->net->dev_addr[4] = info->eui64[6];
-               dev->net->dev_addr[5] = info->eui64[7];
-
-               if (ntohs(pdspinitmsg->length) ==
-                   (sizeof(struct dsp_init_msg) - 20)) {
-                       memcpy(info->ProductMode, pdspinitmsg->ProductMode,
-                              MODESZ);
-                       memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
-                       memcpy(info->RfCalDate, pdspinitmsg->RfCalDate,
-                              CALDATESZ);
-                       pr_debug("RFCalVer = 0x%2x 0x%2x\n",
-                                info->RfCalVer[0], info->RfCalVer[1]);
-               }
-               break;
-       }
-       case DSP_PROVISION:{
-               pr_debug("Command message type = DSP_PROVISION\n");
-
-               /* kick off dspprov routine to start provisioning
-                * Send provisioning data to DSP
-                */
-               if (list_empty(&info->prov_list) == 0) {
-                       dev->fProvComplete = false;
-                       status = ft1000_dsp_prov(dev);
-                       if (status != 0)
-                               goto out;
-               } else {
-                       dev->fProvComplete = true;
-                       status = ft1000_write_register(dev, FT1000_DB_HB,
-                                                      FT1000_REG_DOORBELL);
-                       pr_debug("No more DSP provisioning data in dsp image\n");
-               }
-               pr_debug("DSP PROVISION is done\n");
-               break;
-       }
-       case DSP_STORE_INFO:{
-               pr_debug("Command message type = DSP_STORE_INFO");
-               tempword = ntohs(pdrvmsg->length);
-               info->DSPInfoBlklen = tempword;
-               if (tempword < (MAX_DSP_SESS_REC - 4)) {
-                       pmsg = (u16 *)&pdrvmsg->data[0];
-                       for (i = 0; i < ((tempword + 1) / 2); i++) {
-                               pr_debug("dsp info data = 0x%x\n", *pmsg);
-                               info->DSPInfoBlk[i + 10] = *pmsg++;
-                       }
-               } else {
-                       info->DSPInfoBlklen = 0;
-               }
-               break;
-       }
-       case DSP_GET_INFO:{
-               pr_debug("Got DSP_GET_INFO\n");
-               /* copy dsp info block to dsp */
-               dev->DrvMsgPend = 1;
-               /* allow any outstanding ioctl to finish */
-               mdelay(10);
-               status = ft1000_read_register(dev, &tempword,
-                                             FT1000_REG_DOORBELL);
-               if (tempword & FT1000_DB_DPRAM_TX) {
-                       mdelay(10);
-                       status = ft1000_read_register(dev, &tempword,
-                                                     FT1000_REG_DOORBELL);
-                       if (tempword & FT1000_DB_DPRAM_TX) {
-                               mdelay(10);
-                               status = ft1000_read_register(dev, &tempword,
-                                                       FT1000_REG_DOORBELL);
-                               if (tempword & FT1000_DB_DPRAM_TX)
-                                       break;
-                       }
-               }
-               /* Put message into Slow Queue Form Pseudo header */
-               pmsg = (u16 *)info->DSPInfoBlk;
-               *pmsg++ = 0;
-               *pmsg++ = htons(info->DSPInfoBlklen + 20 + info->DSPInfoBlklen);
-               ppseudo_hdr =
-                       (struct pseudo_hdr *)(u16 *)&info->DSPInfoBlk[2];
-               ppseudo_hdr->length = htons(info->DSPInfoBlklen + 4
-                                           + info->DSPInfoBlklen);
-               ppseudo_hdr->source = 0x10;
-               ppseudo_hdr->destination = 0x20;
-               ppseudo_hdr->portdest = 0;
-               ppseudo_hdr->portsrc = 0;
-               ppseudo_hdr->sh_str_id = 0;
-               ppseudo_hdr->control = 0;
-               ppseudo_hdr->rsvd1 = 0;
-               ppseudo_hdr->rsvd2 = 0;
-               ppseudo_hdr->qos_class = 0;
-               /* Insert slow queue sequence number */
-               ppseudo_hdr->seq_num = info->squeseqnum++;
-               /* Insert application id */
-               ppseudo_hdr->portsrc = 0;
-               /* Calculate new checksum */
-               ppseudo_hdr->checksum = *pmsg++;
-               for (i = 1; i < 7; i++)
-                       ppseudo_hdr->checksum ^= *pmsg++;
-
-               info->DSPInfoBlk[10] = 0x7200;
-               info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
-               status = ft1000_write_dpram32(dev, 0,
-                               (u8 *)&info->DSPInfoBlk[0],
-                               (unsigned short)(info->DSPInfoBlklen + 22));
-               status = ft1000_write_register(dev, FT1000_DB_DPRAM_TX,
-                                              FT1000_REG_DOORBELL);
-               dev->DrvMsgPend = 0;
-               break;
-       }
-       case GET_DRV_ERR_RPT_MSG:{
-               pr_debug("Got GET_DRV_ERR_RPT_MSG\n");
-               /* copy driver error message to dsp */
-               dev->DrvMsgPend = 1;
-               /* allow any outstanding ioctl to finish */
-               mdelay(10);
-               status = ft1000_read_register(dev, &tempword,
-                                             FT1000_REG_DOORBELL);
-               if (tempword & FT1000_DB_DPRAM_TX) {
-                       mdelay(10);
-                       status = ft1000_read_register(dev, &tempword,
-                                                     FT1000_REG_DOORBELL);
-                       if (tempword & FT1000_DB_DPRAM_TX)
-                               mdelay(10);
-               }
-               if ((tempword & FT1000_DB_DPRAM_TX) == 0) {
-                       /* Put message into Slow Queue Form Pseudo header */
-                       pmsg = (u16 *)&tempbuffer[0];
-                       ppseudo_hdr = (struct pseudo_hdr *)pmsg;
-                       ppseudo_hdr->length = htons(0x0012);
-                       ppseudo_hdr->source = 0x10;
-                       ppseudo_hdr->destination = 0x20;
-                       ppseudo_hdr->portdest = 0;
-                       ppseudo_hdr->portsrc = 0;
-                       ppseudo_hdr->sh_str_id = 0;
-                       ppseudo_hdr->control = 0;
-                       ppseudo_hdr->rsvd1 = 0;
-                       ppseudo_hdr->rsvd2 = 0;
-                       ppseudo_hdr->qos_class = 0;
-                       /* Insert slow queue sequence number */
-                       ppseudo_hdr->seq_num = info->squeseqnum++;
-                       /* Insert application id */
-                       ppseudo_hdr->portsrc = 0;
-                       /* Calculate new checksum */
-                       ppseudo_hdr->checksum = *pmsg++;
-                       for (i = 1; i < 7; i++)
-                               ppseudo_hdr->checksum ^= *pmsg++;
-
-                       pmsg = (u16 *)&tempbuffer[16];
-                       *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
-                       *pmsg++ = htons(0x000e);
-                       *pmsg++ = htons(info->DSP_TIME[0]);
-                       *pmsg++ = htons(info->DSP_TIME[1]);
-                       *pmsg++ = htons(info->DSP_TIME[2]);
-                       *pmsg++ = htons(info->DSP_TIME[3]);
-                       convert.byte[0] = info->DspVer[0];
-                       convert.byte[1] = info->DspVer[1];
-                       *pmsg++ = convert.wrd;
-                       convert.byte[0] = info->DspVer[2];
-                       convert.byte[1] = info->DspVer[3];
-                       *pmsg++ = convert.wrd;
-                       *pmsg++ = htons(info->DrvErrNum);
-
-                       status = card_send_command(dev,
-                                       (unsigned char *)&tempbuffer[0],
-                                       (u16)(0x0012 + PSEUDOSZ));
-                       if (status)
-                               goto out;
-                       info->DrvErrNum = 0;
-               }
-               dev->DrvMsgPend = 0;
-               break;
-       }
-       default:
-               break;
-       }
-
-       status = 0;
-out:
-       kfree(cmdbuffer);
-       return status;
-}
-
-/* Check which application has registered for dsp broadcast messages */
-static int dsp_broadcast_msg_id(struct ft1000_usb *dev)
-{
-       struct dpram_blk *pdpram_blk;
-       unsigned long flags;
-       int i;
-
-       for (i = 0; i < MAX_NUM_APP; i++) {
-               if ((dev->app_info[i].DspBCMsgFlag)
-                   && (dev->app_info[i].fileobject)
-                   && (dev->app_info[i].NumOfMsg
-                       < MAX_MSG_LIMIT)) {
-                       pdpram_blk = ft1000_get_buffer(&freercvpool);
-                       if (pdpram_blk == NULL) {
-                               pr_debug("Out of memory in free receive command pool\n");
-                               dev->app_info[i].nRxMsgMiss++;
-                               return -1;
-                       }
-                       if (ft1000_receive_cmd(dev, pdpram_blk->pbuffer,
-                                              MAX_CMD_SQSIZE)) {
-                               /* Put message into the
-                                * appropriate application block
-                                */
-                               dev->app_info[i].nRxMsg++;
-                               spin_lock_irqsave(&free_buff_lock, flags);
-                               list_add_tail(&pdpram_blk->list,
-                                             &dev->app_info[i] .app_sqlist);
-                               dev->app_info[i].NumOfMsg++;
-                               spin_unlock_irqrestore(&free_buff_lock, flags);
-                               wake_up_interruptible(&dev->app_info[i]
-                                                     .wait_dpram_msg);
-                       } else {
-                               dev->app_info[i].nRxMsgMiss++;
-                               ft1000_free_buffer(pdpram_blk, &freercvpool);
-                               pr_debug("ft1000_get_buffer NULL\n");
-                               return -1;
-                       }
-               }
-       }
-       return 0;
-}
-
-static int handle_misc_portid(struct ft1000_usb *dev)
-{
-       struct dpram_blk *pdpram_blk;
-       int i;
-
-       pdpram_blk = ft1000_get_buffer(&freercvpool);
-       if (pdpram_blk == NULL) {
-               pr_debug("Out of memory in free receive command pool\n");
-               return -1;
-       }
-       if (!ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE))
-               goto exit_failure;
-
-       /* Search for correct application block */
-       for (i = 0; i < MAX_NUM_APP; i++) {
-               if (dev->app_info[i].app_id == ((struct pseudo_hdr *)
-                                               pdpram_blk->pbuffer)->portdest)
-                       break;
-       }
-       if (i == MAX_NUM_APP) {
-               pr_debug("No application matching id = %d\n",
-                        ((struct pseudo_hdr *)pdpram_blk->pbuffer)->portdest);
-               goto exit_failure;
-       } else if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
-               goto exit_failure;
-       } else {
-               dev->app_info[i].nRxMsg++;
-               /* Put message into the appropriate application block */
-               list_add_tail(&pdpram_blk->list, &dev->app_info[i].app_sqlist);
-               dev->app_info[i].NumOfMsg++;
-       }
-       return 0;
-
-exit_failure:
-       ft1000_free_buffer(pdpram_blk, &freercvpool);
-       return -1;
-}
-
-int ft1000_poll(void *dev_id)
-{
-       struct ft1000_usb *dev = (struct ft1000_usb *)dev_id;
-       struct ft1000_info *info = netdev_priv(dev->net);
-       u16 tempword;
-       int status;
-       u16 size;
-       int i;
-       u16 data;
-       u16 modulo;
-       u16 portid;
-
-       if (ft1000_chkcard(dev) == FALSE) {
-               pr_debug("failed\n");
-               return -1;
-       }
-       status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
-       if (!status) {
-               if (tempword & FT1000_DB_DPRAM_RX) {
-                       status = ft1000_read_dpram16(dev,
-                                                    0x200, (u8 *)&data, 0);
-                       size = ntohs(data) + 16 + 2;
-                       if (size % 4) {
-                               modulo = 4 - (size % 4);
-                               size = size + modulo;
-                       }
-                       status = ft1000_read_dpram16(dev, 0x201,
-                                                    (u8 *)&portid, 1);
-                       portid &= 0xff;
-                       if (size < MAX_CMD_SQSIZE) {
-                               switch (portid) {
-                               case DRIVERID:
-                                       pr_debug("FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
-                                       status = ft1000_proc_drvmsg(dev, size);
-                                       if (status != 0)
-                                               return status;
-                                       break;
-                               case DSPBCMSGID:
-                                       status = dsp_broadcast_msg_id(dev);
-                                       break;
-                               default:
-                                       status = handle_misc_portid(dev);
-                                       break;
-                               }
-                       } else
-                               pr_debug("Invalid total length for SlowQ = %d\n",
-                                        size);
-                       status = ft1000_write_register(dev,
-                                                      FT1000_DB_DPRAM_RX,
-                                                      FT1000_REG_DOORBELL);
-               } else if (tempword & FT1000_DSP_ASIC_RESET) {
-                       /* Let's reset the ASIC from the Host side as well */
-                       status = ft1000_write_register(dev, ASIC_RESET_BIT,
-                                                      FT1000_REG_RESET);
-                       status = ft1000_read_register(dev, &tempword,
-                                                     FT1000_REG_RESET);
-                       i = 0;
-                       while (tempword & ASIC_RESET_BIT) {
-                               status = ft1000_read_register(dev, &tempword,
-                                                             FT1000_REG_RESET);
-                               usleep_range(9000, 11000);
-                               i++;
-                               if (i == 100)
-                                       break;
-                       }
-                       if (i == 100) {
-                               pr_debug("Unable to reset ASIC\n");
-                               return 0;
-                       }
-                       usleep_range(9000, 11000);
-                       /* Program WMARK register */
-                       status = ft1000_write_register(dev, 0x600,
-                                              FT1000_REG_MAG_WATERMARK);
-                       /* clear ASIC reset doorbell */
-                       status = ft1000_write_register(dev,
-                                                      FT1000_DSP_ASIC_RESET,
-                                                      FT1000_REG_DOORBELL);
-                       usleep_range(9000, 11000);
-               } else if (tempword & FT1000_ASIC_RESET_REQ) {
-                       pr_debug("FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
-                       /* clear ASIC reset request from DSP */
-                       status = ft1000_write_register(dev,
-                                                      FT1000_ASIC_RESET_REQ,
-                                                      FT1000_REG_DOORBELL);
-                       status = ft1000_write_register(dev, HOST_INTF_BE,
-                                                      FT1000_REG_SUP_CTRL);
-                       /* copy dsp session record from Adapter block */
-                       status = ft1000_write_dpram32(dev, 0,
-                                     (u8 *)&info->DSPSess.Rec[0], 1024);
-                       status = ft1000_write_register(dev, 0x600,
-                                              FT1000_REG_MAG_WATERMARK);
-                       /* ring doorbell to tell DSP that
-                        * ASIC is out of reset
-                        * */
-                       status = ft1000_write_register(dev,
-                                                      FT1000_ASIC_RESET_DSP,
-                                                      FT1000_REG_DOORBELL);
-               } else if (tempword & FT1000_DB_COND_RESET) {
-                       pr_debug("FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
-                       if (!dev->fAppMsgPend) {
-                               /* Reset ASIC and DSP */
-                               status = ft1000_read_dpram16(dev,
-                                               FT1000_MAG_DSP_TIMER0,
-                                               (u8 *)&info->DSP_TIME[0],
-                                               FT1000_MAG_DSP_TIMER0_INDX);
-                               status = ft1000_read_dpram16(dev,
-                                               FT1000_MAG_DSP_TIMER1,
-                                               (u8 *)&info->DSP_TIME[1],
-                                               FT1000_MAG_DSP_TIMER1_INDX);
-                               status = ft1000_read_dpram16(dev,
-                                               FT1000_MAG_DSP_TIMER2,
-                                               (u8 *)&info->DSP_TIME[2],
-                                               FT1000_MAG_DSP_TIMER2_INDX);
-                               status = ft1000_read_dpram16(dev,
-                                               FT1000_MAG_DSP_TIMER3,
-                                               (u8 *)&info->DSP_TIME[3],
-                                               FT1000_MAG_DSP_TIMER3_INDX);
-                               info->CardReady = 0;
-                               info->DrvErrNum = DSP_CONDRESET_INFO;
-                               pr_debug("DSP conditional reset requested\n");
-                               info->ft1000_reset(dev->net);
-                       } else {
-                               dev->fProvComplete = false;
-                               dev->fCondResetPend = true;
-                       }
-                       ft1000_write_register(dev, FT1000_DB_COND_RESET,
-                                             FT1000_REG_DOORBELL);
-               }
-       }
-       return 0;
-}
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h b/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h
deleted file mode 100644 (file)
index e9472be..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- *---------------------------------------------------------------------------
- * FT1000 driver for Flarion Flash OFDM NIC Device
- *
- * Copyright (C) 2002 Flarion Technologies, All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option) any
- * later version. This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details. You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place -
- * Suite 330, Boston, MA 02111-1307, USA.
- *---------------------------------------------------------------------------
- *
- * File:         ft1000_ioctl.h
- *
- * Description:    Common structures and defines relating to IOCTL
- *
- * History:
- * 11/5/02    Whc                Created.
- *
- *---------------------------------------------------------------------------
- */
-#ifndef _FT1000IOCTLH_
-#define _FT1000IOCTLH_
-
-struct IOCTL_GET_VER {
-       unsigned long drv_ver;
-} __packed;
-
-/* Data structure for Dsp statistics */
-struct IOCTL_GET_DSP_STAT {
-       unsigned char DspVer[DSPVERSZ];        /* DSP version number */
-       unsigned char HwSerNum[HWSERNUMSZ];    /* Hardware Serial Number */
-       unsigned char Sku[SKUSZ];              /* SKU */
-       unsigned char eui64[EUISZ];            /* EUI64 */
-       unsigned short ConStat;                /* Connection Status */
-       /*    Bits 0-3 = Connection Status Field */
-       /*               0000=Idle (Disconnect) */
-       /*               0001=Searching */
-       /*               0010=Active (Connected) */
-       /*               0011=Waiting for L2 down */
-       /*               0100=Sleep */
-       unsigned short LedStat;                /* Led Status */
-       /*    Bits 0-3   = Signal Strength Field */
-       /*                 0000 = -105dBm to -92dBm */
-       /*                 0001 = -92dBm to -85dBm */
-       /*                 0011 = -85dBm to -75dBm */
-       /*                 0111 = -75dBm to -50dBm */
-       /*                 1111 = -50dBm to 0dBm */
-       /*    Bits 4-7   = Reserved */
-       /*    Bits 8-11  = SNR Field */
-       /*                 0000 = <2dB */
-       /*                 0001 = 2dB to 8dB */
-       /*                 0011 = 8dB to 15dB */
-       /*                 0111 = 15dB to 22dB */
-       /*                 1111 = >22dB */
-       /*    Bits 12-15 = Reserved */
-       unsigned long nTxPkts;                /* Number of packets transmitted
-                                              * from host to dsp
-                                              */
-       unsigned long nRxPkts;                /* Number of packets received from
-                                              * dsp to host
-                                              */
-       unsigned long nTxBytes;               /* Number of bytes transmitted
-                                              * from host to dsp
-                                              */
-       unsigned long nRxBytes;               /* Number of bytes received from
-                                              * dsp to host
-                                              */
-       unsigned long ConTm;                  /* Current session connection time
-                                              * in seconds
-                                              */
-       unsigned char CalVer[CALVERSZ];       /* Proprietary Calibration
-                                              * Version
-                                              */
-       unsigned char CalDate[CALDATESZ];     /* Proprietary Calibration Date */
-} __packed;
-
-/* Data structure for Dual Ported RAM messaging between Host and Dsp */
-struct IOCTL_DPRAM_BLK {
-       unsigned short total_len;
-       struct pseudo_hdr pseudohdr;
-       unsigned char buffer[1780];
-} __packed;
-
-struct IOCTL_DPRAM_COMMAND {
-       unsigned short extra;
-       struct IOCTL_DPRAM_BLK dpram_blk;
-} __packed;
-
-/*
- * Custom IOCTL command codes
- */
-#define FT1000_MAGIC_CODE      'F'
-
-#define IOCTL_REGISTER_CMD     0
-#define IOCTL_SET_DPRAM_CMD    3
-#define IOCTL_GET_DPRAM_CMD    4
-#define IOCTL_GET_DSP_STAT_CMD 6
-#define IOCTL_GET_VER_CMD      7
-#define IOCTL_CONNECT          10
-#define IOCTL_DISCONNECT       11
-
-#define IOCTL_FT1000_GET_DSP_STAT _IOR(FT1000_MAGIC_CODE,              \
-                                      IOCTL_GET_DSP_STAT_CMD,          \
-                                      struct IOCTL_GET_DSP_STAT)
-#define IOCTL_FT1000_GET_VER _IOR(FT1000_MAGIC_CODE, IOCTL_GET_VER_CMD, \
-                                 struct IOCTL_GET_VER)
-#define IOCTL_FT1000_CONNECT _IO(FT1000_MAGIC_CODE, IOCTL_CONNECT)
-#define IOCTL_FT1000_DISCONNECT _IO(FT1000_MAGIC_CODE, IOCTL_DISCONNECT)
-#define IOCTL_FT1000_SET_DPRAM _IOW(FT1000_MAGIC_CODE, IOCTL_SET_DPRAM_CMD, \
-                                   struct IOCTL_DPRAM_BLK)
-#define IOCTL_FT1000_GET_DPRAM _IOR(FT1000_MAGIC_CODE, IOCTL_GET_DPRAM_CMD, \
-                                   struct IOCTL_DPRAM_BLK)
-#define IOCTL_FT1000_REGISTER  _IOW(FT1000_MAGIC_CODE, IOCTL_REGISTER_CMD, \
-                                   unsigned short *)
-
-#endif /* _FT1000IOCTLH_ */
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
deleted file mode 100644 (file)
index fd255c6..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-/*=====================================================
- * CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
- *
- *
- * This file is part of Express Card USB Driver
- *====================================================
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/usb.h>
-#include <linux/netdevice.h>
-#include <linux/etherdevice.h>
-#include <linux/firmware.h>
-#include "ft1000_usb.h"
-
-#include <linux/kthread.h>
-
-MODULE_DESCRIPTION("FT1000 EXPRESS CARD DRIVER");
-MODULE_LICENSE("Dual MPL/GPL");
-MODULE_SUPPORTED_DEVICE("QFT FT1000 Express Cards");
-
-void *pFileStart;
-size_t FileLength;
-
-#define VENDOR_ID 0x1291       /* Qualcomm vendor id */
-#define PRODUCT_ID 0x11                /* fake product id */
-
-/* table of devices that work with this driver */
-static struct usb_device_id id_table[] = {
-       {USB_DEVICE(VENDOR_ID, PRODUCT_ID)},
-       {},
-};
-
-MODULE_DEVICE_TABLE(usb, id_table);
-
-static bool gPollingfailed;
-static int ft1000_poll_thread(void *arg)
-{
-       int ret;
-
-       while (!kthread_should_stop()) {
-               usleep_range(10000, 11000);
-               if (!gPollingfailed) {
-                       ret = ft1000_poll(arg);
-                       if (ret != 0) {
-                               pr_debug("polling failed\n");
-                               gPollingfailed = true;
-                       }
-               }
-       }
-       return 0;
-}
-
-static int ft1000_probe(struct usb_interface *interface,
-                       const struct usb_device_id *id)
-{
-       struct usb_host_interface *iface_desc;
-       struct usb_endpoint_descriptor *endpoint;
-       struct usb_device *dev;
-       unsigned numaltsetting;
-       int i, ret = 0, size;
-
-       struct ft1000_usb *ft1000dev;
-       struct ft1000_info *pft1000info = NULL;
-       const struct firmware *dsp_fw;
-
-       ft1000dev = kzalloc(sizeof(struct ft1000_usb), GFP_KERNEL);
-       if (!ft1000dev)
-               return -ENOMEM;
-
-       dev = interface_to_usbdev(interface);
-       pr_debug("usb device descriptor info - number of configuration is %d\n",
-                dev->descriptor.bNumConfigurations);
-
-       ft1000dev->dev = dev;
-       ft1000dev->status = 0;
-       ft1000dev->net = NULL;
-       ft1000dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
-       ft1000dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
-       if (!ft1000dev->tx_urb || !ft1000dev->rx_urb) {
-               ret = -ENOMEM;
-               goto err_fw;
-       }
-
-       numaltsetting = interface->num_altsetting;
-       pr_debug("number of alt settings is: %d\n", numaltsetting);
-       iface_desc = interface->cur_altsetting;
-       pr_debug("number of endpoints is: %d\n",
-                iface_desc->desc.bNumEndpoints);
-       pr_debug("descriptor type is: %d\n", iface_desc->desc.bDescriptorType);
-       pr_debug("interface number is: %d\n",
-                iface_desc->desc.bInterfaceNumber);
-       pr_debug("alternatesetting is: %d\n",
-                iface_desc->desc.bAlternateSetting);
-       pr_debug("interface class is: %d\n", iface_desc->desc.bInterfaceClass);
-       pr_debug("control endpoint info:\n");
-       pr_debug("descriptor0 type -- %d\n",
-                iface_desc->endpoint[0].desc.bmAttributes);
-       pr_debug("descriptor1 type -- %d\n",
-                iface_desc->endpoint[1].desc.bmAttributes);
-       pr_debug("descriptor2 type -- %d\n",
-                iface_desc->endpoint[2].desc.bmAttributes);
-
-       for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
-               endpoint =
-                       (struct usb_endpoint_descriptor *)&iface_desc->
-                       endpoint[i].desc;
-               pr_debug("endpoint %d\n", i);
-               pr_debug("bEndpointAddress=%x, bmAttributes=%x\n",
-                        endpoint->bEndpointAddress, endpoint->bmAttributes);
-               if ((endpoint->bEndpointAddress & USB_DIR_IN)
-                   && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
-                       USB_ENDPOINT_XFER_BULK)) {
-                       ft1000dev->bulk_in_endpointAddr =
-                               endpoint->bEndpointAddress;
-                       pr_debug("in: %d\n", endpoint->bEndpointAddress);
-               }
-
-               if (!(endpoint->bEndpointAddress & USB_DIR_IN)
-                   && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
-                       USB_ENDPOINT_XFER_BULK)) {
-                       ft1000dev->bulk_out_endpointAddr =
-                               endpoint->bEndpointAddress;
-                       pr_debug("out: %d\n", endpoint->bEndpointAddress);
-               }
-       }
-
-       pr_debug("bulk_in=%d, bulk_out=%d\n",
-                ft1000dev->bulk_in_endpointAddr,
-                ft1000dev->bulk_out_endpointAddr);
-
-       ret = request_firmware(&dsp_fw, "ft3000.img", &dev->dev);
-       if (ret < 0) {
-               dev_err(interface->usb_dev, "Error request_firmware()\n");
-               goto err_fw;
-       }
-
-       size = max_t(uint, dsp_fw->size, 4096);
-       pFileStart = kmalloc(size, GFP_KERNEL);
-
-       if (!pFileStart) {
-               release_firmware(dsp_fw);
-               ret = -ENOMEM;
-               goto err_fw;
-       }
-
-       memcpy(pFileStart, dsp_fw->data, dsp_fw->size);
-       FileLength = dsp_fw->size;
-       release_firmware(dsp_fw);
-
-       pr_debug("start downloading dsp image...\n");
-
-       ret = init_ft1000_netdev(ft1000dev);
-       if (ret)
-               goto err_load;
-
-       pft1000info = netdev_priv(ft1000dev->net);
-
-       pr_debug("pft1000info=%p\n", pft1000info);
-       ret = dsp_reload(ft1000dev);
-       if (ret) {
-               dev_err(interface->usb_dev,
-                       "Problem with DSP image loading\n");
-               goto err_load;
-       }
-
-       gPollingfailed = false;
-       ft1000dev->pPollThread =
-               kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll");
-
-       if (IS_ERR(ft1000dev->pPollThread)) {
-               ret = PTR_ERR(ft1000dev->pPollThread);
-               goto err_load;
-       }
-
-       msleep(500);
-
-       while (!pft1000info->CardReady) {
-               if (gPollingfailed) {
-                       ret = -EIO;
-                       goto err_thread;
-               }
-               msleep(100);
-               pr_debug("Waiting for Card Ready\n");
-       }
-
-       pr_debug("Card Ready!!!! Registering network device\n");
-
-       ret = reg_ft1000_netdev(ft1000dev, interface);
-       if (ret)
-               goto err_thread;
-
-       ft1000dev->NetDevRegDone = 1;
-
-       return 0;
-
-err_thread:
-       kthread_stop(ft1000dev->pPollThread);
-err_load:
-       kfree(pFileStart);
-err_fw:
-       usb_free_urb(ft1000dev->rx_urb);
-       usb_free_urb(ft1000dev->tx_urb);
-       kfree(ft1000dev);
-       return ret;
-}
-
-static void ft1000_disconnect(struct usb_interface *interface)
-{
-       struct ft1000_info *pft1000info;
-       struct ft1000_usb *ft1000dev;
-
-       pft1000info = (struct ft1000_info *)usb_get_intfdata(interface);
-       pr_debug("In disconnect pft1000info=%p\n", pft1000info);
-
-       if (pft1000info) {
-               ft1000dev = pft1000info->priv;
-               if (ft1000dev->pPollThread)
-                       kthread_stop(ft1000dev->pPollThread);
-
-               pr_debug("threads are terminated\n");
-
-               if (ft1000dev->net) {
-                       pr_debug("destroy char driver\n");
-                       ft1000_destroy_dev(ft1000dev->net);
-                       unregister_netdev(ft1000dev->net);
-                       pr_debug("network device unregistered\n");
-                       free_netdev(ft1000dev->net);
-
-               }
-
-               usb_free_urb(ft1000dev->rx_urb);
-               usb_free_urb(ft1000dev->tx_urb);
-
-               pr_debug("urb freed\n");
-
-               kfree(ft1000dev);
-       }
-       kfree(pFileStart);
-}
-
-static struct usb_driver ft1000_usb_driver = {
-       .name = "ft1000usb",
-       .probe = ft1000_probe,
-       .disconnect = ft1000_disconnect,
-       .id_table = id_table,
-};
-
-module_usb_driver(ft1000_usb_driver);
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
deleted file mode 100644 (file)
index 9b5050f..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-#ifndef _FT1000_USB_H_
-#define _FT1000_USB_H_
-
-#include "../ft1000.h"
-#include "ft1000_ioctl.h"
-#define FT1000_DRV_VER      0x01010403
-
-#define  MAX_NUM_APP         6
-#define  MAX_MSG_LIMIT       200
-#define  NUM_OF_FREE_BUFFERS 1500
-
-#define PSEUDOSZ                16
-
-struct app_info_block {
-       u32 nTxMsg;                    /* DPRAM msg sent to DSP with app_id */
-       u32 nRxMsg;                    /* DPRAM msg rcv from dsp with app_id */
-       u32 nTxMsgReject;              /* DPRAM msg rejected due to DSP doorbell
-                                       * set
-                                       */
-       u32 nRxMsgMiss;                /* DPRAM msg dropped due to overflow */
-       struct fown_struct *fileobject;/* Application's file object */
-       u16 app_id;                    /* Application id */
-       int DspBCMsgFlag;
-       int NumOfMsg;                   /* number of messages queued up */
-       wait_queue_head_t wait_dpram_msg;
-       struct list_head app_sqlist;   /* link list of msgs for applicaton on
-                                       * slow queue
-                                       */
-} __packed;
-
-#define FALSE           0
-#define TRUE            1
-
-#define FT1000_STATUS_CLOSING  0x01
-
-#define DSPBCMSGID              0x10
-
-/* Electrabuzz specific DPRAM mapping */
-/* this is used by ft1000_usb driver - isn't that a bug? */
-#undef FT1000_DPRAM_RX_BASE
-#define FT1000_DPRAM_RX_BASE   0x1800  /* RX AREA (SlowQ) */
-
-/* MEMORY MAP FOR MAGNEMITE */
-/* the indexes are swapped comparing to PCMCIA - is it OK or a bug? */
-#undef FT1000_MAG_DSP_LED_INDX
-#define FT1000_MAG_DSP_LED_INDX                0x1     /* dsp led status for PAD
-                                                * device
-                                                */
-#undef FT1000_MAG_DSP_CON_STATE_INDX
-#define FT1000_MAG_DSP_CON_STATE_INDX  0x0     /* DSP Connection Status Info */
-
-/* Maximum times trying to get ASIC out of reset */
-#define MAX_ASIC_RESET_CNT      20
-
-#define MAX_BUF_SIZE            4096
-
-struct ft1000_debug_dirs {
-       struct list_head list;
-       struct dentry *dent;
-       struct dentry *file;
-       int int_number;
-};
-
-struct ft1000_usb {
-       struct usb_device *dev;
-       struct net_device *net;
-
-       u32 status;
-
-       struct urb *rx_urb;
-       struct urb *tx_urb;
-
-       u8 tx_buf[MAX_BUF_SIZE];
-       u8 rx_buf[MAX_BUF_SIZE];
-
-       u8 bulk_in_endpointAddr;
-       u8 bulk_out_endpointAddr;
-
-       struct task_struct *pPollThread;
-       unsigned char fcodeldr;
-       unsigned char bootmode;
-       unsigned char usbboot;
-       unsigned short dspalive;
-       bool fProvComplete;
-       bool fCondResetPend;
-       bool fAppMsgPend;
-       int DeviceCreated;
-       int NetDevRegDone;
-       u8 CardNumber;
-       u8 DeviceName[15];
-       struct ft1000_debug_dirs nodes;
-       spinlock_t fifo_lock;
-       int appcnt;
-       struct app_info_block app_info[MAX_NUM_APP];
-       u16 DrvMsgPend;
-       unsigned short tempbuf[32];
-} __packed;
-
-
-struct dpram_blk {
-       struct list_head list;
-       u16 *pbuffer;
-} __packed;
-
-int ft1000_read_register(struct ft1000_usb *ft1000dev,
-                        u16 *Data, u16 nRegIndx);
-int ft1000_write_register(struct ft1000_usb *ft1000dev,
-                         u16 value, u16 nRegIndx);
-int ft1000_read_dpram32(struct ft1000_usb *ft1000dev,
-                       u16 indx, u8 *buffer, u16 cnt);
-int ft1000_write_dpram32(struct ft1000_usb *ft1000dev,
-                        u16 indx, u8 *buffer, u16 cnt);
-int ft1000_read_dpram16(struct ft1000_usb *ft1000dev,
-                       u16 indx, u8 *buffer, u8 highlow);
-int ft1000_write_dpram16(struct ft1000_usb *ft1000dev,
-                        u16 indx, u16 value, u8 highlow);
-int fix_ft1000_read_dpram32(struct ft1000_usb *ft1000dev,
-                           u16 indx, u8 *buffer);
-int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev,
-                            u16 indx, u8 *buffer);
-
-extern void *pFileStart;
-extern size_t FileLength;
-extern int numofmsgbuf;
-
-int ft1000_close(struct net_device *dev);
-int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
-               u32  FileLength);
-
-extern struct list_head freercvpool;
-
-/* lock to arbitrate free buffer list for receive command data */
-extern spinlock_t free_buff_lock;
-
-int ft1000_create_dev(struct ft1000_usb *dev);
-void ft1000_destroy_dev(struct net_device *dev);
-int card_send_command(struct ft1000_usb *ft1000dev,
-                     void *ptempbuffer, int size);
-
-struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist);
-void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist);
-
-int dsp_reload(struct ft1000_usb *ft1000dev);
-int init_ft1000_netdev(struct ft1000_usb *ft1000dev);
-struct usb_interface;
-int reg_ft1000_netdev(struct ft1000_usb *ft1000dev,
-                     struct usb_interface *intf);
-int ft1000_poll(void *dev_id);
-
-#endif  /* _FT1000_USB_H_ */
diff --git a/drivers/staging/ft1000/ft1000-usb/ft3000.img b/drivers/staging/ft1000/ft1000-usb/ft3000.img
deleted file mode 100644 (file)
index 7bef6bd..0000000
Binary files a/drivers/staging/ft1000/ft1000-usb/ft3000.img and /dev/null differ
diff --git a/drivers/staging/ft1000/ft1000.h b/drivers/staging/ft1000/ft1000.h
deleted file mode 100644 (file)
index 8a2e4ca..0000000
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Common structures and definitions for FT1000 Flarion Flash OFDM PCMCIA and
- * USB devices.
- *
- * Originally copyright (c) 2002 Flarion Technologies
- *
- */
-
-#define DSPVERSZ       4
-#define HWSERNUMSZ     16
-#define SKUSZ          20
-#define EUISZ          8
-#define MODESZ         2
-#define CALVERSZ       2
-#define CALDATESZ      6
-
-#define ELECTRABUZZ_ID 0       /* ASIC ID for Electrabuzz */
-#define MAGNEMITE_ID   0x1a01  /* ASIC ID for Magnemite */
-
-/* MEMORY MAP common to both ELECTRABUZZ and MAGNEMITE */
-#define        FT1000_REG_DPRAM_ADDR   0x000E  /* DPADR - Dual Port Ram Indirect
-                                        * Address Register
-                                        */
-#define        FT1000_REG_SUP_CTRL     0x0020  /* HCTR - Host Control Register */
-#define        FT1000_REG_SUP_STAT     0x0022  /* HSTAT - Host Status Register */
-#define        FT1000_REG_RESET        0x0024  /* HCTR - Host Control Register */
-#define        FT1000_REG_SUP_ISR      0x0026  /* HISR - Host Interrupt Status
-                                        * Register
-                                        */
-#define        FT1000_REG_SUP_IMASK    0x0028  /* HIMASK - Host Interrupt Mask */
-#define        FT1000_REG_DOORBELL     0x002a  /* DBELL - Door Bell Register */
-#define FT1000_REG_ASIC_ID     0x002e  /* ASICID - ASIC Identification
-                                        * Number
-                                        */
-
-/* MEMORY MAP FOR ELECTRABUZZ ASIC */
-#define FT1000_REG_UFIFO_STAT  0x0000  /* UFSR - Uplink FIFO status register */
-#define FT1000_REG_UFIFO_BEG   0x0002  /* UFBR - Uplink FIFO beginning
-                                        * register
-                                        */
-#define        FT1000_REG_UFIFO_MID    0x0004  /* UFMR - Uplink FIFO middle register */
-#define        FT1000_REG_UFIFO_END    0x0006  /* UFER - Uplink FIFO end register */
-#define        FT1000_REG_DFIFO_STAT   0x0008  /* DFSR - Downlink FIFO status
-                                        * register
-                                        */
-#define        FT1000_REG_DFIFO        0x000A  /* DFR - Downlink FIFO Register */
-#define        FT1000_REG_DPRAM_DATA   0x000C  /* DPRAM - Dual Port Indirect
-                                        * Data Register
-                                        */
-#define        FT1000_REG_WATERMARK    0x0010  /* WMARK - Watermark Register */
-
-/* MEMORY MAP FOR MAGNEMITE */
-#define FT1000_REG_MAG_UFDR    0x0000  /* UFDR - Uplink FIFO Data
-                                        * Register (32-bits)
-                                        */
-#define FT1000_REG_MAG_UFDRL   0x0000  /* UFDRL - Uplink FIFO Data
-                                        * Register low-word (16-bits)
-                                        */
-#define FT1000_REG_MAG_UFDRH   0x0002  /* UFDRH - Uplink FIFO Data Register
-                                        * high-word (16-bits)
-                                        */
-#define FT1000_REG_MAG_UFER    0x0004  /* UFER - Uplink FIFO End Register */
-#define FT1000_REG_MAG_UFSR    0x0006  /* UFSR - Uplink FIFO Status Register */
-#define FT1000_REG_MAG_DFR     0x0008  /* DFR - Downlink FIFO Register
-                                        * (32-bits)
-                                        */
-#define FT1000_REG_MAG_DFRL    0x0008  /* DFRL - Downlink FIFO Register
-                                        * low-word (16-bits)
-                                        */
-#define FT1000_REG_MAG_DFRH    0x000a  /* DFRH - Downlink FIFO Register
-                                        * high-word (16-bits)
-                                        */
-#define FT1000_REG_MAG_DFSR    0x000c  /* DFSR - Downlink FIFO Status
-                                        * Register
-                                        */
-#define FT1000_REG_MAG_DPDATA  0x0010  /* DPDATA - Dual Port RAM Indirect
-                                        * Data Register (32-bits)
-                                        */
-#define FT1000_REG_MAG_DPDATAL 0x0010  /* DPDATAL - Dual Port RAM Indirect
-                                        * Data Register low-word (16-bits)
-                                        */
-#define FT1000_REG_MAG_DPDATAH 0x0012  /* DPDATAH - Dual Port RAM Indirect Data
-                                        * Register high-word (16-bits)
-                                        */
-#define        FT1000_REG_MAG_WATERMARK 0x002c /* WMARK - Watermark Register */
-#define FT1000_REG_MAG_VERSION 0x0030  /* LLC Version */
-
-/* Reserved Dual Port RAM offsets for Electrabuzz */
-#define FT1000_DPRAM_TX_BASE   0x0002  /* Host to PC Card Messaging Area */
-#define FT1000_DPRAM_RX_BASE   0x0800  /* PC Card to Host Messaging Area */
-#define FT1000_FIFO_LEN                0x07FC  /* total length for DSP FIFO tracking */
-#define FT1000_HI_HO           0x07FE  /* heartbeat with HI/HO */
-#define FT1000_DSP_STATUS      0x0FFE  /* dsp status - non-zero is a request
-                                        * to reset dsp
-                                        */
-#define FT1000_DSP_LED         0x0FFA  /* dsp led status for PAD device */
-#define FT1000_DSP_CON_STATE   0x0FF8  /* DSP Connection Status Info */
-#define FT1000_DPRAM_FEFE      0x0002  /* location for dsp ready indicator */
-#define FT1000_DSP_TIMER0      0x1FF0  /* Timer Field from Basestation */
-#define FT1000_DSP_TIMER1      0x1FF2  /* Timer Field from Basestation */
-#define FT1000_DSP_TIMER2      0x1FF4  /* Timer Field from Basestation */
-#define FT1000_DSP_TIMER3      0x1FF6  /* Timer Field from Basestation */
-
-/* Reserved Dual Port RAM offsets for Magnemite */
-#define FT1000_DPRAM_MAG_TX_BASE       0x0000  /* Host to PC Card
-                                                * Messaging Area
-                                                */
-#define FT1000_DPRAM_MAG_RX_BASE       0x0200  /* PC Card to Host
-                                                * Messaging Area
-                                                */
-
-#define FT1000_MAG_FIFO_LEN            0x1FF   /* total length for DSP
-                                                * FIFO tracking
-                                                */
-#define FT1000_MAG_FIFO_LEN_INDX       0x1     /* low-word index */
-#define FT1000_MAG_HI_HO               0x1FF   /* heartbeat with HI/HO */
-#define FT1000_MAG_HI_HO_INDX          0x0     /* high-word index */
-#define FT1000_MAG_DSP_LED             0x3FE   /* dsp led status for
-                                                * PAD device
-                                                */
-#define FT1000_MAG_DSP_LED_INDX                0x0     /* dsp led status for
-                                                * PAD device
-                                                */
-#define FT1000_MAG_DSP_CON_STATE       0x3FE   /* DSP Connection Status Info */
-#define FT1000_MAG_DSP_CON_STATE_INDX  0x1     /* DSP Connection Status Info */
-#define FT1000_MAG_DPRAM_FEFE          0x000   /* location for dsp ready
-                                                * indicator
-                                                */
-#define FT1000_MAG_DPRAM_FEFE_INDX     0x0     /* location for dsp ready
-                                                * indicator
-                                                */
-#define FT1000_MAG_DSP_TIMER0          0x3FC   /* Timer Field from
-                                                * Basestation
-                                                */
-#define FT1000_MAG_DSP_TIMER0_INDX     0x1
-#define FT1000_MAG_DSP_TIMER1          0x3FC   /* Timer Field from
-                                                * Basestation
-                                                */
-#define FT1000_MAG_DSP_TIMER1_INDX     0x0
-#define FT1000_MAG_DSP_TIMER2          0x3FD   /* Timer Field from
-                                                * Basestation
-                                                */
-#define FT1000_MAG_DSP_TIMER2_INDX     0x1
-#define FT1000_MAG_DSP_TIMER3          0x3FD   /* Timer Field from
-                                                * Basestation
-                                                */
-#define FT1000_MAG_DSP_TIMER3_INDX     0x0
-#define FT1000_MAG_TOTAL_LEN           0x200
-#define FT1000_MAG_TOTAL_LEN_INDX      0x1
-#define FT1000_MAG_PH_LEN              0x200
-#define FT1000_MAG_PH_LEN_INDX         0x0
-#define FT1000_MAG_PORT_ID             0x201
-#define FT1000_MAG_PORT_ID_INDX                0x0
-
-#define HOST_INTF_LE   0x0     /* Host interface little endian mode */
-#define HOST_INTF_BE   0x1     /* Host interface big endian mode */
-
-/* FT1000 to Host Doorbell assignments */
-#define FT1000_DB_DPRAM_RX     0x0001  /* this value indicates that DSP
-                                        * has data for host in DPRAM
-                                        */
-#define FT1000_DB_DNLD_RX      0x0002  /* Downloader handshake doorbell */
-#define FT1000_ASIC_RESET_REQ  0x0004  /* DSP requesting host to
-                                        * reset the ASIC
-                                        */
-#define FT1000_DSP_ASIC_RESET  0x0008  /* DSP indicating host that
-                                        * it will reset the ASIC
-                                        */
-#define FT1000_DB_COND_RESET   0x0010  /* DSP request for a card reset. */
-
-/* Host to FT1000 Doorbell assignments */
-#define FT1000_DB_DPRAM_TX     0x0100  /* this value indicates that host
-                                        * has data for DSP in DPRAM.
-                                        */
-#define FT1000_DB_DNLD_TX      0x0200  /* Downloader handshake doorbell */
-#define FT1000_ASIC_RESET_DSP  0x0400  /* Responds to FT1000_ASIC_RESET_REQ */
-#define FT1000_DB_HB           0x1000  /* Indicates that supervisor has a
-                                        * heartbeat message for DSP.
-                                        */
-
-#define hi                     0x6869  /* PC Card heartbeat values */
-#define ho                     0x686f  /* PC Card heartbeat values */
-
-/* Magnemite specific defines */
-#define hi_mag                 0x6968  /* Byte swap hi to avoid
-                                        * additional system call
-                                        */
-#define ho_mag                 0x6f68  /* Byte swap ho to avoid
-                                        * additional system call
-                                        */
-
-/* Bit field definitions for Host Interrupt Status Register */
-/* Indicate the cause of an interrupt. */
-#define ISR_EMPTY              0x00    /* no bits set */
-#define ISR_DOORBELL_ACK       0x01    /* Doorbell acknowledge from DSP */
-#define ISR_DOORBELL_PEND      0x02    /* Doorbell pending from DSP */
-#define ISR_RCV                        0x04    /* Packet available in Downlink FIFO */
-#define ISR_WATERMARK          0x08    /* Watermark requirements satisfied */
-
-/* Bit field definition for Host Interrupt Mask */
-#define ISR_MASK_NONE          0x0000  /* no bits set */
-#define ISR_MASK_DOORBELL_ACK  0x0001  /* Doorbell acknowledge mask */
-#define ISR_MASK_DOORBELL_PEND 0x0002  /* Doorbell pending mask */
-#define ISR_MASK_RCV           0x0004  /* Downlink Packet available mask */
-#define ISR_MASK_WATERMARK     0x0008  /* Watermark interrupt mask */
-#define ISR_MASK_ALL           0xffff  /* Mask all interrupts */
-/* Default interrupt mask
- * (Enable Doorbell pending and Packet available interrupts)
- */
-#define ISR_DEFAULT_MASK       0x7ff9
-
-/* Bit field definition for Host Control Register */
-#define DSP_RESET_BIT          0x0001  /* Bit field to control
-                                        * dsp reset state
-                                        */
-                                       /* (0 = out of reset 1 = reset) */
-#define ASIC_RESET_BIT         0x0002  /* Bit field to control
-                                        * ASIC reset state
-                                        */
-                                       /* (0 = out of reset 1 = reset) */
-#define DSP_UNENCRYPTED                0x0004
-#define DSP_ENCRYPTED          0x0008
-#define EFUSE_MEM_DISABLE      0x0040
-
-/* Application specific IDs */
-#define DSPID          0x20
-#define HOSTID         0x10
-#define DSPAIRID       0x90
-#define DRIVERID       0x00
-#define NETWORKID      0x20
-
-/* Size of DPRAM Message */
-#define MAX_CMD_SQSIZE 1780
-
-#define ENET_MAX_SIZE          1514
-#define ENET_HEADER_SIZE       14
-
-#define SLOWQ_TYPE     0
-#define FASTQ_TYPE     1
-
-#define MAX_DSP_SESS_REC       1024
-
-#define DSP_QID_OFFSET 4
-
-/* Driver message types */
-#define MEDIA_STATE            0x0010
-#define TIME_UPDATE            0x0020
-#define DSP_PROVISION          0x0030
-#define DSP_INIT_MSG           0x0050
-#define DSP_HIBERNATE          0x0060
-#define DSP_STORE_INFO         0x0070
-#define DSP_GET_INFO           0x0071
-#define GET_DRV_ERR_RPT_MSG    0x0073
-#define RSP_DRV_ERR_RPT_MSG    0x0074
-
-/* Driver Error Messages for DSP */
-#define DSP_HB_INFO            0x7ef0
-#define DSP_FIFO_INFO          0x7ef1
-#define DSP_CONDRESET_INFO     0x7ef2
-#define DSP_CMDLEN_INFO                0x7ef3
-#define DSP_CMDPHCKSUM_INFO    0x7ef4
-#define DSP_PKTPHCKSUM_INFO    0x7ef5
-#define DSP_PKTLEN_INFO                0x7ef6
-#define DSP_USER_RESET         0x7ef7
-#define FIFO_FLUSH_MAXLIMIT    0x7ef8
-#define FIFO_FLUSH_BADCNT      0x7ef9
-#define FIFO_ZERO_LEN          0x7efa
-
-/* Pseudo Header structure */
-struct pseudo_hdr {
-       unsigned short  length;         /* length of msg body */
-       unsigned char   source;         /* hardware source id */
-                                       /*    Host = 0x10 */
-                                       /*    Dsp  = 0x20 */
-       unsigned char   destination;    /* hardware destination id
-                                        * (refer to source)
-                                        */
-       unsigned char   portdest;       /* software destination port id */
-                                       /*    Host = 0x00 */
-                                       /*    Applicaton Broadcast = 0x10 */
-                                       /*    Network Stack = 0x20 */
-                                       /*    Dsp OAM = 0x80 */
-                                       /*    Dsp Airlink = 0x90 */
-                                       /*    Dsp Loader = 0xa0 */
-                                       /*    Dsp MIP = 0xb0 */
-       unsigned char   portsrc;        /* software source port id
-                                        * (refer to portdest)
-                                        */
-       unsigned short  sh_str_id;      /* not used */
-       unsigned char   control;        /* not used */
-       unsigned char   rsvd1;
-       unsigned char   seq_num;        /* message sequence number */
-       unsigned char   rsvd2;
-       unsigned short  qos_class;      /* not used */
-       unsigned short  checksum;       /* pseudo header checksum */
-} __packed;
-
-struct drv_msg {
-       struct pseudo_hdr pseudo;
-       u16 type;
-       u16 length;
-       u8  data[0];
-} __packed;
-
-struct media_msg {
-       struct pseudo_hdr pseudo;
-       u16 type;
-       u16 length;
-       u16 state;
-       u32 ip_addr;
-       u32 net_mask;
-       u32 gateway;
-       u32 dns_1;
-       u32 dns_2;
-} __packed;
-
-struct dsp_init_msg {
-       struct pseudo_hdr pseudo;
-       u16 type;
-       u16 length;
-       u8 DspVer[DSPVERSZ];            /* DSP version number */
-       u8 HwSerNum[HWSERNUMSZ];        /* Hardware Serial Number */
-       u8 Sku[SKUSZ];                  /* SKU */
-       u8 eui64[EUISZ];                /* EUI64 */
-       u8 ProductMode[MODESZ];         /* Product Mode (Market/Production) */
-       u8 RfCalVer[CALVERSZ];          /* Rf Calibration version */
-       u8 RfCalDate[CALDATESZ];        /* Rf Calibration date */
-} __packed;
-
-struct prov_record {
-       struct list_head list;
-       u8 *pprov_data;
-};
-
-struct ft1000_info {
-       void *priv;
-       struct net_device_stats stats;
-       u16 DrvErrNum;
-       u16 AsicID;
-       int CardReady;
-       int registered;
-       int mediastate;
-       u8 squeseqnum;                  /* sequence number on slow queue */
-       spinlock_t dpram_lock;
-       u16 fifo_cnt;
-       u8 DspVer[DSPVERSZ];            /* DSP version number */
-       u8 HwSerNum[HWSERNUMSZ];        /* Hardware Serial Number */
-       u8 Sku[SKUSZ];                  /* SKU */
-       u8 eui64[EUISZ];                /* EUI64 */
-       time_t ConTm;                   /* Connection Time */
-       u8 ProductMode[MODESZ];
-       u8 RfCalVer[CALVERSZ];
-       u8 RfCalDate[CALDATESZ];
-       u16 DSP_TIME[4];
-       u16 LedStat;
-       u16 ConStat;
-       u16 ProgConStat;
-       struct list_head prov_list;
-       u16 DSPInfoBlklen;
-       int (*ft1000_reset)(void *);
-       u16 DSPInfoBlk[MAX_DSP_SESS_REC];
-       union {
-               u16 Rec[MAX_DSP_SESS_REC];
-               u32 MagRec[MAX_DSP_SESS_REC/2];
-       } DSPSess;
-};
index a8d2cffb411cb8bf7460dfb2b6537343ba10e37c..79de678807ccbf43d73e1fb37a4be5687ede236c 100644 (file)
@@ -162,11 +162,11 @@ static int gdm_lte_emulate_arp(struct sk_buff *skb_in, u32 nic_type)
        skb_reserve(skb_out, NET_IP_ALIGN);
 
        memcpy(skb_put(skb_out, mac_header_len), mac_header_data,
-               mac_header_len);
+              mac_header_len);
        memcpy(skb_put(skb_out, sizeof(struct arphdr)), arp_out,
-               sizeof(struct arphdr));
+              sizeof(struct arphdr));
        memcpy(skb_put(skb_out, sizeof(struct arpdata)), arp_data_out,
-               sizeof(struct arpdata));
+              sizeof(struct arpdata));
 
        skb_out->protocol = ((struct ethhdr *)mac_header_data)->h_proto;
        skb_out->dev = skb_in->dev;
@@ -300,13 +300,13 @@ static int gdm_lte_emulate_ndp(struct sk_buff *skb_in, u32 nic_type)
                memcpy(&ipv6_out, ipv6_in, sizeof(struct ipv6hdr));
                memcpy(ipv6_out.saddr.in6_u.u6_addr8, &na.target_address, 16);
                memcpy(ipv6_out.daddr.in6_u.u6_addr8,
-                       ipv6_in->saddr.in6_u.u6_addr8, 16);
+                      ipv6_in->saddr.in6_u.u6_addr8, 16);
                ipv6_out.payload_len = htons(sizeof(struct icmp6hdr) +
                                sizeof(struct neighbour_advertisement));
 
                memcpy(icmp_na, &icmp6_out, sizeof(struct icmp6hdr));
                memcpy(icmp_na + sizeof(struct icmp6hdr), &na,
-                       sizeof(struct neighbour_advertisement));
+                      sizeof(struct neighbour_advertisement));
 
                icmp6_out.icmp6_cksum = icmp6_checksum(&ipv6_out,
                                        (u16 *)icmp_na, sizeof(icmp_na));
@@ -326,13 +326,13 @@ static int gdm_lte_emulate_ndp(struct sk_buff *skb_in, u32 nic_type)
        skb_reserve(skb_out, NET_IP_ALIGN);
 
        memcpy(skb_put(skb_out, mac_header_len), mac_header_data,
-               mac_header_len);
+              mac_header_len);
        memcpy(skb_put(skb_out, sizeof(struct ipv6hdr)), &ipv6_out,
-               sizeof(struct ipv6hdr));
+              sizeof(struct ipv6hdr));
        memcpy(skb_put(skb_out, sizeof(struct icmp6hdr)), &icmp6_out,
-               sizeof(struct icmp6hdr));
+              sizeof(struct icmp6hdr));
        memcpy(skb_put(skb_out, sizeof(struct neighbour_advertisement)), &na,
-               sizeof(struct neighbour_advertisement));
+              sizeof(struct neighbour_advertisement));
 
        skb_out->protocol = ((struct ethhdr *)mac_header_data)->h_proto;
        skb_out->dev = skb_in->dev;
@@ -377,11 +377,11 @@ static s32 gdm_lte_tx_nic_type(struct net_device *dev, struct sk_buff *skb)
                break;
        case ETH_P_IP:
                nic_type |= NIC_TYPE_F_IPV4;
-               ip = (struct iphdr *)network_data;
+               ip = network_data;
 
                /* Check DHCPv4 */
                if (ip->protocol == IPPROTO_UDP) {
-                       struct udphdr *udp = (struct udphdr *)
+                       struct udphdr *udp =
                                        (network_data + sizeof(struct iphdr));
                        if (ntohs(udp->dest) == 67 || ntohs(udp->dest) == 68)
                                nic_type |= NIC_TYPE_F_DHCP;
@@ -389,15 +389,15 @@ static s32 gdm_lte_tx_nic_type(struct net_device *dev, struct sk_buff *skb)
                break;
        case ETH_P_IPV6:
                nic_type |= NIC_TYPE_F_IPV6;
-               ipv6 = (struct ipv6hdr *)network_data;
+               ipv6 = network_data;
 
                if (ipv6->nexthdr == IPPROTO_ICMPV6) /* Check NDP request */ {
-                       struct icmp6hdr *icmp6 = (struct icmp6hdr *)
+                       struct icmp6hdr *icmp6 =
                                        (network_data + sizeof(struct ipv6hdr));
                        if (icmp6->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION)
                                nic_type |= NIC_TYPE_ICMPV6;
                } else if (ipv6->nexthdr == IPPROTO_UDP) /* Check DHCPv6 */ {
-                       struct udphdr *udp = (struct udphdr *)
+                       struct udphdr *udp =
                                        (network_data + sizeof(struct ipv6hdr));
                        if (ntohs(udp->dest) == 546 || ntohs(udp->dest) == 547)
                                nic_type |= NIC_TYPE_F_DHCP;
@@ -530,7 +530,7 @@ static int gdm_lte_event_send(struct net_device *dev, char *buf, int len)
 }
 
 static void gdm_lte_event_rcv(struct net_device *dev, u16 type,
-                               void *msg, int len)
+                             void *msg, int len)
 {
        struct nic *nic = netdev_priv(dev);
 
@@ -572,7 +572,7 @@ static u8 find_dev_index(u32 nic_type)
 }
 
 static void gdm_lte_netif_rx(struct net_device *dev, char *buf,
-                       int len, int flagged_nic_type)
+                            int len, int flagged_nic_type)
 {
        u32 nic_type;
        struct nic *nic;
@@ -697,9 +697,9 @@ static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len)
        u8 index;
 
        hci_len = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev),
-                               multi_sdu->len);
+                                  multi_sdu->len);
        num_packet = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev),
-                               multi_sdu->num_packet);
+                                     multi_sdu->num_packet);
 
        for (i = 0; i < num_packet; i++) {
                sdu = (struct sdu *)data;
@@ -724,12 +724,12 @@ static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len)
                if (index < MAX_NIC_TYPE) {
                        dev = phy_dev->dev[index];
                        gdm_lte_netif_rx(dev, (char *)sdu->data,
-                                       (int)(hci_len-12), nic_type);
+                                        (int)(hci_len - 12), nic_type);
                } else {
                        pr_err("rx sdu invalid nic_type :%x\n", nic_type);
                }
 
-               data += ((hci_len+3) & 0xfffc) + HCI_HEADER_SIZE;
+               data += ((hci_len + 3) & 0xfffc) + HCI_HEADER_SIZE;
        }
 }
 
@@ -772,10 +772,10 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len)
                return ret;
 
        cmd_evt = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev),
-                               hci->cmd_evt);
+                                  hci->cmd_evt);
 
        dev = phy_dev->dev[0];
-       if (dev == NULL)
+       if (!dev)
                return 0;
 
        switch (cmd_evt) {
@@ -814,9 +814,9 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len)
 
 static int rx_complete(void *arg, void *data, int len, int context)
 {
-       struct phy_dev *phy_dev = (struct phy_dev *)arg;
+       struct phy_dev *phy_dev = arg;
 
-       return gdm_lte_receive_pkt(phy_dev, (char *)data, len);
+       return gdm_lte_receive_pkt(phy_dev, data, len);
 }
 
 void start_rx_proc(struct phy_dev *phy_dev)
@@ -839,7 +839,7 @@ static struct net_device_ops gdm_netdev_ops = {
 static u8 gdm_lte_macaddr[ETH_ALEN] = {0x00, 0x0a, 0x3b, 0x00, 0x00, 0x00};
 
 static void form_mac_address(u8 *dev_addr, u8 *nic_src, u8 *nic_dest,
-                       u8 *mac_address, u8 index)
+                            u8 *mac_address, u8 index)
 {
        /* Form the dev_addr */
        if (!mac_address)
@@ -850,7 +850,7 @@ static void form_mac_address(u8 *dev_addr, u8 *nic_src, u8 *nic_dest,
        /* The last byte of the mac address
         * should be less than or equal to 0xFC
         */
-       dev_addr[ETH_ALEN-1] += index;
+       dev_addr[ETH_ALEN - 1] += index;
 
        /* Create random nic src and copy the first
         * 3 bytes to be the same as dev_addr
@@ -938,7 +938,7 @@ void unregister_lte_device(struct phy_dev *phy_dev)
 
        for (index = 0; index < MAX_NIC_TYPE; index++) {
                net = phy_dev->dev[index];
-               if (net == NULL)
+               if (!net)
                        continue;
 
                unregister_netdev(net);
index 1cf24e4edf251ca1896a72073c5fdf6df0eac336..445f836155752e3225046cdd0268c388e1ff114f 100644 (file)
@@ -48,7 +48,6 @@ static const struct usb_device_id id_table[] = {
        {}
 };
 
-
 MODULE_DEVICE_TABLE(usb, id_table);
 
 static int packet_type_to_index(u16 packetType)
@@ -67,7 +66,7 @@ static struct mux_tx *alloc_mux_tx(int len)
 {
        struct mux_tx *t = NULL;
 
-       t = kzalloc(sizeof(struct mux_tx), GFP_ATOMIC);
+       t = kzalloc(sizeof(*t), GFP_ATOMIC);
        if (!t)
                return NULL;
 
@@ -96,7 +95,7 @@ static struct mux_rx *alloc_mux_rx(void)
 {
        struct mux_rx *r = NULL;
 
-       r = kzalloc(sizeof(struct mux_rx), GFP_KERNEL);
+       r = kzalloc(sizeof(*r), GFP_KERNEL);
        if (!r)
                return NULL;
 
@@ -150,10 +149,9 @@ static void put_rx_struct(struct rx_cxt *rx, struct mux_rx *r)
        spin_unlock_irqrestore(&rx->free_list_lock, flags);
 }
 
-
 static int up_to_host(struct mux_rx *r)
 {
-       struct mux_dev *mux_dev = (struct mux_dev *)r->mux_dev;
+       struct mux_dev *mux_dev = r->mux_dev;
        struct mux_pkt_header *mux_header;
        unsigned int start_flag;
        unsigned int payload_size;
@@ -222,7 +220,7 @@ static void do_rx(struct work_struct *work)
        struct mux_dev *mux_dev =
                container_of(work, struct mux_dev, work_rx.work);
        struct mux_rx *r;
-       struct rx_cxt *rx = (struct rx_cxt *)&mux_dev->rx;
+       struct rx_cxt *rx = &mux_dev->rx;
        unsigned long flags;
        int ret = 0;
 
@@ -262,7 +260,7 @@ static void remove_rx_submit_list(struct mux_rx *r, struct rx_cxt *rx)
 static void gdm_mux_rcv_complete(struct urb *urb)
 {
        struct mux_rx *r = urb->context;
-       struct mux_dev *mux_dev = (struct mux_dev *)r->mux_dev;
+       struct mux_dev *mux_dev = r->mux_dev;
        struct rx_cxt *rx = &mux_dev->rx;
        unsigned long flags;
 
@@ -271,7 +269,7 @@ static void gdm_mux_rcv_complete(struct urb *urb)
        if (urb->status) {
                if (mux_dev->usb_state == PM_NORMAL)
                        dev_err(&urb->dev->dev, "%s: urb status error %d\n",
-                              __func__, urb->status);
+                               __func__, urb->status);
                put_rx_struct(rx, r);
        } else {
                r->len = r->urb->actual_length;
@@ -388,8 +386,8 @@ static int gdm_mux_send(void *priv_dev, void *data, int len, int tty_index,
        mux_header->payload_size = __cpu_to_le32((u32)len);
        mux_header->packet_type = __cpu_to_le16(packet_type[tty_index]);
 
-       memcpy(t->buf+MUX_HEADER_SIZE, data, len);
-       memset(t->buf+MUX_HEADER_SIZE+len, 0, total_len - MUX_HEADER_SIZE -
+       memcpy(t->buf + MUX_HEADER_SIZE, data, len);
+       memset(t->buf + MUX_HEADER_SIZE + len, 0, total_len - MUX_HEADER_SIZE -
               len);
 
        t->len = total_len;
@@ -474,7 +472,6 @@ static void release_usb(struct mux_dev *mux_dev)
        spin_unlock_irqrestore(&rx->to_host_lock, flags);
 }
 
-
 static int init_usb(struct mux_dev *mux_dev)
 {
        struct mux_rx *r;
@@ -492,7 +489,7 @@ static int init_usb(struct mux_dev *mux_dev)
 
        for (i = 0; i < MAX_ISSUE_NUM * 2; i++) {
                r = alloc_mux_rx();
-               if (r == NULL) {
+               if (!r) {
                        ret = -ENOMEM;
                        break;
                }
@@ -526,11 +523,11 @@ static int gdm_mux_probe(struct usb_interface *intf,
        if (bInterfaceNumber != 2)
                return -ENODEV;
 
-       mux_dev = kzalloc(sizeof(struct mux_dev), GFP_KERNEL);
+       mux_dev = kzalloc(sizeof(*mux_dev), GFP_KERNEL);
        if (!mux_dev)
                return -ENOMEM;
 
-       tty_dev = kzalloc(sizeof(struct tty_dev), GFP_KERNEL);
+       tty_dev = kzalloc(sizeof(*tty_dev), GFP_KERNEL);
        if (!tty_dev) {
                ret = -ENOMEM;
                goto err_free_mux;
@@ -612,7 +609,6 @@ static int gdm_mux_suspend(struct usb_interface *intf, pm_message_t pm_msg)
 
        mux_dev->usb_state = PM_SUSPEND;
 
-
        spin_lock_irqsave(&rx->submit_list_lock, flags);
        list_for_each_entry_safe(r, r_next, &rx->rx_submit_list,
                                 rx_submit_list) {
@@ -662,7 +658,7 @@ static int __init gdm_usb_mux_init(void)
 {
 
        mux_rx_wq = create_workqueue("mux_rx_wq");
-       if (mux_rx_wq == NULL) {
+       if (!mux_rx_wq) {
                pr_err("work queue create fail\n");
                return -1;
        }
index 001348ccacf95cacd3cca7829681089314a36e1c..e2c0f228f36937b87390c01672862e9935f785f6 100644 (file)
@@ -88,7 +88,7 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 
        mutex_lock(&gdm_table_lock);
        gdm = gdm_table[i][j];
-       if (gdm == NULL) {
+       if (!gdm) {
                mutex_unlock(&gdm_table_lock);
                return -ENODEV;
        }
@@ -167,7 +167,7 @@ static int gdm_tty_recv_complete(void *data,
 
 static void gdm_tty_send_complete(void *arg)
 {
-       struct gdm *gdm = (struct gdm *)arg;
+       struct gdm *gdm = arg;
 
        if (!GDM_TTY_READY(gdm))
                return;
@@ -193,7 +193,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,
                sending_len = remain > MUX_TX_MAX_SIZE ? MUX_TX_MAX_SIZE :
                                                         remain;
                gdm_tty_send(gdm,
-                            (void *)(buf+sent_len),
+                            (void *)(buf + sent_len),
                             sending_len,
                             gdm->index,
                             gdm_tty_send_complete,
@@ -226,7 +226,7 @@ int register_lte_tty_device(struct tty_dev *tty_dev, struct device *device)
 
        for (i = 0; i < TTY_MAX_COUNT; i++) {
 
-               gdm = kmalloc(sizeof(struct gdm), GFP_KERNEL);
+               gdm = kmalloc(sizeof(*gdm), GFP_KERNEL);
                if (!gdm)
                        return -ENOMEM;
 
index ed1a12f504e2183e459bc3e43e171255caaf9c38..92ea1a16afff2b6c177c53aca6cc3c768f7d98e9 100644 (file)
@@ -63,7 +63,7 @@ static void do_rx(struct work_struct *work);
 
 static int gdm_usb_recv(void *priv_dev,
                        int (*cb)(void *cb_data,
-                               void *data, int len, int context),
+                                 void *data, int len, int context),
                        void *cb_data,
                        int context);
 
@@ -80,7 +80,7 @@ static int request_mac_address(struct lte_udev *udev)
        hci->data[0] = MAC_ADDRESS;
 
        ret = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 2), buf, 5,
-                    &actual, 1000);
+                          &actual, 1000);
 
        udev->request_mac_addr = 1;
 
@@ -92,7 +92,7 @@ static struct usb_tx *alloc_tx_struct(int len)
        struct usb_tx *t = NULL;
        int ret = 0;
 
-       t = kzalloc(sizeof(struct usb_tx), GFP_ATOMIC);
+       t = kzalloc(sizeof(*t), GFP_ATOMIC);
        if (!t) {
                ret = -ENOMEM;
                goto out;
@@ -125,7 +125,7 @@ static struct usb_tx_sdu *alloc_tx_sdu_struct(void)
 {
        struct usb_tx_sdu *t_sdu;
 
-       t_sdu = kzalloc(sizeof(struct usb_tx_sdu), GFP_KERNEL);
+       t_sdu = kzalloc(sizeof(*t_sdu), GFP_KERNEL);
        if (!t_sdu)
                return NULL;
 
@@ -183,7 +183,7 @@ static struct usb_rx *alloc_rx_struct(void)
        struct usb_rx *r = NULL;
        int ret = 0;
 
-       r = kmalloc(sizeof(struct usb_rx), GFP_KERNEL);
+       r = kmalloc(sizeof(*r), GFP_KERNEL);
        if (!r) {
                ret = -ENOMEM;
                goto out;
@@ -338,7 +338,7 @@ static int init_usb(struct lte_udev *udev)
 
        for (i = 0; i < MAX_NUM_SDU_BUF; i++) {
                t_sdu = alloc_tx_sdu_struct();
-               if (t_sdu == NULL) {
+               if (!t_sdu) {
                        ret = -ENOMEM;
                        goto fail;
                }
@@ -347,9 +347,9 @@ static int init_usb(struct lte_udev *udev)
                tx->avail_count++;
        }
 
-       for (i = 0; i < MAX_RX_SUBMIT_COUNT*2; i++) {
+       for (i = 0; i < MAX_RX_SUBMIT_COUNT * 2; i++) {
                r = alloc_rx_struct();
-               if (r == NULL) {
+               if (!r) {
                        ret = -ENOMEM;
                        goto fail;
                }
@@ -367,7 +367,7 @@ fail:
 
 static int set_mac_address(u8 *data, void *arg)
 {
-       struct phy_dev *phy_dev = (struct phy_dev *)arg;
+       struct phy_dev *phy_dev = arg;
        struct lte_udev *udev = phy_dev->priv_dev;
        struct tlv *tlv = (struct tlv *)data;
        u8 mac_address[ETH_ALEN] = {0, };
@@ -376,7 +376,7 @@ static int set_mac_address(u8 *data, void *arg)
                memcpy(mac_address, tlv->data, tlv->len);
 
                if (register_lte_device(phy_dev,
-                               &udev->intf->dev, mac_address) < 0)
+                                       &udev->intf->dev, mac_address) < 0)
                        pr_err("register lte device failed\n");
 
                udev->request_mac_addr = 0;
@@ -406,12 +406,12 @@ static void do_rx(struct work_struct *work)
                        break;
                }
                r = list_entry(rx->to_host_list.next,
-                       struct usb_rx, to_host_list);
+                              struct usb_rx, to_host_list);
                list_del(&r->to_host_list);
                spin_unlock_irqrestore(&rx->to_host_lock, flags);
 
-               phy_dev = (struct phy_dev *)r->cb_data;
-               udev = (struct lte_udev *)phy_dev->priv_dev;
+               phy_dev = r->cb_data;
+               udev = phy_dev->priv_dev;
                hci = (struct hci_packet *)r->buf;
                cmd_evt = gdm_dev16_to_cpu(&udev->gdm_ed, hci->cmd_evt);
 
@@ -481,7 +481,7 @@ static void gdm_usb_rcv_complete(struct urb *urb)
        } else {
                if (urb->status && udev->usb_state == PM_NORMAL)
                        dev_err(&urb->dev->dev, "%s: urb status error %d\n",
-                              __func__, urb->status);
+                               __func__, urb->status);
 
                put_rx_struct(rx, r);
        }
@@ -491,7 +491,7 @@ static void gdm_usb_rcv_complete(struct urb *urb)
 
 static int gdm_usb_recv(void *priv_dev,
                        int (*cb)(void *cb_data,
-                               void *data, int len, int context),
+                                 void *data, int len, int context),
                        void *cb_data,
                        int context)
 {
@@ -576,7 +576,7 @@ static int send_tx_packet(struct usb_device *usbdev, struct usb_tx *t, u32 len)
 {
        int ret = 0;
 
-       if (!(len%512))
+       if (!(len % 512))
                len++;
 
        usb_fill_bulk_urb(t->urb,
@@ -682,7 +682,7 @@ static void do_tx(struct work_struct *work)
                }
 
                t = alloc_tx_struct(TX_BUF_SIZE);
-               if (t == NULL) {
+               if (!t) {
                        spin_unlock_irqrestore(&tx->lock, flags);
                        return;
                }
@@ -711,8 +711,8 @@ static void do_tx(struct work_struct *work)
 
 #define SDU_PARAM_LEN 12
 static int gdm_usb_sdu_send(void *priv_dev, void *data, int len,
-                               unsigned int dftEpsId, unsigned int epsId,
-                               void (*cb)(void *data), void *cb_data,
+                           unsigned int dftEpsId, unsigned int epsId,
+                           void (*cb)(void *data), void *cb_data,
                            int dev_idx, int nic_type)
 {
        struct lte_udev *udev = priv_dev;
@@ -732,7 +732,7 @@ static int gdm_usb_sdu_send(void *priv_dev, void *data, int len,
        t_sdu = get_tx_sdu_struct(tx, &no_spc);
        spin_unlock_irqrestore(&tx->lock, flags);
 
-       if (t_sdu == NULL) {
+       if (!t_sdu) {
                pr_err("sdu send - free list empty\n");
                return TX_NO_SPC;
        }
@@ -745,7 +745,7 @@ static int gdm_usb_sdu_send(void *priv_dev, void *data, int len,
        } else {
            send_len = len - ETH_HLEN;
            send_len += SDU_PARAM_LEN;
-           memcpy(sdu->data, data+ETH_HLEN, len-ETH_HLEN);
+           memcpy(sdu->data, data + ETH_HLEN, len - ETH_HLEN);
        }
 
        sdu->len = gdm_cpu_to_dev16(&udev->gdm_ed, send_len);
@@ -769,7 +769,7 @@ static int gdm_usb_sdu_send(void *priv_dev, void *data, int len,
 }
 
 static int gdm_usb_hci_send(void *priv_dev, void *data, int len,
-                       void (*cb)(void *data), void *cb_data)
+                           void (*cb)(void *data), void *cb_data)
 {
        struct lte_udev *udev = priv_dev;
        struct tx_cxt *tx = &udev->tx;
@@ -782,7 +782,7 @@ static int gdm_usb_hci_send(void *priv_dev, void *data, int len,
        }
 
        t = alloc_tx_struct(len);
-       if (t == NULL) {
+       if (!t) {
                pr_err("hci_send - out of memory\n");
                return -ENOMEM;
        }
@@ -810,7 +810,7 @@ static struct gdm_endian *gdm_usb_get_endian(void *priv_dev)
 }
 
 static int gdm_usb_probe(struct usb_interface *intf,
-       const struct usb_device_id *id)
+                        const struct usb_device_id *id)
 {
        int ret = 0;
        struct phy_dev *phy_dev = NULL;
@@ -830,11 +830,11 @@ static int gdm_usb_probe(struct usb_interface *intf,
                return -ENODEV;
        }
 
-       phy_dev = kzalloc(sizeof(struct phy_dev), GFP_KERNEL);
+       phy_dev = kzalloc(sizeof(*phy_dev), GFP_KERNEL);
        if (!phy_dev)
                return -ENOMEM;
 
-       udev = kzalloc(sizeof(struct lte_udev), GFP_KERNEL);
+       udev = kzalloc(sizeof(*udev), GFP_KERNEL);
        if (!udev) {
                ret = -ENOMEM;
                goto err_udev;
@@ -1006,11 +1006,11 @@ static int __init gdm_usb_lte_init(void)
        }
 
        usb_tx_wq = create_workqueue("usb_tx_wq");
-       if (usb_tx_wq == NULL)
+       if (!usb_tx_wq)
                return -1;
 
        usb_rx_wq = create_workqueue("usb_rx_wq");
-       if (usb_rx_wq == NULL)
+       if (!usb_rx_wq)
                return -1;
 
        return usb_register(&gdm_usb_lte_driver);
index 59a18304ef4a592830b3800ffcd4ecffb0903951..92254fdaae1eec9564fb60f4832883e2357715db 100644 (file)
@@ -34,8 +34,8 @@ static struct semaphore netlink_mutex;
 #define ND_NLMSG_SPACE(len)    (NLMSG_SPACE(len) + ND_IFINDEX_LEN)
 #define ND_NLMSG_DATA(nlh)     ((void *)((char *)NLMSG_DATA(nlh) + \
                                                  ND_IFINDEX_LEN))
-#define ND_NLMSG_S_LEN(len)    (len+ND_IFINDEX_LEN)
-#define ND_NLMSG_R_LEN(nlh)    (nlh->nlmsg_len-ND_IFINDEX_LEN)
+#define ND_NLMSG_S_LEN(len)    (len + ND_IFINDEX_LEN)
+#define ND_NLMSG_R_LEN(nlh)    (nlh->nlmsg_len - ND_IFINDEX_LEN)
 #define ND_NLMSG_IFIDX(nlh)    NLMSG_DATA(nlh)
 #define ND_MAX_MSG_LEN         (1024 * 32)
 
@@ -122,7 +122,7 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
        if (group > ND_MAX_GROUP)
                return -EINVAL;
 
-       if (!netlink_has_listeners(sock, group+1))
+       if (!netlink_has_listeners(sock, group + 1))
                return -ESRCH;
 
        skb = alloc_skb(NLMSG_SPACE(len), GFP_ATOMIC);
@@ -136,14 +136,14 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
        NETLINK_CB(skb).portid = 0;
        NETLINK_CB(skb).dst_group = 0;
 
-       ret = netlink_broadcast(sock, skb, 0, group+1, GFP_ATOMIC);
+       ret = netlink_broadcast(sock, skb, 0, group + 1, GFP_ATOMIC);
        if (!ret)
                return len;
 
        if (ret != -ESRCH)
                pr_err("nl broadcast g=%d, t=%d, l=%d, r=%d\n",
                       group, type, len, ret);
-       else if (netlink_has_listeners(sock, group+1))
+       else if (netlink_has_listeners(sock, group + 1))
                return -EAGAIN;
 
        return ret;
index 96bf2bf87ff4b657a8ba9770e553543a74878378..81feffa5784acf9f79bd3b1f2c10401d082d2d3c 100644 (file)
@@ -59,7 +59,7 @@ static void *alloc_qos_entry(void)
 
 static void free_qos_entry(void *entry)
 {
-       struct qos_entry_s *qentry = (struct qos_entry_s *)entry;
+       struct qos_entry_s *qentry = entry;
        unsigned long flags;
 
        spin_lock_irqsave(&qos_free_list.lock, flags);
@@ -190,7 +190,7 @@ static int get_qos_index(struct nic *nic, u8 *iph, u8 *tcpudph)
        int ip_ver, i;
        struct qos_cb_s *qcb = &nic->qos;
 
-       if (iph == NULL || tcpudph == NULL)
+       if (!iph || !tcpudph)
                return -1;
 
        ip_ver = (iph[0]>>4)&0xf;
index a5fd0794842ee0a9af21577a62b6b2f5ddc83e86..b0521da3c793178ddda39965723562644d7d8621 100644 (file)
@@ -173,12 +173,12 @@ static int init_sdio(struct sdiowm_dev *sdev)
        spin_lock_init(&tx->lock);
 
        tx->sdu_buf = kmalloc(SDU_TX_BUF_SIZE, GFP_KERNEL);
-       if (tx->sdu_buf == NULL)
+       if (!tx->sdu_buf)
                goto fail;
 
        for (i = 0; i < MAX_NR_SDU_BUF; i++) {
                t = alloc_tx_struct(tx);
-               if (t == NULL) {
+               if (!t) {
                        ret = -ENOMEM;
                        goto fail;
                }
@@ -192,7 +192,7 @@ static int init_sdio(struct sdiowm_dev *sdev)
 
        for (i = 0; i < MAX_NR_RX_BUF; i++) {
                r = alloc_rx_struct(rx);
-               if (r == NULL) {
+               if (!r) {
                        ret = -ENOMEM;
                        goto fail;
                }
@@ -200,7 +200,7 @@ static int init_sdio(struct sdiowm_dev *sdev)
        }
 
        rx->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
-       if (rx->rx_buf == NULL)
+       if (!rx->rx_buf)
                goto fail;
 
        return 0;
@@ -359,7 +359,7 @@ static void do_tx(struct work_struct *work)
                is_sdu = 1;
        }
 
-       if (!is_sdu && t == NULL) {
+       if (!is_sdu && !t) {
                spin_unlock_irqrestore(&tx->lock, flags);
                return;
        }
@@ -393,7 +393,7 @@ static int gdm_sdio_send(void *priv_dev, void *data, int len,
        cmd_evt = (pkt[0] << 8) | pkt[1];
        if (cmd_evt == WIMAX_TX_SDU) {
                t = get_tx_struct(tx, &no_spc);
-               if (t == NULL) {
+               if (!t) {
                        /* This case must not happen. */
                        spin_unlock_irqrestore(&tx->lock, flags);
                        return -ENOSPC;
@@ -407,7 +407,7 @@ static int gdm_sdio_send(void *priv_dev, void *data, int len,
                t->cb_data = cb_data;
        } else {
                t = alloc_tx_struct(tx);
-               if (t == NULL) {
+               if (!t) {
                        spin_unlock_irqrestore(&tx->lock, flags);
                        return -ENOMEM;
                }
@@ -581,7 +581,7 @@ static int gdm_sdio_receive(void *priv_dev,
 
        spin_lock_irqsave(&rx->lock, flags);
        r = get_rx_struct(rx);
-       if (r == NULL) {
+       if (!r) {
                spin_unlock_irqrestore(&rx->lock, flags);
                return -ENOMEM;
        }
@@ -615,12 +615,12 @@ static int sdio_wimax_probe(struct sdio_func *func,
                return ret;
 
        phy_dev = kzalloc(sizeof(*phy_dev), GFP_KERNEL);
-       if (phy_dev == NULL) {
+       if (!phy_dev) {
                ret = -ENOMEM;
                goto out;
        }
        sdev = kzalloc(sizeof(*sdev), GFP_KERNEL);
-       if (sdev == NULL) {
+       if (!sdev) {
                ret = -ENOMEM;
                goto out;
        }
index eac2f3478bb99810921c888019fd4d4bf3ffec40..16e497d9d0cf424de81f40d7baca97d5a74493a8 100644 (file)
@@ -139,7 +139,7 @@ static struct usb_rx *get_rx_struct(struct rx_cxt *rx)
 
        if (list_empty(&rx->free_list)) {
                r = alloc_rx_struct(rx);
-               if (r == NULL)
+               if (!r)
                        return NULL;
 
                list_add(&r->list, &rx->free_list);
@@ -224,7 +224,7 @@ static int init_usb(struct usbwm_dev *udev)
        spin_lock_irqsave(&tx->lock, flags);
        for (i = 0; i < MAX_NR_SDU_BUF; i++) {
                t = alloc_tx_struct(tx);
-               if (t == NULL) {
+               if (!t) {
                        spin_unlock_irqrestore(&tx->lock, flags);
                        ret = -ENOMEM;
                        goto fail;
@@ -234,7 +234,7 @@ static int init_usb(struct usbwm_dev *udev)
        spin_unlock_irqrestore(&tx->lock, flags);
 
        r = alloc_rx_struct(rx);
-       if (r == NULL) {
+       if (!r) {
                ret = -ENOMEM;
                goto fail;
        }
@@ -313,7 +313,7 @@ static int gdm_usb_send(void *priv_dev, void *data, int len,
        cmd_evt = (pkt[0] << 8) | pkt[1];
        if (cmd_evt == WIMAX_TX_SDU) {
                t = get_tx_struct(tx, &no_spc);
-               if (t == NULL) {
+               if (!t) {
                        /* This case must not happen. */
                        spin_unlock_irqrestore(&tx->lock, flags);
                        return -ENOSPC;
@@ -321,7 +321,7 @@ static int gdm_usb_send(void *priv_dev, void *data, int len,
                list_add_tail(&t->list, &tx->sdu_list);
        } else {
                t = alloc_tx_struct(tx);
-               if (t == NULL) {
+               if (!t) {
                        spin_unlock_irqrestore(&tx->lock, flags);
                        return -ENOMEM;
                }
@@ -478,7 +478,7 @@ static int gdm_usb_receive(void *priv_dev,
        r = get_rx_struct(rx);
        spin_unlock_irqrestore(&rx->lock, flags);
 
-       if (r == NULL)
+       if (!r)
                return -ENOMEM;
 
        r->callback = cb;
@@ -558,12 +558,12 @@ static int gdm_usb_probe(struct usb_interface *intf,
        }
 
        phy_dev = kzalloc(sizeof(*phy_dev), GFP_KERNEL);
-       if (phy_dev == NULL) {
+       if (!phy_dev) {
                ret = -ENOMEM;
                goto out;
        }
        udev = kzalloc(sizeof(*udev), GFP_KERNEL);
-       if (udev == NULL) {
+       if (!udev) {
                ret = -ENOMEM;
                goto out;
        }
index 08290d901b0c88c04eae7702020eea5e8727a947..d9ddced96e194f4020e443ea4faf6e89e512bb71 100644 (file)
@@ -62,7 +62,7 @@ static inline int gdm_wimax_header(struct sk_buff **pskb)
                struct sk_buff *skb2;
 
                skb2 = skb_realloc_headroom(skb, HCI_HEADER_SIZE);
-               if (skb2 == NULL)
+               if (!skb2)
                        return -ENOMEM;
                if (skb->sk)
                        skb_set_owner_w(skb2, skb->sk);
@@ -339,7 +339,7 @@ static void gdm_wimax_ind_if_updown(struct net_device *dev, int if_up)
 static int gdm_wimax_open(struct net_device *dev)
 {
        struct nic *nic = netdev_priv(dev);
-       struct fsm_s *fsm = (struct fsm_s *)nic->sdk_data[SIOC_DATA_FSM].buf;
+       struct fsm_s *fsm = nic->sdk_data[SIOC_DATA_FSM].buf;
 
        netif_start_queue(dev);
 
@@ -351,7 +351,7 @@ static int gdm_wimax_open(struct net_device *dev)
 static int gdm_wimax_close(struct net_device *dev)
 {
        struct nic *nic = netdev_priv(dev);
-       struct fsm_s *fsm = (struct fsm_s *)nic->sdk_data[SIOC_DATA_FSM].buf;
+       struct fsm_s *fsm = nic->sdk_data[SIOC_DATA_FSM].buf;
 
        netif_stop_queue(dev);
 
@@ -378,7 +378,7 @@ static int gdm_wimax_ioctl_get_data(struct data_s *dst, struct data_s *src)
        if (src->size) {
                if (!dst->buf)
                        return -EINVAL;
-               if (copy_to_user((void __user *)dst->buf, src->buf, size))
+               if (copy_to_user(dst->buf, src->buf, size))
                        return -EFAULT;
        }
        return 0;
@@ -397,11 +397,11 @@ static int gdm_wimax_ioctl_set_data(struct data_s *dst, struct data_s *src)
        if (!(dst->buf && dst->size == src->size)) {
                kdelete(&dst->buf);
                dst->buf = kmalloc(src->size, GFP_KERNEL);
-               if (dst->buf == NULL)
+               if (!dst->buf)
                        return -ENOMEM;
        }
 
-       if (copy_from_user(dst->buf, (void __user *)src->buf, src->size)) {
+       if (copy_from_user(dst->buf, src->buf, src->size)) {
                kdelete(&dst->buf);
                return -EFAULT;
        }
@@ -435,7 +435,7 @@ static void gdm_wimax_ind_fsm_update(struct net_device *dev, struct fsm_s *fsm)
 static void gdm_update_fsm(struct net_device *dev, struct fsm_s *new_fsm)
 {
        struct nic *nic = netdev_priv(dev);
-       struct fsm_s *cur_fsm = (struct fsm_s *)
+       struct fsm_s *cur_fsm =
                                        nic->sdk_data[SIOC_DATA_FSM].buf;
 
        if (!cur_fsm)
@@ -483,7 +483,7 @@ static int gdm_wimax_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                                 * before gdm_wimax_ioctl_set_data is called.
                                 */
                                gdm_update_fsm(dev,
-                                              (struct fsm_s *)req->data.buf);
+                                              req->data.buf);
                        }
                        ret = gdm_wimax_ioctl_set_data(
                                &nic->sdk_data[req->data_id], &req->data);
@@ -581,8 +581,8 @@ static int gdm_wimax_get_prepared_info(struct net_device *dev, char *buf,
                }
 
                pos += gdm_wimax_hci_get_tlv(&buf[pos], &T, &L, &V);
-               if (T == TLV_T(T_MAC_ADDRESS)) {
-                       if (L != dev->addr_len) {
+               if (TLV_T(T_MAC_ADDRESS) == T) {
+                       if (dev->addr_len != L) {
                                netdev_err(dev,
                                           "%s Invalid information result T/L [%x/%d]\n",
                                           __func__, T, L);
@@ -798,7 +798,7 @@ cleanup:
 void unregister_wimax_device(struct phy_dev *phy_dev)
 {
        struct nic *nic = netdev_priv(phy_dev->netdev);
-       struct fsm_s *fsm = (struct fsm_s *)nic->sdk_data[SIOC_DATA_FSM].buf;
+       struct fsm_s *fsm = nic->sdk_data[SIOC_DATA_FSM].buf;
 
        if (fsm)
                fsm->m_status = M_INIT;
index 2c02842ac5da1c5f5981b7c3686ed45aaae30bba..ba94b5f13bb264a57b0e6ed9b4d8b09c3785a59d 100644 (file)
@@ -72,7 +72,7 @@ static int download_image(struct sdio_func *func, const char *img_name)
        }
 
        buf = kmalloc(DOWNLOAD_SIZE + TYPE_A_HEADER_SIZE, GFP_KERNEL);
-       if (buf == NULL)
+       if (!buf)
                return -ENOMEM;
 
        img_len = firm->size;
@@ -139,7 +139,7 @@ int sdio_boot(struct sdio_func *func)
        const char *rfs_name = FW_DIR FW_RFS;
 
        tx_buf = kmalloc(YMEM0_SIZE, GFP_KERNEL);
-       if (tx_buf == NULL)
+       if (!tx_buf)
                return -ENOMEM;
 
        ret = download_image(func, krn_name);
index 3ccc447730e88b23206e261745ffadfd4d01585e..39ca34031a6b7d662d0c071a51e0a4e3cc967ce3 100644 (file)
@@ -159,8 +159,10 @@ int usb_boot(struct usb_device *usbdev, u16 pid)
        }
 
        tx_buf = kmalloc(DOWNLOAD_SIZE, GFP_KERNEL);
-       if (tx_buf == NULL)
+       if (!tx_buf) {
+               release_firmware(firm);
                return -ENOMEM;
+       }
 
        if (firm->size < sizeof(hdr)) {
                dev_err(&usbdev->dev, "Cannot read the image info.\n");
@@ -285,8 +287,10 @@ static int em_download_image(struct usb_device *usbdev, const char *img_name,
        }
 
        buf = kmalloc(DOWNLOAD_CHUCK + pad_size, GFP_KERNEL);
-       if (buf == NULL)
+       if (!buf) {
+               release_firmware(firm);
                return -ENOMEM;
+       }
 
        strcpy(buf+pad_size, type_string);
        ret = gdm_wibro_send(usbdev, buf, strlen(type_string)+pad_size);
index 66ae48fcc2b20e9ffa6818b4bf408bbc80f4afb3..623353db5a08ed019cd2f6d9d8bd8bd983d93067 100644 (file)
@@ -48,7 +48,7 @@ static u32 goldfish_nand_cmd_with_params(struct mtd_info *mtd,
        struct cmd_params *cps = nand->cmd_params;
        unsigned char __iomem  *base = nand->base;
 
-       if (cps == NULL)
+       if (!cps)
                return -1;
 
        switch (cmd) {
@@ -379,7 +379,7 @@ static int goldfish_nand_probe(struct platform_device *pdev)
        unsigned char __iomem  *base;
 
        r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (r == NULL)
+       if (!r)
                return -ENODEV;
 
        base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE);
index fe7f47c7a5c881670de0a174ac551c03837d58f0..43aeba3a4c8f662e94cfcfa3f0b85a1cde7ebe2c 100644 (file)
@@ -66,11 +66,11 @@ enum nand_reg {
 };
 
 struct cmd_params {
-       uint32_t dev;
-       uint32_t addr_low;
-       uint32_t addr_high;
-       uint32_t transfer_size;
+       u32 dev;
+       u32 addr_low;
+       u32 addr_high;
+       u32 transfer_size;
        unsigned long data;
-       uint32_t result;
+       u32 result;
 };
 #endif
index 24d90b35d669898bf39522405397f9a6fb6796c9..7939ae6378d7876efc1bd162a7185878fb365616 100644 (file)
@@ -406,8 +406,10 @@ static int lis3l02dq_initial_setup(struct iio_dev *indio_dev)
                goto err_ret;
        }
 
-       /* Read back to check this has worked acts as loose test of correct
-        * chip */
+       /*
+        * Read back to check this has worked acts as loose test of correct
+        * chip
+        */
        ret = lis3l02dq_spi_read_reg_8(indio_dev,
                                       LIS3L02DQ_REG_CTRL_1_ADDR,
                                       &valtest);
@@ -565,7 +567,7 @@ static int lis3l02dq_read_event_config(struct iio_dev *indio_dev,
 {
        u8 val;
        int ret;
-       u8 mask = (1 << (chan->channel2*2 + (dir == IIO_EV_DIR_RISING)));
+       u8 mask = (1 << (chan->channel2 * 2 + (dir == IIO_EV_DIR_RISING)));
 
        ret = lis3l02dq_spi_read_reg_8(indio_dev,
                                       LIS3L02DQ_REG_WAKE_UP_CFG_ADDR,
@@ -620,7 +622,7 @@ static int lis3l02dq_write_event_config(struct iio_dev *indio_dev,
        u8 val, control;
        u8 currentlyset;
        bool changed = false;
-       u8 mask = (1 << (chan->channel2*2 + (dir == IIO_EV_DIR_RISING)));
+       u8 mask = (1 << (chan->channel2 * 2 + (dir == IIO_EV_DIR_RISING)));
 
        mutex_lock(&indio_dev->mlock);
        /* read current control */
index b892f2cf5f9ef1bd2ed7acf8197c4ceece3ec4c3..50c162e0c31f74fcaa03507c871fd7e0b3275826 100644 (file)
@@ -69,25 +69,25 @@ static int lis3l02dq_read_all(struct iio_dev *indio_dev, u8 *rx_array)
 
        mutex_lock(&st->buf_lock);
 
-       for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++)
+       for (i = 0; i < ARRAY_SIZE(read_all_tx_array) / 4; i++)
                if (test_bit(i, indio_dev->active_scan_mask)) {
                        /* lower byte */
-                       xfers[j].tx_buf = st->tx + 2*j;
-                       st->tx[2*j] = read_all_tx_array[i*4];
-                       st->tx[2*j + 1] = 0;
+                       xfers[j].tx_buf = st->tx + (2 * j);
+                       st->tx[2 * j] = read_all_tx_array[i * 4];
+                       st->tx[2 * j + 1] = 0;
                        if (rx_array)
-                               xfers[j].rx_buf = rx_array + j*2;
+                               xfers[j].rx_buf = rx_array + (j * 2);
                        xfers[j].bits_per_word = 8;
                        xfers[j].len = 2;
                        xfers[j].cs_change = 1;
                        j++;
 
                        /* upper byte */
-                       xfers[j].tx_buf = st->tx + 2*j;
-                       st->tx[2*j] = read_all_tx_array[i*4 + 2];
-                       st->tx[2*j + 1] = 0;
+                       xfers[j].tx_buf = st->tx + (2 * j);
+                       st->tx[2 * j] = read_all_tx_array[i * 4 + 2];
+                       st->tx[2 * j + 1] = 0;
                        if (rx_array)
-                               xfers[j].rx_buf = rx_array + j*2;
+                               xfers[j].rx_buf = rx_array + (j * 2);
                        xfers[j].bits_per_word = 8;
                        xfers[j].len = 2;
                        xfers[j].cs_change = 1;
@@ -127,11 +127,11 @@ static int lis3l02dq_get_buffer_element(struct iio_dev *indio_dev,
                return ret;
        }
        for (i = 0; i < scan_count; i++)
-               data[i] = combine_8_to_16(rx_array[i*4+1],
-                                       rx_array[i*4+3]);
+               data[i] = combine_8_to_16(rx_array[i * 4 + 1],
+                                       rx_array[i * 4 + 3]);
        kfree(rx_array);
 
-       return i*sizeof(data[0]);
+       return i * sizeof(data[0]);
 }
 
 static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
@@ -195,7 +195,8 @@ __lis3l02dq_write_data_ready_config(struct iio_dev *indio_dev, bool state)
        /* Enable requested */
        } else if (state && !currentlyset) {
                /* If not set, enable requested
-                * first disable all events */
+                * first disable all events
+                */
                ret = lis3l02dq_disable_all_events(indio_dev);
                if (ret < 0)
                        goto error_ret;
@@ -255,7 +256,8 @@ static int lis3l02dq_trig_try_reen(struct iio_trigger *trig)
        int i;
 
        /* If gpio still high (or high again)
-        * In theory possible we will need to do this several times */
+        * In theory possible we will need to do this several times
+        */
        for (i = 0; i < 5; i++)
                if (gpio_get_value(st->gpio))
                        lis3l02dq_read_all(indio_dev, NULL);
index fda646246215c2c3180610c59c86a6f286f9838d..02e930c55570237817e24c629b3f7df11fbd1fdd 100644 (file)
@@ -88,7 +88,7 @@ int sca3000_write_reg(struct sca3000_state *st, u8 address, u8 val)
 }
 
 int sca3000_read_data_short(struct sca3000_state *st,
-                           uint8_t reg_address_high,
+                           u8 reg_address_high,
                            int len)
 {
        struct spi_transfer xfer[2] = {
@@ -165,10 +165,9 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
  * Lock must be held.
  **/
 static int sca3000_write_ctrl_reg(struct sca3000_state *st,
-                                 uint8_t sel,
+                                 u8 sel,
                                  uint8_t val)
 {
-
        int ret;
 
        ret = sca3000_reg_lock_on(st);
@@ -374,7 +373,6 @@ error_ret:
        return ret;
 }
 
-
 /*
  * Not even vaguely standard attributes so defined here rather than
  * in the relevant IIO core headers
@@ -471,12 +469,13 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
                                return ret;
                        }
                        *val = (be16_to_cpup((__be16 *)st->rx) >> 3) & 0x1FFF;
-                       *val = ((*val) << (sizeof(*val)*8 - 13)) >>
-                               (sizeof(*val)*8 - 13);
+                       *val = ((*val) << (sizeof(*val) * 8 - 13)) >>
+                               (sizeof(*val) * 8 - 13);
                } else {
                        /* get the temperature when available */
                        ret = sca3000_read_data_short(st,
-                               SCA3000_REG_ADDR_TEMP_MSB, 2);
+                                                     SCA3000_REG_ADDR_TEMP_MSB,
+                                                     2);
                        if (ret < 0) {
                                mutex_unlock(&st->lock);
                                return ret;
@@ -511,8 +510,8 @@ static int sca3000_read_raw(struct iio_dev *indio_dev,
  * at all.
  **/
 static ssize_t sca3000_read_av_freq(struct device *dev,
-                            struct device_attribute *attr,
-                            char *buf)
+                                   struct device_attribute *attr,
+                                   char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct sca3000_state *st = iio_priv(indio_dev);
@@ -529,26 +528,27 @@ static ssize_t sca3000_read_av_freq(struct device *dev,
        case SCA3000_MEAS_MODE_NORMAL:
                len += sprintf(buf + len, "%d %d %d\n",
                               st->info->measurement_mode_freq,
-                              st->info->measurement_mode_freq/2,
-                              st->info->measurement_mode_freq/4);
+                              st->info->measurement_mode_freq / 2,
+                              st->info->measurement_mode_freq / 4);
                break;
        case SCA3000_MEAS_MODE_OP_1:
                len += sprintf(buf + len, "%d %d %d\n",
                               st->info->option_mode_1_freq,
-                              st->info->option_mode_1_freq/2,
-                              st->info->option_mode_1_freq/4);
+                              st->info->option_mode_1_freq / 2,
+                              st->info->option_mode_1_freq / 4);
                break;
        case SCA3000_MEAS_MODE_OP_2:
                len += sprintf(buf + len, "%d %d %d\n",
                               st->info->option_mode_2_freq,
-                              st->info->option_mode_2_freq/2,
-                              st->info->option_mode_2_freq/4);
+                              st->info->option_mode_2_freq / 2,
+                              st->info->option_mode_2_freq / 4);
                break;
        }
        return len;
 error_ret:
        return ret;
 }
+
 /**
  * __sca3000_get_base_freq() obtain mode specific base frequency
  *
@@ -582,8 +582,8 @@ error_ret:
  * sca3000_read_frequency() sysfs interface to get the current frequency
  **/
 static ssize_t sca3000_read_frequency(struct device *dev,
-                              struct device_attribute *attr,
-                              char *buf)
+                                     struct device_attribute *attr,
+                                     char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct sca3000_state *st = iio_priv(indio_dev);
@@ -605,10 +605,10 @@ static ssize_t sca3000_read_frequency(struct device *dev,
                        len = sprintf(buf, "%d\n", base_freq);
                        break;
                case 0x01:
-                       len = sprintf(buf, "%d\n", base_freq/2);
+                       len = sprintf(buf, "%d\n", base_freq / 2);
                        break;
                case 0x02:
-                       len = sprintf(buf, "%d\n", base_freq/4);
+                       len = sprintf(buf, "%d\n", base_freq / 4);
                        break;
        }
 
@@ -623,9 +623,9 @@ error_ret:
  * sca3000_set_frequency() sysfs interface to set the current frequency
  **/
 static ssize_t sca3000_set_frequency(struct device *dev,
-                             struct device_attribute *attr,
-                             const char *buf,
-                             size_t len)
+                                    struct device_attribute *attr,
+                                    const char *buf,
+                                    size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct sca3000_state *st = iio_priv(indio_dev);
@@ -650,9 +650,9 @@ static ssize_t sca3000_set_frequency(struct device *dev,
        /* clear the bits */
        ctrlval &= ~0x03;
 
-       if (val == base_freq/2) {
+       if (val == base_freq / 2) {
                ctrlval |= SCA3000_OUT_CTRL_BUF_DIV_2;
-       } else if (val == base_freq/4) {
+       } else if (val == base_freq / 4) {
                ctrlval |= SCA3000_OUT_CTRL_BUF_DIV_4;
        } else if (val != base_freq) {
                ret = -EINVAL;
@@ -849,9 +849,9 @@ static int sca3000_read_event_config(struct iio_dev *indio_dev,
        if (ret)
                goto error_ret;
 
-       if ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET)
+       if ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET) {
                ret = 0;
-       else {
+       else {
                ret = sca3000_read_ctrl_reg(st, SCA3000_REG_CTRL_SEL_MD_CTRL);
                if (ret < 0)
                        goto error_ret;
@@ -863,6 +863,7 @@ error_ret:
 
        return ret;
 }
+
 /**
  * sca3000_query_free_fall_mode() is free fall mode enabled
  **/
@@ -979,14 +980,14 @@ static int sca3000_write_event_config(struct iio_dev *indio_dev,
        if (ret)
                goto exit_point;
        /* if off and should be on */
-       if ((st->mo_det_use_count)
-           && ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET))
+       if ((st->mo_det_use_count) &&
+           ((st->rx[0] & protect_mask) != SCA3000_MEAS_MODE_MOT_DET))
                ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
                                        (st->rx[0] & ~protect_mask)
                                        | SCA3000_MEAS_MODE_MOT_DET);
        /* if on and should be off */
-       else if (!(st->mo_det_use_count)
-                && ((st->rx[0] & protect_mask) == SCA3000_MEAS_MODE_MOT_DET))
+       else if (!(st->mo_det_use_count) &&
+                ((st->rx[0] & protect_mask) == SCA3000_MEAS_MODE_MOT_DET))
                ret = sca3000_write_reg(st, SCA3000_REG_ADDR_MODE,
                                        (st->rx[0] & ~protect_mask));
 exit_point:
@@ -997,14 +998,14 @@ exit_point:
 
 /* Free fall detector related event attribute */
 static IIO_DEVICE_ATTR_NAMED(accel_xayaz_mag_falling_en,
-                            in_accel_x&y&z_mag_falling_en,
+                            in_accel_x & y & z_mag_falling_en,
                             S_IRUGO | S_IWUSR,
                             sca3000_query_free_fall_mode,
                             sca3000_set_free_fall_mode,
                             0);
 
 static IIO_CONST_ATTR_NAMED(accel_xayaz_mag_falling_period,
-                           in_accel_x&y&z_mag_falling_period,
+                           in_accel_x & y & z_mag_falling_period,
                            "0.226");
 
 static struct attribute *sca3000_event_attributes[] = {
index bd2c69f85949ba6ce40b80c588a2e6a4036964a2..20b878d35ea2eca2929d14af75243f360e330a59 100644 (file)
@@ -34,9 +34,9 @@
  */
 
 static int sca3000_read_data(struct sca3000_state *st,
-                           uint8_t reg_address_high,
-                           u8 **rx_p,
-                           int len)
+                            u8 reg_address_high,
+                            u8 **rx_p,
+                            int len)
 {
        int ret;
        struct spi_transfer xfer[2] = {
@@ -106,7 +106,7 @@ static int sca3000_read_first_n_hw_rb(struct iio_buffer *r,
         * i.e. number of time points * number of channels.
         */
        if (count > num_available * bytes_per_sample)
-               num_read = num_available*bytes_per_sample;
+               num_read = num_available * bytes_per_sample;
        else
                num_read = count;
 
@@ -160,9 +160,9 @@ static ssize_t sca3000_query_ring_int(struct device *dev,
  * sca3000_set_ring_int() set state of ring status interrupt
  **/
 static ssize_t sca3000_set_ring_int(struct device *dev,
-                                     struct device_attribute *attr,
-                                     const char *buf,
-                                     size_t len)
+                                   struct device_attribute *attr,
+                                   const char *buf,
+                                   size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct sca3000_state *st = iio_priv(indio_dev);
@@ -208,7 +208,7 @@ static ssize_t sca3000_show_buffer_scale(struct device *dev,
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct sca3000_state *st = iio_priv(indio_dev);
 
-       return sprintf(buf, "0.%06d\n", 4*st->info->scale);
+       return sprintf(buf, "0.%06d\n", 4 * st->info->scale);
 }
 
 static IIO_DEVICE_ATTR(in_accel_scale,
@@ -267,7 +267,7 @@ int sca3000_configure_ring(struct iio_dev *indio_dev)
        struct iio_buffer *buffer;
 
        buffer = sca3000_rb_allocate(indio_dev);
-       if (buffer == NULL)
+       if (!buffer)
                return -ENOMEM;
        indio_dev->modes |= INDIO_BUFFER_HARDWARE;
 
@@ -307,6 +307,7 @@ error_ret:
 
        return ret;
 }
+
 /**
  * sca3000_hw_ring_preenable() hw ring buffer preenable function
  *
index a3b76559a4f02d03f06da581078bb5d351927f62..bb40f37287426c4855a70b0b19b124802a52c284 100644 (file)
@@ -88,7 +88,6 @@
 #define AD7192_CLK_INT_CO              3 /* Internal 4.92 MHz Clock available
                                           * at the MCLK2 pin */
 
-
 /* Configuration Register Bit Designations (AD7192_REG_CONF) */
 
 #define AD7192_CONF_CHOP       BIT(23) /* CHOP enable */
 #define AD7192_GPOCON_P1DAT    BIT(1) /* P1 state */
 #define AD7192_GPOCON_P0DAT    BIT(0) /* P0 state */
 
-#define AD7192_INT_FREQ_MHz    4915200
+#define AD7192_INT_FREQ_MHZ    4915200
 
 /* NOTE:
  * The AD7190/2/5 features a dual use data out ready DOUT/RDY output.
@@ -201,7 +200,7 @@ static int ad7192_calibrate_all(struct ad7192_state *st)
 }
 
 static int ad7192_setup(struct ad7192_state *st,
-       const struct ad7192_platform_data *pdata)
+                       const struct ad7192_platform_data *pdata)
 {
        struct iio_dev *indio_dev = spi_get_drvdata(st->sd.spi);
        unsigned long long scale_uv;
@@ -224,19 +223,19 @@ static int ad7192_setup(struct ad7192_state *st,
 
        if (id != st->devid)
                dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X)\n",
-                       id);
+                        id);
 
        switch (pdata->clock_source_sel) {
        case AD7192_CLK_EXT_MCLK1_2:
        case AD7192_CLK_EXT_MCLK2:
-               st->mclk = AD7192_INT_FREQ_MHz;
+               st->mclk = AD7192_INT_FREQ_MHZ;
                break;
        case AD7192_CLK_INT:
        case AD7192_CLK_INT_CO:
-               if (pdata->ext_clk_Hz)
-                       st->mclk = pdata->ext_clk_Hz;
+               if (pdata->ext_clk_hz)
+                       st->mclk = pdata->ext_clk_hz;
                else
-                       st->mclk = AD7192_INT_FREQ_MHz;
+                       st->mclk = AD7192_INT_FREQ_MHZ;
                        break;
        default:
                ret = -EINVAL;
@@ -307,8 +306,8 @@ out:
 }
 
 static ssize_t ad7192_read_frequency(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                                    struct device_attribute *attr,
+                                    char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7192_state *st = iio_priv(indio_dev);
@@ -318,9 +317,9 @@ static ssize_t ad7192_read_frequency(struct device *dev,
 }
 
 static ssize_t ad7192_write_frequency(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
+                                     struct device_attribute *attr,
+                                     const char *buf,
+                                     size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7192_state *st = iio_priv(indio_dev);
@@ -359,8 +358,9 @@ static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
                ad7192_read_frequency,
                ad7192_write_frequency);
 
-static ssize_t ad7192_show_scale_available(struct device *dev,
-                       struct device_attribute *attr, char *buf)
+static ssize_t
+ad7192_show_scale_available(struct device *dev,
+                           struct device_attribute *attr, char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7192_state *st = iio_priv(indio_dev);
@@ -383,8 +383,8 @@ static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO,
                       ad7192_show_scale_available, NULL, 0);
 
 static ssize_t ad7192_show_ac_excitation(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                                        struct device_attribute *attr,
+                                        char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7192_state *st = iio_priv(indio_dev);
@@ -393,8 +393,8 @@ static ssize_t ad7192_show_ac_excitation(struct device *dev,
 }
 
 static ssize_t ad7192_show_bridge_switch(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                                        struct device_attribute *attr,
+                                        char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7192_state *st = iio_priv(indio_dev);
@@ -403,9 +403,9 @@ static ssize_t ad7192_show_bridge_switch(struct device *dev,
 }
 
 static ssize_t ad7192_set(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
+                         struct device_attribute *attr,
+                         const char *buf,
+                         size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7192_state *st = iio_priv(indio_dev);
@@ -423,7 +423,7 @@ static ssize_t ad7192_set(struct device *dev,
                return -EBUSY;
        }
 
-       switch ((u32) this_attr->address) {
+       switch ((u32)this_attr->address) {
        case AD7192_REG_GPOCON:
                if (val)
                        st->gpocon |= AD7192_GPOCON_BPDSW;
@@ -529,10 +529,10 @@ static int ad7192_read_raw(struct iio_dev *indio_dev,
 }
 
 static int ad7192_write_raw(struct iio_dev *indio_dev,
-                              struct iio_chan_spec const *chan,
-                              int val,
-                              int val2,
-                              long mask)
+                           struct iio_chan_spec const *chan,
+                           int val,
+                           int val2,
+                           long mask)
 {
        struct ad7192_state *st = iio_priv(indio_dev);
        int ret, i;
@@ -556,7 +556,7 @@ static int ad7192_write_raw(struct iio_dev *indio_dev,
                                if (tmp == st->conf)
                                        break;
                                ad_sd_write_reg(&st->sd, AD7192_REG_CONF,
-                                                3, st->conf);
+                                               3, st->conf);
                                ad7192_calibrate_all(st);
                                break;
                        }
@@ -571,8 +571,8 @@ static int ad7192_write_raw(struct iio_dev *indio_dev,
 }
 
 static int ad7192_write_raw_get_fmt(struct iio_dev *indio_dev,
-                              struct iio_chan_spec const *chan,
-                              long mask)
+                                   struct iio_chan_spec const *chan,
+                                   long mask)
 {
        return IIO_VAL_INT_PLUS_NANO;
 }
@@ -625,7 +625,7 @@ static int ad7192_probe(struct spi_device *spi)
        }
 
        indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-       if (indio_dev == NULL)
+       if (!indio_dev)
                return -ENOMEM;
 
        st = iio_priv(indio_dev);
@@ -639,7 +639,7 @@ static int ad7192_probe(struct spi_device *spi)
                voltage_uv = regulator_get_voltage(st->reg);
        }
 
-       if (pdata && pdata->vref_mv)
+       if (pdata->vref_mv)
                st->int_vref_mv = pdata->vref_mv;
        else if (voltage_uv)
                st->int_vref_mv = voltage_uv / 1000;
index a0a5b61a41f14811851f7d9827188d91fa2b4c8c..7433a43c26113dda136d79f385e0d5f394824cbd 100644 (file)
@@ -34,7 +34,7 @@
 struct ad7192_platform_data {
        u16             vref_mv;
        u8              clock_source_sel;
-       u32             ext_clk_Hz;
+       u32             ext_clk_hz;
        bool            refin2_en;
        bool            rej60_en;
        bool            sinc3_en;
index 8a7c8737adc4d1cd2c0589cab9fed297241ce6aa..35acb1a4669b30b1cbe0fc565ab3a797b4dc04ae 100644 (file)
@@ -89,7 +89,7 @@
 
 #define AD7280A_ALL_CELLS                              (0xAD << 16)
 
-#define AD7280A_MAX_SPI_CLK_Hz         700000 /* < 1MHz */
+#define AD7280A_MAX_SPI_CLK_HZ         700000 /* < 1MHz */
 #define AD7280A_MAX_CHAIN              8
 #define AD7280A_CELLS_PER_DEV          6
 #define AD7280A_BITS                   12
@@ -224,24 +224,24 @@ static int ad7280_write(struct ad7280_state *st, unsigned devaddr,
 }
 
 static int ad7280_read(struct ad7280_state *st, unsigned devaddr,
-                       unsigned addr)
+                      unsigned addr)
 {
        int ret;
        unsigned tmp;
 
        /* turns off the read operation on all parts */
        ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1,
-                       AD7280A_CTRL_HB_CONV_INPUT_ALL |
-                       AD7280A_CTRL_HB_CONV_RES_READ_NO |
-                       st->ctrl_hb);
+                          AD7280A_CTRL_HB_CONV_INPUT_ALL |
+                          AD7280A_CTRL_HB_CONV_RES_READ_NO |
+                          st->ctrl_hb);
        if (ret)
                return ret;
 
        /* turns on the read operation on the addressed part */
        ret = ad7280_write(st, devaddr, AD7280A_CONTROL_HB, 0,
-                       AD7280A_CTRL_HB_CONV_INPUT_ALL |
-                       AD7280A_CTRL_HB_CONV_RES_READ_ALL |
-                       st->ctrl_hb);
+                          AD7280A_CTRL_HB_CONV_INPUT_ALL |
+                          AD7280A_CTRL_HB_CONV_RES_READ_ALL |
+                          st->ctrl_hb);
        if (ret)
                return ret;
 
@@ -272,17 +272,17 @@ static int ad7280_read_channel(struct ad7280_state *st, unsigned devaddr,
                return ret;
 
        ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1,
-                       AD7280A_CTRL_HB_CONV_INPUT_ALL |
-                       AD7280A_CTRL_HB_CONV_RES_READ_NO |
-                       st->ctrl_hb);
+                          AD7280A_CTRL_HB_CONV_INPUT_ALL |
+                          AD7280A_CTRL_HB_CONV_RES_READ_NO |
+                          st->ctrl_hb);
        if (ret)
                return ret;
 
        ret = ad7280_write(st, devaddr, AD7280A_CONTROL_HB, 0,
-                       AD7280A_CTRL_HB_CONV_INPUT_ALL |
-                       AD7280A_CTRL_HB_CONV_RES_READ_ALL |
-                       AD7280A_CTRL_HB_CONV_START_CS |
-                       st->ctrl_hb);
+                          AD7280A_CTRL_HB_CONV_INPUT_ALL |
+                          AD7280A_CTRL_HB_CONV_RES_READ_ALL |
+                          AD7280A_CTRL_HB_CONV_START_CS |
+                          st->ctrl_hb);
        if (ret)
                return ret;
 
@@ -300,7 +300,7 @@ static int ad7280_read_channel(struct ad7280_state *st, unsigned devaddr,
 }
 
 static int ad7280_read_all_channels(struct ad7280_state *st, unsigned cnt,
-                            unsigned *array)
+                                   unsigned *array)
 {
        int i, ret;
        unsigned tmp, sum = 0;
@@ -311,10 +311,10 @@ static int ad7280_read_all_channels(struct ad7280_state *st, unsigned cnt,
                return ret;
 
        ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1,
-                       AD7280A_CTRL_HB_CONV_INPUT_ALL |
-                       AD7280A_CTRL_HB_CONV_RES_READ_ALL |
-                       AD7280A_CTRL_HB_CONV_START_CS |
-                       st->ctrl_hb);
+                          AD7280A_CTRL_HB_CONV_INPUT_ALL |
+                          AD7280A_CTRL_HB_CONV_RES_READ_ALL |
+                          AD7280A_CTRL_HB_CONV_START_CS |
+                          st->ctrl_hb);
        if (ret)
                return ret;
 
@@ -342,24 +342,24 @@ static int ad7280_chain_setup(struct ad7280_state *st)
        int ret;
 
        ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_LB, 1,
-                       AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN |
-                       AD7280A_CTRL_LB_LOCK_DEV_ADDR |
-                       AD7280A_CTRL_LB_MUST_SET |
-                       AD7280A_CTRL_LB_SWRST |
-                       st->ctrl_lb);
+                          AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN |
+                          AD7280A_CTRL_LB_LOCK_DEV_ADDR |
+                          AD7280A_CTRL_LB_MUST_SET |
+                          AD7280A_CTRL_LB_SWRST |
+                          st->ctrl_lb);
        if (ret)
                return ret;
 
        ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_LB, 1,
-                       AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN |
-                       AD7280A_CTRL_LB_LOCK_DEV_ADDR |
-                       AD7280A_CTRL_LB_MUST_SET |
-                       st->ctrl_lb);
+                          AD7280A_CTRL_LB_DAISY_CHAIN_RB_EN |
+                          AD7280A_CTRL_LB_LOCK_DEV_ADDR |
+                          AD7280A_CTRL_LB_MUST_SET |
+                          st->ctrl_lb);
        if (ret)
                return ret;
 
        ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_READ, 1,
-                       AD7280A_CONTROL_LB << 2);
+                          AD7280A_CONTROL_LB << 2);
        if (ret)
                return ret;
 
@@ -379,8 +379,8 @@ static int ad7280_chain_setup(struct ad7280_state *st)
 }
 
 static ssize_t ad7280_show_balance_sw(struct device *dev,
-                                       struct device_attribute *attr,
-                                       char *buf)
+                                     struct device_attribute *attr,
+                                     char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7280_state *st = iio_priv(indio_dev);
@@ -392,9 +392,9 @@ static ssize_t ad7280_show_balance_sw(struct device *dev,
 }
 
 static ssize_t ad7280_store_balance_sw(struct device *dev,
-                                        struct device_attribute *attr,
-                                        const char *buf,
-                                        size_t len)
+                                      struct device_attribute *attr,
+                                      const char *buf,
+                                      size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7280_state *st = iio_priv(indio_dev);
@@ -424,8 +424,8 @@ static ssize_t ad7280_store_balance_sw(struct device *dev,
 }
 
 static ssize_t ad7280_show_balance_timer(struct device *dev,
-                                       struct device_attribute *attr,
-                                       char *buf)
+                                        struct device_attribute *attr,
+                                        char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7280_state *st = iio_priv(indio_dev);
@@ -435,7 +435,7 @@ static ssize_t ad7280_show_balance_timer(struct device *dev,
 
        mutex_lock(&indio_dev->mlock);
        ret = ad7280_read(st, this_attr->address >> 8,
-                       this_attr->address & 0xFF);
+                         this_attr->address & 0xFF);
        mutex_unlock(&indio_dev->mlock);
 
        if (ret < 0)
@@ -447,9 +447,9 @@ static ssize_t ad7280_show_balance_timer(struct device *dev,
 }
 
 static ssize_t ad7280_store_balance_timer(struct device *dev,
-                                        struct device_attribute *attr,
-                                        const char *buf,
-                                        size_t len)
+                                         struct device_attribute *attr,
+                                         const char *buf,
+                                         size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7280_state *st = iio_priv(indio_dev);
@@ -488,12 +488,12 @@ static int ad7280_channel_init(struct ad7280_state *st)
 
        st->channels = kcalloc((st->slave_num + 1) * 12 + 2,
                               sizeof(*st->channels), GFP_KERNEL);
-       if (st->channels == NULL)
+       if (!st->channels)
                return -ENOMEM;
 
        for (dev = 0, cnt = 0; dev <= st->slave_num; dev++)
-               for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_AUX_ADC_6; ch++,
-                       cnt++) {
+               for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_AUX_ADC_6;
+                       ch++, cnt++) {
                        if (ch < AD7280A_AUX_ADC_1) {
                                st->channels[cnt].type = IIO_VOLTAGE;
                                st->channels[cnt].differential = 1;
@@ -550,7 +550,7 @@ static int ad7280_attr_init(struct ad7280_state *st)
        st->iio_attr = kcalloc(2, sizeof(*st->iio_attr) *
                               (st->slave_num + 1) * AD7280A_CELLS_PER_DEV,
                               GFP_KERNEL);
-       if (st->iio_attr == NULL)
+       if (!st->iio_attr)
                return -ENOMEM;
 
        for (dev = 0, cnt = 0; dev <= st->slave_num; dev++)
@@ -566,9 +566,9 @@ static int ad7280_attr_init(struct ad7280_state *st)
                                ad7280_store_balance_sw;
                        st->iio_attr[cnt].dev_attr.attr.name =
                                kasprintf(GFP_KERNEL,
-                                       "in%d-in%d_balance_switch_en",
-                                       (dev * AD7280A_CELLS_PER_DEV) + ch,
-                                       (dev * AD7280A_CELLS_PER_DEV) + ch + 1);
+                                         "in%d-in%d_balance_switch_en",
+                                         dev * AD7280A_CELLS_PER_DEV + ch,
+                                         dev * AD7280A_CELLS_PER_DEV + ch + 1);
                        ad7280_attributes[cnt] =
                                &st->iio_attr[cnt].dev_attr.attr;
                        cnt++;
@@ -582,9 +582,10 @@ static int ad7280_attr_init(struct ad7280_state *st)
                        st->iio_attr[cnt].dev_attr.store =
                                ad7280_store_balance_timer;
                        st->iio_attr[cnt].dev_attr.attr.name =
-                               kasprintf(GFP_KERNEL, "in%d-in%d_balance_timer",
-                                       (dev * AD7280A_CELLS_PER_DEV) + ch,
-                                       (dev * AD7280A_CELLS_PER_DEV) + ch + 1);
+                               kasprintf(GFP_KERNEL,
+                                         "in%d-in%d_balance_timer",
+                                         dev * AD7280A_CELLS_PER_DEV + ch,
+                                         dev * AD7280A_CELLS_PER_DEV + ch + 1);
                        ad7280_attributes[cnt] =
                                &st->iio_attr[cnt].dev_attr.attr;
                }
@@ -595,15 +596,15 @@ static int ad7280_attr_init(struct ad7280_state *st)
 }
 
 static ssize_t ad7280_read_channel_config(struct device *dev,
-                                       struct device_attribute *attr,
-                                       char *buf)
+                                         struct device_attribute *attr,
+                                         char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7280_state *st = iio_priv(indio_dev);
        struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
        unsigned val;
 
-       switch ((u32) this_attr->address) {
+       switch ((u32)this_attr->address) {
        case AD7280A_CELL_OVERVOLTAGE:
                val = 1000 + (st->cell_threshhigh * 1568) / 100;
                break;
@@ -624,9 +625,9 @@ static ssize_t ad7280_read_channel_config(struct device *dev,
 }
 
 static ssize_t ad7280_write_channel_config(struct device *dev,
-                                        struct device_attribute *attr,
-                                        const char *buf,
-                                        size_t len)
+                                          struct device_attribute *attr,
+                                          const char *buf,
+                                          size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7280_state *st = iio_priv(indio_dev);
@@ -639,7 +640,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev,
        if (ret)
                return ret;
 
-       switch ((u32) this_attr->address) {
+       switch ((u32)this_attr->address) {
        case AD7280A_CELL_OVERVOLTAGE:
        case AD7280A_CELL_UNDERVOLTAGE:
                val = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */
@@ -655,7 +656,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev,
        val = clamp(val, 0L, 0xFFL);
 
        mutex_lock(&indio_dev->mlock);
-       switch ((u32) this_attr->address) {
+       switch ((u32)this_attr->address) {
        case AD7280A_CELL_OVERVOLTAGE:
                st->cell_threshhigh = val;
                break;
@@ -686,7 +687,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
        int i, ret;
 
        channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL);
-       if (channels == NULL)
+       if (!channels)
                return IRQ_HANDLED;
 
        ret = ad7280_read_all_channels(st, st->scan_cnt, channels);
@@ -698,39 +699,41 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
                        if (((channels[i] >> 11) & 0xFFF) >=
                                st->cell_threshhigh)
                                iio_push_event(indio_dev,
-                                       IIO_EVENT_CODE(IIO_VOLTAGE,
-                                                      1,
-                                                      0,
-                                                      IIO_EV_DIR_RISING,
-                                                      IIO_EV_TYPE_THRESH,
-                                                      0, 0, 0),
-                                       iio_get_time_ns());
+                                              IIO_EVENT_CODE(IIO_VOLTAGE,
+                                                       1,
+                                                       0,
+                                                       IIO_EV_DIR_RISING,
+                                                       IIO_EV_TYPE_THRESH,
+                                                       0, 0, 0),
+                                              iio_get_time_ns());
                        else if (((channels[i] >> 11) & 0xFFF) <=
                                st->cell_threshlow)
                                iio_push_event(indio_dev,
-                                       IIO_EVENT_CODE(IIO_VOLTAGE,
-                                                      1,
-                                                      0,
-                                                      IIO_EV_DIR_FALLING,
-                                                      IIO_EV_TYPE_THRESH,
-                                                      0, 0, 0),
-                                       iio_get_time_ns());
+                                              IIO_EVENT_CODE(IIO_VOLTAGE,
+                                                       1,
+                                                       0,
+                                                       IIO_EV_DIR_FALLING,
+                                                       IIO_EV_TYPE_THRESH,
+                                                       0, 0, 0),
+                                              iio_get_time_ns());
                } else {
                        if (((channels[i] >> 11) & 0xFFF) >= st->aux_threshhigh)
                                iio_push_event(indio_dev,
-                                       IIO_UNMOD_EVENT_CODE(IIO_TEMP,
-                                       0,
-                                       IIO_EV_TYPE_THRESH,
-                                       IIO_EV_DIR_RISING),
-                                       iio_get_time_ns());
+                                              IIO_UNMOD_EVENT_CODE(
+                                                       IIO_TEMP,
+                                                       0,
+                                                       IIO_EV_TYPE_THRESH,
+                                                       IIO_EV_DIR_RISING),
+                                              iio_get_time_ns());
                        else if (((channels[i] >> 11) & 0xFFF) <=
                                st->aux_threshlow)
                                iio_push_event(indio_dev,
-                                       IIO_UNMOD_EVENT_CODE(IIO_TEMP,
-                                       0,
-                                       IIO_EV_TYPE_THRESH,
-                                       IIO_EV_DIR_FALLING),
-                                       iio_get_time_ns());
+                                              IIO_UNMOD_EVENT_CODE(
+                                                       IIO_TEMP,
+                                                       0,
+                                                       IIO_EV_TYPE_THRESH,
+                                                       IIO_EV_DIR_FALLING),
+                                              iio_get_time_ns());
                }
        }
 
@@ -766,7 +769,6 @@ static IIO_DEVICE_ATTR(in_temp_thresh_high_value,
                ad7280_write_channel_config,
                AD7280A_AUX_ADC_OVERVOLTAGE);
 
-
 static struct attribute *ad7280_event_attributes[] = {
        &iio_dev_attr_in_thresh_low_value.dev_attr.attr,
        &iio_dev_attr_in_thresh_high_value.dev_attr.attr,
@@ -817,7 +819,7 @@ static int ad7280_read_raw(struct iio_dev *indio_dev,
 }
 
 static const struct iio_info ad7280_info = {
-       .read_raw = &ad7280_read_raw,
+       .read_raw = ad7280_read_raw,
        .event_attrs = &ad7280_event_attrs_group,
        .attrs = &ad7280_attrs_group,
        .driver_module = THIS_MODULE,
@@ -839,7 +841,7 @@ static int ad7280_probe(struct spi_device *spi)
        struct iio_dev *indio_dev;
 
        indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-       if (indio_dev == NULL)
+       if (!indio_dev)
                return -ENOMEM;
 
        st = iio_priv(indio_dev);
@@ -851,7 +853,7 @@ static int ad7280_probe(struct spi_device *spi)
 
        ad7280_crc8_build_table(st->crc_tab);
 
-       st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_Hz;
+       st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ;
        st->spi->mode = SPI_MODE_1;
        spi_setup(st->spi);
 
@@ -955,7 +957,7 @@ static int ad7280_remove(struct spi_device *spi)
        iio_device_unregister(indio_dev);
 
        ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1,
-                       AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb);
+                    AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb);
 
        kfree(st->channels);
        kfree(st->iio_attr);
index bf2c8013134c1f66dd9da22017077660c55f3ede..5796ed2409d0aff3938c13cfb331c0450d620e04 100644 (file)
@@ -97,7 +97,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
 
                if (ret < 0)
                        return ret;
-               *val = (short) ret;
+               *val = (short)ret;
                return IIO_VAL_INT;
        case IIO_CHAN_INFO_SCALE:
                *val = st->range * 2;
@@ -108,7 +108,7 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
 }
 
 static ssize_t ad7606_show_range(struct device *dev,
-                       struct device_attribute *attr, char *buf)
+                                struct device_attribute *attr, char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7606_state *st = iio_priv(indio_dev);
@@ -117,7 +117,8 @@ static ssize_t ad7606_show_range(struct device *dev,
 }
 
 static ssize_t ad7606_store_range(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7606_state *st = iio_priv(indio_dev);
@@ -145,7 +146,8 @@ static IIO_DEVICE_ATTR(in_voltage_range, S_IRUGO | S_IWUSR,
 static IIO_CONST_ATTR(in_voltage_range_available, "5000 10000");
 
 static ssize_t ad7606_show_oversampling_ratio(struct device *dev,
-                       struct device_attribute *attr, char *buf)
+                                             struct device_attribute *attr,
+                                             char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7606_state *st = iio_priv(indio_dev);
@@ -166,7 +168,8 @@ static int ad7606_oversampling_get_index(unsigned val)
 }
 
 static ssize_t ad7606_store_oversampling_ratio(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
+                                              struct device_attribute *attr,
+                                              const char *buf, size_t count)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7606_state *st = iio_priv(indio_dev);
@@ -460,9 +463,9 @@ static const struct iio_info ad7606_info_range = {
 };
 
 struct iio_dev *ad7606_probe(struct device *dev, int irq,
-                             void __iomem *base_address,
-                             unsigned id,
-                             const struct ad7606_bus_ops *bops)
+                            void __iomem *base_address,
+                            unsigned id,
+                            const struct ad7606_bus_ops *bops)
 {
        struct ad7606_platform_data *pdata = dev->platform_data;
        struct ad7606_state *st;
@@ -529,7 +532,7 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
                dev_warn(st->dev, "failed to RESET: no RESET GPIO specified\n");
 
        ret = request_irq(irq, ad7606_interrupt,
-               IRQF_TRIGGER_FALLING, st->chip_info->name, indio_dev);
+                         IRQF_TRIGGER_FALLING, st->chip_info->name, indio_dev);
        if (ret)
                goto error_free_gpios;
 
@@ -591,7 +594,7 @@ void ad7606_resume(struct iio_dev *indio_dev)
        if (gpio_is_valid(st->pdata->gpio_stby)) {
                if (gpio_is_valid(st->pdata->gpio_range))
                        gpio_set_value(st->pdata->gpio_range,
-                                       st->range == 10000);
+                                      st->range == 10000);
 
                gpio_set_value(st->pdata->gpio_stby, 1);
                ad7606_reset(st);
index 1d48ae381d16c150ac3f0edc6eca32882f54477a..adc370ee863272f5fc6960625bab8741b8661f83 100644 (file)
 #include "ad7606.h"
 
 static int ad7606_par16_read_block(struct device *dev,
-                                int count, void *buf)
+                                  int count, void *buf)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct iio_dev *indio_dev = platform_get_drvdata(pdev);
        struct ad7606_state *st = iio_priv(indio_dev);
 
-       insw((unsigned long) st->base_address, buf, count);
+       insw((unsigned long)st->base_address, buf, count);
 
        return 0;
 }
@@ -32,13 +32,13 @@ static const struct ad7606_bus_ops ad7606_par16_bops = {
 };
 
 static int ad7606_par8_read_block(struct device *dev,
-                                int count, void *buf)
+                                 int count, void *buf)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct iio_dev *indio_dev = platform_get_drvdata(pdev);
        struct ad7606_state *st = iio_priv(indio_dev);
 
-       insb((unsigned long) st->base_address, buf, count * 2);
+       insb((unsigned long)st->base_address, buf, count * 2);
 
        return 0;
 }
@@ -69,9 +69,9 @@ static int ad7606_par_probe(struct platform_device *pdev)
        remap_size = resource_size(res);
 
        indio_dev = ad7606_probe(&pdev->dev, irq, addr,
-                         platform_get_device_id(pdev)->driver_data,
-                         remap_size > 1 ? &ad7606_par16_bops :
-                         &ad7606_par8_bops);
+                                platform_get_device_id(pdev)->driver_data,
+                                remap_size > 1 ? &ad7606_par16_bops :
+                                &ad7606_par8_bops);
 
        if (IS_ERR(indio_dev))
                return PTR_ERR(indio_dev);
@@ -113,6 +113,7 @@ static const struct dev_pm_ops ad7606_pm_ops = {
        .suspend = ad7606_par_suspend,
        .resume  = ad7606_par_resume,
 };
+
 #define AD7606_PAR_PM_OPS (&ad7606_pm_ops)
 
 #else
index 06b59cbca4438e1f43b466277457a8d7a17719e2..cbb36317200e28ca6cb50a85467c03587875f997 100644 (file)
@@ -44,8 +44,8 @@ static int ad7606_spi_probe(struct spi_device *spi)
        struct iio_dev *indio_dev;
 
        indio_dev = ad7606_probe(&spi->dev, spi->irq, NULL,
-                          spi_get_device_id(spi)->driver_data,
-                          &ad7606_spi_bops);
+                                spi_get_device_id(spi)->driver_data,
+                                &ad7606_spi_bops);
 
        if (IS_ERR(indio_dev))
                return PTR_ERR(indio_dev);
@@ -85,6 +85,7 @@ static const struct dev_pm_ops ad7606_pm_ops = {
        .suspend = ad7606_spi_suspend,
        .resume  = ad7606_spi_resume,
 };
+
 #define AD7606_SPI_PM_OPS (&ad7606_pm_ops)
 
 #else
index b76dd15427f5affb5795c539e004ff79398b3640..3abc7789237f7220945e3df0df0b9f837e7d0c88 100644 (file)
@@ -62,7 +62,7 @@ static struct ad7780_state *ad_sigma_delta_to_ad7780(struct ad_sigma_delta *sd)
 }
 
 static int ad7780_set_mode(struct ad_sigma_delta *sigma_delta,
-       enum ad_sigma_delta_mode mode)
+                          enum ad_sigma_delta_mode mode)
 {
        struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
        unsigned val;
@@ -107,13 +107,13 @@ static int ad7780_read_raw(struct iio_dev *indio_dev,
 }
 
 static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta,
-       unsigned int raw_sample)
+                                    unsigned int raw_sample)
 {
        struct ad7780_state *st = ad_sigma_delta_to_ad7780(sigma_delta);
        const struct ad7780_chip_info *chip_info = st->chip_info;
 
        if ((raw_sample & AD7780_ERR) ||
-               ((raw_sample & chip_info->pattern_mask) != chip_info->pattern))
+           ((raw_sample & chip_info->pattern_mask) != chip_info->pattern))
                return -EIO;
 
        if (raw_sample & AD7780_GAIN)
@@ -206,9 +206,10 @@ static int ad7780_probe(struct spi_device *spi)
        indio_dev->info = &ad7780_info;
 
        if (pdata && gpio_is_valid(pdata->gpio_pdrst)) {
-
-               ret = devm_gpio_request_one(&spi->dev, pdata->gpio_pdrst,
-                                       GPIOF_OUT_INIT_LOW, "AD7780 /PDRST");
+               ret = devm_gpio_request_one(&spi->dev,
+                                           pdata->gpio_pdrst,
+                                           GPIOF_OUT_INIT_LOW,
+                                           "AD7780 /PDRST");
                if (ret) {
                        dev_err(&spi->dev, "failed to request GPIO PDRST\n");
                        goto error_disable_reg;
index f3bbb38cdbe48d4d6d75a38513a18e68a76d536e..c8e15664652856a331938398bffc597b4a8f0b14 100644 (file)
@@ -38,7 +38,6 @@
 #define AD7816_TEMP_FLOAT_OFFSET       2
 #define AD7816_TEMP_FLOAT_MASK         0x3
 
-
 /*
  * struct ad7816_chip_info - chip specific information
  */
@@ -48,7 +47,7 @@ struct ad7816_chip_info {
        u16 rdwr_pin;
        u16 convert_pin;
        u16 busy_pin;
-       u8  oti_data[AD7816_CS_MAX+1];
+       u8  oti_data[AD7816_CS_MAX + 1];
        u8  channel_id; /* 0 always be temperature */
        u8  mode;
 };
@@ -60,6 +59,7 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
 {
        struct spi_device *spi_dev = chip->spi_dev;
        int ret = 0;
+       __be16 buf;
 
        gpio_set_value(chip->rdwr_pin, 1);
        gpio_set_value(chip->rdwr_pin, 0);
@@ -70,7 +70,6 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
        }
        gpio_set_value(chip->rdwr_pin, 1);
 
-
        if (chip->mode == AD7816_PD) { /* operating mode 2 */
                gpio_set_value(chip->convert_pin, 1);
                gpio_set_value(chip->convert_pin, 0);
@@ -84,13 +83,13 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data)
 
        gpio_set_value(chip->rdwr_pin, 0);
        gpio_set_value(chip->rdwr_pin, 1);
-       ret = spi_read(spi_dev, (u8 *)data, sizeof(*data));
+       ret = spi_read(spi_dev, &buf, sizeof(*data));
        if (ret < 0) {
                dev_err(&spi_dev->dev, "SPI data read error\n");
                return ret;
        }
 
-       *data = be16_to_cpu(*data);
+       *data = be16_to_cpu(buf);
 
        return ret;
 }
@@ -110,8 +109,8 @@ static int ad7816_spi_write(struct ad7816_chip_info *chip, u8 data)
 }
 
 static ssize_t ad7816_show_mode(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                               struct device_attribute *attr,
+                               char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7816_chip_info *chip = iio_priv(indio_dev);
@@ -122,9 +121,9 @@ static ssize_t ad7816_show_mode(struct device *dev,
 }
 
 static ssize_t ad7816_store_mode(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
+                                struct device_attribute *attr,
+                                const char *buf,
+                                size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7816_chip_info *chip = iio_priv(indio_dev);
@@ -146,8 +145,8 @@ static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR,
                0);
 
 static ssize_t ad7816_show_available_modes(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                                          struct device_attribute *attr,
+                                          char *buf)
 {
        return sprintf(buf, "full\npower-save\n");
 }
@@ -156,8 +155,8 @@ static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7816_show_available_modes,
                        NULL, 0);
 
 static ssize_t ad7816_show_channel(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                                  struct device_attribute *attr,
+                                  char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7816_chip_info *chip = iio_priv(indio_dev);
@@ -166,9 +165,9 @@ static ssize_t ad7816_show_channel(struct device *dev,
 }
 
 static ssize_t ad7816_store_channel(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
+                                   struct device_attribute *attr,
+                                   const char *buf,
+                                   size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7816_chip_info *chip = iio_priv(indio_dev);
@@ -203,10 +202,9 @@ static IIO_DEVICE_ATTR(channel, S_IRUGO | S_IWUSR,
                ad7816_store_channel,
                0);
 
-
 static ssize_t ad7816_show_value(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                                struct device_attribute *attr,
+                                char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7816_chip_info *chip = iio_priv(indio_dev);
@@ -260,8 +258,8 @@ static irqreturn_t ad7816_event_handler(int irq, void *private)
 }
 
 static ssize_t ad7816_show_oti(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                              struct device_attribute *attr,
+                              char *buf)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7816_chip_info *chip = iio_priv(indio_dev);
@@ -280,9 +278,9 @@ static ssize_t ad7816_show_oti(struct device *dev,
 }
 
 static inline ssize_t ad7816_set_oti(struct device *dev,
-               struct device_attribute *attr,
-               const char *buf,
-               size_t len)
+                                    struct device_attribute *attr,
+                                    const char *buf,
+                                    size_t len)
 {
        struct iio_dev *indio_dev = dev_to_iio_dev(dev);
        struct ad7816_chip_info *chip = iio_priv(indio_dev);
@@ -299,7 +297,7 @@ static inline ssize_t ad7816_set_oti(struct device *dev,
                return -EINVAL;
        } else if (chip->channel_id == 0) {
                if (ret || value < AD7816_BOUND_VALUE_MIN ||
-                       value > AD7816_BOUND_VALUE_MAX)
+                   value > AD7816_BOUND_VALUE_MAX)
                        return -EINVAL;
 
                data = (u8)(value - AD7816_BOUND_VALUE_MIN +
@@ -371,7 +369,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
        chip->busy_pin = pins[2];
 
        ret = devm_gpio_request(&spi_dev->dev, chip->rdwr_pin,
-                                       spi_get_device_id(spi_dev)->name);
+                               spi_get_device_id(spi_dev)->name);
        if (ret) {
                dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n",
                        chip->rdwr_pin);
@@ -379,7 +377,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
        }
        gpio_direction_input(chip->rdwr_pin);
        ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin,
-                                       spi_get_device_id(spi_dev)->name);
+                               spi_get_device_id(spi_dev)->name);
        if (ret) {
                dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n",
                        chip->convert_pin);
@@ -387,7 +385,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
        }
        gpio_direction_input(chip->convert_pin);
        ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin,
-                                       spi_get_device_id(spi_dev)->name);
+                               spi_get_device_id(spi_dev)->name);
        if (ret) {
                dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n",
                        chip->busy_pin);
@@ -417,7 +415,7 @@ static int ad7816_probe(struct spi_device *spi_dev)
                return ret;
 
        dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
-                        indio_dev->name);
+                indio_dev->name);
 
        return 0;
 }
index 5331c442fcfca0e1612ac54684094b803ba63380..d11c54b721860cccb0c6db82a6d9353787560896 100644 (file)
@@ -67,10 +67,10 @@ struct lpc32xx_adc_info {
 };
 
 static int lpc32xx_read_raw(struct iio_dev *indio_dev,
-                               struct iio_chan_spec const *chan,
-                               int *val,
-                               int *val2,
-                               long mask)
+                           struct iio_chan_spec const *chan,
+                           int *val,
+                           int *val2,
+                           long mask)
 {
        struct lpc32xx_adc_info *info = iio_priv(indio_dev);
 
@@ -79,10 +79,10 @@ static int lpc32xx_read_raw(struct iio_dev *indio_dev,
                clk_enable(info->clk);
                /* Measurement setup */
                __raw_writel(AD_INTERNAL | (chan->address) | AD_REFp | AD_REFm,
-                       LPC32XX_ADC_SELECT(info->adc_base));
+                            LPC32XX_ADC_SELECT(info->adc_base));
                /* Trigger conversion */
                __raw_writel(AD_PDN_CTRL | AD_STROBE,
-                       LPC32XX_ADC_CTRL(info->adc_base));
+                            LPC32XX_ADC_CTRL(info->adc_base));
                wait_for_completion(&info->completion); /* set by ISR */
                clk_disable(info->clk);
                *val = info->value;
@@ -137,7 +137,7 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
                dev_err(&pdev->dev, "failed to get platform I/O memory\n");
-               return -EBUSY;
+               return -ENXIO;
        }
 
        iodev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
@@ -162,11 +162,11 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
        irq = platform_get_irq(pdev, 0);
        if (irq <= 0) {
                dev_err(&pdev->dev, "failed getting interrupt resource\n");
-               return -EINVAL;
+               return -ENXIO;
        }
 
        retval = devm_request_irq(&pdev->dev, irq, lpc32xx_adc_isr, 0,
-                                                               MOD_NAME, info);
+                                 MOD_NAME, info);
        if (retval < 0) {
                dev_err(&pdev->dev, "failed requesting interrupt\n");
                return retval;
index 47fc00a3f63bc9e5106f0c77354c7cf8e309f36e..d997d9c74ca824740a825cc5399c12be5d491875 100644 (file)
@@ -108,12 +108,12 @@ static const char * const mx28_lradc_irq_names[] = {
 struct mxs_lradc_of_config {
        const int               irq_count;
        const char * const      *irq_name;
-       const uint32_t          *vref_mv;
+       const u32               *vref_mv;
 };
 
 #define VREF_MV_BASE 1850
 
-static const uint32_t mx23_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
+static const u32 mx23_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
        VREF_MV_BASE,           /* CH0 */
        VREF_MV_BASE,           /* CH1 */
        VREF_MV_BASE,           /* CH2 */
@@ -132,7 +132,7 @@ static const uint32_t mx23_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
        VREF_MV_BASE * 4,       /* CH15 VDD5V */
 };
 
-static const uint32_t mx28_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
+static const u32 mx28_vref_mv[LRADC_MAX_TOTAL_CHANS] = {
        VREF_MV_BASE,           /* CH0 */
        VREF_MV_BASE,           /* CH1 */
        VREF_MV_BASE,           /* CH2 */
@@ -198,14 +198,14 @@ struct mxs_lradc {
 
        struct clk              *clk;
 
-       uint32_t                *buffer;
+       u32                     *buffer;
        struct iio_trigger      *trig;
 
        struct mutex            lock;
 
        struct completion       completion;
 
-       const uint32_t          *vref_mv;
+       const u32               *vref_mv;
        struct mxs_lradc_scale  scale_avail[LRADC_MAX_TOTAL_CHANS][2];
        unsigned long           is_divided;
 
@@ -425,7 +425,7 @@ static void mxs_lradc_map_channel(struct mxs_lradc *lradc, unsigned vch,
                                  unsigned ch)
 {
        mxs_lradc_reg_clear(lradc, LRADC_CTRL4_LRADCSELECT_MASK(vch),
-                               LRADC_CTRL4);
+                           LRADC_CTRL4);
        mxs_lradc_reg_set(lradc, LRADC_CTRL4_LRADCSELECT(vch, ch), LRADC_CTRL4);
 }
 
@@ -440,8 +440,8 @@ static void mxs_lradc_setup_ts_channel(struct mxs_lradc *lradc, unsigned ch)
         * otherwise, the IRQs will not fire."
         */
        mxs_lradc_reg_wrt(lradc, LRADC_CH_ACCUMULATE |
-                       LRADC_CH_NUM_SAMPLES(lradc->over_sample_cnt - 1),
-                       LRADC_CH(ch));
+                         LRADC_CH_NUM_SAMPLES(lradc->over_sample_cnt - 1),
+                         LRADC_CH(ch));
 
        /* from the datasheet:
         * "Software must clear this register in preparation for a
@@ -458,10 +458,10 @@ static void mxs_lradc_setup_ts_channel(struct mxs_lradc *lradc, unsigned ch)
         * the LRADC will not trigger the delay group."
         */
        mxs_lradc_reg_wrt(lradc, LRADC_DELAY_TRIGGER(1 << ch) |
-               LRADC_DELAY_TRIGGER_DELAYS(0) |
-               LRADC_DELAY_LOOP(lradc->over_sample_cnt - 1) |
-               LRADC_DELAY_DELAY(lradc->over_sample_delay - 1),
-                       LRADC_DELAY(3));
+                         LRADC_DELAY_TRIGGER_DELAYS(0) |
+                         LRADC_DELAY_LOOP(lradc->over_sample_cnt - 1) |
+                         LRADC_DELAY_DELAY(lradc->over_sample_delay - 1),
+                         LRADC_DELAY(3));
 
        mxs_lradc_reg_clear(lradc, LRADC_CTRL1_LRADC_IRQ(ch), LRADC_CTRL1);
 
@@ -471,12 +471,13 @@ static void mxs_lradc_setup_ts_channel(struct mxs_lradc *lradc, unsigned ch)
         * SoC's delay unit and start the conversion later
         * and automatically.
         */
-       mxs_lradc_reg_wrt(lradc,
+       mxs_lradc_reg_wrt(
+               lradc,
                LRADC_DELAY_TRIGGER(0) | /* don't trigger ADC */
                LRADC_DELAY_TRIGGER_DELAYS(BIT(3)) | /* trigger DELAY unit#3 */
                LRADC_DELAY_KICK |
                LRADC_DELAY_DELAY(lradc->settling_delay),
-                       LRADC_DELAY(2));
+               LRADC_DELAY(2));
 }
 
 /*
@@ -486,7 +487,7 @@ static void mxs_lradc_setup_ts_channel(struct mxs_lradc *lradc, unsigned ch)
  * hardware report one interrupt if both conversions are done
  */
 static void mxs_lradc_setup_ts_pressure(struct mxs_lradc *lradc, unsigned ch1,
-                                                       unsigned ch2)
+                                       unsigned ch2)
 {
        u32 reg;
 
@@ -511,12 +512,14 @@ static void mxs_lradc_setup_ts_pressure(struct mxs_lradc *lradc, unsigned ch1,
        mxs_lradc_reg_clear(lradc, LRADC_CH_VALUE_MASK, LRADC_CH(ch2));
 
        /* prepare the delay/loop unit according to the oversampling count */
-       mxs_lradc_reg_wrt(lradc, LRADC_DELAY_TRIGGER(1 << ch1) |
-               LRADC_DELAY_TRIGGER(1 << ch2) | /* start both channels */
-               LRADC_DELAY_TRIGGER_DELAYS(0) |
-               LRADC_DELAY_LOOP(lradc->over_sample_cnt - 1) |
-               LRADC_DELAY_DELAY(lradc->over_sample_delay - 1),
-                                       LRADC_DELAY(3));
+       mxs_lradc_reg_wrt(
+                   lradc,
+                   LRADC_DELAY_TRIGGER(1 << ch1) |
+                   LRADC_DELAY_TRIGGER(1 << ch2) | /* start both channels */
+                   LRADC_DELAY_TRIGGER_DELAYS(0) |
+                   LRADC_DELAY_LOOP(lradc->over_sample_cnt - 1) |
+                   LRADC_DELAY_DELAY(lradc->over_sample_delay - 1),
+                   LRADC_DELAY(3));
 
        mxs_lradc_reg_clear(lradc, LRADC_CTRL1_LRADC_IRQ(ch2), LRADC_CTRL1);
 
@@ -526,7 +529,8 @@ static void mxs_lradc_setup_ts_pressure(struct mxs_lradc *lradc, unsigned ch1,
         * SoC's delay unit and start the conversion later
         * and automatically.
         */
-       mxs_lradc_reg_wrt(lradc,
+       mxs_lradc_reg_wrt(
+               lradc,
                LRADC_DELAY_TRIGGER(0) | /* don't trigger ADC */
                LRADC_DELAY_TRIGGER_DELAYS(BIT(3)) | /* trigger DELAY unit#3 */
                LRADC_DELAY_KICK |
@@ -534,7 +538,7 @@ static void mxs_lradc_setup_ts_pressure(struct mxs_lradc *lradc, unsigned ch1,
 }
 
 static unsigned mxs_lradc_read_raw_channel(struct mxs_lradc *lradc,
-                                                       unsigned channel)
+                                          unsigned channel)
 {
        u32 reg;
        unsigned num_samples, val;
@@ -550,7 +554,7 @@ static unsigned mxs_lradc_read_raw_channel(struct mxs_lradc *lradc,
 }
 
 static unsigned mxs_lradc_read_ts_pressure(struct mxs_lradc *lradc,
-                                               unsigned ch1, unsigned ch2)
+                                          unsigned ch1, unsigned ch2)
 {
        u32 reg, mask;
        unsigned pressure, m1, m2;
@@ -607,7 +611,7 @@ static void mxs_lradc_setup_touch_detection(struct mxs_lradc *lradc)
         */
        mxs_lradc_reg_clear(lradc, mxs_lradc_plate_mask(lradc), LRADC_CTRL0);
        mxs_lradc_reg_set(lradc, mxs_lradc_touch_detect_bit(lradc),
-                               LRADC_CTRL0);
+                         LRADC_CTRL0);
 }
 
 /*
@@ -675,7 +679,7 @@ static void mxs_lradc_prepare_pressure(struct mxs_lradc *lradc)
        mxs_lradc_map_channel(lradc, TOUCHSCREEN_VCHANNEL1, TS_CH_YM);
        mxs_lradc_map_channel(lradc, TOUCHSCREEN_VCHANNEL2, TS_CH_XP);
        mxs_lradc_setup_ts_pressure(lradc, TOUCHSCREEN_VCHANNEL2,
-                                               TOUCHSCREEN_VCHANNEL1);
+                                   TOUCHSCREEN_VCHANNEL1);
 }
 
 static void mxs_lradc_enable_touch_detection(struct mxs_lradc *lradc)
@@ -684,16 +688,18 @@ static void mxs_lradc_enable_touch_detection(struct mxs_lradc *lradc)
 
        lradc->cur_plate = LRADC_TOUCH;
        mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ |
-                               LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1);
+                           LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1);
        mxs_lradc_reg_set(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1);
 }
 
 static void mxs_lradc_start_touch_event(struct mxs_lradc *lradc)
 {
-       mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ_EN,
-                               LRADC_CTRL1);
+       mxs_lradc_reg_clear(lradc,
+                           LRADC_CTRL1_TOUCH_DETECT_IRQ_EN,
+                           LRADC_CTRL1);
        mxs_lradc_reg_set(lradc,
-               LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1), LRADC_CTRL1);
+                         LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1),
+                         LRADC_CTRL1);
        /*
         * start with the Y-pos, because it uses nearly the same plate
         * settings like the touch detection
@@ -720,12 +726,14 @@ static void mxs_lradc_complete_touch_event(struct mxs_lradc *lradc)
         */
        mxs_lradc_reg_wrt(lradc, 0, LRADC_CH(TOUCHSCREEN_VCHANNEL1));
        mxs_lradc_reg_clear(lradc,
-               LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) |
-               LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2), LRADC_CTRL1);
-       mxs_lradc_reg_wrt(lradc,
-               LRADC_DELAY_TRIGGER(1 << TOUCHSCREEN_VCHANNEL1) |
-               LRADC_DELAY_KICK | LRADC_DELAY_DELAY(10), /* waste 5 ms */
-                       LRADC_DELAY(2));
+                           LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) |
+                           LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2),
+                           LRADC_CTRL1);
+       mxs_lradc_reg_wrt(
+                   lradc,
+                   LRADC_DELAY_TRIGGER(1 << TOUCHSCREEN_VCHANNEL1) |
+                   LRADC_DELAY_KICK | LRADC_DELAY_DELAY(10), /* waste 5 ms */
+                   LRADC_DELAY(2));
 }
 
 /*
@@ -757,9 +765,11 @@ static void mxs_lradc_finish_touch_event(struct mxs_lradc *lradc, bool valid)
        lradc->cur_plate = LRADC_TOUCH;
        mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(2));
        mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(3));
-       mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ |
-               LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1) |
-               LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1), LRADC_CTRL1);
+       mxs_lradc_reg_clear(lradc,
+                           LRADC_CTRL1_TOUCH_DETECT_IRQ |
+                           LRADC_CTRL1_LRADC_IRQ_EN(TOUCHSCREEN_VCHANNEL1) |
+                           LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1),
+                           LRADC_CTRL1);
        mxs_lradc_reg_set(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ_EN, LRADC_CTRL1);
 }
 
@@ -771,25 +781,28 @@ static void mxs_lradc_handle_touch(struct mxs_lradc *lradc)
                if (mxs_lradc_check_touch_event(lradc))
                        mxs_lradc_start_touch_event(lradc);
                mxs_lradc_reg_clear(lradc, LRADC_CTRL1_TOUCH_DETECT_IRQ,
-                                       LRADC_CTRL1);
+                                   LRADC_CTRL1);
                return;
 
        case LRADC_SAMPLE_Y:
-               lradc->ts_y_pos = mxs_lradc_read_raw_channel(lradc,
-                                                       TOUCHSCREEN_VCHANNEL1);
+               lradc->ts_y_pos =
+                   mxs_lradc_read_raw_channel(lradc,
+                                              TOUCHSCREEN_VCHANNEL1);
                mxs_lradc_prepare_x_pos(lradc);
                return;
 
        case LRADC_SAMPLE_X:
-               lradc->ts_x_pos = mxs_lradc_read_raw_channel(lradc,
-                                                       TOUCHSCREEN_VCHANNEL1);
+               lradc->ts_x_pos =
+                   mxs_lradc_read_raw_channel(lradc,
+                                              TOUCHSCREEN_VCHANNEL1);
                mxs_lradc_prepare_pressure(lradc);
                return;
 
        case LRADC_SAMPLE_PRESSURE:
-               lradc->ts_pressure = mxs_lradc_read_ts_pressure(lradc,
-                                                       TOUCHSCREEN_VCHANNEL2,
-                                                       TOUCHSCREEN_VCHANNEL1);
+               lradc->ts_pressure =
+                   mxs_lradc_read_ts_pressure(lradc,
+                                              TOUCHSCREEN_VCHANNEL2,
+                                              TOUCHSCREEN_VCHANNEL1);
                mxs_lradc_complete_touch_event(lradc);
                return;
 
@@ -826,20 +839,22 @@ static int mxs_lradc_read_single(struct iio_dev *iio_dev, int chan, int *val)
         */
        if (lradc->soc == IMX28_LRADC)
                mxs_lradc_reg_clear(lradc, LRADC_CTRL1_LRADC_IRQ_EN(0),
-                       LRADC_CTRL1);
+                                   LRADC_CTRL1);
        mxs_lradc_reg_clear(lradc, 0x1, LRADC_CTRL0);
 
        /* Enable / disable the divider per requirement */
        if (test_bit(chan, &lradc->is_divided))
-               mxs_lradc_reg_set(lradc, 1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
-                       LRADC_CTRL2);
+               mxs_lradc_reg_set(lradc,
+                                 1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
+                                 LRADC_CTRL2);
        else
                mxs_lradc_reg_clear(lradc,
-                       1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET, LRADC_CTRL2);
+                                   1 << LRADC_CTRL2_DIVIDE_BY_TWO_OFFSET,
+                                   LRADC_CTRL2);
 
        /* Clean the slot's previous content, then set new one. */
        mxs_lradc_reg_clear(lradc, LRADC_CTRL4_LRADCSELECT_MASK(0),
-                       LRADC_CTRL4);
+                           LRADC_CTRL4);
        mxs_lradc_reg_set(lradc, chan, LRADC_CTRL4);
 
        mxs_lradc_reg_wrt(lradc, 0, LRADC_CH(0));
@@ -885,8 +900,8 @@ static int mxs_lradc_read_temp(struct iio_dev *iio_dev, int *val)
 }
 
 static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
-                       const struct iio_chan_spec *chan,
-                       int *val, int *val2, long m)
+                             const struct iio_chan_spec *chan,
+                             int *val, int *val2, long m)
 {
        struct mxs_lradc *lradc = iio_priv(iio_dev);
 
@@ -981,9 +996,9 @@ static int mxs_lradc_write_raw_get_fmt(struct iio_dev *iio_dev,
 }
 
 static ssize_t mxs_lradc_show_scale_available_ch(struct device *dev,
-               struct device_attribute *attr,
-               char *buf,
-               int ch)
+                                                struct device_attribute *attr,
+                                                char *buf,
+                                                int ch)
 {
        struct iio_dev *iio = dev_to_iio_dev(dev);
        struct mxs_lradc *lradc = iio_priv(iio);
@@ -1000,8 +1015,8 @@ static ssize_t mxs_lradc_show_scale_available_ch(struct device *dev,
 }
 
 static ssize_t mxs_lradc_show_scale_available(struct device *dev,
-               struct device_attribute *attr,
-               char *buf)
+                                             struct device_attribute *attr,
+                                             char *buf)
 {
        struct iio_dev_attr *iio_attr = to_iio_dev_attr(attr);
 
@@ -1139,8 +1154,8 @@ static irqreturn_t mxs_lradc_handle_irq(int irq, void *data)
        struct iio_dev *iio = data;
        struct mxs_lradc *lradc = iio_priv(iio);
        unsigned long reg = readl(lradc->base + LRADC_CTRL1);
-       uint32_t clr_irq = mxs_lradc_irq_mask(lradc);
-       const uint32_t ts_irq_mask =
+       u32 clr_irq = mxs_lradc_irq_mask(lradc);
+       const u32 ts_irq_mask =
                LRADC_CTRL1_TOUCH_DETECT_IRQ |
                LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL1) |
                LRADC_CTRL1_LRADC_IRQ(TOUCHSCREEN_VCHANNEL2);
@@ -1176,7 +1191,7 @@ static irqreturn_t mxs_lradc_trigger_handler(int irq, void *p)
        struct iio_poll_func *pf = p;
        struct iio_dev *iio = pf->indio_dev;
        struct mxs_lradc *lradc = iio_priv(iio);
-       const uint32_t chan_value = LRADC_CH_ACCUMULATE |
+       const u32 chan_value = LRADC_CH_ACCUMULATE |
                ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET);
        unsigned int i, j = 0;
 
@@ -1199,7 +1214,7 @@ static int mxs_lradc_configure_trigger(struct iio_trigger *trig, bool state)
 {
        struct iio_dev *iio = iio_trigger_get_drvdata(trig);
        struct mxs_lradc *lradc = iio_priv(iio);
-       const uint32_t st = state ? STMP_OFFSET_REG_SET : STMP_OFFSET_REG_CLR;
+       const u32 st = state ? STMP_OFFSET_REG_SET : STMP_OFFSET_REG_CLR;
 
        mxs_lradc_reg_wrt(lradc, LRADC_DELAY_KICK, LRADC_DELAY(0) + st);
 
@@ -1218,7 +1233,7 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio)
        struct mxs_lradc *lradc = iio_priv(iio);
 
        trig = iio_trigger_alloc("%s-dev%i", iio->name, iio->id);
-       if (trig == NULL)
+       if (!trig)
                return -ENOMEM;
 
        trig->dev.parent = lradc->dev;
@@ -1249,10 +1264,10 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio)
        struct mxs_lradc *lradc = iio_priv(iio);
        int ret = 0, chan, ofs = 0;
        unsigned long enable = 0;
-       uint32_t ctrl4_set = 0;
-       uint32_t ctrl4_clr = 0;
-       uint32_t ctrl1_irq = 0;
-       const uint32_t chan_value = LRADC_CH_ACCUMULATE |
+       u32 ctrl4_set = 0;
+       u32 ctrl4_clr = 0;
+       u32 ctrl1_irq = 0;
+       const u32 chan_value = LRADC_CH_ACCUMULATE |
                ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET);
        const int len = bitmap_weight(iio->active_scan_mask,
                        LRADC_MAX_TOTAL_CHANS);
@@ -1275,7 +1290,8 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio)
        }
 
        if (lradc->soc == IMX28_LRADC)
-               mxs_lradc_reg_clear(lradc,
+               mxs_lradc_reg_clear(
+                       lradc,
                        lradc->buffer_vchans << LRADC_CTRL1_LRADC_IRQ_EN_OFFSET,
                        LRADC_CTRL1);
        mxs_lradc_reg_clear(lradc, lradc->buffer_vchans, LRADC_CTRL0);
@@ -1290,12 +1306,12 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio)
        }
 
        mxs_lradc_reg_clear(lradc, LRADC_DELAY_TRIGGER_LRADCS_MASK |
-                                       LRADC_DELAY_KICK, LRADC_DELAY(0));
+                           LRADC_DELAY_KICK, LRADC_DELAY(0));
        mxs_lradc_reg_clear(lradc, ctrl4_clr, LRADC_CTRL4);
        mxs_lradc_reg_set(lradc, ctrl4_set, LRADC_CTRL4);
        mxs_lradc_reg_set(lradc, ctrl1_irq, LRADC_CTRL1);
        mxs_lradc_reg_set(lradc, enable << LRADC_DELAY_TRIGGER_LRADCS_OFFSET,
-                                       LRADC_DELAY(0));
+                         LRADC_DELAY(0));
 
        return 0;
 
@@ -1309,11 +1325,12 @@ static int mxs_lradc_buffer_postdisable(struct iio_dev *iio)
        struct mxs_lradc *lradc = iio_priv(iio);
 
        mxs_lradc_reg_clear(lradc, LRADC_DELAY_TRIGGER_LRADCS_MASK |
-                                       LRADC_DELAY_KICK, LRADC_DELAY(0));
+                           LRADC_DELAY_KICK, LRADC_DELAY(0));
 
        mxs_lradc_reg_clear(lradc, lradc->buffer_vchans, LRADC_CTRL0);
        if (lradc->soc == IMX28_LRADC)
-               mxs_lradc_reg_clear(lradc,
+               mxs_lradc_reg_clear(
+                       lradc,
                        lradc->buffer_vchans << LRADC_CTRL1_LRADC_IRQ_EN_OFFSET,
                        LRADC_CTRL1);
 
@@ -1324,7 +1341,7 @@ static int mxs_lradc_buffer_postdisable(struct iio_dev *iio)
 }
 
 static bool mxs_lradc_validate_scan_mask(struct iio_dev *iio,
-                                       const unsigned long *mask)
+                                        const unsigned long *mask)
 {
        struct mxs_lradc *lradc = iio_priv(iio);
        const int map_chans = bitmap_weight(mask, LRADC_MAX_TOTAL_CHANS);
@@ -1457,7 +1474,7 @@ static const struct iio_chan_spec mx28_lradc_chan_spec[] = {
 static int mxs_lradc_hw_init(struct mxs_lradc *lradc)
 {
        /* The ADC always uses DELAY CHANNEL 0. */
-       const uint32_t adc_cfg =
+       const u32 adc_cfg =
                (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + 0)) |
                (LRADC_DELAY_TIMER_PER << LRADC_DELAY_DELAY_OFFSET);
 
@@ -1477,11 +1494,11 @@ static int mxs_lradc_hw_init(struct mxs_lradc *lradc)
        /* Configure the touchscreen type */
        if (lradc->soc == IMX28_LRADC) {
                mxs_lradc_reg_clear(lradc, LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE,
-                                                       LRADC_CTRL0);
+                                   LRADC_CTRL0);
 
        if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_5WIRE)
                mxs_lradc_reg_set(lradc, LRADC_CTRL0_MX28_TOUCH_SCREEN_TYPE,
-                               LRADC_CTRL0);
+                                 LRADC_CTRL0);
        }
 
        /* Start internal temperature sensing. */
@@ -1508,13 +1525,13 @@ static const struct of_device_id mxs_lradc_dt_ids[] = {
 MODULE_DEVICE_TABLE(of, mxs_lradc_dt_ids);
 
 static int mxs_lradc_probe_touchscreen(struct mxs_lradc *lradc,
-                                               struct device_node *lradc_node)
+                                      struct device_node *lradc_node)
 {
        int ret;
        u32 ts_wires = 0, adapt;
 
        ret = of_property_read_u32(lradc_node, "fsl,lradc-touchscreen-wires",
-                               &ts_wires);
+                                  &ts_wires);
        if (ret)
                return -ENODEV; /* touchscreen feature disabled */
 
@@ -1584,7 +1601,7 @@ static int mxs_lradc_probe(struct platform_device *pdev)
        struct resource *iores;
        int ret = 0, touch_ret;
        int i, s;
-       uint64_t scale_uv;
+       u64 scale_uv;
 
        /* Allocate the IIO device. */
        iio = devm_iio_device_alloc(dev, sizeof(*lradc));
@@ -1630,8 +1647,8 @@ static int mxs_lradc_probe(struct platform_device *pdev)
                }
 
                ret = devm_request_irq(dev, lradc->irq[i],
-                                       mxs_lradc_handle_irq, 0,
-                                       of_cfg->irq_name[i], iio);
+                                      mxs_lradc_handle_irq, 0,
+                                      of_cfg->irq_name[i], iio);
                if (ret)
                        goto err_clk;
        }
@@ -1658,8 +1675,8 @@ static int mxs_lradc_probe(struct platform_device *pdev)
        }
 
        ret = iio_triggered_buffer_setup(iio, &iio_pollfunc_store_time,
-                               &mxs_lradc_trigger_handler,
-                               &mxs_lradc_buffer_ops);
+                                        &mxs_lradc_trigger_handler,
+                                        &mxs_lradc_buffer_ops);
        if (ret)
                goto err_clk;
 
index c5382374ddf6903f37d248e2f69d8f4b4da4dbcd..712cae0e86086a6bef1b430f0099a65f516e332c 100644 (file)
@@ -191,8 +191,8 @@ static int spear_adc_write_raw(struct iio_dev *indio_dev,
        mutex_lock(&indio_dev->mlock);
 
        if ((val < SPEAR_ADC_CLK_MIN) ||
-               (val > SPEAR_ADC_CLK_MAX) ||
-               (val2 != 0)) {
+           (val > SPEAR_ADC_CLK_MAX) ||
+           (val2 != 0)) {
                ret = -EINVAL;
                goto out;
        }
index 5b11b42c0254deb21c9db53e6add1e2a459bbe7f..3adc4516918c930bce2c4c48ea078eb82fa9345c 100644 (file)
@@ -1756,43 +1756,43 @@ static irqreturn_t adt7316_event_handler(int irq, void *private)
                        stat1 &= 0x1F;
 
                time = iio_get_time_ns();
-               if (stat1 & (1 << 0))
+               if (stat1 & BIT(0))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_RISING),
                                       time);
-               if (stat1 & (1 << 1))
+               if (stat1 & BIT(1))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 0,
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_FALLING),
                                       time);
-               if (stat1 & (1 << 2))
+               if (stat1 & BIT(2))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 1,
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_RISING),
                                       time);
-               if (stat1 & (1 << 3))
+               if (stat1 & BIT(3))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_TEMP, 1,
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_FALLING),
                                       time);
-               if (stat1 & (1 << 5))
+               if (stat1 & BIT(5))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 1,
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_EITHER),
                                       time);
-               if (stat1 & (1 << 6))
+               if (stat1 & BIT(6))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 2,
                                                            IIO_EV_TYPE_THRESH,
                                                            IIO_EV_DIR_EITHER),
                                       time);
-               if (stat1 & (1 << 7))
+               if (stat1 & BIT(7))
                        iio_push_event(indio_dev,
                                       IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, 3,
                                                            IIO_EV_TYPE_THRESH,
@@ -2152,7 +2152,7 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
 
                ret = devm_request_threaded_irq(dev, chip->bus.irq,
                                                NULL,
-                                               &adt7316_event_handler,
+                                               adt7316_event_handler,
                                                chip->bus.irq_flags |
                                                IRQF_ONESHOT,
                                                indio_dev->name,
index a2b7ae3329c0e56cd345340a7c0c6426cfe621fd..e8d0ff2d5c9b9cbd1ec0ffcb7b0c027c44beed0a 100644 (file)
@@ -179,12 +179,9 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev,
                /* Note completely different from the adaptive versions */
        case IIO_EV_TYPE_THRESH:
                value = chip->threshold[rising][chan];
-               ret = i2c_smbus_write_word_data(chip->client,
+               return i2c_smbus_write_word_data(chip->client,
                                                ad7150_addresses[chan][3],
                                                swab16(value));
-               if (ret < 0)
-                       return ret;
-               return 0;
        case IIO_EV_TYPE_MAG_ADAPTIVE:
                sens = chip->mag_sensitivity[rising][chan];
                timeout = chip->mag_timeout[rising][chan];
@@ -222,7 +219,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
        u64 event_code;
 
        /* Something must always be turned on */
-       if (state == 0)
+       if (!state)
                return -EINVAL;
 
        event_code = IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, type, dir);
@@ -636,7 +633,7 @@ static int ad7150_probe(struct i2c_client *client,
                        return ret;
        }
 
-       ret = iio_device_register(indio_dev);
+       ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
        if (ret)
                return ret;
 
@@ -646,15 +643,6 @@ static int ad7150_probe(struct i2c_client *client,
        return 0;
 }
 
-static int ad7150_remove(struct i2c_client *client)
-{
-       struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-       iio_device_unregister(indio_dev);
-
-       return 0;
-}
-
 static const struct i2c_device_id ad7150_id[] = {
        { "ad7150", 0 },
        { "ad7151", 0 },
@@ -669,7 +657,6 @@ static struct i2c_driver ad7150_driver = {
                .name = "ad7150",
        },
        .probe = ad7150_probe,
-       .remove = ad7150_remove,
        .id_table = ad7150_id,
 };
 module_i2c_driver(ad7150_driver);
index 87110d940e9a429d65d136abff4d93805ad8bdc7..485d0a5af53c8ac1f4b74abdec236254de56ffdc 100644 (file)
@@ -290,7 +290,7 @@ static int ad7152_write_raw(struct iio_dev *indio_dev,
                ret = 0;
                break;
        case IIO_CHAN_INFO_SCALE:
-               if (val != 0) {
+               if (val) {
                        ret = -EINVAL;
                        goto out;
                }
@@ -502,7 +502,7 @@ static int ad7152_probe(struct i2c_client *client,
        indio_dev->num_channels = ARRAY_SIZE(ad7152_channels);
        indio_dev->modes = INDIO_DIRECT_MODE;
 
-       ret = iio_device_register(indio_dev);
+       ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
        if (ret)
                return ret;
 
@@ -511,15 +511,6 @@ static int ad7152_probe(struct i2c_client *client,
        return 0;
 }
 
-static int ad7152_remove(struct i2c_client *client)
-{
-       struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-       iio_device_unregister(indio_dev);
-
-       return 0;
-}
-
 static const struct i2c_device_id ad7152_id[] = {
        { "ad7152", 0 },
        { "ad7153", 1 },
@@ -533,7 +524,6 @@ static struct i2c_driver ad7152_driver = {
                .name = KBUILD_MODNAME,
        },
        .probe = ad7152_probe,
-       .remove = ad7152_remove,
        .id_table = ad7152_id,
 };
 module_i2c_driver(ad7152_driver);
index e6e9eaa9eab5477bf1f66ea64c01809e22527ea9..2c5d27784ed300dfa5f090de08f487846bd59079 100644 (file)
 
 #define AD7746_REG_STATUS              0
 #define AD7746_REG_CAP_DATA_HIGH       1
-#define AD7746_REG_CAP_DATA_MID                2
-#define AD7746_REG_CAP_DATA_LOW                3
 #define AD7746_REG_VT_DATA_HIGH                4
-#define AD7746_REG_VT_DATA_MID         5
-#define AD7746_REG_VT_DATA_LOW         6
 #define AD7746_REG_CAP_SETUP           7
 #define AD7746_REG_VT_SETUP            8
 #define AD7746_REG_EXC_SETUP           9
 #define AD7746_REG_CAPDACA             11
 #define AD7746_REG_CAPDACB             12
 #define AD7746_REG_CAP_OFFH            13
-#define AD7746_REG_CAP_OFFL            14
 #define AD7746_REG_CAP_GAINH           15
-#define AD7746_REG_CAP_GAINL           16
 #define AD7746_REG_VOLT_GAINH          17
-#define AD7746_REG_VOLT_GAINL          18
 
 /* Status Register Bit Designations (AD7746_REG_STATUS) */
-#define AD7746_STATUS_EXCERR           (1 << 3)
-#define AD7746_STATUS_RDY              (1 << 2)
-#define AD7746_STATUS_RDYVT            (1 << 1)
-#define AD7746_STATUS_RDYCAP           (1 << 0)
+#define AD7746_STATUS_EXCERR           BIT(3)
+#define AD7746_STATUS_RDY              BIT(2)
+#define AD7746_STATUS_RDYVT            BIT(1)
+#define AD7746_STATUS_RDYCAP           BIT(0)
 
 /* Capacitive Channel Setup Register Bit Designations (AD7746_REG_CAP_SETUP) */
 #define AD7746_CAPSETUP_CAPEN          (1 << 7)
 #define AD7746_VTSETUP_VTCHOP          (1 << 0)
 
 /* Excitation Setup Register Bit Designations (AD7746_REG_EXC_SETUP) */
-#define AD7746_EXCSETUP_CLKCTRL                (1 << 7)
-#define AD7746_EXCSETUP_EXCON          (1 << 6)
-#define AD7746_EXCSETUP_EXCB           (1 << 5)
-#define AD7746_EXCSETUP_NEXCB          (1 << 4)
-#define AD7746_EXCSETUP_EXCA           (1 << 3)
-#define AD7746_EXCSETUP_NEXCA          (1 << 2)
+#define AD7746_EXCSETUP_CLKCTRL                BIT(7)
+#define AD7746_EXCSETUP_EXCON          BIT(6)
+#define AD7746_EXCSETUP_EXCB           BIT(5)
+#define AD7746_EXCSETUP_NEXCB          BIT(4)
+#define AD7746_EXCSETUP_EXCA           BIT(3)
+#define AD7746_EXCSETUP_NEXCA          BIT(2)
 #define AD7746_EXCSETUP_EXCLVL(x)      (((x) & 0x3) << 0)
 
 /* Config Register Bit Designations (AD7746_REG_CFG) */
@@ -528,10 +521,11 @@ static int ad7746_write_raw(struct iio_dev *indio_dev,
                        goto out;
                }
 
-               /* CAPDAC Scale = 21pF_typ / 127
+               /*
+                * CAPDAC Scale = 21pF_typ / 127
                 * CIN Scale = 8.192pF / 2^24
                 * Offset Scale = CAPDAC Scale / CIN Scale = 338646
-                * */
+                */
 
                val /= 338646;
 
@@ -600,7 +594,8 @@ static int ad7746_read_raw(struct iio_dev *indio_dev,
 
                switch (chan->type) {
                case IIO_TEMP:
-               /* temperature in milli degrees Celsius
+               /*
+                * temperature in milli degrees Celsius
                 * T = ((*val / 2048) - 4096) * 1000
                 */
                        *val = (*val * 125) / 256;
@@ -749,21 +744,10 @@ static int ad7746_probe(struct i2c_client *client,
        if (ret < 0)
                return ret;
 
-       ret = iio_device_register(indio_dev);
+       ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
        if (ret)
                return ret;
 
-       dev_info(&client->dev, "%s capacitive sensor registered\n", id->name);
-
-       return 0;
-}
-
-static int ad7746_remove(struct i2c_client *client)
-{
-       struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-       iio_device_unregister(indio_dev);
-
        return 0;
 }
 
@@ -781,7 +765,6 @@ static struct i2c_driver ad7746_driver = {
                .name = KBUILD_MODNAME,
        },
        .probe = ad7746_probe,
-       .remove = ad7746_remove,
        .id_table = ad7746_id,
 };
 module_i2c_driver(ad7746_driver);
index 15f0cc3b4d3172bb6127b29c4527d9a5c9fa4503..6464f2cbe94b556f2738c39f874574262019ea9a 100644 (file)
@@ -111,7 +111,7 @@ static ssize_t ad9834_write(struct device *dev,
                break;
        case AD9834_FSEL:
        case AD9834_PSEL:
-               if (val == 0) {
+               if (!val) {
                        st->control &= ~(this_attr->address | AD9834_PIN_SW);
                } else if (val == 1) {
                        st->control |= this_attr->address;
index b8776d638e662a72a013b302dd811a9b608e09b1..ab816a215eb80f10acb672c905372c977c244d9d 100644 (file)
@@ -67,7 +67,7 @@ static int adis16060_spi_read(struct iio_dev *indio_dev, u16 *val)
         * starts to place data MSB first on the DOUT line at
         * the 6th falling edge of SCLK
         */
-       if (ret == 0)
+       if (!ret)
                *val = ((st->buf[0] & 0x3) << 12) |
                        (st->buf[1] << 4) |
                        ((st->buf[2] >> 4) & 0xF);
@@ -89,11 +89,13 @@ static int adis16060_read_raw(struct iio_dev *indio_dev,
                /* Take the iio_dev status lock */
                mutex_lock(&indio_dev->mlock);
                ret = adis16060_spi_write(indio_dev, chan->address);
-               if (ret < 0) {
-                       mutex_unlock(&indio_dev->mlock);
-                       return ret;
-               }
+               if (ret < 0)
+                       goto out_unlock;
+
                ret = adis16060_spi_read(indio_dev, &tval);
+               if (ret < 0)
+                       goto out_unlock;
+
                mutex_unlock(&indio_dev->mlock);
                *val = tval;
                return IIO_VAL_INT;
@@ -108,6 +110,10 @@ static int adis16060_read_raw(struct iio_dev *indio_dev,
        }
 
        return -EINVAL;
+
+out_unlock:
+       mutex_unlock(&indio_dev->mlock);
+       return ret;
 }
 
 static const struct iio_info adis16060_info = {
index 6d38854c38c89a1032da9aedcc4bf65fec90e216..9e83f348df51f6f609d0143ec5844950d5ee78cb 100644 (file)
 #include "iio_dummy_evgen.h"
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
+#include <linux/irq_work.h>
 
 /* Fiddly bit of faking and irq without hardware */
 #define IIO_EVENTGEN_NO 10
+
+/**
+ * struct iio_dummy_handle_irq - helper struct to simulate interrupt generation
+ * @work: irq_work used to run handlers from hardirq context
+ * @irq: fake irq line number to trigger an interrupt
+ */
+struct iio_dummy_handle_irq {
+       struct irq_work work;
+       int irq;
+};
+
 /**
  * struct iio_dummy_evgen - evgen state
  * @chip: irq chip we are faking
@@ -35,6 +47,7 @@
  * @inuse: mask of which irqs are connected
  * @regs: irq regs we are faking
  * @lock: protect the evgen state
+ * @handler: helper for a 'hardware-like' interrupt simulation
  */
 struct iio_dummy_eventgen {
        struct irq_chip chip;
@@ -43,6 +56,7 @@ struct iio_dummy_eventgen {
        bool inuse[IIO_EVENTGEN_NO];
        struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
        struct mutex lock;
+       struct iio_dummy_handle_irq handler;
 };
 
 /* We can only ever have one instance of this 'device' */
@@ -67,6 +81,14 @@ static void iio_dummy_event_irqunmask(struct irq_data *d)
        evgen->enabled[d->irq - evgen->base] = true;
 }
 
+static void iio_dummy_work_handler(struct irq_work *work)
+{
+       struct iio_dummy_handle_irq *irq_handler;
+
+       irq_handler = container_of(work, struct iio_dummy_handle_irq, work);
+       handle_simple_irq(irq_to_desc(irq_handler->irq));
+}
+
 static int iio_dummy_evgen_create(void)
 {
        int ret, i;
@@ -91,6 +113,7 @@ static int iio_dummy_evgen_create(void)
                                  IRQ_NOREQUEST | IRQ_NOAUTOEN,
                                  IRQ_NOPROBE);
        }
+       init_irq_work(&iio_evgen->handler.work, iio_dummy_work_handler);
        mutex_init(&iio_evgen->lock);
        return 0;
 }
@@ -169,8 +192,9 @@ static ssize_t iio_evgen_poke(struct device *dev,
        iio_evgen->regs[this_attr->address].reg_id   = this_attr->address;
        iio_evgen->regs[this_attr->address].reg_data = event;
 
+       iio_evgen->handler.irq = iio_evgen->base + this_attr->address;
        if (iio_evgen->enabled[this_attr->address])
-               handle_nested_irq(iio_evgen->base + this_attr->address);
+               irq_work_queue(&iio_evgen->handler.work);
 
        return len;
 }
index 381f90ff468a983ca6ff7b318dadca61a7a168b6..43fe4ba7d0dcdac2f5d30666139eb2270001080f 100644 (file)
@@ -137,7 +137,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                 */
                .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ),
                /* The ordering of elements in the buffer via an enum */
-               .scan_index = voltage0,
+               .scan_index = DUMMY_INDEX_VOLTAGE_0,
                .scan_type = { /* Description of storage in buffer */
                        .sign = 'u', /* unsigned */
                        .realbits = 13, /* 13 bits */
@@ -176,7 +176,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                 * sampling_frequency
                 * The frequency in Hz at which the channels are sampled
                 */
-               .scan_index = diffvoltage1m2,
+               .scan_index = DUMMY_INDEX_DIFFVOLTAGE_1M2,
                .scan_type = { /* Description of storage in buffer */
                        .sign = 's', /* signed */
                        .realbits = 12, /* 12 bits */
@@ -194,7 +194,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
                .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
                .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ),
-               .scan_index = diffvoltage3m4,
+               .scan_index = DUMMY_INDEX_DIFFVOLTAGE_3M4,
                .scan_type = {
                        .sign = 's',
                        .realbits = 11,
@@ -221,7 +221,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
                BIT(IIO_CHAN_INFO_CALIBSCALE) |
                BIT(IIO_CHAN_INFO_CALIBBIAS),
                .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ),
-               .scan_index = accelx,
+               .scan_index = DUMMY_INDEX_ACCELX,
                .scan_type = { /* Description of storage in buffer */
                        .sign = 's', /* signed */
                        .realbits = 16, /* 16 bits */
@@ -364,8 +364,7 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
                                ret = IIO_VAL_INT_PLUS_MICRO;
                                break;
                        case 1:
-                               /* all differential adc channels ->
-                                * 0.000001344 */
+                               /* all differential adc -> 0.000001344 */
                                *val = 0;
                                *val2 = 1344;
                                ret = IIO_VAL_INT_PLUS_NANO;
index 8d00224e6fadb2ba8cd37debf0bf2e17d28ed27d..b9069a18067212d0a1e52f50d1b053aa91a160ac 100644 (file)
@@ -46,6 +46,7 @@ struct iio_dummy_state {
        int event_irq;
        int event_val;
        bool event_en;
+       s64 event_timestamp;
 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
 };
 
@@ -97,18 +98,18 @@ iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
 
 /**
  * enum iio_simple_dummy_scan_elements - scan index enum
- * @voltage0:          the single ended voltage channel
- * @diffvoltage1m2:    first differential channel
- * @diffvoltage3m4:    second differenial channel
- * @accelx:            acceleration channel
+ * @DUMMY_INDEX_VOLTAGE_0:         the single ended voltage channel
+ * @DUMMY_INDEX_DIFFVOLTAGE_1M2:   first differential channel
+ * @DUMMY_INDEX_DIFFVOLTAGE_3M4:   second differential channel
+ * @DUMMY_INDEX_ACCELX:            acceleration channel
  *
  * Enum provides convenient numbering for the scan index.
  */
 enum iio_simple_dummy_scan_elements {
-       voltage0,
-       diffvoltage1m2,
-       diffvoltage3m4,
-       accelx,
+       DUMMY_INDEX_VOLTAGE_0,
+       DUMMY_INDEX_DIFFVOLTAGE_1M2,
+       DUMMY_INDEX_DIFFVOLTAGE_3M4,
+       DUMMY_INDEX_ACCELX,
 };
 
 #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
index 00ed7745f3c5b768df4c707f78c0e2ea5c388326..cf44a6f7943118bab29c335edd807cb4f186e7b8 100644 (file)
 /* Some fake data */
 
 static const s16 fakedata[] = {
-       [voltage0] = 7,
-       [diffvoltage1m2] = -33,
-       [diffvoltage3m4] = -2,
-       [accelx] = 344,
+       [DUMMY_INDEX_VOLTAGE_0] = 7,
+       [DUMMY_INDEX_DIFFVOLTAGE_1M2] = -33,
+       [DUMMY_INDEX_DIFFVOLTAGE_3M4] = -2,
+       [DUMMY_INDEX_ACCELX] = 344,
 };
 
 /**
index 73108baf80adffe09bf84cee11d34e1b6bee6963..bfbf1c56bd22630e19ac739eadd514157071ab2b 100644 (file)
@@ -153,6 +153,15 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
        return 0;
 }
 
+static irqreturn_t iio_simple_dummy_get_timestamp(int irq, void *private)
+{
+       struct iio_dev *indio_dev = private;
+       struct iio_dummy_state *st = iio_priv(indio_dev);
+
+       st->event_timestamp = iio_get_time_ns();
+       return IRQ_HANDLED;
+}
+
 /**
  * iio_simple_dummy_event_handler() - identify and pass on event
  * @irq: irq of event line
@@ -177,7 +186,7 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
                               IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
                                              IIO_EV_DIR_RISING,
                                              IIO_EV_TYPE_THRESH, 0, 0, 0),
-                              iio_get_time_ns());
+                              st->event_timestamp);
                break;
        case 1:
                if (st->activity_running > st->event_val)
@@ -187,7 +196,7 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
                                                      IIO_EV_DIR_RISING,
                                                      IIO_EV_TYPE_THRESH,
                                                      0, 0, 0),
-                                      iio_get_time_ns());
+                                      st->event_timestamp);
                break;
        case 2:
                if (st->activity_walking < st->event_val)
@@ -197,14 +206,14 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
                                                      IIO_EV_DIR_FALLING,
                                                      IIO_EV_TYPE_THRESH,
                                                      0, 0, 0),
-                                      iio_get_time_ns());
+                                      st->event_timestamp);
                break;
        case 3:
                iio_push_event(indio_dev,
                               IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
                                              IIO_EV_DIR_NONE,
                                              IIO_EV_TYPE_CHANGE, 0, 0, 0),
-                              iio_get_time_ns());
+                              st->event_timestamp);
                break;
        default:
                break;
@@ -238,7 +247,7 @@ int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
        st->regs = iio_dummy_evgen_get_regs(st->event_irq);
 
        ret = request_threaded_irq(st->event_irq,
-                                  NULL,
+                                  &iio_simple_dummy_get_timestamp,
                                   &iio_simple_dummy_event_handler,
                                   IRQF_ONESHOT,
                                   "iio_simple_event",
index c18109c55497087076df8f780fe81c1270524676..10c43dda0f5a37009d6ba65bda523e2883fb8e17 100644 (file)
@@ -644,7 +644,8 @@ static void ad5933_work(struct work_struct *work)
        struct ad5933_state *st = container_of(work,
                struct ad5933_state, work.work);
        struct iio_dev *indio_dev = i2c_get_clientdata(st->client);
-       signed short buf[2];
+       __be16 buf[2];
+       int val[2];
        unsigned char status;
 
        mutex_lock(&indio_dev->mlock);
@@ -668,12 +669,12 @@ static void ad5933_work(struct work_struct *work)
                                scan_count * 2, (u8 *)buf);
 
                if (scan_count == 2) {
-                       buf[0] = be16_to_cpu(buf[0]);
-                       buf[1] = be16_to_cpu(buf[1]);
+                       val[0] = be16_to_cpu(buf[0]);
+                       val[1] = be16_to_cpu(buf[1]);
                } else {
-                       buf[0] = be16_to_cpu(buf[0]);
+                       val[0] = be16_to_cpu(buf[0]);
                }
-               iio_push_to_buffers(indio_dev, buf);
+               iio_push_to_buffers(indio_dev, val);
        } else {
                /* no data available - try again later */
                schedule_delayed_work(&st->work, st->poll_time_jiffies);
index 019ba5245c2363ac2e671dcde9c4378eb19dcc02..bbf7e35cbc7d1f0eda8fb4db58bc23fe2c4a3674 100644 (file)
@@ -117,12 +117,10 @@ static int isl29018_set_integration_time(struct isl29018_chip *chip,
 {
        int i, ret;
        unsigned int int_time, new_int_time;
-       struct isl29018_scale new_scale;
 
        for (i = 0; i < ARRAY_SIZE(isl29018_int_utimes[chip->type]); ++i) {
                if (utime == isl29018_int_utimes[chip->type][i]) {
                        new_int_time = i;
-                       new_scale = isl29018_scales[new_int_time][0];
                        break;
                }
        }
@@ -370,7 +368,7 @@ static int isl29018_write_raw(struct iio_dev *indio_dev,
                break;
        case IIO_CHAN_INFO_INT_TIME:
                if (chan->type == IIO_LIGHT) {
-                       if (val != 0) {
+                       if (val) {
                                mutex_unlock(&chip->lock);
                                return -EINVAL;
                        }
@@ -716,7 +714,7 @@ static int isl29018_probe(struct i2c_client *client,
        int dev_id = 0;
 
        indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
-       if (indio_dev == NULL) {
+       if (!indio_dev) {
                dev_err(&client->dev, "iio allocation fails\n");
                return -ENOMEM;
        }
index cd6f2727aa58739b329acc46ee49a3321f8daa39..32ae1127da33af4255075ac567a79bc99d108ce5 100644 (file)
@@ -513,7 +513,7 @@ static int isl29028_probe(struct i2c_client *client,
        indio_dev->name = id->name;
        indio_dev->dev.parent = &client->dev;
        indio_dev->modes = INDIO_DIRECT_MODE;
-       ret = iio_device_register(indio_dev);
+       ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
        if (ret < 0) {
                dev_err(chip->dev, "iio registration fails with error %d\n",
                        ret);
@@ -522,14 +522,6 @@ static int isl29028_probe(struct i2c_client *client,
        return 0;
 }
 
-static int isl29028_remove(struct i2c_client *client)
-{
-       struct iio_dev *indio_dev = i2c_get_clientdata(client);
-
-       iio_device_unregister(indio_dev);
-       return 0;
-}
-
 static const struct i2c_device_id isl29028_id[] = {
        {"isl29028", 0},
        {}
@@ -550,7 +542,6 @@ static struct i2c_driver isl29028_driver = {
                .of_match_table = isl29028_of_match,
        },
        .probe   = isl29028_probe,
-       .remove  = isl29028_remove,
        .id_table = isl29028_id,
 };
 
index b5e1b8b0a6f0db24d7a5da3f1e51d2dbc2cc50ce..3100d960fe2c6dc57a49361dcbd5ce53c00e9ef0 100644 (file)
@@ -263,7 +263,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
        if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))
                goto return_max;
 
-       if (ch0 == 0) {
+       if (!ch0) {
                /* have no data, so return LAST VALUE */
                ret = chip->als_cur_info.lux = 0;
                goto out_unlock;
@@ -415,7 +415,7 @@ static int taos_chip_on(struct iio_dev *indio_dev)
 
        /* determine als integration register */
        als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
-       if (als_count == 0)
+       if (!als_count)
                als_count = 1; /* ensure at least one cycle */
 
        /* convert back to time (encompasses overrides) */
@@ -499,7 +499,7 @@ static ssize_t taos_power_state_store(struct device *dev,
        if (kstrtoint(buf, 0, &value))
                return -EINVAL;
 
-       if (value == 0)
+       if (!value)
                taos_chip_off(indio_dev);
        else
                taos_chip_on(indio_dev);
@@ -862,7 +862,7 @@ static int taos_probe(struct i2c_client *clientp,
        indio_dev->dev.parent = &clientp->dev;
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->name = chip->client->name;
-       ret = iio_device_register(indio_dev);
+       ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
        if (ret) {
                dev_err(&clientp->dev, "iio registration failed\n");
                return ret;
@@ -917,13 +917,6 @@ static SIMPLE_DEV_PM_OPS(taos_pm_ops, taos_suspend, taos_resume);
 #define TAOS_PM_OPS NULL
 #endif
 
-static int taos_remove(struct i2c_client *client)
-{
-       iio_device_unregister(i2c_get_clientdata(client));
-
-       return 0;
-}
-
 static struct i2c_device_id taos_idtable[] = {
        { "tsl2580", 0 },
        { "tsl2581", 1 },
@@ -940,7 +933,6 @@ static struct i2c_driver taos_driver = {
        },
        .id_table = taos_idtable,
        .probe = taos_probe,
-       .remove = taos_remove,
 };
 module_i2c_driver(taos_driver);
 
index 010e607dd8804fb1f74ef56fc8c3555cc66af22e..9dfd04855a1b0edb769866686ce505e30339a324 100644 (file)
@@ -403,7 +403,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
                goto return_max;
        }
 
-       if (ch0 == 0) {
+       if (!ch0) {
                /* have no data, so return LAST VALUE */
                ret = chip->als_cur_info.lux;
                goto out_unlock;
@@ -418,9 +418,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
        if (p->ratio == 0) {
                lux = 0;
        } else {
-               ch0lux = DIV_ROUND_UP((ch0 * p->ch0),
+               ch0lux = DIV_ROUND_UP(ch0 * p->ch0,
                        tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
-               ch1lux = DIV_ROUND_UP((ch1 * p->ch1),
+               ch1lux = DIV_ROUND_UP(ch1 * p->ch1,
                        tsl2X7X_als_gainadj[chip->tsl2x7x_settings.als_gain]);
                lux = ch0lux - ch1lux;
        }
@@ -678,7 +678,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 
        /* determine als integration register */
        als_count = (chip->tsl2x7x_settings.als_time * 100 + 135) / 270;
-       if (als_count == 0)
+       if (!als_count)
                als_count = 1; /* ensure at least one cycle */
 
        /* convert back to time (encompasses overrides) */
@@ -825,7 +825,7 @@ void tsl2x7x_prox_calculate(int *data, int length,
        int sample_sum;
        int tmp;
 
-       if (length == 0)
+       if (!length)
                length = 1;
 
        sample_sum = 0;
@@ -1057,7 +1057,7 @@ static ssize_t tsl2x7x_als_persistence_store(struct device *dev,
        z = y * TSL2X7X_MIN_ITIME;
 
        filter_delay =
-               DIV_ROUND_UP(((result.integer * 1000) + result.fract), z);
+               DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
 
        chip->tsl2x7x_settings.persistence &= 0xF0;
        chip->tsl2x7x_settings.persistence |= (filter_delay & 0x0F);
@@ -1103,7 +1103,7 @@ static ssize_t tsl2x7x_prox_persistence_store(struct device *dev,
        z = y * TSL2X7X_MIN_ITIME;
 
        filter_delay =
-               DIV_ROUND_UP(((result.integer * 1000) + result.fract), z);
+               DIV_ROUND_UP((result.integer * 1000) + result.fract, z);
 
        chip->tsl2x7x_settings.persistence &= 0x0F;
        chip->tsl2x7x_settings.persistence |= ((filter_delay << 4) & 0xF0);
index f3d0da2fe4589c29c9ff318cb64555f05ab46e1a..06f35d3828e48be6b0b93014e8a6fc56ab69e8be 100644 (file)
@@ -48,7 +48,7 @@ struct hmc5843_data {
 };
 
 int hmc5843_common_probe(struct device *dev, struct regmap *regmap,
-                        enum hmc5843_ids id);
+                        enum hmc5843_ids id, const char *name);
 int hmc5843_common_remove(struct device *dev);
 
 int hmc5843_common_suspend(struct device *dev);
index fffca3a9f637b868b00ec57126b84f4c72c64d7e..394bc141a1b0c01f3ebb8177092749c22afc628b 100644 (file)
@@ -334,7 +334,7 @@ static int hmc5843_get_scale_index(struct hmc5843_data *data, int val, int val2)
 {
        int i;
 
-       if (val != 0)
+       if (val)
                return -EINVAL;
 
        for (i = 0; i < data->variant->n_regval_to_nanoscale; i++)
@@ -577,7 +577,7 @@ int hmc5843_common_resume(struct device *dev)
 EXPORT_SYMBOL(hmc5843_common_resume);
 
 int hmc5843_common_probe(struct device *dev, struct regmap *regmap,
-                        enum hmc5843_ids id)
+                        enum hmc5843_ids id, const char *name)
 {
        struct hmc5843_data *data;
        struct iio_dev *indio_dev;
@@ -597,7 +597,7 @@ int hmc5843_common_probe(struct device *dev, struct regmap *regmap,
        mutex_init(&data->lock);
 
        indio_dev->dev.parent = dev;
-       indio_dev->name = dev->driver->name;
+       indio_dev->name = name;
        indio_dev->info = &hmc5843_info;
        indio_dev->modes = INDIO_DIRECT_MODE;
        indio_dev->channels = data->variant->channels;
index ff08667fa2f60071ab6a5dd800830db2ae03b224..3e06ceb32059663d1f62ce0daa209108c228d942 100644 (file)
@@ -61,7 +61,7 @@ static int hmc5843_i2c_probe(struct i2c_client *cli,
 {
        return hmc5843_common_probe(&cli->dev,
                        devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
-                       id->driver_data);
+                       id->driver_data, id->name);
 }
 
 static int hmc5843_i2c_remove(struct i2c_client *client)
index 070c918dadcfa1e5887dfe528687f4396036e9db..8be198058ea20452cd3623d6e3564c58537b8d15 100644 (file)
@@ -59,6 +59,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = {
 static int hmc5843_spi_probe(struct spi_device *spi)
 {
        int ret;
+       const struct spi_device_id *id = spi_get_device_id(spi);
 
        spi->mode = SPI_MODE_3;
        spi->max_speed_hz = 8000000;
@@ -69,7 +70,7 @@ static int hmc5843_spi_probe(struct spi_device *spi)
 
        return hmc5843_common_probe(&spi->dev,
                        devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
-                       HMC5983_ID);
+                       id->driver_data, id->name);
 }
 
 static int hmc5843_spi_remove(struct spi_device *spi)
@@ -81,6 +82,7 @@ static const struct spi_device_id hmc5843_id[] = {
        { "hmc5983", HMC5983_ID },
        { }
 };
+MODULE_DEVICE_TABLE(spi, hmc5843_id);
 
 static struct spi_driver hmc5843_driver = {
                .driver = {
index 9ca9fef4b8bac7ffa23484550e3449ac24519ffd..f129039bece3c74b96fb78e70996ea65279502ea 100644 (file)
@@ -219,7 +219,7 @@ static int ade7753_reset(struct device *dev)
        u16 val;
 
        ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
-       val |= 1 << 6; /* Software Chip Reset */
+       val |= BIT(6); /* Software Chip Reset */
 
        return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);
 }
@@ -328,10 +328,10 @@ static int ade7753_set_irq(struct device *dev, bool enable)
                goto error_ret;
 
        if (enable)
-               irqen |= 1 << 3; /* Enables an interrupt when a data is
+               irqen |= BIT(3); /* Enables an interrupt when a data is
                                    present in the waveform register */
        else
-               irqen &= ~(1 << 3);
+               irqen &= ~BIT(3);
 
        ret = ade7753_spi_write_reg_8(dev, ADE7753_IRQEN, irqen);
 
@@ -345,7 +345,7 @@ static int ade7753_stop_device(struct device *dev)
        u16 val;
 
        ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
-       val |= 1 << 4;  /* AD converters can be turned off */
+       val |= BIT(4);  /* AD converters can be turned off */
 
        return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);
 }
@@ -406,7 +406,7 @@ static ssize_t ade7753_write_frequency(struct device *dev,
        ret = kstrtou16(buf, 10, &val);
        if (ret)
                return ret;
-       if (val == 0)
+       if (!val)
                return -EINVAL;
 
        mutex_lock(&indio_dev->mlock);
index 5609872532f11b4a0a6fc8a5d69098dfabd48aea..1e950685e12f94bf3ee1864b9ff1b60a39845271 100644 (file)
@@ -223,7 +223,7 @@ static int ade7754_reset(struct device *dev)
        if (ret < 0)
                return ret;
 
-       val |= 1 << 6; /* Software Chip Reset */
+       val |= BIT(6); /* Software Chip Reset */
        return ade7754_spi_write_reg_8(dev, ADE7754_OPMODE, val);
 }
 
@@ -350,10 +350,10 @@ static int ade7754_set_irq(struct device *dev, bool enable)
                goto error_ret;
 
        if (enable)
-               irqen |= 1 << 14; /* Enables an interrupt when a data is
+               irqen |= BIT(14); /* Enables an interrupt when a data is
                                     present in the waveform register */
        else
-               irqen &= ~(1 << 14);
+               irqen &= ~BIT(14);
 
        ret = ade7754_spi_write_reg_16(dev, ADE7754_IRQEN, irqen);
        if (ret)
@@ -438,7 +438,7 @@ static ssize_t ade7754_write_frequency(struct device *dev,
        ret = kstrtou16(buf, 10, &val);
        if (ret)
                return ret;
-       if (val == 0)
+       if (!val)
                return -EINVAL;
 
        mutex_lock(&indio_dev->mlock);
index d348e161c8484a17ddd6bffc9306844078ba9752..0db23e4d1852b01936823da0c8c79225667d0049 100644 (file)
@@ -308,7 +308,7 @@ static int ade7758_reset(struct device *dev)
                dev_err(dev, "Failed to read opmode reg\n");
                return ret;
        }
-       val |= 1 << 6; /* Software Chip Reset */
+       val |= BIT(6); /* Software Chip Reset */
        ret = ade7758_spi_write_reg_8(dev, ADE7758_OPMODE, val);
        if (ret < 0)
                dev_err(dev, "Failed to write opmode reg\n");
@@ -426,10 +426,10 @@ int ade7758_set_irq(struct device *dev, bool enable)
                goto error_ret;
 
        if (enable)
-               irqen |= 1 << 16; /* Enables an interrupt when a data is
+               irqen |= BIT(16); /* Enables an interrupt when a data is
                                     present in the waveform register */
        else
-               irqen &= ~(1 << 16);
+               irqen &= ~BIT(16);
 
        ret = ade7758_spi_write_reg_24(dev, ADE7758_MASK, irqen);
        if (ret)
index f774a62cad4ef945d63f605c3185fd6c73329d17..684e612a88b934f7f3fde54799d2d2a2fe3ebe88 100644 (file)
@@ -224,7 +224,7 @@ static int ade7759_reset(struct device *dev)
        if (ret < 0)
                return ret;
 
-       val |= 1 << 6; /* Software Chip Reset */
+       val |= BIT(6); /* Software Chip Reset */
        return ade7759_spi_write_reg_16(dev,
                        ADE7759_MODE,
                        val);
@@ -288,10 +288,10 @@ static int ade7759_set_irq(struct device *dev, bool enable)
                goto error_ret;
 
        if (enable)
-               irqen |= 1 << 3; /* Enables an interrupt when a data is
+               irqen |= BIT(3); /* Enables an interrupt when a data is
                                    present in the waveform register */
        else
-               irqen &= ~(1 << 3);
+               irqen &= ~BIT(3);
 
        ret = ade7759_spi_write_reg_8(dev, ADE7759_IRQEN, irqen);
 
@@ -314,7 +314,7 @@ static int ade7759_stop_device(struct device *dev)
                return ret;
        }
 
-       val |= 1 << 4;  /* AD converters can be turned off */
+       val |= BIT(4);  /* AD converters can be turned off */
 
        return ade7759_spi_write_reg_16(dev, ADE7759_MODE, val);
 }
@@ -377,7 +377,7 @@ static ssize_t ade7759_write_frequency(struct device *dev,
        ret = kstrtou16(buf, 10, &val);
        if (ret)
                return ret;
-       if (val == 0)
+       if (!val)
                return -EINVAL;
 
        mutex_lock(&indio_dev->mlock);
index 16f288d8b8f6dc1d9647a0282b5832b29ccff2fc..2413052c5bfb5d23cd880d56e90127d367756528 100644 (file)
@@ -278,7 +278,7 @@ static int ade7854_spi_probe(struct spi_device *spi)
        struct iio_dev *indio_dev;
 
        indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-       if (indio_dev == NULL)
+       if (!indio_dev)
                return -ENOMEM;
        st = iio_priv(indio_dev);
        spi_set_drvdata(spi, indio_dev);
index d620bbd603a30db2264bb5f8499c142eb19a3d8c..a83883596dbcb41e73e8e494527b4a4f5c433e89 100644 (file)
@@ -181,7 +181,7 @@ static int ade7854_reset(struct device *dev)
        u16 val;
 
        st->read_reg_16(dev, ADE7854_CONFIG, &val);
-       val |= 1 << 7; /* Software Chip Reset */
+       val |= BIT(7); /* Software Chip Reset */
 
        return st->write_reg_16(dev, ADE7854_CONFIG, val);
 }
@@ -420,10 +420,10 @@ static int ade7854_set_irq(struct device *dev, bool enable)
                goto error_ret;
 
        if (enable)
-               irqen |= 1 << 17; /* 1: interrupt enabled when all periodical
+               irqen |= BIT(17); /* 1: interrupt enabled when all periodical
                                     (at 8 kHz rate) DSP computations finish. */
        else
-               irqen &= ~(1 << 17);
+               irqen &= ~BIT(17);
 
        ret = st->write_reg_32(dev, ADE7854_MASK0, irqen);
        if (ret)
index 95f5426a14d90a449a27433cc29fb48202aefed2..d97aa2827412a606de57a66e858db205a96f13a0 100644 (file)
@@ -633,7 +633,7 @@ error_ret:
 }
 
 static const struct iio_info ad2s1210_info = {
-       .read_raw = &ad2s1210_read_raw,
+       .read_raw = ad2s1210_read_raw,
        .attrs = &ad2s1210_attribute_group,
        .driver_module = THIS_MODULE,
 };
index cfeedfb7c774e1177a546c370a2ff1747e9dd2cf..5b1c0db33e7f2dfe4ddbebdc48c117b01f146e5b 100644 (file)
@@ -79,7 +79,7 @@ static int ad2s90_probe(struct spi_device *spi)
        indio_dev->num_channels = 1;
        indio_dev->name = spi_get_device_id(spi)->name;
 
-       ret = iio_device_register(indio_dev);
+       ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
        if (ret)
                return ret;
 
@@ -91,13 +91,6 @@ static int ad2s90_probe(struct spi_device *spi)
        return 0;
 }
 
-static int ad2s90_remove(struct spi_device *spi)
-{
-       iio_device_unregister(spi_get_drvdata(spi));
-
-       return 0;
-}
-
 static const struct spi_device_id ad2s90_id[] = {
        { "ad2s90" },
        {}
@@ -109,7 +102,6 @@ static struct spi_driver ad2s90_driver = {
                .name = "ad2s90",
        },
        .probe = ad2s90_probe,
-       .remove = ad2s90_remove,
        .id_table = ad2s90_id,
 };
 module_spi_driver(ad2s90_driver);
index 9fe48ef11473c204fae7e8a3fb542ded85226eee..035dd456d7d67e085db527e10cefad20216f5fc1 100644 (file)
@@ -100,7 +100,7 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
        if (enabled)
                disable_gptimers(st->t->bit);
 
-       if (val == 0)
+       if (!val)
                return count;
 
        val = get_sclk() / val;
@@ -125,7 +125,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
        unsigned int period = get_gptimer_period(st->t->id);
        unsigned long val;
 
-       if (period == 0)
+       if (!period)
                val = 0;
        else
                val = get_sclk() / get_gptimer_period(st->t->id);
index 2db885750fb84384653a54ab97089c835f479dca..00d1393312614f06215ec3f2d37e7a03ec3dcb0c 100644 (file)
@@ -39,7 +39,7 @@ static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state)
        dev_dbg(&trig_info->rtc->dev, "trigger frequency is %u\n",
                trig_info->frequency);
        ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, state);
-       if (ret == 0)
+       if (!ret)
                trig_info->state = state;
 
        return ret;
index 01961d9e6c363c25ba4764415f842dc3334c56ed..4d74e8af5088deec183c6d83cc16a5cfd1dc15fa 100644 (file)
@@ -62,9 +62,6 @@ static inline int __is_po2(unsigned long long val)
 
 #include <linux/list.h>
 
-int libcfs_arch_init(void);
-void libcfs_arch_cleanup(void);
-
 /* need both kernel and user-land acceptor */
 #define LNET_ACCEPTOR_MIN_RESERVED_PORT    512
 #define LNET_ACCEPTOR_MAX_RESERVED_PORT    1023
@@ -155,10 +152,16 @@ extern struct miscdevice libcfs_dev;
 extern char lnet_upcall[1024];
 extern char lnet_debug_log_upcall[1024];
 
-extern void libcfs_init_nidstrings(void);
-
 extern struct cfs_psdev_ops libcfs_psdev_ops;
 
 extern struct cfs_wi_sched *cfs_sched_rehash;
 
+struct lnet_debugfs_symlink_def {
+       char *name;
+       char *target;
+};
+
+void lustre_insert_debugfs(struct ctl_table *table,
+                          const struct lnet_debugfs_symlink_def *symlinks);
+
 #endif /* _LIBCFS_H */
index a3aa644154e24a578b84d125d26e811479656f2b..a1787bb43483b113632a7daa833cc5dd6a9b93df 100644 (file)
@@ -73,6 +73,7 @@ struct ptldebug_header {
        __u32 ph_mask;
        __u16 ph_cpu_id;
        __u16 ph_type;
+       /* time_t overflow in 2106 */
        __u32 ph_sec;
        __u64 ph_usec;
        __u32 ph_stack;
index c408145911899d353cbb5e589369b3663108cd09..70b8b29e831c95197069246efb4087617e13c37b 100644 (file)
@@ -88,10 +88,10 @@ union cfs_hash_lock {
  * cfs_hash_bucket is a container of:
  * - lock, counter ...
  * - array of hash-head starting from hsb_head[0], hash-head can be one of
- *   . cfs_hash_head_t
- *   . cfs_hash_head_dep_t
- *   . cfs_hash_dhead_t
- *   . cfs_hash_dhead_dep_t
+ *   . struct cfs_hash_head
+ *   . struct cfs_hash_head_dep
+ *   . struct cfs_hash_dhead
+ *   . struct cfs_hash_dhead_dep
  *   which depends on requirement of user
  * - some extra bytes (caller can require it while creating hash)
  */
@@ -211,13 +211,13 @@ enum cfs_hash_tag {
 struct cfs_hash {
        /** serialize with rehash, or serialize all operations if
         * the hash-table has CFS_HASH_NO_BKTLOCK */
-       union cfs_hash_lock          hs_lock;
+       union cfs_hash_lock              hs_lock;
        /** hash operations */
-       struct cfs_hash_ops     *hs_ops;
+       struct cfs_hash_ops             *hs_ops;
        /** hash lock operations */
-       struct cfs_hash_lock_ops   *hs_lops;
+       struct cfs_hash_lock_ops        *hs_lops;
        /** hash list operations */
-       struct cfs_hash_hlist_ops  *hs_hops;
+       struct cfs_hash_hlist_ops       *hs_hops;
        /** hash buckets-table */
        struct cfs_hash_bucket   **hs_buckets;
        /** total number of items on this hash-table */
@@ -272,7 +272,7 @@ struct cfs_hash {
        char                    hs_name[0];
 };
 
-typedef struct cfs_hash_lock_ops {
+struct cfs_hash_lock_ops {
        /** lock the hash table */
        void    (*hs_lock)(union cfs_hash_lock *lock, int exclusive);
        /** unlock the hash table */
@@ -281,24 +281,26 @@ typedef struct cfs_hash_lock_ops {
        void    (*hs_bkt_lock)(union cfs_hash_lock *lock, int exclusive);
        /** unlock the hash bucket */
        void    (*hs_bkt_unlock)(union cfs_hash_lock *lock, int exclusive);
-} cfs_hash_lock_ops_t;
+};
 
-typedef struct cfs_hash_hlist_ops {
+struct cfs_hash_hlist_ops {
        /** return hlist_head of hash-head of @bd */
-       struct hlist_head *(*hop_hhead)(struct cfs_hash *hs, struct cfs_hash_bd *bd);
+       struct hlist_head *(*hop_hhead)(struct cfs_hash *hs,
+                                       struct cfs_hash_bd *bd);
        /** return hash-head size */
        int (*hop_hhead_size)(struct cfs_hash *hs);
        /** add @hnode to hash-head of @bd */
-       int (*hop_hnode_add)(struct cfs_hash *hs,
-                            struct cfs_hash_bd *bd, struct hlist_node *hnode);
+       int (*hop_hnode_add)(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                            struct hlist_node *hnode);
        /** remove @hnode from hash-head of @bd */
-       int (*hop_hnode_del)(struct cfs_hash *hs,
-                            struct cfs_hash_bd *bd, struct hlist_node *hnode);
-} cfs_hash_hlist_ops_t;
+       int (*hop_hnode_del)(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                            struct hlist_node *hnode);
+};
 
-typedef struct cfs_hash_ops {
+struct cfs_hash_ops {
        /** return hashed value from @key */
-       unsigned (*hs_hash)(struct cfs_hash *hs, const void *key, unsigned mask);
+       unsigned (*hs_hash)(struct cfs_hash *hs, const void *key,
+                           unsigned mask);
        /** return key address of @hnode */
        void *   (*hs_key)(struct hlist_node *hnode);
        /** copy key from @hnode to @key */
@@ -315,10 +317,11 @@ typedef struct cfs_hash_ops {
        /** release refcount of item */
        void     (*hs_put)(struct cfs_hash *hs, struct hlist_node *hnode);
        /** release refcount of item, always called with holding bucket-lock */
-       void     (*hs_put_locked)(struct cfs_hash *hs, struct hlist_node *hnode);
+       void     (*hs_put_locked)(struct cfs_hash *hs,
+                                 struct hlist_node *hnode);
        /** it's called before removing of @hnode */
        void     (*hs_exit)(struct cfs_hash *hs, struct hlist_node *hnode);
-} cfs_hash_ops_t;
+};
 
 /** total number of buckets in @hs */
 #define CFS_HASH_NBKT(hs)       \
@@ -546,22 +549,26 @@ static inline void cfs_hash_bd_unlock(struct cfs_hash *hs,
  * operations on cfs_hash bucket (bd: bucket descriptor),
  * they are normally for hash-table without rehash
  */
-void cfs_hash_bd_get(struct cfs_hash *hs, const void *key, struct cfs_hash_bd *bd);
+void cfs_hash_bd_get(struct cfs_hash *hs, const void *key,
+                    struct cfs_hash_bd *bd);
 
-static inline void cfs_hash_bd_get_and_lock(struct cfs_hash *hs, const void *key,
-                                           struct cfs_hash_bd *bd, int excl)
+static inline void
+cfs_hash_bd_get_and_lock(struct cfs_hash *hs, const void *key,
+                        struct cfs_hash_bd *bd, int excl)
 {
        cfs_hash_bd_get(hs, key, bd);
        cfs_hash_bd_lock(hs, bd, excl);
 }
 
-static inline unsigned cfs_hash_bd_index_get(struct cfs_hash *hs, struct cfs_hash_bd *bd)
+static inline unsigned
+cfs_hash_bd_index_get(struct cfs_hash *hs, struct cfs_hash_bd *bd)
 {
        return bd->bd_offset | (bd->bd_bucket->hsb_index << hs->hs_bkt_bits);
 }
 
-static inline void cfs_hash_bd_index_set(struct cfs_hash *hs,
-                                        unsigned index, struct cfs_hash_bd *bd)
+static inline void
+cfs_hash_bd_index_set(struct cfs_hash *hs, unsigned index,
+                     struct cfs_hash_bd *bd)
 {
        bd->bd_bucket = hs->hs_buckets[index >> hs->hs_bkt_bits];
        bd->bd_offset = index & (CFS_HASH_BKT_NHLIST(hs) - 1U);
@@ -611,67 +618,73 @@ void cfs_hash_bd_add_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
 void cfs_hash_bd_del_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                            struct hlist_node *hnode);
 void cfs_hash_bd_move_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd_old,
-                            struct cfs_hash_bd *bd_new, struct hlist_node *hnode);
+                            struct cfs_hash_bd *bd_new,
+                            struct hlist_node *hnode);
 
-static inline int cfs_hash_bd_dec_and_lock(struct cfs_hash *hs, struct cfs_hash_bd *bd,
-                                          atomic_t *condition)
+static inline int
+cfs_hash_bd_dec_and_lock(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                        atomic_t *condition)
 {
        LASSERT(cfs_hash_with_spin_bktlock(hs));
-       return atomic_dec_and_lock(condition,
-                                      &bd->bd_bucket->hsb_lock.spin);
+       return atomic_dec_and_lock(condition, &bd->bd_bucket->hsb_lock.spin);
 }
 
-static inline struct hlist_head *cfs_hash_bd_hhead(struct cfs_hash *hs,
-                                                  struct cfs_hash_bd *bd)
+static inline struct hlist_head *
+cfs_hash_bd_hhead(struct cfs_hash *hs, struct cfs_hash_bd *bd)
 {
        return hs->hs_hops->hop_hhead(hs, bd);
 }
 
-struct hlist_node *cfs_hash_bd_lookup_locked(struct cfs_hash *hs,
-                                            struct cfs_hash_bd *bd, const void *key);
-struct hlist_node *cfs_hash_bd_peek_locked(struct cfs_hash *hs,
-                                          struct cfs_hash_bd *bd, const void *key);
-struct hlist_node *cfs_hash_bd_findadd_locked(struct cfs_hash *hs,
-                                             struct cfs_hash_bd *bd, const void *key,
-                                            struct hlist_node *hnode,
-                                            int insist_add);
-struct hlist_node *cfs_hash_bd_finddel_locked(struct cfs_hash *hs,
-                                             struct cfs_hash_bd *bd, const void *key,
-                                            struct hlist_node *hnode);
+struct hlist_node *
+cfs_hash_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                         const void *key);
+struct hlist_node *
+cfs_hash_bd_peek_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                       const void *key);
+struct hlist_node *
+cfs_hash_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                          const void *key, struct hlist_node *hnode,
+                          int insist_add);
+struct hlist_node *
+cfs_hash_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
+                          const void *key, struct hlist_node *hnode);
 
 /**
  * operations on cfs_hash bucket (bd: bucket descriptor),
  * they are safe for hash-table with rehash
  */
-void cfs_hash_dual_bd_get(struct cfs_hash *hs, const void *key, struct cfs_hash_bd *bds);
-void cfs_hash_dual_bd_lock(struct cfs_hash *hs, struct cfs_hash_bd *bds, int excl);
-void cfs_hash_dual_bd_unlock(struct cfs_hash *hs, struct cfs_hash_bd *bds, int excl);
+void cfs_hash_dual_bd_get(struct cfs_hash *hs, const void *key,
+                         struct cfs_hash_bd *bds);
+void cfs_hash_dual_bd_lock(struct cfs_hash *hs, struct cfs_hash_bd *bds,
+                          int excl);
+void cfs_hash_dual_bd_unlock(struct cfs_hash *hs, struct cfs_hash_bd *bds,
+                            int excl);
 
-static inline void cfs_hash_dual_bd_get_and_lock(struct cfs_hash *hs, const void *key,
-                                                struct cfs_hash_bd *bds, int excl)
+static inline void
+cfs_hash_dual_bd_get_and_lock(struct cfs_hash *hs, const void *key,
+                             struct cfs_hash_bd *bds, int excl)
 {
        cfs_hash_dual_bd_get(hs, key, bds);
        cfs_hash_dual_bd_lock(hs, bds, excl);
 }
 
-struct hlist_node *cfs_hash_dual_bd_lookup_locked(struct cfs_hash *hs,
-                                                 struct cfs_hash_bd *bds,
-                                                const void *key);
-struct hlist_node *cfs_hash_dual_bd_findadd_locked(struct cfs_hash *hs,
-                                                  struct cfs_hash_bd *bds,
-                                                 const void *key,
-                                                 struct hlist_node *hnode,
-                                                 int insist_add);
-struct hlist_node *cfs_hash_dual_bd_finddel_locked(struct cfs_hash *hs,
-                                                  struct cfs_hash_bd *bds,
-                                                 const void *key,
-                                                 struct hlist_node *hnode);
+struct hlist_node *
+cfs_hash_dual_bd_lookup_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds,
+                              const void *key);
+struct hlist_node *
+cfs_hash_dual_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds,
+                               const void *key, struct hlist_node *hnode,
+                               int insist_add);
+struct hlist_node *
+cfs_hash_dual_bd_finddel_locked(struct cfs_hash *hs, struct cfs_hash_bd *bds,
+                               const void *key, struct hlist_node *hnode);
 
 /* Hash init/cleanup functions */
-struct cfs_hash *cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits,
-                                unsigned bkt_bits, unsigned extra_bytes,
-                           unsigned min_theta, unsigned max_theta,
-                           cfs_hash_ops_t *ops, unsigned flags);
+struct cfs_hash *
+cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits,
+               unsigned bkt_bits, unsigned extra_bytes,
+               unsigned min_theta, unsigned max_theta,
+               struct cfs_hash_ops *ops, unsigned flags);
 
 struct cfs_hash *cfs_hash_getref(struct cfs_hash *hs);
 void cfs_hash_putref(struct cfs_hash *hs);
@@ -685,28 +698,39 @@ void *cfs_hash_findadd_unique(struct cfs_hash *hs, const void *key,
                              struct hlist_node *hnode);
 
 /* Hash deletion functions */
-void *cfs_hash_del(struct cfs_hash *hs, const void *key, struct hlist_node *hnode);
+void *cfs_hash_del(struct cfs_hash *hs, const void *key,
+                  struct hlist_node *hnode);
 void *cfs_hash_del_key(struct cfs_hash *hs, const void *key);
 
 /* Hash lookup/for_each functions */
 #define CFS_HASH_LOOP_HOG       1024
 
-typedef int (*cfs_hash_for_each_cb_t)(struct cfs_hash *hs, struct cfs_hash_bd *bd,
-                                     struct hlist_node *node, void *data);
-void *cfs_hash_lookup(struct cfs_hash *hs, const void *key);
-void cfs_hash_for_each(struct cfs_hash *hs, cfs_hash_for_each_cb_t, void *data);
-void cfs_hash_for_each_safe(struct cfs_hash *hs, cfs_hash_for_each_cb_t, void *data);
-int  cfs_hash_for_each_nolock(struct cfs_hash *hs,
-                             cfs_hash_for_each_cb_t, void *data);
-int  cfs_hash_for_each_empty(struct cfs_hash *hs,
-                            cfs_hash_for_each_cb_t, void *data);
-void cfs_hash_for_each_key(struct cfs_hash *hs, const void *key,
-                          cfs_hash_for_each_cb_t, void *data);
+typedef int (*cfs_hash_for_each_cb_t)(struct cfs_hash *hs,
+                                     struct cfs_hash_bd *bd,
+                                     struct hlist_node *node,
+                                     void *data);
+void *
+cfs_hash_lookup(struct cfs_hash *hs, const void *key);
+void
+cfs_hash_for_each(struct cfs_hash *hs, cfs_hash_for_each_cb_t, void *data);
+void
+cfs_hash_for_each_safe(struct cfs_hash *hs, cfs_hash_for_each_cb_t, void *data);
+int
+cfs_hash_for_each_nolock(struct cfs_hash *hs, cfs_hash_for_each_cb_t,
+                        void *data);
+int
+cfs_hash_for_each_empty(struct cfs_hash *hs, cfs_hash_for_each_cb_t,
+                       void *data);
+void
+cfs_hash_for_each_key(struct cfs_hash *hs, const void *key,
+                     cfs_hash_for_each_cb_t, void *data);
 typedef int (*cfs_hash_cond_opt_cb_t)(void *obj, void *data);
-void cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t, void *data);
+void
+cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t, void *data);
 
-void cfs_hash_hlist_for_each(struct cfs_hash *hs, unsigned hindex,
-                            cfs_hash_for_each_cb_t, void *data);
+void
+cfs_hash_hlist_for_each(struct cfs_hash *hs, unsigned hindex,
+                       cfs_hash_for_each_cb_t, void *data);
 int  cfs_hash_is_empty(struct cfs_hash *hs);
 __u64 cfs_hash_size_get(struct cfs_hash *hs);
 
@@ -776,7 +800,8 @@ static inline int __cfs_hash_theta(struct cfs_hash *hs)
                CFS_HASH_THETA_BITS) >> hs->hs_cur_bits;
 }
 
-static inline void __cfs_hash_set_theta(struct cfs_hash *hs, int min, int max)
+static inline void
+__cfs_hash_set_theta(struct cfs_hash *hs, int min, int max)
 {
        LASSERT(min < max);
        hs->hs_min_theta = (__u16)min;
index 978d3e2f16d3ddab44dcac70435ec80a94fd6458..082fe6de90e494aa99d813e6bc59821b37fb80e7 100644 (file)
 #ifndef __LIBCFS_PRIM_H__
 #define __LIBCFS_PRIM_H__
 
-/*
- * Timer
- */
-typedef  void (cfs_timer_func_t)(ulong_ptr_t);
-
 void add_wait_queue_exclusive_head(wait_queue_head_t *, wait_queue_t *);
 
-void cfs_init_timer(struct timer_list *t);
-void cfs_timer_init(struct timer_list *t, cfs_timer_func_t *func, void *arg);
-void cfs_timer_done(struct timer_list *t);
-void cfs_timer_arm(struct timer_list *t, unsigned long deadline);
-void cfs_timer_disarm(struct timer_list *t);
-int  cfs_timer_is_armed(struct timer_list *t);
-unsigned long cfs_timer_deadline(struct timer_list *t);
-
 /*
  * Memory
  */
index 9544860e32920a851dd35f20757a199ea5346fef..6af733de69caddbf7672b80e75e1827304e7b237 100644 (file)
@@ -79,7 +79,7 @@ do {                                                                  \
 
 #define KLASSERT(e) LASSERT(e)
 
-void lbug_with_loc(struct libcfs_debug_msg_data *)__attribute__((noreturn));
+void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *);
 
 #define LBUG()                                                   \
 do {                                                               \
index 478e9582ff5414bf63e7e27ac963413f2d22bb46..d8d2e7dc212e8798dfcea9026e103d9d19e41818 100644 (file)
@@ -83,6 +83,8 @@ int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
 int cfs_str2num_check(char *str, int nob, unsigned *num,
                      unsigned min, unsigned max);
 int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
+int cfs_expr_list_print(char *buffer, int count,
+                       struct cfs_expr_list *expr_list);
 int cfs_expr_list_values(struct cfs_expr_list *expr_list,
                         int max, __u32 **values);
 static inline void
@@ -98,8 +100,5 @@ void cfs_expr_list_free(struct cfs_expr_list *expr_list);
 int cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
                        struct cfs_expr_list **elpp);
 void cfs_expr_list_free_list(struct list_head *list);
-int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
-int cfs_ip_addr_match(__u32 addr, struct list_head *list);
-void cfs_ip_addr_free(struct list_head *list);
 
 #endif
index 5de6da085712bc7647c878ae7b8efd46a9d9e9c6..2c7ec2d28f38fb36dcded7b9b66a75d0d3d2257f 100644 (file)
@@ -68,55 +68,6 @@ static inline unsigned long cfs_time_shift(int seconds)
        return cfs_time_add(cfs_time_current(), cfs_time_seconds(seconds));
 }
 
-static inline long cfs_timeval_sub(struct timeval *large, struct timeval *small,
-                                  struct timeval *result)
-{
-       long r = (long)(
-               (large->tv_sec - small->tv_sec) * ONE_MILLION +
-               (large->tv_usec - small->tv_usec));
-       if (result != NULL) {
-               result->tv_usec = r % ONE_MILLION;
-               result->tv_sec = r / ONE_MILLION;
-       }
-       return r;
-}
-
-static inline void cfs_slow_warning(unsigned long now, int seconds, char *msg)
-{
-       if (cfs_time_after(cfs_time_current(),
-                          cfs_time_add(now, cfs_time_seconds(15))))
-               CERROR("slow %s "CFS_TIME_T" sec\n", msg,
-                      cfs_duration_sec(cfs_time_sub(cfs_time_current(), now)));
-}
-
-#define CFS_RATELIMIT(seconds)                           \
-({                                                           \
-       /*                                                    \
-        * XXX nikita: non-portable initializer          \
-        */                                                  \
-       static time_t __next_message;                  \
-       int result;                                          \
-                                                               \
-       if (cfs_time_after(cfs_time_current(), __next_message)) \
-               result = 1;                                  \
-       else {                                            \
-               __next_message = cfs_time_shift(seconds);       \
-               result = 0;                                  \
-       }                                                      \
-       result;                                          \
-})
-
-/*
- * helper function similar to do_gettimeofday() of Linux kernel
- */
-static inline void cfs_fs_timeval(struct timeval *tv)
-{
-       struct timespec time;
-
-       cfs_fs_time_current(&time);
-       cfs_fs_time_usec(&time, tv);
-}
-
 /*
  * return valid time-out based on user supplied one. Currently we only check
  * that time-out is not shorted than allowed.
index 3e2502a69bbd16cb7ef36727c5051d9f76db5e28..aac59008ad1ab5444497bffb8646857ef0a922bb 100644 (file)
@@ -41,7 +41,6 @@
 #error Do not #include this file directly. #include <linux/libcfs/libcfs.h> instead
 #endif
 
-
 #include <linux/bitops.h>
 #include <linux/compiler.h>
 #include <linux/ctype.h>
@@ -86,7 +85,6 @@
 #include "linux-time.h"
 #include "linux-mem.h"
 
-
 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
 
 #if !defined(__x86_64__)
@@ -142,5 +140,4 @@ typedef long long_ptr_t;
 #define WITH_WATCHDOG
 #endif
 
-
 #endif /* _LINUX_LIBCFS_H */
index 0fc490bac2b5907a2d09a0ad132f5f1455baa01e..ed8764b11c8077c580b60c6965f711071c09c0f1 100644 (file)
 
 #include <linux/jiffies.h>
 
-
-static inline void cfs_fs_time_usec(struct timespec *t, struct timeval *v)
-{
-       v->tv_sec  = t->tv_sec;
-       v->tv_usec = t->tv_nsec / 1000;
-}
-
 /*
  * Generic kernel stuff
  */
@@ -75,41 +68,16 @@ static inline unsigned long cfs_time_current(void)
        return jiffies;
 }
 
-static inline void cfs_fs_time_current(struct timespec *t)
-{
-       *t = CURRENT_TIME;
-}
-
-static inline time_t cfs_fs_time_sec(struct timespec *t)
-{
-       return t->tv_sec;
-}
-
 static inline long cfs_time_seconds(int seconds)
 {
        return ((long)seconds) * HZ;
 }
 
-static inline time_t cfs_duration_sec(long d)
+static inline long cfs_duration_sec(long d)
 {
        return d / HZ;
 }
 
-static inline void cfs_duration_usec(long d, struct timeval *s)
-{
-#if (BITS_PER_LONG == 32) && (HZ > 4096)
-       __u64 t;
-
-       s->tv_sec = d / HZ;
-       t = (d - (long)s->tv_sec * HZ) * ONE_MILLION;
-       do_div(t, HZ);
-       s->tv_usec = t;
-#else
-       s->tv_sec = d / HZ;
-       s->tv_usec = ((d - (long)s->tv_sec * HZ) * ONE_MILLION) / HZ;
-#endif
-}
-
 #define cfs_time_current_64 get_jiffies_64
 
 static inline __u64 cfs_time_add_64(__u64 t, __u64 d)
@@ -138,7 +106,6 @@ static inline int cfs_time_beforeq_64(__u64 t1, __u64 t2)
  */
 #define CFS_TICK               (1)
 
-#define CFS_TIME_T           "%lu"
 #define CFS_DURATION_T   "%ld"
 
 #endif /* __LIBCFS_LINUX_LINUX_TIME_H__ */
index a9c9a077c77d3e12d10a6620a19866a40749e00d..b61d5045a56667857e48cf3b5759bb79709a4b54 100644 (file)
@@ -443,8 +443,8 @@ int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
 void lnet_destroy_routes(void);
 int lnet_get_route(int idx, __u32 *net, __u32 *hops,
                   lnet_nid_t *gateway, __u32 *alive, __u32 *priority);
-void lnet_proc_init(void);
-void lnet_proc_fini(void);
+void lnet_router_debugfs_init(void);
+void lnet_router_debugfs_fini(void);
 int  lnet_rtrpools_alloc(int im_a_router);
 void lnet_rtrpools_free(void);
 lnet_remotenet_t *lnet_find_net_locked(__u32 net);
@@ -680,7 +680,7 @@ void lnet_debug_peer(lnet_nid_t nid);
 static inline void
 lnet_peer_set_alive(lnet_peer_t *lp)
 {
-       lp->lp_last_alive = lp->lp_last_query = get_seconds();
+       lp->lp_last_alive = lp->lp_last_query = jiffies;
        if (!lp->lp_alive)
                lnet_notify_locked(lp, 0, 1, lp->lp_last_alive);
 }
index 81a63dbdea252d096132017e6bb3d1ce0b762b55..d792c4adb0ca4fbf56d45ec2221d17215167285f 100644 (file)
@@ -264,7 +264,7 @@ typedef struct lnet_ni {
        lnd_t                    *ni_lnd;       /* procedural interface */
        struct lnet_tx_queue    **ni_tx_queues; /* percpt TX queues */
        int                     **ni_refs;      /* percpt reference count */
-       long                      ni_last_alive;/* when I was last alive */
+       time64_t                  ni_last_alive;/* when I was last alive */
        lnet_ni_status_t         *ni_status;    /* my health status */
        /* equivalent interfaces to use */
        char                     *ni_interfaces[LNET_MAX_INTERFACES];
index a627be9fcdd0a2a18f418f6166ac15aed6741182..46ad9147ad2a4ef173bee3f5c9761adc8e1d93a0 100644 (file)
@@ -57,21 +57,58 @@ struct list_head;
 #define LNET_NIDSTR_COUNT  1024    /* # of nidstrings */
 #define LNET_NIDSTR_SIZE   32      /* size of each one (see below for usage) */
 
-int libcfs_isknown_lnd(int type);
-char *libcfs_lnd2modname(int type);
-char *libcfs_lnd2str(int type);
+/* support decl needed by both kernel and user space */
+char *libcfs_next_nidstring(void);
+int libcfs_isknown_lnd(__u32 lnd);
+char *libcfs_lnd2modname(__u32 lnd);
+char *libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size);
+static inline char *libcfs_lnd2str(__u32 lnd)
+{
+       return libcfs_lnd2str_r(lnd, libcfs_next_nidstring(),
+                               LNET_NIDSTR_SIZE);
+}
 int libcfs_str2lnd(const char *str);
-char *libcfs_net2str(__u32 net);
-char *libcfs_nid2str(lnet_nid_t nid);
+char *libcfs_net2str_r(__u32 net, char *buf, size_t buf_size);
+static inline char *libcfs_net2str(__u32 net)
+{
+       return libcfs_net2str_r(net, libcfs_next_nidstring(),
+                               LNET_NIDSTR_SIZE);
+}
+char *libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size);
+static inline char *libcfs_nid2str(lnet_nid_t nid)
+{
+       return libcfs_nid2str_r(nid, libcfs_next_nidstring(),
+                               LNET_NIDSTR_SIZE);
+}
 __u32 libcfs_str2net(const char *str);
 lnet_nid_t libcfs_str2nid(const char *str);
 int libcfs_str2anynid(lnet_nid_t *nid, const char *str);
 char *libcfs_id2str(lnet_process_id_t id);
 void cfs_free_nidlist(struct list_head *list);
 int cfs_parse_nidlist(char *str, int len, struct list_head *list);
+int cfs_print_nidlist(char *buffer, int count, struct list_head *list);
 int cfs_match_nid(lnet_nid_t nid, struct list_head *list);
+
+int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
+int cfs_ip_addr_match(__u32 addr, struct list_head *list);
 bool cfs_nidrange_is_contiguous(struct list_head *nidlist);
 void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
                               char *max_nid, size_t nidstr_length);
 
+struct netstrfns {
+       __u32   nf_type;
+       char    *nf_name;
+       char    *nf_modname;
+       void    (*nf_addr2str)(__u32 addr, char *str, size_t size);
+       int     (*nf_str2addr)(const char *str, int nob, __u32 *addr);
+       int     (*nf_parse_addrlist)(char *str, int len,
+                                    struct list_head *list);
+       int     (*nf_print_addrlist)(char *buffer, int count,
+                                    struct list_head *list);
+       int     (*nf_match_addr)(__u32 addr, struct list_head *list);
+       bool    (*nf_is_contiguous)(struct list_head *nidlist);
+       void    (*nf_min_max)(struct list_head *nidlist, __u32 *min_nid,
+                             __u32 *max_nid);
+};
+
 #endif /* _LNET_NIDSTRINGS_H */
index 940f73f266d18e5dc477e9a1f2338e773010cc75..11630180c5e7b4a2815cb28bb4021d5f043c20a0 100644 (file)
@@ -303,7 +303,7 @@ static inline int LNetHandleIsEqual(lnet_handle_any_t h1, lnet_handle_any_t h2)
  */
 static inline int LNetHandleIsInvalid(lnet_handle_any_t h)
 {
-       return LNET_WIRE_HANDLE_COOKIE_NONE == h.cookie;
+       return h.cookie == LNET_WIRE_HANDLE_COOKIE_NONE;
 }
 
 /**
index c29d2ced258ce4339f684da4e83bf57050f5f6c1..7c730e3f7453ec034c5f2bc1ad824eb18715b1e7 100644 (file)
@@ -2154,23 +2154,23 @@ static int kiblnd_hdev_setup_mrs(kib_hca_dev_t *hdev)
        if (rc != 0)
                return rc;
 
-               LIBCFS_ALLOC(hdev->ibh_mrs, 1 * sizeof(*hdev->ibh_mrs));
-               if (hdev->ibh_mrs == NULL) {
-                       CERROR("Failed to allocate MRs table\n");
-                       return -ENOMEM;
-               }
+       LIBCFS_ALLOC(hdev->ibh_mrs, 1 * sizeof(*hdev->ibh_mrs));
+       if (hdev->ibh_mrs == NULL) {
+               CERROR("Failed to allocate MRs table\n");
+               return -ENOMEM;
+       }
 
-               hdev->ibh_mrs[0] = NULL;
-               hdev->ibh_nmrs   = 1;
+       hdev->ibh_mrs[0] = NULL;
+       hdev->ibh_nmrs   = 1;
 
-               mr = ib_get_dma_mr(hdev->ibh_pd, acflags);
-               if (IS_ERR(mr)) {
-                       CERROR("Failed ib_get_dma_mr : %ld\n", PTR_ERR(mr));
-                       kiblnd_hdev_cleanup_mrs(hdev);
-                       return PTR_ERR(mr);
-               }
+       mr = ib_get_dma_mr(hdev->ibh_pd, acflags);
+       if (IS_ERR(mr)) {
+               CERROR("Failed ib_get_dma_mr : %ld\n", PTR_ERR(mr));
+               kiblnd_hdev_cleanup_mrs(hdev);
+               return PTR_ERR(mr);
+       }
 
-               hdev->ibh_mrs[0] = mr;
+       hdev->ibh_mrs[0] = mr;
 
        return 0;
 }
@@ -2228,13 +2228,10 @@ static int kiblnd_dev_need_failover(kib_dev_t *dev)
                return rc;
        }
 
-       if (dev->ibd_hdev->ibh_ibdev == cmid->device) {
-               /* don't need device failover */
-               rdma_destroy_id(cmid);
-               return 0;
-       }
+       rc = dev->ibd_hdev->ibh_ibdev != cmid->device; /* true for failover */
+       rdma_destroy_id(cmid);
 
-       return 1;
+       return rc;
 }
 
 int kiblnd_dev_failover(kib_dev_t *dev)
@@ -2752,7 +2749,7 @@ int kiblnd_startup(lnet_ni_t *ni)
        char *ifname;
        kib_dev_t *ibdev = NULL;
        kib_net_t *net;
-       struct timeval tv;
+       struct timespec64 tv;
        unsigned long flags;
        int rc;
        int newdev;
@@ -2770,8 +2767,9 @@ int kiblnd_startup(lnet_ni_t *ni)
        if (net == NULL)
                goto net_failed;
 
-       do_gettimeofday(&tv);
-       net->ibn_incarnation = (((__u64)tv.tv_sec) * 1000000) + tv.tv_usec;
+       ktime_get_real_ts64(&tv);
+       net->ibn_incarnation = tv.tv_sec * USEC_PER_SEC +
+                              tv.tv_nsec / NSEC_PER_USEC;
 
        ni->ni_peertimeout    = *kiblnd_tunables.kib_peertimeout;
        ni->ni_maxtxcredits   = *kiblnd_tunables.kib_credits;
index 993d1ff9ba21987612362d122b7082242314b313..263db37de7c807821ffe98b2156252b4ecf24ebf 100644 (file)
 #define IBLND_N_SCHED_HIGH             4
 
 typedef struct {
-       int          *kib_dev_failover;      /* HCA failover */
-       unsigned int *kib_service;           /* IB service number */
-       int          *kib_min_reconnect_interval; /* first failed connection
-                                                  * retry... */
-       int          *kib_max_reconnect_interval; /* ...exponentially increasing
-                                                  * to this */
-       int          *kib_cksum;             /* checksum kib_msg_t? */
-       int          *kib_timeout;           /* comms timeout (seconds) */
-       int          *kib_keepalive;         /* keepalive timeout (seconds) */
-       int          *kib_ntx;               /* # tx descs */
-       int          *kib_credits;           /* # concurrent sends */
-       int          *kib_peertxcredits;     /* # concurrent sends to 1 peer */
-       int          *kib_peerrtrcredits;    /* # per-peer router buffer
-                                             * credits */
-       int          *kib_peercredits_hiw;   /* # when eagerly to return
-                                             * credits */
-       int          *kib_peertimeout;       /* seconds to consider peer dead */
-       char         **kib_default_ipif;     /* default IPoIB interface */
-       int          *kib_retry_count;
-       int          *kib_rnr_retry_count;
-       int          *kib_concurrent_sends;  /* send work queue sizing */
-       int          *kib_ib_mtu;            /* IB MTU */
-       int          *kib_map_on_demand;     /* map-on-demand if RD has more
-                                             * fragments than this value, 0
-                                             * disable map-on-demand */
-       int          *kib_fmr_pool_size;     /* # FMRs in pool */
-       int          *kib_fmr_flush_trigger; /* When to trigger FMR flush */
-       int          *kib_fmr_cache;         /* enable FMR pool cache? */
-       int          *kib_require_priv_port; /* accept only privileged ports */
-       int          *kib_use_priv_port;     /* use privileged port for active
-                                             * connect */
-       int          *kib_nscheds;           /* # threads on each CPT */
+       int *kib_dev_failover;           /* HCA failover */
+       unsigned int *kib_service;       /* IB service number */
+       int *kib_min_reconnect_interval; /* first failed connection retry... */
+       int *kib_max_reconnect_interval; /* exponentially increasing to this */
+       int *kib_cksum;                  /* checksum kib_msg_t? */
+       int *kib_timeout;                /* comms timeout (seconds) */
+       int *kib_keepalive;              /* keepalive timeout (seconds) */
+       int *kib_ntx;                    /* # tx descs */
+       int *kib_credits;                /* # concurrent sends */
+       int *kib_peertxcredits;          /* # concurrent sends to 1 peer */
+       int *kib_peerrtrcredits;         /* # per-peer router buffer credits */
+       int *kib_peercredits_hiw;        /* # when eagerly to return credits */
+       int *kib_peertimeout;            /* seconds to consider peer dead */
+       char **kib_default_ipif;         /* default IPoIB interface */
+       int *kib_retry_count;
+       int *kib_rnr_retry_count;
+       int *kib_concurrent_sends;       /* send work queue sizing */
+       int *kib_ib_mtu;                 /* IB MTU */
+       int *kib_map_on_demand;          /* map-on-demand if RD has more */
+                                        /* fragments than this value, 0 */
+                                        /* disable map-on-demand */
+       int *kib_fmr_pool_size;          /* # FMRs in pool */
+       int *kib_fmr_flush_trigger;      /* When to trigger FMR flush */
+       int *kib_fmr_cache;              /* enable FMR pool cache? */
+       int *kib_require_priv_port;      /* accept only privileged ports */
+       int *kib_use_priv_port; /* use privileged port for active connect */
+       int *kib_nscheds;                /* # threads on each CPT */
 } kib_tunables_t;
 
 extern kib_tunables_t  kiblnd_tunables;
@@ -201,8 +196,7 @@ typedef struct {
        unsigned long      ibd_next_failover;
        int                ibd_failed_failover; /* # failover failures */
        unsigned int       ibd_failover;        /* failover in progress */
-       unsigned int       ibd_can_failover;    /* IPoIB interface is a bonding
-                                                * master */
+       unsigned int ibd_can_failover; /* IPoIB interface is a bonding master */
        struct list_head   ibd_nets;
        struct kib_hca_dev *ibd_hdev;
 } kib_dev_t;
@@ -251,28 +245,26 @@ typedef struct kib_poolset {
        char                  ps_name[IBLND_POOL_NAME_LEN]; /* pool set name */
        struct list_head      ps_pool_list;       /* list of pools */
        struct list_head      ps_failed_pool_list;/* failed pool list */
-       unsigned long         ps_next_retry;      /* time stamp for retry if
-                                                  * failed to allocate */
+       unsigned long         ps_next_retry;      /* time stamp for retry if */
+                                                 /* failed to allocate */
        int                   ps_increasing;      /* is allocating new pool */
        int                   ps_pool_size;       /* new pool size */
        int                   ps_cpt;             /* CPT id */
 
        kib_ps_pool_create_t  ps_pool_create;     /* create a new pool */
        kib_ps_pool_destroy_t ps_pool_destroy;    /* destroy a pool */
-       kib_ps_node_init_t    ps_node_init;       /* initialize new allocated
-                                                  * node */
+       kib_ps_node_init_t    ps_node_init; /* initialize new allocated node */
        kib_ps_node_fini_t    ps_node_fini;       /* finalize node */
 } kib_poolset_t;
 
 typedef struct kib_pool {
-       struct list_head      po_list;         /* chain on pool list */
-       struct list_head      po_free_list;    /* pre-allocated node */
-       kib_poolset_t         *po_owner;       /* pool_set of this pool */
-       unsigned long         po_deadline;     /* deadline of this pool */
-       int                   po_allocated;    /* # of elements in use */
-       int                   po_failed;       /* pool is created on failed
-                                               * HCA */
-       int                   po_size;         /* # of pre-allocated elements */
+       struct list_head      po_list;       /* chain on pool list */
+       struct list_head      po_free_list;  /* pre-allocated node */
+       kib_poolset_t         *po_owner;     /* pool_set of this pool */
+       unsigned long         po_deadline;   /* deadline of this pool */
+       int                   po_allocated;  /* # of elements in use */
+       int                   po_failed;     /* pool is created on failed HCA */
+       int                   po_size;       /* # of pre-allocated elements */
 } kib_pool_t;
 
 typedef struct {
@@ -297,8 +289,8 @@ typedef struct {
        int                   fps_pool_size;
        int                   fps_flush_trigger;
        int                   fps_increasing;      /* is allocating new pool */
-       unsigned long         fps_next_retry;      /* time stamp for retry if
-                                                   * failed to allocate */
+       unsigned long         fps_next_retry;      /* time stamp for retry if*/
+                                                  /* failed to allocate */
 } kib_fmr_poolset_t;
 
 typedef struct {
@@ -346,31 +338,22 @@ struct kib_sched_info {
 };
 
 typedef struct {
-       int                   kib_init;           /* initialisation state */
-       int                   kib_shutdown;       /* shut down? */
-       struct list_head      kib_devs;           /* IB devices extant */
-       struct list_head      kib_failed_devs;    /* list head of failed
-                                                  * devices */
-       wait_queue_head_t     kib_failover_waitq; /* schedulers sleep here */
-       atomic_t              kib_nthreads;       /* # live threads */
-       rwlock_t              kib_global_lock;    /* stabilize net/dev/peer/conn
-                                                  * ops */
-       struct list_head      *kib_peers;         /* hash table of all my known
-                                                  * peers */
-       int                   kib_peer_hash_size; /* size of kib_peers */
-       void                  *kib_connd;         /* the connd task
-                                                  * (serialisation assertions)
-                                                  */
-       struct list_head      kib_connd_conns;    /* connections to
-                                                  * setup/teardown */
-       struct list_head      kib_connd_zombies;  /* connections with zero
-                                                  * refcount */
-       wait_queue_head_t     kib_connd_waitq;    /* connection daemon sleeps
-                                                  * here */
-       spinlock_t            kib_connd_lock;     /* serialise */
-       struct ib_qp_attr     kib_error_qpa;      /* QP->ERROR */
-       struct kib_sched_info **kib_scheds;       /* percpt data for schedulers
-                                                  */
+       int               kib_init;           /* initialisation state */
+       int               kib_shutdown;       /* shut down? */
+       struct list_head  kib_devs;           /* IB devices extant */
+       struct list_head  kib_failed_devs;    /* list head of failed devices */
+       wait_queue_head_t kib_failover_waitq; /* schedulers sleep here */
+       atomic_t kib_nthreads;                /* # live threads */
+       rwlock_t kib_global_lock;    /* stabilize net/dev/peer/conn ops */
+       struct list_head *kib_peers; /* hash table of all my known peers */
+       int  kib_peer_hash_size;     /* size of kib_peers */
+       void *kib_connd; /* the connd task (serialisation assertions) */
+       struct list_head kib_connd_conns;   /* connections to setup/teardown */
+       struct list_head kib_connd_zombies; /* connections with zero refcount */
+       wait_queue_head_t kib_connd_waitq;  /* connection daemon sleeps here */
+       spinlock_t kib_connd_lock;          /* serialise */
+       struct ib_qp_attr kib_error_qpa;    /* QP->ERROR */
+       struct kib_sched_info **kib_scheds; /* percpt data for schedulers */
 } kib_data_t;
 
 #define IBLND_INIT_NOTHING 0
@@ -482,10 +465,10 @@ typedef struct {
 #define IBLND_REJECT_FATAL          3 /* Anything else */
 #define IBLND_REJECT_CONN_UNCOMPAT  4 /* incompatible version peer */
 #define IBLND_REJECT_CONN_STALE     5 /* stale peer */
-#define IBLND_REJECT_RDMA_FRAGS     6 /* Fatal: peer's rdma frags can't match
-                                      * mine */
-#define IBLND_REJECT_MSG_QUEUE_SIZE 7 /* Fatal: peer's msg queue size can't
-                                      * match mine */
+#define IBLND_REJECT_RDMA_FRAGS     6 /* Fatal: peer's rdma frags can't match */
+                                     /* mine */
+#define IBLND_REJECT_MSG_QUEUE_SIZE 7 /* Fatal: peer's msg queue size can't */
+                                     /* match mine */
 
 /***********************************************************************/
 
@@ -493,8 +476,7 @@ typedef struct kib_rx                         /* receive message */
 {
        struct list_head       rx_list;       /* queue for attention */
        struct kib_conn        *rx_conn;      /* owning conn */
-       int                    rx_nob;        /* # bytes received (-1 while
-                                              * posted) */
+       int                    rx_nob; /* # bytes received (-1 while posted) */
        enum ib_wc_status      rx_status;     /* completion status */
        kib_msg_t              *rx_msg;       /* message buffer (host vaddr) */
        __u64                  rx_msgaddr;    /* message buffer (I/O addr) */
@@ -503,38 +485,35 @@ typedef struct kib_rx                         /* receive message */
        struct ib_sge          rx_sge;        /* ...and its memory */
 } kib_rx_t;
 
-#define IBLND_POSTRX_DONT_POST    0   /* don't post */
-#define IBLND_POSTRX_NO_CREDIT    1   /* post: no credits */
-#define IBLND_POSTRX_PEER_CREDIT  2   /* post: give peer back 1 credit */
-#define IBLND_POSTRX_RSRVD_CREDIT 3   /* post: give myself back 1 reserved
-                                      * credit */
+#define IBLND_POSTRX_DONT_POST    0 /* don't post */
+#define IBLND_POSTRX_NO_CREDIT    1 /* post: no credits */
+#define IBLND_POSTRX_PEER_CREDIT  2 /* post: give peer back 1 credit */
+#define IBLND_POSTRX_RSRVD_CREDIT 3 /* post: give self back 1 reserved credit */
 
 typedef struct kib_tx                         /* transmit message */
 {
-       struct list_head       tx_list;       /* queue on idle_txs ibc_tx_queue
-                                              * etc. */
-       kib_tx_pool_t          *tx_pool;      /* pool I'm from */
-       struct kib_conn        *tx_conn;      /* owning conn */
-       short                  tx_sending;    /* # tx callbacks outstanding */
-       short                  tx_queued;     /* queued for sending */
-       short                  tx_waiting;    /* waiting for peer */
-       int                    tx_status;     /* LNET completion status */
-       unsigned long          tx_deadline;   /* completion deadline */
-       __u64                  tx_cookie;     /* completion cookie */
-       lnet_msg_t             *tx_lntmsg[2]; /* lnet msgs to finalize on
-                                              * completion */
-       kib_msg_t              *tx_msg;       /* message buffer (host vaddr) */
-       __u64                  tx_msgaddr;    /* message buffer (I/O addr) */
+       struct list_head      tx_list; /* queue on idle_txs ibc_tx_queue etc. */
+       kib_tx_pool_t         *tx_pool;       /* pool I'm from */
+       struct kib_conn       *tx_conn;       /* owning conn */
+       short                 tx_sending;     /* # tx callbacks outstanding */
+       short                 tx_queued;      /* queued for sending */
+       short                 tx_waiting;     /* waiting for peer */
+       int                   tx_status;      /* LNET completion status */
+       unsigned long         tx_deadline;    /* completion deadline */
+       __u64                 tx_cookie;      /* completion cookie */
+       lnet_msg_t *tx_lntmsg[2]; /* lnet msgs to finalize on completion */
+       kib_msg_t             *tx_msg;        /* message buffer (host vaddr) */
+       __u64                 tx_msgaddr;     /* message buffer (I/O addr) */
        DECLARE_PCI_UNMAP_ADDR(tx_msgunmap);  /* for dma_unmap_single() */
-       int                    tx_nwrq;       /* # send work items */
-       struct ib_rdma_wr      *tx_wrq;       /* send work items... */
-       struct ib_sge          *tx_sge;       /* ...and their memory */
-       kib_rdma_desc_t        *tx_rd;        /* rdma descriptor */
-       int                    tx_nfrags;     /* # entries in... */
-       struct scatterlist     *tx_frags;     /* dma_map_sg descriptor */
-       __u64                  *tx_pages;     /* rdma phys page addrs */
-       kib_fmr_t               fmr;          /* FMR */
-       int                    tx_dmadir;     /* dma direction */
+       int                   tx_nwrq;        /* # send work items */
+       struct ib_rdma_wr     *tx_wrq;        /* send work items... */
+       struct ib_sge         *tx_sge;        /* ...and their memory */
+       kib_rdma_desc_t       *tx_rd;         /* rdma descriptor */
+       int                   tx_nfrags;      /* # entries in... */
+       struct scatterlist    *tx_frags;      /* dma_map_sg descriptor */
+       __u64                 *tx_pages;      /* rdma phys page addrs */
+       kib_fmr_t             fmr;            /* FMR */
+       int                   tx_dmadir;      /* dma direction */
 } kib_tx_t;
 
 typedef struct kib_connvars {
@@ -542,53 +521,44 @@ typedef struct kib_connvars {
 } kib_connvars_t;
 
 typedef struct kib_conn {
-       struct kib_sched_info *ibc_sched;           /* scheduler information */
-       struct kib_peer       *ibc_peer;            /* owning peer */
-       kib_hca_dev_t         *ibc_hdev;            /* HCA bound on */
-       struct list_head      ibc_list;             /* stash on peer's conn
-                                                    * list */
-       struct list_head      ibc_sched_list;       /* schedule for attention */
-       __u16                 ibc_version;          /* version of connection */
-       __u64                 ibc_incarnation;      /* which instance of the
-                                                    * peer */
-       atomic_t              ibc_refcount;         /* # users */
-       int                   ibc_state;            /* what's happening */
-       int                   ibc_nsends_posted;    /* # uncompleted sends */
-       int                   ibc_noops_posted;     /* # uncompleted NOOPs */
-       int                   ibc_credits;          /* # credits I have */
+       struct kib_sched_info *ibc_sched;      /* scheduler information */
+       struct kib_peer       *ibc_peer;       /* owning peer */
+       kib_hca_dev_t         *ibc_hdev;       /* HCA bound on */
+       struct list_head ibc_list;             /* stash on peer's conn list */
+       struct list_head      ibc_sched_list;  /* schedule for attention */
+       __u16                 ibc_version;     /* version of connection */
+       __u64                 ibc_incarnation; /* which instance of the peer */
+       atomic_t              ibc_refcount;    /* # users */
+       int                   ibc_state;       /* what's happening */
+       int                   ibc_nsends_posted; /* # uncompleted sends */
+       int                   ibc_noops_posted;  /* # uncompleted NOOPs */
+       int                   ibc_credits;     /* # credits I have */
        int                   ibc_outstanding_credits; /* # credits to return */
        int                   ibc_reserved_credits; /* # ACK/DONE msg credits */
-       int                   ibc_comms_error;      /* set on comms error */
-       unsigned int          ibc_nrx:16;           /* receive buffers owned */
-       unsigned int          ibc_scheduled:1;      /* scheduled for attention
-                                                    */
-       unsigned int          ibc_ready:1;          /* CQ callback fired */
-       unsigned long         ibc_last_send;        /* time of last send */
-       struct list_head      ibc_connd_list;       /* link chain for
-                                                    * kiblnd_check_conns only
-                                                    */
-       struct list_head      ibc_early_rxs;        /* rxs completed before
-                                                    * ESTABLISHED */
-       struct list_head      ibc_tx_noops;         /* IBLND_MSG_NOOPs for
-                                                    * IBLND_MSG_VERSION_1 */
-       struct list_head      ibc_tx_queue;         /* sends that need a credit
-                                                    */
-       struct list_head      ibc_tx_queue_nocred;  /* sends that don't need a
-                                                    * credit */
-       struct list_head      ibc_tx_queue_rsrvd;   /* sends that need to
-                                                    * reserve an ACK/DONE msg
-                                                    */
-       struct list_head      ibc_active_txs;       /* active tx awaiting
-                                                    * completion */
-       spinlock_t            ibc_lock;             /* serialise */
-       kib_rx_t              *ibc_rxs;             /* the rx descs */
-       kib_pages_t           *ibc_rx_pages;        /* premapped rx msg pages */
-
-       struct rdma_cm_id     *ibc_cmid;            /* CM id */
-       struct ib_cq          *ibc_cq;              /* completion queue */
-
-       kib_connvars_t        *ibc_connvars;        /* in-progress connection
-                                                    * state */
+       int                   ibc_comms_error; /* set on comms error */
+       unsigned int          ibc_nrx:16;      /* receive buffers owned */
+       unsigned int          ibc_scheduled:1; /* scheduled for attention */
+       unsigned int          ibc_ready:1;     /* CQ callback fired */
+       unsigned long         ibc_last_send;   /* time of last send */
+       struct list_head      ibc_connd_list;  /* link chain for */
+                                              /* kiblnd_check_conns only */
+       struct list_head ibc_early_rxs; /* rxs completed before ESTABLISHED */
+       struct list_head ibc_tx_noops;         /* IBLND_MSG_NOOPs for */
+                                              /* IBLND_MSG_VERSION_1 */
+       struct list_head ibc_tx_queue;         /* sends that need a credit */
+       struct list_head ibc_tx_queue_nocred;  /* sends that don't need a */
+                                              /* credit */
+       struct list_head ibc_tx_queue_rsrvd;   /* sends that need to */
+                                              /* reserve an ACK/DONE msg */
+       struct list_head ibc_active_txs; /* active tx awaiting completion */
+       spinlock_t            ibc_lock;        /* serialise */
+       kib_rx_t              *ibc_rxs;        /* the rx descs */
+       kib_pages_t           *ibc_rx_pages;   /* premapped rx msg pages */
+
+       struct rdma_cm_id     *ibc_cmid;       /* CM id */
+       struct ib_cq          *ibc_cq;         /* completion queue */
+
+       kib_connvars_t        *ibc_connvars; /* in-progress connection state */
 } kib_conn_t;
 
 #define IBLND_CONN_INIT           0     /* being initialised */
@@ -782,8 +752,8 @@ kiblnd_queue2str(kib_conn_t *conn, struct list_head *q)
        return NULL;
 }
 
-/* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the
- * lowest bits of the work request id to stash the work item type. */
+/* CAVEAT EMPTOR: We rely on descriptor alignment to allow us to use the */
+/* lowest bits of the work request id to stash the work item type. */
 
 #define IBLND_WID_TX    0
 #define IBLND_WID_RDMA  1
@@ -880,7 +850,6 @@ kiblnd_rd_msg_size(kib_rdma_desc_t *rd, int msgtype, int n)
               offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[n]);
 }
 
-
 static inline __u64
 kiblnd_dma_mapping_error(struct ib_device *dev, u64 dma_addr)
 {
@@ -930,23 +899,19 @@ static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
        return ib_sg_dma_len(dev, sg);
 }
 
-/* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly
- * right because OFED1.2 defines it as const, to use it we have to add
- * (void *) cast to overcome "const" */
+/* XXX We use KIBLND_CONN_PARAM(e) as writable buffer, it's not strictly */
+/* right because OFED1.2 defines it as const, to use it we have to add */
+/* (void *) cast to overcome "const" */
 
 #define KIBLND_CONN_PARAM(e)     ((e)->param.conn.private_data)
 #define KIBLND_CONN_PARAM_LEN(e) ((e)->param.conn.private_data_len)
 
-
 struct ib_mr *kiblnd_find_rd_dma_mr(kib_hca_dev_t *hdev,
                                    kib_rdma_desc_t *rd);
 struct ib_mr *kiblnd_find_dma_mr(kib_hca_dev_t *hdev,
                                 __u64 addr, __u64 size);
 void kiblnd_map_rx_descs(kib_conn_t *conn);
 void kiblnd_unmap_rx_descs(kib_conn_t *conn);
-int kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx,
-                 kib_rdma_desc_t *rd, int nfrags);
-void kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx);
 void kiblnd_pool_free_node(kib_pool_t *pool, struct list_head *node);
 struct list_head *kiblnd_pool_alloc_node(kib_poolset_t *ps);
 
index a34f1707c16700accd94ace637cc30f29a5be49e..260750354a41707311aaec9afde6667e34959e5a 100644 (file)
@@ -40,6 +40,8 @@
 
 #include "o2iblnd.h"
 
+static void kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx);
+
 static void
 kiblnd_tx_done(lnet_ni_t *ni, kib_tx_t *tx)
 {
@@ -178,24 +180,28 @@ kiblnd_post_rx(kib_rx_t *rx, int credit)
 
        rx->rx_nob = -1;                        /* flag posted */
 
+       /* NB: need an extra reference after ib_post_recv because we don't
+        * own this rx (and rx::rx_conn) anymore, LU-5678.
+        */
+       kiblnd_conn_addref(conn);
        rc = ib_post_recv(conn->ibc_cmid->qp, &rx->rx_wrq, &bad_wrq);
-       if (rc != 0) {
+       if (unlikely(rc != 0)) {
                CERROR("Can't post rx for %s: %d, bad_wrq: %p\n",
                       libcfs_nid2str(conn->ibc_peer->ibp_nid), rc, bad_wrq);
                rx->rx_nob = 0;
        }
 
        if (conn->ibc_state < IBLND_CONN_ESTABLISHED) /* Initial post */
-               return rc;
+               goto out;
 
-       if (rc != 0) {
+       if (unlikely(rc != 0)) {
                kiblnd_close_conn(conn, rc);
                kiblnd_drop_rx(rx);          /* No more posts for this rx */
-               return rc;
+               goto out;
        }
 
        if (credit == IBLND_POSTRX_NO_CREDIT)
-               return 0;
+               goto out;
 
        spin_lock(&conn->ibc_lock);
        if (credit == IBLND_POSTRX_PEER_CREDIT)
@@ -205,7 +211,9 @@ kiblnd_post_rx(kib_rx_t *rx, int credit)
        spin_unlock(&conn->ibc_lock);
 
        kiblnd_check_sends(conn);
-       return 0;
+out:
+       kiblnd_conn_decref(conn);
+       return rc;
 }
 
 static kib_tx_t *
@@ -253,11 +261,10 @@ kiblnd_handle_completion(kib_conn_t *conn, int txtype, int status, __u64 cookie)
        }
 
        if (tx->tx_status == 0) {              /* success so far */
-               if (status < 0) {              /* failed? */
+               if (status < 0) /* failed? */
                        tx->tx_status = status;
-               } else if (txtype == IBLND_MSG_GET_REQ) {
+               else if (txtype == IBLND_MSG_GET_REQ)
                        lnet_set_reply_msg_len(ni, tx->tx_lntmsg[1], status);
-               }
        }
 
        tx->tx_waiting = 0;
@@ -591,8 +598,7 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, int nob)
        return 0;
 }
 
-void
-kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx)
+static void kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx)
 {
        kib_net_t *net = ni->ni_data;
 
@@ -610,9 +616,8 @@ kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx)
        }
 }
 
-int
-kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx,
-             kib_rdma_desc_t *rd, int nfrags)
+static int kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
+                        int nfrags)
 {
        kib_hca_dev_t *hdev = tx->tx_pool->tpo_hdev;
        kib_net_t *net = ni->ni_data;
@@ -650,7 +655,6 @@ kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx,
        return -EINVAL;
 }
 
-
 static int
 kiblnd_setup_rd_iov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
                    unsigned int niov, struct kvec *iov, int offset, int nob)
@@ -1423,6 +1427,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
        unsigned int payload_offset = lntmsg->msg_offset;
        unsigned int payload_nob = lntmsg->msg_len;
        kib_msg_t *ibmsg;
+       kib_rdma_desc_t  *rd;
        kib_tx_t *tx;
        int nob;
        int rc;
@@ -1466,16 +1471,14 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
                }
 
                ibmsg = tx->tx_msg;
-
+               rd = &ibmsg->ibm_u.get.ibgm_rd;
                if ((lntmsg->msg_md->md_options & LNET_MD_KIOV) == 0)
-                       rc = kiblnd_setup_rd_iov(ni, tx,
-                                                &ibmsg->ibm_u.get.ibgm_rd,
+                       rc = kiblnd_setup_rd_iov(ni, tx, rd,
                                                 lntmsg->msg_md->md_niov,
                                                 lntmsg->msg_md->md_iov.iov,
                                                 0, lntmsg->msg_md->md_length);
                else
-                       rc = kiblnd_setup_rd_kiov(ni, tx,
-                                                 &ibmsg->ibm_u.get.ibgm_rd,
+                       rc = kiblnd_setup_rd_kiov(ni, tx, rd,
                                                  lntmsg->msg_md->md_niov,
                                                  lntmsg->msg_md->md_iov.kiov,
                                                  0, lntmsg->msg_md->md_length);
@@ -1486,7 +1489,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
                        return -EIO;
                }
 
-               nob = offsetof(kib_get_msg_t, ibgm_rd.rd_frags[tx->tx_nfrags]);
+               nob = offsetof(kib_get_msg_t, ibgm_rd.rd_frags[rd->rd_nfrags]);
                ibmsg->ibm_u.get.ibgm_cookie = tx->tx_cookie;
                ibmsg->ibm_u.get.ibgm_hdr = *hdr;
 
@@ -1651,7 +1654,6 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
        kib_msg_t *rxmsg = rx->rx_msg;
        kib_conn_t *conn = rx->rx_conn;
        kib_tx_t *tx;
-       kib_msg_t *txmsg;
        int nob;
        int post_credit = IBLND_POSTRX_PEER_CREDIT;
        int rc = 0;
@@ -1688,7 +1690,10 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
                lnet_finalize(ni, lntmsg, 0);
                break;
 
-       case IBLND_MSG_PUT_REQ:
+       case IBLND_MSG_PUT_REQ: {
+               kib_msg_t       *txmsg;
+               kib_rdma_desc_t *rd;
+
                if (mlen == 0) {
                        lnet_finalize(ni, lntmsg, 0);
                        kiblnd_send_completion(rx->rx_conn, IBLND_MSG_PUT_NAK, 0,
@@ -1706,13 +1711,12 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
                }
 
                txmsg = tx->tx_msg;
+               rd = &txmsg->ibm_u.putack.ibpam_rd;
                if (kiov == NULL)
-                       rc = kiblnd_setup_rd_iov(ni, tx,
-                                                &txmsg->ibm_u.putack.ibpam_rd,
+                       rc = kiblnd_setup_rd_iov(ni, tx, rd,
                                                 niov, iov, offset, mlen);
                else
-                       rc = kiblnd_setup_rd_kiov(ni, tx,
-                                                 &txmsg->ibm_u.putack.ibpam_rd,
+                       rc = kiblnd_setup_rd_kiov(ni, tx, rd,
                                                  niov, kiov, offset, mlen);
                if (rc != 0) {
                        CERROR("Can't setup PUT sink for %s: %d\n",
@@ -1724,7 +1728,7 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
                        break;
                }
 
-               nob = offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[tx->tx_nfrags]);
+               nob = offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[rd->rd_nfrags]);
                txmsg->ibm_u.putack.ibpam_src_cookie = rxmsg->ibm_u.putreq.ibprm_cookie;
                txmsg->ibm_u.putack.ibpam_dst_cookie = tx->tx_cookie;
 
@@ -1737,6 +1741,7 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
                /* reposted buffer reserved for PUT_DONE */
                post_credit = IBLND_POSTRX_NO_CREDIT;
                break;
+               }
 
        case IBLND_MSG_GET_REQ:
                if (lntmsg != NULL) {
@@ -2149,6 +2154,7 @@ kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
        unsigned long flags;
        int rc;
        struct sockaddr_in *peer_addr;
+
        LASSERT(!in_interrupt());
 
        /* cmid inherits 'context' from the corresponding listener id */
@@ -2164,6 +2170,7 @@ kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
        if (*kiblnd_tunables.kib_require_priv_port &&
            ntohs(peer_addr->sin_port) >= PROT_SOCK) {
                __u32 ip = ntohl(peer_addr->sin_addr.s_addr);
+
                CERROR("Peer's port (%pI4h:%hu) is not privileged\n",
                       &ip, ntohs(peer_addr->sin_port));
                goto failed;
@@ -3228,7 +3235,7 @@ kiblnd_cq_completion(struct ib_cq *cq, void *arg)
         * consuming my CQ I could be called after all completions have
         * occurred.  But in this case, ibc_nrx == 0 && ibc_nsends_posted == 0
         * and this CQ is about to be destroyed so I NOOP. */
-       kib_conn_t *conn = (kib_conn_t *)arg;
+       kib_conn_t *conn = arg;
        struct kib_sched_info *sched = conn->ibc_sched;
        unsigned long flags;
 
index b3d1b5d627cbd85015695107a824b71da7dc85e9..1d4e7efb53d482b17b6b634e93e56b9bf0622f95 100644 (file)
@@ -135,7 +135,6 @@ static int dev_failover;
 module_param(dev_failover, int, 0444);
 MODULE_PARM_DESC(dev_failover, "HCA failover for bonding (0 off, 1 on, other values reserved)");
 
-
 static int require_privileged_port;
 module_param(require_privileged_port, int, 0644);
 MODULE_PARM_DESC(require_privileged_port, "require privileged port when accepting connection");
index d8bfcadd184a8bb94001b65619e63b6104e71e64..ecfe7330235031468234c9d040b979067697e1d5 100644 (file)
@@ -1838,7 +1838,6 @@ ksocknal_query(lnet_ni_t *ni, lnet_nid_t nid, unsigned long *when)
                ksocknal_launch_all_connections_locked(peer);
 
        write_unlock_bh(glock);
-       return;
 }
 
 static void
@@ -1874,52 +1873,51 @@ ksocknal_push_peer(ksock_peer_t *peer)
        }
 }
 
-static int
-ksocknal_push(lnet_ni_t *ni, lnet_process_id_t id)
+static int ksocknal_push(lnet_ni_t *ni, lnet_process_id_t id)
 {
-       ksock_peer_t *peer;
+       struct list_head *start;
+       struct list_head *end;
        struct list_head *tmp;
-       int index;
-       int i;
-       int j;
        int rc = -ENOENT;
+       unsigned int hsize = ksocknal_data.ksnd_peer_hash_size;
 
-       for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-               for (j = 0; ; j++) {
-                       read_lock(&ksocknal_data.ksnd_global_lock);
+       if (id.nid == LNET_NID_ANY) {
+               start = &ksocknal_data.ksnd_peers[0];
+               end = &ksocknal_data.ksnd_peers[hsize - 1];
+       } else {
+               start = end = ksocknal_nid2peerlist(id.nid);
+       }
 
-                       index = 0;
-                       peer = NULL;
+       for (tmp = start; tmp <= end; tmp++) {
+               int peer_off; /* searching offset in peer hash table */
 
-                       list_for_each(tmp, &ksocknal_data.ksnd_peers[i]) {
-                               peer = list_entry(tmp, ksock_peer_t,
-                                                     ksnp_list);
+               for (peer_off = 0; ; peer_off++) {
+                       ksock_peer_t *peer;
+                       int i = 0;
 
+                       read_lock(&ksocknal_data.ksnd_global_lock);
+                       list_for_each_entry(peer, tmp, ksnp_list) {
                                if (!((id.nid == LNET_NID_ANY ||
                                       id.nid == peer->ksnp_id.nid) &&
                                      (id.pid == LNET_PID_ANY ||
-                                      id.pid == peer->ksnp_id.pid))) {
-                                       peer = NULL;
+                                      id.pid == peer->ksnp_id.pid)))
                                        continue;
-                               }
 
-                               if (index++ == j) {
+                               if (i++ == peer_off) {
                                        ksocknal_peer_addref(peer);
                                        break;
                                }
                        }
-
                        read_unlock(&ksocknal_data.ksnd_global_lock);
 
-                       if (peer != NULL) {
-                               rc = 0;
-                               ksocknal_push_peer(peer);
-                               ksocknal_peer_decref(peer);
-                       }
-               }
+                       if (i == 0) /* no match */
+                               break;
 
+                       rc = 0;
+                       ksocknal_push_peer(peer);
+                       ksocknal_peer_decref(peer);
+               }
        }
-
        return rc;
 }
 
@@ -2261,9 +2259,8 @@ ksocknal_base_shutdown(void)
        case SOCKNAL_INIT_ALL:
        case SOCKNAL_INIT_DATA:
                LASSERT(ksocknal_data.ksnd_peers != NULL);
-               for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
+               for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++)
                        LASSERT(list_empty(&ksocknal_data.ksnd_peers[i]));
-               }
 
                LASSERT(list_empty(&ksocknal_data.ksnd_nets));
                LASSERT(list_empty(&ksocknal_data.ksnd_enomem_conns));
@@ -2427,7 +2424,7 @@ ksocknal_base_startup(void)
 
        ksocknal_data.ksnd_connd_starting       = 0;
        ksocknal_data.ksnd_connd_failed_stamp   = 0;
-       ksocknal_data.ksnd_connd_starting_stamp = get_seconds();
+       ksocknal_data.ksnd_connd_starting_stamp = ktime_get_real_seconds();
        /* must have at least 2 connds to remain responsive to accepts while
         * connecting */
        if (*ksocknal_tunables.ksnd_nconnds < SOCKNAL_CONND_RESV + 1)
@@ -2441,11 +2438,11 @@ ksocknal_base_startup(void)
 
        for (i = 0; i < *ksocknal_tunables.ksnd_nconnds; i++) {
                char name[16];
+
                spin_lock_bh(&ksocknal_data.ksnd_connd_lock);
                ksocknal_data.ksnd_connd_starting++;
                spin_unlock_bh(&ksocknal_data.ksnd_connd_lock);
 
-
                snprintf(name, sizeof(name), "socknal_cd%02d", i);
                rc = ksocknal_thread_start(ksocknal_connd,
                                           (void *)((ulong_ptr_t)i), name);
@@ -2706,6 +2703,7 @@ ksocknal_start_schedulers(struct ksock_sched_info *info)
                long id;
                char name[20];
                ksock_sched_t *sched;
+
                id = KSOCK_THREAD_ID(info->ksi_cpt, info->ksi_nthreads + i);
                sched = &info->ksi_scheds[KSOCK_THREAD_SID(id)];
                snprintf(name, sizeof(name), "socknal_sd%02d_%02d",
@@ -2835,7 +2833,6 @@ ksocknal_startup(lnet_ni_t *ni)
        return -ENETDOWN;
 }
 
-
 static void __exit
 ksocknal_module_fini(void)
 {
index a0fcbc39f86b918ba052329ff1073ef346e219af..b349847f9cf96418f355d9e1c3a6b04c7d9f5f6d 100644 (file)
@@ -216,13 +216,13 @@ typedef struct {
        wait_queue_head_t       ksnd_connd_waitq;       /* connds sleep here */
        int                     ksnd_connd_connecting;  /* # connds connecting
                                                         */
-       long                    ksnd_connd_failed_stamp;/* time stamp of the
+       time64_t                ksnd_connd_failed_stamp;/* time stamp of the
                                                         * last failed
                                                         * connecting attempt */
-       unsigned                ksnd_connd_starting;    /* # starting connd */
-       long                    ksnd_connd_starting_stamp;/* time stamp of the
+       time64_t                ksnd_connd_starting_stamp;/* time stamp of the
                                                           * last starting connd
                                                           */
+       unsigned                ksnd_connd_starting;    /* # starting connd */
        unsigned                ksnd_connd_running;     /* # running connd */
        spinlock_t              ksnd_connd_lock;        /* serialise */
 
index 0d5aac6a2bb3c4c6e941588e378a794ff5559859..477b385f15e058a642d278ab500f2d78263287a9 100644 (file)
@@ -89,7 +89,6 @@ ksocknal_alloc_tx_noop(__u64 cookie, int nonblk)
        return tx;
 }
 
-
 void
 ksocknal_free_tx (ksock_tx_t *tx)
 {
@@ -299,6 +298,7 @@ ksocknal_recv_kiov (ksock_conn_t *conn)
        lnet_kiov_t *kiov = conn->ksnc_rx_kiov;
        int nob;
        int rc;
+
        LASSERT(conn->ksnc_rx_nkiov > 0);
 
        /* Never touch conn->ksnc_rx_kiov or change connection
@@ -626,7 +626,7 @@ ksocknal_find_conn_locked(ksock_peer_t *peer, ksock_tx_t *tx, int nonblk)
        list_for_each (tmp, &peer->ksnp_conns) {
                ksock_conn_t *c  = list_entry(tmp, ksock_conn_t, ksnc_list);
                int nob = atomic_read(&c->ksnc_tx_nob) +
-                                      c->ksnc_sock->sk->sk_wmem_queued;
+                       c->ksnc_sock->sk->sk_wmem_queued;
                int rc;
 
                LASSERT(!c->ksnc_closing);
@@ -714,7 +714,7 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
        LASSERT(tx->tx_resid == tx->tx_nob);
 
        CDEBUG (D_NET, "Packet %p type %d, nob %d niov %d nkiov %d\n",
-               tx, (tx->tx_lnetmsg != NULL) ? tx->tx_lnetmsg->msg_hdr.type:
+               tx, (tx->tx_lnetmsg != NULL) ? tx->tx_lnetmsg->msg_hdr.type :
                                               KSOCK_MSG_NOOP,
                tx->tx_nob, tx->tx_niov, tx->tx_nkiov);
 
@@ -772,7 +772,6 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
        spin_unlock_bh(&sched->kss_lock);
 }
 
-
 ksock_route_t *
 ksocknal_find_connectable_route_locked (ksock_peer_t *peer)
 {
@@ -1092,7 +1091,7 @@ ksocknal_new_packet (ksock_conn_t *conn, int nob_to_skip)
                conn->ksnc_rx_iov[niov].iov_len  = nob;
                niov++;
                skipped += nob;
-               nob_to_skip -=nob;
+               nob_to_skip -= nob;
 
        } while (nob_to_skip != 0 &&    /* mustn't overflow conn's rx iov */
                 niov < sizeof(conn->ksnc_rx_iov_space) / sizeof (struct iovec));
@@ -1313,7 +1312,7 @@ ksocknal_recv (lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
               unsigned int niov, struct kvec *iov, lnet_kiov_t *kiov,
               unsigned int offset, unsigned int mlen, unsigned int rlen)
 {
-       ksock_conn_t *conn = (ksock_conn_t *)private;
+       ksock_conn_t *conn = private;
        ksock_sched_t *sched = conn->ksnc_scheduler;
 
        LASSERT(mlen <= rlen);
@@ -1998,7 +1997,7 @@ ksocknal_connect (ksock_route_t *route)
  * running out of resource.
  */
 static int
-ksocknal_connd_check_start(long sec, long *timeout)
+ksocknal_connd_check_start(time64_t sec, long *timeout)
 {
        char name[16];
        int rc;
@@ -2048,7 +2047,7 @@ ksocknal_connd_check_start(long sec, long *timeout)
        /* we tried ... */
        LASSERT(ksocknal_data.ksnd_connd_starting > 0);
        ksocknal_data.ksnd_connd_starting--;
-       ksocknal_data.ksnd_connd_failed_stamp = get_seconds();
+       ksocknal_data.ksnd_connd_failed_stamp = ktime_get_real_seconds();
 
        return 1;
 }
@@ -2060,7 +2059,7 @@ ksocknal_connd_check_start(long sec, long *timeout)
  * again to recheck these conditions.
  */
 static int
-ksocknal_connd_check_stop(long sec, long *timeout)
+ksocknal_connd_check_stop(time64_t sec, long *timeout)
 {
        int val;
 
@@ -2141,7 +2140,7 @@ ksocknal_connd (void *arg)
 
        while (!ksocknal_data.ksnd_shuttingdown) {
                ksock_route_t *route = NULL;
-               long sec = get_seconds();
+               time64_t sec = ktime_get_real_seconds();
                long timeout = MAX_SCHEDULE_TIMEOUT;
                int dropped_lock = 0;
 
@@ -2240,6 +2239,7 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
 
        list_for_each (ctmp, &peer->ksnp_conns) {
                int error;
+
                conn = list_entry (ctmp, ksock_conn_t, ksnc_list);
 
                /* Don't need the {get,put}connsock dance to deref ksnc_sock */
@@ -2394,7 +2394,6 @@ ksocknal_send_keepalive_locked(ksock_peer_t *peer)
        return -EIO;
 }
 
-
 static void
 ksocknal_check_peer_timeouts (int idx)
 {
index 340706110c21bbef41f2ec3b986701a5a062c8a2..679785b0209cf6a5f9c40c58a10979a77cd3912f 100644 (file)
@@ -355,9 +355,9 @@ ksocknal_lib_recv_kiov(ksock_conn_t *conn)
                        LASSERT(i < niov);
 
                        /* Dang! have to kmap again because I have nowhere to
-                         * stash the mapped address.  But by doing it while the
-                         * page is still mapped, the kernel just bumps the map
-                         * count and returns me the address it stashed. */
+                        * stash the mapped address.  But by doing it while the
+                        * page is still mapped, the kernel just bumps the map
+                        * count and returns me the address it stashed. */
                        base = kmap(kiov[i].kiov_page) + kiov[i].kiov_offset;
                        fragnob = kiov[i].kiov_len;
                        if (fragnob > sum)
index c3ac67698125358e46ea70c19c3cf4806dbdcfab..fdb2b23e2ef01e512a983ac8715f11d3a7ba8a60 100644 (file)
@@ -134,7 +134,6 @@ static unsigned int zc_recv_min_nfrags = 16;
 module_param(zc_recv_min_nfrags, int, 0644);
 MODULE_PARM_DESC(zc_recv_min_nfrags, "minimum # of fragments to enable ZC recv");
 
-
 #if SOCKNAL_VERSION_DEBUG
 static int protocol = 3;
 module_param(protocol, int, 0644);
index 52492fb10f855866172db9ec2a20b01ba830c054..e276fe2bf8f3db68d06ff9ac05d8ffd517d69424 100644 (file)
@@ -1,6 +1,6 @@
 obj-$(CONFIG_LNET) += lnet.o
 
-lnet-y := api-ni.o config.o                                    \
+lnet-y := api-ni.o config.o nidstrings.o                       \
          lib-me.o lib-msg.o lib-eq.o lib-md.o lib-ptl.o        \
          lib-socket.o lib-move.o module.o lo.o                 \
          router.o router_proc.o acceptor.o peer.o
index 99f8396f3822adbcdf14ae807df6c206b7a03d10..92ca1dd64076f5710f1d4e0f7d5b3ebda8bc2a83 100644 (file)
@@ -202,7 +202,6 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
 }
 EXPORT_SYMBOL(lnet_connect);
 
-
 /* Below is the code common for both kernel and MT user-space */
 
 static int
@@ -447,7 +446,6 @@ lnet_acceptor_start(void)
        if (rc != 0)
                return rc;
 
-
        init_completion(&lnet_acceptor_state.pta_signal);
        rc = accept2secure(accept_type, &secure);
        if (rc <= 0)
index d14fe70a56dff99c469858c61530d4691e4024fa..395412639935c673281c51fb312f9f890672c943 100644 (file)
@@ -45,7 +45,6 @@
 lnet_t the_lnet;                          /* THE state of the network */
 EXPORT_SYMBOL(the_lnet);
 
-
 static char *ip2nets = "";
 module_param(ip2nets, charp, 0444);
 MODULE_PARM_DESC(ip2nets, "LNET network <- IP table");
@@ -264,7 +263,7 @@ static void lnet_assert_wire_constants(void)
 }
 
 static lnd_t *
-lnet_find_lnd_by_type(int type)
+lnet_find_lnd_by_type(__u32 type)
 {
        lnd_t *lnd;
        struct list_head *tmp;
@@ -273,7 +272,7 @@ lnet_find_lnd_by_type(int type)
        list_for_each(tmp, &the_lnet.ln_lnds) {
                lnd = list_entry(tmp, lnd_t, lnd_list);
 
-               if ((int)lnd->lnd_type == type)
+               if (lnd->lnd_type == type)
                        return lnd;
        }
 
@@ -529,7 +528,6 @@ lnet_res_lh_initialize(struct lnet_res_container *rec, lnet_libhandle_t *lh)
        list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
 }
 
-
 int lnet_unprepare(void);
 
 static int
@@ -964,7 +962,7 @@ lnet_startup_lndnis(void)
        struct list_head nilist;
        int i;
        int rc = 0;
-       int lnd_type;
+       __u32 lnd_type;
        int nicount = 0;
        char *nets = lnet_get_networks();
 
@@ -1262,7 +1260,7 @@ LNetNIInit(lnet_pid_t requested_pid)
        if (rc != 0)
                goto failed4;
 
-       lnet_proc_init();
+       lnet_router_debugfs_init();
        goto out;
 
  failed4:
@@ -1305,7 +1303,7 @@ LNetNIFini(void)
        } else {
                LASSERT(!the_lnet.ln_niinit_self);
 
-               lnet_proc_fini();
+               lnet_router_debugfs_fini();
                lnet_router_checker_stop();
                lnet_ping_target_fini();
 
@@ -1343,6 +1341,7 @@ LNetCtl(unsigned int cmd, void *arg)
        lnet_process_id_t id = {0};
        lnet_ni_t *ni;
        int rc;
+       unsigned long secs_passed;
 
        LASSERT(the_lnet.ln_init);
        LASSERT(the_lnet.ln_refcount > 0);
@@ -1370,10 +1369,9 @@ LNetCtl(unsigned int cmd, void *arg)
                                      &data->ioc_nid, &data->ioc_flags,
                                      &data->ioc_priority);
        case IOC_LIBCFS_NOTIFY_ROUTER:
+               secs_passed = (ktime_get_real_seconds() - data->ioc_u64[0]);
                return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
-                                  cfs_time_current() -
-                                  cfs_time_seconds(get_seconds() -
-                                                   (time_t)data->ioc_u64[0]));
+                                  jiffies - secs_passed * HZ);
 
        case IOC_LIBCFS_PORTALS_COMPATIBILITY:
                /* This can be removed once lustre stops calling it */
index 9c576ce2f455511c97dfda218586faa2d44df6de..1b3bc8386524f90707b4959523104e76dc0bdeaa 100644 (file)
@@ -166,7 +166,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
 
        /* LND will fill in the address part of the NID */
        ni->ni_nid = LNET_MKNID(net, 0);
-       ni->ni_last_alive = get_seconds();
+       ni->ni_last_alive = ktime_get_real_seconds();
        list_add_tail(&ni->ni_list, nilist);
        return ni;
  failed:
@@ -824,7 +824,7 @@ lnet_match_network_token(char *token, int len, __u32 *ipaddrs, int nip)
        for (rc = i = 0; !rc && i < nip; i++)
                rc = cfs_ip_addr_match(ipaddrs[i], &list);
 
-       cfs_ip_addr_free(&list);
+       cfs_expr_list_free_list(&list);
 
        return rc;
 }
index f19ce9ae6a9a3af47b0fe1f95255f1e43d922c9f..60889ebd2f2bb38ede887ad6dab88c14a32e62a4 100644 (file)
@@ -318,7 +318,6 @@ LNetEQWait(lnet_handle_eq_t eventq, lnet_event_t *event)
 }
 EXPORT_SYMBOL(LNetEQWait);
 
-
 static int
 lnet_eq_wait_locked(int *timeout_ms)
 __must_hold(&the_lnet.ln_eq_wait_lock)
@@ -341,12 +340,9 @@ __must_hold(&the_lnet.ln_eq_wait_lock)
                schedule();
 
        } else {
-               struct timeval tv;
-
-               now = cfs_time_current();
-               schedule_timeout(cfs_time_seconds(tms) / 1000);
-               cfs_duration_usec(cfs_time_sub(cfs_time_current(), now), &tv);
-               tms -= (int)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
+               now = jiffies;
+               schedule_timeout(msecs_to_jiffies(tms));
+               tms -= jiffies_to_msecs(jiffies - now);
                if (tms < 0) /* no more wait but may have new event */
                        tms = 0;
        }
@@ -360,8 +356,6 @@ __must_hold(&the_lnet.ln_eq_wait_lock)
        return wait;
 }
 
-
-
 /**
  * Block the calling process until there's an event from a set of EQs or
  * timeout happens.
index 433faae9a2ff3b38a0d85dd0cc92ce9d679510f7..5631f60a39bc8ffe3487b79275be799e85f19b56 100644 (file)
@@ -275,7 +275,6 @@ lnet_extract_iov(int dst_niov, struct kvec *dst,
 }
 EXPORT_SYMBOL(lnet_extract_iov);
 
-
 unsigned int
 lnet_kiov_nob(unsigned int niov, lnet_kiov_t *kiov)
 {
@@ -727,7 +726,6 @@ lnet_peer_is_alive(lnet_peer_t *lp, unsigned long now)
        return alive;
 }
 
-
 /* NB: returns 1 when alive, 0 when dead, negative when error;
  *     may drop the lnet_net_lock */
 static int
@@ -867,7 +865,6 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
        return 0;
 }
 
-
 static lnet_rtrbufpool_t *
 lnet_msg2bufpool(lnet_msg_t *msg)
 {
@@ -1768,11 +1765,11 @@ lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
        }
 
        if (the_lnet.ln_routing &&
-           ni->ni_last_alive != get_seconds()) {
+           ni->ni_last_alive != ktime_get_real_seconds()) {
                lnet_ni_lock(ni);
 
                /* NB: so far here is the only place to set NI status to "up */
-               ni->ni_last_alive = get_seconds();
+               ni->ni_last_alive = ktime_get_real_seconds();
                if (ni->ni_status != NULL &&
                    ni->ni_status->ns_status == LNET_NI_STATUS_DOWN)
                        ni->ni_status->ns_status = LNET_NI_STATUS_UP;
index 84707c5cb46472035d357578b56a57397bacf397..b4f573ab62ccc5aa53d52c09701ab52cab2f1040 100644 (file)
@@ -420,9 +420,9 @@ lnet_mt_match_md(struct lnet_match_table *mtable,
 
        if (info->mi_opc == LNET_MD_OP_GET ||
            !lnet_ptl_is_lazy(the_lnet.ln_portals[info->mi_portal]))
-               return LNET_MATCHMD_DROP | exhausted;
+               return exhausted | LNET_MATCHMD_DROP;
 
-       return LNET_MATCHMD_NONE | exhausted;
+       return exhausted | LNET_MATCHMD_NONE;
 }
 
 static int
diff --git a/drivers/staging/lustre/lnet/lnet/nidstrings.c b/drivers/staging/lustre/lnet/lnet/nidstrings.c
new file mode 100644 (file)
index 0000000..80f585a
--- /dev/null
@@ -0,0 +1,1260 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lnet/lnet/nidstrings.c
+ *
+ * Author: Phil Schwan <phil@clusterfs.com>
+ */
+
+#define DEBUG_SUBSYSTEM S_LNET
+
+#include "../../include/linux/libcfs/libcfs.h"
+#include "../../include/linux/lnet/lnet.h"
+
+/* max value for numeric network address */
+#define MAX_NUMERIC_VALUE 0xffffffff
+
+#define IPSTRING_LENGTH 16
+
+/* CAVEAT VENDITOR! Keep the canonical string representation of nets/nids
+ * consistent in all conversion functions.  Some code fragments are copied
+ * around for the sake of clarity...
+ */
+
+/* CAVEAT EMPTOR! Racey temporary buffer allocation!
+ * Choose the number of nidstrings to support the MAXIMUM expected number of
+ * concurrent users.  If there are more, the returned string will be volatile.
+ * NB this number must allow for a process to be descheduled for a timeslice
+ * between getting its string and using it.
+ */
+
+static char      libcfs_nidstrings[LNET_NIDSTR_COUNT][LNET_NIDSTR_SIZE];
+static int       libcfs_nidstring_idx;
+
+static DEFINE_SPINLOCK(libcfs_nidstring_lock);
+
+static struct netstrfns *libcfs_namenum2netstrfns(const char *name);
+
+char *
+libcfs_next_nidstring(void)
+{
+       char *str;
+       unsigned long flags;
+
+       spin_lock_irqsave(&libcfs_nidstring_lock, flags);
+
+       str = libcfs_nidstrings[libcfs_nidstring_idx++];
+       if (libcfs_nidstring_idx == ARRAY_SIZE(libcfs_nidstrings))
+               libcfs_nidstring_idx = 0;
+
+       spin_unlock_irqrestore(&libcfs_nidstring_lock, flags);
+       return str;
+}
+EXPORT_SYMBOL(libcfs_next_nidstring);
+
+/**
+ * Nid range list syntax.
+ * \verbatim
+ *
+ * <nidlist>         :== <nidrange> [ ' ' <nidrange> ]
+ * <nidrange>        :== <addrrange> '@' <net>
+ * <addrrange>       :== '*' |
+ *                       <ipaddr_range> |
+ *                      <cfs_expr_list>
+ * <ipaddr_range>    :== <cfs_expr_list>.<cfs_expr_list>.<cfs_expr_list>.
+ *                      <cfs_expr_list>
+ * <cfs_expr_list>   :== <number> |
+ *                       <expr_list>
+ * <expr_list>       :== '[' <range_expr> [ ',' <range_expr>] ']'
+ * <range_expr>      :== <number> |
+ *                       <number> '-' <number> |
+ *                       <number> '-' <number> '/' <number>
+ * <net>             :== <netname> | <netname><number>
+ * <netname>         :== "lo" | "tcp" | "o2ib" | "cib" | "openib" | "iib" |
+ *                       "vib" | "ra" | "elan" | "mx" | "ptl"
+ * \endverbatim
+ */
+
+/**
+ * Structure to represent \<nidrange\> token of the syntax.
+ *
+ * One of this is created for each \<net\> parsed.
+ */
+struct nidrange {
+       /**
+        * Link to list of this structures which is built on nid range
+        * list parsing.
+        */
+       struct list_head nr_link;
+       /**
+        * List head for addrrange::ar_link.
+        */
+       struct list_head nr_addrranges;
+       /**
+        * Flag indicating that *@<net> is found.
+        */
+       int nr_all;
+       /**
+        * Pointer to corresponding element of libcfs_netstrfns.
+        */
+       struct netstrfns *nr_netstrfns;
+       /**
+        * Number of network. E.g. 5 if \<net\> is "elan5".
+        */
+       int nr_netnum;
+};
+
+/**
+ * Structure to represent \<addrrange\> token of the syntax.
+ */
+struct addrrange {
+       /**
+        * Link to nidrange::nr_addrranges.
+        */
+       struct list_head ar_link;
+       /**
+        * List head for cfs_expr_list::el_list.
+        */
+       struct list_head ar_numaddr_ranges;
+};
+
+/**
+ * Parses \<addrrange\> token on the syntax.
+ *
+ * Allocates struct addrrange and links to \a nidrange via
+ * (nidrange::nr_addrranges)
+ *
+ * \retval 0 if \a src parses to '*' | \<ipaddr_range\> | \<cfs_expr_list\>
+ * \retval -errno otherwise
+ */
+static int
+parse_addrange(const struct cfs_lstr *src, struct nidrange *nidrange)
+{
+       struct addrrange *addrrange;
+
+       if (src->ls_len == 1 && src->ls_str[0] == '*') {
+               nidrange->nr_all = 1;
+               return 0;
+       }
+
+       LIBCFS_ALLOC(addrrange, sizeof(struct addrrange));
+       if (addrrange == NULL)
+               return -ENOMEM;
+       list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges);
+       INIT_LIST_HEAD(&addrrange->ar_numaddr_ranges);
+
+       return nidrange->nr_netstrfns->nf_parse_addrlist(src->ls_str,
+                                               src->ls_len,
+                                               &addrrange->ar_numaddr_ranges);
+}
+
+/**
+ * Finds or creates struct nidrange.
+ *
+ * Checks if \a src is a valid network name, looks for corresponding
+ * nidrange on the ist of nidranges (\a nidlist), creates new struct
+ * nidrange if it is not found.
+ *
+ * \retval pointer to struct nidrange matching network specified via \a src
+ * \retval NULL if \a src does not match any network
+ */
+static struct nidrange *
+add_nidrange(const struct cfs_lstr *src,
+            struct list_head *nidlist)
+{
+       struct netstrfns *nf;
+       struct nidrange *nr;
+       int endlen;
+       unsigned netnum;
+
+       if (src->ls_len >= LNET_NIDSTR_SIZE)
+               return NULL;
+
+       nf = libcfs_namenum2netstrfns(src->ls_str);
+       if (nf == NULL)
+               return NULL;
+       endlen = src->ls_len - strlen(nf->nf_name);
+       if (endlen == 0)
+               /* network name only, e.g. "elan" or "tcp" */
+               netnum = 0;
+       else {
+               /* e.g. "elan25" or "tcp23", refuse to parse if
+                * network name is not appended with decimal or
+                * hexadecimal number */
+               if (!cfs_str2num_check(src->ls_str + strlen(nf->nf_name),
+                                      endlen, &netnum, 0, MAX_NUMERIC_VALUE))
+                       return NULL;
+       }
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               if (nr->nr_netstrfns != nf)
+                       continue;
+               if (nr->nr_netnum != netnum)
+                       continue;
+               return nr;
+       }
+
+       LIBCFS_ALLOC(nr, sizeof(struct nidrange));
+       if (nr == NULL)
+               return NULL;
+       list_add_tail(&nr->nr_link, nidlist);
+       INIT_LIST_HEAD(&nr->nr_addrranges);
+       nr->nr_netstrfns = nf;
+       nr->nr_all = 0;
+       nr->nr_netnum = netnum;
+
+       return nr;
+}
+
+/**
+ * Parses \<nidrange\> token of the syntax.
+ *
+ * \retval 1 if \a src parses to \<addrrange\> '@' \<net\>
+ * \retval 0 otherwise
+ */
+static int
+parse_nidrange(struct cfs_lstr *src, struct list_head *nidlist)
+{
+       struct cfs_lstr addrrange;
+       struct cfs_lstr net;
+       struct cfs_lstr tmp;
+       struct nidrange *nr;
+
+       tmp = *src;
+       if (cfs_gettok(src, '@', &addrrange) == 0)
+               goto failed;
+
+       if (cfs_gettok(src, '@', &net) == 0 || src->ls_str != NULL)
+               goto failed;
+
+       nr = add_nidrange(&net, nidlist);
+       if (nr == NULL)
+               goto failed;
+
+       if (parse_addrange(&addrrange, nr) != 0)
+               goto failed;
+
+       return 1;
+failed:
+       CWARN("can't parse nidrange: \"%.*s\"\n", tmp.ls_len, tmp.ls_str);
+       return 0;
+}
+
+/**
+ * Frees addrrange structures of \a list.
+ *
+ * For each struct addrrange structure found on \a list it frees
+ * cfs_expr_list list attached to it and frees the addrrange itself.
+ *
+ * \retval none
+ */
+static void
+free_addrranges(struct list_head *list)
+{
+       while (!list_empty(list)) {
+               struct addrrange *ar;
+
+               ar = list_entry(list->next, struct addrrange, ar_link);
+
+               cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
+               list_del(&ar->ar_link);
+               LIBCFS_FREE(ar, sizeof(struct addrrange));
+       }
+}
+
+/**
+ * Frees nidrange strutures of \a list.
+ *
+ * For each struct nidrange structure found on \a list it frees
+ * addrrange list attached to it and frees the nidrange itself.
+ *
+ * \retval none
+ */
+void
+cfs_free_nidlist(struct list_head *list)
+{
+       struct list_head *pos, *next;
+       struct nidrange *nr;
+
+       list_for_each_safe(pos, next, list) {
+               nr = list_entry(pos, struct nidrange, nr_link);
+               free_addrranges(&nr->nr_addrranges);
+               list_del(pos);
+               LIBCFS_FREE(nr, sizeof(struct nidrange));
+       }
+}
+EXPORT_SYMBOL(cfs_free_nidlist);
+
+/**
+ * Parses nid range list.
+ *
+ * Parses with rigorous syntax and overflow checking \a str into
+ * \<nidrange\> [ ' ' \<nidrange\> ], compiles \a str into set of
+ * structures and links that structure to \a nidlist. The resulting
+ * list can be used to match a NID againts set of NIDS defined by \a
+ * str.
+ * \see cfs_match_nid
+ *
+ * \retval 1 on success
+ * \retval 0 otherwise
+ */
+int
+cfs_parse_nidlist(char *str, int len, struct list_head *nidlist)
+{
+       struct cfs_lstr src;
+       struct cfs_lstr res;
+       int rc;
+
+       src.ls_str = str;
+       src.ls_len = len;
+       INIT_LIST_HEAD(nidlist);
+       while (src.ls_str) {
+               rc = cfs_gettok(&src, ' ', &res);
+               if (rc == 0) {
+                       cfs_free_nidlist(nidlist);
+                       return 0;
+               }
+               rc = parse_nidrange(&res, nidlist);
+               if (rc == 0) {
+                       cfs_free_nidlist(nidlist);
+                       return 0;
+               }
+       }
+       return 1;
+}
+EXPORT_SYMBOL(cfs_parse_nidlist);
+
+/**
+ * Matches a nid (\a nid) against the compiled list of nidranges (\a nidlist).
+ *
+ * \see cfs_parse_nidlist()
+ *
+ * \retval 1 on match
+ * \retval 0  otherwises
+ */
+int cfs_match_nid(lnet_nid_t nid, struct list_head *nidlist)
+{
+       struct nidrange *nr;
+       struct addrrange *ar;
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               if (nr->nr_netstrfns->nf_type != LNET_NETTYP(LNET_NIDNET(nid)))
+                       continue;
+               if (nr->nr_netnum != LNET_NETNUM(LNET_NIDNET(nid)))
+                       continue;
+               if (nr->nr_all)
+                       return 1;
+               list_for_each_entry(ar, &nr->nr_addrranges, ar_link)
+                       if (nr->nr_netstrfns->nf_match_addr(LNET_NIDADDR(nid),
+                                                      &ar->ar_numaddr_ranges))
+                               return 1;
+       }
+       return 0;
+}
+EXPORT_SYMBOL(cfs_match_nid);
+
+/**
+ * Print the network part of the nidrange \a nr into the specified \a buffer.
+ *
+ * \retval number of characters written
+ */
+static int
+cfs_print_network(char *buffer, int count, struct nidrange *nr)
+{
+       struct netstrfns *nf = nr->nr_netstrfns;
+
+       if (nr->nr_netnum == 0)
+               return scnprintf(buffer, count, "@%s", nf->nf_name);
+       else
+               return scnprintf(buffer, count, "@%s%u",
+                                nf->nf_name, nr->nr_netnum);
+}
+
+/**
+ * Print a list of addrrange (\a addrranges) into the specified \a buffer.
+ * At max \a count characters can be printed into \a buffer.
+ *
+ * \retval number of characters written
+ */
+static int
+cfs_print_addrranges(char *buffer, int count, struct list_head *addrranges,
+                    struct nidrange *nr)
+{
+       int i = 0;
+       struct addrrange *ar;
+       struct netstrfns *nf = nr->nr_netstrfns;
+
+       list_for_each_entry(ar, addrranges, ar_link) {
+               if (i != 0)
+                       i += scnprintf(buffer + i, count - i, " ");
+               i += nf->nf_print_addrlist(buffer + i, count - i,
+                                          &ar->ar_numaddr_ranges);
+               i += cfs_print_network(buffer + i, count - i, nr);
+       }
+       return i;
+}
+
+/**
+ * Print a list of nidranges (\a nidlist) into the specified \a buffer.
+ * At max \a count characters can be printed into \a buffer.
+ * Nidranges are separated by a space character.
+ *
+ * \retval number of characters written
+ */
+int cfs_print_nidlist(char *buffer, int count, struct list_head *nidlist)
+{
+       int i = 0;
+       struct nidrange *nr;
+
+       if (count <= 0)
+               return 0;
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               if (i != 0)
+                       i += scnprintf(buffer + i, count - i, " ");
+
+               if (nr->nr_all != 0) {
+                       LASSERT(list_empty(&nr->nr_addrranges));
+                       i += scnprintf(buffer + i, count - i, "*");
+                       i += cfs_print_network(buffer + i, count - i, nr);
+               } else {
+                       i += cfs_print_addrranges(buffer + i, count - i,
+                                                 &nr->nr_addrranges, nr);
+               }
+       }
+       return i;
+}
+EXPORT_SYMBOL(cfs_print_nidlist);
+
+/**
+ * Determines minimum and maximum addresses for a single
+ * numeric address range
+ *
+ * \param      ar
+ * \param      min_nid
+ * \param      max_nid
+ */
+static void cfs_ip_ar_min_max(struct addrrange *ar, __u32 *min_nid,
+                             __u32 *max_nid)
+{
+       struct cfs_expr_list *el;
+       struct cfs_range_expr *re;
+       __u32 tmp_ip_addr = 0;
+       unsigned int min_ip[4] = {0};
+       unsigned int max_ip[4] = {0};
+       int re_count = 0;
+
+       list_for_each_entry(el, &ar->ar_numaddr_ranges, el_link) {
+               list_for_each_entry(re, &el->el_exprs, re_link) {
+                       min_ip[re_count] = re->re_lo;
+                       max_ip[re_count] = re->re_hi;
+                       re_count++;
+               }
+       }
+
+       tmp_ip_addr = ((min_ip[0] << 24) | (min_ip[1] << 16) |
+                      (min_ip[2] << 8) | min_ip[3]);
+
+       if (min_nid != NULL)
+               *min_nid = tmp_ip_addr;
+
+       tmp_ip_addr = ((max_ip[0] << 24) | (max_ip[1] << 16) |
+                      (max_ip[2] << 8) | max_ip[3]);
+
+       if (max_nid != NULL)
+               *max_nid = tmp_ip_addr;
+}
+
+/**
+ * Determines minimum and maximum addresses for a single
+ * numeric address range
+ *
+ * \param      ar
+ * \param      min_nid
+ * \param      max_nid
+ */
+static void cfs_num_ar_min_max(struct addrrange *ar, __u32 *min_nid,
+                              __u32 *max_nid)
+{
+       struct cfs_expr_list *el;
+       struct cfs_range_expr *re;
+       unsigned int min_addr = 0;
+       unsigned int max_addr = 0;
+
+       list_for_each_entry(el, &ar->ar_numaddr_ranges, el_link) {
+               list_for_each_entry(re, &el->el_exprs, re_link) {
+                       if (re->re_lo < min_addr || min_addr == 0)
+                               min_addr = re->re_lo;
+                       if (re->re_hi > max_addr)
+                               max_addr = re->re_hi;
+               }
+       }
+
+       if (min_nid != NULL)
+               *min_nid = min_addr;
+       if (max_nid != NULL)
+               *max_nid = max_addr;
+}
+
+/**
+ * Determines whether an expression list in an nidrange contains exactly
+ * one contiguous address range. Calls the correct netstrfns for the LND
+ *
+ * \param      *nidlist
+ *
+ * \retval     true if contiguous
+ * \retval     false if not contiguous
+ */
+bool cfs_nidrange_is_contiguous(struct list_head *nidlist)
+{
+       struct nidrange *nr;
+       struct netstrfns *nf = NULL;
+       char *lndname = NULL;
+       int netnum = -1;
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               nf = nr->nr_netstrfns;
+               if (lndname == NULL)
+                       lndname = nf->nf_name;
+               if (netnum == -1)
+                       netnum = nr->nr_netnum;
+
+               if (strcmp(lndname, nf->nf_name) != 0 ||
+                   netnum != nr->nr_netnum)
+                       return false;
+       }
+
+       if (nf == NULL)
+               return false;
+
+       if (!nf->nf_is_contiguous(nidlist))
+               return false;
+
+       return true;
+}
+EXPORT_SYMBOL(cfs_nidrange_is_contiguous);
+
+/**
+ * Determines whether an expression list in an num nidrange contains exactly
+ * one contiguous address range.
+ *
+ * \param      *nidlist
+ *
+ * \retval     true if contiguous
+ * \retval     false if not contiguous
+ */
+static bool cfs_num_is_contiguous(struct list_head *nidlist)
+{
+       struct nidrange *nr;
+       struct addrrange *ar;
+       struct cfs_expr_list *el;
+       struct cfs_range_expr *re;
+       int last_hi = 0;
+       __u32 last_end_nid = 0;
+       __u32 current_start_nid = 0;
+       __u32 current_end_nid = 0;
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
+                       cfs_num_ar_min_max(ar, &current_start_nid,
+                                          &current_end_nid);
+                       if (last_end_nid != 0 &&
+                           (current_start_nid - last_end_nid != 1))
+                               return false;
+                       last_end_nid = current_end_nid;
+                       list_for_each_entry(el, &ar->ar_numaddr_ranges,
+                                           el_link) {
+                               list_for_each_entry(re, &el->el_exprs,
+                                                   re_link) {
+                                       if (re->re_stride > 1)
+                                               return false;
+                                       else if (last_hi != 0 &&
+                                                re->re_hi - last_hi != 1)
+                                               return false;
+                                       last_hi = re->re_hi;
+                               }
+                       }
+               }
+       }
+
+       return true;
+}
+
+/**
+ * Determines whether an expression list in an ip nidrange contains exactly
+ * one contiguous address range.
+ *
+ * \param      *nidlist
+ *
+ * \retval     true if contiguous
+ * \retval     false if not contiguous
+ */
+static bool cfs_ip_is_contiguous(struct list_head *nidlist)
+{
+       struct nidrange *nr;
+       struct addrrange *ar;
+       struct cfs_expr_list *el;
+       struct cfs_range_expr *re;
+       int expr_count;
+       int last_hi = 255;
+       int last_diff = 0;
+       __u32 last_end_nid = 0;
+       __u32 current_start_nid = 0;
+       __u32 current_end_nid = 0;
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
+                       last_hi = 255;
+                       last_diff = 0;
+                       cfs_ip_ar_min_max(ar, &current_start_nid,
+                                         &current_end_nid);
+                       if (last_end_nid != 0 &&
+                           (current_start_nid - last_end_nid != 1))
+                               return false;
+                       last_end_nid = current_end_nid;
+                       list_for_each_entry(el, &ar->ar_numaddr_ranges,
+                                           el_link) {
+                               expr_count = 0;
+                               list_for_each_entry(re, &el->el_exprs,
+                                                   re_link) {
+                                       expr_count++;
+                                       if (re->re_stride > 1 ||
+                                           (last_diff > 0 && last_hi != 255) ||
+                                           (last_diff > 0 && last_hi == 255 &&
+                                            re->re_lo > 0))
+                                               return false;
+                                       last_hi = re->re_hi;
+                                       last_diff = re->re_hi - re->re_lo;
+                               }
+                       }
+               }
+       }
+
+       return true;
+}
+
+/**
+ * Takes a linked list of nidrange expressions, determines the minimum
+ * and maximum nid and creates appropriate nid structures
+ *
+ * \param      *nidlist
+ * \param      *min_nid
+ * \param      *max_nid
+ */
+void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
+                              char *max_nid, size_t nidstr_length)
+{
+       struct nidrange *nr;
+       struct netstrfns *nf = NULL;
+       int netnum = -1;
+       __u32 min_addr;
+       __u32 max_addr;
+       char *lndname = NULL;
+       char min_addr_str[IPSTRING_LENGTH];
+       char max_addr_str[IPSTRING_LENGTH];
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               nf = nr->nr_netstrfns;
+               lndname = nf->nf_name;
+               if (netnum == -1)
+                       netnum = nr->nr_netnum;
+
+               nf->nf_min_max(nidlist, &min_addr, &max_addr);
+       }
+       nf->nf_addr2str(min_addr, min_addr_str, sizeof(min_addr_str));
+       nf->nf_addr2str(max_addr, max_addr_str, sizeof(max_addr_str));
+
+       snprintf(min_nid, nidstr_length, "%s@%s%d", min_addr_str, lndname,
+                netnum);
+       snprintf(max_nid, nidstr_length, "%s@%s%d", max_addr_str, lndname,
+                netnum);
+}
+EXPORT_SYMBOL(cfs_nidrange_find_min_max);
+
+/**
+ * Determines the min and max NID values for num LNDs
+ *
+ * \param      *nidlist
+ * \param      *min_nid
+ * \param      *max_nid
+ */
+static void cfs_num_min_max(struct list_head *nidlist, __u32 *min_nid,
+                           __u32 *max_nid)
+{
+       struct nidrange *nr;
+       struct addrrange *ar;
+       unsigned int tmp_min_addr = 0;
+       unsigned int tmp_max_addr = 0;
+       unsigned int min_addr = 0;
+       unsigned int max_addr = 0;
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
+                       cfs_num_ar_min_max(ar, &tmp_min_addr,
+                                          &tmp_max_addr);
+                       if (tmp_min_addr < min_addr || min_addr == 0)
+                               min_addr = tmp_min_addr;
+                       if (tmp_max_addr > max_addr)
+                               max_addr = tmp_min_addr;
+               }
+       }
+       *max_nid = max_addr;
+       *min_nid = min_addr;
+}
+
+/**
+ * Takes an nidlist and determines the minimum and maximum
+ * ip addresses.
+ *
+ * \param      *nidlist
+ * \param      *min_nid
+ * \param      *max_nid
+ */
+static void cfs_ip_min_max(struct list_head *nidlist, __u32 *min_nid,
+                          __u32 *max_nid)
+{
+       struct nidrange *nr;
+       struct addrrange *ar;
+       __u32 tmp_min_ip_addr = 0;
+       __u32 tmp_max_ip_addr = 0;
+       __u32 min_ip_addr = 0;
+       __u32 max_ip_addr = 0;
+
+       list_for_each_entry(nr, nidlist, nr_link) {
+               list_for_each_entry(ar, &nr->nr_addrranges, ar_link) {
+                       cfs_ip_ar_min_max(ar, &tmp_min_ip_addr,
+                                         &tmp_max_ip_addr);
+                       if (tmp_min_ip_addr < min_ip_addr || min_ip_addr == 0)
+                               min_ip_addr = tmp_min_ip_addr;
+                       if (tmp_max_ip_addr > max_ip_addr)
+                               max_ip_addr = tmp_max_ip_addr;
+               }
+       }
+
+       if (min_nid != NULL)
+               *min_nid = min_ip_addr;
+       if (max_nid != NULL)
+               *max_nid = max_ip_addr;
+}
+
+static int
+libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
+{
+       *addr = 0;
+       return 1;
+}
+
+static void
+libcfs_ip_addr2str(__u32 addr, char *str, size_t size)
+{
+       snprintf(str, size, "%u.%u.%u.%u",
+                (addr >> 24) & 0xff, (addr >> 16) & 0xff,
+                (addr >> 8) & 0xff, addr & 0xff);
+}
+
+/* CAVEAT EMPTOR XscanfX
+ * I use "%n" at the end of a sscanf format to detect trailing junk.  However
+ * sscanf may return immediately if it sees the terminating '0' in a string, so
+ * I initialise the %n variable to the expected length.  If sscanf sets it;
+ * fine, if it doesn't, then the scan ended at the end of the string, which is
+ * fine too :) */
+static int
+libcfs_ip_str2addr(const char *str, int nob, __u32 *addr)
+{
+       unsigned int    a;
+       unsigned int    b;
+       unsigned int    c;
+       unsigned int    d;
+       int             n = nob; /* XscanfX */
+
+       /* numeric IP? */
+       if (sscanf(str, "%u.%u.%u.%u%n", &a, &b, &c, &d, &n) >= 4 &&
+           n == nob &&
+           (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
+           (c & ~0xff) == 0 && (d & ~0xff) == 0) {
+               *addr = ((a<<24)|(b<<16)|(c<<8)|d);
+               return 1;
+       }
+
+       return 0;
+}
+
+/* Used by lnet/config.c so it can't be static */
+int
+cfs_ip_addr_parse(char *str, int len, struct list_head *list)
+{
+       struct cfs_expr_list *el;
+       struct cfs_lstr src;
+       int rc;
+       int i;
+
+       src.ls_str = str;
+       src.ls_len = len;
+       i = 0;
+
+       while (src.ls_str != NULL) {
+               struct cfs_lstr res;
+
+               if (!cfs_gettok(&src, '.', &res)) {
+                       rc = -EINVAL;
+                       goto out;
+               }
+
+               rc = cfs_expr_list_parse(res.ls_str, res.ls_len, 0, 255, &el);
+               if (rc != 0)
+                       goto out;
+
+               list_add_tail(&el->el_link, list);
+               i++;
+       }
+
+       if (i == 4)
+               return 0;
+
+       rc = -EINVAL;
+out:
+       cfs_expr_list_free_list(list);
+
+       return rc;
+}
+
+static int
+libcfs_ip_addr_range_print(char *buffer, int count, struct list_head *list)
+{
+       int i = 0, j = 0;
+       struct cfs_expr_list *el;
+
+       list_for_each_entry(el, list, el_link) {
+               LASSERT(j++ < 4);
+               if (i != 0)
+                       i += scnprintf(buffer + i, count - i, ".");
+               i += cfs_expr_list_print(buffer + i, count - i, el);
+       }
+       return i;
+}
+
+/**
+ * Matches address (\a addr) against address set encoded in \a list.
+ *
+ * \retval 1 if \a addr matches
+ * \retval 0 otherwise
+ */
+int
+cfs_ip_addr_match(__u32 addr, struct list_head *list)
+{
+       struct cfs_expr_list *el;
+       int i = 0;
+
+       list_for_each_entry_reverse(el, list, el_link) {
+               if (!cfs_expr_list_match(addr & 0xff, el))
+                       return 0;
+               addr >>= 8;
+               i++;
+       }
+
+       return i == 4;
+}
+
+static void
+libcfs_decnum_addr2str(__u32 addr, char *str, size_t size)
+{
+       snprintf(str, size, "%u", addr);
+}
+
+static int
+libcfs_num_str2addr(const char *str, int nob, __u32 *addr)
+{
+       int     n;
+
+       n = nob;
+       if (sscanf(str, "0x%x%n", addr, &n) >= 1 && n == nob)
+               return 1;
+
+       n = nob;
+       if (sscanf(str, "0X%x%n", addr, &n) >= 1 && n == nob)
+               return 1;
+
+       n = nob;
+       if (sscanf(str, "%u%n", addr, &n) >= 1 && n == nob)
+               return 1;
+
+       return 0;
+}
+
+/**
+ * Nf_parse_addrlist method for networks using numeric addresses.
+ *
+ * Examples of such networks are gm and elan.
+ *
+ * \retval 0 if \a str parsed to numeric address
+ * \retval errno otherwise
+ */
+static int
+libcfs_num_parse(char *str, int len, struct list_head *list)
+{
+       struct cfs_expr_list *el;
+       int     rc;
+
+       rc = cfs_expr_list_parse(str, len, 0, MAX_NUMERIC_VALUE, &el);
+       if (rc == 0)
+               list_add_tail(&el->el_link, list);
+
+       return rc;
+}
+
+static int
+libcfs_num_addr_range_print(char *buffer, int count, struct list_head *list)
+{
+       int i = 0, j = 0;
+       struct cfs_expr_list *el;
+
+       list_for_each_entry(el, list, el_link) {
+               LASSERT(j++ < 1);
+               i += cfs_expr_list_print(buffer + i, count - i, el);
+       }
+       return i;
+}
+
+/*
+ * Nf_match_addr method for networks using numeric addresses
+ *
+ * \retval 1 on match
+ * \retval 0 otherwise
+ */
+static int
+libcfs_num_match(__u32 addr, struct list_head *numaddr)
+{
+       struct cfs_expr_list *el;
+
+       LASSERT(!list_empty(numaddr));
+       el = list_entry(numaddr->next, struct cfs_expr_list, el_link);
+
+       return cfs_expr_list_match(addr, el);
+}
+
+static struct netstrfns libcfs_netstrfns[] = {
+       { .nf_type              = LOLND,
+         .nf_name              = "lo",
+         .nf_modname           = "klolnd",
+         .nf_addr2str          = libcfs_decnum_addr2str,
+         .nf_str2addr          = libcfs_lo_str2addr,
+         .nf_parse_addrlist    = libcfs_num_parse,
+         .nf_print_addrlist    = libcfs_num_addr_range_print,
+         .nf_match_addr        = libcfs_num_match,
+         .nf_is_contiguous     = cfs_num_is_contiguous,
+         .nf_min_max           = cfs_num_min_max },
+       { .nf_type              = SOCKLND,
+         .nf_name              = "tcp",
+         .nf_modname           = "ksocklnd",
+         .nf_addr2str          = libcfs_ip_addr2str,
+         .nf_str2addr          = libcfs_ip_str2addr,
+         .nf_parse_addrlist    = cfs_ip_addr_parse,
+         .nf_print_addrlist    = libcfs_ip_addr_range_print,
+         .nf_match_addr        = cfs_ip_addr_match,
+         .nf_is_contiguous     = cfs_ip_is_contiguous,
+         .nf_min_max           = cfs_ip_min_max },
+       { .nf_type              = O2IBLND,
+         .nf_name              = "o2ib",
+         .nf_modname           = "ko2iblnd",
+         .nf_addr2str          = libcfs_ip_addr2str,
+         .nf_str2addr          = libcfs_ip_str2addr,
+         .nf_parse_addrlist    = cfs_ip_addr_parse,
+         .nf_print_addrlist    = libcfs_ip_addr_range_print,
+         .nf_match_addr        = cfs_ip_addr_match,
+         .nf_is_contiguous     = cfs_ip_is_contiguous,
+         .nf_min_max           = cfs_ip_min_max },
+       { .nf_type              = GNILND,
+         .nf_name              = "gni",
+         .nf_modname           = "kgnilnd",
+         .nf_addr2str          = libcfs_decnum_addr2str,
+         .nf_str2addr          = libcfs_num_str2addr,
+         .nf_parse_addrlist    = libcfs_num_parse,
+         .nf_print_addrlist    = libcfs_num_addr_range_print,
+         .nf_match_addr        = libcfs_num_match,
+         .nf_is_contiguous     = cfs_num_is_contiguous,
+         .nf_min_max           = cfs_num_min_max },
+       { .nf_type              = GNIIPLND,
+         .nf_name              = "gip",
+         .nf_modname           = "kgnilnd",
+         .nf_addr2str          = libcfs_ip_addr2str,
+         .nf_str2addr          = libcfs_ip_str2addr,
+         .nf_parse_addrlist    = cfs_ip_addr_parse,
+         .nf_print_addrlist    = libcfs_ip_addr_range_print,
+         .nf_match_addr        = cfs_ip_addr_match,
+         .nf_is_contiguous     = cfs_ip_is_contiguous,
+         .nf_min_max           = cfs_ip_min_max },
+};
+
+static const size_t libcfs_nnetstrfns = ARRAY_SIZE(libcfs_netstrfns);
+
+static struct netstrfns *
+libcfs_lnd2netstrfns(__u32 lnd)
+{
+       int i;
+
+       for (i = 0; i < libcfs_nnetstrfns; i++)
+               if (lnd == libcfs_netstrfns[i].nf_type)
+                       return &libcfs_netstrfns[i];
+
+       return NULL;
+}
+
+static struct netstrfns *
+libcfs_namenum2netstrfns(const char *name)
+{
+       struct netstrfns *nf;
+       int i;
+
+       for (i = 0; i < libcfs_nnetstrfns; i++) {
+               nf = &libcfs_netstrfns[i];
+               if (!strncmp(name, nf->nf_name, strlen(nf->nf_name)))
+                       return nf;
+       }
+       return NULL;
+}
+
+static struct netstrfns *
+libcfs_name2netstrfns(const char *name)
+{
+       int    i;
+
+       for (i = 0; i < libcfs_nnetstrfns; i++)
+               if (!strcmp(libcfs_netstrfns[i].nf_name, name))
+                       return &libcfs_netstrfns[i];
+
+       return NULL;
+}
+
+int
+libcfs_isknown_lnd(__u32 lnd)
+{
+       return libcfs_lnd2netstrfns(lnd) != NULL;
+}
+EXPORT_SYMBOL(libcfs_isknown_lnd);
+
+char *
+libcfs_lnd2modname(__u32 lnd)
+{
+       struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
+
+       return (nf == NULL) ? NULL : nf->nf_modname;
+}
+EXPORT_SYMBOL(libcfs_lnd2modname);
+
+int
+libcfs_str2lnd(const char *str)
+{
+       struct netstrfns *nf = libcfs_name2netstrfns(str);
+
+       if (nf != NULL)
+               return nf->nf_type;
+
+       return -1;
+}
+EXPORT_SYMBOL(libcfs_str2lnd);
+
+char *
+libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size)
+{
+       struct netstrfns *nf;
+
+       nf = libcfs_lnd2netstrfns(lnd);
+       if (nf == NULL)
+               snprintf(buf, buf_size, "?%u?", lnd);
+       else
+               snprintf(buf, buf_size, "%s", nf->nf_name);
+
+       return buf;
+}
+EXPORT_SYMBOL(libcfs_lnd2str_r);
+
+char *
+libcfs_net2str_r(__u32 net, char *buf, size_t buf_size)
+{
+       __u32 nnum = LNET_NETNUM(net);
+       __u32 lnd = LNET_NETTYP(net);
+       struct netstrfns *nf;
+
+       nf = libcfs_lnd2netstrfns(lnd);
+       if (nf == NULL)
+               snprintf(buf, buf_size, "<%u:%u>", lnd, nnum);
+       else if (nnum == 0)
+               snprintf(buf, buf_size, "%s", nf->nf_name);
+       else
+               snprintf(buf, buf_size, "%s%u", nf->nf_name, nnum);
+
+       return buf;
+}
+EXPORT_SYMBOL(libcfs_net2str_r);
+
+char *
+libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size)
+{
+       __u32 addr = LNET_NIDADDR(nid);
+       __u32 net = LNET_NIDNET(nid);
+       __u32 nnum = LNET_NETNUM(net);
+       __u32 lnd = LNET_NETTYP(net);
+       struct netstrfns *nf;
+
+       if (nid == LNET_NID_ANY) {
+               strncpy(buf, "<?>", buf_size);
+               buf[buf_size - 1] = '\0';
+               return buf;
+       }
+
+       nf = libcfs_lnd2netstrfns(lnd);
+       if (nf == NULL)
+               snprintf(buf, buf_size, "%x@<%u:%u>", addr, lnd, nnum);
+       else {
+               size_t addr_len;
+
+               nf->nf_addr2str(addr, buf, buf_size);
+               addr_len = strlen(buf);
+               if (nnum == 0)
+                       snprintf(buf + addr_len, buf_size - addr_len, "@%s",
+                                nf->nf_name);
+               else
+                       snprintf(buf + addr_len, buf_size - addr_len, "@%s%u",
+                                nf->nf_name, nnum);
+       }
+
+       return buf;
+}
+EXPORT_SYMBOL(libcfs_nid2str_r);
+
+static struct netstrfns *
+libcfs_str2net_internal(const char *str, __u32 *net)
+{
+       struct netstrfns *uninitialized_var(nf);
+       int nob;
+       unsigned int netnum;
+       int i;
+
+       for (i = 0; i < libcfs_nnetstrfns; i++) {
+               nf = &libcfs_netstrfns[i];
+               if (!strncmp(str, nf->nf_name, strlen(nf->nf_name)))
+                       break;
+       }
+
+       if (i == libcfs_nnetstrfns)
+               return NULL;
+
+       nob = strlen(nf->nf_name);
+
+       if (strlen(str) == (unsigned int)nob) {
+               netnum = 0;
+       } else {
+               if (nf->nf_type == LOLND) /* net number not allowed */
+                       return NULL;
+
+               str += nob;
+               i = strlen(str);
+               if (sscanf(str, "%u%n", &netnum, &i) < 1 ||
+                   i != (int)strlen(str))
+                       return NULL;
+       }
+
+       *net = LNET_MKNET(nf->nf_type, netnum);
+       return nf;
+}
+
+__u32
+libcfs_str2net(const char *str)
+{
+       __u32  net;
+
+       if (libcfs_str2net_internal(str, &net) != NULL)
+               return net;
+
+       return LNET_NIDNET(LNET_NID_ANY);
+}
+EXPORT_SYMBOL(libcfs_str2net);
+
+lnet_nid_t
+libcfs_str2nid(const char *str)
+{
+       const char *sep = strchr(str, '@');
+       struct netstrfns *nf;
+       __u32 net;
+       __u32 addr;
+
+       if (sep != NULL) {
+               nf = libcfs_str2net_internal(sep + 1, &net);
+               if (nf == NULL)
+                       return LNET_NID_ANY;
+       } else {
+               sep = str + strlen(str);
+               net = LNET_MKNET(SOCKLND, 0);
+               nf = libcfs_lnd2netstrfns(SOCKLND);
+               LASSERT(nf != NULL);
+       }
+
+       if (!nf->nf_str2addr(str, (int)(sep - str), &addr))
+               return LNET_NID_ANY;
+
+       return LNET_MKNID(net, addr);
+}
+EXPORT_SYMBOL(libcfs_str2nid);
+
+char *
+libcfs_id2str(lnet_process_id_t id)
+{
+       char *str = libcfs_next_nidstring();
+
+       if (id.pid == LNET_PID_ANY) {
+               snprintf(str, LNET_NIDSTR_SIZE,
+                        "LNET_PID_ANY-%s", libcfs_nid2str(id.nid));
+               return str;
+       }
+
+       snprintf(str, LNET_NIDSTR_SIZE, "%s%u-%s",
+                ((id.pid & LNET_PID_USERFLAG) != 0) ? "U" : "",
+                (id.pid & ~LNET_PID_USERFLAG), libcfs_nid2str(id.nid));
+       return str;
+}
+EXPORT_SYMBOL(libcfs_id2str);
+
+int
+libcfs_str2anynid(lnet_nid_t *nidp, const char *str)
+{
+       if (!strcmp(str, "*")) {
+               *nidp = LNET_NID_ANY;
+               return 1;
+       }
+
+       *nidp = libcfs_str2nid(str);
+       return *nidp != LNET_NID_ANY;
+}
+EXPORT_SYMBOL(libcfs_str2anynid);
index 4fbae5ef44a9efb8353545973277d7d9ea9622ba..fe49f1b8765260c8d5cc22d4f0e976993036dd22 100644 (file)
@@ -162,7 +162,6 @@ lnet_ni_notify_locked(lnet_ni_t *ni, lnet_peer_t *lp)
        lp->lp_notifying = 0;
 }
 
-
 static void
 lnet_rtr_addref_locked(lnet_peer_t *lp)
 {
@@ -236,8 +235,8 @@ lnet_find_net_locked(__u32 net)
 static void lnet_shuffle_seed(void)
 {
        static int seeded;
-       int lnd_type, seed[2];
-       struct timeval tv;
+       __u32 lnd_type, seed[2];
+       struct timespec64 ts;
        lnet_ni_t *ni;
        struct list_head *tmp;
 
@@ -256,8 +255,8 @@ static void lnet_shuffle_seed(void)
                        seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type);
        }
 
-       do_gettimeofday(&tv);
-       cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
+       ktime_get_ts64(&ts);
+       cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
        seeded = 1;
 }
 
@@ -789,7 +788,7 @@ static void
 lnet_update_ni_status_locked(void)
 {
        lnet_ni_t *ni;
-       long now;
+       time64_t now;
        int timeout;
 
        LASSERT(the_lnet.ln_routing);
@@ -797,7 +796,7 @@ lnet_update_ni_status_locked(void)
        timeout = router_ping_timeout +
                  max(live_router_check_interval, dead_router_check_interval);
 
-       now = get_seconds();
+       now = ktime_get_real_seconds();
        list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
                if (ni->ni_lnd->lnd_type == LOLND)
                        continue;
@@ -1497,7 +1496,7 @@ lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, unsigned long when)
        unsigned long now = cfs_time_current();
        int cpt = lnet_cpt_of_nid(nid);
 
-       LASSERT(!in_interrupt ());
+       LASSERT(!in_interrupt());
 
        CDEBUG(D_NET, "%s notifying %s: %s\n",
                (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
index 40f418b82960746b5cde2324a7a40d57ae43c775..396c7c4e5c8392c7fac5c516c5028d6779c622f8 100644 (file)
 #include "../../include/linux/libcfs/libcfs.h"
 #include "../../include/linux/lnet/lib-lnet.h"
 
-#if  defined(LNET_ROUTER)
-
 /* This is really lnet_proc.c. You might need to update sanity test 215
  * if any file format is changed. */
 
-static struct ctl_table_header *lnet_table_header;
-
 #define LNET_LOFFT_BITS                (sizeof(loff_t) * 8)
 /*
  * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system
@@ -696,7 +692,7 @@ static int proc_lnet_nis(struct ctl_table *table, int write,
                if (ni != NULL) {
                        struct lnet_tx_queue *tq;
                        char *stat;
-                       long now = get_seconds();
+                       time64_t now = ktime_get_real_seconds();
                        int last_alive = -1;
                        int i;
                        int j;
@@ -914,44 +910,11 @@ static struct ctl_table lnet_table[] = {
        }
 };
 
-static struct ctl_table top_table[] = {
-       {
-               .procname = "lnet",
-               .mode     = 0555,
-               .data     = NULL,
-               .maxlen   = 0,
-               .child    = lnet_table,
-       },
-       {
-       }
-};
-
-void
-lnet_proc_init(void)
+void lnet_router_debugfs_init(void)
 {
-       if (lnet_table_header == NULL)
-               lnet_table_header = register_sysctl_table(top_table);
+       lustre_insert_debugfs(lnet_table, NULL);
 }
 
-void
-lnet_proc_fini(void)
+void lnet_router_debugfs_fini(void)
 {
-       if (lnet_table_header != NULL)
-               unregister_sysctl_table(lnet_table_header);
-
-       lnet_table_header = NULL;
 }
-
-#else
-
-void
-lnet_proc_init(void)
-{
-}
-
-void
-lnet_proc_fini(void)
-{
-}
-
-#endif
index de11f1bc8be767577d5d17b2a5a1a5f07dbc7120..0605c651f7973966ac747ea56c902c4158ac4c85 100644 (file)
@@ -134,14 +134,14 @@ brw_client_init(sfw_test_instance_t *tsi)
 static int
 brw_inject_one_error(void)
 {
-       struct timeval tv;
+       struct timespec64 ts;
 
        if (brw_inject_errors <= 0)
                return 0;
 
-       do_gettimeofday(&tv);
+       ktime_get_ts64(&ts);
 
-       if ((tv.tv_usec & 1) == 0)
+       if (((ts.tv_nsec / NSEC_PER_USEC) & 1) == 0)
                return 0;
 
        return brw_inject_errors--;
index 1a7870e91f23a51dc178329109282bff4a94161b..556c837cf62cd8f1f0d3f0cd25299f73ebfa2160 100644 (file)
@@ -441,7 +441,7 @@ lst_group_info_ioctl(lstio_group_info_args_t *args)
        if (args->lstio_grp_dentsp != NULL &&
            (copy_to_user(args->lstio_grp_idxp, &index, sizeof(index)) ||
             copy_to_user(args->lstio_grp_ndentp, &ndent, sizeof(ndent))))
-               rc = -EFAULT;
+               return -EFAULT;
 
        return 0;
 }
@@ -837,7 +837,7 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
 
        mutex_lock(&console_session.ses_mutex);
 
-       console_session.ses_laststamp = get_seconds();
+       console_session.ses_laststamp = ktime_get_real_seconds();
 
        if (console_session.ses_shutdown) {
                rc = -ESHUTDOWN;
index a1a4e08f7391558e488993c15108144367ad01dd..0060ff64f88e65f4e1a94ddba56c84bd3ea6a5f3 100644 (file)
@@ -40,7 +40,6 @@
  * Author: Liang Zhen <liang@whamcloud.com>
  */
 
-
 #include "../../include/linux/libcfs/libcfs.h"
 #include "../../include/linux/lnet/lib-lnet.h"
 #include "timer.h"
@@ -505,7 +504,7 @@ lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
 
                dur = (long)cfs_time_sub(crpc->crp_stamp,
                      (unsigned long)console_session.ses_id.ses_stamp);
-               cfs_duration_usec(dur, &tv);
+               jiffies_to_timeval(dur, &tv);
 
                if (copy_to_user(&ent->rpe_peer,
                                     &nd->nd_id, sizeof(lnet_process_id_t)) ||
@@ -1176,7 +1175,7 @@ lstcon_rpc_pinger(void *arg)
        srpc_debug_reqst_t *drq;
        lstcon_ndlink_t *ndl;
        lstcon_node_t *nd;
-       time_t intv;
+       int intv;
        int count = 0;
        int rc;
 
@@ -1191,8 +1190,8 @@ lstcon_rpc_pinger(void *arg)
        }
 
        if (!console_session.ses_expired &&
-           get_seconds() - console_session.ses_laststamp >
-           (time_t)console_session.ses_timeout)
+           ktime_get_real_seconds() - console_session.ses_laststamp >
+           (time64_t)console_session.ses_timeout)
                console_session.ses_expired = 1;
 
        trans = console_session.ses_ping;
@@ -1248,9 +1247,8 @@ lstcon_rpc_pinger(void *arg)
                if (nd->nd_state != LST_NODE_ACTIVE)
                        continue;
 
-               intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
-                                                    nd->nd_stamp));
-               if (intv < (time_t)nd->nd_timeout / 2)
+               intv = (jiffies - nd->nd_stamp) / HZ;
+               if (intv < nd->nd_timeout / 2)
                        continue;
 
                rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
@@ -1278,7 +1276,7 @@ lstcon_rpc_pinger(void *arg)
 
        CDEBUG(D_NET, "Ping %d nodes in session\n", count);
 
-       ptimer->stt_expires = (unsigned long)(get_seconds() + LST_PING_INTERVAL);
+       ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
        stt_add_timer(ptimer);
 
        mutex_unlock(&console_session.ses_mutex);
@@ -1301,7 +1299,7 @@ lstcon_rpc_pinger_start(void)
        }
 
        ptimer = &console_session.ses_ping_timer;
-       ptimer->stt_expires = (unsigned long)(get_seconds() + LST_PING_INTERVAL);
+       ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
 
        stt_add_timer(ptimer);
 
index 7d33cf9e9d998e551a1a2fa9ec94ac0c38c44f81..95c832ff7375b89e676788ae847b57a05904abb2 100644 (file)
@@ -105,8 +105,8 @@ typedef struct lstcon_rpc_trans {
 
 #define LST_TRANS_STATQRY       0x21
 
-typedef int (* lstcon_rpc_cond_func_t)(int, struct lstcon_node *, void *);
-typedef int (* lstcon_rpc_readent_func_t)(int, srpc_msg_t *, lstcon_rpc_ent_t *);
+typedef int (*lstcon_rpc_cond_func_t)(int, struct lstcon_node *, void *);
+typedef int (*lstcon_rpc_readent_func_t)(int, srpc_msg_t *, lstcon_rpc_ent_t *);
 
 int  lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
                        unsigned version, lstcon_rpc_t **crpc);
@@ -140,5 +140,4 @@ void lstcon_rpc_cleanup_wait(void);
 int  lstcon_rpc_module_init(void);
 void lstcon_rpc_module_fini(void);
 
-
 #endif
index f47c8f27f975a878ad55677030f6e3a9d0dea4d1..d315dd44ae3b341940ef963827204feb7e5cbf9b 100644 (file)
@@ -40,7 +40,6 @@
  * Author: Liang Zhen <liangzhen@clusterfs.com>
  */
 
-
 #include "../../include/linux/libcfs/libcfs.h"
 #include "../../include/linux/lnet/lib-lnet.h"
 #include "console.h"
@@ -308,7 +307,7 @@ lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
 {
        list_del_init(&ndl->ndl_link);
        lstcon_ndlink_release(ndl);
-       grp->grp_nnode --;
+       grp->grp_nnode--;
 }
 
 static void
@@ -320,7 +319,7 @@ lstcon_group_ndlink_move(lstcon_group_t *old,
 
        list_del(&ndl->ndl_hlink);
        list_del(&ndl->ndl_link);
-       old->grp_nnode --;
+       old->grp_nnode--;
 
        list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
        list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
@@ -527,7 +526,7 @@ lstcon_group_add(char *name)
        lstcon_group_t *grp;
        int rc;
 
-       rc = (lstcon_group_find(name, &grp) == 0)? -EEXIST: 0;
+       rc = (lstcon_group_find(name, &grp) == 0) ? -EEXIST : 0;
        if (rc != 0) {
                /* find a group with same name */
                lstcon_group_put(grp);
@@ -816,7 +815,7 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
                LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
 
        rc = copy_to_user(gents_p, gentp,
-                             sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
+                             sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
 
        LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
 
@@ -847,7 +846,7 @@ lstcon_batch_add(char *name)
        int i;
        int rc;
 
-       rc = (lstcon_batch_find(name, &bat) == 0)? -EEXIST: 0;
+       rc = (lstcon_batch_find(name, &bat) == 0) ? -EEXIST : 0;
        if (rc != 0) {
                CDEBUG(D_NET, "Batch %s already exists\n", name);
                return rc;
@@ -911,7 +910,7 @@ lstcon_batch_list(int index, int len, char *name_up)
        list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
                if (index-- == 0) {
                        return copy_to_user(name_up, bat->bat_name, len) ?
-                              -EFAULT: 0;
+                              -EFAULT : 0;
                }
        }
 
@@ -956,7 +955,7 @@ lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
                                  &test->tes_dst_grp->grp_ndl_list;
 
        if (dents_up != NULL) {
-               rc = lstcon_nodes_getent((server ? srvlst: clilst),
+               rc = lstcon_nodes_getent((server ? srvlst : clilst),
                                         index_p, ndent_p, dents_up);
                return rc;
        }
@@ -1683,7 +1682,7 @@ int
 lstcon_session_match(lst_sid_t sid)
 {
        return (console_session.ses_id.ses_nid   == sid.ses_nid &&
-               console_session.ses_id.ses_stamp == sid.ses_stamp) ?  1: 0;
+               console_session.ses_id.ses_stamp == sid.ses_stamp) ?  1 : 0;
 }
 
 static void
@@ -2004,7 +2003,7 @@ lstcon_console_init(void)
        console_session.ses_expired       = 0;
        console_session.ses_feats_updated = 0;
        console_session.ses_features      = LST_FEATS_MASK;
-       console_session.ses_laststamp     = get_seconds();
+       console_session.ses_laststamp     = ktime_get_real_seconds();
 
        mutex_init(&console_session.ses_mutex);
 
@@ -2021,7 +2020,6 @@ lstcon_console_init(void)
        for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
                INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
 
-
        /* initialize acceptor service table */
        lstcon_init_acceptor_service();
 
index cdce2dd6be7c4b8809a0554e080d05df1d69245b..3f3286c0c7bf3ceecb2ad878d76b69ae7bc0fea0 100644 (file)
@@ -43,7 +43,6 @@
 #ifndef __LST_CONSOLE_H__
 #define __LST_CONSOLE_H__
 
-
 #include "../../include/linux/libcfs/libcfs.h"
 #include "../../include/linux/lnet/lnet.h"
 #include "../../include/linux/lnet/lib-types.h"
@@ -142,7 +141,7 @@ typedef struct {
        int                 ses_key;          /* local session key */
        int                 ses_state;        /* state of session */
        int                 ses_timeout;      /* timeout in seconds */
-       time_t              ses_laststamp;    /* last operation stamp (seconds)
+       time64_t            ses_laststamp;    /* last operation stamp (seconds)
                                               */
        unsigned            ses_features;     /* tests features of the session
                                               */
index 257de353767192d626ba8822b9e99caceb416e8b..f18e5003680904f177f9b95c3a933335b9d01b60 100644 (file)
@@ -170,8 +170,7 @@ sfw_add_session_timer(void)
        LASSERT(!sn->sn_timer_active);
 
        sn->sn_timer_active = 1;
-       timer->stt_expires = cfs_time_add(sn->sn_timeout,
-                                         get_seconds());
+       timer->stt_expires = ktime_get_real_seconds() + sn->sn_timeout;
        stt_add_timer(timer);
        return;
 }
@@ -238,7 +237,6 @@ sfw_deactivate_session(void)
        spin_lock(&sfw_data.fw_lock);
 }
 
-
 static void
 sfw_session_expired(void *data)
 {
@@ -372,7 +370,6 @@ sfw_get_stats(srpc_stat_reqst_t *request, srpc_stat_reply_t *reply)
        sfw_session_t *sn = sfw_data.fw_session;
        sfw_counters_t *cnt = &reply->str_fw;
        sfw_batch_t *bat;
-       struct timeval tv;
 
        reply->str_sid = (sn == NULL) ? LST_INVALID_SID : sn->sn_id;
 
@@ -391,10 +388,7 @@ sfw_get_stats(srpc_stat_reqst_t *request, srpc_stat_reply_t *reply)
 
        /* send over the msecs since the session was started
         - with 32 bits to send, this is ~49 days */
-       cfs_duration_usec(cfs_time_sub(cfs_time_current(),
-                                      sn->sn_started), &tv);
-
-       cnt->running_ms      = (__u32)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
+       cnt->running_ms      = jiffies_to_msecs(jiffies - sn->sn_started);
        cnt->brw_errors      = atomic_read(&sn->sn_brw_errors);
        cnt->ping_errors     = atomic_read(&sn->sn_ping_errors);
        cnt->zombie_sessions = atomic_read(&sfw_data.fw_nzombies);
@@ -1638,7 +1632,6 @@ extern srpc_service_t     brw_test_service;
 extern void brw_init_test_client(void);
 extern void brw_init_test_service(void);
 
-
 int
 sfw_startup(void)
 {
@@ -1648,7 +1641,6 @@ sfw_startup(void)
        srpc_service_t *sv;
        sfw_test_case_t *tsc;
 
-
        if (session_timeout < 0) {
                CERROR("Session timeout must be non-negative: %d\n",
                        session_timeout);
index 09b8f4649796e3a0a117cdaa96a0537c53168d39..46cbdf0456cc93ea6ee9b69ee0cbb3c9f4544aa0 100644 (file)
@@ -150,7 +150,6 @@ error:
        return rc;
 }
 
-
 MODULE_DESCRIPTION("LNet Selftest");
 MODULE_LICENSE("GPL");
 MODULE_VERSION("0.9.0");
index 1dab9984c58e0086546a7d1f58e856261cab3a44..d42653654fa87d33df07ed3f974850dae6c9a531 100644 (file)
@@ -92,7 +92,7 @@ ping_client_prep_rpc(sfw_test_unit_t *tsu,
        srpc_ping_reqst_t *req;
        sfw_test_instance_t *tsi = tsu->tsu_instance;
        sfw_session_t *sn = tsi->tsi_batch->bat_session;
-       struct timeval tv;
+       struct timespec64 ts;
        int rc;
 
        LASSERT(sn != NULL);
@@ -110,9 +110,9 @@ ping_client_prep_rpc(sfw_test_unit_t *tsu,
        req->pnr_seq = lst_ping_data.pnd_counter++;
        spin_unlock(&lst_ping_data.pnd_lock);
 
-       cfs_fs_timeval(&tv);
-       req->pnr_time_sec  = tv.tv_sec;
-       req->pnr_time_usec = tv.tv_usec;
+       ktime_get_real_ts64(&ts);
+       req->pnr_time_sec  = ts.tv_sec;
+       req->pnr_time_usec = ts.tv_nsec / NSEC_PER_USEC;
 
        return rc;
 }
@@ -124,7 +124,7 @@ ping_client_done_rpc(sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
        sfw_session_t *sn = tsi->tsi_batch->bat_session;
        srpc_ping_reqst_t *reqst = &rpc->crpc_reqstmsg.msg_body.ping_reqst;
        srpc_ping_reply_t *reply = &rpc->crpc_replymsg.msg_body.ping_reply;
-       struct timeval tv;
+       struct timespec64 ts;
 
        LASSERT(sn != NULL);
 
@@ -161,10 +161,10 @@ ping_client_done_rpc(sfw_test_unit_t *tsu, srpc_client_rpc_t *rpc)
                return;
        }
 
-       cfs_fs_timeval(&tv);
+       ktime_get_real_ts64(&ts);
        CDEBUG(D_NET, "%d reply in %u usec\n", reply->pnr_seq,
-               (unsigned)((tv.tv_sec - (unsigned)reqst->pnr_time_sec) * 1000000
-                          + (tv.tv_usec - reqst->pnr_time_usec)));
+              (unsigned)((ts.tv_sec - reqst->pnr_time_sec) * 1000000 +
+                         (ts.tv_nsec / NSEC_PER_USEC - reqst->pnr_time_usec)));
        return;
 }
 
index 6ae133138b17976ace3a7e9998b6bbb8c7ad6d9d..162f9d330496bf40026dba82a6822f5d828731cf 100644 (file)
@@ -565,7 +565,7 @@ srpc_add_buffer(struct swi_workitem *wi)
        }
 
        if (rc != 0) {
-               scd->scd_buf_err_stamp = get_seconds();
+               scd->scd_buf_err_stamp = ktime_get_real_seconds();
                scd->scd_buf_err = rc;
 
                LASSERT(scd->scd_buf_posting > 0);
@@ -1100,8 +1100,7 @@ srpc_add_client_rpc_timer(srpc_client_rpc_t *rpc)
        INIT_LIST_HEAD(&timer->stt_list);
        timer->stt_data    = rpc;
        timer->stt_func    = srpc_client_rpc_expired;
-       timer->stt_expires = cfs_time_add(rpc->crpc_timeout,
-                                         get_seconds());
+       timer->stt_expires = ktime_get_real_seconds() + rpc->crpc_timeout;
        stt_add_timer(timer);
        return;
 }
@@ -1355,7 +1354,6 @@ srpc_post_rpc(srpc_client_rpc_t *rpc)
        return;
 }
 
-
 int
 srpc_send_reply(struct srpc_server_rpc *rpc)
 {
@@ -1488,7 +1486,7 @@ srpc_lnet_ev_handler(lnet_event_t *ev)
                }
 
                if (scd->scd_buf_err_stamp != 0 &&
-                   scd->scd_buf_err_stamp < get_seconds()) {
+                   scd->scd_buf_err_stamp < ktime_get_real_seconds()) {
                        /* re-enable adding buffer */
                        scd->scd_buf_err_stamp = 0;
                        scd->scd_buf_err = 0;
@@ -1581,7 +1579,6 @@ srpc_lnet_ev_handler(lnet_event_t *ev)
        }
 }
 
-
 int
 srpc_startup(void)
 {
@@ -1593,7 +1590,7 @@ srpc_startup(void)
        /* 1 second pause to avoid timestamp reuse */
        set_current_state(TASK_UNINTERRUPTIBLE);
        schedule_timeout(cfs_time_seconds(1));
-       srpc_data.rpc_matchbits = ((__u64) get_seconds()) << 48;
+       srpc_data.rpc_matchbits = ((__u64)ktime_get_real_seconds()) << 48;
 
        srpc_data.rpc_state = SRPC_STATE_NONE;
 
index b7b00c6b10043173b687c6c9e68f15b9a433aa9e..6b4a32a9085724e728a916cf52a191592693223d 100644 (file)
@@ -65,7 +65,6 @@ typedef enum {
        SRPC_MSG_JOIN_REPLY     = 17,
 } srpc_msg_type_t;
 
-
 /* CAVEAT EMPTOR:
  * All srpc_*_reqst_t's 1st field must be matchbits of reply buffer,
  * and 2nd field matchbits of bulk buffer if any.
index 7939e4e04d90a7af8d09be9d541e65a62a745561..8a77d3fdfa545b03276414b450dcf459108ebfe6 100644 (file)
@@ -56,7 +56,6 @@
 #define MADE_WITHOUT_COMPROMISE
 #endif
 
-
 #define SWI_STATE_NEWBORN           0
 #define SWI_STATE_REPLY_SUBMITTED   1
 #define SWI_STATE_REPLY_SENT        2
@@ -279,7 +278,7 @@ struct srpc_service_cd {
        /** error code for scd_buf_wi */
        int                     scd_buf_err;
        /** timestamp for scd_buf_err */
-       unsigned long           scd_buf_err_stamp;
+       time64_t                scd_buf_err_stamp;
        /** total # request buffers */
        int                     scd_buf_total;
        /** # posted request buffers */
@@ -497,7 +496,6 @@ swi_deschedule_workitem(swi_workitem_t *swi)
        return cfs_wi_deschedule(swi->swi_sched, &swi->swi_workitem);
 }
 
-
 int sfw_startup(void);
 int srpc_startup(void);
 void sfw_shutdown(void);
@@ -562,17 +560,17 @@ static inline const char *
 swi_state2str (int state)
 {
 #define STATE2STR(x) case x: return #x
-       switch(state) {
-               default:
-                       LBUG();
-               STATE2STR(SWI_STATE_NEWBORN);
-               STATE2STR(SWI_STATE_REPLY_SUBMITTED);
-               STATE2STR(SWI_STATE_REPLY_SENT);
-               STATE2STR(SWI_STATE_REQUEST_SUBMITTED);
-               STATE2STR(SWI_STATE_REQUEST_SENT);
-               STATE2STR(SWI_STATE_REPLY_RECEIVED);
-               STATE2STR(SWI_STATE_BULK_STARTED);
-               STATE2STR(SWI_STATE_DONE);
+       switch (state) {
+       default:
+               LBUG();
+       STATE2STR(SWI_STATE_NEWBORN);
+       STATE2STR(SWI_STATE_REPLY_SUBMITTED);
+       STATE2STR(SWI_STATE_REPLY_SENT);
+       STATE2STR(SWI_STATE_REQUEST_SUBMITTED);
+       STATE2STR(SWI_STATE_REQUEST_SENT);
+       STATE2STR(SWI_STATE_REPLY_RECEIVED);
+       STATE2STR(SWI_STATE_BULK_STARTED);
+       STATE2STR(SWI_STATE_DONE);
        }
 #undef STATE2STR
 }
@@ -583,7 +581,6 @@ swi_state2str (int state)
                schedule_timeout(cfs_time_seconds(1) / 10);     \
        } while (0)
 
-
 #define lst_wait_until(cond, lock, fmt, ...)                           \
 do {                                                                   \
        int __I = 2;                                                    \
index 6133b54f4a8204d4c3c036b5e110b5904da069d4..b98c08a106069aa1274a4f85cbc09f33c35d7a90 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "selftest.h"
 
-
 /*
  * Timers are implemented as a sorted queue of expiry times. The queue
  * is slotted, with each slot holding timers which expire in a
@@ -78,13 +77,13 @@ stt_add_timer(stt_timer_t *timer)
        LASSERT(!stt_data.stt_shuttingdown);
        LASSERT(timer->stt_func != NULL);
        LASSERT(list_empty(&timer->stt_list));
-       LASSERT(cfs_time_after(timer->stt_expires, get_seconds()));
+       LASSERT(timer->stt_expires > ktime_get_real_seconds());
 
        /* a simple insertion sort */
        list_for_each_prev(pos, STTIMER_SLOT(timer->stt_expires)) {
                stt_timer_t *old = list_entry(pos, stt_timer_t, stt_list);
 
-               if (cfs_time_aftereq(timer->stt_expires, old->stt_expires))
+               if (timer->stt_expires >= old->stt_expires)
                        break;
        }
        list_add(&timer->stt_list, pos);
@@ -122,7 +121,7 @@ stt_del_timer(stt_timer_t *timer)
 
 /* called with stt_data.stt_lock held */
 static int
-stt_expire_list(struct list_head *slot, unsigned long now)
+stt_expire_list(struct list_head *slot, time64_t now)
 {
        int expired = 0;
        stt_timer_t *timer;
@@ -130,7 +129,7 @@ stt_expire_list(struct list_head *slot, unsigned long now)
        while (!list_empty(slot)) {
                timer = list_entry(slot->next, stt_timer_t, stt_list);
 
-               if (cfs_time_after(timer->stt_expires, now))
+               if (timer->stt_expires > now)
                        break;
 
                list_del_init(&timer->stt_list);
@@ -149,10 +148,10 @@ static int
 stt_check_timers(unsigned long *last)
 {
        int expired = 0;
-       unsigned long now;
+       time64_t now;
        unsigned long this_slot;
 
-       now = get_seconds();
+       now = ktime_get_real_seconds();
        this_slot = now & STTIMER_SLOTTIMEMASK;
 
        spin_lock(&stt_data.stt_lock);
@@ -167,7 +166,6 @@ stt_check_timers(unsigned long *last)
        return expired;
 }
 
-
 static int
 stt_timer_main(void *arg)
 {
@@ -204,7 +202,6 @@ stt_start_timer_thread(void)
        return 0;
 }
 
-
 int
 stt_startup(void)
 {
@@ -212,7 +209,7 @@ stt_startup(void)
        int i;
 
        stt_data.stt_shuttingdown = 0;
-       stt_data.stt_prev_slot = get_seconds() & STTIMER_SLOTTIMEMASK;
+       stt_data.stt_prev_slot = ktime_get_real_seconds() & STTIMER_SLOTTIMEMASK;
 
        spin_lock_init(&stt_data.stt_lock);
        for (i = 0; i < STTIMER_NSLOTS; i++)
index 2a8803d89de46345d1499c1cb3337fe7a5430bf1..03e2ee294c1c3cf3122b3a1810d0df0cdf335d46 100644 (file)
@@ -40,7 +40,7 @@
 
 typedef struct {
        struct list_head stt_list;
-       unsigned long    stt_expires;
+       time64_t         stt_expires;
        void             (*stt_func) (void *);
        void             *stt_data;
 } stt_timer_t;
index a16d577c6cb184071dd0d015d5e8c9ab79c9b4d4..7c45e74790873d9861a84733e6f1d8eeee63816b 100644 (file)
@@ -150,19 +150,15 @@ int seq_client_alloc_super(struct lu_client_seq *seq,
 
        mutex_lock(&seq->lcs_mutex);
 
-       if (seq->lcs_srv) {
-               rc = 0;
-       } else {
-               /* Check whether the connection to seq controller has been
-                * setup (lcs_exp != NULL) */
-               if (seq->lcs_exp == NULL) {
-                       mutex_unlock(&seq->lcs_mutex);
-                       return -EINPROGRESS;
-               }
-
-               rc = seq_client_rpc(seq, &seq->lcs_space,
-                                   SEQ_ALLOC_SUPER, "super");
+       /* Check whether the connection to seq controller has been
+        * setup (lcs_exp != NULL) */
+       if (!seq->lcs_exp) {
+               mutex_unlock(&seq->lcs_mutex);
+               return -EINPROGRESS;
        }
+
+       rc = seq_client_rpc(seq, &seq->lcs_space,
+                           SEQ_ALLOC_SUPER, "super");
        mutex_unlock(&seq->lcs_mutex);
        return rc;
 }
@@ -173,18 +169,14 @@ static int seq_client_alloc_meta(const struct lu_env *env,
 {
        int rc;
 
-       if (seq->lcs_srv) {
-               rc = 0;
-       } else {
-               do {
-                       /* If meta server return -EINPROGRESS or EAGAIN,
-                        * it means meta server might not be ready to
-                        * allocate super sequence from sequence controller
-                        * (MDT0)yet */
-                       rc = seq_client_rpc(seq, &seq->lcs_space,
-                                           SEQ_ALLOC_META, "meta");
-               } while (rc == -EINPROGRESS || rc == -EAGAIN);
-       }
+       do {
+               /* If meta server return -EINPROGRESS or EAGAIN,
+                * it means meta server might not be ready to
+                * allocate super sequence from sequence controller
+                * (MDT0)yet */
+               rc = seq_client_rpc(seq, &seq->lcs_space,
+                                   SEQ_ALLOC_META, "meta");
+       } while (rc == -EINPROGRESS || rc == -EAGAIN);
 
        return rc;
 }
@@ -248,57 +240,6 @@ static void seq_fid_alloc_fini(struct lu_client_seq *seq)
        wake_up(&seq->lcs_waitq);
 }
 
-/**
- * Allocate the whole seq to the caller.
- **/
-int seq_client_get_seq(const struct lu_env *env,
-                      struct lu_client_seq *seq, u64 *seqnr)
-{
-       wait_queue_t link;
-       int rc;
-
-       LASSERT(seqnr != NULL);
-       mutex_lock(&seq->lcs_mutex);
-       init_waitqueue_entry(&link, current);
-
-       while (1) {
-               rc = seq_fid_alloc_prep(seq, &link);
-               if (rc == 0)
-                       break;
-       }
-
-       rc = seq_client_alloc_seq(env, seq, seqnr);
-       if (rc) {
-               CERROR("%s: Can't allocate new sequence, rc %d\n",
-                      seq->lcs_name, rc);
-               seq_fid_alloc_fini(seq);
-               mutex_unlock(&seq->lcs_mutex);
-               return rc;
-       }
-
-       CDEBUG(D_INFO, "%s: allocate sequence [0x%16.16Lx]\n",
-              seq->lcs_name, *seqnr);
-
-       /* Since the caller require the whole seq,
-        * so marked this seq to be used */
-       if (seq->lcs_type == LUSTRE_SEQ_METADATA)
-               seq->lcs_fid.f_oid = LUSTRE_METADATA_SEQ_MAX_WIDTH;
-       else
-               seq->lcs_fid.f_oid = LUSTRE_DATA_SEQ_MAX_WIDTH;
-
-       seq->lcs_fid.f_seq = *seqnr;
-       seq->lcs_fid.f_ver = 0;
-       /*
-        * Inform caller that sequence switch is performed to allow it
-        * to setup FLD for it.
-        */
-       seq_fid_alloc_fini(seq);
-       mutex_unlock(&seq->lcs_mutex);
-
-       return rc;
-}
-EXPORT_SYMBOL(seq_client_get_seq);
-
 /* Allocate new fid on passed client @seq and save it to @fid. */
 int seq_client_alloc_fid(const struct lu_env *env,
                         struct lu_client_seq *seq, struct lu_fid *fid)
@@ -438,18 +379,26 @@ out_cleanup:
        return rc;
 }
 
-int seq_client_init(struct lu_client_seq *seq,
-                   struct obd_export *exp,
-                   enum lu_cli_type type,
-                   const char *prefix,
-                   struct lu_server_seq *srv)
+static void seq_client_fini(struct lu_client_seq *seq)
+{
+       seq_client_debugfs_fini(seq);
+
+       if (seq->lcs_exp) {
+               class_export_put(seq->lcs_exp);
+               seq->lcs_exp = NULL;
+       }
+}
+
+static int seq_client_init(struct lu_client_seq *seq,
+                          struct obd_export *exp,
+                          enum lu_cli_type type,
+                          const char *prefix)
 {
        int rc;
 
        LASSERT(seq != NULL);
        LASSERT(prefix != NULL);
 
-       seq->lcs_srv = srv;
        seq->lcs_type = type;
 
        mutex_init(&seq->lcs_mutex);
@@ -462,10 +411,7 @@ int seq_client_init(struct lu_client_seq *seq,
        /* Make sure that things are clear before work is started. */
        seq_client_flush(seq);
 
-       if (exp != NULL)
-               seq->lcs_exp = class_export_get(exp);
-       else if (type == LUSTRE_SEQ_METADATA)
-               LASSERT(seq->lcs_srv != NULL);
+       seq->lcs_exp = class_export_get(exp);
 
        snprintf(seq->lcs_name, sizeof(seq->lcs_name),
                 "cli-%s", prefix);
@@ -475,20 +421,6 @@ int seq_client_init(struct lu_client_seq *seq,
                seq_client_fini(seq);
        return rc;
 }
-EXPORT_SYMBOL(seq_client_init);
-
-void seq_client_fini(struct lu_client_seq *seq)
-{
-       seq_client_debugfs_fini(seq);
-
-       if (seq->lcs_exp != NULL) {
-               class_export_put(seq->lcs_exp);
-               seq->lcs_exp = NULL;
-       }
-
-       seq->lcs_srv = NULL;
-}
-EXPORT_SYMBOL(seq_client_fini);
 
 int client_fid_init(struct obd_device *obd,
                    struct obd_export *exp, enum lu_cli_type type)
@@ -510,7 +442,7 @@ int client_fid_init(struct obd_device *obd,
        snprintf(prefix, MAX_OBD_NAME + 5, "cli-%s", obd->obd_name);
 
        /* Init client side sequence-manager */
-       rc = seq_client_init(cli->cl_seq, exp, type, prefix, NULL);
+       rc = seq_client_init(cli->cl_seq, exp, type, prefix);
        kfree(prefix);
        if (rc)
                goto out_free_seq;
index cc2201c25339ba9df389084c4e8bfe7ddef743e7..ce90c1c54a637b4964578d9c807dd144ef956934 100644 (file)
@@ -47,7 +47,6 @@
 
 #include "../include/obd.h"
 #include "../include/obd_class.h"
-#include "../include/dt_object.h"
 #include "../include/obd_support.h"
 #include "../include/lustre_req_layout.h"
 #include "../include/lustre_fid.h"
@@ -205,8 +204,6 @@ ldebugfs_fid_server_seq_show(struct seq_file *m, void *unused)
        if (seq->lcs_exp != NULL) {
                cli = &seq->lcs_exp->exp_obd->u.cli;
                seq_printf(m, "%s\n", cli->cl_target_uuid.uuid);
-       } else {
-               seq_printf(m, "%s\n", seq->lcs_srv->lss_name);
        }
 
        return 0;
index 1b1066b2461ceadb6aeb01e7d12fe76d1b89fa83..446917484637d994032202bf37d438d182dc7b7b 100644 (file)
@@ -53,7 +53,6 @@
 #include "../include/obd_support.h"
 #include "../include/lprocfs_status.h"
 
-#include "../include/dt_object.h"
 #include "../include/lustre_req_layout.h"
 #include "../include/lustre_fld.h"
 #include "fld_internal.h"
@@ -266,7 +265,7 @@ static void fld_cache_punch_hole(struct fld_cache *cache,
        const u64 new_end  = range->lsr_end;
        struct fld_cache_entry *fldt;
 
-       OBD_ALLOC_GFP(fldt, sizeof(*fldt), GFP_ATOMIC);
+       fldt = kzalloc(sizeof(*fldt), GFP_ATOMIC);
        if (!fldt) {
                kfree(f_new);
                /* overlap is not allowed, so dont mess up list. */
index 844576b9bc6f54cd5fb40e09b054d5f7702234fa..fbb232de6c7417a400354aefbc10358a06a73ae8 100644 (file)
@@ -42,7 +42,6 @@
 #define __FLD_INTERNAL_H
 
 #include "../include/lustre/lustre_idl.h"
-#include "../include/dt_object.h"
 
 #include "../../include/linux/libcfs/libcfs.h"
 #include "../include/lustre_req_layout.h"
@@ -175,8 +174,6 @@ void fld_dump_cache_entries(struct fld_cache *cache);
 struct fld_cache_entry
 *fld_cache_entry_lookup_nolock(struct fld_cache *cache,
                              struct lu_seq_range *range);
-int fld_write_range(const struct lu_env *env, struct dt_object *dt,
-                   const struct lu_seq_range *range, struct thandle *th);
 
 static inline const char *
 fld_target_name(struct lu_fld_target *tar)
index 1e450bf953838ef75a996f21a71b3d487cce189d..3fd91bc77da5de0fa1060b31aa0889ab8956aa15 100644 (file)
@@ -52,7 +52,6 @@
 #include "../include/obd_support.h"
 #include "../include/lprocfs_status.h"
 
-#include "../include/dt_object.h"
 #include "../include/lustre_req_layout.h"
 #include "../include/lustre_fld.h"
 #include "../include/lustre_mdc.h"
index da822101e0054e41146b19c4bddc883097d0e3a6..603f56e6095ba82beef14a6ab67da7f0c21f2ca1 100644 (file)
@@ -48,7 +48,6 @@
 
 #include "../include/obd.h"
 #include "../include/obd_class.h"
-#include "../include/dt_object.h"
 #include "../include/obd_support.h"
 #include "../include/lustre_req_layout.h"
 #include "../include/lustre_fld.h"
index d56c8bea89c4089600952c51ee4aeed3c5430e5a..73564f8e388458ca3f3ed8b689edd9e4e8d454c2 100644 (file)
@@ -173,11 +173,11 @@ struct cl_attr {
         */
        loff_t cat_kms;
        /** Modification time. Measured in seconds since epoch. */
-       time_t cat_mtime;
+       time64_t cat_mtime;
        /** Access time. Measured in seconds since epoch. */
-       time_t cat_atime;
+       time64_t cat_atime;
        /** Change time. Measured in seconds since epoch. */
-       time_t cat_ctime;
+       time64_t cat_ctime;
        /**
         * Blocks allocated to this cl_object on the server file system.
         *
@@ -1095,7 +1095,7 @@ do {                                                                  \
                                                                        \
        if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) {              \
                cl_page_print(env, &msgdata, lu_cdebug_printer, page);  \
-               CDEBUG(mask, format , ## __VA_ARGS__);            \
+               CDEBUG(mask, format, ## __VA_ARGS__);             \
        }                                                              \
 } while (0)
 
@@ -1108,7 +1108,7 @@ do {                                                                        \
                                                                              \
        if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) {                    \
                cl_page_header_print(env, &msgdata, lu_cdebug_printer, page); \
-               CDEBUG(mask, format , ## __VA_ARGS__);                  \
+               CDEBUG(mask, format, ## __VA_ARGS__);                   \
        }                                                                    \
 } while (0)
 
@@ -1119,6 +1119,7 @@ static inline int __page_in_use(const struct cl_page *page, int refc)
        LASSERT(atomic_read(&page->cp_ref) > 0);
        return (atomic_read(&page->cp_ref) > refc);
 }
+
 #define cl_page_in_use(pg)       __page_in_use(pg, 1)
 #define cl_page_in_use_noref(pg) __page_in_use(pg, 0)
 
@@ -1475,13 +1476,13 @@ enum cl_lock_flags {
         * lock has been cancelled. This flag is never cleared once set (by
         * cl_lock_cancel0()).
         */
-       CLF_CANCELLED  = 1 << 0,
+       CLF_CANCELLED   = 1 << 0,
        /** cancellation is pending for this lock. */
-       CLF_CANCELPEND = 1 << 1,
+       CLF_CANCELPEND  = 1 << 1,
        /** destruction is pending for this lock. */
-       CLF_DOOMED     = 1 << 2,
+       CLF_DOOMED      = 1 << 2,
        /** from enqueue RPC reply upcall. */
-       CLF_FROM_UPCALL= 1 << 3,
+       CLF_FROM_UPCALL = 1 << 3,
 };
 
 /**
@@ -1833,7 +1834,7 @@ do {                                                                  \
                                                                        \
        if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) {              \
                cl_lock_print(env, &msgdata, lu_cdebug_printer, lock);  \
-               CDEBUG(mask, format , ## __VA_ARGS__);            \
+               CDEBUG(mask, format, ## __VA_ARGS__);             \
        }                                                              \
 } while (0)
 
@@ -2020,7 +2021,6 @@ struct cl_io_slice {
        struct list_head                     cis_linkage;
 };
 
-
 /**
  * Per-layer io operations.
  * \see vvp_io_ops, lov_io_ops, lovsub_io_ops, osc_io_ops
@@ -2294,7 +2294,6 @@ struct cl_io_rw_common {
        int      crw_nonblock;
 };
 
-
 /**
  * State for io.
  *
@@ -2335,7 +2334,6 @@ struct cl_io {
                struct cl_setattr_io {
                        struct ost_lvb   sa_attr;
                        unsigned int     sa_valid;
-                       struct obd_capa *sa_capa;
                } ci_setattr;
                struct cl_fault_io {
                        /** page index within file. */
@@ -2354,7 +2352,6 @@ struct cl_io {
                struct cl_fsync_io {
                        loff_t       fi_start;
                        loff_t       fi_end;
-                       struct obd_capa   *fi_capa;
                        /** file system level fid */
                        struct lu_fid     *fi_fid;
                        enum cl_fsync_mode fi_mode;
@@ -2473,8 +2470,6 @@ struct cl_io {
 struct cl_req_attr {
        /** Generic attributes for the server consumption. */
        struct obdo     *cra_oa;
-       /** Capability. */
-       struct obd_capa *cra_capa;
        /** Jobid */
        char             cra_jobid[JOBSTATS_JOBID_SIZE];
 };
@@ -2737,7 +2732,6 @@ struct cl_object *cl_object_find(const struct lu_env *env, struct cl_device *cd,
                                 const struct cl_object_conf *c);
 
 int  cl_object_header_init(struct cl_object_header *h);
-void cl_object_header_fini(struct cl_object_header *h);
 void cl_object_put     (const struct lu_env *env, struct cl_object *o);
 void cl_object_get     (struct cl_object *o);
 void cl_object_attr_lock  (struct cl_object *o);
@@ -2752,7 +2746,6 @@ int  cl_conf_set    (const struct lu_env *env, struct cl_object *obj,
                           const struct cl_object_conf *conf);
 void cl_object_prune      (const struct lu_env *env, struct cl_object *obj);
 void cl_object_kill       (const struct lu_env *env, struct cl_object *obj);
-int  cl_object_has_locks  (struct cl_object *obj);
 
 /**
  * Returns true, iff \a o0 and \a o1 are slices of the same object.
@@ -2864,7 +2857,6 @@ int  cl_page_flush      (const struct lu_env *env, struct cl_io *io,
 
 /** @} transfer */
 
-
 /**
  * \name helper routines
  * Functions to discard, delete and export a cl_page.
@@ -2939,10 +2931,6 @@ void  cl_lock_release   (const struct lu_env *env, struct cl_lock *lock,
 void  cl_lock_user_add  (const struct lu_env *env, struct cl_lock *lock);
 void  cl_lock_user_del  (const struct lu_env *env, struct cl_lock *lock);
 
-enum cl_lock_state cl_lock_intransit(const struct lu_env *env,
-                                    struct cl_lock *lock);
-void cl_lock_extransit(const struct lu_env *env, struct cl_lock *lock,
-                      enum cl_lock_state state);
 int cl_lock_is_intransit(struct cl_lock *lock);
 
 int cl_lock_enqueue_wait(const struct lu_env *env, struct cl_lock *lock,
@@ -2980,8 +2968,6 @@ int cl_lock_enqueue_wait(const struct lu_env *env, struct cl_lock *lock,
  *
  * @{ */
 
-int   cl_enqueue    (const struct lu_env *env, struct cl_lock *lock,
-                    struct cl_io *io, __u32 flags);
 int   cl_wait       (const struct lu_env *env, struct cl_lock *lock);
 void  cl_unuse      (const struct lu_env *env, struct cl_lock *lock);
 int   cl_enqueue_try(const struct lu_env *env, struct cl_lock *lock,
@@ -3000,7 +2986,6 @@ int  cl_queue_match      (const struct list_head *queue,
                          const struct cl_lock_descr *need);
 
 void cl_lock_mutex_get  (const struct lu_env *env, struct cl_lock *lock);
-int  cl_lock_mutex_try  (const struct lu_env *env, struct cl_lock *lock);
 void cl_lock_mutex_put  (const struct lu_env *env, struct cl_lock *lock);
 int  cl_lock_is_mutexed (struct cl_lock *lock);
 int  cl_lock_nr_mutexed (const struct lu_env *env);
@@ -3066,10 +3051,6 @@ int   cl_io_submit_rw    (const struct lu_env *env, struct cl_io *io,
 int   cl_io_submit_sync  (const struct lu_env *env, struct cl_io *io,
                          enum cl_req_type iot, struct cl_2queue *queue,
                          long timeout);
-void  cl_io_rw_advance   (const struct lu_env *env, struct cl_io *io,
-                         size_t nob);
-int   cl_io_cancel       (const struct lu_env *env, struct cl_io *io,
-                         struct cl_page_list *queue);
 int   cl_io_is_going     (const struct lu_env *env);
 
 /**
@@ -3101,9 +3082,6 @@ static inline int cl_io_is_trunc(const struct cl_io *io)
 
 struct cl_io *cl_io_top(struct cl_io *io);
 
-void cl_io_print(const struct lu_env *env, void *cookie,
-                lu_printer_t printer, const struct cl_io *io);
-
 #define CL_IO_SLICE_CLEAN(foo_io, base)                                        \
 do {                                                                   \
        typeof(foo_io) __foo_io = (foo_io);                             \
@@ -3145,26 +3123,13 @@ void cl_page_list_move   (struct cl_page_list *dst, struct cl_page_list *src,
                          struct cl_page *page);
 void cl_page_list_splice (struct cl_page_list *list,
                          struct cl_page_list *head);
-void cl_page_list_del    (const struct lu_env *env,
-                         struct cl_page_list *plist, struct cl_page *page);
 void cl_page_list_disown (const struct lu_env *env,
                          struct cl_io *io, struct cl_page_list *plist);
-int  cl_page_list_own    (const struct lu_env *env,
-                         struct cl_io *io, struct cl_page_list *plist);
-void cl_page_list_assume (const struct lu_env *env,
-                         struct cl_io *io, struct cl_page_list *plist);
-void cl_page_list_discard(const struct lu_env *env,
-                         struct cl_io *io, struct cl_page_list *plist);
-int  cl_page_list_unmap  (const struct lu_env *env,
-                         struct cl_io *io, struct cl_page_list *plist);
-void cl_page_list_fini   (const struct lu_env *env, struct cl_page_list *plist);
 
 void cl_2queue_init     (struct cl_2queue *queue);
 void cl_2queue_add      (struct cl_2queue *queue, struct cl_page *page);
 void cl_2queue_disown   (const struct lu_env *env,
                         struct cl_io *io, struct cl_2queue *queue);
-void cl_2queue_assume   (const struct lu_env *env,
-                        struct cl_io *io, struct cl_2queue *queue);
 void cl_2queue_discard  (const struct lu_env *env,
                         struct cl_io *io, struct cl_2queue *queue);
 void cl_2queue_fini     (const struct lu_env *env, struct cl_2queue *queue);
@@ -3257,7 +3222,6 @@ struct cl_env_nest {
        void *cen_cookie;
 };
 
-struct lu_env *cl_env_peek       (int *refcheck);
 struct lu_env *cl_env_get      (int *refcheck);
 struct lu_env *cl_env_alloc      (int *refcheck, __u32 tags);
 struct lu_env *cl_env_nested_get (struct cl_env_nest *nest);
@@ -3273,7 +3237,6 @@ void         cl_env_unplant    (struct lu_env *env, int *refcheck);
 /*
  * Misc
  */
-void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr);
 void cl_lvb2attr(struct cl_attr *attr, const struct ost_lvb *lvb);
 
 struct cl_device *cl_type_setup(const struct lu_env *env, struct lu_site *site,
diff --git a/drivers/staging/lustre/lustre/include/dt_object.h b/drivers/staging/lustre/lustre/include/dt_object.h
deleted file mode 100644 (file)
index abae31b..0000000
+++ /dev/null
@@ -1,1496 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-
-#ifndef __LUSTRE_DT_OBJECT_H
-#define __LUSTRE_DT_OBJECT_H
-
-/** \defgroup dt dt
- * Sub-class of lu_object with methods common for "data" objects in OST stack.
- *
- * Data objects behave like regular files: you can read/write them, get and
- * set their attributes. Implementation of dt interface is supposed to
- * implement some form of garbage collection, normally reference counting
- * (nlink) based one.
- *
- * Examples: osd (lustre/osd) is an implementation of dt interface.
- * @{
- */
-
-
-/*
- * super-class definitions.
- */
-#include "lu_object.h"
-
-#include "../../include/linux/libcfs/libcfs.h"
-
-struct seq_file;
-struct lustre_cfg;
-
-struct thandle;
-struct dt_device;
-struct dt_object;
-struct dt_index_features;
-struct niobuf_local;
-struct niobuf_remote;
-struct ldlm_enqueue_info;
-
-typedef enum {
-       MNTOPT_USERXATTR        = 0x00000001,
-       MNTOPT_ACL            = 0x00000002,
-} mntopt_t;
-
-struct dt_device_param {
-       unsigned           ddp_max_name_len;
-       unsigned           ddp_max_nlink;
-       unsigned           ddp_block_shift;
-       mntopt_t           ddp_mntopts;
-       unsigned           ddp_max_ea_size;
-       void          *ddp_mnt; /* XXX: old code can retrieve mnt -bzzz */
-       int             ddp_mount_type;
-       unsigned long long ddp_maxbytes;
-       /* percentage of available space to reserve for grant error margin */
-       int             ddp_grant_reserved;
-       /* per-inode space consumption */
-       short         ddp_inodespace;
-       /* per-fragment grant overhead to be used by client for grant
-        * calculation */
-       int             ddp_grant_frag;
-};
-
-/**
- * Per-transaction commit callback function
- */
-struct dt_txn_commit_cb;
-typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
-                       struct dt_txn_commit_cb *cb, int err);
-/**
- * Special per-transaction callback for cases when just commit callback
- * is needed and per-device callback are not convenient to use
- */
-#define TRANS_COMMIT_CB_MAGIC  0xa0a00a0a
-#define MAX_COMMIT_CB_STR_LEN  32
-
-struct dt_txn_commit_cb {
-       struct list_head        dcb_linkage;
-       dt_cb_t         dcb_func;
-       __u32           dcb_magic;
-       char            dcb_name[MAX_COMMIT_CB_STR_LEN];
-};
-
-/**
- * Operations on dt device.
- */
-struct dt_device_operations {
-       /**
-        * Return device-wide statistics.
-        */
-       int   (*dt_statfs)(const struct lu_env *env,
-                          struct dt_device *dev, struct obd_statfs *osfs);
-       /**
-        * Create transaction, described by \a param.
-        */
-       struct thandle *(*dt_trans_create)(const struct lu_env *env,
-                                          struct dt_device *dev);
-       /**
-        * Start transaction, described by \a param.
-        */
-       int   (*dt_trans_start)(const struct lu_env *env,
-                               struct dt_device *dev, struct thandle *th);
-       /**
-        * Finish previously started transaction.
-        */
-       int   (*dt_trans_stop)(const struct lu_env *env,
-                              struct thandle *th);
-       /**
-        * Add commit callback to the transaction.
-        */
-       int   (*dt_trans_cb_add)(struct thandle *th,
-                                struct dt_txn_commit_cb *dcb);
-       /**
-        * Return fid of root index object.
-        */
-       int   (*dt_root_get)(const struct lu_env *env,
-                            struct dt_device *dev, struct lu_fid *f);
-       /**
-        * Return device configuration data.
-        */
-       void  (*dt_conf_get)(const struct lu_env *env,
-                            const struct dt_device *dev,
-                            struct dt_device_param *param);
-       /**
-        *  handling device state, mostly for tests
-        */
-       int   (*dt_sync)(const struct lu_env *env, struct dt_device *dev);
-       int   (*dt_ro)(const struct lu_env *env, struct dt_device *dev);
-       /**
-         * Start a transaction commit asynchronously
-         *
-         * \param env environment
-         * \param dev dt_device to start commit on
-         *
-         * \return 0 success, negative value if error
-         */
-        int   (*dt_commit_async)(const struct lu_env *env,
-                                 struct dt_device *dev);
-       /**
-        * Initialize capability context.
-        */
-       int   (*dt_init_capa_ctxt)(const struct lu_env *env,
-                                  struct dt_device *dev,
-                                  int mode, unsigned long timeout,
-                                  __u32 alg, struct lustre_capa_key *keys);
-};
-
-struct dt_index_features {
-       /** required feature flags from enum dt_index_flags */
-       __u32 dif_flags;
-       /** minimal required key size */
-       size_t dif_keysize_min;
-       /** maximal required key size, 0 if no limit */
-       size_t dif_keysize_max;
-       /** minimal required record size */
-       size_t dif_recsize_min;
-       /** maximal required record size, 0 if no limit */
-       size_t dif_recsize_max;
-       /** pointer size for record */
-       size_t dif_ptrsize;
-};
-
-enum dt_index_flags {
-       /** index supports variable sized keys */
-       DT_IND_VARKEY = 1 << 0,
-       /** index supports variable sized records */
-       DT_IND_VARREC = 1 << 1,
-       /** index can be modified */
-       DT_IND_UPDATE = 1 << 2,
-       /** index supports records with non-unique (duplicate) keys */
-       DT_IND_NONUNQ = 1 << 3,
-       /**
-        * index support fixed-size keys sorted with natural numerical way
-        * and is able to return left-side value if no exact value found
-        */
-       DT_IND_RANGE = 1 << 4,
-};
-
-/**
- * Features, required from index to support file system directories (mapping
- * names to fids).
- */
-extern const struct dt_index_features dt_directory_features;
-extern const struct dt_index_features dt_otable_features;
-extern const struct dt_index_features dt_lfsck_features;
-
-/* index features supported by the accounting objects */
-extern const struct dt_index_features dt_acct_features;
-
-/* index features supported by the quota global indexes */
-extern const struct dt_index_features dt_quota_glb_features;
-
-/* index features supported by the quota slave indexes */
-extern const struct dt_index_features dt_quota_slv_features;
-
-/**
- * This is a general purpose dt allocation hint.
- * It now contains the parent object.
- * It can contain any allocation hint in the future.
- */
-struct dt_allocation_hint {
-       struct dt_object           *dah_parent;
-       __u32                  dah_mode;
-};
-
-/**
- * object type specifier.
- */
-
-enum dt_format_type {
-       DFT_REGULAR,
-       DFT_DIR,
-       /** for mknod */
-       DFT_NODE,
-       /** for special index */
-       DFT_INDEX,
-       /** for symbolic link */
-       DFT_SYM,
-};
-
-/**
- * object format specifier.
- */
-struct dt_object_format {
-       /** type for dt object */
-       enum dt_format_type dof_type;
-       union {
-               struct dof_regular {
-                       int striped;
-               } dof_reg;
-               struct dof_dir {
-               } dof_dir;
-               struct dof_node {
-               } dof_node;
-               /**
-                * special index need feature as parameter to create
-                * special idx
-                */
-               struct dof_index {
-                       const struct dt_index_features *di_feat;
-               } dof_idx;
-       } u;
-};
-
-enum dt_format_type dt_mode_to_dft(__u32 mode);
-
-typedef __u64 dt_obj_version_t;
-
-/**
- * Per-dt-object operations.
- */
-struct dt_object_operations {
-       void  (*do_read_lock)(const struct lu_env *env,
-                             struct dt_object *dt, unsigned role);
-       void  (*do_write_lock)(const struct lu_env *env,
-                              struct dt_object *dt, unsigned role);
-       void  (*do_read_unlock)(const struct lu_env *env,
-                               struct dt_object *dt);
-       void  (*do_write_unlock)(const struct lu_env *env,
-                                struct dt_object *dt);
-       int  (*do_write_locked)(const struct lu_env *env,
-                               struct dt_object *dt);
-       /**
-        * Note: following ->do_{x,}attr_{set,get}() operations are very
-        * similar to ->moo_{x,}attr_{set,get}() operations in struct
-        * md_object_operations (see md_object.h). These operations are not in
-        * lu_object_operations, because ->do_{x,}attr_set() versions take
-        * transaction handle as an argument (this transaction is started by
-        * caller). We might factor ->do_{x,}attr_get() into
-        * lu_object_operations, but that would break existing symmetry.
-        */
-
-       /**
-        * Return standard attributes.
-        *
-        * precondition: lu_object_exists(&dt->do_lu);
-        */
-       int   (*do_attr_get)(const struct lu_env *env,
-                            struct dt_object *dt, struct lu_attr *attr,
-                            struct lustre_capa *capa);
-       /**
-        * Set standard attributes.
-        *
-        * precondition: dt_object_exists(dt);
-        */
-       int   (*do_declare_attr_set)(const struct lu_env *env,
-                                    struct dt_object *dt,
-                                    const struct lu_attr *attr,
-                                    struct thandle *handle);
-       int   (*do_attr_set)(const struct lu_env *env,
-                            struct dt_object *dt,
-                            const struct lu_attr *attr,
-                            struct thandle *handle,
-                            struct lustre_capa *capa);
-       /**
-        * Return a value of an extended attribute.
-        *
-        * precondition: dt_object_exists(dt);
-        */
-       int   (*do_xattr_get)(const struct lu_env *env, struct dt_object *dt,
-                             struct lu_buf *buf, const char *name,
-                             struct lustre_capa *capa);
-       /**
-        * Set value of an extended attribute.
-        *
-        * \a fl - flags from enum lu_xattr_flags
-        *
-        * precondition: dt_object_exists(dt);
-        */
-       int   (*do_declare_xattr_set)(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     const struct lu_buf *buf,
-                                     const char *name, int fl,
-                                     struct thandle *handle);
-       int   (*do_xattr_set)(const struct lu_env *env,
-                             struct dt_object *dt, const struct lu_buf *buf,
-                             const char *name, int fl, struct thandle *handle,
-                             struct lustre_capa *capa);
-       /**
-        * Delete existing extended attribute.
-        *
-        * precondition: dt_object_exists(dt);
-        */
-       int   (*do_declare_xattr_del)(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     const char *name, struct thandle *handle);
-       int   (*do_xattr_del)(const struct lu_env *env,
-                             struct dt_object *dt,
-                             const char *name, struct thandle *handle,
-                             struct lustre_capa *capa);
-       /**
-        * Place list of existing extended attributes into \a buf (which has
-        * length len).
-        *
-        * precondition: dt_object_exists(dt);
-        */
-       int   (*do_xattr_list)(const struct lu_env *env,
-                              struct dt_object *dt, struct lu_buf *buf,
-                              struct lustre_capa *capa);
-       /**
-        * Init allocation hint using parent object and child mode.
-        * (1) The \a parent might be NULL if this is a partial creation for
-        *     remote object.
-        * (2) The type of child is in \a child_mode.
-        * (3) The result hint is stored in \a ah;
-        */
-       void  (*do_ah_init)(const struct lu_env *env,
-                           struct dt_allocation_hint *ah,
-                           struct dt_object *parent,
-                           struct dt_object *child,
-                           umode_t child_mode);
-       /**
-        * Create new object on this device.
-        *
-        * precondition: !dt_object_exists(dt);
-        * postcondition: ergo(result == 0, dt_object_exists(dt));
-        */
-       int   (*do_declare_create)(const struct lu_env *env,
-                                  struct dt_object *dt,
-                                  struct lu_attr *attr,
-                                  struct dt_allocation_hint *hint,
-                                  struct dt_object_format *dof,
-                                  struct thandle *th);
-       int   (*do_create)(const struct lu_env *env, struct dt_object *dt,
-                          struct lu_attr *attr,
-                          struct dt_allocation_hint *hint,
-                          struct dt_object_format *dof,
-                          struct thandle *th);
-
-       /**
-         Destroy object on this device
-        * precondition: !dt_object_exists(dt);
-        * postcondition: ergo(result == 0, dt_object_exists(dt));
-        */
-       int   (*do_declare_destroy)(const struct lu_env *env,
-                                   struct dt_object *dt,
-                                   struct thandle *th);
-       int   (*do_destroy)(const struct lu_env *env, struct dt_object *dt,
-                           struct thandle *th);
-
-       /**
-        * Announce that this object is going to be used as an index. This
-        * operation check that object supports indexing operations and
-        * installs appropriate dt_index_operations vector on success.
-        *
-        * Also probes for features. Operation is successful if all required
-        * features are supported.
-        */
-       int   (*do_index_try)(const struct lu_env *env,
-                             struct dt_object *dt,
-                             const struct dt_index_features *feat);
-       /**
-        * Add nlink of the object
-        * precondition: dt_object_exists(dt);
-        */
-       int   (*do_declare_ref_add)(const struct lu_env *env,
-                                   struct dt_object *dt, struct thandle *th);
-       int   (*do_ref_add)(const struct lu_env *env,
-                           struct dt_object *dt, struct thandle *th);
-       /**
-        * Del nlink of the object
-        * precondition: dt_object_exists(dt);
-        */
-       int   (*do_declare_ref_del)(const struct lu_env *env,
-                                   struct dt_object *dt, struct thandle *th);
-       int   (*do_ref_del)(const struct lu_env *env,
-                           struct dt_object *dt, struct thandle *th);
-
-       struct obd_capa *(*do_capa_get)(const struct lu_env *env,
-                                       struct dt_object *dt,
-                                       struct lustre_capa *old,
-                                       __u64 opc);
-       int (*do_object_sync)(const struct lu_env *env, struct dt_object *obj,
-                             __u64 start, __u64 end);
-       /**
-        * Get object info of next level. Currently, only get inode from osd.
-        * This is only used by quota b=16542
-        * precondition: dt_object_exists(dt);
-        */
-       int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
-                          void **data);
-
-       /**
-        * Lock object.
-        */
-       int (*do_object_lock)(const struct lu_env *env, struct dt_object *dt,
-                             struct lustre_handle *lh,
-                             struct ldlm_enqueue_info *einfo,
-                             void *policy);
-};
-
-/**
- * Per-dt-object operations on "file body".
- */
-struct dt_body_operations {
-       /**
-        * precondition: dt_object_exists(dt);
-        */
-       ssize_t (*dbo_read)(const struct lu_env *env, struct dt_object *dt,
-                           struct lu_buf *buf, loff_t *pos,
-                           struct lustre_capa *capa);
-       /**
-        * precondition: dt_object_exists(dt);
-        */
-       ssize_t (*dbo_declare_write)(const struct lu_env *env,
-                                    struct dt_object *dt,
-                                    const loff_t size, loff_t pos,
-                                    struct thandle *handle);
-       ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
-                            const struct lu_buf *buf, loff_t *pos,
-                            struct thandle *handle, struct lustre_capa *capa,
-                            int ignore_quota);
-       /*
-        * methods for zero-copy IO
-        */
-
-       /*
-        * precondition: dt_object_exists(dt);
-        * returns:
-        * < 0 - error code
-        * = 0 - illegal
-        * > 0 - number of local buffers prepared
-        */
-       int (*dbo_bufs_get)(const struct lu_env *env, struct dt_object *dt,
-                           loff_t pos, ssize_t len, struct niobuf_local *lb,
-                           int rw, struct lustre_capa *capa);
-       /*
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dbo_bufs_put)(const struct lu_env *env, struct dt_object *dt,
-                           struct niobuf_local *lb, int nr);
-       /*
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dbo_write_prep)(const struct lu_env *env, struct dt_object *dt,
-                             struct niobuf_local *lb, int nr);
-       /*
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dbo_declare_write_commit)(const struct lu_env *env,
-                                       struct dt_object *dt,
-                                       struct niobuf_local *,
-                                       int, struct thandle *);
-       /*
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dbo_write_commit)(const struct lu_env *env, struct dt_object *dt,
-                               struct niobuf_local *, int, struct thandle *);
-       /*
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dbo_read_prep)(const struct lu_env *env, struct dt_object *dt,
-                            struct niobuf_local *lnb, int nr);
-       int (*dbo_fiemap_get)(const struct lu_env *env, struct dt_object *dt,
-                             struct ll_user_fiemap *fm);
-       /**
-        * Punch object's content
-        * precondition: regular object, not index
-        */
-       int   (*dbo_declare_punch)(const struct lu_env *, struct dt_object *,
-                                 __u64, __u64, struct thandle *th);
-       int   (*dbo_punch)(const struct lu_env *env, struct dt_object *dt,
-                         __u64 start, __u64 end, struct thandle *th,
-                         struct lustre_capa *capa);
-};
-
-/**
- * Incomplete type of index record.
- */
-struct dt_rec;
-
-/**
- * Incomplete type of index key.
- */
-struct dt_key;
-
-/**
- * Incomplete type of dt iterator.
- */
-struct dt_it;
-
-/**
- * Per-dt-object operations on object as index.
- */
-struct dt_index_operations {
-       /**
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dio_lookup)(const struct lu_env *env, struct dt_object *dt,
-                         struct dt_rec *rec, const struct dt_key *key,
-                         struct lustre_capa *capa);
-       /**
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dio_declare_insert)(const struct lu_env *env,
-                                 struct dt_object *dt,
-                                 const struct dt_rec *rec,
-                                 const struct dt_key *key,
-                                 struct thandle *handle);
-       int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
-                         const struct dt_rec *rec, const struct dt_key *key,
-                         struct thandle *handle, struct lustre_capa *capa,
-                         int ignore_quota);
-       /**
-        * precondition: dt_object_exists(dt);
-        */
-       int (*dio_declare_delete)(const struct lu_env *env,
-                                 struct dt_object *dt,
-                                 const struct dt_key *key,
-                                 struct thandle *handle);
-       int (*dio_delete)(const struct lu_env *env, struct dt_object *dt,
-                         const struct dt_key *key, struct thandle *handle,
-                         struct lustre_capa *capa);
-       /**
-        * Iterator interface
-        */
-       struct dt_it_ops {
-               /**
-                * Allocate and initialize new iterator.
-                *
-                * precondition: dt_object_exists(dt);
-                */
-               struct dt_it *(*init)(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     __u32 attr,
-                                     struct lustre_capa *capa);
-               void      (*fini)(const struct lu_env *env,
-                                     struct dt_it *di);
-               int         (*get)(const struct lu_env *env,
-                                     struct dt_it *di,
-                                     const struct dt_key *key);
-               void       (*put)(const struct lu_env *env,
-                                     struct dt_it *di);
-               int        (*next)(const struct lu_env *env,
-                                     struct dt_it *di);
-               struct dt_key *(*key)(const struct lu_env *env,
-                                     const struct dt_it *di);
-               int       (*key_size)(const struct lu_env *env,
-                                     const struct dt_it *di);
-               int         (*rec)(const struct lu_env *env,
-                                     const struct dt_it *di,
-                                     struct dt_rec *rec,
-                                     __u32 attr);
-               __u64   (*store)(const struct lu_env *env,
-                                     const struct dt_it *di);
-               int        (*load)(const struct lu_env *env,
-                                     const struct dt_it *di, __u64 hash);
-               int     (*key_rec)(const struct lu_env *env,
-                                     const struct dt_it *di, void *key_rec);
-       } dio_it;
-};
-
-enum dt_otable_it_valid {
-       DOIV_ERROR_HANDLE       = 0x0001,
-};
-
-enum dt_otable_it_flags {
-       /* Exit when fail. */
-       DOIF_FAILOUT    = 0x0001,
-
-       /* Reset iteration position to the device beginning. */
-       DOIF_RESET      = 0x0002,
-
-       /* There is up layer component uses the iteration. */
-       DOIF_OUTUSED    = 0x0004,
-};
-
-/* otable based iteration needs to use the common DT interation APIs.
- * To initialize the iteration, it needs call dio_it::init() firstly.
- * Here is how the otable based iteration should prepare arguments to
- * call dt_it_ops::init().
- *
- * For otable based iteration, the 32-bits 'attr' for dt_it_ops::init()
- * is composed of two parts:
- * low 16-bits is for valid bits, high 16-bits is for flags bits. */
-#define DT_OTABLE_IT_FLAGS_SHIFT       16
-#define DT_OTABLE_IT_FLAGS_MASK        0xffff0000
-
-struct dt_device {
-       struct lu_device                   dd_lu_dev;
-       const struct dt_device_operations *dd_ops;
-
-       /**
-        * List of dt_txn_callback (see below). This is not protected in any
-        * way, because callbacks are supposed to be added/deleted only during
-        * single-threaded start-up shut-down procedures.
-        */
-       struct list_head                         dd_txn_callbacks;
-};
-
-int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
-void dt_device_fini(struct dt_device *dev);
-
-static inline int lu_device_is_dt(const struct lu_device *d)
-{
-       return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
-}
-
-static inline struct dt_device *lu2dt_dev(struct lu_device *l)
-{
-       LASSERT(lu_device_is_dt(l));
-       return container_of0(l, struct dt_device, dd_lu_dev);
-}
-
-struct dt_object {
-       struct lu_object                   do_lu;
-       const struct dt_object_operations *do_ops;
-       const struct dt_body_operations   *do_body_ops;
-       const struct dt_index_operations  *do_index_ops;
-};
-
-/*
- * In-core representation of per-device local object OID storage
- */
-struct local_oid_storage {
-       /* all initialized llog systems on this node linked by this */
-       struct list_head          los_list;
-
-       /* how many handle's reference this los has */
-       atomic_t          los_refcount;
-       struct dt_device *los_dev;
-       struct dt_object *los_obj;
-
-       /* data used to generate new fids */
-       struct mutex      los_id_lock;
-       __u64             los_seq;
-       __u32             los_last_oid;
-};
-
-static inline struct dt_object *lu2dt(struct lu_object *l)
-{
-       LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
-       return container_of0(l, struct dt_object, do_lu);
-}
-
-int  dt_object_init(struct dt_object *obj,
-                   struct lu_object_header *h, struct lu_device *d);
-
-void dt_object_fini(struct dt_object *obj);
-
-static inline int dt_object_exists(const struct dt_object *dt)
-{
-       return lu_object_exists(&dt->do_lu);
-}
-
-static inline int dt_object_remote(const struct dt_object *dt)
-{
-       return lu_object_remote(&dt->do_lu);
-}
-
-static inline struct dt_object *lu2dt_obj(struct lu_object *o)
-{
-       LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
-       return container_of0(o, struct dt_object, do_lu);
-}
-
-/**
- * This is the general purpose transaction handle.
- * 1. Transaction Life Cycle
- *      This transaction handle is allocated upon starting a new transaction,
- *      and deallocated after this transaction is committed.
- * 2. Transaction Nesting
- *      We do _NOT_ support nested transaction. So, every thread should only
- *      have one active transaction, and a transaction only belongs to one
- *      thread. Due to this, transaction handle need no reference count.
- * 3. Transaction & dt_object locking
- *      dt_object locks should be taken inside transaction.
- * 4. Transaction & RPC
- *      No RPC request should be issued inside transaction.
- */
-struct thandle {
-       /** the dt device on which the transactions are executed */
-       struct dt_device *th_dev;
-
-       /** context for this transaction, tag is LCT_TX_HANDLE */
-       struct lu_context th_ctx;
-
-       /** additional tags (layers can add in declare) */
-       __u32        th_tags;
-
-       /** the last operation result in this transaction.
-        * this value is used in recovery */
-       __s32        th_result;
-
-       /** whether we need sync commit */
-       unsigned int            th_sync:1;
-
-       /* local transation, no need to inform other layers */
-       unsigned int            th_local:1;
-
-       /* In DNE, one transaction can be disassemblied into
-        * updates on several different MDTs, and these updates
-        * will be attached to th_remote_update_list per target.
-        * Only single thread will access the list, no need lock
-        */
-       struct list_head                th_remote_update_list;
-       struct update_request   *th_current_request;
-};
-
-/**
- * Transaction call-backs.
- *
- * These are invoked by osd (or underlying transaction engine) when
- * transaction changes state.
- *
- * Call-backs are used by upper layers to modify transaction parameters and to
- * perform some actions on for each transaction state transition. Typical
- * example is mdt registering call-back to write into last-received file
- * before each transaction commit.
- */
-struct dt_txn_callback {
-       int (*dtc_txn_start)(const struct lu_env *env,
-                            struct thandle *txn, void *cookie);
-       int (*dtc_txn_stop)(const struct lu_env *env,
-                           struct thandle *txn, void *cookie);
-       void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
-       void            *dtc_cookie;
-       __u32           dtc_tag;
-       struct list_head           dtc_linkage;
-};
-
-void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
-void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
-
-int dt_txn_hook_start(const struct lu_env *env,
-                     struct dt_device *dev, struct thandle *txn);
-int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
-void dt_txn_hook_commit(struct thandle *txn);
-
-int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
-
-/**
- * Callback function used for parsing path.
- * \see llo_store_resolve
- */
-typedef int (*dt_entry_func_t)(const struct lu_env *env,
-                           const char *name,
-                           void *pvt);
-
-#define DT_MAX_PATH 1024
-
-int dt_path_parser(const struct lu_env *env,
-                  char *local, dt_entry_func_t entry_func,
-                  void *data);
-
-struct dt_object *
-dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
-                const char *path, struct lu_fid *fid);
-
-struct dt_object *dt_store_open(const struct lu_env *env,
-                               struct dt_device *dt,
-                               const char *dirname,
-                               const char *filename,
-                               struct lu_fid *fid);
-
-struct dt_object *dt_find_or_create(const struct lu_env *env,
-                                   struct dt_device *dt,
-                                   const struct lu_fid *fid,
-                                   struct dt_object_format *dof,
-                                   struct lu_attr *attr);
-
-struct dt_object *dt_locate_at(const struct lu_env *env,
-                              struct dt_device *dev,
-                              const struct lu_fid *fid,
-                              struct lu_device *top_dev);
-static inline struct dt_object *
-dt_locate(const struct lu_env *env, struct dt_device *dev,
-         const struct lu_fid *fid)
-{
-       return dt_locate_at(env, dev, fid, dev->dd_lu_dev.ld_site->ls_top_dev);
-}
-
-
-int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
-                          const struct lu_fid *first_fid,
-                          struct local_oid_storage **los);
-void local_oid_storage_fini(const struct lu_env *env,
-                           struct local_oid_storage *los);
-int local_object_fid_generate(const struct lu_env *env,
-                             struct local_oid_storage *los,
-                             struct lu_fid *fid);
-int local_object_declare_create(const struct lu_env *env,
-                               struct local_oid_storage *los,
-                               struct dt_object *o,
-                               struct lu_attr *attr,
-                               struct dt_object_format *dof,
-                               struct thandle *th);
-int local_object_create(const struct lu_env *env,
-                       struct local_oid_storage *los,
-                       struct dt_object *o,
-                       struct lu_attr *attr, struct dt_object_format *dof,
-                       struct thandle *th);
-struct dt_object *local_file_find_or_create(const struct lu_env *env,
-                                           struct local_oid_storage *los,
-                                           struct dt_object *parent,
-                                           const char *name, __u32 mode);
-struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
-                                                    struct dt_device *dt,
-                                                    const struct lu_fid *fid,
-                                                    struct dt_object *parent,
-                                                    const char *name,
-                                                    __u32 mode);
-struct dt_object *
-local_index_find_or_create(const struct lu_env *env,
-                          struct local_oid_storage *los,
-                          struct dt_object *parent,
-                          const char *name, __u32 mode,
-                          const struct dt_index_features *ft);
-struct dt_object *
-local_index_find_or_create_with_fid(const struct lu_env *env,
-                                   struct dt_device *dt,
-                                   const struct lu_fid *fid,
-                                   struct dt_object *parent,
-                                   const char *name, __u32 mode,
-                                   const struct dt_index_features *ft);
-int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
-                       struct dt_object *parent, const char *name);
-
-static inline int dt_object_lock(const struct lu_env *env,
-                                struct dt_object *o, struct lustre_handle *lh,
-                                struct ldlm_enqueue_info *einfo,
-                                void *policy)
-{
-       LASSERT(o);
-       LASSERT(o->do_ops);
-       LASSERT(o->do_ops->do_object_lock);
-       return o->do_ops->do_object_lock(env, o, lh, einfo, policy);
-}
-
-int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
-                 const char *name, struct lu_fid *fid);
-
-static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
-                                __u64 start, __u64 end)
-{
-       LASSERT(o);
-       LASSERT(o->do_ops);
-       LASSERT(o->do_ops->do_object_sync);
-       return o->do_ops->do_object_sync(env, o, start, end);
-}
-
-int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
-                          struct thandle *th);
-void dt_version_set(const struct lu_env *env, struct dt_object *o,
-                   dt_obj_version_t version, struct thandle *th);
-dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o);
-
-
-int dt_read(const struct lu_env *env, struct dt_object *dt,
-           struct lu_buf *buf, loff_t *pos);
-int dt_record_read(const struct lu_env *env, struct dt_object *dt,
-                  struct lu_buf *buf, loff_t *pos);
-int dt_record_write(const struct lu_env *env, struct dt_object *dt,
-                   const struct lu_buf *buf, loff_t *pos, struct thandle *th);
-typedef int (*dt_index_page_build_t)(const struct lu_env *env,
-                                    union lu_page *lp, int nob,
-                                    const struct dt_it_ops *iops,
-                                    struct dt_it *it, __u32 attr, void *arg);
-int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
-                 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
-                 void *arg);
-int dt_index_read(const struct lu_env *env, struct dt_device *dev,
-                 struct idx_info *ii, const struct lu_rdpg *rdpg);
-
-static inline struct thandle *dt_trans_create(const struct lu_env *env,
-                                             struct dt_device *d)
-{
-       LASSERT(d->dd_ops->dt_trans_create);
-       return d->dd_ops->dt_trans_create(env, d);
-}
-
-static inline int dt_trans_start(const struct lu_env *env,
-                                struct dt_device *d, struct thandle *th)
-{
-       LASSERT(d->dd_ops->dt_trans_start);
-       return d->dd_ops->dt_trans_start(env, d, th);
-}
-
-/* for this transaction hooks shouldn't be called */
-static inline int dt_trans_start_local(const struct lu_env *env,
-                                      struct dt_device *d, struct thandle *th)
-{
-       LASSERT(d->dd_ops->dt_trans_start);
-       th->th_local = 1;
-       return d->dd_ops->dt_trans_start(env, d, th);
-}
-
-static inline int dt_trans_stop(const struct lu_env *env,
-                               struct dt_device *d, struct thandle *th)
-{
-       LASSERT(d->dd_ops->dt_trans_stop);
-       return d->dd_ops->dt_trans_stop(env, th);
-}
-
-static inline int dt_trans_cb_add(struct thandle *th,
-                                 struct dt_txn_commit_cb *dcb)
-{
-       LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
-       dcb->dcb_magic = TRANS_COMMIT_CB_MAGIC;
-       return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
-}
-/** @} dt */
-
-
-static inline int dt_declare_record_write(const struct lu_env *env,
-                                         struct dt_object *dt,
-                                         int size, loff_t pos,
-                                         struct thandle *th)
-{
-       int rc;
-
-       LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
-       LASSERT(th != NULL);
-       LASSERT(dt->do_body_ops);
-       LASSERT(dt->do_body_ops->dbo_declare_write);
-       rc = dt->do_body_ops->dbo_declare_write(env, dt, size, pos, th);
-       return rc;
-}
-
-static inline int dt_declare_create(const struct lu_env *env,
-                                   struct dt_object *dt,
-                                   struct lu_attr *attr,
-                                   struct dt_allocation_hint *hint,
-                                   struct dt_object_format *dof,
-                                   struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_declare_create);
-       return dt->do_ops->do_declare_create(env, dt, attr, hint, dof, th);
-}
-
-static inline int dt_create(const struct lu_env *env,
-                                   struct dt_object *dt,
-                                   struct lu_attr *attr,
-                                   struct dt_allocation_hint *hint,
-                                   struct dt_object_format *dof,
-                                   struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_create);
-       return dt->do_ops->do_create(env, dt, attr, hint, dof, th);
-}
-
-static inline int dt_declare_destroy(const struct lu_env *env,
-                                    struct dt_object *dt,
-                                    struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_declare_destroy);
-       return dt->do_ops->do_declare_destroy(env, dt, th);
-}
-
-static inline int dt_destroy(const struct lu_env *env,
-                            struct dt_object *dt,
-                            struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_destroy);
-       return dt->do_ops->do_destroy(env, dt, th);
-}
-
-static inline void dt_read_lock(const struct lu_env *env,
-                               struct dt_object *dt,
-                               unsigned role)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_read_lock);
-       dt->do_ops->do_read_lock(env, dt, role);
-}
-
-static inline void dt_write_lock(const struct lu_env *env,
-                               struct dt_object *dt,
-                               unsigned role)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_write_lock);
-       dt->do_ops->do_write_lock(env, dt, role);
-}
-
-static inline void dt_read_unlock(const struct lu_env *env,
-                               struct dt_object *dt)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_read_unlock);
-       dt->do_ops->do_read_unlock(env, dt);
-}
-
-static inline void dt_write_unlock(const struct lu_env *env,
-                               struct dt_object *dt)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_write_unlock);
-       dt->do_ops->do_write_unlock(env, dt);
-}
-
-static inline int dt_write_locked(const struct lu_env *env,
-                                 struct dt_object *dt)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_write_locked);
-       return dt->do_ops->do_write_locked(env, dt);
-}
-
-static inline int dt_attr_get(const struct lu_env *env, struct dt_object *dt,
-                             struct lu_attr *la, void *arg)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_attr_get);
-       return dt->do_ops->do_attr_get(env, dt, la, arg);
-}
-
-static inline int dt_declare_attr_set(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     const struct lu_attr *la,
-                                     struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_declare_attr_set);
-       return dt->do_ops->do_declare_attr_set(env, dt, la, th);
-}
-
-static inline int dt_attr_set(const struct lu_env *env, struct dt_object *dt,
-                             const struct lu_attr *la, struct thandle *th,
-                             struct lustre_capa *capa)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_attr_set);
-       return dt->do_ops->do_attr_set(env, dt, la, th, capa);
-}
-
-static inline int dt_declare_ref_add(const struct lu_env *env,
-                                    struct dt_object *dt, struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_declare_ref_add);
-       return dt->do_ops->do_declare_ref_add(env, dt, th);
-}
-
-static inline int dt_ref_add(const struct lu_env *env,
-                            struct dt_object *dt, struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_ref_add);
-       return dt->do_ops->do_ref_add(env, dt, th);
-}
-
-static inline int dt_declare_ref_del(const struct lu_env *env,
-                                    struct dt_object *dt, struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_declare_ref_del);
-       return dt->do_ops->do_declare_ref_del(env, dt, th);
-}
-
-static inline int dt_ref_del(const struct lu_env *env,
-                            struct dt_object *dt, struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_ref_del);
-       return dt->do_ops->do_ref_del(env, dt, th);
-}
-
-static inline struct obd_capa *dt_capa_get(const struct lu_env *env,
-                                          struct dt_object *dt,
-                                          struct lustre_capa *old, __u64 opc)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_ref_del);
-       return dt->do_ops->do_capa_get(env, dt, old, opc);
-}
-
-static inline int dt_bufs_get(const struct lu_env *env, struct dt_object *d,
-                             struct niobuf_remote *rnb,
-                             struct niobuf_local *lnb, int rw,
-                             struct lustre_capa *capa)
-{
-       LASSERT(d);
-       LASSERT(d->do_body_ops);
-       LASSERT(d->do_body_ops->dbo_bufs_get);
-       return d->do_body_ops->dbo_bufs_get(env, d, rnb->offset,
-                                           rnb->len, lnb, rw, capa);
-}
-
-static inline int dt_bufs_put(const struct lu_env *env, struct dt_object *d,
-                             struct niobuf_local *lnb, int n)
-{
-       LASSERT(d);
-       LASSERT(d->do_body_ops);
-       LASSERT(d->do_body_ops->dbo_bufs_put);
-       return d->do_body_ops->dbo_bufs_put(env, d, lnb, n);
-}
-
-static inline int dt_write_prep(const struct lu_env *env, struct dt_object *d,
-                               struct niobuf_local *lnb, int n)
-{
-       LASSERT(d);
-       LASSERT(d->do_body_ops);
-       LASSERT(d->do_body_ops->dbo_write_prep);
-       return d->do_body_ops->dbo_write_prep(env, d, lnb, n);
-}
-
-static inline int dt_declare_write_commit(const struct lu_env *env,
-                                         struct dt_object *d,
-                                         struct niobuf_local *lnb,
-                                         int n, struct thandle *th)
-{
-       LASSERTF(d != NULL, "dt is NULL when we want to declare write\n");
-       LASSERT(th != NULL);
-       return d->do_body_ops->dbo_declare_write_commit(env, d, lnb, n, th);
-}
-
-
-static inline int dt_write_commit(const struct lu_env *env,
-                                 struct dt_object *d, struct niobuf_local *lnb,
-                                 int n, struct thandle *th)
-{
-       LASSERT(d);
-       LASSERT(d->do_body_ops);
-       LASSERT(d->do_body_ops->dbo_write_commit);
-       return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
-}
-
-static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
-                              struct niobuf_local *lnb, int n)
-{
-       LASSERT(d);
-       LASSERT(d->do_body_ops);
-       LASSERT(d->do_body_ops->dbo_read_prep);
-       return d->do_body_ops->dbo_read_prep(env, d, lnb, n);
-}
-
-static inline int dt_declare_punch(const struct lu_env *env,
-                                  struct dt_object *dt, __u64 start,
-                                  __u64 end, struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_body_ops);
-       LASSERT(dt->do_body_ops->dbo_declare_punch);
-       return dt->do_body_ops->dbo_declare_punch(env, dt, start, end, th);
-}
-
-static inline int dt_punch(const struct lu_env *env, struct dt_object *dt,
-                          __u64 start, __u64 end, struct thandle *th,
-                          struct lustre_capa *capa)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_body_ops);
-       LASSERT(dt->do_body_ops->dbo_punch);
-       return dt->do_body_ops->dbo_punch(env, dt, start, end, th, capa);
-}
-
-static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
-                               struct ll_user_fiemap *fm)
-{
-       LASSERT(d);
-       if (d->do_body_ops == NULL)
-               return -EPROTO;
-       if (d->do_body_ops->dbo_fiemap_get == NULL)
-               return -EOPNOTSUPP;
-       return d->do_body_ops->dbo_fiemap_get(env, d, fm);
-}
-
-static inline int dt_statfs(const struct lu_env *env, struct dt_device *dev,
-                           struct obd_statfs *osfs)
-{
-       LASSERT(dev);
-       LASSERT(dev->dd_ops);
-       LASSERT(dev->dd_ops->dt_statfs);
-       return dev->dd_ops->dt_statfs(env, dev, osfs);
-}
-
-static inline int dt_root_get(const struct lu_env *env, struct dt_device *dev,
-                             struct lu_fid *f)
-{
-       LASSERT(dev);
-       LASSERT(dev->dd_ops);
-       LASSERT(dev->dd_ops->dt_root_get);
-       return dev->dd_ops->dt_root_get(env, dev, f);
-}
-
-static inline void dt_conf_get(const struct lu_env *env,
-                              const struct dt_device *dev,
-                              struct dt_device_param *param)
-{
-       LASSERT(dev);
-       LASSERT(dev->dd_ops);
-       LASSERT(dev->dd_ops->dt_conf_get);
-       return dev->dd_ops->dt_conf_get(env, dev, param);
-}
-
-static inline int dt_sync(const struct lu_env *env, struct dt_device *dev)
-{
-       LASSERT(dev);
-       LASSERT(dev->dd_ops);
-       LASSERT(dev->dd_ops->dt_sync);
-       return dev->dd_ops->dt_sync(env, dev);
-}
-
-static inline int dt_ro(const struct lu_env *env, struct dt_device *dev)
-{
-       LASSERT(dev);
-       LASSERT(dev->dd_ops);
-       LASSERT(dev->dd_ops->dt_ro);
-       return dev->dd_ops->dt_ro(env, dev);
-}
-
-static inline int dt_declare_insert(const struct lu_env *env,
-                                   struct dt_object *dt,
-                                   const struct dt_rec *rec,
-                                   const struct dt_key *key,
-                                   struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_index_ops);
-       LASSERT(dt->do_index_ops->dio_declare_insert);
-       return dt->do_index_ops->dio_declare_insert(env, dt, rec, key, th);
-}
-
-static inline int dt_insert(const struct lu_env *env,
-                                   struct dt_object *dt,
-                                   const struct dt_rec *rec,
-                                   const struct dt_key *key,
-                                   struct thandle *th,
-                                   struct lustre_capa *capa,
-                                   int noquota)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_index_ops);
-       LASSERT(dt->do_index_ops->dio_insert);
-       return dt->do_index_ops->dio_insert(env, dt, rec, key, th,
-                                           capa, noquota);
-}
-
-static inline int dt_declare_xattr_del(const struct lu_env *env,
-                                      struct dt_object *dt,
-                                      const char *name,
-                                      struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_declare_xattr_del);
-       return dt->do_ops->do_declare_xattr_del(env, dt, name, th);
-}
-
-static inline int dt_xattr_del(const struct lu_env *env,
-                              struct dt_object *dt, const char *name,
-                              struct thandle *th,
-                              struct lustre_capa *capa)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_xattr_del);
-       return dt->do_ops->do_xattr_del(env, dt, name, th, capa);
-}
-
-static inline int dt_declare_xattr_set(const struct lu_env *env,
-                                     struct dt_object *dt,
-                                     const struct lu_buf *buf,
-                                     const char *name, int fl,
-                                     struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_declare_xattr_set);
-       return dt->do_ops->do_declare_xattr_set(env, dt, buf, name, fl, th);
-}
-
-static inline int dt_xattr_set(const struct lu_env *env,
-                             struct dt_object *dt, const struct lu_buf *buf,
-                             const char *name, int fl, struct thandle *th,
-                             struct lustre_capa *capa)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_xattr_set);
-       return dt->do_ops->do_xattr_set(env, dt, buf, name, fl, th, capa);
-}
-
-static inline int dt_xattr_get(const struct lu_env *env,
-                             struct dt_object *dt, struct lu_buf *buf,
-                             const char *name, struct lustre_capa *capa)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_xattr_get);
-       return dt->do_ops->do_xattr_get(env, dt, buf, name, capa);
-}
-
-static inline int dt_xattr_list(const struct lu_env *env,
-                              struct dt_object *dt, struct lu_buf *buf,
-                              struct lustre_capa *capa)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_ops);
-       LASSERT(dt->do_ops->do_xattr_list);
-       return dt->do_ops->do_xattr_list(env, dt, buf, capa);
-}
-
-static inline int dt_declare_delete(const struct lu_env *env,
-                                   struct dt_object *dt,
-                                   const struct dt_key *key,
-                                   struct thandle *th)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_index_ops);
-       LASSERT(dt->do_index_ops->dio_declare_delete);
-       return dt->do_index_ops->dio_declare_delete(env, dt, key, th);
-}
-
-static inline int dt_delete(const struct lu_env *env,
-                           struct dt_object *dt,
-                           const struct dt_key *key,
-                           struct thandle *th,
-                           struct lustre_capa *capa)
-{
-       LASSERT(dt);
-       LASSERT(dt->do_index_ops);
-       LASSERT(dt->do_index_ops->dio_delete);
-       return dt->do_index_ops->dio_delete(env, dt, key, th, capa);
-}
-
-static inline int dt_commit_async(const struct lu_env *env,
-                                 struct dt_device *dev)
-{
-       LASSERT(dev);
-       LASSERT(dev->dd_ops);
-       LASSERT(dev->dd_ops->dt_commit_async);
-       return dev->dd_ops->dt_commit_async(env, dev);
-}
-
-static inline int dt_init_capa_ctxt(const struct lu_env *env,
-                                   struct dt_device *dev,
-                                   int mode, unsigned long timeout,
-                                   __u32 alg, struct lustre_capa_key *keys)
-{
-       LASSERT(dev);
-       LASSERT(dev->dd_ops);
-       LASSERT(dev->dd_ops->dt_init_capa_ctxt);
-       return dev->dd_ops->dt_init_capa_ctxt(env, dev, mode,
-                                             timeout, alg, keys);
-}
-
-static inline int dt_lookup(const struct lu_env *env,
-                           struct dt_object *dt,
-                           struct dt_rec *rec,
-                           const struct dt_key *key,
-                           struct lustre_capa *capa)
-{
-       int ret;
-
-       LASSERT(dt);
-       LASSERT(dt->do_index_ops);
-       LASSERT(dt->do_index_ops->dio_lookup);
-
-       ret = dt->do_index_ops->dio_lookup(env, dt, rec, key, capa);
-       if (ret > 0)
-               ret = 0;
-       else if (ret == 0)
-               ret = -ENOENT;
-       return ret;
-}
-
-#define LU221_BAD_TIME (0x80000000U + 24 * 3600)
-
-struct dt_find_hint {
-       struct lu_fid   *dfh_fid;
-       struct dt_device     *dfh_dt;
-       struct dt_object     *dfh_o;
-};
-
-struct dt_thread_info {
-       char                 dti_buf[DT_MAX_PATH];
-       struct dt_find_hint      dti_dfh;
-       struct lu_attr     dti_attr;
-       struct lu_fid       dti_fid;
-       struct dt_object_format  dti_dof;
-       struct lustre_mdt_attrs  dti_lma;
-       struct lu_buf       dti_lb;
-       loff_t             dti_off;
-};
-
-extern struct lu_context_key dt_key;
-
-static inline struct dt_thread_info *dt_info(const struct lu_env *env)
-{
-       struct dt_thread_info *dti;
-
-       dti = lu_context_key_get(&env->le_ctx, &dt_key);
-       LASSERT(dti);
-       return dti;
-}
-
-int dt_global_init(void);
-void dt_global_fini(void);
-
-int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
-                         int count, int *eof, void *data);
-int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
-                             int count, int *eof, void *data);
-int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
-                            int count, int *eof, void *data);
-int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
-                             int count, int *eof, void *data);
-int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
-                            int count, int *eof, void *data);
-int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
-                           int count, int *eof, void *data);
-
-#endif /* __LUSTRE_DT_OBJECT_H */
index bf9027d5f7733d03c36d99061221c56889d89824..f6df3f33e770d29e16575febcfbc6e2c2b2ae479 100644 (file)
@@ -67,11 +67,6 @@ static inline int interval_is_intree(struct interval_node *node)
        return node->in_intree == 1;
 }
 
-static inline __u64 interval_low(struct interval_node *node)
-{
-       return node->in_extent.start;
-}
-
 static inline __u64 interval_high(struct interval_node *node)
 {
        return node->in_extent.end;
@@ -86,39 +81,8 @@ static inline void interval_set(struct interval_node *node,
        node->in_max_high = end;
 }
 
-/* Rules to write an interval callback.
- *  - the callback returns INTERVAL_ITER_STOP when it thinks the iteration
- *    should be stopped. It will then cause the iteration function to return
- *    immediately with return value INTERVAL_ITER_STOP.
- *  - callbacks for interval_iterate and interval_iterate_reverse: Every
- *    nodes in the tree will be set to @node before the callback being called
- *  - callback for interval_search: Only overlapped node will be set to @node
- *    before the callback being called.
- */
-typedef enum interval_iter (*interval_callback_t)(struct interval_node *node,
-                                                 void *args);
-
 struct interval_node *interval_insert(struct interval_node *node,
                                      struct interval_node **root);
 void interval_erase(struct interval_node *node, struct interval_node **root);
 
-/* Search the extents in the tree and call @func for each overlapped
- * extents. */
-enum interval_iter interval_search(struct interval_node *root,
-                                  struct interval_node_extent *ex,
-                                  interval_callback_t func, void *data);
-
-/* Iterate every node in the tree - by reverse order or regular order. */
-enum interval_iter interval_iterate(struct interval_node *root,
-                                   interval_callback_t func, void *data);
-enum interval_iter interval_iterate_reverse(struct interval_node *root,
-                                   interval_callback_t func, void *data);
-
-void interval_expand(struct interval_node *root,
-                    struct interval_node_extent *ext,
-                    struct interval_node_extent *limiter);
-int interval_is_overlapped(struct interval_node *root,
-                          struct interval_node_extent *ex);
-struct interval_node *interval_find(struct interval_node *root,
-                                   struct interval_node_extent *ex);
 #endif
index c5c3a8d9eaa4026675d30abebfdfb15382513060..36e7a6767e711da00ab9d05c41f9bd4d483be14d 100644 (file)
@@ -71,7 +71,6 @@ enum ccc_setattr_lock_type {
        SETATTR_MATCH_LOCK
 };
 
-
 /**
  * IO state private to vvp or slp layers.
  */
@@ -233,8 +232,6 @@ static inline struct ccc_page *cl2ccc_page(const struct cl_page_slice *slice)
        return container_of(slice, struct ccc_page, cpg_cl);
 }
 
-struct cl_page    *ccc_vmpage_page_transient(struct page *vmpage);
-
 struct ccc_device {
        struct cl_device    cdv_cl;
        struct super_block *cdv_sb;
@@ -289,33 +286,13 @@ void ccc_object_free(const struct lu_env *env, struct lu_object *obj);
 int ccc_lock_init(const struct lu_env *env, struct cl_object *obj,
                  struct cl_lock *lock, const struct cl_io *io,
                  const struct cl_lock_operations *lkops);
-int ccc_attr_set(const struct lu_env *env, struct cl_object *obj,
-                const struct cl_attr *attr, unsigned valid);
 int ccc_object_glimpse(const struct lu_env *env,
                       const struct cl_object *obj, struct ost_lvb *lvb);
-int ccc_conf_set(const struct lu_env *env, struct cl_object *obj,
-                const struct cl_object_conf *conf);
 struct page *ccc_page_vmpage(const struct lu_env *env,
                            const struct cl_page_slice *slice);
 int ccc_page_is_under_lock(const struct lu_env *env,
                           const struct cl_page_slice *slice, struct cl_io *io);
 int ccc_fail(const struct lu_env *env, const struct cl_page_slice *slice);
-void ccc_transient_page_verify(const struct cl_page *page);
-int  ccc_transient_page_own(const struct lu_env *env,
-                           const struct cl_page_slice *slice,
-                           struct cl_io *io, int nonblock);
-void ccc_transient_page_assume(const struct lu_env *env,
-                              const struct cl_page_slice *slice,
-                              struct cl_io *io);
-void ccc_transient_page_unassume(const struct lu_env *env,
-                                const struct cl_page_slice *slice,
-                                struct cl_io *io);
-void ccc_transient_page_disown(const struct lu_env *env,
-                              const struct cl_page_slice *slice,
-                              struct cl_io *io);
-void ccc_transient_page_discard(const struct lu_env *env,
-                               const struct cl_page_slice *slice,
-                               struct cl_io *io);
 int ccc_transient_page_prep(const struct lu_env *env,
                            const struct cl_page_slice *slice,
                            struct cl_io *io);
@@ -336,7 +313,6 @@ void ccc_lock_state(const struct lu_env *env,
                    const struct cl_lock_slice *slice,
                    enum cl_lock_state state);
 
-void ccc_io_fini(const struct lu_env *env, const struct cl_io_slice *ios);
 int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
                          __u32 enqflags, enum cl_lock_mode mode,
                          pgoff_t start, pgoff_t end);
@@ -371,10 +347,8 @@ struct page         *cl2vm_page      (const struct cl_page_slice *slice);
 struct inode       *ccc_object_inode(const struct cl_object *obj);
 struct ccc_object  *cl_inode2ccc    (struct inode *inode);
 
-int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
-                  struct obd_capa *capa);
+int cl_setattr_ost(struct inode *inode, const struct iattr *attr);
 
-struct cl_page *ccc_vmpage_page_transient(struct page *vmpage);
 int ccc_object_invariant(const struct cl_object *obj);
 int cl_file_inode_init(struct inode *inode, struct lustre_md *md);
 void cl_inode_fini(struct inode *inode);
index 6b14406b2920daa640b68f6b80f01cba0fa68aa8..79d8f93075d12d54143509fb538765b5194e94e3 100644 (file)
@@ -61,7 +61,6 @@
 #define module_init(a)     late_initcall(a)
 #endif
 
-
 #define LTIME_S(time)             (time.tv_sec)
 
 #ifndef QUOTA_OK
index 45651caf42ccf6b8df084bbd0e8985308d76f389..3420cfd1278d740c1bf28261cc52ec68785d1b0f 100644 (file)
@@ -39,8 +39,7 @@
 #error Do not #include this file directly. #include <lustre_lite.h> instead
 #endif
 
-
-#include <asm/statfs.h>
+#include <linux/statfs.h>
 
 #include <linux/fs.h>
 #include <linux/dcache.h>
@@ -93,5 +92,4 @@ enum {
         LPROC_LL_FILE_OPCODES
 };
 
-
 #endif
index ebe8d68ed813f854126c3b21407ff3c7c187a37b..33e0b99e1fb4712db6b9797dc3d0f295eb0f7343 100644 (file)
@@ -43,7 +43,6 @@
 #include <linux/mm.h>
 #include <linux/hash.h>
 
-
 #define ll_delete_from_page_cache(page) delete_from_page_cache(page)
 
 static inline void
index 2817e88e014a45826a9dc421f8ea67083604c4cd..468bc28be895aaba7077a5ce89da72a20f66a980 100644 (file)
@@ -70,6 +70,7 @@ static inline void __client_obd_list_lock(client_obd_lock_t *lock,
                                          const char *func, int line)
 {
        unsigned long cur = jiffies;
+
        while (1) {
                if (spin_trylock(&lock->lock)) {
                        LASSERT(lock->task == NULL);
@@ -113,7 +114,6 @@ static inline void client_obd_list_unlock(client_obd_lock_t *lock)
        spin_unlock(&lock->lock);
 }
 
-
 static inline void client_obd_list_lock_init(client_obd_lock_t *lock)
 {
        spin_lock_init(&lock->lock);
index fd3c4df319c205c221a67aba32a6df7b98b1c08c..9e654b218ca358824857226d985e76b35c89421e 100644 (file)
@@ -158,6 +158,7 @@ struct lprocfs_counter {
         */
        __s64   lc_array_sum[1];
 };
+
 #define lc_sum         lc_array_sum[0]
 #define lc_sum_irq     lc_array_sum[1]
 
@@ -206,7 +207,8 @@ struct lprocfs_stats {
 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
 
 /* Pack all opcodes down into a single monotonically increasing index */
-static inline int opcode_offset(__u32 opc) {
+static inline int opcode_offset(__u32 opc)
+{
        if (opc < OST_LAST_OPC) {
                 /* OST opcode */
                return (opc - OST_FIRST_OPC);
@@ -301,7 +303,6 @@ static inline int opcode_offset(__u32 opc) {
        }
 }
 
-
 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
                            OPC_RANGE(MDS)  + \
                            OPC_RANGE(LDLM) + \
@@ -358,15 +359,18 @@ struct obd_histogram;
 struct dhms {
        int d, h, m, s;
 };
-static inline void s2dhms(struct dhms *ts, time_t secs)
+
+static inline void s2dhms(struct dhms *ts, time64_t secs64)
 {
-       ts->d = secs / 86400;
-       secs = secs % 86400;
+       unsigned int secs;
+
+       ts->d = div_u64_rem(secs64, 86400, &secs);
        ts->h = secs / 3600;
        secs = secs % 3600;
        ts->m = secs / 60;
        ts->s = secs % 60;
 }
+
 #define DHMS_FMT "%dd%dh%02dm%02ds"
 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
 
@@ -536,26 +540,14 @@ extern struct lprocfs_stats *
 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
 void lprocfs_clear_stats(struct lprocfs_stats *stats);
 void lprocfs_free_stats(struct lprocfs_stats **stats);
-void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats);
-void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats);
-void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
-int lprocfs_alloc_obd_stats(struct obd_device *obddev,
-                           unsigned int num_private_stats);
-int lprocfs_alloc_md_stats(struct obd_device *obddev,
-                          unsigned int num_private_stats);
 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
                          unsigned conf, const char *name, const char *units);
-void lprocfs_free_obd_stats(struct obd_device *obddev);
-void lprocfs_free_md_stats(struct obd_device *obddev);
 struct obd_export;
 int lprocfs_exp_cleanup(struct obd_export *exp);
 struct dentry *ldebugfs_add_simple(struct dentry *root,
                                   char *name,
                                   void *data,
                                   struct file_operations *fops);
-struct dentry *
-ldebugfs_add_symlink(const char *name, struct dentry *parent,
-                    const char *format, ...);
 
 int ldebugfs_register_stats(struct dentry *parent,
                            const char *name,
@@ -590,14 +582,9 @@ int ldebugfs_obd_seq_create(struct obd_device *dev,
 
 /* Generic callbacks */
 
-int lprocfs_rd_u64(struct seq_file *m, void *data);
-int lprocfs_rd_atomic(struct seq_file *m, void *data);
-int lprocfs_wr_atomic(struct file *file, const char __user *buffer,
-                     unsigned long count, void *data);
 int lprocfs_rd_uint(struct seq_file *m, void *data);
 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
                    unsigned long count, void *data);
-int lprocfs_rd_name(struct seq_file *m, void *data);
 int lprocfs_rd_server_uuid(struct seq_file *m, void *data);
 int lprocfs_rd_conn_uuid(struct seq_file *m, void *data);
 int lprocfs_rd_import(struct seq_file *m, void *data);
@@ -607,10 +594,6 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data);
 struct adaptive_timeout;
 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at);
 int lprocfs_rd_timeouts(struct seq_file *m, void *data);
-int lprocfs_wr_timeouts(struct file *file, const char __user *buffer,
-                       unsigned long count, void *data);
-int lprocfs_wr_evict_client(struct file *file, const char __user *buffer,
-                           size_t count, loff_t *off);
 int lprocfs_wr_ping(struct file *file, const char __user *buffer,
                    size_t count, loff_t *off);
 int lprocfs_wr_import(struct file *file, const char __user *buffer,
@@ -623,7 +606,6 @@ int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
 
 int lprocfs_write_helper(const char __user *buffer, unsigned long count,
                         int *val);
-int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
 int lprocfs_write_u64_helper(const char __user *buffer,
                             unsigned long count, __u64 *val);
 int lprocfs_write_frac_u64_helper(const char *buffer,
@@ -642,20 +624,9 @@ void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
 int lprocfs_single_release(struct inode *, struct file *);
 int lprocfs_seq_release(struct inode *, struct file *);
 
-/* You must use these macros when you want to refer to
- * the import in a client obd_device for a lprocfs entry */
-#define LPROCFS_CLIMP_CHECK(obd) do {     \
-       typecheck(struct obd_device *, obd);    \
-       down_read(&(obd)->u.cli.cl_sem);    \
-       if ((obd)->u.cli.cl_import == NULL) {   \
-            up_read(&(obd)->u.cli.cl_sem); \
-            return -ENODEV;                \
-       }                                      \
-} while (0)
 #define LPROCFS_CLIMP_EXIT(obd)                 \
        up_read(&(obd)->u.cli.cl_sem)
 
-
 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
   proc entries; otherwise, you will define name##_seq_write function also for
   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
@@ -730,22 +701,8 @@ static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
 
-ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
-                        char *buf);
-ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
-                         const char *buf, size_t len);
-
 extern const struct sysfs_ops lustre_sysfs_ops;
 
-/* lproc_ptlrpc.c */
-struct ptlrpc_request;
-void target_print_req(void *seq_file, struct ptlrpc_request *req);
-
-/* lproc_status.c */
-int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file *m, void *data);
-int lprocfs_obd_wr_max_pages_per_rpc(struct file *file, const char *buffer,
-                                    size_t count, loff_t *off);
-
 /* all quota proc functions */
 int lprocfs_quota_rd_bunit(char *page, char **start,
                           loff_t off, int count,
index e1d72a7a5c2dd5bb22eeced75759db6aaf904272..fa78689748a9edc5e73befc001b81ff180f3219b 100644 (file)
@@ -554,9 +554,9 @@ struct fld;
 
 struct lu_site_bkt_data {
        /**
-        * number of busy object on this bucket
+        * number of object in this bucket on the lsb_lru list.
         */
-       long                  lsb_busy;
+       long                    lsb_lru_len;
        /**
         * LRU list, updated on each access to object. Protected by
         * bucket lock of lu_site::ls_obj_hash.
@@ -584,6 +584,7 @@ enum {
        LU_SS_CACHE_RACE,
        LU_SS_CACHE_DEATH_RACE,
        LU_SS_LRU_PURGED,
+       LU_SS_LRU_LEN,  /* # of objects in lsb_lru lists */
        LU_SS_LAST_STAT
 };
 
@@ -670,9 +671,6 @@ void lu_object_fini       (struct lu_object *o);
 void lu_object_add_top    (struct lu_object_header *h, struct lu_object *o);
 void lu_object_add     (struct lu_object *before, struct lu_object *o);
 
-void lu_dev_add_linkage(struct lu_site *s, struct lu_device *d);
-void lu_dev_del_linkage(struct lu_site *s, struct lu_device *d);
-
 /**
  * Helpers to initialize and finalize device types.
  */
@@ -709,16 +707,12 @@ static inline int lu_object_is_dying(const struct lu_object_header *h)
 }
 
 void lu_object_put(const struct lu_env *env, struct lu_object *o);
-void lu_object_put_nocache(const struct lu_env *env, struct lu_object *o);
 void lu_object_unhash(const struct lu_env *env, struct lu_object *o);
 
 int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr);
 
 void lu_site_print(const struct lu_env *env, struct lu_site *s, void *cookie,
                   lu_printer_t printer);
-struct lu_object *lu_object_find(const struct lu_env *env,
-                                struct lu_device *dev, const struct lu_fid *f,
-                                const struct lu_object_conf *conf);
 struct lu_object *lu_object_find_at(const struct lu_env *env,
                                    struct lu_device *dev,
                                    const struct lu_fid *f,
@@ -790,7 +784,7 @@ do {                                                                      \
                                                                          \
        if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) {                \
                lu_object_print(env, &msgdata, lu_cdebug_printer, object);\
-               CDEBUG(mask, format , ## __VA_ARGS__);              \
+               CDEBUG(mask, format, ## __VA_ARGS__);               \
        }                                                                \
 } while (0)
 
@@ -805,7 +799,7 @@ do {                                                                    \
                lu_object_header_print(env, &msgdata, lu_cdebug_printer,\
                                       (object)->lo_header);        \
                lu_cdebug_printer(env, &msgdata, "\n");          \
-               CDEBUG(mask, format , ## __VA_ARGS__);            \
+               CDEBUG(mask, format, ## __VA_ARGS__);             \
        }                                                              \
 } while (0)
 
@@ -820,7 +814,6 @@ void lu_object_header_print(const struct lu_env *env, void *cookie,
  */
 int lu_object_invariant(const struct lu_object *o);
 
-
 /**
  * Check whether object exists, no matter on local or remote storage.
  * Note: LOHA_EXISTS will be set once some one created the object,
@@ -1125,13 +1118,13 @@ struct lu_context_key {
                                                                  \
                CLASSERT(PAGE_CACHE_SIZE >= sizeof (*value));       \
                                                                  \
-               OBD_ALLOC_PTR(value);                        \
+               value = kzalloc(sizeof(*value), GFP_NOFS);      \
                if (value == NULL)                              \
                        value = ERR_PTR(-ENOMEM);                \
                                                                  \
                return value;                                \
        }                                                        \
-       struct __##mod##__dummy_init {;} /* semicolon catcher */
+       struct __##mod##__dummy_init {; } /* semicolon catcher */
 
 #define LU_KEY_FINI(mod, type)                                       \
        static void mod##_key_fini(const struct lu_context *ctx,            \
@@ -1139,9 +1132,9 @@ struct lu_context_key {
        {                                                                  \
                type *info = data;                                        \
                                                                            \
-               OBD_FREE_PTR(info);                                      \
+               kfree(info);                                     \
        }                                                                  \
-       struct __##mod##__dummy_fini {;} /* semicolon catcher */
+       struct __##mod##__dummy_fini {; } /* semicolon catcher */
 
 #define LU_KEY_INIT_FINI(mod, type)   \
        LU_KEY_INIT(mod, type); \
@@ -1166,7 +1159,6 @@ void *lu_context_key_get     (const struct lu_context *ctx,
 void  lu_context_key_quiesce (struct lu_context_key *key);
 void  lu_context_key_revive  (struct lu_context_key *key);
 
-
 /*
  * LU_KEY_INIT_GENERIC() has to be a macro to correctly determine an
  * owning module.
@@ -1193,30 +1185,28 @@ void  lu_context_key_revive  (struct lu_context_key *key);
                mod##_key_init_generic(__VA_ARGS__, NULL);            \
                return lu_context_key_register_many(__VA_ARGS__, NULL); \
        }                                                              \
-       struct __##mod##_dummy_type_init {;}
+       struct __##mod##_dummy_type_init {; }
 
 #define LU_TYPE_FINI(mod, ...)                                   \
        static void mod##_type_fini(struct lu_device_type *t)      \
        {                                                              \
                lu_context_key_degister_many(__VA_ARGS__, NULL);        \
        }                                                              \
-       struct __##mod##_dummy_type_fini {;}
+       struct __##mod##_dummy_type_fini {; }
 
 #define LU_TYPE_START(mod, ...)                                 \
        static void mod##_type_start(struct lu_device_type *t)  \
        {                                                      \
                lu_context_key_revive_many(__VA_ARGS__, NULL);  \
        }                                                      \
-       struct __##mod##_dummy_type_start {;}
+       struct __##mod##_dummy_type_start {; }
 
 #define LU_TYPE_STOP(mod, ...)                           \
        static void mod##_type_stop(struct lu_device_type *t)   \
        {                                                      \
                lu_context_key_quiesce_many(__VA_ARGS__, NULL); \
        }                                                      \
-       struct __##mod##_dummy_type_stop {;}
-
-
+       struct __##mod##_dummy_type_stop {; }
 
 #define LU_TYPE_INIT_FINI(mod, ...)         \
        LU_TYPE_INIT(mod, __VA_ARGS__);  \
@@ -1240,14 +1230,6 @@ void lu_context_key_degister_many(struct lu_context_key *k, ...);
 void lu_context_key_revive_many  (struct lu_context_key *k, ...);
 void lu_context_key_quiesce_many (struct lu_context_key *k, ...);
 
-/*
- * update/clear ctx/ses tags.
- */
-void lu_context_tags_update(__u32 tags);
-void lu_context_tags_clear(__u32 tags);
-void lu_session_tags_update(__u32 tags);
-void lu_session_tags_clear(__u32 tags);
-
 /**
  * Environment.
  */
@@ -1265,7 +1247,6 @@ struct lu_env {
 int  lu_env_init  (struct lu_env *env, __u32 tags);
 void lu_env_fini  (struct lu_env *env);
 int  lu_env_refill(struct lu_env *env);
-int  lu_env_refill_by_tags(struct lu_env *env, __u32 ctags, __u32 stags);
 
 /** @} lu_context */
 
@@ -1318,21 +1299,5 @@ struct lu_kmem_descr {
 int  lu_kmem_init(struct lu_kmem_descr *caches);
 void lu_kmem_fini(struct lu_kmem_descr *caches);
 
-void lu_object_assign_fid(const struct lu_env *env, struct lu_object *o,
-                         const struct lu_fid *fid);
-struct lu_object *lu_object_anon(const struct lu_env *env,
-                                struct lu_device *dev,
-                                const struct lu_object_conf *conf);
-
-/** null buffer */
-extern struct lu_buf LU_BUF_NULL;
-
-void lu_buf_free(struct lu_buf *buf);
-void lu_buf_alloc(struct lu_buf *buf, int size);
-void lu_buf_realloc(struct lu_buf *buf, int size);
-
-int lu_buf_check_and_grow(struct lu_buf *buf, int len);
-struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, int len);
-
 /** @} lu */
 #endif /* __LUSTRE_LU_OBJECT_H */
index b451a888ca3a54c68d8c4ba60bf837a5435d1745..97cd157dd35a9b0117c1612108bd46262f2f44c4 100644 (file)
  * @{
  */
 
-
 /*
  * dummy data structures/functions to pass compile for now.
  * We need to reimplement them with kref.
diff --git a/drivers/staging/lustre/lustre/include/lustre/libiam.h b/drivers/staging/lustre/lustre/include/lustre/libiam.h
deleted file mode 100644 (file)
index e8e0b08..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/include/lustre/libiam.h
- *
- * iam user level library
- *
- * Author: Wang Di <wangdi@clusterfs.com>
- * Author: Nikita Danilov <nikita@clusterfs.com>
- * Author: Fan Yong <fanyong@clusterfs.com>
- */
-
-/*
- *  lustre/libiam.h
- */
-
-#ifndef __IAM_ULIB_H__
-#define __IAM_ULIB_H__
-
-/** \defgroup libiam libiam
- *
- * @{
- */
-
-
-#define DX_FMT_NAME_LEN 16
-
-enum iam_fmt_t {
-       FMT_LFIX,
-       FMT_LVAR
-};
-
-struct iam_uapi_info {
-       __u16 iui_keysize;
-       __u16 iui_recsize;
-       __u16 iui_ptrsize;
-       __u16 iui_height;
-       char  iui_fmt_name[DX_FMT_NAME_LEN];
-};
-
-/*
- * Creat an iam file, but do NOT open it.
- * Return 0 if success, else -1.
- */
-int iam_creat(char *filename, enum iam_fmt_t fmt,
-             int blocksize, int keysize, int recsize, int ptrsize);
-
-/*
- * Open an iam file, but do NOT creat it if the file doesn't exist.
- * Please use iam_creat for creating the file before use iam_open.
- * Return file id (fd) if success, else -1.
- */
-int iam_open(char *filename, struct iam_uapi_info *ua);
-
-/*
- * Close file opened by iam_open.
- */
-int iam_close(int fd);
-
-/*
- * Please use iam_open before use this function.
- */
-int iam_insert(int fd, struct iam_uapi_info *ua,
-              int key_need_convert, char *keybuf,
-              int rec_need_convert, char *recbuf);
-
-/*
- * Please use iam_open before use this function.
- */
-int iam_lookup(int fd, struct iam_uapi_info *ua,
-              int key_need_convert, char *key_buf,
-              int *keysize, char *save_key,
-              int rec_need_convert, char *rec_buf,
-              int *recsize, char *save_rec);
-
-/*
- * Please use iam_open before use this function.
- */
-int iam_delete(int fd, struct iam_uapi_info *ua,
-              int key_need_convert, char *keybuf,
-              int rec_need_convert, char *recbuf);
-
-/*
- * Please use iam_open before use this function.
- */
-int iam_it_start(int fd, struct iam_uapi_info *ua,
-                int key_need_convert, char *key_buf,
-                int *keysize, char *save_key,
-                int rec_need_convert, char *rec_buf,
-                int *recsize, char *save_rec);
-
-/*
- * Please use iam_open before use this function.
- */
-int iam_it_next(int fd, struct iam_uapi_info *ua,
-               int key_need_convert, char *key_buf,
-               int *keysize, char *save_key,
-               int rec_need_convert, char *rec_buf,
-               int *recsize, char *save_rec);
-
-/*
- * Please use iam_open before use this function.
- */
-int iam_it_stop(int fd, struct iam_uapi_info *ua,
-               int key_need_convert, char *keybuf,
-               int rec_need_convert, char *recbuf);
-
-/*
- * Change iam file mode.
- */
-int iam_polymorph(char *filename, unsigned long mode);
-
-/** @} libiam */
-
-#endif
index ad253c6deadd5a2a1b3e91b3b55b230f87011593..06ce8c9ae9ad45cfd2ee98a990ca9fd5ee61257f 100644 (file)
@@ -43,8 +43,6 @@
 #ifndef _LUSTRE_FIEMAP_H
 #define _LUSTRE_FIEMAP_H
 
-
-
 struct ll_fiemap_extent {
        __u64 fe_logical;  /* logical offset in bytes for the start of
                            * the extent from the beginning of the file */
@@ -94,7 +92,6 @@ struct ll_user_fiemap {
                                                    * support extents. Result
                                                    * merged for efficiency. */
 
-
 static inline size_t fiemap_count_to_size(size_t extent_count)
 {
        return (sizeof(struct ll_user_fiemap) + extent_count *
index ac78dbc38b9f3485a3bc32cad305748592c7b21d..0b721c65c2a3eb4bca4faef0b2fcd9620c51af52 100644 (file)
 #define PTL_RPC_MSG_REPLY   4713
 
 /* DON'T use swabbed values of MAGIC as magic! */
-#define LUSTRE_MSG_MAGIC_V1 0x0BD00BD0
 #define LUSTRE_MSG_MAGIC_V2 0x0BD00BD3
-
-#define LUSTRE_MSG_MAGIC_V1_SWABBED 0xD00BD00B
 #define LUSTRE_MSG_MAGIC_V2_SWABBED 0xD30BD00B
 
 #define LUSTRE_MSG_MAGIC LUSTRE_MSG_MAGIC_V2
@@ -297,7 +294,6 @@ static inline int range_compare_loc(const struct lu_seq_range *r1,
        (range)->lsr_index,     \
        fld_range_is_mdt(range) ? "mdt" : "ost"
 
-
 /** \defgroup lu_fid lu_fid
  * @{ */
 
@@ -325,6 +321,7 @@ enum lma_incompat {
        LMAI_REMOTE_PARENT      = 0x00000004, /* the parent of the object
                                                 is on the remote MDT */
 };
+
 #define LMA_INCOMPAT_SUPP      (LMAI_AGENT | LMAI_REMOTE_PARENT)
 
 /**
@@ -365,6 +362,13 @@ static inline __u64 fid_ver_oid(const struct lu_fid *fid)
        return ((__u64)fid_ver(fid) << 32 | fid_oid(fid));
 }
 
+/* copytool uses a 32b bitmask field to encode archive-Ids during register
+ * with MDT thru kuc.
+ * archive num = 0 => all
+ * archive num from 1 to 32
+ */
+#define LL_HSM_MAX_ARCHIVE (sizeof(__u32) * 8)
+
 /**
  * Note that reserved SEQ numbers below 12 will conflict with ldiskfs
  * inodes in the IGIF namespace, so these reserved SEQ numbers can be
@@ -827,7 +831,7 @@ static inline int lu_fid_eq(const struct lu_fid *f0, const struct lu_fid *f1)
        typeof(val0) __val0 = (val0);                      \
        typeof(val1) __val1 = (val1);                      \
                                                                \
-       (__val0 == __val1 ? 0 : __val0 > __val1 ? +1 : -1);     \
+       (__val0 == __val1 ? 0 : __val0 > __val1 ? 1 : -1);     \
 })
 
 static inline int lu_fid_cmp(const struct lu_fid *f0,
@@ -956,7 +960,6 @@ struct luda_type {
 #define DTTOIF(dirtype)                ((dirtype) << IFSHIFT)
 #endif
 
-
 struct lu_dirpage {
        __u64       ldp_hash_start;
        __u64       ldp_hash_end;
@@ -1002,6 +1005,7 @@ static inline int lu_dirent_calc_size(int namelen, __u16 attr)
 
        if (attr & LUDA_TYPE) {
                const unsigned align = sizeof(struct luda_type) - 1;
+
                size = (sizeof(struct lu_dirent) + namelen + align) & ~align;
                size += sizeof(struct luda_type);
        } else
@@ -1041,6 +1045,7 @@ static inline int lu_dirent_size(struct lu_dirent *ent)
 struct lustre_handle {
        __u64 cookie;
 };
+
 #define DEAD_HANDLE_MAGIC 0xdeadbeefcafebabeULL
 
 static inline int lustre_handle_is_used(struct lustre_handle *lh)
@@ -1105,6 +1110,7 @@ struct ptlrpc_body_v3 {
        __u64 pb_padding[4];
        char  pb_jobid[JOBSTATS_JOBID_SIZE];
 };
+
 #define ptlrpc_body     ptlrpc_body_v3
 
 struct ptlrpc_body_v2 {
@@ -1269,7 +1275,6 @@ void lustre_swab_ptlrpc_body(struct ptlrpc_body *pb);
 #define OCD_HAS_FLAG(ocd, flg)  \
        (!!((ocd)->ocd_connect_flags & OBD_CONNECT_##flg))
 
-
 #define LRU_RESIZE_CONNECT_FLAG OBD_CONNECT_LRU_RESIZE
 
 #define MDT_CONNECT_SUPPORTED  (OBD_CONNECT_RDONLY | OBD_CONNECT_VERSION | \
@@ -1386,6 +1391,7 @@ struct obd_connect_data {
        __u64 paddingE;   /* added 2.1.0. also fix lustre_swab_connect */
        __u64 paddingF;   /* added 2.1.0. also fix lustre_swab_connect */
 };
+
 /* XXX README XXX:
  * Please DO NOT use any fields here before first ensuring that this same
  * field is not in use on some other branch.  Please clear any such changes
@@ -1394,7 +1400,6 @@ struct obd_connect_data {
  * the matching OBD_CONNECT flag, so that can be approved and landed easily to
  * reserve the flag for future use. */
 
-
 void lustre_swab_connect(struct obd_connect_data *ocd);
 
 /*
@@ -1404,9 +1409,9 @@ void lustre_swab_connect(struct obd_connect_data *ocd);
  * algorithm and also the OBD_FL_CKSUM* flags.
  */
 typedef enum {
-       OBD_CKSUM_CRC32 = 0x00000001,
-       OBD_CKSUM_ADLER = 0x00000002,
-       OBD_CKSUM_CRC32C= 0x00000004,
+       OBD_CKSUM_CRC32  = 0x00000001,
+       OBD_CKSUM_ADLER  = 0x00000002,
+       OBD_CKSUM_CRC32C = 0x00000004,
 } cksum_type_t;
 
 /*
@@ -1444,7 +1449,7 @@ enum obdo_flags {
        OBD_FL_DELORPHAN    = 0x00000004, /* if set in o_flags delete orphans */
        OBD_FL_NORPC    = 0x00000008, /* set in o_flags do in OSC not OST */
        OBD_FL_IDONLY       = 0x00000010, /* set in o_flags only adjust obj id*/
-       OBD_FL_RECREATE_OBJS= 0x00000020, /* recreate missing obj */
+       OBD_FL_RECREATE_OBJS = 0x00000020, /* recreate missing obj */
        OBD_FL_DEBUG_CHECK  = 0x00000040, /* echo client/server debug check */
        OBD_FL_NO_USRQUOTA  = 0x00000100, /* the object's owner is over quota */
        OBD_FL_NO_GRPQUOTA  = 0x00000200, /* the object's group is over quota */
@@ -1931,6 +1936,7 @@ enum {
        LQUOTA_LAST_RES,
        LQUOTA_FIRST_RES        = LQUOTA_RES_MD
 };
+
 #define LQUOTA_NR_RES (LQUOTA_LAST_RES - LQUOTA_FIRST_RES + 1)
 
 /*
@@ -1978,6 +1984,7 @@ struct ldlm_gl_lquota_desc {
        __u64           gl_time;
        __u64           gl_pad2;
 };
+
 #define gl_qunit       gl_hardlimit /* current qunit value used when
                                      * glimpsing per-ID quota locks */
 
@@ -2046,7 +2053,6 @@ typedef enum {
 
 #define MDS_FIRST_OPC    MDS_GETATTR
 
-
 /* opcodes for object update */
 typedef enum {
        UPDATE_OBJ      = 1000,
@@ -2112,8 +2118,6 @@ void lustre_swab_generic_32s(__u32 *val);
 /* This FULL lock is useful to take on unlink sort of operations */
 #define MDS_INODELOCK_FULL ((1<<(MDS_INODELOCK_MAXSHIFT+1))-1)
 
-void lustre_swab_ll_fid(struct ll_fid *fid);
-
 /* NOTE: until Lustre 1.8.7/2.1.1 the fid_ver() was packed into name[2],
  * but was moved into name[1] along with the OID to avoid consuming the
  * name[2,3] fields that need to be used for the quota id (also a FID). */
@@ -2366,23 +2370,6 @@ void lustre_swab_mdt_rec_setattr(struct mdt_rec_setattr *sa);
                                              */
 #define MDS_OPEN_RELEASE   02000000000000ULL /* Open the file for HSM release */
 
-/* permission for create non-directory file */
-#define MAY_CREATE      (1 << 7)
-/* permission for create directory file */
-#define MAY_LINK       (1 << 8)
-/* permission for delete from the directory */
-#define MAY_UNLINK      (1 << 9)
-/* source's permission for rename */
-#define MAY_RENAME_SRC  (1 << 10)
-/* target's permission for rename */
-#define MAY_RENAME_TAR  (1 << 11)
-/* part (parent's) VTX permission check */
-#define MAY_VTX_PART    (1 << 12)
-/* full VTX permission check */
-#define MAY_VTX_FULL    (1 << 13)
-/* lfs rgetfacl permission check */
-#define MAY_RGETFACL    (1 << 14)
-
 enum mds_op_bias {
        MDS_CHECK_SPLIT         = 1 << 0,
        MDS_CROSS_REF           = 1 << 1,
@@ -2600,8 +2587,6 @@ struct lmv_desc {
        struct obd_uuid ld_uuid;
 };
 
-void lustre_swab_lmv_desc(struct lmv_desc *ld);
-
 /* TODO: lmv_stripe_md should contain mds capabilities for all slave fids */
 struct lmv_stripe_md {
        __u32    mea_magic;
@@ -2612,8 +2597,6 @@ struct lmv_stripe_md {
        struct lu_fid mea_ids[0];
 };
 
-void lustre_swab_lmv_stripe_md(struct lmv_stripe_md *mea);
-
 /* lmv structures */
 #define MEA_MAGIC_LAST_CHAR      0xb2221ca1
 #define MEA_MAGIC_ALL_CHARS      0xb222a11c
@@ -2697,8 +2680,6 @@ struct ldlm_res_id {
 #define PLDLMRES(res)  (res)->lr_name.name[0], (res)->lr_name.name[1], \
                        (res)->lr_name.name[2], (res)->lr_name.name[3]
 
-void lustre_swab_ldlm_res_id(struct ldlm_res_id *id);
-
 static inline int ldlm_res_eq(const struct ldlm_res_id *res0,
                              const struct ldlm_res_id *res1)
 {
@@ -2774,8 +2755,6 @@ typedef union {
        struct ldlm_inodebits l_inodebits;
 } ldlm_wire_policy_data_t;
 
-void lustre_swab_ldlm_policy_data(ldlm_wire_policy_data_t *d);
-
 union ldlm_gl_desc {
        struct ldlm_gl_lquota_desc      lquota_desc;
 };
@@ -2794,8 +2773,6 @@ struct ldlm_resource_desc {
        struct ldlm_res_id lr_name;
 };
 
-void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r);
-
 struct ldlm_lock_desc {
        struct ldlm_resource_desc l_resource;
        ldlm_mode_t l_req_mode;
@@ -2803,8 +2780,6 @@ struct ldlm_lock_desc {
        ldlm_wire_policy_data_t l_policy_data;
 };
 
-void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l);
-
 #define LDLM_LOCKREQ_HANDLES 2
 #define LDLM_ENQUEUE_CANCEL_OFF 1
 
@@ -3337,8 +3312,6 @@ static inline void lustre_get_wire_obdo(struct obd_connect_data *ocd,
        }
 }
 
-void lustre_swab_obdo(struct obdo *o);
-
 /* request structure for OST's */
 struct ost_body {
        struct  obdo oa;
@@ -3366,7 +3339,6 @@ void lustre_swab_llogd_body(struct llogd_body *d);
 void lustre_swab_llog_hdr(struct llog_log_hdr *h);
 void lustre_swab_llogd_conn_body(struct llogd_conn_body *d);
 void lustre_swab_llog_rec(struct llog_rec_hdr *rec);
-void lustre_swab_llog_id(struct llog_logid *lid);
 
 struct lustre_cfg;
 void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg);
@@ -3374,7 +3346,6 @@ void lustre_swab_lustre_cfg(struct lustre_cfg *lcfg);
 /* Functions for dumping PTLRPC fields */
 void dump_rniobuf(struct niobuf_remote *rnb);
 void dump_ioo(struct obd_ioobj *nb);
-void dump_obdo(struct obdo *oa);
 void dump_ost_body(struct ost_body *ob);
 void dump_rcs(__u32 *rc);
 
@@ -3455,8 +3426,6 @@ struct lu_idxpage {
        char    lip_entries[0];
 };
 
-void lustre_swab_lip_header(struct lu_idxpage *lip);
-
 #define LIP_HDR_SIZE (offsetof(struct lu_idxpage, lip_entries))
 
 /* Gather all possible type associated with a 4KB container */
@@ -3491,6 +3460,7 @@ struct lustre_capa {
        __u32      lc_flags;       /** HMAC algorithm & flags */
        __u32      lc_keyid;       /** key# used for the capability */
        __u32      lc_timeout;     /** capa timeout value (sec) */
+/* FIXME: y2038 time_t overflow: */
        __u32      lc_expiry;      /** expiry time (sec) */
        __u8        lc_hmac[CAPA_HMAC_MAX_LEN];   /** HMAC */
 } __attribute__((packed));
@@ -3522,30 +3492,6 @@ enum {
 #define CAPA_OPC_MDS_DEFAULT ~CAPA_OPC_OSS_ONLY
 #define CAPA_OPC_OSS_DEFAULT ~(CAPA_OPC_MDS_ONLY | CAPA_OPC_OSS_ONLY)
 
-/* MDS capability covers object capability for operations of body r/w
- * (dir readpage/sendpage), index lookup/insert/delete and meta data r/w,
- * while OSS capability only covers object capability for operations of
- * oss data(file content) r/w/truncate.
- */
-static inline int capa_for_mds(struct lustre_capa *c)
-{
-       return (c->lc_opc & CAPA_OPC_INDEX_LOOKUP) != 0;
-}
-
-static inline int capa_for_oss(struct lustre_capa *c)
-{
-       return (c->lc_opc & CAPA_OPC_INDEX_LOOKUP) == 0;
-}
-
-/* lustre_capa::lc_hmac_alg */
-enum {
-       CAPA_HMAC_ALG_SHA1 = 1, /**< sha1 algorithm */
-       CAPA_HMAC_ALG_MAX,
-};
-
-#define CAPA_FL_MASK       0x00ffffff
-#define CAPA_HMAC_ALG_MASK      0xff000000
-
 struct lustre_capa_key {
        __u64   lk_seq;       /**< mds# */
        __u32   lk_keyid;     /**< key# */
@@ -3553,8 +3499,6 @@ struct lustre_capa_key {
        __u8    lk_key[CAPA_HMAC_KEY_MAX_LEN];    /**< key */
 } __attribute__((packed));
 
-void lustre_swab_lustre_capa_key(struct lustre_capa_key *k);
-
 /** The link ea holds 1 \a link_ea_entry for each hardlink */
 #define LINK_EA_MAGIC 0x11EAF1DFUL
 struct link_ea_header {
@@ -3574,7 +3518,7 @@ struct link_ea_entry {
        unsigned char      lee_reclen[2];
        unsigned char      lee_parent_fid[sizeof(struct lu_fid)];
        char           lee_name[0];
-}__attribute__((packed));
+} __attribute__((packed));
 
 /** fid2path request/reply structure */
 struct getinfo_fid2path {
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_lfsck_user.h b/drivers/staging/lustre/lustre/include/lustre/lustre_lfsck_user.h
deleted file mode 100644 (file)
index 1c87a61..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License version 2 for more details.  A copy is
- * included in the COPYING file that accompanied this code.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * lustre/include/lustre/lustre_lfsck_user.h
- *
- * Lustre LFSCK userspace interfaces.
- *
- * Author: Fan Yong <yong.fan@whamcloud.com>
- */
-
-#ifndef _LUSTRE_LFSCK_USER_H
-# define _LUSTRE_LFSCK_USER_H
-
-enum lfsck_param_flags {
-       /* Reset LFSCK iterator position to the device beginning. */
-       LPF_RESET       = 0x0001,
-
-       /* Exit when fail. */
-       LPF_FAILOUT     = 0x0002,
-
-       /* Dryrun mode, only check without modification */
-       LPF_DRYRUN      = 0x0004,
-};
-
-enum lfsck_type {
-       /* For MDT-OST consistency check/repair. */
-       LT_LAYOUT       = 0x0001,
-
-       /* For MDT-MDT consistency check/repair. */
-       LT_DNE          = 0x0002,
-
-       /* For FID-in-dirent and linkEA consistency check/repair. */
-       LT_NAMESPACE    = 0x0004,
-};
-
-#define LFSCK_VERSION_V1       1
-#define LFSCK_VERSION_V2       2
-
-#define LFSCK_TYPES_ALL                ((__u16)(~0))
-#define LFSCK_TYPES_DEF                ((__u16)0)
-#define LFSCK_TYPES_SUPPORTED  LT_NAMESPACE
-
-#define LFSCK_SPEED_NO_LIMIT   0
-#define LFSCK_SPEED_LIMIT_DEF  LFSCK_SPEED_NO_LIMIT
-
-enum lfsck_start_valid {
-       LSV_SPEED_LIMIT         = 0x00000001,
-       LSV_ERROR_HANDLE        = 0x00000002,
-       LSV_DRYRUN              = 0x00000004,
-};
-
-/* Arguments for starting lfsck. */
-struct lfsck_start {
-       /* Which arguments are valid, see 'enum lfsck_start_valid'. */
-       __u32   ls_valid;
-
-       /* How many items can be scanned at most per second. */
-       __u32   ls_speed_limit;
-
-       /* For compatibility between user space tools and kernel service. */
-       __u16   ls_version;
-
-       /* Which LFSCK components to be (have been) started. */
-       __u16   ls_active;
-
-       /* Flags for the LFSCK, see 'enum lfsck_param_flags'. */
-       __u16   ls_flags;
-
-       /* For 64-bits aligned. */
-       __u16   ls_padding;
-};
-
-#endif /* _LUSTRE_LFSCK_USER_H */
index 9b1bb23c4d3c00ac89185d3c52a69d7f5808b2c1..80f8ec5294248a605eaaa4f59a1a986863830c90 100644 (file)
@@ -261,7 +261,6 @@ struct ost_id {
 #define LL_IOC_OBD_STATFS       IOC_OBD_STATFS
 #define IOC_MDC_GETSTRIPE       IOC_MDC_GETFILESTRIPE
 
-
 #define MAX_OBD_NAME 128 /* If this changes, a NEW ioctl must be added */
 
 /* Define O_LOV_DELAY_CREATE to be a mask that is not useful for regular
@@ -313,7 +312,7 @@ struct lov_user_ost_data_v1 {     /* per-stripe data structure */
        struct ost_id l_ost_oi;   /* OST object ID */
        __u32 l_ost_gen;          /* generation of this OST index */
        __u32 l_ost_idx;          /* OST index in LOV */
-} __attribute__((packed));
+} __packed;
 
 #define lov_user_md lov_user_md_v1
 struct lov_user_md_v1 {           /* LOV EA user data (host-endian) */
@@ -345,7 +344,7 @@ struct lov_user_md_v3 {        /* LOV EA user data (host-endian) */
        };
        char  lmm_pool_name[LOV_MAXPOOLNAME]; /* pool name */
        struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */
-} __attribute__((packed));
+} __packed;
 
 static inline __u32 lov_user_md_size(__u16 stripes, __u32 lmm_magic)
 {
@@ -365,12 +364,12 @@ static inline __u32 lov_user_md_size(__u16 stripes, __u32 lmm_magic)
 struct lov_user_mds_data_v1 {
        lstat_t lmd_st;          /* MDS stat struct */
        struct lov_user_md_v1 lmd_lmm;  /* LOV EA V1 user data */
-} __attribute__((packed));
+} __packed;
 
 struct lov_user_mds_data_v3 {
        lstat_t lmd_st;          /* MDS stat struct */
        struct lov_user_md_v3 lmd_lmm;  /* LOV EA V3 user data */
-} __attribute__((packed));
+} __packed;
 #endif
 
 /* keep this to be the same size as lov_user_ost_data_v1 */
@@ -406,8 +405,6 @@ static inline int lmv_user_md_size(int stripes, int lmm_magic)
                      stripes * sizeof(struct lmv_user_mds_data);
 }
 
-void lustre_swab_lmv_user_md(struct lmv_user_md *lum);
-
 struct ll_recreate_obj {
        __u64 lrc_id;
        __u32 lrc_ost_idx;
@@ -449,6 +446,7 @@ static inline char *obd_uuid2str(const struct obd_uuid *uuid)
                /* Obviously not safe, but for printfs, no real harm done...
                   we're always null-terminated, even in a race. */
                static char temp[sizeof(*uuid)];
+
                memcpy(temp, uuid->uuid, sizeof(*uuid) - 1);
                temp[sizeof(*uuid) - 1] = '\0';
                return temp;
@@ -489,7 +487,6 @@ static inline void obd_uuid2fsname(char *buf, char *uuid, int buflen)
        &((fid)->f_oid), \
        &((fid)->f_ver)
 
-
 /********* Quotas **********/
 
 /* these must be explicitly translated into linux Q_* in ll_dir_ioctl */
@@ -631,7 +628,6 @@ struct lustre_swap_layouts {
        __u64   sl_dv2;
 };
 
-
 /********* Changelogs **********/
 /** Changelog record types */
 enum changelog_rec_type {
@@ -658,7 +654,8 @@ enum changelog_rec_type {
        CL_LAST
 };
 
-static inline const char *changelog_type2str(int type) {
+static inline const char *changelog_type2str(int type)
+{
        static const char *changelog_str[] = {
                "MARK",  "CREAT", "MKDIR", "HLINK", "SLINK", "MKNOD", "UNLNK",
                "RMDIR", "RENME", "RNMTO", "OPEN",  "CLOSE", "LYOUT", "TRUNC",
@@ -769,7 +766,7 @@ struct changelog_rec {
        };
        lustre_fid          cr_pfid;    /**< parent fid */
        char              cr_name[0];     /**< last element */
-} __attribute__((packed));
+} __packed;
 
 /* changelog_ext_rec is 2*sizeof(lu_fid) bigger than changelog_rec, to save
  * space, only rename uses changelog_ext_rec, while others use changelog_rec to
@@ -791,21 +788,21 @@ struct changelog_ext_rec {
        lustre_fid              cr_sfid;        /**< source fid, or zero */
        lustre_fid              cr_spfid;       /**< source parent fid, or zero */
        char                    cr_name[0];     /**< last element */
-} __attribute__((packed));
+} __packed;
 
 #define CHANGELOG_REC_EXTENDED(rec) \
        (((rec)->cr_flags & CLF_VERMASK) == CLF_EXT_VERSION)
 
 static inline int changelog_rec_size(struct changelog_rec *rec)
 {
-       return CHANGELOG_REC_EXTENDED(rec) ? sizeof(struct changelog_ext_rec):
+       return CHANGELOG_REC_EXTENDED(rec) ? sizeof(struct changelog_ext_rec) :
                                             sizeof(*rec);
 }
 
 static inline char *changelog_rec_name(struct changelog_rec *rec)
 {
        return CHANGELOG_REC_EXTENDED(rec) ?
-               ((struct changelog_ext_rec *)rec)->cr_name: rec->cr_name;
+               ((struct changelog_ext_rec *)rec)->cr_name : rec->cr_name;
 }
 
 static inline int changelog_rec_snamelen(struct changelog_ext_rec *rec)
@@ -836,6 +833,7 @@ struct ioc_data_version {
        __u64 idv_version;
        __u64 idv_flags;     /* See LL_DV_xxx */
 };
+
 #define LL_DV_NOFLUSH 0x01   /* Do not take READ EXTENT LOCK before sampling
                                version. Dirty caches are left unchanged. */
 
@@ -845,7 +843,6 @@ struct ioc_data_version {
 
 #define dot_lustre_name ".lustre"
 
-
 /********* HSM **********/
 
 /** HSM per-file state
@@ -881,6 +878,7 @@ enum hsm_progress_states {
        HPS_RUNNING     = 2,
        HPS_DONE        = 3,
 };
+
 #define HPS_NONE       0
 
 static inline char *hsm_progress_state2name(enum hsm_progress_states s)
@@ -896,7 +894,7 @@ static inline char *hsm_progress_state2name(enum hsm_progress_states s)
 struct hsm_extent {
        __u64 offset;
        __u64 length;
-} __attribute__((packed));
+} __packed;
 
 /**
  * Current HSM states of a Lustre file.
@@ -980,7 +978,7 @@ struct hsm_request {
 struct hsm_user_item {
        lustre_fid      hui_fid;
        struct hsm_extent hui_extent;
-} __attribute__((packed));
+} __packed;
 
 struct hsm_user_request {
        struct hsm_request      hur_request;
@@ -988,7 +986,7 @@ struct hsm_user_request {
        /* extra data blob at end of struct (after all
         * hur_user_items), only use helpers to access it
         */
-} __attribute__((packed));
+} __packed;
 
 /** Return pointer to data field in a hsm user request */
 static inline void *hur_data(struct hsm_user_request *hur)
@@ -1054,7 +1052,7 @@ struct hsm_action_item {
        __u64      hai_cookie;  /* action cookie from coordinator */
        __u64      hai_gid;     /* grouplock id */
        char       hai_data[0]; /* variable length */
-} __attribute__((packed));
+} __packed;
 
 /*
  * helper function which print in hexa the first bytes of
@@ -1098,13 +1096,14 @@ struct hsm_action_list {
        char  hal_fsname[0];   /* null-terminated */
        /* struct hsm_action_item[hal_count] follows, aligned on 8-byte
           boundaries. See hai_zero */
-} __attribute__((packed));
+} __packed;
 
 #ifndef HAVE_CFS_SIZE_ROUND
 static inline int cfs_size_round (int val)
 {
        return (val + 7) & (~0x7);
 }
+
 #define HAVE_CFS_SIZE_ROUND
 #endif
 
@@ -1116,6 +1115,7 @@ static inline struct hsm_action_item *hai_zero(struct hsm_action_list *hal)
                                                                hal_fsname)
                                                         + 1));
 }
+
 /* Return pointer to next hai */
 static inline struct hsm_action_item *hai_next(struct hsm_action_item *hai)
 {
diff --git a/drivers/staging/lustre/lustre/include/lustre_capa.h b/drivers/staging/lustre/lustre/include/lustre_capa.h
deleted file mode 100644 (file)
index fe19534..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/include/lustre_capa.h
- *
- * Author: Lai Siyao <lsy@clusterfs.com>
- */
-
-#ifndef __LINUX_CAPA_H_
-#define __LINUX_CAPA_H_
-
-/** \defgroup capa capa
- *
- * @{
- */
-
-/*
- * capability
- */
-#include <linux/crypto.h>
-#include "lustre/lustre_idl.h"
-
-#define CAPA_TIMEOUT 1800              /* sec, == 30 min */
-#define CAPA_KEY_TIMEOUT (24 * 60 * 60)  /* sec, == 1 days */
-
-struct capa_hmac_alg {
-       const char     *ha_name;
-       int          ha_len;
-       int          ha_keylen;
-};
-
-#define DEF_CAPA_HMAC_ALG(name, type, len, keylen)      \
-[CAPA_HMAC_ALG_ ## type] = {                       \
-       .ha_name         = name,                        \
-       .ha_len   = len,                         \
-       .ha_keylen       = keylen,                    \
-}
-
-struct client_capa {
-       struct inode         *inode;
-       struct list_head                lli_list;     /* link to lli_oss_capas */
-};
-
-struct target_capa {
-       struct hlist_node         c_hash;       /* link to capa hash */
-};
-
-struct obd_capa {
-       struct list_head                c_list;       /* link to capa_list */
-
-       struct lustre_capa      c_capa;       /* capa */
-       atomic_t              c_refc;       /* ref count */
-       unsigned long           c_expiry;     /* jiffies */
-       spinlock_t              c_lock; /* protect capa content */
-       int                     c_site;
-
-       union {
-               struct client_capa      cli;
-               struct target_capa      tgt;
-       } u;
-};
-
-enum {
-       CAPA_SITE_CLIENT = 0,
-       CAPA_SITE_SERVER,
-       CAPA_SITE_MAX
-};
-
-static inline struct lu_fid *capa_fid(struct lustre_capa *capa)
-{
-       return &capa->lc_fid;
-}
-
-static inline __u64 capa_opc(struct lustre_capa *capa)
-{
-       return capa->lc_opc;
-}
-
-static inline __u64 capa_uid(struct lustre_capa *capa)
-{
-       return capa->lc_uid;
-}
-
-static inline __u64 capa_gid(struct lustre_capa *capa)
-{
-       return capa->lc_gid;
-}
-
-static inline __u32 capa_flags(struct lustre_capa *capa)
-{
-       return capa->lc_flags & 0xffffff;
-}
-
-static inline __u32 capa_alg(struct lustre_capa *capa)
-{
-       return (capa->lc_flags >> 24);
-}
-
-static inline __u32 capa_keyid(struct lustre_capa *capa)
-{
-       return capa->lc_keyid;
-}
-
-static inline __u64 capa_key_seq(struct lustre_capa_key *key)
-{
-       return key->lk_seq;
-}
-
-static inline __u32 capa_key_keyid(struct lustre_capa_key *key)
-{
-       return key->lk_keyid;
-}
-
-static inline __u32 capa_timeout(struct lustre_capa *capa)
-{
-       return capa->lc_timeout;
-}
-
-static inline __u32 capa_expiry(struct lustre_capa *capa)
-{
-       return capa->lc_expiry;
-}
-
-void _debug_capa(struct lustre_capa *, struct libcfs_debug_msg_data *,
-                const char *fmt, ...);
-#define DEBUG_CAPA(level, capa, fmt, args...)                            \
-do {                                                                      \
-       if (((level) & D_CANTMASK) != 0 ||                                   \
-           ((libcfs_debug & (level)) != 0 &&                             \
-            (libcfs_subsystem_debug & DEBUG_SUBSYSTEM) != 0)) {               \
-               LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, level, NULL);             \
-               _debug_capa((capa), &msgdata, fmt, ##args);                 \
-       }                                                                     \
-} while (0)
-
-#define DEBUG_CAPA_KEY(level, k, fmt, args...)                          \
-do {                                                                      \
-CDEBUG(level, fmt " capability key@%p seq %llu keyid %u\n",             \
-       ##args, k, capa_key_seq(k), capa_key_keyid(k));                  \
-} while (0)
-
-typedef int (* renew_capa_cb_t)(struct obd_capa *, struct lustre_capa *);
-
-/* obdclass/capa.c */
-extern struct list_head capa_list[];
-extern spinlock_t capa_lock;
-extern int capa_count[];
-extern struct kmem_cache *capa_cachep;
-
-struct hlist_head *init_capa_hash(void);
-void cleanup_capa_hash(struct hlist_head *hash);
-
-struct obd_capa *capa_add(struct hlist_head *hash,
-                         struct lustre_capa *capa);
-struct obd_capa *capa_lookup(struct hlist_head *hash,
-                            struct lustre_capa *capa, int alive);
-
-int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key);
-int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen);
-int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen);
-void capa_cpy(void *dst, struct obd_capa *ocapa);
-static inline struct obd_capa *alloc_capa(int site)
-{
-       struct obd_capa *ocapa;
-
-       if (unlikely(site != CAPA_SITE_CLIENT && site != CAPA_SITE_SERVER))
-               return ERR_PTR(-EINVAL);
-
-       OBD_SLAB_ALLOC_PTR(ocapa, capa_cachep);
-       if (unlikely(!ocapa))
-               return ERR_PTR(-ENOMEM);
-
-       INIT_LIST_HEAD(&ocapa->c_list);
-       atomic_set(&ocapa->c_refc, 1);
-       spin_lock_init(&ocapa->c_lock);
-       ocapa->c_site = site;
-       if (ocapa->c_site == CAPA_SITE_CLIENT)
-               INIT_LIST_HEAD(&ocapa->u.cli.lli_list);
-       else
-               INIT_HLIST_NODE(&ocapa->u.tgt.c_hash);
-
-       return ocapa;
-}
-
-static inline struct obd_capa *capa_get(struct obd_capa *ocapa)
-{
-       if (!ocapa)
-               return NULL;
-
-       atomic_inc(&ocapa->c_refc);
-       return ocapa;
-}
-
-static inline void capa_put(struct obd_capa *ocapa)
-{
-       if (!ocapa)
-               return;
-
-       if (atomic_read(&ocapa->c_refc) == 0) {
-               DEBUG_CAPA(D_ERROR, &ocapa->c_capa, "refc is 0 for");
-               LBUG();
-       }
-
-       if (atomic_dec_and_test(&ocapa->c_refc)) {
-               LASSERT(list_empty(&ocapa->c_list));
-               if (ocapa->c_site == CAPA_SITE_CLIENT) {
-                       LASSERT(list_empty(&ocapa->u.cli.lli_list));
-               } else {
-                       struct hlist_node *hnode;
-
-                       hnode = &ocapa->u.tgt.c_hash;
-                       LASSERT(!hnode->next && !hnode->pprev);
-               }
-               OBD_SLAB_FREE(ocapa, capa_cachep, sizeof(*ocapa));
-       }
-}
-
-static inline int open_flags_to_accmode(int flags)
-{
-       int mode = flags;
-
-       if ((mode + 1) & O_ACCMODE)
-               mode++;
-       if (mode & O_TRUNC)
-               mode |= 2;
-
-       return mode;
-}
-
-static inline __u64 capa_open_opc(int mode)
-{
-       return mode & FMODE_WRITE ? CAPA_OPC_OSS_WRITE : CAPA_OPC_OSS_READ;
-}
-
-static inline void set_capa_expiry(struct obd_capa *ocapa)
-{
-       unsigned long expiry = cfs_time_sub((unsigned long)ocapa->c_capa.lc_expiry,
-                                        get_seconds());
-       ocapa->c_expiry = cfs_time_add(cfs_time_current(),
-                                      cfs_time_seconds(expiry));
-}
-
-static inline int capa_is_expired_sec(struct lustre_capa *capa)
-{
-       return (capa->lc_expiry - get_seconds() <= 0);
-}
-
-static inline int capa_is_expired(struct obd_capa *ocapa)
-{
-       return time_before_eq(ocapa->c_expiry, cfs_time_current());
-}
-
-static inline int capa_opc_supported(struct lustre_capa *capa, __u64 opc)
-{
-       return (capa_opc(capa) & opc) == opc;
-}
-
-struct filter_capa_key {
-       struct list_head              k_list;
-       struct lustre_capa_key  k_key;
-};
-
-enum {
-       LC_ID_NONE      = 0,
-       LC_ID_PLAIN     = 1,
-       LC_ID_CONVERT   = 2
-};
-
-#define BYPASS_CAPA (struct lustre_capa *)ERR_PTR(-ENOENT)
-
-/** @} capa */
-
-#endif /* __LINUX_CAPA_H_ */
index 7b385b87261a4fe5de756d1f959578000700848d..eb6b292b7b25a02bb97ccd5c6b76b3805a13dc8b 100644 (file)
@@ -157,6 +157,7 @@ static inline void *lustre_cfg_buf(struct lustre_cfg *lcfg, int index)
        int i;
        int offset;
        int bufcount;
+
        LASSERT (lcfg != NULL);
        LASSERT (index >= 0);
 
@@ -174,6 +175,7 @@ static inline void lustre_cfg_bufs_init(struct lustre_cfg_bufs *bufs,
                                        struct lustre_cfg *lcfg)
 {
        int i;
+
        bufs->lcfg_bufcount = lcfg->lcfg_bufcount;
        for (i = 0; i < bufs->lcfg_bufcount; i++) {
                bufs->lcfg_buflen[i] = lcfg->lcfg_buflens[i];
@@ -200,6 +202,7 @@ static inline char *lustre_cfg_string(struct lustre_cfg *lcfg, int index)
                int last = min((int)lcfg->lcfg_buflens[index],
                               cfs_size_round(lcfg->lcfg_buflens[index]) - 1);
                char lost = s[last];
+
                s[last] = '\0';
                if (lost != '\0') {
                        CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
@@ -221,7 +224,6 @@ static inline int lustre_cfg_len(__u32 bufcount, __u32 *buflens)
        return cfs_size_round(len);
 }
 
-
 #include "obd_support.h"
 
 static inline struct lustre_cfg *lustre_cfg_new(int cmd,
@@ -231,8 +233,8 @@ static inline struct lustre_cfg *lustre_cfg_new(int cmd,
        char *ptr;
        int i;
 
-       OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
-                                      bufs->lcfg_buflen));
+       lcfg = kzalloc(lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen),
+                      GFP_NOFS);
        if (!lcfg)
                return ERR_PTR(-ENOMEM);
 
@@ -254,7 +256,7 @@ static inline void lustre_cfg_free(struct lustre_cfg *lcfg)
 
        len = lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens);
 
-       OBD_FREE(lcfg, len);
+       kfree(lcfg);
        return;
 }
 
index 6c92d0bc943b2a4545c15b2b495d30fe052581f6..8a089413c92e94f3b8155efee6f02b6a8a3bc0fc 100644 (file)
@@ -46,7 +46,6 @@
 #include "obd.h"
 
 /* lib/debug.c */
-void dump_lniobuf(struct niobuf_local *lnb);
 int dump_req(struct ptlrpc_request *req);
 int block_debug_setup(void *addr, int len, __u64 off, __u64 id);
 int block_debug_check(char *who, void *addr, int len, __u64 off, __u64 id);
index 9b2833131744adb7a641c4e7d9930c63f7283fe2..5e1ac129a681e28f4620e81abff337bb3ca70cce 100644 (file)
 #include "../../include/linux/lnet/types.h"
 #include <linux/backing-dev.h>
 
-/****************** on-disk files *********************/
-
-#define MDT_LOGS_DIR           "LOGS"  /* COMPAT_146 */
-#define MOUNT_CONFIGS_DIR      "CONFIGS"
-#define CONFIGS_FILE           "mountdata"
-/** Persistent mount data are stored on the disk in this file. */
-#define MOUNT_DATA_FILE                MOUNT_CONFIGS_DIR"/"CONFIGS_FILE
-#define LAST_RCVD              "last_rcvd"
-#define LOV_OBJID              "lov_objid"
-#define LOV_OBJSEQ             "lov_objseq"
-#define HEALTH_CHECK           "health_check"
-#define CAPA_KEYS              "capa_keys"
-#define CHANGELOG_USERS                "changelog_users"
-#define MGS_NIDTBL_DIR         "NIDTBL_VERSIONS"
-#define QMT_DIR                        "quota_master"
-#define QSD_DIR                        "quota_slave"
-#define HSM_ACTIONS            "hsm_actions"
-
 /****************** persistent mount data *********************/
 
 #define LDD_F_SV_TYPE_MDT   0x0001
                            LDD_F_SV_TYPE_OST  | \
                            LDD_F_SV_TYPE_MGS)
 #define LDD_F_SV_ALL   0x0008
-/** need an index assignment */
-#define LDD_F_NEED_INDEX    0x0010
-/** never registered */
-#define LDD_F_VIRGIN   0x0020
-/** update the config logs for this server */
-#define LDD_F_UPDATE   0x0040
-/** rewrite the LDD */
-#define LDD_F_REWRITE_LDD   0x0080
-/** regenerate config logs for this fs or server */
-#define LDD_F_WRITECONF     0x0100
-/** COMPAT_14 */
-#define LDD_F_UPGRADE14     0x0200
-/** process as lctl conf_param */
-#define LDD_F_PARAM     0x0400
-/** all nodes are specified as service nodes */
-#define LDD_F_NO_PRIMNODE   0x1000
-/** IR enable flag */
-#define LDD_F_IR_CAPABLE    0x2000
-/** the MGS refused to register the target. */
-#define LDD_F_ERROR     0x4000
-/** process at lctl conf_param */
-#define LDD_F_PARAM2           0x8000
-
-/* opc for target register */
-#define LDD_F_OPC_REG   0x10000000
-#define LDD_F_OPC_UNREG 0x20000000
-#define LDD_F_OPC_READY 0x40000000
-#define LDD_F_OPC_MASK  0xf0000000
-
-#define LDD_F_ONDISK_MASK  (LDD_F_SV_TYPE_MASK)
-
-#define LDD_F_MASK       0xFFFF
-
-enum ldd_mount_type {
-       LDD_MT_EXT3 = 0,
-       LDD_MT_LDISKFS,
-       LDD_MT_SMFS,
-       LDD_MT_REISERFS,
-       LDD_MT_LDISKFS2,
-       LDD_MT_ZFS,
-       LDD_MT_LAST
-};
-
-static inline char *mt_str(enum ldd_mount_type mt)
-{
-       static char *mount_type_string[] = {
-               "ext3",
-               "ldiskfs",
-               "smfs",
-               "reiserfs",
-               "ldiskfs2",
-               "zfs",
-       };
-       return mount_type_string[mt];
-}
-
-static inline char *mt_type(enum ldd_mount_type mt)
-{
-       static char *mount_type_string[] = {
-               "osd-ldiskfs",
-               "osd-ldiskfs",
-               "osd-smfs",
-               "osd-reiserfs",
-               "osd-ldiskfs",
-               "osd-zfs",
-       };
-       return mount_type_string[mt];
-}
-
-#define LDD_INCOMPAT_SUPP 0
-#define LDD_ROCOMPAT_SUPP 0
-
-#define LDD_MAGIC 0x1dd00001
-
-/* On-disk configuration file. In host-endian order. */
-struct lustre_disk_data {
-       __u32      ldd_magic;
-       __u32      ldd_feature_compat;  /* compatible feature flags */
-       __u32      ldd_feature_rocompat;/* read-only compatible feature flags */
-       __u32      ldd_feature_incompat;/* incompatible feature flags */
-
-       __u32      ldd_config_ver;      /* config rewrite count - not used */
-       __u32      ldd_flags;      /* LDD_SV_TYPE */
-       __u32      ldd_svindex;  /* server index (0001), must match
-                                          svname */
-       __u32      ldd_mount_type;      /* target fs type LDD_MT_* */
-       char       ldd_fsname[64];      /* filesystem this server is part of,
-                                          MTI_NAME_MAXLEN */
-       char       ldd_svname[64];      /* this server's name (lustre-mdt0001)*/
-       __u8       ldd_uuid[40];        /* server UUID (COMPAT_146) */
-
-/*200*/ char       ldd_userdata[1024 - 200]; /* arbitrary user string */
-/*1024*/__u8       ldd_padding[4096 - 1024];
-/*4096*/char       ldd_mount_opts[4096]; /* target fs mount opts */
-/*8192*/char       ldd_params[4096];     /* key=value pairs */
-};
-
-
-#define IS_MDT(data)    ((data)->lsi_flags & LDD_F_SV_TYPE_MDT)
-#define IS_OST(data)    ((data)->lsi_flags & LDD_F_SV_TYPE_OST)
-#define IS_MGS(data)    ((data)->lsi_flags & LDD_F_SV_TYPE_MGS)
-#define IS_SERVER(data) ((data)->lsi_flags & (LDD_F_SV_TYPE_MGS | \
-                        LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST))
-#define MT_STR(data)    mt_str((data)->ldd_mount_type)
-
-/* Make the mdt/ost server obd name based on the filesystem name */
-static inline int server_make_name(__u32 flags, __u16 index, char *fs,
-                                  char *name)
-{
-       if (flags & (LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST)) {
-               if (!(flags & LDD_F_SV_ALL))
-                       sprintf(name, "%.8s%c%s%04x", fs,
-                               (flags & LDD_F_VIRGIN) ? ':' :
-                                       ((flags & LDD_F_WRITECONF) ? '=' : '-'),
-                               (flags & LDD_F_SV_TYPE_MDT) ? "MDT" : "OST",
-                               index);
-       } else if (flags & LDD_F_SV_TYPE_MGS) {
-               sprintf(name, "MGS");
-       } else {
-               CERROR("unknown server type %#x\n", flags);
-               return 1;
-       }
-       return 0;
-}
 
 /****************** mount command *********************/
 
@@ -249,7 +107,6 @@ struct lustre_mount_data {
 
 #define lmd_is_client(x) ((x)->lmd_flags & LMD_FLG_CLIENT)
 
-
 /****************** last_rcvd file *********************/
 
 /** version recovery epoch */
@@ -365,7 +222,8 @@ static inline void check_lcd(char *obd_name, int index,
                             struct lsd_client_data *lcd)
 {
        int length = sizeof(lcd->lcd_uuid);
-       if (strnlen((char*)lcd->lcd_uuid, length) == length) {
+
+       if (strnlen((char *)lcd->lcd_uuid, length) == length) {
                lcd->lcd_uuid[length - 1] = '\0';
 
                LCONSOLE_ERROR("the client UUID (%s) on %s for exports stored in last_rcvd(index = %d) is bad!\n",
@@ -378,6 +236,7 @@ static inline void lsd_le_to_cpu(struct lr_server_data *buf,
                                 struct lr_server_data *lsd)
 {
        int i;
+
        memcpy(lsd->lsd_uuid, buf->lsd_uuid, sizeof(lsd->lsd_uuid));
        lsd->lsd_last_transno     = le64_to_cpu(buf->lsd_last_transno);
        lsd->lsd_compat14        = le64_to_cpu(buf->lsd_compat14);
@@ -405,6 +264,7 @@ static inline void lsd_cpu_to_le(struct lr_server_data *lsd,
                                 struct lr_server_data *buf)
 {
        int i;
+
        memcpy(buf->lsd_uuid, lsd->lsd_uuid, sizeof(buf->lsd_uuid));
        buf->lsd_last_transno     = cpu_to_le64(lsd->lsd_last_transno);
        buf->lsd_compat14        = cpu_to_le64(lsd->lsd_compat14);
@@ -512,7 +372,6 @@ struct lustre_sb_info {
 #define            get_mount_flags(sb)    (s2lsi(sb)->lsi_lmd->lmd_flags)
 #define            get_mntdev_name(sb)    (s2lsi(sb)->lsi_lmd->lmd_dev)
 
-
 /****************** mount lookup info *********************/
 
 struct lustre_mount_info {
@@ -525,21 +384,13 @@ struct lustre_mount_info {
 /****************** prototypes *********************/
 
 /* obd_mount.c */
-int server_name2fsname(const char *svname, char *fsname, const char **endptr);
-int server_name2index(const char *svname, __u32 *idx, const char **endptr);
-int server_name2svname(const char *label, char *svname, const char **endptr,
-                      size_t svsize);
-
-int lustre_put_lsi(struct super_block *sb);
-int lustre_start_simple(char *obdname, char *type, char *uuid,
-                       char *s1, char *s2, char *s3, char *s4);
+
 int lustre_start_mgc(struct super_block *sb);
 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
                                                  struct vfsmount *mnt));
 void lustre_register_kill_super_cb(void (*cfs)(struct super_block *sb));
 int lustre_common_put_super(struct super_block *sb);
 
-
 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type);
 
 /** @} disk */
index 355254689dee0b7c21a4e4851a0f6b02f4868849..0e75a15fe0d42f5f1d44cbb3ea82ef9fdab40fac 100644 (file)
@@ -60,9 +60,6 @@
 struct obd_ops;
 struct obd_device;
 
-extern struct kset *ldlm_ns_kset;
-extern struct kset *ldlm_svc_kset;
-
 #define OBD_LDLM_DEVICENAME  "ldlm"
 
 #define LDLM_DEFAULT_LRU_SIZE (100 * num_online_cpus())
@@ -213,7 +210,6 @@ struct ldlm_pool_ops {
        /** Cancel at least \a nr locks from pool \a pl */
        int (*po_shrink)(struct ldlm_pool *pl, int nr,
                         gfp_t gfp_mask);
-       int (*po_setup)(struct ldlm_pool *pl, int limit);
 };
 
 /** One second for pools thread check interval. Each pool has own period. */
@@ -256,9 +252,9 @@ struct ldlm_pool {
         *  server_slv * lock_volume_factor. */
        atomic_t                pl_lock_volume_factor;
        /** Time when last SLV from server was obtained. */
-       time_t                  pl_recalc_time;
+       time64_t                pl_recalc_time;
        /** Recalculation period for pool. */
-       time_t                  pl_recalc_period;
+       time64_t                pl_recalc_period;
        /** Recalculation and shrink operations. */
        const struct ldlm_pool_ops      *pl_ops;
        /** Number of planned locks for next period. */
@@ -271,10 +267,6 @@ struct ldlm_pool {
        struct completion        pl_kobj_unregister;
 };
 
-typedef int (*ldlm_res_policy)(struct ldlm_namespace *, struct ldlm_lock **,
-                              void *req_cookie, ldlm_mode_t mode, __u64 flags,
-                              void *data);
-
 typedef int (*ldlm_cancel_for_recovery)(struct ldlm_lock *lock);
 
 /**
@@ -427,9 +419,6 @@ struct ldlm_namespace {
         */
        unsigned long           ns_next_dump;
 
-       /** "policy" function that does actual lock conflict determination */
-       ldlm_res_policy         ns_policy;
-
        /**
         * LVB operations for this namespace.
         * \see struct ldlm_valblock_ops
@@ -471,32 +460,6 @@ struct ldlm_namespace {
        struct completion       ns_kobj_unregister;
 };
 
-/**
- * Returns 1 if namespace \a ns is a client namespace.
- */
-static inline int ns_is_client(struct ldlm_namespace *ns)
-{
-       LASSERT(ns != NULL);
-       LASSERT(!(ns->ns_client & ~(LDLM_NAMESPACE_CLIENT |
-                                   LDLM_NAMESPACE_SERVER)));
-       LASSERT(ns->ns_client == LDLM_NAMESPACE_CLIENT ||
-               ns->ns_client == LDLM_NAMESPACE_SERVER);
-       return ns->ns_client == LDLM_NAMESPACE_CLIENT;
-}
-
-/**
- * Returns 1 if namespace \a ns is a server namespace.
- */
-static inline int ns_is_server(struct ldlm_namespace *ns)
-{
-       LASSERT(ns != NULL);
-       LASSERT(!(ns->ns_client & ~(LDLM_NAMESPACE_CLIENT |
-                                   LDLM_NAMESPACE_SERVER)));
-       LASSERT(ns->ns_client == LDLM_NAMESPACE_CLIENT ||
-               ns->ns_client == LDLM_NAMESPACE_SERVER);
-       return ns->ns_client == LDLM_NAMESPACE_SERVER;
-}
-
 /**
  * Returns 1 if namespace \a ns supports early lock cancel (ELC).
  */
@@ -552,6 +515,7 @@ struct ldlm_interval {
        struct list_head                li_group; /* the locks which have the same
                                           * policy - group of the policy */
 };
+
 #define to_ldlm_interval(n) container_of(n, struct ldlm_interval, li_node)
 
 /**
@@ -595,9 +559,6 @@ typedef union {
        struct ldlm_inodebits l_inodebits;
 } ldlm_policy_data_t;
 
-void ldlm_convert_policy_to_wire(ldlm_type_t type,
-                                const ldlm_policy_data_t *lpolicy,
-                                ldlm_wire_policy_data_t *wpolicy);
 void ldlm_convert_policy_to_local(struct obd_export *exp, ldlm_type_t type,
                                  const ldlm_wire_policy_data_t *wpolicy,
                                  ldlm_policy_data_t *lpolicy);
@@ -749,7 +710,7 @@ struct ldlm_lock {
         * Seconds. It will be updated if there is any activity related to
         * the lock, e.g. enqueue the lock or send blocking AST.
         */
-       unsigned long           l_last_activity;
+       time64_t                l_last_activity;
 
        /**
         * Time last used by e.g. being matched by lock match.
@@ -883,8 +844,6 @@ struct ldlm_resource {
         * @{ */
        /** List of locks in granted state */
        struct list_head                lr_granted;
-       /** List of locks waiting to change their granted mode (converted) */
-       struct list_head                lr_converting;
        /**
         * List of locks that could not be granted due to conflicts and
         * that are waiting for conflicts to go away */
@@ -1016,7 +975,6 @@ struct ldlm_enqueue_info {
 extern struct obd_ops ldlm_obd_ops;
 
 extern char *ldlm_lockname[];
-extern char *ldlm_typename[];
 char *ldlm_it2str(int it);
 
 /**
@@ -1025,7 +983,7 @@ char *ldlm_it2str(int it);
  * with a debugging message that is ldlm-related
  */
 #define LDLM_DEBUG_NOLOCK(format, a...)                        \
-       CDEBUG(D_DLMTRACE, "### " format "\n" , ##a)
+       CDEBUG(D_DLMTRACE, "### " format "\n", ##a)
 
 /**
  * Support function for lock information printing into debug logs.
@@ -1051,7 +1009,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock,
 #define LDLM_DEBUG_LIMIT(mask, lock, fmt, a...) do {                    \
        static struct cfs_debug_limit_state _ldlm_cdls;                    \
        LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, mask, &_ldlm_cdls);       \
-       ldlm_lock_debug(&msgdata, mask, &_ldlm_cdls, lock, "### " fmt , ##a);\
+       ldlm_lock_debug(&msgdata, mask, &_ldlm_cdls, lock, "### " fmt, ##a);\
 } while (0)
 
 #define LDLM_ERROR(lock, fmt, a...) LDLM_DEBUG_LIMIT(D_ERROR, lock, fmt, ## a)
@@ -1062,7 +1020,7 @@ void _ldlm_lock_debug(struct ldlm_lock *lock,
        if (likely(lock != NULL)) {                                         \
                LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_DLMTRACE, NULL);      \
                ldlm_lock_debug(&msgdata, D_DLMTRACE, NULL, lock,           \
-                               "### " fmt , ##a);                          \
+                               "### " fmt, ##a);                           \
        } else {                                                            \
                LDLM_DEBUG_NOLOCK("no dlm lock: " fmt, ##a);                \
        }                                                                   \
@@ -1087,10 +1045,6 @@ typedef int (*ldlm_res_iterator_t)(struct ldlm_resource *, void *);
  * LDLM provides for a way to iterate through every lock on a resource or
  * namespace or every resource in a namespace.
  * @{ */
-int ldlm_resource_foreach(struct ldlm_resource *res, ldlm_iterator_t iter,
-                         void *closure);
-void ldlm_namespace_foreach(struct ldlm_namespace *ns, ldlm_iterator_t iter,
-                           void *closure);
 int ldlm_resource_iterate(struct ldlm_namespace *, const struct ldlm_res_id *,
                          ldlm_iterator_t iter, void *data);
 /** @} ldlm_iterator */
@@ -1110,16 +1064,11 @@ struct ldlm_callback_suite {
 };
 
 /* ldlm_lockd.c */
-int ldlm_del_waiting_lock(struct ldlm_lock *lock);
-int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout);
 int ldlm_get_ref(void);
 void ldlm_put_ref(void);
-int ldlm_init_export(struct obd_export *exp);
-void ldlm_destroy_export(struct obd_export *exp);
 struct ldlm_lock *ldlm_request_lock(struct ptlrpc_request *req);
 
 /* ldlm_lock.c */
-void ldlm_register_intent(struct ldlm_namespace *ns, ldlm_res_policy arg);
 void ldlm_lock2handle(const struct ldlm_lock *lock,
                      struct lustre_handle *lockh);
 struct ldlm_lock *__ldlm_handle2lock(const struct lustre_handle *, __u64 flags);
@@ -1165,8 +1114,7 @@ static inline int ldlm_res_lvbo_update(struct ldlm_resource *res,
 }
 
 int ldlm_error2errno(ldlm_error_t error);
-ldlm_error_t ldlm_errno2error(int err_no); /* don't call it `errno': this
-                                           * confuses user-space. */
+
 #if LUSTRE_TRACKS_LOCK_EXP_REFS
 void ldlm_dump_export_locks(struct obd_export *exp);
 #endif
@@ -1214,14 +1162,12 @@ do {                                        \
 
 struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
 void ldlm_lock_put(struct ldlm_lock *lock);
-void ldlm_lock_destroy(struct ldlm_lock *lock);
 void ldlm_lock2desc(struct ldlm_lock *lock, struct ldlm_lock_desc *desc);
 void ldlm_lock_addref(struct lustre_handle *lockh, __u32 mode);
 int  ldlm_lock_addref_try(struct lustre_handle *lockh, __u32 mode);
 void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode);
 void ldlm_lock_decref_and_cancel(struct lustre_handle *lockh, __u32 mode);
 void ldlm_lock_fail_match_locked(struct ldlm_lock *lock);
-void ldlm_lock_fail_match(struct ldlm_lock *lock);
 void ldlm_lock_allow_match(struct ldlm_lock *lock);
 void ldlm_lock_allow_match_locked(struct ldlm_lock *lock);
 ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
@@ -1230,12 +1176,7 @@ ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
                            struct lustre_handle *, int unref);
 ldlm_mode_t ldlm_revalidate_lock_handle(struct lustre_handle *lockh,
                                        __u64 *bits);
-struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
-                                       __u32 *flags);
-void ldlm_lock_downgrade(struct ldlm_lock *lock, int new_mode);
 void ldlm_lock_cancel(struct ldlm_lock *lock);
-void ldlm_reprocess_all(struct ldlm_resource *res);
-void ldlm_reprocess_all_ns(struct ldlm_namespace *ns);
 void ldlm_lock_dump_handle(int level, struct lustre_handle *);
 void ldlm_unlink_lock_skiplist(struct ldlm_lock *req);
 
@@ -1245,10 +1186,6 @@ ldlm_namespace_new(struct obd_device *obd, char *name,
                   ldlm_side_t client, ldlm_appetite_t apt,
                   ldlm_ns_type_t ns_type);
 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, __u64 flags);
-void ldlm_namespace_free(struct ldlm_namespace *ns,
-                        struct obd_import *imp, int force);
-void ldlm_namespace_register(struct ldlm_namespace *ns, ldlm_side_t client);
-void ldlm_namespace_unregister(struct ldlm_namespace *ns, ldlm_side_t client);
 void ldlm_namespace_get(struct ldlm_namespace *ns);
 void ldlm_namespace_put(struct ldlm_namespace *ns);
 int ldlm_debugfs_setup(void);
@@ -1259,7 +1196,6 @@ struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
                                        struct ldlm_resource *parent,
                                        const struct ldlm_res_id *,
                                        ldlm_type_t type, int create);
-struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res);
 int ldlm_resource_putref(struct ldlm_resource *res);
 void ldlm_resource_add_lock(struct ldlm_resource *res,
                            struct list_head *head,
@@ -1281,16 +1217,11 @@ int ldlm_lock_change_resource(struct ldlm_namespace *, struct ldlm_lock *,
 } while (0)
 
 /* ldlm_request.c */
-int ldlm_expired_completion_wait(void *data);
 /** \defgroup ldlm_local_ast Default AST handlers for local locks
  * These AST handlers are typically used for server-side local locks and are
  * also used by client-side lock handlers to perform minimum level base
  * processing.
  * @{ */
-int ldlm_blocking_ast_nocheck(struct ldlm_lock *lock);
-int ldlm_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
-                     void *data, int flag);
-int ldlm_glimpse_ast(struct ldlm_lock *lock, void *reqp);
 int ldlm_completion_ast_async(struct ldlm_lock *lock, __u64 flags, void *data);
 int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data);
 /** @} ldlm_local_ast */
@@ -1314,27 +1245,10 @@ int ldlm_prep_elc_req(struct obd_export *exp,
                      int version, int opc, int canceloff,
                      struct list_head *cancels, int count);
 
-struct ptlrpc_request *ldlm_enqueue_pack(struct obd_export *exp, int lvb_len);
-int ldlm_handle_enqueue0(struct ldlm_namespace *ns, struct ptlrpc_request *req,
-                        const struct ldlm_request *dlm_req,
-                        const struct ldlm_callback_suite *cbs);
 int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
                          ldlm_type_t type, __u8 with_policy, ldlm_mode_t mode,
                          __u64 *flags, void *lvb, __u32 lvb_len,
                          struct lustre_handle *lockh, int rc);
-int ldlm_cli_enqueue_local(struct ldlm_namespace *ns,
-                          const struct ldlm_res_id *res_id,
-                          ldlm_type_t type, ldlm_policy_data_t *policy,
-                          ldlm_mode_t mode, __u64 *flags,
-                          ldlm_blocking_callback blocking,
-                          ldlm_completion_callback completion,
-                          ldlm_glimpse_callback glimpse,
-                          void *data, __u32 lvb_len, enum lvb_type lvb_type,
-                          const __u64 *client_cookie,
-                          struct lustre_handle *lockh);
-int ldlm_server_ast(struct lustre_handle *lockh, struct ldlm_lock_desc *new,
-                   void *data, __u32 data_len);
-int ldlm_cli_convert(struct lustre_handle *, int new_mode, __u32 *flags);
 int ldlm_cli_update_pool(struct ptlrpc_request *req);
 int ldlm_cli_cancel(struct lustre_handle *lockh,
                    ldlm_cancel_flags_t cancel_flags);
@@ -1346,8 +1260,6 @@ int ldlm_cli_cancel_unused_resource(struct ldlm_namespace *ns,
                                    ldlm_mode_t mode,
                                    ldlm_cancel_flags_t flags,
                                    void *opaque);
-int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *head,
-                       int count, ldlm_cancel_flags_t flags);
 int ldlm_cancel_resource_local(struct ldlm_resource *res,
                               struct list_head *cancels,
                               ldlm_policy_data_t *policy,
@@ -1364,7 +1276,6 @@ int ldlm_cli_cancel_list(struct list_head *head, int count,
 int intent_disposition(struct ldlm_reply *rep, int flag);
 void intent_set_disposition(struct ldlm_reply *rep, int flag);
 
-
 /* ioctls for trying requests */
 #define IOC_LDLM_TYPE             'f'
 #define IOC_LDLM_MIN_NR                 40
@@ -1417,24 +1328,12 @@ void unlock_res_and_lock(struct ldlm_lock *lock);
  * There are not used outside of ldlm.
  * @{
  */
-int ldlm_pools_recalc(ldlm_side_t client);
 int ldlm_pools_init(void);
 void ldlm_pools_fini(void);
 
 int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns,
                   int idx, ldlm_side_t client);
-int ldlm_pool_shrink(struct ldlm_pool *pl, int nr,
-                    gfp_t gfp_mask);
 void ldlm_pool_fini(struct ldlm_pool *pl);
-int ldlm_pool_setup(struct ldlm_pool *pl, int limit);
-int ldlm_pool_recalc(struct ldlm_pool *pl);
-__u32 ldlm_pool_get_lvf(struct ldlm_pool *pl);
-__u64 ldlm_pool_get_slv(struct ldlm_pool *pl);
-__u64 ldlm_pool_get_clv(struct ldlm_pool *pl);
-__u32 ldlm_pool_get_limit(struct ldlm_pool *pl);
-void ldlm_pool_set_slv(struct ldlm_pool *pl, __u64 slv);
-void ldlm_pool_set_clv(struct ldlm_pool *pl, __u64 clv);
-void ldlm_pool_set_limit(struct ldlm_pool *pl, __u32 limit);
 void ldlm_pool_add(struct ldlm_pool *pl, struct ldlm_lock *lock);
 void ldlm_pool_del(struct ldlm_pool *pl, struct ldlm_lock *lock);
 /** @} */
index d4cc096352712ef3bab6f5b7a13056734b314c45..0d3ed87d38e13ce2017be054f58f5bfae88d665f 100644 (file)
 #define LDLM_FL_ON_WIRE_MASK            0x00000000C08F932FULL
 
 /** extent, mode, or resource changed */
-#define LDLM_FL_LOCK_CHANGED            0x0000000000000001ULL // bit   0
-#define ldlm_is_lock_changed(_l)        LDLM_TEST_FLAG(( _l), 1ULL <<  0)
-#define ldlm_set_lock_changed(_l)       LDLM_SET_FLAG((  _l), 1ULL <<  0)
+#define LDLM_FL_LOCK_CHANGED            0x0000000000000001ULL /* bit 0 */
+#define ldlm_is_lock_changed(_l)        LDLM_TEST_FLAG((_l), 1ULL <<  0)
+#define ldlm_set_lock_changed(_l)       LDLM_SET_FLAG((_l), 1ULL <<  0)
 #define ldlm_clear_lock_changed(_l)     LDLM_CLEAR_FLAG((_l), 1ULL <<  0)
 
 /**
  * Server placed lock on granted list, or a recovering client wants the
  * lock added to the granted list, no questions asked. */
-#define LDLM_FL_BLOCK_GRANTED           0x0000000000000002ULL // bit   1
-#define ldlm_is_block_granted(_l)       LDLM_TEST_FLAG(( _l), 1ULL <<  1)
-#define ldlm_set_block_granted(_l)      LDLM_SET_FLAG((  _l), 1ULL <<  1)
+#define LDLM_FL_BLOCK_GRANTED           0x0000000000000002ULL /* bit 1 */
+#define ldlm_is_block_granted(_l)       LDLM_TEST_FLAG((_l), 1ULL <<  1)
+#define ldlm_set_block_granted(_l)      LDLM_SET_FLAG((_l), 1ULL <<  1)
 #define ldlm_clear_block_granted(_l)    LDLM_CLEAR_FLAG((_l), 1ULL <<  1)
 
 /**
  * Server placed lock on conv list, or a recovering client wants the lock
  * added to the conv list, no questions asked. */
-#define LDLM_FL_BLOCK_CONV              0x0000000000000004ULL // bit   2
-#define ldlm_is_block_conv(_l)          LDLM_TEST_FLAG(( _l), 1ULL <<  2)
-#define ldlm_set_block_conv(_l)         LDLM_SET_FLAG((  _l), 1ULL <<  2)
+#define LDLM_FL_BLOCK_CONV              0x0000000000000004ULL /* bit 2 */
+#define ldlm_is_block_conv(_l)          LDLM_TEST_FLAG((_l), 1ULL <<  2)
+#define ldlm_set_block_conv(_l)         LDLM_SET_FLAG((_l), 1ULL <<  2)
 #define ldlm_clear_block_conv(_l)       LDLM_CLEAR_FLAG((_l), 1ULL <<  2)
 
 /**
  * Server placed lock on wait list, or a recovering client wants the lock
  * added to the wait list, no questions asked. */
-#define LDLM_FL_BLOCK_WAIT              0x0000000000000008ULL // bit   3
-#define ldlm_is_block_wait(_l)          LDLM_TEST_FLAG(( _l), 1ULL <<  3)
-#define ldlm_set_block_wait(_l)         LDLM_SET_FLAG((  _l), 1ULL <<  3)
+#define LDLM_FL_BLOCK_WAIT              0x0000000000000008ULL /* bit 3 */
+#define ldlm_is_block_wait(_l)          LDLM_TEST_FLAG((_l), 1ULL <<  3)
+#define ldlm_set_block_wait(_l)         LDLM_SET_FLAG((_l), 1ULL <<  3)
 #define ldlm_clear_block_wait(_l)       LDLM_CLEAR_FLAG((_l), 1ULL <<  3)
 
 /** blocking or cancel packet was queued for sending. */
-#define LDLM_FL_AST_SENT                0x0000000000000020ULL // bit   5
-#define ldlm_is_ast_sent(_l)            LDLM_TEST_FLAG(( _l), 1ULL <<  5)
-#define ldlm_set_ast_sent(_l)           LDLM_SET_FLAG((  _l), 1ULL <<  5)
+#define LDLM_FL_AST_SENT                0x0000000000000020ULL /* bit 5 */
+#define ldlm_is_ast_sent(_l)            LDLM_TEST_FLAG((_l), 1ULL <<  5)
+#define ldlm_set_ast_sent(_l)           LDLM_SET_FLAG((_l), 1ULL <<  5)
 #define ldlm_clear_ast_sent(_l)         LDLM_CLEAR_FLAG((_l), 1ULL <<  5)
 
 /**
  * Lock is being replayed.  This could probably be implied by the fact that
  * one of BLOCK_{GRANTED,CONV,WAIT} is set, but that is pretty dangerous. */
-#define LDLM_FL_REPLAY                  0x0000000000000100ULL // bit   8
-#define ldlm_is_replay(_l)              LDLM_TEST_FLAG(( _l), 1ULL <<  8)
-#define ldlm_set_replay(_l)             LDLM_SET_FLAG((  _l), 1ULL <<  8)
+#define LDLM_FL_REPLAY                  0x0000000000000100ULL /* bit 8 */
+#define ldlm_is_replay(_l)              LDLM_TEST_FLAG((_l), 1ULL <<  8)
+#define ldlm_set_replay(_l)             LDLM_SET_FLAG((_l), 1ULL <<  8)
 #define ldlm_clear_replay(_l)           LDLM_CLEAR_FLAG((_l), 1ULL <<  8)
 
 /** Don't grant lock, just do intent. */
-#define LDLM_FL_INTENT_ONLY             0x0000000000000200ULL // bit   9
-#define ldlm_is_intent_only(_l)         LDLM_TEST_FLAG(( _l), 1ULL <<  9)
-#define ldlm_set_intent_only(_l)        LDLM_SET_FLAG((  _l), 1ULL <<  9)
+#define LDLM_FL_INTENT_ONLY             0x0000000000000200ULL /* bit 9 */
+#define ldlm_is_intent_only(_l)         LDLM_TEST_FLAG((_l), 1ULL <<  9)
+#define ldlm_set_intent_only(_l)        LDLM_SET_FLAG((_l), 1ULL <<  9)
 #define ldlm_clear_intent_only(_l)      LDLM_CLEAR_FLAG((_l), 1ULL <<  9)
 
 /** lock request has intent */
-#define LDLM_FL_HAS_INTENT              0x0000000000001000ULL // bit  12
-#define ldlm_is_has_intent(_l)          LDLM_TEST_FLAG(( _l), 1ULL << 12)
-#define ldlm_set_has_intent(_l)         LDLM_SET_FLAG((  _l), 1ULL << 12)
+#define LDLM_FL_HAS_INTENT              0x0000000000001000ULL /* bit 12 */
+#define ldlm_is_has_intent(_l)          LDLM_TEST_FLAG((_l), 1ULL << 12)
+#define ldlm_set_has_intent(_l)         LDLM_SET_FLAG((_l), 1ULL << 12)
 #define ldlm_clear_has_intent(_l)       LDLM_CLEAR_FLAG((_l), 1ULL << 12)
 
 /** flock deadlock detected */
 #define ldlm_clear_flock_deadlock(_l)   LDLM_CLEAR_FLAG((_l), 1ULL << 15)
 
 /** discard (no writeback) on cancel */
-#define LDLM_FL_DISCARD_DATA            0x0000000000010000ULL // bit  16
-#define ldlm_is_discard_data(_l)        LDLM_TEST_FLAG(( _l), 1ULL << 16)
-#define ldlm_set_discard_data(_l)       LDLM_SET_FLAG((  _l), 1ULL << 16)
+#define LDLM_FL_DISCARD_DATA            0x0000000000010000ULL /* bit 16 */
+#define ldlm_is_discard_data(_l)        LDLM_TEST_FLAG((_l), 1ULL << 16)
+#define ldlm_set_discard_data(_l)       LDLM_SET_FLAG((_l), 1ULL << 16)
 #define ldlm_clear_discard_data(_l)     LDLM_CLEAR_FLAG((_l), 1ULL << 16)
 
 /** Blocked by group lock - wait indefinitely */
-#define LDLM_FL_NO_TIMEOUT              0x0000000000020000ULL // bit  17
-#define ldlm_is_no_timeout(_l)          LDLM_TEST_FLAG(( _l), 1ULL << 17)
-#define ldlm_set_no_timeout(_l)         LDLM_SET_FLAG((  _l), 1ULL << 17)
+#define LDLM_FL_NO_TIMEOUT              0x0000000000020000ULL /* bit 17 */
+#define ldlm_is_no_timeout(_l)          LDLM_TEST_FLAG((_l), 1ULL << 17)
+#define ldlm_set_no_timeout(_l)         LDLM_SET_FLAG((_l), 1ULL << 17)
 #define ldlm_clear_no_timeout(_l)       LDLM_CLEAR_FLAG((_l), 1ULL << 17)
 
 /**
  * Server told not to wait if blocked. For AGL, OST will not send glimpse
  * callback. */
-#define LDLM_FL_BLOCK_NOWAIT            0x0000000000040000ULL // bit  18
-#define ldlm_is_block_nowait(_l)        LDLM_TEST_FLAG(( _l), 1ULL << 18)
-#define ldlm_set_block_nowait(_l)       LDLM_SET_FLAG((  _l), 1ULL << 18)
+#define LDLM_FL_BLOCK_NOWAIT            0x0000000000040000ULL /* bit 18 */
+#define ldlm_is_block_nowait(_l)        LDLM_TEST_FLAG((_l), 1ULL << 18)
+#define ldlm_set_block_nowait(_l)       LDLM_SET_FLAG((_l), 1ULL << 18)
 #define ldlm_clear_block_nowait(_l)     LDLM_CLEAR_FLAG((_l), 1ULL << 18)
 
 /** return blocking lock */
-#define LDLM_FL_TEST_LOCK               0x0000000000080000ULL // bit  19
-#define ldlm_is_test_lock(_l)           LDLM_TEST_FLAG(( _l), 1ULL << 19)
-#define ldlm_set_test_lock(_l)          LDLM_SET_FLAG((  _l), 1ULL << 19)
+#define LDLM_FL_TEST_LOCK               0x0000000000080000ULL /* bit 19 */
+#define ldlm_is_test_lock(_l)           LDLM_TEST_FLAG((_l), 1ULL << 19)
+#define ldlm_set_test_lock(_l)          LDLM_SET_FLAG((_l), 1ULL << 19)
 #define ldlm_clear_test_lock(_l)        LDLM_CLEAR_FLAG((_l), 1ULL << 19)
 
 /**
  * cancel notification to original lock holder, but expect no reply. This
  * is for clients (like liblustre) that cannot be expected to reliably
  * response to blocking AST. */
-#define LDLM_FL_CANCEL_ON_BLOCK         0x0000000000800000ULL // bit  23
-#define ldlm_is_cancel_on_block(_l)     LDLM_TEST_FLAG(( _l), 1ULL << 23)
-#define ldlm_set_cancel_on_block(_l)    LDLM_SET_FLAG((  _l), 1ULL << 23)
+#define LDLM_FL_CANCEL_ON_BLOCK         0x0000000000800000ULL /* bit 23 */
+#define ldlm_is_cancel_on_block(_l)     LDLM_TEST_FLAG((_l), 1ULL << 23)
+#define ldlm_set_cancel_on_block(_l)    LDLM_SET_FLAG((_l), 1ULL << 23)
 #define ldlm_clear_cancel_on_block(_l)  LDLM_CLEAR_FLAG((_l), 1ULL << 23)
 
 /**
  * measure lock contention and return -EUSERS if locking contention is high */
-#define LDLM_FL_DENY_ON_CONTENTION        0x0000000040000000ULL // bit  30
-#define ldlm_is_deny_on_contention(_l)    LDLM_TEST_FLAG(( _l), 1ULL << 30)
-#define ldlm_set_deny_on_contention(_l)   LDLM_SET_FLAG((  _l), 1ULL << 30)
+#define LDLM_FL_DENY_ON_CONTENTION        0x0000000040000000ULL /* bit 30 */
+#define ldlm_is_deny_on_contention(_l)    LDLM_TEST_FLAG((_l), 1ULL << 30)
+#define ldlm_set_deny_on_contention(_l)   LDLM_SET_FLAG((_l), 1ULL << 30)
 #define ldlm_clear_deny_on_contention(_l) LDLM_CLEAR_FLAG((_l), 1ULL << 30)
 
 /**
  * These are flags that are mapped into the flags and ASTs of blocking
  * locks Add FL_DISCARD to blocking ASTs */
-#define LDLM_FL_AST_DISCARD_DATA        0x0000000080000000ULL // bit  31
-#define ldlm_is_ast_discard_data(_l)    LDLM_TEST_FLAG(( _l), 1ULL << 31)
-#define ldlm_set_ast_discard_data(_l)   LDLM_SET_FLAG((  _l), 1ULL << 31)
+#define LDLM_FL_AST_DISCARD_DATA        0x0000000080000000ULL /* bit 31 */
+#define ldlm_is_ast_discard_data(_l)    LDLM_TEST_FLAG((_l), 1ULL << 31)
+#define ldlm_set_ast_discard_data(_l)   LDLM_SET_FLAG((_l), 1ULL << 31)
 #define ldlm_clear_ast_discard_data(_l) LDLM_CLEAR_FLAG((_l), 1ULL << 31)
 
 /**
  * Used for marking lock as a target for -EINTR while cp_ast sleep emulation
  * + race with upcoming bl_ast. */
-#define LDLM_FL_FAIL_LOC                0x0000000100000000ULL // bit  32
-#define ldlm_is_fail_loc(_l)            LDLM_TEST_FLAG(( _l), 1ULL << 32)
-#define ldlm_set_fail_loc(_l)           LDLM_SET_FLAG((  _l), 1ULL << 32)
+#define LDLM_FL_FAIL_LOC                0x0000000100000000ULL /* bit 32 */
+#define ldlm_is_fail_loc(_l)            LDLM_TEST_FLAG((_l), 1ULL << 32)
+#define ldlm_set_fail_loc(_l)           LDLM_SET_FLAG((_l), 1ULL << 32)
 #define ldlm_clear_fail_loc(_l)         LDLM_CLEAR_FLAG((_l), 1ULL << 32)
 
 /**
  * Used while processing the unused list to know that we have already
  * handled this lock and decided to skip it. */
-#define LDLM_FL_SKIPPED                 0x0000000200000000ULL // bit  33
-#define ldlm_is_skipped(_l)             LDLM_TEST_FLAG(( _l), 1ULL << 33)
-#define ldlm_set_skipped(_l)            LDLM_SET_FLAG((  _l), 1ULL << 33)
+#define LDLM_FL_SKIPPED                 0x0000000200000000ULL /* bit 33 */
+#define ldlm_is_skipped(_l)             LDLM_TEST_FLAG((_l), 1ULL << 33)
+#define ldlm_set_skipped(_l)            LDLM_SET_FLAG((_l), 1ULL << 33)
 #define ldlm_clear_skipped(_l)          LDLM_CLEAR_FLAG((_l), 1ULL << 33)
 
 /** this lock is being destroyed */
-#define LDLM_FL_CBPENDING               0x0000000400000000ULL // bit  34
-#define ldlm_is_cbpending(_l)           LDLM_TEST_FLAG(( _l), 1ULL << 34)
-#define ldlm_set_cbpending(_l)          LDLM_SET_FLAG((  _l), 1ULL << 34)
+#define LDLM_FL_CBPENDING               0x0000000400000000ULL /* bit 34 */
+#define ldlm_is_cbpending(_l)           LDLM_TEST_FLAG((_l), 1ULL << 34)
+#define ldlm_set_cbpending(_l)          LDLM_SET_FLAG((_l), 1ULL << 34)
 #define ldlm_clear_cbpending(_l)        LDLM_CLEAR_FLAG((_l), 1ULL << 34)
 
 /** not a real flag, not saved in lock */
-#define LDLM_FL_WAIT_NOREPROC           0x0000000800000000ULL // bit  35
-#define ldlm_is_wait_noreproc(_l)       LDLM_TEST_FLAG(( _l), 1ULL << 35)
-#define ldlm_set_wait_noreproc(_l)      LDLM_SET_FLAG((  _l), 1ULL << 35)
+#define LDLM_FL_WAIT_NOREPROC           0x0000000800000000ULL /* bit 35 */
+#define ldlm_is_wait_noreproc(_l)       LDLM_TEST_FLAG((_l), 1ULL << 35)
+#define ldlm_set_wait_noreproc(_l)      LDLM_SET_FLAG((_l), 1ULL << 35)
 #define ldlm_clear_wait_noreproc(_l)    LDLM_CLEAR_FLAG((_l), 1ULL << 35)
 
 /** cancellation callback already run */
-#define LDLM_FL_CANCEL                  0x0000001000000000ULL // bit  36
-#define ldlm_is_cancel(_l)              LDLM_TEST_FLAG(( _l), 1ULL << 36)
-#define ldlm_set_cancel(_l)             LDLM_SET_FLAG((  _l), 1ULL << 36)
+#define LDLM_FL_CANCEL                  0x0000001000000000ULL /* bit 36 */
+#define ldlm_is_cancel(_l)              LDLM_TEST_FLAG((_l), 1ULL << 36)
+#define ldlm_set_cancel(_l)             LDLM_SET_FLAG((_l), 1ULL << 36)
 #define ldlm_clear_cancel(_l)           LDLM_CLEAR_FLAG((_l), 1ULL << 36)
 
 /** whatever it might mean */
-#define LDLM_FL_LOCAL_ONLY              0x0000002000000000ULL // bit  37
-#define ldlm_is_local_only(_l)          LDLM_TEST_FLAG(( _l), 1ULL << 37)
-#define ldlm_set_local_only(_l)         LDLM_SET_FLAG((  _l), 1ULL << 37)
+#define LDLM_FL_LOCAL_ONLY              0x0000002000000000ULL /* bit 37 */
+#define ldlm_is_local_only(_l)          LDLM_TEST_FLAG((_l), 1ULL << 37)
+#define ldlm_set_local_only(_l)         LDLM_SET_FLAG((_l), 1ULL << 37)
 #define ldlm_clear_local_only(_l)       LDLM_CLEAR_FLAG((_l), 1ULL << 37)
 
 /** don't run the cancel callback under ldlm_cli_cancel_unused */
-#define LDLM_FL_FAILED                  0x0000004000000000ULL // bit  38
-#define ldlm_is_failed(_l)              LDLM_TEST_FLAG(( _l), 1ULL << 38)
-#define ldlm_set_failed(_l)             LDLM_SET_FLAG((  _l), 1ULL << 38)
+#define LDLM_FL_FAILED                  0x0000004000000000ULL /* bit 38 */
+#define ldlm_is_failed(_l)              LDLM_TEST_FLAG((_l), 1ULL << 38)
+#define ldlm_set_failed(_l)             LDLM_SET_FLAG((_l), 1ULL << 38)
 #define ldlm_clear_failed(_l)           LDLM_CLEAR_FLAG((_l), 1ULL << 38)
 
 /** lock cancel has already been sent */
-#define LDLM_FL_CANCELING               0x0000008000000000ULL // bit  39
-#define ldlm_is_canceling(_l)           LDLM_TEST_FLAG(( _l), 1ULL << 39)
-#define ldlm_set_canceling(_l)          LDLM_SET_FLAG((  _l), 1ULL << 39)
+#define LDLM_FL_CANCELING               0x0000008000000000ULL /* bit 39 */
+#define ldlm_is_canceling(_l)           LDLM_TEST_FLAG((_l), 1ULL << 39)
+#define ldlm_set_canceling(_l)          LDLM_SET_FLAG((_l), 1ULL << 39)
 #define ldlm_clear_canceling(_l)        LDLM_CLEAR_FLAG((_l), 1ULL << 39)
 
 /** local lock (ie, no srv/cli split) */
-#define LDLM_FL_LOCAL                   0x0000010000000000ULL // bit  40
-#define ldlm_is_local(_l)               LDLM_TEST_FLAG(( _l), 1ULL << 40)
-#define ldlm_set_local(_l)              LDLM_SET_FLAG((  _l), 1ULL << 40)
+#define LDLM_FL_LOCAL                   0x0000010000000000ULL /* bit 40 */
+#define ldlm_is_local(_l)               LDLM_TEST_FLAG((_l), 1ULL << 40)
+#define ldlm_set_local(_l)              LDLM_SET_FLAG((_l), 1ULL << 40)
 #define ldlm_clear_local(_l)            LDLM_CLEAR_FLAG((_l), 1ULL << 40)
 
 /**
  * which can be replaced with a LVB-aware wrapping function for OSC locks.
  * That change is pretty high-risk, though, and would need a lot more
  * testing. */
-#define LDLM_FL_LVB_READY               0x0000020000000000ULL // bit  41
-#define ldlm_is_lvb_ready(_l)           LDLM_TEST_FLAG(( _l), 1ULL << 41)
-#define ldlm_set_lvb_ready(_l)          LDLM_SET_FLAG((  _l), 1ULL << 41)
+#define LDLM_FL_LVB_READY               0x0000020000000000ULL /* bit 41 */
+#define ldlm_is_lvb_ready(_l)           LDLM_TEST_FLAG((_l), 1ULL << 41)
+#define ldlm_set_lvb_ready(_l)          LDLM_SET_FLAG((_l), 1ULL << 41)
 #define ldlm_clear_lvb_ready(_l)        LDLM_CLEAR_FLAG((_l), 1ULL << 41)
 
 /**
  * Threads racing to update the KMS after performing their writeback need
  * to know to exclude each other's locks from the calculation as they walk
  * the granted list. */
-#define LDLM_FL_KMS_IGNORE              0x0000040000000000ULL // bit  42
-#define ldlm_is_kms_ignore(_l)          LDLM_TEST_FLAG(( _l), 1ULL << 42)
-#define ldlm_set_kms_ignore(_l)         LDLM_SET_FLAG((  _l), 1ULL << 42)
+#define LDLM_FL_KMS_IGNORE              0x0000040000000000ULL /* bit 42 */
+#define ldlm_is_kms_ignore(_l)          LDLM_TEST_FLAG((_l), 1ULL << 42)
+#define ldlm_set_kms_ignore(_l)         LDLM_SET_FLAG((_l), 1ULL << 42)
 #define ldlm_clear_kms_ignore(_l)       LDLM_CLEAR_FLAG((_l), 1ULL << 42)
 
 /** completion AST to be executed */
-#define LDLM_FL_CP_REQD                 0x0000080000000000ULL // bit  43
-#define ldlm_is_cp_reqd(_l)             LDLM_TEST_FLAG(( _l), 1ULL << 43)
-#define ldlm_set_cp_reqd(_l)            LDLM_SET_FLAG((  _l), 1ULL << 43)
+#define LDLM_FL_CP_REQD                 0x0000080000000000ULL /* bit 43 */
+#define ldlm_is_cp_reqd(_l)             LDLM_TEST_FLAG((_l), 1ULL << 43)
+#define ldlm_set_cp_reqd(_l)            LDLM_SET_FLAG((_l), 1ULL << 43)
 #define ldlm_clear_cp_reqd(_l)          LDLM_CLEAR_FLAG((_l), 1ULL << 43)
 
 /** cleanup_resource has already handled the lock */
-#define LDLM_FL_CLEANED                 0x0000100000000000ULL // bit  44
-#define ldlm_is_cleaned(_l)             LDLM_TEST_FLAG(( _l), 1ULL << 44)
-#define ldlm_set_cleaned(_l)            LDLM_SET_FLAG((  _l), 1ULL << 44)
+#define LDLM_FL_CLEANED                 0x0000100000000000ULL /* bit 44 */
+#define ldlm_is_cleaned(_l)             LDLM_TEST_FLAG((_l), 1ULL << 44)
+#define ldlm_set_cleaned(_l)            LDLM_SET_FLAG((_l), 1ULL << 44)
 #define ldlm_clear_cleaned(_l)          LDLM_CLEAR_FLAG((_l), 1ULL << 44)
 
 /**
  * optimization hint: LDLM can run blocking callback from current context
  * w/o involving separate thread. in order to decrease cs rate */
-#define LDLM_FL_ATOMIC_CB               0x0000200000000000ULL // bit  45
-#define ldlm_is_atomic_cb(_l)           LDLM_TEST_FLAG(( _l), 1ULL << 45)
-#define ldlm_set_atomic_cb(_l)          LDLM_SET_FLAG((  _l), 1ULL << 45)
+#define LDLM_FL_ATOMIC_CB               0x0000200000000000ULL /* bit 45 */
+#define ldlm_is_atomic_cb(_l)           LDLM_TEST_FLAG((_l), 1ULL << 45)
+#define ldlm_set_atomic_cb(_l)          LDLM_SET_FLAG((_l), 1ULL << 45)
 #define ldlm_clear_atomic_cb(_l)        LDLM_CLEAR_FLAG((_l), 1ULL << 45)
 
 /**
  * dropped to let ldlm_callback_handler() return EINVAL to the server. It
  * is used when ELC RPC is already prepared and is waiting for rpc_lock,
  * too late to send a separate CANCEL RPC. */
-#define LDLM_FL_BL_AST                  0x0000400000000000ULL // bit  46
-#define ldlm_is_bl_ast(_l)              LDLM_TEST_FLAG(( _l), 1ULL << 46)
-#define ldlm_set_bl_ast(_l)             LDLM_SET_FLAG((  _l), 1ULL << 46)
+#define LDLM_FL_BL_AST                  0x0000400000000000ULL /* bit 46 */
+#define ldlm_is_bl_ast(_l)              LDLM_TEST_FLAG((_l), 1ULL << 46)
+#define ldlm_set_bl_ast(_l)             LDLM_SET_FLAG((_l), 1ULL << 46)
 #define ldlm_clear_bl_ast(_l)           LDLM_CLEAR_FLAG((_l), 1ULL << 46)
 
 /** whatever it might mean */
-#define LDLM_FL_BL_DONE                 0x0000800000000000ULL // bit  47
-#define ldlm_is_bl_done(_l)             LDLM_TEST_FLAG(( _l), 1ULL << 47)
-#define ldlm_set_bl_done(_l)            LDLM_SET_FLAG((  _l), 1ULL << 47)
+#define LDLM_FL_BL_DONE                 0x0000800000000000ULL /* bit 47 */
+#define ldlm_is_bl_done(_l)             LDLM_TEST_FLAG((_l), 1ULL << 47)
+#define ldlm_set_bl_done(_l)            LDLM_SET_FLAG((_l), 1ULL << 47)
 #define ldlm_clear_bl_done(_l)          LDLM_CLEAR_FLAG((_l), 1ULL << 47)
 
 /**
  * Don't put lock into the LRU list, so that it is not canceled due
  * to aging.  Used by MGC locks, they are cancelled only at unmount or
  * by callback. */
-#define LDLM_FL_NO_LRU                  0x0001000000000000ULL // bit  48
-#define ldlm_is_no_lru(_l)              LDLM_TEST_FLAG(( _l), 1ULL << 48)
-#define ldlm_set_no_lru(_l)             LDLM_SET_FLAG((  _l), 1ULL << 48)
+#define LDLM_FL_NO_LRU                  0x0001000000000000ULL /* bit 48 */
+#define ldlm_is_no_lru(_l)              LDLM_TEST_FLAG((_l), 1ULL << 48)
+#define ldlm_set_no_lru(_l)             LDLM_SET_FLAG((_l), 1ULL << 48)
 #define ldlm_clear_no_lru(_l)           LDLM_CLEAR_FLAG((_l), 1ULL << 48)
 
 /**
  * Set for locks that failed and where the server has been notified.
  *
  * Protected by lock and resource locks. */
-#define LDLM_FL_FAIL_NOTIFIED           0x0002000000000000ULL // bit  49
-#define ldlm_is_fail_notified(_l)       LDLM_TEST_FLAG(( _l), 1ULL << 49)
-#define ldlm_set_fail_notified(_l)      LDLM_SET_FLAG((  _l), 1ULL << 49)
+#define LDLM_FL_FAIL_NOTIFIED           0x0002000000000000ULL /* bit 49 */
+#define ldlm_is_fail_notified(_l)       LDLM_TEST_FLAG((_l), 1ULL << 49)
+#define ldlm_set_fail_notified(_l)      LDLM_SET_FLAG((_l), 1ULL << 49)
 #define ldlm_clear_fail_notified(_l)    LDLM_CLEAR_FLAG((_l), 1ULL << 49)
 
 /**
  * ldlm_lock_destroy_internal().
  *
  * Protected by lock and resource locks. */
-#define LDLM_FL_DESTROYED               0x0004000000000000ULL // bit  50
-#define ldlm_is_destroyed(_l)           LDLM_TEST_FLAG(( _l), 1ULL << 50)
-#define ldlm_set_destroyed(_l)          LDLM_SET_FLAG((  _l), 1ULL << 50)
+#define LDLM_FL_DESTROYED               0x0004000000000000ULL /* bit 50 */
+#define ldlm_is_destroyed(_l)           LDLM_TEST_FLAG((_l), 1ULL << 50)
+#define ldlm_set_destroyed(_l)          LDLM_SET_FLAG((_l), 1ULL << 50)
 #define ldlm_clear_destroyed(_l)        LDLM_CLEAR_FLAG((_l), 1ULL << 50)
 
 /** flag whether this is a server namespace lock */
-#define LDLM_FL_SERVER_LOCK             0x0008000000000000ULL // bit  51
-#define ldlm_is_server_lock(_l)         LDLM_TEST_FLAG(( _l), 1ULL << 51)
-#define ldlm_set_server_lock(_l)        LDLM_SET_FLAG((  _l), 1ULL << 51)
+#define LDLM_FL_SERVER_LOCK             0x0008000000000000ULL /* bit 51 */
+#define ldlm_is_server_lock(_l)         LDLM_TEST_FLAG((_l), 1ULL << 51)
+#define ldlm_set_server_lock(_l)        LDLM_SET_FLAG((_l), 1ULL << 51)
 #define ldlm_clear_server_lock(_l)      LDLM_CLEAR_FLAG((_l), 1ULL << 51)
 
 /**
  * Also, spin_is_locked() is deprecated for kernel code; one reason is
  * because it works only for SMP so user needs to add extra macros like
  * LASSERT_SPIN_LOCKED for uniprocessor kernels. */
-#define LDLM_FL_RES_LOCKED              0x0010000000000000ULL // bit  52
-#define ldlm_is_res_locked(_l)          LDLM_TEST_FLAG(( _l), 1ULL << 52)
-#define ldlm_set_res_locked(_l)         LDLM_SET_FLAG((  _l), 1ULL << 52)
+#define LDLM_FL_RES_LOCKED              0x0010000000000000ULL /* bit 52 */
+#define ldlm_is_res_locked(_l)          LDLM_TEST_FLAG((_l), 1ULL << 52)
+#define ldlm_set_res_locked(_l)         LDLM_SET_FLAG((_l), 1ULL << 52)
 #define ldlm_clear_res_locked(_l)       LDLM_CLEAR_FLAG((_l), 1ULL << 52)
 
 /**
  * lock-timeout timer and it will never be reset.
  *
  * Protected by lock and resource locks. */
-#define LDLM_FL_WAITED                  0x0020000000000000ULL // bit  53
-#define ldlm_is_waited(_l)              LDLM_TEST_FLAG(( _l), 1ULL << 53)
-#define ldlm_set_waited(_l)             LDLM_SET_FLAG((  _l), 1ULL << 53)
+#define LDLM_FL_WAITED                  0x0020000000000000ULL /* bit 53 */
+#define ldlm_is_waited(_l)              LDLM_TEST_FLAG((_l), 1ULL << 53)
+#define ldlm_set_waited(_l)             LDLM_SET_FLAG((_l), 1ULL << 53)
 #define ldlm_clear_waited(_l)           LDLM_CLEAR_FLAG((_l), 1ULL << 53)
 
 /** Flag whether this is a server namespace lock. */
-#define LDLM_FL_NS_SRV                  0x0040000000000000ULL // bit  54
-#define ldlm_is_ns_srv(_l)              LDLM_TEST_FLAG(( _l), 1ULL << 54)
-#define ldlm_set_ns_srv(_l)             LDLM_SET_FLAG((  _l), 1ULL << 54)
+#define LDLM_FL_NS_SRV                  0x0040000000000000ULL /* bit 54 */
+#define ldlm_is_ns_srv(_l)              LDLM_TEST_FLAG((_l), 1ULL << 54)
+#define ldlm_set_ns_srv(_l)             LDLM_SET_FLAG((_l), 1ULL << 54)
 #define ldlm_clear_ns_srv(_l)           LDLM_CLEAR_FLAG((_l), 1ULL << 54)
 
 /** Flag whether this lock can be reused. Used by exclusive open. */
index 0f8f76c43ee1771173455fdbf1f6d38435a3dd7b..fee4d2c75506d528d2bafea196d92c5c5269c1db 100644 (file)
@@ -70,7 +70,6 @@ typedef struct {
 #define CFS_ACL_XATTR_COUNT(size, prefix) \
        (((size) - sizeof(prefix ## _header)) / sizeof(prefix ## _entry))
 
-
 extern ext_acl_xattr_header *
 lustre_posix_acl_xattr_2ext(posix_acl_xattr_header *header, int size);
 extern int
@@ -80,10 +79,6 @@ extern void
 lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size);
 extern void
 lustre_ext_acl_xattr_free(ext_acl_xattr_header *header);
-extern int
-lustre_acl_xattr_merge2posix(posix_acl_xattr_header *posix_header, int size,
-                            ext_acl_xattr_header *ext_header,
-                            posix_acl_xattr_header **out);
 extern ext_acl_xattr_header *
 lustre_acl_xattr_merge2ext(posix_acl_xattr_header *posix_header, int size,
                           ext_acl_xattr_header *ext_header);
index 5189fad0b73cb3b146383f43837c30a175fcb2ff..1daf4c572415c246fcf294155ed4a74812952ac4 100644 (file)
@@ -147,14 +147,6 @@ struct obd_export {
        /** To link all exports on an obd device */
        struct list_head                exp_obd_chain;
        struct hlist_node         exp_uuid_hash; /** uuid-export hash*/
-       struct hlist_node         exp_nid_hash; /** nid-export hash */
-       /**
-        * All exports eligible for ping evictor are linked into a list
-        * through this field in "most time since last request on this export"
-        * order
-        * protected by obd_dev_lock
-        */
-       struct list_head                exp_obd_chain_timed;
        /** Obd device of this export */
        struct obd_device       *exp_obd;
        /**
@@ -179,8 +171,6 @@ struct obd_export {
        spinlock_t                exp_uncommitted_replies_lock;
        /** Last committed transno for this export */
        __u64                exp_last_committed;
-       /** When was last request received */
-       unsigned long           exp_last_request_time;
        /** On replay all requests waiting for replay are linked here */
        struct list_head                exp_req_replay_queue;
        /**
@@ -193,30 +183,15 @@ struct obd_export {
        struct obd_connect_data   exp_connect_data;
        enum obd_option    exp_flags;
        unsigned long        exp_failed:1,
-                                 exp_in_recovery:1,
                                  exp_disconnected:1,
                                  exp_connecting:1,
-                                 /** VBR: export missed recovery */
-                                 exp_delayed:1,
-                                 /** VBR: failed version checking */
-                                 exp_vbr_failed:1,
-                                 exp_req_replay_needed:1,
-                                 exp_lock_replay_needed:1,
-                                 exp_need_sync:1,
                                  exp_flvr_changed:1,
-                                 exp_flvr_adapt:1,
-                                 exp_libclient:1, /* liblustre client? */
-                                 /* client timed out and tried to reconnect,
-                                  * but couldn't because of active rpcs */
-                                 exp_abort_active_req:1,
-                                 /* if to swap nidtbl entries for 2.2 clients.
-                                  * Only used by the MGS to fix LU-1644. */
-                                 exp_need_mne_swab:1;
+                                 exp_flvr_adapt:1;
        /* also protected by exp_lock */
        enum lustre_sec_part      exp_sp_peer;
        struct sptlrpc_flavor     exp_flvr;          /* current */
        struct sptlrpc_flavor     exp_flvr_old[2];      /* about-to-expire */
-       unsigned long           exp_flvr_expire[2];   /* seconds */
+       time64_t                  exp_flvr_expire[2];   /* seconds */
 
        /** protects exp_hp_rpcs */
        spinlock_t                exp_rpc_lock;
@@ -265,13 +240,6 @@ static inline int exp_connect_multibulk(struct obd_export *exp)
        return exp_max_brw_size(exp) > ONE_MB_BRW_SIZE;
 }
 
-static inline int exp_expired(struct obd_export *exp, long age)
-{
-       LASSERT(exp->exp_delayed);
-       return time_before(cfs_time_add(exp->exp_last_request_time, age),
-                          get_seconds());
-}
-
 static inline int exp_connect_cancelset(struct obd_export *exp)
 {
        LASSERT(exp != NULL);
@@ -369,7 +337,6 @@ static inline bool imp_connect_disp_stripe(struct obd_import *imp)
 }
 
 struct obd_export *class_conn2export(struct lustre_handle *conn);
-struct obd_device *class_conn2obd(struct lustre_handle *conn);
 
 /** @} export */
 
index c7c8fe4cdbcc6a0d252c8b6874f7b0cb131e5d13..47c3f375024094a585e6adaa99464548409b911c 100644 (file)
@@ -330,8 +330,6 @@ enum lu_mgr_type {
        LUSTRE_SEQ_CONTROLLER
 };
 
-struct lu_server_seq;
-
 /* Client sequence manager interface. */
 struct lu_client_seq {
        /* Sequence-controller export. */
@@ -366,108 +364,16 @@ struct lu_client_seq {
         */
        __u64              lcs_width;
 
-       /* Seq-server for direct talking */
-       struct lu_server_seq   *lcs_srv;
-
        /* wait queue for fid allocation and update indicator */
        wait_queue_head_t            lcs_waitq;
        int                  lcs_update;
 };
 
-/* server sequence manager interface */
-struct lu_server_seq {
-       /* Available sequences space */
-       struct lu_seq_range      lss_space;
-
-       /* keeps highwater in lsr_end for seq allocation algorithm */
-       struct lu_seq_range      lss_lowater_set;
-       struct lu_seq_range      lss_hiwater_set;
-
-       /*
-        * Device for server side seq manager needs (saving sequences to backing
-        * store).
-        */
-       struct dt_device       *lss_dev;
-
-       /* /seq file object device */
-       struct dt_object       *lss_obj;
-
-       /* LUSTRE_SEQ_SERVER or LUSTRE_SEQ_CONTROLLER */
-       enum lu_mgr_type       lss_type;
-
-       /* Client interface to request controller */
-       struct lu_client_seq   *lss_cli;
-
-       /* Mutex for protecting allocation */
-       struct mutex            lss_mutex;
-
-       /*
-        * Service uuid, passed from MDT + seq name to form unique seq name to
-        * use it with procfs.
-        */
-       char                lss_name[LUSTRE_MDT_MAXNAMELEN];
-
-       /*
-        * Allocation chunks for super and meta sequences. Default values are
-        * LUSTRE_SEQ_SUPER_WIDTH and LUSTRE_SEQ_META_WIDTH.
-        */
-       __u64              lss_width;
-
-       /*
-        * minimum lss_alloc_set size that should be allocated from
-        * lss_space
-        */
-       __u64              lss_set_width;
-
-       /* sync is needed for update operation */
-       __u32              lss_need_sync;
-
-       /**
-        * Pointer to site object, required to access site fld.
-        */
-       struct seq_server_site  *lss_site;
-};
-
-/* Server methods */
-
-int seq_server_init(struct lu_server_seq *seq,
-                   struct dt_device *dev,
-                   const char *prefix,
-                   enum lu_mgr_type type,
-                   struct seq_server_site *ss,
-                   const struct lu_env *env);
-
-void seq_server_fini(struct lu_server_seq *seq,
-                    const struct lu_env *env);
-
-int seq_server_alloc_super(struct lu_server_seq *seq,
-                          struct lu_seq_range *out,
-                          const struct lu_env *env);
-
-int seq_server_alloc_meta(struct lu_server_seq *seq,
-                         struct lu_seq_range *out,
-                         const struct lu_env *env);
-
-int seq_server_set_cli(struct lu_server_seq *seq,
-                      struct lu_client_seq *cli,
-                      const struct lu_env *env);
-
 /* Client methods */
-int seq_client_init(struct lu_client_seq *seq,
-                   struct obd_export *exp,
-                   enum lu_cli_type type,
-                   const char *prefix,
-                   struct lu_server_seq *srv);
-
-void seq_client_fini(struct lu_client_seq *seq);
-
 void seq_client_flush(struct lu_client_seq *seq);
 
 int seq_client_alloc_fid(const struct lu_env *env, struct lu_client_seq *seq,
                         struct lu_fid *fid);
-int seq_client_get_seq(const struct lu_env *env, struct lu_client_seq *seq,
-                      u64 *seqnr);
-int seq_site_fini(const struct lu_env *env, struct seq_server_site *ss);
 /* Fids common stuff */
 int fid_is_local(const struct lu_env *env,
                 struct lu_site *site, const struct lu_fid *fid);
@@ -626,6 +532,7 @@ static inline void ost_fid_build_resid(const struct lu_fid *fid,
 {
        if (fid_is_mdt0(fid) || fid_is_idif(fid)) {
                struct ost_id oi;
+
                oi.oi.oi_id = 0; /* gcc 4.7.2 complains otherwise */
                if (fid_to_ostid(fid, &oi) != 0)
                        return;
@@ -641,6 +548,7 @@ static inline void ost_fid_from_resid(struct lu_fid *fid,
        if (fid_seq_is_mdt0(name->name[LUSTRE_RES_ID_VER_OID_OFF])) {
                /* old resid */
                struct ost_id oi;
+
                ostid_set_seq(&oi, name->name[LUSTRE_RES_ID_VER_OID_OFF]);
                ostid_set_id(&oi, name->name[LUSTRE_RES_ID_SEQ_OFF]);
                ostid_to_fid(fid, &oi, 0);
index c1f08dee3bd6616d704953c69bc664d19a227339..d8b3db9cdebaa950e8cbcda2a802e780010900f0 100644 (file)
@@ -61,7 +61,6 @@ enum {
        LUSTRE_CLI_FLD_HASH_RRB
 };
 
-
 struct lu_fld_target {
        struct list_head               ft_chain;
        struct obd_export       *ft_exp;
@@ -70,10 +69,6 @@ struct lu_fld_target {
 };
 
 struct lu_server_fld {
-       /**
-        * /fld file object device */
-       struct dt_object        *lsf_obj;
-
        /**
         * super sequence controller export, needed to forward fld
         * lookup  request. */
index f3ae02b3eef3efaec9ac46a7784cb8725ad36458..49dfbb14f381a8f591a0166a5faee76cf749f7f7 100644 (file)
@@ -47,7 +47,6 @@ struct obd_export;
 struct obd_device;
 struct ptlrpc_request;
 
-
 int ptlrpc_replay(struct obd_import *imp);
 int ptlrpc_resend(struct obd_import *imp);
 void ptlrpc_free_committed(struct obd_import *imp);
index 726bbd3eaf556c563430b5000489fb92c4f2c469..f39780ae4c8a9fc6042d7e20e202530089ac8e5e 100644 (file)
@@ -50,7 +50,6 @@
 
 #include "../../include/linux/libcfs/libcfs.h"
 
-
 struct portals_handle_ops {
        void (*hop_addref)(void *object);
        void (*hop_free)(void *object, int size);
@@ -78,6 +77,7 @@ struct portals_handle {
        unsigned int                    h_size:31;
        unsigned int                    h_in:1;
 };
+
 #define RCU2HANDLE(rcu)    container_of(rcu, struct portals_handle, h_rcu)
 
 /* handles.c */
@@ -86,7 +86,6 @@ struct portals_handle {
 void class_handle_hash(struct portals_handle *,
                       struct portals_handle_ops *ops);
 void class_handle_unhash(struct portals_handle *);
-void class_handle_hash_back(struct portals_handle *);
 void *class_handle2object(__u64 cookie);
 void class_handle_free_cb(struct rcu_head *rcu);
 int class_handle_init(void);
index 5a38f3d5e011e522e12792be1afa666ba00a99d1..4e4230e94c11ccd7b4c0c5cabacaef58ec0f849f 100644 (file)
@@ -50,7 +50,6 @@
 #include "lustre_handles.h"
 #include "lustre/lustre_idl.h"
 
-
 /**
  * Adaptive Timeout stuff
  *
 #define AT_FLG_NOHIST 0x1        /* use last reported value only */
 
 struct adaptive_timeout {
-       time_t          at_binstart;     /* bin start time */
+       time64_t        at_binstart;     /* bin start time */
        unsigned int    at_hist[AT_BINS];    /* timeout history bins */
        unsigned int    at_flags;
        unsigned int    at_current;       /* current timeout value */
        unsigned int    at_worst_ever;       /* worst-ever timeout value */
-       time_t          at_worst_time;       /* worst-ever timeout timestamp */
+       time64_t        at_worst_time;       /* worst-ever timeout timestamp */
        spinlock_t      at_lock;
 };
 
@@ -74,7 +73,7 @@ struct ptlrpc_at_array {
        struct list_head       *paa_reqs_array; /** array to hold requests */
        __u32        paa_size;       /** the size of array */
        __u32        paa_count;      /** the total count of reqs */
-       time_t      paa_deadline;   /** the earliest deadline of reqs */
+       time64_t     paa_deadline;   /** the earliest deadline of reqs */
        __u32       *paa_reqs_count; /** the count of reqs in each entry */
 };
 
@@ -85,7 +84,6 @@ struct imp_at {
        struct adaptive_timeout iat_service_estimate[IMP_AT_MAX_PORTALS];
 };
 
-
 /** @} */
 
 /** Possible import states */
@@ -148,7 +146,7 @@ struct obd_import_conn {
 #define IMP_STATE_HIST_LEN 16
 struct import_state_hist {
        enum lustre_imp_state ish_state;
-       time_t          ish_time;
+       time64_t        ish_time;
 };
 
 /**
@@ -200,7 +198,7 @@ struct obd_import {
         */
        struct ptlrpc_sec       *imp_sec;
        struct mutex              imp_sec_mutex;
-       unsigned long           imp_sec_expire;
+       time64_t                imp_sec_expire;
        /** @} */
 
        /** Wait queue for those who need to wait for recovery completion */
@@ -306,10 +304,8 @@ struct obd_import {
        __u32                imp_msg_magic;
        __u32                imp_msghdr_flags;       /* adjusted based on server capability */
 
-       struct ptlrpc_request_pool *imp_rq_pool;          /* emergency request pool */
-
        struct imp_at        imp_at;             /* adaptive timeout data */
-       time_t              imp_last_reply_time;    /* for health check */
+       time64_t             imp_last_reply_time;    /* for health check */
 };
 
 typedef void (*obd_import_callback)(struct obd_import *imp, void *closure,
@@ -353,9 +349,10 @@ static inline void at_reset(struct adaptive_timeout *at, int val)
        spin_lock(&at->at_lock);
        at->at_current = val;
        at->at_worst_ever = val;
-       at->at_worst_time = get_seconds();
+       at->at_worst_time = ktime_get_real_seconds();
        spin_unlock(&at->at_lock);
 }
+
 static inline void at_init(struct adaptive_timeout *at, int val, int flags)
 {
        memset(at, 0, sizeof(*at));
@@ -363,11 +360,13 @@ static inline void at_init(struct adaptive_timeout *at, int val, int flags)
        at->at_flags = flags;
        at_reset(at, val);
 }
+
 extern unsigned int at_min;
 static inline int at_get(struct adaptive_timeout *at)
 {
        return (at->at_current > at_min) ? at->at_current : at_min;
 }
+
 int at_measured(struct adaptive_timeout *at, unsigned int val);
 int import_at_get_index(struct obd_import *imp, int portal);
 extern unsigned int at_max;
@@ -376,7 +375,6 @@ extern unsigned int at_max;
 /* genops.c */
 struct obd_export;
 struct obd_import *class_exp2cliimp(struct obd_export *);
-struct obd_import *class_conn2cliimp(struct lustre_handle *);
 
 /** @} import */
 
index 43ee9f0eb4d47f801a8f99acc4bdc41e7294899e..428469fec534f6b663c9a97bdb82e10fa0eb0d8a 100644 (file)
@@ -97,10 +97,10 @@ struct obd_client_handle {
        __u32                    och_magic;
        fmode_t                  och_flags;
 };
+
 #define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
 
 /* statfs_pack.c */
-void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
 
 /*
@@ -178,6 +178,7 @@ struct obd_ioctl_hdr {
 static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
 {
        int len = cfs_size_round(sizeof(struct obd_ioctl_data));
+
        len += cfs_size_round(data->ioc_inllen1);
        len += cfs_size_round(data->ioc_inllen2);
        len += cfs_size_round(data->ioc_inllen3);
@@ -185,7 +186,6 @@ static inline int obd_ioctl_packlen(struct obd_ioctl_data *data)
        return len;
 }
 
-
 static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
 {
        if (data->ioc_len > OBD_MAX_IOCTL_BUFFER) {
@@ -249,7 +249,6 @@ static inline int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
        return 0;
 }
 
-
 #include "obd_support.h"
 
 /* function defined in lustre/obdclass/<platform>/<platform>-module.c */
@@ -258,7 +257,7 @@ int obd_ioctl_popdata(void *arg, void *data, int len);
 
 static inline void obd_ioctl_freedata(char *buf, int len)
 {
-       OBD_FREE_LARGE(buf, len);
+       kvfree(buf);
        return;
 }
 
@@ -289,7 +288,6 @@ static inline void obd_ioctl_freedata(char *buf, int len)
 #define OBD_IOC_READ              _IOWR('f', 109, OBD_IOC_DATA_TYPE)
 #define OBD_IOC_WRITE            _IOWR('f', 110, OBD_IOC_DATA_TYPE)
 
-
 #define OBD_IOC_STATFS          _IOWR('f', 113, OBD_IOC_DATA_TYPE)
 #define OBD_IOC_SYNC              _IOW ('f', 114, OBD_IOC_DATA_TYPE)
 #define OBD_IOC_READ2            _IOWR('f', 115, OBD_IOC_DATA_TYPE)
@@ -313,7 +311,7 @@ static inline void obd_ioctl_freedata(char *buf, int len)
 #define OBD_IOC_CLIENT_RECOVER  _IOW ('f', 133, OBD_IOC_DATA_TYPE)
 #define OBD_IOC_PING_TARGET        _IOW ('f', 136, OBD_IOC_DATA_TYPE)
 
-#define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 139      )
+#define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 139)
 #define OBD_IOC_NO_TRANSNO          _IOW ('f', 140, OBD_IOC_DATA_TYPE)
 #define OBD_IOC_SET_READONLY      _IOW ('f', 141, OBD_IOC_DATA_TYPE)
 #define OBD_IOC_ABORT_RECOVERY  _IOR ('f', 142, OBD_IOC_DATA_TYPE)
@@ -453,7 +451,7 @@ static inline void obd_ioctl_freedata(char *buf, int len)
  *                                      __wake_up_common(q, ...);     (2.2)
  *                                      spin_unlock(&q->lock, flags); (2.3)
  *
- *   OBD_FREE_PTR(obj);                                                  (3)
+ *   kfree(obj);                                                 (3)
  *
  * As l_wait_event() may "short-cut" execution and return without taking
  * wait-queue spin-lock, some additional synchronization is necessary to
@@ -523,7 +521,6 @@ struct l_wait_info {
                           sigmask(SIGTERM) | sigmask(SIGQUIT) |        \
                           sigmask(SIGALRM))
 
-
 /*
  * wait for @condition to become true, but no longer than timeout, specified
  * by @info.
@@ -557,9 +554,9 @@ do {                                                                           \
                if (__timeout == 0) {                                     \
                        schedule();                                            \
                } else {                                                       \
-                       long interval = info->lwi_interval      \
+                       long interval = info->lwi_interval ?      \
                                             min_t(long,             \
-                                                info->lwi_interval,__timeout):\
+                                                info->lwi_interval, __timeout) : \
                                             __timeout;                 \
                        long remaining = schedule_timeout(interval);\
                        __timeout = cfs_time_sub(__timeout,                 \
@@ -604,8 +601,6 @@ do {                                                                           \
        remove_wait_queue(&wq, &__wait);                                           \
 } while (0)
 
-
-
 #define l_wait_event(wq, condition, info)                     \
 ({                                                           \
        int              __ret;                       \
index df557c22abbed38c9287d09b243924adba9a6069..f6d7aae3a0b8473531e3871b3e6da4b3a19a8f39 100644 (file)
@@ -55,7 +55,6 @@
 
 #include "lustre/lustre_user.h"
 
-
 struct lustre_rw_params {
        int             lrp_lock_mode;
        ldlm_policy_data_t lrp_policy;
index 2187fb615e9a874e85cb73f0a50eb7a62e9897e1..1de0c4d6f7f775cb46ee27b47899e9c0e292ddc1 100644 (file)
@@ -58,7 +58,6 @@
 
 #include "obd_class.h"
 #include "lustre/lustre_idl.h"
-#include "dt_object.h"
 
 #define LOG_NAME_LIMIT(logname, name)             \
        snprintf(logname, sizeof(logname), "LOGS/%s", name)
@@ -81,60 +80,20 @@ struct cat_handle_data {
        struct llog_handle      *chd_next_log; /* llog to be used next */
 };
 
-static inline void logid_to_fid(struct llog_logid *id, struct lu_fid *fid)
-{
-       /* For compatibility purposes we identify pre-OSD (~< 2.3.51 MDS)
-        * logid's by non-zero ogen (inode generation) and convert them
-        * into IGIF */
-       if (id->lgl_ogen == 0) {
-               fid->f_seq = id->lgl_oi.oi.oi_seq;
-               fid->f_oid = id->lgl_oi.oi.oi_id;
-               fid->f_ver = 0;
-       } else {
-               lu_igif_build(fid, id->lgl_oi.oi.oi_id, id->lgl_ogen);
-       }
-}
-
-static inline void fid_to_logid(struct lu_fid *fid, struct llog_logid *id)
-{
-       id->lgl_oi.oi.oi_seq = fid->f_seq;
-       id->lgl_oi.oi.oi_id = fid->f_oid;
-       id->lgl_ogen = 0;
-}
-
-static inline void logid_set_id(struct llog_logid *log_id, __u64 id)
-{
-       log_id->lgl_oi.oi.oi_id = id;
-}
-
-static inline __u64 logid_id(struct llog_logid *log_id)
-{
-       return log_id->lgl_oi.oi.oi_id;
-}
-
 struct llog_handle;
 
 /* llog.c  -  general API */
 int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
                     int flags, struct obd_uuid *uuid);
-int llog_copy_handler(const struct lu_env *env, struct llog_handle *llh,
-                     struct llog_rec_hdr *rec, void *data);
 int llog_process(const struct lu_env *env, struct llog_handle *loghandle,
                 llog_cb_t cb, void *data, void *catdata);
 int llog_process_or_fork(const struct lu_env *env,
                         struct llog_handle *loghandle,
                         llog_cb_t cb, void *data, void *catdata, bool fork);
-int llog_reverse_process(const struct lu_env *env,
-                        struct llog_handle *loghandle, llog_cb_t cb,
-                        void *data, void *catdata);
-int llog_cancel_rec(const struct lu_env *env, struct llog_handle *loghandle,
-                   int index);
 int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt,
              struct llog_handle **lgh, struct llog_logid *logid,
              char *name, enum llog_open_param open_param);
 int llog_close(const struct lu_env *env, struct llog_handle *cathandle);
-int llog_is_empty(const struct lu_env *env, struct llog_ctxt *ctxt,
-                 char *name);
 int llog_backup(const struct lu_env *env, struct obd_device *obd,
                struct llog_ctxt *ctxt, struct llog_ctxt *bak_ctxt,
                char *name, char *backup);
@@ -172,29 +131,11 @@ struct llog_process_cat_data {
        int               lpcd_last_idx;
 };
 
+struct thandle;
+
 int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle);
-int llog_cat_add_rec(const struct lu_env *env, struct llog_handle *cathandle,
-                    struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
-                    void *buf, struct thandle *th);
-int llog_cat_declare_add_rec(const struct lu_env *env,
-                            struct llog_handle *cathandle,
-                            struct llog_rec_hdr *rec, struct thandle *th);
-int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
-                struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
-                void *buf);
-int llog_cat_cancel_records(const struct lu_env *env,
-                           struct llog_handle *cathandle, int count,
-                           struct llog_cookie *cookies);
-int llog_cat_process_or_fork(const struct lu_env *env,
-                            struct llog_handle *cat_llh, llog_cb_t cb,
-                            void *data, int startcat, int startidx, bool fork);
 int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
                     llog_cb_t cb, void *data, int startcat, int startidx);
-int llog_cat_reverse_process(const struct lu_env *env,
-                            struct llog_handle *cat_llh, llog_cb_t cb,
-                            void *data);
-int llog_cat_init_and_process(const struct lu_env *env,
-                             struct llog_handle *llh);
 
 /* llog_obd.c */
 int llog_setup(const struct lu_env *env, struct obd_device *obd,
@@ -202,16 +143,11 @@ int llog_setup(const struct lu_env *env, struct obd_device *obd,
               struct obd_device *disk_obd, struct llog_operations *op);
 int __llog_ctxt_put(const struct lu_env *env, struct llog_ctxt *ctxt);
 int llog_cleanup(const struct lu_env *env, struct llog_ctxt *);
-int llog_sync(struct llog_ctxt *ctxt, struct obd_export *exp, int flags);
-int llog_cancel(const struct lu_env *env, struct llog_ctxt *ctxt,
-               struct llog_cookie *cookies, int flags);
 
 /* llog_net.c */
 int llog_initiator_connect(struct llog_ctxt *ctxt);
 
 struct llog_operations {
-       int (*lop_destroy)(const struct lu_env *env,
-                          struct llog_handle *handle);
        int (*lop_next_block)(const struct lu_env *env, struct llog_handle *h,
                              int *curr_idx, int next_idx, __u64 *offset,
                              void *buf, int len);
@@ -254,8 +190,6 @@ struct llog_operations {
        int (*lop_declare_create)(const struct lu_env *env,
                                  struct llog_handle *handle,
                                  struct thandle *th);
-       int (*lop_create)(const struct lu_env *env, struct llog_handle *handle,
-                         struct thandle *th);
        /**
         * write new record in llog. It appends records usually but can edit
         * existing records too.
@@ -287,8 +221,6 @@ struct llog_handle {
        spinlock_t               lgh_hdr_lock; /* protect lgh_hdr data */
        struct llog_logid        lgh_id; /* id of this log */
        struct llog_log_hdr     *lgh_hdr;
-       struct file             *lgh_file;
-       struct dt_object        *lgh_obj;
        int                      lgh_last_idx;
        int                      lgh_cur_idx; /* used during llog_process */
        __u64                    lgh_cur_offset; /* used during llog_process */
@@ -318,25 +250,11 @@ struct llog_ctxt {
        struct mutex             loc_mutex; /* protect loc_imp */
        atomic_t             loc_refcount;
        long                 loc_flags; /* flags, see above defines */
-       struct dt_object        *loc_dir;
 };
 
 #define LLOG_PROC_BREAK 0x0001
 #define LLOG_DEL_RECORD 0x0002
 
-static inline int llog_obd2ops(struct llog_ctxt *ctxt,
-                              struct llog_operations **lop)
-{
-       if (ctxt == NULL)
-               return -ENOTCONN;
-
-       *lop = ctxt->loc_logops;
-       if (*lop == NULL)
-               return -EOPNOTSUPP;
-
-       return 0;
-}
-
 static inline int llog_handle2ops(struct llog_handle *loghandle,
                                  struct llog_operations **lop)
 {
@@ -347,18 +265,6 @@ static inline int llog_handle2ops(struct llog_handle *loghandle,
        return 0;
 }
 
-static inline int llog_data_len(int len)
-{
-       return cfs_size_round(len);
-}
-
-static inline int llog_get_size(struct llog_handle *loghandle)
-{
-       if (loghandle && loghandle->lgh_hdr)
-               return loghandle->lgh_hdr->llh_count;
-       return 0;
-}
-
 static inline struct llog_ctxt *llog_ctxt_get(struct llog_ctxt *ctxt)
 {
        atomic_inc(&ctxt->loc_refcount);
@@ -440,22 +346,6 @@ static inline int llog_ctxt_null(struct obd_device *obd, int index)
        return llog_group_ctxt_null(&obd->obd_olg, index);
 }
 
-static inline int llog_destroy(const struct lu_env *env,
-                              struct llog_handle *handle)
-{
-       struct llog_operations *lop;
-       int rc;
-
-       rc = llog_handle2ops(handle, &lop);
-       if (rc)
-               return rc;
-       if (lop->lop_destroy == NULL)
-               return -EOPNOTSUPP;
-
-       rc = lop->lop_destroy(env, handle);
-       return rc;
-}
-
 static inline int llog_next_block(const struct lu_env *env,
                                  struct llog_handle *loghandle, int *cur_idx,
                                  int next_idx, __u64 *cur_offset, void *buf,
@@ -475,46 +365,7 @@ static inline int llog_next_block(const struct lu_env *env,
        return rc;
 }
 
-static inline int llog_prev_block(const struct lu_env *env,
-                                 struct llog_handle *loghandle,
-                                 int prev_idx, void *buf, int len)
-{
-       struct llog_operations *lop;
-       int rc;
-
-       rc = llog_handle2ops(loghandle, &lop);
-       if (rc)
-               return rc;
-       if (lop->lop_prev_block == NULL)
-               return -EOPNOTSUPP;
-
-       rc = lop->lop_prev_block(env, loghandle, prev_idx, buf, len);
-       return rc;
-}
-
-static inline int llog_connect(struct llog_ctxt *ctxt,
-                              struct llog_logid *logid, struct llog_gen *gen,
-                              struct obd_uuid *uuid)
-{
-       struct llog_operations  *lop;
-       int                      rc;
-
-       rc = llog_obd2ops(ctxt, &lop);
-       if (rc)
-               return rc;
-       if (lop->lop_connect == NULL)
-               return -EOPNOTSUPP;
-
-       rc = lop->lop_connect(ctxt, logid, gen, uuid);
-       return rc;
-}
-
 /* llog.c */
-int llog_exist(struct llog_handle *loghandle);
-int llog_declare_create(const struct lu_env *env,
-                       struct llog_handle *loghandle, struct thandle *th);
-int llog_create(const struct lu_env *env, struct llog_handle *handle,
-               struct thandle *th);
 int llog_declare_write_rec(const struct lu_env *env,
                           struct llog_handle *handle,
                           struct llog_rec_hdr *rec, int idx,
@@ -522,24 +373,10 @@ int llog_declare_write_rec(const struct lu_env *env,
 int llog_write_rec(const struct lu_env *env, struct llog_handle *handle,
                   struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
                   int numcookies, void *buf, int idx, struct thandle *th);
-int llog_add(const struct lu_env *env, struct llog_handle *lgh,
-            struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
-            void *buf, struct thandle *th);
-int llog_declare_add(const struct lu_env *env, struct llog_handle *lgh,
-                    struct llog_rec_hdr *rec, struct thandle *th);
 int lustre_process_log(struct super_block *sb, char *logname,
                       struct config_llog_instance *cfg);
 int lustre_end_log(struct super_block *sb, char *logname,
                   struct config_llog_instance *cfg);
-int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
-                    struct llog_handle **res, struct llog_logid *logid,
-                    char *name);
-int llog_erase(const struct lu_env *env, struct llog_ctxt *ctxt,
-              struct llog_logid *logid, char *name);
-int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
-              struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
-              int cookiecount, void *buf, int idx);
-
 /** @} log */
 
 #endif
index b1b05c8a371a5b447bc79f2124639427bad41065..3da373315856a75ffe14ec76e4f0df2b14a4db45 100644 (file)
@@ -163,7 +163,6 @@ static inline void mdc_update_max_ea_from_body(struct obd_export *exp,
        }
 }
 
-
 struct mdc_cache_waiter {
        struct list_head              mcw_entry;
        wait_queue_head_t            mcw_waitq;
index f0cce41c55c09409e1792d83374de91844545276..a16eb8b611789941dcc9862903fc0bad9375019c 100644 (file)
@@ -59,11 +59,6 @@ struct mds_group_info {
        int group;
 };
 
-struct mds_capa_info {
-       struct obd_uuid *uuid;
-       struct lustre_capa_key *capa;
-};
-
 #define MDD_OBD_NAME     "mdd_obd"
 #define MDD_OBD_UUID     "mdd_obd_uuid"
 
index 48ad60b221223b1c85864bb534244fbb2eb9afab..0127f45ca0c3f571d784f8dabdde1bedb6d36516 100644 (file)
@@ -46,7 +46,6 @@
  * @{
  */
 
-
 #ifndef _LUSTRE_NET_H
 #define _LUSTRE_NET_H
 
@@ -306,7 +305,7 @@ union ptlrpc_async_args {
        /**
         * Scratchpad for passing args to completion interpreter. Users
         * cast to the struct of their choosing, and CLASSERT that this is
-        * big enough.  For _tons_ of context, OBD_ALLOC a struct and store
+        * big enough.  For _tons_ of context, kmalloc a struct and store
         * a pointer to it here.  The pointer_arg ensures this struct is at
         * least big enough for that.
         */
@@ -429,8 +428,7 @@ struct ptlrpc_reply_state {
        unsigned long     rs_on_net:1;   /* reply_out_callback pending? */
        unsigned long     rs_prealloc:1; /* rs from prealloc list */
        unsigned long     rs_committed:1;/* the transaction was committed
-                                                and the rs was dispatched
-                                                by ptlrpc_commit_replies */
+                                         * and the rs was dispatched */
        /** Size of the state */
        int                 rs_size;
        /** opcode */
@@ -500,7 +498,7 @@ struct ptlrpc_request_pool {
        /** Maximum message size that would fit into a request from this pool */
        int prp_rq_size;
        /** Function to allocate more requests for this pool */
-       void (*prp_populate)(struct ptlrpc_request_pool *, int);
+       int (*prp_populate)(struct ptlrpc_request_pool *, int);
 };
 
 struct lu_context;
@@ -643,7 +641,6 @@ struct ptlrpc_nrs_pol_ops {
         *
         * \see ptlrpc_nrs_req_initialize()
         * \see ptlrpc_nrs_hpreq_add_nolock()
-        * \see ptlrpc_nrs_req_hp_move()
         */
        int     (*op_res_get) (struct ptlrpc_nrs_policy *policy,
                               struct ptlrpc_nrs_request *nrq,
@@ -659,7 +656,6 @@ struct ptlrpc_nrs_pol_ops {
         *
         * \see ptlrpc_nrs_req_finalize()
         * \see ptlrpc_nrs_hpreq_add_nolock()
-        * \see ptlrpc_nrs_req_hp_move()
         */
        void    (*op_res_put) (struct ptlrpc_nrs_policy *policy,
                               const struct ptlrpc_nrs_resource *res);
@@ -704,8 +700,6 @@ struct ptlrpc_nrs_pol_ops {
         *
         * \param[in,out] policy The policy the request \a nrq belongs to
         * \param[in,out] nrq    The request to dequeue
-        *
-        * \see ptlrpc_nrs_req_del_nolock()
         */
        void    (*op_req_dequeue) (struct ptlrpc_nrs_policy *policy,
                                   struct ptlrpc_nrs_request *nrq);
@@ -1292,7 +1286,7 @@ struct ptlrpc_request {
        struct ptlrpc_nrs_request rq_nrq;
        /** @} nrs */
        /** the index of service's srv_at_array into which request is linked */
-       time_t rq_at_index;
+       u32 rq_at_index;
        /** Lock to protect request flags and some other important bits, like
         * rq_list
         */
@@ -1440,7 +1434,7 @@ struct ptlrpc_request {
 
        /* server-side... */
        /** request arrival time */
-       struct timeval       rq_arrival_time;
+       struct timespec64       rq_arrival_time;
        /** separated reply state */
        struct ptlrpc_reply_state *rq_reply_state;
        /** incoming request buffer */
@@ -1477,18 +1471,18 @@ struct ptlrpc_request {
        /**
         * when request/reply sent (secs), or time when request should be sent
         */
-       time_t rq_sent;
+       time64_t rq_sent;
        /** time for request really sent out */
-       time_t rq_real_sent;
+       time64_t rq_real_sent;
 
        /** when request must finish. volatile
         * so that servers' early reply updates to the deadline aren't
         * kept in per-cpu cache */
-       volatile time_t rq_deadline;
+       volatile time64_t rq_deadline;
        /** when req reply unlink must finish. */
-       time_t rq_reply_deadline;
+       time64_t rq_reply_deadline;
        /** when req bulk unlink must finish. */
-       time_t rq_bulk_deadline;
+       time64_t rq_bulk_deadline;
        /**
         * service time estimate (secs)
         * If the requestsis not served by this time, it is marked as timed out.
@@ -1533,15 +1527,6 @@ static inline int ptlrpc_req_interpret(const struct lu_env *env,
        return rc;
 }
 
-/** \addtogroup  nrs
- * @{
- */
-int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf);
-int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf);
-void ptlrpc_nrs_req_hp_move(struct ptlrpc_request *req);
-void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
-                               struct ptlrpc_nrs_pol_info *info);
-
 /*
  * Can the request be moved from the regular NRS head to the high-priority NRS
  * head (of the same PTLRPC service partition), if any?
@@ -1560,6 +1545,7 @@ static inline bool ptlrpc_nrs_req_can_move(struct ptlrpc_request *req)
         */
        return nrq->nr_enqueued && !nrq->nr_started && !req->rq_hp;
 }
+
 /** @} nrs */
 
 /**
@@ -2065,7 +2051,7 @@ struct ptlrpc_service_part {
         * rqbd list and incoming requests waiting for preprocess,
         * threads starting & stopping are also protected by this lock.
         */
-       spinlock_t                      scp_lock  __cfs_cacheline_aligned;
+       spinlock_t scp_lock __cfs_cacheline_aligned;
        /** total # req buffer descs allocated */
        int                             scp_nrqbds_total;
        /** # posted request buffers for receiving */
@@ -2191,21 +2177,29 @@ struct ptlrpcd_ctl {
         */
        struct lu_env          pc_env;
        /**
-        * Index of ptlrpcd thread in the array.
+        * CPT the thread is bound on.
         */
-       int                      pc_index;
+       int                             pc_cpt;
        /**
-        * Number of the ptlrpcd's partners.
+        * Index of ptlrpcd thread in the array.
         */
-       int                      pc_npartners;
+       int                             pc_index;
        /**
         * Pointer to the array of partners' ptlrpcd_ctl structure.
         */
        struct ptlrpcd_ctl      **pc_partners;
+       /**
+        * Number of the ptlrpcd's partners.
+        */
+       int                             pc_npartners;
        /**
         * Record the partner index to be processed next.
         */
        int                      pc_cursor;
+       /**
+        * Error code if the thread failed to fully start.
+        */
+       int                             pc_error;
 };
 
 /* Bits for pc_flags */
@@ -2228,10 +2222,6 @@ enum ptlrpcd_ctl_flags {
         * This is a recovery ptlrpc thread.
         */
        LIOD_RECOVERY    = 1 << 3,
-       /**
-        * The ptlrpcd is bound to some CPU core.
-        */
-       LIOD_BIND       = 1 << 4,
 };
 
 /**
@@ -2299,7 +2289,6 @@ int ptlrpc_connection_put(struct ptlrpc_connection *c);
 struct ptlrpc_connection *ptlrpc_connection_addref(struct ptlrpc_connection *);
 int ptlrpc_connection_init(void);
 void ptlrpc_connection_fini(void);
-lnet_pid_t ptl_get_pid(void);
 
 /* ptlrpc/niobuf.c */
 /**
@@ -2307,7 +2296,6 @@ lnet_pid_t ptl_get_pid(void);
  * @{
  */
 
-int ptlrpc_register_bulk(struct ptlrpc_request *req);
 int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async);
 
 static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
@@ -2319,7 +2307,7 @@ static inline int ptlrpc_client_bulk_active(struct ptlrpc_request *req)
        desc = req->rq_bulk;
 
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
-           req->rq_bulk_deadline > get_seconds())
+           req->rq_bulk_deadline > ktime_get_real_seconds())
                return 1;
 
        if (!desc)
@@ -2353,22 +2341,17 @@ void ptlrpc_request_committed(struct ptlrpc_request *req, int force);
 
 void ptlrpc_init_client(int req_portal, int rep_portal, char *name,
                        struct ptlrpc_client *);
-void ptlrpc_cleanup_client(struct obd_import *imp);
 struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid);
 
 int ptlrpc_queue_wait(struct ptlrpc_request *req);
 int ptlrpc_replay_req(struct ptlrpc_request *req);
 int ptlrpc_unregister_reply(struct ptlrpc_request *req, int async);
-void ptlrpc_restart_req(struct ptlrpc_request *req);
 void ptlrpc_abort_inflight(struct obd_import *imp);
-void ptlrpc_cleanup_imp(struct obd_import *imp);
 void ptlrpc_abort_set(struct ptlrpc_request_set *set);
 
 struct ptlrpc_request_set *ptlrpc_prep_set(void);
 struct ptlrpc_request_set *ptlrpc_prep_fcset(int max, set_producer_func func,
                                             void *arg);
-int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
-                     set_interpreter_func fn, void *data);
 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *);
 int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set);
 int ptlrpc_set_wait(struct ptlrpc_request_set *);
@@ -2381,11 +2364,11 @@ void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
                            struct ptlrpc_request *req);
 
 void ptlrpc_free_rq_pool(struct ptlrpc_request_pool *pool);
-void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
+int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq);
 
 struct ptlrpc_request_pool *
 ptlrpc_init_rq_pool(int, int,
-                   void (*populate_pool)(struct ptlrpc_request_pool *, int));
+                   int (*populate_pool)(struct ptlrpc_request_pool *, int));
 
 void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req);
 struct ptlrpc_request *ptlrpc_request_alloc(struct obd_import *imp,
@@ -2402,15 +2385,7 @@ struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
 int ptlrpc_request_bufs_pack(struct ptlrpc_request *request,
                             __u32 version, int opcode, char **bufs,
                             struct ptlrpc_cli_ctx *ctx);
-struct ptlrpc_request *ptlrpc_prep_req(struct obd_import *imp, __u32 version,
-                                      int opcode, int count, __u32 *lengths,
-                                      char **bufs);
-struct ptlrpc_request *ptlrpc_prep_req_pool(struct obd_import *imp,
-                                            __u32 version, int opcode,
-                                           int count, __u32 *lengths, char **bufs,
-                                           struct ptlrpc_request_pool *pool);
 void ptlrpc_req_finished(struct ptlrpc_request *request);
-void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request);
 struct ptlrpc_request *ptlrpc_request_addref(struct ptlrpc_request *req);
 struct ptlrpc_bulk_desc *ptlrpc_prep_bulk_imp(struct ptlrpc_request *req,
                                              unsigned npages, unsigned max_brw,
@@ -2420,10 +2395,12 @@ static inline void ptlrpc_free_bulk_pin(struct ptlrpc_bulk_desc *bulk)
 {
        __ptlrpc_free_bulk(bulk, 1);
 }
+
 static inline void ptlrpc_free_bulk_nopin(struct ptlrpc_bulk_desc *bulk)
 {
        __ptlrpc_free_bulk(bulk, 0);
 }
+
 void __ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
                             struct page *page, int pageoffset, int len, int);
 static inline void ptlrpc_prep_bulk_page_pin(struct ptlrpc_bulk_desc *desc,
@@ -2521,26 +2498,16 @@ struct ptlrpc_service_conf {
  *
  * @{
  */
-void ptlrpc_save_lock(struct ptlrpc_request *req,
-                     struct lustre_handle *lock, int mode, int no_ack);
-void ptlrpc_commit_replies(struct obd_export *exp);
 void ptlrpc_dispatch_difficult_reply(struct ptlrpc_reply_state *rs);
 void ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs);
-int ptlrpc_hpreq_handler(struct ptlrpc_request *req);
 struct ptlrpc_service *ptlrpc_register_service(
                                struct ptlrpc_service_conf *conf,
                                struct kset *parent,
                                struct dentry *debugfs_entry);
-void ptlrpc_stop_all_threads(struct ptlrpc_service *svc);
 
 int ptlrpc_start_threads(struct ptlrpc_service *svc);
 int ptlrpc_unregister_service(struct ptlrpc_service *service);
 int liblustre_check_services(void *arg);
-void ptlrpc_daemonize(char *name);
-int ptlrpc_service_health_check(struct ptlrpc_service *);
-void ptlrpc_server_drop_request(struct ptlrpc_request *req);
-void ptlrpc_request_change_export(struct ptlrpc_request *req,
-                                 struct obd_export *export);
 
 int ptlrpc_hr_init(void);
 void ptlrpc_hr_fini(void);
@@ -2556,8 +2523,6 @@ int ptlrpc_connect_import(struct obd_import *imp);
 int ptlrpc_init_import(struct obd_import *imp);
 int ptlrpc_disconnect_import(struct obd_import *imp, int noclose);
 int ptlrpc_import_recovery_state_machine(struct obd_import *imp);
-void deuuidify(char *uuid, const char *prefix, char **uuid_start,
-              int *uuid_len);
 
 /* ptlrpc/pack_generic.c */
 int ptlrpc_reconnect_import(struct obd_import *imp);
@@ -2575,7 +2540,6 @@ void ptlrpc_buf_set_swabbed(struct ptlrpc_request *req, const int inout,
 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len);
 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len);
 
-int lustre_msg_check_version(struct lustre_msg *msg, __u32 version);
 void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
                        char **bufs);
 int lustre_pack_request(struct ptlrpc_request *, __u32 magic, int count,
@@ -2599,7 +2563,6 @@ int lustre_msg_early_size(void);
 void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size);
 void *lustre_msg_buf(struct lustre_msg *m, int n, int minlen);
 int lustre_msg_buflen(struct lustre_msg *m, int n);
-void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len);
 int lustre_msg_bufcount(struct lustre_msg *m);
 char *lustre_msg_string(struct lustre_msg *m, int n, int max_len);
 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg);
@@ -2610,13 +2573,10 @@ void lustre_msg_set_flags(struct lustre_msg *msg, int flags);
 void lustre_msg_clear_flags(struct lustre_msg *msg, int flags);
 __u32 lustre_msg_get_op_flags(struct lustre_msg *msg);
 void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags);
-void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags);
 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg);
 __u32 lustre_msg_get_type(struct lustre_msg *msg);
-__u32 lustre_msg_get_version(struct lustre_msg *msg);
 void lustre_msg_add_version(struct lustre_msg *msg, int version);
 __u32 lustre_msg_get_opc(struct lustre_msg *msg);
-__u64 lustre_msg_get_last_xid(struct lustre_msg *msg);
 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg);
 __u64 *lustre_msg_get_versions(struct lustre_msg *msg);
 __u64 lustre_msg_get_transno(struct lustre_msg *msg);
@@ -2626,25 +2586,19 @@ void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv);
 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit);
 int lustre_msg_get_status(struct lustre_msg *msg);
 __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg);
-int lustre_msg_is_v1(struct lustre_msg *msg);
 __u32 lustre_msg_get_magic(struct lustre_msg *msg);
 __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
 __u32 lustre_msg_get_service_time(struct lustre_msg *msg);
-char *lustre_msg_get_jobid(struct lustre_msg *msg);
 __u32 lustre_msg_get_cksum(struct lustre_msg *msg);
 __u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
 void lustre_msg_set_handle(struct lustre_msg *msg,
                           struct lustre_handle *handle);
 void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
 void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc);
-void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid);
-void lustre_msg_set_last_committed(struct lustre_msg *msg,
-                                  __u64 last_committed);
 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions);
 void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno);
 void lustre_msg_set_status(struct lustre_msg *msg, __u32 status);
 void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt);
-void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *sizes);
 void ptlrpc_request_set_replen(struct ptlrpc_request *req);
 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout);
 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time);
@@ -2725,7 +2679,7 @@ static inline int
 ptlrpc_client_early(struct ptlrpc_request *req)
 {
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
-           req->rq_reply_deadline > get_seconds())
+           req->rq_reply_deadline > ktime_get_real_seconds())
                return 0;
        return req->rq_early;
 }
@@ -2737,7 +2691,7 @@ static inline int
 ptlrpc_client_replied(struct ptlrpc_request *req)
 {
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
-           req->rq_reply_deadline > get_seconds())
+           req->rq_reply_deadline > ktime_get_real_seconds())
                return 0;
        return req->rq_replied;
 }
@@ -2747,7 +2701,7 @@ static inline int
 ptlrpc_client_recv(struct ptlrpc_request *req)
 {
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
-           req->rq_reply_deadline > get_seconds())
+           req->rq_reply_deadline > ktime_get_real_seconds())
                return 1;
        return req->rq_receiving_reply;
 }
@@ -2759,7 +2713,7 @@ ptlrpc_client_recv_or_unlink(struct ptlrpc_request *req)
 
        spin_lock(&req->rq_lock);
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
-           req->rq_reply_deadline > get_seconds()) {
+           req->rq_reply_deadline > ktime_get_real_seconds()) {
                spin_unlock(&req->rq_lock);
                return 1;
        }
@@ -2878,7 +2832,6 @@ int import_set_conn_priority(struct obd_import *imp, struct obd_uuid *uuid);
 void client_destroy_import(struct obd_import *imp);
 /** @} */
 
-
 /* ptlrpc/pinger.c */
 /**
  * Pinger API (client side only)
@@ -2887,6 +2840,7 @@ void client_destroy_import(struct obd_import *imp);
 enum timeout_event {
        TIMEOUT_GRANT = 1
 };
+
 struct timeout_item;
 typedef int (*timeout_cb_t)(struct timeout_item *, void *);
 int ptlrpc_pinger_add_import(struct obd_import *imp);
@@ -2898,51 +2852,16 @@ int ptlrpc_del_timeout_client(struct list_head *obd_list,
                              enum timeout_event event);
 struct ptlrpc_request *ptlrpc_prep_ping(struct obd_import *imp);
 int ptlrpc_obd_ping(struct obd_device *obd);
-void ping_evictor_start(void);
-void ping_evictor_stop(void);
 void ptlrpc_pinger_ir_up(void);
 void ptlrpc_pinger_ir_down(void);
 /** @} */
 int ptlrpc_pinger_suppress_pings(void);
 
-/* ptlrpc daemon bind policy */
-typedef enum {
-       /* all ptlrpcd threads are free mode */
-       PDB_POLICY_NONE   = 1,
-       /* all ptlrpcd threads are bound mode */
-       PDB_POLICY_FULL   = 2,
-       /* <free1 bound1> <free2 bound2> ... <freeN boundN> */
-       PDB_POLICY_PAIR   = 3,
-       /* <free1 bound1> <bound1 free2> ... <freeN boundN> <boundN free1>,
-        * means each ptlrpcd[X] has two partners: thread[X-1] and thread[X+1].
-        * If kernel supports NUMA, pthrpcd threads are binded and
-        * grouped by NUMA node */
-       PDB_POLICY_NEIGHBOR      = 4,
-} pdb_policy_t;
-
-/* ptlrpc daemon load policy
- * It is caller's duty to specify how to push the async RPC into some ptlrpcd
- * queue, but it is not enforced, affected by "ptlrpcd_bind_policy". If it is
- * "PDB_POLICY_FULL", then the RPC will be processed by the selected ptlrpcd,
- * Otherwise, the RPC may be processed by the selected ptlrpcd or its partner,
- * depends on which is scheduled firstly, to accelerate the RPC processing. */
-typedef enum {
-       /* on the same CPU core as the caller */
-       PDL_POLICY_SAME  = 1,
-       /* within the same CPU partition, but not the same core as the caller */
-       PDL_POLICY_LOCAL        = 2,
-       /* round-robin on all CPU cores, but not the same core as the caller */
-       PDL_POLICY_ROUND        = 3,
-       /* the specified CPU core is preferred, but not enforced */
-       PDL_POLICY_PREFERRED    = 4,
-} pdl_policy_t;
-
 /* ptlrpc/ptlrpcd.c */
 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force);
 void ptlrpcd_free(struct ptlrpcd_ctl *pc);
 void ptlrpcd_wake(struct ptlrpc_request *req);
-void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx);
-void ptlrpcd_add_rqset(struct ptlrpc_request_set *set);
+void ptlrpcd_add_req(struct ptlrpc_request *req);
 int ptlrpcd_addref(void);
 void ptlrpcd_decref(void);
 
@@ -2959,7 +2878,6 @@ void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes);
 
 /* ptlrpc/llog_client.c */
 extern struct llog_operations llog_client_ops;
-
 /** @} net */
 
 #endif
index ed654684cb64a1fa64e2f27eb0ba4b5b43740679..8f6c0b26cfaba308677ad9af7554a51d59706029 100644 (file)
@@ -56,20 +56,8 @@ struct cfg_interop_param {
 
 /* obd_config.c */
 int class_find_param(char *buf, char *key, char **valp);
-struct cfg_interop_param *class_find_old_param(const char *param,
-                                              struct cfg_interop_param *ptr);
-int class_get_next_param(char **params, char *copy);
-int class_match_param(char *buf, char *key, char **valp);
 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
-int class_parse_net(char *buf, __u32 *net, char **endh);
-int class_match_nid(char *buf, char *key, lnet_nid_t nid);
-int class_match_net(char *buf, char *key, __u32 net);
-/* obd_mount.c */
-int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
-           char *s1, char *s2, char *s3, char *s4);
-
-
 
 /****************** User-settable parameter keys *********************/
 /* e.g.
index c6457b27c4e757c7089aa4cb08b4023df470e47f..df292f6d4a85e8d1c73d7b0c8c08ac6180ebc90a 100644 (file)
@@ -80,9 +80,6 @@ void req_capsule_init(struct req_capsule *pill, struct ptlrpc_request *req,
 void req_capsule_fini(struct req_capsule *pill);
 
 void req_capsule_set(struct req_capsule *pill, const struct req_format *fmt);
-void req_capsule_client_dump(struct req_capsule *pill);
-void req_capsule_server_dump(struct req_capsule *pill);
-void req_capsule_init_area(struct req_capsule *pill);
 int req_capsule_filled_sizes(struct req_capsule *pill, enum req_location loc);
 int  req_capsule_server_pack(struct req_capsule *pill);
 
@@ -105,8 +102,6 @@ void *req_capsule_server_swab_get(struct req_capsule *pill,
 void *req_capsule_server_sized_swab_get(struct req_capsule *pill,
                                        const struct req_msg_field *field,
                                        int len, void *swabber);
-const void *req_capsule_other_get(struct req_capsule *pill,
-                                 const struct req_msg_field *field);
 
 void req_capsule_set_size(struct req_capsule *pill,
                          const struct req_msg_field *field,
@@ -122,16 +117,10 @@ void req_capsule_extend(struct req_capsule *pill, const struct req_format *fmt);
 int req_capsule_has_field(const struct req_capsule *pill,
                          const struct req_msg_field *field,
                          enum req_location loc);
-int req_capsule_field_present(const struct req_capsule *pill,
-                             const struct req_msg_field *field,
-                             enum req_location loc);
 void req_capsule_shrink(struct req_capsule *pill,
                        const struct req_msg_field *field,
                        unsigned int newlen,
                        enum req_location loc);
-int req_capsule_server_grow(struct req_capsule *pill,
-                           const struct req_msg_field *field,
-                           unsigned int newlen);
 int  req_layout_init(void);
 void req_layout_fini(void);
 
index 707ff69717c672edab5455ef7ca19eb796efdd1e..dd1033be6bfab046bb717ab5504f4f14e6e46e17 100644 (file)
@@ -295,7 +295,6 @@ enum lustre_sec_part {
        LUSTRE_SP_ANY      = 0xFF
 };
 
-const char *sptlrpc_part2name(enum lustre_sec_part sp);
 enum lustre_sec_part sptlrpc_target_sec_part(struct obd_device *obd);
 
 /**
@@ -323,34 +322,19 @@ struct sptlrpc_rule_set {
 };
 
 int sptlrpc_parse_flavor(const char *str, struct sptlrpc_flavor *flvr);
-int sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr);
+bool sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr);
 
 static inline void sptlrpc_rule_set_init(struct sptlrpc_rule_set *set)
 {
        memset(set, 0, sizeof(*set));
 }
 
-void sptlrpc_rule_set_free(struct sptlrpc_rule_set *set);
-int  sptlrpc_rule_set_expand(struct sptlrpc_rule_set *set);
-int  sptlrpc_rule_set_merge(struct sptlrpc_rule_set *set,
-                           struct sptlrpc_rule *rule);
-int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
-                           enum lustre_sec_part from,
-                           enum lustre_sec_part to,
-                           lnet_nid_t nid,
-                           struct sptlrpc_flavor *sf);
-void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *set);
-
 int  sptlrpc_process_config(struct lustre_cfg *lcfg);
 void sptlrpc_conf_log_start(const char *logname);
 void sptlrpc_conf_log_stop(const char *logname);
 void sptlrpc_conf_log_update_begin(const char *logname);
 void sptlrpc_conf_log_update_end(const char *logname);
 void sptlrpc_conf_client_adapt(struct obd_device *obd);
-void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
-                                 enum lustre_sec_part from,
-                                 lnet_nid_t nid,
-                                 struct sptlrpc_flavor *flavor);
 
 /* The maximum length of security payload. 1024 is enough for Kerberos 5,
  * and should be enough for other future mechanisms but not sure.
@@ -358,7 +342,6 @@ void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
  */
 #define SPTLRPC_MAX_PAYLOAD     (1024)
 
-
 struct vfs_cred {
        uint32_t        vc_uid;
        uint32_t        vc_gid;
@@ -833,7 +816,7 @@ struct ptlrpc_sec {
         */
        struct list_head                      ps_gc_list;
        unsigned long                 ps_gc_interval; /* in seconds */
-       unsigned long                 ps_gc_next;     /* in seconds */
+       time64_t                      ps_gc_next;     /* in seconds */
 };
 
 static inline int sec_is_reverse(struct ptlrpc_sec *sec)
@@ -846,7 +829,6 @@ static inline int sec_is_rootonly(struct ptlrpc_sec *sec)
        return (sec->ps_flvr.sf_flags & PTLRPC_SEC_FL_ROOTONLY);
 }
 
-
 struct ptlrpc_svc_ctx {
        atomic_t                    sc_refcount;
        struct ptlrpc_sec_policy       *sc_policy;
@@ -898,7 +880,6 @@ struct ptlrpc_bulk_sec_desc {
        __u8        bsd_data[0];    /* policy-specific token */
 };
 
-
 /*
  * round size up to next power of 2, for slab allocation.
  * @size must be sane (can't overflow after round up)
@@ -932,7 +913,6 @@ const char *sptlrpc_flavor2name_base(__u32 flvr);
 char *sptlrpc_flavor2name_bulk(struct sptlrpc_flavor *sf,
                               char *buf, int bufsize);
 char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize);
-char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize);
 
 static inline
 struct ptlrpc_sec_policy *sptlrpc_policy_get(struct ptlrpc_sec_policy *policy)
@@ -995,23 +975,18 @@ int cli_ctx_is_eternal(struct ptlrpc_cli_ctx *ctx)
 /*
  * sec get/put
  */
-struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec);
 void sptlrpc_sec_put(struct ptlrpc_sec *sec);
 
 /*
  * internal apis which only used by policy implementation
  */
 int  sptlrpc_get_next_secid(void);
-void sptlrpc_sec_destroy(struct ptlrpc_sec *sec);
 
 /*
  * exported client context api
  */
 struct ptlrpc_cli_ctx *sptlrpc_cli_ctx_get(struct ptlrpc_cli_ctx *ctx);
 void sptlrpc_cli_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync);
-void sptlrpc_cli_ctx_expire(struct ptlrpc_cli_ctx *ctx);
-void sptlrpc_cli_ctx_wakeup(struct ptlrpc_cli_ctx *ctx);
-int sptlrpc_cli_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize);
 
 /*
  * exported client context wrap/buffers
@@ -1046,15 +1021,11 @@ void sptlrpc_import_flush_all_ctx(struct obd_import *imp);
 int  sptlrpc_req_get_ctx(struct ptlrpc_request *req);
 void sptlrpc_req_put_ctx(struct ptlrpc_request *req, int sync);
 int  sptlrpc_req_refresh_ctx(struct ptlrpc_request *req, long timeout);
-int  sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req);
 void sptlrpc_req_set_flavor(struct ptlrpc_request *req, int opcode);
 
-int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule);
-
 /* gc */
 void sptlrpc_gc_add_sec(struct ptlrpc_sec *sec);
 void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec);
-void sptlrpc_gc_add_ctx(struct ptlrpc_cli_ctx *ctx);
 
 /* misc */
 const char *sec2target_str(struct ptlrpc_sec *sec);
@@ -1078,25 +1049,11 @@ int  sptlrpc_svc_wrap_reply(struct ptlrpc_request *req);
 void sptlrpc_svc_free_rs(struct ptlrpc_reply_state *rs);
 void sptlrpc_svc_ctx_addref(struct ptlrpc_request *req);
 void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req);
-void sptlrpc_svc_ctx_invalidate(struct ptlrpc_request *req);
 
 int  sptlrpc_target_export_check(struct obd_export *exp,
                                 struct ptlrpc_request *req);
-void sptlrpc_target_update_exp_flavor(struct obd_device *obd,
-                                     struct sptlrpc_rule_set *rset);
-
-/*
- * reverse context
- */
-int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
-                               struct ptlrpc_svc_ctx *ctx);
-int sptlrpc_cli_install_rvs_ctx(struct obd_import *imp,
-                               struct ptlrpc_cli_ctx *ctx);
 
 /* bulk security api */
-int sptlrpc_enc_pool_add_user(void);
-int sptlrpc_enc_pool_del_user(void);
-int  sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc);
 void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc);
 
 int sptlrpc_cli_wrap_bulk(struct ptlrpc_request *req,
@@ -1123,7 +1080,6 @@ int sptlrpc_current_user_desc_size(void);
 int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset);
 int sptlrpc_unpack_user_desc(struct lustre_msg *req, int offset, int swabbed);
 
-
 #define CFS_CAP_CHOWN_MASK (1 << CFS_CAP_CHOWN)
 #define CFS_CAP_SYS_RESOURCE_MASK (1 << CFS_CAP_SYS_RESOURCE)
 
index 9ad8c268da10efe512aff7b530297faaf6d11aed..5e93afca3435226420197cf48d1e0ac04955585d 100644 (file)
@@ -54,7 +54,6 @@
 #include "lustre_export.h"
 #include "lustre_fid.h"
 #include "lustre_fld.h"
-#include "lustre_capa.h"
 
 #define MAX_OBD_DEVICES 8192
 
@@ -144,10 +143,6 @@ typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
 
 /* obd info for a particular level (lov, osc). */
 struct obd_info {
-       /* Lock policy. It keeps an extent which is specific for a particular
-        * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
-        * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
-       ldlm_policy_data_t      oi_policy;
        /* Flags used for set request specific flags:
           - while lock handling, the flags obtained on the enqueue
           request are set here.
@@ -155,8 +150,6 @@ struct obd_info {
           - while setattr, the flags used for distinguish punch operation
         */
        __u64              oi_flags;
-       /* Lock handle specific for every OSC lock. */
-       struct lustre_handle   *oi_lockh;
        /* lsm data specific for every OSC. */
        struct lov_stripe_md   *oi_md;
        /* obdo data specific for every OSC, if needed at all. */
@@ -168,75 +161,8 @@ struct obd_info {
         * request in osc level for enqueue requests. It is also possible to
         * update some caller data from LOV layer if needed. */
        obd_enqueue_update_f    oi_cb_up;
-       /* oss capability, its type is obd_capa in client to avoid copy.
-        * in contrary its type is lustre_capa in OSS. */
-       void               *oi_capa;
-       /* transfer jobid from ost_sync() to filter_sync()... */
-       char               *oi_jobid;
 };
 
-/* compare all relevant fields. */
-static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
-                                   struct lov_stripe_md *m2)
-{
-       /*
-        * ->lsm_wire contains padding, but it should be zeroed out during
-        * allocation.
-        */
-       return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof(m1->lsm_wire));
-}
-
-static inline int lov_lum_lsm_cmp(struct lov_user_md *lum,
-                                 struct lov_stripe_md  *lsm)
-{
-       if (lsm->lsm_magic != lum->lmm_magic)
-               return 1;
-       if ((lsm->lsm_stripe_count != 0) && (lum->lmm_stripe_count != 0) &&
-           (lsm->lsm_stripe_count != lum->lmm_stripe_count))
-               return 2;
-       if ((lsm->lsm_stripe_size != 0) && (lum->lmm_stripe_size != 0) &&
-           (lsm->lsm_stripe_size != lum->lmm_stripe_size))
-               return 3;
-       if ((lsm->lsm_pattern != 0) && (lum->lmm_pattern != 0) &&
-           (lsm->lsm_pattern != lum->lmm_pattern))
-               return 4;
-       if ((lsm->lsm_magic == LOV_MAGIC_V3) &&
-           (strncmp(lsm->lsm_pool_name,
-                    ((struct lov_user_md_v3 *)lum)->lmm_pool_name,
-                    LOV_MAXPOOLNAME) != 0))
-               return 5;
-       return 0;
-}
-
-static inline int lov_lum_swab_if_needed(struct lov_user_md_v3 *lumv3,
-                                        int *lmm_magic,
-                                        struct lov_user_md *lum)
-{
-       if (lum && copy_from_user(lumv3, lum, sizeof(struct lov_user_md_v1)))
-               return -EFAULT;
-
-       *lmm_magic = lumv3->lmm_magic;
-
-       if (*lmm_magic == __swab32(LOV_USER_MAGIC_V1)) {
-               lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lumv3);
-               *lmm_magic = LOV_USER_MAGIC_V1;
-       } else if (*lmm_magic == LOV_USER_MAGIC_V3) {
-               if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
-                       return -EFAULT;
-       } else if (*lmm_magic == __swab32(LOV_USER_MAGIC_V3)) {
-               if (lum && copy_from_user(lumv3, lum, sizeof(*lumv3)))
-                       return -EFAULT;
-               lustre_swab_lov_user_md_v3(lumv3);
-               *lmm_magic = LOV_USER_MAGIC_V3;
-       } else if (*lmm_magic != LOV_USER_MAGIC_V1) {
-               CDEBUG(D_IOCTL,
-                      "bad userland LOV MAGIC: %#08x != %#08x nor %#08x\n",
-                      *lmm_magic, LOV_USER_MAGIC_V1, LOV_USER_MAGIC_V3);
-                      return -EINVAL;
-       }
-       return 0;
-}
-
 void lov_stripe_lock(struct lov_stripe_md *md);
 void lov_stripe_unlock(struct lov_stripe_md *md);
 
@@ -406,9 +332,6 @@ struct client_obd {
        struct mdc_rpc_lock     *cl_close_lock;
 
        /* mgc datastruct */
-       struct mutex             cl_mgc_mutex;
-       struct local_oid_storage *cl_mgc_los;
-       struct dt_object        *cl_mgc_configs_dir;
        atomic_t             cl_mgc_refcount;
        struct obd_export       *cl_mgc_mgsexp;
 
@@ -439,6 +362,7 @@ struct client_obd {
        /* hash tables for osc_quota_info */
        struct cfs_hash       *cl_quota_hash[MAXQUOTAS];
 };
+
 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
 
 struct obd_id_info {
@@ -455,25 +379,6 @@ struct echo_client_obd {
        __u64           ec_unique;
 };
 
-struct lov_qos_oss {
-       struct obd_uuid     lqo_uuid;       /* ptlrpc's c_remote_uuid */
-       struct list_head          lqo_oss_list;   /* link to lov_qos */
-       __u64          lqo_bavail;     /* total bytes avail on OSS */
-       __u64          lqo_penalty;    /* current penalty */
-       __u64          lqo_penalty_per_obj;/* penalty decrease every obj*/
-       time_t        lqo_used;       /* last used time, seconds */
-       __u32          lqo_ost_count;  /* number of osts on this oss */
-};
-
-struct ltd_qos {
-       struct lov_qos_oss *ltq_oss;     /* oss info */
-       __u64          ltq_penalty;     /* current penalty */
-       __u64          ltq_penalty_per_obj; /* penalty decrease every obj*/
-       __u64          ltq_weight;      /* net weighting */
-       time_t        ltq_used; /* last used time, seconds */
-       unsigned int    ltq_usable:1;    /* usable for striping */
-};
-
 /* Generic subset of OSTs */
 struct ost_pool {
        __u32         *op_array;      /* array of index of
@@ -499,6 +404,7 @@ struct lov_statfs_data {
        struct obd_info   lsd_oi;
        struct obd_statfs lsd_statfs;
 };
+
 /* Stripe placement optimization */
 struct lov_qos {
        struct list_head    lq_oss_list; /* list of OSSs that targets use */
@@ -524,7 +430,6 @@ struct lov_tgt_desc {
        struct obd_uuid     ltd_uuid;
        struct obd_device  *ltd_obd;
        struct obd_export  *ltd_exp;
-       struct ltd_qos      ltd_qos;     /* qos info per target */
        __u32          ltd_gen;
        __u32          ltd_index;   /* index in lov_obd->tgts */
        unsigned long       ltd_active:1,/* is this target up for requests */
@@ -728,8 +633,8 @@ static inline void oti_alloc_cookies(struct obd_trans_info *oti,
        if (num_cookies == 1)
                oti->oti_logcookies = &oti->oti_onecookie;
        else
-               OBD_ALLOC_LARGE(oti->oti_logcookies,
-                               num_cookies * sizeof(oti->oti_onecookie));
+               oti->oti_logcookies = libcfs_kvzalloc(num_cookies * sizeof(oti->oti_onecookie),
+                                                     GFP_NOFS);
 
        oti->oti_numcookies = num_cookies;
 }
@@ -742,8 +647,8 @@ static inline void oti_free_cookies(struct obd_trans_info *oti)
        if (oti->oti_logcookies == &oti->oti_onecookie)
                LASSERT(oti->oti_numcookies == 1);
        else
-               OBD_FREE_LARGE(oti->oti_logcookies,
-                              oti->oti_numcookies*sizeof(oti->oti_onecookie));
+               kvfree(oti->oti_logcookies);
+
        oti->oti_logcookies = NULL;
        oti->oti_numcookies = 0;
 }
@@ -822,8 +727,6 @@ struct obd_device {
        /* bitfield modification is protected by obd_dev_lock */
        unsigned long obd_attached:1,      /* finished attach */
                      obd_set_up:1,     /* finished setup */
-                     obd_recovering:1,    /* there are recoverable clients */
-                     obd_abort_recovery:1,/* recovery expired */
                      obd_version_recov:1, /* obd uses version checking */
                      obd_replayable:1,    /* recovery is enabled; inform clients */
                      obd_no_transno:1,    /* no committed-transno notification */
@@ -843,8 +746,6 @@ struct obd_device {
        unsigned long obd_recovery_expired:1;
        /* uuid-export hash body */
        struct cfs_hash      *obd_uuid_hash;
-       /* nid-export hash body */
-       struct cfs_hash      *obd_nid_hash;
        atomic_t            obd_refcount;
        wait_queue_head_t            obd_refcount_waitq;
        struct list_head              obd_exports;
@@ -867,39 +768,6 @@ struct obd_device {
        struct rw_semaphore     obd_observer_link_sem;
        struct obd_notify_upcall obd_upcall;
        struct obd_export       *obd_self_export;
-       /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
-       struct list_head              obd_exports_timed;
-       time_t            obd_eviction_timer; /* for ping evictor */
-
-       int                           obd_max_recoverable_clients;
-       atomic_t                     obd_connected_clients;
-       int                           obd_stale_clients;
-       int                           obd_delayed_clients;
-       /* this lock protects all recovery list_heads, timer and
-        * obd_next_recovery_transno value */
-       spinlock_t                       obd_recovery_task_lock;
-       __u64                       obd_next_recovery_transno;
-       int                           obd_replayed_requests;
-       int                           obd_requests_queued_for_recovery;
-       wait_queue_head_t                     obd_next_transno_waitq;
-       /* protected by obd_recovery_task_lock */
-       struct timer_list       obd_recovery_timer;
-       time_t                  obd_recovery_start; /* seconds */
-       time_t                  obd_recovery_end; /* seconds, for lprocfs_status */
-       int                           obd_recovery_time_hard;
-       int                           obd_recovery_timeout;
-       int                           obd_recovery_ir_factor;
-
-       /* new recovery stuff from CMD2 */
-       struct target_recovery_data      obd_recovery_data;
-       int                           obd_replayed_locks;
-       atomic_t                     obd_req_replay_clients;
-       atomic_t                     obd_lock_replay_clients;
-       /* all lists are protected by obd_recovery_task_lock */
-       struct list_head                       obd_req_replay_queue;
-       struct list_head                       obd_lock_replay_queue;
-       struct list_head                       obd_final_req_queue;
-       int                           obd_recovery_stage;
 
        union {
                struct client_obd cli;
@@ -954,7 +822,6 @@ enum obd_cleanup_stage {
 #define KEY_ASYNC             "async"
 #define KEY_BLOCKSIZE_BITS      "blocksize_bits"
 #define KEY_BLOCKSIZE     "blocksize"
-#define KEY_CAPA_KEY       "capa_key"
 #define KEY_CHANGELOG_CLEAR     "changelog_clear"
 #define KEY_FID2PATH       "fid2path"
 #define KEY_CHECKSUM       "checksum"
@@ -975,8 +842,6 @@ enum obd_cleanup_stage {
 #define KEY_LOV_IDX         "lov_idx"
 #define KEY_MAX_EASIZE         "max_easize"
 #define KEY_DEFAULT_EASIZE     "default_easize"
-#define KEY_MAX_COOKIESIZE     "max_cookiesize"
-#define KEY_DEFAULT_COOKIESIZE "default_cookiesize"
 #define KEY_MDS_CONN       "mds_conn"
 #define KEY_MGSSEC           "mgssec"
 #define KEY_NEXT_ID         "next_id"
@@ -1057,10 +922,6 @@ struct md_op_data {
        __u64              op_ioepoch;
        __u32              op_flags;
 
-       /* Capa fields */
-       struct obd_capa *op_capa1;
-       struct obd_capa *op_capa2;
-
        /* Various operation flags. */
        enum mds_op_bias        op_bias;
 
@@ -1161,14 +1022,12 @@ struct obd_ops {
                          struct lov_stripe_md **mem_tgt,
                          struct lov_mds_md *disk_src, int disk_len);
        int (*o_preallocate)(struct lustre_handle *, u32 *req, u64 *ids);
-       /* FIXME: add fid capability support for create & destroy! */
        int (*o_create)(const struct lu_env *env, struct obd_export *exp,
                        struct obdo *oa, struct lov_stripe_md **ea,
                        struct obd_trans_info *oti);
        int (*o_destroy)(const struct lu_env *env, struct obd_export *exp,
                         struct obdo *oa, struct lov_stripe_md *ea,
-                        struct obd_trans_info *oti, struct obd_export *md_exp,
-                        void *capa);
+                        struct obd_trans_info *oti, struct obd_export *md_exp);
        int (*o_setattr)(const struct lu_env *, struct obd_export *exp,
                         struct obd_info *oinfo, struct obd_trans_info *oti);
        int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
@@ -1184,7 +1043,7 @@ struct obd_ops {
                        struct obd_export *exp, struct obdo *oa, int objcount,
                        struct obd_ioobj *obj, struct niobuf_remote *remote,
                        int *nr_pages, struct niobuf_local *local,
-                       struct obd_trans_info *oti, struct lustre_capa *capa);
+                       struct obd_trans_info *oti);
        int (*o_commitrw)(const struct lu_env *env, int cmd,
                          struct obd_export *exp, struct obdo *oa,
                          int objcount, struct obd_ioobj *obj,
@@ -1252,8 +1111,6 @@ struct lustre_md {
        struct posix_acl        *posix_acl;
 #endif
        struct mdt_remote_perm  *remote_perm;
-       struct obd_capa  *mds_capa;
-       struct obd_capa  *oss_capa;
 };
 
 struct md_open_data {
@@ -1267,8 +1124,7 @@ struct md_open_data {
 struct lookup_intent;
 
 struct md_ops {
-       int (*m_getstatus)(struct obd_export *, struct lu_fid *,
-                          struct obd_capa **);
+       int (*m_getstatus)(struct obd_export *, struct lu_fid *);
        int (*m_null_inode)(struct obd_export *, const struct lu_fid *);
        int (*m_find_cbdata)(struct obd_export *, const struct lu_fid *,
                             ldlm_iterator_t, void *);
@@ -1300,10 +1156,10 @@ struct md_ops {
                           const struct lu_fid *,
                           struct ptlrpc_request **);
        int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
-                        int , void *, int, struct ptlrpc_request **,
+                        int, void *, int, struct ptlrpc_request **,
                         struct md_open_data **mod);
        int (*m_sync)(struct obd_export *, const struct lu_fid *,
-                     struct obd_capa *, struct ptlrpc_request **);
+                     struct ptlrpc_request **);
        int (*m_readpage)(struct obd_export *, struct md_op_data *,
                          struct page **, struct ptlrpc_request **);
 
@@ -1311,13 +1167,11 @@ struct md_ops {
                        struct ptlrpc_request **);
 
        int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
-                         struct obd_capa *, u64, const char *,
-                         const char *, int, int, int, __u32,
+                         u64, const char *, const char *, int, int, int, __u32,
                          struct ptlrpc_request **);
 
        int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
-                         struct obd_capa *, u64, const char *,
-                         const char *, int, int, int,
+                         u64, const char *, const char *, int, int, int,
                          struct ptlrpc_request **);
 
        int (*m_init_ea_size)(struct obd_export *, int, int, int, int);
@@ -1343,14 +1197,9 @@ struct md_ops {
        int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
                               ldlm_policy_data_t *, ldlm_mode_t,
                               ldlm_cancel_flags_t flags, void *opaque);
-       int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
-                           renew_capa_cb_t cb);
-       int (*m_unpack_capa)(struct obd_export *, struct ptlrpc_request *,
-                            const struct req_msg_field *, struct obd_capa **);
 
        int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
-                                struct obd_capa *, __u32,
-                                struct ptlrpc_request **);
+                                __u32, struct ptlrpc_request **);
 
        int (*m_intent_getattr_async)(struct obd_export *,
                                      struct md_enqueue_info *,
@@ -1399,16 +1248,11 @@ static inline const struct lsm_operations *lsm_op_find(int magic)
 #define OBD_CALC_STRIPE_START   1
 #define OBD_CALC_STRIPE_END     2
 
-static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
-{
-       return oinfo->oi_capa;
-}
-
 static inline struct md_open_data *obd_mod_alloc(void)
 {
        struct md_open_data *mod;
 
-       OBD_ALLOC_PTR(mod);
+       mod = kzalloc(sizeof(*mod), GFP_NOFS);
        if (mod == NULL)
                return NULL;
        atomic_set(&mod->mod_refcount, 1);
@@ -1421,7 +1265,7 @@ static inline struct md_open_data *obd_mod_alloc(void)
        if (atomic_dec_and_test(&(mod)->mod_refcount)) {          \
                if ((mod)->mod_open_req)                          \
                        ptlrpc_req_finished((mod)->mod_open_req);   \
-               OBD_FREE_PTR(mod);                            \
+               kfree(mod);                           \
        }                                                      \
 })
 
diff --git a/drivers/staging/lustre/lustre/include/obd_cache.h b/drivers/staging/lustre/lustre/include/obd_cache.h
deleted file mode 100644 (file)
index c8249fb..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-
-#ifndef _OBD_CACHE_H__
-#define _OBD_CACHE_H__
-
-
-#endif
index 3a63462aa943845c754ec53ef79d3dc72a22456c..a0099d71773a77e1072abe8b10efeabc09c6cb9c 100644 (file)
@@ -156,7 +156,6 @@ static inline cksum_type_t cksum_types_supported_server(void)
        return ret;
 }
 
-
 /* Select the best checksum algorithm among those supplied in the cksum_types
  * input.
  *
index 87bb2cedca7d0002621e334cdf2447ca1b175721..fd5f3731db9264e54a2cc7b574929e21cda1954b 100644 (file)
@@ -36,7 +36,6 @@
 #ifndef __CLASS_OBD_H
 #define __CLASS_OBD_H
 
-
 #include "obd_support.h"
 #include "lustre_import.h"
 #include "lustre_net.h"
@@ -64,7 +63,6 @@ extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
 extern rwlock_t obd_dev_lock;
 
 /* OBD Operations Declarations */
-struct obd_device *class_conn2obd(struct lustre_handle *);
 struct obd_device *class_exp2obd(struct obd_export *);
 int class_handle_ioctl(unsigned int cmd, unsigned long arg);
 int lustre_get_jobid(char *jobid);
@@ -84,58 +82,36 @@ void class_release_dev(struct obd_device *obd);
 int class_name2dev(const char *name);
 struct obd_device *class_name2obd(const char *name);
 int class_uuid2dev(struct obd_uuid *uuid);
-struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
-void class_obd_list(void);
 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
                                          const char *typ_name,
                                          struct obd_uuid *grp_uuid);
 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
                                           int *next);
 struct obd_device *class_num2obd(int num);
-int get_devices_count(void);
 
 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
 
-char *obd_export_nid2str(struct obd_export *exp);
-
-int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
-int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
 
 int obd_zombie_impexp_init(void);
 void obd_zombie_impexp_stop(void);
-void obd_zombie_impexp_cull(void);
 void obd_zombie_barrier(void);
-void obd_exports_barrier(struct obd_device *obd);
-int kuc_len(int payload_len);
-struct kuc_hdr *kuc_ptr(void *p);
-int kuc_ispayload(void *p);
-void *kuc_alloc(int payload_len, int transport, int type);
-void kuc_free(void *p, int payload_len);
 
 struct llog_handle;
 struct llog_rec_hdr;
 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
                         struct llog_rec_hdr *, void *);
 /* obd_config.c */
-struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
-                                    const char *new_name);
 int class_process_config(struct lustre_cfg *lcfg);
 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
                             struct lustre_cfg *lcfg, void *data);
-int class_attach(struct lustre_cfg *lcfg);
-int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
-int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
-int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
 struct obd_device *class_incref(struct obd_device *obd,
                                const char *scope, const void *source);
 void class_decref(struct obd_device *obd,
                  const char *scope, const void *source);
-void dump_exports(struct obd_device *obd, int locks);
 int class_config_llog_handler(const struct lu_env *env,
                              struct llog_handle *handle,
                              struct llog_rec_hdr *rec, void *data);
-int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
 int class_add_uuid(const char *uuid, __u64 nid);
 
 /*obdecho*/
@@ -157,11 +133,9 @@ struct config_llog_instance {
        int              cfg_last_idx; /* for partial llog processing */
        int              cfg_flags;
 };
+
 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
                            char *name, struct config_llog_instance *cfg);
-int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
-                          char *name, struct config_llog_instance *cfg);
-
 enum {
        CONFIG_T_CONFIG  = 0,
        CONFIG_T_SPTLRPC = 1,
@@ -215,6 +189,25 @@ extern void (*class_export_dump_hook)(struct obd_export *);
 
 #endif
 
+/* genops.c */
+struct obd_export *class_export_get(struct obd_export *exp);
+void class_export_put(struct obd_export *exp);
+struct obd_export *class_new_export(struct obd_device *obddev,
+                               struct obd_uuid *cluuid);
+void class_unlink_export(struct obd_export *exp);
+
+struct obd_import *class_import_get(struct obd_import *);
+void class_import_put(struct obd_import *);
+struct obd_import *class_new_import(struct obd_device *obd);
+void class_destroy_import(struct obd_import *exp);
+
+void class_put_type(struct obd_type *type);
+int class_connect(struct lustre_handle *conn, struct obd_device *obd,
+               struct obd_uuid *cluuid);
+int class_disconnect(struct obd_export *exp);
+void class_fail_export(struct obd_export *exp);
+int class_manual_cleanup(struct obd_device *obd);
+
 static inline void class_export_rpc_inc(struct obd_export *exp)
 {
        atomic_inc(&(exp)->exp_rpc_count);
@@ -230,93 +223,51 @@ static inline void class_export_rpc_dec(struct obd_export *exp)
               (exp), atomic_read(&(exp)->exp_rpc_count));
 }
 
-#define class_export_lock_get(exp, lock)                               \
-({                                                                   \
-       atomic_inc(&(exp)->exp_locks_count);                    \
-       __class_export_add_lock_ref(exp, lock);                  \
-       CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
-              (exp), atomic_read(&(exp)->exp_locks_count));    \
-       class_export_get(exp);                                    \
-})
-
-#define class_export_lock_put(exp, lock)                               \
-({                                                                   \
-       LASSERT_ATOMIC_POS(&exp->exp_locks_count);                    \
-       atomic_dec(&(exp)->exp_locks_count);                    \
-       __class_export_del_lock_ref(exp, lock);                  \
-       CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
-              (exp), atomic_read(&(exp)->exp_locks_count));    \
-       class_export_put(exp);                                    \
-})
-
-#define class_export_cb_get(exp)                                       \
-({                                                                   \
-       atomic_inc(&(exp)->exp_cb_count);                          \
-       CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
-              (exp), atomic_read(&(exp)->exp_cb_count));          \
-       class_export_get(exp);                                    \
-})
-
-#define class_export_cb_put(exp)                                       \
-({                                                                   \
-       LASSERT_ATOMIC_POS(&exp->exp_cb_count);                  \
-       atomic_dec(&(exp)->exp_cb_count);                          \
-       CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
-              (exp), atomic_read(&(exp)->exp_cb_count));          \
-       class_export_put(exp);                                    \
-})
-
-/* genops.c */
-struct obd_export *class_export_get(struct obd_export *exp);
-void class_export_put(struct obd_export *exp);
-struct obd_export *class_new_export(struct obd_device *obddev,
-                                   struct obd_uuid *cluuid);
-void class_unlink_export(struct obd_export *exp);
+static inline struct obd_export *class_export_lock_get(struct obd_export *exp,
+                                                      struct ldlm_lock *lock)
+{
+       atomic_inc(&(exp)->exp_locks_count);
+       __class_export_add_lock_ref(exp, lock);
+       CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n",
+              (exp), atomic_read(&(exp)->exp_locks_count));
+       return class_export_get(exp);
+}
 
-struct obd_import *class_import_get(struct obd_import *);
-void class_import_put(struct obd_import *);
-struct obd_import *class_new_import(struct obd_device *obd);
-void class_destroy_import(struct obd_import *exp);
+static inline void class_export_lock_put(struct obd_export *exp,
+                                        struct ldlm_lock *lock)
+{
+       LASSERT_ATOMIC_POS(&exp->exp_locks_count);
+       atomic_dec(&(exp)->exp_locks_count);
+       __class_export_del_lock_ref(exp, lock);
+       CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n",
+              (exp), atomic_read(&(exp)->exp_locks_count));
+       class_export_put(exp);
+}
 
-struct obd_type *class_search_type(const char *name);
-struct obd_type *class_get_type(const char *name);
-void class_put_type(struct obd_type *type);
-int class_connect(struct lustre_handle *conn, struct obd_device *obd,
-                 struct obd_uuid *cluuid);
-int class_disconnect(struct obd_export *exp);
-void class_fail_export(struct obd_export *exp);
-int class_connected_export(struct obd_export *exp);
-void class_disconnect_exports(struct obd_device *obddev);
-int class_manual_cleanup(struct obd_device *obd);
-void class_disconnect_stale_exports(struct obd_device *,
-                                   int (*test_export)(struct obd_export *));
 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
 {
        return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
                (obd->obd_force ? OBD_OPT_FORCE : 0) |
-               (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
                0);
 }
 
+static inline int lprocfs_climp_check(struct obd_device *obd)
+{
+       down_read(&(obd)->u.cli.cl_sem);
+       if (!(obd)->u.cli.cl_import) {
+               up_read(&(obd)->u.cli.cl_sem);
+               return -ENODEV;
+       }
+       return 0;
+}
+
 struct inode;
 struct lu_attr;
 struct obdo;
-void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid);
-void la_from_obdo(struct lu_attr *la, struct obdo *dst, u32 valid);
 void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid);
-void obdo_to_inode(struct inode *dst, struct obdo *src, u32 valid);
 
-void obdo_cpy_md(struct obdo *dst, struct obdo *src, u32 valid);
 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
-void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
-                    unsigned int ia_valid);
-void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid);
 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid);
-void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
-                 unsigned int valid);
-
-void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo);
-void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
 
 #define OBT(dev)       (dev)->obd_type
 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
@@ -398,17 +349,6 @@ static inline int obd_check_dev_active(struct obd_device *obd)
                                (export)->exp_md_stats, coffset);           \
        }
 
-
-#define OBD_CHECK_MD_OP(obd, op, err)                     \
-do {                                                       \
-       if (!OBT(obd) || !MDP((obd), op)) {                  \
-               if (err)                                        \
-                       CERROR("md_" #op ": dev %s/%d no operation\n", \
-                              obd->obd_name, obd->obd_minor);  \
-               return err;                                 \
-       }                                                      \
-} while (0)
-
 #define EXP_CHECK_MD_OP(exp, op)                               \
 do {                                                       \
        if ((exp) == NULL) {                                \
@@ -427,7 +367,6 @@ do {                                                            \
        }                                                      \
 } while (0)
 
-
 #define OBD_CHECK_DT_OP(obd, op, err)                     \
 do {                                                       \
        if (!OBT(obd) || !OBP((obd), op)) {                  \
@@ -531,6 +470,7 @@ static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
        if (ldt != NULL) {
                struct lu_context  session_ctx;
                struct lu_env env;
+
                lu_context_init(&session_ctx, LCT_SESSION);
                session_ctx.lc_thread = NULL;
                lu_context_enter(&session_ctx);
@@ -622,14 +562,11 @@ static inline void obd_cleanup_client_import(struct obd_device *obd)
        down_write(&obd->u.cli.cl_sem);
        if (obd->u.cli.cl_import) {
                struct obd_import *imp;
+
                imp = obd->u.cli.cl_import;
                CDEBUG(D_CONFIG, "%s: client import never connected\n",
                       obd->obd_name);
                ptlrpc_invalidate_import(imp);
-               if (imp->imp_rq_pool) {
-                       ptlrpc_free_rq_pool(imp->imp_rq_pool);
-                       imp->imp_rq_pool = NULL;
-               }
                client_destroy_import(imp);
                obd->u.cli.cl_import = NULL;
        }
@@ -769,14 +706,14 @@ static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
                              struct obdo *obdo, struct lov_stripe_md *ea,
                              struct obd_trans_info *oti,
-                             struct obd_export *md_exp, void *capa)
+                             struct obd_export *md_exp)
 {
        int rc;
 
        EXP_CHECK_DT_OP(exp, destroy);
        EXP_COUNTER_INCREMENT(exp, destroy);
 
-       rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
+       rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp);
        return rc;
 }
 
@@ -1118,7 +1055,7 @@ static inline int obd_statfs_rqset(struct obd_export *exp,
                                   __u32 flags)
 {
        struct ptlrpc_request_set *set = NULL;
-       struct obd_info oinfo = { { { 0 } } };
+       struct obd_info oinfo = { };
        int rc = 0;
 
        set =  ptlrpc_prep_set();
@@ -1177,8 +1114,7 @@ static inline int obd_preprw(const struct lu_env *env, int cmd,
                             int objcount, struct obd_ioobj *obj,
                             struct niobuf_remote *remote, int *pages,
                             struct niobuf_local *local,
-                            struct obd_trans_info *oti,
-                            struct lustre_capa *capa)
+                            struct obd_trans_info *oti)
 {
        int rc;
 
@@ -1186,7 +1122,7 @@ static inline int obd_preprw(const struct lu_env *env, int cmd,
        EXP_COUNTER_INCREMENT(exp, preprw);
 
        rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
-                                      pages, local, oti, capa);
+                                      pages, local, oti);
        return rc;
 }
 
@@ -1434,14 +1370,13 @@ static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
 #endif
 
 /* metadata helpers */
-static inline int md_getstatus(struct obd_export *exp,
-                              struct lu_fid *fid, struct obd_capa **pc)
+static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
 {
        int rc;
 
        EXP_CHECK_MD_OP(exp, getstatus);
        EXP_MD_COUNTER_INCREMENT(exp, getstatus);
-       rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
+       rc = MDP(exp->exp_obd, getstatus)(exp, fid);
        return rc;
 }
 
@@ -1616,13 +1551,13 @@ static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
 }
 
 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
-                         struct obd_capa *oc, struct ptlrpc_request **request)
+                         struct ptlrpc_request **request)
 {
        int rc;
 
        EXP_CHECK_MD_OP(exp, sync);
        EXP_MD_COUNTER_INCREMENT(exp, sync);
-       rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
+       rc = MDP(exp->exp_obd, sync)(exp, fid, request);
        return rc;
 }
 
@@ -1668,8 +1603,7 @@ static inline int md_free_lustre_md(struct obd_export *exp,
        return MDP(exp->exp_obd, free_lustre_md)(exp, md);
 }
 
-static inline int md_setxattr(struct obd_export *exp,
-                             const struct lu_fid *fid, struct obd_capa *oc,
+static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
                              u64 valid, const char *name,
                              const char *input, int input_size,
                              int output_size, int flags, __u32 suppgid,
@@ -1677,13 +1611,12 @@ static inline int md_setxattr(struct obd_export *exp,
 {
        EXP_CHECK_MD_OP(exp, setxattr);
        EXP_MD_COUNTER_INCREMENT(exp, setxattr);
-       return MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
+       return MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
                                           input_size, output_size, flags,
                                           suppgid, request);
 }
 
-static inline int md_getxattr(struct obd_export *exp,
-                             const struct lu_fid *fid, struct obd_capa *oc,
+static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
                              u64 valid, const char *name,
                              const char *input, int input_size,
                              int output_size, int flags,
@@ -1691,7 +1624,7 @@ static inline int md_getxattr(struct obd_export *exp,
 {
        EXP_CHECK_MD_OP(exp, getxattr);
        EXP_MD_COUNTER_INCREMENT(exp, getxattr);
-       return MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
+       return MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
                                           input_size, output_size, flags,
                                           request);
 }
@@ -1762,40 +1695,15 @@ static inline int md_init_ea_size(struct obd_export *exp, int easize,
 }
 
 static inline int md_get_remote_perm(struct obd_export *exp,
-                                    const struct lu_fid *fid,
-                                    struct obd_capa *oc, __u32 suppgid,
+                                    const struct lu_fid *fid, __u32 suppgid,
                                     struct ptlrpc_request **request)
 {
        EXP_CHECK_MD_OP(exp, get_remote_perm);
        EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
-       return MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
+       return MDP(exp->exp_obd, get_remote_perm)(exp, fid, suppgid,
                                                  request);
 }
 
-static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
-                               renew_capa_cb_t cb)
-{
-       int rc;
-
-       EXP_CHECK_MD_OP(exp, renew_capa);
-       EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
-       rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
-       return rc;
-}
-
-static inline int md_unpack_capa(struct obd_export *exp,
-                                struct ptlrpc_request *req,
-                                const struct req_msg_field *field,
-                                struct obd_capa **oc)
-{
-       int rc;
-
-       EXP_CHECK_MD_OP(exp, unpack_capa);
-       EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
-       rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
-       return rc;
-}
-
 static inline int md_intent_getattr_async(struct obd_export *exp,
                                          struct md_enqueue_info *minfo,
                                          struct ldlm_enqueue_info *einfo)
@@ -1820,7 +1728,6 @@ static inline int md_revalidate_lock(struct obd_export *exp,
        return rc;
 }
 
-
 /* OBD Metadata Support */
 
 int obd_init_caches(void);
@@ -1829,17 +1736,6 @@ void obd_cleanup_caches(void);
 /* support routines */
 extern struct kmem_cache *obdo_cachep;
 
-#define OBDO_ALLOC(ptr)                                                       \
-do {                                                                     \
-       OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS);             \
-} while (0)
-
-#define OBDO_FREE(ptr)                                                 \
-do {                                                                     \
-       OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                          \
-} while (0)
-
-
 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
 {
        /* something here */
index 18aec796a724a77b2a84b2217913d353293a4a8e..a22a5308fb48d0de96b67cac62ea2bc41e92ec74 100644 (file)
 #include "lprocfs_status.h"
 
 /* global variables */
-extern struct lprocfs_stats *obd_memory;
-enum {
-       OBD_MEMORY_STAT = 0,
-       OBD_MEMORY_PAGES_STAT = 1,
-       OBD_STATS_NUM,
-};
-
 extern unsigned int obd_debug_peer_on_timeout;
 extern unsigned int obd_dump_on_timeout;
 extern unsigned int obd_dump_on_eviction;
@@ -66,13 +59,8 @@ extern unsigned int obd_sync_filter;
 extern unsigned int obd_max_dirty_pages;
 extern atomic_t obd_dirty_pages;
 extern atomic_t obd_dirty_transit_pages;
-extern unsigned int obd_alloc_fail_rate;
 extern char obd_jobid_var[];
 
-/* lvfs.c */
-int obd_alloc_fail(const void *ptr, const char *name, const char *type,
-                  size_t size, const char *file, int line);
-
 /* Some hash init argument constants */
 #define HASH_POOLS_BKT_BITS 3
 #define HASH_POOLS_CUR_BITS 3
@@ -428,8 +416,6 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 
 #define OBD_FAIL_LPROC_REMOVE      0xB00
 
-#define OBD_FAIL_GENERAL_ALLOC    0xC00
-
 #define OBD_FAIL_SEQ                0x1000
 #define OBD_FAIL_SEQ_QUERY_NET    0x1001
 #define OBD_FAIL_SEQ_EXHAUST            0x1002
@@ -486,7 +472,6 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_UPDATE_OBJ_NET                        0x1700
 #define OBD_FAIL_UPDATE_OBJ_NET_REP            0x1701
 
-
 /* Assign references to moved code to reduce code changes */
 #define OBD_FAIL_PRECHECK(id)             CFS_FAIL_PRECHECK(id)
 #define OBD_FAIL_CHECK(id)                   CFS_FAIL_CHECK(id)
@@ -501,151 +486,6 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
 #define OBD_FAIL_ONCE                     CFS_FAIL_ONCE
 #define OBD_FAILED                           CFS_FAILED
 
-void obd_update_maxusage(void);
-
-#define obd_memory_add(size)                                             \
-       lprocfs_counter_add(obd_memory, OBD_MEMORY_STAT, (long)(size))
-#define obd_memory_sub(size)                                             \
-       lprocfs_counter_sub(obd_memory, OBD_MEMORY_STAT, (long)(size))
-#define obd_memory_sum()                                                     \
-       lprocfs_stats_collector(obd_memory, OBD_MEMORY_STAT,              \
-                               LPROCFS_FIELDS_FLAGS_SUM)
-#define obd_pages_add(order)                                             \
-       lprocfs_counter_add(obd_memory, OBD_MEMORY_PAGES_STAT,          \
-                           (long)(1 << (order)))
-#define obd_pages_sub(order)                                             \
-       lprocfs_counter_sub(obd_memory, OBD_MEMORY_PAGES_STAT,          \
-                           (long)(1 << (order)))
-#define obd_pages_sum()                                                       \
-       lprocfs_stats_collector(obd_memory, OBD_MEMORY_PAGES_STAT,          \
-                               LPROCFS_FIELDS_FLAGS_SUM)
-
-__u64 obd_memory_max(void);
-__u64 obd_pages_max(void);
-
-#define OBD_DEBUG_MEMUSAGE (1)
-
-#if OBD_DEBUG_MEMUSAGE
-#define OBD_ALLOC_POST(ptr, size, name)                                 \
-               obd_memory_add(size);                              \
-               CDEBUG(D_MALLOC, name " '" #ptr "': %d at %p.\n",       \
-                      (int)(size), ptr)
-
-#define OBD_FREE_PRE(ptr, size, name)                             \
-       LASSERT(ptr);                                              \
-       obd_memory_sub(size);                                      \
-       CDEBUG(D_MALLOC, name " '" #ptr "': %d at %p.\n",              \
-              (int)(size), ptr);                                      \
-       POISON(ptr, 0x5a, size)
-
-#else /* !OBD_DEBUG_MEMUSAGE */
-
-#define OBD_ALLOC_POST(ptr, size, name) ((void)0)
-#define OBD_FREE_PRE(ptr, size, name)   ((void)0)
-
-#endif /* !OBD_DEBUG_MEMUSAGE */
-
-#define HAS_FAIL_ALLOC_FLAG OBD_FAIL_CHECK(OBD_FAIL_GENERAL_ALLOC)
-
-#define OBD_ALLOC_FAIL_BITS 24
-#define OBD_ALLOC_FAIL_MASK ((1 << OBD_ALLOC_FAIL_BITS) - 1)
-#define OBD_ALLOC_FAIL_MULT (OBD_ALLOC_FAIL_MASK / 100)
-
-#if defined(LUSTRE_UTILS) /* this version is for utils only */
-#define __OBD_MALLOC_VERBOSE(ptr, cptab, cpt, size, flags)                   \
-do {                                                                         \
-       (ptr) = (cptab) == NULL ?                                             \
-               kmalloc(size, flags) :                                \
-               kmalloc_node(size, flags, cfs_cpt_spread_node(cptab, cpt));   \
-       if (unlikely((ptr) == NULL)) {                                  \
-               CERROR("kmalloc of '" #ptr "' (%d bytes) failed at %s:%d\n",  \
-                      (int)(size), __FILE__, __LINE__);                      \
-       } else {                                                              \
-               memset(ptr, 0, size);                                         \
-               CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p\n",          \
-                      (int)(size), ptr);                                     \
-       }                                                                     \
-} while (0)
-
-#else /* this version is for the kernel and liblustre */
-#define OBD_FREE_RTN0(ptr)                                                 \
-({                                                                         \
-       kfree(ptr);                                                     \
-       (ptr) = NULL;                                                    \
-       0;                                                                  \
-})
-
-#define __OBD_MALLOC_VERBOSE(ptr, cptab, cpt, size, flags)                   \
-do {                                                                         \
-       (ptr) = (cptab) == NULL ?                                             \
-               kmalloc(size, flags | __GFP_ZERO) :                           \
-               kmalloc_node(size, flags | __GFP_ZERO,                        \
-                            cfs_cpt_spread_node(cptab, cpt));                \
-       if (likely((ptr) != NULL &&                                        \
-                  (!HAS_FAIL_ALLOC_FLAG || obd_alloc_fail_rate == 0 ||       \
-                   !obd_alloc_fail(ptr, #ptr, "km", size,                  \
-                                   __FILE__, __LINE__) ||                  \
-                   OBD_FREE_RTN0(ptr)))){                                  \
-               OBD_ALLOC_POST(ptr, size, "kmalloced");                \
-       }                                                                    \
-} while (0)
-#endif
-
-#define OBD_ALLOC_GFP(ptr, size, gfp_mask)                                   \
-       __OBD_MALLOC_VERBOSE(ptr, NULL, 0, size, gfp_mask)
-
-#define OBD_ALLOC(ptr, size) OBD_ALLOC_GFP(ptr, size, GFP_NOFS)
-#define OBD_ALLOC_WAIT(ptr, size) OBD_ALLOC_GFP(ptr, size, GFP_KERNEL)
-#define OBD_ALLOC_PTR(ptr) OBD_ALLOC(ptr, sizeof(*(ptr)))
-#define OBD_ALLOC_PTR_WAIT(ptr) OBD_ALLOC_WAIT(ptr, sizeof(*(ptr)))
-
-#define OBD_CPT_ALLOC_GFP(ptr, cptab, cpt, size, gfp_mask)                   \
-       __OBD_MALLOC_VERBOSE(ptr, cptab, cpt, size, gfp_mask)
-
-#define OBD_CPT_ALLOC(ptr, cptab, cpt, size)                                 \
-       OBD_CPT_ALLOC_GFP(ptr, cptab, cpt, size, GFP_NOFS)
-
-#define OBD_CPT_ALLOC_PTR(ptr, cptab, cpt)                                   \
-       OBD_CPT_ALLOC(ptr, cptab, cpt, sizeof(*(ptr)))
-
-# define __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)                        \
-do {                                                                         \
-       (ptr) = cptab == NULL ?                                               \
-               vzalloc(size) :                                               \
-               vzalloc_node(size, cfs_cpt_spread_node(cptab, cpt));          \
-       if (unlikely((ptr) == NULL)) {                                  \
-               CERROR("vmalloc of '" #ptr "' (%d bytes) failed\n",        \
-                      (int)(size));                                      \
-               CERROR("%llu total bytes allocated by Lustre\n",              \
-                      obd_memory_sum());                                     \
-       } else {                                                              \
-               OBD_ALLOC_POST(ptr, size, "vmalloced");                \
-       }                                                                    \
-} while (0)
-
-# define OBD_VMALLOC(ptr, size)                                                      \
-        __OBD_VMALLOC_VEROBSE(ptr, NULL, 0, size)
-# define OBD_CPT_VMALLOC(ptr, cptab, cpt, size)                                      \
-        __OBD_VMALLOC_VEROBSE(ptr, cptab, cpt, size)
-
-
-#define OBD_ALLOC_LARGE(ptr, size)                                         \
-do {                                                                     \
-       ptr = libcfs_kvzalloc(size, GFP_NOFS);                            \
-} while (0)
-
-#define OBD_CPT_ALLOC_LARGE(ptr, cptab, cpt, size)                           \
-do {                                                                         \
-       ptr = libcfs_kvzalloc_cpt(cptab, cpt, size, GFP_NOFS);                \
-} while (0)
-
-#define OBD_FREE_LARGE(ptr, size)                                           \
-do {                                                                     \
-       (void)(size);                                                   \
-       kvfree(ptr);                                                      \
-} while (0)
-
-
 #ifdef CONFIG_DEBUG_SLAB
 #define POISON(ptr, c, s) do {} while (0)
 #define POISON_PTR(ptr)  ((void)0)
@@ -655,20 +495,14 @@ do {                                                                        \
 #endif
 
 #ifdef POISON_BULK
-#define POISON_PAGE(page, val) do { memset(kmap(page), val, PAGE_CACHE_SIZE);   \
-                                   kunmap(page); } while (0)
+#define POISON_PAGE(page, val) do {              \
+       memset(kmap(page), val, PAGE_CACHE_SIZE); \
+       kunmap(page);                             \
+} while (0)
 #else
 #define POISON_PAGE(page, val) do { } while (0)
 #endif
 
-#define OBD_FREE(ptr, size)                                               \
-do {                                                                     \
-       OBD_FREE_PRE(ptr, size, "kfreed");                                  \
-       kfree(ptr);                                                     \
-       POISON_PTR(ptr);                                                      \
-} while (0)
-
-
 #define OBD_FREE_RCU(ptr, size, handle)                                              \
 do {                                                                         \
        struct portals_handle *__h = (handle);                                \
@@ -680,117 +514,7 @@ do {                                                                            \
        POISON_PTR(ptr);                                                      \
 } while (0)
 
-
-#define OBD_VFREE(ptr, size)                           \
-       do {                                            \
-               OBD_FREE_PRE(ptr, size, "vfreed");      \
-               vfree(ptr);                     \
-               POISON_PTR(ptr);                        \
-       } while (0)
-
-/* we memset() the slab object to 0 when allocation succeeds, so DO NOT
- * HAVE A CTOR THAT DOES ANYTHING.  its work will be cleared here.  we'd
- * love to assert on that, but slab.c keeps kmem_cache_s all to itself. */
-#define OBD_SLAB_FREE_RTN0(ptr, slab)                                   \
-({                                                                         \
-       kmem_cache_free((slab), (ptr));                             \
-       (ptr) = NULL;                                                    \
-       0;                                                                  \
-})
-
-#define __OBD_SLAB_ALLOC_VERBOSE(ptr, slab, cptab, cpt, size, type)          \
-do {                                                                         \
-       LASSERT(ergo((type) != GFP_ATOMIC, !in_interrupt()));         \
-       (ptr) = (cptab) == NULL ?                                             \
-               kmem_cache_alloc(slab, type | __GFP_ZERO) :             \
-               kmem_cache_alloc_node(slab, type | __GFP_ZERO,          \
-                                     cfs_cpt_spread_node(cptab, cpt)); \
-       if (likely((ptr) != NULL &&                                        \
-                  (!HAS_FAIL_ALLOC_FLAG || obd_alloc_fail_rate == 0 ||       \
-                   !obd_alloc_fail(ptr, #ptr, "slab-", size,            \
-                                   __FILE__, __LINE__) ||                  \
-                   OBD_SLAB_FREE_RTN0(ptr, slab)))) {                  \
-               OBD_ALLOC_POST(ptr, size, "slab-alloced");                  \
-       }                                                                    \
-} while (0)
-
-#define OBD_SLAB_ALLOC_GFP(ptr, slab, size, flags)                           \
-       __OBD_SLAB_ALLOC_VERBOSE(ptr, slab, NULL, 0, size, flags)
-#define OBD_SLAB_CPT_ALLOC_GFP(ptr, slab, cptab, cpt, size, flags)           \
-       __OBD_SLAB_ALLOC_VERBOSE(ptr, slab, cptab, cpt, size, flags)
-
-#define OBD_FREE_PTR(ptr) OBD_FREE(ptr, sizeof(*(ptr)))
-
-#define OBD_SLAB_FREE(ptr, slab, size)                                 \
-do {                                                                     \
-       OBD_FREE_PRE(ptr, size, "slab-freed");                          \
-       kmem_cache_free(slab, ptr);                                     \
-       POISON_PTR(ptr);                                                      \
-} while (0)
-
-#define OBD_SLAB_ALLOC(ptr, slab, size)                                              \
-       OBD_SLAB_ALLOC_GFP(ptr, slab, size, GFP_NOFS)
-
-#define OBD_SLAB_CPT_ALLOC(ptr, slab, cptab, cpt, size)                              \
-       OBD_SLAB_CPT_ALLOC_GFP(ptr, slab, cptab, cpt, size, GFP_NOFS)
-
-#define OBD_SLAB_ALLOC_PTR(ptr, slab)                                        \
-       OBD_SLAB_ALLOC(ptr, slab, sizeof(*(ptr)))
-
-#define OBD_SLAB_CPT_ALLOC_PTR(ptr, slab, cptab, cpt)                        \
-       OBD_SLAB_CPT_ALLOC(ptr, slab, cptab, cpt, sizeof(*(ptr)))
-
-#define OBD_SLAB_ALLOC_PTR_GFP(ptr, slab, flags)                             \
-       OBD_SLAB_ALLOC_GFP(ptr, slab, sizeof(*(ptr)), flags)
-
-#define OBD_SLAB_CPT_ALLOC_PTR_GFP(ptr, slab, cptab, cpt, flags)                     \
-       OBD_SLAB_CPT_ALLOC_GFP(ptr, slab, cptab, cpt, sizeof(*(ptr)), flags)
-
-#define OBD_SLAB_FREE_PTR(ptr, slab)                                         \
-       OBD_SLAB_FREE((ptr), (slab), sizeof(*(ptr)))
-
 #define KEY_IS(str) \
        (keylen >= (sizeof(str)-1) && memcmp(key, str, (sizeof(str)-1)) == 0)
 
-/* Wrapper for contiguous page frame allocation */
-#define __OBD_PAGE_ALLOC_VERBOSE(ptr, cptab, cpt, gfp_mask)                  \
-do {                                                                         \
-       (ptr) = (cptab) == NULL ?                                             \
-               alloc_page(gfp_mask) :                                \
-               alloc_pages_node(cfs_cpt_spread_node(cptab, cpt), gfp_mask, 0);\
-       if (unlikely((ptr) == NULL)) {                                  \
-               CERROR("alloc_pages of '" #ptr "' %d page(s) / %llu bytes "\
-                      "failed\n", (int)1,                                  \
-                      (__u64)(1 << PAGE_CACHE_SHIFT));                  \
-               CERROR("%llu total bytes and %llu total pages "    \
-                      "(%llu bytes) allocated by Lustre\n",                  \
-                      obd_memory_sum(),                                      \
-                      obd_pages_sum() << PAGE_CACHE_SHIFT,                  \
-                      obd_pages_sum());                                       \
-       } else {                                                              \
-               obd_pages_add(0);                                            \
-               CDEBUG(D_MALLOC, "alloc_pages '" #ptr "': %d page(s) / "      \
-                      "%llu bytes at %p.\n",                           \
-                      (int)1,                                          \
-                      (__u64)(1 << PAGE_CACHE_SHIFT), ptr);                \
-       }                                                                    \
-} while (0)
-
-#define OBD_PAGE_ALLOC(ptr, gfp_mask)                                        \
-       __OBD_PAGE_ALLOC_VERBOSE(ptr, NULL, 0, gfp_mask)
-#define OBD_PAGE_CPT_ALLOC(ptr, cptab, cpt, gfp_mask)                        \
-       __OBD_PAGE_ALLOC_VERBOSE(ptr, cptab, cpt, gfp_mask)
-
-#define OBD_PAGE_FREE(ptr)                                                 \
-do {                                                                     \
-       LASSERT(ptr);                                                    \
-       obd_pages_sub(0);                                                    \
-       CDEBUG(D_MALLOC, "free_pages '" #ptr "': %d page(s) / %llu bytes " \
-              "at %p.\n",                                                  \
-              (int)1, (__u64)(1 << PAGE_CACHE_SHIFT),                    \
-              ptr);                                                      \
-       __free_page(ptr);                                                  \
-       (ptr) = (void *)0xdeadbeef;                                        \
-} while (0)
-
 #endif
index b9f2bb66de218f4f312f08e65e5b164191134d39..8533a1e539f41d3047e401c9e179982c6e5fd0d7 100644 (file)
@@ -73,7 +73,7 @@ blkcnt_t dirty_cnt(struct inode *inode)
        struct ccc_object *vob = cl_inode2ccc(inode);
        void          *results[1];
 
-       if (inode->i_mapping != NULL)
+       if (inode->i_mapping)
                cnt += radix_tree_gang_lookup_tag(&inode->i_mapping->page_tree,
                                                  results, 0, 1,
                                                  PAGECACHE_TAG_DIRTY);
@@ -129,7 +129,7 @@ int cl_glimpse_lock(const struct lu_env *env, struct cl_io *io,
                                               current);
                        cio->cui_glimpse = 0;
 
-                       if (lock == NULL)
+                       if (!lock)
                                return 0;
 
                        if (IS_ERR(lock))
@@ -255,7 +255,7 @@ int cl_local_size(struct inode *inode)
                *descr = whole_file;
                descr->cld_obj = clob;
                lock = cl_lock_peek(env, io, descr, "localsize", current);
-               if (lock != NULL) {
+               if (lock) {
                        cl_merge_lvb(env, inode);
                        cl_unuse(env, lock);
                        cl_lock_release(env, lock, "localsize", current);
index 9053f811629874f72f479d20c630b6946a12f3f6..0b8e4d2175ae5cf80dbebe33b3f1905547e0ca5e 100644 (file)
@@ -116,7 +116,7 @@ void *ccc_key_init(const struct lu_context *ctx, struct lu_context_key *key)
 {
        struct ccc_thread_info *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, ccc_thread_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(ccc_thread_kmem, GFP_NOFS | __GFP_ZERO);
        if (info == NULL)
                info = ERR_PTR(-ENOMEM);
        return info;
@@ -127,7 +127,7 @@ void ccc_key_fini(const struct lu_context *ctx,
 {
        struct ccc_thread_info *info = data;
 
-       OBD_SLAB_FREE_PTR(info, ccc_thread_kmem);
+       kmem_cache_free(ccc_thread_kmem, info);
 }
 
 void *ccc_session_key_init(const struct lu_context *ctx,
@@ -135,7 +135,7 @@ void *ccc_session_key_init(const struct lu_context *ctx,
 {
        struct ccc_session *session;
 
-       OBD_SLAB_ALLOC_PTR_GFP(session, ccc_session_kmem, GFP_NOFS);
+       session = kmem_cache_alloc(ccc_session_kmem, GFP_NOFS | __GFP_ZERO);
        if (session == NULL)
                session = ERR_PTR(-ENOMEM);
        return session;
@@ -146,7 +146,7 @@ void ccc_session_key_fini(const struct lu_context *ctx,
 {
        struct ccc_session *session = data;
 
-       OBD_SLAB_FREE_PTR(session, ccc_session_kmem);
+       kmem_cache_free(ccc_session_kmem, session);
 }
 
 struct lu_context_key ccc_key = {
@@ -161,7 +161,6 @@ struct lu_context_key ccc_session_key = {
        .lct_fini = ccc_session_key_fini
 };
 
-
 /* type constructor/destructor: ccc_type_{init,fini,start,stop}(). */
 /* LU_TYPE_INIT_FINI(ccc, &ccc_key, &ccc_session_key); */
 
@@ -252,7 +251,7 @@ int ccc_req_init(const struct lu_env *env, struct cl_device *dev,
        struct ccc_req *vrq;
        int result;
 
-       OBD_SLAB_ALLOC_PTR_GFP(vrq, ccc_req_kmem, GFP_NOFS);
+       vrq = kmem_cache_alloc(ccc_req_kmem, GFP_NOFS | __GFP_ZERO);
        if (vrq != NULL) {
                cl_req_slice_add(req, &vrq->crq_cl, dev, &ccc_req_ops);
                result = 0;
@@ -328,7 +327,7 @@ struct lu_object *ccc_object_alloc(const struct lu_env *env,
        struct ccc_object *vob;
        struct lu_object  *obj;
 
-       OBD_SLAB_ALLOC_PTR_GFP(vob, ccc_object_kmem, GFP_NOFS);
+       vob = kmem_cache_alloc(ccc_object_kmem, GFP_NOFS | __GFP_ZERO);
        if (vob != NULL) {
                struct cl_object_header *hdr;
 
@@ -384,7 +383,7 @@ void ccc_object_free(const struct lu_env *env, struct lu_object *obj)
 
        lu_object_fini(obj);
        lu_object_header_fini(obj->lo_header);
-       OBD_SLAB_FREE_PTR(vob, ccc_object_kmem);
+       kmem_cache_free(ccc_object_kmem, vob);
 }
 
 int ccc_lock_init(const struct lu_env *env,
@@ -397,7 +396,7 @@ int ccc_lock_init(const struct lu_env *env,
 
        CLOBINVRNT(env, obj, ccc_object_invariant(obj));
 
-       OBD_SLAB_ALLOC_PTR_GFP(clk, ccc_lock_kmem, GFP_NOFS);
+       clk = kmem_cache_alloc(ccc_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (clk != NULL) {
                cl_lock_slice_add(lock, &clk->clk_cl, obj, lkops);
                result = 0;
@@ -406,12 +405,6 @@ int ccc_lock_init(const struct lu_env *env,
        return result;
 }
 
-int ccc_attr_set(const struct lu_env *env, struct cl_object *obj,
-                const struct cl_attr *attr, unsigned valid)
-{
-       return 0;
-}
-
 int ccc_object_glimpse(const struct lu_env *env,
                       const struct cl_object *obj, struct ost_lvb *lvb)
 {
@@ -430,15 +423,6 @@ int ccc_object_glimpse(const struct lu_env *env,
        return 0;
 }
 
-
-
-int ccc_conf_set(const struct lu_env *env, struct cl_object *obj,
-                       const struct cl_object_conf *conf)
-{
-       /* TODO: destroy all pages attached to this object. */
-       return 0;
-}
-
 static void ccc_object_size_lock(struct cl_object *obj)
 {
        struct inode *inode = ccc_object_inode(obj);
@@ -503,54 +487,6 @@ int ccc_fail(const struct lu_env *env, const struct cl_page_slice *slice)
        return 0;
 }
 
-void ccc_transient_page_verify(const struct cl_page *page)
-{
-}
-
-int ccc_transient_page_own(const struct lu_env *env,
-                                  const struct cl_page_slice *slice,
-                                  struct cl_io *unused,
-                                  int nonblock)
-{
-       ccc_transient_page_verify(slice->cpl_page);
-       return 0;
-}
-
-void ccc_transient_page_assume(const struct lu_env *env,
-                                     const struct cl_page_slice *slice,
-                                     struct cl_io *unused)
-{
-       ccc_transient_page_verify(slice->cpl_page);
-}
-
-void ccc_transient_page_unassume(const struct lu_env *env,
-                                       const struct cl_page_slice *slice,
-                                       struct cl_io *unused)
-{
-       ccc_transient_page_verify(slice->cpl_page);
-}
-
-void ccc_transient_page_disown(const struct lu_env *env,
-                                     const struct cl_page_slice *slice,
-                                     struct cl_io *unused)
-{
-       ccc_transient_page_verify(slice->cpl_page);
-}
-
-void ccc_transient_page_discard(const struct lu_env *env,
-                                      const struct cl_page_slice *slice,
-                                      struct cl_io *unused)
-{
-       struct cl_page *page = slice->cpl_page;
-
-       ccc_transient_page_verify(slice->cpl_page);
-
-       /*
-        * For transient pages, remove it from the radix tree.
-        */
-       cl_page_delete(env, page);
-}
-
 int ccc_transient_page_prep(const struct lu_env *env,
                                   const struct cl_page_slice *slice,
                                   struct cl_io *unused)
@@ -575,7 +511,7 @@ void ccc_lock_fini(const struct lu_env *env, struct cl_lock_slice *slice)
 {
        struct ccc_lock *clk = cl2ccc_lock(slice);
 
-       OBD_SLAB_FREE_PTR(clk, ccc_lock_kmem);
+       kmem_cache_free(ccc_lock_kmem, clk);
 }
 
 int ccc_lock_enqueue(const struct lu_env *env,
@@ -690,13 +626,6 @@ void ccc_lock_state(const struct lu_env *env,
  *
  */
 
-void ccc_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
-{
-       struct cl_io *io = ios->cis_io;
-
-       CLOBINVRNT(env, io->ci_obj, ccc_object_invariant(io->ci_obj));
-}
-
 int ccc_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
                          __u32 enqflags, enum cl_lock_mode mode,
                          pgoff_t start, pgoff_t end)
@@ -875,7 +804,7 @@ void ccc_req_completion(const struct lu_env *env,
                cl_stats_tally(slice->crs_dev, slice->crs_req->crq_type, ioret);
 
        vrq = cl2ccc_req(slice);
-       OBD_SLAB_FREE_PTR(vrq, ccc_req_kmem);
+       kmem_cache_free(ccc_req_kmem, vrq);
 }
 
 /**
@@ -896,7 +825,6 @@ void ccc_req_completion(const struct lu_env *env,
  *
  *    - o_ioepoch,
  *
- *  and capability.
  */
 void ccc_req_attr_set(const struct lu_env *env,
                      const struct cl_req_slice *slice,
@@ -911,12 +839,6 @@ void ccc_req_attr_set(const struct lu_env *env,
        inode = ccc_object_inode(obj);
        valid_flags = OBD_MD_FLTYPE;
 
-       if ((flags & OBD_MD_FLOSSCAPA) != 0) {
-               LASSERT(attr->cra_capa == NULL);
-               attr->cra_capa = cl_capa_lookup(inode,
-                                               slice->crs_req->crq_type);
-       }
-
        if (slice->crs_req->crq_type == CRT_WRITE) {
                if (flags & OBD_MD_FLEPOCH) {
                        oa->o_valid |= OBD_MD_FLEPOCH;
@@ -936,8 +858,7 @@ static const struct cl_req_operations ccc_req_ops = {
        .cro_completion = ccc_req_completion
 };
 
-int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
-                  struct obd_capa *capa)
+int cl_setattr_ost(struct inode *inode, const struct iattr *attr)
 {
        struct lu_env *env;
        struct cl_io  *io;
@@ -956,7 +877,6 @@ int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
        io->u.ci_setattr.sa_attr.lvb_ctime = LTIME_S(attr->ia_ctime);
        io->u.ci_setattr.sa_attr.lvb_size = attr->ia_size;
        io->u.ci_setattr.sa_valid = attr->ia_valid;
-       io->u.ci_setattr.sa_capa = capa;
 
 again:
        if (cl_io_init(env, io, CIT_SETATTR, io->ci_obj) == 0) {
index 01bf894d4a8731f3c0c32115b31f91feb3fe4874..8389a0edad367f982dac3323fa648bf518b70448 100644 (file)
@@ -45,7 +45,6 @@
 
 #include "../include/lustre_lite.h"
 
-
 /* Initialize the default and maximum LOV EA and cookie sizes.  This allows
  * us to make MDS RPCs with large enough reply buffers to hold the
  * maximum-sized (= maximum striped) EA and cookie without having to
index eab2bd60241b4bafac30a3e38261464a109b9fda..39b571721881c36b4cb97840a22493f869940fc9 100644 (file)
@@ -96,12 +96,6 @@ static inline int extent_equal(struct interval_node_extent *e1,
        return (e1->start == e2->start) && (e1->end == e2->end);
 }
 
-static inline int extent_overlapped(struct interval_node_extent *e1,
-                                   struct interval_node_extent *e2)
-{
-       return (e1->start <= e2->end) && (e2->start <= e1->end);
-}
-
 static inline int node_compare(struct interval_node *n1,
                               struct interval_node *n2)
 {
@@ -119,19 +113,6 @@ static inline __u64 max_u64(__u64 x, __u64 y)
        return x > y ? x : y;
 }
 
-static inline __u64 min_u64(__u64 x, __u64 y)
-{
-       return x < y ? x : y;
-}
-
-#define interval_for_each(node, root)             \
-for (node = interval_first(root); node != NULL;         \
-       node = interval_next(node))
-
-#define interval_for_each_reverse(node, root)     \
-for (node = interval_last(root); node != NULL;   \
-       node = interval_prev(node))
-
 static struct interval_node *interval_first(struct interval_node *node)
 {
        if (!node)
@@ -141,15 +122,6 @@ static struct interval_node *interval_first(struct interval_node *node)
        return node;
 }
 
-static struct interval_node *interval_last(struct interval_node *node)
-{
-       if (!node)
-               return NULL;
-       while (node->in_right)
-               node = node->in_right;
-       return node;
-}
-
 static struct interval_node *interval_next(struct interval_node *node)
 {
        if (!node)
@@ -161,76 +133,6 @@ static struct interval_node *interval_next(struct interval_node *node)
        return node->in_parent;
 }
 
-static struct interval_node *interval_prev(struct interval_node *node)
-{
-       if (!node)
-               return NULL;
-
-       if (node->in_left)
-               return interval_last(node->in_left);
-
-       while (node->in_parent && node_is_left_child(node))
-               node = node->in_parent;
-
-       return node->in_parent;
-}
-
-enum interval_iter interval_iterate(struct interval_node *root,
-                                   interval_callback_t func,
-                                   void *data)
-{
-       struct interval_node *node;
-       enum interval_iter rc = INTERVAL_ITER_CONT;
-
-       interval_for_each(node, root) {
-               rc = func(node, data);
-               if (rc == INTERVAL_ITER_STOP)
-                       break;
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(interval_iterate);
-
-enum interval_iter interval_iterate_reverse(struct interval_node *root,
-                                           interval_callback_t func,
-                                           void *data)
-{
-       struct interval_node *node;
-       enum interval_iter rc = INTERVAL_ITER_CONT;
-
-       interval_for_each_reverse(node, root) {
-               rc = func(node, data);
-               if (rc == INTERVAL_ITER_STOP)
-                       break;
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(interval_iterate_reverse);
-
-/* try to find a node with same interval in the tree,
- * if found, return the pointer to the node, otherwise return NULL*/
-struct interval_node *interval_find(struct interval_node *root,
-                                   struct interval_node_extent *ex)
-{
-       struct interval_node *walk = root;
-       int rc;
-
-       while (walk) {
-               rc = extent_compare(ex, &walk->in_extent);
-               if (rc == 0)
-                       break;
-               else if (rc < 0)
-                       walk = walk->in_left;
-               else
-                       walk = walk->in_right;
-       }
-
-       return walk;
-}
-EXPORT_SYMBOL(interval_find);
-
 static void __rotate_change_maxhigh(struct interval_node *node,
                                    struct interval_node *rotate)
 {
@@ -392,7 +294,8 @@ struct interval_node *interval_insert(struct interval_node *node,
        /* link node into the tree */
        node->in_parent = parent;
        node->in_color = INTERVAL_RED;
-       node->in_left = node->in_right = NULL;
+       node->in_left = NULL;
+       node->in_right = NULL;
        *p = node;
 
        interval_insert_color(node, root);
@@ -576,176 +479,3 @@ color:
                interval_erase_color(child, parent, root);
 }
 EXPORT_SYMBOL(interval_erase);
-
-static inline int interval_may_overlap(struct interval_node *node,
-                                         struct interval_node_extent *ext)
-{
-       return (ext->start <= node->in_max_high &&
-               ext->end >= interval_low(node));
-}
-
-/*
- * This function finds all intervals that overlap interval ext,
- * and calls func to handle resulted intervals one by one.
- * in lustre, this function will find all conflicting locks in
- * the granted queue and add these locks to the ast work list.
- *
- * {
- *       if (node == NULL)
- *            return 0;
- *       if (ext->end < interval_low(node)) {
- *            interval_search(node->in_left, ext, func, data);
- *       } else if (interval_may_overlap(node, ext)) {
- *            if (extent_overlapped(ext, &node->in_extent))
- *                    func(node, data);
- *            interval_search(node->in_left, ext, func, data);
- *            interval_search(node->in_right, ext, func, data);
- *       }
- *       return 0;
- * }
- *
- */
-enum interval_iter interval_search(struct interval_node *node,
-                                  struct interval_node_extent *ext,
-                                  interval_callback_t func,
-                                  void *data)
-{
-       struct interval_node *parent;
-       enum interval_iter rc = INTERVAL_ITER_CONT;
-
-       LASSERT(ext != NULL);
-       LASSERT(func != NULL);
-
-       while (node) {
-               if (ext->end < interval_low(node)) {
-                       if (node->in_left) {
-                               node = node->in_left;
-                               continue;
-                       }
-               } else if (interval_may_overlap(node, ext)) {
-                       if (extent_overlapped(ext, &node->in_extent)) {
-                               rc = func(node, data);
-                               if (rc == INTERVAL_ITER_STOP)
-                                       break;
-                       }
-
-                       if (node->in_left) {
-                               node = node->in_left;
-                               continue;
-                       }
-                       if (node->in_right) {
-                               node = node->in_right;
-                               continue;
-                       }
-               }
-
-               parent = node->in_parent;
-               while (parent) {
-                       if (node_is_left_child(node) &&
-                           parent->in_right) {
-                               /* If we ever got the left, it means that the
-                                * parent met ext->end<interval_low(parent), or
-                                * may_overlap(parent). If the former is true,
-                                * we needn't go back. So stop early and check
-                                * may_overlap(parent) after this loop.  */
-                               node = parent->in_right;
-                               break;
-                       }
-                       node = parent;
-                       parent = parent->in_parent;
-               }
-               if (parent == NULL || !interval_may_overlap(parent, ext))
-                       break;
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(interval_search);
-
-static enum interval_iter interval_overlap_cb(struct interval_node *n,
-                                             void *args)
-{
-       *(int *)args = 1;
-       return INTERVAL_ITER_STOP;
-}
-
-int interval_is_overlapped(struct interval_node *root,
-                          struct interval_node_extent *ext)
-{
-       int has = 0;
-       (void)interval_search(root, ext, interval_overlap_cb, &has);
-       return has;
-}
-EXPORT_SYMBOL(interval_is_overlapped);
-
-/* Don't expand to low. Expanding downwards is expensive, and meaningless to
- * some extents, because programs seldom do IO backward.
- *
- * The recursive algorithm of expanding low:
- * expand_low {
- *     struct interval_node *tmp;
- *     static __u64 res = 0;
- *
- *     if (root == NULL)
- *             return res;
- *     if (root->in_max_high < low) {
- *             res = max_u64(root->in_max_high + 1, res);
- *             return res;
- *     } else if (low < interval_low(root)) {
- *             interval_expand_low(root->in_left, low);
- *             return res;
- *     }
- *
- *     if (interval_high(root) < low)
- *             res = max_u64(interval_high(root) + 1, res);
- *     interval_expand_low(root->in_left, low);
- *     interval_expand_low(root->in_right, low);
- *
- *     return res;
- * }
- *
- * It's much easy to eliminate the recursion, see interval_search for
- * an example. -jay
- */
-static inline __u64 interval_expand_low(struct interval_node *root, __u64 low)
-{
-       /* we only concern the empty tree right now. */
-       if (root == NULL)
-               return 0;
-       return low;
-}
-
-static inline __u64 interval_expand_high(struct interval_node *node, __u64 high)
-{
-       __u64 result = ~0;
-
-       while (node != NULL) {
-               if (node->in_max_high < high)
-                       break;
-
-               if (interval_low(node) > high) {
-                       result = interval_low(node) - 1;
-                       node = node->in_left;
-               } else {
-                       node = node->in_right;
-               }
-       }
-
-       return result;
-}
-
-/* expanding the extent based on @ext. */
-void interval_expand(struct interval_node *root,
-                    struct interval_node_extent *ext,
-                    struct interval_node_extent *limiter)
-{
-       /* The assertion of interval_is_overlapped is expensive because we may
-        * travel many nodes to find the overlapped node. */
-       LASSERT(interval_is_overlapped(root, ext) == 0);
-       if (!limiter || limiter->start < ext->start)
-               ext->start = interval_expand_low(root, ext->start);
-       if (!limiter || limiter->end > ext->end)
-               ext->end = interval_expand_high(root, ext->end);
-       LASSERT(interval_is_overlapped(root, ext) == 0);
-}
-EXPORT_SYMBOL(interval_expand);
index cd8ab40e32676b9a47ad176449faf24aa51d704d..e5d1344e817ae2f3d40b947bb34f5dcfa3085651 100644 (file)
@@ -50,9 +50,7 @@
  */
 struct ldlm_resource *lock_res_and_lock(struct ldlm_lock *lock)
 {
-       /* on server-side resource of lock doesn't change */
-       if ((lock->l_flags & LDLM_FL_NS_SRV) == 0)
-               spin_lock(&lock->l_lock);
+       spin_lock(&lock->l_lock);
 
        lock_res(lock->l_resource);
 
@@ -70,7 +68,6 @@ void unlock_res_and_lock(struct ldlm_lock *lock)
        lock->l_flags &= ~LDLM_FL_RES_LOCKED;
 
        unlock_res(lock->l_resource);
-       if ((lock->l_flags & LDLM_FL_NS_SRV) == 0)
-               spin_unlock(&lock->l_lock);
+       spin_unlock(&lock->l_lock);
 }
 EXPORT_SYMBOL(unlock_res_and_lock);
index fd9b059361f934ea2c67ca191d82c24b691626a2..c787888eb8af4dcd3c4e6663f15d39c510e084a2 100644 (file)
@@ -58,7 +58,6 @@
 #include "../include/lustre_lib.h"
 #include "ldlm_internal.h"
 
-
 /* When a lock is cancelled by a client, the KMS may undergo change if this
  * is the "highest lock".  This function returns the new KMS value.
  * Caller must hold lr_lock already.
@@ -97,12 +96,23 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms)
 EXPORT_SYMBOL(ldlm_extent_shift_kms);
 
 struct kmem_cache *ldlm_interval_slab;
+
+/* interval tree, for LDLM_EXTENT. */
+static void ldlm_interval_attach(struct ldlm_interval *n, struct ldlm_lock *l)
+{
+       LASSERT(!l->l_tree_node);
+       LASSERT(l->l_resource->lr_type == LDLM_EXTENT);
+
+       list_add_tail(&l->l_sl_policy, &n->li_group);
+       l->l_tree_node = n;
+}
+
 struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock)
 {
        struct ldlm_interval *node;
 
        LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
-       OBD_SLAB_ALLOC_PTR_GFP(node, ldlm_interval_slab, GFP_NOFS);
+       node = kmem_cache_alloc(ldlm_interval_slab, GFP_NOFS | __GFP_ZERO);
        if (node == NULL)
                return NULL;
 
@@ -116,21 +126,10 @@ void ldlm_interval_free(struct ldlm_interval *node)
        if (node) {
                LASSERT(list_empty(&node->li_group));
                LASSERT(!interval_is_intree(&node->li_node));
-               OBD_SLAB_FREE(node, ldlm_interval_slab, sizeof(*node));
+               kmem_cache_free(ldlm_interval_slab, node);
        }
 }
 
-/* interval tree, for LDLM_EXTENT. */
-void ldlm_interval_attach(struct ldlm_interval *n,
-                         struct ldlm_lock *l)
-{
-       LASSERT(l->l_tree_node == NULL);
-       LASSERT(l->l_resource->lr_type == LDLM_EXTENT);
-
-       list_add_tail(&l->l_sl_policy, &n->li_group);
-       l->l_tree_node = n;
-}
-
 struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l)
 {
        struct ldlm_interval *n = l->l_tree_node;
index a4c252febfe4ec4d1815eccff5fd877ba0d2bdc8..4310154e17284f36a4dc55d209c4d39b569b59c5 100644 (file)
@@ -63,9 +63,6 @@
 #include <linux/list.h>
 #include "ldlm_internal.h"
 
-int ldlm_flock_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
-                           void *data, int flag);
-
 /**
  * list_for_remaining_safe - iterate over the remaining entries in a list
  *           and safeguard against removal of a list entry.
@@ -94,40 +91,6 @@ ldlm_flocks_overlap(struct ldlm_lock *lock, struct ldlm_lock *new)
                lock->l_policy_data.l_flock.start));
 }
 
-static inline void ldlm_flock_blocking_link(struct ldlm_lock *req,
-                                           struct ldlm_lock *lock)
-{
-       /* For server only */
-       if (req->l_export == NULL)
-               return;
-
-       LASSERT(hlist_unhashed(&req->l_exp_flock_hash));
-
-       req->l_policy_data.l_flock.blocking_owner =
-               lock->l_policy_data.l_flock.owner;
-       req->l_policy_data.l_flock.blocking_export =
-               lock->l_export;
-       req->l_policy_data.l_flock.blocking_refs = 0;
-
-       cfs_hash_add(req->l_export->exp_flock_hash,
-                    &req->l_policy_data.l_flock.owner,
-                    &req->l_exp_flock_hash);
-}
-
-static inline void ldlm_flock_blocking_unlink(struct ldlm_lock *req)
-{
-       /* For server only */
-       if (req->l_export == NULL)
-               return;
-
-       check_res_locked(req->l_resource);
-       if (req->l_export->exp_flock_hash != NULL &&
-           !hlist_unhashed(&req->l_exp_flock_hash))
-               cfs_hash_del(req->l_export->exp_flock_hash,
-                            &req->l_policy_data.l_flock.owner,
-                            &req->l_exp_flock_hash);
-}
-
 static inline void
 ldlm_flock_destroy(struct ldlm_lock *lock, ldlm_mode_t mode, __u64 flags)
 {
@@ -151,79 +114,6 @@ ldlm_flock_destroy(struct ldlm_lock *lock, ldlm_mode_t mode, __u64 flags)
        ldlm_lock_destroy_nolock(lock);
 }
 
-/**
- * POSIX locks deadlock detection code.
- *
- * Given a new lock \a req and an existing lock \a bl_lock it conflicts
- * with, we need to iterate through all blocked POSIX locks for this
- * export and see if there is a deadlock condition arising. (i.e. when
- * one client holds a lock on something and want a lock on something
- * else and at the same time another client has the opposite situation).
- */
-static int
-ldlm_flock_deadlock(struct ldlm_lock *req, struct ldlm_lock *bl_lock)
-{
-       struct obd_export *req_exp = req->l_export;
-       struct obd_export *bl_exp = bl_lock->l_export;
-       __u64 req_owner = req->l_policy_data.l_flock.owner;
-       __u64 bl_owner = bl_lock->l_policy_data.l_flock.owner;
-
-       /* For server only */
-       if (req_exp == NULL)
-               return 0;
-
-       class_export_get(bl_exp);
-       while (1) {
-               struct obd_export *bl_exp_new;
-               struct ldlm_lock *lock = NULL;
-               struct ldlm_flock *flock;
-
-               if (bl_exp->exp_flock_hash != NULL)
-                       lock = cfs_hash_lookup(bl_exp->exp_flock_hash,
-                                              &bl_owner);
-               if (lock == NULL)
-                       break;
-
-               LASSERT(req != lock);
-               flock = &lock->l_policy_data.l_flock;
-               LASSERT(flock->owner == bl_owner);
-               bl_owner = flock->blocking_owner;
-               bl_exp_new = class_export_get(flock->blocking_export);
-               class_export_put(bl_exp);
-
-               cfs_hash_put(bl_exp->exp_flock_hash, &lock->l_exp_flock_hash);
-               bl_exp = bl_exp_new;
-
-               if (bl_owner == req_owner && bl_exp == req_exp) {
-                       class_export_put(bl_exp);
-                       return 1;
-               }
-       }
-       class_export_put(bl_exp);
-
-       return 0;
-}
-
-static void ldlm_flock_cancel_on_deadlock(struct ldlm_lock *lock,
-                                         struct list_head *work_list)
-{
-       CDEBUG(D_INFO, "reprocess deadlock req=%p\n", lock);
-
-       if ((exp_connect_flags(lock->l_export) &
-                               OBD_CONNECT_FLOCK_DEAD) == 0) {
-               CERROR(
-                     "deadlock found, but client doesn't support flock canceliation\n");
-       } else {
-               LASSERT(lock->l_completion_ast);
-               LASSERT((lock->l_flags & LDLM_FL_AST_SENT) == 0);
-               lock->l_flags |= LDLM_FL_AST_SENT | LDLM_FL_CANCEL_ON_BLOCK |
-                       LDLM_FL_FLOCK_DEADLOCK;
-               ldlm_flock_blocking_unlink(lock);
-               ldlm_resource_unlink_lock(lock);
-               ldlm_add_ast_work_item(lock, NULL, work_list);
-       }
-}
-
 /**
  * Process a granting attempt for flock lock.
  * Must be called under ns lock held.
@@ -242,9 +132,9 @@ static void ldlm_flock_cancel_on_deadlock(struct ldlm_lock *lock,
  *   - blocking ASTs have not been sent yet, so list of conflicting locks
  *     would be collected and ASTs sent.
  */
-int
-ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
-                       ldlm_error_t *err, struct list_head *work_list)
+static int ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags,
+                                  int first_enq, ldlm_error_t *err,
+                                  struct list_head *work_list)
 {
        struct ldlm_resource *res = req->l_resource;
        struct ldlm_namespace *ns = ldlm_res_to_ns(res);
@@ -254,7 +144,6 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
        struct ldlm_lock *new = req;
        struct ldlm_lock *new2 = NULL;
        ldlm_mode_t mode = req->l_req_mode;
-       int local = ns_is_client(ns);
        int added = (mode == LCK_NL);
        int overlaps = 0;
        int splitted = 0;
@@ -269,14 +158,9 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
 
        *err = ELDLM_OK;
 
-       if (local) {
-               /* No blocking ASTs are sent to the clients for
-                * Posix file & record locks */
-               req->l_blocking_ast = NULL;
-       } else {
-               /* Called on the server for lock cancels. */
-               req->l_blocking_ast = ldlm_flock_blocking_ast;
-       }
+       /* No blocking ASTs are sent to the clients for
+        * Posix file & record locks */
+       req->l_blocking_ast = NULL;
 
 reprocess:
        if ((*flags == LDLM_FL_WAIT_NOREPROC) || (mode == LCK_NL)) {
@@ -316,11 +200,6 @@ reprocess:
 
                        if (!first_enq) {
                                reprocess_failed = 1;
-                               if (ldlm_flock_deadlock(req, lock)) {
-                                       ldlm_flock_cancel_on_deadlock(req,
-                                                       work_list);
-                                       return LDLM_ITER_CONTINUE;
-                               }
                                continue;
                        }
 
@@ -343,17 +222,6 @@ reprocess:
                                return LDLM_ITER_STOP;
                        }
 
-                       /* add lock to blocking list before deadlock
-                        * check to prevent race */
-                       ldlm_flock_blocking_link(req, lock);
-
-                       if (ldlm_flock_deadlock(req, lock)) {
-                               ldlm_flock_blocking_unlink(req);
-                               ldlm_flock_destroy(req, mode, *flags);
-                               *err = -EDEADLK;
-                               return LDLM_ITER_STOP;
-                       }
-
                        ldlm_resource_add_lock(res, &res->lr_waiting, req);
                        *flags |= LDLM_FL_BLOCK_GRANTED;
                        return LDLM_ITER_STOP;
@@ -369,10 +237,6 @@ reprocess:
                return LDLM_ITER_STOP;
        }
 
-       /* In case we had slept on this lock request take it off of the
-        * deadlock detection hash list. */
-       ldlm_flock_blocking_unlink(req);
-
        /* Scan the locks owned by this process that overlap this request.
         * We may have to merge or split existing locks. */
 
@@ -523,7 +387,6 @@ reprocess:
        /* At this point we're granting the lock request. */
        req->l_granted_mode = req->l_req_mode;
 
-       /* Add req to the granted queue before calling ldlm_reprocess_all(). */
        if (!added) {
                list_del_init(&req->l_res_link);
                /* insert new lock before ownlocks in list. */
@@ -561,9 +424,7 @@ ldlm_flock_interrupted_wait(void *data)
 
        lock = ((struct ldlm_flock_wait_data *)data)->fwd_lock;
 
-       /* take lock off the deadlock detection hash list. */
        lock_res_and_lock(lock);
-       ldlm_flock_blocking_unlink(lock);
 
        /* client side - set flag to prevent lock from being put on LRU list */
        lock->l_flags |= LDLM_FL_CBPENDING;
@@ -602,7 +463,7 @@ ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data)
            (LDLM_FL_FAILED|LDLM_FL_LOCAL_ONLY)) {
                if (lock->l_req_mode == lock->l_granted_mode &&
                    lock->l_granted_mode != LCK_NL &&
-                   NULL == data)
+                   data == NULL)
                        ldlm_lock_decref_internal(lock, lock->l_req_mode);
 
                /* Need to wake up the waiter if we were evicted */
@@ -614,7 +475,7 @@ ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data)
 
        if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
                       LDLM_FL_BLOCK_CONV))) {
-               if (NULL == data)
+               if (data == NULL)
                        /* mds granted the lock in the reply */
                        goto granted;
                /* CP AST RPC: lock get granted, wake it up */
@@ -627,10 +488,10 @@ ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data)
        obd = class_exp2obd(lock->l_conn_export);
 
        /* if this is a local lock, there is no import */
-       if (NULL != obd)
+       if (obd != NULL)
                imp = obd->u.cli.cl_import;
 
-       if (NULL != imp) {
+       if (imp != NULL) {
                spin_lock(&imp->imp_lock);
                fwd.fwd_generation = imp->imp_generation;
                spin_unlock(&imp->imp_lock);
@@ -670,9 +531,6 @@ granted:
 
        lock_res_and_lock(lock);
 
-       /* take lock off the deadlock detection hash list. */
-       ldlm_flock_blocking_unlink(lock);
-
        /* ldlm_lock_enqueue() has already placed lock on the granted list. */
        list_del_init(&lock->l_res_link);
 
@@ -709,19 +567,6 @@ granted:
 }
 EXPORT_SYMBOL(ldlm_flock_completion_ast);
 
-int ldlm_flock_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
-                           void *data, int flag)
-{
-       LASSERT(lock);
-       LASSERT(flag == LDLM_CB_CANCELING);
-
-       /* take lock off the deadlock detection hash list. */
-       lock_res_and_lock(lock);
-       ldlm_flock_blocking_unlink(lock);
-       unlock_res_and_lock(lock);
-       return 0;
-}
-
 void ldlm_flock_policy_wire18_to_local(const ldlm_wire_policy_data_t *wpolicy,
                                       ldlm_policy_data_t *lpolicy)
 {
@@ -735,7 +580,6 @@ void ldlm_flock_policy_wire18_to_local(const ldlm_wire_policy_data_t *wpolicy,
        lpolicy->l_flock.owner = wpolicy->l_flock.lfw_pid;
 }
 
-
 void ldlm_flock_policy_wire21_to_local(const ldlm_wire_policy_data_t *wpolicy,
                                       ldlm_policy_data_t *lpolicy)
 {
@@ -755,105 +599,3 @@ void ldlm_flock_policy_local_to_wire(const ldlm_policy_data_t *lpolicy,
        wpolicy->l_flock.lfw_pid = lpolicy->l_flock.pid;
        wpolicy->l_flock.lfw_owner = lpolicy->l_flock.owner;
 }
-
-/*
- * Export handle<->flock hash operations.
- */
-static unsigned
-ldlm_export_flock_hash(struct cfs_hash *hs, const void *key, unsigned mask)
-{
-       return cfs_hash_u64_hash(*(__u64 *)key, mask);
-}
-
-static void *
-ldlm_export_flock_key(struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_flock_hash);
-       return &lock->l_policy_data.l_flock.owner;
-}
-
-static int
-ldlm_export_flock_keycmp(const void *key, struct hlist_node *hnode)
-{
-       return !memcmp(ldlm_export_flock_key(hnode), key, sizeof(__u64));
-}
-
-static void *
-ldlm_export_flock_object(struct hlist_node *hnode)
-{
-       return hlist_entry(hnode, struct ldlm_lock, l_exp_flock_hash);
-}
-
-static void
-ldlm_export_flock_get(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-       struct ldlm_flock *flock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_flock_hash);
-       LDLM_LOCK_GET(lock);
-
-       flock = &lock->l_policy_data.l_flock;
-       LASSERT(flock->blocking_export != NULL);
-       class_export_get(flock->blocking_export);
-       flock->blocking_refs++;
-}
-
-static void
-ldlm_export_flock_put(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-       struct ldlm_flock *flock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_flock_hash);
-       LDLM_LOCK_RELEASE(lock);
-
-       flock = &lock->l_policy_data.l_flock;
-       LASSERT(flock->blocking_export != NULL);
-       class_export_put(flock->blocking_export);
-       if (--flock->blocking_refs == 0) {
-               flock->blocking_owner = 0;
-               flock->blocking_export = NULL;
-       }
-}
-
-static cfs_hash_ops_t ldlm_export_flock_ops = {
-       .hs_hash        = ldlm_export_flock_hash,
-       .hs_key  = ldlm_export_flock_key,
-       .hs_keycmp      = ldlm_export_flock_keycmp,
-       .hs_object      = ldlm_export_flock_object,
-       .hs_get  = ldlm_export_flock_get,
-       .hs_put  = ldlm_export_flock_put,
-       .hs_put_locked  = ldlm_export_flock_put,
-};
-
-int ldlm_init_flock_export(struct obd_export *exp)
-{
-       if (strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MDT_NAME) != 0)
-               return 0;
-
-       exp->exp_flock_hash =
-               cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
-                               HASH_EXP_LOCK_CUR_BITS,
-                               HASH_EXP_LOCK_MAX_BITS,
-                               HASH_EXP_LOCK_BKT_BITS, 0,
-                               CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA,
-                               &ldlm_export_flock_ops,
-                               CFS_HASH_DEFAULT | CFS_HASH_NBLK_CHANGE);
-       if (!exp->exp_flock_hash)
-               return -ENOMEM;
-
-       return 0;
-}
-EXPORT_SYMBOL(ldlm_init_flock_export);
-
-void ldlm_destroy_flock_export(struct obd_export *exp)
-{
-       if (exp->exp_flock_hash) {
-               cfs_hash_putref(exp->exp_flock_hash);
-               exp->exp_flock_hash = NULL;
-       }
-}
-EXPORT_SYMBOL(ldlm_destroy_flock_export);
index 40d3338506ae2f61a4fcdf668e867bd687673d4b..b1bed1e17d3244782968fdce2a6fe3d76c23f50f 100644 (file)
@@ -58,7 +58,6 @@
 #include "../include/lustre_lib.h"
 #include "ldlm_internal.h"
 
-
 void ldlm_ibits_policy_wire_to_local(const ldlm_wire_policy_data_t *wpolicy,
                                     ldlm_policy_data_t *lpolicy)
 {
index fa4b7c760d496c6f4a53550676218576cba799a7..db3c9b7af7d50d4ace790e606f3f5000e1aa9485 100644 (file)
@@ -42,7 +42,6 @@ extern struct mutex ldlm_srv_namespace_lock;
 extern struct list_head ldlm_srv_namespace_list;
 extern struct mutex ldlm_cli_namespace_lock;
 extern struct list_head ldlm_cli_active_namespace_list;
-extern struct list_head ldlm_cli_inactive_namespace_list;
 
 static inline int ldlm_namespace_nr_read(ldlm_side_t client)
 {
@@ -72,12 +71,6 @@ static inline struct list_head *ldlm_namespace_list(ldlm_side_t client)
                &ldlm_srv_namespace_list : &ldlm_cli_active_namespace_list;
 }
 
-static inline struct list_head *ldlm_namespace_inactive_list(ldlm_side_t client)
-{
-       return client == LDLM_NAMESPACE_SERVER ?
-               &ldlm_srv_namespace_list : &ldlm_cli_inactive_namespace_list;
-}
-
 static inline struct mutex *ldlm_namespace_lock(ldlm_side_t client)
 {
        return client == LDLM_NAMESPACE_SERVER ?
@@ -109,15 +102,12 @@ enum {
 int ldlm_cancel_lru(struct ldlm_namespace *ns, int nr,
                    ldlm_cancel_flags_t sync, int flags);
 int ldlm_cancel_lru_local(struct ldlm_namespace *ns,
-                         struct list_head *cancels, int count, int max,
-                         ldlm_cancel_flags_t cancel_flags, int flags);
+                        struct list_head *cancels, int count, int max,
+                        ldlm_cancel_flags_t cancel_flags, int flags);
 extern int ldlm_enqueue_min;
-int ldlm_get_enq_timeout(struct ldlm_lock *lock);
 
 /* ldlm_resource.c */
 int ldlm_resource_putref_locked(struct ldlm_resource *res);
-void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
-                                    struct ldlm_lock *new);
 void ldlm_namespace_free_prior(struct ldlm_namespace *ns,
                               struct obd_import *imp, int force);
 void ldlm_namespace_free_post(struct ldlm_namespace *ns);
@@ -152,20 +142,12 @@ void ldlm_lock_addref_internal(struct ldlm_lock *, __u32 mode);
 void ldlm_lock_addref_internal_nolock(struct ldlm_lock *, __u32 mode);
 void ldlm_lock_decref_internal(struct ldlm_lock *, __u32 mode);
 void ldlm_lock_decref_internal_nolock(struct ldlm_lock *, __u32 mode);
-void ldlm_add_ast_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
-                           struct list_head *work_list);
 int ldlm_run_ast_work(struct ldlm_namespace *ns, struct list_head *rpc_list,
                      enum ldlm_desc_ast_t ast_type);
-int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq);
 int ldlm_lock_remove_from_lru(struct ldlm_lock *lock);
 int ldlm_lock_remove_from_lru_nolock(struct ldlm_lock *lock);
-void ldlm_lock_add_to_lru_nolock(struct ldlm_lock *lock);
-void ldlm_lock_add_to_lru(struct ldlm_lock *lock);
-void ldlm_lock_touch_in_lru(struct ldlm_lock *lock);
 void ldlm_lock_destroy_nolock(struct ldlm_lock *lock);
 
-void ldlm_cancel_locks_for_export(struct obd_export *export);
-
 /* ldlm_lockd.c */
 int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
                           struct ldlm_lock *lock);
@@ -178,6 +160,7 @@ void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
                             struct ldlm_lock_desc *ld, struct ldlm_lock *lock);
 
 extern struct kmem_cache *ldlm_resource_slab;
+extern struct kset *ldlm_ns_kset;
 
 /* ldlm_lockd.c & ldlm_lock.c */
 extern struct kmem_cache *ldlm_lock_slab;
@@ -186,13 +169,6 @@ extern struct kmem_cache *ldlm_lock_slab;
 void ldlm_extent_add_lock(struct ldlm_resource *res, struct ldlm_lock *lock);
 void ldlm_extent_unlink_lock(struct ldlm_lock *lock);
 
-/* ldlm_flock.c */
-int ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags,
-                           int first_enq, ldlm_error_t *err,
-                           struct list_head *work_list);
-int ldlm_init_flock_export(struct obd_export *exp);
-void ldlm_destroy_flock_export(struct obd_export *exp);
-
 /* l_lock.c */
 void l_check_ns_lock(struct ldlm_namespace *ns);
 void l_check_no_ns_lock(struct ldlm_namespace *ns);
@@ -207,9 +183,13 @@ struct ldlm_state {
        struct ldlm_bl_pool *ldlm_bl_pool;
 };
 
+/* ldlm_pool.c */
+__u64 ldlm_pool_get_slv(struct ldlm_pool *pl);
+void ldlm_pool_set_clv(struct ldlm_pool *pl, __u64 clv);
+__u32 ldlm_pool_get_lvf(struct ldlm_pool *pl);
+
 /* interval tree, for LDLM_EXTENT. */
 extern struct kmem_cache *ldlm_interval_slab; /* slab cache for ldlm_interval */
-void ldlm_interval_attach(struct ldlm_interval *n, struct ldlm_lock *l);
 struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l);
 struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock);
 void ldlm_interval_free(struct ldlm_interval *node);
index badd227e4f67a0732982a73f8555fa69b5927f4d..ccce1e5031202cd4057141d1c91ca9aaec218493 100644 (file)
@@ -335,7 +335,6 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
        }
 
        init_rwsem(&cli->cl_sem);
-       mutex_init(&cli->cl_mgc_mutex);
        cli->cl_conn_count = 0;
        memcpy(server_uuid.uuid, lustre_cfg_buf(lcfg, 2),
               min_t(unsigned int, LUSTRE_CFG_BUFLEN(lcfg, 2),
@@ -627,7 +626,6 @@ out_disconnect:
 }
 EXPORT_SYMBOL(client_disconnect_export);
 
-
 /**
  * Packs current SLV and Limit into \a req.
  */
@@ -815,42 +813,6 @@ int ldlm_error2errno(ldlm_error_t error)
 }
 EXPORT_SYMBOL(ldlm_error2errno);
 
-/**
- * Dual to ldlm_error2errno(): maps errno values back to ldlm_error_t.
- */
-ldlm_error_t ldlm_errno2error(int err_no)
-{
-       int error;
-
-       switch (err_no) {
-       case 0:
-               error = ELDLM_OK;
-               break;
-       case -ESTALE:
-               error = ELDLM_LOCK_CHANGED;
-               break;
-       case -ENAVAIL:
-               error = ELDLM_LOCK_ABORTED;
-               break;
-       case -ESRCH:
-               error = ELDLM_LOCK_REPLACED;
-               break;
-       case -ENOENT:
-               error = ELDLM_NO_LOCK_DATA;
-               break;
-       case -EEXIST:
-               error = ELDLM_NAMESPACE_EXISTS;
-               break;
-       case -EBADF:
-               error = ELDLM_BAD_NAMESPACE;
-               break;
-       default:
-               error = err_no;
-       }
-       return error;
-}
-EXPORT_SYMBOL(ldlm_errno2error);
-
 #if LUSTRE_TRACKS_LOCK_EXP_REFS
 void ldlm_dump_export_locks(struct obd_export *exp)
 {
index cd340fc8ceab45238e51449434f130973b61cda4..7f8c70056ffdeb011db2e175904025714e174a3e 100644 (file)
@@ -60,13 +60,12 @@ char *ldlm_lockname[] = {
 };
 EXPORT_SYMBOL(ldlm_lockname);
 
-char *ldlm_typename[] = {
+static char *ldlm_typename[] = {
        [LDLM_PLAIN]    = "PLN",
        [LDLM_EXTENT]   = "EXT",
        [LDLM_FLOCK]    = "FLK",
        [LDLM_IBITS]    = "IBT",
 };
-EXPORT_SYMBOL(ldlm_typename);
 
 static ldlm_policy_wire_to_local_t ldlm_policy_wire18_to_local[] = {
        [LDLM_PLAIN - LDLM_MIN_TYPE]    = ldlm_plain_policy_wire_to_local,
@@ -92,9 +91,9 @@ static ldlm_policy_local_to_wire_t ldlm_policy_local_to_wire[] = {
 /**
  * Converts lock policy from local format to on the wire lock_desc format
  */
-void ldlm_convert_policy_to_wire(ldlm_type_t type,
-                                const ldlm_policy_data_t *lpolicy,
-                                ldlm_wire_policy_data_t *wpolicy)
+static void ldlm_convert_policy_to_wire(ldlm_type_t type,
+                                       const ldlm_policy_data_t *lpolicy,
+                                       ldlm_wire_policy_data_t *wpolicy)
 {
        ldlm_policy_local_to_wire_t convert;
 
@@ -151,18 +150,10 @@ char *ldlm_it2str(int it)
 }
 EXPORT_SYMBOL(ldlm_it2str);
 
-
-void ldlm_register_intent(struct ldlm_namespace *ns, ldlm_res_policy arg)
-{
-       ns->ns_policy = arg;
-}
-EXPORT_SYMBOL(ldlm_register_intent);
-
 /*
  * REFCOUNTED LOCK OBJECTS
  */
 
-
 /**
  * Get a reference on a lock.
  *
@@ -244,11 +235,6 @@ int ldlm_lock_remove_from_lru(struct ldlm_lock *lock)
        struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
        int rc;
 
-       if (lock->l_flags & LDLM_FL_NS_SRV) {
-               LASSERT(list_empty(&lock->l_lru));
-               return 0;
-       }
-
        spin_lock(&ns->ns_lock);
        rc = ldlm_lock_remove_from_lru_nolock(lock);
        spin_unlock(&ns->ns_lock);
@@ -258,7 +244,7 @@ int ldlm_lock_remove_from_lru(struct ldlm_lock *lock)
 /**
  * Adds LDLM lock \a lock to namespace LRU. Assumes LRU is already locked.
  */
-void ldlm_lock_add_to_lru_nolock(struct ldlm_lock *lock)
+static void ldlm_lock_add_to_lru_nolock(struct ldlm_lock *lock)
 {
        struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
 
@@ -276,7 +262,7 @@ void ldlm_lock_add_to_lru_nolock(struct ldlm_lock *lock)
  * Adds LDLM lock \a lock to namespace LRU. Obtains necessary LRU locks
  * first.
  */
-void ldlm_lock_add_to_lru(struct ldlm_lock *lock)
+static void ldlm_lock_add_to_lru(struct ldlm_lock *lock)
 {
        struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
 
@@ -289,15 +275,10 @@ void ldlm_lock_add_to_lru(struct ldlm_lock *lock)
  * Moves LDLM lock \a lock that is already in namespace LRU to the tail of
  * the LRU. Performs necessary LRU locking
  */
-void ldlm_lock_touch_in_lru(struct ldlm_lock *lock)
+static void ldlm_lock_touch_in_lru(struct ldlm_lock *lock)
 {
        struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
 
-       if (lock->l_flags & LDLM_FL_NS_SRV) {
-               LASSERT(list_empty(&lock->l_lru));
-               return;
-       }
-
        spin_lock(&ns->ns_lock);
        if (!list_empty(&lock->l_lru)) {
                ldlm_lock_remove_from_lru_nolock(lock);
@@ -325,7 +306,7 @@ void ldlm_lock_touch_in_lru(struct ldlm_lock *lock)
  * ldlm_lock_destroy, you can never drop your final references on this lock.
  * Because it's not in the hash table anymore.  -phil
  */
-int ldlm_lock_destroy_internal(struct ldlm_lock *lock)
+static int ldlm_lock_destroy_internal(struct ldlm_lock *lock)
 {
        if (lock->l_readers || lock->l_writers) {
                LDLM_ERROR(lock, "lock still has references");
@@ -372,7 +353,7 @@ int ldlm_lock_destroy_internal(struct ldlm_lock *lock)
 /**
  * Destroys a LDLM lock \a lock. Performs necessary locking first.
  */
-void ldlm_lock_destroy(struct ldlm_lock *lock)
+static void ldlm_lock_destroy(struct ldlm_lock *lock)
 {
        int first;
 
@@ -411,10 +392,10 @@ static void lock_handle_addref(void *lock)
 static void lock_handle_free(void *lock, int size)
 {
        LASSERT(size == sizeof(struct ldlm_lock));
-       OBD_SLAB_FREE(lock, ldlm_lock_slab, size);
+       kmem_cache_free(ldlm_lock_slab, lock);
 }
 
-struct portals_handle_ops lock_handle_ops = {
+static struct portals_handle_ops lock_handle_ops = {
        .hop_addref = lock_handle_addref,
        .hop_free   = lock_handle_free,
 };
@@ -434,7 +415,7 @@ static struct ldlm_lock *ldlm_lock_new(struct ldlm_resource *resource)
        if (resource == NULL)
                LBUG();
 
-       OBD_SLAB_ALLOC_PTR_GFP(lock, ldlm_lock_slab, GFP_NOFS);
+       lock = kmem_cache_alloc(ldlm_lock_slab, GFP_NOFS | __GFP_ZERO);
        if (lock == NULL)
                return NULL;
 
@@ -487,8 +468,6 @@ int ldlm_lock_change_resource(struct ldlm_namespace *ns, struct ldlm_lock *lock,
        struct ldlm_resource *newres;
        int type;
 
-       LASSERT(ns_is_client(ns));
-
        lock_res_and_lock(lock);
        if (memcmp(new_resid, &lock->l_resource->lr_name,
                   sizeof(lock->l_resource->lr_name)) == 0) {
@@ -625,8 +604,8 @@ EXPORT_SYMBOL(ldlm_lock2desc);
  *
  * Only add if we have not sent a blocking AST to the lock yet.
  */
-void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
-                          struct list_head *work_list)
+static void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
+                                 struct list_head *work_list)
 {
        if ((lock->l_flags & LDLM_FL_AST_SENT) == 0) {
                LDLM_DEBUG(lock, "lock incompatible; sending blocking AST.");
@@ -646,7 +625,8 @@ void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
 /**
  * Add a lock to list of just granted locks to send completion AST to.
  */
-void ldlm_add_cp_work_item(struct ldlm_lock *lock, struct list_head *work_list)
+static void ldlm_add_cp_work_item(struct ldlm_lock *lock,
+                                 struct list_head *work_list)
 {
        if ((lock->l_flags & LDLM_FL_CP_REQD) == 0) {
                lock->l_flags |= LDLM_FL_CP_REQD;
@@ -663,8 +643,9 @@ void ldlm_add_cp_work_item(struct ldlm_lock *lock, struct list_head *work_list)
  * adding function.
  * Must be called with lr_lock held.
  */
-void ldlm_add_ast_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
-                           struct list_head *work_list)
+static void ldlm_add_ast_work_item(struct ldlm_lock *lock,
+                                  struct ldlm_lock *new,
+                                  struct list_head *work_list)
 {
        check_res_locked(lock->l_resource);
        if (new)
@@ -808,8 +789,6 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
            (lock->l_flags & LDLM_FL_CBPENDING)) {
                /* If we received a blocked AST and this was the last reference,
                 * run the callback. */
-               if ((lock->l_flags & LDLM_FL_NS_SRV) && lock->l_export)
-                       CERROR("FL_CBPENDING set on non-local lock--just a warning\n");
 
                LDLM_DEBUG(lock, "final decref done on cbpending lock");
 
@@ -823,8 +802,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
                if ((lock->l_flags & LDLM_FL_ATOMIC_CB) ||
                    ldlm_bl_to_thread_lock(ns, NULL, lock) != 0)
                        ldlm_handle_bl_callback(ns, NULL, lock);
-       } else if (ns_is_client(ns) &&
-                  !lock->l_readers && !lock->l_writers &&
+       } else if (!lock->l_readers && !lock->l_writers &&
                   !(lock->l_flags & LDLM_FL_NO_LRU) &&
                   !(lock->l_flags & LDLM_FL_BL_AST)) {
 
@@ -1158,14 +1136,6 @@ void ldlm_lock_fail_match_locked(struct ldlm_lock *lock)
 }
 EXPORT_SYMBOL(ldlm_lock_fail_match_locked);
 
-void ldlm_lock_fail_match(struct ldlm_lock *lock)
-{
-       lock_res_and_lock(lock);
-       ldlm_lock_fail_match_locked(lock);
-       unlock_res_and_lock(lock);
-}
-EXPORT_SYMBOL(ldlm_lock_fail_match);
-
 /**
  * Mark lock as "matchable" by OST.
  *
@@ -1260,12 +1230,6 @@ ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
                rc = 0;
                goto out;
        }
-       lock = search_queue(&res->lr_converting, &mode, policy, old_lock,
-                           flags, unref);
-       if (lock != NULL) {
-               rc = 1;
-               goto out;
-       }
        lock = search_queue(&res->lr_waiting, &mode, policy, old_lock,
                            flags, unref);
        if (lock != NULL) {
@@ -1510,8 +1474,6 @@ struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
        lock->l_req_mode = mode;
        lock->l_ast_data = data;
        lock->l_pid = current_pid();
-       if (ns_is_server(ns))
-               lock->l_flags |= LDLM_FL_NS_SRV;
        if (cbs) {
                lock->l_blocking_ast = cbs->lcs_blocking;
                lock->l_completion_ast = cbs->lcs_completion;
@@ -1546,13 +1508,11 @@ out:
 
 /**
  * Enqueue (request) a lock.
+ * On the client this is called from ldlm_cli_enqueue_fini
+ * after we already got an initial reply from the server with some status.
  *
  * Does not block. As a result of enqueue the lock would be put
  * into granted or waiting list.
- *
- * If namespace has intent policy sent and the lock has LDLM_FL_HAS_INTENT flag
- * set, skip all the enqueueing and delegate lock processing to intent policy
- * function.
  */
 ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
                               struct ldlm_lock **lockp,
@@ -1560,43 +1520,11 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
 {
        struct ldlm_lock *lock = *lockp;
        struct ldlm_resource *res = lock->l_resource;
-       int local = ns_is_client(ldlm_res_to_ns(res));
-       ldlm_error_t rc = ELDLM_OK;
-       struct ldlm_interval *node = NULL;
-
-       lock->l_last_activity = get_seconds();
-       /* policies are not executed on the client or during replay */
-       if ((*flags & (LDLM_FL_HAS_INTENT|LDLM_FL_REPLAY)) == LDLM_FL_HAS_INTENT
-           && !local && ns->ns_policy) {
-               rc = ns->ns_policy(ns, lockp, cookie, lock->l_req_mode, *flags,
-                                  NULL);
-               if (rc == ELDLM_LOCK_REPLACED) {
-                       /* The lock that was returned has already been granted,
-                        * and placed into lockp.  If it's not the same as the
-                        * one we passed in, then destroy the old one and our
-                        * work here is done. */
-                       if (lock != *lockp) {
-                               ldlm_lock_destroy(lock);
-                               LDLM_LOCK_RELEASE(lock);
-                       }
-                       *flags |= LDLM_FL_LOCK_CHANGED;
-                       return 0;
-               } else if (rc != ELDLM_OK ||
-                          (rc == ELDLM_OK && (*flags & LDLM_FL_INTENT_ONLY))) {
-                       ldlm_lock_destroy(lock);
-                       return rc;
-               }
-       }
 
-       /* For a replaying lock, it might be already in granted list. So
-        * unlinking the lock will cause the interval node to be freed, we
-        * have to allocate the interval node early otherwise we can't regrant
-        * this lock in the future. - jay */
-       if (!local && (*flags & LDLM_FL_REPLAY) && res->lr_type == LDLM_EXTENT)
-               OBD_SLAB_ALLOC_PTR_GFP(node, ldlm_interval_slab, GFP_NOFS);
+       lock->l_last_activity = ktime_get_real_seconds();
 
        lock_res_and_lock(lock);
-       if (local && lock->l_req_mode == lock->l_granted_mode) {
+       if (lock->l_req_mode == lock->l_granted_mode) {
                /* The server returned a blocked lock, but it was granted
                 * before we got a chance to actually enqueue it.  We don't
                 * need to do anything else. */
@@ -1606,54 +1534,32 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
        }
 
        ldlm_resource_unlink_lock(lock);
-       if (res->lr_type == LDLM_EXTENT && lock->l_tree_node == NULL) {
-               if (node == NULL) {
-                       ldlm_lock_destroy_nolock(lock);
-                       rc = -ENOMEM;
-                       goto out;
-               }
 
-               INIT_LIST_HEAD(&node->li_group);
-               ldlm_interval_attach(node, lock);
-               node = NULL;
-       }
+       /* Cannot happen unless on the server */
+       if (res->lr_type == LDLM_EXTENT && !lock->l_tree_node)
+               LBUG();
 
        /* Some flags from the enqueue want to make it into the AST, via the
         * lock's l_flags. */
        lock->l_flags |= *flags & LDLM_FL_AST_DISCARD_DATA;
 
-       /* This distinction between local lock trees is very important; a client
+       /*
+        * This distinction between local lock trees is very important; a client
         * namespace only has information about locks taken by that client, and
         * thus doesn't have enough information to decide for itself if it can
         * be granted (below).  In this case, we do exactly what the server
         * tells us to do, as dictated by the 'flags'.
-        *
-        * We do exactly the same thing during recovery, when the server is
-        * more or less trusting the clients not to lie.
-        *
-        * FIXME (bug 268): Detect obvious lies by checking compatibility in
-        * granted/converting queues. */
-       if (local) {
-               if (*flags & LDLM_FL_BLOCK_CONV)
-                       ldlm_resource_add_lock(res, &res->lr_converting, lock);
-               else if (*flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED))
-                       ldlm_resource_add_lock(res, &res->lr_waiting, lock);
-               else
-                       ldlm_grant_lock(lock, NULL);
-               goto out;
-       } else {
-               CERROR("This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n");
-               LBUG();
-       }
+        */
+       if (*flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED))
+               ldlm_resource_add_lock(res, &res->lr_waiting, lock);
+       else
+               ldlm_grant_lock(lock, NULL);
 
 out:
        unlock_res_and_lock(lock);
-       if (node)
-               OBD_SLAB_FREE(node, ldlm_interval_slab, sizeof(*node));
-       return rc;
+       return ELDLM_OK;
 }
 
-
 /**
  * Process a call to blocking AST callback for a lock in ast_work list
  */
@@ -1765,7 +1671,7 @@ ldlm_work_revoke_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
 /**
  * Process a call to glimpse AST callback for a lock in ast_work list
  */
-int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
+static int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
 {
        struct ldlm_cb_set_arg          *arg = opaq;
        struct ldlm_glimpse_work        *gl_work;
@@ -1861,54 +1767,6 @@ out:
        return rc;
 }
 
-static int reprocess_one_queue(struct ldlm_resource *res, void *closure)
-{
-       ldlm_reprocess_all(res);
-       return LDLM_ITER_CONTINUE;
-}
-
-static int ldlm_reprocess_res(struct cfs_hash *hs, struct cfs_hash_bd *bd,
-                             struct hlist_node *hnode, void *arg)
-{
-       struct ldlm_resource *res = cfs_hash_object(hs, hnode);
-       int    rc;
-
-       rc = reprocess_one_queue(res, arg);
-
-       return rc == LDLM_ITER_STOP;
-}
-
-/**
- * Iterate through all resources on a namespace attempting to grant waiting
- * locks.
- */
-void ldlm_reprocess_all_ns(struct ldlm_namespace *ns)
-{
-       if (ns != NULL) {
-               cfs_hash_for_each_nolock(ns->ns_rs_hash,
-                                        ldlm_reprocess_res, NULL);
-       }
-}
-EXPORT_SYMBOL(ldlm_reprocess_all_ns);
-
-/**
- * Try to grant all waiting locks on a resource.
- *
- * Calls ldlm_reprocess_queue on converting and waiting queues.
- *
- * Typically called after some resource locks are cancelled to see
- * if anything could be granted as a result of the cancellation.
- */
-void ldlm_reprocess_all(struct ldlm_resource *res)
-{
-       LIST_HEAD(rpc_list);
-
-       if (!ns_is_client(ldlm_res_to_ns(res))) {
-               CERROR("This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n");
-               LBUG();
-       }
-}
-
 /**
  * Helper function to call blocking AST for LDLM lock \a lock in a
  * "cancelling" mode.
@@ -1963,17 +1821,9 @@ void ldlm_lock_cancel(struct ldlm_lock *lock)
                LBUG();
        }
 
-       if (lock->l_flags & LDLM_FL_WAITED)
-               ldlm_del_waiting_lock(lock);
-
        /* Releases cancel callback. */
        ldlm_cancel_callback(lock);
 
-       /* Yes, second time, just in case it was added again while we were
-        * running with no res lock in ldlm_cancel_callback */
-       if (lock->l_flags & LDLM_FL_WAITED)
-               ldlm_del_waiting_lock(lock);
-
        ldlm_resource_unlink_lock(lock);
        ldlm_lock_destroy_nolock(lock);
 
@@ -2011,175 +1861,6 @@ struct export_cl_data {
        int                     ecl_loop;
 };
 
-/**
- * Iterator function for ldlm_cancel_locks_for_export.
- * Cancels passed locks.
- */
-int ldlm_cancel_locks_for_export_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
-                                   struct hlist_node *hnode, void *data)
-
-{
-       struct export_cl_data   *ecl = (struct export_cl_data *)data;
-       struct obd_export       *exp  = ecl->ecl_exp;
-       struct ldlm_lock     *lock = cfs_hash_object(hs, hnode);
-       struct ldlm_resource *res;
-
-       res = ldlm_resource_getref(lock->l_resource);
-       LDLM_LOCK_GET(lock);
-
-       LDLM_DEBUG(lock, "export %p", exp);
-       ldlm_res_lvbo_update(res, NULL, 1);
-       ldlm_lock_cancel(lock);
-       ldlm_reprocess_all(res);
-       ldlm_resource_putref(res);
-       LDLM_LOCK_RELEASE(lock);
-
-       ecl->ecl_loop++;
-       if ((ecl->ecl_loop & -ecl->ecl_loop) == ecl->ecl_loop) {
-               CDEBUG(D_INFO,
-                      "Cancel lock %p for export %p (loop %d), still have %d locks left on hash table.\n",
-                      lock, exp, ecl->ecl_loop,
-                      atomic_read(&hs->hs_count));
-       }
-
-       return 0;
-}
-
-/**
- * Cancel all locks for given export.
- *
- * Typically called on client disconnection/eviction
- */
-void ldlm_cancel_locks_for_export(struct obd_export *exp)
-{
-       struct export_cl_data   ecl = {
-               .ecl_exp        = exp,
-               .ecl_loop       = 0,
-       };
-
-       cfs_hash_for_each_empty(exp->exp_lock_hash,
-                               ldlm_cancel_locks_for_export_cb, &ecl);
-}
-
-/**
- * Downgrade an exclusive lock.
- *
- * A fast variant of ldlm_lock_convert for conversion of exclusive
- * locks. The conversion is always successful.
- * Used by Commit on Sharing (COS) code.
- *
- * \param lock A lock to convert
- * \param new_mode new lock mode
- */
-void ldlm_lock_downgrade(struct ldlm_lock *lock, int new_mode)
-{
-       LASSERT(lock->l_granted_mode & (LCK_PW | LCK_EX));
-       LASSERT(new_mode == LCK_COS);
-
-       lock_res_and_lock(lock);
-       ldlm_resource_unlink_lock(lock);
-       /*
-        * Remove the lock from pool as it will be added again in
-        * ldlm_grant_lock() called below.
-        */
-       ldlm_pool_del(&ldlm_lock_to_ns(lock)->ns_pool, lock);
-
-       lock->l_req_mode = new_mode;
-       ldlm_grant_lock(lock, NULL);
-       unlock_res_and_lock(lock);
-       ldlm_reprocess_all(lock->l_resource);
-}
-EXPORT_SYMBOL(ldlm_lock_downgrade);
-
-/**
- * Attempt to convert already granted lock to a different mode.
- *
- * While lock conversion is not currently used, future client-side
- * optimizations could take advantage of it to avoid discarding cached
- * pages on a file.
- */
-struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
-                                       __u32 *flags)
-{
-       LIST_HEAD(rpc_list);
-       struct ldlm_resource *res;
-       struct ldlm_namespace *ns;
-       int granted = 0;
-       struct ldlm_interval *node;
-
-       /* Just return if mode is unchanged. */
-       if (new_mode == lock->l_granted_mode) {
-               *flags |= LDLM_FL_BLOCK_GRANTED;
-               return lock->l_resource;
-       }
-
-       /* I can't check the type of lock here because the bitlock of lock
-        * is not held here, so do the allocation blindly. -jay */
-       OBD_SLAB_ALLOC_PTR_GFP(node, ldlm_interval_slab, GFP_NOFS);
-       if (node == NULL)
-               /* Actually, this causes EDEADLOCK to be returned */
-               return NULL;
-
-       LASSERTF((new_mode == LCK_PW && lock->l_granted_mode == LCK_PR),
-                "new_mode %u, granted %u\n", new_mode, lock->l_granted_mode);
-
-       lock_res_and_lock(lock);
-
-       res = lock->l_resource;
-       ns  = ldlm_res_to_ns(res);
-
-       lock->l_req_mode = new_mode;
-       if (res->lr_type == LDLM_PLAIN || res->lr_type == LDLM_IBITS) {
-               ldlm_resource_unlink_lock(lock);
-       } else {
-               ldlm_resource_unlink_lock(lock);
-               if (res->lr_type == LDLM_EXTENT) {
-                       /* FIXME: ugly code, I have to attach the lock to a
-                        * interval node again since perhaps it will be granted
-                        * soon */
-                       INIT_LIST_HEAD(&node->li_group);
-                       ldlm_interval_attach(node, lock);
-                       node = NULL;
-               }
-       }
-
-       /*
-        * Remove old lock from the pool before adding the lock with new
-        * mode below in ->policy()
-        */
-       ldlm_pool_del(&ns->ns_pool, lock);
-
-       /* If this is a local resource, put it on the appropriate list. */
-       if (ns_is_client(ldlm_res_to_ns(res))) {
-               if (*flags & (LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_GRANTED)) {
-                       ldlm_resource_add_lock(res, &res->lr_converting, lock);
-               } else {
-                       /* This should never happen, because of the way the
-                        * server handles conversions. */
-                       LDLM_ERROR(lock, "Erroneous flags %x on local lock\n",
-                                  *flags);
-                       LBUG();
-
-                       ldlm_grant_lock(lock, &rpc_list);
-                       granted = 1;
-                       /* FIXME: completion handling not with lr_lock held ! */
-                       if (lock->l_completion_ast)
-                               lock->l_completion_ast(lock, 0, NULL);
-               }
-       } else {
-               CERROR("This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n");
-               LBUG();
-       }
-       unlock_res_and_lock(lock);
-
-       if (granted)
-               ldlm_run_ast_work(ns, &rpc_list, LDLM_WORK_CP_AST);
-       if (node)
-               OBD_SLAB_FREE(node, ldlm_interval_slab, sizeof(*node));
-       return res;
-}
-EXPORT_SYMBOL(ldlm_lock_convert);
-
 /**
  * Print lock with lock handle \a lockh description into debug log.
  *
index ac79db952da78babfedf328047d798526e74780a..ca115119501ae1ba3a2272665fc83c4fa3a336db 100644 (file)
@@ -58,9 +58,9 @@ MODULE_PARM_DESC(ldlm_cpts, "CPU partitions ldlm threads should run on");
 static struct mutex    ldlm_ref_mutex;
 static int ldlm_refcount;
 
-struct kobject *ldlm_kobj;
+static struct kobject *ldlm_kobj;
 struct kset *ldlm_ns_kset;
-struct kset *ldlm_svc_kset;
+static struct kset *ldlm_svc_kset;
 
 struct ldlm_cb_async_args {
        struct ldlm_cb_set_arg *ca_set_arg;
@@ -71,11 +71,6 @@ struct ldlm_cb_async_args {
 
 static struct ldlm_state *ldlm_state;
 
-inline unsigned long round_timeout(unsigned long timeout)
-{
-       return cfs_time_seconds((int)cfs_duration_sec(cfs_time_sub(timeout, 0)) + 1);
-}
-
 #define ELT_STOPPED   0
 #define ELT_READY     1
 #define ELT_TERMINATE 2
@@ -116,19 +111,6 @@ struct ldlm_bl_work_item {
        int                  blwi_mem_pressure;
 };
 
-
-int ldlm_del_waiting_lock(struct ldlm_lock *lock)
-{
-       return 0;
-}
-
-int ldlm_refresh_waiting_lock(struct ldlm_lock *lock, int timeout)
-{
-       return 0;
-}
-
-
-
 /**
  * Callback handler for receiving incoming blocking ASTs.
  *
@@ -461,7 +443,6 @@ static int ldlm_bl_to_thread(struct ldlm_namespace *ns,
        }
 }
 
-
 int ldlm_bl_to_thread_lock(struct ldlm_namespace *ns, struct ldlm_lock_desc *ld,
                           struct ldlm_lock *lock)
 {
@@ -713,7 +694,6 @@ static int ldlm_callback_handler(struct ptlrpc_request *req)
        return 0;
 }
 
-
 static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
 {
        struct ldlm_bl_work_item *blwi = NULL;
@@ -855,7 +835,6 @@ static int ldlm_bl_thread_main(void *arg)
        return 0;
 }
 
-
 static int ldlm_setup(void);
 static int ldlm_cleanup(void);
 
@@ -892,111 +871,6 @@ void ldlm_put_ref(void)
 }
 EXPORT_SYMBOL(ldlm_put_ref);
 
-/*
- * Export handle<->lock hash operations.
- */
-static unsigned
-ldlm_export_lock_hash(struct cfs_hash *hs, const void *key, unsigned mask)
-{
-       return cfs_hash_u64_hash(((struct lustre_handle *)key)->cookie, mask);
-}
-
-static void *
-ldlm_export_lock_key(struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       return &lock->l_remote_handle;
-}
-
-static void
-ldlm_export_lock_keycpy(struct hlist_node *hnode, void *key)
-{
-       struct ldlm_lock     *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       lock->l_remote_handle = *(struct lustre_handle *)key;
-}
-
-static int
-ldlm_export_lock_keycmp(const void *key, struct hlist_node *hnode)
-{
-       return lustre_handle_equal(ldlm_export_lock_key(hnode), key);
-}
-
-static void *
-ldlm_export_lock_object(struct hlist_node *hnode)
-{
-       return hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-}
-
-static void
-ldlm_export_lock_get(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       LDLM_LOCK_GET(lock);
-}
-
-static void
-ldlm_export_lock_put(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct ldlm_lock *lock;
-
-       lock = hlist_entry(hnode, struct ldlm_lock, l_exp_hash);
-       LDLM_LOCK_RELEASE(lock);
-}
-
-static cfs_hash_ops_t ldlm_export_lock_ops = {
-       .hs_hash        = ldlm_export_lock_hash,
-       .hs_key  = ldlm_export_lock_key,
-       .hs_keycmp      = ldlm_export_lock_keycmp,
-       .hs_keycpy      = ldlm_export_lock_keycpy,
-       .hs_object      = ldlm_export_lock_object,
-       .hs_get  = ldlm_export_lock_get,
-       .hs_put  = ldlm_export_lock_put,
-       .hs_put_locked  = ldlm_export_lock_put,
-};
-
-int ldlm_init_export(struct obd_export *exp)
-{
-       int rc;
-
-       exp->exp_lock_hash =
-               cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
-                               HASH_EXP_LOCK_CUR_BITS,
-                               HASH_EXP_LOCK_MAX_BITS,
-                               HASH_EXP_LOCK_BKT_BITS, 0,
-                               CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA,
-                               &ldlm_export_lock_ops,
-                               CFS_HASH_DEFAULT | CFS_HASH_REHASH_KEY |
-                               CFS_HASH_NBLK_CHANGE);
-
-       if (!exp->exp_lock_hash)
-               return -ENOMEM;
-
-       rc = ldlm_init_flock_export(exp);
-       if (rc)
-               goto err;
-
-       return 0;
-err:
-       ldlm_destroy_export(exp);
-       return rc;
-}
-EXPORT_SYMBOL(ldlm_init_export);
-
-void ldlm_destroy_export(struct obd_export *exp)
-{
-       cfs_hash_putref(exp->exp_lock_hash);
-       exp->exp_lock_hash = NULL;
-
-       ldlm_destroy_flock_export(exp);
-}
-EXPORT_SYMBOL(ldlm_destroy_export);
-
 extern unsigned int ldlm_cancel_unused_locks_before_replay;
 
 static ssize_t cancel_unused_locks_before_replay_show(struct kobject *kobj,
@@ -1005,6 +879,7 @@ static ssize_t cancel_unused_locks_before_replay_show(struct kobject *kobj,
 {
        return sprintf(buf, "%d\n", ldlm_cancel_unused_locks_before_replay);
 }
+
 static ssize_t cancel_unused_locks_before_replay_store(struct kobject *kobj,
                                                       struct attribute *attr,
                                                       const char *buffer,
@@ -1112,7 +987,6 @@ static int ldlm_setup(void)
                goto out;
        }
 
-
        blp = kzalloc(sizeof(*blp), GFP_NOFS);
        if (!blp) {
                rc = -ENOMEM;
index a1fe2c161e384ee3fd84e4a418ddb028a40e081a..0c1965ddabb9e15bbd8615eb55af3c2f0c9db861 100644 (file)
@@ -58,7 +58,6 @@
 
 #include "ldlm_internal.h"
 
-
 void ldlm_plain_policy_wire_to_local(const ldlm_wire_policy_data_t *wpolicy,
                                     ldlm_policy_data_t *lpolicy)
 {
index c234acb85f10063cef7aa0a8c9b8f71c8519b8b2..1a4eef64658f9cf02d7b4050839d8936a541b019 100644 (file)
 #include "../include/obd_support.h"
 #include "ldlm_internal.h"
 
-
 /*
  * 50 ldlm locks for 1MB of RAM.
  */
@@ -214,67 +213,19 @@ static inline int ldlm_pool_t2gsp(unsigned int t)
 }
 
 /**
- * Recalculates next grant limit on passed \a pl.
- *
- * \pre ->pl_lock is locked.
+ * Returns current \a pl limit.
  */
-static void ldlm_pool_recalc_grant_plan(struct ldlm_pool *pl)
+static __u32 ldlm_pool_get_limit(struct ldlm_pool *pl)
 {
-       int granted, grant_step, limit;
-
-       limit = ldlm_pool_get_limit(pl);
-       granted = atomic_read(&pl->pl_granted);
-
-       grant_step = ldlm_pool_t2gsp(pl->pl_recalc_period);
-       grant_step = ((limit - granted) * grant_step) / 100;
-       pl->pl_grant_plan = granted + grant_step;
-       limit = (limit * 5) >> 2;
-       if (pl->pl_grant_plan > limit)
-               pl->pl_grant_plan = limit;
+       return atomic_read(&pl->pl_limit);
 }
 
 /**
- * Recalculates next SLV on passed \a pl.
- *
- * \pre ->pl_lock is locked.
+ * Sets passed \a limit to \a pl.
  */
-static void ldlm_pool_recalc_slv(struct ldlm_pool *pl)
+static void ldlm_pool_set_limit(struct ldlm_pool *pl, __u32 limit)
 {
-       int granted;
-       int grant_plan;
-       int round_up;
-       __u64 slv;
-       __u64 slv_factor;
-       __u64 grant_usage;
-       __u32 limit;
-
-       slv = pl->pl_server_lock_volume;
-       grant_plan = pl->pl_grant_plan;
-       limit = ldlm_pool_get_limit(pl);
-       granted = atomic_read(&pl->pl_granted);
-       round_up = granted < limit;
-
-       grant_usage = max_t(int, limit - (granted - grant_plan), 1);
-
-       /*
-        * Find out SLV change factor which is the ratio of grant usage
-        * from limit. SLV changes as fast as the ratio of grant plan
-        * consumption. The more locks from grant plan are not consumed
-        * by clients in last interval (idle time), the faster grows
-        * SLV. And the opposite, the more grant plan is over-consumed
-        * (load time) the faster drops SLV.
-        */
-       slv_factor = grant_usage << LDLM_POOL_SLV_SHIFT;
-       do_div(slv_factor, limit);
-       slv = slv * slv_factor;
-       slv = dru(slv, LDLM_POOL_SLV_SHIFT, round_up);
-
-       if (slv > ldlm_pool_slv_max(limit))
-               slv = ldlm_pool_slv_max(limit);
-       else if (slv < ldlm_pool_slv_min(limit))
-               slv = ldlm_pool_slv_min(limit);
-
-       pl->pl_server_lock_volume = slv;
+       atomic_set(&pl->pl_limit, limit);
 }
 
 /**
@@ -302,147 +253,6 @@ static void ldlm_pool_recalc_stats(struct ldlm_pool *pl)
                            cancel_rate);
 }
 
-/**
- * Sets current SLV into obd accessible via ldlm_pl2ns(pl)->ns_obd.
- */
-static void ldlm_srv_pool_push_slv(struct ldlm_pool *pl)
-{
-       struct obd_device *obd;
-
-       /*
-        * Set new SLV in obd field for using it later without accessing the
-        * pool. This is required to avoid race between sending reply to client
-        * with new SLV and cleanup server stack in which we can't guarantee
-        * that namespace is still alive. We know only that obd is alive as
-        * long as valid export is alive.
-        */
-       obd = ldlm_pl2ns(pl)->ns_obd;
-       LASSERT(obd != NULL);
-       write_lock(&obd->obd_pool_lock);
-       obd->obd_pool_slv = pl->pl_server_lock_volume;
-       write_unlock(&obd->obd_pool_lock);
-}
-
-/**
- * Recalculates all pool fields on passed \a pl.
- *
- * \pre ->pl_lock is not locked.
- */
-static int ldlm_srv_pool_recalc(struct ldlm_pool *pl)
-{
-       time_t recalc_interval_sec;
-
-       recalc_interval_sec = get_seconds() - pl->pl_recalc_time;
-       if (recalc_interval_sec < pl->pl_recalc_period)
-               return 0;
-
-       spin_lock(&pl->pl_lock);
-       recalc_interval_sec = get_seconds() - pl->pl_recalc_time;
-       if (recalc_interval_sec < pl->pl_recalc_period) {
-               spin_unlock(&pl->pl_lock);
-               return 0;
-       }
-       /*
-        * Recalc SLV after last period. This should be done
-        * _before_ recalculating new grant plan.
-        */
-       ldlm_pool_recalc_slv(pl);
-
-       /*
-        * Make sure that pool informed obd of last SLV changes.
-        */
-       ldlm_srv_pool_push_slv(pl);
-
-       /*
-        * Update grant_plan for new period.
-        */
-       ldlm_pool_recalc_grant_plan(pl);
-
-       pl->pl_recalc_time = get_seconds();
-       lprocfs_counter_add(pl->pl_stats, LDLM_POOL_TIMING_STAT,
-                           recalc_interval_sec);
-       spin_unlock(&pl->pl_lock);
-       return 0;
-}
-
-/**
- * This function is used on server side as main entry point for memory
- * pressure handling. It decreases SLV on \a pl according to passed
- * \a nr and \a gfp_mask.
- *
- * Our goal here is to decrease SLV such a way that clients hold \a nr
- * locks smaller in next 10h.
- */
-static int ldlm_srv_pool_shrink(struct ldlm_pool *pl,
-                               int nr, gfp_t gfp_mask)
-{
-       __u32 limit;
-
-       /*
-        * VM is asking how many entries may be potentially freed.
-        */
-       if (nr == 0)
-               return atomic_read(&pl->pl_granted);
-
-       /*
-        * Client already canceled locks but server is already in shrinker
-        * and can't cancel anything. Let's catch this race.
-        */
-       if (atomic_read(&pl->pl_granted) == 0)
-               return 0;
-
-       spin_lock(&pl->pl_lock);
-
-       /*
-        * We want shrinker to possibly cause cancellation of @nr locks from
-        * clients or grant approximately @nr locks smaller next intervals.
-        *
-        * This is why we decreased SLV by @nr. This effect will only be as
-        * long as one re-calc interval (1s these days) and this should be
-        * enough to pass this decreased SLV to all clients. On next recalc
-        * interval pool will either increase SLV if locks load is not high
-        * or will keep on same level or even decrease again, thus, shrinker
-        * decreased SLV will affect next recalc intervals and this way will
-        * make locking load lower.
-        */
-       if (nr < pl->pl_server_lock_volume) {
-               pl->pl_server_lock_volume = pl->pl_server_lock_volume - nr;
-       } else {
-               limit = ldlm_pool_get_limit(pl);
-               pl->pl_server_lock_volume = ldlm_pool_slv_min(limit);
-       }
-
-       /*
-        * Make sure that pool informed obd of last SLV changes.
-        */
-       ldlm_srv_pool_push_slv(pl);
-       spin_unlock(&pl->pl_lock);
-
-       /*
-        * We did not really free any memory here so far, it only will be
-        * freed later may be, so that we return 0 to not confuse VM.
-        */
-       return 0;
-}
-
-/**
- * Setup server side pool \a pl with passed \a limit.
- */
-static int ldlm_srv_pool_setup(struct ldlm_pool *pl, int limit)
-{
-       struct obd_device *obd;
-
-       obd = ldlm_pl2ns(pl)->ns_obd;
-       LASSERT(obd != NULL && obd != LP_POISON);
-       LASSERT(obd->obd_type != LP_POISON);
-       write_lock(&obd->obd_pool_lock);
-       obd->obd_pool_limit = limit;
-       write_unlock(&obd->obd_pool_lock);
-
-       ldlm_pool_set_limit(pl, limit);
-       return 0;
-}
-
 /**
  * Sets SLV and Limit from ldlm_pl2ns(pl)->ns_obd tp passed \a pl.
  */
@@ -467,10 +277,10 @@ static void ldlm_cli_pool_pop_slv(struct ldlm_pool *pl)
  */
 static int ldlm_cli_pool_recalc(struct ldlm_pool *pl)
 {
-       time_t recalc_interval_sec;
+       time64_t recalc_interval_sec;
        int ret;
 
-       recalc_interval_sec = get_seconds() - pl->pl_recalc_time;
+       recalc_interval_sec = ktime_get_real_seconds() - pl->pl_recalc_time;
        if (recalc_interval_sec < pl->pl_recalc_period)
                return 0;
 
@@ -478,7 +288,7 @@ static int ldlm_cli_pool_recalc(struct ldlm_pool *pl)
        /*
         * Check if we need to recalc lists now.
         */
-       recalc_interval_sec = get_seconds() - pl->pl_recalc_time;
+       recalc_interval_sec = ktime_get_real_seconds() - pl->pl_recalc_time;
        if (recalc_interval_sec < pl->pl_recalc_period) {
                spin_unlock(&pl->pl_lock);
                return 0;
@@ -513,7 +323,7 @@ out:
         * Time of LRU resizing might be longer than period,
         * so update after LRU resizing rather than before it.
         */
-       pl->pl_recalc_time = get_seconds();
+       pl->pl_recalc_time = ktime_get_real_seconds();
        lprocfs_counter_add(pl->pl_stats, LDLM_POOL_TIMING_STAT,
                            recalc_interval_sec);
        spin_unlock(&pl->pl_lock);
@@ -554,12 +364,6 @@ static int ldlm_cli_pool_shrink(struct ldlm_pool *pl,
                return ldlm_cancel_lru(ns, nr, LCF_ASYNC, LDLM_CANCEL_SHRINK);
 }
 
-static const struct ldlm_pool_ops ldlm_srv_pool_ops = {
-       .po_recalc = ldlm_srv_pool_recalc,
-       .po_shrink = ldlm_srv_pool_shrink,
-       .po_setup  = ldlm_srv_pool_setup
-};
-
 static const struct ldlm_pool_ops ldlm_cli_pool_ops = {
        .po_recalc = ldlm_cli_pool_recalc,
        .po_shrink = ldlm_cli_pool_shrink
@@ -569,12 +373,12 @@ static const struct ldlm_pool_ops ldlm_cli_pool_ops = {
  * Pool recalc wrapper. Will call either client or server pool recalc callback
  * depending what pool \a pl is used.
  */
-int ldlm_pool_recalc(struct ldlm_pool *pl)
+static int ldlm_pool_recalc(struct ldlm_pool *pl)
 {
-       time_t recalc_interval_sec;
+       u32 recalc_interval_sec;
        int count;
 
-       recalc_interval_sec = get_seconds() - pl->pl_recalc_time;
+       recalc_interval_sec = ktime_get_seconds() - pl->pl_recalc_time;
        if (recalc_interval_sec <= 0)
                goto recalc;
 
@@ -599,14 +403,14 @@ int ldlm_pool_recalc(struct ldlm_pool *pl)
                lprocfs_counter_add(pl->pl_stats, LDLM_POOL_RECALC_STAT,
                                    count);
        }
-       recalc_interval_sec = pl->pl_recalc_time - get_seconds() +
+       recalc_interval_sec = pl->pl_recalc_time - ktime_get_seconds() +
                              pl->pl_recalc_period;
        if (recalc_interval_sec <= 0) {
                /* Prevent too frequent recalculation. */
-               CDEBUG(D_DLMTRACE, "Negative interval(%ld), "
-                      "too short period(%ld)",
+               CDEBUG(D_DLMTRACE,
+                      "Negative interval(%d), too short period(%lld)",
                       recalc_interval_sec,
-                      pl->pl_recalc_period);
+                      (s64)pl->pl_recalc_period);
                recalc_interval_sec = 1;
        }
 
@@ -618,8 +422,7 @@ int ldlm_pool_recalc(struct ldlm_pool *pl)
  * depending what pool pl is used. When nr == 0, just return the number of
  * freeable locks. Otherwise, return the number of canceled locks.
  */
-int ldlm_pool_shrink(struct ldlm_pool *pl, int nr,
-                    gfp_t gfp_mask)
+static int ldlm_pool_shrink(struct ldlm_pool *pl, int nr, gfp_t gfp_mask)
 {
        int cancel = 0;
 
@@ -638,26 +441,11 @@ int ldlm_pool_shrink(struct ldlm_pool *pl, int nr,
        }
        return cancel;
 }
-EXPORT_SYMBOL(ldlm_pool_shrink);
-
-/**
- * Pool setup wrapper. Will call either client or server pool recalc callback
- * depending what pool \a pl is used.
- *
- * Sets passed \a limit into pool \a pl.
- */
-int ldlm_pool_setup(struct ldlm_pool *pl, int limit)
-{
-       if (pl->pl_ops->po_setup != NULL)
-               return pl->pl_ops->po_setup(pl, limit);
-       return 0;
-}
-EXPORT_SYMBOL(ldlm_pool_setup);
 
 static int lprocfs_pool_state_seq_show(struct seq_file *m, void *unused)
 {
-       int granted, grant_rate, cancel_rate, grant_step;
-       int grant_speed, grant_plan, lvf;
+       int granted, grant_rate, cancel_rate;
+       int grant_speed, lvf;
        struct ldlm_pool *pl = m->private;
        __u64 slv, clv;
        __u32 limit;
@@ -666,13 +454,11 @@ static int lprocfs_pool_state_seq_show(struct seq_file *m, void *unused)
        slv = pl->pl_server_lock_volume;
        clv = pl->pl_client_lock_volume;
        limit = ldlm_pool_get_limit(pl);
-       grant_plan = pl->pl_grant_plan;
        granted = atomic_read(&pl->pl_granted);
        grant_rate = atomic_read(&pl->pl_grant_rate);
        cancel_rate = atomic_read(&pl->pl_cancel_rate);
        grant_speed = grant_rate - cancel_rate;
        lvf = atomic_read(&pl->pl_lock_volume_factor);
-       grant_step = ldlm_pool_t2gsp(pl->pl_recalc_period);
        spin_unlock(&pl->pl_lock);
 
        seq_printf(m, "LDLM pool state (%s):\n"
@@ -681,11 +467,6 @@ static int lprocfs_pool_state_seq_show(struct seq_file *m, void *unused)
                      "  LVF: %d\n",
                      pl->pl_name, slv, clv, lvf);
 
-       if (ns_is_server(ldlm_pl2ns(pl))) {
-               seq_printf(m, "  GSP: %d%%\n"
-                             "  GP:  %d\n",
-                             grant_step, grant_plan);
-       }
        seq_printf(m, "  GR:  %d\n  CR:  %d\n  GS:  %d\n"
                      "  G:   %d\n  L:   %d\n",
                      grant_rate, cancel_rate, grant_speed,
@@ -693,6 +474,7 @@ static int lprocfs_pool_state_seq_show(struct seq_file *m, void *unused)
 
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(lprocfs_pool_state);
 
 static ssize_t grant_speed_show(struct kobject *kobj, struct attribute *attr,
@@ -893,7 +675,7 @@ int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns,
 
        spin_lock_init(&pl->pl_lock);
        atomic_set(&pl->pl_granted, 0);
-       pl->pl_recalc_time = get_seconds();
+       pl->pl_recalc_time = ktime_get_seconds();
        atomic_set(&pl->pl_lock_volume_factor, 1);
 
        atomic_set(&pl->pl_grant_rate, 0);
@@ -903,17 +685,10 @@ int ldlm_pool_init(struct ldlm_pool *pl, struct ldlm_namespace *ns,
        snprintf(pl->pl_name, sizeof(pl->pl_name), "ldlm-pool-%s-%d",
                 ldlm_ns_name(ns), idx);
 
-       if (client == LDLM_NAMESPACE_SERVER) {
-               pl->pl_ops = &ldlm_srv_pool_ops;
-               ldlm_pool_set_limit(pl, LDLM_POOL_HOST_L);
-               pl->pl_recalc_period = LDLM_POOL_SRV_DEF_RECALC_PERIOD;
-               pl->pl_server_lock_volume = ldlm_pool_slv_max(LDLM_POOL_HOST_L);
-       } else {
-               ldlm_pool_set_limit(pl, 1);
-               pl->pl_server_lock_volume = 0;
-               pl->pl_ops = &ldlm_cli_pool_ops;
-               pl->pl_recalc_period = LDLM_POOL_CLI_DEF_RECALC_PERIOD;
-       }
+       ldlm_pool_set_limit(pl, 1);
+       pl->pl_server_lock_volume = 0;
+       pl->pl_ops = &ldlm_cli_pool_ops;
+       pl->pl_recalc_period = LDLM_POOL_CLI_DEF_RECALC_PERIOD;
        pl->pl_client_lock_volume = 0;
        rc = ldlm_pool_debugfs_init(pl);
        if (rc)
@@ -966,8 +741,6 @@ void ldlm_pool_add(struct ldlm_pool *pl, struct ldlm_lock *lock)
         * enqueue/cancel rpc. Also we do not want to run out of stack
         * with too long call paths.
         */
-       if (ns_is_server(ldlm_pl2ns(pl)))
-               ldlm_pool_recalc(pl);
 }
 EXPORT_SYMBOL(ldlm_pool_add);
 
@@ -987,9 +760,6 @@ void ldlm_pool_del(struct ldlm_pool *pl, struct ldlm_lock *lock)
        atomic_inc(&pl->pl_cancel_rate);
 
        lprocfs_counter_incr(pl->pl_stats, LDLM_POOL_CANCEL_STAT);
-
-       if (ns_is_server(ldlm_pl2ns(pl)))
-               ldlm_pool_recalc(pl);
 }
 EXPORT_SYMBOL(ldlm_pool_del);
 
@@ -1007,36 +777,6 @@ __u64 ldlm_pool_get_slv(struct ldlm_pool *pl)
        spin_unlock(&pl->pl_lock);
        return slv;
 }
-EXPORT_SYMBOL(ldlm_pool_get_slv);
-
-/**
- * Sets passed \a slv to \a pl.
- *
- * \pre ->pl_lock is not locked.
- */
-void ldlm_pool_set_slv(struct ldlm_pool *pl, __u64 slv)
-{
-       spin_lock(&pl->pl_lock);
-       pl->pl_server_lock_volume = slv;
-       spin_unlock(&pl->pl_lock);
-}
-EXPORT_SYMBOL(ldlm_pool_set_slv);
-
-/**
- * Returns current \a pl CLV.
- *
- * \pre ->pl_lock is not locked.
- */
-__u64 ldlm_pool_get_clv(struct ldlm_pool *pl)
-{
-       __u64 slv;
-
-       spin_lock(&pl->pl_lock);
-       slv = pl->pl_client_lock_volume;
-       spin_unlock(&pl->pl_lock);
-       return slv;
-}
-EXPORT_SYMBOL(ldlm_pool_get_clv);
 
 /**
  * Sets passed \a clv to \a pl.
@@ -1049,25 +789,6 @@ void ldlm_pool_set_clv(struct ldlm_pool *pl, __u64 clv)
        pl->pl_client_lock_volume = clv;
        spin_unlock(&pl->pl_lock);
 }
-EXPORT_SYMBOL(ldlm_pool_set_clv);
-
-/**
- * Returns current \a pl limit.
- */
-__u32 ldlm_pool_get_limit(struct ldlm_pool *pl)
-{
-       return atomic_read(&pl->pl_limit);
-}
-EXPORT_SYMBOL(ldlm_pool_get_limit);
-
-/**
- * Sets passed \a limit to \a pl.
- */
-void ldlm_pool_set_limit(struct ldlm_pool *pl, __u32 limit)
-{
-       atomic_set(&pl->pl_limit, limit);
-}
-EXPORT_SYMBOL(ldlm_pool_set_limit);
 
 /**
  * Returns current LVF from \a pl.
@@ -1076,7 +797,6 @@ __u32 ldlm_pool_get_lvf(struct ldlm_pool *pl)
 {
        return atomic_read(&pl->pl_lock_volume_factor);
 }
-EXPORT_SYMBOL(ldlm_pool_get_lvf);
 
 static int ldlm_pool_granted(struct ldlm_pool *pl)
 {
@@ -1189,20 +909,7 @@ static unsigned long ldlm_pools_scan(ldlm_side_t client, int nr, gfp_t gfp_mask)
         * we only decrease the SLV in server pools shrinker, return
         * SHRINK_STOP to kernel to avoid needless loop. LU-1128
         */
-       return (client == LDLM_NAMESPACE_SERVER) ? SHRINK_STOP : freed;
-}
-
-static unsigned long ldlm_pools_srv_count(struct shrinker *s,
-                                         struct shrink_control *sc)
-{
-       return ldlm_pools_count(LDLM_NAMESPACE_SERVER, sc->gfp_mask);
-}
-
-static unsigned long ldlm_pools_srv_scan(struct shrinker *s,
-                                        struct shrink_control *sc)
-{
-       return ldlm_pools_scan(LDLM_NAMESPACE_SERVER, sc->nr_to_scan,
-                              sc->gfp_mask);
+       return freed;
 }
 
 static unsigned long ldlm_pools_cli_count(struct shrinker *s,
@@ -1218,81 +925,13 @@ static unsigned long ldlm_pools_cli_scan(struct shrinker *s,
                               sc->gfp_mask);
 }
 
-int ldlm_pools_recalc(ldlm_side_t client)
+static int ldlm_pools_recalc(ldlm_side_t client)
 {
-       __u32 nr_l = 0, nr_p = 0, l;
        struct ldlm_namespace *ns;
        struct ldlm_namespace *ns_old = NULL;
-       int nr, equal = 0;
+       int nr;
        int time = 50; /* seconds of sleep if no active namespaces */
 
-       /*
-        * No need to setup pool limit for client pools.
-        */
-       if (client == LDLM_NAMESPACE_SERVER) {
-               /*
-                * Check all modest namespaces first.
-                */
-               mutex_lock(ldlm_namespace_lock(client));
-               list_for_each_entry(ns, ldlm_namespace_list(client),
-                                       ns_list_chain) {
-                       if (ns->ns_appetite != LDLM_NAMESPACE_MODEST)
-                               continue;
-
-                       l = ldlm_pool_granted(&ns->ns_pool);
-                       if (l == 0)
-                               l = 1;
-
-                       /*
-                        * Set the modest pools limit equal to their avg granted
-                        * locks + ~6%.
-                        */
-                       l += dru(l, LDLM_POOLS_MODEST_MARGIN_SHIFT, 0);
-                       ldlm_pool_setup(&ns->ns_pool, l);
-                       nr_l += l;
-                       nr_p++;
-               }
-
-               /*
-                * Make sure that modest namespaces did not eat more that 2/3
-                * of limit.
-                */
-               if (nr_l >= 2 * (LDLM_POOL_HOST_L / 3)) {
-                       CWARN("\"Modest\" pools eat out 2/3 of server locks limit (%d of %lu). This means that you have too many clients for this amount of server RAM. Upgrade server!\n",
-                             nr_l, LDLM_POOL_HOST_L);
-                       equal = 1;
-               }
-
-               /*
-                * The rest is given to greedy namespaces.
-                */
-               list_for_each_entry(ns, ldlm_namespace_list(client),
-                                   ns_list_chain) {
-                       if (!equal && ns->ns_appetite != LDLM_NAMESPACE_GREEDY)
-                               continue;
-
-                       if (equal) {
-                               /*
-                                * In the case 2/3 locks are eaten out by
-                                * modest pools, we re-setup equal limit
-                                * for _all_ pools.
-                                */
-                               l = LDLM_POOL_HOST_L /
-                                       ldlm_namespace_nr_read(client);
-                       } else {
-                               /*
-                                * All the rest of greedy pools will have
-                                * all locks in equal parts.
-                                */
-                               l = (LDLM_POOL_HOST_L - nr_l) /
-                                       (ldlm_namespace_nr_read(client) -
-                                        nr_p);
-                       }
-                       ldlm_pool_setup(&ns->ns_pool, l);
-               }
-               mutex_unlock(ldlm_namespace_lock(client));
-       }
-
        /*
         * Recalc at least ldlm_namespace_nr_read(client) namespaces.
         */
@@ -1366,12 +1005,11 @@ int ldlm_pools_recalc(ldlm_side_t client)
        }
        return time;
 }
-EXPORT_SYMBOL(ldlm_pools_recalc);
 
 static int ldlm_pools_thread_main(void *arg)
 {
        struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
-       int s_time, c_time;
+       int c_time;
 
        thread_set_flags(thread, SVC_RUNNING);
        wake_up(&thread->t_ctl_waitq);
@@ -1385,14 +1023,13 @@ static int ldlm_pools_thread_main(void *arg)
                /*
                 * Recal all pools on this tick.
                 */
-               s_time = ldlm_pools_recalc(LDLM_NAMESPACE_SERVER);
                c_time = ldlm_pools_recalc(LDLM_NAMESPACE_CLIENT);
 
                /*
                 * Wait until the next check time, or until we're
                 * stopped.
                 */
-               lwi = LWI_TIMEOUT(cfs_time_seconds(min(s_time, c_time)),
+               lwi = LWI_TIMEOUT(cfs_time_seconds(c_time),
                                  NULL, NULL);
                l_wait_event(thread->t_ctl_waitq,
                             thread_is_stopping(thread) ||
@@ -1459,12 +1096,6 @@ static void ldlm_pools_thread_stop(void)
        ldlm_pools_thread = NULL;
 }
 
-static struct shrinker ldlm_pools_srv_shrinker = {
-       .count_objects  = ldlm_pools_srv_count,
-       .scan_objects   = ldlm_pools_srv_scan,
-       .seeks          = DEFAULT_SEEKS,
-};
-
 static struct shrinker ldlm_pools_cli_shrinker = {
        .count_objects  = ldlm_pools_cli_count,
        .scan_objects   = ldlm_pools_cli_scan,
@@ -1476,20 +1107,18 @@ int ldlm_pools_init(void)
        int rc;
 
        rc = ldlm_pools_thread_start();
-       if (rc == 0) {
-               register_shrinker(&ldlm_pools_srv_shrinker);
+       if (rc == 0)
                register_shrinker(&ldlm_pools_cli_shrinker);
-       }
+
        return rc;
 }
 EXPORT_SYMBOL(ldlm_pools_init);
 
 void ldlm_pools_fini(void)
 {
-       if (ldlm_pools_thread) {
-               unregister_shrinker(&ldlm_pools_srv_shrinker);
+       if (ldlm_pools_thread)
                unregister_shrinker(&ldlm_pools_cli_shrinker);
-       }
+
        ldlm_pools_thread_stop();
 }
 EXPORT_SYMBOL(ldlm_pools_fini);
index 6245a2c36a0f6e3a34732b4d5b6a485c2c066534..fdf81b87aad7b29e90faedee95070a1fd4fdd93f 100644 (file)
@@ -87,7 +87,7 @@ struct ldlm_async_args {
        struct lustre_handle lock_handle;
 };
 
-int ldlm_expired_completion_wait(void *data)
+static int ldlm_expired_completion_wait(void *data)
 {
        struct lock_wait_data *lwd = data;
        struct ldlm_lock *lock = lwd->lwd_lock;
@@ -97,15 +97,14 @@ int ldlm_expired_completion_wait(void *data)
        if (lock->l_conn_export == NULL) {
                static unsigned long next_dump, last_dump;
 
-               LCONSOLE_WARN("lock timed out (enqueued at "CFS_TIME_T", "
-                             CFS_DURATION_T"s ago)\n",
-                             lock->l_last_activity,
-                             cfs_time_sub(get_seconds(),
-                                          lock->l_last_activity));
-               LDLM_DEBUG(lock, "lock timed out (enqueued at " CFS_TIME_T ", " CFS_DURATION_T "s ago); not entering recovery in server code, just going back to sleep",
-                          lock->l_last_activity,
-                          cfs_time_sub(get_seconds(),
-                                       lock->l_last_activity));
+               LCONSOLE_WARN("lock timed out (enqueued at %lld, %llds ago)\n",
+                             (s64)lock->l_last_activity,
+                             (s64)(ktime_get_real_seconds() -
+                                   lock->l_last_activity));
+               LDLM_DEBUG(lock, "lock timed out (enqueued at %lld, %llds ago); not entering recovery in server code, just going back to sleep",
+                          (s64)lock->l_last_activity,
+                          (s64)(ktime_get_real_seconds() -
+                                lock->l_last_activity));
                if (cfs_time_after(cfs_time_current(), next_dump)) {
                        last_dump = next_dump;
                        next_dump = cfs_time_shift(300);
@@ -120,19 +119,17 @@ int ldlm_expired_completion_wait(void *data)
        obd = lock->l_conn_export->exp_obd;
        imp = obd->u.cli.cl_import;
        ptlrpc_fail_import(imp, lwd->lwd_conn_cnt);
-       LDLM_ERROR(lock, "lock timed out (enqueued at "CFS_TIME_T", "
-                 CFS_DURATION_T"s ago), entering recovery for %s@%s",
-                 lock->l_last_activity,
-                 cfs_time_sub(get_seconds(), lock->l_last_activity),
-                 obd2cli_tgt(obd), imp->imp_connection->c_remote_uuid.uuid);
+       LDLM_ERROR(lock, "lock timed out (enqueued at %lld, %llds ago), entering recovery for %s@%s",
+                  (s64)lock->l_last_activity,
+                  (s64)(ktime_get_real_seconds() - lock->l_last_activity),
+                  obd2cli_tgt(obd), imp->imp_connection->c_remote_uuid.uuid);
 
        return 0;
 }
-EXPORT_SYMBOL(ldlm_expired_completion_wait);
 
 /* We use the same basis for both server side and client side functions
    from a single node. */
-int ldlm_get_enq_timeout(struct ldlm_lock *lock)
+static int ldlm_get_enq_timeout(struct ldlm_lock *lock)
 {
        int timeout = at_get(ldlm_lock_to_ns_at(lock));
 
@@ -144,7 +141,6 @@ int ldlm_get_enq_timeout(struct ldlm_lock *lock)
        timeout = min_t(int, at_max, timeout + (timeout >> 1)); /* 150% */
        return max(timeout, ldlm_enqueue_min);
 }
-EXPORT_SYMBOL(ldlm_get_enq_timeout);
 
 /**
  * Helper function for ldlm_completion_ast(), updating timings when lock is
@@ -159,10 +155,9 @@ static int ldlm_completion_tail(struct ldlm_lock *lock)
                LDLM_DEBUG(lock, "client-side enqueue: destroyed");
                result = -EIO;
        } else {
-               delay = cfs_time_sub(get_seconds(),
-                                    lock->l_last_activity);
-               LDLM_DEBUG(lock, "client-side enqueue: granted after "
-                          CFS_DURATION_T"s", delay);
+               delay = ktime_get_real_seconds() - lock->l_last_activity;
+               LDLM_DEBUG(lock, "client-side enqueue: granted after %lds",
+                          delay);
 
                /* Update our time estimate */
                at_measured(ldlm_lock_to_ns_at(lock),
@@ -191,7 +186,6 @@ int ldlm_completion_ast_async(struct ldlm_lock *lock, __u64 flags, void *data)
        }
 
        LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, going forward");
-       ldlm_reprocess_all(lock->l_resource);
        return 0;
 }
 EXPORT_SYMBOL(ldlm_completion_ast_async);
@@ -270,8 +264,7 @@ noreproc:
                spin_unlock(&imp->imp_lock);
        }
 
-       if (ns_is_client(ldlm_lock_to_ns(lock)) &&
-           OBD_FAIL_CHECK_RESET(OBD_FAIL_LDLM_INTR_CP_AST,
+       if (OBD_FAIL_CHECK_RESET(OBD_FAIL_LDLM_INTR_CP_AST,
                                 OBD_FAIL_LDLM_CP_BL_RACE | OBD_FAIL_ONCE)) {
                lock->l_flags |= LDLM_FL_FAIL_LOC;
                rc = -EINTR;
@@ -291,172 +284,6 @@ noreproc:
 }
 EXPORT_SYMBOL(ldlm_completion_ast);
 
-/**
- * A helper to build a blocking AST function
- *
- * Perform a common operation for blocking ASTs:
- * deferred lock cancellation.
- *
- * \param lock the lock blocking or canceling AST was called on
- * \retval 0
- * \see mdt_blocking_ast
- * \see ldlm_blocking_ast
- */
-int ldlm_blocking_ast_nocheck(struct ldlm_lock *lock)
-{
-       int do_ast;
-
-       lock->l_flags |= LDLM_FL_CBPENDING;
-       do_ast = !lock->l_readers && !lock->l_writers;
-       unlock_res_and_lock(lock);
-
-       if (do_ast) {
-               struct lustre_handle lockh;
-               int rc;
-
-               LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
-               ldlm_lock2handle(lock, &lockh);
-               rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
-               if (rc < 0)
-                       CERROR("ldlm_cli_cancel: %d\n", rc);
-       } else {
-               LDLM_DEBUG(lock, "Lock still has references, will be cancelled later");
-       }
-       return 0;
-}
-EXPORT_SYMBOL(ldlm_blocking_ast_nocheck);
-
-/**
- * Server blocking AST
- *
- * ->l_blocking_ast() callback for LDLM locks acquired by server-side
- * OBDs.
- *
- * \param lock the lock which blocks a request or cancelling lock
- * \param desc unused
- * \param data unused
- * \param flag indicates whether this cancelling or blocking callback
- * \retval 0
- * \see ldlm_blocking_ast_nocheck
- */
-int ldlm_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
-                     void *data, int flag)
-{
-       if (flag == LDLM_CB_CANCELING) {
-               /* Don't need to do anything here. */
-               return 0;
-       }
-
-       lock_res_and_lock(lock);
-       /* Get this: if ldlm_blocking_ast is racing with intent_policy, such
-        * that ldlm_blocking_ast is called just before intent_policy method
-        * takes the lr_lock, then by the time we get the lock, we might not
-        * be the correct blocking function anymore.  So check, and return
-        * early, if so. */
-       if (lock->l_blocking_ast != ldlm_blocking_ast) {
-               unlock_res_and_lock(lock);
-               return 0;
-       }
-       return ldlm_blocking_ast_nocheck(lock);
-}
-EXPORT_SYMBOL(ldlm_blocking_ast);
-
-/**
- * ->l_glimpse_ast() for DLM extent locks acquired on the server-side. See
- * comment in filter_intent_policy() on why you may need this.
- */
-int ldlm_glimpse_ast(struct ldlm_lock *lock, void *reqp)
-{
-       /*
-        * Returning -ELDLM_NO_LOCK_DATA actually works, but the reason for
-        * that is rather subtle: with OST-side locking, it may so happen that
-        * _all_ extent locks are held by the OST. If client wants to obtain
-        * current file size it calls ll{,u}_glimpse_size(), and (as locks are
-        * on the server), dummy glimpse callback fires and does
-        * nothing. Client still receives correct file size due to the
-        * following fragment in filter_intent_policy():
-        *
-        * rc = l->l_glimpse_ast(l, NULL); // this will update the LVB
-        * if (rc != 0 && res->lr_namespace->ns_lvbo &&
-        *     res->lr_namespace->ns_lvbo->lvbo_update) {
-        *       res->lr_namespace->ns_lvbo->lvbo_update(res, NULL, 0, 1);
-        * }
-        *
-        * that is, after glimpse_ast() fails, filter_lvbo_update() runs, and
-        * returns correct file size to the client.
-        */
-       return -ELDLM_NO_LOCK_DATA;
-}
-EXPORT_SYMBOL(ldlm_glimpse_ast);
-
-/**
- * Enqueue a local lock (typically on a server).
- */
-int ldlm_cli_enqueue_local(struct ldlm_namespace *ns,
-                          const struct ldlm_res_id *res_id,
-                          ldlm_type_t type, ldlm_policy_data_t *policy,
-                          ldlm_mode_t mode, __u64 *flags,
-                          ldlm_blocking_callback blocking,
-                          ldlm_completion_callback completion,
-                          ldlm_glimpse_callback glimpse,
-                          void *data, __u32 lvb_len, enum lvb_type lvb_type,
-                          const __u64 *client_cookie,
-                          struct lustre_handle *lockh)
-{
-       struct ldlm_lock *lock;
-       int err;
-       const struct ldlm_callback_suite cbs = { .lcs_completion = completion,
-                                                .lcs_blocking   = blocking,
-                                                .lcs_glimpse    = glimpse,
-       };
-
-       LASSERT(!(*flags & LDLM_FL_REPLAY));
-       if (unlikely(ns_is_client(ns))) {
-               CERROR("Trying to enqueue local lock in a shadow namespace\n");
-               LBUG();
-       }
-
-       lock = ldlm_lock_create(ns, res_id, type, mode, &cbs, data, lvb_len,
-                               lvb_type);
-       if (unlikely(!lock)) {
-               err = -ENOMEM;
-               goto out_nolock;
-       }
-
-       ldlm_lock2handle(lock, lockh);
-
-       /* NB: we don't have any lock now (lock_res_and_lock)
-        * because it's a new lock */
-       ldlm_lock_addref_internal_nolock(lock, mode);
-       lock->l_flags |= LDLM_FL_LOCAL;
-       if (*flags & LDLM_FL_ATOMIC_CB)
-               lock->l_flags |= LDLM_FL_ATOMIC_CB;
-
-       if (policy != NULL)
-               lock->l_policy_data = *policy;
-       if (client_cookie != NULL)
-               lock->l_client_cookie = *client_cookie;
-       if (type == LDLM_EXTENT)
-               lock->l_req_extent = policy->l_extent;
-
-       err = ldlm_lock_enqueue(ns, &lock, policy, flags);
-       if (unlikely(err != ELDLM_OK))
-               goto out;
-
-       if (policy != NULL)
-               *policy = lock->l_policy_data;
-
-       if (lock->l_completion_ast)
-               lock->l_completion_ast(lock, *flags, NULL);
-
-       LDLM_DEBUG(lock, "client-side local enqueue handler, new lock created");
- out:
-       LDLM_LOCK_RELEASE(lock);
- out_nolock:
-       return err;
-}
-EXPORT_SYMBOL(ldlm_cli_enqueue_local);
-
 static void failed_lock_cleanup(struct ldlm_namespace *ns,
                                struct ldlm_lock *lock, int mode)
 {
@@ -813,27 +640,6 @@ int ldlm_prep_enqueue_req(struct obd_export *exp, struct ptlrpc_request *req,
 }
 EXPORT_SYMBOL(ldlm_prep_enqueue_req);
 
-struct ptlrpc_request *ldlm_enqueue_pack(struct obd_export *exp, int lvb_len)
-{
-       struct ptlrpc_request *req;
-       int rc;
-
-       req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_LDLM_ENQUEUE);
-       if (req == NULL)
-               return ERR_PTR(-ENOMEM);
-
-       rc = ldlm_prep_enqueue_req(exp, req, NULL, 0);
-       if (rc) {
-               ptlrpc_request_free(req);
-               return ERR_PTR(rc);
-       }
-
-       req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER, lvb_len);
-       ptlrpc_request_set_replen(req);
-       return req;
-}
-EXPORT_SYMBOL(ldlm_enqueue_pack);
-
 /**
  * Client-side lock enqueue.
  *
@@ -977,107 +783,6 @@ int ldlm_cli_enqueue(struct obd_export *exp, struct ptlrpc_request **reqp,
 }
 EXPORT_SYMBOL(ldlm_cli_enqueue);
 
-static int ldlm_cli_convert_local(struct ldlm_lock *lock, int new_mode,
-                                 __u32 *flags)
-{
-       struct ldlm_resource *res;
-       int rc;
-
-       if (ns_is_client(ldlm_lock_to_ns(lock))) {
-               CERROR("Trying to cancel local lock\n");
-               LBUG();
-       }
-       LDLM_DEBUG(lock, "client-side local convert");
-
-       res = ldlm_lock_convert(lock, new_mode, flags);
-       if (res) {
-               ldlm_reprocess_all(res);
-               rc = 0;
-       } else {
-               rc = LUSTRE_EDEADLK;
-       }
-       LDLM_DEBUG(lock, "client-side local convert handler END");
-       LDLM_LOCK_PUT(lock);
-       return rc;
-}
-
-/* FIXME: one of ldlm_cli_convert or the server side should reject attempted
- * conversion of locks which are on the waiting or converting queue */
-/* Caller of this code is supposed to take care of lock readers/writers
-   accounting */
-int ldlm_cli_convert(struct lustre_handle *lockh, int new_mode, __u32 *flags)
-{
-       struct ldlm_request   *body;
-       struct ldlm_reply     *reply;
-       struct ldlm_lock      *lock;
-       struct ldlm_resource  *res;
-       struct ptlrpc_request *req;
-       int                 rc;
-
-       lock = ldlm_handle2lock(lockh);
-       if (!lock) {
-               LBUG();
-               return -EINVAL;
-       }
-       *flags = 0;
-
-       if (lock->l_conn_export == NULL)
-               return ldlm_cli_convert_local(lock, new_mode, flags);
-
-       LDLM_DEBUG(lock, "client-side convert");
-
-       req = ptlrpc_request_alloc_pack(class_exp2cliimp(lock->l_conn_export),
-                                       &RQF_LDLM_CONVERT, LUSTRE_DLM_VERSION,
-                                       LDLM_CONVERT);
-       if (req == NULL) {
-               LDLM_LOCK_PUT(lock);
-               return -ENOMEM;
-       }
-
-       body = req_capsule_client_get(&req->rq_pill, &RMF_DLM_REQ);
-       body->lock_handle[0] = lock->l_remote_handle;
-
-       body->lock_desc.l_req_mode = new_mode;
-       body->lock_flags = ldlm_flags_to_wire(*flags);
-
-
-       ptlrpc_request_set_replen(req);
-       rc = ptlrpc_queue_wait(req);
-       if (rc != ELDLM_OK)
-               goto out;
-
-       reply = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
-       if (reply == NULL) {
-               rc = -EPROTO;
-               goto out;
-       }
-
-       if (req->rq_status) {
-               rc = req->rq_status;
-               goto out;
-       }
-
-       res = ldlm_lock_convert(lock, new_mode, &reply->lock_flags);
-       if (res != NULL) {
-               ldlm_reprocess_all(res);
-               /* Go to sleep until the lock is granted. */
-               /* FIXME: or cancelled. */
-               if (lock->l_completion_ast) {
-                       rc = lock->l_completion_ast(lock, LDLM_FL_WAIT_NOREPROC,
-                                                   NULL);
-                       if (rc)
-                               goto out;
-               }
-       } else {
-               rc = LUSTRE_EDEADLK;
-       }
- out:
-       LDLM_LOCK_PUT(lock);
-       ptlrpc_req_finished(req);
-       return rc;
-}
-EXPORT_SYMBOL(ldlm_cli_convert);
-
 /**
  * Cancel locks locally.
  * Returns:
@@ -1109,13 +814,8 @@ static __u64 ldlm_cli_cancel_local(struct ldlm_lock *lock)
                }
                ldlm_lock_cancel(lock);
        } else {
-               if (ns_is_client(ldlm_lock_to_ns(lock))) {
-                       LDLM_ERROR(lock, "Trying to cancel local lock");
-                       LBUG();
-               }
-               LDLM_DEBUG(lock, "server-side local cancel");
-               ldlm_lock_cancel(lock);
-               ldlm_reprocess_all(lock->l_resource);
+               LDLM_ERROR(lock, "Trying to cancel local lock");
+               LBUG();
        }
 
        return rc;
@@ -1159,8 +859,9 @@ static void ldlm_cancel_pack(struct ptlrpc_request *req,
 /**
  * Prepare and send a batched cancel RPC. It will include \a count lock
  * handles of locks given in \a cancels list. */
-int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *cancels,
-                       int count, ldlm_cancel_flags_t flags)
+static int ldlm_cli_cancel_req(struct obd_export *exp,
+                              struct list_head *cancels,
+                              int count, ldlm_cancel_flags_t flags)
 {
        struct ptlrpc_request *req = NULL;
        struct obd_import *imp;
@@ -1212,12 +913,12 @@ int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *cancels,
 
                ptlrpc_request_set_replen(req);
                if (flags & LCF_ASYNC) {
-                       ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
+                       ptlrpcd_add_req(req);
                        sent = count;
                        goto out;
-               } else {
-                       rc = ptlrpc_queue_wait(req);
                }
+
+               rc = ptlrpc_queue_wait(req);
                if (rc == LUSTRE_ESTALE) {
                        CDEBUG(D_DLMTRACE, "client/server (nid %s) out of sync -- not fatal\n",
                               libcfs_nid2str(req->rq_import->
@@ -1242,7 +943,6 @@ int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *cancels,
 out:
        return sent ? sent : rc;
 }
-EXPORT_SYMBOL(ldlm_cli_cancel_req);
 
 static inline struct ldlm_pool *ldlm_imp2pl(struct obd_import *imp)
 {
@@ -1723,9 +1423,9 @@ static int ldlm_prepare_lru_list(struct ldlm_namespace *ns,
        return added;
 }
 
-int ldlm_cancel_lru_local(struct ldlm_namespace *ns, struct list_head *cancels,
-                         int count, int max, ldlm_cancel_flags_t cancel_flags,
-                         int flags)
+int ldlm_cancel_lru_local(struct ldlm_namespace *ns,
+                         struct list_head *cancels, int count, int max,
+                         ldlm_cancel_flags_t cancel_flags, int flags)
 {
        int added;
 
@@ -1962,8 +1662,8 @@ EXPORT_SYMBOL(ldlm_cli_cancel_unused);
 
 /* Lock iterators. */
 
-int ldlm_resource_foreach(struct ldlm_resource *res, ldlm_iterator_t iter,
-                         void *closure)
+static int ldlm_resource_foreach(struct ldlm_resource *res,
+                                ldlm_iterator_t iter, void *closure)
 {
        struct list_head *tmp, *next;
        struct ldlm_lock *lock;
@@ -1982,15 +1682,6 @@ int ldlm_resource_foreach(struct ldlm_resource *res, ldlm_iterator_t iter,
                }
        }
 
-       list_for_each_safe(tmp, next, &res->lr_converting) {
-               lock = list_entry(tmp, struct ldlm_lock, l_res_link);
-
-               if (iter(lock, closure) == LDLM_ITER_STOP) {
-                       rc = LDLM_ITER_STOP;
-                       goto out;
-               }
-       }
-
        list_for_each_safe(tmp, next, &res->lr_waiting) {
                lock = list_entry(tmp, struct ldlm_lock, l_res_link);
 
@@ -2003,7 +1694,6 @@ int ldlm_resource_foreach(struct ldlm_resource *res, ldlm_iterator_t iter,
        unlock_res(res);
        return rc;
 }
-EXPORT_SYMBOL(ldlm_resource_foreach);
 
 struct iter_helper_data {
        ldlm_iterator_t iter;
@@ -2027,8 +1717,8 @@ static int ldlm_res_iter_helper(struct cfs_hash *hs, struct cfs_hash_bd *bd,
               LDLM_ITER_STOP;
 }
 
-void ldlm_namespace_foreach(struct ldlm_namespace *ns,
-                           ldlm_iterator_t iter, void *closure)
+static void ldlm_namespace_foreach(struct ldlm_namespace *ns,
+                                  ldlm_iterator_t iter, void *closure)
 
 {
        struct iter_helper_data helper = {
@@ -2040,7 +1730,6 @@ void ldlm_namespace_foreach(struct ldlm_namespace *ns,
                                 ldlm_res_iter_helper, &helper);
 
 }
-EXPORT_SYMBOL(ldlm_namespace_foreach);
 
 /* non-blocking function to manipulate a lock whose cb_data is being put away.
  * return  0:  find no resource
@@ -2106,7 +1795,6 @@ static int replay_lock_interpret(const struct lu_env *env,
        if (rc != ELDLM_OK)
                goto out;
 
-
        reply = req_capsule_server_get(&req->rq_pill, &RMF_DLM_REP);
        if (reply == NULL) {
                rc = -EPROTO;
@@ -2223,7 +1911,7 @@ static int replay_one_lock(struct obd_import *imp, struct ldlm_lock *lock)
        aa = ptlrpc_req_async_args(req);
        aa->lock_handle = body->lock_handle[0];
        req->rq_interpret_reply = (ptlrpc_interpterer_t)replay_lock_interpret;
-       ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
+       ptlrpcd_add_req(req);
 
        return 0;
 }
index 4bb3173bcd5f18d0c7d4467b0b330f59e892e401..c0a54bf406ca58b0dac23ac20e24ca6395822bfe 100644 (file)
@@ -47,8 +47,8 @@
 
 struct kmem_cache *ldlm_resource_slab, *ldlm_lock_slab;
 
-int ldlm_srv_namespace_nr = 0;
-int ldlm_cli_namespace_nr = 0;
+int ldlm_srv_namespace_nr;
+int ldlm_cli_namespace_nr;
 
 struct mutex ldlm_srv_namespace_lock;
 LIST_HEAD(ldlm_srv_namespace_list);
@@ -59,7 +59,7 @@ struct mutex ldlm_cli_namespace_lock;
  * inactive list */
 LIST_HEAD(ldlm_cli_active_namespace_list);
 /* Client namespaces that don't have any locks in them */
-LIST_HEAD(ldlm_cli_inactive_namespace_list);
+static LIST_HEAD(ldlm_cli_inactive_namespace_list);
 
 static struct dentry *ldlm_debugfs_dir;
 static struct dentry *ldlm_ns_debugfs_dir;
@@ -67,7 +67,7 @@ struct dentry *ldlm_svc_debugfs_dir;
 
 /* during debug dump certain amount of granted locks for one resource to avoid
  * DDOS. */
-unsigned int ldlm_dump_granted_max = 256;
+static unsigned int ldlm_dump_granted_max = 256;
 
 static ssize_t
 lprocfs_wr_dump_ns(struct file *file, const char __user *buffer,
@@ -77,6 +77,7 @@ lprocfs_wr_dump_ns(struct file *file, const char __user *buffer,
        ldlm_dump_all_namespaces(LDLM_NAMESPACE_CLIENT, D_DLMTRACE);
        return count;
 }
+
 LPROC_SEQ_FOPS_WR_ONLY(ldlm, dump_ns);
 
 LPROC_SEQ_FOPS_RW_TYPE(ldlm_rw, uint);
@@ -383,13 +384,13 @@ static void ldlm_namespace_debugfs_unregister(struct ldlm_namespace *ns)
                lprocfs_free_stats(&ns->ns_stats);
 }
 
-void ldlm_namespace_sysfs_unregister(struct ldlm_namespace *ns)
+static void ldlm_namespace_sysfs_unregister(struct ldlm_namespace *ns)
 {
        kobject_put(&ns->ns_kobj);
        wait_for_completion(&ns->ns_kobj_unregister);
 }
 
-int ldlm_namespace_sysfs_register(struct ldlm_namespace *ns)
+static int ldlm_namespace_sysfs_register(struct ldlm_namespace *ns)
 {
        int err;
 
@@ -426,8 +427,19 @@ static int ldlm_namespace_debugfs_register(struct ldlm_namespace *ns)
 
        return 0;
 }
+
 #undef MAX_STRING_SIZE
 
+static struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
+{
+       LASSERT(res);
+       LASSERT(res != LP_POISON);
+       atomic_inc(&res->lr_refcount);
+       CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
+              atomic_read(&res->lr_refcount));
+       return res;
+}
+
 static unsigned ldlm_res_hop_hash(struct cfs_hash *hs,
                                  const void *key, unsigned mask)
 {
@@ -519,26 +531,26 @@ static void ldlm_res_hop_put(struct cfs_hash *hs, struct hlist_node *hnode)
        ldlm_resource_putref(res);
 }
 
-cfs_hash_ops_t ldlm_ns_hash_ops = {
+static struct cfs_hash_ops ldlm_ns_hash_ops = {
        .hs_hash        = ldlm_res_hop_hash,
-       .hs_key  = ldlm_res_hop_key,
+       .hs_key         = ldlm_res_hop_key,
        .hs_keycmp      = ldlm_res_hop_keycmp,
        .hs_keycpy      = NULL,
        .hs_object      = ldlm_res_hop_object,
-       .hs_get  = ldlm_res_hop_get_locked,
+       .hs_get         = ldlm_res_hop_get_locked,
        .hs_put_locked  = ldlm_res_hop_put_locked,
-       .hs_put  = ldlm_res_hop_put
+       .hs_put         = ldlm_res_hop_put
 };
 
-cfs_hash_ops_t ldlm_ns_fid_hash_ops = {
+static struct cfs_hash_ops ldlm_ns_fid_hash_ops = {
        .hs_hash        = ldlm_res_hop_fid_hash,
-       .hs_key  = ldlm_res_hop_key,
+       .hs_key         = ldlm_res_hop_key,
        .hs_keycmp      = ldlm_res_hop_keycmp,
        .hs_keycpy      = NULL,
        .hs_object      = ldlm_res_hop_object,
-       .hs_get  = ldlm_res_hop_get_locked,
+       .hs_get         = ldlm_res_hop_get_locked,
        .hs_put_locked  = ldlm_res_hop_put_locked,
-       .hs_put  = ldlm_res_hop_put
+       .hs_put         = ldlm_res_hop_put
 };
 
 struct ldlm_ns_hash_def {
@@ -548,10 +560,10 @@ struct ldlm_ns_hash_def {
        /** hash bits */
        unsigned        nsd_all_bits;
        /** hash operations */
-       cfs_hash_ops_t *nsd_hops;
+       struct cfs_hash_ops *nsd_hops;
 };
 
-struct ldlm_ns_hash_def ldlm_ns_hash_defs[] = {
+static struct ldlm_ns_hash_def ldlm_ns_hash_defs[] = {
        {
                .nsd_type       = LDLM_NS_TYPE_MDC,
                .nsd_bkt_bits   = 11,
@@ -593,6 +605,17 @@ struct ldlm_ns_hash_def ldlm_ns_hash_defs[] = {
        },
 };
 
+/** Register \a ns in the list of namespaces */
+static void ldlm_namespace_register(struct ldlm_namespace *ns,
+                                   ldlm_side_t client)
+{
+       mutex_lock(ldlm_namespace_lock(client));
+       LASSERT(list_empty(&ns->ns_list_chain));
+       list_add(&ns->ns_list_chain, &ldlm_cli_inactive_namespace_list);
+       ldlm_namespace_nr_inc(client);
+       mutex_unlock(ldlm_namespace_lock(client));
+}
+
 /**
  * Create and initialize new empty namespace.
  */
@@ -718,11 +741,12 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
                             __u64 flags)
 {
        struct list_head *tmp;
-       int rc = 0, client = ns_is_client(ldlm_res_to_ns(res));
+       int rc = 0;
        bool local_only = !!(flags & LDLM_FL_LOCAL_ONLY);
 
        do {
                struct ldlm_lock *lock = NULL;
+               struct lustre_handle lockh;
 
                /* First, we look for non-cleaned-yet lock
                 * all cleaned locks are marked by CLEANED flag. */
@@ -767,20 +791,11 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
                        continue;
                }
 
-               if (client) {
-                       struct lustre_handle lockh;
-
-                       unlock_res(res);
-                       ldlm_lock2handle(lock, &lockh);
-                       rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
-                       if (rc)
-                               CERROR("ldlm_cli_cancel: %d\n", rc);
-               } else {
-                       ldlm_resource_unlink_lock(lock);
-                       unlock_res(res);
-                       LDLM_DEBUG(lock, "Freeing a lock still held by a client node");
-                       ldlm_lock_destroy(lock);
-               }
+               unlock_res(res);
+               ldlm_lock2handle(lock, &lockh);
+               rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
+               if (rc)
+                       CERROR("ldlm_cli_cancel: %d\n", rc);
                LDLM_LOCK_RELEASE(lock);
        } while (1);
 }
@@ -792,7 +807,6 @@ static int ldlm_resource_clean(struct cfs_hash *hs, struct cfs_hash_bd *bd,
        __u64 flags = *(__u64 *)arg;
 
        cleanup_resource(res, &res->lr_granted, flags);
-       cleanup_resource(res, &res->lr_converting, flags);
        cleanup_resource(res, &res->lr_waiting, flags);
 
        return 0;
@@ -921,6 +935,20 @@ void ldlm_namespace_free_prior(struct ldlm_namespace *ns,
        }
 }
 
+/** Unregister \a ns from the list of namespaces. */
+static void ldlm_namespace_unregister(struct ldlm_namespace *ns,
+                                     ldlm_side_t client)
+{
+       mutex_lock(ldlm_namespace_lock(client));
+       LASSERT(!list_empty(&ns->ns_list_chain));
+       /* Some asserts and possibly other parts of the code are still
+        * using list_empty(&ns->ns_list_chain). This is why it is
+        * important to use list_del_init() here. */
+       list_del_init(&ns->ns_list_chain);
+       ldlm_namespace_nr_dec(client);
+       mutex_unlock(ldlm_namespace_lock(client));
+}
+
 /**
  * Performs freeing memory structures related to \a ns. This is only done
  * when ldlm_namespce_free_prior() successfully removed all resources
@@ -949,33 +977,6 @@ void ldlm_namespace_free_post(struct ldlm_namespace *ns)
        ldlm_put_ref();
 }
 
-/**
- * Cleanup the resource, and free namespace.
- * bug 12864:
- * Deadlock issue:
- * proc1: destroy import
- *     class_disconnect_export(grab cl_sem) ->
- *           -> ldlm_namespace_free ->
- *           -> ldebugfs_remove(grab _lprocfs_lock).
- * proc2: read proc info
- *     lprocfs_fops_read(grab _lprocfs_lock) ->
- *           -> osc_rd_active, etc(grab cl_sem).
- *
- * So that I have to split the ldlm_namespace_free into two parts - the first
- * part ldlm_namespace_free_prior is used to cleanup the resource which is
- * being used; the 2nd part ldlm_namespace_free_post is used to unregister the
- * lprocfs entries, and then free memory. It will be called w/o cli->cl_sem
- * held.
- */
-void ldlm_namespace_free(struct ldlm_namespace *ns,
-                        struct obd_import *imp,
-                        int force)
-{
-       ldlm_namespace_free_prior(ns, imp, force);
-       ldlm_namespace_free_post(ns);
-}
-EXPORT_SYMBOL(ldlm_namespace_free);
-
 void ldlm_namespace_get(struct ldlm_namespace *ns)
 {
        atomic_inc(&ns->ns_bref);
@@ -983,7 +984,7 @@ void ldlm_namespace_get(struct ldlm_namespace *ns)
 EXPORT_SYMBOL(ldlm_namespace_get);
 
 /* This is only for callers that care about refcount */
-int ldlm_namespace_get_return(struct ldlm_namespace *ns)
+static int ldlm_namespace_get_return(struct ldlm_namespace *ns)
 {
        return atomic_inc_return(&ns->ns_bref);
 }
@@ -997,29 +998,6 @@ void ldlm_namespace_put(struct ldlm_namespace *ns)
 }
 EXPORT_SYMBOL(ldlm_namespace_put);
 
-/** Register \a ns in the list of namespaces */
-void ldlm_namespace_register(struct ldlm_namespace *ns, ldlm_side_t client)
-{
-       mutex_lock(ldlm_namespace_lock(client));
-       LASSERT(list_empty(&ns->ns_list_chain));
-       list_add(&ns->ns_list_chain, ldlm_namespace_inactive_list(client));
-       ldlm_namespace_nr_inc(client);
-       mutex_unlock(ldlm_namespace_lock(client));
-}
-
-/** Unregister \a ns from the list of namespaces. */
-void ldlm_namespace_unregister(struct ldlm_namespace *ns, ldlm_side_t client)
-{
-       mutex_lock(ldlm_namespace_lock(client));
-       LASSERT(!list_empty(&ns->ns_list_chain));
-       /* Some asserts and possibly other parts of the code are still
-        * using list_empty(&ns->ns_list_chain). This is why it is
-        * important to use list_del_init() here. */
-       list_del_init(&ns->ns_list_chain);
-       ldlm_namespace_nr_dec(client);
-       mutex_unlock(ldlm_namespace_lock(client));
-}
-
 /** Should be called with ldlm_namespace_lock(client) taken. */
 void ldlm_namespace_move_to_active_locked(struct ldlm_namespace *ns,
                                          ldlm_side_t client)
@@ -1035,8 +1013,7 @@ void ldlm_namespace_move_to_inactive_locked(struct ldlm_namespace *ns,
 {
        LASSERT(!list_empty(&ns->ns_list_chain));
        LASSERT(mutex_is_locked(ldlm_namespace_lock(client)));
-       list_move_tail(&ns->ns_list_chain,
-                      ldlm_namespace_inactive_list(client));
+       list_move_tail(&ns->ns_list_chain, &ldlm_cli_inactive_namespace_list);
 }
 
 /** Should be called with ldlm_namespace_lock(client) taken. */
@@ -1054,12 +1031,11 @@ static struct ldlm_resource *ldlm_resource_new(void)
        struct ldlm_resource *res;
        int idx;
 
-       OBD_SLAB_ALLOC_PTR_GFP(res, ldlm_resource_slab, GFP_NOFS);
+       res = kmem_cache_alloc(ldlm_resource_slab, GFP_NOFS | __GFP_ZERO);
        if (res == NULL)
                return NULL;
 
        INIT_LIST_HEAD(&res->lr_granted);
-       INIT_LIST_HEAD(&res->lr_converting);
        INIT_LIST_HEAD(&res->lr_waiting);
 
        /* Initialize interval trees for each lock mode. */
@@ -1148,7 +1124,7 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
                lu_ref_fini(&res->lr_reference);
                /* We have taken lr_lvb_mutex. Drop it. */
                mutex_unlock(&res->lr_lvb_mutex);
-               OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof(*res));
+               kmem_cache_free(ldlm_resource_slab, res);
 
                res = hlist_entry(hnode, struct ldlm_resource, lr_hash);
                /* Synchronize with regard to resource creation. */
@@ -1194,7 +1170,7 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
         * namespace. If so, and this is a client namespace, we need to move
         * the namespace into the active namespaces list to be patrolled by
         * the ldlm_poold. */
-       if (ns_is_client(ns) && ns_refcount == 1) {
+       if (ns_refcount == 1) {
                mutex_lock(ldlm_namespace_lock(LDLM_NAMESPACE_CLIENT));
                ldlm_namespace_move_to_active_locked(ns, LDLM_NAMESPACE_CLIENT);
                mutex_unlock(ldlm_namespace_lock(LDLM_NAMESPACE_CLIENT));
@@ -1204,16 +1180,6 @@ ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
 }
 EXPORT_SYMBOL(ldlm_resource_get);
 
-struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
-{
-       LASSERT(res != NULL);
-       LASSERT(res != LP_POISON);
-       atomic_inc(&res->lr_refcount);
-       CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
-              atomic_read(&res->lr_refcount));
-       return res;
-}
-
 static void __ldlm_resource_putref_final(struct cfs_hash_bd *bd,
                                         struct ldlm_resource *res)
 {
@@ -1224,11 +1190,6 @@ static void __ldlm_resource_putref_final(struct cfs_hash_bd *bd,
                LBUG();
        }
 
-       if (!list_empty(&res->lr_converting)) {
-               ldlm_resource_dump(D_ERROR, res);
-               LBUG();
-       }
-
        if (!list_empty(&res->lr_waiting)) {
                ldlm_resource_dump(D_ERROR, res);
                LBUG();
@@ -1257,7 +1218,7 @@ int ldlm_resource_putref(struct ldlm_resource *res)
                cfs_hash_bd_unlock(ns->ns_rs_hash, &bd, 1);
                if (ns->ns_lvbo && ns->ns_lvbo->lvbo_free)
                        ns->ns_lvbo->lvbo_free(res);
-               OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof(*res));
+               kmem_cache_free(ldlm_resource_slab, res);
                return 1;
        }
        return 0;
@@ -1287,7 +1248,7 @@ int ldlm_resource_putref_locked(struct ldlm_resource *res)
                 */
                if (ns->ns_lvbo && ns->ns_lvbo->lvbo_free)
                        ns->ns_lvbo->lvbo_free(res);
-               OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof(*res));
+               kmem_cache_free(ldlm_resource_slab, res);
 
                cfs_hash_bd_lock(ns->ns_rs_hash, &bd, 1);
                return 1;
@@ -1315,32 +1276,6 @@ void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
        list_add_tail(&lock->l_res_link, head);
 }
 
-/**
- * Insert a lock into resource after specified lock.
- *
- * Obtain resource description from the lock we are inserting after.
- */
-void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
-                                    struct ldlm_lock *new)
-{
-       struct ldlm_resource *res = original->l_resource;
-
-       check_res_locked(res);
-
-       ldlm_resource_dump(D_INFO, res);
-       LDLM_DEBUG(new, "About to insert this lock after %p:\n", original);
-
-       if (new->l_flags & LDLM_FL_DESTROYED) {
-               CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
-               goto out;
-       }
-
-       LASSERT(list_empty(&new->l_res_link));
-
-       list_add(&new->l_res_link, &original->l_res_link);
- out:;
-}
-
 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
 {
        int type = lock->l_resource->lr_type;
@@ -1406,9 +1341,8 @@ void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
        if (!((libcfs_debug | D_ERROR) & level))
                return;
 
-       CDEBUG(level, "--- Namespace: %s (rc: %d, side: %s)\n",
-              ldlm_ns_name(ns), atomic_read(&ns->ns_bref),
-              ns_is_client(ns) ? "client" : "server");
+       CDEBUG(level, "--- Namespace: %s (rc: %d, side: client)\n",
+              ldlm_ns_name(ns), atomic_read(&ns->ns_bref));
 
        if (time_before(cfs_time_current(), ns->ns_next_dump))
                return;
@@ -1451,11 +1385,6 @@ void ldlm_resource_dump(int level, struct ldlm_resource *res)
                        }
                }
        }
-       if (!list_empty(&res->lr_converting)) {
-               CDEBUG(level, "Converting locks:\n");
-               list_for_each_entry(lock, &res->lr_converting, l_res_link)
-                       LDLM_DEBUG_LIMIT(level, lock, "###");
-       }
        if (!list_empty(&res->lr_waiting)) {
                CDEBUG(level, "Waiting locks:\n");
                list_for_each_entry(lock, &res->lr_waiting, l_res_link)
index ec98f44a10dd882d97183342206e100fac131ac8..03d3f3d7b1f815232d6284735cc3ca3561ff00d5 100644 (file)
@@ -10,7 +10,7 @@ libcfs-linux-objs += linux-mem.o
 
 libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
 
-libcfs-all-objs := debug.o fail.o nidstrings.o module.o tracefile.o \
+libcfs-all-objs := debug.o fail.o module.o tracefile.o \
                   libcfs_string.o hash.o kernel_user_comm.o \
                   prng.o workitem.o libcfs_cpu.o \
                   libcfs_mem.o libcfs_lock.o
index e93f556fac0dde68da054320fc320815c1025258..1d1c67164418f46324b3099a34a7d7c8c4fdd2f5 100644 (file)
@@ -452,8 +452,8 @@ void libcfs_debug_dumplog_internal(void *arg)
 
        if (strncmp(libcfs_debug_file_path_arr, "NONE", 4) != 0) {
                snprintf(debug_file_name, sizeof(debug_file_name) - 1,
-                        "%s.%ld.%ld", libcfs_debug_file_path_arr,
-                        get_seconds(), (long_ptr_t)arg);
+                        "%s.%lld.%ld", libcfs_debug_file_path_arr,
+                        (s64)ktime_get_real_seconds(), (long_ptr_t)arg);
                pr_alert("LustreError: dumping log to %s\n",
                       debug_file_name);
                cfs_tracefile_dump_all_pages(debug_file_name);
@@ -562,6 +562,7 @@ int libcfs_debug_mark_buffer(const char *text)
 
        return 0;
 }
+
 #undef DEBUG_SUBSYSTEM
 #define DEBUG_SUBSYSTEM S_LNET
 
index 42d615fbd664f9ba90552690dfd614a52ac2ea8d..d39fecebd12d0996713b8205dbe6fc7c85133df5 100644 (file)
 
 #include "../../include/linux/libcfs/libcfs.h"
 
-unsigned long cfs_fail_loc = 0;
+unsigned long cfs_fail_loc;
 EXPORT_SYMBOL(cfs_fail_loc);
 
-unsigned int cfs_fail_val = 0;
+unsigned int cfs_fail_val;
 EXPORT_SYMBOL(cfs_fail_val);
 
 DECLARE_WAIT_QUEUE_HEAD(cfs_race_waitq);
index 0ed06314523082000b04f4a093119da1d87d6257..030874428952120eb128c27eeec3d70ab0913555 100644 (file)
@@ -159,7 +159,7 @@ cfs_hash_rw_unlock(union cfs_hash_lock *lock, int exclusive)
 }
 
 /** No lock hash */
-static cfs_hash_lock_ops_t cfs_hash_nl_lops = {
+static struct cfs_hash_lock_ops cfs_hash_nl_lops = {
        .hs_lock        = cfs_hash_nl_lock,
        .hs_unlock      = cfs_hash_nl_unlock,
        .hs_bkt_lock    = cfs_hash_nl_lock,
@@ -167,7 +167,7 @@ static cfs_hash_lock_ops_t cfs_hash_nl_lops = {
 };
 
 /** no bucket lock, one spinlock to protect everything */
-static cfs_hash_lock_ops_t cfs_hash_nbl_lops = {
+static struct cfs_hash_lock_ops cfs_hash_nbl_lops = {
        .hs_lock        = cfs_hash_spin_lock,
        .hs_unlock      = cfs_hash_spin_unlock,
        .hs_bkt_lock    = cfs_hash_nl_lock,
@@ -175,7 +175,7 @@ static cfs_hash_lock_ops_t cfs_hash_nbl_lops = {
 };
 
 /** spin bucket lock, rehash is enabled */
-static cfs_hash_lock_ops_t cfs_hash_bkt_spin_lops = {
+static struct cfs_hash_lock_ops cfs_hash_bkt_spin_lops = {
        .hs_lock        = cfs_hash_rw_lock,
        .hs_unlock      = cfs_hash_rw_unlock,
        .hs_bkt_lock    = cfs_hash_spin_lock,
@@ -183,7 +183,7 @@ static cfs_hash_lock_ops_t cfs_hash_bkt_spin_lops = {
 };
 
 /** rw bucket lock, rehash is enabled */
-static cfs_hash_lock_ops_t cfs_hash_bkt_rw_lops = {
+static struct cfs_hash_lock_ops cfs_hash_bkt_rw_lops = {
        .hs_lock        = cfs_hash_rw_lock,
        .hs_unlock      = cfs_hash_rw_unlock,
        .hs_bkt_lock    = cfs_hash_rw_lock,
@@ -191,7 +191,7 @@ static cfs_hash_lock_ops_t cfs_hash_bkt_rw_lops = {
 };
 
 /** spin bucket lock, rehash is disabled */
-static cfs_hash_lock_ops_t cfs_hash_nr_bkt_spin_lops = {
+static struct cfs_hash_lock_ops cfs_hash_nr_bkt_spin_lops = {
        .hs_lock        = cfs_hash_nl_lock,
        .hs_unlock      = cfs_hash_nl_unlock,
        .hs_bkt_lock    = cfs_hash_spin_lock,
@@ -199,7 +199,7 @@ static cfs_hash_lock_ops_t cfs_hash_nr_bkt_spin_lops = {
 };
 
 /** rw bucket lock, rehash is disabled */
-static cfs_hash_lock_ops_t cfs_hash_nr_bkt_rw_lops = {
+static struct cfs_hash_lock_ops cfs_hash_nr_bkt_rw_lops = {
        .hs_lock        = cfs_hash_nl_lock,
        .hs_unlock      = cfs_hash_nl_unlock,
        .hs_bkt_lock    = cfs_hash_rw_lock,
@@ -239,21 +239,22 @@ cfs_hash_lock_setup(struct cfs_hash *hs)
  * Simple hash head without depth tracking
  * new element is always added to head of hlist
  */
-typedef struct {
+struct cfs_hash_head {
        struct hlist_head       hh_head;        /**< entries list */
-} cfs_hash_head_t;
+};
 
 static int
 cfs_hash_hh_hhead_size(struct cfs_hash *hs)
 {
-       return sizeof(cfs_hash_head_t);
+       return sizeof(struct cfs_hash_head);
 }
 
 static struct hlist_head *
 cfs_hash_hh_hhead(struct cfs_hash *hs, struct cfs_hash_bd *bd)
 {
-       cfs_hash_head_t *head = (cfs_hash_head_t *)&bd->bd_bucket->hsb_head[0];
+       struct cfs_hash_head *head;
 
+       head = (struct cfs_hash_head *)&bd->bd_bucket->hsb_head[0];
        return &head[bd->bd_offset].hh_head;
 }
 
@@ -277,23 +278,23 @@ cfs_hash_hh_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd,
  * Simple hash head with depth tracking
  * new element is always added to head of hlist
  */
-typedef struct {
+struct cfs_hash_head_dep {
        struct hlist_head       hd_head;        /**< entries list */
-       unsigned int        hd_depth;       /**< list length */
-} cfs_hash_head_dep_t;
+       unsigned int            hd_depth;       /**< list length */
+};
 
 static int
 cfs_hash_hd_hhead_size(struct cfs_hash *hs)
 {
-       return sizeof(cfs_hash_head_dep_t);
+       return sizeof(struct cfs_hash_head_dep);
 }
 
 static struct hlist_head *
 cfs_hash_hd_hhead(struct cfs_hash *hs, struct cfs_hash_bd *bd)
 {
-       cfs_hash_head_dep_t   *head;
+       struct cfs_hash_head_dep   *head;
 
-       head = (cfs_hash_head_dep_t *)&bd->bd_bucket->hsb_head[0];
+       head = (struct cfs_hash_head_dep *)&bd->bd_bucket->hsb_head[0];
        return &head[bd->bd_offset].hd_head;
 }
 
@@ -301,8 +302,10 @@ static int
 cfs_hash_hd_hnode_add(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                      struct hlist_node *hnode)
 {
-       cfs_hash_head_dep_t *hh = container_of(cfs_hash_hd_hhead(hs, bd),
-                                              cfs_hash_head_dep_t, hd_head);
+       struct cfs_hash_head_dep *hh;
+
+       hh = container_of(cfs_hash_hd_hhead(hs, bd),
+                         struct cfs_hash_head_dep, hd_head);
        hlist_add_head(hnode, &hh->hd_head);
        return ++hh->hd_depth;
 }
@@ -311,8 +314,10 @@ static int
 cfs_hash_hd_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                      struct hlist_node *hnode)
 {
-       cfs_hash_head_dep_t *hh = container_of(cfs_hash_hd_hhead(hs, bd),
-                                              cfs_hash_head_dep_t, hd_head);
+       struct cfs_hash_head_dep *hh;
+
+       hh = container_of(cfs_hash_hd_hhead(hs, bd),
+                         struct cfs_hash_head_dep, hd_head);
        hlist_del_init(hnode);
        return --hh->hd_depth;
 }
@@ -321,23 +326,23 @@ cfs_hash_hd_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd,
  * double links hash head without depth tracking
  * new element is always added to tail of hlist
  */
-typedef struct {
+struct cfs_hash_dhead {
        struct hlist_head       dh_head;        /**< entries list */
        struct hlist_node       *dh_tail;       /**< the last entry */
-} cfs_hash_dhead_t;
+};
 
 static int
 cfs_hash_dh_hhead_size(struct cfs_hash *hs)
 {
-       return sizeof(cfs_hash_dhead_t);
+       return sizeof(struct cfs_hash_dhead);
 }
 
 static struct hlist_head *
 cfs_hash_dh_hhead(struct cfs_hash *hs, struct cfs_hash_bd *bd)
 {
-       cfs_hash_dhead_t *head;
+       struct cfs_hash_dhead *head;
 
-       head = (cfs_hash_dhead_t *)&bd->bd_bucket->hsb_head[0];
+       head = (struct cfs_hash_dhead *)&bd->bd_bucket->hsb_head[0];
        return &head[bd->bd_offset].dh_head;
 }
 
@@ -345,9 +350,10 @@ static int
 cfs_hash_dh_hnode_add(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                      struct hlist_node *hnode)
 {
-       cfs_hash_dhead_t *dh = container_of(cfs_hash_dh_hhead(hs, bd),
-                                           cfs_hash_dhead_t, dh_head);
+       struct cfs_hash_dhead *dh;
 
+       dh = container_of(cfs_hash_dh_hhead(hs, bd),
+                         struct cfs_hash_dhead, dh_head);
        if (dh->dh_tail != NULL) /* not empty */
                hlist_add_behind(hnode, dh->dh_tail);
        else /* empty list */
@@ -360,9 +366,10 @@ static int
 cfs_hash_dh_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                      struct hlist_node *hnd)
 {
-       cfs_hash_dhead_t *dh = container_of(cfs_hash_dh_hhead(hs, bd),
-                                           cfs_hash_dhead_t, dh_head);
+       struct cfs_hash_dhead *dh;
 
+       dh = container_of(cfs_hash_dh_hhead(hs, bd),
+                         struct cfs_hash_dhead, dh_head);
        if (hnd->next == NULL) { /* it's the tail */
                dh->dh_tail = (hnd->pprev == &dh->dh_head.first) ? NULL :
                              container_of(hnd->pprev, struct hlist_node, next);
@@ -375,24 +382,24 @@ cfs_hash_dh_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd,
  * double links hash head with depth tracking
  * new element is always added to tail of hlist
  */
-typedef struct {
+struct cfs_hash_dhead_dep {
        struct hlist_head       dd_head;        /**< entries list */
        struct hlist_node       *dd_tail;       /**< the last entry */
        unsigned int        dd_depth;       /**< list length */
-} cfs_hash_dhead_dep_t;
+};
 
 static int
 cfs_hash_dd_hhead_size(struct cfs_hash *hs)
 {
-       return sizeof(cfs_hash_dhead_dep_t);
+       return sizeof(struct cfs_hash_dhead_dep);
 }
 
 static struct hlist_head *
 cfs_hash_dd_hhead(struct cfs_hash *hs, struct cfs_hash_bd *bd)
 {
-       cfs_hash_dhead_dep_t *head;
+       struct cfs_hash_dhead_dep *head;
 
-       head = (cfs_hash_dhead_dep_t *)&bd->bd_bucket->hsb_head[0];
+       head = (struct cfs_hash_dhead_dep *)&bd->bd_bucket->hsb_head[0];
        return &head[bd->bd_offset].dd_head;
 }
 
@@ -400,9 +407,10 @@ static int
 cfs_hash_dd_hnode_add(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                      struct hlist_node *hnode)
 {
-       cfs_hash_dhead_dep_t *dh = container_of(cfs_hash_dd_hhead(hs, bd),
-                                               cfs_hash_dhead_dep_t, dd_head);
+       struct cfs_hash_dhead_dep *dh;
 
+       dh = container_of(cfs_hash_dd_hhead(hs, bd),
+                         struct cfs_hash_dhead_dep, dd_head);
        if (dh->dd_tail != NULL) /* not empty */
                hlist_add_behind(hnode, dh->dd_tail);
        else /* empty list */
@@ -415,9 +423,10 @@ static int
 cfs_hash_dd_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                      struct hlist_node *hnd)
 {
-       cfs_hash_dhead_dep_t *dh = container_of(cfs_hash_dd_hhead(hs, bd),
-                                               cfs_hash_dhead_dep_t, dd_head);
+       struct cfs_hash_dhead_dep *dh;
 
+       dh = container_of(cfs_hash_dd_hhead(hs, bd),
+                         struct cfs_hash_dhead_dep, dd_head);
        if (hnd->next == NULL) { /* it's the tail */
                dh->dd_tail = (hnd->pprev == &dh->dd_head.first) ? NULL :
                              container_of(hnd->pprev, struct hlist_node, next);
@@ -426,28 +435,28 @@ cfs_hash_dd_hnode_del(struct cfs_hash *hs, struct cfs_hash_bd *bd,
        return --dh->dd_depth;
 }
 
-static cfs_hash_hlist_ops_t cfs_hash_hh_hops = {
+static struct cfs_hash_hlist_ops cfs_hash_hh_hops = {
        .hop_hhead      = cfs_hash_hh_hhead,
        .hop_hhead_size = cfs_hash_hh_hhead_size,
        .hop_hnode_add  = cfs_hash_hh_hnode_add,
        .hop_hnode_del  = cfs_hash_hh_hnode_del,
 };
 
-static cfs_hash_hlist_ops_t cfs_hash_hd_hops = {
+static struct cfs_hash_hlist_ops cfs_hash_hd_hops = {
        .hop_hhead      = cfs_hash_hd_hhead,
        .hop_hhead_size = cfs_hash_hd_hhead_size,
        .hop_hnode_add  = cfs_hash_hd_hnode_add,
        .hop_hnode_del  = cfs_hash_hd_hnode_del,
 };
 
-static cfs_hash_hlist_ops_t cfs_hash_dh_hops = {
+static struct cfs_hash_hlist_ops cfs_hash_dh_hops = {
        .hop_hhead      = cfs_hash_dh_hhead,
        .hop_hhead_size = cfs_hash_dh_hhead_size,
        .hop_hnode_add  = cfs_hash_dh_hnode_add,
        .hop_hnode_del  = cfs_hash_dh_hnode_del,
 };
 
-static cfs_hash_hlist_ops_t cfs_hash_dd_hops = {
+static struct cfs_hash_hlist_ops cfs_hash_dd_hops = {
        .hop_hhead      = cfs_hash_dd_hhead,
        .hop_hhead_size = cfs_hash_dd_hhead_size,
        .hop_hnode_add  = cfs_hash_dd_hnode_add,
@@ -588,16 +597,16 @@ EXPORT_SYMBOL(cfs_hash_bd_move_locked);
 
 enum {
        /** always set, for sanity (avoid ZERO intent) */
-       CFS_HS_LOOKUP_MASK_FIND     = 1 << 0,
+       CFS_HS_LOOKUP_MASK_FIND     = BIT(0),
        /** return entry with a ref */
-       CFS_HS_LOOKUP_MASK_REF      = 1 << 1,
+       CFS_HS_LOOKUP_MASK_REF      = BIT(1),
        /** add entry if not existing */
-       CFS_HS_LOOKUP_MASK_ADD      = 1 << 2,
+       CFS_HS_LOOKUP_MASK_ADD      = BIT(2),
        /** delete entry, ignore other masks */
-       CFS_HS_LOOKUP_MASK_DEL      = 1 << 3,
+       CFS_HS_LOOKUP_MASK_DEL      = BIT(3),
 };
 
-typedef enum cfs_hash_lookup_intent {
+enum cfs_hash_lookup_intent {
        /** return item w/o refcount */
        CFS_HS_LOOKUP_IT_PEEK       = CFS_HS_LOOKUP_MASK_FIND,
        /** return item with refcount */
@@ -612,12 +621,12 @@ typedef enum cfs_hash_lookup_intent {
        /** delete if existed */
        CFS_HS_LOOKUP_IT_FINDDEL    = (CFS_HS_LOOKUP_MASK_FIND |
                                       CFS_HS_LOOKUP_MASK_DEL)
-} cfs_hash_lookup_intent_t;
+};
 
 static struct hlist_node *
 cfs_hash_bd_lookup_intent(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                          const void *key, struct hlist_node *hnode,
-                         cfs_hash_lookup_intent_t intent)
+                         enum cfs_hash_lookup_intent intent)
 
 {
        struct hlist_head  *hhead = cfs_hash_bd_hhead(hs, bd);
@@ -677,8 +686,8 @@ cfs_hash_bd_findadd_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                           int noref)
 {
        return cfs_hash_bd_lookup_intent(hs, bd, key, hnode,
-                                        CFS_HS_LOOKUP_IT_ADD |
-                                        (!noref * CFS_HS_LOOKUP_MASK_REF));
+                                        (!noref * CFS_HS_LOOKUP_MASK_REF) |
+                                        CFS_HS_LOOKUP_IT_ADD);
 }
 EXPORT_SYMBOL(cfs_hash_bd_findadd_locked);
 
@@ -756,7 +765,7 @@ cfs_hash_multi_bd_findadd_locked(struct cfs_hash *hs,
        unsigned           i;
 
        LASSERT(hnode != NULL);
-       intent = CFS_HS_LOOKUP_IT_PEEK | (!noref * CFS_HS_LOOKUP_MASK_REF);
+       intent = (!noref * CFS_HS_LOOKUP_MASK_REF) | CFS_HS_LOOKUP_IT_PEEK;
 
        cfs_hash_for_each_bd(bds, n, i) {
                ehnode = cfs_hash_bd_lookup_intent(hs, &bds[i], key,
@@ -1019,7 +1028,7 @@ struct cfs_hash *
 cfs_hash_create(char *name, unsigned cur_bits, unsigned max_bits,
                unsigned bkt_bits, unsigned extra_bytes,
                unsigned min_theta, unsigned max_theta,
-               cfs_hash_ops_t *ops, unsigned flags)
+               struct cfs_hash_ops *ops, unsigned flags)
 {
        struct cfs_hash *hs;
        int      len;
@@ -1480,16 +1489,16 @@ cfs_hash_for_each_tight(struct cfs_hash *hs, cfs_hash_for_each_cb_t func,
        return count;
 }
 
-typedef struct {
-       cfs_hash_cond_opt_cb_t  func;
-       void               *arg;
-} cfs_hash_cond_arg_t;
+struct cfs_hash_cond_arg {
+       cfs_hash_cond_opt_cb_t  func;
+       void                    *arg;
+};
 
 static int
 cfs_hash_cond_del_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
                         struct hlist_node *hnode, void *data)
 {
-       cfs_hash_cond_arg_t *cond = data;
+       struct cfs_hash_cond_arg *cond = data;
 
        if (cond->func(cfs_hash_object(hs, hnode), cond->arg))
                cfs_hash_bd_del_locked(hs, bd, hnode);
@@ -1504,7 +1513,7 @@ cfs_hash_cond_del_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd,
 void
 cfs_hash_cond_del(struct cfs_hash *hs, cfs_hash_cond_opt_cb_t func, void *data)
 {
-       cfs_hash_cond_arg_t arg = {
+       struct cfs_hash_cond_arg arg = {
                .func   = func,
                .arg    = data,
        };
@@ -1623,8 +1632,12 @@ cfs_hash_for_each_relax(struct cfs_hash *hs, cfs_hash_for_each_cb_t func,
                                if (rc) /* callback wants to break iteration */
                                        break;
                        }
+                       if (rc) /* callback wants to break iteration */
+                               break;
                }
                cfs_hash_bd_unlock(hs, &bd, 0);
+               if (rc) /* callback wants to break iteration */
+                       break;
        }
        cfs_hash_unlock(hs, 0);
 
index d9b7c6b69db412012f27932f131d96ba7ff41347..ad661a33a21107a8f678d8c836604e6aa3fc5958 100644 (file)
@@ -100,6 +100,7 @@ struct kkuc_reg {
        struct file     *kr_fp;
        __u32           kr_data;
 };
+
 static struct list_head kkuc_groups[KUC_GRP_MAX+1] = {};
 /* Protect message sending against remove and adds */
 static DECLARE_RWSEM(kg_sem);
index 2c199c7259fe027850bcc5c870d567e488e99736..94bc0078500057d5fe62ba85b5700e643c6691c0 100644 (file)
@@ -34,7 +34,6 @@
 
 #include "../../include/linux/libcfs/libcfs.h"
 
-
 /** destroy cpu-partition lock, see libcfs_private.h for more detail */
 void
 cfs_percpt_lock_free(struct cfs_percpt_lock *pcl)
@@ -63,12 +62,12 @@ cfs_percpt_lock_alloc(struct cfs_cpt_table *cptab)
 
        /* NB: cptab can be NULL, pcl will be for HW CPUs on that case */
        LIBCFS_ALLOC(pcl, sizeof(*pcl));
-       if (pcl == NULL)
+       if (!pcl)
                return NULL;
 
        pcl->pcl_cptab = cptab;
        pcl->pcl_locks = cfs_percpt_alloc(cptab, sizeof(*lock));
-       if (pcl->pcl_locks == NULL) {
+       if (!pcl->pcl_locks) {
                LIBCFS_FREE(pcl, sizeof(*pcl));
                return NULL;
        }
@@ -146,7 +145,6 @@ cfs_percpt_unlock(struct cfs_percpt_lock *pcl, int index)
 }
 EXPORT_SYMBOL(cfs_percpt_unlock);
 
-
 /** free cpu-partition refcount */
 void
 cfs_percpt_atomic_free(atomic_t **refs)
@@ -164,7 +162,7 @@ cfs_percpt_atomic_alloc(struct cfs_cpt_table *cptab, int init_val)
        int             i;
 
        refs = cfs_percpt_alloc(cptab, sizeof(*ref));
-       if (refs == NULL)
+       if (!refs)
                return NULL;
 
        cfs_percpt_for_each(ref, i, refs)
index 1debdda72e727c9fd10187c43f377df3860a9f43..f4e08daba4d9bd3238efadb27d38319f017f4f6d 100644 (file)
@@ -84,7 +84,7 @@ cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size)
        count = cfs_cpt_number(cptab);
 
        LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count]));
-       if (arr == NULL)
+       if (!arr)
                return NULL;
 
        arr->va_size    = size = L1_CACHE_ALIGN(size);
@@ -93,7 +93,7 @@ cfs_percpt_alloc(struct cfs_cpt_table *cptab, unsigned int size)
 
        for (i = 0; i < count; i++) {
                LIBCFS_CPT_ALLOC(arr->va_ptrs[i], cptab, i, size);
-               if (arr->va_ptrs[i] == NULL) {
+               if (!arr->va_ptrs[i]) {
                        cfs_percpt_free((void *)&arr->va_ptrs[0]);
                        return NULL;
                }
@@ -160,7 +160,7 @@ cfs_array_free(void *vars)
        arr = container_of(vars, struct cfs_var_array, va_ptrs[0]);
 
        for (i = 0; i < arr->va_count; i++) {
-               if (arr->va_ptrs[i] == NULL)
+               if (!arr->va_ptrs[i])
                        continue;
 
                LIBCFS_FREE(arr->va_ptrs[i], arr->va_size);
@@ -182,7 +182,7 @@ cfs_array_alloc(int count, unsigned int size)
        int                     i;
 
        LIBCFS_ALLOC(arr, offsetof(struct cfs_var_array, va_ptrs[count]));
-       if (arr == NULL)
+       if (!arr)
                return NULL;
 
        arr->va_count   = count;
@@ -191,7 +191,7 @@ cfs_array_alloc(int count, unsigned int size)
        for (i = 0; i < count; i++) {
                LIBCFS_ALLOC(arr->va_ptrs[i], size);
 
-               if (arr->va_ptrs[i] == NULL) {
+               if (!arr->va_ptrs[i]) {
                        cfs_array_free((void *)&arr->va_ptrs[0]);
                        return NULL;
                }
index efe5e667a2e56292d2557492b0290fe0b38f7adc..d40be5396769482d6cdd305d2029b2914997ca3b 100644 (file)
@@ -214,6 +214,7 @@ cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res)
        res->ls_len = end - res->ls_str + 1;
        return 1;
 }
+EXPORT_SYMBOL(cfs_gettok);
 
 /**
  * Converts string to integer.
@@ -242,6 +243,7 @@ cfs_str2num_check(char *str, int nob, unsigned *num,
 
        return (*num >= min && *num <= max);
 }
+EXPORT_SYMBOL(cfs_str2num_check);
 
 /**
  * Parses \<range_expr\> token of the syntax. If \a bracketed is false,
@@ -320,6 +322,73 @@ cfs_range_expr_parse(struct cfs_lstr *src, unsigned min, unsigned max,
        return -EINVAL;
 }
 
+/**
+ * Print the range expression \a re into specified \a buffer.
+ * If \a bracketed is true, expression does not need additional
+ * brackets.
+ *
+ * \retval number of characters written
+ */
+static int
+cfs_range_expr_print(char *buffer, int count, struct cfs_range_expr *expr,
+                    bool bracketed)
+{
+       int i;
+       char s[] = "[";
+       char e[] = "]";
+
+       if (bracketed)
+               s[0] = e[0] = '\0';
+
+       if (expr->re_lo == expr->re_hi)
+               i = scnprintf(buffer, count, "%u", expr->re_lo);
+       else if (expr->re_stride == 1)
+               i = scnprintf(buffer, count, "%s%u-%u%s",
+                               s, expr->re_lo, expr->re_hi, e);
+       else
+               i = scnprintf(buffer, count, "%s%u-%u/%u%s",
+                               s, expr->re_lo, expr->re_hi,
+                               expr->re_stride, e);
+       return i;
+}
+
+/**
+ * Print a list of range expressions (\a expr_list) into specified \a buffer.
+ * If the list contains several expressions, separate them with comma
+ * and surround the list with brackets.
+ *
+ * \retval number of characters written
+ */
+int
+cfs_expr_list_print(char *buffer, int count, struct cfs_expr_list *expr_list)
+{
+       struct cfs_range_expr *expr;
+       int i = 0, j = 0;
+       int numexprs = 0;
+
+       if (count <= 0)
+               return 0;
+
+       list_for_each_entry(expr, &expr_list->el_exprs, re_link)
+               numexprs++;
+
+       if (numexprs > 1)
+               i += scnprintf(buffer + i, count - i, "[");
+
+       list_for_each_entry(expr, &expr_list->el_exprs, re_link) {
+               if (j++ != 0)
+                       i += scnprintf(buffer + i, count - i, ",");
+               i += cfs_range_expr_print(buffer + i, count - i, expr,
+                                         numexprs > 1);
+       }
+
+       if (numexprs > 1)
+               i += scnprintf(buffer + i, count - i, "]");
+
+       return i;
+}
+EXPORT_SYMBOL(cfs_expr_list_print);
+
 /**
  * Matches value (\a value) against ranges expression list \a expr_list.
  *
@@ -339,6 +408,7 @@ cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list)
 
        return 0;
 }
+EXPORT_SYMBOL(cfs_expr_list_match);
 
 /**
  * Convert express list (\a expr_list) to an array of all matched values
@@ -412,8 +482,8 @@ EXPORT_SYMBOL(cfs_expr_list_free);
 /**
  * Parses \<cfs_expr_list\> token of the syntax.
  *
- * \retval 1 if \a str parses to \<number\> | \<expr_list\>
- * \retval 0 otherwise
+ * \retval 0 if \a str parses to \<number\> | \<expr_list\>
+ * \retval -errno otherwise
  */
 int
 cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
@@ -491,72 +561,4 @@ cfs_expr_list_free_list(struct list_head *list)
                cfs_expr_list_free(el);
        }
 }
-
-int
-cfs_ip_addr_parse(char *str, int len, struct list_head *list)
-{
-       struct cfs_expr_list    *el;
-       struct cfs_lstr         src;
-       int                     rc;
-       int                     i;
-
-       src.ls_str = str;
-       src.ls_len = len;
-       i = 0;
-
-       while (src.ls_str != NULL) {
-               struct cfs_lstr res;
-
-               if (!cfs_gettok(&src, '.', &res)) {
-                       rc = -EINVAL;
-                       goto out;
-               }
-
-               rc = cfs_expr_list_parse(res.ls_str, res.ls_len, 0, 255, &el);
-               if (rc != 0)
-                       goto out;
-
-               list_add_tail(&el->el_link, list);
-               i++;
-       }
-
-       if (i == 4)
-               return 0;
-
-       rc = -EINVAL;
- out:
-       cfs_expr_list_free_list(list);
-
-       return rc;
-}
-EXPORT_SYMBOL(cfs_ip_addr_parse);
-
-/**
- * Matches address (\a addr) against address set encoded in \a list.
- *
- * \retval 1 if \a addr matches
- * \retval 0 otherwise
- */
-int
-cfs_ip_addr_match(__u32 addr, struct list_head *list)
-{
-       struct cfs_expr_list *el;
-       int i = 0;
-
-       list_for_each_entry_reverse(el, list, el_link) {
-               if (!cfs_expr_list_match(addr & 0xff, el))
-                       return 0;
-               addr >>= 8;
-               i++;
-       }
-
-       return i == 4;
-}
-EXPORT_SYMBOL(cfs_ip_addr_match);
-
-void
-cfs_ip_addr_free(struct list_head *list)
-{
-       cfs_expr_list_free_list(list);
-}
-EXPORT_SYMBOL(cfs_ip_addr_free);
+EXPORT_SYMBOL(cfs_expr_list_free_list);
index f9262243f9359aa2b9ae0ddd00a9f5c0937cbe6f..209736454d06e575009fe066b2eadb46c183d7d7 100644 (file)
@@ -699,7 +699,8 @@ cfs_cpt_num_estimate(void)
        /* generate reasonable number of CPU partitions based on total number
         * of CPUs, Preferred N should be power2 and match this condition:
         * 2 * (N - 1)^2 < NCPUS <= 2 * N^2 */
-       for (ncpt = 2; ncpu > 2 * ncpt * ncpt; ncpt <<= 1) {}
+       for (ncpt = 2; ncpu > 2 * ncpt * ncpt; ncpt <<= 1)
+               ;
 
        if (ncpt <= nnode) { /* fat numa system */
                while (nnode > ncpt)
index 5e185fa5942ad611ce79fa274310e9ae883506c5..5d8d8b79fa1f352c23c2b133ae7db144d47ecf11 100644 (file)
@@ -82,6 +82,7 @@ static int adler32_update(struct shash_desc *desc, const u8 *data,
        *cksump = __adler32(*cksump, data, len);
        return 0;
 }
+
 static int __adler32_finup(u32 *cksump, const u8 *data, unsigned int len,
                           u8 *out)
 {
@@ -109,6 +110,7 @@ static int adler32_digest(struct shash_desc *desc, const u8 *data,
        return __adler32_finup(crypto_shash_ctx(desc->tfm), data, len,
                                    out);
 }
+
 static struct shash_alg alg = {
        .setkey         = adler32_setkey,
        .init           = adler32_init,
@@ -129,7 +131,6 @@ static struct shash_alg alg = {
        }
 };
 
-
 int cfs_crypto_adler32_register(void)
 {
        return crypto_register_shash(&alg);
index fbbc8a7e308dc40f5e5d714723a0849951509a07..079d50ebfa3acd7c07c6d4d507827eec436d4293 100644 (file)
@@ -36,8 +36,6 @@
  */
 static int cfs_crypto_hash_speeds[CFS_HASH_ALG_MAX];
 
-
-
 static int cfs_crypto_hash_alloc(unsigned char alg_id,
                                 const struct cfs_crypto_hash_type **type,
                                 struct hash_desc *desc, unsigned char *key,
@@ -71,13 +69,12 @@ static int cfs_crypto_hash_alloc(unsigned char alg_id,
         * Skip this function for digest, because we use shash logic at
         * cfs_crypto_hash_alloc.
         */
-       if (key != NULL) {
+       if (key != NULL)
                err = crypto_hash_setkey(desc->tfm, key, key_len);
-       } else if ((*type)->cht_key != 0) {
+       else if ((*type)->cht_key != 0)
                err = crypto_hash_setkey(desc->tfm,
                                         (unsigned char *)&((*type)->cht_key),
                                         (*type)->cht_size);
-       }
 
        if (err != 0) {
                crypto_free_hash(desc->tfm);
@@ -225,6 +222,7 @@ static void cfs_crypto_performance_test(unsigned char alg_id,
                       cfs_crypto_hash_name(alg_id), err);
        } else {
                unsigned long   tmp;
+
                tmp = ((bcount * buf_len / jiffies_to_msecs(end - start)) *
                       1000) / (1024 * 1024);
                cfs_crypto_hash_speeds[alg_id] = (int)tmp;
@@ -282,6 +280,7 @@ int cfs_crypto_register(void)
        cfs_crypto_test_hashes();
        return 0;
 }
+
 void cfs_crypto_unregister(void)
 {
        if (adler32 == 0)
index 277f6b890e09f4bddcfc335785083485a9330898..c74c80915dca8bd15ed770cfe31ed82c1d52359f 100644 (file)
@@ -91,6 +91,7 @@ static void cfs_kernel_cap_pack(kernel_cap_t kcap, cfs_cap_t *cap)
 cfs_cap_t cfs_curproc_cap_pack(void)
 {
        cfs_cap_t cap;
+
        cfs_kernel_cap_pack(current_cap(), &cap);
        return cap;
 }
index 4545d54f71c6f3d93cbbb6ed3c021ba82d6c483e..8689ea757c99372614524fe708103089470e9e0f 100644 (file)
@@ -146,7 +146,7 @@ void libcfs_run_lbug_upcall(struct libcfs_debug_msg_data *msgdata)
 }
 
 /* coverity[+kill] */
-void lbug_with_loc(struct libcfs_debug_msg_data *msgdata)
+void __noreturn lbug_with_loc(struct libcfs_debug_msg_data *msgdata)
 {
        libcfs_catastrophe = 1;
        libcfs_debug_msg(msgdata, "LBUG\n");
index 64a984b42845ddb840e0512a1327bcc0a49bcb44..70a99cf019de51be8e2fce8fc5ab436c9aaa7b3b 100644 (file)
@@ -62,7 +62,6 @@ int libcfs_ioctl_getdata(char *buf, char *end, void *arg)
                return -EINVAL;
        }
 
-
        if (hdr->ioc_len < sizeof(struct libcfs_ioctl_data)) {
                CERROR("PORTALS: user buffer too small for ioctl\n");
                return -EINVAL;
index 838f5f3bd6af450579b7cedb2fe08713d882c65f..89084460231a420fce32080bcb98029cf1558634 100644 (file)
@@ -70,61 +70,6 @@ add_wait_queue_exclusive_head(wait_queue_head_t *waitq, wait_queue_t *link)
 }
 EXPORT_SYMBOL(add_wait_queue_exclusive_head);
 
-void cfs_init_timer(struct timer_list *t)
-{
-       init_timer(t);
-}
-EXPORT_SYMBOL(cfs_init_timer);
-
-void cfs_timer_init(struct timer_list *t, cfs_timer_func_t *func, void *arg)
-{
-       init_timer(t);
-       t->function = func;
-       t->data = (unsigned long)arg;
-}
-EXPORT_SYMBOL(cfs_timer_init);
-
-void cfs_timer_done(struct timer_list *t)
-{
-       return;
-}
-EXPORT_SYMBOL(cfs_timer_done);
-
-void cfs_timer_arm(struct timer_list *t, unsigned long deadline)
-{
-       mod_timer(t, deadline);
-}
-EXPORT_SYMBOL(cfs_timer_arm);
-
-void cfs_timer_disarm(struct timer_list *t)
-{
-       del_timer(t);
-}
-EXPORT_SYMBOL(cfs_timer_disarm);
-
-int  cfs_timer_is_armed(struct timer_list *t)
-{
-       return timer_pending(t);
-}
-EXPORT_SYMBOL(cfs_timer_is_armed);
-
-unsigned long cfs_timer_deadline(struct timer_list *t)
-{
-       return t->expires;
-}
-EXPORT_SYMBOL(cfs_timer_deadline);
-
-void cfs_enter_debugger(void)
-{
-#if defined(CONFIG_KGDB)
-       /* BREAKPOINT(); */
-#else
-       /* nothing */
-#endif
-}
-EXPORT_SYMBOL(cfs_enter_debugger);
-
-
 sigset_t
 cfs_block_allsigs(void)
 {
@@ -200,18 +145,3 @@ cfs_clear_sigpending(void)
        spin_unlock_irqrestore(&current->sighand->siglock, flags);
 }
 EXPORT_SYMBOL(cfs_clear_sigpending);
-
-int
-libcfs_arch_init(void)
-{
-       return 0;
-}
-EXPORT_SYMBOL(libcfs_arch_init);
-
-void
-libcfs_arch_cleanup(void)
-{
-       return;
-}
-EXPORT_SYMBOL(libcfs_arch_cleanup);
-
index eb10e3b478aae03dd84f55c7347a4c72b7b5e50b..64a136cd503db28a0ca22cfc7bcf69fa2e5c4572 100644 (file)
@@ -191,16 +191,18 @@ cfs_set_ptldebug_header(struct ptldebug_header *header,
                        struct libcfs_debug_msg_data *msgdata,
                        unsigned long stack)
 {
-       struct timeval tv;
+       struct timespec64 ts;
 
-       do_gettimeofday(&tv);
+       ktime_get_real_ts64(&ts);
 
        header->ph_subsys = msgdata->msg_subsys;
        header->ph_mask = msgdata->msg_mask;
        header->ph_cpu_id = smp_processor_id();
        header->ph_type = cfs_trace_buf_idx_get();
-       header->ph_sec = (__u32)tv.tv_sec;
-       header->ph_usec = tv.tv_usec;
+       /* y2038 safe since all user space treats this as unsigned, but
+        * will overflow in 2106 */
+       header->ph_sec = (u32)ts.tv_sec;
+       header->ph_usec = ts.tv_nsec / NSEC_PER_USEC;
        header->ph_stack = stack;
        header->ph_pid = current->pid;
        header->ph_line_num = msgdata->msg_line;
@@ -212,12 +214,11 @@ static char *
 dbghdr_to_err_string(struct ptldebug_header *hdr)
 {
        switch (hdr->ph_subsys) {
-
-               case S_LND:
-               case S_LNET:
-                       return "LNetError";
-               default:
-                       return "LustreError";
+       case S_LND:
+       case S_LNET:
+               return "LNetError";
+       default:
+               return "LustreError";
        }
 }
 
@@ -225,12 +226,11 @@ static char *
 dbghdr_to_info_string(struct ptldebug_header *hdr)
 {
        switch (hdr->ph_subsys) {
-
-               case S_LND:
-               case S_LNET:
-                       return "LNet";
-               default:
-                       return "Lustre";
+       case S_LND:
+       case S_LNET:
+               return "LNet";
+       default:
+               return "Lustre";
        }
 }
 
index 806f9747a3a299ead2f07d18da2a38c9aadff88a..50e8fd23fa17fdf70307b4201fa4018d37ccfac8 100644 (file)
@@ -66,9 +66,6 @@ MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
 MODULE_DESCRIPTION("Portals v3.1");
 MODULE_LICENSE("GPL");
 
-static void insert_debugfs(void);
-static void remove_debugfs(void);
-
 static struct dentry *lnet_debugfs_root;
 
 static void kportal_memhog_free(struct libcfs_device_userstate *ldu)
@@ -296,6 +293,7 @@ static int libcfs_ioctl_int(struct cfs_psdev_file *pfile, unsigned long cmd,
 
        default: {
                struct libcfs_ioctl_handler *hand;
+
                err = -EINVAL;
                down_read(&ioctl_list_sem);
                list_for_each_entry(hand, &ioctl_list, item) {
@@ -340,7 +338,6 @@ out:
        return err;
 }
 
-
 struct cfs_psdev_ops libcfs_psdev_ops = {
        libcfs_psdev_open,
        libcfs_psdev_release,
@@ -349,90 +346,6 @@ struct cfs_psdev_ops libcfs_psdev_ops = {
        libcfs_ioctl
 };
 
-static int init_libcfs_module(void)
-{
-       int rc;
-
-       libcfs_arch_init();
-       libcfs_init_nidstrings();
-
-       rc = libcfs_debug_init(5 * 1024 * 1024);
-       if (rc < 0) {
-               pr_err("LustreError: libcfs_debug_init: %d\n", rc);
-               return rc;
-       }
-
-       rc = cfs_cpu_init();
-       if (rc != 0)
-               goto cleanup_debug;
-
-       rc = misc_register(&libcfs_dev);
-       if (rc) {
-               CERROR("misc_register: error %d\n", rc);
-               goto cleanup_cpu;
-       }
-
-       rc = cfs_wi_startup();
-       if (rc) {
-               CERROR("initialize workitem: error %d\n", rc);
-               goto cleanup_deregister;
-       }
-
-       /* max to 4 threads, should be enough for rehash */
-       rc = min(cfs_cpt_weight(cfs_cpt_table, CFS_CPT_ANY), 4);
-       rc = cfs_wi_sched_create("cfs_rh", cfs_cpt_table, CFS_CPT_ANY,
-                                rc, &cfs_sched_rehash);
-       if (rc != 0) {
-               CERROR("Startup workitem scheduler: error: %d\n", rc);
-               goto cleanup_deregister;
-       }
-
-       rc = cfs_crypto_register();
-       if (rc) {
-               CERROR("cfs_crypto_register: error %d\n", rc);
-               goto cleanup_wi;
-       }
-
-       insert_debugfs();
-
-       CDEBUG(D_OTHER, "portals setup OK\n");
-       return 0;
- cleanup_wi:
-       cfs_wi_shutdown();
- cleanup_deregister:
-       misc_deregister(&libcfs_dev);
-cleanup_cpu:
-       cfs_cpu_fini();
- cleanup_debug:
-       libcfs_debug_cleanup();
-       return rc;
-}
-
-static void exit_libcfs_module(void)
-{
-       int rc;
-
-       remove_debugfs();
-
-       if (cfs_sched_rehash != NULL) {
-               cfs_wi_sched_destroy(cfs_sched_rehash);
-               cfs_sched_rehash = NULL;
-       }
-
-       cfs_crypto_unregister();
-       cfs_wi_shutdown();
-
-       misc_deregister(&libcfs_dev);
-
-       cfs_cpu_fini();
-
-       rc = libcfs_debug_cleanup();
-       if (rc)
-               pr_err("LustreError: libcfs_debug_cleanup: %d\n", rc);
-
-       libcfs_arch_cleanup();
-}
-
 static int proc_call_handler(void *data, int write, loff_t *ppos,
                void __user *buffer, size_t *lenp,
                int (*handler)(void *data, int write,
@@ -700,11 +613,6 @@ static struct ctl_table lnet_table[] = {
        }
 };
 
-struct lnet_debugfs_symlink_def {
-       char *name;
-       char *target;
-};
-
 static const struct lnet_debugfs_symlink_def lnet_debugfs_symlinks[] = {
        { "console_ratelimit",
          "/sys/module/libcfs/parameters/libcfs_console_ratelimit"},
@@ -756,11 +664,10 @@ static const struct file_operations lnet_debugfs_file_operations = {
        .llseek         = default_llseek,
 };
 
-static void insert_debugfs(void)
+void lustre_insert_debugfs(struct ctl_table *table,
+                          const struct lnet_debugfs_symlink_def *symlinks)
 {
-       struct ctl_table *table;
        struct dentry *entry;
-       const struct lnet_debugfs_symlink_def *symlinks;
 
        if (lnet_debugfs_root == NULL)
                lnet_debugfs_root = debugfs_create_dir("lnet", NULL);
@@ -769,19 +676,20 @@ static void insert_debugfs(void)
        if (IS_ERR_OR_NULL(lnet_debugfs_root))
                return;
 
-       for (table = lnet_table; table->procname; table++)
+       for (; table->procname; table++)
                entry = debugfs_create_file(table->procname, table->mode,
                                            lnet_debugfs_root, table,
                                            &lnet_debugfs_file_operations);
 
-       for (symlinks = lnet_debugfs_symlinks; symlinks->name; symlinks++)
+       for (; symlinks && symlinks->name; symlinks++)
                entry = debugfs_create_symlink(symlinks->name,
                                               lnet_debugfs_root,
                                               symlinks->target);
 
 }
+EXPORT_SYMBOL_GPL(lustre_insert_debugfs);
 
-static void remove_debugfs(void)
+static void lustre_remove_debugfs(void)
 {
        if (lnet_debugfs_root != NULL)
                debugfs_remove_recursive(lnet_debugfs_root);
@@ -789,6 +697,85 @@ static void remove_debugfs(void)
        lnet_debugfs_root = NULL;
 }
 
+static int init_libcfs_module(void)
+{
+       int rc;
+
+       rc = libcfs_debug_init(5 * 1024 * 1024);
+       if (rc < 0) {
+               pr_err("LustreError: libcfs_debug_init: %d\n", rc);
+               return rc;
+       }
+
+       rc = cfs_cpu_init();
+       if (rc != 0)
+               goto cleanup_debug;
+
+       rc = misc_register(&libcfs_dev);
+       if (rc) {
+               CERROR("misc_register: error %d\n", rc);
+               goto cleanup_cpu;
+       }
+
+       rc = cfs_wi_startup();
+       if (rc) {
+               CERROR("initialize workitem: error %d\n", rc);
+               goto cleanup_deregister;
+       }
+
+       /* max to 4 threads, should be enough for rehash */
+       rc = min(cfs_cpt_weight(cfs_cpt_table, CFS_CPT_ANY), 4);
+       rc = cfs_wi_sched_create("cfs_rh", cfs_cpt_table, CFS_CPT_ANY,
+                                rc, &cfs_sched_rehash);
+       if (rc != 0) {
+               CERROR("Startup workitem scheduler: error: %d\n", rc);
+               goto cleanup_deregister;
+       }
+
+       rc = cfs_crypto_register();
+       if (rc) {
+               CERROR("cfs_crypto_register: error %d\n", rc);
+               goto cleanup_wi;
+       }
+
+       lustre_insert_debugfs(lnet_table, lnet_debugfs_symlinks);
+
+       CDEBUG(D_OTHER, "portals setup OK\n");
+       return 0;
+ cleanup_wi:
+       cfs_wi_shutdown();
+ cleanup_deregister:
+       misc_deregister(&libcfs_dev);
+cleanup_cpu:
+       cfs_cpu_fini();
+ cleanup_debug:
+       libcfs_debug_cleanup();
+       return rc;
+}
+
+static void exit_libcfs_module(void)
+{
+       int rc;
+
+       lustre_remove_debugfs();
+
+       if (cfs_sched_rehash) {
+               cfs_wi_sched_destroy(cfs_sched_rehash);
+               cfs_sched_rehash = NULL;
+       }
+
+       cfs_crypto_unregister();
+       cfs_wi_shutdown();
+
+       misc_deregister(&libcfs_dev);
+
+       cfs_cpu_fini();
+
+       rc = libcfs_debug_cleanup();
+       if (rc)
+               pr_err("LustreError: libcfs_debug_cleanup: %d\n", rc);
+}
+
 MODULE_VERSION("1.0.0");
 
 module_init(init_libcfs_module);
diff --git a/drivers/staging/lustre/lustre/libcfs/nidstrings.c b/drivers/staging/lustre/lustre/libcfs/nidstrings.c
deleted file mode 100644 (file)
index 087449f..0000000
+++ /dev/null
@@ -1,842 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * libcfs/libcfs/nidstrings.c
- *
- * Author: Phil Schwan <phil@clusterfs.com>
- */
-
-#define DEBUG_SUBSYSTEM S_LNET
-
-#include "../../include/linux/libcfs/libcfs.h"
-#include "../../include/linux/lnet/lnet.h"
-
-/* CAVEAT VENDITOR! Keep the canonical string representation of nets/nids
- * consistent in all conversion functions.  Some code fragments are copied
- * around for the sake of clarity...
- */
-
-/* CAVEAT EMPTOR! Racey temporary buffer allocation!
- * Choose the number of nidstrings to support the MAXIMUM expected number of
- * concurrent users.  If there are more, the returned string will be volatile.
- * NB this number must allow for a process to be descheduled for a timeslice
- * between getting its string and using it.
- */
-
-static char      libcfs_nidstrings[LNET_NIDSTR_COUNT][LNET_NIDSTR_SIZE];
-static int       libcfs_nidstring_idx;
-
-static spinlock_t libcfs_nidstring_lock;
-
-void libcfs_init_nidstrings(void)
-{
-       spin_lock_init(&libcfs_nidstring_lock);
-}
-
-static char *
-libcfs_next_nidstring(void)
-{
-       char      *str;
-       unsigned long  flags;
-
-       spin_lock_irqsave(&libcfs_nidstring_lock, flags);
-
-       str = libcfs_nidstrings[libcfs_nidstring_idx++];
-       if (libcfs_nidstring_idx == ARRAY_SIZE(libcfs_nidstrings))
-               libcfs_nidstring_idx = 0;
-
-       spin_unlock_irqrestore(&libcfs_nidstring_lock, flags);
-       return str;
-}
-
-static int libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
-{
-       *addr = 0;
-       return 1;
-}
-
-static void libcfs_ip_addr2str(__u32 addr, char *str)
-{
-       snprintf(str, LNET_NIDSTR_SIZE, "%u.%u.%u.%u",
-                (addr >> 24) & 0xff, (addr >> 16) & 0xff,
-                (addr >> 8) & 0xff, addr & 0xff);
-}
-
-static int libcfs_ip_str2addr(const char *str, int nob, __u32 *addr)
-{
-       unsigned int    a;
-       unsigned int    b;
-       unsigned int    c;
-       unsigned int    d;
-       int             n = nob; /* XscanfX */
-
-       /* numeric IP? */
-       if (sscanf(str, "%u.%u.%u.%u%n", &a, &b, &c, &d, &n) >= 4 &&
-           n == nob &&
-           (a & ~0xff) == 0 && (b & ~0xff) == 0 &&
-           (c & ~0xff) == 0 && (d & ~0xff) == 0) {
-               *addr = ((a<<24)|(b<<16)|(c<<8)|d);
-               return 1;
-       }
-
-       return 0;
-}
-
-static void libcfs_decnum_addr2str(__u32 addr, char *str)
-{
-       snprintf(str, LNET_NIDSTR_SIZE, "%u", addr);
-}
-
-static void libcfs_hexnum_addr2str(__u32 addr, char *str)
-{
-       snprintf(str, LNET_NIDSTR_SIZE, "0x%x", addr);
-}
-
-static int libcfs_num_str2addr(const char *str, int nob, __u32 *addr)
-{
-       int     n;
-
-       n = nob;
-       if (sscanf(str, "0x%x%n", addr, &n) >= 1 && n == nob)
-               return 1;
-
-       n = nob;
-       if (sscanf(str, "0X%x%n", addr, &n) >= 1 && n == nob)
-               return 1;
-
-       n = nob;
-       if (sscanf(str, "%u%n", addr, &n) >= 1 && n == nob)
-               return 1;
-
-       return 0;
-}
-
-/**
- * Nf_parse_addrlist method for networks using numeric addresses.
- *
- * Examples of such networks are gm and elan.
- *
- * \retval 0 if \a str parsed to numeric address
- * \retval errno otherwise
- */
-static int
-libcfs_num_parse(char *str, int len, struct list_head *list)
-{
-       struct cfs_expr_list *el;
-       int     rc;
-
-       rc = cfs_expr_list_parse(str, len, 0, MAX_NUMERIC_VALUE, &el);
-       if (rc == 0)
-               list_add_tail(&el->el_link, list);
-
-       return rc;
-}
-
-/*
- * Nf_match_addr method for networks using numeric addresses
- *
- * \retval 1 on match
- * \retval 0 otherwise
- */
-static int
-libcfs_num_match(__u32 addr, struct list_head *numaddr)
-{
-       struct cfs_expr_list *el;
-
-       LASSERT(!list_empty(numaddr));
-       el = list_entry(numaddr->next, struct cfs_expr_list, el_link);
-
-       return cfs_expr_list_match(addr, el);
-}
-
-struct netstrfns {
-       int       nf_type;
-       char    *nf_name;
-       char    *nf_modname;
-       void       (*nf_addr2str)(__u32 addr, char *str);
-       int     (*nf_str2addr)(const char *str, int nob, __u32 *addr);
-       int     (*nf_parse_addrlist)(char *str, int len,
-                                       struct list_head *list);
-       int     (*nf_match_addr)(__u32 addr, struct list_head *list);
-};
-
-static struct netstrfns  libcfs_netstrfns[] = {
-       {/* .nf_type      */  LOLND,
-        /* .nf_name      */  "lo",
-        /* .nf_modname   */  "klolnd",
-        /* .nf_addr2str  */  libcfs_decnum_addr2str,
-        /* .nf_str2addr  */  libcfs_lo_str2addr,
-        /* .nf_parse_addr*/  libcfs_num_parse,
-        /* .nf_match_addr*/  libcfs_num_match},
-       {/* .nf_type      */  SOCKLND,
-        /* .nf_name      */  "tcp",
-        /* .nf_modname   */  "ksocklnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  O2IBLND,
-        /* .nf_name      */  "o2ib",
-        /* .nf_modname   */  "ko2iblnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  CIBLND,
-        /* .nf_name      */  "cib",
-        /* .nf_modname   */  "kciblnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  OPENIBLND,
-        /* .nf_name      */  "openib",
-        /* .nf_modname   */  "kopeniblnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  IIBLND,
-        /* .nf_name      */  "iib",
-        /* .nf_modname   */  "kiiblnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  VIBLND,
-        /* .nf_name      */  "vib",
-        /* .nf_modname   */  "kviblnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  RALND,
-        /* .nf_name      */  "ra",
-        /* .nf_modname   */  "kralnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  QSWLND,
-        /* .nf_name      */  "elan",
-        /* .nf_modname   */  "kqswlnd",
-        /* .nf_addr2str  */  libcfs_decnum_addr2str,
-        /* .nf_str2addr  */  libcfs_num_str2addr,
-        /* .nf_parse_addrlist*/  libcfs_num_parse,
-        /* .nf_match_addr*/  libcfs_num_match},
-       {/* .nf_type      */  GMLND,
-        /* .nf_name      */  "gm",
-        /* .nf_modname   */  "kgmlnd",
-        /* .nf_addr2str  */  libcfs_hexnum_addr2str,
-        /* .nf_str2addr  */  libcfs_num_str2addr,
-        /* .nf_parse_addrlist*/  libcfs_num_parse,
-        /* .nf_match_addr*/  libcfs_num_match},
-       {/* .nf_type      */  MXLND,
-        /* .nf_name      */  "mx",
-        /* .nf_modname   */  "kmxlnd",
-        /* .nf_addr2str  */  libcfs_ip_addr2str,
-        /* .nf_str2addr  */  libcfs_ip_str2addr,
-        /* .nf_parse_addrlist*/  cfs_ip_addr_parse,
-        /* .nf_match_addr*/  cfs_ip_addr_match},
-       {/* .nf_type      */  PTLLND,
-        /* .nf_name      */  "ptl",
-        /* .nf_modname   */  "kptllnd",
-        /* .nf_addr2str  */  libcfs_decnum_addr2str,
-        /* .nf_str2addr  */  libcfs_num_str2addr,
-        /* .nf_parse_addrlist*/  libcfs_num_parse,
-        /* .nf_match_addr*/  libcfs_num_match},
-       {/* .nf_type      */  GNILND,
-        /* .nf_name      */  "gni",
-        /* .nf_modname   */  "kgnilnd",
-        /* .nf_addr2str  */  libcfs_decnum_addr2str,
-        /* .nf_str2addr  */  libcfs_num_str2addr,
-        /* .nf_parse_addrlist*/  libcfs_num_parse,
-        /* .nf_match_addr*/  libcfs_num_match},
-       /* placeholder for net0 alias.  It MUST BE THE LAST ENTRY */
-       {/* .nf_type      */  -1},
-};
-
-static const int libcfs_nnetstrfns = ARRAY_SIZE(libcfs_netstrfns);
-
-/* CAVEAT EMPTOR XscanfX
- * I use "%n" at the end of a sscanf format to detect trailing junk.  However
- * sscanf may return immediately if it sees the terminating '0' in a string, so
- * I initialise the %n variable to the expected length.  If sscanf sets it;
- * fine, if it doesn't, then the scan ended at the end of the string, which is
- * fine too :) */
-
-static struct netstrfns *
-libcfs_lnd2netstrfns(int lnd)
-{
-       int    i;
-
-       if (lnd >= 0)
-               for (i = 0; i < libcfs_nnetstrfns; i++)
-                       if (lnd == libcfs_netstrfns[i].nf_type)
-                               return &libcfs_netstrfns[i];
-
-       return NULL;
-}
-
-static struct netstrfns *
-libcfs_namenum2netstrfns(const char *name)
-{
-       struct netstrfns *nf;
-       int            i;
-
-       for (i = 0; i < libcfs_nnetstrfns; i++) {
-               nf = &libcfs_netstrfns[i];
-               if (nf->nf_type >= 0 &&
-                   !strncmp(name, nf->nf_name, strlen(nf->nf_name)))
-                       return nf;
-       }
-       return NULL;
-}
-
-static struct netstrfns *
-libcfs_name2netstrfns(const char *name)
-{
-       int    i;
-
-       for (i = 0; i < libcfs_nnetstrfns; i++)
-               if (libcfs_netstrfns[i].nf_type >= 0 &&
-                   !strcmp(libcfs_netstrfns[i].nf_name, name))
-                       return &libcfs_netstrfns[i];
-
-       return NULL;
-}
-
-int
-libcfs_isknown_lnd(int type)
-{
-       return libcfs_lnd2netstrfns(type) != NULL;
-}
-EXPORT_SYMBOL(libcfs_isknown_lnd);
-
-char *
-libcfs_lnd2modname(int lnd)
-{
-       struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
-
-       return (nf == NULL) ? NULL : nf->nf_modname;
-}
-EXPORT_SYMBOL(libcfs_lnd2modname);
-
-char *
-libcfs_lnd2str(int lnd)
-{
-       char       *str;
-       struct netstrfns *nf = libcfs_lnd2netstrfns(lnd);
-
-       if (nf != NULL)
-               return nf->nf_name;
-
-       str = libcfs_next_nidstring();
-       snprintf(str, LNET_NIDSTR_SIZE, "?%d?", lnd);
-       return str;
-}
-EXPORT_SYMBOL(libcfs_lnd2str);
-
-int
-libcfs_str2lnd(const char *str)
-{
-       struct netstrfns *nf = libcfs_name2netstrfns(str);
-
-       if (nf != NULL)
-               return nf->nf_type;
-
-       return -1;
-}
-EXPORT_SYMBOL(libcfs_str2lnd);
-
-char *
-libcfs_net2str(__u32 net)
-{
-       int            lnd = LNET_NETTYP(net);
-       int            num = LNET_NETNUM(net);
-       struct netstrfns *nf  = libcfs_lnd2netstrfns(lnd);
-       char         *str = libcfs_next_nidstring();
-
-       if (nf == NULL)
-               snprintf(str, LNET_NIDSTR_SIZE, "<%d:%d>", lnd, num);
-       else if (num == 0)
-               snprintf(str, LNET_NIDSTR_SIZE, "%s", nf->nf_name);
-       else
-               snprintf(str, LNET_NIDSTR_SIZE, "%s%d", nf->nf_name, num);
-
-       return str;
-}
-EXPORT_SYMBOL(libcfs_net2str);
-
-char *
-libcfs_nid2str(lnet_nid_t nid)
-{
-       __u32        addr = LNET_NIDADDR(nid);
-       __u32        net = LNET_NIDNET(nid);
-       int            lnd = LNET_NETTYP(net);
-       int            nnum = LNET_NETNUM(net);
-       struct netstrfns *nf;
-       char         *str;
-       int            nob;
-
-       if (nid == LNET_NID_ANY)
-               return "<?>";
-
-       nf = libcfs_lnd2netstrfns(lnd);
-       str = libcfs_next_nidstring();
-
-       if (nf == NULL)
-               snprintf(str, LNET_NIDSTR_SIZE, "%x@<%d:%d>", addr, lnd, nnum);
-       else {
-               nf->nf_addr2str(addr, str);
-               nob = strlen(str);
-               if (nnum == 0)
-                       snprintf(str + nob, LNET_NIDSTR_SIZE - nob, "@%s",
-                                nf->nf_name);
-               else
-                       snprintf(str + nob, LNET_NIDSTR_SIZE - nob, "@%s%d",
-                                nf->nf_name, nnum);
-       }
-
-       return str;
-}
-EXPORT_SYMBOL(libcfs_nid2str);
-
-static struct netstrfns *
-libcfs_str2net_internal(const char *str, __u32 *net)
-{
-       struct netstrfns *uninitialized_var(nf);
-       int            nob;
-       unsigned int   netnum;
-       int            i;
-
-       for (i = 0; i < libcfs_nnetstrfns; i++) {
-               nf = &libcfs_netstrfns[i];
-               if (nf->nf_type >= 0 &&
-                   !strncmp(str, nf->nf_name, strlen(nf->nf_name)))
-                       break;
-       }
-
-       if (i == libcfs_nnetstrfns)
-               return NULL;
-
-       nob = strlen(nf->nf_name);
-
-       if (strlen(str) == (unsigned int)nob) {
-               netnum = 0;
-       } else {
-               if (nf->nf_type == LOLND) /* net number not allowed */
-                       return NULL;
-
-               str += nob;
-               i = strlen(str);
-               if (sscanf(str, "%u%n", &netnum, &i) < 1 ||
-                   i != (int)strlen(str))
-                       return NULL;
-       }
-
-       *net = LNET_MKNET(nf->nf_type, netnum);
-       return nf;
-}
-
-__u32
-libcfs_str2net(const char *str)
-{
-       __u32  net;
-
-       if (libcfs_str2net_internal(str, &net) != NULL)
-               return net;
-
-       return LNET_NIDNET(LNET_NID_ANY);
-}
-EXPORT_SYMBOL(libcfs_str2net);
-
-lnet_nid_t
-libcfs_str2nid(const char *str)
-{
-       const char       *sep = strchr(str, '@');
-       struct netstrfns *nf;
-       __u32        net;
-       __u32        addr;
-
-       if (sep != NULL) {
-               nf = libcfs_str2net_internal(sep + 1, &net);
-               if (nf == NULL)
-                       return LNET_NID_ANY;
-       } else {
-               sep = str + strlen(str);
-               net = LNET_MKNET(SOCKLND, 0);
-               nf = libcfs_lnd2netstrfns(SOCKLND);
-               LASSERT(nf != NULL);
-       }
-
-       if (!nf->nf_str2addr(str, (int)(sep - str), &addr))
-               return LNET_NID_ANY;
-
-       return LNET_MKNID(net, addr);
-}
-EXPORT_SYMBOL(libcfs_str2nid);
-
-char *
-libcfs_id2str(lnet_process_id_t id)
-{
-       char *str = libcfs_next_nidstring();
-
-       if (id.pid == LNET_PID_ANY) {
-               snprintf(str, LNET_NIDSTR_SIZE,
-                        "LNET_PID_ANY-%s", libcfs_nid2str(id.nid));
-               return str;
-       }
-
-       snprintf(str, LNET_NIDSTR_SIZE, "%s%u-%s",
-                ((id.pid & LNET_PID_USERFLAG) != 0) ? "U" : "",
-                (id.pid & ~LNET_PID_USERFLAG), libcfs_nid2str(id.nid));
-       return str;
-}
-EXPORT_SYMBOL(libcfs_id2str);
-
-int
-libcfs_str2anynid(lnet_nid_t *nidp, const char *str)
-{
-       if (!strcmp(str, "*")) {
-               *nidp = LNET_NID_ANY;
-               return 1;
-       }
-
-       *nidp = libcfs_str2nid(str);
-       return *nidp != LNET_NID_ANY;
-}
-EXPORT_SYMBOL(libcfs_str2anynid);
-
-/**
- * Nid range list syntax.
- * \verbatim
- *
- * <nidlist>    :== <nidrange> [ ' ' <nidrange> ]
- * <nidrange>  :== <addrrange> '@' <net>
- * <addrrange>       :== '*' |
- *                    <ipaddr_range> |
- *                      <cfs_expr_list>
- * <ipaddr_range>    :== <cfs_expr_list>.<cfs_expr_list>.<cfs_expr_list>.
- *                      <cfs_expr_list>
- * <cfs_expr_list>   :== <number> |
- *                    <expr_list>
- * <expr_list>       :== '[' <range_expr> [ ',' <range_expr>] ']'
- * <range_expr>      :== <number> |
- *                    <number> '-' <number> |
- *                    <number> '-' <number> '/' <number>
- * <net>            :== <netname> | <netname><number>
- * <netname>    :== "lo" | "tcp" | "o2ib" | "cib" | "openib" | "iib" |
- *                    "vib" | "ra" | "elan" | "mx" | "ptl"
- * \endverbatim
- */
-
-/**
- * Structure to represent \<nidrange\> token of the syntax.
- *
- * One of this is created for each \<net\> parsed.
- */
-struct nidrange {
-       /**
-        * Link to list of this structures which is built on nid range
-        * list parsing.
-        */
-       struct list_head nr_link;
-       /**
-        * List head for addrrange::ar_link.
-        */
-       struct list_head nr_addrranges;
-       /**
-        * Flag indicating that *@<net> is found.
-        */
-       int nr_all;
-       /**
-        * Pointer to corresponding element of libcfs_netstrfns.
-        */
-       struct netstrfns *nr_netstrfns;
-       /**
-        * Number of network. E.g. 5 if \<net\> is "elan5".
-        */
-       int nr_netnum;
-};
-
-/**
- * Structure to represent \<addrrange\> token of the syntax.
- */
-struct addrrange {
-       /**
-        * Link to nidrange::nr_addrranges.
-        */
-       struct list_head ar_link;
-       /**
-        * List head for cfs_expr_list::el_list.
-        */
-       struct list_head ar_numaddr_ranges;
-};
-
-/**
- * Parses \<addrrange\> token on the syntax.
- *
- * Allocates struct addrrange and links to \a nidrange via
- * (nidrange::nr_addrranges)
- *
- * \retval 1 if \a src parses to '*' | \<ipaddr_range\> | \<cfs_expr_list\>
- * \retval 0 otherwise
- */
-static int
-parse_addrange(const struct cfs_lstr *src, struct nidrange *nidrange)
-{
-       struct addrrange *addrrange;
-
-       if (src->ls_len == 1 && src->ls_str[0] == '*') {
-               nidrange->nr_all = 1;
-               return 1;
-       }
-
-       LIBCFS_ALLOC(addrrange, sizeof(struct addrrange));
-       if (addrrange == NULL)
-               return 0;
-       list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges);
-       INIT_LIST_HEAD(&addrrange->ar_numaddr_ranges);
-
-       return nidrange->nr_netstrfns->nf_parse_addrlist(src->ls_str,
-                                               src->ls_len,
-                                               &addrrange->ar_numaddr_ranges);
-}
-
-/**
- * Finds or creates struct nidrange.
- *
- * Checks if \a src is a valid network name, looks for corresponding
- * nidrange on the ist of nidranges (\a nidlist), creates new struct
- * nidrange if it is not found.
- *
- * \retval pointer to struct nidrange matching network specified via \a src
- * \retval NULL if \a src does not match any network
- */
-static struct nidrange *
-add_nidrange(const struct cfs_lstr *src,
-            struct list_head *nidlist)
-{
-       struct netstrfns *nf;
-       struct nidrange *nr;
-       int endlen;
-       unsigned netnum;
-
-       if (src->ls_len >= LNET_NIDSTR_SIZE)
-               return NULL;
-
-       nf = libcfs_namenum2netstrfns(src->ls_str);
-       if (nf == NULL)
-               return NULL;
-       endlen = src->ls_len - strlen(nf->nf_name);
-       if (endlen == 0)
-               /* network name only, e.g. "elan" or "tcp" */
-               netnum = 0;
-       else {
-               /* e.g. "elan25" or "tcp23", refuse to parse if
-                * network name is not appended with decimal or
-                * hexadecimal number */
-               if (!cfs_str2num_check(src->ls_str + strlen(nf->nf_name),
-                                      endlen, &netnum, 0, MAX_NUMERIC_VALUE))
-                       return NULL;
-       }
-
-       list_for_each_entry(nr, nidlist, nr_link) {
-               if (nr->nr_netstrfns != nf)
-                       continue;
-               if (nr->nr_netnum != netnum)
-                       continue;
-               return nr;
-       }
-
-       LIBCFS_ALLOC(nr, sizeof(struct nidrange));
-       if (nr == NULL)
-               return NULL;
-       list_add_tail(&nr->nr_link, nidlist);
-       INIT_LIST_HEAD(&nr->nr_addrranges);
-       nr->nr_netstrfns = nf;
-       nr->nr_all = 0;
-       nr->nr_netnum = netnum;
-
-       return nr;
-}
-
-/**
- * Parses \<nidrange\> token of the syntax.
- *
- * \retval 1 if \a src parses to \<addrrange\> '@' \<net\>
- * \retval 0 otherwise
- */
-static int
-parse_nidrange(struct cfs_lstr *src, struct list_head *nidlist)
-{
-       struct cfs_lstr addrrange;
-       struct cfs_lstr net;
-       struct cfs_lstr tmp;
-       struct nidrange *nr;
-
-       tmp = *src;
-       if (cfs_gettok(src, '@', &addrrange) == 0)
-               goto failed;
-
-       if (cfs_gettok(src, '@', &net) == 0 || src->ls_str != NULL)
-               goto failed;
-
-       nr = add_nidrange(&net, nidlist);
-       if (nr == NULL)
-               goto failed;
-
-       if (parse_addrange(&addrrange, nr) != 0)
-               goto failed;
-
-       return 1;
- failed:
-       CWARN("can't parse nidrange: \"%.*s\"\n", tmp.ls_len, tmp.ls_str);
-       return 0;
-}
-
-/**
- * Frees addrrange structures of \a list.
- *
- * For each struct addrrange structure found on \a list it frees
- * cfs_expr_list list attached to it and frees the addrrange itself.
- *
- * \retval none
- */
-static void
-free_addrranges(struct list_head *list)
-{
-       while (!list_empty(list)) {
-               struct addrrange *ar;
-
-               ar = list_entry(list->next, struct addrrange, ar_link);
-
-               cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
-               list_del(&ar->ar_link);
-               LIBCFS_FREE(ar, sizeof(struct addrrange));
-       }
-}
-
-/**
- * Frees nidrange strutures of \a list.
- *
- * For each struct nidrange structure found on \a list it frees
- * addrrange list attached to it and frees the nidrange itself.
- *
- * \retval none
- */
-void
-cfs_free_nidlist(struct list_head *list)
-{
-       struct list_head *pos, *next;
-       struct nidrange *nr;
-
-       list_for_each_safe(pos, next, list) {
-               nr = list_entry(pos, struct nidrange, nr_link);
-               free_addrranges(&nr->nr_addrranges);
-               list_del(pos);
-               LIBCFS_FREE(nr, sizeof(struct nidrange));
-       }
-}
-EXPORT_SYMBOL(cfs_free_nidlist);
-
-/**
- * Parses nid range list.
- *
- * Parses with rigorous syntax and overflow checking \a str into
- * \<nidrange\> [ ' ' \<nidrange\> ], compiles \a str into set of
- * structures and links that structure to \a nidlist. The resulting
- * list can be used to match a NID againts set of NIDS defined by \a
- * str.
- * \see cfs_match_nid
- *
- * \retval 1 on success
- * \retval 0 otherwise
- */
-int
-cfs_parse_nidlist(char *str, int len, struct list_head *nidlist)
-{
-       struct cfs_lstr src;
-       struct cfs_lstr res;
-       int rc;
-
-       src.ls_str = str;
-       src.ls_len = len;
-       INIT_LIST_HEAD(nidlist);
-       while (src.ls_str) {
-               rc = cfs_gettok(&src, ' ', &res);
-               if (rc == 0) {
-                       cfs_free_nidlist(nidlist);
-                       return 0;
-               }
-               rc = parse_nidrange(&res, nidlist);
-               if (rc == 0) {
-                       cfs_free_nidlist(nidlist);
-                       return 0;
-               }
-       }
-       return 1;
-}
-EXPORT_SYMBOL(cfs_parse_nidlist);
-
-/**
- * Matches a nid (\a nid) against the compiled list of nidranges (\a nidlist).
- *
- * \see cfs_parse_nidlist()
- *
- * \retval 1 on match
- * \retval 0  otherwises
- */
-int cfs_match_nid(lnet_nid_t nid, struct list_head *nidlist)
-{
-       struct nidrange *nr;
-       struct addrrange *ar;
-
-       list_for_each_entry(nr, nidlist, nr_link) {
-               if (nr->nr_netstrfns->nf_type != LNET_NETTYP(LNET_NIDNET(nid)))
-                       continue;
-               if (nr->nr_netnum != LNET_NETNUM(LNET_NIDNET(nid)))
-                       continue;
-               if (nr->nr_all)
-                       return 1;
-               list_for_each_entry(ar, &nr->nr_addrranges, ar_link)
-                       if (nr->nr_netstrfns->nf_match_addr(LNET_NIDADDR(nid),
-                                                      &ar->ar_numaddr_ranges))
-                               return 1;
-       }
-       return 0;
-}
-EXPORT_SYMBOL(cfs_match_nid);
index effa2af58c13a905a60f108cae21a8af8a79eead..973c7c209dfcaab4d4a1a56cb6c87c62407d83b2 100644 (file)
@@ -39,7 +39,6 @@
  * Author: Phil Schwan <phil@clusterfs.com>
  */
 
-
 #define DEBUG_SUBSYSTEM S_LNET
 #define LUSTRE_TRACEFILE_PRIVATE
 #include "tracefile.h"
@@ -124,7 +123,7 @@ int cfs_trace_refill_stock(struct cfs_trace_cpu_data *tcd, gfp_t gfp,
         * from here: this will lead to infinite recursion.
         */
 
-       for (i = 0; i + tcd->tcd_cur_stock_pages < TCD_STOCK_PAGES ; ++ i) {
+       for (i = 0; i + tcd->tcd_cur_stock_pages < TCD_STOCK_PAGES ; ++i) {
                struct cfs_trace_page *tage;
 
                tage = cfs_tage_alloc(gfp);
@@ -370,7 +369,7 @@ int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata,
        /* indent message according to the nesting level */
        while (depth-- > 0) {
                *(debug_buf++) = '.';
-               ++ tage->used;
+               ++tage->used;
        }
 
        strcpy(debug_buf, file);
@@ -652,6 +651,7 @@ void cfs_trace_debug_print(void)
                while (p < ((char *)page_address(page) + tage->used)) {
                        struct ptldebug_header *hdr;
                        int len;
+
                        hdr = (void *)p;
                        p += sizeof(*hdr);
                        file = p;
index e931f6d98de9632383b1afd5fb61052d1253a2ee..cb7a3963589f4a702a5739472e82329723f20aad 100644 (file)
@@ -65,8 +65,6 @@ void cfs_trace_stop_thread(void);
 int cfs_tracefile_init(int max_pages);
 void cfs_tracefile_exit(void);
 
-
-
 int cfs_trace_copyin_string(char *knl_buffer, int knl_buffer_nob,
                            const char __user *usr_buffer, int usr_buffer_nob);
 int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,
@@ -309,7 +307,6 @@ cfs_trace_put_tcd (struct cfs_trace_cpu_data *tcd)
 int cfs_trace_refill_stock(struct cfs_trace_cpu_data *tcd, gfp_t gfp,
                           struct list_head *stock);
 
-
 int cfs_tcd_owns_tage(struct cfs_trace_cpu_data *tcd,
                      struct cfs_trace_page *tage);
 
index 48009b7758456acae626aa1ae576acea5c20078d..e1143a566ac4aaf712d20c5e5bd20530656f04e5 100644 (file)
@@ -45,7 +45,7 @@
 
 #define CFS_WS_NAME_LEN         16
 
-typedef struct cfs_wi_sched {
+struct cfs_wi_sched {
        struct list_head                ws_list;        /* chain on global list */
        /** serialised workitems */
        spinlock_t              ws_lock;
@@ -73,7 +73,7 @@ typedef struct cfs_wi_sched {
        unsigned int            ws_starting:1;
        /** scheduler name */
        char                    ws_name[CFS_WS_NAME_LEN];
-} cfs_wi_sched_t;
+};
 
 static struct cfs_workitem_data {
        /** serialize */
@@ -87,19 +87,19 @@ static struct cfs_workitem_data {
 } cfs_wi_data;
 
 static inline void
-cfs_wi_sched_lock(cfs_wi_sched_t *sched)
+cfs_wi_sched_lock(struct cfs_wi_sched *sched)
 {
        spin_lock(&sched->ws_lock);
 }
 
 static inline void
-cfs_wi_sched_unlock(cfs_wi_sched_t *sched)
+cfs_wi_sched_unlock(struct cfs_wi_sched *sched)
 {
        spin_unlock(&sched->ws_lock);
 }
 
 static inline int
-cfs_wi_sched_cansleep(cfs_wi_sched_t *sched)
+cfs_wi_sched_cansleep(struct cfs_wi_sched *sched)
 {
        cfs_wi_sched_lock(sched);
        if (sched->ws_stopping) {
@@ -115,7 +115,6 @@ cfs_wi_sched_cansleep(cfs_wi_sched_t *sched)
        return 1;
 }
 
-
 /* XXX:
  * 0. it only works when called from wi->wi_action.
  * 1. when it returns no one shall try to schedule the workitem.
@@ -217,11 +216,10 @@ cfs_wi_schedule(struct cfs_wi_sched *sched, cfs_workitem_t *wi)
 }
 EXPORT_SYMBOL(cfs_wi_schedule);
 
-
 static int
 cfs_wi_scheduler (void *arg)
 {
-       struct cfs_wi_sched     *sched = (cfs_wi_sched_t *)arg;
+       struct cfs_wi_sched     *sched = (struct cfs_wi_sched *)arg;
 
        cfs_block_allsigs();
 
@@ -258,7 +256,6 @@ cfs_wi_scheduler (void *arg)
                        wi->wi_running   = 1;
                        wi->wi_scheduled = 0;
 
-
                        cfs_wi_sched_unlock(sched);
                        nloops++;
 
@@ -302,7 +299,6 @@ cfs_wi_scheduler (void *arg)
        return 0;
 }
 
-
 void
 cfs_wi_sched_destroy(struct cfs_wi_sched *sched)
 {
index 2cbc46838fdd83b0861ac8b98f654eb470dbf56b..9ac29e718da320a4b62e74b814937a050800eaff 100644 (file)
@@ -2,7 +2,7 @@ obj-$(CONFIG_LUSTRE_FS) += lustre.o
 obj-$(CONFIG_LUSTRE_LLITE_LLOOP) += llite_lloop.o
 lustre-y := dcache.o dir.o file.o llite_close.o llite_lib.o llite_nfs.o \
            rw.o namei.o symlink.o llite_mmap.o \
-           xattr.o xattr_cache.o remote_perm.o llite_rmtacl.o llite_capa.o \
+           xattr.o xattr_cache.o remote_perm.o llite_rmtacl.o \
            rw26.o super25.o statahead.o \
            ../lclient/glimpse.o ../lclient/lcommon_cl.o ../lclient/lcommon_misc.o \
            vvp_dev.o vvp_page.o vvp_lock.o vvp_io.o vvp_object.o lproc_llite.o
index b86685912d28c9dc74c0e62743dd441dbd2773e0..80cba0448499481eab069fccedf69d88b7954430 100644 (file)
@@ -344,7 +344,6 @@ static int ll_revalidate_nd(struct dentry *dentry, unsigned int flags)
        return ll_revalidate_dentry(dentry, flags);
 }
 
-
 static void ll_d_iput(struct dentry *de, struct inode *inode)
 {
        LASSERT(inode);
index a9bc6e23fc2582f39c5a753638979fba15451e61..5c9502b5b3582ab98633dd88c480b2030b2f795c 100644 (file)
@@ -660,7 +660,7 @@ static int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
        int mode;
        int err;
 
-       mode = (0755 & ~current_umask()) | S_IFDIR;
+       mode = (~current_umask() & 0755) | S_IFDIR;
        op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
                                     strlen(filename), mode, LUSTRE_OPC_MKDIR,
                                     lump);
@@ -838,11 +838,11 @@ int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
        /* We don't swab objects for directories */
        switch (le32_to_cpu(lmm->lmm_magic)) {
        case LOV_MAGIC_V1:
-               if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
+               if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC)
                        lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
                break;
        case LOV_MAGIC_V3:
-               if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
+               if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC)
                        lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
                break;
        default:
@@ -907,7 +907,6 @@ static int ll_ioc_copy_start(struct super_block *sb, struct hsm_copy *copy)
        hpk.hpk_errval = 0;
        hpk.hpk_data_version = 0;
 
-
        /* For archive request, we need to read the current file version. */
        if (copy->hc_hai.hai_action == HSMA_ARCHIVE) {
                struct inode    *inode;
@@ -1047,7 +1046,6 @@ progress:
        return rc;
 }
 
-
 static int copy_and_ioctl(int cmd, struct obd_export *exp,
                          const void __user *data, size_t size)
 {
@@ -1554,7 +1552,7 @@ out_req:
 
                switch (lmm->lmm_magic) {
                case LOV_USER_MAGIC_V1:
-                       if (LOV_USER_MAGIC_V1 == cpu_to_le32(LOV_USER_MAGIC_V1))
+                       if (cpu_to_le32(LOV_USER_MAGIC_V1) == LOV_USER_MAGIC_V1)
                                break;
                        /* swab objects first so that stripes num will be sane */
                        lustre_swab_lov_user_md_objects(
@@ -1563,7 +1561,7 @@ out_req:
                        lustre_swab_lov_user_md_v1((struct lov_user_md_v1 *)lmm);
                        break;
                case LOV_USER_MAGIC_V3:
-                       if (LOV_USER_MAGIC_V3 == cpu_to_le32(LOV_USER_MAGIC_V3))
+                       if (cpu_to_le32(LOV_USER_MAGIC_V3) == LOV_USER_MAGIC_V3)
                                break;
                        /* swab objects first so that stripes num will be sane */
                        lustre_swab_lov_user_md_objects(
@@ -1734,6 +1732,9 @@ out_quotactl:
        }
        case OBD_IOC_CHANGELOG_SEND:
        case OBD_IOC_CHANGELOG_CLEAR:
+               if (!capable(CFS_CAP_SYS_ADMIN))
+                       return -EPERM;
+
                rc = copy_and_ioctl(cmd, sbi->ll_md_exp, (void *)arg,
                                    sizeof(struct ioc_changelog));
                return rc;
index 4edbf46869d47d9f586eb15d46f0506ca84a1d69..02f27593013e3650e16bd22b511084755b2dc519 100644 (file)
@@ -64,7 +64,7 @@ static struct ll_file_data *ll_file_data_get(void)
 {
        struct ll_file_data *fd;
 
-       OBD_SLAB_ALLOC_PTR_GFP(fd, ll_file_data_slab, GFP_NOFS);
+       fd = kmem_cache_alloc(ll_file_data_slab, GFP_NOFS | __GFP_ZERO);
        if (fd == NULL)
                return NULL;
        fd->fd_write_failed = false;
@@ -74,7 +74,7 @@ static struct ll_file_data *ll_file_data_get(void)
 static void ll_file_data_put(struct ll_file_data *fd)
 {
        if (fd != NULL)
-               OBD_SLAB_FREE_PTR(fd, ll_file_data_slab);
+               kmem_cache_free(ll_file_data_slab, fd);
 }
 
 void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
@@ -92,9 +92,8 @@ void ll_pack_inode2opdata(struct inode *inode, struct md_op_data *op_data,
        op_data->op_ioepoch = ll_i2info(inode)->lli_ioepoch;
        if (fh)
                op_data->op_handle = *fh;
-       op_data->op_capa1 = ll_mdscapa_get(inode);
 
-       if (LLIF_DATA_MODIFIED & ll_i2info(inode)->lli_flags)
+       if (ll_i2info(inode)->lli_flags & LLIF_DATA_MODIFIED)
                op_data->op_bias |= MDS_DATA_MODIFIED;
 }
 
@@ -270,7 +269,7 @@ static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
        int lockmode;
        __u64 flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_TEST_LOCK;
        struct lustre_handle lockh;
-       ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_OPEN}};
+       ldlm_policy_data_t policy = {.l_inodebits = {MDS_INODELOCK_OPEN} };
        int rc = 0;
 
        /* clear group lock, if present */
@@ -321,7 +320,6 @@ static int ll_md_close(struct obd_export *md_exp, struct inode *inode,
 out:
        LUSTRE_FPRIVATE(file) = NULL;
        ll_file_data_put(fd);
-       ll_capa_close(inode);
 
        return rc;
 }
@@ -679,8 +677,6 @@ restart:
        if (!S_ISREG(inode->i_mode))
                goto out_och_free;
 
-       ll_capa_open(inode);
-
        if (!lli->lli_has_smd &&
            (cl_is_lov_delay_create(file->f_flags) ||
             (file->f_mode & FMODE_WRITE) == 0)) {
@@ -694,7 +690,7 @@ out_och_free:
        if (rc) {
                if (och_p && *och_p) {
                        kfree(*och_p);
-                       *och_p = NULL; /* OBD_FREE writes some magic there */
+                       *och_p = NULL;
                        (*och_usecount)--;
                }
                mutex_unlock(&lli->lli_och_mutex);
@@ -912,11 +908,10 @@ static int ll_lease_close(struct obd_client_handle *och, struct inode *inode,
 
 /* Fills the obdo with the attributes for the lsm */
 static int ll_lsm_getattr(struct lov_stripe_md *lsm, struct obd_export *exp,
-                         struct obd_capa *capa, struct obdo *obdo,
-                         __u64 ioepoch, int sync)
+                         struct obdo *obdo, __u64 ioepoch, int sync)
 {
        struct ptlrpc_request_set *set;
-       struct obd_info     oinfo = { { { 0 } } };
+       struct obd_info     oinfo = { };
        int                     rc;
 
        LASSERT(lsm != NULL);
@@ -932,7 +927,6 @@ static int ll_lsm_getattr(struct lov_stripe_md *lsm, struct obd_export *exp,
                               OBD_MD_FLMTIME | OBD_MD_FLCTIME |
                               OBD_MD_FLGROUP | OBD_MD_FLEPOCH |
                               OBD_MD_FLDATAVERSION;
-       oinfo.oi_capa = capa;
        if (sync) {
                oinfo.oi_oa->o_valid |= OBD_MD_FLFLAGS;
                oinfo.oi_oa->o_flags |= OBD_FL_SRVLOCK;
@@ -963,14 +957,12 @@ static int ll_lsm_getattr(struct lov_stripe_md *lsm, struct obd_export *exp,
 int ll_inode_getattr(struct inode *inode, struct obdo *obdo,
                     __u64 ioepoch, int sync)
 {
-       struct obd_capa      *capa = ll_mdscapa_get(inode);
        struct lov_stripe_md *lsm;
        int rc;
 
        lsm = ccc_inode_lsm_get(inode);
        rc = ll_lsm_getattr(lsm, ll_i2dtexp(inode),
-                           capa, obdo, ioepoch, sync);
-       capa_put(capa);
+                           obdo, ioepoch, sync);
        if (rc == 0) {
                struct ost_id *oi = lsm ? &lsm->lsm_oi : &obdo->o_oi;
 
@@ -1038,7 +1030,7 @@ int ll_glimpse_ioctl(struct ll_sb_info *sbi, struct lov_stripe_md *lsm,
        struct obdo obdo = { 0 };
        int rc;
 
-       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, NULL, &obdo, 0, 0);
+       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, &obdo, 0, 0);
        if (rc == 0) {
                st->st_size   = obdo.o_size;
                st->st_blocks = obdo.o_blocks;
@@ -1268,7 +1260,7 @@ static int ll_lov_recreate(struct inode *inode, struct ost_id *oi, u32 ost_idx)
        int rc = 0;
        struct lov_stripe_md *lsm = NULL, *lsm2;
 
-       OBDO_ALLOC(oa);
+       oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
        if (oa == NULL)
                return -ENOMEM;
 
@@ -1303,7 +1295,7 @@ static int ll_lov_recreate(struct inode *inode, struct ost_id *oi, u32 ost_idx)
        goto out;
 out:
        ccc_inode_lsm_put(inode, lsm);
-       OBDO_FREE(oa);
+       kmem_cache_free(obdo_cachep, oa);
        return rc;
 }
 
@@ -1433,7 +1425,7 @@ int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
         * little endian.  We convert it to host endian before
         * passing it to userspace.
         */
-       if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC)) {
+       if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) {
                int stripe_count;
 
                stripe_count = le16_to_cpu(lmm->lmm_stripe_count);
@@ -1874,7 +1866,7 @@ int ll_data_version(struct inode *inode, __u64 *data_version,
                goto out;
        }
 
-       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, NULL, obdo, 0, extent_lock);
+       rc = ll_lsm_getattr(lsm, sbi->ll_dt_exp, obdo, 0, extent_lock);
        if (rc == 0) {
                if (!(obdo->o_valid & OBD_MD_FLDATAVERSION))
                        rc = -EOPNOTSUPP;
@@ -1899,7 +1891,6 @@ int ll_hsm_release(struct inode *inode)
        __u64 data_version = 0;
        int rc;
 
-
        CDEBUG(D_INODE, "%s: Releasing file "DFID".\n",
               ll_get_fsname(inode->i_sb, NULL, 0),
               PFID(&ll_i2info(inode)->lli_fid));
@@ -1931,7 +1922,6 @@ int ll_hsm_release(struct inode *inode)
                                       &data_version);
        och = NULL;
 
-
 out:
        if (och != NULL && !IS_ERR(och)) /* close the file */
                ll_lease_close(och, inode, NULL);
@@ -2118,12 +2108,21 @@ static int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss)
        struct md_op_data       *op_data;
        int                      rc;
 
+       /* Detect out-of range masks */
+       if ((hss->hss_setmask | hss->hss_clearmask) & ~HSM_FLAGS_MASK)
+               return -EINVAL;
+
        /* Non-root users are forbidden to set or clear flags which are
         * NOT defined in HSM_USER_MASK. */
        if (((hss->hss_setmask | hss->hss_clearmask) & ~HSM_USER_MASK) &&
            !capable(CFS_CAP_SYS_ADMIN))
                return -EPERM;
 
+       /* Detect out-of range archive id */
+       if ((hss->hss_valid & HSS_ARCHIVE_ID) &&
+           (hss->hss_archive_id > LL_HSM_MAX_ARCHIVE))
+               return -EINVAL;
+
        op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
                                     LUSTRE_OPC_ANY, hss);
        if (IS_ERR(op_data))
@@ -2144,7 +2143,6 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
        struct iattr            *attr = NULL;
        int                      rc;
 
-
        if (!S_ISREG(inode->i_mode))
                return -EINVAL;
 
@@ -2494,8 +2492,8 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        default: {
                int err;
 
-               if (LLIOC_STOP ==
-                    ll_iocontrol_call(inode, file, cmd, arg, &err))
+               if (ll_iocontrol_call(inode, file, cmd, arg, &err) ==
+                    LLIOC_STOP)
                        return err;
 
                return obd_iocontrol(cmd, ll_i2dtexp(inode), 0, NULL,
@@ -2504,7 +2502,6 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 }
 
-
 static loff_t ll_file_seek(struct file *file, loff_t offset, int origin)
 {
        struct inode *inode = file_inode(file);
@@ -2565,7 +2562,6 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
        struct cl_env_nest nest;
        struct lu_env *env;
        struct cl_io *io;
-       struct obd_capa *capa = NULL;
        struct cl_fsync_io *fio;
        int result;
 
@@ -2577,15 +2573,12 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
        if (IS_ERR(env))
                return PTR_ERR(env);
 
-       capa = ll_osscapa_get(inode, CAPA_OPC_OSS_WRITE);
-
        io = ccc_env_thread_io(env);
        io->ci_obj = cl_i2info(inode)->lli_clob;
        io->ci_ignore_layout = ignore_layout;
 
        /* initialize parameters for sync */
        fio = &io->u.ci_fsync;
-       fio->fi_capa = capa;
        fio->fi_start = start;
        fio->fi_end = end;
        fio->fi_fid = ll_inode2fid(inode);
@@ -2601,8 +2594,6 @@ int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
        cl_io_fini(env, io);
        cl_env_nested_put(&nest, env);
 
-       capa_put(capa);
-
        return result;
 }
 
@@ -2611,7 +2602,6 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
        struct inode *inode = file_inode(file);
        struct ll_inode_info *lli = ll_i2info(inode);
        struct ptlrpc_request *req;
-       struct obd_capa *oc;
        int rc, err;
 
        CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
@@ -2633,10 +2623,7 @@ int ll_fsync(struct file *file, loff_t start, loff_t end, int datasync)
                        rc = err;
        }
 
-       oc = ll_mdscapa_get(inode);
-       err = md_sync(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), oc,
-                     &req);
-       capa_put(oc);
+       err = md_sync(ll_i2sbi(inode)->ll_md_exp, ll_inode2fid(inode), &req);
        if (!rc)
                rc = err;
        if (!err)
@@ -2670,7 +2657,7 @@ ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
        };
        struct md_op_data *op_data;
        struct lustre_handle lockh = {0};
-       ldlm_policy_data_t flock = {{0}};
+       ldlm_policy_data_t flock = { {0} };
        __u64 flags = 0;
        int rc;
        int rc2 = 0;
@@ -2846,7 +2833,7 @@ ldlm_mode_t ll_take_md_lock(struct inode *inode, __u64 bits,
        fid = &ll_i2info(inode)->lli_fid;
        CDEBUG(D_INFO, "trying to match res "DFID"\n", PFID(fid));
 
-       rc = md_lock_match(ll_i2mdexp(inode), LDLM_FL_BLOCK_GRANTED|flags,
+       rc = md_lock_match(ll_i2mdexp(inode), flags | LDLM_FL_BLOCK_GRANTED,
                           fid, LDLM_IBITS, &policy, mode, lockh);
 
        return rc;
@@ -2950,9 +2937,6 @@ static int __ll_inode_revalidate(struct dentry *dentry, __u64 ibits)
                        return PTR_ERR(op_data);
 
                op_data->op_valid = valid;
-               /* Once OBD_CONNECT_ATTRFID is not supported, we can't find one
-                * capa for this inode. Because we only keep capas of dirs
-                * fresh. */
                rc = md_getattr(sbi->ll_md_exp, op_data, &req);
                ll_finish_md_op_data(op_data);
                if (rc) {
@@ -3079,7 +3063,6 @@ struct posix_acl *ll_get_acl(struct inode *inode, int type)
        return acl;
 }
 
-
 int ll_inode_permission(struct inode *inode, int mask)
 {
        int rc = 0;
@@ -3177,7 +3160,6 @@ static struct llioc_ctl_data {
        LIST_HEAD_INIT(llioc.ioc_head)
 };
 
-
 struct llioc_data {
        struct list_head              iocd_list;
        unsigned int        iocd_size;
@@ -3303,7 +3285,6 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
 
 {
        struct ll_sb_info *sbi = ll_i2sbi(inode);
-       struct obd_capa *oc;
        struct ptlrpc_request *req;
        struct mdt_body *body;
        void *lvbdata;
@@ -3323,13 +3304,11 @@ static int ll_layout_fetch(struct inode *inode, struct ldlm_lock *lock)
         * blocked and then granted via completion ast, we have to fetch
         * layout here. Please note that we can't use the LVB buffer in
         * completion AST because it doesn't have a large enough buffer */
-       oc = ll_mdscapa_get(inode);
        rc = ll_get_default_mdsize(sbi, &lmmsize);
        if (rc == 0)
-               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
-                               OBD_MD_FLXATTR, XATTR_NAME_LOV, NULL, 0,
-                               lmmsize, 0, &req);
-       capa_put(oc);
+               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode),
+                                OBD_MD_FLXATTR, XATTR_NAME_LOV, NULL, 0,
+                                lmmsize, 0, &req);
        if (rc < 0)
                return rc;
 
diff --git a/drivers/staging/lustre/lustre/llite/llite_capa.c b/drivers/staging/lustre/lustre/llite/llite_capa.c
deleted file mode 100644 (file)
index 24590ae..0000000
+++ /dev/null
@@ -1,661 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/llite/llite_capa.c
- *
- * Author: Lai Siyao <lsy@clusterfs.com>
- */
-
-#define DEBUG_SUBSYSTEM S_LLITE
-
-#include <linux/fs.h>
-#include <linux/uaccess.h>
-#include <linux/file.h>
-#include <linux/kmod.h>
-
-#include "../include/lustre_lite.h"
-#include "llite_internal.h"
-
-/* for obd_capa.c_list, client capa might stay in three places:
- * 1. ll_capa_list.
- * 2. ll_idle_capas.
- * 3. stand alone: just allocated.
- */
-
-/* capas for oss writeback and those failed to renew */
-static LIST_HEAD(ll_idle_capas);
-static struct ptlrpc_thread ll_capa_thread;
-static struct list_head *ll_capa_list = &capa_list[CAPA_SITE_CLIENT];
-
-/* llite capa renewal timer */
-struct timer_list ll_capa_timer;
-/* for debug: indicate whether capa on llite is enabled or not */
-static atomic_t ll_capa_debug = ATOMIC_INIT(0);
-static unsigned long long ll_capa_renewed;
-static unsigned long long ll_capa_renewal_noent;
-static unsigned long long ll_capa_renewal_failed;
-static unsigned long long ll_capa_renewal_retries;
-
-static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa);
-
-static inline void update_capa_timer(struct obd_capa *ocapa,
-                                    unsigned long expiry)
-{
-       if (time_before(expiry, ll_capa_timer.expires) ||
-           !timer_pending(&ll_capa_timer)) {
-               mod_timer(&ll_capa_timer, expiry);
-               DEBUG_CAPA(D_SEC, &ocapa->c_capa,
-                          "ll_capa_timer update: %lu/%lu by", expiry, jiffies);
-       }
-}
-
-static inline unsigned long capa_renewal_time(struct obd_capa *ocapa)
-{
-       return cfs_time_sub(ocapa->c_expiry,
-                           cfs_time_seconds(ocapa->c_capa.lc_timeout) / 2);
-}
-
-static inline int capa_is_to_expire(struct obd_capa *ocapa)
-{
-       return time_before_eq(capa_renewal_time(ocapa), cfs_time_current());
-}
-
-static inline int have_expired_capa(void)
-{
-       struct obd_capa *ocapa = NULL;
-       int expired = 0;
-
-       /* if ll_capa_list has client capa to expire or ll_idle_capas has
-        * expired capa, return 1.
-        */
-       spin_lock(&capa_lock);
-       if (!list_empty(ll_capa_list)) {
-               ocapa = list_entry(ll_capa_list->next, struct obd_capa,
-                                  c_list);
-               expired = capa_is_to_expire(ocapa);
-               if (!expired)
-                       update_capa_timer(ocapa, capa_renewal_time(ocapa));
-       } else if (!list_empty(&ll_idle_capas)) {
-               ocapa = list_entry(ll_idle_capas.next, struct obd_capa,
-                                  c_list);
-               expired = capa_is_expired(ocapa);
-               if (!expired)
-                       update_capa_timer(ocapa, ocapa->c_expiry);
-       }
-       spin_unlock(&capa_lock);
-
-       if (expired)
-               DEBUG_CAPA(D_SEC, &ocapa->c_capa, "expired");
-       return expired;
-}
-
-static void sort_add_capa(struct obd_capa *ocapa, struct list_head *head)
-{
-       struct obd_capa *tmp;
-       struct list_head *before = NULL;
-
-       /* TODO: client capa is sorted by expiry, this could be optimized */
-       list_for_each_entry_reverse(tmp, head, c_list) {
-               if (cfs_time_aftereq(ocapa->c_expiry, tmp->c_expiry)) {
-                       before = &tmp->c_list;
-                       break;
-               }
-       }
-
-       LASSERT(&ocapa->c_list != before);
-       list_add(&ocapa->c_list, before ?: head);
-}
-
-static inline int obd_capa_open_count(struct obd_capa *oc)
-{
-       struct ll_inode_info *lli = ll_i2info(oc->u.cli.inode);
-
-       return atomic_read(&lli->lli_open_count);
-}
-
-static void ll_delete_capa(struct obd_capa *ocapa)
-{
-       struct ll_inode_info *lli = ll_i2info(ocapa->u.cli.inode);
-
-       if (capa_for_mds(&ocapa->c_capa)) {
-               LASSERT(lli->lli_mds_capa == ocapa);
-               lli->lli_mds_capa = NULL;
-       } else if (capa_for_oss(&ocapa->c_capa)) {
-               list_del_init(&ocapa->u.cli.lli_list);
-       }
-
-       DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free client");
-       list_del_init(&ocapa->c_list);
-       capa_count[CAPA_SITE_CLIENT]--;
-       /* release the ref when alloc */
-       capa_put(ocapa);
-}
-
-/* three places where client capa is deleted:
- * 1. capa_thread_main(), main place to delete expired capa.
- * 2. ll_clear_inode_capas() in ll_clear_inode().
- * 3. ll_truncate_free_capa() delete truncate capa explicitly in
- *    ll_setattr_ost().
- */
-static int capa_thread_main(void *unused)
-{
-       struct obd_capa *ocapa, *tmp, *next;
-       struct inode *inode = NULL;
-       struct l_wait_info lwi = { 0 };
-       int rc;
-
-       thread_set_flags(&ll_capa_thread, SVC_RUNNING);
-       wake_up(&ll_capa_thread.t_ctl_waitq);
-
-       while (1) {
-               l_wait_event(ll_capa_thread.t_ctl_waitq,
-                            !thread_is_running(&ll_capa_thread) ||
-                            have_expired_capa(),
-                            &lwi);
-
-               if (!thread_is_running(&ll_capa_thread))
-                       break;
-
-               next = NULL;
-
-               spin_lock(&capa_lock);
-               list_for_each_entry_safe(ocapa, tmp, ll_capa_list, c_list) {
-                       __u64 ibits;
-
-                       LASSERT(ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC);
-
-                       if (!capa_is_to_expire(ocapa)) {
-                               next = ocapa;
-                               break;
-                       }
-
-                       list_del_init(&ocapa->c_list);
-
-                       /* for MDS capability, only renew those which belong to
-                        * dir, or its inode is opened, or client holds LOOKUP
-                        * lock.
-                        */
-                       /* ibits may be changed by ll_have_md_lock() so we have
-                        * to set it each time
-                        */
-                       ibits = MDS_INODELOCK_LOOKUP;
-                       if (capa_for_mds(&ocapa->c_capa) &&
-                           !S_ISDIR(ocapa->u.cli.inode->i_mode) &&
-                           obd_capa_open_count(ocapa) == 0 &&
-                           !ll_have_md_lock(ocapa->u.cli.inode,
-                                            &ibits, LCK_MINMODE)) {
-                               DEBUG_CAPA(D_SEC, &ocapa->c_capa,
-                                          "skip renewal for");
-                               sort_add_capa(ocapa, &ll_idle_capas);
-                               continue;
-                       }
-
-                       /* for OSS capability, only renew those whose inode is
-                        * opened.
-                        */
-                       if (capa_for_oss(&ocapa->c_capa) &&
-                           obd_capa_open_count(ocapa) == 0) {
-                               /* oss capa with open count == 0 won't renew,
-                                * move to idle list
-                                */
-                               sort_add_capa(ocapa, &ll_idle_capas);
-                               continue;
-                       }
-
-                       /* NB iput() is in ll_update_capa() */
-                       inode = igrab(ocapa->u.cli.inode);
-                       if (!inode) {
-                               DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
-                                          "igrab failed for");
-                               continue;
-                       }
-
-                       capa_get(ocapa);
-                       ll_capa_renewed++;
-                       spin_unlock(&capa_lock);
-                       rc = md_renew_capa(ll_i2mdexp(inode), ocapa,
-                                          ll_update_capa);
-                       spin_lock(&capa_lock);
-                       if (rc) {
-                               DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
-                                          "renew failed: %d", rc);
-                               ll_capa_renewal_failed++;
-                       }
-               }
-
-               if (next)
-                       update_capa_timer(next, capa_renewal_time(next));
-
-               list_for_each_entry_safe(ocapa, tmp, &ll_idle_capas,
-                                        c_list) {
-                       if (!capa_is_expired(ocapa)) {
-                               if (!next)
-                                       update_capa_timer(ocapa,
-                                                         ocapa->c_expiry);
-                               break;
-                       }
-
-                       if (atomic_read(&ocapa->c_refc) > 1) {
-                               DEBUG_CAPA(D_SEC, &ocapa->c_capa,
-                                          "expired(c_refc %d), don't release",
-                                          atomic_read(&ocapa->c_refc));
-                               /* don't try to renew any more */
-                               list_del_init(&ocapa->c_list);
-                               continue;
-                       }
-
-                       /* expired capa is released. */
-                       DEBUG_CAPA(D_SEC, &ocapa->c_capa, "release expired");
-                       ll_delete_capa(ocapa);
-               }
-
-               spin_unlock(&capa_lock);
-       }
-
-       thread_set_flags(&ll_capa_thread, SVC_STOPPED);
-       wake_up(&ll_capa_thread.t_ctl_waitq);
-       return 0;
-}
-
-void ll_capa_timer_callback(unsigned long unused)
-{
-       wake_up(&ll_capa_thread.t_ctl_waitq);
-}
-
-int ll_capa_thread_start(void)
-{
-       struct task_struct *task;
-
-       init_waitqueue_head(&ll_capa_thread.t_ctl_waitq);
-
-       task = kthread_run(capa_thread_main, NULL, "ll_capa");
-       if (IS_ERR(task)) {
-               CERROR("cannot start expired capa thread: rc %ld\n",
-                      PTR_ERR(task));
-               return PTR_ERR(task);
-       }
-       wait_event(ll_capa_thread.t_ctl_waitq,
-                  thread_is_running(&ll_capa_thread));
-
-       return 0;
-}
-
-void ll_capa_thread_stop(void)
-{
-       thread_set_flags(&ll_capa_thread, SVC_STOPPING);
-       wake_up(&ll_capa_thread.t_ctl_waitq);
-       wait_event(ll_capa_thread.t_ctl_waitq,
-                  thread_is_stopped(&ll_capa_thread));
-}
-
-struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-       struct obd_capa *ocapa;
-       int found = 0;
-
-       if ((ll_i2sbi(inode)->ll_flags & LL_SBI_OSS_CAPA) == 0)
-               return NULL;
-
-       LASSERT(opc == CAPA_OPC_OSS_WRITE || opc == CAPA_OPC_OSS_RW ||
-               opc == CAPA_OPC_OSS_TRUNC);
-
-       spin_lock(&capa_lock);
-       list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) {
-               if (capa_is_expired(ocapa))
-                       continue;
-               if ((opc & CAPA_OPC_OSS_WRITE) &&
-                   capa_opc_supported(&ocapa->c_capa, CAPA_OPC_OSS_WRITE)) {
-                       found = 1;
-                       break;
-               } else if ((opc & CAPA_OPC_OSS_READ) &&
-                          capa_opc_supported(&ocapa->c_capa,
-                                             CAPA_OPC_OSS_READ)) {
-                       found = 1;
-                       break;
-               } else if ((opc & CAPA_OPC_OSS_TRUNC) &&
-                          capa_opc_supported(&ocapa->c_capa, opc)) {
-                       found = 1;
-                       break;
-               }
-       }
-
-       if (found) {
-               LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa),
-                                 ll_inode2fid(inode)));
-               LASSERT(ocapa->c_site == CAPA_SITE_CLIENT);
-
-               capa_get(ocapa);
-
-               DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client");
-       } else {
-               ocapa = NULL;
-
-               if (atomic_read(&ll_capa_debug)) {
-                       CERROR("no capability for " DFID " opc %#llx\n",
-                              PFID(&lli->lli_fid), opc);
-                       atomic_set(&ll_capa_debug, 0);
-               }
-       }
-       spin_unlock(&capa_lock);
-
-       return ocapa;
-}
-EXPORT_SYMBOL(ll_osscapa_get);
-
-struct obd_capa *ll_mdscapa_get(struct inode *inode)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-       struct obd_capa *ocapa;
-
-       LASSERT(inode);
-
-       if ((ll_i2sbi(inode)->ll_flags & LL_SBI_MDS_CAPA) == 0)
-               return NULL;
-
-       spin_lock(&capa_lock);
-       ocapa = capa_get(lli->lli_mds_capa);
-       spin_unlock(&capa_lock);
-       if (!ocapa && atomic_read(&ll_capa_debug)) {
-               CERROR("no mds capability for " DFID "\n", PFID(&lli->lli_fid));
-               atomic_set(&ll_capa_debug, 0);
-       }
-
-       return ocapa;
-}
-
-static struct obd_capa *do_add_mds_capa(struct inode *inode,
-                                       struct obd_capa *ocapa)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-       struct obd_capa *old = lli->lli_mds_capa;
-       struct lustre_capa *capa = &ocapa->c_capa;
-
-       if (!old) {
-               ocapa->u.cli.inode = inode;
-               lli->lli_mds_capa = ocapa;
-               capa_count[CAPA_SITE_CLIENT]++;
-
-               DEBUG_CAPA(D_SEC, capa, "add MDS");
-       } else {
-               spin_lock(&old->c_lock);
-               old->c_capa = *capa;
-               spin_unlock(&old->c_lock);
-
-               DEBUG_CAPA(D_SEC, capa, "update MDS");
-
-               capa_put(ocapa);
-               ocapa = old;
-       }
-       return ocapa;
-}
-
-static struct obd_capa *do_lookup_oss_capa(struct inode *inode, int opc)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-       struct obd_capa *ocapa;
-
-       /* inside capa_lock */
-       list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) {
-               if ((capa_opc(&ocapa->c_capa) & opc) != opc)
-                       continue;
-
-               LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa),
-                                 ll_inode2fid(inode)));
-               LASSERT(ocapa->c_site == CAPA_SITE_CLIENT);
-
-               DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client");
-               return ocapa;
-       }
-
-       return NULL;
-}
-
-static inline void inode_add_oss_capa(struct inode *inode,
-                                     struct obd_capa *ocapa)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-       struct obd_capa *tmp;
-       struct list_head *next = NULL;
-
-       /* capa is sorted in lli_oss_capas so lookup can always find the
-        * latest one
-        */
-       list_for_each_entry(tmp, &lli->lli_oss_capas, u.cli.lli_list) {
-               if (cfs_time_after(ocapa->c_expiry, tmp->c_expiry)) {
-                       next = &tmp->u.cli.lli_list;
-                       break;
-               }
-       }
-       LASSERT(&ocapa->u.cli.lli_list != next);
-       list_move_tail(&ocapa->u.cli.lli_list, next ?: &lli->lli_oss_capas);
-}
-
-static struct obd_capa *do_add_oss_capa(struct inode *inode,
-                                       struct obd_capa *ocapa)
-{
-       struct obd_capa *old;
-       struct lustre_capa *capa = &ocapa->c_capa;
-
-       LASSERTF(S_ISREG(inode->i_mode),
-                "inode has oss capa, but not regular file, mode: %d\n",
-                inode->i_mode);
-
-       /* FIXME: can't replace it so easily with fine-grained opc */
-       old = do_lookup_oss_capa(inode, capa_opc(capa) & CAPA_OPC_OSS_ONLY);
-       if (!old) {
-               ocapa->u.cli.inode = inode;
-               INIT_LIST_HEAD(&ocapa->u.cli.lli_list);
-               capa_count[CAPA_SITE_CLIENT]++;
-
-               DEBUG_CAPA(D_SEC, capa, "add OSS");
-       } else {
-               spin_lock(&old->c_lock);
-               old->c_capa = *capa;
-               spin_unlock(&old->c_lock);
-
-               DEBUG_CAPA(D_SEC, capa, "update OSS");
-
-               capa_put(ocapa);
-               ocapa = old;
-       }
-
-       inode_add_oss_capa(inode, ocapa);
-       return ocapa;
-}
-
-struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa)
-{
-       spin_lock(&capa_lock);
-       ocapa = capa_for_mds(&ocapa->c_capa) ? do_add_mds_capa(inode, ocapa) :
-                                              do_add_oss_capa(inode, ocapa);
-
-       /* truncate capa won't renew */
-       if (ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC) {
-               set_capa_expiry(ocapa);
-               list_del_init(&ocapa->c_list);
-               sort_add_capa(ocapa, ll_capa_list);
-
-               update_capa_timer(ocapa, capa_renewal_time(ocapa));
-       }
-
-       spin_unlock(&capa_lock);
-
-       atomic_set(&ll_capa_debug, 1);
-       return ocapa;
-}
-
-static inline void delay_capa_renew(struct obd_capa *oc, unsigned long delay)
-{
-       /* NB: set a fake expiry for this capa to prevent it renew too soon */
-       oc->c_expiry = cfs_time_add(oc->c_expiry, cfs_time_seconds(delay));
-}
-
-static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
-{
-       struct inode *inode = ocapa->u.cli.inode;
-       int rc = 0;
-
-       LASSERT(ocapa);
-
-       if (IS_ERR(capa)) {
-               /* set error code */
-               rc = PTR_ERR(capa);
-               spin_lock(&capa_lock);
-               if (rc == -ENOENT) {
-                       DEBUG_CAPA(D_SEC, &ocapa->c_capa,
-                                  "renewal canceled because object removed");
-                       ll_capa_renewal_noent++;
-               } else {
-                       ll_capa_renewal_failed++;
-
-                       /* failed capa won't be renewed any longer, but if -EIO,
-                        * client might be doing recovery, retry in 2 min.
-                        */
-                       if (rc == -EIO && !capa_is_expired(ocapa)) {
-                               delay_capa_renew(ocapa, 120);
-                               DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
-                                          "renewal failed: -EIO, retry in 2 mins");
-                               ll_capa_renewal_retries++;
-                               goto retry;
-                       } else {
-                               DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
-                                          "renewal failed(rc: %d) for", rc);
-                       }
-               }
-
-               list_del_init(&ocapa->c_list);
-               sort_add_capa(ocapa, &ll_idle_capas);
-               spin_unlock(&capa_lock);
-
-               capa_put(ocapa);
-               iput(inode);
-               return rc;
-       }
-
-       spin_lock(&ocapa->c_lock);
-       LASSERT(!memcmp(&ocapa->c_capa, capa,
-                       offsetof(struct lustre_capa, lc_opc)));
-       ocapa->c_capa = *capa;
-       set_capa_expiry(ocapa);
-       spin_unlock(&ocapa->c_lock);
-
-       spin_lock(&capa_lock);
-       if (capa_for_oss(capa))
-               inode_add_oss_capa(inode, ocapa);
-       DEBUG_CAPA(D_SEC, capa, "renew");
-retry:
-       list_del_init(&ocapa->c_list);
-       sort_add_capa(ocapa, ll_capa_list);
-       update_capa_timer(ocapa, capa_renewal_time(ocapa));
-       spin_unlock(&capa_lock);
-
-       capa_put(ocapa);
-       iput(inode);
-       return rc;
-}
-
-void ll_capa_open(struct inode *inode)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-
-       if ((ll_i2sbi(inode)->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
-           == 0)
-               return;
-
-       if (!S_ISREG(inode->i_mode))
-               return;
-
-       atomic_inc(&lli->lli_open_count);
-}
-
-void ll_capa_close(struct inode *inode)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-
-       if ((ll_i2sbi(inode)->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
-           == 0)
-               return;
-
-       if (!S_ISREG(inode->i_mode))
-               return;
-
-       atomic_dec(&lli->lli_open_count);
-}
-
-/* delete CAPA_OPC_OSS_TRUNC only */
-void ll_truncate_free_capa(struct obd_capa *ocapa)
-{
-       if (!ocapa)
-               return;
-
-       LASSERT(ocapa->c_capa.lc_opc & CAPA_OPC_OSS_TRUNC);
-       DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free truncate");
-
-       /* release ref when find */
-       capa_put(ocapa);
-       if (likely(ocapa->c_capa.lc_opc == CAPA_OPC_OSS_TRUNC)) {
-               spin_lock(&capa_lock);
-               ll_delete_capa(ocapa);
-               spin_unlock(&capa_lock);
-       }
-}
-
-void ll_clear_inode_capas(struct inode *inode)
-{
-       struct ll_inode_info *lli = ll_i2info(inode);
-       struct obd_capa *ocapa, *tmp;
-
-       spin_lock(&capa_lock);
-       ocapa = lli->lli_mds_capa;
-       if (ocapa)
-               ll_delete_capa(ocapa);
-
-       list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas,
-                                u.cli.lli_list)
-               ll_delete_capa(ocapa);
-       spin_unlock(&capa_lock);
-}
-
-void ll_print_capa_stat(struct ll_sb_info *sbi)
-{
-       if (sbi->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
-               LCONSOLE_INFO("Fid capabilities renewed: %llu\n"
-                             "Fid capabilities renewal ENOENT: %llu\n"
-                             "Fid capabilities failed to renew: %llu\n"
-                             "Fid capabilities renewal retries: %llu\n",
-                             ll_capa_renewed, ll_capa_renewal_noent,
-                             ll_capa_renewal_failed, ll_capa_renewal_retries);
-}
index 7bdae723fedde6f072cb29876504eaf9bf6c0dcc..3f348a3aad43f58bd63b605c36e7588d0a57e04b 100644 (file)
@@ -221,7 +221,7 @@ int ll_som_update(struct inode *inode, struct md_op_data *op_data)
                       inode->i_ino, inode->i_generation,
                       lli->lli_flags);
 
-       OBDO_ALLOC(oa);
+       oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
        if (!oa) {
                CERROR("can't allocate memory for Size-on-MDS update.\n");
                return -ENOMEM;
@@ -252,7 +252,7 @@ int ll_som_update(struct inode *inode, struct md_op_data *op_data)
                        NULL, 0, NULL, 0, &request, NULL);
        ptlrpc_req_finished(request);
 
-       OBDO_FREE(oa);
+       kmem_cache_free(obdo_cachep, oa);
        return rc;
 }
 
@@ -293,14 +293,13 @@ static void ll_done_writing(struct inode *inode)
                goto out;
 
        rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, NULL);
-       if (rc == -EAGAIN) {
+       if (rc == -EAGAIN)
                /* MDS has instructed us to obtain Size-on-MDS attribute from
                 * OSTs and send setattr to back to MDS. */
                rc = ll_som_update(inode, op_data);
-       } else if (rc) {
+       else if (rc)
                CERROR("inode %lu mdc done_writing failed: rc = %d\n",
                       inode->i_ino, rc);
-       }
 out:
        ll_finish_md_op_data(op_data);
        if (och) {
index ec8fff4632085a9652581b7b6fec3c8573c99365..9096d311e45d76baa411fb53b0d331685f304972 100644 (file)
@@ -71,7 +71,7 @@ struct ll_dentry_data {
        struct rcu_head                 lld_rcu_head;
 };
 
-#define ll_d2d(de) ((struct ll_dentry_data*)((de)->d_fsdata))
+#define ll_d2d(de) ((struct ll_dentry_data *)((de)->d_fsdata))
 
 #define LLI_INODE_MAGIC                 0x111d0de5
 #define LLI_INODE_DEAD           0xdeadd00d
@@ -134,11 +134,9 @@ struct ll_inode_info {
        struct lu_fid              lli_pfid;
 
        struct list_head                      lli_close_list;
-       struct list_head                      lli_oss_capas;
        /* open count currently used by capability only, indicate whether
         * capability needs renewal */
        atomic_t                    lli_open_count;
-       struct obd_capa         *lli_mds_capa;
        unsigned long                 lli_rmtperm_time;
 
        /* handle is to be sent to MDS later on done_writing and setattr.
@@ -398,8 +396,8 @@ enum stats_track_type {
 #define LL_SBI_USER_XATTR      0x08 /* support user xattr */
 #define LL_SBI_ACL            0x10 /* support ACL */
 #define LL_SBI_RMT_CLIENT      0x40 /* remote client */
-#define LL_SBI_MDS_CAPA          0x80 /* support mds capa */
-#define LL_SBI_OSS_CAPA         0x100 /* support oss capa */
+#define LL_SBI_MDS_CAPA                 0x80 /* support mds capa, obsolete */
+#define LL_SBI_OSS_CAPA                0x100 /* support oss capa, obsolete */
 #define LL_SBI_LOCALFLOCK       0x200 /* Local flocks support by kernel */
 #define LL_SBI_LRU_RESIZE       0x400 /* lru resize support */
 #define LL_SBI_LAZYSTATFS       0x800 /* lazystatfs mount option */
@@ -659,7 +657,6 @@ static inline int ll_need_32bit_api(struct ll_sb_info *sbi)
 
 void ll_ra_read_in(struct file *f, struct ll_ra_read *rar);
 void ll_ra_read_ex(struct file *f, struct ll_ra_read *rar);
-struct ll_ra_read *ll_ra_read_get(struct file *f);
 
 /* llite/lproc_llite.c */
 int ldebugfs_register_mountpoint(struct dentry *parent,
@@ -690,7 +687,6 @@ struct inode *ll_iget(struct super_block *sb, ino_t hash,
 int ll_md_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
                       void *data, int flag);
 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de);
-int ll_rmdir_entry(struct inode *dir, char *name, int namelen);
 
 /* llite/rw.c */
 int ll_prepare_write(struct file *, struct page *, unsigned from, unsigned to);
@@ -791,8 +787,6 @@ int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
 int ll_obd_statfs(struct inode *inode, void *arg);
 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *max_mdsize);
 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *default_mdsize);
-int ll_get_max_cookiesize(struct ll_sb_info *sbi, int *max_cookiesize);
-int ll_get_default_cookiesize(struct ll_sb_info *sbi, int *default_cookiesize);
 int ll_process_config(struct lustre_cfg *lcfg);
 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
                                      struct inode *i1, struct inode *i2,
@@ -801,6 +795,7 @@ struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
 void ll_finish_md_op_data(struct md_op_data *op_data);
 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg);
 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen);
+void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req);
 
 /* llite/llite_nfs.c */
 extern struct export_operations lustre_export_operations;
@@ -823,7 +818,6 @@ struct ll_close_queue {
 
 struct ccc_object *cl_inode2ccc(struct inode *inode);
 
-
 void vvp_write_pending (struct ccc_object *club, struct ccc_page *page);
 void vvp_write_complete(struct ccc_object *club, struct ccc_page *page);
 
@@ -850,7 +844,7 @@ struct vvp_io {
                         * Inode modification time that is checked across DLM
                         * lock request.
                         */
-                       time_t           ft_mtime;
+                       time64_t            ft_mtime;
                        struct vm_area_struct *ft_vma;
                        /**
                         *  locked page returned from vvp_io
@@ -1000,6 +994,7 @@ static inline struct obd_export *ll_s2mdexp(struct super_block *sb)
 static inline struct client_obd *sbi2mdc(struct ll_sb_info *sbi)
 {
        struct obd_device *obd = sbi->ll_md_exp->exp_obd;
+
        if (obd == NULL)
                LBUG();
        return &obd->u.cli;
@@ -1052,25 +1047,6 @@ void free_rmtperm_hash(struct hlist_head *hash);
 int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm);
 int lustre_check_remote_perm(struct inode *inode, int mask);
 
-/* llite/llite_capa.c */
-extern struct timer_list ll_capa_timer;
-
-int ll_capa_thread_start(void);
-void ll_capa_thread_stop(void);
-void ll_capa_timer_callback(unsigned long unused);
-
-struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa);
-
-void ll_capa_open(struct inode *inode);
-void ll_capa_close(struct inode *inode);
-
-struct obd_capa *ll_mdscapa_get(struct inode *inode);
-struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc);
-
-void ll_truncate_free_capa(struct obd_capa *ocapa);
-void ll_clear_inode_capas(struct inode *inode);
-void ll_print_capa_stat(struct ll_sb_info *sbi);
-
 /* llite/llite_cl.c */
 extern struct lu_device_type vvp_device_type;
 
@@ -1296,7 +1272,6 @@ typedef enum llioc_iter (*llioc_callback_t)(struct inode *inode,
 void *ll_iocontrol_register(llioc_callback_t cb, int count, unsigned int *cmd);
 void ll_iocontrol_unregister(void *magic);
 
-
 /* lclient compat stuff */
 #define cl_inode_info ll_inode_info
 #define cl_i2info(info) ll_i2info(info)
@@ -1344,8 +1319,6 @@ static inline int cl_merge_lvb(const struct lu_env *env, struct inode *inode)
 #define cl_inode_ctime(inode) LTIME_S((inode)->i_ctime)
 #define cl_inode_mtime(inode) LTIME_S((inode)->i_mtime)
 
-struct obd_capa *cl_capa_lookup(struct inode *inode, enum cl_req_type crt);
-
 int cl_sync_file_range(struct inode *inode, loff_t start, loff_t end,
                       enum cl_fsync_mode mode, int ignore_layout);
 
@@ -1465,7 +1438,15 @@ static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
        spin_lock_nested(&dentry->d_lock,
                         nested ? DENTRY_D_LOCK_NESTED : DENTRY_D_LOCK_NORMAL);
        __d_lustre_invalidate(dentry);
-       if (d_count(dentry) == 0)
+       /*
+        * We should be careful about dentries created by d_obtain_alias().
+        * These dentries are not put in the dentry tree, instead they are
+        * linked to sb->s_anon through dentry->d_hash.
+        * shrink_dcache_for_umount() shrinks the tree and sb->s_anon list.
+        * If we unhashed such a dentry, unmount would not be able to find
+        * it and busy inodes would be reported.
+        */
+       if (d_count(dentry) == 0 && !(dentry->d_flags & DCACHE_DISCONNECTED))
                __d_drop(dentry);
        spin_unlock(&dentry->d_lock);
 }
index b4ed6c89af3d4c4129d89f1c84c01b1da1fed28d..4a8c759fef42c4db97089658723df050113330ef 100644 (file)
@@ -146,7 +146,6 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
        struct inode *root = NULL;
        struct ll_sb_info *sbi = ll_s2sbi(sb);
        struct obd_device *obd;
-       struct obd_capa *oc = NULL;
        struct obd_statfs *osfs = NULL;
        struct ptlrpc_request *request = NULL;
        struct obd_connect_data *data = NULL;
@@ -182,7 +181,6 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
        data->ocd_connect_flags = OBD_CONNECT_IBITS    | OBD_CONNECT_NODEVOH  |
                                  OBD_CONNECT_ATTRFID  |
                                  OBD_CONNECT_VERSION  | OBD_CONNECT_BRW_SIZE |
-                                 OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
                                  OBD_CONNECT_CANCELSET | OBD_CONNECT_FID     |
                                  OBD_CONNECT_AT       | OBD_CONNECT_LOV_V3   |
                                  OBD_CONNECT_RMT_CLIENT | OBD_CONNECT_VBR    |
@@ -334,16 +332,6 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
                }
        }
 
-       if (data->ocd_connect_flags & OBD_CONNECT_MDS_CAPA) {
-               LCONSOLE_INFO("client enabled MDS capability!\n");
-               sbi->ll_flags |= LL_SBI_MDS_CAPA;
-       }
-
-       if (data->ocd_connect_flags & OBD_CONNECT_OSS_CAPA) {
-               LCONSOLE_INFO("client enabled OSS capability!\n");
-               sbi->ll_flags |= LL_SBI_OSS_CAPA;
-       }
-
        if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
                sbi->ll_flags |= LL_SBI_64BIT_HASH;
 
@@ -445,7 +433,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
        mutex_unlock(&sbi->ll_lco.lco_lock);
 
        fid_zero(&sbi->ll_root_fid);
-       err = md_getstatus(sbi->ll_md_exp, &sbi->ll_root_fid, &oc);
+       err = md_getstatus(sbi->ll_md_exp, &sbi->ll_root_fid);
        if (err) {
                CERROR("cannot mds_connect: rc = %d\n", err);
                goto out_lock_cn_cb;
@@ -466,7 +454,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
 
        /* make root inode
         * XXX: move this to after cbd setup? */
-       valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMDSCAPA;
+       valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS;
        if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
                valid |= OBD_MD_FLRMTPERM;
        else if (sbi->ll_flags & LL_SBI_ACL)
@@ -480,12 +468,9 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
 
        op_data->op_fid1 = sbi->ll_root_fid;
        op_data->op_mode = 0;
-       op_data->op_capa1 = oc;
        op_data->op_valid = valid;
 
        err = md_getattr(sbi->ll_md_exp, op_data, &request);
-       if (oc)
-               capa_put(oc);
        kfree(op_data);
        if (err) {
                CERROR("%s: md_getattr failed for root: rc = %d\n",
@@ -619,32 +604,6 @@ int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
        return rc;
 }
 
-int ll_get_max_cookiesize(struct ll_sb_info *sbi, int *lmmsize)
-{
-       int size, rc;
-
-       size = sizeof(int);
-       rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_COOKIESIZE),
-                         KEY_MAX_COOKIESIZE, &size, lmmsize, NULL);
-       if (rc)
-               CERROR("Get max cookiesize error rc %d\n", rc);
-
-       return rc;
-}
-
-int ll_get_default_cookiesize(struct ll_sb_info *sbi, int *lmmsize)
-{
-       int size, rc;
-
-       size = sizeof(int);
-       rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_COOKIESIZE),
-                         KEY_DEFAULT_COOKIESIZE, &size, lmmsize, NULL);
-       if (rc)
-               CERROR("Get default cookiesize error rc %d\n", rc);
-
-       return rc;
-}
-
 static void client_common_put_super(struct super_block *sb)
 {
        struct ll_sb_info *sbi = ll_s2sbi(sb);
@@ -838,9 +797,7 @@ void ll_lli_init(struct ll_inode_info *lli)
        /* Do not set lli_fid, it has been initialized already. */
        fid_zero(&lli->lli_pfid);
        INIT_LIST_HEAD(&lli->lli_close_list);
-       INIT_LIST_HEAD(&lli->lli_oss_capas);
        atomic_set(&lli->lli_open_count, 0);
-       lli->lli_mds_capa = NULL;
        lli->lli_rmtperm_time = 0;
        lli->lli_pending_och = NULL;
        lli->lli_mds_read_och = NULL;
@@ -994,8 +951,6 @@ void ll_put_super(struct super_block *sb)
 
        CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
 
-       ll_print_capa_stat(sbi);
-
        cfg.cfg_instance = sb;
        lustre_end_log(sb, profilenm, &cfg);
 
@@ -1126,7 +1081,6 @@ void ll_clear_inode(struct inode *inode)
 #endif
        lli->lli_inode_magic = LLI_INODE_DEAD;
 
-       ll_clear_inode_capas(inode);
        if (!S_ISDIR(inode->i_mode))
                LASSERT(list_empty(&lli->lli_agl_list));
 
@@ -1183,7 +1137,7 @@ static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data,
        }
 
        ia_valid = op_data->op_attr.ia_valid;
-       /* inode size will be in ll_setattr_ost, can't do it now since dirty
+       /* inode size will be in cl_setattr_ost, can't do it now since dirty
         * cache is not cleared yet. */
        op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
        rc = simple_setattr(dentry, &op_data->op_attr);
@@ -1219,38 +1173,16 @@ static int ll_setattr_done_writing(struct inode *inode,
        ll_pack_inode2opdata(inode, op_data, NULL);
 
        rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, mod);
-       if (rc == -EAGAIN) {
+       if (rc == -EAGAIN)
                /* MDS has instructed us to obtain Size-on-MDS attribute
                 * from OSTs and send setattr to back to MDS. */
                rc = ll_som_update(inode, op_data);
-       } else if (rc) {
+       else if (rc)
                CERROR("inode %lu mdc truncate failed: rc = %d\n",
                       inode->i_ino, rc);
-       }
-       return rc;
-}
-
-static int ll_setattr_ost(struct inode *inode, struct iattr *attr)
-{
-       struct obd_capa *capa;
-       int rc;
-
-       if (attr->ia_valid & ATTR_SIZE)
-               capa = ll_osscapa_get(inode, CAPA_OPC_OSS_TRUNC);
-       else
-               capa = ll_mdscapa_get(inode);
-
-       rc = cl_setattr_ost(inode, attr, capa);
-
-       if (attr->ia_valid & ATTR_SIZE)
-               ll_truncate_free_capa(capa);
-       else
-               capa_put(capa);
-
        return rc;
 }
 
-
 /* If this inode has objects allocated to it (lsm != NULL), then the OST
  * object(s) determine the file size and mtime.  Otherwise, the MDS will
  * keep these values until such a time that objects are allocated for it.
@@ -1325,9 +1257,9 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
        }
 
        if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
-               CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
+               CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %llu\n",
                       LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
-                      get_seconds());
+                      (s64)ktime_get_real_seconds());
 
        /* If we are changing file size, file content is modified, flag it. */
        if (attr->ia_valid & ATTR_SIZE) {
@@ -1413,19 +1345,18 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
                 * time de-synchronization between MDT inode and OST objects */
                if (attr->ia_valid & ATTR_SIZE)
                        down_write(&lli->lli_trunc_sem);
-               rc = ll_setattr_ost(inode, attr);
+               rc = cl_setattr_ost(inode, attr);
                if (attr->ia_valid & ATTR_SIZE)
                        up_write(&lli->lli_trunc_sem);
        }
 out:
-       if (op_data) {
-               if (op_data->op_ioepoch) {
-                       rc1 = ll_setattr_done_writing(inode, op_data, mod);
-                       if (!rc)
-                               rc = rc1;
-               }
-               ll_finish_md_op_data(op_data);
+       if (op_data->op_ioepoch) {
+               rc1 = ll_setattr_done_writing(inode, op_data, mod);
+               if (!rc)
+                       rc = rc1;
        }
+       ll_finish_md_op_data(op_data);
+
        if (!S_ISDIR(inode->i_mode)) {
                mutex_lock(&inode->i_mutex);
                if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
@@ -1517,6 +1448,7 @@ int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
 
        return rc;
 }
+
 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
 {
        struct super_block *sb = de->d_sb;
@@ -1706,15 +1638,6 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
                        inode->i_blocks = body->blocks;
        }
 
-       if (body->valid & OBD_MD_FLMDSCAPA) {
-               LASSERT(md->mds_capa);
-               ll_add_capa(inode, md->mds_capa);
-       }
-       if (body->valid & OBD_MD_FLOSSCAPA) {
-               LASSERT(md->oss_capa);
-               ll_add_capa(inode, md->oss_capa);
-       }
-
        if (body->valid & OBD_MD_TSTATE) {
                if (body->t_state & MS_RESTORE)
                        lli->lli_flags |= LLIF_FILE_RESTORING;
@@ -1825,7 +1748,7 @@ int ll_iocontrol(struct inode *inode, struct file *file,
        }
        case FSFILT_IOC_SETFLAGS: {
                struct lov_stripe_md *lsm;
-               struct obd_info oinfo = { { { 0 } } };
+               struct obd_info oinfo = { };
                struct md_op_data *op_data;
 
                if (get_user(flags, (int *)arg))
@@ -1853,7 +1776,8 @@ int ll_iocontrol(struct inode *inode, struct file *file,
                        return 0;
                }
 
-               OBDO_ALLOC(oinfo.oi_oa);
+               oinfo.oi_oa = kmem_cache_alloc(obdo_cachep,
+                                              GFP_NOFS | __GFP_ZERO);
                if (!oinfo.oi_oa) {
                        ccc_inode_lsm_put(inode, lsm);
                        return -ENOMEM;
@@ -1863,11 +1787,9 @@ int ll_iocontrol(struct inode *inode, struct file *file,
                oinfo.oi_oa->o_flags = flags;
                oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS |
                                       OBD_MD_FLGROUP;
-               oinfo.oi_capa = ll_mdscapa_get(inode);
                obdo_set_parent_fid(oinfo.oi_oa, &ll_i2info(inode)->lli_fid);
                rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
-               capa_put(oinfo.oi_capa);
-               OBDO_FREE(oinfo.oi_oa);
+               kmem_cache_free(obdo_cachep, oinfo.oi_oa);
                ccc_inode_lsm_put(inode, lsm);
 
                if (rc && rc != -EPERM && rc != -EACCES)
@@ -1974,6 +1896,47 @@ int ll_remount_fs(struct super_block *sb, int *flags, char *data)
        return 0;
 }
 
+/**
+ * Cleanup the open handle that is cached on MDT-side.
+ *
+ * For open case, the client side open handling thread may hit error
+ * after the MDT grant the open. Under such case, the client should
+ * send close RPC to the MDT as cleanup; otherwise, the open handle
+ * on the MDT will be leaked there until the client umount or evicted.
+ *
+ * In further, if someone unlinked the file, because the open handle
+ * holds the reference on such file/object, then it will block the
+ * subsequent threads that want to locate such object via FID.
+ *
+ * \param[in] sb       super block for this file-system
+ * \param[in] open_req pointer to the original open request
+ */
+void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
+{
+       struct mdt_body                 *body;
+       struct md_op_data               *op_data;
+       struct ptlrpc_request           *close_req = NULL;
+       struct obd_export               *exp       = ll_s2sbi(sb)->ll_md_exp;
+
+       body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
+       op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
+       if (!op_data) {
+               CWARN("%s: cannot allocate op_data to release open handle for "
+                     DFID "\n",
+                     ll_get_fsname(sb, NULL, 0), PFID(&body->fid1));
+
+               return;
+       }
+
+       op_data->op_fid1 = body->fid1;
+       op_data->op_ioepoch = body->ioepoch;
+       op_data->op_handle = body->handle;
+       op_data->op_mod_time = get_seconds();
+       md_close(exp, op_data, NULL, &close_req);
+       ptlrpc_req_finished(close_req);
+       ll_finish_md_op_data(op_data);
+}
+
 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
                  struct super_block *sb, struct lookup_intent *it)
 {
@@ -1986,7 +1949,7 @@ int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
        rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
                              sbi->ll_md_exp, &md);
        if (rc)
-               return rc;
+               goto cleanup;
 
        if (*inode) {
                ll_update_inode(*inode, &md);
@@ -2048,6 +2011,11 @@ out:
        if (md.lsm != NULL)
                obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
        md_free_lustre_md(sbi->ll_md_exp, &md);
+
+cleanup:
+       if (rc != 0 && it && it->it_op & IT_OPEN)
+               ll_open_cleanup(sb ? sb : (*inode)->i_sb, req);
+
        return rc;
 }
 
@@ -2160,20 +2128,16 @@ struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
 
        ll_i2gids(op_data->op_suppgids, i1, i2);
        op_data->op_fid1 = *ll_inode2fid(i1);
-       op_data->op_capa1 = ll_mdscapa_get(i1);
 
-       if (i2) {
+       if (i2)
                op_data->op_fid2 = *ll_inode2fid(i2);
-               op_data->op_capa2 = ll_mdscapa_get(i2);
-       } else {
+       else
                fid_zero(&op_data->op_fid2);
-               op_data->op_capa2 = NULL;
-       }
 
        op_data->op_name = name;
        op_data->op_namelen = namelen;
        op_data->op_mode = mode;
-       op_data->op_mod_time = get_seconds();
+       op_data->op_mod_time = ktime_get_real_seconds();
        op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
        op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
        op_data->op_cap = cfs_curproc_cap_pack();
@@ -2197,11 +2161,10 @@ struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
                if (likely(!lli->lli_has_smd && !fid_is_zero(&lli->lli_pfid)))
                        op_data->op_fid1 = lli->lli_pfid;
                spin_unlock(&lli->lli_lock);
-               /** We ignore parent's capability temporary. */
        }
 
        /* When called by ll_setattr_raw, file is i1. */
-       if (LLIF_DATA_MODIFIED & ll_i2info(i1)->lli_flags)
+       if (ll_i2info(i1)->lli_flags & LLIF_DATA_MODIFIED)
                op_data->op_bias |= MDS_DATA_MODIFIED;
 
        return op_data;
@@ -2209,8 +2172,6 @@ struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
 
 void ll_finish_md_op_data(struct md_op_data *op_data)
 {
-       capa_put(op_data->op_capa1);
-       capa_put(op_data->op_capa2);
        kfree(op_data);
 }
 
index a90214bb84ddfe7f3e32d47d8a901935c1af97bd..7df978371c9a34a69d6a4d80c09fb668062e5ac5 100644 (file)
@@ -258,8 +258,6 @@ out:
        return result;
 }
 
-
-
 static inline int to_fault_error(int result)
 {
        switch (result) {
index 8d1c253d4669b38266e8a945425539894af7367a..e578a1130ad1bfd007ef8c498b06fe4917d07efe 100644 (file)
@@ -49,6 +49,7 @@
 __u32 get_uuid2int(const char *name, int len)
 {
        __u32 key0 = 0x12a3fe2d, key1 = 0x37abe8f9;
+
        while (len--) {
                __u32 key = key1 + (key0 ^ (*name++ * 7152373));
 
@@ -78,8 +79,7 @@ void get_uuid2fsid(const char *name, int len, __kernel_fsid_t *fsid)
 
 static int ll_nfs_test_inode(struct inode *inode, void *opaque)
 {
-       return lu_fid_eq(&ll_i2info(inode)->lli_fid,
-                        (struct lu_fid *)opaque);
+       return lu_fid_eq(&ll_i2info(inode)->lli_fid, opaque);
 }
 
 struct inode *search_inode_for_lustre(struct super_block *sb,
@@ -168,11 +168,8 @@ ll_iget_for_nfs(struct super_block *sb, struct lu_fid *fid, struct lu_fid *paren
                spin_unlock(&lli->lli_lock);
        }
 
+       /* N.B. d_obtain_alias() drops inode ref on error */
        result = d_obtain_alias(inode);
-       if (IS_ERR(result)) {
-               iput(inode);
-               return result;
-       }
 
        return result;
 }
index c8a450b5cb180be5e3a167d7ecab24d4ded2c456..b27c3f2fcd02949b2da82e4e721af6aa6062770b 100644 (file)
@@ -178,7 +178,6 @@ void rct_fini(struct rmtacl_ctl_table *rct)
        spin_unlock(&rct->rct_lock);
 }
 
-
 static struct eacl_entry *ee_alloc(pid_t key, struct lu_fid *fid, int type,
                                   ext_acl_xattr_header *header)
 {
index 5f0d80cc97183e2104c1fcbcd71610750bc08626..e6974c36276d784be00eafcdeaad994a7188bc5d 100644 (file)
@@ -315,7 +315,6 @@ static unsigned int loop_get_bio(struct lloop_device *lo, struct bio **req)
                if (page_count + (*bio)->bi_vcnt > LLOOP_MAX_SEGMENTS)
                        break;
 
-
                page_count += (*bio)->bi_vcnt;
                count++;
                bio = &(*bio)->bi_next;
@@ -370,13 +369,14 @@ err:
        bio_io_error(old_bio);
 }
 
-
 static inline void loop_handle_bio(struct lloop_device *lo, struct bio *bio)
 {
        int ret;
+
        ret = do_bio_lustrebacked(lo, bio);
        while (bio) {
                struct bio *tmp = bio->bi_next;
+
                bio->bi_next = NULL;
                bio->bi_error = ret;
                bio_endio(bio);
@@ -430,6 +430,7 @@ static int loop_thread(void *data)
                wait_event(lo->lo_bh_wait, loop_active(lo));
                if (!atomic_read(&lo->lo_pending)) {
                        int exiting = 0;
+
                        spin_lock_irq(&lo->lo_lock);
                        exiting = (lo->lo_state == LLOOP_RUNDOWN);
                        spin_unlock_irq(&lo->lo_lock);
index 486dca6077de2e692d1bc0b7d58751be4a664b2b..190fc44114e1cd4fe0e2a51e9e32c855fcdf1225 100644 (file)
@@ -218,6 +218,7 @@ static int ll_site_stats_seq_show(struct seq_file *m, void *v)
         */
        return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site), m);
 }
+
 LPROC_SEQ_FOPS_RO(ll_site_stats);
 
 static ssize_t max_read_ahead_mb_show(struct kobject *kobj,
@@ -478,6 +479,7 @@ out:
        }
        return rc;
 }
+
 LPROC_SEQ_FOPS(ll_max_cached_mb);
 
 static ssize_t checksum_pages_show(struct kobject *kobj, struct attribute *attr,
@@ -684,6 +686,7 @@ static int ll_statahead_stats_seq_show(struct seq_file *m, void *v)
                   atomic_read(&sbi->ll_agl_total));
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(ll_statahead_stats);
 
 static ssize_t lazystatfs_show(struct kobject *kobj,
@@ -775,6 +778,7 @@ static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
        seq_printf(m, "\b\n");
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(ll_sbi_flags);
 
 static ssize_t xattr_cache_show(struct kobject *kobj,
@@ -960,7 +964,6 @@ int ldebugfs_register_mountpoint(struct dentry *parent,
        char name[MAX_STRING_SIZE + 1], *ptr;
        int err, id, len, rc;
 
-
        name[MAX_STRING_SIZE] = '\0';
 
        LASSERT(sbi != NULL);
@@ -1017,6 +1020,7 @@ int ldebugfs_register_mountpoint(struct dentry *parent,
        for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
                __u32 type = llite_opcode_table[id].type;
                void *ptr = NULL;
+
                if (type & LPROCFS_TYPE_REGS)
                        ptr = "regs";
                else if (type & LPROCFS_TYPE_BYTES)
@@ -1049,7 +1053,6 @@ int ldebugfs_register_mountpoint(struct dentry *parent,
        if (err)
                goto out;
 
-
        err = ldebugfs_add_vars(sbi->ll_debugfs_entry,
                                lprocfs_llite_obd_vars, sb);
        if (err)
@@ -1094,6 +1097,7 @@ void ldebugfs_unregister_mountpoint(struct ll_sb_info *sbi)
                lprocfs_free_stats(&sbi->ll_stats);
        }
 }
+
 #undef MAX_STRING_SIZE
 
 #define pct(a, b) (b ? a * 100 / b : 0)
@@ -1140,20 +1144,20 @@ static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
 
 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
 {
-       struct timeval now;
+       struct timespec64 now;
        struct ll_sb_info *sbi = seq->private;
        struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
        int k;
 
-       do_gettimeofday(&now);
+       ktime_get_real_ts64(&now);
 
        if (!sbi->ll_rw_stats_on) {
                seq_printf(seq, "disabled\n"
                           "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
                return 0;
        }
-       seq_printf(seq, "snapshot_time:  %lu.%lu (secs.usecs)\n",
-                  now.tv_sec, (unsigned long)now.tv_usec);
+       seq_printf(seq, "snapshot_time:  %llu.%09lu (secs.usecs)\n",
+                  (s64)now.tv_sec, (unsigned long)now.tv_nsec);
        seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
        seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
                   "extents", "calls", "%", "cum%",
@@ -1219,19 +1223,19 @@ LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
 
 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
 {
-       struct timeval now;
+       struct timespec64 now;
        struct ll_sb_info *sbi = seq->private;
        struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
 
-       do_gettimeofday(&now);
+       ktime_get_real_ts64(&now);
 
        if (!sbi->ll_rw_stats_on) {
                seq_printf(seq, "disabled\n"
                           "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
                return 0;
        }
-       seq_printf(seq, "snapshot_time:  %lu.%lu (secs.usecs)\n",
-                  now.tv_sec, (unsigned long)now.tv_usec);
+       seq_printf(seq, "snapshot_time:  %llu.%09lu (secs.usecs)\n",
+                  (u64)now.tv_sec, (unsigned long)now.tv_nsec);
 
        seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
        seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
@@ -1288,6 +1292,7 @@ static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
 
        return len;
 }
+
 LPROC_SEQ_FOPS(ll_rw_extents_stats);
 
 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
@@ -1325,8 +1330,9 @@ void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
                lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
        }
 
-       for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
-            (i < (LL_HIST_MAX - 1)); i++);
+       for (i = 0; (count >= (1 << LL_HIST_START << i)) &&
+            (i < (LL_HIST_MAX - 1)); i++)
+               ;
        if (rw == 0) {
                io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
                io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
@@ -1395,13 +1401,13 @@ void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
 
 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
 {
-       struct timeval now;
+       struct timespec64 now;
        struct ll_sb_info *sbi = seq->private;
        struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
        struct ll_rw_process_info *process = sbi->ll_rw_process_info;
        int i;
 
-       do_gettimeofday(&now);
+       ktime_get_real_ts64(&now);
 
        if (!sbi->ll_rw_stats_on) {
                seq_printf(seq, "disabled\n"
@@ -1410,8 +1416,8 @@ static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
        }
        spin_lock(&sbi->ll_process_lock);
 
-       seq_printf(seq, "snapshot_time:  %lu.%lu (secs.usecs)\n",
-                  now.tv_sec, (unsigned long)now.tv_usec);
+       seq_printf(seq, "snapshot_time:  %llu.%09lu (secs.usecs)\n",
+                  (s64)now.tv_sec, (unsigned long)now.tv_nsec);
        seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
                   "R/W", "PID", "RANGE START", "RANGE END",
                   "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
index 05e7dc85989edde49566857d9fec19d6539b3f94..2ca22001a534d87759e644151da517368338ad4a 100644 (file)
@@ -100,7 +100,6 @@ static int ll_set_inode(struct inode *inode, void *opaque)
        return 0;
 }
 
-
 /*
  * Get an inode by inode number (already instantiated by the intent lookup).
  * Returns inode or NULL
@@ -409,7 +408,7 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
 {
        struct inode *inode = NULL;
        __u64 bits = 0;
-       int rc;
+       int rc = 0;
 
        /* NB 1 request reference will be taken away by ll_intent_lock()
         * when I return */
@@ -439,8 +438,10 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
                struct dentry *alias;
 
                alias = ll_splice_alias(inode, *de);
-               if (IS_ERR(alias))
-                       return PTR_ERR(alias);
+               if (IS_ERR(alias)) {
+                       rc = PTR_ERR(alias);
+                       goto out;
+               }
                *de = alias;
        } else if (!it_disposition(it, DISP_LOOKUP_NEG)  &&
                   !it_disposition(it, DISP_OPEN_CREATE)) {
@@ -471,7 +472,11 @@ static int ll_lookup_it_finish(struct ptlrpc_request *request,
                }
        }
 
-       return 0;
+out:
+       if (rc != 0 && it->it_op & IT_OPEN)
+               ll_open_cleanup((*de)->d_sb, request);
+
+       return rc;
 }
 
 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
@@ -668,7 +673,6 @@ out_release:
        return rc;
 }
 
-
 /* We depend on "mode" being set with the proper file type/umask by now */
 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
 {
@@ -864,34 +868,6 @@ static inline void ll_get_child_fid(struct dentry *child, struct lu_fid *fid)
                *fid = *ll_inode2fid(d_inode(child));
 }
 
-/**
- * Remove dir entry
- **/
-int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
-{
-       struct ptlrpc_request *request = NULL;
-       struct md_op_data *op_data;
-       int rc;
-
-       CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s,dir=%lu/%u(%p)\n",
-              namelen, name, dir->i_ino, dir->i_generation, dir);
-
-       op_data = ll_prep_md_op_data(NULL, dir, NULL, name, strlen(name),
-                                    S_IFDIR, LUSTRE_OPC_ANY, NULL);
-       if (IS_ERR(op_data))
-               return PTR_ERR(op_data);
-       op_data->op_cli_flags |= CLI_RM_ENTRY;
-       rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
-       ll_finish_md_op_data(op_data);
-       if (rc == 0) {
-               ll_update_times(request, dir);
-               ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
-       }
-
-       ptlrpc_req_finished(request);
-       return rc;
-}
-
 int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
 {
        struct mdt_body *body;
@@ -899,7 +875,6 @@ int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
        struct lov_stripe_md *lsm = NULL;
        struct obd_trans_info oti = { 0 };
        struct obdo *oa;
-       struct obd_capa *oc = NULL;
        int rc;
 
        /* req is swabbed so this is safe */
@@ -928,7 +903,7 @@ int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
        }
        LASSERT(rc >= sizeof(*lsm));
 
-       OBDO_ALLOC(oa);
+       oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
        if (oa == NULL) {
                rc = -ENOMEM;
                goto out_free_memmd;
@@ -951,21 +926,14 @@ int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
                }
        }
 
-       if (body->valid & OBD_MD_FLOSSCAPA) {
-               rc = md_unpack_capa(ll_i2mdexp(dir), request, &RMF_CAPA2, &oc);
-               if (rc)
-                       goto out_free_memmd;
-       }
-
        rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti,
-                        ll_i2mdexp(dir), oc);
-       capa_put(oc);
+                        ll_i2mdexp(dir));
        if (rc)
                CERROR("obd destroy objid "DOSTID" error %d\n",
                       POSTID(&lsm->lsm_oi), rc);
 out_free_memmd:
        obd_free_memmd(ll_i2dtexp(dir), &lsm);
-       OBDO_FREE(oa);
+       kmem_cache_free(obdo_cachep, oa);
 out:
        return rc;
 }
index 39022ea88b5f5744f8b61fca48701225e6ce3e65..c902133dfc97256f1444c6ba69f540f66d988324 100644 (file)
@@ -61,7 +61,7 @@ static inline struct ll_remote_perm *alloc_ll_remote_perm(void)
 {
        struct ll_remote_perm *lrp;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lrp, ll_remote_perm_cachep, GFP_KERNEL);
+       lrp = kmem_cache_alloc(ll_remote_perm_cachep, GFP_KERNEL | __GFP_ZERO);
        if (lrp)
                INIT_HLIST_NODE(&lrp->lrp_list);
        return lrp;
@@ -74,7 +74,7 @@ static inline void free_ll_remote_perm(struct ll_remote_perm *lrp)
 
        if (!hlist_unhashed(&lrp->lrp_list))
                hlist_del(&lrp->lrp_list);
-       OBD_SLAB_FREE(lrp, ll_remote_perm_cachep, sizeof(*lrp));
+       kmem_cache_free(ll_remote_perm_cachep, lrp);
 }
 
 static struct hlist_head *alloc_rmtperm_hash(void)
@@ -82,9 +82,7 @@ static struct hlist_head *alloc_rmtperm_hash(void)
        struct hlist_head *hash;
        int i;
 
-       OBD_SLAB_ALLOC_GFP(hash, ll_rmtperm_hash_cachep,
-                          REMOTE_PERM_HASHSIZE * sizeof(*hash),
-                          GFP_IOFS);
+       hash = kmem_cache_alloc(ll_rmtperm_hash_cachep, GFP_IOFS | __GFP_ZERO);
        if (!hash)
                return NULL;
 
@@ -106,8 +104,7 @@ void free_rmtperm_hash(struct hlist_head *hash)
        for (i = 0; i < REMOTE_PERM_HASHSIZE; i++)
                hlist_for_each_entry_safe(lrp, next, hash + i, lrp_list)
                        free_ll_remote_perm(lrp);
-       OBD_SLAB_FREE(hash, ll_rmtperm_hash_cachep,
-                     REMOTE_PERM_HASHSIZE * sizeof(*hash));
+       kmem_cache_free(ll_rmtperm_hash_cachep, hash);
 }
 
 static inline int remote_perm_hashfunc(uid_t uid)
@@ -249,7 +246,6 @@ int lustre_check_remote_perm(struct inode *inode, int mask)
        struct ll_sb_info *sbi = ll_i2sbi(inode);
        struct ptlrpc_request *req = NULL;
        struct mdt_remote_perm *perm;
-       struct obd_capa *oc;
        unsigned long save;
        int i = 0, rc;
 
@@ -276,10 +272,8 @@ int lustre_check_remote_perm(struct inode *inode, int mask)
                        LBUG();
                }
 
-               oc = ll_mdscapa_get(inode);
-               rc = md_get_remote_perm(sbi->ll_md_exp, ll_inode2fid(inode), oc,
+               rc = md_get_remote_perm(sbi->ll_md_exp, ll_inode2fid(inode),
                                        ll_i2suppgid(inode), &req);
-               capa_put(oc);
                if (rc) {
                        mutex_unlock(&lli->lli_rmtperm_mutex);
                        break;
index 991d20c5065d3d0e83b169614cc474c54fa6d46d..f79193fa2fb7727d9450f016f746d2d9b6ca742c 100644 (file)
@@ -277,14 +277,6 @@ int ll_commit_write(struct file *file, struct page *vmpage, unsigned from,
        return result;
 }
 
-struct obd_capa *cl_capa_lookup(struct inode *inode, enum cl_req_type crt)
-{
-       __u64 opc;
-
-       opc = crt == CRT_WRITE ? CAPA_OPC_OSS_WRITE : CAPA_OPC_OSS_RW;
-       return ll_osscapa_get(inode, opc);
-}
-
 static void ll_ra_stats_inc_sbi(struct ll_sb_info *sbi, enum ra_stat which);
 
 /**
@@ -335,6 +327,7 @@ static unsigned long ll_ra_count_get(struct ll_sb_info *sbi,
         * the RPC boundary from needing an extra read RPC. */
        if (ria->ria_pages == 0) {
                long beyond_rpc = (ria->ria_start + ret) % PTLRPC_MAX_BRW_PAGES;
+
                if (/* beyond_rpc != 0 && */ beyond_rpc < ret)
                        ret -= beyond_rpc;
        }
@@ -351,6 +344,7 @@ out:
 void ll_ra_count_put(struct ll_sb_info *sbi, unsigned long len)
 {
        struct ll_ra_info *ra = &sbi->ll_ra_info;
+
        atomic_sub(len, &ra->ra_cur_pages);
 }
 
@@ -363,6 +357,7 @@ static void ll_ra_stats_inc_sbi(struct ll_sb_info *sbi, enum ra_stat which)
 void ll_ra_stats_inc(struct address_space *mapping, enum ra_stat which)
 {
        struct ll_sb_info *sbi = ll_i2sbi(mapping->host);
+
        ll_ra_stats_inc_sbi(sbi, which);
 }
 
@@ -425,30 +420,6 @@ void ll_ra_read_ex(struct file *f, struct ll_ra_read *rar)
        spin_unlock(&ras->ras_lock);
 }
 
-static struct ll_ra_read *ll_ra_read_get_locked(struct ll_readahead_state *ras)
-{
-       struct ll_ra_read *scan;
-
-       list_for_each_entry(scan, &ras->ras_read_beads, lrr_linkage) {
-               if (scan->lrr_reader == current)
-                       return scan;
-       }
-       return NULL;
-}
-
-struct ll_ra_read *ll_ra_read_get(struct file *f)
-{
-       struct ll_readahead_state *ras;
-       struct ll_ra_read        *bead;
-
-       ras = ll_ras_get(f);
-
-       spin_lock(&ras->ras_lock);
-       bead = ll_ra_read_get_locked(ras);
-       spin_unlock(&ras->ras_lock);
-       return bead;
-}
-
 static int cl_read_ahead_page(const struct lu_env *env, struct cl_io *io,
                              struct cl_page_list *queue, struct cl_page *page,
                              struct page *vmpage)
@@ -557,6 +528,7 @@ static inline int stride_io_mode(struct ll_readahead_state *ras)
 {
        return ras->ras_consecutive_stride_requests > 1;
 }
+
 /* The function calculates how much pages will be read in
  * [off, off + length], in such stride IO area,
  * stride_offset = st_off, stride_length = st_len,
@@ -656,7 +628,7 @@ static int ll_read_ahead_pages(const struct lu_env *env,
                                                page_idx, mapping);
                        if (rc == 1) {
                                (*reserved_pages)--;
-                               count ++;
+                               count++;
                        } else if (rc == -ENOLCK)
                                break;
                } else if (stride_ria) {
@@ -890,7 +862,7 @@ static void ras_update_stride_detector(struct ll_readahead_state *ras,
        if (!stride_io_mode(ras) && (stride_gap != 0 ||
             ras->ras_consecutive_stride_requests == 0)) {
                ras->ras_stride_pages = ras->ras_consecutive_pages;
-               ras->ras_stride_length = stride_gap +ras->ras_consecutive_pages;
+               ras->ras_stride_length = stride_gap+ras->ras_consecutive_pages;
        }
        LASSERT(ras->ras_request_index == 0);
        LASSERT(ras->ras_consecutive_stride_requests == 0);
@@ -902,7 +874,7 @@ static void ras_update_stride_detector(struct ll_readahead_state *ras,
        }
 
        ras->ras_stride_pages = ras->ras_consecutive_pages;
-       ras->ras_stride_length = stride_gap +ras->ras_consecutive_pages;
+       ras->ras_stride_length = stride_gap+ras->ras_consecutive_pages;
 
        RAS_CDEBUG(ras);
        return;
index b17b7cea582cacb353bb33f8aa3350096859e8d0..3da4c01e2159684faf4e8b63c3d706be08622bf2 100644 (file)
@@ -418,6 +418,7 @@ static ssize_t ll_direct_IO_26(struct kiocb *iocb, struct iov_iter *iter,
                result = iov_iter_get_pages_alloc(iter, &pages, count, &offs);
                if (likely(result > 0)) {
                        int n = DIV_ROUND_UP(result + offs, PAGE_SIZE);
+
                        result = ll_direct_IO_26_seg(env, io, iov_iter_rw(iter),
                                                     inode, file->f_mapping,
                                                     result, file_offset, pages,
index f97371dd8539f6fef6aabab90ba4ba56468f83c0..18f5f2b7e90209e38a9e1a67fc8d54ce758654e3 100644 (file)
@@ -659,7 +659,7 @@ static void ll_post_statahead(struct ll_statahead_info *sai)
                 * revalidate.
                 */
                /* unlinked and re-created with the same name */
-               if (unlikely(!lu_fid_eq(&minfo->mi_data.op_fid2, &body->fid1))){
+               if (unlikely(!lu_fid_eq(&minfo->mi_data.op_fid2, &body->fid1))) {
                        entry->se_inode = NULL;
                        iput(child);
                        child = NULL;
@@ -784,25 +784,16 @@ static void sa_args_fini(struct md_enqueue_info *minfo,
 {
        LASSERT(minfo && einfo);
        iput(minfo->mi_dir);
-       capa_put(minfo->mi_data.op_capa1);
-       capa_put(minfo->mi_data.op_capa2);
        kfree(minfo);
        kfree(einfo);
 }
 
 /**
- * There is race condition between "capa_put" and "ll_statahead_interpret" for
- * accessing "op_data.op_capa[1,2]" as following:
- * "capa_put" releases "op_data.op_capa[1,2]"'s reference count after calling
- * "md_intent_getattr_async". But "ll_statahead_interpret" maybe run first, and
- * fill "op_data.op_capa[1,2]" as POISON, then cause "capa_put" access invalid
- * "ocapa". So here reserve "op_data.op_capa[1,2]" in "pcapa" before calling
- * "md_intent_getattr_async".
+ * prepare arguments for async stat RPC.
  */
 static int sa_args_init(struct inode *dir, struct inode *child,
                        struct ll_sa_entry *entry, struct md_enqueue_info **pmi,
-                       struct ldlm_enqueue_info **pei,
-                       struct obd_capa **pcapa)
+                       struct ldlm_enqueue_info **pei)
 {
        struct qstr           *qstr = &entry->se_qstr;
        struct ll_inode_info     *lli  = ll_i2info(dir);
@@ -843,8 +834,6 @@ static int sa_args_init(struct inode *dir, struct inode *child,
 
        *pmi = minfo;
        *pei = einfo;
-       pcapa[0] = op_data->op_capa1;
-       pcapa[1] = op_data->op_capa2;
 
        return 0;
 }
@@ -853,20 +842,15 @@ static int do_sa_lookup(struct inode *dir, struct ll_sa_entry *entry)
 {
        struct md_enqueue_info   *minfo;
        struct ldlm_enqueue_info *einfo;
-       struct obd_capa   *capas[2];
        int                    rc;
 
-       rc = sa_args_init(dir, NULL, entry, &minfo, &einfo, capas);
+       rc = sa_args_init(dir, NULL, entry, &minfo, &einfo);
        if (rc)
                return rc;
 
        rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo, einfo);
-       if (!rc) {
-               capa_put(capas[0]);
-               capa_put(capas[1]);
-       } else {
+       if (rc < 0)
                sa_args_fini(minfo, einfo);
-       }
 
        return rc;
 }
@@ -885,7 +869,6 @@ static int do_sa_revalidate(struct inode *dir, struct ll_sa_entry *entry,
                                         .d.lustre.it_lock_handle = 0 };
        struct md_enqueue_info   *minfo;
        struct ldlm_enqueue_info *einfo;
-       struct obd_capa   *capas[2];
        int rc;
 
        if (unlikely(inode == NULL))
@@ -903,7 +886,7 @@ static int do_sa_revalidate(struct inode *dir, struct ll_sa_entry *entry,
                return 1;
        }
 
-       rc = sa_args_init(dir, inode, entry, &minfo, &einfo, capas);
+       rc = sa_args_init(dir, inode, entry, &minfo, &einfo);
        if (rc) {
                entry->se_inode = NULL;
                iput(inode);
@@ -911,10 +894,7 @@ static int do_sa_revalidate(struct inode *dir, struct ll_sa_entry *entry,
        }
 
        rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo, einfo);
-       if (!rc) {
-               capa_put(capas[0]);
-               capa_put(capas[1]);
-       } else {
+       if (rc < 0) {
                entry->se_inode = NULL;
                iput(inode);
                sa_args_fini(minfo, einfo);
@@ -967,7 +947,7 @@ static void ll_statahead_one(struct dentry *parent, const char *entry_name,
 
 static int ll_agl_thread(void *arg)
 {
-       struct dentry       *parent = (struct dentry *)arg;
+       struct dentry       *parent = arg;
        struct inode         *dir    = d_inode(parent);
        struct ll_inode_info     *plli   = ll_i2info(dir);
        struct ll_inode_info     *clli;
@@ -1058,7 +1038,7 @@ static void ll_start_agl(struct dentry *parent, struct ll_statahead_info *sai)
 
 static int ll_statahead_thread(void *arg)
 {
-       struct dentry       *parent = (struct dentry *)arg;
+       struct dentry       *parent = arg;
        struct inode         *dir    = d_inode(parent);
        struct ll_inode_info     *plli   = ll_i2info(dir);
        struct ll_inode_info     *clli;
@@ -1215,7 +1195,7 @@ do_it:
                        while (1) {
                                l_wait_event(thread->t_ctl_waitq,
                                             !sa_received_empty(sai) ||
-                                            sai->sai_sent == sai->sai_replied||
+                                            sai->sai_sent == sai->sai_replied ||
                                             !thread_is_running(thread),
                                             &lwi);
 
index e4020ce8cb7b85d8c771f42b05cc9c77335709cd..0131368606644fc0b6ef2259878fefb5c00e50ea 100644 (file)
@@ -51,8 +51,9 @@ static struct kmem_cache *ll_inode_cachep;
 static struct inode *ll_alloc_inode(struct super_block *sb)
 {
        struct ll_inode_info *lli;
+
        ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_ALLOC_INODE, 1);
-       OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
+       lli = kmem_cache_alloc(ll_inode_cachep, GFP_NOFS | __GFP_ZERO);
        if (lli == NULL)
                return NULL;
 
@@ -64,7 +65,8 @@ static void ll_inode_destroy_callback(struct rcu_head *head)
 {
        struct inode *inode = container_of(head, struct inode, i_rcu);
        struct ll_inode_info *ptr = ll_i2info(inode);
-       OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
+
+       kmem_cache_free(ll_inode_cachep, ptr);
 }
 
 static void ll_destroy_inode(struct inode *inode)
@@ -90,7 +92,7 @@ void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg));
 static int __init init_lustre_lite(void)
 {
        lnet_process_id_t lnet_id;
-       struct timeval tv;
+       struct timespec64 ts;
        int i, rc, seed[2];
 
        CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1);
@@ -152,16 +154,12 @@ static int __init init_lustre_lite(void)
                        seed[0] ^= LNET_NIDADDR(lnet_id.nid);
        }
 
-       do_gettimeofday(&tv);
-       cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
-       setup_timer(&ll_capa_timer, ll_capa_timer_callback, 0);
-       rc = ll_capa_thread_start();
-       if (rc != 0)
-               goto out_sysfs;
+       ktime_get_ts64(&ts);
+       cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
 
        rc = vvp_global_init();
        if (rc != 0)
-               goto out_capa;
+               goto out_sysfs;
 
        rc = ll_xattr_init();
        if (rc != 0)
@@ -175,26 +173,15 @@ static int __init init_lustre_lite(void)
 
 out_vvp:
        vvp_global_fini();
-out_capa:
-       del_timer(&ll_capa_timer);
-       ll_capa_thread_stop();
 out_sysfs:
        kset_unregister(llite_kset);
 out_debugfs:
        debugfs_remove(llite_root);
 out_cache:
-       if (ll_inode_cachep != NULL)
-               kmem_cache_destroy(ll_inode_cachep);
-
-       if (ll_file_data_slab != NULL)
-               kmem_cache_destroy(ll_file_data_slab);
-
-       if (ll_remote_perm_cachep != NULL)
-               kmem_cache_destroy(ll_remote_perm_cachep);
-
-       if (ll_rmtperm_hash_cachep != NULL)
-               kmem_cache_destroy(ll_rmtperm_hash_cachep);
-
+       kmem_cache_destroy(ll_inode_cachep);
+       kmem_cache_destroy(ll_file_data_slab);
+       kmem_cache_destroy(ll_remote_perm_cachep);
+       kmem_cache_destroy(ll_rmtperm_hash_cachep);
        return rc;
 }
 
@@ -209,11 +196,6 @@ static void __exit exit_lustre_lite(void)
 
        ll_xattr_fini();
        vvp_global_fini();
-       del_timer(&ll_capa_timer);
-       ll_capa_thread_stop();
-       LASSERTF(capa_count[CAPA_SITE_CLIENT] == 0,
-                "client remaining capa count %d\n",
-                capa_count[CAPA_SITE_CLIENT]);
 
        kmem_cache_destroy(ll_inode_cachep);
        kmem_cache_destroy(ll_rmtperm_hash_cachep);
index b8f6a8779fd3e5385996db7386156d926a09d735..d16d6cfce81a6b99dffa4afb20d87deaa8a4d13a 100644 (file)
@@ -40,7 +40,6 @@
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
-
 #include "../include/obd.h"
 #include "../include/lustre_lite.h"
 #include "llite_internal.h"
@@ -80,7 +79,7 @@ static void *vvp_key_init(const struct lu_context *ctx,
 {
        struct vvp_thread_info *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, vvp_thread_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(vvp_thread_kmem, GFP_NOFS | __GFP_ZERO);
        if (info == NULL)
                info = ERR_PTR(-ENOMEM);
        return info;
@@ -91,7 +90,7 @@ static void vvp_key_fini(const struct lu_context *ctx,
 {
        struct vvp_thread_info *info = data;
 
-       OBD_SLAB_FREE_PTR(info, vvp_thread_kmem);
+       kmem_cache_free(vvp_thread_kmem, info);
 }
 
 static void *vvp_session_key_init(const struct lu_context *ctx,
@@ -99,7 +98,7 @@ static void *vvp_session_key_init(const struct lu_context *ctx,
 {
        struct vvp_session *session;
 
-       OBD_SLAB_ALLOC_PTR_GFP(session, vvp_session_kmem, GFP_NOFS);
+       session = kmem_cache_alloc(vvp_session_kmem, GFP_NOFS | __GFP_ZERO);
        if (session == NULL)
                session = ERR_PTR(-ENOMEM);
        return session;
@@ -110,10 +109,9 @@ static void vvp_session_key_fini(const struct lu_context *ctx,
 {
        struct vvp_session *session = data;
 
-       OBD_SLAB_FREE_PTR(session, vvp_session_kmem);
+       kmem_cache_free(vvp_session_kmem, session);
 }
 
-
 struct lu_context_key vvp_key = {
        .lct_tags = LCT_CL_THREAD,
        .lct_init = vvp_key_init,
@@ -187,7 +185,6 @@ void vvp_global_fini(void)
        lu_kmem_fini(vvp_caches);
 }
 
-
 /*****************************************************************************
  *
  * mirror obd-devices into cl devices.
index 2162bf6c08a78a1948039e6357d66ff68b067fe2..b5a6661d47d5e5ab0485c2417842c0e8cb315aeb 100644 (file)
@@ -39,7 +39,6 @@
 #ifndef VVP_INTERNAL_H
 #define VVP_INTERNAL_H
 
-
 #include "../include/cl_object.h"
 #include "llite_internal.h"
 
index a659962e09c8a49146b80ac74a4ad13356cfa2cb..37773c181729e4e07bdec5f6e9c1e7de0f03902c 100644 (file)
@@ -41,7 +41,6 @@
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
-
 #include "../include/obd.h"
 #include "../include/lustre_lite.h"
 
@@ -109,7 +108,7 @@ static int vvp_io_fault_iter_init(const struct lu_env *env,
 
        LASSERT(inode ==
                file_inode(cl2ccc_io(env, ios)->cui_fd->fd_file));
-       vio->u.fault.ft_mtime = LTIME_S(inode->i_mtime);
+       vio->u.fault.ft_mtime = inode->i_mtime.tv_sec;
        return 0;
 }
 
@@ -643,7 +642,6 @@ static int vvp_io_kernel_fault(struct vvp_fault_io *cfio)
        return -EINVAL;
 }
 
-
 static int vvp_io_fault_start(const struct lu_env *env,
                              const struct cl_io_slice *ios)
 {
@@ -661,7 +659,7 @@ static int vvp_io_fault_start(const struct lu_env *env,
        pgoff_t       last; /* last page in a file data region */
 
        if (fio->ft_executable &&
-           LTIME_S(inode->i_mtime) != vio->u.fault.ft_mtime)
+           inode->i_mtime.tv_sec != vio->u.fault.ft_mtime)
                CWARN("binary "DFID
                      " changed while waiting for the page fault lock\n",
                      PFID(lu_object_fid(&obj->co_lu)));
@@ -698,11 +696,10 @@ static int vvp_io_fault_start(const struct lu_env *env,
 
                /* return +1 to stop cl_io_loop() and ll_fault() will catch
                 * and retry. */
-               result = +1;
+               result = 1;
                goto out;
        }
 
-
        if (fio->ft_mkwrite) {
                pgoff_t last_index;
                /*
@@ -1039,6 +1036,7 @@ static int vvp_io_commit_write(const struct lu_env *env,
                                need_clip = false;
                        } else if (last_index == pg->cp_index) {
                                int size_to = i_size_read(inode) & ~CFS_PAGE_MASK;
+
                                if (to < size_to)
                                        to = size_to;
                        }
index f354e82d4ae7cfa0d5ec54c99be713a9267128fc..f7b1144aadeeabc532b0dab47e2148abb344439e 100644 (file)
@@ -38,7 +38,6 @@
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
-
 #include "../include/obd.h"
 #include "../include/lustre_lite.h"
 
index b6f6d4cb6e41c2eae11850ce3b08af740cb0ccd6..e13afb7e8dca97a29d3775e270ac300b6025db60 100644 (file)
@@ -40,7 +40,6 @@
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
-
 #include "../../include/linux/libcfs/libcfs.h"
 
 #include "../include/obd.h"
@@ -87,9 +86,9 @@ static int vvp_attr_get(const struct lu_env *env, struct cl_object *obj,
         */
 
        attr->cat_size = i_size_read(inode);
-       attr->cat_mtime = LTIME_S(inode->i_mtime);
-       attr->cat_atime = LTIME_S(inode->i_atime);
-       attr->cat_ctime = LTIME_S(inode->i_ctime);
+       attr->cat_mtime = inode->i_mtime.tv_sec;
+       attr->cat_atime = inode->i_atime.tv_sec;
+       attr->cat_ctime = inode->i_ctime.tv_sec;
        attr->cat_blocks = inode->i_blocks;
        attr->cat_uid = from_kuid(&init_user_ns, inode->i_uid);
        attr->cat_gid = from_kgid(&init_user_ns, inode->i_gid);
@@ -107,11 +106,11 @@ static int vvp_attr_set(const struct lu_env *env, struct cl_object *obj,
        if (valid & CAT_GID)
                inode->i_gid = make_kgid(&init_user_ns, attr->cat_gid);
        if (valid & CAT_ATIME)
-               LTIME_S(inode->i_atime) = attr->cat_atime;
+               inode->i_atime.tv_sec = attr->cat_atime;
        if (valid & CAT_MTIME)
-               LTIME_S(inode->i_mtime) = attr->cat_mtime;
+               inode->i_mtime.tv_sec = attr->cat_mtime;
        if (valid & CAT_CTIME)
-               LTIME_S(inode->i_ctime) = attr->cat_ctime;
+               inode->i_ctime.tv_sec = attr->cat_ctime;
        if (0 && valid & CAT_SIZE)
                cl_isize_write_nolock(inode, attr->cat_size);
        /* not currently necessary */
index a3cf5ad20c6036b215092ee3c91bc5a7d2145770..92f60c350f35be9701d915a5fb66bbeb1fe4232f 100644 (file)
@@ -41,7 +41,6 @@
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
-
 #include "../include/obd.h"
 #include "../include/lustre_lite.h"
 
index 362a87d0d0d349502464921673dc68e05b421753..4b7eb33f7d0172d8f8c716c309e98b7fdce19b1a 100644 (file)
@@ -111,7 +111,6 @@ int ll_setxattr_common(struct inode *inode, const char *name,
        struct ll_sb_info *sbi = ll_i2sbi(inode);
        struct ptlrpc_request *req = NULL;
        int xattr_type, rc;
-       struct obd_capa *oc;
 #ifdef CONFIG_FS_POSIX_ACL
        struct rmtacl_ctl_entry *rce = NULL;
        posix_acl_xattr_header *new_value = NULL;
@@ -175,11 +174,12 @@ int ll_setxattr_common(struct inode *inode, const char *name,
                        }
                        ee_free(ee);
                } else if (rce->rce_ops == RMT_RSETFACL) {
-                       size = lustre_posix_acl_xattr_filter(
+                       rc = lustre_posix_acl_xattr_filter(
                                                (posix_acl_xattr_header *)value,
                                                size, &new_value);
-                       if (unlikely(size < 0))
-                               return size;
+                       if (unlikely(rc < 0))
+                               return rc;
+                       size = rc;
 
                        pv = (const char *)new_value;
                } else
@@ -188,11 +188,9 @@ int ll_setxattr_common(struct inode *inode, const char *name,
                valid |= rce_ops2valid(rce->rce_ops);
        }
 #endif
-       oc = ll_mdscapa_get(inode);
-       rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
+       rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode),
                         valid, name, pv, size, 0, flags,
                         ll_i2suppgid(inode), &req);
-       capa_put(oc);
 #ifdef CONFIG_FS_POSIX_ACL
        if (new_value != NULL)
                lustre_posix_acl_xattr_free(new_value, size);
@@ -289,7 +287,6 @@ int ll_getxattr_common(struct inode *inode, const char *name,
        struct mdt_body *body;
        int xattr_type, rc;
        void *xdata;
-       struct obd_capa *oc;
        struct rmtacl_ctl_entry *rce = NULL;
        struct ll_inode_info *lli = ll_i2info(inode);
 
@@ -380,11 +377,9 @@ do_getxattr:
                }
        } else {
 getxattr_nocache:
-               oc = ll_mdscapa_get(inode);
-               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), oc,
+               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode),
                                valid | (rce ? rce_ops2valid(rce->rce_ops) : 0),
                                name, NULL, 0, size, 0, &req);
-               capa_put(oc);
 
                if (rc < 0)
                        goto out_xattr;
@@ -524,7 +519,7 @@ ssize_t ll_getxattr(struct dentry *dentry, const char *name,
                        goto out;
                }
 
-               lump = (struct lov_user_md *)buffer;
+               lump = buffer;
                memcpy(lump, lmm, lmmsize);
                /* do not return layout gen for getxattr otherwise it would
                 * confuse tar --xattr by recognizing layout gen as stripe
index 9e763ce244e3d14d2799ec6440b3b3f0b4bda16b..e1e599ceb173c4e28d7ef3bb9fe7a0c28a56d1cf 100644 (file)
@@ -58,7 +58,6 @@ void ll_xattr_fini(void)
 static void ll_xattr_cache_init(struct ll_inode_info *lli)
 {
 
-
        LASSERT(lli != NULL);
 
        INIT_LIST_HEAD(&lli->lli_xattrs);
@@ -80,8 +79,6 @@ static int ll_xattr_cache_find(struct list_head *cache,
 {
        struct ll_xattr_entry *entry;
 
-
-
        list_for_each_entry(entry, cache, xe_list) {
                /* xattr_name == NULL means look for any entry */
                if (xattr_name == NULL ||
@@ -113,14 +110,12 @@ static int ll_xattr_cache_add(struct list_head *cache,
 {
        struct ll_xattr_entry *xattr;
 
-
-
        if (ll_xattr_cache_find(cache, xattr_name, &xattr) == 0) {
                CDEBUG(D_CACHE, "duplicate xattr: [%s]\n", xattr_name);
                return -EPROTO;
        }
 
-       OBD_SLAB_ALLOC_PTR_GFP(xattr, xattr_kmem, GFP_NOFS);
+       xattr = kmem_cache_alloc(xattr_kmem, GFP_NOFS | __GFP_ZERO);
        if (xattr == NULL) {
                CDEBUG(D_CACHE, "failed to allocate xattr\n");
                return -ENOMEM;
@@ -146,7 +141,7 @@ static int ll_xattr_cache_add(struct list_head *cache,
 err_value:
        kfree(xattr->xe_name);
 err_name:
-       OBD_SLAB_FREE_PTR(xattr, xattr_kmem);
+       kmem_cache_free(xattr_kmem, xattr);
 
        return -ENOMEM;
 }
@@ -164,15 +159,13 @@ static int ll_xattr_cache_del(struct list_head *cache,
 {
        struct ll_xattr_entry *xattr;
 
-
-
        CDEBUG(D_CACHE, "del xattr: %s\n", xattr_name);
 
        if (ll_xattr_cache_find(cache, xattr_name, &xattr) == 0) {
                list_del(&xattr->xe_list);
                kfree(xattr->xe_name);
                kfree(xattr->xe_value);
-               OBD_SLAB_FREE_PTR(xattr, xattr_kmem);
+               kmem_cache_free(xattr_kmem, xattr);
 
                return 0;
        }
@@ -197,8 +190,6 @@ static int ll_xattr_cache_list(struct list_head *cache,
        struct ll_xattr_entry *xattr, *tmp;
        int xld_tail = 0;
 
-
-
        list_for_each_entry_safe(xattr, tmp, cache, xe_list) {
                CDEBUG(D_CACHE, "list: buffer=%p[%d] name=%s\n",
                        xld_buffer, xld_tail, xattr->xe_name);
@@ -240,7 +231,6 @@ static int ll_xattr_cache_valid(struct ll_inode_info *lli)
 static int ll_xattr_cache_destroy_locked(struct ll_inode_info *lli)
 {
 
-
        if (!ll_xattr_cache_valid(lli))
                return 0;
 
@@ -256,8 +246,6 @@ int ll_xattr_cache_destroy(struct inode *inode)
        struct ll_inode_info *lli = ll_i2info(inode);
        int rc;
 
-
-
        down_write(&lli->lli_xattrs_list_rwsem);
        rc = ll_xattr_cache_destroy_locked(lli);
        up_write(&lli->lli_xattrs_list_rwsem);
@@ -292,8 +280,6 @@ static int ll_xattr_find_get_lock(struct inode *inode,
        struct obd_export *exp = sbi->ll_md_exp;
        int rc;
 
-
-
        mutex_lock(&lli->lli_xattrs_enq_lock);
        /* inode may have been shrunk and recreated, so data is gone, match lock
         * only when data exists. */
@@ -359,8 +345,6 @@ static int ll_xattr_cache_refill(struct inode *inode, struct lookup_intent *oit)
        __u32 *xsizes;
        int rc, i;
 
-
-
        rc = ll_xattr_find_get_lock(inode, oit, &req);
        if (rc)
                goto out_no_unlock;
@@ -495,8 +479,6 @@ int ll_xattr_cache_get(struct inode *inode,
        struct ll_inode_info *lli = ll_i2info(inode);
        int rc = 0;
 
-
-
        LASSERT(!!(valid & OBD_MD_FLXATTR) ^ !!(valid & OBD_MD_FLXATTRLS));
 
        down_read(&lli->lli_xattrs_list_rwsem);
index c9e0536e9f2a18948b8c9b2aeed7418355cc0604..635a93cc94deeebd6a1b06e7417e9f4e340b4c41 100644 (file)
@@ -560,6 +560,7 @@ int lmv_check_connect(struct obd_device *obd)
  out_disc:
        while (i-- > 0) {
                int rc2;
+
                tgt = lmv->tgts[i];
                if (tgt == NULL)
                        continue;
@@ -593,11 +594,11 @@ static int lmv_disconnect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
                mdc_obd->obd_force = obd->obd_force;
                mdc_obd->obd_fail = obd->obd_fail;
                mdc_obd->obd_no_recov = obd->obd_no_recov;
-       }
 
-       if (lmv->lmv_tgts_kobj)
-               sysfs_remove_link(lmv->lmv_tgts_kobj,
-                                 mdc_obd->obd_name);
+               if (lmv->lmv_tgts_kobj)
+                       sysfs_remove_link(lmv->lmv_tgts_kobj,
+                                         mdc_obd->obd_name);
+       }
 
        rc = obd_fid_fini(tgt->ltd_exp->exp_obd);
        if (rc)
@@ -862,9 +863,6 @@ static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
        return rc;
 }
 
-
-
-
 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
                         int len, void *karg, void *uarg)
 {
@@ -1084,6 +1082,7 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
        }
        case LL_IOC_HSM_CT_START: {
                struct lustre_kernelcomm *lk = karg;
+
                if (lk->lk_flags & LK_FLG_STOP)
                        rc = lmv_hsm_ct_unregister(lmv, cmd, len, lk, uarg);
                else
@@ -1335,6 +1334,7 @@ static int lmv_cleanup(struct obd_device *obd)
        fld_client_fini(&lmv->lmv_fld);
        if (lmv->tgts != NULL) {
                int i;
+
                for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
                        if (lmv->tgts[i] == NULL)
                                continue;
@@ -1438,8 +1438,7 @@ out_free_temp:
 }
 
 static int lmv_getstatus(struct obd_export *exp,
-                        struct lu_fid *fid,
-                        struct obd_capa **pc)
+                        struct lu_fid *fid)
 {
        struct obd_device    *obd = exp->exp_obd;
        struct lmv_obd       *lmv = &obd->u.lmv;
@@ -1449,12 +1448,12 @@ static int lmv_getstatus(struct obd_export *exp,
        if (rc)
                return rc;
 
-       rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid, pc);
+       rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid);
        return rc;
 }
 
 static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
-                       struct obd_capa *oc, u64 valid, const char *name,
+                       u64 valid, const char *name,
                        const char *input, int input_size, int output_size,
                        int flags, struct ptlrpc_request **request)
 {
@@ -1471,14 +1470,14 @@ static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
        if (IS_ERR(tgt))
                return PTR_ERR(tgt);
 
-       rc = md_getxattr(tgt->ltd_exp, fid, oc, valid, name, input,
+       rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input,
                         input_size, output_size, flags, request);
 
        return rc;
 }
 
 static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
-                       struct obd_capa *oc, u64 valid, const char *name,
+                       u64 valid, const char *name,
                        const char *input, int input_size, int output_size,
                        int flags, __u32 suppgid,
                        struct ptlrpc_request **request)
@@ -1496,7 +1495,7 @@ static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
        if (IS_ERR(tgt))
                return PTR_ERR(tgt);
 
-       rc = md_setxattr(tgt->ltd_exp, fid, oc, valid, name, input,
+       rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input,
                         input_size, output_size, flags, suppgid,
                         request);
 
@@ -1586,7 +1585,6 @@ static int lmv_find_cbdata(struct obd_export *exp, const struct lu_fid *fid,
        return rc;
 }
 
-
 static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
                     struct md_open_data *mod, struct ptlrpc_request **request)
 {
@@ -1814,6 +1812,7 @@ lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
 
        if (body->valid & OBD_MD_MDS) {
                struct lu_fid rid = body->fid1;
+
                CDEBUG(D_INODE, "Request attrs for "DFID"\n",
                       PFID(&rid));
 
@@ -1849,7 +1848,7 @@ static int lmv_early_cancel(struct obd_export *exp, struct md_op_data *op_data,
        struct obd_device      *obd = exp->exp_obd;
        struct lmv_obd   *lmv = &obd->u.lmv;
        struct lmv_tgt_desc    *tgt;
-       ldlm_policy_data_t      policy = {{0}};
+       ldlm_policy_data_t      policy = { {0} };
        int                  rc = 0;
 
        if (!fid_is_sane(fid))
@@ -2014,7 +2013,7 @@ static int lmv_setattr(struct obd_export *exp, struct md_op_data *op_data,
 }
 
 static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
-                   struct obd_capa *oc, struct ptlrpc_request **request)
+                   struct ptlrpc_request **request)
 {
        struct obd_device        *obd = exp->exp_obd;
        struct lmv_obd      *lmv = &obd->u.lmv;
@@ -2029,7 +2028,7 @@ static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
        if (IS_ERR(tgt))
                return PTR_ERR(tgt);
 
-       rc = md_sync(tgt->ltd_exp, fid, oc, request);
+       rc = md_sync(tgt->ltd_exp, fid, request);
        return rc;
 }
 
@@ -2099,7 +2098,8 @@ static void lmv_adjust_dirpages(struct page **pages, int ncfspgs, int nlupgs)
                while (--nlupgs > 0) {
                        ent = lu_dirent_start(dp);
                        for (end_dirent = ent; ent != NULL;
-                            end_dirent = ent, ent = lu_dirent_next(ent));
+                            end_dirent = ent, ent = lu_dirent_next(ent))
+                               ;
 
                        /* Advance dp to next lu_dirpage. */
                        dp = (struct lu_dirpage *)((char *)dp + LU_PAGE_SIZE);
@@ -2322,8 +2322,6 @@ static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
                return -EINVAL;
        } else if (KEY_IS(KEY_MAX_EASIZE) ||
                   KEY_IS(KEY_DEFAULT_EASIZE) ||
-                  KEY_IS(KEY_MAX_COOKIESIZE) ||
-                  KEY_IS(KEY_DEFAULT_COOKIESIZE) ||
                   KEY_IS(KEY_CONN_DATA)) {
                rc = lmv_check_connect(obd);
                if (rc)
@@ -2606,8 +2604,7 @@ static int lmv_clear_open_replay_data(struct obd_export *exp,
 
 static int lmv_get_remote_perm(struct obd_export *exp,
                               const struct lu_fid *fid,
-                              struct obd_capa *oc, __u32 suppgid,
-                              struct ptlrpc_request **request)
+                              __u32 suppgid, struct ptlrpc_request **request)
 {
        struct obd_device       *obd = exp->exp_obd;
        struct lmv_obd    *lmv = &obd->u.lmv;
@@ -2622,39 +2619,10 @@ static int lmv_get_remote_perm(struct obd_export *exp,
        if (IS_ERR(tgt))
                return PTR_ERR(tgt);
 
-       rc = md_get_remote_perm(tgt->ltd_exp, fid, oc, suppgid, request);
+       rc = md_get_remote_perm(tgt->ltd_exp, fid, suppgid, request);
        return rc;
 }
 
-static int lmv_renew_capa(struct obd_export *exp, struct obd_capa *oc,
-                         renew_capa_cb_t cb)
-{
-       struct obd_device       *obd = exp->exp_obd;
-       struct lmv_obd    *lmv = &obd->u.lmv;
-       struct lmv_tgt_desc     *tgt;
-       int                   rc;
-
-       rc = lmv_check_connect(obd);
-       if (rc)
-               return rc;
-
-       tgt = lmv_find_target(lmv, &oc->c_capa.lc_fid);
-       if (IS_ERR(tgt))
-               return PTR_ERR(tgt);
-
-       rc = md_renew_capa(tgt->ltd_exp, oc, cb);
-       return rc;
-}
-
-static int lmv_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
-                          const struct req_msg_field *field,
-                          struct obd_capa **oc)
-{
-       struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
-
-       return md_unpack_capa(lmv->tgts[0]->ltd_exp, req, field, oc);
-}
-
 static int lmv_intent_getattr_async(struct obd_export *exp,
                                    struct md_enqueue_info *minfo,
                                    struct ldlm_enqueue_info *einfo)
@@ -2724,6 +2692,7 @@ static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
        curspace = curinodes = 0;
        for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
                int err;
+
                tgt = lmv->tgts[i];
 
                if (tgt == NULL || tgt->ltd_exp == NULL || tgt->ltd_active == 0)
@@ -2759,6 +2728,7 @@ static int lmv_quotacheck(struct obd_device *unused, struct obd_export *exp,
 
        for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
                int err;
+
                tgt = lmv->tgts[i];
                if (tgt == NULL || tgt->ltd_exp == NULL || !tgt->ltd_active) {
                        CERROR("lmv idx %d inactive\n", i);
@@ -2820,8 +2790,6 @@ static struct md_ops lmv_md_ops = {
        .m_free_lustre_md       = lmv_free_lustre_md,
        .m_set_open_replay_data = lmv_set_open_replay_data,
        .m_clear_open_replay_data = lmv_clear_open_replay_data,
-       .m_renew_capa      = lmv_renew_capa,
-       .m_unpack_capa    = lmv_unpack_capa,
        .m_get_remote_perm      = lmv_get_remote_perm,
        .m_intent_getattr_async = lmv_intent_getattr_async,
        .m_revalidate_lock      = lmv_revalidate_lock
index 311fc1b70c4d0042e6afa163bf9e98751f54674d..40cf4d9f04860ca05cc27f678bd831e0e2f9eaec 100644 (file)
@@ -143,12 +143,14 @@ static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v)
        seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid);
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(lmv_desc_uuid);
 
 static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
 {
        struct obd_device       *dev = p->private;
        struct lmv_obd    *lmv = &dev->u.lmv;
+
        return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos];
 }
 
index 314ce8525aedc76a16bbf46bd635f671d12c44d9..1c0fe65243e15879badcc38123eefe1612e20809 100644 (file)
@@ -438,7 +438,6 @@ struct lovsub_page {
        struct cl_page_slice lsb_cl;
 };
 
-
 struct lov_thread_info {
        struct cl_object_conf   lti_stripe_conf;
        struct lu_fid      lti_fid;
@@ -611,7 +610,6 @@ int   lov_sublock_modify(const struct lu_env *env, struct lov_lock *lov,
                           struct lovsub_lock *sublock,
                           const struct cl_lock_descr *d, int idx);
 
-
 int   lov_page_init(const struct lu_env *env, struct cl_object *ob,
                           struct cl_page *page, struct page *vmpage);
 int   lovsub_page_init(const struct lu_env *env, struct cl_object *ob,
@@ -637,9 +635,6 @@ struct lov_io_sub    *lov_page_subio(const struct lu_env *env,
                                         struct lov_io *lio,
                                         const struct cl_page_slice *slice);
 
-void lov_lsm_decref(struct lov_object *lov, struct lov_stripe_md *lsm);
-struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov);
-
 #define lov_foreach_target(lov, var)               \
        for (var = 0; var < lov_targets_nr(lov); ++var)
 
index 8c3bbe574723cc54f4a4d1adf104560d4981ea24..2e8b566458f6d6c08d6386a9ca134fcc2a95c415 100644 (file)
@@ -46,7 +46,6 @@
 #include "lov_cl_internal.h"
 #include "lov_internal.h"
 
-
 struct kmem_cache *lov_lock_kmem;
 struct kmem_cache *lov_object_kmem;
 struct kmem_cache *lov_thread_kmem;
@@ -125,7 +124,7 @@ static void lov_req_completion(const struct lu_env *env,
        struct lov_req *lr;
 
        lr = cl2lov_req(slice);
-       OBD_SLAB_FREE_PTR(lr, lov_req_kmem);
+       kmem_cache_free(lov_req_kmem, lr);
 }
 
 static const struct cl_req_operations lov_req_ops = {
@@ -143,7 +142,7 @@ static void *lov_key_init(const struct lu_context *ctx,
 {
        struct lov_thread_info *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, lov_thread_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(lov_thread_kmem, GFP_NOFS | __GFP_ZERO);
        if (info != NULL)
                INIT_LIST_HEAD(&info->lti_closure.clc_list);
        else
@@ -155,8 +154,9 @@ static void lov_key_fini(const struct lu_context *ctx,
                         struct lu_context_key *key, void *data)
 {
        struct lov_thread_info *info = data;
+
        LINVRNT(list_empty(&info->lti_closure.clc_list));
-       OBD_SLAB_FREE_PTR(info, lov_thread_kmem);
+       kmem_cache_free(lov_thread_kmem, info);
 }
 
 struct lu_context_key lov_key = {
@@ -170,7 +170,7 @@ static void *lov_session_key_init(const struct lu_context *ctx,
 {
        struct lov_session *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, lov_session_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(lov_session_kmem, GFP_NOFS | __GFP_ZERO);
        if (info == NULL)
                info = ERR_PTR(-ENOMEM);
        return info;
@@ -180,7 +180,8 @@ static void lov_session_key_fini(const struct lu_context *ctx,
                                 struct lu_context_key *key, void *data)
 {
        struct lov_session *info = data;
-       OBD_SLAB_FREE_PTR(info, lov_session_kmem);
+
+       kmem_cache_free(lov_session_kmem, info);
 }
 
 struct lu_context_key lov_session_key = {
@@ -260,7 +261,7 @@ static int lov_req_init(const struct lu_env *env, struct cl_device *dev,
        struct lov_req *lr;
        int result;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lr, lov_req_kmem, GFP_NOFS);
+       lr = kmem_cache_alloc(lov_req_kmem, GFP_NOFS | __GFP_ZERO);
        if (lr != NULL) {
                cl_req_slice_add(req, &lr->lr_cl, dev, &lov_req_ops);
                result = 0;
index 3f51b573e1fb86e2cb77e0d6708c5a443f1aa359..34c1346f0dc76e9c1f05d3651676cd2098ddea23 100644 (file)
@@ -100,7 +100,7 @@ struct lov_stripe_md *lsm_alloc_plain(__u16 stripe_count, int *size)
                return NULL;
 
        for (i = 0; i < stripe_count; i++) {
-               OBD_SLAB_ALLOC_PTR_GFP(loi, lov_oinfo_slab, GFP_NOFS);
+               loi = kmem_cache_alloc(lov_oinfo_slab, GFP_NOFS | __GFP_ZERO);
                if (loi == NULL)
                        goto err;
                lsm->lsm_oinfo[i] = loi;
@@ -110,7 +110,7 @@ struct lov_stripe_md *lsm_alloc_plain(__u16 stripe_count, int *size)
 
 err:
        while (--i >= 0)
-               OBD_SLAB_FREE(lsm->lsm_oinfo[i], lov_oinfo_slab, sizeof(*loi));
+               kmem_cache_free(lov_oinfo_slab, lsm->lsm_oinfo[i]);
        kvfree(lsm);
        return NULL;
 }
@@ -121,8 +121,7 @@ void lsm_free_plain(struct lov_stripe_md *lsm)
        int i;
 
        for (i = 0; i < stripe_count; i++)
-               OBD_SLAB_FREE(lsm->lsm_oinfo[i], lov_oinfo_slab,
-                             sizeof(struct lov_oinfo));
+               kmem_cache_free(lov_oinfo_slab, lsm->lsm_oinfo[i]);
        kvfree(lsm);
 }
 
index dde9656d4dd61b4b8bdb7bac17c7697fd3d0ffd6..515a5c147827436a9ddfb78c0b53b28acc524e47 100644 (file)
@@ -220,7 +220,6 @@ int lov_free_memmd(struct lov_stripe_md **lsmp);
 void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm);
 void lov_dump_lmm_v3(int level, struct lov_mds_md_v3 *lmm);
 void lov_dump_lmm_common(int level, void *lmmp);
-void lov_dump_lmm(int level, void *lmm);
 
 /* lov_ea.c */
 struct lov_stripe_md *lsm_alloc_plain(__u16 stripe_count, int *size);
@@ -235,7 +234,7 @@ void lprocfs_lov_init_vars(struct lprocfs_static_vars *lvars);
 extern struct lu_device_type lov_device_type;
 
 /* pools */
-extern cfs_hash_ops_t pool_hash_operations;
+extern struct cfs_hash_ops pool_hash_operations;
 /* ost_pool methods */
 int lov_ost_pool_init(struct ost_pool *op, unsigned int count);
 int lov_ost_pool_extend(struct ost_pool *op, unsigned int min_count);
@@ -248,7 +247,6 @@ int lov_pool_new(struct obd_device *obd, char *poolname);
 int lov_pool_del(struct obd_device *obd, char *poolname);
 int lov_pool_add(struct obd_device *obd, char *poolname, char *ostname);
 int lov_pool_remove(struct obd_device *obd, char *poolname, char *ostname);
-void lov_dump_pool(int level, struct pool_desc *pool);
 struct pool_desc *lov_find_pool(struct lov_obd *lov, char *poolname);
 int lov_check_index_in_pool(__u32 idx, struct pool_desc *pool);
 void lov_pool_putref(struct pool_desc *pool);
@@ -271,5 +269,4 @@ static inline bool lov_oinfo_is_dummy(const struct lov_oinfo *loi)
        return false;
 }
 
-
 #endif
index bf3629151d6879b2ba6c99aadb5a6c90aaede52d..5e6228b9ca0111255884b94575ae7b390eecde5d 100644 (file)
@@ -51,6 +51,7 @@ static inline void lov_sub_enter(struct lov_io_sub *sub)
 {
        sub->sub_reenter++;
 }
+
 static inline void lov_sub_exit(struct lov_io_sub *sub)
 {
        sub->sub_reenter--;
@@ -90,7 +91,6 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
        case CIT_SETATTR: {
                io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
                io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
-               io->u.ci_setattr.sa_capa = parent->u.ci_setattr.sa_capa;
                if (cl_io_is_trunc(io)) {
                        loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
 
@@ -111,7 +111,6 @@ static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
        case CIT_FSYNC: {
                io->u.ci_fsync.fi_start = start;
                io->u.ci_fsync.fi_end = end;
-               io->u.ci_fsync.fi_capa = parent->u.ci_fsync.fi_capa;
                io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
                io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
                break;
@@ -273,7 +272,6 @@ struct lov_io_sub *lov_page_subio(const struct lu_env *env, struct lov_io *lio,
        return lov_sub_get(env, lio, stripe);
 }
 
-
 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
                             struct cl_io *io)
 {
@@ -332,6 +330,7 @@ static void lov_io_slice_init(struct lov_io *lio,
 
        case CIT_FAULT: {
                pgoff_t index = io->u.ci_fault.ft_index;
+
                lio->lis_pos = cl_offset(io->ci_obj, index);
                lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
                break;
@@ -546,7 +545,6 @@ static void lov_io_unlock(const struct lu_env *env,
        LASSERT(rc == 0);
 }
 
-
 static struct cl_page_list *lov_io_submit_qin(struct lov_device *ld,
                                              struct cl_page_list *qin,
                                              int idx, int alloc)
@@ -729,6 +727,8 @@ static int lov_io_fault_start(const struct lu_env *env,
        fio = &ios->cis_io->u.ci_fault;
        lio = cl2lov_io(env, ios);
        sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
+       if (IS_ERR(sub))
+               return PTR_ERR(sub);
        sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
        lov_sub_put(sub);
        return lov_io_start(env, ios);
@@ -990,4 +990,5 @@ int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
        io->ci_result = result < 0 ? result : 0;
        return result != 0;
 }
+
 /** @} lov */
index a6938085ff24bb4d45b129e098d840949effe41a..d866791d7b22748fed6ea28003af5893fd095881 100644 (file)
@@ -144,7 +144,7 @@ static struct cl_lock *lov_sublock_alloc(const struct lu_env *env,
 
        LASSERT(idx < lck->lls_nr);
 
-       OBD_SLAB_ALLOC_PTR_GFP(link, lov_lock_link_kmem, GFP_NOFS);
+       link = kmem_cache_alloc(lov_lock_link_kmem, GFP_NOFS | __GFP_ZERO);
        if (link != NULL) {
                struct lov_sublock_env *subenv;
                struct lov_lock_sub  *lls;
@@ -173,7 +173,7 @@ static struct cl_lock *lov_sublock_alloc(const struct lu_env *env,
                if (!IS_ERR(sublock))
                        *out = link;
                else
-                       OBD_SLAB_FREE_PTR(link, lov_lock_link_kmem);
+                       kmem_cache_free(lov_lock_link_kmem, link);
        } else
                sublock = ERR_PTR(-ENOMEM);
        return sublock;
@@ -227,6 +227,7 @@ static int lov_sublock_lock(const struct lu_env *env,
                        result = CLO_REPEAT;
                } else if (lsep) {
                        struct lov_sublock_env *subenv;
+
                        subenv = lov_sublock_env_get(env, parent, lls);
                        if (IS_ERR(subenv)) {
                                lov_sublock_unlock(env, sublock,
@@ -443,7 +444,7 @@ static void lov_lock_fini(const struct lu_env *env,
                        LASSERT(lck->lls_sub[i].sub_lock == NULL);
                kvfree(lck->lls_sub);
        }
-       OBD_SLAB_FREE_PTR(lck, lov_lock_kmem);
+       kmem_cache_free(lov_lock_kmem, lck);
 }
 
 static int lov_lock_enqueue_wait(const struct lu_env *env,
@@ -517,7 +518,7 @@ static int lov_sublock_fill(const struct lu_env *env, struct cl_lock *parent,
                    lck->lls_sub[idx].sub_lock == NULL) {
                        lov_sublock_adopt(env, lck, sublock, idx, link);
                } else {
-                       OBD_SLAB_FREE_PTR(link, lov_lock_link_kmem);
+                       kmem_cache_free(lov_lock_link_kmem, link);
                        /* other thread allocated sub-lock, or enqueue is no
                         * longer going on */
                        cl_lock_mutex_put(env, parent);
@@ -677,7 +678,6 @@ static int lov_lock_unuse(const struct lu_env *env,
        return result;
 }
 
-
 static void lov_lock_cancel(const struct lu_env *env,
                           const struct cl_lock_slice *slice)
 {
@@ -981,6 +981,7 @@ static int lov_lock_fits_into(const struct lu_env *env,
                result = cl_lock_ext_match(&lov->lls_orig, need);
        else if (lov->lls_nr == 1) {
                struct cl_lock_descr *got = &lov->lls_sub[0].sub_got;
+
                result = lov_lock_stripe_is_matching(env,
                                                     cl2lov(slice->cls_obj),
                                                     lov->lls_sub[0].sub_stripe,
@@ -1026,7 +1027,7 @@ void lov_lock_unlink(const struct lu_env *env,
        lck->lls_nr_filled--;
        lu_ref_del(&parent->cll_reference, "lov-child", sub->lss_cl.cls_lock);
        cl_lock_put(env, parent);
-       OBD_SLAB_FREE_PTR(link, lov_lock_link_kmem);
+       kmem_cache_free(lov_lock_link_kmem, link);
 }
 
 struct lov_lock_link *lov_lock_link_find(const struct lu_env *env,
@@ -1138,7 +1139,7 @@ int lov_lock_init_raid0(const struct lu_env *env, struct cl_object *obj,
        struct lov_lock *lck;
        int result;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lck, lov_lock_kmem, GFP_NOFS);
+       lck = kmem_cache_alloc(lov_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (lck != NULL) {
                cl_lock_slice_add(lock, &lck->lls_cl, obj, &lov_lock_ops);
                result = lov_lock_sub_init(env, lck, io);
@@ -1151,7 +1152,8 @@ static void lov_empty_lock_fini(const struct lu_env *env,
                                struct cl_lock_slice *slice)
 {
        struct lov_lock *lck = cl2lov_lock(slice);
-       OBD_SLAB_FREE_PTR(lck, lov_lock_kmem);
+
+       kmem_cache_free(lov_lock_kmem, lck);
 }
 
 static int lov_empty_lock_print(const struct lu_env *env, void *cookie,
@@ -1173,7 +1175,7 @@ int lov_lock_init_empty(const struct lu_env *env, struct cl_object *obj,
        struct lov_lock *lck;
        int result = -ENOMEM;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lck, lov_lock_kmem, GFP_NOFS);
+       lck = kmem_cache_alloc(lov_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (lck != NULL) {
                cl_lock_slice_add(lock, &lck->lls_cl, obj, &lov_empty_lock_ops);
                lck->lls_orig = lock->cll_descr;
@@ -1193,5 +1195,4 @@ static struct cl_lock_closure *lov_closure_get(const struct lu_env *env,
        return closure;
 }
 
-
 /** @} lov */
index c5c67d982ef2387c73cb247aef6a9fa96cf4db31..7abe484c07c043fa724146bccda6a69247ed7a17 100644 (file)
@@ -85,6 +85,7 @@ static void lov_putref(struct obd_device *obd)
                LIST_HEAD(kill);
                int i;
                struct lov_tgt_desc *tgt, *n;
+
                CDEBUG(D_CONFIG, "destroying %d lov targets\n",
                       lov->lov_death_row);
                for (i = 0; i < lov->desc.ld_tgt_count; i++) {
@@ -121,7 +122,6 @@ static int lov_set_osc_active(struct obd_device *obd, struct obd_uuid *uuid,
 static int lov_notify(struct obd_device *obd, struct obd_device *watched,
                      enum obd_notify_event ev, void *data);
 
-
 #define MAX_STRING_SIZE 128
 int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
                    struct obd_connect_data *data)
@@ -169,7 +169,6 @@ int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
                return rc;
        }
 
-
        if (imp->imp_invalid) {
                CDEBUG(D_CONFIG, "not connecting OSC %s; administratively disabled\n",
                       obd_uuid2str(tgt_uuid));
@@ -833,6 +832,7 @@ static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
        switch (stage) {
        case OBD_CLEANUP_EARLY: {
                int i;
+
                for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                        if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
                                continue;
@@ -869,6 +869,7 @@ static int lov_cleanup(struct obd_device *obd)
        lprocfs_obd_cleanup(obd);
        if (lov->lov_tgts) {
                int i;
+
                obd_getref(obd);
                for (i = 0; i < lov->desc.ld_tgt_count; i++) {
                        if (!lov->lov_tgts[i])
@@ -913,14 +914,12 @@ int lov_process_config_base(struct obd_device *obd, struct lustre_cfg *lcfg,
 
                obd_str2uuid(&obd_uuid,  lustre_cfg_buf(lcfg, 1));
 
-               if (sscanf(lustre_cfg_buf(lcfg, 2), "%d", indexp) != 1) {
-                       rc = -EINVAL;
+               rc = kstrtoint(lustre_cfg_buf(lcfg, 2), 10, indexp);
+               if (rc < 0)
                        goto out;
-               }
-               if (sscanf(lustre_cfg_buf(lcfg, 3), "%d", genp) != 1) {
-                       rc = -EINVAL;
+               rc = kstrtoint(lustre_cfg_buf(lcfg, 3), 10, genp);
+               if (rc < 0)
                        goto out;
-               }
                index = *indexp;
                gen = *genp;
                if (cmd == LCFG_LOV_ADD_OBD)
@@ -1061,8 +1060,7 @@ do {                                                                          \
 
 static int lov_destroy(const struct lu_env *env, struct obd_export *exp,
                       struct obdo *oa, struct lov_stripe_md *lsm,
-                      struct obd_trans_info *oti, struct obd_export *md_exp,
-                      void *capa)
+                      struct obd_trans_info *oti, struct obd_export *md_exp)
 {
        struct lov_request_set *set;
        struct obd_info oinfo;
@@ -1094,7 +1092,7 @@ static int lov_destroy(const struct lu_env *env, struct obd_export *exp,
                        oti->oti_logcookies = set->set_cookies + req->rq_stripe;
 
                err = obd_destroy(env, lov->lov_tgts[req->rq_idx]->ltd_exp,
-                                 req->rq_oi.oi_oa, NULL, oti, NULL, capa);
+                                 req->rq_oi.oi_oa, NULL, oti, NULL);
                err = lov_update_common_set(set, req, err);
                if (err) {
                        CERROR("%s: destroying objid "DOSTID" subobj "
@@ -1257,6 +1255,7 @@ static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
        /* If we are not waiting for responses on async requests, return. */
        if (rc || !rqset || list_empty(&rqset->set_requests)) {
                int err;
+
                if (rc)
                        atomic_set(&set->set_completes, 0);
                err = lov_fini_setattr_set(set);
@@ -1349,6 +1348,7 @@ static int lov_statfs_async(struct obd_export *exp, struct obd_info *oinfo,
 
        if (rc || list_empty(&rqset->set_requests)) {
                int err;
+
                if (rc)
                        atomic_set(&set->set_completes, 0);
                err = lov_fini_statfs_set(set);
@@ -1365,7 +1365,7 @@ static int lov_statfs(const struct lu_env *env, struct obd_export *exp,
                      struct obd_statfs *osfs, __u64 max_age, __u32 flags)
 {
        struct ptlrpc_request_set *set = NULL;
-       struct obd_info oinfo = { { { 0 } } };
+       struct obd_info oinfo = { };
        int rc = 0;
 
        /* for obdclass we forbid using obd_statfs_rqset, but prefer using async
@@ -1487,7 +1487,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                struct obd_quotactl *oqctl;
 
                if (qctl->qc_valid == QC_OSTIDX) {
-                       if (qctl->qc_idx < 0 || count <= qctl->qc_idx)
+                       if (count <= qctl->qc_idx)
                                return -EINVAL;
 
                        tgt = lov->lov_tgts[qctl->qc_idx];
@@ -1672,7 +1672,7 @@ static int fiemap_calc_last_stripe(struct lov_stripe_md *lsm, u64 fm_start,
                                break;
                }
                *stripe_count = j;
-               last_stripe = (start_stripe + j - 1) %lsm->lsm_stripe_count;
+               last_stripe = (start_stripe + j - 1) % lsm->lsm_stripe_count;
        }
 
        return last_stripe;
@@ -1862,7 +1862,7 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
                        fm_local->fm_start = lun_start;
                        fm_local->fm_flags &= ~FIEMAP_FLAG_DEVICE_ORDER;
                        memcpy(&fm_key->fiemap, fm_local, sizeof(*fm_local));
-                       *vallen=fiemap_count_to_size(fm_local->fm_extent_count);
+                       *vallen = fiemap_count_to_size(fm_local->fm_extent_count);
                        rc = obd_get_info(NULL,
                                          lov->lov_tgts[ost_index]->ltd_exp,
                                          keylen, key, vallen, fm_local, lsm);
@@ -2067,7 +2067,7 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
        struct lov_tgt_desc *tgt;
        unsigned incr, check_uuid,
                 do_inactive, no_set;
-       unsigned next_id = 0,  mds_con = 0, capa = 0;
+       unsigned next_id = 0,  mds_con = 0;
 
        incr = check_uuid = do_inactive = no_set = 0;
        if (set == NULL) {
@@ -2092,8 +2092,6 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
                /* use defaults:  do_inactive = incr = 0; */
        } else if (KEY_IS(KEY_MDS_CONN)) {
                mds_con = 1;
-       } else if (KEY_IS(KEY_CAPA_KEY)) {
-               capa = 1;
        } else if (KEY_IS(KEY_CACHE_SET)) {
                LASSERT(lov->lov_cache == NULL);
                lov->lov_cache = val;
@@ -2101,11 +2099,10 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
        }
 
        for (i = 0; i < count; i++, val = (char *)val + incr) {
-               if (next_id) {
+               if (next_id)
                        tgt = lov->lov_tgts[((struct obd_id_info *)val)->idx];
-               } else {
+               else
                        tgt = lov->lov_tgts[i];
-               }
                /* OST was disconnected */
                if (!tgt || !tgt->ltd_exp)
                        continue;
@@ -2132,19 +2129,6 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
                        err = obd_set_info_async(env, tgt->ltd_exp,
                                         keylen, key, vallen,
                                         ((struct obd_id_info *)val)->data, set);
-               } else if (capa) {
-                       struct mds_capa_info *info = (struct mds_capa_info *)val;
-
-                       LASSERT(vallen == sizeof(*info));
-
-                        /* Only want a specific OSC */
-                       if (info->uuid &&
-                           !obd_uuid_equals(info->uuid, &tgt->ltd_uuid))
-                               continue;
-
-                       err = obd_set_info_async(env, tgt->ltd_exp, keylen,
-                                                key, sizeof(*info->capa),
-                                                info->capa, set);
                } else {
                        /* Only want a specific OSC */
                        if (check_uuid &&
index 4d7cd924a27e01d7815245bd02fed4e0825f7ee5..c7ff817bb6fb098dfd34771d17d395505a0cd3de 100644 (file)
@@ -42,7 +42,6 @@
 #define DEBUG_SUBSYSTEM S_LOV
 
 #include "lov_cl_internal.h"
-#include "../include/lclient.h"
 
 /** \addtogroup lov
  *  @{
@@ -809,7 +808,7 @@ static void lov_object_free(const struct lu_env *env, struct lu_object *obj)
 
        LOV_2DISPATCH_VOID(lov, llo_fini, env, lov, &lov->u);
        lu_object_fini(obj);
-       OBD_SLAB_FREE_PTR(lov, lov_object_kmem);
+       kmem_cache_free(lov_object_kmem, lov);
 }
 
 static int lov_object_print(const struct lu_env *env, void *cookie,
@@ -892,7 +891,7 @@ struct lu_object *lov_object_alloc(const struct lu_env *env,
        struct lov_object *lov;
        struct lu_object  *obj;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lov, lov_object_kmem, GFP_NOFS);
+       lov = kmem_cache_alloc(lov_object_kmem, GFP_NOFS | __GFP_ZERO);
        if (lov != NULL) {
                obj = lov2lu(lov);
                lu_object_init(obj, NULL, dev);
@@ -909,7 +908,7 @@ struct lu_object *lov_object_alloc(const struct lu_env *env,
        return obj;
 }
 
-struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
+static struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
 {
        struct lov_stripe_md *lsm = NULL;
 
@@ -924,17 +923,6 @@ struct lov_stripe_md *lov_lsm_addref(struct lov_object *lov)
        return lsm;
 }
 
-void lov_lsm_decref(struct lov_object *lov, struct lov_stripe_md *lsm)
-{
-       if (lsm == NULL)
-               return;
-
-       CDEBUG(D_INODE, "lsm %p decref %d by %p.\n",
-               lsm, atomic_read(&lsm->lsm_refc), current);
-
-       lov_free_memmd(&lsm);
-}
-
 struct lov_stripe_md *lov_lsm_get(struct cl_object *clobj)
 {
        struct lu_object *luobj;
index 6b1c135c9ab0cddc892b6a46e03f71796b631731..2fb1e974cc70b188e788faf579c1466b38c793f5 100644 (file)
@@ -100,26 +100,6 @@ void lov_dump_lmm_v3(int level, struct lov_mds_md_v3 *lmm)
                             le16_to_cpu(lmm->lmm_stripe_count));
 }
 
-void lov_dump_lmm(int level, void *lmm)
-{
-       int magic;
-
-       magic = le32_to_cpu(((struct lov_mds_md *)lmm)->lmm_magic);
-       switch (magic) {
-       case LOV_MAGIC_V1:
-               lov_dump_lmm_v1(level, (struct lov_mds_md_v1 *)lmm);
-               break;
-       case LOV_MAGIC_V3:
-               lov_dump_lmm_v3(level, (struct lov_mds_md_v3 *)lmm);
-               break;
-       default:
-               CDEBUG(level, "unrecognized lmm_magic %x, assuming %x\n",
-                      magic, LOV_MAGIC_V1);
-               lov_dump_lmm_common(level, lmm);
-               break;
-       }
-}
-
 /* Pack LOV object metadata for disk storage.  It is packed in LE byte
  * order and is opaque to the networking layer.
  *
@@ -273,7 +253,6 @@ __u16 lov_get_stripecnt(struct lov_obd *lov, __u32 magic, __u16 stripe_count)
        return stripe_count;
 }
 
-
 static int lov_verify_lmm(void *lmm, int lmm_bytes, __u16 *stripe_count)
 {
        int rc;
@@ -347,7 +326,6 @@ int lov_free_memmd(struct lov_stripe_md **lsmp)
        return refc;
 }
 
-
 /* Unpack LOV object metadata from disk storage.  It is packed in LE byte
  * order and is opaque to the networking layer.
  */
index c4596e8e57831a8b9c36fb651b61e55bcd5c50df..463cadbd9d40d8f1870ccf6129c1695f2d655b1e 100644 (file)
@@ -208,7 +208,6 @@ out:
        return rc;
 }
 
-
 static const struct cl_page_operations lov_empty_page_ops = {
        .cpo_fini   = lov_empty_page_fini,
        .cpo_print  = lov_page_print
@@ -228,5 +227,4 @@ int lov_page_init_empty(const struct lu_env *env, struct cl_object *obj,
        return 0;
 }
 
-
 /** @} lov */
index c59b1402616e23e7c6e8521c1d1414149608924c..b03827ef65145bfddb7cf49801fc5b24f4176058 100644 (file)
@@ -142,12 +142,12 @@ static void pool_hashrefcount_put_locked(struct cfs_hash *hs,
        lov_pool_putref_locked(pool);
 }
 
-cfs_hash_ops_t pool_hash_operations = {
+struct cfs_hash_ops pool_hash_operations = {
        .hs_hash        = pool_hashfn,
-       .hs_key  = pool_key,
+       .hs_key         = pool_key,
        .hs_keycmp      = pool_hashkey_keycmp,
        .hs_object      = pool_hashobject,
-       .hs_get  = pool_hashrefcount_get,
+       .hs_get         = pool_hashrefcount_get,
        .hs_put_locked  = pool_hashrefcount_put_locked,
 
 };
@@ -282,6 +282,7 @@ static int pool_proc_open(struct inode *inode, struct file *file)
        rc = seq_open(file, &pool_proc_ops);
        if (!rc) {
                struct seq_file *s = file->private_data;
+
                s->private = inode->i_private;
        }
        return rc;
@@ -294,28 +295,6 @@ static struct file_operations pool_proc_operations = {
        .release        = seq_release,
 };
 
-void lov_dump_pool(int level, struct pool_desc *pool)
-{
-       int i;
-
-       lov_pool_getref(pool);
-
-       CDEBUG(level, "pool "LOV_POOLNAMEF" has %d members\n",
-              pool->pool_name, pool->pool_obds.op_count);
-       down_read(&pool_tgt_rw_sem(pool));
-
-       for (i = 0; i < pool_tgt_count(pool) ; i++) {
-               if (!pool_tgt(pool, i) || !(pool_tgt(pool, i))->ltd_exp)
-                       continue;
-               CDEBUG(level, "pool "LOV_POOLNAMEF"[%d] = %s\n",
-                      pool->pool_name, i,
-                      obd_uuid2str(&((pool_tgt(pool, i))->ltd_uuid)));
-       }
-
-       up_read(&pool_tgt_rw_sem(pool));
-       lov_pool_putref(pool);
-}
-
 #define LOV_POOL_INIT_COUNT 2
 int lov_ost_pool_init(struct ost_pool *op, unsigned int count)
 {
@@ -418,7 +397,6 @@ int lov_ost_pool_free(struct ost_pool *op)
        return 0;
 }
 
-
 int lov_pool_new(struct obd_device *obd, char *poolname)
 {
        struct lov_obd *lov;
@@ -530,7 +508,6 @@ int lov_pool_del(struct obd_device *obd, char *poolname)
        return 0;
 }
 
-
 int lov_pool_add(struct obd_device *obd, char *poolname, char *ostname)
 {
        struct obd_uuid ost_uuid;
@@ -547,7 +524,6 @@ int lov_pool_add(struct obd_device *obd, char *poolname, char *ostname)
 
        obd_str2uuid(&ost_uuid, ostname);
 
-
        /* search ost in lov array */
        obd_getref(obd);
        for (lov_idx = 0; lov_idx < lov->desc.ld_tgt_count; lov_idx++) {
index 416e42ed779252314820661f908bfa244a351259..1a150c26798dee432482b6c5c208d02cb41c5aa9 100644 (file)
@@ -67,7 +67,7 @@ void lov_finish_set(struct lov_request_set *set)
                list_del_init(&req->rq_link);
 
                if (req->rq_oi.oi_oa)
-                       OBDO_FREE(req->rq_oi.oi_oa);
+                       kmem_cache_free(obdo_cachep, req->rq_oi.oi_oa);
                kfree(req->rq_oi.oi_osfs);
                kfree(req);
        }
@@ -202,7 +202,7 @@ static int common_attr_done(struct lov_request_set *set)
        if (!atomic_read(&set->set_success))
                return -EIO;
 
-       OBDO_ALLOC(tmp_oa);
+       tmp_oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
        if (tmp_oa == NULL) {
                rc = -ENOMEM;
                goto out;
@@ -236,7 +236,7 @@ static int common_attr_done(struct lov_request_set *set)
        memcpy(set->set_oi->oi_oa, tmp_oa, sizeof(*set->set_oi->oi_oa));
 out:
        if (tmp_oa)
-               OBDO_FREE(tmp_oa);
+               kmem_cache_free(obdo_cachep, tmp_oa);
        return rc;
 
 }
@@ -309,7 +309,8 @@ int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
                req->rq_stripe = i;
                req->rq_idx = loi->loi_ost_idx;
 
-               OBDO_ALLOC(req->rq_oi.oi_oa);
+               req->rq_oi.oi_oa = kmem_cache_alloc(obdo_cachep,
+                                                   GFP_NOFS | __GFP_ZERO);
                if (req->rq_oi.oi_oa == NULL) {
                        kfree(req);
                        rc = -ENOMEM;
@@ -319,7 +320,6 @@ int lov_prep_getattr_set(struct obd_export *exp, struct obd_info *oinfo,
                       sizeof(*req->rq_oi.oi_oa));
                req->rq_oi.oi_oa->o_oi = loi->loi_oi;
                req->rq_oi.oi_cb_up = cb_getattr_update;
-               req->rq_oi.oi_capa = oinfo->oi_capa;
 
                lov_set_add_req(req, set);
        }
@@ -392,7 +392,8 @@ int lov_prep_destroy_set(struct obd_export *exp, struct obd_info *oinfo,
                req->rq_stripe = i;
                req->rq_idx = loi->loi_ost_idx;
 
-               OBDO_ALLOC(req->rq_oi.oi_oa);
+               req->rq_oi.oi_oa = kmem_cache_alloc(obdo_cachep,
+                                                   GFP_NOFS | __GFP_ZERO);
                if (req->rq_oi.oi_oa == NULL) {
                        kfree(req);
                        rc = -ENOMEM;
@@ -507,7 +508,8 @@ int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
                req->rq_stripe = i;
                req->rq_idx = loi->loi_ost_idx;
 
-               OBDO_ALLOC(req->rq_oi.oi_oa);
+               req->rq_oi.oi_oa = kmem_cache_alloc(obdo_cachep,
+                                                   GFP_NOFS | __GFP_ZERO);
                if (req->rq_oi.oi_oa == NULL) {
                        kfree(req);
                        rc = -ENOMEM;
@@ -518,7 +520,6 @@ int lov_prep_setattr_set(struct obd_export *exp, struct obd_info *oinfo,
                req->rq_oi.oi_oa->o_oi = loi->loi_oi;
                req->rq_oi.oi_oa->o_stripe_idx = i;
                req->rq_oi.oi_cb_up = cb_setattr_update;
-               req->rq_oi.oi_capa = oinfo->oi_capa;
 
                if (oinfo->oi_oa->o_valid & OBD_MD_FLSIZE) {
                        int off = lov_stripe_offset(oinfo->oi_md,
index 90d9ec386a1a7c0bde6bcf8786062007ab3d646d..8bc04c8d3d600bb797d68cc81bec024a02afdc39 100644 (file)
@@ -56,7 +56,7 @@ static void lovsub_req_completion(const struct lu_env *env,
        struct lovsub_req *lsr;
 
        lsr = cl2lovsub_req(slice);
-       OBD_SLAB_FREE_PTR(lsr, lovsub_req_kmem);
+       kmem_cache_free(lovsub_req_kmem, lsr);
 }
 
 /**
@@ -146,7 +146,7 @@ static int lovsub_req_init(const struct lu_env *env, struct cl_device *dev,
        struct lovsub_req *lsr;
        int result;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lsr, lovsub_req_kmem, GFP_NOFS);
+       lsr = kmem_cache_alloc(lovsub_req_kmem, GFP_NOFS | __GFP_ZERO);
        if (lsr != NULL) {
                cl_req_slice_add(req, &lsr->lsrq_cl, dev, &lovsub_req_ops);
                result = 0;
@@ -205,5 +205,4 @@ struct lu_device_type lovsub_device_type = {
        .ldt_ctx_tags = LCT_CL_THREAD
 };
 
-
 /** @} lov */
index 62b696d25d81242fdafb7a6b7b4318a017ecd162..1a3e30a14895726694cfd3b617bcaa460badb19a 100644 (file)
@@ -59,7 +59,7 @@ static void lovsub_lock_fini(const struct lu_env *env,
 
        lsl = cl2lovsub_lock(slice);
        LASSERT(list_empty(&lsl->lss_parents));
-       OBD_SLAB_FREE_PTR(lsl, lovsub_lock_kmem);
+       kmem_cache_free(lovsub_lock_kmem, lsl);
 }
 
 static void lovsub_parent_lock(const struct lu_env *env, struct lov_lock *lov)
@@ -453,7 +453,7 @@ int lovsub_lock_init(const struct lu_env *env, struct cl_object *obj,
        struct lovsub_lock *lsk;
        int result;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lsk, lovsub_lock_kmem, GFP_NOFS);
+       lsk = kmem_cache_alloc(lovsub_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (lsk != NULL) {
                INIT_LIST_HEAD(&lsk->lss_parents);
                cl_lock_slice_add(lock, &lsk->lss_cl, obj, &lovsub_lock_ops);
index 57e3629fccee30fe8f57a1500fe33d86c3f774bb..d775e28d40973d02a52bfdc51869567c12a95086 100644 (file)
@@ -91,7 +91,7 @@ static void lovsub_object_free(const struct lu_env *env, struct lu_object *obj)
 
        lu_object_fini(obj);
        lu_object_header_fini(&los->lso_header.coh_lu);
-       OBD_SLAB_FREE_PTR(los, lovsub_object_kmem);
+       kmem_cache_free(lovsub_object_kmem, los);
 }
 
 static int lovsub_object_print(const struct lu_env *env, void *cookie,
@@ -120,8 +120,6 @@ static int lovsub_object_glimpse(const struct lu_env *env,
        return cl_object_glimpse(env, &los->lso_super->lo_cl, lvb);
 }
 
-
-
 static const struct cl_object_operations lovsub_ops = {
        .coo_page_init = lovsub_page_init,
        .coo_lock_init = lovsub_lock_init,
@@ -145,7 +143,7 @@ struct lu_object *lovsub_object_alloc(const struct lu_env *env,
        struct lovsub_object *los;
        struct lu_object     *obj;
 
-       OBD_SLAB_ALLOC_PTR_GFP(los, lovsub_object_kmem, GFP_NOFS);
+       los = kmem_cache_alloc(lovsub_object_kmem, GFP_NOFS | __GFP_ZERO);
        if (los != NULL) {
                struct cl_object_header *hdr;
 
index 380b8271bf24ad340bc423800251bf4d7ea85f67..a0be15c6b55acf66f8e8a8c6d7adf275602a1761 100644 (file)
@@ -71,6 +71,7 @@ static ssize_t lov_stripesize_seq_write(struct file *file,
        desc->ld_default_stripe_size = val;
        return count;
 }
+
 LPROC_SEQ_FOPS(lov_stripesize);
 
 static int lov_stripeoffset_seq_show(struct seq_file *m, void *v)
@@ -102,6 +103,7 @@ static ssize_t lov_stripeoffset_seq_write(struct file *file,
        desc->ld_default_stripe_offset = val;
        return count;
 }
+
 LPROC_SEQ_FOPS(lov_stripeoffset);
 
 static int lov_stripetype_seq_show(struct seq_file *m, void *v)
@@ -133,6 +135,7 @@ static ssize_t lov_stripetype_seq_write(struct file *file,
        desc->ld_pattern = val;
        return count;
 }
+
 LPROC_SEQ_FOPS(lov_stripetype);
 
 static int lov_stripecount_seq_show(struct seq_file *m, void *v)
@@ -164,6 +167,7 @@ static ssize_t lov_stripecount_seq_write(struct file *file,
        desc->ld_default_stripe_count = val;
        return count;
 }
+
 LPROC_SEQ_FOPS(lov_stripecount);
 
 static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
@@ -200,6 +204,7 @@ static int lov_desc_uuid_seq_show(struct seq_file *m, void *v)
        seq_printf(m, "%s\n", lov->desc.ld_uuid.uuid);
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(lov_desc_uuid);
 
 static void *lov_tgt_seq_start(struct seq_file *p, loff_t *pos)
index 4d149435e949acaf34d6a35212f3ff54ffd0d731..29b46f754726ef88937a6b3e151f5ea6d9cc1ac6 100644 (file)
 void lprocfs_mdc_init_vars(struct lprocfs_static_vars *lvars);
 
 void mdc_pack_body(struct ptlrpc_request *req, const struct lu_fid *fid,
-                  struct obd_capa *oc, __u64 valid, int ea_size,
-                  __u32 suppgid, int flags);
-void mdc_pack_capa(struct ptlrpc_request *req,
-                  const struct req_msg_field *field, struct obd_capa *oc);
+                  __u64 valid, int ea_size, __u32 suppgid, int flags);
 int mdc_pack_req(struct ptlrpc_request *req, int version, int opc);
 void mdc_is_subdir_pack(struct ptlrpc_request *req, const struct lu_fid *pfid,
                        const struct lu_fid *cfid, int flags);
 void mdc_swap_layouts_pack(struct ptlrpc_request *req,
                           struct md_op_data *op_data);
 void mdc_readdir_pack(struct ptlrpc_request *req, __u64 pgoff, __u32 size,
-                     const struct lu_fid *fid, struct obd_capa *oc);
+                     const struct lu_fid *fid);
 void mdc_getattr_pack(struct ptlrpc_request *req, __u64 valid, int flags,
                      struct md_op_data *data, int ea_size);
 void mdc_setattr_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
@@ -140,17 +137,6 @@ int mdc_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
                      ldlm_policy_data_t *policy, ldlm_mode_t mode,
                      ldlm_cancel_flags_t flags, void *opaque);
 
-static inline void mdc_set_capa_size(struct ptlrpc_request *req,
-                                    const struct req_msg_field *field,
-                                    struct obd_capa *oc)
-{
-       if (oc == NULL)
-               req_capsule_set_size(&req->rq_pill, field, RCL_CLIENT, 0);
-       else
-               /* it is already calculated as sizeof struct obd_capa */
-               ;
-}
-
 int mdc_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
                        struct lu_fid *fid, __u64 *bits);
 
index 1a850ea2684945411a66fc46e38a272b3ccb2105..227fc9ee0dcfb2a382b796564705cedda7f0102a 100644 (file)
@@ -39,7 +39,6 @@
 #include "../include/lustre/lustre_idl.h"
 #include "mdc_internal.h"
 
-
 static void __mdc_pack_body(struct mdt_body *b, __u32 suppgid)
 {
        LASSERT(b != NULL);
@@ -52,24 +51,6 @@ static void __mdc_pack_body(struct mdt_body *b, __u32 suppgid)
        b->capability = cfs_curproc_cap_pack();
 }
 
-void mdc_pack_capa(struct ptlrpc_request *req,
-                  const struct req_msg_field *field,
-                  struct obd_capa *oc)
-{
-       struct req_capsule *pill = &req->rq_pill;
-       struct lustre_capa *c;
-
-       if (oc == NULL) {
-               LASSERT(req_capsule_get_size(pill, field, RCL_CLIENT) == 0);
-               return;
-       }
-
-       c = req_capsule_client_get(pill, field);
-       LASSERT(c != NULL);
-       capa_cpy(c, oc);
-       DEBUG_CAPA(D_SEC, c, "pack");
-}
-
 void mdc_is_subdir_pack(struct ptlrpc_request *req, const struct lu_fid *pfid,
                        const struct lu_fid *cfid, int flags)
 {
@@ -95,13 +76,9 @@ void mdc_swap_layouts_pack(struct ptlrpc_request *req,
        b->fid1 = op_data->op_fid1;
        b->fid2 = op_data->op_fid2;
        b->valid |= OBD_MD_FLID;
-
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-       mdc_pack_capa(req, &RMF_CAPA2, op_data->op_capa2);
 }
 
-void mdc_pack_body(struct ptlrpc_request *req,
-                  const struct lu_fid *fid, struct obd_capa *oc,
+void mdc_pack_body(struct ptlrpc_request *req, const struct lu_fid *fid,
                   __u64 valid, int ea_size, __u32 suppgid, int flags)
 {
        struct mdt_body *b = req_capsule_client_get(&req->rq_pill,
@@ -114,12 +91,11 @@ void mdc_pack_body(struct ptlrpc_request *req,
        if (fid) {
                b->fid1 = *fid;
                b->valid |= OBD_MD_FLID;
-               mdc_pack_capa(req, &RMF_CAPA1, oc);
        }
 }
 
 void mdc_readdir_pack(struct ptlrpc_request *req, __u64 pgoff,
-                     __u32 size, const struct lu_fid *fid, struct obd_capa *oc)
+                     __u32 size, const struct lu_fid *fid)
 {
        struct mdt_body *b = req_capsule_client_get(&req->rq_pill,
                                                    &RMF_MDT_BODY);
@@ -129,8 +105,6 @@ void mdc_readdir_pack(struct ptlrpc_request *req, __u64 pgoff,
        b->nlink = size;                        /* !! */
        __mdc_pack_body(b, -1);
        b->mode = LUDA_FID | LUDA_TYPE;
-
-       mdc_pack_capa(req, &RMF_CAPA1, oc);
 }
 
 /* packing of MDS records */
@@ -145,7 +119,6 @@ void mdc_create_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
        CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_create));
        rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
 
-
        rec->cr_opcode   = REINT_CREATE;
        rec->cr_fsuid    = uid;
        rec->cr_fsgid    = gid;
@@ -164,8 +137,6 @@ void mdc_create_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
        rec->cr_bias     = op_data->op_bias;
        rec->cr_umask    = current_umask();
 
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-
        tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
        LOGL0(op_data->op_name, op_data->op_namelen, tmp);
 
@@ -235,10 +206,6 @@ void mdc_open_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
        rec->cr_umask    = current_umask();
        rec->cr_old_handle = op_data->op_handle;
 
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-       /* the next buffer is child capa, which is used for replay,
-        * will be packed from the data in reply message. */
-
        if (op_data->op_name) {
                tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
                LOGL0(op_data->op_name, op_data->op_namelen, tmp);
@@ -347,8 +314,6 @@ void mdc_setattr_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
        rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
        mdc_setattr_pack_rec(rec, op_data);
 
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-
        if (op_data->op_flags & (MF_SOM_CHANGE | MF_EPOCH_OPEN)) {
                epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
                mdc_ioepoch_pack(epoch, op_data);
@@ -396,8 +361,6 @@ void mdc_unlink_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
        rec->ul_time     = op_data->op_mod_time;
        rec->ul_bias     = op_data->op_bias;
 
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-
        tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
        LASSERT(tmp != NULL);
        LOGL0(op_data->op_name, op_data->op_namelen, tmp);
@@ -423,9 +386,6 @@ void mdc_link_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
        rec->lk_time     = op_data->op_mod_time;
        rec->lk_bias     = op_data->op_bias;
 
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-       mdc_pack_capa(req, &RMF_CAPA2, op_data->op_capa2);
-
        tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
        LOGL0(op_data->op_name, op_data->op_namelen, tmp);
 }
@@ -452,9 +412,6 @@ void mdc_rename_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
        rec->rn_mode     = op_data->op_mode;
        rec->rn_bias     = op_data->op_bias;
 
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-       mdc_pack_capa(req, &RMF_CAPA2, op_data->op_capa2);
-
        tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
        LOGL0(old, oldlen, tmp);
 
@@ -483,8 +440,6 @@ void mdc_getattr_pack(struct ptlrpc_request *req, __u64 valid, int flags,
        b->fid2 = op_data->op_fid2;
        b->valid |= OBD_MD_FLID;
 
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
-
        if (op_data->op_name) {
                char *tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
 
@@ -524,7 +479,6 @@ void mdc_close_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
        rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
 
        mdc_setattr_pack_rec(rec, op_data);
-       mdc_pack_capa(req, &RMF_CAPA1, op_data->op_capa1);
        mdc_ioepoch_pack(epoch, op_data);
        mdc_hsm_release_pack(req, op_data);
 }
index bcb6c00c49ff68d5f63122a5830ea27a58e2052f..d4bf34b61f3a6ec80b4557d5e80da1ed2a399b03 100644 (file)
@@ -322,12 +322,6 @@ static struct ptlrpc_request *mdc_intent_open_pack(struct obd_export *exp,
                return ERR_PTR(-ENOMEM);
        }
 
-       /* parent capability */
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-       /* child capability, reserve the size according to parent capa, it will
-        * be filled after we get the reply */
-       mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa1);
-
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                             op_data->op_namelen + 1);
        req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
@@ -369,15 +363,11 @@ mdc_intent_getxattr_pack(struct obd_export *exp,
        int                     rc, count = 0, maxdata;
        LIST_HEAD(cancels);
 
-
-
        req = ptlrpc_request_alloc(class_exp2cliimp(exp),
                                        &RQF_LDLM_INTENT_GETXATTR);
        if (req == NULL)
                return ERR_PTR(-ENOMEM);
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-
        rc = ldlm_prep_enqueue_req(exp, req, &cancels, count);
        if (rc) {
                ptlrpc_request_free(req);
@@ -391,8 +381,8 @@ mdc_intent_getxattr_pack(struct obd_export *exp,
        maxdata = class_exp2cliimp(exp)->imp_connect_data.ocd_max_easize;
 
        /* pack the intended request */
-       mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
-                       op_data->op_valid, maxdata, -1, 0);
+       mdc_pack_body(req, &op_data->op_fid1, op_data->op_valid, maxdata, -1,
+                     0);
 
        req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
                                RCL_SERVER, maxdata);
@@ -422,7 +412,6 @@ static struct ptlrpc_request *mdc_intent_unlink_pack(struct obd_export *exp,
        if (req == NULL)
                return ERR_PTR(-ENOMEM);
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                             op_data->op_namelen + 1);
 
@@ -455,7 +444,7 @@ static struct ptlrpc_request *mdc_intent_getattr_pack(struct obd_export *exp,
        struct obd_device     *obddev = class_exp2obd(exp);
        u64                    valid = OBD_MD_FLGETATTR | OBD_MD_FLEASIZE |
                                       OBD_MD_FLMODEASIZE | OBD_MD_FLDIREA |
-                                      OBD_MD_FLMDSCAPA | OBD_MD_MEA |
+                                      OBD_MD_MEA |
                                       (client_is_remote(exp) ?
                                               OBD_MD_FLRMTPERM : OBD_MD_FLACL);
        struct ldlm_intent    *lit;
@@ -467,7 +456,6 @@ static struct ptlrpc_request *mdc_intent_getattr_pack(struct obd_export *exp,
        if (req == NULL)
                return ERR_PTR(-ENOMEM);
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                             op_data->op_namelen + 1);
 
@@ -705,27 +693,6 @@ static int mdc_finish_enqueue(struct obd_export *exp,
                        if (perm == NULL)
                                return -EPROTO;
                }
-               if (body->valid & OBD_MD_FLMDSCAPA) {
-                       struct lustre_capa *capa, *p;
-
-                       capa = req_capsule_server_get(pill, &RMF_CAPA1);
-                       if (capa == NULL)
-                               return -EPROTO;
-
-                       if (it->it_op & IT_OPEN) {
-                               /* client fid capa will be checked in replay */
-                               p = req_capsule_client_get(pill, &RMF_CAPA2);
-                               LASSERT(p);
-                               *p = *capa;
-                       }
-               }
-               if (body->valid & OBD_MD_FLOSSCAPA) {
-                       struct lustre_capa *capa;
-
-                       capa = req_capsule_server_get(pill, &RMF_CAPA2);
-                       if (capa == NULL)
-                               return -EPROTO;
-               }
        } else if (it->it_op & IT_LAYOUT) {
                /* maybe the lock was granted right away and layout
                 * is packed into RMF_DLM_LVB of req */
@@ -826,7 +793,7 @@ resend:
                LASSERT(lmm && lmmsize == 0);
                LASSERTF(einfo->ei_type == LDLM_FLOCK, "lock type %d\n",
                         einfo->ei_type);
-               policy = (ldlm_policy_data_t *)lmm;
+               policy = lmm;
                res_id.name[3] = LDLM_FLOCK;
                req = NULL;
        } else if (it->it_op & IT_OPEN) {
@@ -864,7 +831,7 @@ resend:
        if (resends) {
                req->rq_generation_set = 1;
                req->rq_import_generation = generation;
-               req->rq_sent = get_seconds() + resends;
+               req->rq_sent = ktime_get_real_seconds() + resends;
        }
 
        /* It is important to obtain rpc_lock first (if applicable), so that
@@ -918,7 +885,7 @@ resend:
 
        /* Retry the create infinitely when we get -EINPROGRESS from
         * server. This is required by the new quota design. */
-       if (it && it->it_op & IT_CREAT &&
+       if (it->it_op & IT_CREAT &&
            (int)lockrep->lock_policy_res2 == -EINPROGRESS) {
                mdc_clear_replay_flag(req, rc);
                ptlrpc_req_finished(req);
@@ -1307,7 +1274,7 @@ int mdc_intent_getattr_async(struct obd_export *exp,
        ga->ga_einfo = einfo;
 
        req->rq_interpret_reply = mdc_intent_getattr_async_interpret;
-       ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
+       ptlrpcd_add_req(req);
 
        return 0;
 }
index 5e9c6296c39d89560e1b1a744fcc993fa1e4bd3a..c87c7d8efa074b70a62f30570cee412c73f9f45e 100644 (file)
@@ -127,7 +127,6 @@ int mdc_setattr(struct obd_export *exp, struct md_op_data *op_data,
                ldlm_lock_list_put(&cancels, l_bl_ast, count);
                return -ENOMEM;
        }
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
        if ((op_data->op_flags & (MF_SOM_CHANGE | MF_EPOCH_OPEN)) == 0)
                req_capsule_set_size(&req->rq_pill, &RMF_MDT_EPOCH, RCL_CLIENT,
                                     0);
@@ -144,8 +143,7 @@ int mdc_setattr(struct obd_export *exp, struct md_op_data *op_data,
        rpc_lock = obd->u.cli.cl_rpc_lock;
 
        if (op_data->op_attr.ia_valid & (ATTR_MTIME | ATTR_CTIME))
-               CDEBUG(D_INODE, "setting mtime "CFS_TIME_T
-                      ", ctime "CFS_TIME_T"\n",
+               CDEBUG(D_INODE, "setting mtime %ld, ctime %ld\n",
                       LTIME_S(op_data->op_attr.ia_mtime),
                       LTIME_S(op_data->op_attr.ia_ctime));
        mdc_setattr_pack(req, op_data, ea, ealen, ea2, ea2len);
@@ -243,7 +241,6 @@ rebuild:
                ldlm_lock_list_put(&cancels, l_bl_ast, count);
                return -ENOMEM;
        }
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                             op_data->op_namelen + 1);
        req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
@@ -271,7 +268,7 @@ rebuild:
        if (resends) {
                req->rq_generation_set = 1;
                req->rq_import_generation = generation;
-               req->rq_sent = get_seconds() + resends;
+               req->rq_sent = ktime_get_real_seconds() + resends;
        }
        level = LUSTRE_IMP_FULL;
  resend:
@@ -297,18 +294,6 @@ rebuild:
                        CDEBUG(D_HA, "resend cross eviction\n");
                        return -EIO;
                }
-       } else if (rc == 0) {
-               struct mdt_body *body;
-               struct lustre_capa *capa;
-
-               body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
-               LASSERT(body);
-               if (body->valid & OBD_MD_FLMDSCAPA) {
-                       capa = req_capsule_server_get(&req->rq_pill,
-                                                     &RMF_CAPA1);
-                       if (capa == NULL)
-                               rc = -EPROTO;
-               }
        }
 
        *request = req;
@@ -343,7 +328,6 @@ int mdc_unlink(struct obd_export *exp, struct md_op_data *op_data,
                ldlm_lock_list_put(&cancels, l_bl_ast, count);
                return -ENOMEM;
        }
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                             op_data->op_namelen + 1);
 
@@ -393,8 +377,6 @@ int mdc_link(struct obd_export *exp, struct md_op_data *op_data,
                ldlm_lock_list_put(&cancels, l_bl_ast, count);
                return -ENOMEM;
        }
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-       mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                             op_data->op_namelen + 1);
 
@@ -452,8 +434,6 @@ int mdc_rename(struct obd_export *exp, struct md_op_data *op_data,
                return -ENOMEM;
        }
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-       mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, oldlen + 1);
        req_capsule_set_size(&req->rq_pill, &RMF_SYMTGT, RCL_CLIENT, newlen+1);
 
index 204d512625607fa7e3fa483a0cd3f185f5bc45b2..16a5a10d371edf11de40f12dcf294bd199614261 100644 (file)
 
 #define REQUEST_MINOR 244
 
-struct mdc_renew_capa_args {
-       struct obd_capa *ra_oc;
-       renew_capa_cb_t  ra_cb;
-};
-
 static int mdc_cleanup(struct obd_device *obd);
 
-static int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
-                   const struct req_msg_field *field, struct obd_capa **oc)
-{
-       struct lustre_capa *capa;
-       struct obd_capa *c;
-
-       /* swabbed already in mdc_enqueue */
-       capa = req_capsule_server_get(&req->rq_pill, field);
-       if (capa == NULL)
-               return -EPROTO;
-
-       c = alloc_capa(CAPA_SITE_CLIENT);
-       if (IS_ERR(c)) {
-               CDEBUG(D_INFO, "alloc capa failed!\n");
-               return PTR_ERR(c);
-       }
-
-       c->c_capa = *capa;
-       *oc = c;
-       return 0;
-}
-
 static inline int mdc_queue_wait(struct ptlrpc_request *req)
 {
        struct client_obd *cli = &req->rq_import->imp_obd->u.cli;
@@ -100,23 +73,20 @@ static inline int mdc_queue_wait(struct ptlrpc_request *req)
        return rc;
 }
 
-/* Helper that implements most of mdc_getstatus and signal_completed_replay. */
-/* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
-static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
-                         struct obd_capa **pc, int level, int msg_flags)
+static int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid)
 {
        struct ptlrpc_request *req;
        struct mdt_body       *body;
        int                 rc;
 
-       req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
+       req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
+                                       &RQF_MDS_GETSTATUS,
                                        LUSTRE_MDS_VERSION, MDS_GETSTATUS);
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
-       lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
-       req->rq_send_state = level;
+       mdc_pack_body(req, NULL, 0, 0, -1, 0);
+       req->rq_send_state = LUSTRE_IMP_FULL;
 
        ptlrpc_request_set_replen(req);
 
@@ -130,12 +100,6 @@ static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
                goto out;
        }
 
-       if (body->valid & OBD_MD_FLMDSCAPA) {
-               rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
-               if (rc)
-                       goto out;
-       }
-
        *rootfid = body->fid1;
        CDEBUG(D_NET,
               "root fid="DFID", last_committed=%llu\n",
@@ -146,14 +110,6 @@ out:
        return rc;
 }
 
-/* This should be mdc_get_info("rootfid") */
-static int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
-                 struct obd_capa **pc)
-{
-       return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
-                             LUSTRE_IMP_FULL, 0);
-}
-
 /*
  * This function now is known to always saying that it will receive 4 buffers
  * from server. Even for cases when acl_size and md_size is zero, RPC header
@@ -203,14 +159,6 @@ static int mdc_getattr_common(struct obd_export *exp,
                        return -EPROTO;
        }
 
-       if (body->valid & OBD_MD_FLMDSCAPA) {
-               struct lustre_capa *capa;
-
-               capa = req_capsule_server_get(pill, &RMF_CAPA1);
-               if (capa == NULL)
-                       return -EPROTO;
-       }
-
        return 0;
 }
 
@@ -230,16 +178,14 @@ static int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
        if (rc) {
                ptlrpc_request_free(req);
                return rc;
        }
 
-       mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
-                     op_data->op_valid, op_data->op_mode, -1, 0);
+       mdc_pack_body(req, &op_data->op_fid1, op_data->op_valid,
+                     op_data->op_mode, -1, 0);
 
        req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
                             op_data->op_mode);
@@ -270,7 +216,6 @@ static int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
        req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                             op_data->op_namelen + 1);
 
@@ -280,9 +225,8 @@ static int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
                return rc;
        }
 
-       mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
-                     op_data->op_valid, op_data->op_mode,
-                     op_data->op_suppgids[0], 0);
+       mdc_pack_body(req, &op_data->op_fid1, op_data->op_valid,
+                     op_data->op_mode, op_data->op_suppgids[0], 0);
 
        if (op_data->op_name) {
                char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
@@ -333,7 +277,7 @@ static int mdc_is_subdir(struct obd_export *exp,
 static int mdc_xattr_common(struct obd_export *exp,
                            const struct req_format *fmt,
                            const struct lu_fid *fid,
-                           struct obd_capa *oc, int opcode, u64 valid,
+                           int opcode, u64 valid,
                            const char *xattr_name, const char *input,
                            int input_size, int output_size, int flags,
                            __u32 suppgid, struct ptlrpc_request **request)
@@ -348,7 +292,6 @@ static int mdc_xattr_common(struct obd_export *exp,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, oc);
        if (xattr_name) {
                xattr_namelen = strlen(xattr_name) + 1;
                req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
@@ -402,13 +345,12 @@ static int mdc_xattr_common(struct obd_export *exp,
                rec->sx_suppgid2 = -1;
                rec->sx_fid    = *fid;
                rec->sx_valid  = valid | OBD_MD_FLCTIME;
-               rec->sx_time   = get_seconds();
+               rec->sx_time   = ktime_get_real_seconds();
                rec->sx_size   = output_size;
                rec->sx_flags  = flags;
 
-               mdc_pack_capa(req, &RMF_CAPA1, oc);
        } else {
-               mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
+               mdc_pack_body(req, fid, valid, output_size, suppgid, flags);
        }
 
        if (xattr_name) {
@@ -442,23 +384,24 @@ static int mdc_xattr_common(struct obd_export *exp,
 }
 
 static int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
-                struct obd_capa *oc, u64 valid, const char *xattr_name,
-                const char *input, int input_size, int output_size,
-                int flags, __u32 suppgid, struct ptlrpc_request **request)
+                       u64 valid, const char *xattr_name,
+                       const char *input, int input_size, int output_size,
+                       int flags, __u32 suppgid,
+                       struct ptlrpc_request **request)
 {
        return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
-                               fid, oc, MDS_REINT, valid, xattr_name,
+                               fid, MDS_REINT, valid, xattr_name,
                                input, input_size, output_size, flags,
                                suppgid, request);
 }
 
 static int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
-                struct obd_capa *oc, u64 valid, const char *xattr_name,
-                const char *input, int input_size, int output_size,
-                int flags, struct ptlrpc_request **request)
+                       u64 valid, const char *xattr_name,
+                       const char *input, int input_size, int output_size,
+                       int flags, struct ptlrpc_request **request)
 {
        return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
-                               fid, oc, MDS_GETXATTR, valid, xattr_name,
+                               fid, MDS_GETXATTR, valid, xattr_name,
                                input, input_size, output_size, flags,
                                -1, request);
 }
@@ -618,34 +561,9 @@ int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
 #endif
                }
        }
-       if (md->body->valid & OBD_MD_FLMDSCAPA) {
-               struct obd_capa *oc = NULL;
-
-               rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
-               if (rc)
-                       goto out;
-               md->mds_capa = oc;
-       }
-
-       if (md->body->valid & OBD_MD_FLOSSCAPA) {
-               struct obd_capa *oc = NULL;
-
-               rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
-               if (rc)
-                       goto out;
-               md->oss_capa = oc;
-       }
 
 out:
        if (rc) {
-               if (md->oss_capa) {
-                       capa_put(md->oss_capa);
-                       md->oss_capa = NULL;
-               }
-               if (md->mds_capa) {
-                       capa_put(md->mds_capa);
-                       md->mds_capa = NULL;
-               }
 #ifdef CONFIG_FS_POSIX_ACL
                posix_acl_release(md->posix_acl);
 #endif
@@ -867,7 +785,6 @@ static int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
        int                    rc;
        int                    saved_rc = 0;
 
-
        req_fmt = &RQF_MDS_CLOSE;
        if (op_data->op_bias & MDS_HSM_RELEASE) {
                req_fmt = &RQF_MDS_RELEASE_CLOSE;
@@ -887,8 +804,6 @@ static int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
        if (rc) {
                ptlrpc_request_free(req);
@@ -989,7 +904,6 @@ static int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
        if (rc) {
                ptlrpc_request_free(req);
@@ -1046,7 +960,6 @@ static int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
        return rc;
 }
 
-
 static int mdc_readpage(struct obd_export *exp, struct md_op_data *op_data,
                        struct page **pages, struct ptlrpc_request **request)
 {
@@ -1066,8 +979,6 @@ restart_bulk:
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
        if (rc) {
                ptlrpc_request_free(req);
@@ -1090,7 +1001,7 @@ restart_bulk:
 
        mdc_readdir_pack(req, op_data->op_offset,
                         PAGE_CACHE_SIZE * op_data->op_npages,
-                        &op_data->op_fid1, op_data->op_capa1);
+                        &op_data->op_fid1);
 
        ptlrpc_request_set_replen(req);
        rc = ptlrpc_queue_wait(req);
@@ -1253,7 +1164,7 @@ static int mdc_ioc_hsm_progress(struct obd_export *exp,
                goto out;
        }
 
-       mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
+       mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
 
        /* Copy hsm_progress struct */
        req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS);
@@ -1288,7 +1199,7 @@ static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives)
                goto out;
        }
 
-       mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
+       mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
 
        /* Copy hsm_progress struct */
        archive_mask = req_capsule_client_get(&req->rq_pill,
@@ -1322,16 +1233,14 @@ static int mdc_ioc_hsm_current_action(struct obd_export *exp,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION);
        if (rc) {
                ptlrpc_request_free(req);
                return rc;
        }
 
-       mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
-                     OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
+       mdc_pack_body(req, &op_data->op_fid1, OBD_MD_FLRMTPERM, 0,
+                     op_data->op_suppgids[0], 0);
 
        ptlrpc_request_set_replen(req);
 
@@ -1366,7 +1275,7 @@ static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp)
                goto out;
        }
 
-       mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
+       mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
 
        ptlrpc_request_set_replen(req);
 
@@ -1390,16 +1299,14 @@ static int mdc_ioc_hsm_state_get(struct obd_export *exp,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET);
        if (rc != 0) {
                ptlrpc_request_free(req);
                return rc;
        }
 
-       mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
-                     OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
+       mdc_pack_body(req, &op_data->op_fid1, OBD_MD_FLRMTPERM, 0,
+                     op_data->op_suppgids[0], 0);
 
        ptlrpc_request_set_replen(req);
 
@@ -1433,16 +1340,14 @@ static int mdc_ioc_hsm_state_set(struct obd_export *exp,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET);
        if (rc) {
                ptlrpc_request_free(req);
                return rc;
        }
 
-       mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
-                     OBD_MD_FLRMTPERM, 0, op_data->op_suppgids[0], 0);
+       mdc_pack_body(req, &op_data->op_fid1, OBD_MD_FLRMTPERM, 0,
+                     op_data->op_suppgids[0], 0);
 
        /* Copy states */
        req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET);
@@ -1490,7 +1395,7 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
                return rc;
        }
 
-       mdc_pack_body(req, NULL, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
+       mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0);
 
        /* Copy hsm_request struct */
        req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST);
@@ -1799,9 +1704,6 @@ static int mdc_ioc_swap_layouts(struct obd_export *exp,
                return -ENOMEM;
        }
 
-       mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
-       mdc_set_capa_size(req, &RMF_CAPA2, op_data->op_capa2);
-
        rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count);
        if (rc) {
                ptlrpc_request_free(req);
@@ -2220,26 +2122,6 @@ static int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
                default_easize = val;
                *default_easize = exp->exp_obd->u.cli.cl_default_mds_easize;
                return 0;
-       } else if (KEY_IS(KEY_MAX_COOKIESIZE)) {
-               int mdsize, *max_cookiesize;
-
-               if (*vallen != sizeof(int))
-                       return -EINVAL;
-               mdsize = *(int *)val;
-               if (mdsize > exp->exp_obd->u.cli.cl_max_mds_cookiesize)
-                       exp->exp_obd->u.cli.cl_max_mds_cookiesize = mdsize;
-               max_cookiesize = val;
-               *max_cookiesize = exp->exp_obd->u.cli.cl_max_mds_cookiesize;
-               return 0;
-       } else if (KEY_IS(KEY_DEFAULT_COOKIESIZE)) {
-               int *default_cookiesize;
-
-               if (*vallen != sizeof(int))
-                       return -EINVAL;
-               default_cookiesize = val;
-               *default_cookiesize =
-                       exp->exp_obd->u.cli.cl_default_mds_cookiesize;
-               return 0;
        } else if (KEY_IS(KEY_CONN_DATA)) {
                struct obd_import *imp = class_exp2cliimp(exp);
                struct obd_connect_data *data = val;
@@ -2260,7 +2142,7 @@ static int mdc_get_info(const struct lu_env *env, struct obd_export *exp,
 }
 
 static int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
-                   struct obd_capa *oc, struct ptlrpc_request **request)
+                   struct ptlrpc_request **request)
 {
        struct ptlrpc_request *req;
        int                 rc;
@@ -2270,15 +2152,13 @@ static int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, oc);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
        if (rc) {
                ptlrpc_request_free(req);
                return rc;
        }
 
-       mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
+       mdc_pack_body(req, fid, 0, 0, -1, 0);
 
        ptlrpc_request_set_replen(req);
 
@@ -2544,11 +2424,9 @@ static int mdc_process_config(struct obd_device *obd, u32 len, void *buf)
        return rc;
 }
 
-
 /* get remote permission for current user on fid */
 static int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
-                              struct obd_capa *oc, __u32 suppgid,
-                              struct ptlrpc_request **request)
+                              __u32 suppgid, struct ptlrpc_request **request)
 {
        struct ptlrpc_request  *req;
        int                 rc;
@@ -2560,15 +2438,13 @@ static int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
        if (req == NULL)
                return -ENOMEM;
 
-       mdc_set_capa_size(req, &RMF_CAPA1, oc);
-
        rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
        if (rc) {
                ptlrpc_request_free(req);
                return rc;
        }
 
-       mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
+       mdc_pack_body(req, fid, OBD_MD_FLRMTPERM, 0, suppgid, 0);
 
        req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
                             sizeof(struct mdt_remote_perm));
@@ -2583,66 +2459,6 @@ static int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
        return rc;
 }
 
-static int mdc_interpret_renew_capa(const struct lu_env *env,
-                                   struct ptlrpc_request *req, void *args,
-                                   int status)
-{
-       struct mdc_renew_capa_args *ra = args;
-       struct mdt_body *body = NULL;
-       struct lustre_capa *capa;
-
-       if (status) {
-               capa = ERR_PTR(status);
-               goto out;
-       }
-
-       body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
-       if (body == NULL) {
-               capa = ERR_PTR(-EFAULT);
-               goto out;
-       }
-
-       if ((body->valid & OBD_MD_FLOSSCAPA) == 0) {
-               capa = ERR_PTR(-ENOENT);
-               goto out;
-       }
-
-       capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
-       if (!capa) {
-               capa = ERR_PTR(-EFAULT);
-               goto out;
-       }
-out:
-       ra->ra_cb(ra->ra_oc, capa);
-       return 0;
-}
-
-static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
-                         renew_capa_cb_t cb)
-{
-       struct ptlrpc_request *req;
-       struct mdc_renew_capa_args *ra;
-
-       req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
-                                       LUSTRE_MDS_VERSION, MDS_GETATTR);
-       if (req == NULL)
-               return -ENOMEM;
-
-       /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
-        * capa to renew is oss capa.
-        */
-       mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
-       ptlrpc_request_set_replen(req);
-
-       CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args));
-       ra = ptlrpc_req_async_args(req);
-       ra->ra_oc = oc;
-       ra->ra_cb = cb;
-       req->rq_interpret_reply = mdc_interpret_renew_capa;
-       ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
-       return 0;
-}
-
 static struct obd_ops mdc_obd_ops = {
        .o_owner            = THIS_MODULE,
        .o_setup            = mdc_setup,
@@ -2694,8 +2510,6 @@ static struct md_ops mdc_md_ops = {
        .m_free_lustre_md   = mdc_free_lustre_md,
        .m_set_open_replay_data = mdc_set_open_replay_data,
        .m_clear_open_replay_data = mdc_clear_open_replay_data,
-       .m_renew_capa       = mdc_renew_capa,
-       .m_unpack_capa      = mdc_unpack_capa,
        .m_get_remote_perm  = mdc_get_remote_perm,
        .m_intent_getattr_async = mdc_intent_getattr_async,
        .m_revalidate_lock      = mdc_revalidate_lock
index 34a9317d6d63cf56013a9e6be4c153bdfe38238b..8d5bc5a751a4989e8bdaf215f39080448dd739b1 100644 (file)
@@ -52,6 +52,7 @@ static int mgc_ir_state_seq_show(struct seq_file *m, void *v)
 {
        return lprocfs_mgc_rd_ir_state(m, m->private);
 }
+
 LPROC_SEQ_FOPS_RO(mgc_ir_state);
 
 static struct lprocfs_vars lprocfs_mgc_obd_vars[] = {
index 019ee2f256aa1b94b90f7c0f23af9aeebbe2a585..b81efcd997aee821093e4b907e5c5ecacc7496cd 100644 (file)
@@ -248,29 +248,15 @@ static struct config_llog_data *config_recover_log_add(struct obd_device *obd,
        struct super_block *sb)
 {
        struct config_llog_instance lcfg = *cfg;
-       struct lustre_sb_info *lsi = s2lsi(sb);
        struct config_llog_data *cld;
        char logname[32];
 
-       if (IS_OST(lsi))
-               return NULL;
-
-       /* for osp-on-ost, see lustre_start_osp() */
-       if (IS_MDT(lsi) && lcfg.cfg_instance)
-               return NULL;
-
        /* we have to use different llog for clients and mdts for cmd
         * where only clients are notified if one of cmd server restarts */
        LASSERT(strlen(fsname) < sizeof(logname) / 2);
        strcpy(logname, fsname);
-       if (IS_SERVER(lsi)) { /* mdt */
-               LASSERT(lcfg.cfg_instance == NULL);
-               lcfg.cfg_instance = sb;
-               strcat(logname, "-mdtir");
-       } else {
-               LASSERT(lcfg.cfg_instance != NULL);
-               strcat(logname, "-cliir");
-       }
+       LASSERT(lcfg.cfg_instance);
+       strcat(logname, "-cliir");
 
        cld = do_config_log_add(obd, logname, CONFIG_T_RECOVER, &lcfg, sb);
        return cld;
@@ -454,8 +440,12 @@ int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)
        struct obd_import       *imp;
        struct obd_connect_data *ocd;
        struct config_llog_data *cld;
+       int rc;
+
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
 
-       LPROCFS_CLIMP_CHECK(obd);
        imp = obd->u.cli.cl_import;
        ocd = &imp->imp_connect_data;
 
@@ -770,7 +760,7 @@ static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
                            void *data, int flag)
 {
        struct lustre_handle lockh;
-       struct config_llog_data *cld = (struct config_llog_data *)data;
+       struct config_llog_data *cld = data;
        int rc = 0;
 
        switch (flag) {
@@ -874,7 +864,7 @@ static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
                       void *data, __u32 lvb_len, void *lvb_swabber,
                       struct lustre_handle *lockh)
 {
-       struct config_llog_data *cld = (struct config_llog_data *)data;
+       struct config_llog_data *cld = data;
        struct ldlm_enqueue_info einfo = {
                .ei_type        = type,
                .ei_mode        = mode,
@@ -899,12 +889,6 @@ static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
        req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER, 0);
        ptlrpc_request_set_replen(req);
 
-       /* check if this is server or client */
-       if (cld->cld_cfg.cfg_sb) {
-               struct lustre_sb_info *lsi = s2lsi(cld->cld_cfg.cfg_sb);
-               if (lsi && IS_SERVER(lsi))
-                       short_limit = 1;
-       }
        /* Limit how long we will wait for the enqueue to complete */
        req->rq_delay_limit = short_limit ? 5 : MGC_ENQUEUE_LIMIT;
        rc = ldlm_cli_enqueue(exp, &req, &einfo, &cld->cld_resid, NULL, flags,
@@ -975,6 +959,7 @@ static int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
        if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
                struct obd_import *imp = class_exp2cliimp(exp);
                int value;
+
                if (vallen != sizeof(int))
                        return -EINVAL;
                value = *(int *)val;
@@ -992,7 +977,7 @@ static int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
        if (KEY_IS(KEY_SET_INFO)) {
                struct mgs_send_param *msp;
 
-               msp = (struct mgs_send_param *)val;
+               msp = val;
                rc =  mgc_set_mgs_param(exp, msp);
                return rc;
        }
@@ -1078,6 +1063,7 @@ static int mgc_import_event(struct obd_device *obd,
                break;
        case IMP_EVENT_INVALIDATE: {
                struct ldlm_namespace *ns = obd->obd_namespace;
+
                ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
                break;
        }
@@ -1112,7 +1098,6 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
                                  void *data, int datalen, bool mne_swab)
 {
        struct config_llog_instance *cfg = &cld->cld_cfg;
-       struct lustre_sb_info       *lsi = s2lsi(cfg->cfg_sb);
        struct mgs_nidtbl_entry *entry;
        struct lustre_cfg       *lcfg;
        struct lustre_cfg_bufs   bufs;
@@ -1131,21 +1116,10 @@ static int mgc_apply_recover_logs(struct obd_device *mgc,
        if (!inst)
                return -ENOMEM;
 
-       if (!IS_SERVER(lsi)) {
-               pos = snprintf(inst, PAGE_CACHE_SIZE, "%p", cfg->cfg_instance);
-               if (pos >= PAGE_CACHE_SIZE) {
-                       kfree(inst);
-                       return -E2BIG;
-               }
-       } else {
-               LASSERT(IS_MDT(lsi));
-               rc = server_name2svname(lsi->lsi_svname, inst, NULL,
-                                       PAGE_CACHE_SIZE);
-               if (rc) {
-                       kfree(inst);
-                       return -EINVAL;
-               }
-               pos = strlen(inst);
+       pos = snprintf(inst, PAGE_CACHE_SIZE, "%p", cfg->cfg_instance);
+       if (pos >= PAGE_CACHE_SIZE) {
+               kfree(inst);
+               return -E2BIG;
        }
 
        ++pos;
@@ -1588,7 +1562,6 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)
                config_log_get(cld);
        }
 
-
        if (cld_is_recover(cld)) {
                rc = 0; /* this is not a fatal error for recover log */
                if (rcl == 0)
@@ -1609,7 +1582,6 @@ int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)
        return rc;
 }
 
-
 /** Called from lustre_process_log.
  * LCFG_LOG_START gets the config log from the MGS, processes it to start
  * any services, and adds it to the list logs to watch (follow).
@@ -1680,6 +1652,7 @@ static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)
                                rc = mgc_process_log(obd, cld->cld_recover);
                        } else {
                                struct config_llog_data *cir = cld->cld_recover;
+
                                cld->cld_recover = NULL;
                                config_log_put(cir);
                        }
@@ -1724,7 +1697,7 @@ out:
        return rc;
 }
 
-struct obd_ops mgc_obd_ops = {
+static struct obd_ops mgc_obd_ops = {
        .o_owner        = THIS_MODULE,
        .o_setup        = mgc_setup,
        .o_precleanup   = mgc_precleanup,
index d0f70b41acf6f050f37d4f3372dc943db37ed469..acc685712ce9e62a96afa7e802add42716ef4628 100644 (file)
@@ -5,5 +5,5 @@ obdclass-y := linux/linux-module.o linux/linux-obdo.o linux/linux-sysctl.o \
              genops.o uuid.o lprocfs_status.o \
              lustre_handles.o lustre_peer.o \
              statfs_pack.o obdo.o obd_config.o obd_mount.o \
-             lu_object.o dt_object.o capa.o cl_object.o   \
+             lu_object.o cl_object.o   \
              cl_page.o cl_lock.o cl_io.o lu_ref.o acl.o lprocfs_counters.o
index 933456c502d1ce2bfd9797ff7fad3dfea1946db0..2e20cf635b2779ebd7062f18ac348368da788d65 100644 (file)
@@ -92,7 +92,6 @@ static inline void lustre_posix_acl_cpu_to_le(posix_acl_xattr_entry *d,
        d->e_id  = cpu_to_le32(s->e_id);
 }
 
-
 /* if "new_count == 0", then "new = {a_version, NULL}", NOT NULL. */
 static int lustre_posix_acl_xattr_reduce_space(posix_acl_xattr_header **header,
                                               int old_count, int new_count)
@@ -286,125 +285,6 @@ again:
        return NULL;
 }
 
-/*
- * Merge the posix ACL and the extended ACL into new posix ACL.
- */
-int lustre_acl_xattr_merge2posix(posix_acl_xattr_header *posix_header, int size,
-                                ext_acl_xattr_header *ext_header,
-                                posix_acl_xattr_header **out)
-{
-       int posix_count, posix_size, i, j;
-       int ext_count = le32_to_cpu(ext_header->a_count), pos = 0, rc = 0;
-       posix_acl_xattr_entry pe = {ACL_MASK, 0, ACL_UNDEFINED_ID};
-       posix_acl_xattr_header *new;
-       ext_acl_xattr_entry *ee, ae;
-
-       lustre_posix_acl_cpu_to_le(&pe, &pe);
-       ee = lustre_ext_acl_xattr_search(ext_header, &pe, &pos);
-       if (ee == NULL || le32_to_cpu(ee->e_stat) == ES_DEL) {
-               /* there are only base ACL entries at most. */
-               posix_count = 3;
-               posix_size = CFS_ACL_XATTR_SIZE(posix_count, posix_acl_xattr);
-               new = kzalloc(posix_size, GFP_NOFS);
-               if (unlikely(new == NULL))
-                       return -ENOMEM;
-
-               new->a_version = cpu_to_le32(CFS_ACL_XATTR_VERSION);
-               for (i = 0, j = 0; i < ext_count; i++) {
-                       lustre_ext_acl_le_to_cpu(&ae,
-                                                &ext_header->a_entries[i]);
-                       switch (ae.e_tag) {
-                       case ACL_USER_OBJ:
-                       case ACL_GROUP_OBJ:
-                       case ACL_OTHER:
-                               if (ae.e_id != ACL_UNDEFINED_ID) {
-                                       rc = -EIO;
-                                       goto _out;
-                               }
-
-                               if (ae.e_stat != ES_DEL) {
-                                       new->a_entries[j].e_tag =
-                                               ext_header->a_entries[i].e_tag;
-                                       new->a_entries[j].e_perm =
-                                               ext_header->a_entries[i].e_perm;
-                                       new->a_entries[j++].e_id =
-                                               ext_header->a_entries[i].e_id;
-                               }
-                               break;
-                       case ACL_MASK:
-                       case ACL_USER:
-                       case ACL_GROUP:
-                               if (ae.e_stat == ES_DEL)
-                                       break;
-                       default:
-                               rc = -EIO;
-                               goto _out;
-                       }
-               }
-       } else {
-               /* maybe there are valid ACL_USER or ACL_GROUP entries in the
-                * original server-side ACL, they are regarded as ES_UNC stat.*/
-               int ori_posix_count;
-
-               if (unlikely(size < 0))
-                       return -EINVAL;
-               else if (!size)
-                       ori_posix_count = 0;
-               else
-                       ori_posix_count =
-                               CFS_ACL_XATTR_COUNT(size, posix_acl_xattr);
-               posix_count = ori_posix_count + ext_count;
-               posix_size =
-                       CFS_ACL_XATTR_SIZE(posix_count, posix_acl_xattr);
-               new = kzalloc(posix_size, GFP_NOFS);
-               if (unlikely(new == NULL))
-                       return -ENOMEM;
-
-               new->a_version = cpu_to_le32(CFS_ACL_XATTR_VERSION);
-               /* 1. process the unchanged ACL entries
-                *    in the original server-side ACL. */
-               pos = 0;
-               for (i = 0, j = 0; i < ori_posix_count; i++) {
-                       ee = lustre_ext_acl_xattr_search(ext_header,
-                                       &posix_header->a_entries[i], &pos);
-                       if (ee == NULL)
-                               memcpy(&new->a_entries[j++],
-                                      &posix_header->a_entries[i],
-                                      sizeof(posix_acl_xattr_entry));
-               }
-
-               /* 2. process the non-deleted entries
-                *    from client-side extended ACL. */
-               for (i = 0; i < ext_count; i++) {
-                       if (le16_to_cpu(ext_header->a_entries[i].e_stat) !=
-                           ES_DEL) {
-                               new->a_entries[j].e_tag =
-                                               ext_header->a_entries[i].e_tag;
-                               new->a_entries[j].e_perm =
-                                               ext_header->a_entries[i].e_perm;
-                               new->a_entries[j++].e_id =
-                                               ext_header->a_entries[i].e_id;
-                       }
-               }
-       }
-
-       /* free unused space. */
-       rc = lustre_posix_acl_xattr_reduce_space(&new, posix_count, j);
-       if (rc >= 0) {
-               posix_size = rc;
-               *out = new;
-               rc = 0;
-       }
-
-_out:
-       if (rc) {
-               kfree(new);
-               posix_size = rc;
-       }
-       return posix_size;
-}
-EXPORT_SYMBOL(lustre_acl_xattr_merge2posix);
-
 /*
  * Merge the posix ACL and the extended ACL into new extended ACL.
  */
diff --git a/drivers/staging/lustre/lustre/obdclass/capa.c b/drivers/staging/lustre/lustre/obdclass/capa.c
deleted file mode 100644 (file)
index d8d1a66..0000000
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/capa.c
- *
- * Lustre Capability Hash Management
- *
- * Author: Lai Siyao<lsy@clusterfs.com>
- */
-
-#define DEBUG_SUBSYSTEM S_SEC
-
-#include <linux/fs.h>
-#include <asm/unistd.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/crypto.h>
-
-#include "../include/obd_class.h"
-#include "../include/lustre_debug.h"
-#include "../include/lustre/lustre_idl.h"
-
-#include <linux/list.h>
-#include "../include/lustre_capa.h"
-
-#define NR_CAPAHASH 32
-#define CAPA_HASH_SIZE 3000          /* for MDS & OSS */
-
-struct kmem_cache *capa_cachep = NULL;
-
-/* lock for capa hash/capa_list/fo_capa_keys */
-DEFINE_SPINLOCK(capa_lock);
-
-struct list_head capa_list[CAPA_SITE_MAX];
-
-static struct capa_hmac_alg capa_hmac_algs[] = {
-       DEF_CAPA_HMAC_ALG("sha1", SHA1, 20, 20),
-};
-/* capa count */
-int capa_count[CAPA_SITE_MAX] = { 0, };
-
-EXPORT_SYMBOL(capa_cachep);
-EXPORT_SYMBOL(capa_list);
-EXPORT_SYMBOL(capa_lock);
-EXPORT_SYMBOL(capa_count);
-
-static inline
-unsigned int ll_crypto_tfm_alg_min_keysize(struct crypto_blkcipher *tfm)
-{
-       return crypto_blkcipher_tfm(tfm)->__crt_alg->cra_blkcipher.min_keysize;
-}
-
-struct hlist_head *init_capa_hash(void)
-{
-       struct hlist_head *hash;
-       int nr_hash, i;
-
-       hash = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
-       if (!hash)
-               return NULL;
-
-       nr_hash = PAGE_CACHE_SIZE / sizeof(struct hlist_head);
-       LASSERT(nr_hash > NR_CAPAHASH);
-
-       for (i = 0; i < NR_CAPAHASH; i++)
-               INIT_HLIST_HEAD(hash + i);
-       return hash;
-}
-EXPORT_SYMBOL(init_capa_hash);
-
-static inline int capa_on_server(struct obd_capa *ocapa)
-{
-       return ocapa->c_site == CAPA_SITE_SERVER;
-}
-
-static inline void capa_delete(struct obd_capa *ocapa)
-{
-       LASSERT(capa_on_server(ocapa));
-       hlist_del_init(&ocapa->u.tgt.c_hash);
-       list_del_init(&ocapa->c_list);
-       capa_count[ocapa->c_site]--;
-       /* release the ref when alloc */
-       capa_put(ocapa);
-}
-
-void cleanup_capa_hash(struct hlist_head *hash)
-{
-       int i;
-       struct hlist_node *next;
-       struct obd_capa *oc;
-
-       spin_lock(&capa_lock);
-       for (i = 0; i < NR_CAPAHASH; i++) {
-               hlist_for_each_entry_safe(oc, next, hash + i,
-                                             u.tgt.c_hash)
-                       capa_delete(oc);
-       }
-       spin_unlock(&capa_lock);
-
-       kfree(hash);
-}
-EXPORT_SYMBOL(cleanup_capa_hash);
-
-static inline int capa_hashfn(struct lu_fid *fid)
-{
-       return (fid_oid(fid) ^ fid_ver(fid)) *
-              (unsigned long)(fid_seq(fid) + 1) % NR_CAPAHASH;
-}
-
-/* capa renewal time check is earlier than that on client, which is to prevent
- * client renew right after obtaining it. */
-static inline int capa_is_to_expire(struct obd_capa *oc)
-{
-       return time_before(cfs_time_sub(oc->c_expiry,
-                                       cfs_time_seconds(oc->c_capa.lc_timeout)*2/3),
-                          cfs_time_current());
-}
-
-static struct obd_capa *find_capa(struct lustre_capa *capa,
-                                 struct hlist_head *head, int alive)
-{
-       struct obd_capa *ocapa;
-       int len = alive ? offsetof(struct lustre_capa, lc_keyid):sizeof(*capa);
-
-       hlist_for_each_entry(ocapa, head, u.tgt.c_hash) {
-               if (memcmp(&ocapa->c_capa, capa, len))
-                       continue;
-               /* don't return one that will expire soon in this case */
-               if (alive && capa_is_to_expire(ocapa))
-                       continue;
-
-               LASSERT(capa_on_server(ocapa));
-
-               DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found");
-               return ocapa;
-       }
-
-       return NULL;
-}
-
-#define LRU_CAPA_DELETE_COUNT 12
-static inline void capa_delete_lru(struct list_head *head)
-{
-       struct obd_capa *ocapa;
-       struct list_head *node = head->next;
-       int count = 0;
-
-       /* free LRU_CAPA_DELETE_COUNT unused capa from head */
-       while (count++ < LRU_CAPA_DELETE_COUNT) {
-               ocapa = list_entry(node, struct obd_capa, c_list);
-               node = node->next;
-               if (atomic_read(&ocapa->c_refc))
-                       continue;
-
-               DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free lru");
-               capa_delete(ocapa);
-       }
-}
-
-/* add or update */
-struct obd_capa *capa_add(struct hlist_head *hash, struct lustre_capa *capa)
-{
-       struct hlist_head *head = hash + capa_hashfn(&capa->lc_fid);
-       struct obd_capa *ocapa, *old = NULL;
-       struct list_head *list = &capa_list[CAPA_SITE_SERVER];
-
-       ocapa = alloc_capa(CAPA_SITE_SERVER);
-       if (IS_ERR(ocapa))
-               return NULL;
-
-       spin_lock(&capa_lock);
-       old = find_capa(capa, head, 0);
-       if (!old) {
-               ocapa->c_capa = *capa;
-               set_capa_expiry(ocapa);
-               hlist_add_head(&ocapa->u.tgt.c_hash, head);
-               list_add_tail(&ocapa->c_list, list);
-               capa_get(ocapa);
-               capa_count[CAPA_SITE_SERVER]++;
-               if (capa_count[CAPA_SITE_SERVER] > CAPA_HASH_SIZE)
-                       capa_delete_lru(list);
-               spin_unlock(&capa_lock);
-               return ocapa;
-       }
-       capa_get(old);
-       spin_unlock(&capa_lock);
-       capa_put(ocapa);
-       return old;
-}
-EXPORT_SYMBOL(capa_add);
-
-struct obd_capa *capa_lookup(struct hlist_head *hash, struct lustre_capa *capa,
-                            int alive)
-{
-       struct obd_capa *ocapa;
-
-       spin_lock(&capa_lock);
-       ocapa = find_capa(capa, hash + capa_hashfn(&capa->lc_fid), alive);
-       if (ocapa) {
-               list_move_tail(&ocapa->c_list,
-                                  &capa_list[CAPA_SITE_SERVER]);
-               capa_get(ocapa);
-       }
-       spin_unlock(&capa_lock);
-
-       return ocapa;
-}
-EXPORT_SYMBOL(capa_lookup);
-
-static inline int ll_crypto_hmac(struct crypto_hash *tfm,
-                                u8 *key, unsigned int *keylen,
-                                struct scatterlist *sg,
-                                unsigned int size, u8 *result)
-{
-       struct hash_desc desc;
-       int           rv;
-       desc.tfm   = tfm;
-       desc.flags = 0;
-       rv = crypto_hash_setkey(desc.tfm, key, *keylen);
-       if (rv) {
-               CERROR("failed to hash setkey: %d\n", rv);
-               return rv;
-       }
-       return crypto_hash_digest(&desc, sg, size, result);
-}
-
-int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key)
-{
-       struct crypto_hash *tfm;
-       struct capa_hmac_alg  *alg;
-       int keylen;
-       struct scatterlist sl;
-
-       if (capa_alg(capa) != CAPA_HMAC_ALG_SHA1) {
-               CERROR("unknown capability hmac algorithm!\n");
-               return -EFAULT;
-       }
-
-       alg = &capa_hmac_algs[capa_alg(capa)];
-
-       tfm = crypto_alloc_hash(alg->ha_name, 0, 0);
-       if (IS_ERR(tfm)) {
-               CERROR("crypto_alloc_tfm failed, check whether your kernel has crypto support!\n");
-               return PTR_ERR(tfm);
-       }
-       keylen = alg->ha_keylen;
-
-       sg_init_table(&sl, 1);
-       sg_set_page(&sl, virt_to_page(capa),
-                   offsetof(struct lustre_capa, lc_hmac),
-                   (unsigned long)(capa) % PAGE_CACHE_SIZE);
-
-       ll_crypto_hmac(tfm, key, &keylen, &sl, sl.length, hmac);
-       crypto_free_hash(tfm);
-
-       return 0;
-}
-EXPORT_SYMBOL(capa_hmac);
-
-int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
-{
-       struct crypto_blkcipher *tfm;
-       struct scatterlist sd;
-       struct scatterlist ss;
-       struct blkcipher_desc desc;
-       unsigned int min;
-       int rc;
-       char alg[CRYPTO_MAX_ALG_NAME+1] = "aes";
-
-       /* passing "aes" in a variable instead of a constant string keeps gcc
-        * 4.3.2 happy */
-       tfm = crypto_alloc_blkcipher(alg, 0, 0);
-       if (IS_ERR(tfm)) {
-               CERROR("failed to load transform for aes\n");
-               return PTR_ERR(tfm);
-       }
-
-       min = ll_crypto_tfm_alg_min_keysize(tfm);
-       if (keylen < min) {
-               CERROR("keylen at least %d bits for aes\n", min * 8);
-               rc = -EINVAL;
-               goto out;
-       }
-
-       rc = crypto_blkcipher_setkey(tfm, key, min);
-       if (rc) {
-               CERROR("failed to setting key for aes\n");
-               goto out;
-       }
-
-       sg_init_table(&sd, 1);
-       sg_set_page(&sd, virt_to_page(d), 16,
-                   (unsigned long)(d) % PAGE_CACHE_SIZE);
-
-       sg_init_table(&ss, 1);
-       sg_set_page(&ss, virt_to_page(s), 16,
-                   (unsigned long)(s) % PAGE_CACHE_SIZE);
-       desc.tfm   = tfm;
-       desc.info  = NULL;
-       desc.flags = 0;
-       rc = crypto_blkcipher_encrypt(&desc, &sd, &ss, 16);
-       if (rc) {
-               CERROR("failed to encrypt for aes\n");
-               goto out;
-       }
-
-out:
-       crypto_free_blkcipher(tfm);
-       return rc;
-}
-EXPORT_SYMBOL(capa_encrypt_id);
-
-int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
-{
-       struct crypto_blkcipher *tfm;
-       struct scatterlist sd;
-       struct scatterlist ss;
-       struct blkcipher_desc desc;
-       unsigned int min;
-       int rc;
-       char alg[CRYPTO_MAX_ALG_NAME+1] = "aes";
-
-       /* passing "aes" in a variable instead of a constant string keeps gcc
-        * 4.3.2 happy */
-       tfm = crypto_alloc_blkcipher(alg, 0, 0);
-       if (IS_ERR(tfm)) {
-               CERROR("failed to load transform for aes\n");
-               return PTR_ERR(tfm);
-       }
-
-       min = ll_crypto_tfm_alg_min_keysize(tfm);
-       if (keylen < min) {
-               CERROR("keylen at least %d bits for aes\n", min * 8);
-               rc = -EINVAL;
-               goto out;
-       }
-
-       rc = crypto_blkcipher_setkey(tfm, key, min);
-       if (rc) {
-               CERROR("failed to setting key for aes\n");
-               goto out;
-       }
-
-       sg_init_table(&sd, 1);
-       sg_set_page(&sd, virt_to_page(d), 16,
-                   (unsigned long)(d) % PAGE_CACHE_SIZE);
-
-       sg_init_table(&ss, 1);
-       sg_set_page(&ss, virt_to_page(s), 16,
-                   (unsigned long)(s) % PAGE_CACHE_SIZE);
-
-       desc.tfm   = tfm;
-       desc.info  = NULL;
-       desc.flags = 0;
-       rc = crypto_blkcipher_decrypt(&desc, &sd, &ss, 16);
-       if (rc) {
-               CERROR("failed to decrypt for aes\n");
-               goto out;
-       }
-
-out:
-       crypto_free_blkcipher(tfm);
-       return rc;
-}
-EXPORT_SYMBOL(capa_decrypt_id);
-
-void capa_cpy(void *capa, struct obd_capa *ocapa)
-{
-       spin_lock(&ocapa->c_lock);
-       *(struct lustre_capa *)capa = ocapa->c_capa;
-       spin_unlock(&ocapa->c_lock);
-}
-EXPORT_SYMBOL(capa_cpy);
-
-void _debug_capa(struct lustre_capa *c,
-                struct libcfs_debug_msg_data *msgdata,
-                const char *fmt, ...)
-{
-       va_list args;
-       va_start(args, fmt);
-       libcfs_debug_vmsg2(msgdata, fmt, args,
-                          " capability@%p fid " DFID " opc %#llx uid %llu gid %llu flags %u alg %d keyid %u timeout %u expiry %u\n",
-                          c, PFID(capa_fid(c)), capa_opc(c),
-                          capa_uid(c), capa_gid(c), capa_flags(c),
-                          capa_alg(c), capa_keyid(c), capa_timeout(c),
-                          capa_expiry(c));
-       va_end(args);
-}
-EXPORT_SYMBOL(_debug_capa);
index fd1a4c5421e8fc7bc28152119bd41a9c1d3a532d..e67cea7584052a7784e8920c60017da196f51920 100644 (file)
@@ -307,7 +307,7 @@ static void cl_io_locks_sort(struct cl_io *io)
                                         */
                                default:
                                        LBUG();
-                               case +1:
+                               case 1:
                                        list_move_tail(&curr->cill_linkage,
                                                           &prev->cill_linkage);
                                        done = 0;
@@ -335,7 +335,7 @@ int cl_queue_match(const struct list_head *queue,
 
        list_for_each_entry(scan, queue, cill_linkage) {
               if (cl_lock_descr_match(&scan->cill_descr, need))
-                      return +1;
+                      return 1;
        }
        return 0;
 }
@@ -353,7 +353,7 @@ static int cl_queue_merge(const struct list_head *queue,
               CDEBUG(D_VFSTRACE, "lock: %d: [%lu, %lu]\n",
                      scan->cill_descr.cld_mode, scan->cill_descr.cld_start,
                      scan->cill_descr.cld_end);
-              return +1;
+              return 1;
        }
        return 0;
 
@@ -570,7 +570,8 @@ EXPORT_SYMBOL(cl_io_iter_fini);
 /**
  * Records that read or write io progressed \a nob bytes forward.
  */
-void cl_io_rw_advance(const struct lu_env *env, struct cl_io *io, size_t nob)
+static void cl_io_rw_advance(const struct lu_env *env, struct cl_io *io,
+                            size_t nob)
 {
        const struct cl_io_slice *scan;
 
@@ -589,7 +590,6 @@ void cl_io_rw_advance(const struct lu_env *env, struct cl_io *io, size_t nob)
                                                                   nob);
        }
 }
-EXPORT_SYMBOL(cl_io_rw_advance);
 
 /**
  * Adds a lock to a lockset.
@@ -600,7 +600,7 @@ int cl_io_lock_add(const struct lu_env *env, struct cl_io *io,
        int result;
 
        if (cl_lockset_merge(&io->ci_lockset, &link->cill_descr))
-               result = +1;
+               result = 1;
        else {
                list_add(&link->cill_linkage, &io->ci_lockset.cls_todo);
                result = 0;
@@ -715,6 +715,7 @@ static int cl_page_in_io(const struct cl_page *page, const struct cl_io *io)
                 */
                if (!cl_io_is_append(io)) {
                        const struct cl_io_rw_common *crw = &(io->u.ci_rw);
+
                        start = cl_offset(page->cp_obj, idx);
                        end   = cl_offset(page->cp_obj, idx + 1);
                        result = crw->crw_pos < end &&
@@ -918,7 +919,7 @@ int cl_io_submit_sync(const struct lu_env *env, struct cl_io *io,
                 */
                 cl_page_list_for_each(pg, &queue->c2_qin) {
                        pg->cp_sync_io = NULL;
-                       cl_sync_io_note(anchor, +1);
+                       cl_sync_io_note(anchor, 1);
                 }
 
                 /* wait for the IO to be finished. */
@@ -936,8 +937,8 @@ EXPORT_SYMBOL(cl_io_submit_sync);
 /**
  * Cancel an IO which has been submitted by cl_io_submit_rw.
  */
-int cl_io_cancel(const struct lu_env *env, struct cl_io *io,
-                struct cl_page_list *queue)
+static int cl_io_cancel(const struct lu_env *env, struct cl_io *io,
+                       struct cl_page_list *queue)
 {
        struct cl_page *page;
        int result = 0;
@@ -952,7 +953,6 @@ int cl_io_cancel(const struct lu_env *env, struct cl_io *io,
        }
        return result;
 }
-EXPORT_SYMBOL(cl_io_cancel);
 
 /**
  * Main io loop.
@@ -1040,7 +1040,6 @@ void cl_io_slice_add(struct cl_io *io, struct cl_io_slice *slice,
 }
 EXPORT_SYMBOL(cl_io_slice_add);
 
-
 /**
  * Initializes page list.
  */
@@ -1076,8 +1075,8 @@ EXPORT_SYMBOL(cl_page_list_add);
 /**
  * Removes a page from a page list.
  */
-void cl_page_list_del(const struct lu_env *env,
-                     struct cl_page_list *plist, struct cl_page *page)
+static void cl_page_list_del(const struct lu_env *env,
+                            struct cl_page_list *plist, struct cl_page *page)
 {
        LASSERT(plist->pl_nr > 0);
        LINVRNT(plist->pl_owner == current);
@@ -1090,7 +1089,6 @@ void cl_page_list_del(const struct lu_env *env,
        lu_ref_del_at(&page->cp_reference, &page->cp_queue_ref, "queue", plist);
        cl_page_put(env, page);
 }
-EXPORT_SYMBOL(cl_page_list_del);
 
 /**
  * Moves a page from one page list to another.
@@ -1167,7 +1165,8 @@ EXPORT_SYMBOL(cl_page_list_disown);
 /**
  * Releases pages from queue.
  */
-void cl_page_list_fini(const struct lu_env *env, struct cl_page_list *plist)
+static void cl_page_list_fini(const struct lu_env *env,
+                             struct cl_page_list *plist)
 {
        struct cl_page *page;
        struct cl_page *temp;
@@ -1178,39 +1177,12 @@ void cl_page_list_fini(const struct lu_env *env, struct cl_page_list *plist)
                cl_page_list_del(env, plist, page);
        LASSERT(plist->pl_nr == 0);
 }
-EXPORT_SYMBOL(cl_page_list_fini);
-
-/**
- * Owns all pages in a queue.
- */
-int cl_page_list_own(const struct lu_env *env,
-                    struct cl_io *io, struct cl_page_list *plist)
-{
-       struct cl_page *page;
-       struct cl_page *temp;
-       pgoff_t index = 0;
-       int result;
-
-       LINVRNT(plist->pl_owner == current);
-
-       result = 0;
-       cl_page_list_for_each_safe(page, temp, plist) {
-               LASSERT(index <= page->cp_index);
-               index = page->cp_index;
-               if (cl_page_own(env, io, page) == 0)
-                       result = result ?: page->cp_error;
-               else
-                       cl_page_list_del(env, plist, page);
-       }
-       return result;
-}
-EXPORT_SYMBOL(cl_page_list_own);
 
 /**
  * Assumes all pages in a queue.
  */
-void cl_page_list_assume(const struct lu_env *env,
-                        struct cl_io *io, struct cl_page_list *plist)
+static void cl_page_list_assume(const struct lu_env *env,
+                               struct cl_io *io, struct cl_page_list *plist)
 {
        struct cl_page *page;
 
@@ -1219,13 +1191,12 @@ void cl_page_list_assume(const struct lu_env *env,
        cl_page_list_for_each(page, plist)
                cl_page_assume(env, io, page);
 }
-EXPORT_SYMBOL(cl_page_list_assume);
 
 /**
  * Discards all pages in a queue.
  */
-void cl_page_list_discard(const struct lu_env *env, struct cl_io *io,
-                         struct cl_page_list *plist)
+static void cl_page_list_discard(const struct lu_env *env, struct cl_io *io,
+                                struct cl_page_list *plist)
 {
        struct cl_page *page;
 
@@ -1233,27 +1204,6 @@ void cl_page_list_discard(const struct lu_env *env, struct cl_io *io,
        cl_page_list_for_each(page, plist)
                cl_page_discard(env, io, page);
 }
-EXPORT_SYMBOL(cl_page_list_discard);
-
-/**
- * Unmaps all pages in a queue from user virtual memory.
- */
-int cl_page_list_unmap(const struct lu_env *env, struct cl_io *io,
-                       struct cl_page_list *plist)
-{
-       struct cl_page *page;
-       int result;
-
-       LINVRNT(plist->pl_owner == current);
-       result = 0;
-       cl_page_list_for_each(page, plist) {
-               result = cl_page_unmap(env, io, page);
-               if (result != 0)
-                       break;
-       }
-       return result;
-}
-EXPORT_SYMBOL(cl_page_list_unmap);
 
 /**
  * Initialize dual page queue.
@@ -1296,17 +1246,6 @@ void cl_2queue_discard(const struct lu_env *env,
 }
 EXPORT_SYMBOL(cl_2queue_discard);
 
-/**
- * Assume to own the pages in cl_2queue
- */
-void cl_2queue_assume(const struct lu_env *env,
-                     struct cl_io *io, struct cl_2queue *queue)
-{
-       cl_page_list_assume(env, io, &queue->c2_qin);
-       cl_page_list_assume(env, io, &queue->c2_qout);
-}
-EXPORT_SYMBOL(cl_2queue_assume);
-
 /**
  * Finalize both page lists of a 2-queue.
  */
@@ -1340,14 +1279,6 @@ struct cl_io *cl_io_top(struct cl_io *io)
 }
 EXPORT_SYMBOL(cl_io_top);
 
-/**
- * Prints human readable representation of \a io to the \a f.
- */
-void cl_io_print(const struct lu_env *env, void *cookie,
-                lu_printer_t printer, const struct cl_io *io)
-{
-}
-
 /**
  * Adds request slice to the compound request.
  *
@@ -1380,6 +1311,7 @@ static void cl_req_free(const struct lu_env *env, struct cl_req *req)
        if (req->crq_o != NULL) {
                for (i = 0; i < req->crq_nrobjs; ++i) {
                        struct cl_object *obj = req->crq_o[i].ro_obj;
+
                        if (obj != NULL) {
                                lu_object_ref_del_at(&obj->co_lu,
                                                     &req->crq_o[i].ro_obj_ref,
index b081167f97670a881020c8524b1e17502a207000..5621bebf33a9d3dc7fea98e8b4e0e45207e90a38 100644 (file)
@@ -129,6 +129,7 @@ static void cl_lock_trace0(int level, const struct lu_env *env,
                           const char *func, const int line)
 {
        struct cl_object_header *h = cl_object_header(lock->cll_descr.cld_obj);
+
        CDEBUG(level, "%s: %p@(%d %p %d %d %d %d %d %lx)(%p/%d/%d) at %s():%d\n",
               prefix, lock, atomic_read(&lock->cll_ref),
               lock->cll_guarder, lock->cll_depth,
@@ -137,6 +138,7 @@ static void cl_lock_trace0(int level, const struct lu_env *env,
               env, h->coh_nesting, cl_lock_nr_mutexed(env),
               func, line);
 }
+
 #define cl_lock_trace(level, env, prefix, lock)                         \
        cl_lock_trace0(level, env, prefix, lock, __func__, __LINE__)
 
@@ -268,7 +270,7 @@ static void cl_lock_free(const struct lu_env *env, struct cl_lock *lock)
        lu_ref_fini(&lock->cll_reference);
        lu_ref_fini(&lock->cll_holders);
        mutex_destroy(&lock->cll_guard);
-       OBD_SLAB_FREE_PTR(lock, cl_lock_kmem);
+       kmem_cache_free(cl_lock_kmem, lock);
 }
 
 /**
@@ -359,7 +361,7 @@ static struct cl_lock *cl_lock_alloc(const struct lu_env *env,
        struct cl_lock    *lock;
        struct lu_object_header *head;
 
-       OBD_SLAB_ALLOC_PTR_GFP(lock, cl_lock_kmem, GFP_NOFS);
+       lock = kmem_cache_alloc(cl_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (lock != NULL) {
                atomic_set(&lock->cll_ref, 1);
                lock->cll_descr = *descr;
@@ -403,8 +405,8 @@ static struct cl_lock *cl_lock_alloc(const struct lu_env *env,
  * \post state: CLS_INTRANSIT
  * \see CLS_INTRANSIT
  */
-enum cl_lock_state cl_lock_intransit(const struct lu_env *env,
-                                    struct cl_lock *lock)
+static enum cl_lock_state cl_lock_intransit(const struct lu_env *env,
+                                           struct cl_lock *lock)
 {
        enum cl_lock_state state = lock->cll_state;
 
@@ -418,13 +420,12 @@ enum cl_lock_state cl_lock_intransit(const struct lu_env *env,
        cl_lock_hold_add(env, lock, "intransit", current);
        return state;
 }
-EXPORT_SYMBOL(cl_lock_intransit);
 
 /**
  *  Exit the intransit state and restore the lock state to the original state
  */
-void cl_lock_extransit(const struct lu_env *env, struct cl_lock *lock,
-                      enum cl_lock_state state)
+static void cl_lock_extransit(const struct lu_env *env, struct cl_lock *lock,
+                             enum cl_lock_state state)
 {
        LASSERT(cl_lock_is_mutexed(lock));
        LASSERT(lock->cll_state == CLS_INTRANSIT);
@@ -435,7 +436,6 @@ void cl_lock_extransit(const struct lu_env *env, struct cl_lock *lock,
        cl_lock_state_set(env, lock, state);
        cl_lock_unhold(env, lock, "intransit", current);
 }
-EXPORT_SYMBOL(cl_lock_extransit);
 
 /**
  * Checking whether the lock is intransit state
@@ -1100,6 +1100,7 @@ int cl_use_try(const struct lu_env *env, struct cl_lock *lock, int atomic)
                /* @atomic means back-off-on-failure. */
                if (atomic) {
                        int rc;
+
                        rc = cl_unuse_try_internal(env, lock);
                        /* Vet the results. */
                        if (rc < 0 && result > 0)
@@ -1275,32 +1276,6 @@ static int cl_enqueue_locked(const struct lu_env *env, struct cl_lock *lock,
        return result;
 }
 
-/**
- * Enqueues a lock.
- *
- * \pre current thread or io owns a hold on lock.
- *
- * \post ergo(result == 0, lock->users increased)
- * \post ergo(result == 0, lock->cll_state == CLS_ENQUEUED ||
- *                      lock->cll_state == CLS_HELD)
- */
-int cl_enqueue(const struct lu_env *env, struct cl_lock *lock,
-              struct cl_io *io, __u32 enqflags)
-{
-       int result;
-
-       cl_lock_lockdep_acquire(env, lock, enqflags);
-       cl_lock_mutex_get(env, lock);
-       result = cl_enqueue_locked(env, lock, io, enqflags);
-       cl_lock_mutex_put(env, lock);
-       if (result != 0)
-               cl_lock_lockdep_release(env, lock);
-       LASSERT(ergo(result == 0, lock->cll_state == CLS_ENQUEUED ||
-                    lock->cll_state == CLS_HELD));
-       return result;
-}
-EXPORT_SYMBOL(cl_enqueue);
-
 /**
  * Tries to unlock a lock.
  *
@@ -2027,7 +2002,7 @@ static struct cl_lock *cl_lock_hold_mutex(const struct lu_env *env,
                cl_lock_mutex_get(env, lock);
                if (lock->cll_state < CLS_FREEING &&
                    !(lock->cll_flags & CLF_CANCELLED)) {
-                       cl_lock_hold_mod(env, lock, +1);
+                       cl_lock_hold_mod(env, lock, 1);
                        lu_ref_add(&lock->cll_holders, scope, source);
                        lu_ref_add(&lock->cll_reference, scope, source);
                        break;
@@ -2115,7 +2090,7 @@ void cl_lock_hold_add(const struct lu_env *env, struct cl_lock *lock,
        LINVRNT(cl_lock_invariant(env, lock));
        LASSERT(lock->cll_state != CLS_FREEING);
 
-       cl_lock_hold_mod(env, lock, +1);
+       cl_lock_hold_mod(env, lock, 1);
        cl_lock_get(lock);
        lu_ref_add(&lock->cll_holders, scope, source);
        lu_ref_add(&lock->cll_reference, scope, source);
@@ -2157,7 +2132,7 @@ void cl_lock_user_add(const struct lu_env *env, struct cl_lock *lock)
        LINVRNT(cl_lock_is_mutexed(lock));
        LINVRNT(cl_lock_invariant(env, lock));
 
-       cl_lock_used_mod(env, lock, +1);
+       cl_lock_used_mod(env, lock, 1);
 }
 EXPORT_SYMBOL(cl_lock_user_add);
 
index 163fe0cd7f9aa84de19034df50e54a02b1e48c97..a1a6024220ffd26c564a68cd2f875907cc8f120b 100644 (file)
@@ -97,16 +97,6 @@ int cl_object_header_init(struct cl_object_header *h)
 }
 EXPORT_SYMBOL(cl_object_header_init);
 
-/**
- * Finalize cl_object_header.
- */
-void cl_object_header_fini(struct cl_object_header *h)
-{
-       LASSERT(list_empty(&h->coh_locks));
-       lu_object_header_fini(&h->coh_lu);
-}
-EXPORT_SYMBOL(cl_object_header_fini);
-
 /**
  * Returns a cl_object with a given \a fid.
  *
@@ -363,22 +353,6 @@ void cl_object_prune(const struct lu_env *env, struct cl_object *obj)
 }
 EXPORT_SYMBOL(cl_object_prune);
 
-/**
- * Check if the object has locks.
- */
-int cl_object_has_locks(struct cl_object *obj)
-{
-       struct cl_object_header *head = cl_object_header(obj);
-       int has;
-
-       spin_lock(&head->coh_lock_guard);
-       has = list_empty(&head->coh_locks);
-       spin_unlock(&head->coh_lock_guard);
-
-       return (has == 0);
-}
-EXPORT_SYMBOL(cl_object_has_locks);
-
 void cache_stats_init(struct cache_stats *cs, const char *name)
 {
        int i;
@@ -573,7 +547,6 @@ static void cl_env_init0(struct cl_env *cle, void *debug)
        CL_ENV_INC(busy);
 }
 
-
 /*
  * The implementation of using hash table to connect cl_env and thread
  */
@@ -593,6 +566,7 @@ static unsigned cl_env_hops_hash(struct cfs_hash *lh,
 static void *cl_env_hops_obj(struct hlist_node *hn)
 {
        struct cl_env *cle = hlist_entry(hn, struct cl_env, ce_node);
+
        LASSERT(cle->ce_magic == &cl_env_init0);
        return (void *)cle;
 }
@@ -608,15 +582,16 @@ static int cl_env_hops_keycmp(const void *key, struct hlist_node *hn)
 static void cl_env_hops_noop(struct cfs_hash *hs, struct hlist_node *hn)
 {
        struct cl_env *cle = hlist_entry(hn, struct cl_env, ce_node);
+
        LASSERT(cle->ce_magic == &cl_env_init0);
 }
 
-static cfs_hash_ops_t cl_env_hops = {
+static struct cfs_hash_ops cl_env_hops = {
        .hs_hash        = cl_env_hops_hash,
-       .hs_key  = cl_env_hops_obj,
+       .hs_key         = cl_env_hops_obj,
        .hs_keycmp      = cl_env_hops_keycmp,
        .hs_object      = cl_env_hops_obj,
-       .hs_get  = cl_env_hops_noop,
+       .hs_get         = cl_env_hops_noop,
        .hs_put_locked  = cl_env_hops_noop,
 };
 
@@ -653,7 +628,8 @@ static inline void cl_env_do_detach(struct cl_env *cle)
        cle->ce_owner = NULL;
 }
 
-static int cl_env_store_init(void) {
+static int cl_env_store_init(void)
+{
        cl_env_hash = cfs_hash_create("cl_env",
                                      HASH_CL_ENV_BITS, HASH_CL_ENV_BITS,
                                      HASH_CL_ENV_BKT_BITS, 0,
@@ -661,7 +637,7 @@ static int cl_env_store_init(void) {
                                      CFS_HASH_MAX_THETA,
                                      &cl_env_hops,
                                      CFS_HASH_RW_BKTLOCK);
-       return cl_env_hash != NULL ? 0 :-ENOMEM;
+       return cl_env_hash != NULL ? 0 : -ENOMEM;
 }
 
 static void cl_env_store_fini(void)
@@ -669,7 +645,6 @@ static void cl_env_store_fini(void)
        cfs_hash_putref(cl_env_hash);
 }
 
-
 static inline struct cl_env *cl_env_detach(struct cl_env *cle)
 {
        if (cle == NULL)
@@ -686,17 +661,17 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
        struct lu_env *env;
        struct cl_env *cle;
 
-       OBD_SLAB_ALLOC_PTR_GFP(cle, cl_env_kmem, GFP_NOFS);
+       cle = kmem_cache_alloc(cl_env_kmem, GFP_NOFS | __GFP_ZERO);
        if (cle != NULL) {
                int rc;
 
                INIT_LIST_HEAD(&cle->ce_linkage);
                cle->ce_magic = &cl_env_init0;
                env = &cle->ce_lu;
-               rc = lu_env_init(env, LCT_CL_THREAD|ctx_tags);
+               rc = lu_env_init(env, ctx_tags | LCT_CL_THREAD);
                if (rc == 0) {
                        rc = lu_context_init(&cle->ce_ses,
-                                            LCT_SESSION | ses_tags);
+                                            ses_tags | LCT_SESSION);
                        if (rc == 0) {
                                lu_context_enter(&cle->ce_ses);
                                env->le_ses = &cle->ce_ses;
@@ -705,7 +680,7 @@ static struct lu_env *cl_env_new(__u32 ctx_tags, __u32 ses_tags, void *debug)
                                lu_env_fini(env);
                }
                if (rc != 0) {
-                       OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
+                       kmem_cache_free(cl_env_kmem, cle);
                        env = ERR_PTR(rc);
                } else {
                        CL_ENV_INC(create);
@@ -721,7 +696,7 @@ static void cl_env_fini(struct cl_env *cle)
        CL_ENV_DEC(total);
        lu_context_fini(&cle->ce_lu.le_ctx);
        lu_context_fini(&cle->ce_ses);
-       OBD_SLAB_FREE_PTR(cle, cl_env_kmem);
+       kmem_cache_free(cl_env_kmem, cle);
 }
 
 static inline struct cl_env *cl_env_container(struct lu_env *env)
@@ -927,21 +902,6 @@ void cl_env_nested_put(struct cl_env_nest *nest, struct lu_env *env)
 }
 EXPORT_SYMBOL(cl_env_nested_put);
 
-/**
- * Converts struct cl_attr to struct ost_lvb.
- *
- * \see cl_lvb2attr
- */
-void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr)
-{
-       lvb->lvb_size   = attr->cat_size;
-       lvb->lvb_mtime  = attr->cat_mtime;
-       lvb->lvb_atime  = attr->cat_atime;
-       lvb->lvb_ctime  = attr->cat_ctime;
-       lvb->lvb_blocks = attr->cat_blocks;
-}
-EXPORT_SYMBOL(cl_attr2lvb);
-
 /**
  * Converts struct ost_lvb to struct cl_attr.
  *
@@ -1074,7 +1034,7 @@ static struct lu_kmem_descr cl_object_caches[] = {
        {
                .ckd_cache = &cl_env_kmem,
                .ckd_name  = "cl_env_kmem",
-               .ckd_size  = sizeof (struct cl_env)
+               .ckd_size  = sizeof(struct cl_env)
        },
        {
                .ckd_cache = NULL
index d5fb81f84cd4effa1d625206ec39255c636dde04..2f569edd081143fff4473ee97d1e7bee03cc8721 100644 (file)
@@ -283,8 +283,7 @@ static struct cl_page *cl_page_alloc(const struct lu_env *env,
        struct cl_page    *page;
        struct lu_object_header *head;
 
-       OBD_ALLOC_GFP(page, cl_object_header(o)->coh_page_bufsize,
-                       GFP_NOFS);
+       page = kzalloc(cl_object_header(o)->coh_page_bufsize, GFP_NOFS);
        if (page != NULL) {
                int result = 0;
 
@@ -442,7 +441,6 @@ struct cl_page *cl_page_find(const struct lu_env *env, struct cl_object *o,
 }
 EXPORT_SYMBOL(cl_page_find);
 
-
 struct cl_page *cl_page_find_sub(const struct lu_env *env, struct cl_object *o,
                                 pgoff_t idx, struct page *vmpage,
                                 struct cl_page *parent)
@@ -904,7 +902,6 @@ int cl_page_own_try(const struct lu_env *env, struct cl_io *io,
 }
 EXPORT_SYMBOL(cl_page_own_try);
 
-
 /**
  * Assume page ownership.
  *
index 2c705d76211f88b84a52e71bc790009c5139f84e..3e9c246846907b4291d9bdf76be4687f43849fa9 100644 (file)
 #include "../include/cl_object.h"
 #include "llog_internal.h"
 
-
 struct obd_device *obd_devs[MAX_OBD_DEVICES];
 EXPORT_SYMBOL(obd_devs);
 struct list_head obd_types;
 DEFINE_RWLOCK(obd_dev_lock);
 
-__u64 obd_max_pages = 0;
-EXPORT_SYMBOL(obd_max_pages);
-__u64 obd_max_alloc = 0;
-EXPORT_SYMBOL(obd_max_alloc);
-__u64 obd_alloc;
-EXPORT_SYMBOL(obd_alloc);
-__u64 obd_pages;
-EXPORT_SYMBOL(obd_pages);
-static DEFINE_SPINLOCK(obd_updatemax_lock);
-
 /* The following are visible and mutable through /proc/sys/lustre/. */
-unsigned int obd_alloc_fail_rate = 0;
-EXPORT_SYMBOL(obd_alloc_fail_rate);
 unsigned int obd_debug_peer_on_timeout;
 EXPORT_SYMBOL(obd_debug_peer_on_timeout);
 unsigned int obd_dump_on_timeout;
@@ -81,7 +68,7 @@ EXPORT_SYMBOL(obd_timeout);
 unsigned int obd_timeout_set;
 EXPORT_SYMBOL(obd_timeout_set);
 /* Adaptive timeout defs here instead of ptlrpc module for /proc/sys/ access */
-unsigned int at_min = 0;
+unsigned int at_min;
 EXPORT_SYMBOL(at_min);
 unsigned int at_max = 600;
 EXPORT_SYMBOL(at_max);
@@ -132,25 +119,6 @@ int lustre_get_jobid(char *jobid)
 }
 EXPORT_SYMBOL(lustre_get_jobid);
 
-int obd_alloc_fail(const void *ptr, const char *name, const char *type,
-                  size_t size, const char *file, int line)
-{
-       if (ptr == NULL ||
-           (cfs_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) {
-               CERROR("%s%salloc of %s (%llu bytes) failed at %s:%d\n",
-                      ptr ? "force " :"", type, name, (__u64)size, file,
-                      line);
-               CERROR("%llu total bytes and %llu total pages"
-                       " (%llu bytes) allocated by Lustre\n",
-                      obd_memory_sum(),
-                      obd_pages_sum() << PAGE_CACHE_SHIFT,
-                      obd_pages_sum());
-               return 1;
-       }
-       return 0;
-}
-EXPORT_SYMBOL(obd_alloc_fail);
-
 static inline void obd_data2conn(struct lustre_handle *conn,
                                 struct obd_ioctl_data *data)
 {
@@ -164,7 +132,7 @@ static inline void obd_conn2data(struct obd_ioctl_data *data,
        data->ioc_cookie = conn->cookie;
 }
 
-int class_resolve_dev_name(__u32 len, const char *name)
+static int class_resolve_dev_name(__u32 len, const char *name)
 {
        int rc;
        int dev;
@@ -434,7 +402,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
 } /* class_handle_ioctl */
 
 #define OBD_INIT_CHECK
-int obd_init_checks(void)
+static int obd_init_checks(void)
 {
        __u64 u64val, div64val;
        char buf[64];
@@ -470,7 +438,7 @@ int obd_init_checks(void)
                return -EOVERFLOW;
        }
        if (do_div(div64val, 256) != (u64val & 255)) {
-               CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val &255);
+               CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
                return -EOVERFLOW;
        }
        if (u64val >> 8 != div64val) {
@@ -508,32 +476,14 @@ extern int class_procfs_clean(void);
 static int __init init_obdclass(void)
 {
        int i, err;
-       int lustre_register_fs(void);
 
-       for (i = CAPA_SITE_CLIENT; i < CAPA_SITE_MAX; i++)
-               INIT_LIST_HEAD(&capa_list[i]);
+       int lustre_register_fs(void);
 
        LCONSOLE_INFO("Lustre: Build Version: "BUILD_VERSION"\n");
 
        spin_lock_init(&obd_types_lock);
        obd_zombie_impexp_init();
 
-       obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
-                                        LPROCFS_STATS_FLAG_NONE |
-                                        LPROCFS_STATS_FLAG_IRQ_SAFE);
-
-       if (obd_memory == NULL) {
-               CERROR("kmalloc of 'obd_memory' failed\n");
-               return -ENOMEM;
-       }
-
-       lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
-                            LPROCFS_CNTR_AVGMINMAX,
-                            "memused", "bytes");
-       lprocfs_counter_init(obd_memory, OBD_MEMORY_PAGES_STAT,
-                            LPROCFS_CNTR_AVGMINMAX,
-                            "pagesused", "pages");
-
        err = obd_init_checks();
        if (err == -EOVERFLOW)
                return err;
@@ -583,7 +533,6 @@ static int __init init_obdclass(void)
        if (err != 0)
                return err;
 
-
        err = llog_info_init();
        if (err)
                return err;
@@ -593,60 +542,20 @@ static int __init init_obdclass(void)
        return err;
 }
 
-void obd_update_maxusage(void)
-{
-       __u64 max1, max2;
-
-       max1 = obd_pages_sum();
-       max2 = obd_memory_sum();
-
-       spin_lock(&obd_updatemax_lock);
-       if (max1 > obd_max_pages)
-               obd_max_pages = max1;
-       if (max2 > obd_max_alloc)
-               obd_max_alloc = max2;
-       spin_unlock(&obd_updatemax_lock);
-}
-EXPORT_SYMBOL(obd_update_maxusage);
-
-__u64 obd_memory_max(void)
-{
-       __u64 ret;
-
-       spin_lock(&obd_updatemax_lock);
-       ret = obd_max_alloc;
-       spin_unlock(&obd_updatemax_lock);
-
-       return ret;
-}
-EXPORT_SYMBOL(obd_memory_max);
-
-__u64 obd_pages_max(void)
-{
-       __u64 ret;
-
-       spin_lock(&obd_updatemax_lock);
-       ret = obd_max_pages;
-       spin_unlock(&obd_updatemax_lock);
-
-       return ret;
-}
-EXPORT_SYMBOL(obd_pages_max);
-
 /* liblustre doesn't call cleanup_obdclass, apparently.  we carry on in this
  * ifdef to the end of the file to cover module and versioning goo.*/
 static void cleanup_obdclass(void)
 {
        int i;
+
        int lustre_unregister_fs(void);
-       __u64 memory_leaked, pages_leaked;
-       __u64 memory_max, pages_max;
 
        lustre_unregister_fs();
 
        misc_deregister(&obd_psdev);
        for (i = 0; i < class_devno_max(); i++) {
                struct obd_device *obd = class_num2obd(i);
+
                if (obd && obd->obd_set_up &&
                    OBT(obd) && OBP(obd, detach)) {
                        /* XXX should this call generic detach otherwise? */
@@ -665,20 +574,6 @@ static void cleanup_obdclass(void)
        class_handle_cleanup();
        class_exit_uuidlist();
        obd_zombie_impexp_stop();
-
-       memory_leaked = obd_memory_sum();
-       pages_leaked = obd_pages_sum();
-
-       memory_max = obd_memory_max();
-       pages_max = obd_pages_max();
-
-       lprocfs_free_stats(&obd_memory);
-       CDEBUG((memory_leaked) ? D_ERROR : D_INFO,
-              "obd_memory max: %llu, leaked: %llu\n",
-              memory_max, memory_leaked);
-       CDEBUG((pages_leaked) ? D_ERROR : D_INFO,
-              "obd_memory_pages max: %llu, leaked: %llu\n",
-              pages_max, pages_leaked);
 }
 
 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
index c61add46b4268b722eeaad74a0540a4a2c48f1e8..43a7f7a79b35b691ea1a119cf8d554287538ae59 100644 (file)
 #include "../include/lustre_debug.h"
 #include "../include/lustre_net.h"
 
-void dump_lniobuf(struct niobuf_local *nb)
-{
-       CDEBUG(D_RPCTRACE,
-              "niobuf_local: file_offset=%lld, len=%d, page=%p, rc=%d\n",
-              nb->lnb_file_offset, nb->len, nb->page, nb->rc);
-       CDEBUG(D_RPCTRACE, "nb->page: index = %ld\n",
-                       nb->page ? page_index(nb->page) : -1);
-}
-EXPORT_SYMBOL(dump_lniobuf);
-
 #define LPDS sizeof(__u64)
 int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
 {
diff --git a/drivers/staging/lustre/lustre/obdclass/dt_object.c b/drivers/staging/lustre/lustre/obdclass/dt_object.c
deleted file mode 100644 (file)
index b67b0fe..0000000
+++ /dev/null
@@ -1,1054 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/dt_object.c
- *
- * Dt Object.
- * Generic functions from dt_object.h
- *
- * Author: Nikita Danilov <nikita@clusterfs.com>
- */
-
-#define DEBUG_SUBSYSTEM S_CLASS
-
-#include "../include/obd.h"
-#include "../include/dt_object.h"
-#include <linux/list.h>
-/* fid_be_to_cpu() */
-#include "../include/lustre_fid.h"
-
-/* context key constructor/destructor: dt_global_key_init, dt_global_key_fini */
-LU_KEY_INIT(dt_global, struct dt_thread_info);
-LU_KEY_FINI(dt_global, struct dt_thread_info);
-
-struct lu_context_key dt_key = {
-       .lct_tags = LCT_MD_THREAD | LCT_DT_THREAD | LCT_MG_THREAD | LCT_LOCAL,
-       .lct_init = dt_global_key_init,
-       .lct_fini = dt_global_key_fini
-};
-EXPORT_SYMBOL(dt_key);
-
-/* no lock is necessary to protect the list, because call-backs
- * are added during system startup. Please refer to "struct dt_device".
- */
-void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb)
-{
-       list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
-}
-EXPORT_SYMBOL(dt_txn_callback_add);
-
-void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb)
-{
-       list_del_init(&cb->dtc_linkage);
-}
-EXPORT_SYMBOL(dt_txn_callback_del);
-
-int dt_txn_hook_start(const struct lu_env *env,
-                     struct dt_device *dev, struct thandle *th)
-{
-       int rc = 0;
-       struct dt_txn_callback *cb;
-
-       if (th->th_local)
-               return 0;
-
-       list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
-               if (cb->dtc_txn_start == NULL ||
-                   !(cb->dtc_tag & env->le_ctx.lc_tags))
-                       continue;
-               rc = cb->dtc_txn_start(env, th, cb->dtc_cookie);
-               if (rc < 0)
-                       break;
-       }
-       return rc;
-}
-EXPORT_SYMBOL(dt_txn_hook_start);
-
-int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn)
-{
-       struct dt_device       *dev = txn->th_dev;
-       struct dt_txn_callback *cb;
-       int                  rc = 0;
-
-       if (txn->th_local)
-               return 0;
-
-       list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
-               if (cb->dtc_txn_stop == NULL ||
-                   !(cb->dtc_tag & env->le_ctx.lc_tags))
-                       continue;
-               rc = cb->dtc_txn_stop(env, txn, cb->dtc_cookie);
-               if (rc < 0)
-                       break;
-       }
-       return rc;
-}
-EXPORT_SYMBOL(dt_txn_hook_stop);
-
-void dt_txn_hook_commit(struct thandle *txn)
-{
-       struct dt_txn_callback *cb;
-
-       if (txn->th_local)
-               return;
-
-       list_for_each_entry(cb, &txn->th_dev->dd_txn_callbacks,
-                               dtc_linkage) {
-               if (cb->dtc_txn_commit)
-                       cb->dtc_txn_commit(txn, cb->dtc_cookie);
-       }
-}
-EXPORT_SYMBOL(dt_txn_hook_commit);
-
-int dt_device_init(struct dt_device *dev, struct lu_device_type *t)
-{
-
-       INIT_LIST_HEAD(&dev->dd_txn_callbacks);
-       return lu_device_init(&dev->dd_lu_dev, t);
-}
-EXPORT_SYMBOL(dt_device_init);
-
-void dt_device_fini(struct dt_device *dev)
-{
-       lu_device_fini(&dev->dd_lu_dev);
-}
-EXPORT_SYMBOL(dt_device_fini);
-
-int dt_object_init(struct dt_object *obj,
-                  struct lu_object_header *h, struct lu_device *d)
-
-{
-       return lu_object_init(&obj->do_lu, h, d);
-}
-EXPORT_SYMBOL(dt_object_init);
-
-void dt_object_fini(struct dt_object *obj)
-{
-       lu_object_fini(&obj->do_lu);
-}
-EXPORT_SYMBOL(dt_object_fini);
-
-int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj)
-{
-       if (obj->do_index_ops == NULL)
-               obj->do_ops->do_index_try(env, obj, &dt_directory_features);
-       return obj->do_index_ops != NULL;
-}
-EXPORT_SYMBOL(dt_try_as_dir);
-
-enum dt_format_type dt_mode_to_dft(__u32 mode)
-{
-       enum dt_format_type result;
-
-       switch (mode & S_IFMT) {
-       case S_IFDIR:
-               result = DFT_DIR;
-               break;
-       case S_IFREG:
-               result = DFT_REGULAR;
-               break;
-       case S_IFLNK:
-               result = DFT_SYM;
-               break;
-       case S_IFCHR:
-       case S_IFBLK:
-       case S_IFIFO:
-       case S_IFSOCK:
-               result = DFT_NODE;
-               break;
-       default:
-               LBUG();
-               break;
-       }
-       return result;
-}
-EXPORT_SYMBOL(dt_mode_to_dft);
-
-/**
- * lookup fid for object named \a name in directory \a dir.
- */
-
-int dt_lookup_dir(const struct lu_env *env, struct dt_object *dir,
-                 const char *name, struct lu_fid *fid)
-{
-       if (dt_try_as_dir(env, dir))
-               return dt_lookup(env, dir, (struct dt_rec *)fid,
-                                (const struct dt_key *)name, BYPASS_CAPA);
-       return -ENOTDIR;
-}
-EXPORT_SYMBOL(dt_lookup_dir);
-
-/* this differs from dt_locate by top_dev as parameter
- * but not one from lu_site */
-struct dt_object *dt_locate_at(const struct lu_env *env,
-                              struct dt_device *dev, const struct lu_fid *fid,
-                              struct lu_device *top_dev)
-{
-       struct lu_object *lo, *n;
-
-       lo = lu_object_find_at(env, top_dev, fid, NULL);
-       if (IS_ERR(lo))
-               return (void *)lo;
-
-       LASSERT(lo != NULL);
-
-       list_for_each_entry(n, &lo->lo_header->loh_layers, lo_linkage) {
-               if (n->lo_dev == &dev->dd_lu_dev)
-                       return container_of0(n, struct dt_object, do_lu);
-       }
-       return ERR_PTR(-ENOENT);
-}
-EXPORT_SYMBOL(dt_locate_at);
-
-/**
- * find a object named \a entry in given \a dfh->dfh_o directory.
- */
-static int dt_find_entry(const struct lu_env *env,
-                        const char *entry, void *data)
-{
-       struct dt_find_hint  *dfh = data;
-       struct dt_device     *dt = dfh->dfh_dt;
-       struct lu_fid   *fid = dfh->dfh_fid;
-       struct dt_object     *obj = dfh->dfh_o;
-       int                result;
-
-       result = dt_lookup_dir(env, obj, entry, fid);
-       lu_object_put(env, &obj->do_lu);
-       if (result == 0) {
-               obj = dt_locate(env, dt, fid);
-               if (IS_ERR(obj))
-                       result = PTR_ERR(obj);
-       }
-       dfh->dfh_o = obj;
-       return result;
-}
-
-/**
- * Abstract function which parses path name. This function feeds
- * path component to \a entry_func.
- */
-int dt_path_parser(const struct lu_env *env,
-                  char *path, dt_entry_func_t entry_func,
-                  void *data)
-{
-       char *e;
-       int rc = 0;
-
-       while (1) {
-               e = strsep(&path, "/");
-               if (e == NULL)
-                       break;
-
-               if (e[0] == 0) {
-                       if (!path || path[0] == '\0')
-                               break;
-                       continue;
-               }
-               rc = entry_func(env, e, data);
-               if (rc)
-                       break;
-       }
-
-       return rc;
-}
-
-struct dt_object *
-dt_store_resolve(const struct lu_env *env, struct dt_device *dt,
-                const char *path, struct lu_fid *fid)
-{
-       struct dt_thread_info *info = dt_info(env);
-       struct dt_find_hint   *dfh = &info->dti_dfh;
-       struct dt_object      *obj;
-       char                  *local = info->dti_buf;
-       int                    result;
-
-
-       dfh->dfh_dt = dt;
-       dfh->dfh_fid = fid;
-
-       strncpy(local, path, DT_MAX_PATH);
-       local[DT_MAX_PATH - 1] = '\0';
-
-       result = dt->dd_ops->dt_root_get(env, dt, fid);
-       if (result == 0) {
-               obj = dt_locate(env, dt, fid);
-               if (!IS_ERR(obj)) {
-                       dfh->dfh_o = obj;
-                       result = dt_path_parser(env, local, dt_find_entry, dfh);
-                       if (result != 0)
-                               obj = ERR_PTR(result);
-                       else
-                               obj = dfh->dfh_o;
-               }
-       } else {
-               obj = ERR_PTR(result);
-       }
-       return obj;
-}
-EXPORT_SYMBOL(dt_store_resolve);
-
-static struct dt_object *dt_reg_open(const struct lu_env *env,
-                                    struct dt_device *dt,
-                                    struct dt_object *p,
-                                    const char *name,
-                                    struct lu_fid *fid)
-{
-       struct dt_object *o;
-       int result;
-
-       result = dt_lookup_dir(env, p, name, fid);
-       if (result == 0)
-               o = dt_locate(env, dt, fid);
-       else
-               o = ERR_PTR(result);
-
-       return o;
-}
-
-/**
- * Open dt object named \a filename from \a dirname directory.
- *      \param  dt      dt device
- *      \param  fid     on success, object fid is stored in *fid
- */
-struct dt_object *dt_store_open(const struct lu_env *env,
-                               struct dt_device *dt,
-                               const char *dirname,
-                               const char *filename,
-                               struct lu_fid *fid)
-{
-       struct dt_object *file;
-       struct dt_object *dir;
-
-       dir = dt_store_resolve(env, dt, dirname, fid);
-       if (!IS_ERR(dir)) {
-               file = dt_reg_open(env, dt, dir,
-                                  filename, fid);
-               lu_object_put(env, &dir->do_lu);
-       } else {
-               file = dir;
-       }
-       return file;
-}
-EXPORT_SYMBOL(dt_store_open);
-
-struct dt_object *dt_find_or_create(const struct lu_env *env,
-                                   struct dt_device *dt,
-                                   const struct lu_fid *fid,
-                                   struct dt_object_format *dof,
-                                   struct lu_attr *at)
-{
-       struct dt_object *dto;
-       struct thandle *th;
-       int rc;
-
-       dto = dt_locate(env, dt, fid);
-       if (IS_ERR(dto))
-               return dto;
-
-       LASSERT(dto != NULL);
-       if (dt_object_exists(dto))
-               return dto;
-
-       th = dt_trans_create(env, dt);
-       if (IS_ERR(th)) {
-               rc = PTR_ERR(th);
-               goto out;
-       }
-
-       rc = dt_declare_create(env, dto, at, NULL, dof, th);
-       if (rc)
-               goto trans_stop;
-
-       rc = dt_trans_start_local(env, dt, th);
-       if (rc)
-               goto trans_stop;
-
-       dt_write_lock(env, dto, 0);
-       if (dt_object_exists(dto)) {
-               rc = 0;
-               goto unlock;
-       }
-
-       CDEBUG(D_OTHER, "create new object "DFID"\n", PFID(fid));
-
-       rc = dt_create(env, dto, at, NULL, dof, th);
-       if (rc)
-               goto unlock;
-       LASSERT(dt_object_exists(dto));
-unlock:
-       dt_write_unlock(env, dto);
-trans_stop:
-       dt_trans_stop(env, dt, th);
-out:
-       if (rc) {
-               lu_object_put(env, &dto->do_lu);
-               return ERR_PTR(rc);
-       }
-       return dto;
-}
-EXPORT_SYMBOL(dt_find_or_create);
-
-/* dt class init function. */
-int dt_global_init(void)
-{
-       LU_CONTEXT_KEY_INIT(&dt_key);
-       return lu_context_key_register(&dt_key);
-}
-
-void dt_global_fini(void)
-{
-       lu_context_key_degister(&dt_key);
-}
-
-/**
- * Generic read helper. May return an error for partial reads.
- *
- * \param env  lustre environment
- * \param dt   object to be read
- * \param buf  lu_buf to be filled, with buffer pointer and length
- * \param pos position to start reading, updated as data is read
- *
- * \retval real size of data read
- * \retval -ve errno on failure
- */
-int dt_read(const struct lu_env *env, struct dt_object *dt,
-           struct lu_buf *buf, loff_t *pos)
-{
-       LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
-       return dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
-}
-EXPORT_SYMBOL(dt_read);
-
-/**
- * Read structures of fixed size from storage.  Unlike dt_read(), using
- * dt_record_read() will return an error for partial reads.
- *
- * \param env  lustre environment
- * \param dt   object to be read
- * \param buf  lu_buf to be filled, with buffer pointer and length
- * \param pos position to start reading, updated as data is read
- *
- * \retval 0 on successfully reading full buffer
- * \retval -EFAULT on short read
- * \retval -ve errno on failure
- */
-int dt_record_read(const struct lu_env *env, struct dt_object *dt,
-                  struct lu_buf *buf, loff_t *pos)
-{
-       int rc;
-
-       LASSERTF(dt != NULL, "dt is NULL when we want to read record\n");
-
-       rc = dt->do_body_ops->dbo_read(env, dt, buf, pos, BYPASS_CAPA);
-
-       if (rc == buf->lb_len)
-               rc = 0;
-       else if (rc >= 0)
-               rc = -EFAULT;
-       return rc;
-}
-EXPORT_SYMBOL(dt_record_read);
-
-int dt_record_write(const struct lu_env *env, struct dt_object *dt,
-                   const struct lu_buf *buf, loff_t *pos, struct thandle *th)
-{
-       int rc;
-
-       LASSERTF(dt != NULL, "dt is NULL when we want to write record\n");
-       LASSERT(th != NULL);
-       LASSERT(dt->do_body_ops);
-       LASSERT(dt->do_body_ops->dbo_write);
-       rc = dt->do_body_ops->dbo_write(env, dt, buf, pos, th, BYPASS_CAPA, 1);
-       if (rc == buf->lb_len)
-               rc = 0;
-       else if (rc >= 0)
-               rc = -EFAULT;
-       return rc;
-}
-EXPORT_SYMBOL(dt_record_write);
-
-int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
-                          struct thandle *th)
-{
-       struct lu_buf vbuf;
-       char *xname = XATTR_NAME_VERSION;
-
-       LASSERT(o);
-       vbuf.lb_buf = NULL;
-       vbuf.lb_len = sizeof(dt_obj_version_t);
-       return dt_declare_xattr_set(env, o, &vbuf, xname, 0, th);
-
-}
-EXPORT_SYMBOL(dt_declare_version_set);
-
-void dt_version_set(const struct lu_env *env, struct dt_object *o,
-                   dt_obj_version_t version, struct thandle *th)
-{
-       struct lu_buf vbuf;
-       char *xname = XATTR_NAME_VERSION;
-       int rc;
-
-       LASSERT(o);
-       vbuf.lb_buf = &version;
-       vbuf.lb_len = sizeof(version);
-
-       rc = dt_xattr_set(env, o, &vbuf, xname, 0, th, BYPASS_CAPA);
-       if (rc < 0)
-               CDEBUG(D_INODE, "Can't set version, rc %d\n", rc);
-       return;
-}
-EXPORT_SYMBOL(dt_version_set);
-
-dt_obj_version_t dt_version_get(const struct lu_env *env, struct dt_object *o)
-{
-       struct lu_buf vbuf;
-       char *xname = XATTR_NAME_VERSION;
-       dt_obj_version_t version;
-       int rc;
-
-       LASSERT(o);
-       vbuf.lb_buf = &version;
-       vbuf.lb_len = sizeof(version);
-       rc = dt_xattr_get(env, o, &vbuf, xname, BYPASS_CAPA);
-       if (rc != sizeof(version)) {
-               CDEBUG(D_INODE, "Can't get version, rc %d\n", rc);
-               version = 0;
-       }
-       return version;
-}
-EXPORT_SYMBOL(dt_version_get);
-
-/* list of all supported index types */
-
-/* directories */
-const struct dt_index_features dt_directory_features;
-EXPORT_SYMBOL(dt_directory_features);
-
-/* scrub iterator */
-const struct dt_index_features dt_otable_features;
-EXPORT_SYMBOL(dt_otable_features);
-
-/* lfsck */
-const struct dt_index_features dt_lfsck_features = {
-       .dif_flags              = DT_IND_UPDATE,
-       .dif_keysize_min        = sizeof(struct lu_fid),
-       .dif_keysize_max        = sizeof(struct lu_fid),
-       .dif_recsize_min        = sizeof(__u8),
-       .dif_recsize_max        = sizeof(__u8),
-       .dif_ptrsize            = 4
-};
-EXPORT_SYMBOL(dt_lfsck_features);
-
-/* accounting indexes */
-const struct dt_index_features dt_acct_features = {
-       .dif_flags              = DT_IND_UPDATE,
-       .dif_keysize_min        = sizeof(__u64), /* 64-bit uid/gid */
-       .dif_keysize_max        = sizeof(__u64), /* 64-bit uid/gid */
-       .dif_recsize_min        = sizeof(struct lquota_acct_rec), /* 16 bytes */
-       .dif_recsize_max        = sizeof(struct lquota_acct_rec), /* 16 bytes */
-       .dif_ptrsize            = 4
-};
-EXPORT_SYMBOL(dt_acct_features);
-
-/* global quota files */
-const struct dt_index_features dt_quota_glb_features = {
-       .dif_flags              = DT_IND_UPDATE,
-       /* a different key would have to be used for per-directory quota */
-       .dif_keysize_min        = sizeof(__u64), /* 64-bit uid/gid */
-       .dif_keysize_max        = sizeof(__u64), /* 64-bit uid/gid */
-       .dif_recsize_min        = sizeof(struct lquota_glb_rec), /* 32 bytes */
-       .dif_recsize_max        = sizeof(struct lquota_glb_rec), /* 32 bytes */
-       .dif_ptrsize            = 4
-};
-EXPORT_SYMBOL(dt_quota_glb_features);
-
-/* slave quota files */
-const struct dt_index_features dt_quota_slv_features = {
-       .dif_flags              = DT_IND_UPDATE,
-       /* a different key would have to be used for per-directory quota */
-       .dif_keysize_min        = sizeof(__u64), /* 64-bit uid/gid */
-       .dif_keysize_max        = sizeof(__u64), /* 64-bit uid/gid */
-       .dif_recsize_min        = sizeof(struct lquota_slv_rec), /* 8 bytes */
-       .dif_recsize_max        = sizeof(struct lquota_slv_rec), /* 8 bytes */
-       .dif_ptrsize            = 4
-};
-EXPORT_SYMBOL(dt_quota_slv_features);
-
-/* helper function returning what dt_index_features structure should be used
- * based on the FID sequence. This is used by OBD_IDX_READ RPC */
-static inline const struct dt_index_features *dt_index_feat_select(__u64 seq,
-                                                                  __u32 mode)
-{
-       if (seq == FID_SEQ_QUOTA_GLB) {
-               /* global quota index */
-               if (!S_ISREG(mode))
-                       /* global quota index should be a regular file */
-                       return ERR_PTR(-ENOENT);
-               return &dt_quota_glb_features;
-       } else if (seq == FID_SEQ_QUOTA) {
-               /* quota slave index */
-               if (!S_ISREG(mode))
-                       /* slave index should be a regular file */
-                       return ERR_PTR(-ENOENT);
-               return &dt_quota_slv_features;
-       } else if (seq >= FID_SEQ_NORMAL) {
-               /* object is part of the namespace, verify that it is a
-                * directory */
-               if (!S_ISDIR(mode))
-                       /* sorry, we can only deal with directory */
-                       return ERR_PTR(-ENOTDIR);
-               return &dt_directory_features;
-       }
-
-       return ERR_PTR(-EOPNOTSUPP);
-}
-
-/*
- * Fill a lu_idxpage with key/record pairs read for transfer via OBD_IDX_READ
- * RPC
- *
- * \param env - is the environment passed by the caller
- * \param lp  - is a pointer to the lu_page to fill
- * \param nob - is the maximum number of bytes that should be copied
- * \param iops - is the index operation vector associated with the index object
- * \param it   - is a pointer to the current iterator
- * \param attr - is the index attribute to pass to iops->rec()
- * \param arg  - is a pointer to the idx_info structure
- */
-static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
-                              int nob, const struct dt_it_ops *iops,
-                              struct dt_it *it, __u32 attr, void *arg)
-{
-       struct idx_info         *ii = (struct idx_info *)arg;
-       struct lu_idxpage       *lip = &lp->lp_idx;
-       char                    *entry;
-       int                      rc, size;
-
-       /* no support for variable key & record size for now */
-       LASSERT((ii->ii_flags & II_FL_VARKEY) == 0);
-       LASSERT((ii->ii_flags & II_FL_VARREC) == 0);
-
-       /* initialize the header of the new container */
-       memset(lip, 0, LIP_HDR_SIZE);
-       lip->lip_magic = LIP_MAGIC;
-       nob        -= LIP_HDR_SIZE;
-
-       /* compute size needed to store a key/record pair */
-       size = ii->ii_recsize + ii->ii_keysize;
-       if ((ii->ii_flags & II_FL_NOHASH) == 0)
-               /* add hash if the client wants it */
-               size += sizeof(__u64);
-
-       entry = lip->lip_entries;
-       do {
-               char            *tmp_entry = entry;
-               struct dt_key   *key;
-               __u64            hash;
-
-               /* fetch 64-bit hash value */
-               hash = iops->store(env, it);
-               ii->ii_hash_end = hash;
-
-               if (OBD_FAIL_CHECK(OBD_FAIL_OBD_IDX_READ_BREAK)) {
-                       if (lip->lip_nr != 0) {
-                               rc = 0;
-                               goto out;
-                       }
-               }
-
-               if (nob < size) {
-                       if (lip->lip_nr == 0)
-                               rc = -EINVAL;
-                       else
-                               rc = 0;
-                       goto out;
-               }
-
-               if ((ii->ii_flags & II_FL_NOHASH) == 0) {
-                       /* client wants to the 64-bit hash value associated with
-                        * each record */
-                       memcpy(tmp_entry, &hash, sizeof(hash));
-                       tmp_entry += sizeof(hash);
-               }
-
-               /* then the key value */
-               LASSERT(iops->key_size(env, it) == ii->ii_keysize);
-               key = iops->key(env, it);
-               memcpy(tmp_entry, key, ii->ii_keysize);
-               tmp_entry += ii->ii_keysize;
-
-               /* and finally the record */
-               rc = iops->rec(env, it, (struct dt_rec *)tmp_entry, attr);
-               if (rc != -ESTALE) {
-                       if (rc != 0)
-                               goto out;
-
-                       /* hash/key/record successfully copied! */
-                       lip->lip_nr++;
-                       if (unlikely(lip->lip_nr == 1 && ii->ii_count == 0))
-                               ii->ii_hash_start = hash;
-                       entry = tmp_entry + ii->ii_recsize;
-                       nob -= size;
-               }
-
-               /* move on to the next record */
-               do {
-                       rc = iops->next(env, it);
-               } while (rc == -ESTALE);
-
-       } while (rc == 0);
-
-       goto out;
-out:
-       if (rc >= 0 && lip->lip_nr > 0)
-               /* one more container */
-               ii->ii_count++;
-       if (rc > 0)
-               /* no more entries */
-               ii->ii_hash_end = II_END_OFF;
-       return rc;
-}
-
-/*
- * Walk index and fill lu_page containers with key/record pairs
- *
- * \param env - is the environment passed by the caller
- * \param obj - is the index object to parse
- * \param rdpg - is the lu_rdpg descriptor associated with the transfer
- * \param filler - is the callback function responsible for filling a lu_page
- *              with key/record pairs in the format wanted by the caller
- * \param arg    - is an opaq argument passed to the filler function
- *
- * \retval sum (in bytes) of all filled lu_pages
- * \retval -ve errno on failure
- */
-int dt_index_walk(const struct lu_env *env, struct dt_object *obj,
-                 const struct lu_rdpg *rdpg, dt_index_page_build_t filler,
-                 void *arg)
-{
-       struct dt_it            *it;
-       const struct dt_it_ops  *iops;
-       unsigned int             pageidx, nob, nlupgs = 0;
-       int                      rc;
-
-       LASSERT(rdpg->rp_pages != NULL);
-       LASSERT(obj->do_index_ops != NULL);
-
-       nob = rdpg->rp_count;
-       if (nob <= 0)
-               return -EFAULT;
-
-       /* Iterate through index and fill containers from @rdpg */
-       iops = &obj->do_index_ops->dio_it;
-       LASSERT(iops != NULL);
-       it = iops->init(env, obj, rdpg->rp_attrs, BYPASS_CAPA);
-       if (IS_ERR(it))
-               return PTR_ERR(it);
-
-       rc = iops->load(env, it, rdpg->rp_hash);
-       if (rc == 0) {
-               /*
-                * Iterator didn't find record with exactly the key requested.
-                *
-                * It is currently either
-                *
-                *     - positioned above record with key less than
-                *     requested---skip it.
-                *     - or not positioned at all (is in IAM_IT_SKEWED
-                *     state)---position it on the next item.
-                */
-               rc = iops->next(env, it);
-       } else if (rc > 0) {
-               rc = 0;
-       }
-
-       /* Fill containers one after the other. There might be multiple
-        * containers per physical page.
-        *
-        * At this point and across for-loop:
-        *  rc == 0 -> ok, proceed.
-        *  rc >  0 -> end of index.
-        *  rc <  0 -> error. */
-       for (pageidx = 0; rc == 0 && nob > 0; pageidx++) {
-               union lu_page   *lp;
-               int              i;
-
-               LASSERT(pageidx < rdpg->rp_npages);
-               lp = kmap(rdpg->rp_pages[pageidx]);
-
-               /* fill lu pages */
-               for (i = 0; i < LU_PAGE_COUNT; i++, lp++, nob -= LU_PAGE_SIZE) {
-                       rc = filler(env, lp, min_t(int, nob, LU_PAGE_SIZE),
-                                   iops, it, rdpg->rp_attrs, arg);
-                       if (rc < 0)
-                               break;
-                       /* one more lu_page */
-                       nlupgs++;
-                       if (rc > 0)
-                               /* end of index */
-                               break;
-               }
-               kunmap(rdpg->rp_pages[i]);
-       }
-
-       iops->put(env, it);
-       iops->fini(env, it);
-
-       if (rc >= 0)
-               rc = min_t(unsigned int, nlupgs * LU_PAGE_SIZE, rdpg->rp_count);
-
-       return rc;
-}
-EXPORT_SYMBOL(dt_index_walk);
-
-/**
- * Walk key/record pairs of an index and copy them into 4KB containers to be
- * transferred over the network. This is the common handler for OBD_IDX_READ
- * RPC processing.
- *
- * \param env - is the environment passed by the caller
- * \param dev - is the dt_device storing the index
- * \param ii  - is the idx_info structure packed by the client in the
- *           OBD_IDX_READ request
- * \param rdpg - is the lu_rdpg descriptor
- *
- * \retval on success, return sum (in bytes) of all filled containers
- * \retval appropriate error otherwise.
- */
-int dt_index_read(const struct lu_env *env, struct dt_device *dev,
-                 struct idx_info *ii, const struct lu_rdpg *rdpg)
-{
-       const struct dt_index_features  *feat;
-       struct dt_object                *obj;
-       int                              rc;
-
-       /* rp_count shouldn't be null and should be a multiple of the container
-        * size */
-       if (rdpg->rp_count <= 0 && (rdpg->rp_count & (LU_PAGE_SIZE - 1)) != 0)
-               return -EFAULT;
-
-       if (fid_seq(&ii->ii_fid) >= FID_SEQ_NORMAL)
-               /* we don't support directory transfer via OBD_IDX_READ for the
-                * time being */
-               return -EOPNOTSUPP;
-
-       if (!fid_is_quota(&ii->ii_fid))
-               /* block access to all local files except quota files */
-               return -EPERM;
-
-       /* lookup index object subject to the transfer */
-       obj = dt_locate(env, dev, &ii->ii_fid);
-       if (IS_ERR(obj))
-               return PTR_ERR(obj);
-       if (dt_object_exists(obj) == 0) {
-               rc = -ENOENT;
-               goto out;
-       }
-
-       /* fetch index features associated with index object */
-       feat = dt_index_feat_select(fid_seq(&ii->ii_fid),
-                                   lu_object_attr(&obj->do_lu));
-       if (IS_ERR(feat)) {
-               rc = PTR_ERR(feat);
-               goto out;
-       }
-
-       /* load index feature if not done already */
-       if (obj->do_index_ops == NULL) {
-               rc = obj->do_ops->do_index_try(env, obj, feat);
-               if (rc)
-                       goto out;
-       }
-
-       /* fill ii_flags with supported index features */
-       ii->ii_flags &= II_FL_NOHASH;
-
-       ii->ii_keysize = feat->dif_keysize_max;
-       if ((feat->dif_flags & DT_IND_VARKEY) != 0) {
-               /* key size is variable */
-               ii->ii_flags |= II_FL_VARKEY;
-               /* we don't support variable key size for the time being */
-               rc = -EOPNOTSUPP;
-               goto out;
-       }
-
-       ii->ii_recsize = feat->dif_recsize_max;
-       if ((feat->dif_flags & DT_IND_VARREC) != 0) {
-               /* record size is variable */
-               ii->ii_flags |= II_FL_VARREC;
-               /* we don't support variable record size for the time being */
-               rc = -EOPNOTSUPP;
-               goto out;
-       }
-
-       if ((feat->dif_flags & DT_IND_NONUNQ) != 0)
-               /* key isn't necessarily unique */
-               ii->ii_flags |= II_FL_NONUNQ;
-
-       dt_read_lock(env, obj, 0);
-       /* fetch object version before walking the index */
-       ii->ii_version = dt_version_get(env, obj);
-
-       /* walk the index and fill lu_idxpages with key/record pairs */
-       rc = dt_index_walk(env, obj, rdpg, dt_index_page_build, ii);
-       dt_read_unlock(env, obj);
-
-       if (rc == 0) {
-               /* index is empty */
-               LASSERT(ii->ii_count == 0);
-               ii->ii_hash_end = II_END_OFF;
-       }
-
-       goto out;
-out:
-       lu_object_put(env, &obj->do_lu);
-       return rc;
-}
-EXPORT_SYMBOL(dt_index_read);
-
-int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
-                         int count, int *eof, void *data)
-{
-       struct dt_device *dt = data;
-       struct obd_statfs osfs;
-       int rc = dt_statfs(NULL, dt, &osfs);
-
-       if (rc == 0) {
-               *eof = 1;
-               rc = snprintf(page, count, "%u\n",
-                               (unsigned) osfs.os_bsize);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_dt_rd_blksize);
-
-int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
-                             int count, int *eof, void *data)
-{
-       struct dt_device *dt = data;
-       struct obd_statfs osfs;
-       int rc = dt_statfs(NULL, dt, &osfs);
-
-       if (rc == 0) {
-               __u32 blk_size = osfs.os_bsize >> 10;
-               __u64 result = osfs.os_blocks;
-
-               while (blk_size >>= 1)
-                       result <<= 1;
-
-               *eof = 1;
-               rc = snprintf(page, count, "%llu\n", result);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_dt_rd_kbytestotal);
-
-int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
-                            int count, int *eof, void *data)
-{
-       struct dt_device *dt = data;
-       struct obd_statfs osfs;
-       int rc = dt_statfs(NULL, dt, &osfs);
-
-       if (rc == 0) {
-               __u32 blk_size = osfs.os_bsize >> 10;
-               __u64 result = osfs.os_bfree;
-
-               while (blk_size >>= 1)
-                       result <<= 1;
-
-               *eof = 1;
-               rc = snprintf(page, count, "%llu\n", result);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_dt_rd_kbytesfree);
-
-int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
-                             int count, int *eof, void *data)
-{
-       struct dt_device *dt = data;
-       struct obd_statfs osfs;
-       int rc = dt_statfs(NULL, dt, &osfs);
-
-       if (rc == 0) {
-               __u32 blk_size = osfs.os_bsize >> 10;
-               __u64 result = osfs.os_bavail;
-
-               while (blk_size >>= 1)
-                       result <<= 1;
-
-               *eof = 1;
-               rc = snprintf(page, count, "%llu\n", result);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_dt_rd_kbytesavail);
-
-int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
-                            int count, int *eof, void *data)
-{
-       struct dt_device *dt = data;
-       struct obd_statfs osfs;
-       int rc = dt_statfs(NULL, dt, &osfs);
-
-       if (rc == 0) {
-               *eof = 1;
-               rc = snprintf(page, count, "%llu\n", osfs.os_files);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_dt_rd_filestotal);
-
-int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
-                           int count, int *eof, void *data)
-{
-       struct dt_device *dt = data;
-       struct obd_statfs osfs;
-       int rc = dt_statfs(NULL, dt, &osfs);
-
-       if (rc == 0) {
-               *eof = 1;
-               rc = snprintf(page, count, "%llu\n", osfs.os_ffree);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_dt_rd_filesfree);
index 0ca730948f7adbea81ecccba24f18db198e20835..6477aeb88028c93573192d0fce8b09e00ddb58b6 100644 (file)
@@ -56,8 +56,6 @@ static spinlock_t  obd_zombie_impexp_lock;
 static void obd_zombie_impexp_notify(void);
 static void obd_zombie_export_add(struct obd_export *exp);
 static void obd_zombie_import_add(struct obd_import *imp);
-static void print_export_data(struct obd_export *exp,
-                             const char *status, int locks);
 
 int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
 EXPORT_SYMBOL(ptlrpc_put_connection_superhack);
@@ -70,7 +68,7 @@ static struct obd_device *obd_device_alloc(void)
 {
        struct obd_device *obd;
 
-       OBD_SLAB_ALLOC_PTR_GFP(obd, obd_device_cachep, GFP_NOFS);
+       obd = kmem_cache_alloc(obd_device_cachep, GFP_NOFS | __GFP_ZERO);
        if (obd != NULL)
                obd->obd_magic = OBD_DEVICE_MAGIC;
        return obd;
@@ -87,10 +85,10 @@ static void obd_device_free(struct obd_device *obd)
                LBUG();
        }
        lu_ref_fini(&obd->obd_reference);
-       OBD_SLAB_FREE_PTR(obd, obd_device_cachep);
+       kmem_cache_free(obd_device_cachep, obd);
 }
 
-struct obd_type *class_search_type(const char *name)
+static struct obd_type *class_search_type(const char *name)
 {
        struct list_head *tmp;
        struct obd_type *type;
@@ -106,9 +104,8 @@ struct obd_type *class_search_type(const char *name)
        spin_unlock(&obd_types_lock);
        return NULL;
 }
-EXPORT_SYMBOL(class_search_type);
 
-struct obd_type *class_get_type(const char *name)
+static struct obd_type *class_get_type(const char *name)
 {
        struct obd_type *type = class_search_type(name);
 
@@ -140,7 +137,6 @@ struct obd_type *class_get_type(const char *name)
        }
        return type;
 }
-EXPORT_SYMBOL(class_get_type);
 
 void class_put_type(struct obd_type *type)
 {
@@ -178,9 +174,9 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
        type->typ_md_ops = kzalloc(sizeof(*type->typ_md_ops), GFP_NOFS);
        type->typ_name = kzalloc(strlen(name) + 1, GFP_NOFS);
 
-       if (type->typ_dt_ops == NULL ||
-           type->typ_md_ops == NULL ||
-           type->typ_name == NULL)
+       if (!type->typ_dt_ops ||
+           !type->typ_md_ops ||
+           !type->typ_name)
                goto failed;
 
        *(type->typ_dt_ops) = *dt_ops;
@@ -293,13 +289,13 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
        }
 
        type = class_get_type(type_name);
-       if (type == NULL) {
+       if (!type) {
                CERROR("OBD: unknown type: %s\n", type_name);
                return ERR_PTR(-ENODEV);
        }
 
        newdev = obd_device_alloc();
-       if (newdev == NULL) {
+       if (!newdev) {
                result = ERR_PTR(-ENOMEM);
                goto out_type;
        }
@@ -339,7 +335,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
        }
        write_unlock(&obd_dev_lock);
 
-       if (result == NULL && i >= class_devno_max()) {
+       if (!result && i >= class_devno_max()) {
                CERROR("all %u OBD devices used, increase MAX_OBD_DEVICES\n",
                       class_devno_max());
                result = ERR_PTR(-EOVERFLOW);
@@ -439,15 +435,6 @@ int class_uuid2dev(struct obd_uuid *uuid)
 }
 EXPORT_SYMBOL(class_uuid2dev);
 
-struct obd_device *class_uuid2obd(struct obd_uuid *uuid)
-{
-       int dev = class_uuid2dev(uuid);
-       if (dev < 0)
-               return NULL;
-       return class_num2obd(dev);
-}
-EXPORT_SYMBOL(class_uuid2obd);
-
 /**
  * Get obd device from ::obd_devs[]
  *
@@ -462,7 +449,7 @@ struct obd_device *class_num2obd(int num)
 
        if (num < class_devno_max()) {
                obd = obd_devs[num];
-               if (obd == NULL)
+               if (!obd)
                        return NULL;
 
                LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
@@ -477,55 +464,6 @@ struct obd_device *class_num2obd(int num)
 }
 EXPORT_SYMBOL(class_num2obd);
 
-/**
- * Get obd devices count. Device in any
- *    state are counted
- * \retval obd device count
- */
-int get_devices_count(void)
-{
-       int index, max_index = class_devno_max(), dev_count = 0;
-
-       read_lock(&obd_dev_lock);
-       for (index = 0; index <= max_index; index++) {
-               struct obd_device *obd = class_num2obd(index);
-               if (obd != NULL)
-                       dev_count++;
-       }
-       read_unlock(&obd_dev_lock);
-
-       return dev_count;
-}
-EXPORT_SYMBOL(get_devices_count);
-
-void class_obd_list(void)
-{
-       char *status;
-       int i;
-
-       read_lock(&obd_dev_lock);
-       for (i = 0; i < class_devno_max(); i++) {
-               struct obd_device *obd = class_num2obd(i);
-
-               if (obd == NULL)
-                       continue;
-               if (obd->obd_stopping)
-                       status = "ST";
-               else if (obd->obd_set_up)
-                       status = "UP";
-               else if (obd->obd_attached)
-                       status = "AT";
-               else
-                       status = "--";
-               LCONSOLE(D_CONFIG, "%3d %s %s %s %s %d\n",
-                        i, status, obd->obd_type->typ_name,
-                        obd->obd_name, obd->obd_uuid.uuid,
-                        atomic_read(&obd->obd_refcount));
-       }
-       read_unlock(&obd_dev_lock);
-       return;
-}
-
 /* Search for a client OBD connected to tgt_uuid.  If grp_uuid is
    specified, then only the client with that uuid is returned,
    otherwise any client connected to the tgt is returned. */
@@ -539,13 +477,13 @@ struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
        for (i = 0; i < class_devno_max(); i++) {
                struct obd_device *obd = class_num2obd(i);
 
-               if (obd == NULL)
+               if (!obd)
                        continue;
                if ((strncmp(obd->obd_type->typ_name, typ_name,
                             strlen(typ_name)) == 0)) {
                        if (obd_uuid_equals(tgt_uuid,
                                            &obd->u.cli.cl_target_uuid) &&
-                           ((grp_uuid)? obd_uuid_equals(grp_uuid,
+                           ((grp_uuid) ? obd_uuid_equals(grp_uuid,
                                                         &obd->obd_uuid) : 1)) {
                                read_unlock(&obd_dev_lock);
                                return obd;
@@ -566,7 +504,7 @@ struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid, int *next)
 {
        int i;
 
-       if (next == NULL)
+       if (!next)
                i = 0;
        else if (*next >= 0 && *next < class_devno_max())
                i = *next;
@@ -577,10 +515,10 @@ struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid, int *next)
        for (; i < class_devno_max(); i++) {
                struct obd_device *obd = class_num2obd(i);
 
-               if (obd == NULL)
+               if (!obd)
                        continue;
                if (obd_uuid_equals(grp_uuid, &obd->obd_uuid)) {
-                       if (next != NULL)
+                       if (next)
                                *next = i+1;
                        read_unlock(&obd_dev_lock);
                        return obd;
@@ -608,7 +546,7 @@ int class_notify_sptlrpc_conf(const char *fsname, int namelen)
        for (i = 0; i < class_devno_max(); i++) {
                obd = class_num2obd(i);
 
-               if (obd == NULL || obd->obd_set_up == 0 || obd->obd_stopping)
+               if (!obd || obd->obd_set_up == 0 || obd->obd_stopping)
                        continue;
 
                /* only notify mdc, osc, mdt, ost */
@@ -638,52 +576,36 @@ EXPORT_SYMBOL(class_notify_sptlrpc_conf);
 
 void obd_cleanup_caches(void)
 {
-       if (obd_device_cachep) {
-               kmem_cache_destroy(obd_device_cachep);
-               obd_device_cachep = NULL;
-       }
-       if (obdo_cachep) {
-               kmem_cache_destroy(obdo_cachep);
-               obdo_cachep = NULL;
-       }
-       if (import_cachep) {
-               kmem_cache_destroy(import_cachep);
-               import_cachep = NULL;
-       }
-       if (capa_cachep) {
-               kmem_cache_destroy(capa_cachep);
-               capa_cachep = NULL;
-       }
+       kmem_cache_destroy(obd_device_cachep);
+       obd_device_cachep = NULL;
+       kmem_cache_destroy(obdo_cachep);
+       obdo_cachep = NULL;
+       kmem_cache_destroy(import_cachep);
+       import_cachep = NULL;
 }
 
 int obd_init_caches(void)
 {
-       LASSERT(obd_device_cachep == NULL);
+       LASSERT(!obd_device_cachep);
        obd_device_cachep = kmem_cache_create("ll_obd_dev_cache",
                                                 sizeof(struct obd_device),
                                                 0, 0, NULL);
        if (!obd_device_cachep)
                goto out;
 
-       LASSERT(obdo_cachep == NULL);
+       LASSERT(!obdo_cachep);
        obdo_cachep = kmem_cache_create("ll_obdo_cache", sizeof(struct obdo),
                                           0, 0, NULL);
        if (!obdo_cachep)
                goto out;
 
-       LASSERT(import_cachep == NULL);
+       LASSERT(!import_cachep);
        import_cachep = kmem_cache_create("ll_import_cache",
                                             sizeof(struct obd_import),
                                             0, 0, NULL);
        if (!import_cachep)
                goto out;
 
-       LASSERT(capa_cachep == NULL);
-       capa_cachep = kmem_cache_create("capa_cache",
-                                          sizeof(struct obd_capa), 0, 0, NULL);
-       if (!capa_cachep)
-               goto out;
-
        return 0;
  out:
        obd_cleanup_caches();
@@ -720,36 +642,15 @@ struct obd_device *class_exp2obd(struct obd_export *exp)
 }
 EXPORT_SYMBOL(class_exp2obd);
 
-struct obd_device *class_conn2obd(struct lustre_handle *conn)
-{
-       struct obd_export *export;
-       export = class_conn2export(conn);
-       if (export) {
-               struct obd_device *obd = export->exp_obd;
-               class_export_put(export);
-               return obd;
-       }
-       return NULL;
-}
-EXPORT_SYMBOL(class_conn2obd);
-
 struct obd_import *class_exp2cliimp(struct obd_export *exp)
 {
        struct obd_device *obd = exp->exp_obd;
-       if (obd == NULL)
-               return NULL;
-       return obd->u.cli.cl_import;
-}
-EXPORT_SYMBOL(class_exp2cliimp);
 
-struct obd_import *class_conn2cliimp(struct lustre_handle *conn)
-{
-       struct obd_device *obd = class_conn2obd(conn);
-       if (obd == NULL)
+       if (!obd)
                return NULL;
        return obd->u.cli.cl_import;
 }
-EXPORT_SYMBOL(class_conn2cliimp);
+EXPORT_SYMBOL(class_exp2cliimp);
 
 /* Export management functions */
 static void class_export_destroy(struct obd_export *exp)
@@ -849,11 +750,9 @@ struct obd_export *class_new_export(struct obd_device *obd,
        INIT_LIST_HEAD(&export->exp_handle.h_link);
        INIT_LIST_HEAD(&export->exp_hp_rpcs);
        class_handle_hash(&export->exp_handle, &export_handle_ops);
-       export->exp_last_request_time = get_seconds();
        spin_lock_init(&export->exp_lock);
        spin_lock_init(&export->exp_rpc_lock);
        INIT_HLIST_NODE(&export->exp_uuid_hash);
-       INIT_HLIST_NODE(&export->exp_nid_hash);
        spin_lock_init(&export->exp_bl_list_lock);
        INIT_LIST_HEAD(&export->exp_bl_list);
 
@@ -870,7 +769,7 @@ struct obd_export *class_new_export(struct obd_device *obd,
        }
 
        hash = cfs_hash_getref(obd->obd_uuid_hash);
-       if (hash == NULL) {
+       if (!hash) {
                rc = -ENODEV;
                goto exit_unlock;
        }
@@ -895,8 +794,6 @@ struct obd_export *class_new_export(struct obd_device *obd,
 
        class_incref(obd, "export", export);
        list_add(&export->exp_obd_chain, &export->exp_obd->obd_exports);
-       list_add_tail(&export->exp_obd_chain_timed,
-                         &export->exp_obd->obd_exports_timed);
        export->exp_obd->obd_num_exports++;
        spin_unlock(&obd->obd_dev_lock);
        cfs_hash_putref(hash);
@@ -927,7 +824,6 @@ void class_unlink_export(struct obd_export *exp)
                             &exp->exp_uuid_hash);
 
        list_move(&exp->exp_obd_chain, &exp->exp_obd->obd_unlinked_exports);
-       list_del_init(&exp->exp_obd_chain_timed);
        exp->exp_obd->obd_num_exports--;
        spin_unlock(&exp->exp_obd->obd_dev_lock);
        class_export_put(exp);
@@ -954,7 +850,7 @@ static void class_import_destroy(struct obd_import *imp)
                kfree(imp_conn);
        }
 
-       LASSERT(imp->imp_sec == NULL);
+       LASSERT(!imp->imp_sec);
        class_decref(imp->imp_obd, "import", imp);
        OBD_FREE_RCU(imp, sizeof(*imp), &imp->imp_handle);
 }
@@ -1001,6 +897,7 @@ EXPORT_SYMBOL(class_import_put);
 static void init_imp_at(struct imp_at *at)
 {
        int i;
+
        at_init(&at->iat_net_latency, 0, 0);
        for (i = 0; i < IMP_AT_MAX_PORTALS; i++) {
                /* max service estimates are tracked on the server side, so
@@ -1078,7 +975,7 @@ void __class_export_add_lock_ref(struct obd_export *exp, struct ldlm_lock *lock)
                LCONSOLE_WARN("setting export %p for lock %p which already has export %p\n",
                              exp, lock, lock->l_exp_refs_target);
        }
-       if ((lock->l_exp_refs_nr ++) == 0) {
+       if ((lock->l_exp_refs_nr++) == 0) {
                list_add(&lock->l_exp_refs_link, &exp->exp_locks_list);
                lock->l_exp_refs_target = exp;
        }
@@ -1115,6 +1012,7 @@ int class_connect(struct lustre_handle *conn, struct obd_device *obd,
                  struct obd_uuid *cluuid)
 {
        struct obd_export *export;
+
        LASSERT(conn != NULL);
        LASSERT(obd != NULL);
        LASSERT(cluuid != NULL);
@@ -1132,51 +1030,6 @@ int class_connect(struct lustre_handle *conn, struct obd_device *obd,
 }
 EXPORT_SYMBOL(class_connect);
 
-/* if export is involved in recovery then clean up related things */
-static void class_export_recovery_cleanup(struct obd_export *exp)
-{
-       struct obd_device *obd = exp->exp_obd;
-
-       spin_lock(&obd->obd_recovery_task_lock);
-       if (exp->exp_delayed)
-               obd->obd_delayed_clients--;
-       if (obd->obd_recovering) {
-               if (exp->exp_in_recovery) {
-                       spin_lock(&exp->exp_lock);
-                       exp->exp_in_recovery = 0;
-                       spin_unlock(&exp->exp_lock);
-                       LASSERT_ATOMIC_POS(&obd->obd_connected_clients);
-                       atomic_dec(&obd->obd_connected_clients);
-               }
-
-               /* if called during recovery then should update
-                * obd_stale_clients counter,
-                * lightweight exports are not counted */
-               if (exp->exp_failed &&
-                   (exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT) == 0)
-                       exp->exp_obd->obd_stale_clients++;
-       }
-       spin_unlock(&obd->obd_recovery_task_lock);
-
-       spin_lock(&exp->exp_lock);
-       /** Cleanup req replay fields */
-       if (exp->exp_req_replay_needed) {
-               exp->exp_req_replay_needed = 0;
-
-               LASSERT(atomic_read(&obd->obd_req_replay_clients));
-               atomic_dec(&obd->obd_req_replay_clients);
-       }
-
-       /** Cleanup lock replay data */
-       if (exp->exp_lock_replay_needed) {
-               exp->exp_lock_replay_needed = 0;
-
-               LASSERT(atomic_read(&obd->obd_lock_replay_clients));
-               atomic_dec(&obd->obd_lock_replay_clients);
-       }
-       spin_unlock(&exp->exp_lock);
-}
-
 /* This function removes 1-3 references from the export:
  * 1 - for export pointer passed
  * and if disconnect really need
@@ -1187,7 +1040,7 @@ int class_disconnect(struct obd_export *export)
 {
        int already_disconnected;
 
-       if (export == NULL) {
+       if (!export) {
                CWARN("attempting to free NULL export %p\n", export);
                return -EINVAL;
        }
@@ -1200,20 +1053,12 @@ int class_disconnect(struct obd_export *export)
        /* class_cleanup(), abort_recovery(), and class_fail_export()
         * all end up in here, and if any of them race we shouldn't
         * call extra class_export_puts(). */
-       if (already_disconnected) {
-               LASSERT(hlist_unhashed(&export->exp_nid_hash));
+       if (already_disconnected)
                goto no_disconn;
-       }
 
        CDEBUG(D_IOCTL, "disconnect: cookie %#llx\n",
               export->exp_handle.h_cookie);
 
-       if (!hlist_unhashed(&export->exp_nid_hash))
-               cfs_hash_del(export->exp_obd->obd_nid_hash,
-                            &export->exp_connection->c_peer.nid,
-                            &export->exp_nid_hash);
-
-       class_export_recovery_cleanup(export);
        class_unlink_export(export);
 no_disconn:
        class_export_put(export);
@@ -1221,135 +1066,6 @@ no_disconn:
 }
 EXPORT_SYMBOL(class_disconnect);
 
-/* Return non-zero for a fully connected export */
-int class_connected_export(struct obd_export *exp)
-{
-       if (exp) {
-               int connected;
-               spin_lock(&exp->exp_lock);
-               connected = exp->exp_conn_cnt > 0;
-               spin_unlock(&exp->exp_lock);
-               return connected;
-       }
-       return 0;
-}
-EXPORT_SYMBOL(class_connected_export);
-
-static void class_disconnect_export_list(struct list_head *list,
-                                        enum obd_option flags)
-{
-       int rc;
-       struct obd_export *exp;
-
-       /* It's possible that an export may disconnect itself, but
-        * nothing else will be added to this list. */
-       while (!list_empty(list)) {
-               exp = list_entry(list->next, struct obd_export,
-                                    exp_obd_chain);
-               /* need for safe call CDEBUG after obd_disconnect */
-               class_export_get(exp);
-
-               spin_lock(&exp->exp_lock);
-               exp->exp_flags = flags;
-               spin_unlock(&exp->exp_lock);
-
-               if (obd_uuid_equals(&exp->exp_client_uuid,
-                                   &exp->exp_obd->obd_uuid)) {
-                       CDEBUG(D_HA,
-                              "exp %p export uuid == obd uuid, don't discon\n",
-                              exp);
-                       /* Need to delete this now so we don't end up pointing
-                        * to work_list later when this export is cleaned up. */
-                       list_del_init(&exp->exp_obd_chain);
-                       class_export_put(exp);
-                       continue;
-               }
-
-               class_export_get(exp);
-               CDEBUG(D_HA, "%s: disconnecting export at %s (%p), last request at " CFS_TIME_T "\n",
-                      exp->exp_obd->obd_name, obd_export_nid2str(exp),
-                      exp, exp->exp_last_request_time);
-               /* release one export reference anyway */
-               rc = obd_disconnect(exp);
-
-               CDEBUG(D_HA, "disconnected export at %s (%p): rc %d\n",
-                      obd_export_nid2str(exp), exp, rc);
-               class_export_put(exp);
-       }
-}
-
-void class_disconnect_exports(struct obd_device *obd)
-{
-       struct list_head work_list;
-
-       /* Move all of the exports from obd_exports to a work list, en masse. */
-       INIT_LIST_HEAD(&work_list);
-       spin_lock(&obd->obd_dev_lock);
-       list_splice_init(&obd->obd_exports, &work_list);
-       list_splice_init(&obd->obd_delayed_exports, &work_list);
-       spin_unlock(&obd->obd_dev_lock);
-
-       if (!list_empty(&work_list)) {
-               CDEBUG(D_HA, "OBD device %d (%p) has exports, disconnecting them\n",
-                      obd->obd_minor, obd);
-               class_disconnect_export_list(&work_list,
-                                            exp_flags_from_obd(obd));
-       } else
-               CDEBUG(D_HA, "OBD device %d (%p) has no exports\n",
-                      obd->obd_minor, obd);
-}
-EXPORT_SYMBOL(class_disconnect_exports);
-
-/* Remove exports that have not completed recovery.
- */
-void class_disconnect_stale_exports(struct obd_device *obd,
-                                   int (*test_export)(struct obd_export *))
-{
-       struct list_head work_list;
-       struct obd_export *exp, *n;
-       int evicted = 0;
-
-       INIT_LIST_HEAD(&work_list);
-       spin_lock(&obd->obd_dev_lock);
-       list_for_each_entry_safe(exp, n, &obd->obd_exports,
-                                    exp_obd_chain) {
-               /* don't count self-export as client */
-               if (obd_uuid_equals(&exp->exp_client_uuid,
-                                   &exp->exp_obd->obd_uuid))
-                       continue;
-
-               /* don't evict clients which have no slot in last_rcvd
-                * (e.g. lightweight connection) */
-               if (exp->exp_target_data.ted_lr_idx == -1)
-                       continue;
-
-               spin_lock(&exp->exp_lock);
-               if (exp->exp_failed || test_export(exp)) {
-                       spin_unlock(&exp->exp_lock);
-                       continue;
-               }
-               exp->exp_failed = 1;
-               spin_unlock(&exp->exp_lock);
-
-               list_move(&exp->exp_obd_chain, &work_list);
-               evicted++;
-               CDEBUG(D_HA, "%s: disconnect stale client %s@%s\n",
-                      obd->obd_name, exp->exp_client_uuid.uuid,
-                      exp->exp_connection == NULL ? "<unknown>" :
-                      libcfs_nid2str(exp->exp_connection->c_peer.nid));
-               print_export_data(exp, "EVICTING", 0);
-       }
-       spin_unlock(&obd->obd_dev_lock);
-
-       if (evicted)
-               LCONSOLE_WARN("%s: disconnecting %d stale clients\n",
-                             obd->obd_name, evicted);
-
-       class_disconnect_export_list(&work_list, exp_flags_from_obd(obd) |
-                                                OBD_OPT_ABORT_RECOV);
-}
-EXPORT_SYMBOL(class_disconnect_stale_exports);
-
 void class_fail_export(struct obd_export *exp)
 {
        int rc, already_failed;
@@ -1388,189 +1104,18 @@ void class_fail_export(struct obd_export *exp)
 }
 EXPORT_SYMBOL(class_fail_export);
 
-char *obd_export_nid2str(struct obd_export *exp)
-{
-       if (exp->exp_connection != NULL)
-               return libcfs_nid2str(exp->exp_connection->c_peer.nid);
-
-       return "(no nid)";
-}
-EXPORT_SYMBOL(obd_export_nid2str);
-
-int obd_export_evict_by_nid(struct obd_device *obd, const char *nid)
-{
-       struct cfs_hash *nid_hash;
-       struct obd_export *doomed_exp = NULL;
-       int exports_evicted = 0;
-
-       lnet_nid_t nid_key = libcfs_str2nid((char *)nid);
-
-       spin_lock(&obd->obd_dev_lock);
-       /* umount has run already, so evict thread should leave
-        * its task to umount thread now */
-       if (obd->obd_stopping) {
-               spin_unlock(&obd->obd_dev_lock);
-               return exports_evicted;
-       }
-       nid_hash = obd->obd_nid_hash;
-       cfs_hash_getref(nid_hash);
-       spin_unlock(&obd->obd_dev_lock);
-
-       do {
-               doomed_exp = cfs_hash_lookup(nid_hash, &nid_key);
-               if (doomed_exp == NULL)
-                       break;
-
-               LASSERTF(doomed_exp->exp_connection->c_peer.nid == nid_key,
-                        "nid %s found, wanted nid %s, requested nid %s\n",
-                        obd_export_nid2str(doomed_exp),
-                        libcfs_nid2str(nid_key), nid);
-               LASSERTF(doomed_exp != obd->obd_self_export,
-                        "self-export is hashed by NID?\n");
-               exports_evicted++;
-               LCONSOLE_WARN("%s: evicting %s (at %s) by administrative request\n",
-                             obd->obd_name,
-                             obd_uuid2str(&doomed_exp->exp_client_uuid),
-                             obd_export_nid2str(doomed_exp));
-               class_fail_export(doomed_exp);
-               class_export_put(doomed_exp);
-       } while (1);
-
-       cfs_hash_putref(nid_hash);
-
-       if (!exports_evicted)
-               CDEBUG(D_HA,
-                      "%s: can't disconnect NID '%s': no exports found\n",
-                      obd->obd_name, nid);
-       return exports_evicted;
-}
-EXPORT_SYMBOL(obd_export_evict_by_nid);
-
-int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid)
-{
-       struct cfs_hash *uuid_hash;
-       struct obd_export *doomed_exp = NULL;
-       struct obd_uuid doomed_uuid;
-       int exports_evicted = 0;
-
-       spin_lock(&obd->obd_dev_lock);
-       if (obd->obd_stopping) {
-               spin_unlock(&obd->obd_dev_lock);
-               return exports_evicted;
-       }
-       uuid_hash = obd->obd_uuid_hash;
-       cfs_hash_getref(uuid_hash);
-       spin_unlock(&obd->obd_dev_lock);
-
-       obd_str2uuid(&doomed_uuid, uuid);
-       if (obd_uuid_equals(&doomed_uuid, &obd->obd_uuid)) {
-               CERROR("%s: can't evict myself\n", obd->obd_name);
-               cfs_hash_putref(uuid_hash);
-               return exports_evicted;
-       }
-
-       doomed_exp = cfs_hash_lookup(uuid_hash, &doomed_uuid);
-
-       if (doomed_exp == NULL) {
-               CERROR("%s: can't disconnect %s: no exports found\n",
-                      obd->obd_name, uuid);
-       } else {
-               CWARN("%s: evicting %s at administrative request\n",
-                      obd->obd_name, doomed_exp->exp_client_uuid.uuid);
-               class_fail_export(doomed_exp);
-               class_export_put(doomed_exp);
-               exports_evicted++;
-       }
-       cfs_hash_putref(uuid_hash);
-
-       return exports_evicted;
-}
-EXPORT_SYMBOL(obd_export_evict_by_uuid);
-
 #if LUSTRE_TRACKS_LOCK_EXP_REFS
-void (*class_export_dump_hook)(struct obd_export*) = NULL;
+void (*class_export_dump_hook)(struct obd_export *) = NULL;
 EXPORT_SYMBOL(class_export_dump_hook);
 #endif
 
-static void print_export_data(struct obd_export *exp, const char *status,
-                             int locks)
-{
-       struct ptlrpc_reply_state *rs;
-       struct ptlrpc_reply_state *first_reply = NULL;
-       int nreplies = 0;
-
-       spin_lock(&exp->exp_lock);
-       list_for_each_entry(rs, &exp->exp_outstanding_replies,
-                               rs_exp_list) {
-               if (nreplies == 0)
-                       first_reply = rs;
-               nreplies++;
-       }
-       spin_unlock(&exp->exp_lock);
-
-       CDEBUG(D_HA, "%s: %s %p %s %s %d (%d %d %d) %d %d %d %d: %p %s %llu\n",
-              exp->exp_obd->obd_name, status, exp, exp->exp_client_uuid.uuid,
-              obd_export_nid2str(exp), atomic_read(&exp->exp_refcount),
-              atomic_read(&exp->exp_rpc_count),
-              atomic_read(&exp->exp_cb_count),
-              atomic_read(&exp->exp_locks_count),
-              exp->exp_disconnected, exp->exp_delayed, exp->exp_failed,
-              nreplies, first_reply, nreplies > 3 ? "..." : "",
-              exp->exp_last_committed);
-#if LUSTRE_TRACKS_LOCK_EXP_REFS
-       if (locks && class_export_dump_hook != NULL)
-               class_export_dump_hook(exp);
-#endif
-}
-
-void dump_exports(struct obd_device *obd, int locks)
-{
-       struct obd_export *exp;
-
-       spin_lock(&obd->obd_dev_lock);
-       list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain)
-               print_export_data(exp, "ACTIVE", locks);
-       list_for_each_entry(exp, &obd->obd_unlinked_exports, exp_obd_chain)
-               print_export_data(exp, "UNLINKED", locks);
-       list_for_each_entry(exp, &obd->obd_delayed_exports, exp_obd_chain)
-               print_export_data(exp, "DELAYED", locks);
-       spin_unlock(&obd->obd_dev_lock);
-       spin_lock(&obd_zombie_impexp_lock);
-       list_for_each_entry(exp, &obd_zombie_exports, exp_obd_chain)
-               print_export_data(exp, "ZOMBIE", locks);
-       spin_unlock(&obd_zombie_impexp_lock);
-}
-EXPORT_SYMBOL(dump_exports);
-
-void obd_exports_barrier(struct obd_device *obd)
-{
-       int waited = 2;
-       LASSERT(list_empty(&obd->obd_exports));
-       spin_lock(&obd->obd_dev_lock);
-       while (!list_empty(&obd->obd_unlinked_exports)) {
-               spin_unlock(&obd->obd_dev_lock);
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(cfs_time_seconds(waited));
-               if (waited > 5 && IS_PO2(waited)) {
-                       LCONSOLE_WARN("%s is waiting for obd_unlinked_exports more than %d seconds. The obd refcount = %d. Is it stuck?\n",
-                                     obd->obd_name, waited,
-                                     atomic_read(&obd->obd_refcount));
-                       dump_exports(obd, 1);
-               }
-               waited *= 2;
-               spin_lock(&obd->obd_dev_lock);
-       }
-       spin_unlock(&obd->obd_dev_lock);
-}
-EXPORT_SYMBOL(obd_exports_barrier);
-
 /* Total amount of zombies to be destroyed */
 static int zombies_count;
 
 /**
  * kill zombie imports and exports
  */
-void obd_zombie_impexp_cull(void)
+static void obd_zombie_impexp_cull(void)
 {
        struct obd_import *import;
        struct obd_export *export;
@@ -1661,8 +1206,7 @@ static void obd_zombie_export_add(struct obd_export *exp)
  */
 static void obd_zombie_import_add(struct obd_import *imp)
 {
-       LASSERT(imp->imp_sec == NULL);
-       LASSERT(imp->imp_rq_pool == NULL);
+       LASSERT(!imp->imp_sec);
        spin_lock(&obd_zombie_impexp_lock);
        LASSERT(list_empty(&imp->imp_zombie_chain));
        zombies_count++;
@@ -1713,7 +1257,6 @@ void obd_zombie_barrier(void)
 }
 EXPORT_SYMBOL(obd_zombie_barrier);
 
-
 /**
  * destroy zombie export/import thread.
  */
@@ -1743,7 +1286,6 @@ static int obd_zombie_impexp_thread(void *unused)
        return 0;
 }
 
-
 /**
  * start destroy zombie import/export thread
  */
@@ -1766,6 +1308,7 @@ int obd_zombie_impexp_init(void)
        wait_for_completion(&obd_zombie_start);
        return 0;
 }
+
 /**
  * stop destroy zombie import/export thread
  */
@@ -1775,68 +1318,3 @@ void obd_zombie_impexp_stop(void)
        obd_zombie_impexp_notify();
        wait_for_completion(&obd_zombie_stop);
 }
-
-/***** Kernel-userspace comm helpers *******/
-
-/* Get length of entire message, including header */
-int kuc_len(int payload_len)
-{
-       return sizeof(struct kuc_hdr) + payload_len;
-}
-EXPORT_SYMBOL(kuc_len);
-
-/* Get a pointer to kuc header, given a ptr to the payload
- * @param p Pointer to payload area
- * @returns Pointer to kuc header
- */
-struct kuc_hdr *kuc_ptr(void *p)
-{
-       struct kuc_hdr *lh = ((struct kuc_hdr *)p) - 1;
-       LASSERT(lh->kuc_magic == KUC_MAGIC);
-       return lh;
-}
-EXPORT_SYMBOL(kuc_ptr);
-
-/* Test if payload is part of kuc message
- * @param p Pointer to payload area
- * @returns boolean
- */
-int kuc_ispayload(void *p)
-{
-       struct kuc_hdr *kh = ((struct kuc_hdr *)p) - 1;
-
-       if (kh->kuc_magic == KUC_MAGIC)
-               return 1;
-       else
-               return 0;
-}
-EXPORT_SYMBOL(kuc_ispayload);
-
-/* Alloc space for a message, and fill in header
- * @return Pointer to payload area
- */
-void *kuc_alloc(int payload_len, int transport, int type)
-{
-       struct kuc_hdr *lh;
-       int len = kuc_len(payload_len);
-
-       lh = kzalloc(len, GFP_NOFS);
-       if (!lh)
-               return ERR_PTR(-ENOMEM);
-
-       lh->kuc_magic = KUC_MAGIC;
-       lh->kuc_transport = transport;
-       lh->kuc_msgtype = type;
-       lh->kuc_msglen = len;
-
-       return (void *)(lh + 1);
-}
-EXPORT_SYMBOL(kuc_alloc);
-
-/* Takes pointer to payload area */
-inline void kuc_free(void *p, int payload_len)
-{
-       struct kuc_hdr *lh = kuc_ptr(p);
-       kfree(lh);
-}
-EXPORT_SYMBOL(kuc_free);
index 6218ef34ee801521a21cac7005f47bba50b07511..a055cbb4f1628b75617a419d6a76550bc968ce67 100644 (file)
@@ -73,8 +73,6 @@
 #include "../../include/lustre_ver.h"
 #include "../../include/lustre/lustre_build_version.h"
 
-int proc_version;
-
 /* buffer MUST be at least the size of obd_ioctl_hdr */
 int obd_ioctl_getdata(char **buf, int *len, void *arg)
 {
@@ -215,7 +213,6 @@ struct miscdevice obd_psdev = {
        .fops  = &obd_psdev_fops,
 };
 
-
 static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
                            char *buf)
 {
index 62ed706b136d56a6c3b81be566ad078eb751ac92..9496c09b2b69cf9d51c0b3fb35beb62f085870d2 100644 (file)
 #include <linux/fs.h>
 #include <linux/pagemap.h> /* for PAGE_CACHE_SIZE */
 
-/*FIXME: Just copy from obdo_from_inode*/
-void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid)
-{
-       u32 newvalid = 0;
-
-       if (valid & LA_ATIME) {
-               dst->o_atime = la->la_atime;
-               newvalid |= OBD_MD_FLATIME;
-       }
-       if (valid & LA_MTIME) {
-               dst->o_mtime = la->la_mtime;
-               newvalid |= OBD_MD_FLMTIME;
-       }
-       if (valid & LA_CTIME) {
-               dst->o_ctime = la->la_ctime;
-               newvalid |= OBD_MD_FLCTIME;
-       }
-       if (valid & LA_SIZE) {
-               dst->o_size = la->la_size;
-               newvalid |= OBD_MD_FLSIZE;
-       }
-       if (valid & LA_BLOCKS) {  /* allocation of space (x512 bytes) */
-               dst->o_blocks = la->la_blocks;
-               newvalid |= OBD_MD_FLBLOCKS;
-       }
-       if (valid & LA_TYPE) {
-               dst->o_mode = (dst->o_mode & S_IALLUGO) |
-                             (la->la_mode & S_IFMT);
-               newvalid |= OBD_MD_FLTYPE;
-       }
-       if (valid & LA_MODE) {
-               dst->o_mode = (dst->o_mode & S_IFMT) |
-                             (la->la_mode & S_IALLUGO);
-               newvalid |= OBD_MD_FLMODE;
-       }
-       if (valid & LA_UID) {
-               dst->o_uid = la->la_uid;
-               newvalid |= OBD_MD_FLUID;
-       }
-       if (valid & LA_GID) {
-               dst->o_gid = la->la_gid;
-               newvalid |= OBD_MD_FLGID;
-       }
-       dst->o_valid |= newvalid;
-}
-EXPORT_SYMBOL(obdo_from_la);
-
-/*FIXME: Just copy from obdo_from_inode*/
-void la_from_obdo(struct lu_attr *dst, struct obdo *obdo, u32 valid)
-{
-       __u64 newvalid = 0;
-
-       valid &= obdo->o_valid;
-
-       if (valid & OBD_MD_FLATIME) {
-               dst->la_atime = obdo->o_atime;
-               newvalid |= LA_ATIME;
-       }
-       if (valid & OBD_MD_FLMTIME) {
-               dst->la_mtime = obdo->o_mtime;
-               newvalid |= LA_MTIME;
-       }
-       if (valid & OBD_MD_FLCTIME) {
-               dst->la_ctime = obdo->o_ctime;
-               newvalid |= LA_CTIME;
-       }
-       if (valid & OBD_MD_FLSIZE) {
-               dst->la_size = obdo->o_size;
-               newvalid |= LA_SIZE;
-       }
-       if (valid & OBD_MD_FLBLOCKS) {
-               dst->la_blocks = obdo->o_blocks;
-               newvalid |= LA_BLOCKS;
-       }
-       if (valid & OBD_MD_FLTYPE) {
-               dst->la_mode = (dst->la_mode & S_IALLUGO) |
-                              (obdo->o_mode & S_IFMT);
-               newvalid |= LA_TYPE;
-       }
-       if (valid & OBD_MD_FLMODE) {
-               dst->la_mode = (dst->la_mode & S_IFMT) |
-                              (obdo->o_mode & S_IALLUGO);
-               newvalid |= LA_MODE;
-       }
-       if (valid & OBD_MD_FLUID) {
-               dst->la_uid = obdo->o_uid;
-               newvalid |= LA_UID;
-       }
-       if (valid & OBD_MD_FLGID) {
-               dst->la_gid = obdo->o_gid;
-               newvalid |= LA_GID;
-       }
-       dst->la_valid = newvalid;
-}
-EXPORT_SYMBOL(la_from_obdo);
-
 void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid)
 {
        valid &= src->o_valid;
@@ -179,44 +83,3 @@ void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid)
                dst->i_blocks = src->o_blocks;
 }
 EXPORT_SYMBOL(obdo_refresh_inode);
-
-void obdo_to_inode(struct inode *dst, struct obdo *src, u32 valid)
-{
-       valid &= src->o_valid;
-
-       LASSERTF(!(valid & (OBD_MD_FLTYPE | OBD_MD_FLGENER | OBD_MD_FLFID |
-                           OBD_MD_FLID | OBD_MD_FLGROUP)),
-                "object "DOSTID", valid %x\n", POSTID(&src->o_oi), valid);
-
-       if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
-               CDEBUG(D_INODE,
-                      "valid %#llx, cur time %lu/%lu, new %llu/%llu\n",
-                      src->o_valid, LTIME_S(dst->i_mtime),
-                      LTIME_S(dst->i_ctime), src->o_mtime, src->o_ctime);
-
-       if (valid & OBD_MD_FLATIME)
-               LTIME_S(dst->i_atime) = src->o_atime;
-       if (valid & OBD_MD_FLMTIME)
-               LTIME_S(dst->i_mtime) = src->o_mtime;
-       if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(dst->i_ctime))
-               LTIME_S(dst->i_ctime) = src->o_ctime;
-       if (valid & OBD_MD_FLSIZE)
-               i_size_write(dst, src->o_size);
-       if (valid & OBD_MD_FLBLOCKS) { /* allocation of space */
-               dst->i_blocks = src->o_blocks;
-               if (dst->i_blocks < src->o_blocks) /* overflow */
-                       dst->i_blocks = -1;
-
-       }
-       if (valid & OBD_MD_FLBLKSZ)
-               dst->i_blkbits = ffs(src->o_blksize)-1;
-       if (valid & OBD_MD_FLMODE)
-               dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
-       if (valid & OBD_MD_FLUID)
-               dst->i_uid = make_kuid(&init_user_ns, src->o_uid);
-       if (valid & OBD_MD_FLGID)
-               dst->i_gid = make_kgid(&init_user_ns, src->o_gid);
-       if (valid & OBD_MD_FLFLAGS)
-               dst->i_flags = src->o_flags;
-}
-EXPORT_SYMBOL(obdo_to_inode);
index 1515163a81a5385f5e183c12f3bd4e573d042605..518288df4d53df69820259f8085bf726d8e78cd5 100644 (file)
@@ -162,7 +162,3 @@ int obd_sysctl_init(void)
 {
        return sysfs_create_group(lustre_kobj, &lustre_attr_group);
 }
-
-void obd_sysctl_clean(void)
-{
-}
index facc8351fcea50163c83b2c12b29ad31500f3800..7cb55ef79737b46c9607cc9068834cfbbcaf4e36 100644 (file)
@@ -47,7 +47,6 @@
 
 #define DEBUG_SUBSYSTEM S_LOG
 
-
 #include "../include/obd_class.h"
 #include "../include/lustre_log.h"
 #include "llog_internal.h"
@@ -105,66 +104,6 @@ void llog_handle_put(struct llog_handle *loghandle)
                llog_free_handle(loghandle);
 }
 
-/* returns negative on error; 0 if success; 1 if success & log destroyed */
-int llog_cancel_rec(const struct lu_env *env, struct llog_handle *loghandle,
-                   int index)
-{
-       struct llog_log_hdr *llh = loghandle->lgh_hdr;
-       int rc = 0;
-
-       CDEBUG(D_RPCTRACE, "Canceling %d in log "DOSTID"\n",
-              index, POSTID(&loghandle->lgh_id.lgl_oi));
-
-       if (index == 0) {
-               CERROR("Can't cancel index 0 which is header\n");
-               return -EINVAL;
-       }
-
-       spin_lock(&loghandle->lgh_hdr_lock);
-       if (!ext2_clear_bit(index, llh->llh_bitmap)) {
-               spin_unlock(&loghandle->lgh_hdr_lock);
-               CDEBUG(D_RPCTRACE, "Catalog index %u already clear?\n", index);
-               return -ENOENT;
-       }
-
-       llh->llh_count--;
-
-       if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
-           (llh->llh_count == 1) &&
-           (loghandle->lgh_last_idx == (LLOG_BITMAP_BYTES * 8) - 1)) {
-               spin_unlock(&loghandle->lgh_hdr_lock);
-               rc = llog_destroy(env, loghandle);
-               if (rc < 0) {
-                       CERROR("%s: can't destroy empty llog #"DOSTID
-                              "#%08x: rc = %d\n",
-                              loghandle->lgh_ctxt->loc_obd->obd_name,
-                              POSTID(&loghandle->lgh_id.lgl_oi),
-                              loghandle->lgh_id.lgl_ogen, rc);
-                       goto out_err;
-               }
-               return 1;
-       }
-       spin_unlock(&loghandle->lgh_hdr_lock);
-
-       rc = llog_write(env, loghandle, &llh->llh_hdr, NULL, 0, NULL, 0);
-       if (rc < 0) {
-               CERROR("%s: fail to write header for llog #"DOSTID
-                      "#%08x: rc = %d\n",
-                      loghandle->lgh_ctxt->loc_obd->obd_name,
-                      POSTID(&loghandle->lgh_id.lgl_oi),
-                      loghandle->lgh_id.lgl_ogen, rc);
-               goto out_err;
-       }
-       return 0;
-out_err:
-       spin_lock(&loghandle->lgh_hdr_lock);
-       ext2_set_bit(index, llh->llh_bitmap);
-       llh->llh_count++;
-       spin_unlock(&loghandle->lgh_hdr_lock);
-       return rc;
-}
-EXPORT_SYMBOL(llog_cancel_rec);
-
 static int llog_read_header(const struct lu_env *env,
                            struct llog_handle *handle,
                            struct obd_uuid *uuid)
@@ -188,7 +127,7 @@ static int llog_read_header(const struct lu_env *env,
                llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC;
                llh->llh_hdr.lrh_len = llh->llh_tail.lrt_len = LLOG_CHUNK_SIZE;
                llh->llh_hdr.lrh_index = llh->llh_tail.lrt_index = 0;
-               llh->llh_timestamp = get_seconds();
+               llh->llh_timestamp = ktime_get_real_seconds();
                if (uuid)
                        memcpy(&llh->llh_tgtuuid, uuid,
                               sizeof(llh->llh_tgtuuid));
@@ -326,7 +265,7 @@ repeat:
                 * swabbing is done at the beginning of the loop. */
                for (rec = (struct llog_rec_hdr *)buf;
                     (char *)rec < buf + LLOG_CHUNK_SIZE;
-                    rec = (struct llog_rec_hdr *)((char *)rec + rec->lrh_len)){
+                    rec = (struct llog_rec_hdr *)((char *)rec + rec->lrh_len)) {
 
                        CDEBUG(D_OTHER, "processing rec 0x%p type %#x\n",
                               rec, rec->lrh_type);
@@ -373,14 +312,6 @@ repeat:
                                rc = lpi->lpi_cb(lpi->lpi_env, loghandle, rec,
                                                 lpi->lpi_cbdata);
                                last_called_index = index;
-                               if (rc == LLOG_PROC_BREAK) {
-                                       goto out;
-                               } else if (rc == LLOG_DEL_RECORD) {
-                                       llog_cancel_rec(lpi->lpi_env,
-                                                       loghandle,
-                                                       rec->lrh_index);
-                                       rc = 0;
-                               }
                                if (rc)
                                        goto out;
                        } else {
@@ -475,380 +406,6 @@ int llog_process(const struct lu_env *env, struct llog_handle *loghandle,
 }
 EXPORT_SYMBOL(llog_process);
 
-int llog_reverse_process(const struct lu_env *env,
-                        struct llog_handle *loghandle, llog_cb_t cb,
-                        void *data, void *catdata)
-{
-       struct llog_log_hdr *llh = loghandle->lgh_hdr;
-       struct llog_process_cat_data *cd = catdata;
-       void *buf;
-       int rc = 0, first_index = 1, index, idx;
-
-       buf = kzalloc(LLOG_CHUNK_SIZE, GFP_NOFS);
-       if (!buf)
-               return -ENOMEM;
-
-       if (cd != NULL)
-               first_index = cd->lpcd_first_idx + 1;
-       if (cd != NULL && cd->lpcd_last_idx)
-               index = cd->lpcd_last_idx;
-       else
-               index = LLOG_BITMAP_BYTES * 8 - 1;
-
-       while (rc == 0) {
-               struct llog_rec_hdr *rec;
-               struct llog_rec_tail *tail;
-
-               /* skip records not set in bitmap */
-               while (index >= first_index &&
-                      !ext2_test_bit(index, llh->llh_bitmap))
-                       --index;
-
-               LASSERT(index >= first_index - 1);
-               if (index == first_index - 1)
-                       break;
-
-               /* get the buf with our target record; avoid old garbage */
-               memset(buf, 0, LLOG_CHUNK_SIZE);
-               rc = llog_prev_block(env, loghandle, index, buf,
-                                    LLOG_CHUNK_SIZE);
-               if (rc)
-                       goto out;
-
-               rec = buf;
-               idx = rec->lrh_index;
-               CDEBUG(D_RPCTRACE, "index %u : idx %u\n", index, idx);
-               while (idx < index) {
-                       rec = (void *)rec + rec->lrh_len;
-                       if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
-                               lustre_swab_llog_rec(rec);
-                       idx ++;
-               }
-               LASSERT(idx == index);
-               tail = (void *)rec + rec->lrh_len - sizeof(*tail);
-
-               /* process records in buffer, starting where we found one */
-               while ((void *)tail > buf) {
-                       if (tail->lrt_index == 0) {
-                               /* no more records */
-                               rc = 0;
-                               goto out;
-                       }
-
-                       /* if set, process the callback on this record */
-                       if (ext2_test_bit(index, llh->llh_bitmap)) {
-                               rec = (void *)tail - tail->lrt_len +
-                                     sizeof(*tail);
-
-                               rc = cb(env, loghandle, rec, data);
-                               if (rc == LLOG_PROC_BREAK) {
-                                       goto out;
-                               } else if (rc == LLOG_DEL_RECORD) {
-                                       llog_cancel_rec(env, loghandle,
-                                                       tail->lrt_index);
-                                       rc = 0;
-                               }
-                               if (rc)
-                                       goto out;
-                       }
-
-                       /* previous record, still in buffer? */
-                       --index;
-                       if (index < first_index) {
-                               rc = 0;
-                               goto out;
-                       }
-                       tail = (void *)tail - tail->lrt_len;
-               }
-       }
-
-out:
-       kfree(buf);
-       return rc;
-}
-EXPORT_SYMBOL(llog_reverse_process);
-
-/**
- * new llog API
- *
- * API functions:
- *      llog_open - open llog, may not exist
- *      llog_exist - check if llog exists
- *      llog_close - close opened llog, pair for open, frees llog_handle
- *      llog_declare_create - declare llog creation
- *      llog_create - create new llog on disk, need transaction handle
- *      llog_declare_write_rec - declaration of llog write
- *      llog_write_rec - write llog record on disk, need transaction handle
- *      llog_declare_add - declare llog catalog record addition
- *      llog_add - add llog record in catalog, need transaction handle
- */
-int llog_exist(struct llog_handle *loghandle)
-{
-       struct llog_operations  *lop;
-       int                      rc;
-
-       rc = llog_handle2ops(loghandle, &lop);
-       if (rc)
-               return rc;
-       if (lop->lop_exist == NULL)
-               return -EOPNOTSUPP;
-
-       rc = lop->lop_exist(loghandle);
-       return rc;
-}
-EXPORT_SYMBOL(llog_exist);
-
-int llog_declare_create(const struct lu_env *env,
-                       struct llog_handle *loghandle, struct thandle *th)
-{
-       struct llog_operations  *lop;
-       int                      raised, rc;
-
-       rc = llog_handle2ops(loghandle, &lop);
-       if (rc)
-               return rc;
-       if (lop->lop_declare_create == NULL)
-               return -EOPNOTSUPP;
-
-       raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
-       if (!raised)
-               cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
-       rc = lop->lop_declare_create(env, loghandle, th);
-       if (!raised)
-               cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
-       return rc;
-}
-EXPORT_SYMBOL(llog_declare_create);
-
-int llog_create(const struct lu_env *env, struct llog_handle *handle,
-               struct thandle *th)
-{
-       struct llog_operations  *lop;
-       int                      raised, rc;
-
-       rc = llog_handle2ops(handle, &lop);
-       if (rc)
-               return rc;
-       if (lop->lop_create == NULL)
-               return -EOPNOTSUPP;
-
-       raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
-       if (!raised)
-               cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
-       rc = lop->lop_create(env, handle, th);
-       if (!raised)
-               cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
-       return rc;
-}
-EXPORT_SYMBOL(llog_create);
-
-int llog_declare_write_rec(const struct lu_env *env,
-                          struct llog_handle *handle,
-                          struct llog_rec_hdr *rec, int idx,
-                          struct thandle *th)
-{
-       struct llog_operations  *lop;
-       int                      raised, rc;
-
-       rc = llog_handle2ops(handle, &lop);
-       if (rc)
-               return rc;
-       LASSERT(lop);
-       if (lop->lop_declare_write_rec == NULL)
-               return -EOPNOTSUPP;
-
-       raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
-       if (!raised)
-               cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
-       rc = lop->lop_declare_write_rec(env, handle, rec, idx, th);
-       if (!raised)
-               cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
-       return rc;
-}
-EXPORT_SYMBOL(llog_declare_write_rec);
-
-int llog_write_rec(const struct lu_env *env, struct llog_handle *handle,
-                  struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
-                  int numcookies, void *buf, int idx, struct thandle *th)
-{
-       struct llog_operations  *lop;
-       int                      raised, rc, buflen;
-
-       rc = llog_handle2ops(handle, &lop);
-       if (rc)
-               return rc;
-
-       LASSERT(lop);
-       if (lop->lop_write_rec == NULL)
-               return -EOPNOTSUPP;
-
-       if (buf)
-               buflen = rec->lrh_len + sizeof(struct llog_rec_hdr) +
-                        sizeof(struct llog_rec_tail);
-       else
-               buflen = rec->lrh_len;
-       LASSERT(cfs_size_round(buflen) == buflen);
-
-       raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
-       if (!raised)
-               cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
-       rc = lop->lop_write_rec(env, handle, rec, logcookies, numcookies,
-                               buf, idx, th);
-       if (!raised)
-               cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
-       return rc;
-}
-EXPORT_SYMBOL(llog_write_rec);
-
-int llog_add(const struct lu_env *env, struct llog_handle *lgh,
-            struct llog_rec_hdr *rec, struct llog_cookie *logcookies,
-            void *buf, struct thandle *th)
-{
-       int raised, rc;
-
-       if (lgh->lgh_logops->lop_add == NULL)
-               return -EOPNOTSUPP;
-
-       raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
-       if (!raised)
-               cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
-       rc = lgh->lgh_logops->lop_add(env, lgh, rec, logcookies, buf, th);
-       if (!raised)
-               cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
-       return rc;
-}
-EXPORT_SYMBOL(llog_add);
-
-int llog_declare_add(const struct lu_env *env, struct llog_handle *lgh,
-                    struct llog_rec_hdr *rec, struct thandle *th)
-{
-       int raised, rc;
-
-       if (lgh->lgh_logops->lop_declare_add == NULL)
-               return -EOPNOTSUPP;
-
-       raised = cfs_cap_raised(CFS_CAP_SYS_RESOURCE);
-       if (!raised)
-               cfs_cap_raise(CFS_CAP_SYS_RESOURCE);
-       rc = lgh->lgh_logops->lop_declare_add(env, lgh, rec, th);
-       if (!raised)
-               cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
-       return rc;
-}
-EXPORT_SYMBOL(llog_declare_add);
-
-/**
- * Helper function to open llog or create it if doesn't exist.
- * It hides all transaction handling from caller.
- */
-int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
-                    struct llog_handle **res, struct llog_logid *logid,
-                    char *name)
-{
-       struct dt_device        *d;
-       struct thandle          *th;
-       int                      rc;
-
-       rc = llog_open(env, ctxt, res, logid, name, LLOG_OPEN_NEW);
-       if (rc)
-               return rc;
-
-       if (llog_exist(*res))
-               return 0;
-
-       LASSERT((*res)->lgh_obj != NULL);
-
-       d = lu2dt_dev((*res)->lgh_obj->do_lu.lo_dev);
-
-       th = dt_trans_create(env, d);
-       if (IS_ERR(th)) {
-               rc = PTR_ERR(th);
-               goto out;
-       }
-
-       rc = llog_declare_create(env, *res, th);
-       if (rc == 0) {
-               rc = dt_trans_start_local(env, d, th);
-               if (rc == 0)
-                       rc = llog_create(env, *res, th);
-       }
-       dt_trans_stop(env, d, th);
-out:
-       if (rc)
-               llog_close(env, *res);
-       return rc;
-}
-EXPORT_SYMBOL(llog_open_create);
-
-/**
- * Helper function to delete existent llog.
- */
-int llog_erase(const struct lu_env *env, struct llog_ctxt *ctxt,
-              struct llog_logid *logid, char *name)
-{
-       struct llog_handle      *handle;
-       int                      rc = 0, rc2;
-
-       /* nothing to erase */
-       if (name == NULL && logid == NULL)
-               return 0;
-
-       rc = llog_open(env, ctxt, &handle, logid, name, LLOG_OPEN_EXISTS);
-       if (rc < 0)
-               return rc;
-
-       rc = llog_init_handle(env, handle, LLOG_F_IS_PLAIN, NULL);
-       if (rc == 0)
-               rc = llog_destroy(env, handle);
-
-       rc2 = llog_close(env, handle);
-       if (rc == 0)
-               rc = rc2;
-       return rc;
-}
-EXPORT_SYMBOL(llog_erase);
-
-/*
- * Helper function for write record in llog.
- * It hides all transaction handling from caller.
- * Valid only with local llog.
- */
-int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
-              struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
-              int cookiecount, void *buf, int idx)
-{
-       struct dt_device        *dt;
-       struct thandle          *th;
-       int                      rc;
-
-       LASSERT(loghandle);
-       LASSERT(loghandle->lgh_ctxt);
-       LASSERT(loghandle->lgh_obj != NULL);
-
-       dt = lu2dt_dev(loghandle->lgh_obj->do_lu.lo_dev);
-
-       th = dt_trans_create(env, dt);
-       if (IS_ERR(th))
-               return PTR_ERR(th);
-
-       rc = llog_declare_write_rec(env, loghandle, rec, idx, th);
-       if (rc)
-               goto out_trans;
-
-       rc = dt_trans_start_local(env, dt, th);
-       if (rc)
-               goto out_trans;
-
-       down_write(&loghandle->lgh_lock);
-       rc = llog_write_rec(env, loghandle, rec, reccookie,
-                           cookiecount, buf, idx, th);
-       up_write(&loghandle->lgh_lock);
-out_trans:
-       dt_trans_stop(env, dt, th);
-       return rc;
-}
-EXPORT_SYMBOL(llog_write);
-
 int llog_open(const struct lu_env *env, struct llog_ctxt *ctxt,
              struct llog_handle **lgh, struct llog_logid *logid,
              char *name, enum llog_open_param open_param)
@@ -902,105 +459,3 @@ out:
        return rc;
 }
 EXPORT_SYMBOL(llog_close);
-
-int llog_is_empty(const struct lu_env *env, struct llog_ctxt *ctxt,
-                 char *name)
-{
-       struct llog_handle      *llh;
-       int                      rc;
-
-       rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
-       if (rc < 0) {
-               if (likely(rc == -ENOENT))
-                       rc = 0;
-               goto out;
-       }
-
-       rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
-       if (rc)
-               goto out_close;
-       rc = llog_get_size(llh);
-
-out_close:
-       llog_close(env, llh);
-out:
-       /* header is record 1 */
-       return rc <= 1;
-}
-EXPORT_SYMBOL(llog_is_empty);
-
-int llog_copy_handler(const struct lu_env *env, struct llog_handle *llh,
-                     struct llog_rec_hdr *rec, void *data)
-{
-       struct llog_handle      *copy_llh = data;
-
-       /* Append all records */
-       return llog_write(env, copy_llh, rec, NULL, 0, NULL, -1);
-}
-EXPORT_SYMBOL(llog_copy_handler);
-
-/* backup plain llog */
-int llog_backup(const struct lu_env *env, struct obd_device *obd,
-               struct llog_ctxt *ctxt, struct llog_ctxt *bctxt,
-               char *name, char *backup)
-{
-       struct llog_handle      *llh, *bllh;
-       int                      rc;
-
-
-
-       /* open original log */
-       rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
-       if (rc < 0) {
-               /* the -ENOENT case is also reported to the caller
-                * but silently so it should handle that if needed.
-                */
-               if (rc != -ENOENT)
-                       CERROR("%s: failed to open log %s: rc = %d\n",
-                              obd->obd_name, name, rc);
-               return rc;
-       }
-
-       rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
-       if (rc)
-               goto out_close;
-
-       /* Make sure there's no old backup log */
-       rc = llog_erase(env, bctxt, NULL, backup);
-       if (rc < 0 && rc != -ENOENT)
-               goto out_close;
-
-       /* open backup log */
-       rc = llog_open_create(env, bctxt, &bllh, NULL, backup);
-       if (rc) {
-               CERROR("%s: failed to open backup logfile %s: rc = %d\n",
-                      obd->obd_name, backup, rc);
-               goto out_close;
-       }
-
-       /* check that backup llog is not the same object as original one */
-       if (llh->lgh_obj == bllh->lgh_obj) {
-               CERROR("%s: backup llog %s to itself (%s), objects %p/%p\n",
-                      obd->obd_name, name, backup, llh->lgh_obj,
-                      bllh->lgh_obj);
-               rc = -EEXIST;
-               goto out_backup;
-       }
-
-       rc = llog_init_handle(env, bllh, LLOG_F_IS_PLAIN, NULL);
-       if (rc)
-               goto out_backup;
-
-       /* Copy log record by record */
-       rc = llog_process_or_fork(env, llh, llog_copy_handler, (void *)bllh,
-                                 NULL, false);
-       if (rc)
-               CERROR("%s: failed to backup log %s: rc = %d\n",
-                      obd->obd_name, name, rc);
-out_backup:
-       llog_close(env, bllh);
-out_close:
-       llog_close(env, llh);
-       return rc;
-}
-EXPORT_SYMBOL(llog_backup);
index 48dbbcf977020d150a6898f8bcd734b3c1718d4d..c442cae5fd375d95ec0e28c0e2b4e12f670f5759 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_LOG
 
-
 #include "../include/obd_class.h"
 
 #include "llog_internal.h"
 
-/* Create a new log handle and add it to the open list.
- * This log handle will be closed when all of the records in it are removed.
- *
- * Assumes caller has already pushed us into the kernel context and is locking.
- */
-static int llog_cat_new_log(const struct lu_env *env,
-                           struct llog_handle *cathandle,
-                           struct llog_handle *loghandle,
-                           struct thandle *th)
-{
-
-       struct llog_log_hdr *llh;
-       struct llog_logid_rec rec = { { 0 }, };
-       int rc, index, bitmap_size;
-
-       llh = cathandle->lgh_hdr;
-       bitmap_size = LLOG_BITMAP_SIZE(llh);
-
-       index = (cathandle->lgh_last_idx + 1) % bitmap_size;
-
-       /* maximum number of available slots in catlog is bitmap_size - 2 */
-       if (llh->llh_cat_idx == index) {
-               CERROR("no free catalog slots for log...\n");
-               return -ENOSPC;
-       }
-
-       if (OBD_FAIL_CHECK(OBD_FAIL_MDS_LLOG_CREATE_FAILED))
-               return -ENOSPC;
-
-       rc = llog_create(env, loghandle, th);
-       /* if llog is already created, no need to initialize it */
-       if (rc == -EEXIST) {
-               return 0;
-       } else if (rc != 0) {
-               CERROR("%s: can't create new plain llog in catalog: rc = %d\n",
-                      loghandle->lgh_ctxt->loc_obd->obd_name, rc);
-               return rc;
-       }
-
-       rc = llog_init_handle(env, loghandle,
-                             LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
-                             &cathandle->lgh_hdr->llh_tgtuuid);
-       if (rc)
-               goto out_destroy;
-
-       if (index == 0)
-               index = 1;
-
-       spin_lock(&loghandle->lgh_hdr_lock);
-       llh->llh_count++;
-       if (ext2_set_bit(index, llh->llh_bitmap)) {
-               CERROR("argh, index %u already set in log bitmap?\n",
-                      index);
-               spin_unlock(&loghandle->lgh_hdr_lock);
-               LBUG(); /* should never happen */
-       }
-       spin_unlock(&loghandle->lgh_hdr_lock);
-
-       cathandle->lgh_last_idx = index;
-       llh->llh_tail.lrt_index = index;
-
-       CDEBUG(D_RPCTRACE,
-              "new recovery log "DOSTID":%x for index %u of catalog"
-              DOSTID"\n", POSTID(&loghandle->lgh_id.lgl_oi),
-              loghandle->lgh_id.lgl_ogen, index,
-              POSTID(&cathandle->lgh_id.lgl_oi));
-       /* build the record for this log in the catalog */
-       rec.lid_hdr.lrh_len = sizeof(rec);
-       rec.lid_hdr.lrh_index = index;
-       rec.lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
-       rec.lid_id = loghandle->lgh_id;
-       rec.lid_tail.lrt_len = sizeof(rec);
-       rec.lid_tail.lrt_index = index;
-
-       /* update the catalog: header and record */
-       rc = llog_write_rec(env, cathandle, &rec.lid_hdr,
-                           &loghandle->u.phd.phd_cookie, 1, NULL, index, th);
-       if (rc < 0)
-               goto out_destroy;
-
-       loghandle->lgh_hdr->llh_cat_idx = index;
-       return 0;
-out_destroy:
-       llog_destroy(env, loghandle);
-       return rc;
-}
-
 /* Open an existent log handle and add it to the open list.
  * This log handle will be closed when all of the records in it are removed.
  *
@@ -149,8 +61,10 @@ out_destroy:
  * This takes extra reference on llog_handle via llog_handle_get() and require
  * this reference to be put by caller using llog_handle_put()
  */
-int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
-                      struct llog_handle **res, struct llog_logid *logid)
+static int llog_cat_id2handle(const struct lu_env *env,
+                             struct llog_handle *cathandle,
+                             struct llog_handle **res,
+                             struct llog_logid *logid)
 {
        struct llog_handle      *loghandle;
        int                      rc = 0;
@@ -217,24 +131,8 @@ int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
 
        list_for_each_entry_safe(loghandle, n, &cathandle->u.chd.chd_head,
                                     u.phd.phd_entry) {
-               struct llog_log_hdr     *llh = loghandle->lgh_hdr;
-               int                      index;
-
                /* unlink open-not-created llogs */
                list_del_init(&loghandle->u.phd.phd_entry);
-               llh = loghandle->lgh_hdr;
-               if (loghandle->lgh_obj != NULL && llh != NULL &&
-                   (llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
-                   (llh->llh_count == 1)) {
-                       rc = llog_destroy(env, loghandle);
-                       if (rc)
-                               CERROR("%s: failure destroying log during cleanup: rc = %d\n",
-                                      loghandle->lgh_ctxt->loc_obd->obd_name,
-                                      rc);
-
-                       index = loghandle->u.phd.phd_cookie.lgc_index;
-                       llog_cat_cleanup(env, cathandle, NULL, index);
-               }
                llog_close(env, loghandle);
        }
        /* if handle was stored in ctxt, remove it too */
@@ -245,285 +143,6 @@ int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
 }
 EXPORT_SYMBOL(llog_cat_close);
 
-/**
- * lockdep markers for nested struct llog_handle::lgh_lock locking.
- */
-enum {
-       LLOGH_CAT,
-       LLOGH_LOG
-};
-
-/** Return the currently active log handle.  If the current log handle doesn't
- * have enough space left for the current record, start a new one.
- *
- * If reclen is 0, we only want to know what the currently active log is,
- * otherwise we get a lock on this log so nobody can steal our space.
- *
- * Assumes caller has already pushed us into the kernel context and is locking.
- *
- * NOTE: loghandle is write-locked upon successful return
- */
-static struct llog_handle *llog_cat_current_log(struct llog_handle *cathandle,
-                                               struct thandle *th)
-{
-       struct llog_handle *loghandle = NULL;
-
-       down_read_nested(&cathandle->lgh_lock, LLOGH_CAT);
-       loghandle = cathandle->u.chd.chd_current_log;
-       if (loghandle) {
-               struct llog_log_hdr *llh;
-
-               down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
-               llh = loghandle->lgh_hdr;
-               if (llh == NULL ||
-                   loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
-                       up_read(&cathandle->lgh_lock);
-                       return loghandle;
-               }
-               up_write(&loghandle->lgh_lock);
-       }
-       up_read(&cathandle->lgh_lock);
-
-       /* time to use next log */
-
-       /* first, we have to make sure the state hasn't changed */
-       down_write_nested(&cathandle->lgh_lock, LLOGH_CAT);
-       loghandle = cathandle->u.chd.chd_current_log;
-       if (loghandle) {
-               struct llog_log_hdr *llh;
-
-               down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
-               llh = loghandle->lgh_hdr;
-               LASSERT(llh);
-               if (loghandle->lgh_last_idx < LLOG_BITMAP_SIZE(llh) - 1) {
-                       up_write(&cathandle->lgh_lock);
-                       return loghandle;
-               }
-               up_write(&loghandle->lgh_lock);
-       }
-
-       CDEBUG(D_INODE, "use next log\n");
-
-       loghandle = cathandle->u.chd.chd_next_log;
-       cathandle->u.chd.chd_current_log = loghandle;
-       cathandle->u.chd.chd_next_log = NULL;
-       down_write_nested(&loghandle->lgh_lock, LLOGH_LOG);
-       up_write(&cathandle->lgh_lock);
-       LASSERT(loghandle);
-       return loghandle;
-}
-
-/* Add a single record to the recovery log(s) using a catalog
- * Returns as llog_write_record
- *
- * Assumes caller has already pushed us into the kernel context.
- */
-int llog_cat_add_rec(const struct lu_env *env, struct llog_handle *cathandle,
-                    struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
-                    void *buf, struct thandle *th)
-{
-       struct llog_handle *loghandle;
-       int rc;
-
-       LASSERT(rec->lrh_len <= LLOG_CHUNK_SIZE);
-       loghandle = llog_cat_current_log(cathandle, th);
-       LASSERT(!IS_ERR(loghandle));
-
-       /* loghandle is already locked by llog_cat_current_log() for us */
-       if (!llog_exist(loghandle)) {
-               rc = llog_cat_new_log(env, cathandle, loghandle, th);
-               if (rc < 0) {
-                       up_write(&loghandle->lgh_lock);
-                       return rc;
-               }
-       }
-       /* now let's try to add the record */
-       rc = llog_write_rec(env, loghandle, rec, reccookie, 1, buf, -1, th);
-       if (rc < 0)
-               CDEBUG_LIMIT(rc == -ENOSPC ? D_HA : D_ERROR,
-                            "llog_write_rec %d: lh=%p\n", rc, loghandle);
-       up_write(&loghandle->lgh_lock);
-       if (rc == -ENOSPC) {
-               /* try to use next log */
-               loghandle = llog_cat_current_log(cathandle, th);
-               LASSERT(!IS_ERR(loghandle));
-               /* new llog can be created concurrently */
-               if (!llog_exist(loghandle)) {
-                       rc = llog_cat_new_log(env, cathandle, loghandle, th);
-                       if (rc < 0) {
-                               up_write(&loghandle->lgh_lock);
-                               return rc;
-                       }
-               }
-               /* now let's try to add the record */
-               rc = llog_write_rec(env, loghandle, rec, reccookie, 1, buf,
-                                   -1, th);
-               if (rc < 0)
-                       CERROR("llog_write_rec %d: lh=%p\n", rc, loghandle);
-               up_write(&loghandle->lgh_lock);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(llog_cat_add_rec);
-
-int llog_cat_declare_add_rec(const struct lu_env *env,
-                            struct llog_handle *cathandle,
-                            struct llog_rec_hdr *rec, struct thandle *th)
-{
-       struct llog_handle      *loghandle, *next;
-       int                      rc = 0;
-
-       if (cathandle->u.chd.chd_current_log == NULL) {
-               /* declare new plain llog */
-               down_write(&cathandle->lgh_lock);
-               if (cathandle->u.chd.chd_current_log == NULL) {
-                       rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
-                                      NULL, NULL, LLOG_OPEN_NEW);
-                       if (rc == 0) {
-                               cathandle->u.chd.chd_current_log = loghandle;
-                               list_add_tail(&loghandle->u.phd.phd_entry,
-                                                 &cathandle->u.chd.chd_head);
-                       }
-               }
-               up_write(&cathandle->lgh_lock);
-       } else if (cathandle->u.chd.chd_next_log == NULL) {
-               /* declare next plain llog */
-               down_write(&cathandle->lgh_lock);
-               if (cathandle->u.chd.chd_next_log == NULL) {
-                       rc = llog_open(env, cathandle->lgh_ctxt, &loghandle,
-                                      NULL, NULL, LLOG_OPEN_NEW);
-                       if (rc == 0) {
-                               cathandle->u.chd.chd_next_log = loghandle;
-                               list_add_tail(&loghandle->u.phd.phd_entry,
-                                                 &cathandle->u.chd.chd_head);
-                       }
-               }
-               up_write(&cathandle->lgh_lock);
-       }
-       if (rc)
-               goto out;
-
-       if (!llog_exist(cathandle->u.chd.chd_current_log)) {
-               rc = llog_declare_create(env, cathandle->u.chd.chd_current_log,
-                                        th);
-               if (rc)
-                       goto out;
-               llog_declare_write_rec(env, cathandle, NULL, -1, th);
-       }
-       /* declare records in the llogs */
-       rc = llog_declare_write_rec(env, cathandle->u.chd.chd_current_log,
-                                   rec, -1, th);
-       if (rc)
-               goto out;
-
-       next = cathandle->u.chd.chd_next_log;
-       if (next) {
-               if (!llog_exist(next)) {
-                       rc = llog_declare_create(env, next, th);
-                       llog_declare_write_rec(env, cathandle, NULL, -1, th);
-               }
-               llog_declare_write_rec(env, next, rec, -1, th);
-       }
-out:
-       return rc;
-}
-EXPORT_SYMBOL(llog_cat_declare_add_rec);
-
-int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
-                struct llog_rec_hdr *rec, struct llog_cookie *reccookie,
-                void *buf)
-{
-       struct llog_ctxt        *ctxt;
-       struct dt_device        *dt;
-       struct thandle          *th = NULL;
-       int                      rc;
-
-       ctxt = cathandle->lgh_ctxt;
-       LASSERT(ctxt);
-       LASSERT(ctxt->loc_exp);
-
-       if (cathandle->lgh_obj != NULL) {
-               dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
-               LASSERT(dt);
-
-               th = dt_trans_create(env, dt);
-               if (IS_ERR(th))
-                       return PTR_ERR(th);
-
-               rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
-               if (rc)
-                       goto out_trans;
-
-               rc = dt_trans_start_local(env, dt, th);
-               if (rc)
-                       goto out_trans;
-               rc = llog_cat_add_rec(env, cathandle, rec, reccookie, buf, th);
-out_trans:
-               dt_trans_stop(env, dt, th);
-       } else { /* lvfs compat code */
-               LASSERT(cathandle->lgh_file != NULL);
-               rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
-               if (rc == 0)
-                       rc = llog_cat_add_rec(env, cathandle, rec, reccookie,
-                                             buf, th);
-       }
-       return rc;
-}
-EXPORT_SYMBOL(llog_cat_add);
-
-/* For each cookie in the cookie array, we clear the log in-use bit and either:
- * - the log is empty, so mark it free in the catalog header and delete it
- * - the log is not empty, just write out the log header
- *
- * The cookies may be in different log files, so we need to get new logs
- * each time.
- *
- * Assumes caller has already pushed us into the kernel context.
- */
-int llog_cat_cancel_records(const struct lu_env *env,
-                           struct llog_handle *cathandle, int count,
-                           struct llog_cookie *cookies)
-{
-       int i, index, rc = 0, failed = 0;
-
-       for (i = 0; i < count; i++, cookies++) {
-               struct llog_handle      *loghandle;
-               struct llog_logid       *lgl = &cookies->lgc_lgl;
-               int                      lrc;
-
-               rc = llog_cat_id2handle(env, cathandle, &loghandle, lgl);
-               if (rc) {
-                       CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
-                              cathandle->lgh_ctxt->loc_obd->obd_name,
-                              POSTID(&lgl->lgl_oi), rc);
-                       failed++;
-                       continue;
-               }
-
-               lrc = llog_cancel_rec(env, loghandle, cookies->lgc_index);
-               if (lrc == 1) {   /* log has been destroyed */
-                       index = loghandle->u.phd.phd_cookie.lgc_index;
-                       rc = llog_cat_cleanup(env, cathandle, loghandle,
-                                             index);
-               } else if (lrc == -ENOENT) {
-                       if (rc == 0) /* ENOENT shouldn't rewrite any error */
-                               rc = lrc;
-               } else if (lrc < 0) {
-                       failed++;
-                       rc = lrc;
-               }
-               llog_handle_put(loghandle);
-       }
-       if (rc)
-               CERROR("%s: fail to cancel %d of %d llog-records: rc = %d\n",
-                      cathandle->lgh_ctxt->loc_obd->obd_name, failed, count,
-                      rc);
-
-       return rc;
-}
-EXPORT_SYMBOL(llog_cat_cancel_records);
-
 static int llog_cat_process_cb(const struct lu_env *env,
                               struct llog_handle *cat_llh,
                               struct llog_rec_hdr *rec, void *data)
@@ -571,10 +190,10 @@ static int llog_cat_process_cb(const struct lu_env *env,
        return rc;
 }
 
-int llog_cat_process_or_fork(const struct lu_env *env,
-                            struct llog_handle *cat_llh,
-                            llog_cb_t cb, void *data, int startcat,
-                            int startidx, bool fork)
+static int llog_cat_process_or_fork(const struct lu_env *env,
+                                   struct llog_handle *cat_llh,
+                                   llog_cb_t cb, void *data, int startcat,
+                                   int startidx, bool fork)
 {
        struct llog_process_data d;
        struct llog_log_hdr *llh = cat_llh->lgh_hdr;
@@ -610,7 +229,6 @@ int llog_cat_process_or_fork(const struct lu_env *env,
 
        return rc;
 }
-EXPORT_SYMBOL(llog_cat_process_or_fork);
 
 int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
                     llog_cb_t cb, void *data, int startcat, int startidx)
@@ -619,195 +237,3 @@ int llog_cat_process(const struct lu_env *env, struct llog_handle *cat_llh,
                                        startidx, false);
 }
 EXPORT_SYMBOL(llog_cat_process);
-
-static int llog_cat_reverse_process_cb(const struct lu_env *env,
-                                      struct llog_handle *cat_llh,
-                                      struct llog_rec_hdr *rec, void *data)
-{
-       struct llog_process_data *d = data;
-       struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
-       struct llog_handle *llh;
-       int rc;
-
-       if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {
-               CERROR("invalid record in catalog\n");
-               return -EINVAL;
-       }
-       CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
-              DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
-              le32_to_cpu(rec->lrh_index), POSTID(&cat_llh->lgh_id.lgl_oi));
-
-       rc = llog_cat_id2handle(env, cat_llh, &llh, &lir->lid_id);
-       if (rc) {
-               CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
-                      cat_llh->lgh_ctxt->loc_obd->obd_name,
-                      POSTID(&lir->lid_id.lgl_oi), rc);
-               return rc;
-       }
-
-       rc = llog_reverse_process(env, llh, d->lpd_cb, d->lpd_data, NULL);
-       llog_handle_put(llh);
-       return rc;
-}
-
-int llog_cat_reverse_process(const struct lu_env *env,
-                            struct llog_handle *cat_llh,
-                            llog_cb_t cb, void *data)
-{
-       struct llog_process_data d;
-       struct llog_process_cat_data cd;
-       struct llog_log_hdr *llh = cat_llh->lgh_hdr;
-       int rc;
-
-       LASSERT(llh->llh_flags & LLOG_F_IS_CAT);
-       d.lpd_data = data;
-       d.lpd_cb = cb;
-
-       if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {
-               CWARN("catalog "DOSTID" crosses index zero\n",
-                     POSTID(&cat_llh->lgh_id.lgl_oi));
-
-               cd.lpcd_first_idx = 0;
-               cd.lpcd_last_idx = cat_llh->lgh_last_idx;
-               rc = llog_reverse_process(env, cat_llh,
-                                         llog_cat_reverse_process_cb,
-                                         &d, &cd);
-               if (rc != 0)
-                       return rc;
-
-               cd.lpcd_first_idx = le32_to_cpu(llh->llh_cat_idx);
-               cd.lpcd_last_idx = 0;
-               rc = llog_reverse_process(env, cat_llh,
-                                         llog_cat_reverse_process_cb,
-                                         &d, &cd);
-       } else {
-               rc = llog_reverse_process(env, cat_llh,
-                                         llog_cat_reverse_process_cb,
-                                         &d, NULL);
-       }
-
-       return rc;
-}
-EXPORT_SYMBOL(llog_cat_reverse_process);
-
-static int llog_cat_set_first_idx(struct llog_handle *cathandle, int index)
-{
-       struct llog_log_hdr *llh = cathandle->lgh_hdr;
-       int i, bitmap_size, idx;
-
-       bitmap_size = LLOG_BITMAP_SIZE(llh);
-       if (llh->llh_cat_idx == (index - 1)) {
-               idx = llh->llh_cat_idx + 1;
-               llh->llh_cat_idx = idx;
-               if (idx == cathandle->lgh_last_idx)
-                       goto out;
-               for (i = (index + 1) % bitmap_size;
-                    i != cathandle->lgh_last_idx;
-                    i = (i + 1) % bitmap_size) {
-                       if (!ext2_test_bit(i, llh->llh_bitmap)) {
-                               idx = llh->llh_cat_idx + 1;
-                               llh->llh_cat_idx = idx;
-                       } else if (i == 0) {
-                               llh->llh_cat_idx = 0;
-                       } else {
-                               break;
-                       }
-               }
-out:
-               CDEBUG(D_RPCTRACE, "set catlog "DOSTID" first idx %u\n",
-                      POSTID(&cathandle->lgh_id.lgl_oi), llh->llh_cat_idx);
-       }
-
-       return 0;
-}
-
-/* Cleanup deleted plain llog traces from catalog */
-int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
-                    struct llog_handle *loghandle, int index)
-{
-       int rc;
-
-       LASSERT(index);
-       if (loghandle != NULL) {
-               /* remove destroyed llog from catalog list and
-                * chd_current_log variable */
-               down_write(&cathandle->lgh_lock);
-               if (cathandle->u.chd.chd_current_log == loghandle)
-                       cathandle->u.chd.chd_current_log = NULL;
-               list_del_init(&loghandle->u.phd.phd_entry);
-               up_write(&cathandle->lgh_lock);
-               LASSERT(index == loghandle->u.phd.phd_cookie.lgc_index);
-               /* llog was opened and keep in a list, close it now */
-               llog_close(env, loghandle);
-       }
-       /* remove plain llog entry from catalog by index */
-       llog_cat_set_first_idx(cathandle, index);
-       rc = llog_cancel_rec(env, cathandle, index);
-       if (rc == 0)
-               CDEBUG(D_HA, "cancel plain log at index %u of catalog " DOSTID "\n",
-                      index, POSTID(&cathandle->lgh_id.lgl_oi));
-       return rc;
-}
-
-static int cat_cancel_cb(const struct lu_env *env, struct llog_handle *cathandle,
-                 struct llog_rec_hdr *rec, void *data)
-{
-       struct llog_logid_rec   *lir = (struct llog_logid_rec *)rec;
-       struct llog_handle      *loghandle;
-       struct llog_log_hdr     *llh;
-       int                      rc;
-
-       if (rec->lrh_type != LLOG_LOGID_MAGIC) {
-               CERROR("invalid record in catalog\n");
-               return -EINVAL;
-       }
-
-       CDEBUG(D_HA, "processing log "DOSTID":%x at index %u of catalog "
-              DOSTID"\n", POSTID(&lir->lid_id.lgl_oi), lir->lid_id.lgl_ogen,
-              rec->lrh_index, POSTID(&cathandle->lgh_id.lgl_oi));
-
-       rc = llog_cat_id2handle(env, cathandle, &loghandle, &lir->lid_id);
-       if (rc) {
-               CERROR("%s: cannot find handle for llog "DOSTID": %d\n",
-                      cathandle->lgh_ctxt->loc_obd->obd_name,
-                      POSTID(&lir->lid_id.lgl_oi), rc);
-               if (rc == -ENOENT || rc == -ESTALE) {
-                       /* remove index from catalog */
-                       llog_cat_cleanup(env, cathandle, NULL, rec->lrh_index);
-               }
-               return rc;
-       }
-
-       llh = loghandle->lgh_hdr;
-       if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&
-           (llh->llh_count == 1)) {
-               rc = llog_destroy(env, loghandle);
-               if (rc)
-                       CERROR("%s: fail to destroy empty log: rc = %d\n",
-                              loghandle->lgh_ctxt->loc_obd->obd_name, rc);
-
-               llog_cat_cleanup(env, cathandle, loghandle,
-                                loghandle->u.phd.phd_cookie.lgc_index);
-       }
-       llog_handle_put(loghandle);
-
-       return rc;
-}
-
-/* helper to initialize catalog llog and process it to cancel */
-int llog_cat_init_and_process(const struct lu_env *env,
-                             struct llog_handle *llh)
-{
-       int rc;
-
-       rc = llog_init_handle(env, llh, LLOG_F_IS_CAT, NULL);
-       if (rc)
-               return rc;
-
-       rc = llog_process_or_fork(env, llh, cat_cancel_cb, NULL, NULL, false);
-       if (rc)
-               CERROR("%s: llog_process() with cat_cancel_cb failed: rc = %d\n",
-                      llh->lgh_ctxt->loc_obd->obd_name, rc);
-       return 0;
-}
-EXPORT_SYMBOL(llog_cat_init_and_process);
index 5332131a2a2e429391f105fd452fa5f2ee42a0cc..b9fe4b01c690a7a2504128781acc7739ad8f7431 100644 (file)
@@ -53,7 +53,6 @@ struct llog_process_info {
 struct llog_thread_info {
        struct lu_attr                   lgi_attr;
        struct lu_fid                    lgi_fid;
-       struct dt_object_format          lgi_dof;
        struct lu_buf                    lgi_buf;
        loff_t                           lgi_off;
        struct llog_rec_hdr              lgi_lrh;
@@ -62,34 +61,14 @@ struct llog_thread_info {
 
 extern struct lu_context_key llog_thread_key;
 
-static inline struct llog_thread_info *llog_info(const struct lu_env *env)
-{
-       struct llog_thread_info *lgi;
-
-       lgi = lu_context_key_get(&env->le_ctx, &llog_thread_key);
-       LASSERT(lgi);
-       return lgi;
-}
-
-static inline void
-lustre_build_llog_lvfs_oid(struct llog_logid *logid, __u64 ino, __u32 gen)
-{
-       ostid_set_seq_llog(&logid->lgl_oi);
-       ostid_set_id(&logid->lgl_oi, ino);
-       logid->lgl_ogen = gen;
-}
-
 int llog_info_init(void);
 void llog_info_fini(void);
 
 void llog_handle_get(struct llog_handle *loghandle);
 void llog_handle_put(struct llog_handle *loghandle);
-int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
-                      struct llog_handle **res, struct llog_logid *logid);
 int class_config_dump_handler(const struct lu_env *env,
                              struct llog_handle *handle,
                              struct llog_rec_hdr *rec, void *data);
-int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size);
 int llog_process_or_fork(const struct lu_env *env,
                         struct llog_handle *loghandle,
                         llog_cb_t cb, void *data, void *catdata, bool fork);
index 81ab27e7376f125b49669ee0af2c8b30135da9c6..3900b9d4007e792e676adb6040bb5187ec79b36c 100644 (file)
@@ -36,7 +36,6 @@
 
 #define DEBUG_SUBSYSTEM S_LOG
 
-
 #include "../include/obd_class.h"
 #include "../include/lustre_log.h"
 #include "llog_internal.h"
@@ -212,36 +211,6 @@ int llog_setup(const struct lu_env *env, struct obd_device *obd,
 }
 EXPORT_SYMBOL(llog_setup);
 
-int llog_sync(struct llog_ctxt *ctxt, struct obd_export *exp, int flags)
-{
-       int rc = 0;
-
-       if (!ctxt)
-               return 0;
-
-       if (CTXTP(ctxt, sync))
-               rc = CTXTP(ctxt, sync)(ctxt, exp, flags);
-
-       return rc;
-}
-EXPORT_SYMBOL(llog_sync);
-
-int llog_cancel(const struct lu_env *env, struct llog_ctxt *ctxt,
-               struct llog_cookie *cookies, int flags)
-{
-       int rc;
-
-       if (!ctxt) {
-               CERROR("No ctxt\n");
-               return -ENODEV;
-       }
-
-       CTXT_CHECK_OP(ctxt, cancel, -EOPNOTSUPP);
-       rc = CTXTP(ctxt, cancel)(env, ctxt, cookies, flags);
-       return rc;
-}
-EXPORT_SYMBOL(llog_cancel);
-
 /* context key constructor/destructor: llog_key_init, llog_key_fini */
 LU_KEY_INIT_FINI(llog, struct llog_thread_info);
 /* context key: llog_thread_key */
index a2d5aa105d6bf200bd1555b815400ed9b7eb3ff4..9354f75b5cab7b6e438d03be0aa05ad0057fdbdf 100644 (file)
@@ -42,7 +42,6 @@
 
 #define DEBUG_SUBSYSTEM S_LOG
 
-
 #include "../include/lustre_log.h"
 
 static void print_llogd_body(struct llogd_body *d)
@@ -78,13 +77,12 @@ void lustre_swab_ost_id(struct ost_id *oid)
 }
 EXPORT_SYMBOL(lustre_swab_ost_id);
 
-void lustre_swab_llog_id(struct llog_logid *log_id)
+static void lustre_swab_llog_id(struct llog_logid *log_id)
 {
        __swab64s(&log_id->lgl_oi.oi.oi_id);
        __swab64s(&log_id->lgl_oi.oi.oi_seq);
        __swab32s(&log_id->lgl_ogen);
 }
-EXPORT_SYMBOL(lustre_swab_llog_id);
 
 void lustre_swab_llogd_body(struct llogd_body *d)
 {
@@ -109,13 +107,12 @@ void lustre_swab_llogd_conn_body(struct llogd_conn_body *d)
 }
 EXPORT_SYMBOL(lustre_swab_llogd_conn_body);
 
-void lustre_swab_ll_fid(struct ll_fid *fid)
+static void lustre_swab_ll_fid(struct ll_fid *fid)
 {
        __swab64s(&fid->id);
        __swab32s(&fid->generation);
        __swab32s(&fid->f_type);
 }
-EXPORT_SYMBOL(lustre_swab_ll_fid);
 
 void lustre_swab_lu_seq_range(struct lu_seq_range *range)
 {
index c49dfe541925790d00d07c97ea783ae4a62df21c..6acc4a10fde9b046ba7ff1461ef52ba7aca95e61 100644 (file)
@@ -41,9 +41,6 @@
 #include "../include/lprocfs_status.h"
 #include "../include/obd_support.h"
 
-struct lprocfs_stats *obd_memory = NULL;
-EXPORT_SYMBOL(obd_memory);
-
 void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount)
 {
        struct lprocfs_counter          *percpu_cntr;
@@ -74,9 +71,6 @@ void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount)
                 * ldlm_pool_shrink(), which calls lprocfs_counter_add().
                 * LU-1727.
                 *
-                * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
-                * flag, because it needs accurate counting lest memory leak
-                * check reports error.
                 */
                if (in_interrupt() &&
                    (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
@@ -124,9 +118,6 @@ void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount)
                 * softirq context here, use separate counter for that.
                 * bz20650.
                 *
-                * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
-                * flag, because it needs accurate counting lest memory leak
-                * check reports error.
                 */
                if (in_interrupt() &&
                    (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
index 08d1f0edf98d1008c26eca3a02ee02d407715ee3..333ac7d269b7ed3ae5667a0c8eccc5bc4894bba4 100644 (file)
@@ -40,7 +40,6 @@
 
 #define DEBUG_SUBSYSTEM S_CLASS
 
-
 #include "../include/obd_class.h"
 #include "../include/lprocfs_status.h"
 #include "../include/lustre/lustre_idl.h"
@@ -264,36 +263,6 @@ struct dentry *ldebugfs_add_simple(struct dentry *root,
 }
 EXPORT_SYMBOL(ldebugfs_add_simple);
 
-struct dentry *ldebugfs_add_symlink(const char *name, struct dentry *parent,
-                                   const char *format, ...)
-{
-       struct dentry *entry;
-       char *dest;
-       va_list ap;
-
-       if (parent == NULL || format == NULL)
-               return NULL;
-
-       dest = kzalloc(MAX_STRING_SIZE + 1, GFP_KERNEL);
-       if (!dest)
-               return NULL;
-
-       va_start(ap, format);
-       vsnprintf(dest, MAX_STRING_SIZE, format, ap);
-       va_end(ap);
-
-       entry = debugfs_create_symlink(name, parent, dest);
-       if (IS_ERR_OR_NULL(entry)) {
-               CERROR("LdebugFS: Could not create symbolic link from %s to %s",
-                       name, dest);
-               entry = NULL;
-       }
-
-       kfree(dest);
-       return entry;
-}
-EXPORT_SYMBOL(ldebugfs_add_symlink);
-
 static struct file_operations lprocfs_generic_fops = { };
 
 int ldebugfs_add_vars(struct dentry *parent,
@@ -388,41 +357,6 @@ int lprocfs_wr_uint(struct file *file, const char __user *buffer,
 }
 EXPORT_SYMBOL(lprocfs_wr_uint);
 
-int lprocfs_rd_u64(struct seq_file *m, void *data)
-{
-       seq_printf(m, "%llu\n", *(__u64 *)data);
-       return 0;
-}
-EXPORT_SYMBOL(lprocfs_rd_u64);
-
-int lprocfs_rd_atomic(struct seq_file *m, void *data)
-{
-       atomic_t *atom = data;
-       LASSERT(atom != NULL);
-       seq_printf(m, "%d\n", atomic_read(atom));
-       return 0;
-}
-EXPORT_SYMBOL(lprocfs_rd_atomic);
-
-int lprocfs_wr_atomic(struct file *file, const char __user *buffer,
-                     unsigned long count, void *data)
-{
-       atomic_t *atm = data;
-       int val = 0;
-       int rc;
-
-       rc = lprocfs_write_helper(buffer, count, &val);
-       if (rc < 0)
-               return rc;
-
-       if (val <= 0)
-               return -ERANGE;
-
-       atomic_set(atm, val);
-       return count;
-}
-EXPORT_SYMBOL(lprocfs_wr_atomic);
-
 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
                         char *buf)
 {
@@ -433,16 +367,6 @@ static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,
 }
 LUSTRE_RO_ATTR(uuid);
 
-int lprocfs_rd_name(struct seq_file *m, void *data)
-{
-       struct obd_device *dev = data;
-
-       LASSERT(dev != NULL);
-       seq_printf(m, "%s\n", dev->obd_name);
-       return 0;
-}
-EXPORT_SYMBOL(lprocfs_rd_name);
-
 static ssize_t blocksize_show(struct kobject *kobj, struct attribute *attr,
                              char *buf)
 {
@@ -565,9 +489,13 @@ int lprocfs_rd_server_uuid(struct seq_file *m, void *data)
        struct obd_device *obd = data;
        struct obd_import *imp;
        char *imp_state_name = NULL;
+       int rc;
 
        LASSERT(obd != NULL);
-       LPROCFS_CLIMP_CHECK(obd);
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
+
        imp = obd->u.cli.cl_import;
        imp_state_name = ptlrpc_import_state_name(imp->imp_state);
        seq_printf(m, "%s\t%s%s\n",
@@ -584,10 +512,14 @@ int lprocfs_rd_conn_uuid(struct seq_file *m, void *data)
 {
        struct obd_device *obd = data;
        struct ptlrpc_connection *conn;
+       int rc;
 
        LASSERT(obd != NULL);
 
-       LPROCFS_CLIMP_CHECK(obd);
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
+
        conn = obd->u.cli.cl_import->imp_connection;
        if (conn && obd->u.cli.cl_import)
                seq_printf(m, "%s\n", conn->c_remote_uuid.uuid);
@@ -663,6 +595,7 @@ static int obd_import_flags2str(struct obd_import *imp, struct seq_file *m)
        flag2str(pingable, first);
        return 0;
 }
+
 #undef flags2str
 
 static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep)
@@ -685,17 +618,22 @@ static void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, char *sep
 
 int lprocfs_rd_import(struct seq_file *m, void *data)
 {
+       char                            nidstr[LNET_NIDSTR_SIZE];
        struct lprocfs_counter          ret;
        struct lprocfs_counter_header   *header;
-       struct obd_device               *obd    = (struct obd_device *)data;
+       struct obd_device               *obd    = data;
        struct obd_import               *imp;
        struct obd_import_conn          *conn;
        int                             j;
        int                             k;
        int                             rw      = 0;
+       int                             rc;
 
        LASSERT(obd != NULL);
-       LPROCFS_CLIMP_CHECK(obd);
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
+
        imp = obd->u.cli.cl_import;
 
        seq_printf(m,
@@ -722,18 +660,20 @@ int lprocfs_rd_import(struct seq_file *m, void *data)
        spin_lock(&imp->imp_lock);
        j = 0;
        list_for_each_entry(conn, &imp->imp_conn_list, oic_item) {
-               seq_printf(m, "%s%s", j ? ", " : "",
-                          libcfs_nid2str(conn->oic_conn->c_peer.nid));
+               libcfs_nid2str_r(conn->oic_conn->c_peer.nid,
+                                nidstr, sizeof(nidstr));
+               seq_printf(m, "%s%s", j ? ", " : "", nidstr);
                j++;
        }
+       libcfs_nid2str_r(imp->imp_connection->c_peer.nid,
+                        nidstr, sizeof(nidstr));
        seq_printf(m,
                      "]\n"
                      "       current_connection: %s\n"
                      "       connection_attempts: %u\n"
                      "       generation: %u\n"
                      "       in-progress_invalidations: %u\n",
-                     imp->imp_connection == NULL ? "<none>" :
-                             libcfs_nid2str(imp->imp_connection->c_peer.nid),
+                     imp->imp_connection == NULL ? "<none>" : nidstr,
                      imp->imp_conn_cnt,
                      imp->imp_generation,
                      atomic_read(&imp->imp_inval_count));
@@ -747,6 +687,7 @@ int lprocfs_rd_import(struct seq_file *m, void *data)
        if (ret.lc_count != 0) {
                /* first argument to do_div MUST be __u64 */
                __u64 sum = ret.lc_sum;
+
                do_div(sum, ret.lc_count);
                ret.lc_sum = sum;
        } else
@@ -793,6 +734,7 @@ int lprocfs_rd_import(struct seq_file *m, void *data)
                if (ret.lc_sum > 0 && ret.lc_count > 0) {
                        /* first argument to do_div MUST be __u64 */
                        __u64 sum = ret.lc_sum;
+
                        do_div(sum, ret.lc_count);
                        ret.lc_sum = sum;
                        seq_printf(m,
@@ -808,6 +750,7 @@ int lprocfs_rd_import(struct seq_file *m, void *data)
                if (ret.lc_sum > 0 && ret.lc_count != 0) {
                        /* first argument to do_div MUST be __u64 */
                        __u64 sum = ret.lc_sum;
+
                        do_div(sum, ret.lc_count);
                        ret.lc_sum = sum;
                        seq_printf(m,
@@ -829,12 +772,15 @@ EXPORT_SYMBOL(lprocfs_rd_import);
 
 int lprocfs_rd_state(struct seq_file *m, void *data)
 {
-       struct obd_device *obd = (struct obd_device *)data;
+       struct obd_device *obd = data;
        struct obd_import *imp;
-       int j, k;
+       int j, k, rc;
 
        LASSERT(obd != NULL);
-       LPROCFS_CLIMP_CHECK(obd);
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
+
        imp = obd->u.cli.cl_import;
 
        seq_printf(m, "current_state: %s\n",
@@ -846,9 +792,8 @@ int lprocfs_rd_state(struct seq_file *m, void *data)
                        &imp->imp_state_hist[(k + j) % IMP_STATE_HIST_LEN];
                if (ish->ish_state == 0)
                        continue;
-               seq_printf(m, " - ["CFS_TIME_T", %s]\n",
-                             ish->ish_time,
-                             ptlrpc_import_state_name(ish->ish_state));
+               seq_printf(m, " - [%lld, %s]\n", (s64)ish->ish_time,
+                          ptlrpc_import_state_name(ish->ish_state));
        }
 
        LPROCFS_CLIMP_EXIT(obd);
@@ -859,6 +804,7 @@ EXPORT_SYMBOL(lprocfs_rd_state);
 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at)
 {
        int i;
+
        for (i = 0; i < AT_BINS; i++)
                seq_printf(m, "%3u ", at->at_hist[i]);
        seq_printf(m, "\n");
@@ -869,30 +815,33 @@ EXPORT_SYMBOL(lprocfs_at_hist_helper);
 /* See also ptlrpc_lprocfs_rd_timeouts */
 int lprocfs_rd_timeouts(struct seq_file *m, void *data)
 {
-       struct obd_device *obd = (struct obd_device *)data;
+       struct obd_device *obd = data;
        struct obd_import *imp;
        unsigned int cur, worst;
-       time_t now, worstt;
+       time64_t now, worstt;
        struct dhms ts;
-       int i;
+       int i, rc;
 
        LASSERT(obd != NULL);
-       LPROCFS_CLIMP_CHECK(obd);
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
+
        imp = obd->u.cli.cl_import;
 
-       now = get_seconds();
+       now = ktime_get_real_seconds();
 
        /* Some network health info for kicks */
        s2dhms(&ts, now - imp->imp_last_reply_time);
-       seq_printf(m, "%-10s : %ld, "DHMS_FMT" ago\n",
-                      "last reply", imp->imp_last_reply_time, DHMS_VARS(&ts));
+       seq_printf(m, "%-10s : %lld, " DHMS_FMT " ago\n",
+                  "last reply", (s64)imp->imp_last_reply_time, DHMS_VARS(&ts));
 
        cur = at_get(&imp->imp_at.iat_net_latency);
        worst = imp->imp_at.iat_net_latency.at_worst_ever;
        worstt = imp->imp_at.iat_net_latency.at_worst_time;
        s2dhms(&ts, now - worstt);
-       seq_printf(m, "%-10s : cur %3u  worst %3u (at %ld, "DHMS_FMT" ago) ",
-                      "network", cur, worst, worstt, DHMS_VARS(&ts));
+       seq_printf(m, "%-10s : cur %3u  worst %3u (at %lld, " DHMS_FMT " ago) ",
+                  "network", cur, worst, (s64)worstt, DHMS_VARS(&ts));
        lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
 
        for (i = 0; i < IMP_AT_MAX_PORTALS; i++) {
@@ -902,9 +851,9 @@ int lprocfs_rd_timeouts(struct seq_file *m, void *data)
                worst = imp->imp_at.iat_service_estimate[i].at_worst_ever;
                worstt = imp->imp_at.iat_service_estimate[i].at_worst_time;
                s2dhms(&ts, now - worstt);
-               seq_printf(m, "portal %-2d  : cur %3u  worst %3u (at %ld, "
-                              DHMS_FMT" ago) ", imp->imp_at.iat_portal[i],
-                              cur, worst, worstt, DHMS_VARS(&ts));
+               seq_printf(m, "portal %-2d  : cur %3u  worst %3u (at %lld, "
+                          DHMS_FMT " ago) ", imp->imp_at.iat_portal[i],
+                          cur, worst, (s64)worstt, DHMS_VARS(&ts));
                lprocfs_at_hist_helper(m, &imp->imp_at.iat_service_estimate[i]);
        }
 
@@ -917,8 +866,12 @@ int lprocfs_rd_connect_flags(struct seq_file *m, void *data)
 {
        struct obd_device *obd = data;
        __u64 flags;
+       int rc;
+
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
 
-       LPROCFS_CLIMP_CHECK(obd);
        flags = obd->u.cli.cl_import->imp_connect_data.ocd_connect_flags;
        seq_printf(m, "flags=%#llx\n", flags);
        obd_connect_seq_flags2str(m, flags, "\n");
@@ -1082,7 +1035,7 @@ struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
                        goto fail;
                stats->ls_biggest_alloc_num = 1;
        } else if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0) {
-               /* alloc all percpu data, currently only obd_memory use this */
+               /* alloc all percpu data */
                for (i = 0; i < num_entry; ++i)
                        if (lprocfs_stats_alloc_one(stats, i) < 0)
                                goto fail;
@@ -1190,11 +1143,12 @@ static int lprocfs_stats_seq_show(struct seq_file *p, void *v)
        int                              idx    = *(loff_t *)v;
 
        if (idx == 0) {
-               struct timeval now;
-               do_gettimeofday(&now);
-               seq_printf(p, "%-25s %lu.%lu secs.usecs\n",
+               struct timespec64 now;
+
+               ktime_get_real_ts64(&now);
+               seq_printf(p, "%-25s %llu.%9lu secs.usecs\n",
                           "snapshot_time",
-                          now.tv_sec, (unsigned long)now.tv_usec);
+                          (s64)now.tv_sec, (unsigned long)now.tv_nsec);
        }
 
        hdr = &stats->ls_cnt_header[idx];
@@ -1300,227 +1254,6 @@ void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
 }
 EXPORT_SYMBOL(lprocfs_counter_init);
 
-#define LPROCFS_OBD_OP_INIT(base, stats, op)                          \
-do {                                                                  \
-       unsigned int coffset = base + OBD_COUNTER_OFFSET(op);         \
-       LASSERT(coffset < stats->ls_num);                                 \
-       lprocfs_counter_init(stats, coffset, 0, #op, "reqs");         \
-} while (0)
-
-void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats)
-{
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, iocontrol);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_info);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, set_info_async);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, attach);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, detach);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, setup);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, precleanup);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, cleanup);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, process_config);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, postrecov);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, add_conn);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, del_conn);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, connect);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, reconnect);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, disconnect);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_init);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_fini);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_alloc);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs_async);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr_async);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, adjust_kms);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, find_cbdata);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, health_check);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_uuid);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotacheck);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotactl);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_new);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_rem);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_add);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_del);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, getref);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, putref);
-}
-EXPORT_SYMBOL(lprocfs_init_ops_stats);
-
-int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
-{
-       struct lprocfs_stats *stats;
-       unsigned int num_stats;
-       int rc, i;
-
-       LASSERT(obd->obd_stats == NULL);
-       LASSERT(obd->obd_debugfs_entry != NULL);
-       LASSERT(obd->obd_cntr_base == 0);
-
-       num_stats = ((int)sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
-               num_private_stats - 1 /* o_owner */;
-       stats = lprocfs_alloc_stats(num_stats, 0);
-       if (stats == NULL)
-               return -ENOMEM;
-
-       lprocfs_init_ops_stats(num_private_stats, stats);
-
-       for (i = num_private_stats; i < num_stats; i++) {
-               /* If this LBUGs, it is likely that an obd
-                * operation was added to struct obd_ops in
-                * <obd.h>, and that the corresponding line item
-                * LPROCFS_OBD_OP_INIT(.., .., opname)
-                * is missing from the list above. */
-               LASSERTF(stats->ls_cnt_header[i].lc_name != NULL,
-                        "Missing obd_stat initializer obd_op operation at offset %d.\n",
-                        i - num_private_stats);
-       }
-       rc = ldebugfs_register_stats(obd->obd_debugfs_entry, "stats", stats);
-       if (rc < 0) {
-               lprocfs_free_stats(&stats);
-       } else {
-               obd->obd_stats  = stats;
-               obd->obd_cntr_base = num_private_stats;
-       }
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_alloc_obd_stats);
-
-void lprocfs_free_obd_stats(struct obd_device *obd)
-{
-       if (obd->obd_stats)
-               lprocfs_free_stats(&obd->obd_stats);
-}
-EXPORT_SYMBOL(lprocfs_free_obd_stats);
-
-#define LPROCFS_MD_OP_INIT(base, stats, op)                         \
-do {                                                               \
-       unsigned int coffset = base + MD_COUNTER_OFFSET(op);        \
-       LASSERT(coffset < stats->ls_num);                              \
-       lprocfs_counter_init(stats, coffset, 0, #op, "reqs");      \
-} while (0)
-
-void lprocfs_init_mps_stats(int num_private_stats, struct lprocfs_stats *stats)
-{
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, getstatus);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, null_inode);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, find_cbdata);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, close);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, create);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, done_writing);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, enqueue);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, getattr_name);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_lock);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, link);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, rename);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, is_subdir);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, setattr);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, sync);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, readpage);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, unlink);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, setxattr);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, getxattr);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, init_ea_size);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, get_lustre_md);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, free_lustre_md);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, set_open_replay_data);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, clear_open_replay_data);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, set_lock_data);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, lock_match);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, cancel_unused);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, renew_capa);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, unpack_capa);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, get_remote_perm);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, intent_getattr_async);
-       LPROCFS_MD_OP_INIT(num_private_stats, stats, revalidate_lock);
-}
-EXPORT_SYMBOL(lprocfs_init_mps_stats);
-
-int lprocfs_alloc_md_stats(struct obd_device *obd,
-                          unsigned num_private_stats)
-{
-       struct lprocfs_stats *stats;
-       unsigned int num_stats;
-       int rc, i;
-
-       LASSERT(obd->md_stats == NULL);
-       LASSERT(obd->obd_debugfs_entry != NULL);
-       LASSERT(obd->md_cntr_base == 0);
-
-       num_stats = 1 + MD_COUNTER_OFFSET(revalidate_lock) +
-                   num_private_stats;
-       stats = lprocfs_alloc_stats(num_stats, 0);
-       if (stats == NULL)
-               return -ENOMEM;
-
-       lprocfs_init_mps_stats(num_private_stats, stats);
-
-       for (i = num_private_stats; i < num_stats; i++) {
-               if (stats->ls_cnt_header[i].lc_name == NULL) {
-                       CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
-                              i - num_private_stats);
-                       LBUG();
-               }
-       }
-       rc = ldebugfs_register_stats(obd->obd_debugfs_entry, "md_stats", stats);
-       if (rc < 0) {
-               lprocfs_free_stats(&stats);
-       } else {
-               obd->md_stats  = stats;
-               obd->md_cntr_base = num_private_stats;
-       }
-       return rc;
-}
-EXPORT_SYMBOL(lprocfs_alloc_md_stats);
-
-void lprocfs_free_md_stats(struct obd_device *obd)
-{
-       struct lprocfs_stats *stats = obd->md_stats;
-
-       if (stats != NULL) {
-               obd->md_stats = NULL;
-               obd->md_cntr_base = 0;
-               lprocfs_free_stats(&stats);
-       }
-}
-EXPORT_SYMBOL(lprocfs_free_md_stats);
-
-void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
-{
-       lprocfs_counter_init(ldlm_stats,
-                            LDLM_ENQUEUE - LDLM_FIRST_OPC,
-                            0, "ldlm_enqueue", "reqs");
-       lprocfs_counter_init(ldlm_stats,
-                            LDLM_CONVERT - LDLM_FIRST_OPC,
-                            0, "ldlm_convert", "reqs");
-       lprocfs_counter_init(ldlm_stats,
-                            LDLM_CANCEL - LDLM_FIRST_OPC,
-                            0, "ldlm_cancel", "reqs");
-       lprocfs_counter_init(ldlm_stats,
-                            LDLM_BL_CALLBACK - LDLM_FIRST_OPC,
-                            0, "ldlm_bl_callback", "reqs");
-       lprocfs_counter_init(ldlm_stats,
-                            LDLM_CP_CALLBACK - LDLM_FIRST_OPC,
-                            0, "ldlm_cp_callback", "reqs");
-       lprocfs_counter_init(ldlm_stats,
-                            LDLM_GL_CALLBACK - LDLM_FIRST_OPC,
-                            0, "ldlm_gl_callback", "reqs");
-}
-EXPORT_SYMBOL(lprocfs_init_ldlm_stats);
-
 int lprocfs_exp_cleanup(struct obd_export *exp)
 {
        return 0;
@@ -1576,31 +1309,6 @@ int lprocfs_write_helper(const char __user *buffer, unsigned long count,
 }
 EXPORT_SYMBOL(lprocfs_write_helper);
 
-int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
-{
-       long decimal_val, frac_val;
-
-       decimal_val = val / mult;
-       seq_printf(m, "%ld", decimal_val);
-       frac_val = val % mult;
-
-       if (frac_val > 0) {
-               frac_val *= 100;
-               frac_val /= mult;
-       }
-       if (frac_val > 0) {
-               /* Three cases: x0, xx, 0x */
-               if ((frac_val % 10) != 0)
-                       seq_printf(m, ".%ld", frac_val);
-               else
-                       seq_printf(m, ".%ld", frac_val / 10);
-       }
-
-       seq_printf(m, "\n");
-       return 0;
-}
-EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
-
 int lprocfs_write_u64_helper(const char __user *buffer, unsigned long count,
                             __u64 *val)
 {
@@ -1635,6 +1343,7 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
 
        if (*end == '.') {
                int i;
+
                pbuf = end + 1;
 
                /* need to limit frac_d to a __u32 */
@@ -1788,36 +1497,21 @@ void lprocfs_oh_clear(struct obd_histogram *oh)
 }
 EXPORT_SYMBOL(lprocfs_oh_clear);
 
-int lprocfs_obd_rd_max_pages_per_rpc(struct seq_file *m, void *data)
-{
-       struct obd_device *dev = data;
-       struct client_obd *cli = &dev->u.cli;
-
-       client_obd_list_lock(&cli->cl_loi_list_lock);
-       seq_printf(m, "%d\n", cli->cl_max_pages_per_rpc);
-       client_obd_list_unlock(&cli->cl_loi_list_lock);
-
-       return 0;
-}
-EXPORT_SYMBOL(lprocfs_obd_rd_max_pages_per_rpc);
-
-ssize_t lustre_attr_show(struct kobject *kobj,
-                        struct attribute *attr, char *buf)
+static ssize_t lustre_attr_show(struct kobject *kobj,
+                               struct attribute *attr, char *buf)
 {
        struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
 
        return a->show ? a->show(kobj, attr, buf) : 0;
 }
-EXPORT_SYMBOL_GPL(lustre_attr_show);
 
-ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
-                         const char *buf, size_t len)
+static ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
+                                const char *buf, size_t len)
 {
        struct lustre_attr *a = container_of(attr, struct lustre_attr, attr);
 
        return a->store ? a->store(kobj, attr, buf, len) : len;
 }
-EXPORT_SYMBOL_GPL(lustre_attr_store);
 
 const struct sysfs_ops lustre_sysfs_ops = {
        .show  = lustre_attr_show,
index 8e472327c880e3201992b3995456785227bcf4f6..0193608a930adc6c95ad03b505e84f445dc42760 100644 (file)
@@ -59,6 +59,7 @@
 #include <linux/list.h>
 
 static void lu_object_free(const struct lu_env *env, struct lu_object *o);
+static __u32 ls_stats_read(struct lprocfs_stats *stats, int idx);
 
 /**
  * Decrease reference counter on object. If last reference is freed, return
@@ -113,8 +114,6 @@ void lu_object_put(const struct lu_env *env, struct lu_object *o)
                return;
        }
 
-       LASSERT(bkt->lsb_busy > 0);
-       bkt->lsb_busy--;
        /*
         * When last reference is released, iterate over object
         * layers, and notify them that object is no longer busy.
@@ -127,6 +126,10 @@ void lu_object_put(const struct lu_env *env, struct lu_object *o)
        if (!lu_object_is_dying(top)) {
                LASSERT(list_empty(&top->loh_lru));
                list_add_tail(&top->loh_lru, &bkt->lsb_lru);
+               bkt->lsb_lru_len++;
+               lprocfs_counter_incr(site->ls_stats, LU_SS_LRU_LEN);
+               CDEBUG(D_INODE, "Add %p to site lru. hash: %p, bkt: %p, lru_len: %ld\n",
+                      o, site->ls_obj_hash, bkt, bkt->lsb_lru_len);
                cfs_hash_bd_unlock(site->ls_obj_hash, &bd, 1);
                return;
        }
@@ -153,17 +156,6 @@ void lu_object_put(const struct lu_env *env, struct lu_object *o)
 }
 EXPORT_SYMBOL(lu_object_put);
 
-/**
- * Put object and don't keep in cache. This is temporary solution for
- * multi-site objects when its layering is not constant.
- */
-void lu_object_put_nocache(const struct lu_env *env, struct lu_object *o)
-{
-       set_bit(LU_OBJECT_HEARD_BANSHEE, &o->lo_header->loh_flags);
-       return lu_object_put(env, o);
-}
-EXPORT_SYMBOL(lu_object_put_nocache);
-
 /**
  * Kill the object and take it out of LRU cache.
  * Currently used by client code for layout change.
@@ -175,11 +167,19 @@ void lu_object_unhash(const struct lu_env *env, struct lu_object *o)
        top = o->lo_header;
        set_bit(LU_OBJECT_HEARD_BANSHEE, &top->loh_flags);
        if (!test_and_set_bit(LU_OBJECT_UNHASHED, &top->loh_flags)) {
-               struct cfs_hash *obj_hash = o->lo_dev->ld_site->ls_obj_hash;
+               struct lu_site *site = o->lo_dev->ld_site;
+               struct cfs_hash *obj_hash = site->ls_obj_hash;
                struct cfs_hash_bd bd;
 
                cfs_hash_bd_get_and_lock(obj_hash, &top->loh_fid, &bd, 1);
-               list_del_init(&top->loh_lru);
+               if (!list_empty(&top->loh_lru)) {
+                       struct lu_site_bkt_data *bkt;
+
+                       list_del_init(&top->loh_lru);
+                       bkt = cfs_hash_bd_extra_get(obj_hash, &bd);
+                       bkt->lsb_lru_len--;
+                       lprocfs_counter_decr(site->ls_stats, LU_SS_LRU_LEN);
+               }
                cfs_hash_bd_del_locked(obj_hash, &bd, &top->loh_hash);
                cfs_hash_bd_unlock(obj_hash, &bd, 1);
        }
@@ -349,6 +349,8 @@ int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr)
                        cfs_hash_bd_del_locked(s->ls_obj_hash,
                                               &bd2, &h->loh_hash);
                        list_move(&h->loh_lru, &dispose);
+                       bkt->lsb_lru_len--;
+                       lprocfs_counter_decr(s->ls_stats, LU_SS_LRU_LEN);
                        if (did_sth == 0)
                                did_sth = 1;
 
@@ -427,7 +429,7 @@ LU_KEY_INIT_FINI(lu_global, struct lu_cdebug_data);
  * Key, holding temporary buffer. This key is registered very early by
  * lu_global_init().
  */
-struct lu_context_key lu_global_key = {
+static struct lu_context_key lu_global_key = {
        .lct_tags = LCT_MD_THREAD | LCT_DT_THREAD |
                    LCT_MG_THREAD | LCT_CL_THREAD | LCT_LOCAL,
        .lct_init = lu_global_key_init,
@@ -516,23 +518,6 @@ void lu_object_print(const struct lu_env *env, void *cookie,
 }
 EXPORT_SYMBOL(lu_object_print);
 
-/**
- * Check object consistency.
- */
-int lu_object_invariant(const struct lu_object *o)
-{
-       struct lu_object_header *top;
-
-       top = o->lo_header;
-       list_for_each_entry(o, &top->loh_layers, lo_linkage) {
-               if (o->lo_ops->loo_object_invariant != NULL &&
-                   !o->lo_ops->loo_object_invariant(o))
-                       return 0;
-       }
-       return 1;
-}
-EXPORT_SYMBOL(lu_object_invariant);
-
 static struct lu_object *htable_lookup(struct lu_site *s,
                                       struct cfs_hash_bd *bd,
                                       const struct lu_fid *f,
@@ -561,7 +546,11 @@ static struct lu_object *htable_lookup(struct lu_site *s,
        if (likely(!lu_object_is_dying(h))) {
                cfs_hash_get(s->ls_obj_hash, hnode);
                lprocfs_counter_incr(s->ls_stats, LU_SS_CACHE_HIT);
-               list_del_init(&h->loh_lru);
+               if (!list_empty(&h->loh_lru)) {
+                       list_del_init(&h->loh_lru);
+                       bkt->lsb_lru_len--;
+                       lprocfs_counter_decr(s->ls_stats, LU_SS_LRU_LEN);
+               }
                return lu_object_top(h);
        }
 
@@ -583,13 +572,13 @@ static struct lu_object *htable_lookup(struct lu_site *s,
  * return it. Otherwise, create new object, insert it into cache and return
  * it. In any case, additional reference is acquired on the returned object.
  */
-struct lu_object *lu_object_find(const struct lu_env *env,
-                                struct lu_device *dev, const struct lu_fid *f,
-                                const struct lu_object_conf *conf)
+static struct lu_object *lu_object_find(const struct lu_env *env,
+                                       struct lu_device *dev,
+                                       const struct lu_fid *f,
+                                       const struct lu_object_conf *conf)
 {
        return lu_object_find_at(env, dev->ld_site->ls_top_dev, f, conf);
 }
-EXPORT_SYMBOL(lu_object_find);
 
 static struct lu_object *lu_object_new(const struct lu_env *env,
                                       struct lu_device *dev,
@@ -599,7 +588,6 @@ static struct lu_object *lu_object_new(const struct lu_env *env,
        struct lu_object        *o;
        struct cfs_hash       *hs;
        struct cfs_hash_bd          bd;
-       struct lu_site_bkt_data *bkt;
 
        o = lu_object_alloc(env, dev, f, conf);
        if (IS_ERR(o))
@@ -607,9 +595,7 @@ static struct lu_object *lu_object_new(const struct lu_env *env,
 
        hs = dev->ld_site->ls_obj_hash;
        cfs_hash_bd_get_and_lock(hs, (void *)f, &bd, 1);
-       bkt = cfs_hash_bd_extra_get(hs, &bd);
        cfs_hash_bd_add_locked(hs, &bd, &o->lo_header->loh_hash);
-       bkt->lsb_busy++;
        cfs_hash_bd_unlock(hs, &bd, 1);
        return o;
 }
@@ -675,11 +661,7 @@ static struct lu_object *lu_object_find_try(const struct lu_env *env,
 
        shadow = htable_lookup(s, &bd, f, waiter, &version);
        if (likely(PTR_ERR(shadow) == -ENOENT)) {
-               struct lu_site_bkt_data *bkt;
-
-               bkt = cfs_hash_bd_extra_get(hs, &bd);
                cfs_hash_bd_add_locked(hs, &bd, &o->lo_header->loh_hash);
-               bkt->lsb_busy++;
                cfs_hash_bd_unlock(hs, &bd, 1);
                return o;
        }
@@ -926,14 +908,7 @@ static void lu_obj_hop_get(struct cfs_hash *hs, struct hlist_node *hnode)
        struct lu_object_header *h;
 
        h = hlist_entry(hnode, struct lu_object_header, loh_hash);
-       if (atomic_add_return(1, &h->loh_ref) == 1) {
-               struct lu_site_bkt_data *bkt;
-               struct cfs_hash_bd          bd;
-
-               cfs_hash_bd_get(hs, &h->loh_fid, &bd);
-               bkt = cfs_hash_bd_extra_get(hs, &bd);
-               bkt->lsb_busy++;
-       }
+       atomic_inc(&h->loh_ref);
 }
 
 static void lu_obj_hop_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
@@ -941,31 +916,22 @@ static void lu_obj_hop_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
        LBUG(); /* we should never called it */
 }
 
-cfs_hash_ops_t lu_site_hash_ops = {
+struct cfs_hash_ops lu_site_hash_ops = {
        .hs_hash        = lu_obj_hop_hash,
-       .hs_key  = lu_obj_hop_key,
+       .hs_key         = lu_obj_hop_key,
        .hs_keycmp      = lu_obj_hop_keycmp,
        .hs_object      = lu_obj_hop_object,
-       .hs_get  = lu_obj_hop_get,
+       .hs_get         = lu_obj_hop_get,
        .hs_put_locked  = lu_obj_hop_put_locked,
 };
 
-void lu_dev_add_linkage(struct lu_site *s, struct lu_device *d)
+static void lu_dev_add_linkage(struct lu_site *s, struct lu_device *d)
 {
        spin_lock(&s->ls_ld_lock);
        if (list_empty(&d->ld_linkage))
                list_add(&d->ld_linkage, &s->ls_ld_linkage);
        spin_unlock(&s->ls_ld_lock);
 }
-EXPORT_SYMBOL(lu_dev_add_linkage);
-
-void lu_dev_del_linkage(struct lu_site *s, struct lu_device *d)
-{
-       spin_lock(&s->ls_ld_lock);
-       list_del_init(&d->ld_linkage);
-       spin_unlock(&s->ls_ld_lock);
-}
-EXPORT_SYMBOL(lu_dev_del_linkage);
 
 /**
  * Initialize site \a s, with \a d as the top level device.
@@ -1034,6 +1000,12 @@ int lu_site_init(struct lu_site *s, struct lu_device *top)
                             0, "cache_death_race", "cache_death_race");
        lprocfs_counter_init(s->ls_stats, LU_SS_LRU_PURGED,
                             0, "lru_purged", "lru_purged");
+       /*
+        * Unlike other counters, lru_len can be decremented so
+        * need lc_sum instead of just lc_count
+        */
+       lprocfs_counter_init(s->ls_stats, LU_SS_LRU_LEN,
+                            LPROCFS_CNTR_AVGMINMAX, "lru_len", "lru_len");
 
        INIT_LIST_HEAD(&s->ls_linkage);
        s->ls_top_dev = top;
@@ -1082,6 +1054,7 @@ EXPORT_SYMBOL(lu_site_fini);
 int lu_site_init_finish(struct lu_site *s)
 {
        int result;
+
        mutex_lock(&lu_sites_guard);
        result = lu_context_refill(&lu_shrink_env.le_ctx);
        if (result == 0)
@@ -1252,8 +1225,6 @@ struct lu_object *lu_object_locate(struct lu_object_header *h,
 }
 EXPORT_SYMBOL(lu_object_locate);
 
-
-
 /**
  * Finalize and free devices in the device stack.
  *
@@ -1689,44 +1660,8 @@ EXPORT_SYMBOL(lu_context_refill);
  * predefined when the lu_device type are registered, during the module probe
  * phase.
  */
-__u32 lu_context_tags_default = 0;
-__u32 lu_session_tags_default = 0;
-
-void lu_context_tags_update(__u32 tags)
-{
-       spin_lock(&lu_keys_guard);
-       lu_context_tags_default |= tags;
-       key_set_version++;
-       spin_unlock(&lu_keys_guard);
-}
-EXPORT_SYMBOL(lu_context_tags_update);
-
-void lu_context_tags_clear(__u32 tags)
-{
-       spin_lock(&lu_keys_guard);
-       lu_context_tags_default &= ~tags;
-       key_set_version++;
-       spin_unlock(&lu_keys_guard);
-}
-EXPORT_SYMBOL(lu_context_tags_clear);
-
-void lu_session_tags_update(__u32 tags)
-{
-       spin_lock(&lu_keys_guard);
-       lu_session_tags_default |= tags;
-       key_set_version++;
-       spin_unlock(&lu_keys_guard);
-}
-EXPORT_SYMBOL(lu_session_tags_update);
-
-void lu_session_tags_clear(__u32 tags)
-{
-       spin_lock(&lu_keys_guard);
-       lu_session_tags_default &= ~tags;
-       key_set_version++;
-       spin_unlock(&lu_keys_guard);
-}
-EXPORT_SYMBOL(lu_session_tags_clear);
+__u32 lu_context_tags_default;
+__u32 lu_session_tags_default;
 
 int lu_env_init(struct lu_env *env, __u32 tags)
 {
@@ -1759,40 +1694,15 @@ int lu_env_refill(struct lu_env *env)
 }
 EXPORT_SYMBOL(lu_env_refill);
 
-/**
- * Currently, this API will only be used by echo client.
- * Because echo client and normal lustre client will share
- * same cl_env cache. So echo client needs to refresh
- * the env context after it get one from the cache, especially
- * when normal client and echo client co-exist in the same client.
- */
-int lu_env_refill_by_tags(struct lu_env *env, __u32 ctags,
-                         __u32 stags)
-{
-       if ((env->le_ctx.lc_tags & ctags) != ctags) {
-               env->le_ctx.lc_version = 0;
-               env->le_ctx.lc_tags |= ctags;
-       }
-
-       if (env->le_ses && (env->le_ses->lc_tags & stags) != stags) {
-               env->le_ses->lc_version = 0;
-               env->le_ses->lc_tags |= stags;
-       }
-
-       return lu_env_refill(env);
-}
-EXPORT_SYMBOL(lu_env_refill_by_tags);
-
-
-typedef struct lu_site_stats{
+struct lu_site_stats {
        unsigned        lss_populated;
        unsigned        lss_max_search;
        unsigned        lss_total;
        unsigned        lss_busy;
-} lu_site_stats_t;
+};
 
 static void lu_site_stats_get(struct cfs_hash *hs,
-                             lu_site_stats_t *stats, int populated)
+                             struct lu_site_stats *stats, int populated)
 {
        struct cfs_hash_bd bd;
        int        i;
@@ -1802,7 +1712,8 @@ static void lu_site_stats_get(struct cfs_hash *hs,
                struct hlist_head       *hhead;
 
                cfs_hash_bd_lock(hs, &bd, 1);
-               stats->lss_busy  += bkt->lsb_busy;
+               stats->lss_busy  +=
+                       cfs_hash_bd_count_get(&bd) - bkt->lsb_lru_len;
                stats->lss_total += cfs_hash_bd_count_get(&bd);
                stats->lss_max_search = max((int)stats->lss_max_search,
                                            cfs_hash_bd_depmax_get(&bd));
@@ -1819,29 +1730,22 @@ static void lu_site_stats_get(struct cfs_hash *hs,
        }
 }
 
-
 /*
- * There exists a potential lock inversion deadlock scenario when using
- * Lustre on top of ZFS. This occurs between one of ZFS's
- * buf_hash_table.ht_lock's, and Lustre's lu_sites_guard lock. Essentially,
- * thread A will take the lu_sites_guard lock and sleep on the ht_lock,
- * while thread B will take the ht_lock and sleep on the lu_sites_guard
- * lock. Obviously neither thread will wake and drop their respective hold
- * on their lock.
+ * lu_cache_shrink_count returns the number of cached objects that are
+ * candidates to be freed by shrink_slab(). A counter, which tracks
+ * the number of items in the site's lru, is maintained in the per cpu
+ * stats of each site. The counter is incremented when an object is added
+ * to a site's lru and decremented when one is removed. The number of
+ * free-able objects is the sum of all per cpu counters for all sites.
  *
- * To prevent this from happening we must ensure the lu_sites_guard lock is
- * not taken while down this code path. ZFS reliably does not set the
- * __GFP_FS bit in its code paths, so this can be used to determine if it
- * is safe to take the lu_sites_guard lock.
- *
- * Ideally we should accurately return the remaining number of cached
- * objects without taking the  lu_sites_guard lock, but this is not
- * possible in the current implementation.
+ * Using a per cpu counter is a compromise solution to concurrent access:
+ * lu_object_put() can update the counter without locking the site and
+ * lu_cache_shrink_count can sum the counters without locking each
+ * ls_obj_hash bucket.
  */
 static unsigned long lu_cache_shrink_count(struct shrinker *sk,
                                           struct shrink_control *sc)
 {
-       lu_site_stats_t stats;
        struct lu_site *s;
        struct lu_site *tmp;
        unsigned long cached = 0;
@@ -1851,14 +1755,14 @@ static unsigned long lu_cache_shrink_count(struct shrinker *sk,
 
        mutex_lock(&lu_sites_guard);
        list_for_each_entry_safe(s, tmp, &lu_sites, ls_linkage) {
-               memset(&stats, 0, sizeof(stats));
-               lu_site_stats_get(s->ls_obj_hash, &stats, 0);
-               cached += stats.lss_total - stats.lss_busy;
+               cached += ls_stats_read(s->ls_stats, LU_SS_LRU_LEN);
        }
        mutex_unlock(&lu_sites_guard);
 
        cached = (cached / 100) * sysctl_vfs_cache_pressure;
-       CDEBUG(D_INODE, "%ld objects cached\n", cached);
+       CDEBUG(D_INODE, "%ld objects cached, cache pressure %d\n",
+              cached, sysctl_vfs_cache_pressure);
+
        return cached;
 }
 
@@ -1900,29 +1804,9 @@ static unsigned long lu_cache_shrink_scan(struct shrinker *sk,
        return sc->nr_to_scan - remain;
 }
 
-/*
- * Debugging stuff.
- */
-
-/**
- * Environment to be used in debugger, contains all tags.
- */
-struct lu_env lu_debugging_env;
-
 /**
  * Debugging printer function using printk().
  */
-int lu_printk_printer(const struct lu_env *env,
-                     void *unused, const char *format, ...)
-{
-       va_list args;
-
-       va_start(args, format);
-       vprintk(format, args);
-       va_end(args);
-       return 0;
-}
-
 static struct shrinker lu_site_shrinker = {
        .count_objects  = lu_cache_shrink_count,
        .scan_objects   = lu_cache_shrink_scan,
@@ -1992,6 +1876,13 @@ static __u32 ls_stats_read(struct lprocfs_stats *stats, int idx)
        struct lprocfs_counter ret;
 
        lprocfs_stats_collect(stats, idx, &ret);
+       if (idx == LU_SS_LRU_LEN)
+               /*
+                * protect against counter on cpu A being decremented
+                * before counter is incremented on cpu B; unlikely
+                */
+               return (__u32)((ret.lc_sum > 0) ? ret.lc_sum : 0);
+
        return (__u32)ret.lc_count;
 }
 
@@ -2001,12 +1892,12 @@ static __u32 ls_stats_read(struct lprocfs_stats *stats, int idx)
  */
 int lu_site_stats_print(const struct lu_site *s, struct seq_file *m)
 {
-       lu_site_stats_t stats;
+       struct lu_site_stats stats;
 
        memset(&stats, 0, sizeof(stats));
        lu_site_stats_get(s->ls_obj_hash, &stats, 1);
 
-       seq_printf(m, "%d/%d %d/%d %d %d %d %d %d %d %d\n",
+       seq_printf(m, "%d/%d %d/%d %d %d %d %d %d %d %d %d\n",
                   stats.lss_busy,
                   stats.lss_total,
                   stats.lss_populated,
@@ -2017,7 +1908,8 @@ int lu_site_stats_print(const struct lu_site *s, struct seq_file *m)
                   ls_stats_read(s->ls_stats, LU_SS_CACHE_MISS),
                   ls_stats_read(s->ls_stats, LU_SS_CACHE_RACE),
                   ls_stats_read(s->ls_stats, LU_SS_CACHE_DEATH_RACE),
-                  ls_stats_read(s->ls_stats, LU_SS_LRU_PURGED));
+                  ls_stats_read(s->ls_stats, LU_SS_LRU_PURGED),
+                  ls_stats_read(s->ls_stats, LU_SS_LRU_LEN));
        return 0;
 }
 EXPORT_SYMBOL(lu_site_stats_print);
@@ -2052,137 +1944,8 @@ EXPORT_SYMBOL(lu_kmem_init);
 void lu_kmem_fini(struct lu_kmem_descr *caches)
 {
        for (; caches->ckd_cache != NULL; ++caches) {
-               if (*caches->ckd_cache != NULL) {
-                       kmem_cache_destroy(*caches->ckd_cache);
-                       *caches->ckd_cache = NULL;
-               }
+               kmem_cache_destroy(*caches->ckd_cache);
+               *caches->ckd_cache = NULL;
        }
 }
 EXPORT_SYMBOL(lu_kmem_fini);
-
-/**
- * Temporary solution to be able to assign fid in ->do_create()
- * till we have fully-functional OST fids
- */
-void lu_object_assign_fid(const struct lu_env *env, struct lu_object *o,
-                         const struct lu_fid *fid)
-{
-       struct lu_site          *s = o->lo_dev->ld_site;
-       struct lu_fid           *old = &o->lo_header->loh_fid;
-       struct lu_site_bkt_data *bkt;
-       struct lu_object        *shadow;
-       wait_queue_t             waiter;
-       struct cfs_hash         *hs;
-       struct cfs_hash_bd       bd;
-       __u64                    version = 0;
-
-       LASSERT(fid_is_zero(old));
-
-       hs = s->ls_obj_hash;
-       cfs_hash_bd_get_and_lock(hs, (void *)fid, &bd, 1);
-       shadow = htable_lookup(s, &bd, fid, &waiter, &version);
-       /* supposed to be unique */
-       LASSERT(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT);
-       *old = *fid;
-       bkt = cfs_hash_bd_extra_get(hs, &bd);
-       cfs_hash_bd_add_locked(hs, &bd, &o->lo_header->loh_hash);
-       bkt->lsb_busy++;
-       cfs_hash_bd_unlock(hs, &bd, 1);
-}
-EXPORT_SYMBOL(lu_object_assign_fid);
-
-/**
- * allocates object with 0 (non-assigned) fid
- * XXX: temporary solution to be able to assign fid in ->do_create()
- *      till we have fully-functional OST fids
- */
-struct lu_object *lu_object_anon(const struct lu_env *env,
-                                struct lu_device *dev,
-                                const struct lu_object_conf *conf)
-{
-       struct lu_fid     fid;
-       struct lu_object *o;
-
-       fid_zero(&fid);
-       o = lu_object_alloc(env, dev, &fid, conf);
-
-       return o;
-}
-EXPORT_SYMBOL(lu_object_anon);
-
-struct lu_buf LU_BUF_NULL = {
-       .lb_buf = NULL,
-       .lb_len = 0
-};
-EXPORT_SYMBOL(LU_BUF_NULL);
-
-void lu_buf_free(struct lu_buf *buf)
-{
-       LASSERT(buf);
-       if (buf->lb_buf) {
-               LASSERT(buf->lb_len > 0);
-               kvfree(buf->lb_buf);
-               buf->lb_buf = NULL;
-               buf->lb_len = 0;
-       }
-}
-EXPORT_SYMBOL(lu_buf_free);
-
-void lu_buf_alloc(struct lu_buf *buf, int size)
-{
-       LASSERT(buf);
-       LASSERT(buf->lb_buf == NULL);
-       LASSERT(buf->lb_len == 0);
-       buf->lb_buf = libcfs_kvzalloc(size, GFP_NOFS);
-       if (likely(buf->lb_buf))
-               buf->lb_len = size;
-}
-EXPORT_SYMBOL(lu_buf_alloc);
-
-void lu_buf_realloc(struct lu_buf *buf, int size)
-{
-       lu_buf_free(buf);
-       lu_buf_alloc(buf, size);
-}
-EXPORT_SYMBOL(lu_buf_realloc);
-
-struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, int len)
-{
-       if (buf->lb_buf == NULL && buf->lb_len == 0)
-               lu_buf_alloc(buf, len);
-
-       if ((len > buf->lb_len) && (buf->lb_buf != NULL))
-               lu_buf_realloc(buf, len);
-
-       return buf;
-}
-EXPORT_SYMBOL(lu_buf_check_and_alloc);
-
-/**
- * Increase the size of the \a buf.
- * preserves old data in buffer
- * old buffer remains unchanged on error
- * \retval 0 or -ENOMEM
- */
-int lu_buf_check_and_grow(struct lu_buf *buf, int len)
-{
-       char *ptr;
-
-       if (len <= buf->lb_len)
-               return 0;
-
-       ptr = libcfs_kvzalloc(len, GFP_NOFS);
-       if (ptr == NULL)
-               return -ENOMEM;
-
-       /* Free the old buf */
-       if (buf->lb_buf != NULL) {
-               memcpy(ptr, buf->lb_buf, buf->lb_len);
-               kvfree(buf->lb_buf);
-       }
-
-       buf->lb_buf = ptr;
-       buf->lb_len = len;
-       return 0;
-}
-EXPORT_SYMBOL(lu_buf_check_and_grow);
index 35a94a8f4fd36df0af07936f213de805641d7692..fb9147cc607f19c0cdaaab7c9e6dc7dfb435986d 100644 (file)
@@ -44,7 +44,6 @@
 #include "../include/lustre_handles.h"
 #include "../include/lustre_lib.h"
 
-
 static __u64 handle_base;
 #define HANDLE_INCR 7
 static spinlock_t handle_base_lock;
@@ -126,6 +125,7 @@ static void class_handle_unhash_nolock(struct portals_handle *h)
 void class_handle_unhash(struct portals_handle *h)
 {
        struct handle_bucket *bucket;
+
        bucket = handle_hash + (h->h_cookie & HANDLE_HASH_MASK);
 
        spin_lock(&bucket->lock);
@@ -134,19 +134,6 @@ void class_handle_unhash(struct portals_handle *h)
 }
 EXPORT_SYMBOL(class_handle_unhash);
 
-void class_handle_hash_back(struct portals_handle *h)
-{
-       struct handle_bucket *bucket;
-
-       bucket = handle_hash + (h->h_cookie & HANDLE_HASH_MASK);
-
-       spin_lock(&bucket->lock);
-       list_add_rcu(&h->h_link, &bucket->head);
-       h->h_in = 1;
-       spin_unlock(&bucket->lock);
-}
-EXPORT_SYMBOL(class_handle_hash_back);
-
 void *class_handle2object(__u64 cookie)
 {
        struct handle_bucket *bucket;
@@ -193,7 +180,7 @@ EXPORT_SYMBOL(class_handle_free_cb);
 int class_handle_init(void)
 {
        struct handle_bucket *bucket;
-       struct timeval tv;
+       struct timespec64 ts;
        int seed[2];
 
        LASSERT(handle_hash == NULL);
@@ -212,8 +199,8 @@ int class_handle_init(void)
 
        /** bug 21430: add randomness to the initial base */
        cfs_get_random_bytes(seed, sizeof(seed));
-       do_gettimeofday(&tv);
-       cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
+       ktime_get_ts64(&ts);
+       cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
 
        cfs_get_random_bytes(&handle_base, sizeof(handle_base));
        LASSERT(handle_base != 0ULL);
@@ -246,6 +233,7 @@ static int cleanup_all_handles(void)
 void class_handle_cleanup(void)
 {
        int count;
+
        LASSERT(handle_hash != NULL);
 
        count = cleanup_all_handles();
index 93805ac93c5a8e78f31189db7277ab329c705210..c231e0da0e2aeaf165f76de030db2e76aa3a298f 100644 (file)
@@ -47,8 +47,7 @@
 
 #include "llog_internal.h"
 
-static cfs_hash_ops_t uuid_hash_ops;
-static cfs_hash_ops_t nid_hash_ops;
+static struct cfs_hash_ops uuid_hash_ops;
 
 /*********** string parsing utils *********/
 
@@ -61,7 +60,7 @@ int class_find_param(char *buf, char *key, char **valp)
                return 1;
 
        ptr = strstr(buf, key);
-       if (ptr == NULL)
+       if (!ptr)
                return 1;
 
        if (valp)
@@ -71,117 +70,9 @@ int class_find_param(char *buf, char *key, char **valp)
 }
 EXPORT_SYMBOL(class_find_param);
 
-/**
- * Check whether the proc parameter \a param is an old parameter or not from
- * the array \a ptr which contains the mapping from old parameters to new ones.
- * If it's an old one, then return the pointer to the cfg_interop_param struc-
- * ture which contains both the old and new parameters.
- *
- * \param param                        proc parameter
- * \param ptr                  an array which contains the mapping from
- *                             old parameters to new ones
- *
- * \retval valid-pointer       pointer to the cfg_interop_param structure
- *                             which contains the old and new parameters
- * \retval NULL                        \a param or \a ptr is NULL,
- *                             or \a param is not an old parameter
- */
-struct cfg_interop_param *class_find_old_param(const char *param,
-                                              struct cfg_interop_param *ptr)
-{
-       char *value = NULL;
-       int   name_len = 0;
-
-       if (param == NULL || ptr == NULL)
-               return NULL;
-
-       value = strchr(param, '=');
-       if (value == NULL)
-               name_len = strlen(param);
-       else
-               name_len = value - param;
-
-       while (ptr->old_param != NULL) {
-               if (strncmp(param, ptr->old_param, name_len) == 0 &&
-                   name_len == strlen(ptr->old_param))
-                       return ptr;
-               ptr++;
-       }
-
-       return NULL;
-}
-EXPORT_SYMBOL(class_find_old_param);
-
-/**
- * Finds a parameter in \a params and copies it to \a copy.
- *
- * Leading spaces are skipped. Next space or end of string is the
- * parameter terminator with the exception that spaces inside single or double
- * quotes get included into a parameter. The parameter is copied into \a copy
- * which has to be allocated big enough by a caller, quotes are stripped in
- * the copy and the copy is terminated by 0.
- *
- * On return \a params is set to next parameter or to NULL if last
- * parameter is returned.
- *
- * \retval 0 if parameter is returned in \a copy
- * \retval 1 otherwise
- * \retval -EINVAL if unbalanced quota is found
- */
-int class_get_next_param(char **params, char *copy)
-{
-       char *q1, *q2, *str;
-       int len;
-
-       str = *params;
-       while (*str == ' ')
-               str++;
-
-       if (*str == '\0') {
-               *params = NULL;
-               return 1;
-       }
-
-       while (1) {
-               q1 = strpbrk(str, " '\"");
-               if (q1 == NULL) {
-                       len = strlen(str);
-                       memcpy(copy, str, len);
-                       copy[len] = '\0';
-                       *params = NULL;
-                       return 0;
-               }
-               len = q1 - str;
-               if (*q1 == ' ') {
-                       memcpy(copy, str, len);
-                       copy[len] = '\0';
-                       *params = str + len;
-                       return 0;
-               }
-
-               memcpy(copy, str, len);
-               copy += len;
-
-               /* search for the matching closing quote */
-               str = q1 + 1;
-               q2 = strchr(str, *q1);
-               if (q2 == NULL) {
-                       CERROR("Unbalanced quota in parameters: \"%s\"\n",
-                              *params);
-                       return -EINVAL;
-               }
-               len = q2 - str;
-               memcpy(copy, str, len);
-               copy += len;
-               str = q2 + 1;
-       }
-       return 1;
-}
-EXPORT_SYMBOL(class_get_next_param);
-
 /* returns 0 if this is the first key in the buffer, else 1.
    valp points to first char after key. */
-int class_match_param(char *buf, char *key, char **valp)
+static int class_match_param(char *buf, char *key, char **valp)
 {
        if (!buf)
                return 1;
@@ -194,11 +85,10 @@ int class_match_param(char *buf, char *key, char **valp)
 
        return 0;
 }
-EXPORT_SYMBOL(class_match_param);
 
 static int parse_nid(char *buf, void *value, int quiet)
 {
-       lnet_nid_t *nid = (lnet_nid_t *)value;
+       lnet_nid_t *nid = value;
 
        *nid = libcfs_str2nid(buf);
        if (*nid != LNET_NID_ANY)
@@ -211,7 +101,7 @@ static int parse_nid(char *buf, void *value, int quiet)
 
 static int parse_net(char *buf, void *value)
 {
-       __u32 *net = (__u32 *)value;
+       __u32 *net = value;
 
        *net = libcfs_str2net(buf);
        CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net));
@@ -243,7 +133,7 @@ static int class_parse_value(char *buf, int opc, void *value, char **endh,
 
        /* nid separators or end of nids */
        endp = strpbrk(buf, ",: /");
-       if (endp == NULL)
+       if (!endp)
                endp = buf + strlen(buf);
 
        tmp = *endp;
@@ -278,59 +168,13 @@ int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh)
 }
 EXPORT_SYMBOL(class_parse_nid_quiet);
 
-int class_parse_net(char *buf, __u32 *net, char **endh)
-{
-       return class_parse_value(buf, CLASS_PARSE_NET, (void *)net, endh, 0);
-}
-EXPORT_SYMBOL(class_parse_net);
-
-/* 1 param contains key and match
- * 0 param contains key and not match
- * -1 param does not contain key
- */
-int class_match_nid(char *buf, char *key, lnet_nid_t nid)
-{
-       lnet_nid_t tmp;
-       int   rc = -1;
-
-       while (class_find_param(buf, key, &buf) == 0) {
-               /* please restrict to the nids pertaining to
-                * the specified nids */
-               while (class_parse_nid(buf, &tmp, &buf) == 0) {
-                       if (tmp == nid)
-                               return 1;
-               }
-               rc = 0;
-       }
-       return rc;
-}
-EXPORT_SYMBOL(class_match_nid);
-
-int class_match_net(char *buf, char *key, __u32 net)
-{
-       __u32 tmp;
-       int   rc = -1;
-
-       while (class_find_param(buf, key, &buf) == 0) {
-               /* please restrict to the nids pertaining to
-                * the specified networks */
-               while (class_parse_net(buf, &tmp, &buf) == 0) {
-                       if (tmp == net)
-                               return 1;
-               }
-               rc = 0;
-       }
-       return rc;
-}
-EXPORT_SYMBOL(class_match_net);
-
 /********************** class fns **********************/
 
 /**
  * Create a new obd device and set the type, name and uuid.  If successful,
  * the new device can be accessed by either name or uuid.
  */
-int class_attach(struct lustre_cfg *lcfg)
+static int class_attach(struct lustre_cfg *lcfg)
 {
        struct obd_device *obd = NULL;
        char *typename, *name, *uuid;
@@ -381,7 +225,6 @@ int class_attach(struct lustre_cfg *lcfg)
        INIT_LIST_HEAD(&obd->obd_exports);
        INIT_LIST_HEAD(&obd->obd_unlinked_exports);
        INIT_LIST_HEAD(&obd->obd_delayed_exports);
-       INIT_LIST_HEAD(&obd->obd_exports_timed);
        spin_lock_init(&obd->obd_nid_lock);
        spin_lock_init(&obd->obd_dev_lock);
        mutex_init(&obd->obd_dev_mutex);
@@ -393,14 +236,7 @@ int class_attach(struct lustre_cfg *lcfg)
        /* XXX belongs in setup not attach  */
        init_rwsem(&obd->obd_observer_link_sem);
        /* recovery data */
-       cfs_init_timer(&obd->obd_recovery_timer);
-       spin_lock_init(&obd->obd_recovery_task_lock);
-       init_waitqueue_head(&obd->obd_next_transno_waitq);
        init_waitqueue_head(&obd->obd_evict_inprogress_waitq);
-       INIT_LIST_HEAD(&obd->obd_req_replay_queue);
-       INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
-       INIT_LIST_HEAD(&obd->obd_final_req_queue);
-       INIT_LIST_HEAD(&obd->obd_evict_list);
 
        llog_group_init(&obd->obd_olg, FID_SEQ_LLOG);
 
@@ -441,12 +277,11 @@ int class_attach(struct lustre_cfg *lcfg)
        }
        return rc;
 }
-EXPORT_SYMBOL(class_attach);
 
 /** Create hashes, self-export, and call type-specific setup.
  * Setup is effectively the "start this obd" call.
  */
-int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
+static int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
        int err = 0;
        struct obd_export *exp;
@@ -483,7 +318,6 @@ int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
           other fns check that status, and we're not actually set up yet. */
        obd->obd_starting = 1;
        obd->obd_uuid_hash = NULL;
-       obd->obd_nid_hash = NULL;
        spin_unlock(&obd->obd_dev_lock);
 
        /* create an uuid-export lustre hash */
@@ -499,19 +333,6 @@ int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                goto err_hash;
        }
 
-       /* create a nid-export lustre hash */
-       obd->obd_nid_hash = cfs_hash_create("NID_HASH",
-                                           HASH_NID_CUR_BITS,
-                                           HASH_NID_MAX_BITS,
-                                           HASH_NID_BKT_BITS, 0,
-                                           CFS_HASH_MIN_THETA,
-                                           CFS_HASH_MAX_THETA,
-                                           &nid_hash_ops, CFS_HASH_DEFAULT);
-       if (!obd->obd_nid_hash) {
-               err = -ENOMEM;
-               goto err_hash;
-       }
-
        exp = class_new_export(obd, &obd->obd_uuid);
        if (IS_ERR(exp)) {
                err = PTR_ERR(exp);
@@ -519,7 +340,6 @@ int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
        }
 
        obd->obd_self_export = exp;
-       list_del_init(&exp->exp_obd_chain_timed);
        class_export_put(exp);
 
        err = obd_setup(obd, lcfg);
@@ -547,20 +367,15 @@ err_hash:
                cfs_hash_putref(obd->obd_uuid_hash);
                obd->obd_uuid_hash = NULL;
        }
-       if (obd->obd_nid_hash) {
-               cfs_hash_putref(obd->obd_nid_hash);
-               obd->obd_nid_hash = NULL;
-       }
        obd->obd_starting = 0;
        CERROR("setup %s failed (%d)\n", obd->obd_name, err);
        return err;
 }
-EXPORT_SYMBOL(class_setup);
 
 /** We have finished using this obd and are ready to destroy it.
  * There can be no more references to this obd.
  */
-int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
+static int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
        if (obd->obd_set_up) {
                CERROR("OBD device %d still set up\n", obd->obd_minor);
@@ -582,13 +397,12 @@ int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
        class_decref(obd, "attach", obd);
        return 0;
 }
-EXPORT_SYMBOL(class_detach);
 
 /** Start shutting down the obd.  There may be in-progress ops when
  * this is called.  We tell them to start shutting down with a call
  * to class_disconnect_exports().
  */
-int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
+static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
        int err = 0;
        char *flag;
@@ -644,18 +458,6 @@ int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
 
        LASSERT(obd->obd_self_export);
 
-       /* The three references that should be remaining are the
-        * obd_self_export and the attach and setup references. */
-       if (atomic_read(&obd->obd_refcount) > 3) {
-               /* refcount - 3 might be the number of real exports
-                  (excluding self export). But class_incref is called
-                  by other things as well, so don't count on it. */
-               CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
-                      obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
-               dump_exports(obd, 0);
-               class_disconnect_exports(obd);
-       }
-
        /* Precleanup, we must make sure all exports get destroyed. */
        err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
        if (err)
@@ -668,18 +470,11 @@ int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
                obd->obd_uuid_hash = NULL;
        }
 
-       /* destroy a nid-export hash body */
-       if (obd->obd_nid_hash) {
-               cfs_hash_putref(obd->obd_nid_hash);
-               obd->obd_nid_hash = NULL;
-       }
-
        class_decref(obd, "setup", obd);
        obd->obd_set_up = 0;
 
        return 0;
 }
-EXPORT_SYMBOL(class_cleanup);
 
 struct obd_device *class_incref(struct obd_device *obd,
                                const char *scope, const void *source)
@@ -743,7 +538,7 @@ EXPORT_SYMBOL(class_decref);
 /** Add a failover nid location.
  * Client obd types contact server obd types using this nid list.
  */
-int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
+static int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
        struct obd_import *imp;
        struct obd_uuid uuid;
@@ -774,11 +569,10 @@ int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
 
        return rc;
 }
-EXPORT_SYMBOL(class_add_conn);
 
 /** Remove a failover nid location.
  */
-int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
+static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
        struct obd_import *imp;
        struct obd_uuid uuid;
@@ -826,8 +620,8 @@ EXPORT_SYMBOL(class_get_profile);
  * This defines the mdc and osc names to use for a client.
  * This also is used to define the lov to be used by a mdt.
  */
-int class_add_profile(int proflen, char *prof, int osclen, char *osc,
-                     int mdclen, char *mdc)
+static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
+                            int mdclen, char *mdc)
 {
        struct lustre_profile *lprof;
        int err = 0;
@@ -841,14 +635,14 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
 
        LASSERT(proflen == (strlen(prof) + 1));
        lprof->lp_profile = kmemdup(prof, proflen, GFP_NOFS);
-       if (lprof->lp_profile == NULL) {
+       if (!lprof->lp_profile) {
                err = -ENOMEM;
                goto free_lprof;
        }
 
        LASSERT(osclen == (strlen(osc) + 1));
        lprof->lp_dt = kmemdup(osc, osclen, GFP_NOFS);
-       if (lprof->lp_dt == NULL) {
+       if (!lprof->lp_dt) {
                err = -ENOMEM;
                goto free_lp_profile;
        }
@@ -856,7 +650,7 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
        if (mdclen > 0) {
                LASSERT(mdclen == (strlen(mdc) + 1));
                lprof->lp_md = kmemdup(mdc, mdclen, GFP_NOFS);
-               if (lprof->lp_md == NULL) {
+               if (!lprof->lp_md) {
                        err = -ENOMEM;
                        goto free_lp_dt;
                }
@@ -928,11 +722,10 @@ static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
        return 0;
 }
 
-
 /* We can't call ll_process_config or lquota_process_config directly because
  * it lives in a module that must be loaded after this one. */
-static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
-static int (*quota_process_config)(struct lustre_cfg *lcfg) = NULL;
+static int (*client_process_config)(struct lustre_cfg *lcfg);
+static int (*quota_process_config)(struct lustre_cfg *lcfg);
 
 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
 {
@@ -940,78 +733,6 @@ void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
 }
 EXPORT_SYMBOL(lustre_register_client_process_config);
 
-/**
- * Rename the proc parameter in \a cfg with a new name \a new_name.
- *
- * \param cfg     config structure which contains the proc parameter
- * \param new_name new name of the proc parameter
- *
- * \retval valid-pointer    pointer to the newly-allocated config structure
- *                         which contains the renamed proc parameter
- * \retval ERR_PTR(-EINVAL) if \a cfg or \a new_name is NULL, or \a cfg does
- *                         not contain a proc parameter
- * \retval ERR_PTR(-ENOMEM) if memory allocation failure occurs
- */
-struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
-                                    const char *new_name)
-{
-       struct lustre_cfg_bufs  *bufs = NULL;
-       struct lustre_cfg       *new_cfg = NULL;
-       char                    *param = NULL;
-       char                    *new_param = NULL;
-       char                    *value = NULL;
-       int                      name_len = 0;
-       int                      new_len = 0;
-
-       if (cfg == NULL || new_name == NULL)
-               return ERR_PTR(-EINVAL);
-
-       param = lustre_cfg_string(cfg, 1);
-       if (param == NULL)
-               return ERR_PTR(-EINVAL);
-
-       value = strchr(param, '=');
-       if (value == NULL)
-               name_len = strlen(param);
-       else
-               name_len = value - param;
-
-       new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
-
-       new_param = kzalloc(new_len, GFP_NOFS);
-       if (!new_param)
-               return ERR_PTR(-ENOMEM);
-
-       strcpy(new_param, new_name);
-       if (value != NULL)
-               strcat(new_param, value);
-
-       bufs = kzalloc(sizeof(*bufs), GFP_NOFS);
-       if (!bufs) {
-               kfree(new_param);
-               return ERR_PTR(-ENOMEM);
-       }
-
-       lustre_cfg_bufs_reset(bufs, NULL);
-       lustre_cfg_bufs_init(bufs, cfg);
-       lustre_cfg_bufs_set_string(bufs, 1, new_param);
-
-       new_cfg = lustre_cfg_new(cfg->lcfg_command, bufs);
-
-       kfree(new_param);
-       kfree(bufs);
-       if (new_cfg == NULL)
-               return ERR_PTR(-ENOMEM);
-
-       new_cfg->lcfg_num = cfg->lcfg_num;
-       new_cfg->lcfg_flags = cfg->lcfg_flags;
-       new_cfg->lcfg_nid = cfg->lcfg_nid;
-       new_cfg->lcfg_nal = cfg->lcfg_nal;
-
-       return new_cfg;
-}
-EXPORT_SYMBOL(lustre_cfg_rename);
-
 static int process_param2_config(struct lustre_cfg *lcfg)
 {
        char *param = lustre_cfg_string(lcfg, 1);
@@ -1022,42 +743,35 @@ static int process_param2_config(struct lustre_cfg *lcfg)
                [2] = param,
                [3] = NULL
        };
-       struct timeval  start;
-       struct timeval  end;
+       ktime_t start;
+       ktime_t end;
        int             rc;
 
-
        /* Add upcall processing here. Now only lctl is supported */
        if (strcmp(upcall, LCTL_UPCALL) != 0) {
                CERROR("Unsupported upcall %s\n", upcall);
                return -EINVAL;
        }
 
-       do_gettimeofday(&start);
+       start = ktime_get();
        rc = call_usermodehelper(argv[0], argv, NULL, 1);
-       do_gettimeofday(&end);
+       end = ktime_get();
 
        if (rc < 0) {
                CERROR(
                       "lctl: error invoking upcall %s %s %s: rc = %d; time %ldus\n",
                       argv[0], argv[1], argv[2], rc,
-                      cfs_timeval_sub(&end, &start, NULL));
+                      (long)ktime_us_delta(end, start));
        } else {
                CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
                       argv[0], argv[1], argv[2],
-                      cfs_timeval_sub(&end, &start, NULL));
+                      (long)ktime_us_delta(end, start));
                       rc = 0;
        }
 
        return rc;
 }
 
-void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg))
-{
-       quota_process_config = qpc;
-}
-EXPORT_SYMBOL(lustre_register_quota_process_config);
-
 /** Process configuration commands given in lustre_cfg form.
  * These may come from direct calls (e.g. class_manual_cleanup)
  * or processing the config llog, or ioctl from lctl.
@@ -1135,6 +849,7 @@ int class_process_config(struct lustre_cfg *lcfg)
        }
        case LCFG_MARKER: {
                struct cfg_marker *marker;
+
                marker = lustre_cfg_buf(lcfg, 1);
                CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
                       marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
@@ -1178,7 +893,7 @@ int class_process_config(struct lustre_cfg *lcfg)
        }
        /* Commands that require a device */
        obd = class_name2obd(lustre_cfg_string(lcfg, 0));
-       if (obd == NULL) {
+       if (!obd) {
                if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
                        CERROR("this lcfg command requires a device name\n");
                else
@@ -1299,6 +1014,7 @@ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
                                rc = -EROFS;
                                if (var->fops && var->fops->write) {
                                        mm_segment_t oldfs;
+
                                        oldfs = get_fs();
                                        set_fs(KERNEL_DS);
                                        rc = (var->fops->write)(&fakefile, sval,
@@ -1354,8 +1070,6 @@ int class_config_llog_handler(const struct lu_env *env,
        char *cfg_buf = (char *) (rec + 1);
        int rc = 0;
 
-       //class_config_dump_handler(handle, rec, data);
-
        switch (rec->lrh_type) {
        case OBD_CFG_REC: {
                struct lustre_cfg *lcfg, *lcfg_new;
@@ -1377,6 +1091,7 @@ int class_config_llog_handler(const struct lu_env *env,
                /* Figure out config state info */
                if (lcfg->lcfg_command == LCFG_MARKER) {
                        struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
+
                        lustre_swab_cfg_marker(marker, swab,
                                               LUSTRE_CFG_BUFLEN(lcfg, 1));
                        CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
@@ -1439,7 +1154,6 @@ int class_config_llog_handler(const struct lu_env *env,
                        }
                }
 
-
                if (clli->cfg_flags & CFG_F_EXCLUDE) {
                        CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
                               lcfg->lcfg_command);
@@ -1451,18 +1165,17 @@ int class_config_llog_handler(const struct lu_env *env,
                lustre_cfg_bufs_init(&bufs, lcfg);
 
                if (clli && clli->cfg_instance &&
-                   LUSTRE_CFG_BUFLEN(lcfg, 0) > 0){
+                   LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
                        inst = 1;
                        inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
                                   sizeof(clli->cfg_instance) * 2 + 4;
-                       inst_name = kzalloc(inst_len, GFP_NOFS);
+                       inst_name = kasprintf(GFP_NOFS, "%s-%p",
+                                             lustre_cfg_string(lcfg, 0),
+                                             clli->cfg_instance);
                        if (!inst_name) {
                                rc = -ENOMEM;
                                goto out;
                        }
-                       sprintf(inst_name, "%s-%p",
-                               lustre_cfg_string(lcfg, 0),
-                               clli->cfg_instance);
                        lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
                        CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
                               lcfg->lcfg_command, inst_name);
@@ -1482,7 +1195,7 @@ int class_config_llog_handler(const struct lu_env *env,
                 * moving them to index [1] and [2], and insert MGC's
                 * obdname at index [0].
                 */
-               if (clli && clli->cfg_instance == NULL &&
+               if (clli && !clli->cfg_instance &&
                    lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
                        lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
                                            bufs.lcfg_buflen[1]);
@@ -1582,7 +1295,8 @@ EXPORT_SYMBOL(class_config_parse_llog);
  * This is separated from class_config_dump_handler() to use
  * for ioctl needs as well
  */
-int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
+static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf,
+                                 int size)
 {
        struct lustre_cfg       *lcfg = (struct lustre_cfg *)(rec + 1);
        char                    *ptr = buf;
@@ -1602,10 +1316,13 @@ int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
        if (lcfg->lcfg_num)
                ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
 
-       if (lcfg->lcfg_nid)
+       if (lcfg->lcfg_nid) {
+               char nidstr[LNET_NIDSTR_SIZE];
+
+               libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
                ptr += snprintf(ptr, end-ptr, "nid=%s(%#llx)\n     ",
-                               libcfs_nid2str(lcfg->lcfg_nid),
-                               lcfg->lcfg_nid);
+                               nidstr, lcfg->lcfg_nid);
+       }
 
        if (lcfg->lcfg_command == LCFG_MARKER) {
                struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
@@ -1649,31 +1366,6 @@ int class_config_dump_handler(const struct lu_env *env,
        return rc;
 }
 
-int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
-                          char *name, struct config_llog_instance *cfg)
-{
-       struct llog_handle      *llh;
-       int                      rc;
-
-       LCONSOLE_INFO("Dumping config log %s\n", name);
-
-       rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
-       if (rc)
-               return rc;
-
-       rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
-       if (rc)
-               goto parse_out;
-
-       rc = llog_process(env, llh, class_config_dump_handler, cfg, NULL);
-parse_out:
-       llog_close(env, llh);
-
-       LCONSOLE_INFO("End config log %s\n", name);
-       return rc;
-}
-EXPORT_SYMBOL(class_config_dump_llog);
-
 /** Call class_cleanup and class_detach.
  * "Manual" only in the sense that we're faking lcfg commands.
  */
@@ -1781,81 +1473,11 @@ uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
        class_export_put(exp);
 }
 
-static cfs_hash_ops_t uuid_hash_ops = {
+static struct cfs_hash_ops uuid_hash_ops = {
        .hs_hash        = uuid_hash,
-       .hs_key  = uuid_key,
+       .hs_key         = uuid_key,
        .hs_keycmp      = uuid_keycmp,
        .hs_object      = uuid_export_object,
-       .hs_get  = uuid_export_get,
+       .hs_get         = uuid_export_get,
        .hs_put_locked  = uuid_export_put_locked,
 };
-
-
-/*
- * nid<->export hash operations
- */
-
-static unsigned
-nid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
-{
-       return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
-}
-
-static void *
-nid_key(struct hlist_node *hnode)
-{
-       struct obd_export *exp;
-
-       exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
-
-       return &exp->exp_connection->c_peer.nid;
-}
-
-/*
- * NOTE: It is impossible to find an export that is in failed
- *       state with this function
- */
-static int
-nid_kepcmp(const void *key, struct hlist_node *hnode)
-{
-       struct obd_export *exp;
-
-       LASSERT(key);
-       exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
-
-       return exp->exp_connection->c_peer.nid == *(lnet_nid_t *)key &&
-              !exp->exp_failed;
-}
-
-static void *
-nid_export_object(struct hlist_node *hnode)
-{
-       return hlist_entry(hnode, struct obd_export, exp_nid_hash);
-}
-
-static void
-nid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct obd_export *exp;
-
-       exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
-       class_export_get(exp);
-}
-
-static void
-nid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
-{
-       struct obd_export *exp;
-
-       exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
-       class_export_put(exp);
-}
-
-static cfs_hash_ops_t nid_hash_ops = {
-       .hs_hash        = nid_hash,
-       .hs_key  = nid_key,
-       .hs_keycmp      = nid_kepcmp,
-       .hs_object      = nid_export_object,
-       .hs_get  = nid_export_get,
-       .hs_put_locked  = nid_export_put_locked,
-};
index 7c5bab377f5cc27b4dfb30f53b6fb7157b9a40df..48003d5325e3206a833ab1f37bdcba0fb9b14b82 100644 (file)
@@ -40,7 +40,6 @@
  * Author: Nathan Rutman <nathan@clusterfs.com>
  */
 
-
 #define DEBUG_SUBSYSTEM S_CLASS
 #define D_MOUNT (D_SUPER|D_CONFIG/*|D_WARNING */)
 #define PRINT_CMD CDEBUG
@@ -143,8 +142,8 @@ EXPORT_SYMBOL(lustre_end_log);
 /** lustre_cfg_bufs are a holdover from 1.4; we can still set these up from
  * lctl (and do for echo cli/srv.
  */
-int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
-           char *s1, char *s2, char *s3, char *s4)
+static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
+                  char *s1, char *s2, char *s3, char *s4)
 {
        struct lustre_cfg_bufs bufs;
        struct lustre_cfg     *lcfg = NULL;
@@ -169,15 +168,15 @@ int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
        lustre_cfg_free(lcfg);
        return rc;
 }
-EXPORT_SYMBOL(do_lcfg);
 
 /** Call class_attach and class_setup.  These methods in turn call
  * obd type-specific methods.
  */
-int lustre_start_simple(char *obdname, char *type, char *uuid,
-                       char *s1, char *s2, char *s3, char *s4)
+static int lustre_start_simple(char *obdname, char *type, char *uuid,
+                              char *s1, char *s2, char *s3, char *s4)
 {
        int rc;
+
        CDEBUG(D_MOUNT, "Starting obd %s (typ=%s)\n", obdname, type);
 
        rc = do_lcfg(obdname, 0, LCFG_ATTACH, type, uuid, NULL, NULL);
@@ -210,35 +209,17 @@ int lustre_start_mgc(struct super_block *sb)
        struct obd_uuid *uuid;
        class_uuid_t uuidc;
        lnet_nid_t nid;
+       char nidstr[LNET_NIDSTR_SIZE];
        char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL;
        char *ptr;
-       int rc = 0, i = 0, j, len;
+       int rc = 0, i = 0, j;
 
        LASSERT(lsi->lsi_lmd);
 
-       /* Find the first non-lo MGS nid for our MGC name */
-       if (IS_SERVER(lsi)) {
-               /* mount -o mgsnode=nid */
-               ptr = lsi->lsi_lmd->lmd_mgs;
-               if (lsi->lsi_lmd->lmd_mgs &&
-                   (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) {
-                       i++;
-               } else if (IS_MGS(lsi)) {
-                       lnet_process_id_t id;
-                       while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
-                               if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
-                                       continue;
-                               nid = id.nid;
-                               i++;
-                               break;
-                       }
-               }
-       } else { /* client */
-               /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
-               ptr = lsi->lsi_lmd->lmd_dev;
-               if (class_parse_nid(ptr, &nid, &ptr) == 0)
-                       i++;
-       }
+       /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
+       ptr = lsi->lsi_lmd->lmd_dev;
+       if (class_parse_nid(ptr, &nid, &ptr) == 0)
+               i++;
        if (i == 0) {
                CERROR("No valid MGS nids found.\n");
                return -EINVAL;
@@ -246,9 +227,9 @@ int lustre_start_mgc(struct super_block *sb)
 
        mutex_lock(&mgc_start_lock);
 
-       len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
+       libcfs_nid2str_r(nid, nidstr, sizeof(nidstr));
        mgcname = kasprintf(GFP_NOFS,
-                           "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
+                           "%s%s", LUSTRE_MGC_OBDNAME, nidstr);
        niduuid = kasprintf(GFP_NOFS, "%s_%x", mgcname, i);
        if (!mgcname || !niduuid) {
                rc = -ENOMEM;
@@ -300,12 +281,6 @@ int lustre_start_mgc(struct super_block *sb)
                }
 
                recov_bk = 0;
-               /* If we are restarting the MGS, don't try to keep the MGC's
-                  old connection, or registration will fail. */
-               if (IS_MGS(lsi)) {
-                       CDEBUG(D_MOUNT, "New MGS with live MGC\n");
-                       recov_bk = 1;
-               }
 
                /* Try all connections, but only once (again).
                   We don't want to block another target from starting
@@ -326,45 +301,15 @@ int lustre_start_mgc(struct super_block *sb)
 
        /* Add the primary nids for the MGS */
        i = 0;
-       if (IS_SERVER(lsi)) {
-               ptr = lsi->lsi_lmd->lmd_mgs;
-               if (IS_MGS(lsi)) {
-                       /* Use local nids (including LO) */
-                       lnet_process_id_t id;
-                       while ((rc = LNetGetId(i++, &id)) != -ENOENT) {
-                               rc = do_lcfg(mgcname, id.nid,
-                                            LCFG_ADD_UUID, niduuid,
-                                            NULL, NULL, NULL);
-                       }
-               } else {
-                       /* Use mgsnode= nids */
-                       /* mount -o mgsnode=nid */
-                       if (lsi->lsi_lmd->lmd_mgs) {
-                               ptr = lsi->lsi_lmd->lmd_mgs;
-                       } else if (class_find_param(ptr, PARAM_MGSNODE,
-                                                   &ptr) != 0) {
-                               CERROR("No MGS nids given.\n");
-                               rc = -EINVAL;
-                               goto out_free;
-                       }
-                       while (class_parse_nid(ptr, &nid, &ptr) == 0) {
-                               rc = do_lcfg(mgcname, nid,
-                                            LCFG_ADD_UUID, niduuid,
-                                            NULL, NULL, NULL);
-                               i++;
-                       }
-               }
-       } else { /* client */
-               /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
-               ptr = lsi->lsi_lmd->lmd_dev;
-               while (class_parse_nid(ptr, &nid, &ptr) == 0) {
-                       rc = do_lcfg(mgcname, nid,
-                                    LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
-                       i++;
-                       /* Stop at the first failover nid */
-                       if (*ptr == ':')
-                               break;
-               }
+       /* Use nids from mount line: uml1,1@elan:uml2,2@elan:/lustre */
+       ptr = lsi->lsi_lmd->lmd_dev;
+       while (class_parse_nid(ptr, &nid, &ptr) == 0) {
+               rc = do_lcfg(mgcname, nid,
+                            LCFG_ADD_UUID, niduuid, NULL, NULL, NULL);
+               i++;
+               /* Stop at the first failover nid */
+               if (*ptr == ':')
+                       break;
        }
        if (i == 0) {
                CERROR("No valid MGS nids found.\n");
@@ -543,7 +488,7 @@ out:
 
 /***************** lustre superblock **************/
 
-struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
+static struct lustre_sb_info *lustre_init_lsi(struct super_block *sb)
 {
        struct lustre_sb_info *lsi;
 
@@ -602,7 +547,7 @@ static int lustre_free_lsi(struct super_block *sb)
 
 /* The lsi has one reference for every server that is using the disk -
    e.g. MDT, MGS, and potentially MGC */
-int lustre_put_lsi(struct super_block *sb)
+static int lustre_put_lsi(struct super_block *sb)
 {
        struct lustre_sb_info *lsi = s2lsi(sb);
 
@@ -610,14 +555,6 @@ int lustre_put_lsi(struct super_block *sb)
 
        CDEBUG(D_MOUNT, "put %p %d\n", sb, atomic_read(&lsi->lsi_mounts));
        if (atomic_dec_and_test(&lsi->lsi_mounts)) {
-               if (IS_SERVER(lsi) && lsi->lsi_osd_exp) {
-                       lu_device_put(&lsi->lsi_dt_dev->dd_lu_dev);
-                       lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt = NULL;
-                       lsi->lsi_dt_dev = NULL;
-                       obd_disconnect(lsi->lsi_osd_exp);
-                       /* wait till OSD is gone */
-                       obd_zombie_barrier();
-               }
                lustre_free_lsi(sb);
                return 1;
        }
@@ -640,7 +577,8 @@ int lustre_put_lsi(struct super_block *sb)
  * @param [out] endptr if endptr isn't NULL it is set to end of fsname
  * rc < 0  on error
  */
-int server_name2fsname(const char *svname, char *fsname, const char **endptr)
+static int server_name2fsname(const char *svname, char *fsname,
+                             const char **endptr)
 {
        const char *dash;
 
@@ -660,40 +598,13 @@ int server_name2fsname(const char *svname, char *fsname, const char **endptr)
 
        return 0;
 }
-EXPORT_SYMBOL(server_name2fsname);
-
-/**
- * Get service name (svname) from string
- * rc < 0 on error
- * if endptr isn't NULL it is set to end of fsname *
- */
-int server_name2svname(const char *label, char *svname, const char **endptr,
-                      size_t svsize)
-{
-       int rc;
-       const char *dash;
-
-       /* We use server_name2fsname() just for parsing */
-       rc = server_name2fsname(label, NULL, &dash);
-       if (rc != 0)
-               return rc;
-
-       if (endptr != NULL)
-               *endptr = dash;
-
-       if (strlcpy(svname, dash + 1, svsize) >= svsize)
-               return -E2BIG;
-
-       return 0;
-}
-EXPORT_SYMBOL(server_name2svname);
-
 
 /* Get the index from the obd name.
    rc = server type, or
    rc < 0  on error
    if endptr isn't NULL it is set to end of name */
-int server_name2index(const char *svname, __u32 *idx, const char **endptr)
+static int server_name2index(const char *svname, __u32 *idx,
+                            const char **endptr)
 {
        unsigned long index;
        int rc;
@@ -732,7 +643,6 @@ int server_name2index(const char *svname, __u32 *idx, const char **endptr)
 
        return rc;
 }
-EXPORT_SYMBOL(server_name2index);
 
 /*************** mount common between server and client ***************/
 
@@ -929,7 +839,8 @@ static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
        int   oldlen = 0;
 
        /* Find end of nidlist */
-       while (class_parse_nid_quiet(tail, &nid, &tail) == 0) {}
+       while (class_parse_nid_quiet(tail, &nid, &tail) == 0)
+               ;
        length = tail - *ptr;
        if (length == 0) {
                LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", *ptr);
@@ -1069,6 +980,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                } else if (strncmp(s1, "param=", 6) == 0) {
                        int length;
                        char *tail = strchr(s1 + 6, ',');
+
                        if (tail == NULL)
                                length = strlen(s1);
                        else
@@ -1117,7 +1029,8 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
                ++s1;
                lmd->lmd_flags |= LMD_FLG_CLIENT;
                /* Remove leading /s from fsname */
-               while (*++s1 == '/') ;
+               while (*++s1 == '/')
+                       ;
                /* Freed in lustre_free_lsi */
                lmd->lmd_profile = kasprintf(GFP_NOFS, "%s-client", s1);
                if (!lmd->lmd_profile)
@@ -1162,7 +1075,7 @@ struct lustre_mount_data2 {
  * and this is where we start setting things up.
  * @param data Mount options (e.g. -o flock,abort_recov)
  */
-int lustre_fill_super(struct super_block *sb, void *data, int silent)
+static int lustre_fill_super(struct super_block *sb, void *data, int silent)
 {
        struct lustre_mount_data *lmd;
        struct lustre_mount_data2 *lmd2 = data;
@@ -1188,7 +1101,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
        obd_zombie_barrier();
 
        /* Figure out the lmd from the mount options */
-       if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
+       if (lmd_parse((lmd2->lmd2_data), lmd)) {
                lustre_put_lsi(sb);
                rc = -EINVAL;
                goto out;
@@ -1233,7 +1146,6 @@ out:
        return rc;
 }
 
-
 /* We can't call ll_fill_super by name because it lives in a module that
    must be loaded after this one. */
 void lustre_register_client_fill_super(int (*cfs)(struct super_block *sb,
@@ -1265,7 +1177,7 @@ static void lustre_kill_super(struct super_block *sb)
 {
        struct lustre_sb_info *lsi = s2lsi(sb);
 
-       if (kill_super_cb && lsi && !IS_SERVER(lsi))
+       if (kill_super_cb && lsi)
                (*kill_super_cb)(sb);
 
        kill_anon_super(sb);
@@ -1273,7 +1185,7 @@ static void lustre_kill_super(struct super_block *sb)
 
 /** Register the "lustre" fs type
  */
-struct file_system_type lustre_fs_type = {
+static struct file_system_type lustre_fs_type = {
        .owner  = THIS_MODULE,
        .name    = "lustre",
        .mount  = lustre_mount,
index 307ffe3471867b81ed546d611a20acb371827e57..75e1deadddd97bf61984d121f08a8d96d1bf408e 100644 (file)
@@ -115,90 +115,6 @@ void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid)
 }
 EXPORT_SYMBOL(obdo_from_inode);
 
-void obdo_cpy_md(struct obdo *dst, struct obdo *src, u32 valid)
-{
-       CDEBUG(D_INODE, "src obdo "DOSTID" valid %#llx, dst obdo "DOSTID"\n",
-              POSTID(&src->o_oi), src->o_valid, POSTID(&dst->o_oi));
-       if (valid & OBD_MD_FLATIME)
-               dst->o_atime = src->o_atime;
-       if (valid & OBD_MD_FLMTIME)
-               dst->o_mtime = src->o_mtime;
-       if (valid & OBD_MD_FLCTIME)
-               dst->o_ctime = src->o_ctime;
-       if (valid & OBD_MD_FLSIZE)
-               dst->o_size = src->o_size;
-       if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
-               dst->o_blocks = src->o_blocks;
-       if (valid & OBD_MD_FLBLKSZ)
-               dst->o_blksize = src->o_blksize;
-       if (valid & OBD_MD_FLTYPE)
-               dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
-       if (valid & OBD_MD_FLMODE)
-               dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
-       if (valid & OBD_MD_FLUID)
-               dst->o_uid = src->o_uid;
-       if (valid & OBD_MD_FLGID)
-               dst->o_gid = src->o_gid;
-       if (valid & OBD_MD_FLFLAGS)
-               dst->o_flags = src->o_flags;
-       if (valid & OBD_MD_FLFID) {
-               dst->o_parent_seq = src->o_parent_seq;
-               dst->o_parent_ver = src->o_parent_ver;
-       }
-       if (valid & OBD_MD_FLGENER)
-               dst->o_parent_oid = src->o_parent_oid;
-       if (valid & OBD_MD_FLHANDLE)
-               dst->o_handle = src->o_handle;
-       if (valid & OBD_MD_FLCOOKIE)
-               dst->o_lcookie = src->o_lcookie;
-
-       dst->o_valid |= valid;
-}
-EXPORT_SYMBOL(obdo_cpy_md);
-
-/* returns FALSE if comparison (by flags) is same, TRUE if changed */
-int obdo_cmp_md(struct obdo *dst, struct obdo *src, u32 compare)
-{
-       int res = 0;
-
-       if (compare & OBD_MD_FLATIME)
-               res |= dst->o_atime != src->o_atime;
-       if (compare & OBD_MD_FLMTIME)
-               res |= dst->o_mtime != src->o_mtime;
-       if (compare & OBD_MD_FLCTIME)
-               res |= dst->o_ctime != src->o_ctime;
-       if (compare & OBD_MD_FLSIZE)
-               res |= dst->o_size != src->o_size;
-       if (compare & OBD_MD_FLBLOCKS) /* allocation of space */
-               res |= dst->o_blocks != src->o_blocks;
-       if (compare & OBD_MD_FLBLKSZ)
-               res |= dst->o_blksize != src->o_blksize;
-       if (compare & OBD_MD_FLTYPE)
-               res |= ((dst->o_mode ^ src->o_mode) & S_IFMT) != 0;
-       if (compare & OBD_MD_FLMODE)
-               res |= ((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0;
-       if (compare & OBD_MD_FLUID)
-               res |= dst->o_uid != src->o_uid;
-       if (compare & OBD_MD_FLGID)
-               res |= dst->o_gid != src->o_gid;
-       if (compare & OBD_MD_FLFLAGS)
-               res |= dst->o_flags != src->o_flags;
-       if (compare & OBD_MD_FLNLINK)
-               res |= dst->o_nlink != src->o_nlink;
-       if (compare & OBD_MD_FLFID) {
-               res |= dst->o_parent_seq != src->o_parent_seq;
-               res |= dst->o_parent_ver != src->o_parent_ver;
-       }
-       if (compare & OBD_MD_FLGENER)
-               res |= dst->o_parent_oid != src->o_parent_oid;
-       /* XXX Don't know if these should be included here - wasn't previously
-       if ( compare & OBD_MD_FLINLINE )
-               res |= memcmp(dst->o_inline, src->o_inline);
-       */
-       return res;
-}
-EXPORT_SYMBOL(obdo_cmp_md);
-
 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj)
 {
        ioobj->ioo_oid = oa->o_oi;
@@ -211,43 +127,7 @@ void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj)
 }
 EXPORT_SYMBOL(obdo_to_ioobj);
 
-void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned int ia_valid)
-{
-       if (ia_valid & ATTR_ATIME) {
-               oa->o_atime = LTIME_S(attr->ia_atime);
-               oa->o_valid |= OBD_MD_FLATIME;
-       }
-       if (ia_valid & ATTR_MTIME) {
-               oa->o_mtime = LTIME_S(attr->ia_mtime);
-               oa->o_valid |= OBD_MD_FLMTIME;
-       }
-       if (ia_valid & ATTR_CTIME) {
-               oa->o_ctime = LTIME_S(attr->ia_ctime);
-               oa->o_valid |= OBD_MD_FLCTIME;
-       }
-       if (ia_valid & ATTR_SIZE) {
-               oa->o_size = attr->ia_size;
-               oa->o_valid |= OBD_MD_FLSIZE;
-       }
-       if (ia_valid & ATTR_MODE) {
-               oa->o_mode = attr->ia_mode;
-               oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
-               if (!in_group_p(make_kgid(&init_user_ns, oa->o_gid)) &&
-                   !capable(CFS_CAP_FSETID))
-                       oa->o_mode &= ~S_ISGID;
-       }
-       if (ia_valid & ATTR_UID) {
-               oa->o_uid = from_kuid(&init_user_ns, attr->ia_uid);
-               oa->o_valid |= OBD_MD_FLUID;
-       }
-       if (ia_valid & ATTR_GID) {
-               oa->o_gid = from_kgid(&init_user_ns, attr->ia_gid);
-               oa->o_valid |= OBD_MD_FLGID;
-       }
-}
-EXPORT_SYMBOL(obdo_from_iattr);
-
-void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid)
+static void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid)
 {
        valid &= oa->o_valid;
 
@@ -294,7 +174,6 @@ void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid)
                attr->ia_valid |= ATTR_GID;
        }
 }
-EXPORT_SYMBOL(iattr_from_obdo);
 
 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid)
 {
@@ -310,53 +189,3 @@ void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid)
        }
 }
 EXPORT_SYMBOL(md_from_obdo);
-
-void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
-                 unsigned int valid)
-{
-       obdo_from_iattr(oa, &op_data->op_attr, valid);
-       if (valid & ATTR_BLOCKS) {
-               oa->o_blocks = op_data->op_attr_blocks;
-               oa->o_valid |= OBD_MD_FLBLOCKS;
-       }
-       if (valid & ATTR_ATTR_FLAG) {
-               oa->o_flags =
-                       ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags;
-               oa->o_valid |= OBD_MD_FLFLAGS;
-       }
-}
-EXPORT_SYMBOL(obdo_from_md);
-
-void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo)
-{
-       dobdo->o_size = cpu_to_le64(sobdo->o_size);
-       dobdo->o_mtime = cpu_to_le64(sobdo->o_mtime);
-       dobdo->o_atime = cpu_to_le64(sobdo->o_atime);
-       dobdo->o_ctime = cpu_to_le64(sobdo->o_ctime);
-       dobdo->o_blocks = cpu_to_le64(sobdo->o_blocks);
-       dobdo->o_mode = cpu_to_le32(sobdo->o_mode);
-       dobdo->o_uid = cpu_to_le32(sobdo->o_uid);
-       dobdo->o_gid = cpu_to_le32(sobdo->o_gid);
-       dobdo->o_flags = cpu_to_le32(sobdo->o_flags);
-       dobdo->o_nlink = cpu_to_le32(sobdo->o_nlink);
-       dobdo->o_blksize = cpu_to_le32(sobdo->o_blksize);
-       dobdo->o_valid = cpu_to_le64(sobdo->o_valid);
-}
-EXPORT_SYMBOL(obdo_cpu_to_le);
-
-void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo)
-{
-       dobdo->o_size = le64_to_cpu(sobdo->o_size);
-       dobdo->o_mtime = le64_to_cpu(sobdo->o_mtime);
-       dobdo->o_atime = le64_to_cpu(sobdo->o_atime);
-       dobdo->o_ctime = le64_to_cpu(sobdo->o_ctime);
-       dobdo->o_blocks = le64_to_cpu(sobdo->o_blocks);
-       dobdo->o_mode = le32_to_cpu(sobdo->o_mode);
-       dobdo->o_uid = le32_to_cpu(sobdo->o_uid);
-       dobdo->o_gid = le32_to_cpu(sobdo->o_gid);
-       dobdo->o_flags = le32_to_cpu(sobdo->o_flags);
-       dobdo->o_nlink = le32_to_cpu(sobdo->o_nlink);
-       dobdo->o_blksize = le32_to_cpu(sobdo->o_blksize);
-       dobdo->o_valid = le64_to_cpu(sobdo->o_valid);
-}
-EXPORT_SYMBOL(obdo_le_to_cpu);
index cc785ab3f29a981ed1722d4765f30a03a14efe85..fb4e3ae845e0eeb5794ae0eec6e658aff0919693 100644 (file)
 #include "../include/obd_support.h"
 #include "../include/obd_class.h"
 
-void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs)
-{
-       memset(osfs, 0, sizeof(*osfs));
-       osfs->os_type = sfs->f_type;
-       osfs->os_blocks = sfs->f_blocks;
-       osfs->os_bfree = sfs->f_bfree;
-       osfs->os_bavail = sfs->f_bavail;
-       osfs->os_files = sfs->f_files;
-       osfs->os_ffree = sfs->f_ffree;
-       osfs->os_bsize = sfs->f_bsize;
-       osfs->os_namelen = sfs->f_namelen;
-}
-EXPORT_SYMBOL(statfs_pack);
-
 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs)
 {
        memset(sfs, 0, sizeof(*sfs));
index 27bd170c3a2831c6e2c1c9a5980cdb956900d569..b6f000bb8c825638b002344d4430fa871f64eeb9 100644 (file)
@@ -98,7 +98,6 @@ static int echo_client_setup(const struct lu_env *env,
                             struct lustre_cfg *lcfg);
 static int echo_client_cleanup(struct obd_device *obddev);
 
-
 /** \defgroup echo_helpers Helper functions
  * @{
  */
@@ -323,6 +322,7 @@ static const struct cl_page_operations echo_page_ops = {
                }
        }
 };
+
 /** @} echo_page */
 
 /** \defgroup echo_lock Locking
@@ -337,7 +337,7 @@ static void echo_lock_fini(const struct lu_env *env,
        struct echo_lock *ecl = cl2echo_lock(slice);
 
        LASSERT(list_empty(&ecl->el_chain));
-       OBD_SLAB_FREE_PTR(ecl, echo_lock_kmem);
+       kmem_cache_free(echo_lock_kmem, ecl);
 }
 
 static void echo_lock_delete(const struct lu_env *env,
@@ -396,7 +396,7 @@ static int echo_lock_init(const struct lu_env *env,
 {
        struct echo_lock *el;
 
-       OBD_SLAB_ALLOC_PTR_GFP(el, echo_lock_kmem, GFP_NOFS);
+       el = kmem_cache_alloc(echo_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (el != NULL) {
                cl_lock_slice_add(lock, &el->el_cl, obj, &echo_lock_ops);
                el->el_object = cl2echo_obj(obj);
@@ -418,6 +418,7 @@ static const struct cl_object_operations echo_cl_obj_ops = {
        .coo_io_init   = echo_io_init,
        .coo_conf_set  = echo_conf_set
 };
+
 /** @} echo_cl_ops */
 
 /** \defgroup echo_lu_ops lu_object operations
@@ -529,7 +530,7 @@ static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
 
        if (eco->eo_lsm)
                echo_free_memmd(eco->eo_dev, &eco->eo_lsm);
-       OBD_SLAB_FREE_PTR(eco, echo_object_kmem);
+       kmem_cache_free(echo_object_kmem, eco);
 }
 
 static int echo_object_print(const struct lu_env *env, void *cookie,
@@ -548,6 +549,7 @@ static const struct lu_object_operations echo_lu_obj_ops = {
        .loo_object_print     = echo_object_print,
        .loo_object_invariant = NULL
 };
+
 /** @} echo_lu_ops */
 
 /** \defgroup echo_lu_dev_ops  lu_device operations
@@ -565,7 +567,7 @@ static struct lu_object *echo_object_alloc(const struct lu_env *env,
 
        /* we're the top dev. */
        LASSERT(hdr == NULL);
-       OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, GFP_NOFS);
+       eco = kmem_cache_alloc(echo_object_kmem, GFP_NOFS | __GFP_ZERO);
        if (eco != NULL) {
                struct cl_object_header *hdr = &eco->eo_hdr;
 
@@ -628,7 +630,7 @@ static void *echo_thread_key_init(const struct lu_context *ctx,
 {
        struct echo_thread_info *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(echo_thread_kmem, GFP_NOFS | __GFP_ZERO);
        if (info == NULL)
                info = ERR_PTR(-ENOMEM);
        return info;
@@ -639,7 +641,7 @@ static void echo_thread_key_fini(const struct lu_context *ctx,
 {
        struct echo_thread_info *info = data;
 
-       OBD_SLAB_FREE_PTR(info, echo_thread_kmem);
+       kmem_cache_free(echo_thread_kmem, info);
 }
 
 static void echo_thread_key_exit(const struct lu_context *ctx,
@@ -659,7 +661,7 @@ static void *echo_session_key_init(const struct lu_context *ctx,
 {
        struct echo_session_info *session;
 
-       OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, GFP_NOFS);
+       session = kmem_cache_alloc(echo_session_kmem, GFP_NOFS | __GFP_ZERO);
        if (session == NULL)
                session = ERR_PTR(-ENOMEM);
        return session;
@@ -670,7 +672,7 @@ static void echo_session_key_fini(const struct lu_context *ctx,
 {
        struct echo_session_info *session = data;
 
-       OBD_SLAB_FREE_PTR(session, echo_session_kmem);
+       kmem_cache_free(echo_session_kmem, session);
 }
 
 static void echo_session_key_exit(const struct lu_context *ctx,
@@ -919,6 +921,7 @@ static struct lu_device_type echo_device_type = {
        .ldt_ops      = &echo_device_type_ops,
        .ldt_ctx_tags = LCT_CL_THREAD,
 };
+
 /** @} echo_init */
 
 /** \defgroup echo_exports Exported operations
@@ -1202,7 +1205,6 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset,
                goto out;
        LASSERT(rc == 0);
 
-
        rc = cl_echo_enqueue0(env, eco, offset,
                              offset + npages * PAGE_CACHE_SIZE - 1,
                              rw == READ ? LCK_PR : LCK_PW, &lh.cookie,
@@ -1259,8 +1261,8 @@ out:
        cl_env_put(env, &refcheck);
        return rc;
 }
-/** @} echo_exports */
 
+/** @} echo_exports */
 
 static u64 last_object_id;
 
@@ -1304,7 +1306,6 @@ echo_copyin_lsm(struct echo_device *ed, struct lov_stripe_md *lsm,
            ((__u64)lsm->lsm_stripe_size * lsm->lsm_stripe_count > ~0UL))
                return -EINVAL;
 
-
        for (i = 0; i < lsm->lsm_stripe_count; i++) {
                if (copy_from_user(lsm->lsm_oinfo[i],
                                       ((struct lov_stripe_md *)ulsm)-> \
@@ -1400,7 +1401,7 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
 
  failed:
        if (created && rc)
-               obd_destroy(env, ec->ec_exp, oa, lsm, oti, NULL, NULL);
+               obd_destroy(env, ec->ec_exp, oa, lsm, oti, NULL);
        if (lsm)
                echo_free_memmd(ed, &lsm);
        if (rc)
@@ -1594,7 +1595,7 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                LASSERT(pgp->pg == NULL);      /* for cleanup */
 
                rc = -ENOMEM;
-               OBD_PAGE_ALLOC(pgp->pg, gfp_mask);
+               pgp->pg = alloc_page(gfp_mask);
                if (pgp->pg == NULL)
                        goto out;
 
@@ -1630,7 +1631,7 @@ static int echo_client_kbrw(struct echo_device *ed, int rw, struct obdo *oa,
                        if (vrc != 0 && rc == 0)
                                rc = vrc;
                }
-               OBD_PAGE_FREE(pgp->pg);
+               __free_page(pgp->pg);
        }
        kfree(pga);
        kfree(pages);
@@ -1691,7 +1692,7 @@ static int echo_client_prep_commit(const struct lu_env *env,
 
                lpages = npages;
                ret = obd_preprw(env, rw, exp, oa, 1, &ioo, rnb, &lpages,
-                                lnb, oti, NULL);
+                                lnb, oti);
                if (ret != 0)
                        goto out;
                LASSERT(lpages == npages);
@@ -1907,7 +1908,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                rc = echo_get_object(&eco, ed, oa);
                if (rc == 0) {
                        rc = obd_destroy(env, ec->ec_exp, oa, eco->eo_lsm,
-                                        &dummy_oti, NULL, NULL);
+                                        &dummy_oti, NULL);
                        if (rc == 0)
                                eco->eo_deleted = 1;
                        echo_put_object(eco);
@@ -1917,7 +1918,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
        case OBD_IOC_GETATTR:
                rc = echo_get_object(&eco, ed, oa);
                if (rc == 0) {
-                       struct obd_info oinfo = { { { 0 } } };
+                       struct obd_info oinfo = { };
 
                        oinfo.oi_md = eco->eo_lsm;
                        oinfo.oi_oa = oa;
@@ -1934,7 +1935,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 
                rc = echo_get_object(&eco, ed, oa);
                if (rc == 0) {
-                       struct obd_info oinfo = { { { 0 } } };
+                       struct obd_info oinfo = { };
 
                        oinfo.oi_oa = oa;
                        oinfo.oi_md = eco->eo_lsm;
@@ -2065,12 +2066,6 @@ static int echo_client_setup(const struct lu_env *env,
        ocd->ocd_group = FID_SEQ_ECHO;
 
        rc = obd_connect(env, &ec->ec_exp, tgt, &echo_uuid, ocd, NULL);
-       if (rc == 0) {
-               /* Turn off pinger because it connects to tgt obd directly. */
-               spin_lock(&tgt->obd_dev_lock);
-               list_del_init(&ec->ec_exp->exp_obd_chain_timed);
-               spin_unlock(&tgt->obd_dev_lock);
-       }
 
        kfree(ocd);
 
index 8e9dbc2351e7b0a3ad4d9e67228e245fad605f41..69063fa65d35417198acbab4b0fb016bea60b344 100644 (file)
@@ -43,5 +43,4 @@
 /* block size to use for data verification */
 #define OBD_ECHO_BLOCK_SIZE    (4<<10)
 
-
 #endif
index ff6d2e2ffdab23db6ef800de0552a4a40c83771e..c4d44e70f1d719ba9781fef157575bef92a73a61 100644 (file)
@@ -63,7 +63,7 @@ static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
        rc = kstrtoul(buffer, 10, &val);
        if (rc)
                return rc;
-       if (val < 0 || val > 1)
+       if (val > 1)
                return -ERANGE;
 
        /* opposite senses */
@@ -96,9 +96,9 @@ static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
        struct obd_device *dev = container_of(kobj, struct obd_device,
                                              obd_kobj);
        struct client_obd *cli = &dev->u.cli;
-       struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
        int rc;
        unsigned long val;
+       int adding, added, req_count;
 
        rc = kstrtoul(buffer, 10, &val);
        if (rc)
@@ -107,8 +107,19 @@ static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
        if (val < 1 || val > OSC_MAX_RIF_MAX)
                return -ERANGE;
 
-       if (pool && val > cli->cl_max_rpcs_in_flight)
-               pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
+       adding = val - cli->cl_max_rpcs_in_flight;
+       req_count = atomic_read(&osc_pool_req_count);
+       if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
+               /*
+                * There might be some race which will cause over-limit
+                * allocation, but it is fine.
+                */
+               if (req_count + adding > osc_reqpool_maxreqcount)
+                       adding = osc_reqpool_maxreqcount - req_count;
+
+               added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
+               atomic_add(added, &osc_pool_req_count);
+       }
 
        client_obd_list_lock(&cli->cl_loi_list_lock);
        cli->cl_max_rpcs_in_flight = val;
@@ -216,6 +227,7 @@ static ssize_t osc_cached_mb_seq_write(struct file *file,
 
        return count;
 }
+
 LPROC_SEQ_FOPS(osc_cached_mb);
 
 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
@@ -366,6 +378,7 @@ static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *obd = m->private;
        int i;
+
        DECLARE_CKSUM_NAME;
 
        if (obd == NULL)
@@ -389,6 +402,7 @@ static ssize_t osc_checksum_type_seq_write(struct file *file,
 {
        struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
        int i;
+
        DECLARE_CKSUM_NAME;
        char kernbuf[10];
 
@@ -414,6 +428,7 @@ static ssize_t osc_checksum_type_seq_write(struct file *file,
        }
        return -EINVAL;
 }
+
 LPROC_SEQ_FOPS(osc_checksum_type);
 
 static ssize_t resend_count_show(struct kobject *kobj,
@@ -440,9 +455,6 @@ static ssize_t resend_count_store(struct kobject *kobj,
        if (rc)
                return rc;
 
-       if (val < 0)
-              return -EINVAL;
-
        atomic_set(&obd->u.cli.cl_resends, val);
 
        return count;
@@ -586,18 +598,18 @@ static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
 
 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 {
-       struct timeval now;
+       struct timespec64 now;
        struct obd_device *dev = seq->private;
        struct client_obd *cli = &dev->u.cli;
        unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
        int i;
 
-       do_gettimeofday(&now);
+       ktime_get_real_ts64(&now);
 
        client_obd_list_lock(&cli->cl_loi_list_lock);
 
-       seq_printf(seq, "snapshot_time:  %lu.%lu (secs.usecs)\n",
-                  now.tv_sec, (unsigned long)now.tv_usec);
+       seq_printf(seq, "snapshot_time:  %llu.%9lu (secs.usecs)\n",
+                  (s64)now.tv_sec, (unsigned long)now.tv_nsec);
        seq_printf(seq, "read RPCs in flight:  %d\n",
                   cli->cl_r_in_flight);
        seq_printf(seq, "write RPCs in flight: %d\n",
@@ -619,6 +631,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
        for (i = 0; i < OBD_HIST_MAX; i++) {
                unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
                unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
+
                read_cum += r;
                write_cum += w;
                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
@@ -642,6 +655,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
        for (i = 0; i < OBD_HIST_MAX; i++) {
                unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
                unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
+
                read_cum += r;
                write_cum += w;
                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
@@ -665,6 +679,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
        for (i = 0; i < OBD_HIST_MAX; i++) {
                unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
                unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
+
                read_cum += r;
                write_cum += w;
                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
@@ -679,6 +694,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 
        return 0;
 }
+
 #undef pct
 
 static ssize_t osc_rpc_stats_seq_write(struct file *file,
@@ -703,14 +719,14 @@ LPROC_SEQ_FOPS(osc_rpc_stats);
 
 static int osc_stats_seq_show(struct seq_file *seq, void *v)
 {
-       struct timeval now;
+       struct timespec64 now;
        struct obd_device *dev = seq->private;
        struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
 
-       do_gettimeofday(&now);
+       ktime_get_real_ts64(&now);
 
-       seq_printf(seq, "snapshot_time:  %lu.%lu (secs.usecs)\n",
-                  now.tv_sec, (unsigned long)now.tv_usec);
+       seq_printf(seq, "snapshot_time:  %llu.%9lu (secs.usecs)\n",
+                  (s64)now.tv_sec, (unsigned long)now.tv_nsec);
        seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
                   stats->os_lockless_writes);
        seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
index c72035e048aa9842d25af105ae0d6cab749a49ed..cfb83bcfcb17525ac99e7f08b428fde98e86316c 100644 (file)
@@ -247,6 +247,7 @@ static int osc_extent_sanity_check0(struct osc_extent *ext,
 
        if (ext->oe_osclock) {
                struct cl_lock_descr *descr;
+
                descr = &ext->oe_osclock->cll_descr;
                if (!(descr->cld_start <= ext->oe_start &&
                      descr->cld_end >= ext->oe_max_end)) {
@@ -305,7 +306,6 @@ out:
        __res;                                                          \
 })
 
-
 /**
  * sanity check - to make sure there is no overlapped extent in the tree.
  */
@@ -346,7 +346,7 @@ static struct osc_extent *osc_extent_alloc(struct osc_object *obj)
 {
        struct osc_extent *ext;
 
-       OBD_SLAB_ALLOC_PTR_GFP(ext, osc_extent_kmem, GFP_IOFS);
+       ext = kmem_cache_alloc(osc_extent_kmem, GFP_IOFS | __GFP_ZERO);
        if (ext == NULL)
                return NULL;
 
@@ -365,7 +365,7 @@ static struct osc_extent *osc_extent_alloc(struct osc_object *obj)
 
 static void osc_extent_free(struct osc_extent *ext)
 {
-       OBD_SLAB_FREE_PTR(ext, osc_extent_kmem);
+       kmem_cache_free(osc_extent_kmem, ext);
 }
 
 static struct osc_extent *osc_extent_get(struct osc_extent *ext)
@@ -475,6 +475,7 @@ static void osc_extent_insert(struct osc_object *obj, struct osc_extent *ext)
 static void osc_extent_erase(struct osc_extent *ext)
 {
        struct osc_object *obj = ext->oe_obj;
+
        LASSERT(osc_object_is_locked(obj));
        if (ext->oe_intree) {
                rb_erase(&ext->oe_node, &obj->oo_root);
@@ -868,6 +869,7 @@ int osc_extent_finish(const struct lu_env *env, struct osc_extent *ext,
                int offset = oap->oap_page_off & ~CFS_PAGE_MASK;
                int count = oap->oap_count + (offset & (blocksize - 1));
                int end = (offset + oap->oap_count) & (blocksize - 1);
+
                if (end)
                        count += blocksize - end;
 
@@ -1025,7 +1027,6 @@ static int osc_extent_truncate(struct osc_extent *ext, pgoff_t trunc_index,
                int chunks = (ext->oe_end >> ppc_bits) - trunc_chunk;
                pgoff_t last_index;
 
-
                /* if there is no pages in this chunk, we can also free grants
                 * for the last chunk */
                if (pages_in_chunk == 0) {
@@ -1510,6 +1511,7 @@ static int osc_enter_cache_try(struct client_obd *cli,
 static int ocw_granted(struct client_obd *cli, struct osc_cache_waiter *ocw)
 {
        int rc;
+
        client_obd_list_lock(&cli->cl_loi_list_lock);
        rc = list_empty(&ocw->ocw_entry);
        client_obd_list_unlock(&cli->cl_loi_list_lock);
@@ -1632,6 +1634,7 @@ wakeup:
 static int osc_max_rpc_in_flight(struct client_obd *cli, struct osc_object *osc)
 {
        int hprpc = !!list_empty(&osc->oo_hp_exts);
+
        return rpcs_in_flight(cli) >= cli->cl_max_rpcs_in_flight + hprpc;
 }
 
@@ -1693,6 +1696,7 @@ static int osc_makes_rpc(struct client_obd *cli, struct osc_object *osc,
 static void osc_update_pending(struct osc_object *obj, int cmd, int delta)
 {
        struct client_obd *cli = osc_cli(obj);
+
        if (cmd & OBD_BRW_WRITE) {
                atomic_add(delta, &obj->oo_nr_writes);
                atomic_add(delta, &cli->cl_pending_w_pages);
@@ -1775,7 +1779,6 @@ static void osc_process_ar(struct osc_async_rc *ar, __u64 xid,
                ar->ar_force_sync = 0;
 }
 
-
 /* this must be called holding the loi list lock to give coverage to exit_cache,
  * async_flag maintenance, and oap_request */
 static void osc_ap_completion(const struct lu_env *env, struct client_obd *cli,
@@ -1934,7 +1937,7 @@ static int get_write_extents(struct osc_object *obj, struct list_head *rpclist)
 
 static int
 osc_send_write_rpc(const struct lu_env *env, struct client_obd *cli,
-                  struct osc_object *osc, pdl_policy_t pol)
+                  struct osc_object *osc)
 {
        LIST_HEAD(rpclist);
        struct osc_extent *ext;
@@ -1986,7 +1989,7 @@ osc_send_write_rpc(const struct lu_env *env, struct client_obd *cli,
 
        if (!list_empty(&rpclist)) {
                LASSERT(page_count > 0);
-               rc = osc_build_rpc(env, cli, &rpclist, OBD_BRW_WRITE, pol);
+               rc = osc_build_rpc(env, cli, &rpclist, OBD_BRW_WRITE);
                LASSERT(list_empty(&rpclist));
        }
 
@@ -2006,7 +2009,7 @@ osc_send_write_rpc(const struct lu_env *env, struct client_obd *cli,
  */
 static int
 osc_send_read_rpc(const struct lu_env *env, struct client_obd *cli,
-                 struct osc_object *osc, pdl_policy_t pol)
+                 struct osc_object *osc)
 {
        struct osc_extent *ext;
        struct osc_extent *next;
@@ -2033,7 +2036,7 @@ osc_send_read_rpc(const struct lu_env *env, struct client_obd *cli,
                osc_object_unlock(osc);
 
                LASSERT(page_count > 0);
-               rc = osc_build_rpc(env, cli, &rpclist, OBD_BRW_READ, pol);
+               rc = osc_build_rpc(env, cli, &rpclist, OBD_BRW_READ);
                LASSERT(list_empty(&rpclist));
 
                osc_object_lock(osc);
@@ -2079,8 +2082,7 @@ static struct osc_object *osc_next_obj(struct client_obd *cli)
 }
 
 /* called with the loi list lock held */
-static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli,
-                          pdl_policy_t pol)
+static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli)
 {
        struct osc_object *osc;
        int rc = 0;
@@ -2109,7 +2111,7 @@ static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli,
                 * do io on writes while there are cache waiters */
                osc_object_lock(osc);
                if (osc_makes_rpc(cli, osc, OBD_BRW_WRITE)) {
-                       rc = osc_send_write_rpc(env, cli, osc, pol);
+                       rc = osc_send_write_rpc(env, cli, osc);
                        if (rc < 0) {
                                CERROR("Write request failed with %d\n", rc);
 
@@ -2133,7 +2135,7 @@ static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli,
                        }
                }
                if (osc_makes_rpc(cli, osc, OBD_BRW_READ)) {
-                       rc = osc_send_read_rpc(env, cli, osc, pol);
+                       rc = osc_send_read_rpc(env, cli, osc);
                        if (rc < 0)
                                CERROR("Read request failed with %d\n", rc);
                }
@@ -2149,7 +2151,7 @@ static void osc_check_rpcs(const struct lu_env *env, struct client_obd *cli,
 }
 
 static int osc_io_unplug0(const struct lu_env *env, struct client_obd *cli,
-                         struct osc_object *osc, pdl_policy_t pol, int async)
+                         struct osc_object *osc, int async)
 {
        int rc = 0;
 
@@ -2161,7 +2163,7 @@ static int osc_io_unplug0(const struct lu_env *env, struct client_obd *cli,
                 * potential stack overrun problem. LU-2859 */
                atomic_inc(&cli->cl_lru_shrinkers);
                client_obd_list_lock(&cli->cl_loi_list_lock);
-               osc_check_rpcs(env, cli, pol);
+               osc_check_rpcs(env, cli);
                client_obd_list_unlock(&cli->cl_loi_list_lock);
                atomic_dec(&cli->cl_lru_shrinkers);
        } else {
@@ -2175,14 +2177,13 @@ static int osc_io_unplug0(const struct lu_env *env, struct client_obd *cli,
 static int osc_io_unplug_async(const struct lu_env *env,
                               struct client_obd *cli, struct osc_object *osc)
 {
-       /* XXX: policy is no use actually. */
-       return osc_io_unplug0(env, cli, osc, PDL_POLICY_ROUND, 1);
+       return osc_io_unplug0(env, cli, osc, 1);
 }
 
 void osc_io_unplug(const struct lu_env *env, struct client_obd *cli,
-                  struct osc_object *osc, pdl_policy_t pol)
+                  struct osc_object *osc)
 {
-       (void)osc_io_unplug0(env, cli, osc, pol, 0);
+       (void)osc_io_unplug0(env, cli, osc, 0);
 }
 
 int osc_prep_async_page(struct osc_object *osc, struct osc_page *ops,
@@ -2568,6 +2569,7 @@ int osc_queue_sync_pages(const struct lu_env *env, struct osc_object *obj,
 
        list_for_each_entry(oap, list, oap_pending_item) {
                struct cl_page *cp = oap2cl_page(oap);
+
                if (cp->cp_index > end)
                        end = cp->cp_index;
                if (cp->cp_index < start)
@@ -2853,6 +2855,7 @@ int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj,
                        result += ext->oe_nr_pages;
                        if (!discard) {
                                struct list_head *list = NULL;
+
                                if (hp) {
                                        EASSERT(!ext->oe_hp, ext);
                                        ext->oe_hp = 1;
@@ -2922,10 +2925,11 @@ int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj,
        }
 
        if (unplug)
-               osc_io_unplug(env, osc_cli(obj), obj, PDL_POLICY_ROUND);
+               osc_io_unplug(env, osc_cli(obj), obj);
 
        if (hp || discard) {
                int rc;
+
                rc = osc_cache_wait_range(env, obj, start, end);
                if (result >= 0 && rc < 0)
                        result = rc;
index 365b2787b3c834415e605b9038a034fa7ea7e45f..d2d68452d38271b9ab842de92530ae86fa01cf17 100644 (file)
@@ -329,7 +329,6 @@ struct osc_lock {
        struct osc_io      *ols_owner;
 };
 
-
 /**
  * Page state private for osc layer.
  */
@@ -454,7 +453,7 @@ int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj,
 int osc_cache_wait_range(const struct lu_env *env, struct osc_object *obj,
                         pgoff_t start, pgoff_t end);
 void osc_io_unplug(const struct lu_env *env, struct client_obd *cli,
-                  struct osc_object *osc, pdl_policy_t pol);
+                  struct osc_object *osc);
 
 void osc_object_set_contended  (struct osc_object *obj);
 void osc_object_clear_contended(struct osc_object *obj);
index 91fdec44792b097edf45b7a2d80bcdc2dd7e90b8..69b523c0f570263cb0a32eedd699f2b115a44829 100644 (file)
@@ -122,7 +122,7 @@ static void *osc_key_init(const struct lu_context *ctx,
 {
        struct osc_thread_info *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, osc_thread_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(osc_thread_kmem, GFP_NOFS | __GFP_ZERO);
        if (info == NULL)
                info = ERR_PTR(-ENOMEM);
        return info;
@@ -133,7 +133,7 @@ static void osc_key_fini(const struct lu_context *ctx,
 {
        struct osc_thread_info *info = data;
 
-       OBD_SLAB_FREE_PTR(info, osc_thread_kmem);
+       kmem_cache_free(osc_thread_kmem, info);
 }
 
 struct lu_context_key osc_key = {
@@ -147,7 +147,7 @@ static void *osc_session_init(const struct lu_context *ctx,
 {
        struct osc_session *info;
 
-       OBD_SLAB_ALLOC_PTR_GFP(info, osc_session_kmem, GFP_NOFS);
+       info = kmem_cache_alloc(osc_session_kmem, GFP_NOFS | __GFP_ZERO);
        if (info == NULL)
                info = ERR_PTR(-ENOMEM);
        return info;
@@ -158,7 +158,7 @@ static void osc_session_fini(const struct lu_context *ctx,
 {
        struct osc_session *info = data;
 
-       OBD_SLAB_FREE_PTR(info, osc_session_kmem);
+       kmem_cache_free(osc_session_kmem, info);
 }
 
 struct lu_context_key osc_session_key = {
index 470698b0dd75280ca8f085dddc5e2b9836a356dd..5ed30ecc84e34bc3db4c2b96e4149a6219002ab3 100644 (file)
 
 #define OAP_MAGIC 8675309
 
+extern atomic_t osc_pool_req_count;
+extern unsigned int osc_reqpool_maxreqcount;
+extern struct ptlrpc_request_pool *osc_rq_pool;
+
 struct lu_env;
 
 enum async_flags {
@@ -128,7 +132,7 @@ int osc_sync_base(struct obd_export *exp, struct obd_info *oinfo,
 
 int osc_process_config_base(struct obd_device *obd, struct lustre_cfg *cfg);
 int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
-                 struct list_head *ext_list, int cmd, pdl_policy_t p);
+                 struct list_head *ext_list, int cmd);
 int osc_lru_shrink(struct client_obd *cli, int target);
 
 extern spinlock_t osc_ast_guard;
@@ -181,6 +185,7 @@ struct osc_quota_info {
        struct hlist_node oqi_hash;
        u32       oqi_id;
 };
+
 int osc_quota_setup(struct obd_device *obd);
 int osc_quota_cleanup(struct obd_device *obd);
 int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
index fa24e9ed1831427f8ec47c43043a7314d48795cf..d413496c0f63276b08caf6e9740567556cb7fb20 100644 (file)
@@ -78,7 +78,6 @@ static struct osc_page *osc_cl_page_osc(struct cl_page *page)
        return cl2osc_page(slice);
 }
 
-
 /*****************************************************************************
  *
  * io operations.
@@ -402,7 +401,7 @@ static int osc_io_setattr_start(const struct lu_env *env,
        __u64 size = io->u.ci_setattr.sa_attr.lvb_size;
        unsigned int ia_valid = io->u.ci_setattr.sa_valid;
        int result = 0;
-       struct obd_info oinfo = { { { 0 } } };
+       struct obd_info oinfo = { };
 
        /* truncate cache dirty pages first */
        if (cl_io_is_trunc(io))
@@ -457,7 +456,6 @@ static int osc_io_setattr_start(const struct lu_env *env,
                }
 
                oinfo.oi_oa = oa;
-               oinfo.oi_capa = io->u.ci_setattr.sa_capa;
                init_completion(&cbargs->opc_sync);
 
                if (ia_valid & ATTR_SIZE)
@@ -518,7 +516,7 @@ static int osc_io_read_start(const struct lu_env *env,
 
        if (!slice->cis_io->ci_noatime) {
                cl_object_attr_lock(obj);
-               attr->cat_atime = LTIME_S(CURRENT_TIME);
+               attr->cat_atime = ktime_get_real_seconds();
                rc = cl_object_attr_set(env, obj, attr, CAT_ATIME);
                cl_object_attr_unlock(obj);
        }
@@ -534,7 +532,7 @@ static int osc_io_write_start(const struct lu_env *env,
 
        OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_DELAY_SETTIME, 1);
        cl_object_attr_lock(obj);
-       attr->cat_mtime = attr->cat_ctime = LTIME_S(CURRENT_TIME);
+       attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds();
        rc = cl_object_attr_set(env, obj, attr, CAT_MTIME | CAT_CTIME);
        cl_object_attr_unlock(obj);
 
@@ -564,7 +562,6 @@ static int osc_fsync_ost(const struct lu_env *env, struct osc_object *obj,
 
        memset(oinfo, 0, sizeof(*oinfo));
        oinfo->oi_oa = oa;
-       oinfo->oi_capa = fio->fi_capa;
        init_completion(&cbargs->opc_sync);
 
        rc = osc_sync_base(osc_export(obj), oinfo, osc_async_upcall, cbargs,
@@ -703,7 +700,7 @@ static void osc_req_completion(const struct lu_env *env,
        struct osc_req *or;
 
        or = cl2osc_req(slice);
-       OBD_SLAB_FREE_PTR(or, osc_req_kmem);
+       kmem_cache_free(osc_req_kmem, or);
 }
 
 /**
@@ -790,7 +787,6 @@ static const struct cl_req_operations osc_req_ops = {
        .cro_completion = osc_req_completion
 };
 
-
 int osc_io_init(const struct lu_env *env,
                struct cl_object *obj, struct cl_io *io)
 {
@@ -807,7 +803,7 @@ int osc_req_init(const struct lu_env *env, struct cl_device *dev,
        struct osc_req *or;
        int result;
 
-       OBD_SLAB_ALLOC_PTR_GFP(or, osc_req_kmem, GFP_NOFS);
+       or = kmem_cache_alloc(osc_req_kmem, GFP_NOFS | __GFP_ZERO);
        if (or != NULL) {
                cl_req_slice_add(req, &or->or_cl, dev, &osc_req_ops);
                result = 0;
index 70b1b43f692b0231a2c16121ed9e7ee3caf8f327..194490dcaca9e0f6d4a7c5ad6b25ced9645edbb0 100644 (file)
@@ -251,7 +251,7 @@ static void osc_lock_fini(const struct lu_env *env,
        LASSERT(atomic_read(&ols->ols_pageref) == 0 ||
                atomic_read(&ols->ols_pageref) == _PAGEREF_MAGIC);
 
-       OBD_SLAB_FREE_PTR(ols, osc_lock_kmem);
+       kmem_cache_free(osc_lock_kmem, ols);
 }
 
 static void osc_lock_build_policy(const struct lu_env *env,
@@ -1555,7 +1555,7 @@ int osc_lock_init(const struct lu_env *env,
        struct osc_lock *clk;
        int result;
 
-       OBD_SLAB_ALLOC_PTR_GFP(clk, osc_lock_kmem, GFP_NOFS);
+       clk = kmem_cache_alloc(osc_lock_kmem, GFP_NOFS | __GFP_ZERO);
        if (clk != NULL) {
                __u32 enqflags = lock->cll_descr.cld_enq_flags;
 
index c628a250ebd6dfca1374e05a3e05af56c363f43a..ba57f8df5c7f7a63a77465376c46d482c14a4b30 100644 (file)
@@ -122,7 +122,7 @@ static void osc_object_free(const struct lu_env *env, struct lu_object *obj)
        LASSERT(atomic_read(&osc->oo_nr_writes) == 0);
 
        lu_object_fini(obj);
-       OBD_SLAB_FREE_PTR(osc, osc_object_kmem);
+       kmem_cache_free(osc_object_kmem, osc);
 }
 
 int osc_lvb_print(const struct lu_env *env, void *cookie,
@@ -148,7 +148,6 @@ static int osc_object_print(const struct lu_env *env, void *cookie,
        return 0;
 }
 
-
 static int osc_attr_get(const struct lu_env *env, struct cl_object *obj,
                        struct cl_attr *attr)
 {
@@ -193,7 +192,6 @@ static int osc_object_glimpse(const struct lu_env *env,
        return 0;
 }
 
-
 void osc_object_set_contended(struct osc_object *obj)
 {
        obj->oo_contention_time = cfs_time_current();
@@ -257,7 +255,7 @@ struct lu_object *osc_object_alloc(const struct lu_env *env,
        struct osc_object *osc;
        struct lu_object *obj;
 
-       OBD_SLAB_ALLOC_PTR_GFP(osc, osc_object_kmem, GFP_NOFS);
+       osc = kmem_cache_alloc(osc_object_kmem, GFP_NOFS | __GFP_ZERO);
        if (osc != NULL) {
                obj = osc2lu(osc);
                lu_object_init(obj, NULL, dev);
index f9cf5cea643d8f846a4b10ca243818fd6c4def32..61eaf7172fdf892b2f13bf4faf5e99ce77204d8b 100644 (file)
@@ -166,6 +166,7 @@ static void osc_page_fini(const struct lu_env *env,
                          struct cl_page_slice *slice)
 {
        struct osc_page *opg = cl2osc_page(slice);
+
        CDEBUG(D_TRACE, "%p\n", opg);
        LASSERT(opg->ops_lock == NULL);
 }
@@ -346,7 +347,6 @@ static int osc_page_fail(const struct lu_env *env,
        return 0;
 }
 
-
 static const char *osc_list(struct list_head *head)
 {
        return list_empty(head) ? "-" : "+";
@@ -512,6 +512,7 @@ int osc_page_init(const struct lu_env *env, struct cl_object *obj,
                                        cl_offset(obj, page->cp_index));
        if (result == 0) {
                struct osc_io *oio = osc_env_io(env);
+
                opg->ops_srvlock = osc_io_srvlock(oio);
                cl_page_slice_add(page, &opg->ops_cl, obj,
                                &osc_page_ops);
@@ -553,7 +554,7 @@ void osc_page_submit(const struct lu_env *env, struct osc_page *opg,
        oap->oap_cmd = crt == CRT_WRITE ? OBD_BRW_WRITE : OBD_BRW_READ;
        oap->oap_page_off = opg->ops_from;
        oap->oap_count = opg->ops_to - opg->ops_from;
-       oap->oap_brw_flags = OBD_BRW_SYNC | brw_flags;
+       oap->oap_brw_flags = brw_flags | OBD_BRW_SYNC;
 
        if (!client_is_remote(osc_export(obj)) &&
                        capable(CFS_CAP_SYS_RESOURCE)) {
@@ -624,6 +625,7 @@ static int discard_pagevec(const struct lu_env *env, struct cl_io *io,
 
        for (count = 0, i = 0; i < max_index; i++) {
                struct cl_page *page = pvec[i];
+
                if (cl_page_own_try(env, io, page) == 0) {
                        /* free LRU page only if nobody is using it.
                         * This check is necessary to avoid freeing the pages
@@ -818,7 +820,6 @@ static int osc_lru_reclaim(struct client_obd *cli)
        int rc;
 
        LASSERT(cache != NULL);
-       LASSERT(!list_empty(&cache->ccc_lru));
 
        rc = osc_lru_shrink(cli, lru_shrink_min);
        if (rc != 0) {
@@ -835,6 +836,8 @@ static int osc_lru_reclaim(struct client_obd *cli)
        /* Reclaim LRU slots from other client_obd as it can't free enough
         * from its own. This should rarely happen. */
        spin_lock(&cache->ccc_lru_lock);
+       LASSERT(!list_empty(&cache->ccc_lru));
+
        cache->ccc_lru_shrinkers++;
        list_move_tail(&cli->cl_lru_osc, &cache->ccc_lru);
 
index 2ff253f458f8af5255f11ed3a2c7f79f35ccd9e4..199783103f711367c9d78206eb9deb794242f1c2 100644 (file)
@@ -35,7 +35,7 @@ static inline struct osc_quota_info *osc_oqi_alloc(u32 id)
 {
        struct osc_quota_info *oqi;
 
-       OBD_SLAB_ALLOC_PTR(oqi, osc_quota_kmem);
+       oqi = kmem_cache_alloc(osc_quota_kmem, GFP_NOFS | __GFP_ZERO);
        if (oqi != NULL)
                oqi->oqi_id = id;
 
@@ -104,7 +104,7 @@ int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
                        /* race with others? */
                        if (rc == -EALREADY) {
                                rc = 0;
-                               OBD_SLAB_FREE_PTR(oqi, osc_quota_kmem);
+                               kmem_cache_free(osc_quota_kmem, oqi);
                        }
 
                        CDEBUG(D_QUOTA, "%s: setdq to insert for %s %d (%d)\n",
@@ -120,7 +120,7 @@ int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
                        oqi = cfs_hash_del_key(cli->cl_quota_hash[type],
                                               &qid[type]);
                        if (oqi)
-                               OBD_SLAB_FREE_PTR(oqi, osc_quota_kmem);
+                               kmem_cache_free(osc_quota_kmem, oqi);
 
                        CDEBUG(D_QUOTA, "%s: setdq to remove for %s %d (%p)\n",
                               cli->cl_import->imp_obd->obd_name,
@@ -158,6 +158,7 @@ static void *
 oqi_key(struct hlist_node *hnode)
 {
        struct osc_quota_info *oqi;
+
        oqi = hlist_entry(hnode, struct osc_quota_info, oqi_hash);
        return &oqi->oqi_id;
 }
@@ -185,14 +186,14 @@ oqi_exit(struct cfs_hash *hs, struct hlist_node *hnode)
 
        oqi = hlist_entry(hnode, struct osc_quota_info, oqi_hash);
 
-       OBD_SLAB_FREE_PTR(oqi, osc_quota_kmem);
+       kmem_cache_free(osc_quota_kmem, oqi);
 }
 
 #define HASH_QUOTA_BKT_BITS 5
 #define HASH_QUOTA_CUR_BITS 5
 #define HASH_QUOTA_MAX_BITS 15
 
-static cfs_hash_ops_t quota_hash_ops = {
+static struct cfs_hash_ops quota_hash_ops = {
        .hs_hash        = oqi_hashfn,
        .hs_keycmp      = oqi_keycmp,
        .hs_key         = oqi_key,
index 12113dfd87b8e614f948a9162442ba44b6f61894..367f83af12c008c7470732b3adf9ea05af57a7bb 100644 (file)
@@ -38,7 +38,6 @@
 
 #include "../../include/linux/libcfs/libcfs.h"
 
-
 #include "../include/lustre_dlm.h"
 #include "../include/lustre_net.h"
 #include "../include/lustre/lustre_user.h"
 #include "../include/lustre_param.h"
 #include "../include/lustre_fid.h"
 #include "../include/obd_class.h"
+#include "../include/obd.h"
 #include "osc_internal.h"
 #include "osc_cl_internal.h"
 
+atomic_t osc_pool_req_count;
+unsigned int osc_reqpool_maxreqcount;
+struct ptlrpc_request_pool *osc_rq_pool;
+
+/* max memory used for request pool, unit is MB */
+static unsigned int osc_reqpool_mem_max = 5;
+module_param(osc_reqpool_mem_max, uint, 0444);
+
 struct osc_brw_async_args {
        struct obdo       *aa_oa;
        int             aa_requested_nob;
@@ -63,7 +71,6 @@ struct osc_brw_async_args {
        struct client_obd *aa_cli;
        struct list_head         aa_oaps;
        struct list_head         aa_exts;
-       struct obd_capa   *aa_ocapa;
        struct cl_req     *aa_clerq;
 };
 
@@ -191,22 +198,6 @@ static int osc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
        return lsm_size;
 }
 
-static inline void osc_pack_capa(struct ptlrpc_request *req,
-                                struct ost_body *body, void *capa)
-{
-       struct obd_capa *oc = (struct obd_capa *)capa;
-       struct lustre_capa *c;
-
-       if (!capa)
-               return;
-
-       c = req_capsule_client_get(&req->rq_pill, &RMF_CAPA1);
-       LASSERT(c);
-       capa_cpy(c, oc);
-       body->oa.o_valid |= OBD_MD_FLOSSCAPA;
-       DEBUG_CAPA(D_SEC, c, "pack");
-}
-
 static inline void osc_pack_req_body(struct ptlrpc_request *req,
                                     struct obd_info *oinfo)
 {
@@ -217,18 +208,6 @@ static inline void osc_pack_req_body(struct ptlrpc_request *req,
 
        lustre_set_wire_obdo(&req->rq_import->imp_connect_data, &body->oa,
                             oinfo->oi_oa);
-       osc_pack_capa(req, body, oinfo->oi_capa);
-}
-
-static inline void osc_set_capa_size(struct ptlrpc_request *req,
-                                    const struct req_msg_field *field,
-                                    struct obd_capa *oc)
-{
-       if (oc == NULL)
-               req_capsule_set_size(&req->rq_pill, field, RCL_CLIENT, 0);
-       else
-               /* it is already calculated as sizeof struct obd_capa */
-               ;
 }
 
 static int osc_getattr_interpret(const struct lu_env *env,
@@ -270,7 +249,6 @@ static int osc_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
        if (req == NULL)
                return -ENOMEM;
 
-       osc_set_capa_size(req, &RMF_CAPA1, oinfo->oi_capa);
        rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_GETATTR);
        if (rc) {
                ptlrpc_request_free(req);
@@ -301,7 +279,6 @@ static int osc_getattr(const struct lu_env *env, struct obd_export *exp,
        if (req == NULL)
                return -ENOMEM;
 
-       osc_set_capa_size(req, &RMF_CAPA1, oinfo->oi_capa);
        rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_GETATTR);
        if (rc) {
                ptlrpc_request_free(req);
@@ -347,7 +324,6 @@ static int osc_setattr(const struct lu_env *env, struct obd_export *exp,
        if (req == NULL)
                return -ENOMEM;
 
-       osc_set_capa_size(req, &RMF_CAPA1, oinfo->oi_capa);
        rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_SETATTR);
        if (rc) {
                ptlrpc_request_free(req);
@@ -411,7 +387,6 @@ int osc_setattr_async_base(struct obd_export *exp, struct obd_info *oinfo,
        if (req == NULL)
                return -ENOMEM;
 
-       osc_set_capa_size(req, &RMF_CAPA1, oinfo->oi_capa);
        rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_SETATTR);
        if (rc) {
                ptlrpc_request_free(req);
@@ -428,19 +403,19 @@ int osc_setattr_async_base(struct obd_export *exp, struct obd_info *oinfo,
        /* do mds to ost setattr asynchronously */
        if (!rqset) {
                /* Do not wait for response. */
-               ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+               ptlrpcd_add_req(req);
        } else {
                req->rq_interpret_reply =
                        (ptlrpc_interpterer_t)osc_setattr_interpret;
 
-               CLASSERT (sizeof(*sa) <= sizeof(req->rq_async_args));
+               CLASSERT(sizeof(*sa) <= sizeof(req->rq_async_args));
                sa = ptlrpc_req_async_args(req);
                sa->sa_oa = oinfo->oi_oa;
                sa->sa_upcall = upcall;
                sa->sa_cookie = cookie;
 
                if (rqset == PTLRPCD_SET)
-                       ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+                       ptlrpcd_add_req(req);
                else
                        ptlrpc_set_add_req(rqset, req);
        }
@@ -557,7 +532,6 @@ int osc_punch_base(struct obd_export *exp, struct obd_info *oinfo,
        if (req == NULL)
                return -ENOMEM;
 
-       osc_set_capa_size(req, &RMF_CAPA1, oinfo->oi_capa);
        rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_PUNCH);
        if (rc) {
                ptlrpc_request_free(req);
@@ -570,18 +544,17 @@ int osc_punch_base(struct obd_export *exp, struct obd_info *oinfo,
        LASSERT(body);
        lustre_set_wire_obdo(&req->rq_import->imp_connect_data, &body->oa,
                             oinfo->oi_oa);
-       osc_pack_capa(req, body, oinfo->oi_capa);
 
        ptlrpc_request_set_replen(req);
 
        req->rq_interpret_reply = (ptlrpc_interpterer_t)osc_setattr_interpret;
-       CLASSERT (sizeof(*sa) <= sizeof(req->rq_async_args));
+       CLASSERT(sizeof(*sa) <= sizeof(req->rq_async_args));
        sa = ptlrpc_req_async_args(req);
        sa->sa_oa = oinfo->oi_oa;
        sa->sa_upcall = upcall;
        sa->sa_cookie = cookie;
        if (rqset == PTLRPCD_SET)
-               ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+               ptlrpcd_add_req(req);
        else
                ptlrpc_set_add_req(rqset, req);
 
@@ -600,7 +573,7 @@ static int osc_sync_interpret(const struct lu_env *env,
 
        body = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
        if (body == NULL) {
-               CERROR ("can't unpack ost_body\n");
+               CERROR("can't unpack ost_body\n");
                rc = -EPROTO;
                goto out;
        }
@@ -624,7 +597,6 @@ int osc_sync_base(struct obd_export *exp, struct obd_info *oinfo,
        if (req == NULL)
                return -ENOMEM;
 
-       osc_set_capa_size(req, &RMF_CAPA1, oinfo->oi_capa);
        rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_SYNC);
        if (rc) {
                ptlrpc_request_free(req);
@@ -636,7 +608,6 @@ int osc_sync_base(struct obd_export *exp, struct obd_info *oinfo,
        LASSERT(body);
        lustre_set_wire_obdo(&req->rq_import->imp_connect_data, &body->oa,
                             oinfo->oi_oa);
-       osc_pack_capa(req, body, oinfo->oi_capa);
 
        ptlrpc_request_set_replen(req);
        req->rq_interpret_reply = osc_sync_interpret;
@@ -648,7 +619,7 @@ int osc_sync_base(struct obd_export *exp, struct obd_info *oinfo,
        fa->fa_cookie = cookie;
 
        if (rqset == PTLRPCD_SET)
-               ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+               ptlrpcd_add_req(req);
        else
                ptlrpc_set_add_req(rqset, req);
 
@@ -754,8 +725,7 @@ int osc_create(const struct lu_env *env, struct obd_export *exp,
  * cookies to the MDS after committing destroy transactions. */
 static int osc_destroy(const struct lu_env *env, struct obd_export *exp,
                       struct obdo *oa, struct lov_stripe_md *ea,
-                      struct obd_trans_info *oti, struct obd_export *md_export,
-                      void *capa)
+                      struct obd_trans_info *oti, struct obd_export *md_export)
 {
        struct client_obd *cli = &exp->exp_obd->u.cli;
        struct ptlrpc_request *req;
@@ -777,7 +747,6 @@ static int osc_destroy(const struct lu_env *env, struct obd_export *exp,
                return -ENOMEM;
        }
 
-       osc_set_capa_size(req, &RMF_CAPA1, (struct obd_capa *)capa);
        rc = ldlm_prep_elc_req(exp, req, LUSTRE_OST_VERSION, OST_DESTROY,
                               0, &cancels, count);
        if (rc) {
@@ -794,7 +763,6 @@ static int osc_destroy(const struct lu_env *env, struct obd_export *exp,
        LASSERT(body);
        lustre_set_wire_obdo(&req->rq_import->imp_connect_data, &body->oa, oa);
 
-       osc_pack_capa(req, body, (struct obd_capa *)capa);
        ptlrpc_request_set_replen(req);
 
        /* If osc_destroy is for destroying the unlink orphan,
@@ -817,7 +785,7 @@ static int osc_destroy(const struct lu_env *env, struct obd_export *exp,
        }
 
        /* Do not wait for response */
-       ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+       ptlrpcd_add_req(req);
        return 0;
 }
 
@@ -910,7 +878,7 @@ static int osc_shrink_grant_interpret(const struct lu_env *env,
        LASSERT(body);
        osc_update_grant(cli, body);
 out:
-       OBDO_FREE(oa);
+       kmem_cache_free(obdo_cachep, oa);
        return rc;
 }
 
@@ -1100,7 +1068,7 @@ static void handle_short_read(int nob_read, u32 page_count,
 
        /* skip bytes read OK */
        while (nob_read > 0) {
-               LASSERT (page_count > 0);
+               LASSERT(page_count > 0);
 
                if (pga[i]->count > nob_read) {
                        /* EOF inside this page */
@@ -1210,6 +1178,7 @@ static u32 osc_checksum_bulk(int nob, u32 pg_count,
                    OBD_FAIL_CHECK(OBD_FAIL_OSC_CHECKSUM_RECEIVE)) {
                        unsigned char *ptr = kmap(pga[i]->pg);
                        int off = pga[i]->off & ~CFS_PAGE_MASK;
+
                        memcpy(ptr + off, "bad1", min(4, nob));
                        kunmap(pga[i]->pg);
                }
@@ -1247,7 +1216,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
                                struct lov_stripe_md *lsm, u32 page_count,
                                struct brw_page **pga,
                                struct ptlrpc_request **reqp,
-                               struct obd_capa *ocapa, int reserve,
+                               int reserve,
                                int resend)
 {
        struct ptlrpc_request *req;
@@ -1268,7 +1237,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
        if ((cmd & OBD_BRW_WRITE) != 0) {
                opc = OST_WRITE;
                req = ptlrpc_request_alloc_pool(cli->cl_import,
-                                               cli->cl_import->imp_rq_pool,
+                                               osc_rq_pool,
                                                &RQF_OST_BRW_WRITE);
        } else {
                opc = OST_READ;
@@ -1287,7 +1256,6 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
                             sizeof(*ioobj));
        req_capsule_set_size(pill, &RMF_NIOBUF_REMOTE, RCL_CLIENT,
                             niocount * sizeof(*niobuf));
-       osc_set_capa_size(req, &RMF_CAPA1, ocapa);
 
        rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, opc);
        if (rc) {
@@ -1326,7 +1294,6 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
         * "max - 1" for old client compatibility sending "0", and also so the
         * the actual maximum is a power-of-two number, not one less. LU-1431 */
        ioobj_max_brw_set(ioobj, desc->bd_md_max_brw);
-       osc_pack_capa(req, body, ocapa);
        LASSERT(page_count > 0);
        pg_prev = pga[0];
        for (requested_nob = i = 0; i < page_count; i++, niobuf++) {
@@ -1435,8 +1402,6 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
        aa->aa_ppga = pga;
        aa->aa_cli = cli;
        INIT_LIST_HEAD(&aa->aa_oaps);
-       if (ocapa && reserve)
-               aa->aa_ocapa = capa_get(ocapa);
 
        *reqp = req;
        return 0;
@@ -1571,7 +1536,7 @@ static int osc_brw_fini_request(struct ptlrpc_request *req, int rc)
        }
 
        if (rc != req->rq_bulk->bd_nob_transferred) {
-               CERROR ("Unexpected rc %d (%d transferred)\n",
+               CERROR("Unexpected rc %d (%d transferred)\n",
                        rc, req->rq_bulk->bd_nob_transferred);
                return -EPROTO;
        }
@@ -1582,19 +1547,17 @@ static int osc_brw_fini_request(struct ptlrpc_request *req, int rc)
        if (body->oa.o_valid & OBD_MD_FLCKSUM) {
                static int cksum_counter;
                __u32 server_cksum = body->oa.o_cksum;
-               char *via;
-               char *router;
+               char *via = "";
+               char *router = "";
                cksum_type_t cksum_type;
 
-               cksum_type = cksum_type_unpack(body->oa.o_valid &OBD_MD_FLFLAGS?
+               cksum_type = cksum_type_unpack(body->oa.o_valid&OBD_MD_FLFLAGS ?
                                               body->oa.o_flags : 0);
                client_cksum = osc_checksum_bulk(rc, aa->aa_page_count,
                                                 aa->aa_ppga, OST_READ,
                                                 cksum_type);
 
-               if (peer->nid == req->rq_bulk->bd_sender) {
-                       via = router = "";
-               } else {
+               if (peer->nid != req->rq_bulk->bd_sender) {
                        via = " via ";
                        router = libcfs_nid2str(req->rq_bulk->bd_sender);
                }
@@ -1654,11 +1617,11 @@ static int osc_brw_redo_request(struct ptlrpc_request *request,
                  "redo for recoverable error %d", rc);
 
        rc = osc_brw_prep_request(lustre_msg_get_opc(request->rq_reqmsg) ==
-                                       OST_WRITE ? OBD_BRW_WRITE :OBD_BRW_READ,
+                                       OST_WRITE ? OBD_BRW_WRITE : OBD_BRW_READ,
                                  aa->aa_cli, aa->aa_oa,
                                  NULL /* lsm unused by osc currently */,
                                  aa->aa_page_count, aa->aa_ppga,
-                                 &new_req, aa->aa_ocapa, 0, 1);
+                                 &new_req, 0, 1);
        if (rc)
                return rc;
 
@@ -1681,9 +1644,9 @@ static int osc_brw_redo_request(struct ptlrpc_request *request,
        /* cap resend delay to the current request timeout, this is similar to
         * what ptlrpc does (see after_reply()) */
        if (aa->aa_resends > new_req->rq_timeout)
-               new_req->rq_sent = get_seconds() + new_req->rq_timeout;
+               new_req->rq_sent = ktime_get_real_seconds() + new_req->rq_timeout;
        else
-               new_req->rq_sent = get_seconds() + aa->aa_resends;
+               new_req->rq_sent = ktime_get_real_seconds() + aa->aa_resends;
        new_req->rq_generation_set = 1;
        new_req->rq_import_generation = request->rq_import_generation;
 
@@ -1702,14 +1665,11 @@ static int osc_brw_redo_request(struct ptlrpc_request *request,
                }
        }
 
-       new_aa->aa_ocapa = aa->aa_ocapa;
-       aa->aa_ocapa = NULL;
-
        /* XXX: This code will run into problem if we're going to support
         * to add a series of BRW RPCs into a self-defined ptlrpc_request_set
         * and wait for all of them to be finished. We should inherit request
         * set from old request. */
-       ptlrpcd_add_req(new_req, PDL_POLICY_SAME, -1);
+       ptlrpcd_add_req(new_req);
 
        DEBUG_REQ(D_INFO, new_req, "new request");
        return 0;
@@ -1786,11 +1746,6 @@ static int brw_interpret(const struct lu_env *env,
                        rc = -EIO;
        }
 
-       if (aa->aa_ocapa) {
-               capa_put(aa->aa_ocapa);
-               aa->aa_ocapa = NULL;
-       }
-
        list_for_each_entry_safe(ext, tmp, &aa->aa_exts, oe_link) {
                if (obj == NULL && rc == 0) {
                        obj = osc2cl(ext->oe_obj);
@@ -1832,7 +1787,7 @@ static int brw_interpret(const struct lu_env *env,
                }
                cl_object_put(env, obj);
        }
-       OBDO_FREE(aa->aa_oa);
+       kmem_cache_free(obdo_cachep, aa->aa_oa);
 
        cl_req_completion(env, aa->aa_clerq, rc < 0 ? rc :
                          req->rq_bulk->bd_nob_transferred);
@@ -1850,7 +1805,7 @@ static int brw_interpret(const struct lu_env *env,
        osc_wake_cache_waiters(cli);
        client_obd_list_unlock(&cli->cl_loi_list_lock);
 
-       osc_io_unplug(env, cli, NULL, PDL_POLICY_SAME);
+       osc_io_unplug(env, cli, NULL);
        return rc;
 }
 
@@ -1860,7 +1815,7 @@ static int brw_interpret(const struct lu_env *env,
  * Extents in the list must be in OES_RPC state.
  */
 int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
-                 struct list_head *ext_list, int cmd, pdl_policy_t pol)
+                 struct list_head *ext_list, int cmd)
 {
        struct ptlrpc_request *req = NULL;
        struct osc_extent *ext;
@@ -1920,7 +1875,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
                goto out;
        }
 
-       OBDO_ALLOC(oa);
+       oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
        if (oa == NULL) {
                rc = -ENOMEM;
                goto out;
@@ -1929,6 +1884,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
        i = 0;
        list_for_each_entry(oap, &rpc_list, oap_rpc_item) {
                struct cl_page *page = oap2cl_page(oap);
+
                if (clerq == NULL) {
                        clerq = cl_req_alloc(env, page, crt,
                                             1 /* only 1-object rpcs for now */);
@@ -1966,7 +1922,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
 
        sort_brw_pages(pga, page_count);
        rc = osc_brw_prep_request(cmd, cli, oa, NULL, page_count,
-                       pga, &req, crattr->cra_capa, 1, 0);
+                       pga, &req, 1, 0);
        if (rc != 0) {
                CERROR("prep_req failed: %d\n", rc);
                goto out;
@@ -2034,35 +1990,20 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
                  page_count, aa, cli->cl_r_in_flight,
                  cli->cl_w_in_flight);
 
-       /* XXX: Maybe the caller can check the RPC bulk descriptor to
-        * see which CPU/NUMA node the majority of pages were allocated
-        * on, and try to assign the async RPC to the CPU core
-        * (PDL_POLICY_PREFERRED) to reduce cross-CPU memory traffic.
-        *
-        * But on the other hand, we expect that multiple ptlrpcd
-        * threads and the initial write sponsor can run in parallel,
-        * especially when data checksum is enabled, which is CPU-bound
-        * operation and single ptlrpcd thread cannot process in time.
-        * So more ptlrpcd threads sharing BRW load
-        * (with PDL_POLICY_ROUND) seems better.
-        */
-       ptlrpcd_add_req(req, pol, -1);
+       ptlrpcd_add_req(req);
        rc = 0;
 
 out:
        if (mem_tight != 0)
                cfs_memory_pressure_restore(mpflag);
 
-       if (crattr != NULL) {
-               capa_put(crattr->cra_capa);
-               kfree(crattr);
-       }
+       kfree(crattr);
 
        if (rc != 0) {
                LASSERT(req == NULL);
 
                if (oa)
-                       OBDO_FREE(oa);
+                       kmem_cache_free(obdo_cachep, oa);
                kfree(pga);
                /* this should happen rarely and is pretty bad, it makes the
                 * pending list not follow the dirty order */
@@ -2149,6 +2090,7 @@ static int osc_enqueue_fini(struct ptlrpc_request *req, struct ost_lvb *lvb,
                /* The request was created before ldlm_cli_enqueue call. */
                if (rc == ELDLM_LOCK_ABORTED) {
                        struct ldlm_reply *rep;
+
                        rep = req_capsule_server_get(&req->rq_pill,
                                                     &RMF_DLM_REP);
 
@@ -2335,6 +2277,7 @@ int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
  no_match:
        if (intent) {
                LIST_HEAD(cancels);
+
                req = ptlrpc_request_alloc(class_exp2cliimp(exp),
                                           &RQF_LDLM_ENQUEUE_LVB);
                if (req == NULL)
@@ -2359,6 +2302,7 @@ int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
        if (rqset) {
                if (!rc) {
                        struct osc_enqueue_args *aa;
+
                        CLASSERT (sizeof(*aa) <= sizeof(req->rq_async_args));
                        aa = ptlrpc_req_async_args(req);
                        aa->oa_ei = einfo;
@@ -2373,7 +2317,7 @@ int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
                        req->rq_interpret_reply =
                                (ptlrpc_interpterer_t)osc_enqueue_interpret;
                        if (rqset == PTLRPCD_SET)
-                               ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+                               ptlrpcd_add_req(req);
                        else
                                ptlrpc_set_add_req(rqset, req);
                } else if (intent) {
@@ -2645,7 +2589,6 @@ static int osc_getstripe(struct lov_stripe_md *lsm, struct lov_user_md *lump)
        return rc;
 }
 
-
 static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                         void *karg, void *uarg)
 {
@@ -2720,7 +2663,7 @@ static int osc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                                               data->ioc_offset);
                goto out;
        case OBD_IOC_POLL_QUOTACHECK:
-               err = osc_quota_poll_check(exp, (struct if_quotacheck *)karg);
+               err = osc_quota_poll_check(exp, karg);
                goto out;
        case OBD_IOC_PING_TARGET:
                err = ptlrpc_obd_ping(obd);
@@ -2787,8 +2730,7 @@ static int osc_get_info(const struct lu_env *env, struct obd_export *exp,
                ptlrpc_req_finished(req);
                return rc;
        } else if (KEY_IS(KEY_FIEMAP)) {
-               struct ll_fiemap_info_key *fm_key =
-                               (struct ll_fiemap_info_key *)key;
+               struct ll_fiemap_info_key *fm_key = key;
                struct ldlm_res_id res_id;
                ldlm_policy_data_t policy;
                struct lustre_handle lockh;
@@ -2910,7 +2852,7 @@ static int osc_set_info_async(const struct lu_env *env, struct obd_export *exp,
                struct client_obd *cli = &obd->u.cli;
 
                LASSERT(cli->cl_cache == NULL); /* only once */
-               cli->cl_cache = (struct cl_client_cache *)val;
+               cli->cl_cache = val;
                atomic_inc(&cli->cl_cache->ccc_users);
                cli->cl_lru_left = &cli->cl_cache->ccc_lru_left;
 
@@ -2973,7 +2915,7 @@ static int osc_set_info_async(const struct lu_env *env, struct obd_export *exp,
 
                CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args));
                aa = ptlrpc_req_async_args(req);
-               OBDO_ALLOC(oa);
+               oa = kmem_cache_alloc(obdo_cachep, GFP_NOFS | __GFP_ZERO);
                if (!oa) {
                        ptlrpc_req_finished(req);
                        return -ENOMEM;
@@ -2988,8 +2930,9 @@ static int osc_set_info_async(const struct lu_env *env, struct obd_export *exp,
                LASSERT(set != NULL);
                ptlrpc_set_add_req(set, req);
                ptlrpc_check_set(NULL, set);
-       } else
-               ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+       } else {
+               ptlrpcd_add_req(req);
+       }
 
        return 0;
 }
@@ -3081,7 +3024,7 @@ static int osc_import_event(struct obd_device *obd,
                        cli = &obd->u.cli;
                        /* all pages go to failing rpcs due to the invalid
                         * import */
-                       osc_io_unplug(env, cli, NULL, PDL_POLICY_ROUND);
+                       osc_io_unplug(env, cli, NULL);
 
                        ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
                        cl_env_put(env, &refcheck);
@@ -3101,7 +3044,7 @@ static int osc_import_event(struct obd_device *obd,
 
                /* See bug 7198 */
                if (ocd->ocd_connect_flags & OBD_CONNECT_REQPORTAL)
-                       imp->imp_client->cli_request_portal =OST_REQUEST_PORTAL;
+                       imp->imp_client->cli_request_portal = OST_REQUEST_PORTAL;
 
                rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
                break;
@@ -3153,7 +3096,7 @@ static int brw_queue_work(const struct lu_env *env, void *data)
 
        CDEBUG(D_CACHE, "Run writeback work for client obd %p.\n", cli);
 
-       osc_io_unplug(env, cli, NULL, PDL_POLICY_SAME);
+       osc_io_unplug(env, cli, NULL);
        return 0;
 }
 
@@ -3163,6 +3106,9 @@ int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
        struct client_obd *cli = &obd->u.cli;
        void *handler;
        int rc;
+       int adding;
+       int added;
+       int req_count;
 
        rc = ptlrpcd_addref();
        if (rc)
@@ -3191,15 +3137,20 @@ int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
                ptlrpc_lprocfs_register_obd(obd);
        }
 
-       /* We need to allocate a few requests more, because
-        * brw_interpret tries to create new requests before freeing
-        * previous ones, Ideally we want to have 2x max_rpcs_in_flight
-        * reserved, but I'm afraid that might be too much wasted RAM
-        * in fact, so 2 is just my guess and still should work. */
-       cli->cl_import->imp_rq_pool =
-               ptlrpc_init_rq_pool(cli->cl_max_rpcs_in_flight + 2,
-                                   OST_MAXREQSIZE,
-                                   ptlrpc_add_rqs_to_pool);
+       /*
+        * We try to control the total number of requests with a upper limit
+        * osc_reqpool_maxreqcount. There might be some race which will cause
+        * over-limit allocation, but it is fine.
+        */
+       req_count = atomic_read(&osc_pool_req_count);
+       if (req_count < osc_reqpool_maxreqcount) {
+               adding = cli->cl_max_rpcs_in_flight + 2;
+               if (req_count + adding > osc_reqpool_maxreqcount)
+                       adding = osc_reqpool_maxreqcount - req_count;
+
+               added = ptlrpc_add_rqs_to_pool(osc_rq_pool, adding);
+               atomic_add(added, &osc_pool_req_count);
+       }
 
        INIT_LIST_HEAD(&cli->cl_grant_shrink_list);
        ns_register_cancel(obd->obd_namespace, osc_cancel_for_recovery);
@@ -3219,6 +3170,7 @@ static int osc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
        switch (stage) {
        case OBD_CLEANUP_EARLY: {
                struct obd_import *imp;
+
                imp = obd->u.cli.cl_import;
                CDEBUG(D_HA, "Deactivating import %s\n", obd->obd_name);
                /* ptlrpc_abort_inflight to stop an mds_lov_synchronize */
@@ -3339,6 +3291,8 @@ extern struct lock_class_key osc_ast_guard_class;
 static int __init osc_init(void)
 {
        struct lprocfs_static_vars lvars = { NULL };
+       unsigned int reqpool_size;
+       unsigned int reqsize;
        int rc;
 
        /* print an address of _any_ initialized kernel symbol from this
@@ -3354,14 +3308,45 @@ static int __init osc_init(void)
 
        rc = class_register_type(&osc_obd_ops, NULL,
                                 LUSTRE_OSC_NAME, &osc_device_type);
-       if (rc) {
-               lu_kmem_fini(osc_caches);
-               return rc;
-       }
+       if (rc)
+               goto out_kmem;
 
        spin_lock_init(&osc_ast_guard);
        lockdep_set_class(&osc_ast_guard, &osc_ast_guard_class);
 
+       /* This is obviously too much memory, only prevent overflow here */
+       if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0) {
+               rc = -EINVAL;
+               goto out_type;
+       }
+
+       reqpool_size = osc_reqpool_mem_max << 20;
+
+       reqsize = 1;
+       while (reqsize < OST_MAXREQSIZE)
+               reqsize = reqsize << 1;
+
+       /*
+        * We don't enlarge the request count in OSC pool according to
+        * cl_max_rpcs_in_flight. The allocation from the pool will only be
+        * tried after normal allocation failed. So a small OSC pool won't
+        * cause much performance degression in most of cases.
+        */
+       osc_reqpool_maxreqcount = reqpool_size / reqsize;
+
+       atomic_set(&osc_pool_req_count, 0);
+       osc_rq_pool = ptlrpc_init_rq_pool(0, OST_MAXREQSIZE,
+                                         ptlrpc_add_rqs_to_pool);
+
+       if (osc_rq_pool)
+               return 0;
+
+       rc = -ENOMEM;
+
+out_type:
+       class_unregister_type(LUSTRE_OSC_NAME);
+out_kmem:
+       lu_kmem_fini(osc_caches);
        return rc;
 }
 
@@ -3369,6 +3354,7 @@ static void /*__exit*/ osc_exit(void)
 {
        class_unregister_type(LUSTRE_OSC_NAME);
        lu_kmem_fini(osc_caches);
+       ptlrpc_free_rq_pool(osc_rq_pool);
 }
 
 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
index c83a34a01e659cea3b2d583d1d1711e97f2d953b..a9f1bf536da9b014b010c7aef2164b3e6e58ae08 100644 (file)
@@ -72,9 +72,11 @@ struct ptlrpc_connection *ptlrpc_uuid_to_connection(struct obd_uuid *uuid)
        lnet_process_id_t peer;
        int err;
 
-       /* ptlrpc_uuid_to_peer() initializes its 2nd parameter
-        * before accessing its values. */
-       /* coverity[uninit_use_in_call] */
+       /*
+        * ptlrpc_uuid_to_peer() initializes its 2nd parameter
+        * before accessing its values.
+        * coverity[uninit_use_in_call]
+        */
        err = ptlrpc_uuid_to_peer(uuid, &peer, &self);
        if (err != 0) {
                CNETERR("cannot find peer %s!\n", uuid->uuid);
@@ -117,8 +119,10 @@ struct ptlrpc_bulk_desc *ptlrpc_new_bulk(unsigned npages, unsigned max_brw,
        desc->bd_md_count = 0;
        LASSERT(max_brw > 0);
        desc->bd_md_max_brw = min(max_brw, PTLRPC_BULK_OPS_COUNT);
-       /* PTLRPC_BULK_OPS_COUNT is the compile-time transfer limit for this
-        * node. Negotiated ocd_brw_size will always be <= this number. */
+       /*
+        * PTLRPC_BULK_OPS_COUNT is the compile-time transfer limit for this
+        * node. Negotiated ocd_brw_size will always be <= this number.
+        */
        for (i = 0; i < PTLRPC_BULK_OPS_COUNT; i++)
                LNetInvalidateHandle(&desc->bd_mds[i]);
 
@@ -223,8 +227,9 @@ void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req)
        LASSERT(req->rq_import);
 
        if (AT_OFF) {
-               /* non-AT settings */
-               /**
+               /*
+                * non-AT settings
+                *
                 * \a imp_server_timeout means this is reverse import and
                 * we send (currently only) ASTs to the client and cannot afford
                 * to wait too long for the reply, otherwise the other client
@@ -240,11 +245,15 @@ void ptlrpc_at_set_req_timeout(struct ptlrpc_request *req)
                serv_est = at_get(&at->iat_service_estimate[idx]);
                req->rq_timeout = at_est2timeout(serv_est);
        }
-       /* We could get even fancier here, using history to predict increased
-          loading... */
+       /*
+        * We could get even fancier here, using history to predict increased
+        * loading...
+        */
 
-       /* Let the server know what this RPC timeout is by putting it in the
-          reqmsg*/
+       /*
+        * Let the server know what this RPC timeout is by putting it in the
+        * reqmsg
+        */
        lustre_msg_set_timeout(req->rq_reqmsg, req->rq_timeout);
 }
 EXPORT_SYMBOL(ptlrpc_at_set_req_timeout);
@@ -261,8 +270,10 @@ static void ptlrpc_at_adj_service(struct ptlrpc_request *req,
        at = &req->rq_import->imp_at;
 
        idx = import_at_get_index(req->rq_import, req->rq_request_portal);
-       /* max service estimates are tracked on the server side,
-          so just keep minimal history here */
+       /*
+        * max service estimates are tracked on the server side,
+        * so just keep minimal history here
+        */
        oldse = at_measured(&at->iat_service_estimate[idx], serv_est);
        if (oldse != 0)
                CDEBUG(D_ADAPTTO, "The RPC service estimate for %s ptl %d has changed from %d to %d\n",
@@ -282,12 +293,13 @@ static void ptlrpc_at_adj_net_latency(struct ptlrpc_request *req,
 {
        unsigned int nl, oldnl;
        struct imp_at *at;
-       time_t now = get_seconds();
+       time64_t now = ktime_get_real_seconds();
 
        LASSERT(req->rq_import);
 
        if (service_time > now - req->rq_sent + 3) {
-               /* bz16408, however, this can also happen if early reply
+               /*
+                * bz16408, however, this can also happen if early reply
                 * is lost and client RPC is expired and resent, early reply
                 * or reply of original RPC can still be fit in reply buffer
                 * of resent RPC, now client is measuring time from the
@@ -298,7 +310,7 @@ static void ptlrpc_at_adj_net_latency(struct ptlrpc_request *req,
                       D_ADAPTTO : D_WARNING,
                       "Reported service time %u > total measured time "
                       CFS_DURATION_T"\n", service_time,
-                      cfs_time_sub(now, req->rq_sent));
+                      (long)(now - req->rq_sent));
                return;
        }
 
@@ -343,7 +355,7 @@ static int unpack_reply(struct ptlrpc_request *req)
 static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req)
 {
        struct ptlrpc_request *early_req;
-       time_t olddl;
+       time64_t olddl;
        int rc;
 
        req->rq_early = 0;
@@ -376,16 +388,18 @@ static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req)
 
        spin_lock(&req->rq_lock);
        olddl = req->rq_deadline;
-       /* server assumes it now has rq_timeout from when it sent the
-        * early reply, so client should give it at least that long. */
-       req->rq_deadline = get_seconds() + req->rq_timeout +
+       /*
+        * server assumes it now has rq_timeout from when it sent the
+        * early reply, so client should give it at least that long.
+        */
+       req->rq_deadline = ktime_get_real_seconds() + req->rq_timeout +
                           ptlrpc_at_get_net_latency(req);
 
        DEBUG_REQ(D_ADAPTTO, req,
-                 "Early reply #%d, new deadline in " CFS_DURATION_T "s (" CFS_DURATION_T "s)",
+                 "Early reply #%d, new deadline in %lds (%lds)",
                  req->rq_early_count,
-                 cfs_time_sub(req->rq_deadline, get_seconds()),
-                 cfs_time_sub(req->rq_deadline, olddl));
+                 (long)(req->rq_deadline - ktime_get_real_seconds()),
+                 (long)(req->rq_deadline - olddl));
 
        return rc;
 }
@@ -409,13 +423,13 @@ struct ptlrpc_request *ptlrpc_request_cache_alloc(gfp_t flags)
 {
        struct ptlrpc_request *req;
 
-       OBD_SLAB_ALLOC_PTR_GFP(req, request_cache, flags);
+       req = kmem_cache_alloc(request_cache, flags | __GFP_ZERO);
        return req;
 }
 
 void ptlrpc_request_cache_free(struct ptlrpc_request *req)
 {
-       OBD_SLAB_FREE_PTR(req, request_cache);
+       kmem_cache_free(request_cache, req);
 }
 
 /**
@@ -446,7 +460,7 @@ EXPORT_SYMBOL(ptlrpc_free_rq_pool);
 /**
  * Allocates, initializes and adds \a num_rq requests to the pool \a pool
  */
-void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
+int ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
 {
        int i;
        int size = 1;
@@ -468,11 +482,11 @@ void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
                spin_unlock(&pool->prp_lock);
                req = ptlrpc_request_cache_alloc(GFP_NOFS);
                if (!req)
-                       return;
+                       return i;
                msg = libcfs_kvzalloc(size, GFP_NOFS);
                if (!msg) {
                        ptlrpc_request_cache_free(req);
-                       return;
+                       return i;
                }
                req->rq_reqbuf = msg;
                req->rq_reqbuf_len = size;
@@ -481,6 +495,7 @@ void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
                list_add_tail(&req->rq_list, &pool->prp_req_list);
        }
        spin_unlock(&pool->prp_lock);
+       return num_rq;
 }
 EXPORT_SYMBOL(ptlrpc_add_rqs_to_pool);
 
@@ -494,7 +509,7 @@ EXPORT_SYMBOL(ptlrpc_add_rqs_to_pool);
  */
 struct ptlrpc_request_pool *
 ptlrpc_init_rq_pool(int num_rq, int msgsize,
-                   void (*populate_pool)(struct ptlrpc_request_pool *, int))
+                   int (*populate_pool)(struct ptlrpc_request_pool *, int))
 {
        struct ptlrpc_request_pool *pool;
 
@@ -502,8 +517,10 @@ ptlrpc_init_rq_pool(int num_rq, int msgsize,
        if (!pool)
                return NULL;
 
-       /* Request next power of two for the allocation, because internally
-          kernel would do exactly this */
+       /*
+        * Request next power of two for the allocation, because internally
+        * kernel would do exactly this
+        */
 
        spin_lock_init(&pool->prp_lock);
        INIT_LIST_HEAD(&pool->prp_req_list);
@@ -512,11 +529,6 @@ ptlrpc_init_rq_pool(int num_rq, int msgsize,
 
        populate_pool(pool, num_rq);
 
-       if (list_empty(&pool->prp_req_list)) {
-               /* have not allocated a single request for the pool */
-               kfree(pool);
-               pool = NULL;
-       }
        return pool;
 }
 EXPORT_SYMBOL(ptlrpc_init_rq_pool);
@@ -535,10 +547,12 @@ ptlrpc_prep_req_from_pool(struct ptlrpc_request_pool *pool)
 
        spin_lock(&pool->prp_lock);
 
-       /* See if we have anything in a pool, and bail out if nothing,
+       /*
+        * See if we have anything in a pool, and bail out if nothing,
         * in writeout path, where this matters, this is safe to do, because
         * nothing is lost in this case, and when some in-flight requests
-        * complete, this code will be called again. */
+        * complete, this code will be called again.
+        */
        if (unlikely(list_empty(&pool->prp_req_list))) {
                spin_unlock(&pool->prp_lock);
                return NULL;
@@ -664,11 +678,13 @@ int ptlrpc_request_pack(struct ptlrpc_request *request,
                        __u32 version, int opcode)
 {
        int rc;
+
        rc = ptlrpc_request_bufs_pack(request, version, opcode, NULL, NULL);
        if (rc)
                return rc;
 
-       /* For some old 1.8 clients (< 1.8.7), they will LASSERT the size of
+       /*
+        * For some old 1.8 clients (< 1.8.7), they will LASSERT the size of
         * ptlrpc_body sent from server equal to local ptlrpc_body size, so we
         * have to send old ptlrpc_body to keep interoperability with these
         * clients.
@@ -700,13 +716,12 @@ static inline
 struct ptlrpc_request *__ptlrpc_request_alloc(struct obd_import *imp,
                                              struct ptlrpc_request_pool *pool)
 {
-       struct ptlrpc_request *request = NULL;
+       struct ptlrpc_request *request;
 
-       if (pool)
-               request = ptlrpc_prep_req_from_pool(pool);
+       request = ptlrpc_request_cache_alloc(GFP_NOFS);
 
-       if (!request)
-               request = ptlrpc_request_cache_alloc(GFP_NOFS);
+       if (!request && pool)
+               request = ptlrpc_prep_req_from_pool(pool);
 
        if (request) {
                LASSERTF((unsigned long)imp > 0x1000, "%p", imp);
@@ -807,56 +822,17 @@ struct ptlrpc_request *ptlrpc_request_alloc_pack(struct obd_import *imp,
 EXPORT_SYMBOL(ptlrpc_request_alloc_pack);
 
 /**
- * Prepare request (fetched from pool \a pool if not NULL) on import \a imp
- * for operation \a opcode. Request would contain \a count buffers.
- * Sizes of buffers are described in array \a lengths and buffers themselves
- * are provided by a pointer \a bufs.
- * Returns prepared request structure pointer or NULL on error.
- */
-struct ptlrpc_request *
-ptlrpc_prep_req_pool(struct obd_import *imp,
-                    __u32 version, int opcode,
-                    int count, __u32 *lengths, char **bufs,
-                    struct ptlrpc_request_pool *pool)
-{
-       struct ptlrpc_request *request;
-       int rc;
-
-       request = __ptlrpc_request_alloc(imp, pool);
-       if (!request)
-               return NULL;
-
-       rc = __ptlrpc_request_bufs_pack(request, version, opcode, count,
-                                       lengths, bufs, NULL);
-       if (rc) {
-               ptlrpc_request_free(request);
-               request = NULL;
-       }
-       return request;
-}
-EXPORT_SYMBOL(ptlrpc_prep_req_pool);
-
-/**
- * Same as ptlrpc_prep_req_pool, but without pool
- */
-struct ptlrpc_request *
-ptlrpc_prep_req(struct obd_import *imp, __u32 version, int opcode, int count,
-               __u32 *lengths, char **bufs)
-{
-       return ptlrpc_prep_req_pool(imp, version, opcode, count, lengths, bufs,
-                                   NULL);
-}
-EXPORT_SYMBOL(ptlrpc_prep_req);
-
-/**
- * Allocate and initialize new request set structure.
+ * Allocate and initialize new request set structure on the current CPT.
  * Returns a pointer to the newly allocated set structure or NULL on error.
  */
 struct ptlrpc_request_set *ptlrpc_prep_set(void)
 {
        struct ptlrpc_request_set *set;
+       int cpt;
 
-       set = kzalloc(sizeof(*set), GFP_NOFS);
+       cpt = cfs_cpt_current(cfs_cpt_table, 0);
+       set = kzalloc_node(sizeof(*set), GFP_NOFS,
+                          cfs_cpt_spread_node(cfs_cpt_table, cpt));
        if (!set)
                return NULL;
        atomic_set(&set->set_refcount, 1);
@@ -960,28 +936,6 @@ void ptlrpc_set_destroy(struct ptlrpc_request_set *set)
 }
 EXPORT_SYMBOL(ptlrpc_set_destroy);
 
-/**
- * Add a callback function \a fn to the set.
- * This function would be called when all requests on this set are completed.
- * The function will be passed \a data argument.
- */
-int ptlrpc_set_add_cb(struct ptlrpc_request_set *set,
-                     set_interpreter_func fn, void *data)
-{
-       struct ptlrpc_set_cbdata *cbdata;
-
-       cbdata = kzalloc(sizeof(*cbdata), GFP_NOFS);
-       if (!cbdata)
-               return -ENOMEM;
-
-       cbdata->psc_interpret = fn;
-       cbdata->psc_data = data;
-       list_add_tail(&cbdata->psc_item, &set->set_cblist);
-
-       return 0;
-}
-EXPORT_SYMBOL(ptlrpc_set_add_cb);
-
 /**
  * Add a new request to the general purpose request set.
  * Assumes request reference from the caller.
@@ -1001,8 +955,10 @@ void ptlrpc_set_add_req(struct ptlrpc_request_set *set,
                lustre_msg_set_jobid(req->rq_reqmsg, NULL);
 
        if (set->set_producer != NULL)
-               /* If the request set has a producer callback, the RPC must be
-                * sent straight away */
+               /*
+                * If the request set has a producer callback, the RPC must be
+                * sent straight away
+                */
                ptlrpc_send_new_req(req);
 }
 EXPORT_SYMBOL(ptlrpc_set_add_req);
@@ -1022,9 +978,7 @@ void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
        LASSERT(test_bit(LIOD_STOP, &pc->pc_flags) == 0);
 
        spin_lock(&set->set_new_req_lock);
-       /*
-        * The set takes over the caller's request reference.
-        */
+       /* The set takes over the caller's request reference.  */
        req->rq_set = set;
        req->rq_queued_time = cfs_time_current();
        list_add_tail(&req->rq_set_chain, &set->set_new_requests);
@@ -1035,9 +989,11 @@ void ptlrpc_set_add_new_req(struct ptlrpcd_ctl *pc,
        if (count == 1) {
                wake_up(&set->set_waitq);
 
-               /* XXX: It maybe unnecessary to wakeup all the partners. But to
+               /*
+                * XXX: It maybe unnecessary to wakeup all the partners. But to
                 *      guarantee the async RPC can be processed ASAP, we have
-                *      no other better choice. It maybe fixed in future. */
+                *      no other better choice. It maybe fixed in future.
+                */
                for (i = 0; i < pc->pc_npartners; i++)
                        wake_up(&pc->pc_partners[i]->pc_set->set_waitq);
        }
@@ -1125,8 +1081,10 @@ static int ptlrpc_console_allow(struct ptlrpc_request *req)
        LASSERT(req->rq_reqmsg != NULL);
        opc = lustre_msg_get_opc(req->rq_reqmsg);
 
-       /* Suppress particular reconnect errors which are to be expected.  No
-        * errors are suppressed for the initial connection on an import */
+       /*
+        * Suppress particular reconnect errors which are to be expected.  No
+        * errors are suppressed for the initial connection on an import
+        */
        if ((lustre_handle_is_used(&req->rq_import->imp_remote_handle)) &&
            (opc == OST_CONNECT || opc == MDS_CONNECT || opc == MGS_CONNECT)) {
 
@@ -1155,6 +1113,7 @@ static int ptlrpc_check_status(struct ptlrpc_request *req)
        if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
                struct obd_import *imp = req->rq_import;
                __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
+
                if (ptlrpc_console_allow(req))
                        LCONSOLE_ERROR_MSG(0x011, "%s: Communicating with %s, operation %s failed with %d.\n",
                                           imp->imp_obd->obd_name,
@@ -1164,12 +1123,11 @@ static int ptlrpc_check_status(struct ptlrpc_request *req)
                return err < 0 ? err : -EINVAL;
        }
 
-       if (err < 0) {
+       if (err < 0)
                DEBUG_REQ(D_INFO, req, "status is %d", err);
-       } else if (err > 0) {
+       else if (err > 0)
                /* XXX: translate this error from net to host */
                DEBUG_REQ(D_INFO, req, "status is %d", err);
-       }
 
        return err;
 }
@@ -1206,7 +1164,7 @@ static int after_reply(struct ptlrpc_request *req)
        struct obd_import *imp = req->rq_import;
        struct obd_device *obd = req->rq_import->imp_obd;
        int rc;
-       struct timeval work_start;
+       struct timespec64 work_start;
        long timediff;
 
        LASSERT(obd != NULL);
@@ -1221,10 +1179,11 @@ static int after_reply(struct ptlrpc_request *req)
                }
 
                sptlrpc_cli_free_repbuf(req);
-               /* Pass the required reply buffer size (include
-                * space for early reply).
-                * NB: no need to roundup because alloc_repbuf
-                * will roundup it */
+               /*
+                * Pass the required reply buffer size (include space for early
+                * reply).  NB: no need to round up because alloc_repbuf will
+                * round it up
+                */
                req->rq_replen       = req->rq_nob_received;
                req->rq_nob_received = 0;
                spin_lock(&req->rq_lock);
@@ -1243,9 +1202,7 @@ static int after_reply(struct ptlrpc_request *req)
                return rc;
        }
 
-       /*
-        * Security layer unwrap might ask resend this request.
-        */
+       /* Security layer unwrap might ask resend this request. */
        if (req->rq_resend)
                return 0;
 
@@ -1256,7 +1213,7 @@ static int after_reply(struct ptlrpc_request *req)
        /* retry indefinitely on EINPROGRESS */
        if (lustre_msg_get_status(req->rq_repmsg) == -EINPROGRESS &&
            ptlrpc_no_resend(req) == 0 && !req->rq_no_retry_einprogress) {
-               time_t  now = get_seconds();
+               time64_t now = ktime_get_real_seconds();
 
                DEBUG_REQ(D_RPCTRACE, req, "Resending request on EINPROGRESS");
                spin_lock(&req->rq_lock);
@@ -1266,18 +1223,19 @@ static int after_reply(struct ptlrpc_request *req)
 
                /* allocate new xid to avoid reply reconstruction */
                if (!req->rq_bulk) {
-                       /* new xid is already allocated for bulk in
-                        * ptlrpc_check_set() */
+                       /* new xid is already allocated for bulk in ptlrpc_check_set() */
                        req->rq_xid = ptlrpc_next_xid();
                        DEBUG_REQ(D_RPCTRACE, req, "Allocating new xid for resend on EINPROGRESS");
                }
 
                /* Readjust the timeout for current conditions */
                ptlrpc_at_set_req_timeout(req);
-               /* delay resend to give a chance to the server to get ready.
+               /*
+                * delay resend to give a chance to the server to get ready.
                 * The delay is increased by 1s on every resend and is capped to
                 * the current request timeout (i.e. obd_timeout if AT is off,
-                * or AT service time x 125% + 5s, see at_est2timeout) */
+                * or AT service time x 125% + 5s, see at_est2timeout)
+                */
                if (req->rq_nr_resend > req->rq_timeout)
                        req->rq_sent = now + req->rq_timeout;
                else
@@ -1286,8 +1244,9 @@ static int after_reply(struct ptlrpc_request *req)
                return 0;
        }
 
-       do_gettimeofday(&work_start);
-       timediff = cfs_timeval_sub(&work_start, &req->rq_arrival_time, NULL);
+       ktime_get_real_ts64(&work_start);
+       timediff = (work_start.tv_sec - req->rq_arrival_time.tv_sec) * USEC_PER_SEC +
+                  (work_start.tv_nsec - req->rq_arrival_time.tv_nsec) / NSEC_PER_USEC;
        if (obd->obd_svc_stats != NULL) {
                lprocfs_counter_add(obd->obd_svc_stats, PTLRPC_REQWAIT_CNTR,
                                    timediff);
@@ -1332,9 +1291,7 @@ static int after_reply(struct ptlrpc_request *req)
                ldlm_cli_update_pool(req);
        }
 
-       /*
-        * Store transno in reqmsg for replay.
-        */
+       /* Store transno in reqmsg for replay. */
        if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY)) {
                req->rq_transno = lustre_msg_get_transno(req->rq_repmsg);
                lustre_msg_set_transno(req->rq_reqmsg, req->rq_transno);
@@ -1350,22 +1307,22 @@ static int after_reply(struct ptlrpc_request *req)
                    (req->rq_transno >
                     lustre_msg_get_last_committed(req->rq_repmsg) ||
                     req->rq_replay)) {
-                       /** version recovery */
+                       /* version recovery */
                        ptlrpc_save_versions(req);
                        ptlrpc_retain_replayable_request(req, imp);
                } else if (req->rq_commit_cb != NULL &&
                           list_empty(&req->rq_replay_list)) {
-                       /* NB: don't call rq_commit_cb if it's already on
+                       /*
+                        * NB: don't call rq_commit_cb if it's already on
                         * rq_replay_list, ptlrpc_free_committed() will call
-                        * it later, see LU-3618 for details */
+                        * it later, see LU-3618 for details
+                        */
                        spin_unlock(&imp->imp_lock);
                        req->rq_commit_cb(req);
                        spin_lock(&imp->imp_lock);
                }
 
-               /*
-                * Replay-enabled imports return commit-status information.
-                */
+               /* Replay-enabled imports return commit-status information. */
                if (lustre_msg_get_last_committed(req->rq_repmsg)) {
                        imp->imp_peer_committed_transno =
                                lustre_msg_get_last_committed(req->rq_repmsg);
@@ -1404,7 +1361,7 @@ static int ptlrpc_send_new_req(struct ptlrpc_request *req)
        int rc;
 
        LASSERT(req->rq_phase == RQ_PHASE_NEW);
-       if (req->rq_sent && (req->rq_sent > get_seconds()) &&
+       if (req->rq_sent && (req->rq_sent > ktime_get_real_seconds()) &&
            (!req->rq_generation_set ||
             req->rq_import_generation == imp->imp_generation))
                return 0;
@@ -1484,8 +1441,10 @@ static inline int ptlrpc_set_producer(struct ptlrpc_request_set *set)
 
        remaining = atomic_read(&set->set_remaining);
 
-       /* populate the ->set_requests list with requests until we
-        * reach the maximum number of RPCs in flight for this set */
+       /*
+        * populate the ->set_requests list with requests until we
+        * reach the maximum number of RPCs in flight for this set
+        */
        while (atomic_read(&set->set_remaining) < set->set_max_inflight) {
                rc = set->set_producer(set, set->set_producer_arg);
                if (rc == -ENOENT) {
@@ -1525,7 +1484,8 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                int unregistered = 0;
                int rc = 0;
 
-               /* This schedule point is mainly for the ptlrpcd caller of this
+               /*
+                * This schedule point is mainly for the ptlrpcd caller of this
                 * function.  Most ptlrpc sets are not long-lived and unbounded
                 * in length, but at the least the set used by the ptlrpcd is.
                 * Since the processing time is unbounded, we need to insert an
@@ -1544,7 +1504,7 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
 
                /* delayed resend - skip */
                if (req->rq_phase == RQ_PHASE_RPC && req->rq_resend &&
-                   req->rq_sent > get_seconds())
+                   req->rq_sent > ktime_get_real_seconds())
                        continue;
 
                if (!(req->rq_phase == RQ_PHASE_RPC ||
@@ -1584,8 +1544,7 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                                                     OBD_FAIL_ONCE);
                        }
 
-                       /*
-                        * Move to next phase if reply was successfully
+                       /* Move to next phase if reply was successfully
                         * unlinked.
                         */
                        ptlrpc_rqphase_move(req, req->rq_next_phase);
@@ -1599,15 +1558,11 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                if (req->rq_phase == RQ_PHASE_INTERPRET)
                        goto interpret;
 
-               /*
-                * Note that this also will start async reply unlink.
-                */
+               /* Note that this also will start async reply unlink. */
                if (req->rq_net_err && !req->rq_timedout) {
                        ptlrpc_expire_one_request(req, 1);
 
-                       /*
-                        * Check if we still need to wait for unlink.
-                        */
+                       /* Check if we still need to wait for unlink. */
                        if (ptlrpc_client_recv_or_unlink(req) ||
                            ptlrpc_client_bulk_active(req))
                                continue;
@@ -1632,7 +1587,8 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                        goto interpret;
                }
 
-               /* ptlrpc_set_wait->l_wait_event sets lwi_allow_intr
+               /*
+                * ptlrpc_set_wait->l_wait_event sets lwi_allow_intr
                 * so it sets rq_intr regardless of individual rpc
                 * timeouts. The synchronous IO waiting path sets
                 * rq_intr irrespective of whether ptlrpcd
@@ -1659,8 +1615,10 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                                spin_lock(&imp->imp_lock);
                                if (ptlrpc_import_delay_req(imp, req,
                                                            &status)) {
-                                       /* put on delay list - only if we wait
-                                        * recovery finished - before send */
+                                       /*
+                                        * put on delay list - only if we wait
+                                        * recovery finished - before send
+                                        */
                                        list_del_init(&req->rq_list);
                                        list_add_tail(&req->rq_list,
                                                          &imp->
@@ -1696,8 +1654,7 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                                spin_unlock(&req->rq_lock);
 
                                if (req->rq_timedout || req->rq_resend) {
-                                       /* This is re-sending anyways,
-                                        * let's mark req as resend. */
+                                       /* This is re-sending anyway, let's mark req as resend. */
                                        spin_lock(&req->rq_lock);
                                        req->rq_resend = 1;
                                        spin_unlock(&req->rq_lock);
@@ -1775,8 +1732,10 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
 
                        spin_unlock(&req->rq_lock);
 
-                       /* unlink from net because we are going to
-                        * swab in-place of reply buffer */
+                       /*
+                        * unlink from net because we are going to
+                        * swab in-place of reply buffer
+                        */
                        unregistered = ptlrpc_unregister_reply(req, 1);
                        if (!unregistered)
                                continue;
@@ -1785,7 +1744,8 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                        if (req->rq_resend)
                                continue;
 
-                       /* If there is no bulk associated with this request,
+                       /*
+                        * If there is no bulk associated with this request,
                         * then we're done and should let the interpreter
                         * process the reply. Similarly if the RPC returned
                         * an error, and therefore the bulk will never arrive.
@@ -1803,10 +1763,12 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
                        continue;
 
                if (req->rq_bulk->bd_failure) {
-                       /* The RPC reply arrived OK, but the bulk screwed
+                       /*
+                        * The RPC reply arrived OK, but the bulk screwed
                         * up!  Dead weird since the server told us the RPC
                         * was good after getting the REPLY for her GET or
-                        * the ACK for her PUT. */
+                        * the ACK for her PUT.
+                        */
                        DEBUG_REQ(D_ERROR, req, "bulk transfer failed");
                        req->rq_status = -EIO;
                }
@@ -1816,8 +1778,10 @@ int ptlrpc_check_set(const struct lu_env *env, struct ptlrpc_request_set *set)
 interpret:
                LASSERT(req->rq_phase == RQ_PHASE_INTERPRET);
 
-               /* This moves to "unregistering" phase we need to wait for
-                * reply unlink. */
+               /*
+                * This moves to "unregistering" phase we need to wait for
+                * reply unlink.
+                */
                if (!unregistered && !ptlrpc_unregister_reply(req, 1)) {
                        /* start async bulk unlink too */
                        ptlrpc_unregister_bulk(req, 1);
@@ -1827,8 +1791,7 @@ interpret:
                if (!ptlrpc_unregister_bulk(req, 1))
                        continue;
 
-               /* When calling interpret receiving already should be
-                * finished. */
+               /* When calling interpret receive should already be finished. */
                LASSERT(!req->rq_receiving_reply);
 
                ptlrpc_req_interpret(env, req, req->rq_status);
@@ -1847,10 +1810,12 @@ interpret:
                       lustre_msg_get_opc(req->rq_reqmsg));
 
                spin_lock(&imp->imp_lock);
-               /* Request already may be not on sending or delaying list. This
+               /*
+                * Request already may be not on sending or delaying list. This
                 * may happen in the case of marking it erroneous for the case
                 * ptlrpc_import_delay_req(req, status) find it impossible to
-                * allow sending this rpc and returns *status != 0. */
+                * allow sending this rpc and returns *status != 0.
+                */
                if (!list_empty(&req->rq_list)) {
                        list_del_init(&req->rq_list);
                        atomic_dec(&imp->imp_inflight);
@@ -1865,8 +1830,10 @@ interpret:
                        if (ptlrpc_set_producer(set) > 0)
                                force_timer_recalc = 1;
 
-                       /* free the request that has just been completed
-                        * in order not to pollute set->set_requests */
+                       /*
+                        * free the request that has just been completed
+                        * in order not to pollute set->set_requests
+                        */
                        list_del_init(&req->rq_set_chain);
                        spin_lock(&req->rq_lock);
                        req->rq_set = NULL;
@@ -1882,8 +1849,10 @@ interpret:
                }
        }
 
-       /* move completed request at the head of list so it's easier for
-        * caller to find them */
+       /*
+        * move completed request at the head of list so it's easier for
+        * caller to find them
+        */
        list_splice(&comp_reqs, &set->set_requests);
 
        /* If we hit an error, we want to recover promptly. */
@@ -1905,14 +1874,13 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink)
        req->rq_timedout = 1;
        spin_unlock(&req->rq_lock);
 
-       DEBUG_REQ(D_WARNING, req, "Request sent has %s: [sent "CFS_DURATION_T
-                 "/real "CFS_DURATION_T"]",
+       DEBUG_REQ(D_WARNING, req, "Request sent has %s: [sent %lld/real %lld]",
                  req->rq_net_err ? "failed due to network error" :
                     ((req->rq_real_sent == 0 ||
-                      time_before((unsigned long)req->rq_real_sent, (unsigned long)req->rq_sent) ||
-                      cfs_time_aftereq(req->rq_real_sent, req->rq_deadline)) ?
+                      req->rq_real_sent < req->rq_sent ||
+                      req->rq_real_sent >= req->rq_deadline) ?
                      "timed out for sent delay" : "timed out for slow reply"),
-                 req->rq_sent, req->rq_real_sent);
+                 (s64)req->rq_sent, (s64)req->rq_real_sent);
 
        if (imp != NULL && obd_debug_peer_on_timeout)
                LNetCtl(IOC_LIBCFS_DEBUG_PEER, &imp->imp_connection->c_peer);
@@ -1934,8 +1902,10 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink)
        if (imp->imp_dlm_fake)
                return 1;
 
-       /* If this request is for recovery or other primordial tasks,
-        * then error it out here. */
+       /*
+        * If this request is for recovery or other primordial tasks,
+        * then error it out here.
+        */
        if (req->rq_ctx_init || req->rq_ctx_fini ||
            req->rq_send_state != LUSTRE_IMP_FULL ||
            imp->imp_obd->obd_no_recov) {
@@ -1949,8 +1919,10 @@ int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink)
                return 1;
        }
 
-       /* if a request can't be resent we can't wait for an answer after
-          the timeout */
+       /*
+        * if a request can't be resent we can't wait for an answer after
+        * the timeout
+        */
        if (ptlrpc_no_resend(req)) {
                DEBUG_REQ(D_RPCTRACE, req, "TIMEOUT-NORESEND:");
                rc = 1;
@@ -1970,13 +1942,11 @@ int ptlrpc_expired_set(void *data)
 {
        struct ptlrpc_request_set *set = data;
        struct list_head *tmp;
-       time_t now = get_seconds();
+       time64_t now = ktime_get_real_seconds();
 
        LASSERT(set != NULL);
 
-       /*
-        * A timeout expired. See which reqs it applies to...
-        */
+       /* A timeout expired. See which reqs it applies to...  */
        list_for_each(tmp, &set->set_requests) {
                struct ptlrpc_request *req =
                        list_entry(tmp, struct ptlrpc_request,
@@ -1996,8 +1966,10 @@ int ptlrpc_expired_set(void *data)
                    req->rq_deadline > now) /* not expired */
                        continue;
 
-               /* Deal with this guy. Do it asynchronously to not block
-                * ptlrpcd thread. */
+               /*
+                * Deal with this guy. Do it asynchronously to not block
+                * ptlrpcd thread.
+                */
                ptlrpc_expire_one_request(req, 1);
        }
 
@@ -2053,31 +2025,25 @@ EXPORT_SYMBOL(ptlrpc_interrupted_set);
 int ptlrpc_set_next_timeout(struct ptlrpc_request_set *set)
 {
        struct list_head *tmp;
-       time_t now = get_seconds();
+       time64_t now = ktime_get_real_seconds();
        int timeout = 0;
        struct ptlrpc_request *req;
-       int deadline;
+       time64_t deadline;
 
        list_for_each(tmp, &set->set_requests) {
                req = list_entry(tmp, struct ptlrpc_request, rq_set_chain);
 
-               /*
-                * Request in-flight?
-                */
+               /* Request in-flight? */
                if (!(((req->rq_phase == RQ_PHASE_RPC) && !req->rq_waiting) ||
                      (req->rq_phase == RQ_PHASE_BULK) ||
                      (req->rq_phase == RQ_PHASE_NEW)))
                        continue;
 
-               /*
-                * Already timed out.
-                */
+               /* Already timed out. */
                if (req->rq_timedout)
                        continue;
 
-               /*
-                * Waiting for ctx.
-                */
+               /* Waiting for ctx. */
                if (req->rq_wait_ctx)
                        continue;
 
@@ -2126,8 +2092,10 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set)
        do {
                timeout = ptlrpc_set_next_timeout(set);
 
-               /* wait until all complete, interrupted, or an in-flight
-                * req times out */
+               /*
+                * wait until all complete, interrupted, or an in-flight
+                * req times out
+                */
                CDEBUG(D_RPCTRACE, "set %p going to sleep for %d seconds\n",
                       set, timeout);
 
@@ -2152,18 +2120,22 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set)
 
                rc = l_wait_event(set->set_waitq, ptlrpc_check_set(NULL, set), &lwi);
 
-               /* LU-769 - if we ignored the signal because it was already
+               /*
+                * LU-769 - if we ignored the signal because it was already
                 * pending when we started, we need to handle it now or we risk
-                * it being ignored forever */
+                * it being ignored forever
+                */
                if (rc == -ETIMEDOUT && !lwi.lwi_allow_intr &&
                    cfs_signal_pending()) {
                        sigset_t blocked_sigs =
                                           cfs_block_sigsinv(LUSTRE_FATAL_SIGS);
 
-                       /* In fact we only interrupt for the "fatal" signals
+                       /*
+                        * In fact we only interrupt for the "fatal" signals
                         * like SIGINT or SIGKILL. We still ignore less
                         * important signals since ptlrpc set is not easily
-                        * reentrant from userspace again */
+                        * reentrant from userspace again
+                        */
                        if (cfs_signal_pending())
                                ptlrpc_interrupted_set(set);
                        cfs_restore_sigs(blocked_sigs);
@@ -2171,13 +2143,15 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set)
 
                LASSERT(rc == 0 || rc == -EINTR || rc == -ETIMEDOUT);
 
-               /* -EINTR => all requests have been flagged rq_intr so next
+               /*
+                * -EINTR => all requests have been flagged rq_intr so next
                 * check completes.
                 * -ETIMEDOUT => someone timed out.  When all reqs have
                 * timed out, signals are enabled allowing completion with
                 * EINTR.
                 * I don't really care if we go once more round the loop in
-                * the error cases -eeb. */
+                * the error cases -eeb.
+                */
                if (rc == 0 && atomic_read(&set->set_remaining) == 0) {
                        list_for_each(tmp, &set->set_requests) {
                                req = list_entry(tmp, struct ptlrpc_request,
@@ -2243,8 +2217,10 @@ static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
 
        req_capsule_fini(&request->rq_pill);
 
-       /* We must take it off the imp_replay_list first.  Otherwise, we'll set
-        * request->rq_reqmsg to NULL while osc_close is dereferencing it. */
+       /*
+        * We must take it off the imp_replay_list first.  Otherwise, we'll set
+        * request->rq_reqmsg to NULL while osc_close is dereferencing it.
+        */
        if (request->rq_import != NULL) {
                if (!locked)
                        spin_lock(&request->rq_import->imp_lock);
@@ -2285,18 +2261,6 @@ static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
                ptlrpc_request_cache_free(request);
 }
 
-static int __ptlrpc_req_finished(struct ptlrpc_request *request, int locked);
-/**
- * Drop one request reference. Must be called with import imp_lock held.
- * When reference count drops to zero, request is freed.
- */
-void ptlrpc_req_finished_with_imp_lock(struct ptlrpc_request *request)
-{
-       assert_spin_locked(&request->rq_import->imp_lock);
-       (void)__ptlrpc_req_finished(request, 1);
-}
-EXPORT_SYMBOL(ptlrpc_req_finished_with_imp_lock);
-
 /**
  * Helper function
  * Drops one reference count for request \a request.
@@ -2357,40 +2321,28 @@ int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async)
        wait_queue_head_t *wq;
        struct l_wait_info lwi;
 
-       /*
-        * Might sleep.
-        */
+       /* Might sleep. */
        LASSERT(!in_interrupt());
 
-       /*
-        * Let's setup deadline for reply unlink.
-        */
+       /* Let's setup deadline for reply unlink. */
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_REPL_UNLINK) &&
            async && request->rq_reply_deadline == 0)
-               request->rq_reply_deadline = get_seconds()+LONG_UNLINK;
+               request->rq_reply_deadline = ktime_get_real_seconds()+LONG_UNLINK;
 
-       /*
-        * Nothing left to do.
-        */
+       /* Nothing left to do. */
        if (!ptlrpc_client_recv_or_unlink(request))
                return 1;
 
        LNetMDUnlink(request->rq_reply_md_h);
 
-       /*
-        * Let's check it once again.
-        */
+       /* Let's check it once again. */
        if (!ptlrpc_client_recv_or_unlink(request))
                return 1;
 
-       /*
-        * Move to "Unregistering" phase as reply was not unlinked yet.
-        */
+       /* Move to "Unregistering" phase as reply was not unlinked yet. */
        ptlrpc_rqphase_move(request, RQ_PHASE_UNREGISTERING);
 
-       /*
-        * Do not wait for unlink to finish.
-        */
+       /* Do not wait for unlink to finish. */
        if (async)
                return 0;
 
@@ -2405,8 +2357,10 @@ int ptlrpc_unregister_reply(struct ptlrpc_request *request, int async)
                wq = &request->rq_reply_waitq;
 
        for (;;) {
-               /* Network access will complete in finite time but the HUGE
-                * timeout lets us CWARN for visibility of sluggish NALs */
+               /*
+                * Network access will complete in finite time but the HUGE
+                * timeout lets us CWARN for visibility of sluggish NALs
+                */
                lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(LONG_UNLINK),
                                           cfs_time_seconds(1), NULL, NULL);
                rc = l_wait_event(*wq, !ptlrpc_client_recv_or_unlink(request),
@@ -2538,11 +2492,6 @@ free_req:
        }
 }
 
-void ptlrpc_cleanup_client(struct obd_import *imp)
-{
-}
-EXPORT_SYMBOL(ptlrpc_cleanup_client);
-
 /**
  * Schedule previously sent request for resend.
  * For bulk requests we assign new xid (to avoid problems with
@@ -2554,8 +2503,10 @@ void ptlrpc_resend_req(struct ptlrpc_request *req)
        DEBUG_REQ(D_HA, req, "going to resend");
        spin_lock(&req->rq_lock);
 
-       /* Request got reply but linked to the import list still.
-          Let ptlrpc_check_set() to process it. */
+       /*
+        * Request got reply but linked to the import list still.
+        * Let ptlrpc_check_set() to process it.
+        */
        if (ptlrpc_client_replied(req)) {
                spin_unlock(&req->rq_lock);
                DEBUG_REQ(D_HA, req, "it has reply, so skip it");
@@ -2581,20 +2532,6 @@ void ptlrpc_resend_req(struct ptlrpc_request *req)
 }
 EXPORT_SYMBOL(ptlrpc_resend_req);
 
-/* XXX: this function and rq_status are currently unused */
-void ptlrpc_restart_req(struct ptlrpc_request *req)
-{
-       DEBUG_REQ(D_HA, req, "restarting (possibly-)completed request");
-       req->rq_status = -ERESTARTSYS;
-
-       spin_lock(&req->rq_lock);
-       req->rq_restart = 1;
-       req->rq_timedout = 0;
-       ptlrpc_client_wake_req(req);
-       spin_unlock(&req->rq_lock);
-}
-EXPORT_SYMBOL(ptlrpc_restart_req);
-
 /**
  * Grab additional reference on a request \a req
  */
@@ -2621,8 +2558,10 @@ void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
                LBUG();
        }
 
-       /* clear this for new requests that were resent as well
-          as resent replayed requests. */
+       /*
+        * clear this for new requests that were resent as well
+        * as resent replayed requests.
+        */
        lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
 
        /* don't re-add requests that have been replayed */
@@ -2639,7 +2578,8 @@ void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
                        list_entry(tmp, struct ptlrpc_request,
                                       rq_replay_list);
 
-               /* We may have duplicate transnos if we create and then
+               /*
+                * We may have duplicate transnos if we create and then
                 * open a file, or for closes retained if to match creating
                 * opens, so use req->rq_xid as a secondary key.
                 * (See bugs 684, 685, and 428.)
@@ -2824,8 +2764,10 @@ int ptlrpc_replay_req(struct ptlrpc_request *req)
        /* Readjust the timeout for current conditions */
        ptlrpc_at_set_req_timeout(req);
 
-       /* Tell server the net_latency, so the server can calculate how long
-        * it should wait for next replay */
+       /*
+        * Tell server the net_latency, so the server can calculate how long
+        * it should wait for next replay
+        */
        lustre_msg_set_service_time(req->rq_reqmsg,
                                    ptlrpc_at_get_net_latency(req));
        DEBUG_REQ(D_HA, req, "REPLAY");
@@ -2833,7 +2775,7 @@ int ptlrpc_replay_req(struct ptlrpc_request *req)
        atomic_inc(&req->rq_import->imp_replay_inflight);
        ptlrpc_request_addref(req); /* ptlrpcd needs a ref */
 
-       ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
+       ptlrpcd_add_req(req);
        return 0;
 }
 EXPORT_SYMBOL(ptlrpc_replay_req);
@@ -2845,13 +2787,15 @@ void ptlrpc_abort_inflight(struct obd_import *imp)
 {
        struct list_head *tmp, *n;
 
-       /* Make sure that no new requests get processed for this import.
+       /*
+        * Make sure that no new requests get processed for this import.
         * ptlrpc_{queue,set}_wait must (and does) hold imp_lock while testing
         * this flag and then putting requests on sending_list or delayed_list.
         */
        spin_lock(&imp->imp_lock);
 
-       /* XXX locking?  Maybe we should remove each request with the list
+       /*
+        * XXX locking?  Maybe we should remove each request with the list
         * locked?  Also, how do we know if the requests on the list are
         * being freed at this time?
         */
@@ -2885,8 +2829,10 @@ void ptlrpc_abort_inflight(struct obd_import *imp)
                spin_unlock(&req->rq_lock);
        }
 
-       /* Last chance to free reqs left on the replay list, but we
-        * will still leak reqs that haven't committed.  */
+       /*
+        * Last chance to free reqs left on the replay list, but we
+        * will still leak reqs that haven't committed.
+        */
        if (imp->imp_replayable)
                ptlrpc_free_committed(imp);
 
@@ -2942,7 +2888,7 @@ static spinlock_t ptlrpc_last_xid_lock;
 #define YEAR_2004 (1ULL << 30)
 void ptlrpc_init_xid(void)
 {
-       time_t now = get_seconds();
+       time64_t now = ktime_get_real_seconds();
 
        spin_lock_init(&ptlrpc_last_xid_lock);
        if (now < YEAR_2004) {
@@ -2954,7 +2900,7 @@ void ptlrpc_init_xid(void)
        }
 
        /* Always need to be aligned to a power-of-two for multi-bulk BRW */
-       CLASSERT((PTLRPC_BULK_OPS_COUNT & (PTLRPC_BULK_OPS_COUNT - 1)) == 0);
+       CLASSERT(((PTLRPC_BULK_OPS_COUNT - 1) & PTLRPC_BULK_OPS_COUNT) == 0);
        ptlrpc_last_xid &= PTLRPC_BULK_OPS_MASK;
 }
 
@@ -3031,7 +2977,7 @@ static void ptlrpcd_add_work_req(struct ptlrpc_request *req)
 {
        /* re-initialize the req */
        req->rq_timeout         = obd_timeout;
-       req->rq_sent            = get_seconds();
+       req->rq_sent            = ktime_get_real_seconds();
        req->rq_deadline        = req->rq_sent + req->rq_timeout;
        req->rq_reply_deadline  = req->rq_deadline;
        req->rq_phase           = RQ_PHASE_INTERPRET;
@@ -3039,7 +2985,7 @@ static void ptlrpcd_add_work_req(struct ptlrpc_request *req)
        req->rq_xid             = ptlrpc_next_xid();
        req->rq_import_generation = req->rq_import->imp_generation;
 
-       ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+       ptlrpcd_add_req(req);
 }
 
 static int work_interpreter(const struct lu_env *env,
index ffe36e22245febe10cf080302da23a35c195bfd9..da1f0b1ac3e38a7e88f664e7f9a61c24e9b6a907 100644 (file)
@@ -42,7 +42,7 @@
 #include "ptlrpc_internal.h"
 
 static struct cfs_hash *conn_hash;
-static cfs_hash_ops_t conn_hash_ops;
+static struct cfs_hash_ops conn_hash_ops;
 
 struct ptlrpc_connection *
 ptlrpc_connection_get(lnet_process_id_t peer, lnet_nid_t self,
@@ -173,7 +173,7 @@ conn_keycmp(const void *key, struct hlist_node *hnode)
        const lnet_process_id_t *conn_key;
 
        LASSERT(key != NULL);
-       conn_key = (lnet_process_id_t *)key;
+       conn_key = key;
        conn = hlist_entry(hnode, struct ptlrpc_connection, c_hash);
 
        return conn_key->nid == conn->c_peer.nid &&
@@ -230,12 +230,12 @@ conn_exit(struct cfs_hash *hs, struct hlist_node *hnode)
        kfree(conn);
 }
 
-static cfs_hash_ops_t conn_hash_ops = {
+static struct cfs_hash_ops conn_hash_ops = {
        .hs_hash        = conn_hashfn,
        .hs_keycmp      = conn_keycmp,
-       .hs_key  = conn_key,
+       .hs_key         = conn_key,
        .hs_object      = conn_object,
-       .hs_get  = conn_get,
+       .hs_get         = conn_get,
        .hs_put_locked  = conn_put_locked,
        .hs_exit        = conn_exit,
 };
index c8ef9e57826326c62019a7d76eadce99d367a2e7..9c2fd34e2eb9b095b4b0f1c1d1b84d6d33ad528f 100644 (file)
@@ -64,7 +64,7 @@ void request_out_callback(lnet_event_t *ev)
 
        sptlrpc_request_out_callback(req);
        spin_lock(&req->rq_lock);
-       req->rq_real_sent = get_seconds();
+       req->rq_real_sent = ktime_get_real_seconds();
        if (ev->unlinked)
                req->rq_req_unlink = 0;
 
@@ -158,7 +158,7 @@ void reply_in_callback(lnet_event_t *ev)
                          ev->mlength, ev->offset, req->rq_replen);
        }
 
-       req->rq_import->imp_last_reply_time = get_seconds();
+       req->rq_import->imp_last_reply_time = ktime_get_real_seconds();
 
 out_wake:
        /* NB don't unlock till after wakeup; req can disappear under us
@@ -246,7 +246,7 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt,
                                   struct ptlrpc_request *req)
 {
        __u64 sec = req->rq_arrival_time.tv_sec;
-       __u32 usec = req->rq_arrival_time.tv_usec >> 4; /* usec / 16 */
+       __u32 usec = req->rq_arrival_time.tv_nsec / NSEC_PER_USEC / 16; /* usec / 16 */
        __u64 new_seq;
 
        /* set sequence ID for request and add it to history list,
@@ -327,7 +327,7 @@ void request_in_callback(lnet_event_t *ev)
        req->rq_reqbuf = ev->md.start + ev->offset;
        if (ev->type == LNET_EVENT_PUT && ev->status == 0)
                req->rq_reqdata_len = ev->mlength;
-       do_gettimeofday(&req->rq_arrival_time);
+       ktime_get_real_ts64(&req->rq_arrival_time);
        req->rq_peer = ev->initiator;
        req->rq_self = ev->target.nid;
        req->rq_rqbd = rqbd;
@@ -415,7 +415,6 @@ void reply_out_callback(lnet_event_t *ev)
        }
 }
 
-
 static void ptlrpc_master_callback(lnet_event_t *ev)
 {
        struct ptlrpc_cb_id *cbid = ev->md.user_ptr;
@@ -521,7 +520,7 @@ static void ptlrpc_ni_fini(void)
        /* notreached */
 }
 
-lnet_pid_t ptl_get_pid(void)
+static lnet_pid_t ptl_get_pid(void)
 {
        lnet_pid_t pid;
 
@@ -560,7 +559,6 @@ static int ptlrpc_ni_init(void)
        return -ENOMEM;
 }
 
-
 int ptlrpc_init_portals(void)
 {
        int rc = ptlrpc_ni_init();
index 1eae3896c0375ce6f2d7ed0c6856b000f2a487f3..bfa410f7e773fbe0f2ae2271f6c8b6c095c9a486 100644 (file)
@@ -79,7 +79,7 @@ static void __import_set_state(struct obd_import *imp,
        imp->imp_state = state;
        imp->imp_state_hist[imp->imp_state_hist_idx].ish_state = state;
        imp->imp_state_hist[imp->imp_state_hist_idx].ish_time =
-               get_seconds();
+               ktime_get_real_seconds();
        imp->imp_state_hist_idx = (imp->imp_state_hist_idx + 1) %
                IMP_STATE_HIST_LEN;
 }
@@ -103,7 +103,6 @@ do {                                                                        \
        spin_unlock(&imp->imp_lock);                                    \
 } while (0)
 
-
 static int ptlrpc_connect_interpret(const struct lu_env *env,
                                    struct ptlrpc_request *request,
                                    void *data, int rc);
@@ -128,7 +127,8 @@ int ptlrpc_init_import(struct obd_import *imp)
 EXPORT_SYMBOL(ptlrpc_init_import);
 
 #define UUID_STR "_UUID"
-void deuuidify(char *uuid, const char *prefix, char **uuid_start, int *uuid_len)
+static void deuuidify(char *uuid, const char *prefix, char **uuid_start,
+                     int *uuid_len)
 {
        *uuid_start = !prefix || strncmp(uuid, prefix, strlen(prefix))
                ? uuid : uuid + strlen(prefix);
@@ -142,7 +142,6 @@ void deuuidify(char *uuid, const char *prefix, char **uuid_start, int *uuid_len)
                    UUID_STR, strlen(UUID_STR)))
                *uuid_len -= strlen(UUID_STR);
 }
-EXPORT_SYMBOL(deuuidify);
 
 /**
  * Returns true if import was FULL, false if import was already not
@@ -200,12 +199,15 @@ int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt)
        return rc;
 }
 
-/* Must be called with imp_lock held! */
-static void ptlrpc_deactivate_and_unlock_import(struct obd_import *imp)
+/*
+ * This acts as a barrier; all existing requests are rejected, and
+ * no new requests will be accepted until the import is valid again.
+ */
+void ptlrpc_deactivate_import(struct obd_import *imp)
 {
-       assert_spin_locked(&imp->imp_lock);
-
        CDEBUG(D_HA, "setting import %s INVALID\n", obd2cli_tgt(imp->imp_obd));
+
+       spin_lock(&imp->imp_lock);
        imp->imp_invalid = 1;
        imp->imp_generation++;
        spin_unlock(&imp->imp_lock);
@@ -213,20 +215,10 @@ static void ptlrpc_deactivate_and_unlock_import(struct obd_import *imp)
        ptlrpc_abort_inflight(imp);
        obd_import_event(imp->imp_obd, imp, IMP_EVENT_INACTIVE);
 }
-
-/*
- * This acts as a barrier; all existing requests are rejected, and
- * no new requests will be accepted until the import is valid again.
- */
-void ptlrpc_deactivate_import(struct obd_import *imp)
-{
-       spin_lock(&imp->imp_lock);
-       ptlrpc_deactivate_and_unlock_import(imp);
-}
 EXPORT_SYMBOL(ptlrpc_deactivate_import);
 
 static unsigned int
-ptlrpc_inflight_deadline(struct ptlrpc_request *req, time_t now)
+ptlrpc_inflight_deadline(struct ptlrpc_request *req, time64_t now)
 {
        long dl;
 
@@ -251,7 +243,7 @@ ptlrpc_inflight_deadline(struct ptlrpc_request *req, time_t now)
 
 static unsigned int ptlrpc_inflight_timeout(struct obd_import *imp)
 {
-       time_t now = get_seconds();
+       time64_t now = ktime_get_real_seconds();
        struct list_head *tmp, *n;
        struct ptlrpc_request *req;
        unsigned int timeout = 0;
@@ -461,6 +453,7 @@ int ptlrpc_reconnect_import(struct obd_import *imp)
        if (atomic_read(&imp->imp_inval_count) > 0) {
                int rc;
                struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
+
                rc = l_wait_event(imp->imp_recovery_waitq,
                                  (atomic_read(&imp->imp_inval_count) == 0),
                                  &lwi);
@@ -542,6 +535,7 @@ static int import_select_connection(struct obd_import *imp)
           trying to reconnect on it.) */
        if (tried_all && (imp->imp_conn_list.next == &imp_conn->oic_item)) {
                struct adaptive_timeout *at = &imp->imp_at.iat_net_latency;
+
                if (at_get(at) < CONNECTION_SWITCH_MAX) {
                        at_measured(at, at_get(at) + CONNECTION_SWITCH_INC);
                        if (at_get(at) > CONNECTION_SWITCH_MAX)
@@ -749,12 +743,11 @@ int ptlrpc_connect_import(struct obd_import *imp)
 
        DEBUG_REQ(D_RPCTRACE, request, "(re)connect request (timeout %d)",
                  request->rq_timeout);
-       ptlrpcd_add_req(request, PDL_POLICY_ROUND, -1);
+       ptlrpcd_add_req(request);
        rc = 0;
 out:
-       if (rc != 0) {
+       if (rc != 0)
                IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
-       }
 
        return rc;
 }
@@ -906,7 +899,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
        }
 
        /* Determine what recovery state to move the import to. */
-       if (MSG_CONNECT_RECONNECT & msg_flags) {
+       if (msg_flags & MSG_CONNECT_RECONNECT) {
                memset(&old_hdl, 0, sizeof(old_hdl));
                if (!memcmp(&old_hdl, lustre_msg_get_handle(request->rq_repmsg),
                            sizeof(old_hdl))) {
@@ -931,7 +924,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
                         * eviction. If it is in recovery - we are safe to
                         * participate since we can reestablish all of our state
                         * with server again */
-                       if ((MSG_CONNECT_RECOVERING & msg_flags)) {
+                       if ((msg_flags & MSG_CONNECT_RECOVERING)) {
                                CDEBUG(level, "%s@%s changed server handle from %#llx to %#llx but is still in recovery\n",
                                       obd2cli_tgt(imp->imp_obd),
                                       imp->imp_connection->c_remote_uuid.uuid,
@@ -948,11 +941,10 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
                                                      request->rq_repmsg)->cookie);
                        }
 
-
                        imp->imp_remote_handle =
                                     *lustre_msg_get_handle(request->rq_repmsg);
 
-                       if (!(MSG_CONNECT_RECOVERING & msg_flags)) {
+                       if (!(msg_flags & MSG_CONNECT_RECOVERING)) {
                                IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
                                rc = 0;
                                goto finish;
@@ -968,7 +960,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
                        CDEBUG(D_HA, "%s: reconnected but import is invalid; marking evicted\n",
                               imp->imp_obd->obd_name);
                        IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
-               } else if (MSG_CONNECT_RECOVERING & msg_flags) {
+               } else if (msg_flags & MSG_CONNECT_RECOVERING) {
                        CDEBUG(D_HA, "%s: reconnected to %s during replay\n",
                               imp->imp_obd->obd_name,
                               obd2cli_tgt(imp->imp_obd));
@@ -981,7 +973,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
                } else {
                        IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
                }
-       } else if ((MSG_CONNECT_RECOVERING & msg_flags) && !imp->imp_invalid) {
+       } else if ((msg_flags & MSG_CONNECT_RECOVERING) && !imp->imp_invalid) {
                LASSERT(imp->imp_replayable);
                imp->imp_remote_handle =
                                *lustre_msg_get_handle(request->rq_repmsg);
@@ -1264,7 +1256,7 @@ static int signal_completed_replay(struct obd_import *imp)
                req->rq_timeout *= 3;
        req->rq_interpret_reply = completed_replay_interpret;
 
-       ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+       ptlrpcd_add_req(req);
        return 0;
 }
 
@@ -1511,16 +1503,6 @@ out:
 }
 EXPORT_SYMBOL(ptlrpc_disconnect_import);
 
-void ptlrpc_cleanup_imp(struct obd_import *imp)
-{
-       spin_lock(&imp->imp_lock);
-       IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED);
-       imp->imp_generation++;
-       spin_unlock(&imp->imp_lock);
-       ptlrpc_abort_inflight(imp);
-}
-EXPORT_SYMBOL(ptlrpc_cleanup_imp);
-
 /* Adaptive Timeout utils */
 extern unsigned int at_min, at_max, at_history;
 
@@ -1531,12 +1513,12 @@ extern unsigned int at_min, at_max, at_history;
 int at_measured(struct adaptive_timeout *at, unsigned int val)
 {
        unsigned int old = at->at_current;
-       time_t now = get_seconds();
-       time_t binlimit = max_t(time_t, at_history / AT_BINS, 1);
+       time64_t now = ktime_get_real_seconds();
+       long binlimit = max_t(long, at_history / AT_BINS, 1);
 
        LASSERT(at);
        CDEBUG(D_OTHER, "add %u to %p time=%lu v=%u (%u %u %u %u)\n",
-              val, at, now - at->at_binstart, at->at_current,
+              val, at, (long)(now - at->at_binstart), at->at_current,
               at->at_hist[0], at->at_hist[1], at->at_hist[2], at->at_hist[3]);
 
        if (val == 0)
@@ -1561,7 +1543,7 @@ int at_measured(struct adaptive_timeout *at, unsigned int val)
                int i, shift;
                unsigned int maxv = val;
                /* move bins over */
-               shift = (now - at->at_binstart) / binlimit;
+               shift = (u32)(now - at->at_binstart) / binlimit;
                LASSERT(shift > 0);
                for (i = AT_BINS - 1; i >= 0; i--) {
                        if (i >= shift) {
index d14c200088507739b85a248342dadeb96a4ebf7f..d7c4f47808bd1682437c515d5bc66e46bd3e0c5a 100644 (file)
@@ -404,6 +404,7 @@ static const struct req_msg_field *ldlm_intent_layout_client[] = {
        &RMF_LAYOUT_INTENT,
        &RMF_EADATA /* for new layout to be set up */
 };
+
 static const struct req_msg_field *ldlm_intent_open_server[] = {
        &RMF_PTLRPC_BODY,
        &RMF_DLM_REP,
@@ -578,7 +579,6 @@ static const struct req_msg_field *ost_destroy_client[] = {
        &RMF_CAPA1
 };
 
-
 static const struct req_msg_field *ost_brw_client[] = {
        &RMF_PTLRPC_BODY,
        &RMF_OST_BODY,
@@ -789,17 +789,17 @@ enum rmf_flags {
        /**
         * The field is a string, must be NUL-terminated.
         */
-       RMF_F_STRING = 1 << 0,
+       RMF_F_STRING = BIT(0),
        /**
         * The field's buffer size need not match the declared \a rmf_size.
         */
-       RMF_F_NO_SIZE_CHECK = 1 << 1,
+       RMF_F_NO_SIZE_CHECK = BIT(1),
        /**
         * The field's buffer size must be a whole multiple of the declared \a
         * rmf_size and the \a rmf_swabber function must work on the declared \a
         * rmf_size worth of bytes.
         */
-       RMF_F_STRUCT_ARRAY = 1 << 2
+       RMF_F_STRUCT_ARRAY = BIT(2)
 };
 
 struct req_capsule;
@@ -1679,7 +1679,7 @@ EXPORT_SYMBOL(req_layout_fini);
  * req_capsule_msg_size().  The \a rc_area information is used by.
  * ptlrpc_request_set_replen().
  */
-void req_capsule_init_area(struct req_capsule *pill)
+static void req_capsule_init_area(struct req_capsule *pill)
 {
        int i;
 
@@ -1688,7 +1688,6 @@ void req_capsule_init_area(struct req_capsule *pill)
                pill->rc_area[RCL_SERVER][i] = -1;
        }
 }
-EXPORT_SYMBOL(req_capsule_init_area);
 
 /**
  * Initialize a pill.
@@ -1995,55 +1994,6 @@ static void *__req_capsule_get(struct req_capsule *pill,
        return value;
 }
 
-/**
- * Dump a request and/or reply
- */
-static void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
-{
-       const struct req_format *fmt;
-       const struct req_msg_field *field;
-       int len;
-       int i;
-
-       fmt = pill->rc_fmt;
-
-       DEBUG_REQ(D_RPCTRACE, pill->rc_req, "BEGIN REQ CAPSULE DUMP\n");
-       for (i = 0; i < fmt->rf_fields[loc].nr; ++i) {
-               field = FMT_FIELD(fmt, loc, i);
-               if (field->rmf_dumper == NULL) {
-                       /*
-                        * FIXME Add a default hex dumper for fields that don't
-                        * have a specific dumper
-                        */
-                       len = req_capsule_get_size(pill, field, loc);
-                       CDEBUG(D_RPCTRACE, "Field %s has no dumper function; field size is %d\n",
-                              field->rmf_name, len);
-               } else {
-                       /* It's the dumping side-effect that we're interested in */
-                       (void) __req_capsule_get(pill, field, loc, NULL, 1);
-               }
-       }
-       CDEBUG(D_RPCTRACE, "END REQ CAPSULE DUMP\n");
-}
-
-/**
- * Dump a request.
- */
-void req_capsule_client_dump(struct req_capsule *pill)
-{
-       __req_capsule_dump(pill, RCL_CLIENT);
-}
-EXPORT_SYMBOL(req_capsule_client_dump);
-
-/**
- * Dump a reply
- */
-void req_capsule_server_dump(struct req_capsule *pill)
-{
-       __req_capsule_dump(pill, RCL_SERVER);
-}
-EXPORT_SYMBOL(req_capsule_server_dump);
-
 /**
  * Trivial wrapper around __req_capsule_get(), that returns the PTLRPC request
  * buffer corresponding to the given RMF (\a field) of a \a pill.
@@ -2135,21 +2085,6 @@ void *req_capsule_server_sized_swab_get(struct req_capsule *pill,
 }
 EXPORT_SYMBOL(req_capsule_server_sized_swab_get);
 
-/**
- * Returns the buffer of a \a pill corresponding to the given \a field from the
- * request (if the caller is executing on the server-side) or reply (if the
- * caller is executing on the client-side).
- *
- * This function convenient for use is code that could be executed on the
- * client and server alike.
- */
-const void *req_capsule_other_get(struct req_capsule *pill,
-                                 const struct req_msg_field *field)
-{
-       return __req_capsule_get(pill, field, pill->rc_loc ^ 1, NULL, 0);
-}
-EXPORT_SYMBOL(req_capsule_other_get);
-
 /**
  * Set the size of the PTLRPC request/reply (\a loc) buffer for the given \a
  * field of the given \a pill.
@@ -2324,9 +2259,9 @@ EXPORT_SYMBOL(req_capsule_has_field);
  * Returns a non-zero value if the given \a field is present in the given \a
  * pill's PTLRPC request or reply (\a loc), else it returns 0.
  */
-int req_capsule_field_present(const struct req_capsule *pill,
-                             const struct req_msg_field *field,
-                             enum req_location loc)
+static int req_capsule_field_present(const struct req_capsule *pill,
+                                    const struct req_msg_field *field,
+                                    enum req_location loc)
 {
        int offset;
 
@@ -2336,7 +2271,6 @@ int req_capsule_field_present(const struct req_capsule *pill,
        offset = __req_capsule_offset(pill, field, loc);
        return lustre_msg_bufcount(__req_msg(pill, loc)) > offset;
 }
-EXPORT_SYMBOL(req_capsule_field_present);
 
 /**
  * This function shrinks the size of the _buffer_ of the \a pill's PTLRPC
@@ -2376,67 +2310,5 @@ void req_capsule_shrink(struct req_capsule *pill,
 }
 EXPORT_SYMBOL(req_capsule_shrink);
 
-int req_capsule_server_grow(struct req_capsule *pill,
-                           const struct req_msg_field *field,
-                           unsigned int newlen)
-{
-       struct ptlrpc_reply_state *rs = pill->rc_req->rq_reply_state, *nrs;
-       char *from, *to;
-       int offset, len, rc;
-
-       LASSERT(pill->rc_fmt != NULL);
-       LASSERT(__req_format_is_sane(pill->rc_fmt));
-       LASSERT(req_capsule_has_field(pill, field, RCL_SERVER));
-       LASSERT(req_capsule_field_present(pill, field, RCL_SERVER));
-
-       len = req_capsule_get_size(pill, field, RCL_SERVER);
-       offset = __req_capsule_offset(pill, field, RCL_SERVER);
-       if (pill->rc_req->rq_repbuf_len >=
-           lustre_packed_msg_size(pill->rc_req->rq_repmsg) - len + newlen)
-               CERROR("Inplace repack might be done\n");
-
-       pill->rc_req->rq_reply_state = NULL;
-       req_capsule_set_size(pill, field, RCL_SERVER, newlen);
-       rc = req_capsule_server_pack(pill);
-       if (rc) {
-               /* put old rs back, the caller will decide what to do */
-               pill->rc_req->rq_reply_state = rs;
-               return rc;
-       }
-       nrs = pill->rc_req->rq_reply_state;
-       /* Now we need only buffers, copy first chunk */
-       to = lustre_msg_buf(nrs->rs_msg, 0, 0);
-       from = lustre_msg_buf(rs->rs_msg, 0, 0);
-       len = (char *)lustre_msg_buf(rs->rs_msg, offset, 0) - from;
-       memcpy(to, from, len);
-       /* check if we have tail and copy it too */
-       if (rs->rs_msg->lm_bufcount > offset + 1) {
-               to = lustre_msg_buf(nrs->rs_msg, offset + 1, 0);
-               from = lustre_msg_buf(rs->rs_msg, offset + 1, 0);
-               offset = rs->rs_msg->lm_bufcount - 1;
-               len = (char *)lustre_msg_buf(rs->rs_msg, offset, 0) +
-                     cfs_size_round(rs->rs_msg->lm_buflens[offset]) - from;
-               memcpy(to, from, len);
-       }
-       /* drop old reply if everything is fine */
-       if (rs->rs_difficult) {
-               /* copy rs data */
-               int i;
-
-               nrs->rs_difficult = 1;
-               nrs->rs_no_ack = rs->rs_no_ack;
-               for (i = 0; i < rs->rs_nlocks; i++) {
-                       nrs->rs_locks[i] = rs->rs_locks[i];
-                       nrs->rs_modes[i] = rs->rs_modes[i];
-                       nrs->rs_nlocks++;
-               }
-               rs->rs_nlocks = 0;
-               rs->rs_difficult = 0;
-               rs->rs_no_ack = 0;
-       }
-       ptlrpc_rs_decref(rs);
-       return 0;
-}
-EXPORT_SYMBOL(req_capsule_server_grow);
 /* __REQ_LAYOUT_USER__ */
 #endif
index 1c701e0a0bc71b6b670d9fa5c31ff00860d3cb5d..5122205cbb99c41599554ce34502f72ec1687d2a 100644 (file)
@@ -118,6 +118,7 @@ static int llog_client_open(const struct lu_env *env,
 
        if (name) {
                char *tmp;
+
                tmp = req_capsule_client_sized_get(&req->rq_pill, &RMF_NAME,
                                                   strlen(name) + 1);
                LASSERT(tmp);
@@ -142,41 +143,6 @@ out:
        return rc;
 }
 
-static int llog_client_destroy(const struct lu_env *env,
-                              struct llog_handle *loghandle)
-{
-       struct obd_import *imp;
-       struct ptlrpc_request *req = NULL;
-       struct llogd_body *body;
-       int rc;
-
-       LLOG_CLIENT_ENTRY(loghandle->lgh_ctxt, imp);
-       req = ptlrpc_request_alloc_pack(imp, &RQF_LLOG_ORIGIN_HANDLE_DESTROY,
-                                       LUSTRE_LOG_VERSION,
-                                       LLOG_ORIGIN_HANDLE_DESTROY);
-       if (req == NULL) {
-               rc = -ENOMEM;
-               goto err_exit;
-       }
-
-       body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
-       body->lgd_logid = loghandle->lgh_id;
-       body->lgd_llh_flags = loghandle->lgh_hdr->llh_flags;
-
-       if (!(body->lgd_llh_flags & LLOG_F_IS_PLAIN))
-               CERROR("%s: wrong llog flags %x\n", imp->imp_obd->obd_name,
-                      body->lgd_llh_flags);
-
-       ptlrpc_request_set_replen(req);
-       rc = ptlrpc_queue_wait(req);
-
-       ptlrpc_req_finished(req);
-err_exit:
-       LLOG_CLIENT_EXIT(loghandle->lgh_ctxt, imp);
-       return rc;
-}
-
-
 static int llog_client_next_block(const struct lu_env *env,
                                  struct llog_handle *loghandle,
                                  int *cur_idx, int next_idx,
@@ -360,7 +326,6 @@ struct llog_operations llog_client_ops = {
        .lop_prev_block         = llog_client_prev_block,
        .lop_read_header        = llog_client_read_header,
        .lop_open               = llog_client_open,
-       .lop_destroy            = llog_client_destroy,
        .lop_close              = llog_client_close,
 };
 EXPORT_SYMBOL(llog_client_ops);
index 53f9af1f2f3eaa109599b9a3e610171acf7ecd64..afab0dee7a5ce0603bb26b1636c0dbb58b3aae66 100644 (file)
@@ -35,7 +35,6 @@
  */
 #define DEBUG_SUBSYSTEM S_CLASS
 
-
 #include "../include/obd_support.h"
 #include "../include/obd.h"
 #include "../include/lprocfs_status.h"
@@ -44,7 +43,6 @@
 #include "../include/obd_class.h"
 #include "ptlrpc_internal.h"
 
-
 static struct ll_rpc_opcode {
        __u32       opcode;
        const char *opname;
@@ -54,7 +52,7 @@ static struct ll_rpc_opcode {
        { OST_SETATTR,      "ost_setattr" },
        { OST_READ,      "ost_read" },
        { OST_WRITE,    "ost_write" },
-       { OST_CREATE ,      "ost_create" },
+       { OST_CREATE      "ost_create" },
        { OST_DESTROY,      "ost_destroy" },
        { OST_GET_INFO,     "ost_get_info" },
        { OST_CONNECT,      "ost_connect" },
@@ -166,6 +164,7 @@ const char *ll_opcode2str(__u32 opcode)
         *      ptlrpc_internal.h needs to be modified.
         */
        __u32 offset = opcode_offset(opcode);
+
        LASSERTF(offset < LUSTRE_MAX_OPCODES,
                 "offset %u >= LUSTRE_MAX_OPCODES %u\n",
                 offset, LUSTRE_MAX_OPCODES);
@@ -239,6 +238,7 @@ ptlrpc_ldebugfs_register(struct dentry *root, char *dir,
        }
        for (i = 0; i < LUSTRE_MAX_OPCODES; i++) {
                __u32 opcode = ll_rpc_opcode_table[i].opcode;
+
                lprocfs_counter_init(svc_stats,
                                     EXTRA_MAX_OPCODES + i, svc_counter_config,
                                     ll_opcode2str(opcode), "usec");
@@ -270,6 +270,7 @@ ptlrpc_lprocfs_req_history_len_seq_show(struct seq_file *m, void *v)
        seq_printf(m, "%d\n", total);
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_req_history_len);
 
 static int
@@ -322,8 +323,8 @@ ptlrpc_lprocfs_req_history_max_seq_write(struct file *file,
 
        return count;
 }
-LPROC_SEQ_FOPS(ptlrpc_lprocfs_req_history_max);
 
+LPROC_SEQ_FOPS(ptlrpc_lprocfs_req_history_max);
 
 static ssize_t threads_min_show(struct kobject *kobj, struct attribute *attr,
                                char *buf)
@@ -420,7 +421,6 @@ LUSTRE_RW_ATTR(threads_max);
  * \addtogoup nrs
  * @{
  */
-extern struct nrs_core nrs_core;
 
 /**
  * Translates \e ptlrpc_nrs_pol_state values to human-readable strings.
@@ -453,7 +453,7 @@ static const char *nrs_state2str(enum ptlrpc_nrs_pol_state state)
  * \param[in] policy The policy
  * \param[out] info  Holds returned status information
  */
-void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
+static void nrs_policy_get_info_locked(struct ptlrpc_nrs_policy *policy,
                                struct ptlrpc_nrs_pol_info *info)
 {
        LASSERT(policy != NULL);
@@ -714,6 +714,7 @@ out:
 
        return rc < 0 ? rc : count;
 }
+
 LPROC_SEQ_FOPS(ptlrpc_lprocfs_nrs);
 
 /** @} nrs */
@@ -891,36 +892,6 @@ ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
        return NULL;
 }
 
-/* common ost/mdt so_req_printer */
-void target_print_req(void *seq_file, struct ptlrpc_request *req)
-{
-       /* Called holding srv_lock with irqs disabled.
-        * Print specific req contents and a newline.
-        * CAVEAT EMPTOR: check request message length before printing!!!
-        * You might have received any old crap so you must be just as
-        * careful here as the service's request parser!!! */
-       struct seq_file *sf = seq_file;
-
-       switch (req->rq_phase) {
-       case RQ_PHASE_NEW:
-               /* still awaiting a service thread's attention, or rejected
-                * because the generic request message didn't unpack */
-               seq_printf(sf, "<not swabbed>\n");
-               break;
-       case RQ_PHASE_INTERPRET:
-               /* being handled, so basic msg swabbed, and opc is valid
-                * but racing with mds_handle() */
-       case RQ_PHASE_COMPLETE:
-               /* been handled by mds_handle() reply state possibly still
-                * volatile */
-               seq_printf(sf, "opc %d\n", lustre_msg_get_opc(req->rq_reqmsg));
-               break;
-       default:
-               DEBUG_REQ(D_ERROR, req, "bad phase %d", req->rq_phase);
-       }
-}
-EXPORT_SYMBOL(target_print_req);
-
 static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
 {
        struct ptlrpc_service *svc = s->private;
@@ -938,23 +909,26 @@ static int ptlrpc_lprocfs_svc_req_history_show(struct seq_file *s, void *iter)
        rc = ptlrpc_lprocfs_svc_req_history_seek(svcpt, srhi, srhi->srhi_seq);
 
        if (rc == 0) {
+               char nidstr[LNET_NIDSTR_SIZE];
+
                req = srhi->srhi_req;
 
+               libcfs_nid2str_r(req->rq_self, nidstr, sizeof(nidstr));
                /* Print common req fields.
                 * CAVEAT EMPTOR: we're racing with the service handler
                 * here.  The request could contain any old crap, so you
                 * must be just as careful as the service's request
                 * parser. Currently I only print stuff here I know is OK
                 * to look at coz it was set up in request_in_callback()!!! */
-               seq_printf(s, "%lld:%s:%s:x%llu:%d:%s:%ld:%lds(%+lds) ",
-                          req->rq_history_seq, libcfs_nid2str(req->rq_self),
+               seq_printf(s, "%lld:%s:%s:x%llu:%d:%s:%lld:%lds(%+lds) ",
+                          req->rq_history_seq, nidstr,
                           libcfs_id2str(req->rq_peer), req->rq_xid,
                           req->rq_reqlen, ptlrpc_rqphase2str(req),
-                          req->rq_arrival_time.tv_sec,
-                          req->rq_sent - req->rq_arrival_time.tv_sec,
-                          req->rq_sent - req->rq_deadline);
+                          (s64)req->rq_arrival_time.tv_sec,
+                          (long)(req->rq_sent - req->rq_arrival_time.tv_sec),
+                          (long)(req->rq_sent - req->rq_deadline));
                if (svc->srv_ops.so_req_printer == NULL)
-                       seq_printf(s, "\n");
+                       seq_putc(s, '\n');
                else
                        svc->srv_ops.so_req_printer(s, srhi->srhi_req);
        }
@@ -990,7 +964,7 @@ static int ptlrpc_lprocfs_timeouts_seq_show(struct seq_file *m, void *n)
        struct ptlrpc_service *svc = m->private;
        struct ptlrpc_service_part *svcpt;
        struct dhms ts;
-       time_t worstt;
+       time64_t worstt;
        unsigned int cur;
        unsigned int worst;
        int i;
@@ -1005,17 +979,18 @@ static int ptlrpc_lprocfs_timeouts_seq_show(struct seq_file *m, void *n)
                cur     = at_get(&svcpt->scp_at_estimate);
                worst   = svcpt->scp_at_estimate.at_worst_ever;
                worstt  = svcpt->scp_at_estimate.at_worst_time;
-               s2dhms(&ts, get_seconds() - worstt);
+               s2dhms(&ts, ktime_get_real_seconds() - worstt);
 
-               seq_printf(m, "%10s : cur %3u  worst %3u (at %ld, "
+               seq_printf(m, "%10s : cur %3u  worst %3u (at %lld, "
                              DHMS_FMT" ago) ", "service",
-                             cur, worst, worstt, DHMS_VARS(&ts));
+                             cur, worst, (s64)worstt, DHMS_VARS(&ts));
 
                lprocfs_at_hist_helper(m, &svcpt->scp_at_estimate);
        }
 
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(ptlrpc_lprocfs_timeouts);
 
 static ssize_t high_priority_ratio_show(struct kobject *kobj,
@@ -1208,55 +1183,6 @@ void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd)
 }
 EXPORT_SYMBOL(ptlrpc_lprocfs_unregister_obd);
 
-
-#define BUFLEN (UUID_MAX + 5)
-
-int lprocfs_wr_evict_client(struct file *file, const char __user *buffer,
-                           size_t count, loff_t *off)
-{
-       struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
-       char *kbuf;
-       char *tmpbuf;
-
-       kbuf = kzalloc(BUFLEN, GFP_NOFS);
-       if (!kbuf)
-               return -ENOMEM;
-
-       /*
-        * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
-        * bytes into kbuf, to ensure that the string is NUL-terminated.
-        * UUID_MAX should include a trailing NUL already.
-        */
-       if (copy_from_user(kbuf, buffer,
-                              min_t(unsigned long, BUFLEN - 1, count))) {
-               count = -EFAULT;
-               goto out;
-       }
-       tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
-       /* Kludge code(deadlock situation): the lprocfs lock has been held
-        * since the client is evicted by writing client's
-        * uuid/nid to procfs "evict_client" entry. However,
-        * obd_export_evict_by_uuid() will call ldebugfs_remove() to destroy
-        * the proc entries under the being destroyed export{}, so I have
-        * to drop the lock at first here.
-        * - jay, jxiong@clusterfs.com */
-       class_incref(obd, __func__, current);
-
-       if (strncmp(tmpbuf, "nid:", 4) == 0)
-               obd_export_evict_by_nid(obd, tmpbuf + 4);
-       else if (strncmp(tmpbuf, "uuid:", 5) == 0)
-               obd_export_evict_by_uuid(obd, tmpbuf + 5);
-       else
-               obd_export_evict_by_uuid(obd, tmpbuf);
-
-       class_decref(obd, __func__, current);
-
-out:
-       kfree(kbuf);
-       return count;
-}
-EXPORT_SYMBOL(lprocfs_wr_evict_client);
-
 #undef BUFLEN
 
 int lprocfs_wr_ping(struct file *file, const char __user *buffer,
@@ -1266,7 +1192,10 @@ int lprocfs_wr_ping(struct file *file, const char __user *buffer,
        struct ptlrpc_request *req;
        int rc;
 
-       LPROCFS_CLIMP_CHECK(obd);
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
+
        req = ptlrpc_prep_ping(obd->u.cli.cl_import);
        LPROCFS_CLIMP_EXIT(obd);
        if (req == NULL)
@@ -1328,7 +1257,7 @@ int lprocfs_wr_import(struct file *file, const char __user *buffer,
                *ptr = 0;
                do_reconn = 0;
                ptr += strlen("::");
-               inst = simple_strtol(ptr, &endptr, 10);
+               inst = simple_strtoul(ptr, &endptr, 10);
                if (*endptr) {
                        CERROR("config: wrong instance # %s\n", ptr);
                } else if (inst != imp->imp_connect_data.ocd_instance) {
@@ -1355,8 +1284,12 @@ int lprocfs_rd_pinger_recov(struct seq_file *m, void *n)
 {
        struct obd_device *obd = m->private;
        struct obd_import *imp = obd->u.cli.cl_import;
+       int rc;
+
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
 
-       LPROCFS_CLIMP_CHECK(obd);
        seq_printf(m, "%d\n", !imp->imp_no_pinger_recover);
        LPROCFS_CLIMP_EXIT(obd);
 
@@ -1379,7 +1312,10 @@ int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
        if (val != 0 && val != 1)
                return -ERANGE;
 
-       LPROCFS_CLIMP_CHECK(obd);
+       rc = lprocfs_climp_check(obd);
+       if (rc)
+               return rc;
+
        spin_lock(&imp->imp_lock);
        imp->imp_no_pinger_recover = !val;
        spin_unlock(&imp->imp_lock);
index 92c746b44462159ae64ae9338c0c3db2a9610604..09ddeef6ba484d543b327de89628bd3344746b45 100644 (file)
@@ -106,12 +106,11 @@ static void mdunlink_iterate_helper(lnet_handle_md_t *bd_mds, int count)
                LNetMDUnlink(bd_mds[i]);
 }
 
-
 /**
  * Register bulk at the sender for later transfer.
  * Returns 0 on success or error code.
  */
-int ptlrpc_register_bulk(struct ptlrpc_request *req)
+static int ptlrpc_register_bulk(struct ptlrpc_request *req)
 {
        struct ptlrpc_bulk_desc *desc = req->rq_bulk;
        lnet_process_id_t peer;
@@ -232,7 +231,6 @@ int ptlrpc_register_bulk(struct ptlrpc_request *req)
 
        return 0;
 }
-EXPORT_SYMBOL(ptlrpc_register_bulk);
 
 /**
  * Disconnect a bulk desc from the network. Idempotent. Not
@@ -252,7 +250,7 @@ int ptlrpc_unregister_bulk(struct ptlrpc_request *req, int async)
        /* Let's setup deadline for reply unlink. */
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_LONG_BULK_UNLINK) &&
            async && req->rq_bulk_deadline == 0)
-               req->rq_bulk_deadline = get_seconds() + LONG_UNLINK;
+               req->rq_bulk_deadline = ktime_get_real_seconds() + LONG_UNLINK;
 
        if (ptlrpc_client_bulk_active(req) == 0)        /* completed or */
                return 1;                               /* never registered */
@@ -303,7 +301,7 @@ static void ptlrpc_at_set_reply(struct ptlrpc_request *req, int flags)
 {
        struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
        struct ptlrpc_service *svc = svcpt->scp_service;
-       int service_time = max_t(int, get_seconds() -
+       int service_time = max_t(int, ktime_get_real_seconds() -
                                 req->rq_arrival_time.tv_sec, 1);
 
        if (!(flags & PTLRPC_REPLY_EARLY) &&
@@ -328,8 +326,7 @@ static void ptlrpc_at_set_reply(struct ptlrpc_request *req, int flags)
        /* Report service time estimate for future client reqs, but report 0
         * (to be ignored by client) if it's a error reply during recovery.
         * (bz15815) */
-       if (req->rq_type == PTL_RPC_MSG_ERR &&
-           (req->rq_export == NULL || req->rq_export->exp_obd->obd_recovering))
+       if (req->rq_type == PTL_RPC_MSG_ERR && !req->rq_export)
                lustre_msg_set_timeout(req->rq_repmsg, 0);
        else
                lustre_msg_set_timeout(req->rq_repmsg,
@@ -337,9 +334,8 @@ static void ptlrpc_at_set_reply(struct ptlrpc_request *req, int flags)
 
        if (req->rq_reqmsg &&
            !(lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) {
-               CDEBUG(D_ADAPTTO, "No early reply support: flags=%#x req_flags=%#x magic=%d:%x/%x len=%d\n",
+               CDEBUG(D_ADAPTTO, "No early reply support: flags=%#x req_flags=%#x magic=%x/%x len=%d\n",
                       flags, lustre_msg_get_flags(req->rq_reqmsg),
-                      lustre_msg_is_v1(req->rq_reqmsg),
                       lustre_msg_get_magic(req->rq_reqmsg),
                       lustre_msg_get_magic(req->rq_repmsg), req->rq_replen);
        }
@@ -422,7 +418,7 @@ int ptlrpc_send_reply(struct ptlrpc_request *req, int flags)
        if (unlikely(rc))
                goto out;
 
-       req->rq_sent = get_seconds();
+       req->rq_sent = ktime_get_real_seconds();
 
        rc = ptl_send_buf(&rs->rs_md_h, rs->rs_repbuf, rs->rs_repdata_len,
                          (rs->rs_difficult && !rs->rs_no_ack) ?
@@ -601,7 +597,7 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply)
                /* Manage remote for early replies */
                reply_md.options = PTLRPC_MD_OPTIONS | LNET_MD_OP_PUT |
                        LNET_MD_MANAGE_REMOTE |
-                       LNET_MD_TRUNCATE; /* allow to make EOVERFLOW error */;
+                       LNET_MD_TRUNCATE; /* allow to make EOVERFLOW error */
                reply_md.user_ptr = &request->rq_reply_cbid;
                reply_md.eq_handle = ptlrpc_eq_h;
 
@@ -633,8 +629,8 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply)
 
        OBD_FAIL_TIMEOUT(OBD_FAIL_PTLRPC_DELAY_SEND, request->rq_timeout + 5);
 
-       do_gettimeofday(&request->rq_arrival_time);
-       request->rq_sent = get_seconds();
+       ktime_get_real_ts64(&request->rq_arrival_time);
+       request->rq_sent = ktime_get_real_seconds();
        /* We give the server rq_timeout secs to process the req, and
           add the network latency for our local timeout. */
        request->rq_deadline = request->rq_sent + request->rq_timeout +
index d37cdd5ac58065481ec7403c7d9962cef90df1c4..7044e1ff66920eb3a1430efd38a4a2dcb66bacab 100644 (file)
@@ -49,7 +49,6 @@
 
 /* XXX: This is just for liblustre. Remove the #if defined directive when the
  * "cfs_" prefix is dropped from cfs_list_head. */
-extern struct list_head ptlrpc_all_services;
 
 /**
  * NRS core object.
@@ -478,7 +477,6 @@ static void nrs_resource_get_safe(struct ptlrpc_nrs *nrs,
  *
  * \param resp the resource hierarchy that is being released
  *
- * \see ptlrpc_nrs_req_hp_move()
  * \see ptlrpc_nrs_req_finalize()
  */
 static void nrs_resource_put_safe(struct ptlrpc_nrs_resource **resp)
@@ -1113,7 +1111,7 @@ again:
  * \retval -ve error
  * \retval   0 success
  */
-int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
+static int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
 {
        struct ptlrpc_service *svc;
        struct ptlrpc_nrs_pol_desc *desc;
@@ -1249,71 +1247,6 @@ fail:
 
        return rc;
 }
-EXPORT_SYMBOL(ptlrpc_nrs_policy_register);
-
-/**
- * Unregisters a previously registered policy with NRS core. All instances of
- * the policy on all NRS heads of all supported services are removed.
- *
- * N.B. This function should only be called from a module's exit() function.
- *     Although it can be used for policies that ship alongside NRS core, the
- *     function is primarily intended for policies that register externally,
- *     from other modules.
- *
- * \param[in] conf configuration information for the policy to unregister
- *
- * \retval -ve error
- * \retval   0 success
- */
-int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf)
-{
-       struct ptlrpc_nrs_pol_desc *desc;
-       int rc;
-
-       LASSERT(conf != NULL);
-
-       if (conf->nc_flags & PTLRPC_NRS_FL_FALLBACK) {
-               CERROR("Unable to unregister a fallback policy, unless the PTLRPC service is stopping.\n");
-               return -EPERM;
-       }
-
-       conf->nc_name[NRS_POL_NAME_MAX - 1] = '\0';
-
-       mutex_lock(&nrs_core.nrs_mutex);
-
-       desc = nrs_policy_find_desc_locked(conf->nc_name);
-       if (desc == NULL) {
-               CERROR("Failing to unregister NRS policy %s which has not been registered with NRS core!\n",
-                      conf->nc_name);
-               rc = -ENOENT;
-               goto not_exist;
-       }
-
-       mutex_lock(&ptlrpc_all_services_mutex);
-
-       rc = nrs_policy_unregister_locked(desc);
-       if (rc < 0) {
-               if (rc == -EBUSY)
-                       CERROR("Please first stop policy %s on all service partitions and then retry to unregister the policy.\n",
-                              conf->nc_name);
-               goto fail;
-       }
-
-       CDEBUG(D_INFO, "Unregistering policy %s from NRS core.\n",
-              conf->nc_name);
-
-       list_del(&desc->pd_list);
-       kfree(desc);
-
-fail:
-       mutex_unlock(&ptlrpc_all_services_mutex);
-
-not_exist:
-       mutex_unlock(&nrs_core.nrs_mutex);
-
-       return rc;
-}
-EXPORT_SYMBOL(ptlrpc_nrs_policy_unregister);
 
 /**
  * Setup NRS heads on all service partitions of service \a svc, and register
@@ -1553,22 +1486,6 @@ ptlrpc_nrs_req_get_nolock0(struct ptlrpc_service_part *svcpt, bool hp,
        return NULL;
 }
 
-/**
- * Dequeues request \a req from the policy it has been enqueued on.
- *
- * \param[in] req the request
- */
-void ptlrpc_nrs_req_del_nolock(struct ptlrpc_request *req)
-{
-       struct ptlrpc_nrs_policy *policy = nrs_request_policy(&req->rq_nrq);
-
-       policy->pol_desc->pd_ops->op_req_dequeue(policy, &req->rq_nrq);
-
-       req->rq_nrq.nr_enqueued = 0;
-
-       nrs_request_removed(policy);
-}
-
 /**
  * Returns whether there are any requests currently enqueued on any of the
  * policies of service partition's \a svcpt NRS head specified by \a hp. Should
@@ -1589,48 +1506,6 @@ bool ptlrpc_nrs_req_pending_nolock(struct ptlrpc_service_part *svcpt, bool hp)
        return nrs->nrs_req_queued > 0;
 };
 
-/**
- * Moves request \a req from the regular to the high-priority NRS head.
- *
- * \param[in] req the request to move
- */
-void ptlrpc_nrs_req_hp_move(struct ptlrpc_request *req)
-{
-       struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
-       struct ptlrpc_nrs_request *nrq = &req->rq_nrq;
-       struct ptlrpc_nrs_resource *res1[NRS_RES_MAX];
-       struct ptlrpc_nrs_resource *res2[NRS_RES_MAX];
-
-       /**
-        * Obtain the high-priority NRS head resources.
-        */
-       nrs_resource_get_safe(nrs_svcpt2nrs(svcpt, true), nrq, res1, true);
-
-       spin_lock(&svcpt->scp_req_lock);
-
-       if (!ptlrpc_nrs_req_can_move(req))
-               goto out;
-
-       ptlrpc_nrs_req_del_nolock(req);
-
-       memcpy(res2, nrq->nr_res_ptrs, NRS_RES_MAX * sizeof(res2[0]));
-       memcpy(nrq->nr_res_ptrs, res1, NRS_RES_MAX * sizeof(res1[0]));
-
-       ptlrpc_nrs_hpreq_add_nolock(req);
-
-       memcpy(res1, res2, NRS_RES_MAX * sizeof(res1[0]));
-out:
-       spin_unlock(&svcpt->scp_req_lock);
-
-       /**
-        * Release either the regular NRS head resources if we moved the
-        * request, or the high-priority NRS head resources if we took a
-        * reference earlier in this function and ptlrpc_nrs_req_can_move()
-        * returned false.
-        */
-       nrs_resource_put_safe(res1);
-}
-
 /**
  * Carries out a control operation \a opc on the policy identified by the
  * human-readable \a name, on either all partitions, or only on the first
@@ -1698,7 +1573,6 @@ out:
        return rc;
 }
 
-
 /* ptlrpc/nrs_fifo.c */
 extern struct ptlrpc_nrs_pol_conf nrs_conf_fifo;
 
@@ -1720,7 +1594,6 @@ int ptlrpc_nrs_init(void)
        if (rc != 0)
                goto fail;
 
-
        return rc;
 fail:
        /**
index 84937ad905709633f9d33ffb456e5ccd006c9f2e..f3cb5184fa85172c56969c82be90290eda99cfc6 100644 (file)
@@ -94,32 +94,11 @@ int ptlrpc_buf_need_swab(struct ptlrpc_request *req, const int inout,
 }
 EXPORT_SYMBOL(ptlrpc_buf_need_swab);
 
-static inline int lustre_msg_check_version_v2(struct lustre_msg_v2 *msg,
-                                             __u32 version)
-{
-       __u32 ver = lustre_msg_get_version(msg);
-       return (ver & LUSTRE_VERSION_MASK) != version;
-}
-
-int lustre_msg_check_version(struct lustre_msg *msg, __u32 version)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               CERROR("msg v1 not supported - please upgrade you system\n");
-               return -EINVAL;
-       case LUSTRE_MSG_MAGIC_V2:
-               return lustre_msg_check_version_v2(msg, version);
-       default:
-               CERROR("incorrect message magic: %08x\n", msg->lm_magic);
-               return 0;
-       }
-}
-EXPORT_SYMBOL(lustre_msg_check_version);
-
 /* early reply size */
 int lustre_msg_early_size(void)
 {
        static int size;
+
        if (!size) {
                /* Always reply old ptlrpc_body_v2 to keep interoperability
                 * with the old client (< 2.3) which doesn't have pb_jobid
@@ -129,6 +108,7 @@ int lustre_msg_early_size(void)
                 *     client.
                 */
                __u32 pblen = sizeof(struct ptlrpc_body_v2);
+
                size = lustre_msg_size(LUSTRE_MSG_MAGIC_V2, 1, &pblen);
        }
        return size;
@@ -209,6 +189,7 @@ void lustre_init_msg_v2(struct lustre_msg_v2 *msg, int count, __u32 *lens,
        ptr = (char *)msg + lustre_msg_hdr_size_v2(count);
        for (i = 0; i < count; i++) {
                char *tmp = bufs[i];
+
                LOGL(tmp, lens[i], ptr);
        }
 }
@@ -433,14 +414,15 @@ void *lustre_msg_buf(struct lustre_msg *m, int n, int min_size)
        case LUSTRE_MSG_MAGIC_V2:
                return lustre_msg_buf_v2(m, n, min_size);
        default:
-               LASSERTF(0, "incorrect message magic: %08x(msg:%p)\n", m->lm_magic, m);
+               LASSERTF(0, "incorrect message magic: %08x (msg:%p)\n",
+                        m->lm_magic, m);
                return NULL;
        }
 }
 EXPORT_SYMBOL(lustre_msg_buf);
 
-int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
-                        unsigned int newlen, int move_data)
+static int lustre_shrink_msg_v2(struct lustre_msg_v2 *msg, int segment,
+                               unsigned int newlen, int move_data)
 {
        char *tail = NULL, *newpos;
        int tail_len = 0, n;
@@ -593,6 +575,7 @@ EXPORT_SYMBOL(__lustre_unpack_msg);
 int ptlrpc_unpack_req_msg(struct ptlrpc_request *req, int len)
 {
        int rc;
+
        rc = __lustre_unpack_msg(req->rq_reqmsg, len);
        if (rc == 1) {
                lustre_set_req_swabbed(req, MSG_PTLRPC_HEADER_OFF);
@@ -605,6 +588,7 @@ EXPORT_SYMBOL(ptlrpc_unpack_req_msg);
 int ptlrpc_unpack_rep_msg(struct ptlrpc_request *req, int len)
 {
        int rc;
+
        rc = __lustre_unpack_msg(req->rq_repmsg, len);
        if (rc == 1) {
                lustre_set_rep_swabbed(req, MSG_PTLRPC_HEADER_OFF);
@@ -692,28 +676,6 @@ int lustre_msg_buflen(struct lustre_msg *m, int n)
 }
 EXPORT_SYMBOL(lustre_msg_buflen);
 
-static inline void
-lustre_msg_set_buflen_v2(struct lustre_msg_v2 *m, int n, int len)
-{
-       if (n >= m->lm_bufcount)
-               LBUG();
-
-       m->lm_buflens[n] = len;
-}
-
-void lustre_msg_set_buflen(struct lustre_msg *m, int n, int len)
-{
-       switch (m->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V2:
-               lustre_msg_set_buflen_v2(m, n, len);
-               return;
-       default:
-               LASSERTF(0, "incorrect message magic: %08x\n", m->lm_magic);
-       }
-}
-
-EXPORT_SYMBOL(lustre_msg_set_buflen);
-
 /* NB return the bufcount for lustre_msg_v2 format, so if message is packed
  * in V1 format, the result is one bigger. (add struct ptlrpc_body). */
 int lustre_msg_bufcount(struct lustre_msg *m)
@@ -802,14 +764,11 @@ static inline struct ptlrpc_body *lustre_msg_ptlrpc_body(struct lustre_msg *msg)
 __u32 lustre_msghdr_get_flags(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-       case LUSTRE_MSG_MAGIC_V1_SWABBED:
-               return 0;
        case LUSTRE_MSG_MAGIC_V2:
                /* already in host endian */
                return msg->lm_flags;
        default:
-               LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
+               CERROR("incorrect message magic: %08x\n", msg->lm_magic);
                return 0;
        }
 }
@@ -818,8 +777,6 @@ EXPORT_SYMBOL(lustre_msghdr_get_flags);
 void lustre_msghdr_set_flags(struct lustre_msg *msg, __u32 flags)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               return;
        case LUSTRE_MSG_MAGIC_V2:
                msg->lm_flags = flags;
                return;
@@ -833,12 +790,13 @@ __u32 lustre_msg_get_flags(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               if (!pb) {
-                       CERROR("invalid msg %p: no ptlrpc body!\n", msg);
-                       return 0;
-               }
-               return pb->pb_flags;
+
+               if (pb)
+                       return pb->pb_flags;
+
+               CERROR("invalid msg %p: no ptlrpc body!\n", msg);
        }
+       /* no break */
        default:
                /* flags might be printed in debug code while message
                 * uninitialized */
@@ -852,6 +810,7 @@ void lustre_msg_add_flags(struct lustre_msg *msg, int flags)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_flags |= flags;
                return;
@@ -867,6 +826,7 @@ void lustre_msg_set_flags(struct lustre_msg *msg, int flags)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_flags = flags;
                return;
@@ -882,8 +842,9 @@ void lustre_msg_clear_flags(struct lustre_msg *msg, int flags)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
-               pb->pb_flags &= ~(MSG_GEN_FLAG_MASK & flags);
+               pb->pb_flags &= ~(flags & MSG_GEN_FLAG_MASK);
                return;
        }
        default:
@@ -897,12 +858,13 @@ __u32 lustre_msg_get_op_flags(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               if (!pb) {
-                       CERROR("invalid msg %p: no ptlrpc body!\n", msg);
-                       return 0;
-               }
-               return pb->pb_op_flags;
+
+               if (pb)
+                       return pb->pb_op_flags;
+
+               CERROR("invalid msg %p: no ptlrpc body!\n", msg);
        }
+       /* no break */
        default:
                return 0;
        }
@@ -914,21 +876,7 @@ void lustre_msg_add_op_flags(struct lustre_msg *msg, int flags)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
-               pb->pb_op_flags |= flags;
-               return;
-       }
-       default:
-               LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
-       }
-}
-EXPORT_SYMBOL(lustre_msg_add_op_flags);
 
-void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_op_flags |= flags;
                return;
@@ -937,13 +885,14 @@ void lustre_msg_set_op_flags(struct lustre_msg *msg, int flags)
                LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
        }
 }
-EXPORT_SYMBOL(lustre_msg_set_op_flags);
+EXPORT_SYMBOL(lustre_msg_add_op_flags);
 
 struct lustre_handle *lustre_msg_get_handle(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return NULL;
@@ -962,6 +911,7 @@ __u32 lustre_msg_get_type(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return PTL_RPC_MSG_ERR;
@@ -975,29 +925,12 @@ __u32 lustre_msg_get_type(struct lustre_msg *msg)
 }
 EXPORT_SYMBOL(lustre_msg_get_type);
 
-__u32 lustre_msg_get_version(struct lustre_msg *msg)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               if (!pb) {
-                       CERROR("invalid msg %p: no ptlrpc body!\n", msg);
-                       return 0;
-               }
-               return pb->pb_version;
-       }
-       default:
-               CERROR("incorrect message magic: %08x\n", msg->lm_magic);
-               return 0;
-       }
-}
-EXPORT_SYMBOL(lustre_msg_get_version);
-
 void lustre_msg_add_version(struct lustre_msg *msg, int version)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_version |= version;
                return;
@@ -1013,6 +946,7 @@ __u32 lustre_msg_get_opc(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1020,36 +954,19 @@ __u32 lustre_msg_get_opc(struct lustre_msg *msg)
                return pb->pb_opc;
        }
        default:
-               CERROR("incorrect message magic: %08x(msg:%p)\n", msg->lm_magic, msg);
-               LBUG();
+               CERROR("incorrect message magic: %08x (msg:%p)\n",
+                      msg->lm_magic, msg);
                return 0;
        }
 }
 EXPORT_SYMBOL(lustre_msg_get_opc);
 
-__u64 lustre_msg_get_last_xid(struct lustre_msg *msg)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               if (!pb) {
-                       CERROR("invalid msg %p: no ptlrpc body!\n", msg);
-                       return 0;
-               }
-               return pb->pb_last_xid;
-       }
-       default:
-               CERROR("incorrect message magic: %08x\n", msg->lm_magic);
-               return 0;
-       }
-}
-EXPORT_SYMBOL(lustre_msg_get_last_xid);
-
 __u64 lustre_msg_get_last_committed(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1066,10 +983,9 @@ EXPORT_SYMBOL(lustre_msg_get_last_committed);
 __u64 *lustre_msg_get_versions(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               return NULL;
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return NULL;
@@ -1088,6 +1004,7 @@ __u64 lustre_msg_get_transno(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1106,12 +1023,13 @@ int lustre_msg_get_status(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               if (!pb) {
-                       CERROR("invalid msg %p: no ptlrpc body!\n", msg);
-                       return -EINVAL;
-               }
-               return pb->pb_status;
+
+               if (pb)
+                       return pb->pb_status;
+
+               CERROR("invalid msg %p: no ptlrpc body!\n", msg);
        }
+       /* no break */
        default:
                /* status might be printed in debug code while message
                 * uninitialized */
@@ -1125,6 +1043,7 @@ __u64 lustre_msg_get_slv(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return -EINVAL;
@@ -1138,12 +1057,12 @@ __u64 lustre_msg_get_slv(struct lustre_msg *msg)
 }
 EXPORT_SYMBOL(lustre_msg_get_slv);
 
-
 void lustre_msg_set_slv(struct lustre_msg *msg, __u64 slv)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return;
@@ -1163,6 +1082,7 @@ __u32 lustre_msg_get_limit(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return -EINVAL;
@@ -1176,12 +1096,12 @@ __u32 lustre_msg_get_limit(struct lustre_msg *msg)
 }
 EXPORT_SYMBOL(lustre_msg_get_limit);
 
-
 void lustre_msg_set_limit(struct lustre_msg *msg, __u64 limit)
 {
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return;
@@ -1201,6 +1121,7 @@ __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1214,18 +1135,6 @@ __u32 lustre_msg_get_conn_cnt(struct lustre_msg *msg)
 }
 EXPORT_SYMBOL(lustre_msg_get_conn_cnt);
 
-int lustre_msg_is_v1(struct lustre_msg *msg)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-       case LUSTRE_MSG_MAGIC_V1_SWABBED:
-               return 1;
-       default:
-               return 0;
-       }
-}
-EXPORT_SYMBOL(lustre_msg_is_v1);
-
 __u32 lustre_msg_get_magic(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
@@ -1241,11 +1150,9 @@ EXPORT_SYMBOL(lustre_msg_get_magic);
 __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-       case LUSTRE_MSG_MAGIC_V1_SWABBED:
-               return 0;
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1255,18 +1162,16 @@ __u32 lustre_msg_get_timeout(struct lustre_msg *msg)
        }
        default:
                CERROR("incorrect message magic: %08x\n", msg->lm_magic);
-               return 0;
+               return -EPROTO;
        }
 }
 
 __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-       case LUSTRE_MSG_MAGIC_V1_SWABBED:
-               return 0;
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                if (!pb) {
                        CERROR("invalid msg %p: no ptlrpc body!\n", msg);
                        return 0;
@@ -1280,28 +1185,6 @@ __u32 lustre_msg_get_service_time(struct lustre_msg *msg)
        }
 }
 
-char *lustre_msg_get_jobid(struct lustre_msg *msg)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-       case LUSTRE_MSG_MAGIC_V1_SWABBED:
-               return NULL;
-       case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb =
-                       lustre_msg_buf_v2(msg, MSG_PTLRPC_BODY_OFF,
-                                         sizeof(struct ptlrpc_body));
-               if (!pb)
-                       return NULL;
-
-               return pb->pb_jobid;
-       }
-       default:
-               CERROR("incorrect message magic: %08x\n", msg->lm_magic);
-               return NULL;
-       }
-}
-EXPORT_SYMBOL(lustre_msg_get_jobid);
-
 __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
 {
        switch (msg->lm_magic) {
@@ -1320,6 +1203,7 @@ __u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
                __u32 crc;
                unsigned int hsize = 4;
+
                cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
                                   lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF),
                                   NULL, 0, (unsigned char *)&crc, &hsize);
@@ -1336,6 +1220,7 @@ void lustre_msg_set_handle(struct lustre_msg *msg, struct lustre_handle *handle)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_handle = *handle;
                return;
@@ -1351,6 +1236,7 @@ void lustre_msg_set_type(struct lustre_msg *msg, __u32 type)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_type = type;
                return;
@@ -1366,6 +1252,7 @@ void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_opc = opc;
                return;
@@ -1376,43 +1263,12 @@ void lustre_msg_set_opc(struct lustre_msg *msg, __u32 opc)
 }
 EXPORT_SYMBOL(lustre_msg_set_opc);
 
-void lustre_msg_set_last_xid(struct lustre_msg *msg, __u64 last_xid)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
-               pb->pb_last_xid = last_xid;
-               return;
-       }
-       default:
-               LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
-       }
-}
-EXPORT_SYMBOL(lustre_msg_set_last_xid);
-
-void lustre_msg_set_last_committed(struct lustre_msg *msg, __u64 last_committed)
-{
-       switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V2: {
-               struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
-               LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
-               pb->pb_last_committed = last_committed;
-               return;
-       }
-       default:
-               LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
-       }
-}
-EXPORT_SYMBOL(lustre_msg_set_last_committed);
-
 void lustre_msg_set_versions(struct lustre_msg *msg, __u64 *versions)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               return;
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_pre_versions[0] = versions[0];
                pb->pb_pre_versions[1] = versions[1];
@@ -1431,6 +1287,7 @@ void lustre_msg_set_transno(struct lustre_msg *msg, __u64 transno)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_transno = transno;
                return;
@@ -1446,6 +1303,7 @@ void lustre_msg_set_status(struct lustre_msg *msg, __u32 status)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_status = status;
                return;
@@ -1461,6 +1319,7 @@ void lustre_msg_set_conn_cnt(struct lustre_msg *msg, __u32 conn_cnt)
        switch (msg->lm_magic) {
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_conn_cnt = conn_cnt;
                return;
@@ -1474,10 +1333,9 @@ EXPORT_SYMBOL(lustre_msg_set_conn_cnt);
 void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               return;
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_timeout = timeout;
                return;
@@ -1490,10 +1348,9 @@ void lustre_msg_set_timeout(struct lustre_msg *msg, __u32 timeout)
 void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               return;
        case LUSTRE_MSG_MAGIC_V2: {
                struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
+
                LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
                pb->pb_service_time = service_time;
                return;
@@ -1506,8 +1363,6 @@ void lustre_msg_set_service_time(struct lustre_msg *msg, __u32 service_time)
 void lustre_msg_set_jobid(struct lustre_msg *msg, char *jobid)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               return;
        case LUSTRE_MSG_MAGIC_V2: {
                __u32 opc = lustre_msg_get_opc(msg);
                struct ptlrpc_body *pb;
@@ -1537,8 +1392,6 @@ EXPORT_SYMBOL(lustre_msg_set_jobid);
 void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
 {
        switch (msg->lm_magic) {
-       case LUSTRE_MSG_MAGIC_V1:
-               return;
        case LUSTRE_MSG_MAGIC_V2:
                msg->lm_cksum = cksum;
                return;
@@ -1547,7 +1400,6 @@ void lustre_msg_set_cksum(struct lustre_msg *msg, __u32 cksum)
        }
 }
 
-
 void ptlrpc_request_set_replen(struct ptlrpc_request *req)
 {
        int count = req_capsule_filled_sizes(&req->rq_pill, RCL_SERVER);
@@ -1559,14 +1411,6 @@ void ptlrpc_request_set_replen(struct ptlrpc_request *req)
 }
 EXPORT_SYMBOL(ptlrpc_request_set_replen);
 
-void ptlrpc_req_set_repsize(struct ptlrpc_request *req, int count, __u32 *lens)
-{
-       req->rq_replen = lustre_msg_size(req->rq_reqmsg->lm_magic, count, lens);
-       if (req->rq_reqmsg->lm_magic == LUSTRE_MSG_MAGIC_V2)
-               req->rq_reqmsg->lm_repsize = req->rq_replen;
-}
-EXPORT_SYMBOL(ptlrpc_req_set_repsize);
-
 /**
  * Send a remote set_info_async.
  *
@@ -1690,7 +1534,7 @@ void lustre_swab_connect(struct obd_connect_data *ocd)
        CLASSERT(offsetof(typeof(*ocd), paddingF) != 0);
 }
 
-void lustre_swab_obdo(struct obdo *o)
+static void lustre_swab_obdo(struct obdo *o)
 {
        __swab64s(&o->o_valid);
        lustre_swab_ost_id(&o->o_oi);
@@ -1722,7 +1566,6 @@ void lustre_swab_obdo(struct obdo *o)
        CLASSERT(offsetof(typeof(*o), o_padding_6) != 0);
 
 }
-EXPORT_SYMBOL(lustre_swab_obdo);
 
 void lustre_swab_obd_statfs(struct obd_statfs *os)
 {
@@ -1874,6 +1717,7 @@ EXPORT_SYMBOL(lustre_swab_mdt_ioepoch);
 void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
 {
        int i;
+
        __swab32s(&mti->mti_lustre_ver);
        __swab32s(&mti->mti_stripe_index);
        __swab32s(&mti->mti_config_ver);
@@ -1979,7 +1823,7 @@ void lustre_swab_fid2path(struct getinfo_fid2path *gf)
 }
 EXPORT_SYMBOL(lustre_swab_fid2path);
 
-void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
+static void lustre_swab_fiemap_extent(struct ll_fiemap_extent *fm_extent)
 {
        __swab64s(&fm_extent->fe_logical);
        __swab64s(&fm_extent->fe_physical);
@@ -2018,15 +1862,6 @@ void lustre_swab_idx_info(struct idx_info *ii)
        __swab16s(&ii->ii_recsize);
 }
 
-void lustre_swab_lip_header(struct lu_idxpage *lip)
-{
-       /* swab header */
-       __swab32s(&lip->lip_magic);
-       __swab16s(&lip->lip_flags);
-       __swab16s(&lip->lip_nr);
-}
-EXPORT_SYMBOL(lustre_swab_lip_header);
-
 void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
 {
        __swab32s(&rr->rr_opcode);
@@ -2069,46 +1904,6 @@ void lustre_swab_lov_desc(struct lov_desc *ld)
 }
 EXPORT_SYMBOL(lustre_swab_lov_desc);
 
-void lustre_swab_lmv_desc(struct lmv_desc *ld)
-{
-       __swab32s(&ld->ld_tgt_count);
-       __swab32s(&ld->ld_active_tgt_count);
-       __swab32s(&ld->ld_default_stripe_count);
-       __swab32s(&ld->ld_pattern);
-       __swab64s(&ld->ld_default_hash_size);
-       __swab32s(&ld->ld_qos_maxage);
-       /* uuid endian insensitive */
-}
-
-void lustre_swab_lmv_stripe_md(struct lmv_stripe_md *mea)
-{
-       __swab32s(&mea->mea_magic);
-       __swab32s(&mea->mea_count);
-       __swab32s(&mea->mea_master);
-       CLASSERT(offsetof(typeof(*mea), mea_padding) != 0);
-}
-
-void lustre_swab_lmv_user_md(struct lmv_user_md *lum)
-{
-       int i;
-
-       __swab32s(&lum->lum_magic);
-       __swab32s(&lum->lum_stripe_count);
-       __swab32s(&lum->lum_stripe_offset);
-       __swab32s(&lum->lum_hash_type);
-       __swab32s(&lum->lum_type);
-       CLASSERT(offsetof(typeof(*lum), lum_padding1) != 0);
-       CLASSERT(offsetof(typeof(*lum), lum_padding2) != 0);
-       CLASSERT(offsetof(typeof(*lum), lum_padding3) != 0);
-
-       for (i = 0; i < lum->lum_stripe_count; i++) {
-               __swab32s(&lum->lum_objects[i].lum_mds);
-               lustre_swab_lu_fid(&lum->lum_objects[i].lum_fid);
-       }
-
-}
-EXPORT_SYMBOL(lustre_swab_lmv_user_md);
-
 static void print_lum(struct lov_user_md *lum)
 {
        CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
@@ -2179,16 +1974,15 @@ void lustre_swab_lov_user_md_objects(struct lov_user_ost_data *lod,
 }
 EXPORT_SYMBOL(lustre_swab_lov_user_md_objects);
 
-void lustre_swab_ldlm_res_id(struct ldlm_res_id *id)
+static void lustre_swab_ldlm_res_id(struct ldlm_res_id *id)
 {
        int i;
 
        for (i = 0; i < RES_NAME_SIZE; i++)
                __swab64s(&id->name[i]);
 }
-EXPORT_SYMBOL(lustre_swab_ldlm_res_id);
 
-void lustre_swab_ldlm_policy_data(ldlm_wire_policy_data_t *d)
+static void lustre_swab_ldlm_policy_data(ldlm_wire_policy_data_t *d)
 {
        /* the lock data is a union and the first two fields are always an
         * extent so it's ok to process an LDLM_EXTENT and LDLM_FLOCK lock
@@ -2199,7 +1993,6 @@ void lustre_swab_ldlm_policy_data(ldlm_wire_policy_data_t *d)
        __swab64s(&d->l_flock.lfw_owner);
        __swab32s(&d->l_flock.lfw_pid);
 }
-EXPORT_SYMBOL(lustre_swab_ldlm_policy_data);
 
 void lustre_swab_ldlm_intent(struct ldlm_intent *i)
 {
@@ -2207,22 +2000,20 @@ void lustre_swab_ldlm_intent(struct ldlm_intent *i)
 }
 EXPORT_SYMBOL(lustre_swab_ldlm_intent);
 
-void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
+static void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
 {
        __swab32s(&r->lr_type);
        CLASSERT(offsetof(typeof(*r), lr_padding) != 0);
        lustre_swab_ldlm_res_id(&r->lr_name);
 }
-EXPORT_SYMBOL(lustre_swab_ldlm_resource_desc);
 
-void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l)
+static void lustre_swab_ldlm_lock_desc(struct ldlm_lock_desc *l)
 {
        lustre_swab_ldlm_resource_desc(&l->l_resource);
        __swab32s(&l->l_req_mode);
        __swab32s(&l->l_granted_mode);
        lustre_swab_ldlm_policy_data(&l->l_policy_data);
 }
-EXPORT_SYMBOL(lustre_swab_ldlm_lock_desc);
 
 void lustre_swab_ldlm_request(struct ldlm_request *rq)
 {
@@ -2271,7 +2062,7 @@ void dump_rniobuf(struct niobuf_remote *nb)
 }
 EXPORT_SYMBOL(dump_rniobuf);
 
-void dump_obdo(struct obdo *oa)
+static void dump_obdo(struct obdo *oa)
 {
        __u32 valid = oa->o_valid;
 
@@ -2332,7 +2123,6 @@ void dump_obdo(struct obdo *oa)
        if (valid & OBD_MD_FLCOOKIE)
                CDEBUG(D_RPCTRACE, "obdo: o_lcookie = (llog_cookie dumping not yet implemented)\n");
 }
-EXPORT_SYMBOL(dump_obdo);
 
 void dump_ost_body(struct ost_body *ob)
 {
@@ -2394,7 +2184,7 @@ void _debug_req(struct ptlrpc_request *req,
 
        va_start(args, fmt);
        libcfs_debug_vmsg2(msgdata, fmt, args,
-                          " req@%p x%llu/t%lld(%lld) o%d->%s@%s:%d/%d lens %d/%d e %d to %d dl " CFS_TIME_T " ref %d fl " REQ_FLAGS_FMT "/%x/%x rc %d/%d\n",
+                          " req@%p x%llu/t%lld(%lld) o%d->%s@%s:%d/%d lens %d/%d e %d to %lld dl %lld ref %d fl " REQ_FLAGS_FMT "/%x/%x rc %d/%d\n",
                           req, req->rq_xid, req->rq_transno,
                           req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
                           req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
@@ -2406,8 +2196,8 @@ void _debug_req(struct ptlrpc_request *req,
                           libcfs_nid2str(nid),
                           req->rq_request_portal, req->rq_reply_portal,
                           req->rq_reqlen, req->rq_replen,
-                          req->rq_early_count, req->rq_timedout,
-                          req->rq_deadline,
+                          req->rq_early_count, (s64)req->rq_timedout,
+                          (s64)req->rq_deadline,
                           atomic_read(&req->rq_refcount),
                           DEBUG_REQ_FLAGS(req),
                           req_ok ? lustre_msg_get_flags(req->rq_reqmsg) : -1,
@@ -2431,14 +2221,6 @@ void lustre_swab_lustre_capa(struct lustre_capa *c)
 }
 EXPORT_SYMBOL(lustre_swab_lustre_capa);
 
-void lustre_swab_lustre_capa_key(struct lustre_capa_key *k)
-{
-       __swab64s(&k->lk_seq);
-       __swab32s(&k->lk_keyid);
-       CLASSERT(offsetof(typeof(*k), lk_padding) != 0);
-}
-EXPORT_SYMBOL(lustre_swab_lustre_capa_key);
-
 void lustre_swab_hsm_user_state(struct hsm_user_state *state)
 {
        __swab32s(&state->hus_states);
@@ -2455,7 +2237,7 @@ void lustre_swab_hsm_state_set(struct hsm_state_set *hss)
 }
 EXPORT_SYMBOL(lustre_swab_hsm_state_set);
 
-void lustre_swab_hsm_extent(struct hsm_extent *extent)
+static void lustre_swab_hsm_extent(struct hsm_extent *extent)
 {
        __swab64s(&extent->offset);
        __swab64s(&extent->length);
index e1334c24ebe33292bd07ace083f92af814dd7e23..2a2a9fb6549ce5991c744ed0a748f8b4a4676391 100644 (file)
@@ -42,7 +42,6 @@
 
 #include "ptlrpc_internal.h"
 
-
 void ptlrpc_fill_bulk_md(lnet_md_t *md, struct ptlrpc_bulk_desc *desc,
                         int mdidx)
 {
index f8edb791a998bc0373fd398ed608a30ed8cdd4ac..5c719f175657c56180f067ff2b134b06ceb44c4f 100644 (file)
 #include "../include/obd_class.h"
 #include "ptlrpc_internal.h"
 
-static int suppress_pings;
-module_param(suppress_pings, int, 0644);
-MODULE_PARM_DESC(suppress_pings, "Suppress pings");
-
 struct mutex pinger_mutex;
 static LIST_HEAD(pinger_imports);
 static struct list_head timeout_list = LIST_HEAD_INIT(timeout_list);
 
-int ptlrpc_pinger_suppress_pings(void)
-{
-       return suppress_pings;
-}
-EXPORT_SYMBOL(ptlrpc_pinger_suppress_pings);
-
 struct ptlrpc_request *
 ptlrpc_prep_ping(struct obd_import *imp)
 {
@@ -105,7 +95,7 @@ static int ptlrpc_ping(struct obd_import *imp)
 
        DEBUG_REQ(D_INFO, req, "pinging %s->%s",
                  imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd));
-       ptlrpcd_add_req(req, PDL_POLICY_ROUND, -1);
+       ptlrpcd_add_req(req);
 
        return 0;
 }
@@ -113,6 +103,7 @@ static int ptlrpc_ping(struct obd_import *imp)
 static void ptlrpc_update_next_ping(struct obd_import *imp, int soon)
 {
        int time = soon ? PING_INTERVAL_SHORT : PING_INTERVAL;
+
        if (imp->imp_state == LUSTRE_IMP_DISCON) {
                int dtime = max_t(int, CONNECTION_SWITCH_MIN,
                                  AT_OFF ? 0 :
@@ -122,11 +113,6 @@ static void ptlrpc_update_next_ping(struct obd_import *imp, int soon)
        imp->imp_next_ping = cfs_time_shift(time);
 }
 
-void ptlrpc_ping_import_soon(struct obd_import *imp)
-{
-       imp->imp_next_ping = cfs_time_current();
-}
-
 static inline int imp_is_deactive(struct obd_import *imp)
 {
        return (imp->imp_deactive ||
@@ -150,6 +136,7 @@ static long pinger_check_timeout(unsigned long time)
        mutex_lock(&pinger_mutex);
        list_for_each_entry(item, &timeout_list, ti_chain) {
                int ti_timeout = item->ti_timeout;
+
                if (timeout > ti_timeout)
                        timeout = ti_timeout;
                break;
@@ -234,7 +221,7 @@ static void ptlrpc_pinger_process_import(struct obd_import *imp,
 
 static int ptlrpc_pinger_main(void *arg)
 {
-       struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
+       struct ptlrpc_thread *thread = arg;
 
        /* Record that the thread is running */
        thread_set_flags(thread, SVC_RUNNING);
@@ -266,8 +253,6 @@ static int ptlrpc_pinger_main(void *arg)
                                ptlrpc_update_next_ping(imp, 0);
                }
                mutex_unlock(&pinger_mutex);
-               /* update memory usage info */
-               obd_update_maxusage();
 
                /* Wait until the next ping time, or until we're stopped. */
                time_to_next_wake = pinger_check_timeout(this_ping);
@@ -277,8 +262,8 @@ static int ptlrpc_pinger_main(void *arg)
                   next ping time to next_ping + .01 sec, which means
                   we will SKIP the next ping at next_ping, and the
                   ping will get sent 2 timeouts from now!  Beware. */
-               CDEBUG(D_INFO, "next wakeup in "CFS_DURATION_T" ("
-                      CFS_TIME_T")\n", time_to_next_wake,
+               CDEBUG(D_INFO, "next wakeup in " CFS_DURATION_T " (%ld)\n",
+                      time_to_next_wake,
                       cfs_time_add(this_ping,
                                    cfs_time_seconds(PING_INTERVAL)));
                if (time_to_next_wake > 0) {
@@ -327,13 +312,10 @@ int ptlrpc_start_pinger(void)
        l_wait_event(pinger_thread.t_ctl_waitq,
                     thread_is_running(&pinger_thread), &lwi);
 
-       if (suppress_pings)
-               CWARN("Pings will be suppressed at the request of the administrator.  The configuration shall meet the additional requirements described in the manual.  (Search for the \"suppress_pings\" kernel module parameter.)\n");
-
        return 0;
 }
 
-int ptlrpc_pinger_remove_timeouts(void);
+static int ptlrpc_pinger_remove_timeouts(void);
 
 int ptlrpc_stop_pinger(void)
 {
@@ -517,7 +499,7 @@ int ptlrpc_del_timeout_client(struct list_head *obd_list,
 }
 EXPORT_SYMBOL(ptlrpc_del_timeout_client);
 
-int ptlrpc_pinger_remove_timeouts(void)
+static int ptlrpc_pinger_remove_timeouts(void)
 {
        struct timeout_item *item, *tmp;
 
@@ -536,139 +518,3 @@ void ptlrpc_pinger_wake_up(void)
        thread_add_flags(&pinger_thread, SVC_EVENT);
        wake_up(&pinger_thread.t_ctl_waitq);
 }
-
-/* Ping evictor thread */
-#define PET_READY     1
-#define PET_TERMINATE 2
-
-static int pet_refcount;
-static int pet_state;
-static wait_queue_head_t pet_waitq;
-static LIST_HEAD(pet_list);
-static DEFINE_SPINLOCK(pet_lock);
-
-int ping_evictor_wake(struct obd_export *exp)
-{
-       struct obd_device *obd;
-
-       spin_lock(&pet_lock);
-       if (pet_state != PET_READY) {
-               /* eventually the new obd will call here again. */
-               spin_unlock(&pet_lock);
-               return 1;
-       }
-
-       obd = class_exp2obd(exp);
-       if (list_empty(&obd->obd_evict_list)) {
-               class_incref(obd, "evictor", obd);
-               list_add(&obd->obd_evict_list, &pet_list);
-       }
-       spin_unlock(&pet_lock);
-
-       wake_up(&pet_waitq);
-       return 0;
-}
-
-static int ping_evictor_main(void *arg)
-{
-       struct obd_device *obd;
-       struct obd_export *exp;
-       struct l_wait_info lwi = { 0 };
-       time_t expire_time;
-
-       unshare_fs_struct();
-
-       CDEBUG(D_HA, "Starting Ping Evictor\n");
-       pet_state = PET_READY;
-       while (1) {
-               l_wait_event(pet_waitq, (!list_empty(&pet_list)) ||
-                            (pet_state == PET_TERMINATE), &lwi);
-
-               /* loop until all obd's will be removed */
-               if ((pet_state == PET_TERMINATE) && list_empty(&pet_list))
-                       break;
-
-               /* we only get here if pet_exp != NULL, and the end of this
-                * loop is the only place which sets it NULL again, so lock
-                * is not strictly necessary. */
-               spin_lock(&pet_lock);
-               obd = list_entry(pet_list.next, struct obd_device,
-                                    obd_evict_list);
-               spin_unlock(&pet_lock);
-
-               expire_time = get_seconds() - PING_EVICT_TIMEOUT;
-
-               CDEBUG(D_HA, "evicting all exports of obd %s older than %ld\n",
-                      obd->obd_name, expire_time);
-
-               /* Exports can't be deleted out of the list while we hold
-                * the obd lock (class_unlink_export), which means we can't
-                * lose the last ref on the export.  If they've already been
-                * removed from the list, we won't find them here. */
-               spin_lock(&obd->obd_dev_lock);
-               while (!list_empty(&obd->obd_exports_timed)) {
-                       exp = list_entry(obd->obd_exports_timed.next,
-                                            struct obd_export,
-                                            exp_obd_chain_timed);
-                       if (expire_time > exp->exp_last_request_time) {
-                               class_export_get(exp);
-                               spin_unlock(&obd->obd_dev_lock);
-                               LCONSOLE_WARN("%s: haven't heard from client %s (at %s) in %ld seconds. I think it's dead, and I am evicting it. exp %p, cur %ld expire %ld last %ld\n",
-                                             obd->obd_name,
-                                             obd_uuid2str(&exp->exp_client_uuid),
-                                             obd_export_nid2str(exp),
-                                             (long)(get_seconds() -
-                                                    exp->exp_last_request_time),
-                                             exp, (long)get_seconds(),
-                                             (long)expire_time,
-                                             (long)exp->exp_last_request_time);
-                               CDEBUG(D_HA, "Last request was at %ld\n",
-                                      exp->exp_last_request_time);
-                               class_fail_export(exp);
-                               class_export_put(exp);
-                               spin_lock(&obd->obd_dev_lock);
-                       } else {
-                               /* List is sorted, so everyone below is ok */
-                               break;
-                       }
-               }
-               spin_unlock(&obd->obd_dev_lock);
-
-               spin_lock(&pet_lock);
-               list_del_init(&obd->obd_evict_list);
-               spin_unlock(&pet_lock);
-
-               class_decref(obd, "evictor", obd);
-       }
-       CDEBUG(D_HA, "Exiting Ping Evictor\n");
-
-       return 0;
-}
-
-void ping_evictor_start(void)
-{
-       struct task_struct *task;
-
-       if (++pet_refcount > 1)
-               return;
-
-       init_waitqueue_head(&pet_waitq);
-
-       task = kthread_run(ping_evictor_main, NULL, "ll_evictor");
-       if (IS_ERR(task)) {
-               pet_refcount--;
-               CERROR("Cannot start ping evictor thread: %ld\n",
-                       PTR_ERR(task));
-       }
-}
-EXPORT_SYMBOL(ping_evictor_start);
-
-void ping_evictor_stop(void)
-{
-       if (--pet_refcount > 0)
-               return;
-
-       pet_state = PET_TERMINATE;
-       wake_up(&pet_waitq);
-}
-EXPORT_SYMBOL(ping_evictor_stop);
index 6dc3998dcd248cf3b78f524b77bc4ef6f67ed790..ab6c4580f91c3fc0432aab342d079d0c6a204faf 100644 (file)
@@ -47,10 +47,14 @@ struct ldlm_res_id;
 struct ptlrpc_request_set;
 extern int test_req_buffer_pressure;
 extern struct mutex ptlrpc_all_services_mutex;
+extern struct list_head ptlrpc_all_services;
+
+extern struct mutex ptlrpcd_mutex;
+extern struct mutex pinger_mutex;
 
 int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait);
 /* ptlrpcd.c */
-int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc);
+int ptlrpcd_start(struct ptlrpcd_ctl *pc);
 
 /* client.c */
 struct ptlrpc_bulk_desc *ptlrpc_new_bulk(unsigned npages, unsigned max_brw,
@@ -110,6 +114,8 @@ struct nrs_core {
 
 };
 
+extern struct nrs_core nrs_core;
+
 int ptlrpc_service_nrs_setup(struct ptlrpc_service *svc);
 void ptlrpc_service_nrs_cleanup(struct ptlrpc_service *svc);
 
@@ -131,13 +137,6 @@ ptlrpc_nrs_req_get_nolock(struct ptlrpc_service_part *svcpt, bool hp,
        return ptlrpc_nrs_req_get_nolock0(svcpt, hp, false, force);
 }
 
-static inline struct ptlrpc_request *
-ptlrpc_nrs_req_peek_nolock(struct ptlrpc_service_part *svcpt, bool hp)
-{
-       return ptlrpc_nrs_req_get_nolock0(svcpt, hp, true, false);
-}
-
-void ptlrpc_nrs_req_del_nolock(struct ptlrpc_request *req);
 bool ptlrpc_nrs_req_pending_nolock(struct ptlrpc_service_part *svcpt, bool hp);
 
 int ptlrpc_nrs_policy_control(const struct ptlrpc_service *svc,
@@ -243,8 +242,6 @@ int ptlrpc_stop_pinger(void);
 void ptlrpc_pinger_sending_on_import(struct obd_import *imp);
 void ptlrpc_pinger_commit_expected(struct obd_import *imp);
 void ptlrpc_pinger_wake_up(void);
-void ptlrpc_ping_import_soon(struct obd_import *imp);
-int ping_evictor_wake(struct obd_export *exp);
 
 /* sec_null.c */
 int  sptlrpc_null_init(void);
@@ -298,6 +295,6 @@ static inline void tgt_mod_exit(void)
 static inline void ptlrpc_reqset_put(struct ptlrpc_request_set *set)
 {
        if (atomic_dec_and_test(&set->set_refcount))
-               OBD_FREE_PTR(set);
+               kfree(set);
 }
 #endif /* PTLRPC_INTERNAL_H */
index ae99180d6036f10647d0b4dbbf8b7e3bdbcb1589..9deeb244166fad7153ce851753e32935bf43fa06 100644 (file)
@@ -36,7 +36,6 @@
 
 #define DEBUG_SUBSYSTEM S_RPC
 
-
 #include "../include/obd_support.h"
 #include "../include/obd_class.h"
 #include "../include/lustre_net.h"
@@ -48,8 +47,6 @@ extern spinlock_t ptlrpc_last_xid_lock;
 #if RS_DEBUG
 extern spinlock_t ptlrpc_rs_debug_lock;
 #endif
-extern struct mutex pinger_mutex;
-extern struct mutex ptlrpcd_mutex;
 
 static int __init ptlrpc_init(void)
 {
@@ -143,7 +140,8 @@ cleanup:
                ptlrpc_hr_fini();
                req_layout_fini();
                /* Fall through */
-       default: ;
+       default:
+               ;
        }
 
        return rc;
index 17cc81d5074f3706c3ad97463ce0b15492cd791f..ce036a1ac4663fdea1e2b3d9145b0d30d60fd895 100644 (file)
 
 #include "ptlrpc_internal.h"
 
+/* One of these per CPT. */
 struct ptlrpcd {
        int pd_size;
        int pd_index;
+       int pd_cpt;
+       int pd_cursor;
        int pd_nthreads;
-       struct ptlrpcd_ctl pd_thread_rcv;
+       int pd_groupsize;
        struct ptlrpcd_ctl pd_threads[0];
 };
 
+/*
+ * max_ptlrpcds is obsolete, but retained to ensure that the kernel
+ * module will load on a system where it has been tuned.
+ * A value other than 0 implies it was tuned, in which case the value
+ * is used to derive a setting for ptlrpcd_per_cpt_max.
+ */
 static int max_ptlrpcds;
 module_param(max_ptlrpcds, int, 0644);
 MODULE_PARM_DESC(max_ptlrpcds, "Max ptlrpcd thread count to be started.");
 
-static int ptlrpcd_bind_policy = PDB_POLICY_PAIR;
+/*
+ * ptlrpcd_bind_policy is obsolete, but retained to ensure that
+ * the kernel module will load on a system where it has been tuned.
+ * A value other than 0 implies it was tuned, in which case the value
+ * is used to derive a setting for ptlrpcd_partner_group_size.
+ */
+static int ptlrpcd_bind_policy;
 module_param(ptlrpcd_bind_policy, int, 0644);
-MODULE_PARM_DESC(ptlrpcd_bind_policy, "Ptlrpcd threads binding mode.");
-static struct ptlrpcd *ptlrpcds;
+MODULE_PARM_DESC(ptlrpcd_bind_policy,
+                "Ptlrpcd threads binding mode (obsolete).");
+
+/*
+ * ptlrpcd_per_cpt_max: The maximum number of ptlrpcd threads to run
+ * in a CPT.
+ */
+static int ptlrpcd_per_cpt_max;
+module_param(ptlrpcd_per_cpt_max, int, 0644);
+MODULE_PARM_DESC(ptlrpcd_per_cpt_max,
+                "Max ptlrpcd thread count to be started per cpt.");
+
+/*
+ * ptlrpcd_partner_group_size: The desired number of threads in each
+ * ptlrpcd partner thread group. Default is 2, corresponding to the
+ * old PDB_POLICY_PAIR. A negative value makes all ptlrpcd threads in
+ * a CPT partners of each other.
+ */
+static int ptlrpcd_partner_group_size;
+module_param(ptlrpcd_partner_group_size, int, 0644);
+MODULE_PARM_DESC(ptlrpcd_partner_group_size,
+                "Number of ptlrpcd threads in a partner group.");
+
+/*
+ * ptlrpcd_cpts: A CPT string describing the CPU partitions that
+ * ptlrpcd threads should run on. Used to make ptlrpcd threads run on
+ * a subset of all CPTs.
+ *
+ * ptlrpcd_cpts=2
+ * ptlrpcd_cpts=[2]
+ *   run ptlrpcd threads only on CPT 2.
+ *
+ * ptlrpcd_cpts=0-3
+ * ptlrpcd_cpts=[0-3]
+ *   run ptlrpcd threads on CPTs 0, 1, 2, and 3.
+ *
+ * ptlrpcd_cpts=[0-3,5,7]
+ *   run ptlrpcd threads on CPTS 0, 1, 2, 3, 5, and 7.
+ */
+static char *ptlrpcd_cpts;
+module_param(ptlrpcd_cpts, charp, 0644);
+MODULE_PARM_DESC(ptlrpcd_cpts,
+                "CPU partitions ptlrpcd threads should run in");
+
+/* ptlrpcds_cpt_idx maps cpt numbers to an index in the ptlrpcds array. */
+static int             *ptlrpcds_cpt_idx;
+
+/* ptlrpcds_num is the number of entries in the ptlrpcds array. */
+static int             ptlrpcds_num;
+static struct ptlrpcd  **ptlrpcds;
+
+/*
+ * In addition to the regular thread pool above, there is a single
+ * global recovery thread. Recovery isn't critical for performance,
+ * and doesn't block, but must always be able to proceed, and it is
+ * possible that all normal ptlrpcd threads are blocked. Hence the
+ * need for a dedicated thread.
+ */
+static struct ptlrpcd_ctl ptlrpcd_rcv;
 
 struct mutex ptlrpcd_mutex;
 static int ptlrpcd_users;
@@ -98,88 +170,30 @@ void ptlrpcd_wake(struct ptlrpc_request *req)
 EXPORT_SYMBOL(ptlrpcd_wake);
 
 static struct ptlrpcd_ctl *
-ptlrpcd_select_pc(struct ptlrpc_request *req, pdl_policy_t policy, int index)
+ptlrpcd_select_pc(struct ptlrpc_request *req)
 {
-       int idx = 0;
+       struct ptlrpcd  *pd;
+       int             cpt;
+       int             idx;
 
        if (req != NULL && req->rq_send_state != LUSTRE_IMP_FULL)
-               return &ptlrpcds->pd_thread_rcv;
-
-       switch (policy) {
-       case PDL_POLICY_SAME:
-               idx = smp_processor_id() % ptlrpcds->pd_nthreads;
-               break;
-       case PDL_POLICY_LOCAL:
-               /* Before CPU partition patches available, process it the same
-                * as "PDL_POLICY_ROUND". */
-# ifdef CFS_CPU_MODE_NUMA
-# warning "fix this code to use new CPU partition APIs"
-# endif
-               /* Fall through to PDL_POLICY_ROUND until the CPU
-                * CPU partition patches are available. */
-               index = -1;
-       case PDL_POLICY_PREFERRED:
-               if (index >= 0 && index < num_online_cpus()) {
-                       idx = index % ptlrpcds->pd_nthreads;
-                       break;
-               }
-               /* Fall through to PDL_POLICY_ROUND for bad index. */
-       default:
-               /* Fall through to PDL_POLICY_ROUND for unknown policy. */
-       case PDL_POLICY_ROUND:
-               /* We do not care whether it is strict load balance. */
-               idx = ptlrpcds->pd_index + 1;
-               if (idx == smp_processor_id())
-                       idx++;
-               idx %= ptlrpcds->pd_nthreads;
-               ptlrpcds->pd_index = idx;
-               break;
-       }
-
-       return &ptlrpcds->pd_threads[idx];
-}
-
-/**
- * Move all request from an existing request set to the ptlrpcd queue.
- * All requests from the set must be in phase RQ_PHASE_NEW.
- */
-void ptlrpcd_add_rqset(struct ptlrpc_request_set *set)
-{
-       struct list_head *tmp, *pos;
-       struct ptlrpcd_ctl *pc;
-       struct ptlrpc_request_set *new;
-       int count, i;
+               return &ptlrpcd_rcv;
 
-       pc = ptlrpcd_select_pc(NULL, PDL_POLICY_LOCAL, -1);
-       new = pc->pc_set;
+       cpt = cfs_cpt_current(cfs_cpt_table, 1);
+       if (!ptlrpcds_cpt_idx)
+               idx = cpt;
+       else
+               idx = ptlrpcds_cpt_idx[cpt];
+       pd = ptlrpcds[idx];
 
-       list_for_each_safe(pos, tmp, &set->set_requests) {
-               struct ptlrpc_request *req =
-                       list_entry(pos, struct ptlrpc_request,
-                                      rq_set_chain);
-
-               LASSERT(req->rq_phase == RQ_PHASE_NEW);
-               req->rq_set = new;
-               req->rq_queued_time = cfs_time_current();
-       }
+               /* We do not care whether it is strict load balance. */
+       idx = pd->pd_cursor;
+       if (++idx == pd->pd_nthreads)
+               idx = 0;
+       pd->pd_cursor = idx;
 
-       spin_lock(&new->set_new_req_lock);
-       list_splice_init(&set->set_requests, &new->set_new_requests);
-       i = atomic_read(&set->set_remaining);
-       count = atomic_add_return(i, &new->set_new_count);
-       atomic_set(&set->set_remaining, 0);
-       spin_unlock(&new->set_new_req_lock);
-       if (count == i) {
-               wake_up(&new->set_waitq);
-
-               /* XXX: It maybe unnecessary to wakeup all the partners. But to
-                *      guarantee the async RPC can be processed ASAP, we have
-                *      no other better choice. It maybe fixed in future. */
-               for (i = 0; i < pc->pc_npartners; i++)
-                       wake_up(&pc->pc_partners[i]->pc_set->set_waitq);
-       }
+       return &pd->pd_threads[idx];
 }
-EXPORT_SYMBOL(ptlrpcd_add_rqset);
 
 /**
  * Return transferred RPCs count.
@@ -212,7 +226,7 @@ static int ptlrpcd_steal_rqset(struct ptlrpc_request_set *des,
  * Requests that are added to the ptlrpcd queue are sent via
  * ptlrpcd_check->ptlrpc_check_set().
  */
-void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx)
+void ptlrpcd_add_req(struct ptlrpc_request *req)
 {
        struct ptlrpcd_ctl *pc;
 
@@ -242,7 +256,7 @@ void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx)
                spin_unlock(&req->rq_lock);
        }
 
-       pc = ptlrpcd_select_pc(req, policy, idx);
+       pc = ptlrpcd_select_pc(req);
 
        DEBUG_REQ(D_INFO, req, "add req [%p] to pc [%s:%d]",
                  req, pc->pc_name, pc->pc_index);
@@ -372,25 +386,29 @@ static int ptlrpcd_check(struct lu_env *env, struct ptlrpcd_ctl *pc)
 static int ptlrpcd(void *arg)
 {
        struct ptlrpcd_ctl *pc = arg;
-       struct ptlrpc_request_set *set = pc->pc_set;
+       struct ptlrpc_request_set *set;
        struct lu_env env = { .le_ses = NULL };
-       int rc, exit = 0;
+       int rc = 0;
+       int exit = 0;
 
        unshare_fs_struct();
-#if defined(CONFIG_SMP)
-       if (test_bit(LIOD_BIND, &pc->pc_flags)) {
-               int index = pc->pc_index;
-
-               if (index >= 0 && index < num_possible_cpus()) {
-                       while (!cpu_online(index)) {
-                               if (++index >= num_possible_cpus())
-                                       index = 0;
-                       }
-                       set_cpus_allowed_ptr(current,
-                                       cpumask_of_node(cpu_to_node(index)));
-               }
+       if (cfs_cpt_bind(cfs_cpt_table, pc->pc_cpt) != 0)
+               CWARN("Failed to bind %s on CPT %d\n", pc->pc_name, pc->pc_cpt);
+
+       /*
+        * Allocate the request set after the thread has been bound
+        * above. This is safe because no requests will be queued
+        * until all ptlrpcd threads have confirmed that they have
+        * successfully started.
+        */
+       set = ptlrpc_prep_set();
+       if (!set) {
+               rc = -ENOMEM;
+               goto failed;
        }
-#endif
+       spin_lock(&pc->pc_lock);
+       pc->pc_set = set;
+       spin_unlock(&pc->pc_lock);
        /*
         * XXX So far only "client" ptlrpcd uses an environment. In
         * the future, ptlrpcd thread (or a thread-set) has to given
@@ -398,10 +416,10 @@ static int ptlrpcd(void *arg)
         */
        rc = lu_context_init(&env.le_ctx,
                             LCT_CL_THREAD|LCT_REMEMBER|LCT_NOREF);
-       complete(&pc->pc_starting);
-
        if (rc != 0)
-               return rc;
+               goto failed;
+
+       complete(&pc->pc_starting);
 
        /*
         * This mainloop strongly resembles ptlrpc_set_wait() except that our
@@ -447,174 +465,97 @@ static int ptlrpcd(void *arg)
        complete(&pc->pc_finishing);
 
        return 0;
+failed:
+       pc->pc_error = rc;
+       complete(&pc->pc_starting);
+       return rc;
 }
 
-/* XXX: We want multiple CPU cores to share the async RPC load. So we start many
- *      ptlrpcd threads. We also want to reduce the ptlrpcd overhead caused by
- *      data transfer cross-CPU cores. So we bind ptlrpcd thread to specified
- *      CPU core. But binding all ptlrpcd threads maybe cause response delay
- *      because of some CPU core(s) busy with other loads.
- *
- *      For example: "ls -l", some async RPCs for statahead are assigned to
- *      ptlrpcd_0, and ptlrpcd_0 is bound to CPU_0, but CPU_0 may be quite busy
- *      with other non-ptlrpcd, like "ls -l" itself (we want to the "ls -l"
- *      thread, statahead thread, and ptlrpcd thread can run in parallel), under
- *      such case, the statahead async RPCs can not be processed in time, it is
- *      unexpected. If ptlrpcd_0 can be re-scheduled on other CPU core, it may
- *      be better. But it breaks former data transfer policy.
- *
- *      So we shouldn't be blind for avoiding the data transfer. We make some
- *      compromise: divide the ptlrpcd threads pool into two parts. One part is
- *      for bound mode, each ptlrpcd thread in this part is bound to some CPU
- *      core. The other part is for free mode, all the ptlrpcd threads in the
- *      part can be scheduled on any CPU core. We specify some partnership
- *      between bound mode ptlrpcd thread(s) and free mode ptlrpcd thread(s),
- *      and the async RPC load within the partners are shared.
+static void ptlrpcd_ctl_init(struct ptlrpcd_ctl *pc, int index, int cpt)
+{
+       pc->pc_index = index;
+       pc->pc_cpt = cpt;
+       init_completion(&pc->pc_starting);
+       init_completion(&pc->pc_finishing);
+       spin_lock_init(&pc->pc_lock);
+
+       if (index < 0) {
+               /* Recovery thread. */
+               snprintf(pc->pc_name, sizeof(pc->pc_name), "ptlrpcd_rcv");
+       } else {
+               /* Regular thread. */
+               snprintf(pc->pc_name, sizeof(pc->pc_name),
+                        "ptlrpcd_%02d_%02d", cpt, index);
+       }
+}
+
+/* XXX: We want multiple CPU cores to share the async RPC load. So we
+ *     start many ptlrpcd threads. We also want to reduce the ptlrpcd
+ *     overhead caused by data transfer cross-CPU cores. So we bind
+ *     all ptlrpcd threads to a CPT, in the expectation that CPTs
+ *     will be defined in a way that matches these boundaries. Within
+ *     a CPT a ptlrpcd thread can be scheduled on any available core.
  *
- *      It can partly avoid data transfer cross-CPU (if the bound mode ptlrpcd
- *      thread can be scheduled in time), and try to guarantee the async RPC
- *      processed ASAP (as long as the free mode ptlrpcd thread can be scheduled
- *      on any CPU core).
+ *     Each ptlrpcd thread has its own request queue. This can cause
+ *     response delay if the thread is already busy. To help with
+ *     this we define partner threads: these are other threads bound
+ *     to the same CPT which will check for work in each other's
+ *     request queues if they have no work to do.
  *
- *      As for how to specify the partnership between bound mode ptlrpcd
- *      thread(s) and free mode ptlrpcd thread(s), the simplest way is to use
- *      <free bound> pair. In future, we can specify some more complex
- *      partnership based on the patches for CPU partition. But before such
- *      patches are available, we prefer to use the simplest one.
+ *     The desired number of partner threads can be tuned by setting
+ *     ptlrpcd_partner_group_size. The default is to create pairs of
+ *     partner threads.
  */
-# ifdef CFS_CPU_MODE_NUMA
-# warning "fix ptlrpcd_bind() to use new CPU partition APIs"
-# endif
-static int ptlrpcd_bind(int index, int max)
+static int ptlrpcd_partners(struct ptlrpcd *pd, int index)
 {
        struct ptlrpcd_ctl *pc;
+       struct ptlrpcd_ctl **ppc;
+       int first;
+       int i;
        int rc = 0;
-#if defined(CONFIG_NUMA)
-       cpumask_t mask;
-#endif
+       int size;
 
-       LASSERT(index <= max - 1);
-       pc = &ptlrpcds->pd_threads[index];
-       switch (ptlrpcd_bind_policy) {
-       case PDB_POLICY_NONE:
-               pc->pc_npartners = -1;
-               break;
-       case PDB_POLICY_FULL:
+       LASSERT(index >= 0 && index < pd->pd_nthreads);
+       pc = &pd->pd_threads[index];
+       pc->pc_npartners = pd->pd_groupsize - 1;
+
+       if (pc->pc_npartners <= 0)
+               goto out;
+
+       size = sizeof(struct ptlrpcd_ctl *) * pc->pc_npartners;
+       pc->pc_partners = kzalloc_node(size, GFP_NOFS,
+                                      cfs_cpt_spread_node(cfs_cpt_table,
+                                                          pc->pc_cpt));
+       if (!pc->pc_partners) {
                pc->pc_npartners = 0;
-               set_bit(LIOD_BIND, &pc->pc_flags);
-               break;
-       case PDB_POLICY_PAIR:
-               LASSERT(max % 2 == 0);
-               pc->pc_npartners = 1;
-               break;
-       case PDB_POLICY_NEIGHBOR:
-#if defined(CONFIG_NUMA)
-       {
-               int i;
-               cpumask_copy(&mask, cpumask_of_node(cpu_to_node(index)));
-               for (i = max; i < num_online_cpus(); i++)
-                       cpumask_clear_cpu(i, &mask);
-               pc->pc_npartners = cpumask_weight(&mask) - 1;
-               set_bit(LIOD_BIND, &pc->pc_flags);
-       }
-#else
-               LASSERT(max >= 3);
-               pc->pc_npartners = 2;
-#endif
-               break;
-       default:
-               CERROR("unknown ptlrpcd bind policy %d\n", ptlrpcd_bind_policy);
-               rc = -EINVAL;
+               rc = -ENOMEM;
+               goto out;
        }
 
-       if (rc == 0 && pc->pc_npartners > 0) {
-               pc->pc_partners = kcalloc(pc->pc_npartners,
-                                         sizeof(struct ptlrpcd_ctl *),
-                                         GFP_NOFS);
-               if (pc->pc_partners == NULL) {
-                       pc->pc_npartners = 0;
-                       rc = -ENOMEM;
-               } else {
-                       switch (ptlrpcd_bind_policy) {
-                       case PDB_POLICY_PAIR:
-                               if (index & 0x1) {
-                                       set_bit(LIOD_BIND, &pc->pc_flags);
-                                       pc->pc_partners[0] = &ptlrpcds->
-                                               pd_threads[index - 1];
-                                       ptlrpcds->pd_threads[index - 1].
-                                               pc_partners[0] = pc;
-                               }
-                               break;
-                       case PDB_POLICY_NEIGHBOR:
-#if defined(CONFIG_NUMA)
-                       {
-                               struct ptlrpcd_ctl *ppc;
-                               int i, pidx;
-                               /* partners are cores in the same NUMA node.
-                                * setup partnership only with ptlrpcd threads
-                                * that are already initialized
-                                */
-                               for (pidx = 0, i = 0; i < index; i++) {
-                                       if (cpumask_test_cpu(i, &mask)) {
-                                               ppc = &ptlrpcds->pd_threads[i];
-                                               pc->pc_partners[pidx++] = ppc;
-                                               ppc->pc_partners[ppc->
-                                                         pc_npartners++] = pc;
-                                       }
-                               }
-                               /* adjust number of partners to the number
-                                * of partnership really setup */
-                               pc->pc_npartners = pidx;
-                       }
-#else
-                               if (index & 0x1)
-                                       set_bit(LIOD_BIND, &pc->pc_flags);
-                               if (index > 0) {
-                                       pc->pc_partners[0] = &ptlrpcds->
-                                               pd_threads[index - 1];
-                                       ptlrpcds->pd_threads[index - 1].
-                                               pc_partners[1] = pc;
-                                       if (index == max - 1) {
-                                               pc->pc_partners[1] =
-                                               &ptlrpcds->pd_threads[0];
-                                               ptlrpcds->pd_threads[0].
-                                               pc_partners[0] = pc;
-                                       }
-                               }
-#endif
-                               break;
-                       }
-               }
+       first = index - index % pd->pd_groupsize;
+       ppc = pc->pc_partners;
+       for (i = first; i < first + pd->pd_groupsize; i++) {
+               if (i != index)
+                       *ppc++ = &pd->pd_threads[i];
        }
-
+out:
        return rc;
 }
 
-
-int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc)
+int ptlrpcd_start(struct ptlrpcd_ctl *pc)
 {
-       int rc;
+       struct task_struct *task;
+       int rc = 0;
 
        /*
         * Do not allow start second thread for one pc.
         */
        if (test_and_set_bit(LIOD_START, &pc->pc_flags)) {
                CWARN("Starting second thread (%s) for same pc %p\n",
-                     name, pc);
+                     pc->pc_name, pc);
                return 0;
        }
 
-       pc->pc_index = index;
-       init_completion(&pc->pc_starting);
-       init_completion(&pc->pc_finishing);
-       spin_lock_init(&pc->pc_lock);
-       strlcpy(pc->pc_name, name, sizeof(pc->pc_name));
-       pc->pc_set = ptlrpc_prep_set();
-       if (pc->pc_set == NULL) {
-               rc = -ENOMEM;
-               goto out;
-       }
-
        /*
         * So far only "client" ptlrpcd uses an environment. In the future,
         * ptlrpcd thread (or a thread-set) has to be given an argument,
@@ -622,29 +563,21 @@ int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc)
         */
        rc = lu_context_init(&pc->pc_env.le_ctx, LCT_CL_THREAD|LCT_REMEMBER);
        if (rc != 0)
-               goto out_set;
+               goto out;
 
-       {
-               struct task_struct *task;
-               if (index >= 0) {
-                       rc = ptlrpcd_bind(index, max);
-                       if (rc < 0)
-                               goto out_env;
-               }
+       task = kthread_run(ptlrpcd, pc, "%s", pc->pc_name);
+       if (IS_ERR(task)) {
+               rc = PTR_ERR(task);
+               goto out_set;
+       }
 
-               task = kthread_run(ptlrpcd, pc, "%s", pc->pc_name);
-               if (IS_ERR(task)) {
-                       rc = PTR_ERR(task);
-                       goto out_env;
-               }
+       wait_for_completion(&pc->pc_starting);
+       rc = pc->pc_error;
+       if (rc != 0)
+               goto out_set;
 
-               wait_for_completion(&pc->pc_starting);
-       }
        return 0;
 
-out_env:
-       lu_context_fini(&pc->pc_env.le_ctx);
-
 out_set:
        if (pc->pc_set != NULL) {
                struct ptlrpc_request_set *set = pc->pc_set;
@@ -654,7 +587,7 @@ out_set:
                spin_unlock(&pc->pc_lock);
                ptlrpc_set_destroy(set);
        }
-       clear_bit(LIOD_BIND, &pc->pc_flags);
+       lu_context_fini(&pc->pc_env.le_ctx);
 
 out:
        clear_bit(LIOD_START, &pc->pc_flags);
@@ -694,7 +627,6 @@ void ptlrpcd_free(struct ptlrpcd_ctl *pc)
        clear_bit(LIOD_START, &pc->pc_flags);
        clear_bit(LIOD_STOP, &pc->pc_flags);
        clear_bit(LIOD_FORCE, &pc->pc_flags);
-       clear_bit(LIOD_BIND, &pc->pc_flags);
 
 out:
        if (pc->pc_npartners > 0) {
@@ -704,88 +636,262 @@ out:
                pc->pc_partners = NULL;
        }
        pc->pc_npartners = 0;
+       pc->pc_error = 0;
 }
 
 static void ptlrpcd_fini(void)
 {
        int i;
+       int j;
 
        if (ptlrpcds != NULL) {
-               for (i = 0; i < ptlrpcds->pd_nthreads; i++)
-                       ptlrpcd_stop(&ptlrpcds->pd_threads[i], 0);
-               for (i = 0; i < ptlrpcds->pd_nthreads; i++)
-                       ptlrpcd_free(&ptlrpcds->pd_threads[i]);
-               ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
-               ptlrpcd_free(&ptlrpcds->pd_thread_rcv);
+               for (i = 0; i < ptlrpcds_num; i++) {
+                       if (!ptlrpcds[i])
+                               break;
+                       for (j = 0; j < ptlrpcds[i]->pd_nthreads; j++)
+                               ptlrpcd_stop(&ptlrpcds[i]->pd_threads[j], 0);
+                       for (j = 0; j < ptlrpcds[i]->pd_nthreads; j++)
+                               ptlrpcd_free(&ptlrpcds[i]->pd_threads[j]);
+                       kfree(ptlrpcds[i]);
+                       ptlrpcds[i] = NULL;
+               }
                kfree(ptlrpcds);
-               ptlrpcds = NULL;
        }
+       ptlrpcds_num = 0;
+
+       ptlrpcd_stop(&ptlrpcd_rcv, 0);
+       ptlrpcd_free(&ptlrpcd_rcv);
+
+       kfree(ptlrpcds_cpt_idx);
+       ptlrpcds_cpt_idx = NULL;
 }
 
 static int ptlrpcd_init(void)
 {
-       int nthreads = num_online_cpus();
-       char name[16];
-       int size, i = -1, j, rc = 0;
-
-       if (max_ptlrpcds > 0 && max_ptlrpcds < nthreads)
-               nthreads = max_ptlrpcds;
-       if (nthreads < 2)
-               nthreads = 2;
-       if (nthreads < 3 && ptlrpcd_bind_policy == PDB_POLICY_NEIGHBOR)
-               ptlrpcd_bind_policy = PDB_POLICY_PAIR;
-       else if (nthreads % 2 != 0 && ptlrpcd_bind_policy == PDB_POLICY_PAIR)
-               nthreads &= ~1; /* make sure it is even */
-
-       size = offsetof(struct ptlrpcd, pd_threads[nthreads]);
-       ptlrpcds = kzalloc(size, GFP_NOFS);
+       int nthreads;
+       int groupsize;
+       int size;
+       int i;
+       int j;
+       int rc = 0;
+       struct cfs_cpt_table *cptable;
+       __u32 *cpts = NULL;
+       int ncpts;
+       int cpt;
+       struct ptlrpcd *pd;
+
+       /*
+        * Determine the CPTs that ptlrpcd threads will run on.
+        */
+       cptable = cfs_cpt_table;
+       ncpts = cfs_cpt_number(cptable);
+       if (ptlrpcd_cpts) {
+               struct cfs_expr_list *el;
+
+               size = ncpts * sizeof(ptlrpcds_cpt_idx[0]);
+               ptlrpcds_cpt_idx = kzalloc(size, GFP_KERNEL);
+               if (!ptlrpcds_cpt_idx) {
+                       rc = -ENOMEM;
+                       goto out;
+               }
+
+               rc = cfs_expr_list_parse(ptlrpcd_cpts,
+                                        strlen(ptlrpcd_cpts),
+                                        0, ncpts - 1, &el);
+
+               if (rc != 0) {
+                       CERROR("ptlrpcd_cpts: invalid CPT pattern string: %s",
+                              ptlrpcd_cpts);
+                       rc = -EINVAL;
+                       goto out;
+               }
+
+               rc = cfs_expr_list_values(el, ncpts, &cpts);
+               cfs_expr_list_free(el);
+               if (rc <= 0) {
+                       CERROR("ptlrpcd_cpts: failed to parse CPT array %s: %d\n",
+                              ptlrpcd_cpts, rc);
+                       if (rc == 0)
+                               rc = -EINVAL;
+                       goto out;
+               }
+
+               /*
+                * Create the cpt-to-index map. When there is no match
+                * in the cpt table, pick a cpt at random. This could
+                * be changed to take the topology of the system into
+                * account.
+                */
+               for (cpt = 0; cpt < ncpts; cpt++) {
+                       for (i = 0; i < rc; i++)
+                               if (cpts[i] == cpt)
+                                       break;
+                       if (i >= rc)
+                               i = cpt % rc;
+                       ptlrpcds_cpt_idx[cpt] = i;
+               }
+
+               cfs_expr_list_values_free(cpts, rc);
+               ncpts = rc;
+       }
+       ptlrpcds_num = ncpts;
+
+       size = ncpts * sizeof(ptlrpcds[0]);
+       ptlrpcds = kzalloc(size, GFP_KERNEL);
        if (!ptlrpcds) {
                rc = -ENOMEM;
                goto out;
        }
 
-       snprintf(name, sizeof(name), "ptlrpcd_rcv");
-       set_bit(LIOD_RECOVERY, &ptlrpcds->pd_thread_rcv.pc_flags);
-       rc = ptlrpcd_start(-1, nthreads, name, &ptlrpcds->pd_thread_rcv);
+       /*
+        * The max_ptlrpcds parameter is obsolete, but do something
+        * sane if it has been tuned, and complain if
+        * ptlrpcd_per_cpt_max has also been tuned.
+        */
+       if (max_ptlrpcds != 0) {
+               CWARN("max_ptlrpcds is obsolete.\n");
+               if (ptlrpcd_per_cpt_max == 0) {
+                       ptlrpcd_per_cpt_max = max_ptlrpcds / ncpts;
+                       /* Round up if there is a remainder. */
+                       if (max_ptlrpcds % ncpts != 0)
+                               ptlrpcd_per_cpt_max++;
+                       CWARN("Setting ptlrpcd_per_cpt_max = %d\n",
+                             ptlrpcd_per_cpt_max);
+               } else {
+                       CWARN("ptlrpd_per_cpt_max is also set!\n");
+               }
+       }
+
+       /*
+        * The ptlrpcd_bind_policy parameter is obsolete, but do
+        * something sane if it has been tuned, and complain if
+        * ptlrpcd_partner_group_size is also tuned.
+        */
+       if (ptlrpcd_bind_policy != 0) {
+               CWARN("ptlrpcd_bind_policy is obsolete.\n");
+               if (ptlrpcd_partner_group_size == 0) {
+                       switch (ptlrpcd_bind_policy) {
+                       case 1: /* PDB_POLICY_NONE */
+                       case 2: /* PDB_POLICY_FULL */
+                               ptlrpcd_partner_group_size = 1;
+                               break;
+                       case 3: /* PDB_POLICY_PAIR */
+                               ptlrpcd_partner_group_size = 2;
+                               break;
+                       case 4: /* PDB_POLICY_NEIGHBOR */
+#ifdef CONFIG_NUMA
+                               ptlrpcd_partner_group_size = -1; /* CPT */
+#else
+                               ptlrpcd_partner_group_size = 3; /* Triplets */
+#endif
+                               break;
+                       default: /* Illegal value, use the default. */
+                               ptlrpcd_partner_group_size = 2;
+                               break;
+                       }
+                       CWARN("Setting ptlrpcd_partner_group_size = %d\n",
+                             ptlrpcd_partner_group_size);
+               } else {
+                       CWARN("ptlrpcd_partner_group_size is also set!\n");
+               }
+       }
+
+       if (ptlrpcd_partner_group_size == 0)
+               ptlrpcd_partner_group_size = 2;
+       else if (ptlrpcd_partner_group_size < 0)
+               ptlrpcd_partner_group_size = -1;
+       else if (ptlrpcd_per_cpt_max > 0 &&
+                ptlrpcd_partner_group_size > ptlrpcd_per_cpt_max)
+               ptlrpcd_partner_group_size = ptlrpcd_per_cpt_max;
+
+       /*
+        * Start the recovery thread first.
+        */
+       set_bit(LIOD_RECOVERY, &ptlrpcd_rcv.pc_flags);
+       ptlrpcd_ctl_init(&ptlrpcd_rcv, -1, CFS_CPT_ANY);
+       rc = ptlrpcd_start(&ptlrpcd_rcv);
        if (rc < 0)
                goto out;
 
-       /* XXX: We start nthreads ptlrpc daemons. Each of them can process any
-        *      non-recovery async RPC to improve overall async RPC efficiency.
-        *
-        *      But there are some issues with async I/O RPCs and async non-I/O
-        *      RPCs processed in the same set under some cases. The ptlrpcd may
-        *      be blocked by some async I/O RPC(s), then will cause other async
-        *      non-I/O RPC(s) can not be processed in time.
-        *
-        *      Maybe we should distinguish blocked async RPCs from non-blocked
-        *      async RPCs, and process them in different ptlrpcd sets to avoid
-        *      unnecessary dependency. But how to distribute async RPCs load
-        *      among all the ptlrpc daemons becomes another trouble. */
-       for (i = 0; i < nthreads; i++) {
-               snprintf(name, sizeof(name), "ptlrpcd_%d", i);
-               rc = ptlrpcd_start(i, nthreads, name, &ptlrpcds->pd_threads[i]);
-               if (rc < 0)
+       for (i = 0; i < ncpts; i++) {
+               if (!cpts)
+                       cpt = i;
+               else
+                       cpt = cpts[i];
+
+               nthreads = cfs_cpt_weight(cptable, cpt);
+               if (ptlrpcd_per_cpt_max > 0 && ptlrpcd_per_cpt_max < nthreads)
+                       nthreads = ptlrpcd_per_cpt_max;
+               if (nthreads < 2)
+                       nthreads = 2;
+
+               if (ptlrpcd_partner_group_size <= 0) {
+                       groupsize = nthreads;
+               } else if (nthreads <= ptlrpcd_partner_group_size) {
+                       groupsize = nthreads;
+               } else {
+                       groupsize = ptlrpcd_partner_group_size;
+                       if (nthreads % groupsize != 0)
+                               nthreads += groupsize - (nthreads % groupsize);
+               }
+
+               size = offsetof(struct ptlrpcd, pd_threads[nthreads]);
+               pd = kzalloc_node(size, GFP_NOFS,
+                                 cfs_cpt_spread_node(cfs_cpt_table, cpt));
+               if (!pd) {
+                       rc = -ENOMEM;
                        goto out;
-       }
+               }
+               pd->pd_size = size;
+               pd->pd_index = i;
+               pd->pd_cpt = cpt;
+               pd->pd_cursor = 0;
+               pd->pd_nthreads = nthreads;
+               pd->pd_groupsize = groupsize;
+               ptlrpcds[i] = pd;
 
-       ptlrpcds->pd_size = size;
-       ptlrpcds->pd_index = 0;
-       ptlrpcds->pd_nthreads = nthreads;
+               /*
+                * The ptlrpcd threads in a partner group can access
+                * each other's struct ptlrpcd_ctl, so these must be
+                * initialized before any thread is started.
+                */
+               for (j = 0; j < nthreads; j++) {
+                       ptlrpcd_ctl_init(&pd->pd_threads[j], j, cpt);
+                       rc = ptlrpcd_partners(pd, j);
+                       if (rc < 0)
+                               goto out;
+               }
 
-out:
-       if (rc != 0 && ptlrpcds != NULL) {
-               for (j = 0; j <= i; j++)
-                       ptlrpcd_stop(&ptlrpcds->pd_threads[j], 0);
-               for (j = 0; j <= i; j++)
-                       ptlrpcd_free(&ptlrpcds->pd_threads[j]);
-               ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
-               ptlrpcd_free(&ptlrpcds->pd_thread_rcv);
-               kfree(ptlrpcds);
-               ptlrpcds = NULL;
+               /* XXX: We start nthreads ptlrpc daemons.
+                *      Each of them can process any non-recovery
+                *      async RPC to improve overall async RPC
+                *      efficiency.
+                *
+                *      But there are some issues with async I/O RPCs
+                *      and async non-I/O RPCs processed in the same
+                *      set under some cases. The ptlrpcd may be
+                *      blocked by some async I/O RPC(s), then will
+                *      cause other async non-I/O RPC(s) can not be
+                *      processed in time.
+                *
+                *      Maybe we should distinguish blocked async RPCs
+                *      from non-blocked async RPCs, and process them
+                *      in different ptlrpcd sets to avoid unnecessary
+                *      dependency. But how to distribute async RPCs
+                *      load among all the ptlrpc daemons becomes
+                *      another trouble.
+                */
+               for (j = 0; j < nthreads; j++) {
+                       rc = ptlrpcd_start(&pd->pd_threads[j]);
+                       if (rc < 0)
+                               goto out;
+               }
        }
+out:
+       if (rc != 0)
+               ptlrpcd_fini();
 
-       return 0;
+       return rc;
 }
 
 int ptlrpcd_addref(void)
index b9821db2290467d676bed6f0afcee5e32e2b82b0..39f5261c9854184a48d4d42a917a754b436ef3fc 100644 (file)
@@ -227,7 +227,7 @@ char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize)
 }
 EXPORT_SYMBOL(sptlrpc_flavor2name);
 
-char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize)
+static char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize)
 {
        buf[0] = '\0';
 
@@ -244,7 +244,6 @@ char *sptlrpc_secflags2str(__u32 flags, char *buf, int bufsize)
 
        return buf;
 }
-EXPORT_SYMBOL(sptlrpc_secflags2str);
 
 /**************************************************
  * client context APIs                     *
@@ -297,53 +296,13 @@ void sptlrpc_cli_ctx_put(struct ptlrpc_cli_ctx *ctx, int sync)
 }
 EXPORT_SYMBOL(sptlrpc_cli_ctx_put);
 
-/**
- * Expire the client context immediately.
- *
- * \pre Caller must hold at least 1 reference on the \a ctx.
- */
-void sptlrpc_cli_ctx_expire(struct ptlrpc_cli_ctx *ctx)
-{
-       LASSERT(ctx->cc_ops->force_die);
-       ctx->cc_ops->force_die(ctx, 0);
-}
-EXPORT_SYMBOL(sptlrpc_cli_ctx_expire);
-
-/**
- * To wake up the threads who are waiting for this client context. Called
- * after some status change happened on \a ctx.
- */
-void sptlrpc_cli_ctx_wakeup(struct ptlrpc_cli_ctx *ctx)
-{
-       struct ptlrpc_request *req, *next;
-
-       spin_lock(&ctx->cc_lock);
-       list_for_each_entry_safe(req, next, &ctx->cc_req_list,
-                                    rq_ctx_chain) {
-               list_del_init(&req->rq_ctx_chain);
-               ptlrpc_client_wake_req(req);
-       }
-       spin_unlock(&ctx->cc_lock);
-}
-EXPORT_SYMBOL(sptlrpc_cli_ctx_wakeup);
-
-int sptlrpc_cli_ctx_display(struct ptlrpc_cli_ctx *ctx, char *buf, int bufsize)
-{
-       LASSERT(ctx->cc_ops);
-
-       if (ctx->cc_ops->display == NULL)
-               return 0;
-
-       return ctx->cc_ops->display(ctx, buf, bufsize);
-}
-
 static int import_sec_check_expire(struct obd_import *imp)
 {
        int adapt = 0;
 
        spin_lock(&imp->imp_lock);
        if (imp->imp_sec_expire &&
-           imp->imp_sec_expire < get_seconds()) {
+           imp->imp_sec_expire < ktime_get_real_seconds()) {
                adapt = 1;
                imp->imp_sec_expire = 0;
        }
@@ -510,7 +469,7 @@ int sptlrpc_req_ctx_switch(struct ptlrpc_request *req,
  * \note a request must have a context, to keep other parts of code happy.
  * In any case of failure during the switching, we must restore the old one.
  */
-int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req)
+static int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req)
 {
        struct ptlrpc_cli_ctx *oldctx = req->rq_cli_ctx;
        struct ptlrpc_cli_ctx *newctx;
@@ -563,7 +522,6 @@ int sptlrpc_req_replace_dead_ctx(struct ptlrpc_request *req)
        sptlrpc_cli_ctx_put(oldctx, 1);
        return 0;
 }
-EXPORT_SYMBOL(sptlrpc_req_replace_dead_ctx);
 
 static
 int ctx_check_refresh(struct ptlrpc_cli_ctx *ctx)
@@ -1229,12 +1187,6 @@ static void sec_cop_destroy_sec(struct ptlrpc_sec *sec)
        sptlrpc_policy_put(policy);
 }
 
-void sptlrpc_sec_destroy(struct ptlrpc_sec *sec)
-{
-       sec_cop_destroy_sec(sec);
-}
-EXPORT_SYMBOL(sptlrpc_sec_destroy);
-
 static void sptlrpc_sec_kill(struct ptlrpc_sec *sec)
 {
        LASSERT_ATOMIC_POS(&sec->ps_refcount);
@@ -1246,14 +1198,13 @@ static void sptlrpc_sec_kill(struct ptlrpc_sec *sec)
        }
 }
 
-struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec)
+static struct ptlrpc_sec *sptlrpc_sec_get(struct ptlrpc_sec *sec)
 {
        if (sec)
                atomic_inc(&sec->ps_refcount);
 
        return sec;
 }
-EXPORT_SYMBOL(sptlrpc_sec_get);
 
 void sptlrpc_sec_put(struct ptlrpc_sec *sec)
 {
@@ -1507,13 +1458,6 @@ static void import_flush_ctx_common(struct obd_import *imp,
        sptlrpc_sec_put(sec);
 }
 
-void sptlrpc_import_flush_root_ctx(struct obd_import *imp)
-{
-       /* it's important to use grace mode, see explain in
-        * sptlrpc_req_refresh_ctx() */
-       import_flush_ctx_common(imp, 0, 1, 1);
-}
-
 void sptlrpc_import_flush_my_ctx(struct obd_import *imp)
 {
        import_flush_ctx_common(imp, from_kuid(&init_user_ns, current_uid()),
@@ -1697,18 +1641,8 @@ void sptlrpc_cli_free_repbuf(struct ptlrpc_request *req)
        req->rq_repmsg = NULL;
 }
 
-int sptlrpc_cli_install_rvs_ctx(struct obd_import *imp,
-                               struct ptlrpc_cli_ctx *ctx)
-{
-       struct ptlrpc_sec_policy *policy = ctx->cc_sec->ps_policy;
-
-       if (!policy->sp_cops->install_rctx)
-               return 0;
-       return policy->sp_cops->install_rctx(imp, ctx->cc_sec, ctx);
-}
-
-int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
-                               struct ptlrpc_svc_ctx *ctx)
+static int sptlrpc_svc_install_rvs_ctx(struct obd_import *imp,
+                                      struct ptlrpc_svc_ctx *ctx)
 {
        struct ptlrpc_sec_policy *policy = ctx->sc_policy;
 
@@ -1779,7 +1713,7 @@ int sptlrpc_target_export_check(struct obd_export *exp,
                exp->exp_flvr_old[1] = exp->exp_flvr_old[0];
                exp->exp_flvr_expire[1] = exp->exp_flvr_expire[0];
                exp->exp_flvr_old[0] = exp->exp_flvr;
-               exp->exp_flvr_expire[0] = get_seconds() +
+               exp->exp_flvr_expire[0] = ktime_get_real_seconds() +
                                          EXP_FLVR_UPDATE_EXPIRE;
                exp->exp_flvr = flavor;
 
@@ -1853,14 +1787,14 @@ int sptlrpc_target_export_check(struct obd_export *exp,
        }
 
        if (exp->exp_flvr_expire[0]) {
-               if (exp->exp_flvr_expire[0] >= get_seconds()) {
+               if (exp->exp_flvr_expire[0] >= ktime_get_real_seconds()) {
                        if (flavor_allowed(&exp->exp_flvr_old[0], req)) {
-                               CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the middle one (" CFS_DURATION_T ")\n", exp,
+                               CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the middle one (%lld)\n", exp,
                                       exp->exp_flvr.sf_rpc,
                                       exp->exp_flvr_old[0].sf_rpc,
                                       exp->exp_flvr_old[1].sf_rpc,
-                                      exp->exp_flvr_expire[0] -
-                                      get_seconds());
+                                      (s64)(exp->exp_flvr_expire[0] -
+                                      ktime_get_real_seconds()));
                                spin_unlock(&exp->exp_lock);
                                return 0;
                        }
@@ -1877,15 +1811,15 @@ int sptlrpc_target_export_check(struct obd_export *exp,
        /* now it doesn't match the current flavor, the only chance we can
         * accept it is match the old flavors which is not expired. */
        if (exp->exp_flvr_changed == 0 && exp->exp_flvr_expire[1]) {
-               if (exp->exp_flvr_expire[1] >= get_seconds()) {
+               if (exp->exp_flvr_expire[1] >= ktime_get_real_seconds()) {
                        if (flavor_allowed(&exp->exp_flvr_old[1], req)) {
-                               CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the oldest one (" CFS_DURATION_T ")\n",
+                               CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the oldest one (%lld)\n",
                                       exp,
                                       exp->exp_flvr.sf_rpc,
                                       exp->exp_flvr_old[0].sf_rpc,
                                       exp->exp_flvr_old[1].sf_rpc,
-                                      exp->exp_flvr_expire[1] -
-                                      get_seconds());
+                                      (s64)(exp->exp_flvr_expire[1] -
+                                      ktime_get_real_seconds()));
                                spin_unlock(&exp->exp_lock);
                                return 0;
                        }
@@ -1905,7 +1839,7 @@ int sptlrpc_target_export_check(struct obd_export *exp,
 
        spin_unlock(&exp->exp_lock);
 
-       CWARN("exp %p(%s): req %p (%u|%u|%u|%u|%u|%u) with unauthorized flavor %x, expect %x|%x(%+ld)|%x(%+ld)\n",
+       CWARN("exp %p(%s): req %p (%u|%u|%u|%u|%u|%u) with unauthorized flavor %x, expect %x|%x(%+lld)|%x(%+lld)\n",
              exp, exp->exp_obd->obd_name,
              req, req->rq_auth_gss, req->rq_ctx_init, req->rq_ctx_fini,
              req->rq_auth_usr_root, req->rq_auth_usr_mdt, req->rq_auth_usr_ost,
@@ -1913,56 +1847,14 @@ int sptlrpc_target_export_check(struct obd_export *exp,
              exp->exp_flvr.sf_rpc,
              exp->exp_flvr_old[0].sf_rpc,
              exp->exp_flvr_expire[0] ?
-             (unsigned long) (exp->exp_flvr_expire[0] -
-                              get_seconds()) : 0,
+             (s64)(exp->exp_flvr_expire[0] - ktime_get_real_seconds()) : 0,
              exp->exp_flvr_old[1].sf_rpc,
              exp->exp_flvr_expire[1] ?
-             (unsigned long) (exp->exp_flvr_expire[1] -
-                              get_seconds()) : 0);
+             (s64)(exp->exp_flvr_expire[1] - ktime_get_real_seconds()) : 0);
        return -EACCES;
 }
 EXPORT_SYMBOL(sptlrpc_target_export_check);
 
-void sptlrpc_target_update_exp_flavor(struct obd_device *obd,
-                                     struct sptlrpc_rule_set *rset)
-{
-       struct obd_export *exp;
-       struct sptlrpc_flavor new_flvr;
-
-       LASSERT(obd);
-
-       spin_lock(&obd->obd_dev_lock);
-
-       list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
-               if (exp->exp_connection == NULL)
-                       continue;
-
-               /* note if this export had just been updated flavor
-                * (exp_flvr_changed == 1), this will override the
-                * previous one. */
-               spin_lock(&exp->exp_lock);
-               sptlrpc_target_choose_flavor(rset, exp->exp_sp_peer,
-                                            exp->exp_connection->c_peer.nid,
-                                            &new_flvr);
-               if (exp->exp_flvr_changed ||
-                   !flavor_equal(&new_flvr, &exp->exp_flvr)) {
-                       exp->exp_flvr_old[1] = new_flvr;
-                       exp->exp_flvr_expire[1] = 0;
-                       exp->exp_flvr_changed = 1;
-                       exp->exp_flvr_adapt = 1;
-
-                       CDEBUG(D_SEC, "exp %p (%s): updated flavor %x->%x\n",
-                              exp, sptlrpc_part2name(exp->exp_sp_peer),
-                              exp->exp_flvr.sf_rpc,
-                              exp->exp_flvr_old[1].sf_rpc);
-               }
-               spin_unlock(&exp->exp_lock);
-       }
-
-       spin_unlock(&obd->obd_dev_lock);
-}
-EXPORT_SYMBOL(sptlrpc_target_update_exp_flavor);
-
 static int sptlrpc_svc_check_from(struct ptlrpc_request *req, int svc_rc)
 {
        /* peer's claim is unreliable unless gss is being used */
@@ -2090,6 +1982,7 @@ int sptlrpc_svc_alloc_rs(struct ptlrpc_request *req, int msglen)
        rc = policy->sp_sops->alloc_rs(req, msglen);
        if (unlikely(rc == -ENOMEM)) {
                struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
+
                if (svcpt->scp_service->srv_max_reply_size <
                   msglen + sizeof(struct ptlrpc_reply_state)) {
                        /* Just return failure if the size is too big */
@@ -2185,19 +2078,6 @@ void sptlrpc_svc_ctx_decref(struct ptlrpc_request *req)
        req->rq_svc_ctx = NULL;
 }
 
-void sptlrpc_svc_ctx_invalidate(struct ptlrpc_request *req)
-{
-       struct ptlrpc_svc_ctx *ctx = req->rq_svc_ctx;
-
-       if (ctx == NULL)
-               return;
-
-       LASSERT_ATOMIC_POS(&ctx->sc_refcount);
-       if (ctx->sc_policy->sp_sops->invalidate_ctx)
-               ctx->sc_policy->sp_sops->invalidate_ctx(ctx);
-}
-EXPORT_SYMBOL(sptlrpc_svc_ctx_invalidate);
-
 /****************************************
  * bulk security                       *
  ****************************************/
@@ -2285,7 +2165,6 @@ int sptlrpc_cli_unwrap_bulk_write(struct ptlrpc_request *req,
 }
 EXPORT_SYMBOL(sptlrpc_cli_unwrap_bulk_write);
 
-
 /****************************************
  * user descriptor helpers           *
  ****************************************/
@@ -2382,14 +2261,14 @@ EXPORT_SYMBOL(sec2target_str);
 /*
  * return true if the bulk data is protected
  */
-int sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr)
+bool sptlrpc_flavor_has_bulk(struct sptlrpc_flavor *flvr)
 {
        switch (SPTLRPC_FLVR_BULK_SVC(flvr->sf_rpc)) {
        case SPTLRPC_BULK_SVC_INTG:
        case SPTLRPC_BULK_SVC_PRIV:
-               return 1;
+               return true;
        default:
-               return 0;
+               return false;
        }
 }
 EXPORT_SYMBOL(sptlrpc_flavor_has_bulk);
index 2ee3e8b2e879eac164aa73e7454fd5393d89c416..cd8a9987f7ac9706901664bc207b4270663bc0d9 100644 (file)
@@ -58,7 +58,6 @@
  * bulk encryption page pools     *
  ****************************************/
 
-
 #define POINTERS_PER_PAGE      (PAGE_CACHE_SIZE / sizeof(void *))
 #define PAGES_PER_POOL         (POINTERS_PER_PAGE)
 
@@ -92,8 +91,8 @@ static struct ptlrpc_enc_page_pool {
        unsigned long    epp_idle_idx;
 
        /* last shrink time due to mem tight */
-       long         epp_last_shrink;
-       long         epp_last_access;
+       time64_t         epp_last_shrink;
+       time64_t         epp_last_access;
 
        /*
         * in-pool pages bookkeeping
@@ -145,7 +144,7 @@ int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v)
                   "cache missing:         %lu\n"
                   "low free mark:         %lu\n"
                   "max waitqueue depth:     %u\n"
-                  "max wait time:         " CFS_TIME_T "/%u\n",
+                  "max wait time:         %ld/%u\n",
                   totalram_pages,
                   PAGES_PER_POOL,
                   page_pools.epp_max_pages,
@@ -153,8 +152,8 @@ int sptlrpc_proc_enc_pool_seq_show(struct seq_file *m, void *v)
                   page_pools.epp_total_pages,
                   page_pools.epp_free_pages,
                   page_pools.epp_idle_idx,
-                  get_seconds() - page_pools.epp_last_shrink,
-                  get_seconds() - page_pools.epp_last_access,
+                  (long)(ktime_get_seconds() - page_pools.epp_last_shrink),
+                  (long)(ktime_get_seconds() - page_pools.epp_last_access),
                   page_pools.epp_st_max_pages,
                   page_pools.epp_st_grows,
                   page_pools.epp_st_grow_fails,
@@ -226,7 +225,7 @@ static unsigned long enc_pools_shrink_count(struct shrinker *s,
         * if no pool access for a long time, we consider it's fully idle.
         * a little race here is fine.
         */
-       if (unlikely(get_seconds() - page_pools.epp_last_access >
+       if (unlikely(ktime_get_seconds() - page_pools.epp_last_access >
                     CACHE_QUIESCENT_PERIOD)) {
                spin_lock(&page_pools.epp_lock);
                page_pools.epp_idle_idx = IDLE_IDX_MAX;
@@ -253,7 +252,7 @@ static unsigned long enc_pools_shrink_scan(struct shrinker *s,
                       (long)sc->nr_to_scan, page_pools.epp_free_pages);
 
                page_pools.epp_st_shrinks++;
-               page_pools.epp_last_shrink = get_seconds();
+               page_pools.epp_last_shrink = ktime_get_seconds();
        }
        spin_unlock(&page_pools.epp_lock);
 
@@ -261,7 +260,7 @@ static unsigned long enc_pools_shrink_scan(struct shrinker *s,
         * if no pool access for a long time, we consider it's fully idle.
         * a little race here is fine.
         */
-       if (unlikely(get_seconds() - page_pools.epp_last_access >
+       if (unlikely(ktime_get_seconds() - page_pools.epp_last_access >
                     CACHE_QUIESCENT_PERIOD)) {
                spin_lock(&page_pools.epp_lock);
                page_pools.epp_idle_idx = IDLE_IDX_MAX;
@@ -302,150 +301,6 @@ static unsigned long enc_pools_cleanup(struct page ***pools, int npools)
        return cleaned;
 }
 
-/*
- * merge @npools pointed by @pools which contains @npages new pages
- * into current pools.
- *
- * we have options to avoid most memory copy with some tricks. but we choose
- * the simplest way to avoid complexity. It's not frequently called.
- */
-static void enc_pools_insert(struct page ***pools, int npools, int npages)
-{
-       int freeslot;
-       int op_idx, np_idx, og_idx, ng_idx;
-       int cur_npools, end_npools;
-
-       LASSERT(npages > 0);
-       LASSERT(page_pools.epp_total_pages+npages <= page_pools.epp_max_pages);
-       LASSERT(npages_to_npools(npages) == npools);
-       LASSERT(page_pools.epp_growing);
-
-       spin_lock(&page_pools.epp_lock);
-
-       /*
-        * (1) fill all the free slots of current pools.
-        */
-       /* free slots are those left by rent pages, and the extra ones with
-        * index >= total_pages, locate at the tail of last pool. */
-       freeslot = page_pools.epp_total_pages % PAGES_PER_POOL;
-       if (freeslot != 0)
-               freeslot = PAGES_PER_POOL - freeslot;
-       freeslot += page_pools.epp_total_pages - page_pools.epp_free_pages;
-
-       op_idx = page_pools.epp_free_pages / PAGES_PER_POOL;
-       og_idx = page_pools.epp_free_pages % PAGES_PER_POOL;
-       np_idx = npools - 1;
-       ng_idx = (npages - 1) % PAGES_PER_POOL;
-
-       while (freeslot) {
-               LASSERT(page_pools.epp_pools[op_idx][og_idx] == NULL);
-               LASSERT(pools[np_idx][ng_idx] != NULL);
-
-               page_pools.epp_pools[op_idx][og_idx] = pools[np_idx][ng_idx];
-               pools[np_idx][ng_idx] = NULL;
-
-               freeslot--;
-
-               if (++og_idx == PAGES_PER_POOL) {
-                       op_idx++;
-                       og_idx = 0;
-               }
-               if (--ng_idx < 0) {
-                       if (np_idx == 0)
-                               break;
-                       np_idx--;
-                       ng_idx = PAGES_PER_POOL - 1;
-               }
-       }
-
-       /*
-        * (2) add pools if needed.
-        */
-       cur_npools = (page_pools.epp_total_pages + PAGES_PER_POOL - 1) /
-                    PAGES_PER_POOL;
-       end_npools = (page_pools.epp_total_pages + npages + PAGES_PER_POOL - 1)
-                    / PAGES_PER_POOL;
-       LASSERT(end_npools <= page_pools.epp_max_pools);
-
-       np_idx = 0;
-       while (cur_npools < end_npools) {
-               LASSERT(page_pools.epp_pools[cur_npools] == NULL);
-               LASSERT(np_idx < npools);
-               LASSERT(pools[np_idx] != NULL);
-
-               page_pools.epp_pools[cur_npools++] = pools[np_idx];
-               pools[np_idx++] = NULL;
-       }
-
-       page_pools.epp_total_pages += npages;
-       page_pools.epp_free_pages += npages;
-       page_pools.epp_st_lowfree = page_pools.epp_free_pages;
-
-       if (page_pools.epp_total_pages > page_pools.epp_st_max_pages)
-               page_pools.epp_st_max_pages = page_pools.epp_total_pages;
-
-       CDEBUG(D_SEC, "add %d pages to total %lu\n", npages,
-              page_pools.epp_total_pages);
-
-       spin_unlock(&page_pools.epp_lock);
-}
-
-static int enc_pools_add_pages(int npages)
-{
-       static DEFINE_MUTEX(add_pages_mutex);
-       struct page ***pools;
-       int npools, alloced = 0;
-       int i, j, rc = -ENOMEM;
-
-       if (npages < PTLRPC_MAX_BRW_PAGES)
-               npages = PTLRPC_MAX_BRW_PAGES;
-
-       mutex_lock(&add_pages_mutex);
-
-       if (npages + page_pools.epp_total_pages > page_pools.epp_max_pages)
-               npages = page_pools.epp_max_pages - page_pools.epp_total_pages;
-       LASSERT(npages > 0);
-
-       page_pools.epp_st_grows++;
-
-       npools = npages_to_npools(npages);
-       pools = kcalloc(npools, sizeof(*pools), GFP_NOFS);
-       if (pools == NULL)
-               goto out;
-
-       for (i = 0; i < npools; i++) {
-               pools[i] = kzalloc(PAGE_CACHE_SIZE, GFP_NOFS);
-               if (!pools[i])
-                       goto out_pools;
-
-               for (j = 0; j < PAGES_PER_POOL && alloced < npages; j++) {
-                       pools[i][j] = alloc_page(GFP_NOFS |
-                                                    __GFP_HIGHMEM);
-                       if (pools[i][j] == NULL)
-                               goto out_pools;
-
-                       alloced++;
-               }
-       }
-       LASSERT(alloced == npages);
-
-       enc_pools_insert(pools, npools, npages);
-       CDEBUG(D_SEC, "added %d pages into pools\n", npages);
-       rc = 0;
-
-out_pools:
-       enc_pools_cleanup(pools, npools);
-       kfree(pools);
-out:
-       if (rc) {
-               page_pools.epp_st_grow_fails++;
-               CERROR("Failed to allocate %d enc pages\n", npages);
-       }
-
-       mutex_unlock(&add_pages_mutex);
-       return rc;
-}
-
 static inline void enc_pools_wakeup(void)
 {
        assert_spin_locked(&page_pools.epp_lock);
@@ -457,156 +312,6 @@ static inline void enc_pools_wakeup(void)
        }
 }
 
-static int enc_pools_should_grow(int page_needed, long now)
-{
-       /* don't grow if someone else is growing the pools right now,
-        * or the pools has reached its full capacity
-        */
-       if (page_pools.epp_growing ||
-           page_pools.epp_total_pages == page_pools.epp_max_pages)
-               return 0;
-
-       /* if total pages is not enough, we need to grow */
-       if (page_pools.epp_total_pages < page_needed)
-               return 1;
-
-       /*
-        * we wanted to return 0 here if there was a shrink just happened
-        * moment ago, but this may cause deadlock if both client and ost
-        * live on single node.
-        */
-#if 0
-       if (now - page_pools.epp_last_shrink < 2)
-               return 0;
-#endif
-
-       /*
-        * here we perhaps need consider other factors like wait queue
-        * length, idle index, etc. ?
-        */
-
-       /* grow the pools in any other cases */
-       return 1;
-}
-
-/*
- * we allocate the requested pages atomically.
- */
-int sptlrpc_enc_pool_get_pages(struct ptlrpc_bulk_desc *desc)
-{
-       wait_queue_t waitlink;
-       unsigned long this_idle = -1;
-       unsigned long tick = 0;
-       long now;
-       int p_idx, g_idx;
-       int i;
-
-       LASSERT(desc->bd_iov_count > 0);
-       LASSERT(desc->bd_iov_count <= page_pools.epp_max_pages);
-
-       /* resent bulk, enc iov might have been allocated previously */
-       if (desc->bd_enc_iov != NULL)
-               return 0;
-
-       desc->bd_enc_iov = kcalloc(desc->bd_iov_count,
-                                  sizeof(*desc->bd_enc_iov), GFP_NOFS);
-       if (desc->bd_enc_iov == NULL)
-               return -ENOMEM;
-
-       spin_lock(&page_pools.epp_lock);
-
-       page_pools.epp_st_access++;
-again:
-       if (unlikely(page_pools.epp_free_pages < desc->bd_iov_count)) {
-               if (tick == 0)
-                       tick = cfs_time_current();
-
-               now = get_seconds();
-
-               page_pools.epp_st_missings++;
-               page_pools.epp_pages_short += desc->bd_iov_count;
-
-               if (enc_pools_should_grow(desc->bd_iov_count, now)) {
-                       page_pools.epp_growing = 1;
-
-                       spin_unlock(&page_pools.epp_lock);
-                       enc_pools_add_pages(page_pools.epp_pages_short / 2);
-                       spin_lock(&page_pools.epp_lock);
-
-                       page_pools.epp_growing = 0;
-
-                       enc_pools_wakeup();
-               } else {
-                       if (++page_pools.epp_waitqlen >
-                           page_pools.epp_st_max_wqlen)
-                               page_pools.epp_st_max_wqlen =
-                                               page_pools.epp_waitqlen;
-
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       init_waitqueue_entry(&waitlink, current);
-                       add_wait_queue(&page_pools.epp_waitq, &waitlink);
-
-                       spin_unlock(&page_pools.epp_lock);
-                       schedule();
-                       remove_wait_queue(&page_pools.epp_waitq, &waitlink);
-                       LASSERT(page_pools.epp_waitqlen > 0);
-                       spin_lock(&page_pools.epp_lock);
-                       page_pools.epp_waitqlen--;
-               }
-
-               LASSERT(page_pools.epp_pages_short >= desc->bd_iov_count);
-               page_pools.epp_pages_short -= desc->bd_iov_count;
-
-               this_idle = 0;
-               goto again;
-       }
-
-       /* record max wait time */
-       if (unlikely(tick != 0)) {
-               tick = cfs_time_current() - tick;
-               if (tick > page_pools.epp_st_max_wait)
-                       page_pools.epp_st_max_wait = tick;
-       }
-
-       /* proceed with rest of allocation */
-       page_pools.epp_free_pages -= desc->bd_iov_count;
-
-       p_idx = page_pools.epp_free_pages / PAGES_PER_POOL;
-       g_idx = page_pools.epp_free_pages % PAGES_PER_POOL;
-
-       for (i = 0; i < desc->bd_iov_count; i++) {
-               LASSERT(page_pools.epp_pools[p_idx][g_idx] != NULL);
-               desc->bd_enc_iov[i].kiov_page =
-                                       page_pools.epp_pools[p_idx][g_idx];
-               page_pools.epp_pools[p_idx][g_idx] = NULL;
-
-               if (++g_idx == PAGES_PER_POOL) {
-                       p_idx++;
-                       g_idx = 0;
-               }
-       }
-
-       if (page_pools.epp_free_pages < page_pools.epp_st_lowfree)
-               page_pools.epp_st_lowfree = page_pools.epp_free_pages;
-
-       /*
-        * new idle index = (old * weight + new) / (weight + 1)
-        */
-       if (this_idle == -1) {
-               this_idle = page_pools.epp_free_pages * IDLE_IDX_MAX /
-                           page_pools.epp_total_pages;
-       }
-       page_pools.epp_idle_idx = (page_pools.epp_idle_idx * IDLE_IDX_WEIGHT +
-                                  this_idle) /
-                                 (IDLE_IDX_WEIGHT + 1);
-
-       page_pools.epp_last_access = get_seconds();
-
-       spin_unlock(&page_pools.epp_lock);
-       return 0;
-}
-EXPORT_SYMBOL(sptlrpc_enc_pool_get_pages);
-
 void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc)
 {
        int p_idx, g_idx;
@@ -651,41 +356,6 @@ void sptlrpc_enc_pool_put_pages(struct ptlrpc_bulk_desc *desc)
 }
 EXPORT_SYMBOL(sptlrpc_enc_pool_put_pages);
 
-/*
- * we don't do much stuff for add_user/del_user anymore, except adding some
- * initial pages in add_user() if current pools are empty, rest would be
- * handled by the pools's self-adaption.
- */
-int sptlrpc_enc_pool_add_user(void)
-{
-       int need_grow = 0;
-
-       spin_lock(&page_pools.epp_lock);
-       if (page_pools.epp_growing == 0 && page_pools.epp_total_pages == 0) {
-               page_pools.epp_growing = 1;
-               need_grow = 1;
-       }
-       spin_unlock(&page_pools.epp_lock);
-
-       if (need_grow) {
-               enc_pools_add_pages(PTLRPC_MAX_BRW_PAGES +
-                                   PTLRPC_MAX_BRW_PAGES);
-
-               spin_lock(&page_pools.epp_lock);
-               page_pools.epp_growing = 0;
-               enc_pools_wakeup();
-               spin_unlock(&page_pools.epp_lock);
-       }
-       return 0;
-}
-EXPORT_SYMBOL(sptlrpc_enc_pool_add_user);
-
-int sptlrpc_enc_pool_del_user(void)
-{
-       return 0;
-}
-EXPORT_SYMBOL(sptlrpc_enc_pool_del_user);
-
 static inline void enc_pools_alloc(void)
 {
        LASSERT(page_pools.epp_max_pools);
@@ -725,8 +395,8 @@ int sptlrpc_enc_pool_init(void)
        page_pools.epp_growing = 0;
 
        page_pools.epp_idle_idx = 0;
-       page_pools.epp_last_shrink = get_seconds();
-       page_pools.epp_last_access = get_seconds();
+       page_pools.epp_last_shrink = ktime_get_seconds();
+       page_pools.epp_last_access = ktime_get_seconds();
 
        spin_lock_init(&page_pools.epp_lock);
        page_pools.epp_total_pages = 0;
@@ -768,8 +438,7 @@ void sptlrpc_enc_pool_fini(void)
 
        if (page_pools.epp_st_access > 0) {
                CDEBUG(D_SEC,
-                      "max pages %lu, grows %u, grow fails %u, shrinks %u, access %lu, missing %lu, max qlen %u, max wait "
-                      CFS_TIME_T"/%d\n",
+                      "max pages %lu, grows %u, grow fails %u, shrinks %u, access %lu, missing %lu, max qlen %u, max wait %ld/%d\n",
                       page_pools.epp_st_max_pages, page_pools.epp_st_grows,
                       page_pools.epp_st_grow_fails,
                       page_pools.epp_st_shrinks, page_pools.epp_st_access,
@@ -778,7 +447,6 @@ void sptlrpc_enc_pool_fini(void)
        }
 }
 
-
 static int cfs_hash_alg_id[] = {
        [BULK_HASH_ALG_NULL]    = CFS_HASH_ALG_NULL,
        [BULK_HASH_ALG_ADLER32] = CFS_HASH_ALG_ADLER32,
@@ -789,6 +457,7 @@ static int cfs_hash_alg_id[] = {
        [BULK_HASH_ALG_SHA384]  = CFS_HASH_ALG_SHA384,
        [BULK_HASH_ALG_SHA512]  = CFS_HASH_ALG_SHA512,
 };
+
 const char *sptlrpc_get_hash_name(__u8 hash_alg)
 {
        return cfs_crypto_hash_name(cfs_hash_alg_id[hash_alg]);
@@ -871,8 +540,7 @@ int sptlrpc_get_bulk_checksum(struct ptlrpc_bulk_desc *desc, __u8 alg,
                memcpy(buf, hashbuf, buflen);
        } else {
                bufsize = buflen;
-               err = cfs_crypto_hash_final(hdesc, (unsigned char *)buf,
-                                           &bufsize);
+               err = cfs_crypto_hash_final(hdesc, buf, &bufsize);
        }
 
        if (err)
index e7f2f333257db9f964ac590aff1dad7b6979a064..7ff948fe1424721e3f2dd8590efef8f7c3b7496e 100644 (file)
 
 #include "ptlrpc_internal.h"
 
-const char *sptlrpc_part2name(enum lustre_sec_part part)
-{
-       switch (part) {
-       case LUSTRE_SP_CLI:
-               return "cli";
-       case LUSTRE_SP_MDT:
-               return "mdt";
-       case LUSTRE_SP_OST:
-               return "ost";
-       case LUSTRE_SP_MGC:
-               return "mgc";
-       case LUSTRE_SP_MGS:
-               return "mgs";
-       case LUSTRE_SP_ANY:
-               return "any";
-       default:
-               return "err";
-       }
-}
-EXPORT_SYMBOL(sptlrpc_part2name);
-
 enum lustre_sec_part sptlrpc_target_sec_part(struct obd_device *obd)
 {
        const char *type = obd->obd_type->typ_name;
@@ -180,7 +159,7 @@ static void sptlrpc_rule_init(struct sptlrpc_rule *rule)
 /*
  * format: network[.direction]=flavor
  */
-int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule)
+static int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule)
 {
        char *flavor, *dir;
        int rc;
@@ -234,9 +213,8 @@ int sptlrpc_parse_rule(char *param, struct sptlrpc_rule *rule)
 
        return 0;
 }
-EXPORT_SYMBOL(sptlrpc_parse_rule);
 
-void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
+static void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
 {
        LASSERT(rset->srs_nslot ||
                (rset->srs_nrule == 0 && rset->srs_rules == NULL));
@@ -246,12 +224,11 @@ void sptlrpc_rule_set_free(struct sptlrpc_rule_set *rset)
                sptlrpc_rule_set_init(rset);
        }
 }
-EXPORT_SYMBOL(sptlrpc_rule_set_free);
 
 /*
  * return 0 if the rule set could accommodate one more rule.
  */
-int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
+static int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
 {
        struct sptlrpc_rule *rules;
        int nslot;
@@ -280,22 +257,24 @@ int sptlrpc_rule_set_expand(struct sptlrpc_rule_set *rset)
        rset->srs_nslot = nslot;
        return 0;
 }
-EXPORT_SYMBOL(sptlrpc_rule_set_expand);
 
 static inline int rule_spec_dir(struct sptlrpc_rule *rule)
 {
        return (rule->sr_from != LUSTRE_SP_ANY ||
                rule->sr_to != LUSTRE_SP_ANY);
 }
+
 static inline int rule_spec_net(struct sptlrpc_rule *rule)
 {
        return (rule->sr_netid != LNET_NIDNET(LNET_NID_ANY));
 }
+
 static inline int rule_match_dir(struct sptlrpc_rule *r1,
                                 struct sptlrpc_rule *r2)
 {
        return (r1->sr_from == r2->sr_from && r1->sr_to == r2->sr_to);
 }
+
 static inline int rule_match_net(struct sptlrpc_rule *r1,
                                 struct sptlrpc_rule *r2)
 {
@@ -306,8 +285,8 @@ static inline int rule_match_net(struct sptlrpc_rule *r1,
  * merge @rule into @rset.
  * the @rset slots might be expanded.
  */
-int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
-                          struct sptlrpc_rule *rule)
+static int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
+                                 struct sptlrpc_rule *rule)
 {
        struct sptlrpc_rule *p = rset->srs_rules;
        int spec_dir, spec_net;
@@ -391,17 +370,16 @@ int sptlrpc_rule_set_merge(struct sptlrpc_rule_set *rset,
 
        return 0;
 }
-EXPORT_SYMBOL(sptlrpc_rule_set_merge);
 
 /**
  * given from/to/nid, determine a matching flavor in ruleset.
  * return 1 if a match found, otherwise return 0.
  */
-int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
-                           enum lustre_sec_part from,
-                           enum lustre_sec_part to,
-                           lnet_nid_t nid,
-                           struct sptlrpc_flavor *sf)
+static int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
+                                  enum lustre_sec_part from,
+                                  enum lustre_sec_part to,
+                                  lnet_nid_t nid,
+                                  struct sptlrpc_flavor *sf)
 {
        struct sptlrpc_rule *r;
        int n;
@@ -428,20 +406,6 @@ int sptlrpc_rule_set_choose(struct sptlrpc_rule_set *rset,
 
        return 0;
 }
-EXPORT_SYMBOL(sptlrpc_rule_set_choose);
-
-void sptlrpc_rule_set_dump(struct sptlrpc_rule_set *rset)
-{
-       struct sptlrpc_rule *r;
-       int n;
-
-       for (n = 0; n < rset->srs_nrule; n++) {
-               r = &rset->srs_rules[n];
-               CDEBUG(D_SEC, "<%02d> from %x to %x, net %x, rpc %x\n", n,
-                      r->sr_from, r->sr_to, r->sr_netid, r->sr_flvr.sf_rpc);
-       }
-}
-EXPORT_SYMBOL(sptlrpc_rule_set_dump);
 
 /**********************************
  * sptlrpc configuration support  *
@@ -836,20 +800,6 @@ out:
        flavor_set_flags(sf, from, to, 1);
 }
 
-/**
- * called by target devices, determine the expected flavor from
- * certain peer (from, nid).
- */
-void sptlrpc_target_choose_flavor(struct sptlrpc_rule_set *rset,
-                                 enum lustre_sec_part from,
-                                 lnet_nid_t nid,
-                                 struct sptlrpc_flavor *sf)
-{
-       if (sptlrpc_rule_set_choose(rset, from, LUSTRE_SP_ANY, nid, sf) == 0)
-               get_default_flavor(sf);
-}
-EXPORT_SYMBOL(sptlrpc_target_choose_flavor);
-
 #define SEC_ADAPT_DELAY         (10)
 
 /**
@@ -871,7 +821,7 @@ void sptlrpc_conf_client_adapt(struct obd_device *obd)
        if (imp) {
                spin_lock(&imp->imp_lock);
                if (imp->imp_sec)
-                       imp->imp_sec_expire = get_seconds() +
+                       imp->imp_sec_expire = ktime_get_real_seconds() +
                                SEC_ADAPT_DELAY;
                spin_unlock(&imp->imp_lock);
        }
index cdad608bdb8d722e4b56f4111a0b2f8a71ee7731..6e58d5f955d68690fc99753b85b0fbc0348eebaa 100644 (file)
@@ -51,7 +51,6 @@
 
 #define SEC_GC_INTERVAL (30 * 60)
 
-
 static struct mutex sec_gc_mutex;
 static LIST_HEAD(sec_gc_list);
 static spinlock_t sec_gc_list_lock;
@@ -62,14 +61,13 @@ static spinlock_t sec_gc_ctx_list_lock;
 static struct ptlrpc_thread sec_gc_thread;
 static atomic_t sec_gc_wait_del = ATOMIC_INIT(0);
 
-
 void sptlrpc_gc_add_sec(struct ptlrpc_sec *sec)
 {
        LASSERT(sec->ps_policy->sp_cops->gc_ctx);
        LASSERT(sec->ps_gc_interval > 0);
        LASSERT(list_empty(&sec->ps_gc_list));
 
-       sec->ps_gc_next = get_seconds() + sec->ps_gc_interval;
+       sec->ps_gc_next = ktime_get_real_seconds() + sec->ps_gc_interval;
 
        spin_lock(&sec_gc_list_lock);
        list_add_tail(&sec_gc_list, &sec->ps_gc_list);
@@ -103,21 +101,6 @@ void sptlrpc_gc_del_sec(struct ptlrpc_sec *sec)
 }
 EXPORT_SYMBOL(sptlrpc_gc_del_sec);
 
-void sptlrpc_gc_add_ctx(struct ptlrpc_cli_ctx *ctx)
-{
-       LASSERT(list_empty(&ctx->cc_gc_chain));
-
-       CDEBUG(D_SEC, "hand over ctx %p(%u->%s)\n",
-              ctx, ctx->cc_vcred.vc_uid, sec2target_str(ctx->cc_sec));
-       spin_lock(&sec_gc_ctx_list_lock);
-       list_add(&ctx->cc_gc_chain, &sec_gc_ctx_list);
-       spin_unlock(&sec_gc_ctx_list_lock);
-
-       thread_add_flags(&sec_gc_thread, SVC_SIGNAL);
-       wake_up(&sec_gc_thread.t_ctl_waitq);
-}
-EXPORT_SYMBOL(sptlrpc_gc_add_ctx);
-
 static void sec_process_ctx_list(void)
 {
        struct ptlrpc_cli_ctx *ctx;
@@ -154,16 +137,16 @@ static void sec_do_gc(struct ptlrpc_sec *sec)
 
        CDEBUG(D_SEC, "check on sec %p(%s)\n", sec, sec->ps_policy->sp_name);
 
-       if (cfs_time_after(sec->ps_gc_next, get_seconds()))
+       if (sec->ps_gc_next > ktime_get_real_seconds())
                return;
 
        sec->ps_policy->sp_cops->gc_ctx(sec);
-       sec->ps_gc_next = get_seconds() + sec->ps_gc_interval;
+       sec->ps_gc_next = ktime_get_real_seconds() + sec->ps_gc_interval;
 }
 
 static int sec_gc_main(void *arg)
 {
-       struct ptlrpc_thread *thread = (struct ptlrpc_thread *) arg;
+       struct ptlrpc_thread *thread = arg;
        struct l_wait_info lwi;
 
        unshare_fs_struct();
index 68fcac14b3ee3402aac1b5dbd4b36ee255d81428..bda9a77af67ae96050f1c5088e7636617e648161 100644 (file)
@@ -98,14 +98,15 @@ static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
                   atomic_read(&sec->ps_refcount));
        seq_printf(seq, "nctx:    %d\n", atomic_read(&sec->ps_nctx));
        seq_printf(seq, "gc internal    %ld\n", sec->ps_gc_interval);
-       seq_printf(seq, "gc next        %ld\n",
+       seq_printf(seq, "gc next        %lld\n",
                   sec->ps_gc_interval ?
-                  sec->ps_gc_next - get_seconds() : 0);
+                  (s64)(sec->ps_gc_next - ktime_get_real_seconds()) : 0ll);
 
        sptlrpc_sec_put(sec);
 out:
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
 
 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
@@ -130,6 +131,7 @@ static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
 out:
        return 0;
 }
+
 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
 
 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
index ce1c563d0175bdf0bb2322f4f838f9c93dc3fc40..ebfa6092be142cdf47159f08c9a07504ceaad7ba 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_SEC
 
-
 #include "../include/obd_support.h"
 #include "../include/obd_cksum.h"
 #include "../include/obd_class.h"
 #include "../include/lustre_net.h"
 #include "../include/lustre_sec.h"
 
+#include "ptlrpc_internal.h"
+
 static struct ptlrpc_sec_policy null_policy;
 static struct ptlrpc_sec       null_sec;
 static struct ptlrpc_cli_ctx    null_cli_ctx;
@@ -82,6 +83,7 @@ int null_ctx_sign(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req)
 
        if (!req->rq_import->imp_dlm_fake) {
                struct obd_device *obd = req->rq_import->imp_obd;
+
                null_encode_sec_part(req->rq_reqbuf,
                                     obd->u.cli.cl_sp_me);
        }
index a243db60f69776ddc4b9c197d67e39d6a77b9a65..f448b4567af0e9af16f61d1523fc893e39fd2608 100644 (file)
 
 #define DEBUG_SUBSYSTEM S_SEC
 
-
 #include "../include/obd_support.h"
 #include "../include/obd_cksum.h"
 #include "../include/obd_class.h"
 #include "../include/lustre_net.h"
 #include "../include/lustre_sec.h"
+#include "ptlrpc_internal.h"
 
 struct plain_sec {
        struct ptlrpc_sec       pls_base;
index 003344ccfffcde1d88a43556fa404be11072be36..f45898f17793bebfabb28d6d208abf7710c90079 100644 (file)
@@ -58,7 +58,6 @@ MODULE_PARM_DESC(at_early_margin, "How soon before an RPC deadline to send an ea
 module_param(at_extra, int, 0644);
 MODULE_PARM_DESC(at_extra, "How much extra time to give with each early reply");
 
-
 /* forward ref */
 static int ptlrpc_server_post_idle_rqbds(struct ptlrpc_service_part *svcpt);
 static void ptlrpc_server_hpreq_fini(struct ptlrpc_request *req);
@@ -86,8 +85,10 @@ ptlrpc_alloc_rqbd(struct ptlrpc_service_part *svcpt)
        rqbd->rqbd_cbid.cbid_fn = request_in_callback;
        rqbd->rqbd_cbid.cbid_arg = rqbd;
        INIT_LIST_HEAD(&rqbd->rqbd_reqs);
-       OBD_CPT_ALLOC_LARGE(rqbd->rqbd_buffer, svc->srv_cptable,
-                           svcpt->scp_cpt, svc->srv_buf_size);
+       rqbd->rqbd_buffer = libcfs_kvzalloc_cpt(svc->srv_cptable,
+                                               svcpt->scp_cpt,
+                                               svc->srv_buf_size,
+                                               GFP_KERNEL);
        if (rqbd->rqbd_buffer == NULL) {
                kfree(rqbd);
                return NULL;
@@ -141,7 +142,6 @@ ptlrpc_grow_req_bufs(struct ptlrpc_service_part *svcpt, int post)
        svcpt->scp_rqbd_allocating++;
        spin_unlock(&svcpt->scp_lock);
 
-
        for (i = 0; i < svc->srv_nbuf_per_group; i++) {
                /* NB: another thread might have recycled enough rqbds, we
                 * need to make sure it wouldn't over-allocate, see LU-1212. */
@@ -177,33 +177,6 @@ ptlrpc_grow_req_bufs(struct ptlrpc_service_part *svcpt, int post)
        return rc;
 }
 
-/**
- * Part of Rep-Ack logic.
- * Puts a lock and its mode into reply state associated to request reply.
- */
-void
-ptlrpc_save_lock(struct ptlrpc_request *req,
-                struct lustre_handle *lock, int mode, int no_ack)
-{
-       struct ptlrpc_reply_state *rs = req->rq_reply_state;
-       int idx;
-
-       LASSERT(rs != NULL);
-       LASSERT(rs->rs_nlocks < RS_MAX_LOCKS);
-
-       if (req->rq_export->exp_disconnected) {
-               ldlm_lock_decref(lock, mode);
-       } else {
-               idx = rs->rs_nlocks++;
-               rs->rs_locks[idx] = *lock;
-               rs->rs_modes[idx] = mode;
-               rs->rs_difficult = 1;
-               rs->rs_no_ack = !!no_ack;
-       }
-}
-EXPORT_SYMBOL(ptlrpc_save_lock);
-
-
 struct ptlrpc_hr_partition;
 
 struct ptlrpc_hr_thread {
@@ -244,31 +217,9 @@ struct ptlrpc_hr_service {
        struct ptlrpc_hr_partition      **hr_partitions;
 };
 
-struct rs_batch {
-       struct list_head                        rsb_replies;
-       unsigned int                    rsb_n_replies;
-       struct ptlrpc_service_part      *rsb_svcpt;
-};
-
 /** reply handling service. */
 static struct ptlrpc_hr_service                ptlrpc_hr;
 
-/**
- * maximum number of replies scheduled in one batch
- */
-#define MAX_SCHEDULED 256
-
-/**
- * Initialize a reply batch.
- *
- * \param b batch
- */
-static void rs_batch_init(struct rs_batch *b)
-{
-       memset(b, 0, sizeof(*b));
-       INIT_LIST_HEAD(&b->rsb_replies);
-}
-
 /**
  * Choose an hr thread to dispatch requests to.
  */
@@ -294,76 +245,6 @@ ptlrpc_hr_select(struct ptlrpc_service_part *svcpt)
        return &hrp->hrp_thrs[rotor % hrp->hrp_nthrs];
 }
 
-/**
- * Dispatch all replies accumulated in the batch to one from
- * dedicated reply handling threads.
- *
- * \param b batch
- */
-static void rs_batch_dispatch(struct rs_batch *b)
-{
-       if (b->rsb_n_replies != 0) {
-               struct ptlrpc_hr_thread *hrt;
-
-               hrt = ptlrpc_hr_select(b->rsb_svcpt);
-
-               spin_lock(&hrt->hrt_lock);
-               list_splice_init(&b->rsb_replies, &hrt->hrt_queue);
-               spin_unlock(&hrt->hrt_lock);
-
-               wake_up(&hrt->hrt_waitq);
-               b->rsb_n_replies = 0;
-       }
-}
-
-/**
- * Add a reply to a batch.
- * Add one reply object to a batch, schedule batched replies if overload.
- *
- * \param b batch
- * \param rs reply
- */
-static void rs_batch_add(struct rs_batch *b, struct ptlrpc_reply_state *rs)
-{
-       struct ptlrpc_service_part *svcpt = rs->rs_svcpt;
-
-       if (svcpt != b->rsb_svcpt || b->rsb_n_replies >= MAX_SCHEDULED) {
-               if (b->rsb_svcpt != NULL) {
-                       rs_batch_dispatch(b);
-                       spin_unlock(&b->rsb_svcpt->scp_rep_lock);
-               }
-               spin_lock(&svcpt->scp_rep_lock);
-               b->rsb_svcpt = svcpt;
-       }
-       spin_lock(&rs->rs_lock);
-       rs->rs_scheduled_ever = 1;
-       if (rs->rs_scheduled == 0) {
-               list_move(&rs->rs_list, &b->rsb_replies);
-               rs->rs_scheduled = 1;
-               b->rsb_n_replies++;
-       }
-       rs->rs_committed = 1;
-       spin_unlock(&rs->rs_lock);
-}
-
-/**
- * Reply batch finalization.
- * Dispatch remaining replies from the batch
- * and release remaining spinlock.
- *
- * \param b batch
- */
-static void rs_batch_fini(struct rs_batch *b)
-{
-       if (b->rsb_svcpt != NULL) {
-               rs_batch_dispatch(b);
-               spin_unlock(&b->rsb_svcpt->scp_rep_lock);
-       }
-}
-
-#define DECLARE_RS_BATCH(b)     struct rs_batch b
-
-
 /**
  * Put reply state into a queue for processing because we received
  * ACK from the client
@@ -401,32 +282,6 @@ ptlrpc_schedule_difficult_reply(struct ptlrpc_reply_state *rs)
 }
 EXPORT_SYMBOL(ptlrpc_schedule_difficult_reply);
 
-void ptlrpc_commit_replies(struct obd_export *exp)
-{
-       struct ptlrpc_reply_state *rs, *nxt;
-       DECLARE_RS_BATCH(batch);
-
-       rs_batch_init(&batch);
-       /* Find any replies that have been committed and get their service
-        * to attend to complete them. */
-
-       /* CAVEAT EMPTOR: spinlock ordering!!! */
-       spin_lock(&exp->exp_uncommitted_replies_lock);
-       list_for_each_entry_safe(rs, nxt, &exp->exp_uncommitted_replies,
-                                    rs_obd_list) {
-               LASSERT(rs->rs_difficult);
-               /* VBR: per-export last_committed */
-               LASSERT(rs->rs_export);
-               if (rs->rs_transno <= exp->exp_last_committed) {
-                       list_del_init(&rs->rs_obd_list);
-                       rs_batch_add(&batch, rs);
-               }
-       }
-       spin_unlock(&exp->exp_uncommitted_replies_lock);
-       rs_batch_fini(&batch);
-}
-EXPORT_SYMBOL(ptlrpc_commit_replies);
-
 static int
 ptlrpc_server_post_idle_rqbds(struct ptlrpc_service_part *svcpt)
 {
@@ -647,7 +502,9 @@ ptlrpc_service_part_init(struct ptlrpc_service *svc,
        if (array->paa_reqs_count == NULL)
                goto free_reqs_array;
 
-       cfs_timer_init(&svcpt->scp_at_timer, ptlrpc_at_timer, svcpt);
+       setup_timer(&svcpt->scp_at_timer, ptlrpc_at_timer,
+                   (unsigned long)svcpt);
+
        /* At SOW, service time should be quick; 10s seems generous. If client
         * timeout is less than this, we'll be sending an early reply. */
        at_init(&svcpt->scp_at_estimate, 10, 0);
@@ -856,7 +713,7 @@ static void ptlrpc_server_free_request(struct ptlrpc_request *req)
  * drop a reference count of the request. if it reaches 0, we either
  * put it into history list, or free it immediately.
  */
-void ptlrpc_server_drop_request(struct ptlrpc_request *req)
+static void ptlrpc_server_drop_request(struct ptlrpc_request *req)
 {
        struct ptlrpc_request_buffer_desc *rqbd = req->rq_rqbd;
        struct ptlrpc_service_part *svcpt = rqbd->rqbd_svcpt;
@@ -960,35 +817,6 @@ void ptlrpc_server_drop_request(struct ptlrpc_request *req)
        }
 }
 
-/** Change request export and move hp request from old export to new */
-void ptlrpc_request_change_export(struct ptlrpc_request *req,
-                                 struct obd_export *export)
-{
-       if (req->rq_export != NULL) {
-               if (!list_empty(&req->rq_exp_list)) {
-                       /* remove rq_exp_list from last export */
-                       spin_lock_bh(&req->rq_export->exp_rpc_lock);
-                       list_del_init(&req->rq_exp_list);
-                       spin_unlock_bh(&req->rq_export->exp_rpc_lock);
-
-                       /* export has one reference already, so it`s safe to
-                        * add req to export queue here and get another
-                        * reference for request later */
-                       spin_lock_bh(&export->exp_rpc_lock);
-                       list_add(&req->rq_exp_list, &export->exp_hp_rpcs);
-                       spin_unlock_bh(&export->exp_rpc_lock);
-               }
-               class_export_rpc_dec(req->rq_export);
-               class_export_put(req->rq_export);
-       }
-
-       /* request takes one export refcount */
-       req->rq_export = class_export_get(export);
-       class_export_rpc_inc(export);
-
-       return;
-}
-
 /**
  * to finish a request: stop sending more early replies, and release
  * the request.
@@ -1024,82 +852,6 @@ static void ptlrpc_server_finish_active_request(
        ptlrpc_server_finish_request(svcpt, req);
 }
 
-/**
- * This function makes sure dead exports are evicted in a timely manner.
- * This function is only called when some export receives a message (i.e.,
- * the network is up.)
- */
-static void ptlrpc_update_export_timer(struct obd_export *exp, long extra_delay)
-{
-       struct obd_export *oldest_exp;
-       time_t oldest_time, new_time;
-
-       LASSERT(exp);
-
-       /* Compensate for slow machines, etc, by faking our request time
-          into the future.  Although this can break the strict time-ordering
-          of the list, we can be really lazy here - we don't have to evict
-          at the exact right moment.  Eventually, all silent exports
-          will make it to the top of the list. */
-
-       /* Do not pay attention on 1sec or smaller renewals. */
-       new_time = get_seconds() + extra_delay;
-       if (exp->exp_last_request_time + 1 /*second */ >= new_time)
-               return;
-
-       exp->exp_last_request_time = new_time;
-
-       /* exports may get disconnected from the chain even though the
-          export has references, so we must keep the spin lock while
-          manipulating the lists */
-       spin_lock(&exp->exp_obd->obd_dev_lock);
-
-       if (list_empty(&exp->exp_obd_chain_timed)) {
-               /* this one is not timed */
-               spin_unlock(&exp->exp_obd->obd_dev_lock);
-               return;
-       }
-
-       list_move_tail(&exp->exp_obd_chain_timed,
-                          &exp->exp_obd->obd_exports_timed);
-
-       oldest_exp = list_entry(exp->exp_obd->obd_exports_timed.next,
-                                   struct obd_export, exp_obd_chain_timed);
-       oldest_time = oldest_exp->exp_last_request_time;
-       spin_unlock(&exp->exp_obd->obd_dev_lock);
-
-       if (exp->exp_obd->obd_recovering) {
-               /* be nice to everyone during recovery */
-               return;
-       }
-
-       /* Note - racing to start/reset the obd_eviction timer is safe */
-       if (exp->exp_obd->obd_eviction_timer == 0) {
-               /* Check if the oldest entry is expired. */
-               if (get_seconds() > (oldest_time + PING_EVICT_TIMEOUT +
-                                             extra_delay)) {
-                       /* We need a second timer, in case the net was down and
-                        * it just came back. Since the pinger may skip every
-                        * other PING_INTERVAL (see note in ptlrpc_pinger_main),
-                        * we better wait for 3. */
-                       exp->exp_obd->obd_eviction_timer =
-                               get_seconds() + 3 * PING_INTERVAL;
-                       CDEBUG(D_HA, "%s: Think about evicting %s from "CFS_TIME_T"\n",
-                              exp->exp_obd->obd_name,
-                              obd_export_nid2str(oldest_exp), oldest_time);
-               }
-       } else {
-               if (get_seconds() >
-                   (exp->exp_obd->obd_eviction_timer + extra_delay)) {
-                       /* The evictor won't evict anyone who we've heard from
-                        * recently, so we don't have to check before we start
-                        * it. */
-                       if (!ping_evictor_wake(exp))
-                               exp->exp_obd->obd_eviction_timer = 0;
-               }
-       }
-}
-
 /**
  * Sanity check request \a req.
  * Return 0 if all is ok, error code otherwise.
@@ -1126,18 +878,16 @@ static int ptlrpc_check_req(struct ptlrpc_request *req)
                       req, (obd != NULL) ? obd->obd_name : "unknown");
                rc = -ENODEV;
        } else if (lustre_msg_get_flags(req->rq_reqmsg) &
-                  (MSG_REPLAY | MSG_REQ_REPLAY_DONE) &&
-                  !obd->obd_recovering) {
-                       DEBUG_REQ(D_ERROR, req,
-                                 "Invalid replay without recovery");
-                       class_fail_export(req->rq_export);
-                       rc = -ENODEV;
-       } else if (lustre_msg_get_transno(req->rq_reqmsg) != 0 &&
-                  !obd->obd_recovering) {
-                       DEBUG_REQ(D_ERROR, req, "Invalid req with transno %llu without recovery",
-                                 lustre_msg_get_transno(req->rq_reqmsg));
-                       class_fail_export(req->rq_export);
-                       rc = -ENODEV;
+                  (MSG_REPLAY | MSG_REQ_REPLAY_DONE)) {
+               DEBUG_REQ(D_ERROR, req, "Invalid replay without recovery");
+               class_fail_export(req->rq_export);
+               rc = -ENODEV;
+       } else if (lustre_msg_get_transno(req->rq_reqmsg) != 0) {
+               DEBUG_REQ(D_ERROR, req,
+                         "Invalid req with transno %llu without recovery",
+                         lustre_msg_get_transno(req->rq_reqmsg));
+               class_fail_export(req->rq_export);
+               rc = -ENODEV;
        }
 
        if (unlikely(rc < 0)) {
@@ -1153,17 +903,17 @@ static void ptlrpc_at_set_timer(struct ptlrpc_service_part *svcpt)
        __s32 next;
 
        if (array->paa_count == 0) {
-               cfs_timer_disarm(&svcpt->scp_at_timer);
+               del_timer(&svcpt->scp_at_timer);
                return;
        }
 
        /* Set timer for closest deadline */
-       next = (__s32)(array->paa_deadline - get_seconds() -
+       next = (__s32)(array->paa_deadline - ktime_get_real_seconds() -
                       at_early_margin);
        if (next <= 0) {
                ptlrpc_at_timer((unsigned long)svcpt);
        } else {
-               cfs_timer_arm(&svcpt->scp_at_timer, cfs_time_shift(next));
+               mod_timer(&svcpt->scp_at_timer, cfs_time_shift(next));
                CDEBUG(D_INFO, "armed %s at %+ds\n",
                       svcpt->scp_service->srv_name, next);
        }
@@ -1189,7 +939,7 @@ static int ptlrpc_at_add_timed(struct ptlrpc_request *req)
        spin_lock(&svcpt->scp_at_lock);
        LASSERT(list_empty(&req->rq_timed_list));
 
-       index = (unsigned long)req->rq_deadline % array->paa_size;
+       div_u64_rem(req->rq_deadline, array->paa_size, &index);
        if (array->paa_reqs_count[index] > 0) {
                /* latest rpcs will have the latest deadlines in the list,
                 * so search backward. */
@@ -1248,8 +998,8 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
        struct ptlrpc_service_part *svcpt = req->rq_rqbd->rqbd_svcpt;
        struct ptlrpc_request *reqcopy;
        struct lustre_msg *reqmsg;
-       long olddl = req->rq_deadline - get_seconds();
-       time_t newdl;
+       long olddl = req->rq_deadline - ktime_get_real_seconds();
+       time64_t newdl;
        int rc;
 
        /* deadline is when the client expects us to reply, margin is the
@@ -1276,36 +1026,22 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
                return -ENOSYS;
        }
 
-       if (req->rq_export &&
-           lustre_msg_get_flags(req->rq_reqmsg) &
-           (MSG_REPLAY | MSG_REQ_REPLAY_DONE | MSG_LOCK_REPLAY_DONE)) {
-               /* During recovery, we don't want to send too many early
-                * replies, but on the other hand we want to make sure the
-                * client has enough time to resend if the rpc is lost. So
-                * during the recovery period send at least 4 early replies,
-                * spacing them every at_extra if we can. at_estimate should
-                * always equal this fixed value during recovery. */
-               at_measured(&svcpt->scp_at_estimate, min(at_extra,
-                           req->rq_export->exp_obd->obd_recovery_timeout / 4));
-       } else {
-               /* Fake our processing time into the future to ask the clients
-                * for some extra amount of time */
-               at_measured(&svcpt->scp_at_estimate, at_extra +
-                           get_seconds() -
-                           req->rq_arrival_time.tv_sec);
-
-               /* Check to see if we've actually increased the deadline -
-                * we may be past adaptive_max */
-               if (req->rq_deadline >= req->rq_arrival_time.tv_sec +
-                   at_get(&svcpt->scp_at_estimate)) {
-                       DEBUG_REQ(D_WARNING, req, "Couldn't add any time (%ld/%ld), not sending early reply\n",
-                                 olddl, req->rq_arrival_time.tv_sec +
-                                 at_get(&svcpt->scp_at_estimate) -
-                                 get_seconds());
-                       return -ETIMEDOUT;
-               }
+       /* Fake our processing time into the future to ask the clients
+        * for some extra amount of time */
+       at_measured(&svcpt->scp_at_estimate, at_extra +
+                   ktime_get_real_seconds() - req->rq_arrival_time.tv_sec);
+
+       /* Check to see if we've actually increased the deadline -
+        * we may be past adaptive_max */
+       if (req->rq_deadline >= req->rq_arrival_time.tv_sec +
+           at_get(&svcpt->scp_at_estimate)) {
+               DEBUG_REQ(D_WARNING, req, "Couldn't add any time (%ld/%lld), not sending early reply\n",
+                         olddl, req->rq_arrival_time.tv_sec +
+                         at_get(&svcpt->scp_at_estimate) -
+                         ktime_get_real_seconds());
+               return -ETIMEDOUT;
        }
-       newdl = get_seconds() + at_get(&svcpt->scp_at_estimate);
+       newdl = ktime_get_real_seconds() + at_get(&svcpt->scp_at_estimate);
 
        reqcopy = ptlrpc_request_cache_alloc(GFP_NOFS);
        if (reqcopy == NULL)
@@ -1388,8 +1124,8 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service_part *svcpt)
        struct ptlrpc_request *rq, *n;
        struct list_head work_list;
        __u32 index, count;
-       time_t deadline;
-       time_t now = get_seconds();
+       time64_t deadline;
+       time64_t now = ktime_get_real_seconds();
        long delay;
        int first, counter = 0;
 
@@ -1419,7 +1155,7 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service_part *svcpt)
           server will take. Send early replies to everyone expiring soon. */
        INIT_LIST_HEAD(&work_list);
        deadline = -1;
-       index = (unsigned long)array->paa_deadline % array->paa_size;
+       div_u64_rem(array->paa_deadline, array->paa_size, &index);
        count = array->paa_count;
        while (count > 0) {
                count -= array->paa_reqs_count[index];
@@ -1461,7 +1197,7 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service_part *svcpt)
                   chance to send early replies */
                LCONSOLE_WARN("%s: This server is not able to keep up with request traffic (cpu-bound).\n",
                              svcpt->scp_service->srv_name);
-               CWARN("earlyQ=%d reqQ=%d recA=%d, svcEst=%d, delay=" CFS_DURATION_T "(jiff)\n",
+               CWARN("earlyQ=%d reqQ=%d recA=%d, svcEst=%d, delay=%ld(jiff)\n",
                      counter, svcpt->scp_nreqs_incoming,
                      svcpt->scp_nreqs_active,
                      at_get(&svcpt->scp_at_estimate), delay);
@@ -1546,30 +1282,6 @@ static void ptlrpc_server_hpreq_fini(struct ptlrpc_request *req)
        }
 }
 
-static int ptlrpc_hpreq_check(struct ptlrpc_request *req)
-{
-       return 1;
-}
-
-static struct ptlrpc_hpreq_ops ptlrpc_hpreq_common = {
-       .hpreq_check       = ptlrpc_hpreq_check,
-};
-
-/* Hi-Priority RPC check by RPC operation code. */
-int ptlrpc_hpreq_handler(struct ptlrpc_request *req)
-{
-       int opc = lustre_msg_get_opc(req->rq_reqmsg);
-
-       /* Check for export to let only reconnects for not yet evicted
-        * export to become a HP rpc. */
-       if ((req->rq_export != NULL) &&
-           (opc == OBD_PING || opc == MDS_CONNECT || opc == OST_CONNECT))
-               req->rq_ops = &ptlrpc_hpreq_common;
-
-       return 0;
-}
-EXPORT_SYMBOL(ptlrpc_hpreq_handler);
-
 static int ptlrpc_server_request_add(struct ptlrpc_service_part *svcpt,
                                     struct ptlrpc_request *req)
 {
@@ -1638,6 +1350,7 @@ static bool ptlrpc_server_allow_normal(struct ptlrpc_service_part *svcpt,
                                       bool force)
 {
        int running = svcpt->scp_nthrs_running;
+
        if (unlikely(svcpt->scp_service->srv_req_portal == MDS_REQUEST_PORTAL &&
                     CFS_FAIL_PRECHECK(OBD_FAIL_PTLRPC_CANCEL_RESEND))) {
                /* leave just 1 thread for normal RPCs */
@@ -1828,14 +1541,13 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service_part *svcpt,
 
                if (rc)
                        goto err_req;
-               ptlrpc_update_export_timer(req->rq_export, 0);
        }
 
        /* req_in handling should/must be fast */
-       if (get_seconds() - req->rq_arrival_time.tv_sec > 5)
+       if (ktime_get_real_seconds() - req->rq_arrival_time.tv_sec > 5)
                DEBUG_REQ(D_WARNING, req, "Slow req_in handling "CFS_DURATION_T"s",
-                         cfs_time_sub(get_seconds(),
-                                      req->rq_arrival_time.tv_sec));
+                         (long)(ktime_get_real_seconds() -
+                                req->rq_arrival_time.tv_sec));
 
        /* Set rpc server deadline and add it to the timed list */
        deadline = (lustre_msghdr_get_flags(req->rq_reqmsg) &
@@ -1876,9 +1588,12 @@ ptlrpc_server_handle_request(struct ptlrpc_service_part *svcpt,
 {
        struct ptlrpc_service *svc = svcpt->scp_service;
        struct ptlrpc_request *request;
-       struct timeval work_start;
-       struct timeval work_end;
-       long timediff;
+       struct timespec64 work_start;
+       struct timespec64 work_end;
+       struct timespec64 timediff;
+       struct timespec64 arrived;
+       unsigned long timediff_usecs;
+       unsigned long arrived_usecs;
        int rc;
        int fail_opc = 0;
 
@@ -1901,12 +1616,13 @@ ptlrpc_server_handle_request(struct ptlrpc_service_part *svcpt,
        if (OBD_FAIL_CHECK(OBD_FAIL_PTLRPC_DUMP_LOG))
                libcfs_debug_dumplog();
 
-       do_gettimeofday(&work_start);
-       timediff = cfs_timeval_sub(&work_start, &request->rq_arrival_time,
-                                  NULL);
+       ktime_get_real_ts64(&work_start);
+       timediff = timespec64_sub(work_start, request->rq_arrival_time);
+       timediff_usecs = timediff.tv_sec * USEC_PER_SEC +
+                        timediff.tv_nsec / NSEC_PER_USEC;
        if (likely(svc->srv_stats != NULL)) {
                lprocfs_counter_add(svc->srv_stats, PTLRPC_REQWAIT_CNTR,
-                                   timediff);
+                                   timediff_usecs);
                lprocfs_counter_add(svc->srv_stats, PTLRPC_REQQDEPTH_CNTR,
                                    svcpt->scp_nreqs_incoming);
                lprocfs_counter_add(svc->srv_stats, PTLRPC_REQACTIVE_CNTR,
@@ -1933,18 +1649,17 @@ ptlrpc_server_handle_request(struct ptlrpc_service_part *svcpt,
        if (likely(request->rq_export)) {
                if (unlikely(ptlrpc_check_req(request)))
                        goto put_conn;
-               ptlrpc_update_export_timer(request->rq_export, timediff >> 19);
        }
 
        /* Discard requests queued for longer than the deadline.
           The deadline is increased if we send an early reply. */
-       if (get_seconds() > request->rq_deadline) {
+       if (ktime_get_real_seconds() > request->rq_deadline) {
                DEBUG_REQ(D_ERROR, request, "Dropping timed-out request from %s: deadline " CFS_DURATION_T ":" CFS_DURATION_T "s ago\n",
                          libcfs_id2str(request->rq_peer),
-                         cfs_time_sub(request->rq_deadline,
-                                      request->rq_arrival_time.tv_sec),
-                         cfs_time_sub(get_seconds(),
-                                      request->rq_deadline));
+                         (long)(request->rq_deadline -
+                                request->rq_arrival_time.tv_sec),
+                         (long)(ktime_get_real_seconds() -
+                                request->rq_deadline));
                goto put_conn;
        }
 
@@ -1969,19 +1684,22 @@ put_conn:
        lu_context_exit(&request->rq_session);
        lu_context_fini(&request->rq_session);
 
-       if (unlikely(get_seconds() > request->rq_deadline)) {
+       if (unlikely(ktime_get_real_seconds() > request->rq_deadline)) {
                DEBUG_REQ(D_WARNING, request,
-                         "Request took longer than estimated ("
-                               CFS_DURATION_T":"CFS_DURATION_T
-                               "s); client may timeout.",
-                         cfs_time_sub(request->rq_deadline,
-                                      request->rq_arrival_time.tv_sec),
-                         cfs_time_sub(get_seconds(),
-                                      request->rq_deadline));
-       }
-
-       do_gettimeofday(&work_end);
-       timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
+                         "Request took longer than estimated (%lld:%llds); "
+                         "client may timeout.",
+                         (s64)request->rq_deadline -
+                              request->rq_arrival_time.tv_sec,
+                         (s64)ktime_get_real_seconds() - request->rq_deadline);
+       }
+
+       ktime_get_real_ts64(&work_end);
+       timediff = timespec64_sub(work_end, work_start);
+       timediff_usecs = timediff.tv_sec * USEC_PER_SEC +
+                        timediff.tv_nsec / NSEC_PER_USEC;
+       arrived = timespec64_sub(work_end, request->rq_arrival_time);
+       arrived_usecs = arrived.tv_sec * USEC_PER_SEC +
+                        arrived.tv_nsec / NSEC_PER_USEC;
        CDEBUG(D_RPCTRACE, "Handled RPC pname:cluuid+ref:pid:xid:nid:opc %s:%s+%d:%d:x%llu:%s:%d Request processed in %ldus (%ldus total) trans %llu rc %d/%d\n",
               current_comm(),
               (request->rq_export ?
@@ -1992,8 +1710,8 @@ put_conn:
               request->rq_xid,
               libcfs_id2str(request->rq_peer),
               lustre_msg_get_opc(request->rq_reqmsg),
-              timediff,
-              cfs_timeval_sub(&work_end, &request->rq_arrival_time, NULL),
+              timediff_usecs,
+              arrived_usecs,
               (request->rq_repmsg ?
                lustre_msg_get_transno(request->rq_repmsg) :
                request->rq_transno),
@@ -2003,20 +1721,20 @@ put_conn:
        if (likely(svc->srv_stats != NULL && request->rq_reqmsg != NULL)) {
                __u32 op = lustre_msg_get_opc(request->rq_reqmsg);
                int opc = opcode_offset(op);
+
                if (opc > 0 && !(op == LDLM_ENQUEUE || op == MDS_REINT)) {
                        LASSERT(opc < LUSTRE_MAX_OPCODES);
                        lprocfs_counter_add(svc->srv_stats,
                                            opc + EXTRA_MAX_OPCODES,
-                                           timediff);
+                                           timediff_usecs);
                }
        }
        if (unlikely(request->rq_early_count)) {
                DEBUG_REQ(D_ADAPTTO, request,
-                         "sent %d early replies before finishing in "
-                         CFS_DURATION_T"s",
+                         "sent %d early replies before finishing in %llds",
                          request->rq_early_count,
-                         cfs_time_sub(work_end.tv_sec,
-                         request->rq_arrival_time.tv_sec));
+                         (s64)work_end.tv_sec -
+                         request->rq_arrival_time.tv_sec);
        }
 
 out_req:
@@ -2128,7 +1846,6 @@ ptlrpc_handle_rs(struct ptlrpc_reply_state *rs)
        return 1;
 }
 
-
 static void
 ptlrpc_check_rqbd_pool(struct ptlrpc_service_part *svcpt)
 {
@@ -2155,7 +1872,7 @@ ptlrpc_check_rqbd_pool(struct ptlrpc_service_part *svcpt)
 static int
 ptlrpc_retry_rqbds(void *arg)
 {
-       struct ptlrpc_service_part *svcpt = (struct ptlrpc_service_part *)arg;
+       struct ptlrpc_service_part *svcpt = arg;
 
        svcpt->scp_rqbd_timeout = 0;
        return -ETIMEDOUT;
@@ -2262,7 +1979,7 @@ ptlrpc_wait_event(struct ptlrpc_service_part *svcpt,
  */
 static int ptlrpc_main(void *arg)
 {
-       struct ptlrpc_thread *thread = (struct ptlrpc_thread *)arg;
+       struct ptlrpc_thread *thread = arg;
        struct ptlrpc_service_part *svcpt = thread->t_svcpt;
        struct ptlrpc_service *svc = svcpt->scp_service;
        struct ptlrpc_reply_state *rs;
@@ -2464,7 +2181,7 @@ static int hrt_dont_sleep(struct ptlrpc_hr_thread *hrt,
  */
 static int ptlrpc_hr_main(void *arg)
 {
-       struct ptlrpc_hr_thread *hrt = (struct ptlrpc_hr_thread *)arg;
+       struct ptlrpc_hr_thread *hrt = arg;
        struct ptlrpc_hr_partition *hrp = hrt->hrt_partition;
        LIST_HEAD       (replies);
        char threadname[20];
@@ -2538,6 +2255,7 @@ static int ptlrpc_start_hr_threads(void)
 
                for (j = 0; j < hrp->hrp_nthrs; j++) {
                        struct  ptlrpc_hr_thread *hrt = &hrp->hrp_thrs[j];
+
                        rc = PTR_ERR(kthread_run(ptlrpc_hr_main,
                                                 &hrp->hrp_thrs[j],
                                                 "ptlrpc_hr%02d_%03d",
@@ -2609,7 +2327,7 @@ static void ptlrpc_svcpt_stop_threads(struct ptlrpc_service_part *svcpt)
 /**
  * Stops all threads of a particular service \a svc
  */
-void ptlrpc_stop_all_threads(struct ptlrpc_service *svc)
+static void ptlrpc_stop_all_threads(struct ptlrpc_service *svc)
 {
        struct ptlrpc_service_part *svcpt;
        int i;
@@ -2619,7 +2337,6 @@ void ptlrpc_stop_all_threads(struct ptlrpc_service *svc)
                        ptlrpc_svcpt_stop_threads(svcpt);
        }
 }
-EXPORT_SYMBOL(ptlrpc_stop_all_threads);
 
 int ptlrpc_start_threads(struct ptlrpc_service *svc)
 {
@@ -2833,7 +2550,6 @@ void ptlrpc_hr_fini(void)
        ptlrpc_hr.hr_partitions = NULL;
 }
 
-
 /**
  * Wait until all already scheduled replies are processed.
  */
@@ -2862,7 +2578,7 @@ ptlrpc_service_del_atimer(struct ptlrpc_service *svc)
        /* early disarm AT timer... */
        ptlrpc_service_for_each_part(svcpt, i, svc) {
                if (svcpt->scp_service != NULL)
-                       cfs_timer_disarm(&svcpt->scp_at_timer);
+                       del_timer(&svcpt->scp_at_timer);
        }
 }
 
@@ -3002,7 +2718,7 @@ ptlrpc_service_free(struct ptlrpc_service *svc)
                        break;
 
                /* In case somebody rearmed this in the meantime */
-               cfs_timer_disarm(&svcpt->scp_at_timer);
+               del_timer(&svcpt->scp_at_timer);
                array = &svcpt->scp_at_array;
 
                kfree(array->paa_reqs_array);
@@ -3045,61 +2761,3 @@ int ptlrpc_unregister_service(struct ptlrpc_service *service)
        return 0;
 }
 EXPORT_SYMBOL(ptlrpc_unregister_service);
-
-/**
- * Returns 0 if the service is healthy.
- *
- * Right now, it just checks to make sure that requests aren't languishing
- * in the queue.  We'll use this health check to govern whether a node needs
- * to be shot, so it's intentionally non-aggressive. */
-static int ptlrpc_svcpt_health_check(struct ptlrpc_service_part *svcpt)
-{
-       struct ptlrpc_request *request = NULL;
-       struct timeval right_now;
-       long timediff;
-
-       do_gettimeofday(&right_now);
-
-       spin_lock(&svcpt->scp_req_lock);
-       /* How long has the next entry been waiting? */
-       if (ptlrpc_server_high_pending(svcpt, true))
-               request = ptlrpc_nrs_req_peek_nolock(svcpt, true);
-       else if (ptlrpc_server_normal_pending(svcpt, true))
-               request = ptlrpc_nrs_req_peek_nolock(svcpt, false);
-
-       if (request == NULL) {
-               spin_unlock(&svcpt->scp_req_lock);
-               return 0;
-       }
-
-       timediff = cfs_timeval_sub(&right_now, &request->rq_arrival_time, NULL);
-       spin_unlock(&svcpt->scp_req_lock);
-
-       if ((timediff / ONE_MILLION) >
-           (AT_OFF ? obd_timeout * 3 / 2 : at_max)) {
-               CERROR("%s: unhealthy - request has been waiting %lds\n",
-                      svcpt->scp_service->srv_name, timediff / ONE_MILLION);
-               return -1;
-       }
-
-       return 0;
-}
-
-int
-ptlrpc_service_health_check(struct ptlrpc_service *svc)
-{
-       struct ptlrpc_service_part *svcpt;
-       int i;
-
-       if (svc == NULL)
-               return 0;
-
-       ptlrpc_service_for_each_part(svcpt, i, svc) {
-               int rc = ptlrpc_svcpt_health_check(svcpt);
-
-               if (rc != 0)
-                       return rc;
-       }
-       return 0;
-}
-EXPORT_SYMBOL(ptlrpc_service_health_check);
index d6d92046c34899f864afa419cba2442b69d079f4..40f720ca3b140249e69136bbd15e2529e6dd7c64 100644 (file)
@@ -43,6 +43,8 @@
 #include "../include/obd_class.h"
 #include "../include/lustre_net.h"
 #include "../include/lustre_disk.h"
+#include "ptlrpc_internal.h"
+
 void lustre_assert_wire_constants(void)
 {
         /* Wire protocol assertions generated by 'wirecheck'
@@ -636,12 +638,8 @@ void lustre_assert_wire_constants(void)
                 (long long)(int)offsetof(struct lustre_msg_v2, lm_buflens[0]));
        LASSERTF((int)sizeof(((struct lustre_msg_v2 *)0)->lm_buflens[0]) == 4, "found %lld\n",
                 (long long)(int)sizeof(((struct lustre_msg_v2 *)0)->lm_buflens[0]));
-       LASSERTF(LUSTRE_MSG_MAGIC_V1 == 0x0BD00BD0, "found 0x%.8x\n",
-               LUSTRE_MSG_MAGIC_V1);
        LASSERTF(LUSTRE_MSG_MAGIC_V2 == 0x0BD00BD3, "found 0x%.8x\n",
                LUSTRE_MSG_MAGIC_V2);
-       LASSERTF(LUSTRE_MSG_MAGIC_V1_SWABBED == 0xD00BD00B, "found 0x%.8x\n",
-               LUSTRE_MSG_MAGIC_V1_SWABBED);
        LASSERTF(LUSTRE_MSG_MAGIC_V2_SWABBED == 0xD30BD00B, "found 0x%.8x\n",
                LUSTRE_MSG_MAGIC_V2_SWABBED);
 
index 1bbb90ce00867793dc49e8622f4e4c17c94da29d..b1dfa2ccc4ef3ad61a68139ceaa1e1e4db826027 100644 (file)
@@ -79,7 +79,7 @@ static int ipipe_set_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
        }
 
        dev = ipipe->subdev.v4l2_dev->dev;
-       dpc_param = (struct vpfe_ipipe_lutdpc *)param;
+       dpc_param = param;
        lutdpc->en = dpc_param->en;
        lutdpc->repl_white = dpc_param->repl_white;
        lutdpc->dpc_size = dpc_param->dpc_size;
@@ -96,7 +96,7 @@ success:
 
 static int ipipe_get_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_lutdpc *lut_param = (struct vpfe_ipipe_lutdpc *)param;
+       struct vpfe_ipipe_lutdpc *lut_param = param;
        struct vpfe_ipipe_lutdpc *lutdpc = &ipipe->config.lutdpc;
 
        lut_param->en = lutdpc->en;
@@ -171,7 +171,7 @@ static int ipipe_validate_otfdpc_params(struct vpfe_ipipe_otfdpc *dpc_param)
 
 static int ipipe_set_otfdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_otfdpc *dpc_param = (struct vpfe_ipipe_otfdpc *)param;
+       struct vpfe_ipipe_otfdpc *dpc_param = param;
        struct vpfe_ipipe_otfdpc *otfdpc = &ipipe->config.otfdpc;
        struct device *dev;
 
@@ -194,7 +194,7 @@ success:
 
 static int ipipe_get_otfdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_otfdpc *dpc_param = (struct vpfe_ipipe_otfdpc *)param;
+       struct vpfe_ipipe_otfdpc *dpc_param = param;
        struct vpfe_ipipe_otfdpc *otfdpc = &ipipe->config.otfdpc;
 
        memcpy(dpc_param, otfdpc, sizeof(struct vpfe_ipipe_otfdpc));
@@ -226,7 +226,7 @@ static int ipipe_validate_nf_params(struct vpfe_ipipe_nf *nf_param)
 static int ipipe_set_nf_params(struct vpfe_ipipe_device *ipipe,
                               unsigned int id, void *param)
 {
-       struct vpfe_ipipe_nf *nf_param = (struct vpfe_ipipe_nf *)param;
+       struct vpfe_ipipe_nf *nf_param = param;
        struct vpfe_ipipe_nf *nf = &ipipe->config.nf1;
        struct device *dev;
 
@@ -264,7 +264,7 @@ static int ipipe_set_nf2_params(struct vpfe_ipipe_device *ipipe, void *param)
 static int ipipe_get_nf_params(struct vpfe_ipipe_device *ipipe,
                               unsigned int id, void *param)
 {
-       struct vpfe_ipipe_nf *nf_param = (struct vpfe_ipipe_nf *)param;
+       struct vpfe_ipipe_nf *nf_param = param;
        struct vpfe_ipipe_nf *nf = &ipipe->config.nf1;
 
        if (id == IPIPE_D2F_2ND)
@@ -299,7 +299,7 @@ static int ipipe_validate_gic_params(struct vpfe_ipipe_gic *gic)
 
 static int ipipe_set_gic_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_gic *gic_param = (struct vpfe_ipipe_gic *)param;
+       struct vpfe_ipipe_gic *gic_param = param;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        struct vpfe_ipipe_gic *gic = &ipipe->config.gic;
 
@@ -322,7 +322,7 @@ success:
 
 static int ipipe_get_gic_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_gic *gic_param = (struct vpfe_ipipe_gic *)param;
+       struct vpfe_ipipe_gic *gic_param = param;
        struct vpfe_ipipe_gic *gic = &ipipe->config.gic;
 
        memcpy(gic_param, gic, sizeof(struct vpfe_ipipe_gic));
@@ -351,7 +351,7 @@ static int ipipe_validate_wb_params(struct vpfe_ipipe_wb *wbal)
 
 static int ipipe_set_wb_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_wb *wb_param = (struct vpfe_ipipe_wb *)param;
+       struct vpfe_ipipe_wb *wb_param = param;
        struct vpfe_ipipe_wb *wbal = &ipipe->config.wbal;
 
        if (!wb_param) {
@@ -377,7 +377,7 @@ success:
 
 static int ipipe_get_wb_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_wb *wb_param = (struct vpfe_ipipe_wb *)param;
+       struct vpfe_ipipe_wb *wb_param = param;
        struct vpfe_ipipe_wb *wbal = &ipipe->config.wbal;
 
        memcpy(wb_param, wbal, sizeof(struct vpfe_ipipe_wb));
@@ -407,7 +407,7 @@ static int ipipe_validate_cfa_params(struct vpfe_ipipe_cfa *cfa)
 
 static int ipipe_set_cfa_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_cfa *cfa_param = (struct vpfe_ipipe_cfa *)param;
+       struct vpfe_ipipe_cfa *cfa_param = param;
        struct vpfe_ipipe_cfa *cfa = &ipipe->config.cfa;
 
        if (!cfa_param) {
@@ -428,7 +428,7 @@ success:
 
 static int ipipe_get_cfa_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_cfa *cfa_param = (struct vpfe_ipipe_cfa *)param;
+       struct vpfe_ipipe_cfa *cfa_param = param;
        struct vpfe_ipipe_cfa *cfa = &ipipe->config.cfa;
 
        memcpy(cfa_param, cfa, sizeof(struct vpfe_ipipe_cfa));
@@ -498,7 +498,7 @@ static int ipipe_set_rgb2rgb_params(struct vpfe_ipipe_device *ipipe,
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        struct vpfe_ipipe_rgb2rgb *rgb2rgb_param;
 
-       rgb2rgb_param = (struct vpfe_ipipe_rgb2rgb *)param;
+       rgb2rgb_param = param;
 
        if (id == IPIPE_RGB2RGB_2)
                rgb2rgb = &ipipe->config.rgb2rgb2;
@@ -551,7 +551,7 @@ static int ipipe_get_rgb2rgb_params(struct vpfe_ipipe_device *ipipe,
        struct vpfe_ipipe_rgb2rgb *rgb2rgb = &ipipe->config.rgb2rgb1;
        struct vpfe_ipipe_rgb2rgb *rgb2rgb_param;
 
-       rgb2rgb_param = (struct vpfe_ipipe_rgb2rgb *)param;
+       rgb2rgb_param = param;
 
        if (id == IPIPE_RGB2RGB_2)
                rgb2rgb = &ipipe->config.rgb2rgb2;
@@ -634,7 +634,7 @@ ipipe_validate_gamma_params(struct vpfe_ipipe_gamma *gamma, struct device *dev)
 static int
 ipipe_set_gamma_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_gamma *gamma_param = (struct vpfe_ipipe_gamma *)param;
+       struct vpfe_ipipe_gamma *gamma_param = param;
        struct vpfe_ipipe_gamma *gamma = &ipipe->config.gamma;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        int table_size;
@@ -678,7 +678,7 @@ success:
 
 static int ipipe_get_gamma_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_gamma *gamma_param = (struct vpfe_ipipe_gamma *)param;
+       struct vpfe_ipipe_gamma *gamma_param = param;
        struct vpfe_ipipe_gamma *gamma = &ipipe->config.gamma;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        int table_size;
@@ -737,7 +737,7 @@ static int ipipe_validate_3d_lut_params(struct vpfe_ipipe_3d_lut *lut)
 
 static int ipipe_get_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_3d_lut *lut_param = (struct vpfe_ipipe_3d_lut *)param;
+       struct vpfe_ipipe_3d_lut *lut_param = param;
        struct vpfe_ipipe_3d_lut *lut = &ipipe->config.lut;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
 
@@ -757,7 +757,7 @@ static int ipipe_get_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param)
 static int
 ipipe_set_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_3d_lut *lut_param = (struct vpfe_ipipe_3d_lut *)param;
+       struct vpfe_ipipe_3d_lut *lut_param = param;
        struct vpfe_ipipe_3d_lut *lut = &ipipe->config.lut;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
 
@@ -831,7 +831,7 @@ ipipe_set_rgb2yuv_params(struct vpfe_ipipe_device *ipipe, void *param)
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        struct vpfe_ipipe_rgb2yuv *rgb2yuv_param;
 
-       rgb2yuv_param = (struct vpfe_ipipe_rgb2yuv *)param;
+       rgb2yuv_param = param;
        if (!rgb2yuv_param) {
                /* Defaults for rgb2yuv conversion */
                const struct vpfe_ipipe_rgb2yuv rgb2yuv_defaults = {
@@ -871,7 +871,7 @@ ipipe_get_rgb2yuv_params(struct vpfe_ipipe_device *ipipe, void *param)
        struct vpfe_ipipe_rgb2yuv *rgb2yuv = &ipipe->config.rgb2yuv;
        struct vpfe_ipipe_rgb2yuv *rgb2yuv_param;
 
-       rgb2yuv_param = (struct vpfe_ipipe_rgb2yuv *)param;
+       rgb2yuv_param = param;
        memcpy(rgb2yuv_param, rgb2yuv, sizeof(struct vpfe_ipipe_rgb2yuv));
        return 0;
 }
@@ -896,7 +896,7 @@ static int ipipe_validate_gbce_params(struct vpfe_ipipe_gbce *gbce)
 
 static int ipipe_set_gbce_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_gbce *gbce_param = (struct vpfe_ipipe_gbce *)param;
+       struct vpfe_ipipe_gbce *gbce_param = param;
        struct vpfe_ipipe_gbce *gbce = &ipipe->config.gbce;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
 
@@ -917,7 +917,7 @@ static int ipipe_set_gbce_params(struct vpfe_ipipe_device *ipipe, void *param)
 
 static int ipipe_get_gbce_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_gbce *gbce_param = (struct vpfe_ipipe_gbce *)param;
+       struct vpfe_ipipe_gbce *gbce_param = param;
        struct vpfe_ipipe_gbce *gbce = &ipipe->config.gbce;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
 
@@ -950,7 +950,7 @@ ipipe_set_yuv422_conv_params(struct vpfe_ipipe_device *ipipe, void *param)
        struct vpfe_ipipe_yuv422_conv *yuv422_conv_param;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
 
-       yuv422_conv_param = (struct vpfe_ipipe_yuv422_conv *)param;
+       yuv422_conv_param = param;
        if (!yuv422_conv_param) {
                memset(yuv422_conv, 0, sizeof(struct vpfe_ipipe_yuv422_conv));
                yuv422_conv->chrom_pos = VPFE_IPIPE_YUV422_CHR_POS_COSITE;
@@ -974,7 +974,7 @@ ipipe_get_yuv422_conv_params(struct vpfe_ipipe_device *ipipe, void *param)
        struct vpfe_ipipe_yuv422_conv *yuv422_conv = &ipipe->config.yuv422_conv;
        struct vpfe_ipipe_yuv422_conv *yuv422_conv_param;
 
-       yuv422_conv_param = (struct vpfe_ipipe_yuv422_conv *)param;
+       yuv422_conv_param = param;
        memcpy(yuv422_conv_param, yuv422_conv,
               sizeof(struct vpfe_ipipe_yuv422_conv));
 
@@ -1018,7 +1018,7 @@ static int ipipe_validate_yee_params(struct vpfe_ipipe_yee *yee)
 
 static int ipipe_set_yee_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_yee *yee_param = (struct vpfe_ipipe_yee *)param;
+       struct vpfe_ipipe_yee *yee_param = param;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        struct vpfe_ipipe_yee *yee = &ipipe->config.yee;
 
@@ -1039,7 +1039,7 @@ static int ipipe_set_yee_params(struct vpfe_ipipe_device *ipipe, void *param)
 
 static int ipipe_get_yee_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_yee *yee_param = (struct vpfe_ipipe_yee *)param;
+       struct vpfe_ipipe_yee *yee_param = param;
        struct vpfe_ipipe_yee *yee = &ipipe->config.yee;
 
        yee_param->en = yee->en;
@@ -1081,7 +1081,7 @@ static int ipipe_validate_car_params(struct vpfe_ipipe_car *car)
 
 static int ipipe_set_car_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_car *car_param = (struct vpfe_ipipe_car *)param;
+       struct vpfe_ipipe_car *car_param = param;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        struct vpfe_ipipe_car *car = &ipipe->config.car;
 
@@ -1102,7 +1102,7 @@ static int ipipe_set_car_params(struct vpfe_ipipe_device *ipipe, void *param)
 
 static int ipipe_get_car_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_car *car_param = (struct vpfe_ipipe_car *)param;
+       struct vpfe_ipipe_car *car_param = param;
        struct vpfe_ipipe_car *car = &ipipe->config.car;
 
        memcpy(car_param, car, sizeof(struct vpfe_ipipe_car));
@@ -1119,7 +1119,7 @@ static int ipipe_validate_cgs_params(struct vpfe_ipipe_cgs *cgs)
 
 static int ipipe_set_cgs_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_cgs *cgs_param = (struct vpfe_ipipe_cgs *)param;
+       struct vpfe_ipipe_cgs *cgs_param = param;
        struct device *dev = ipipe->subdev.v4l2_dev->dev;
        struct vpfe_ipipe_cgs *cgs = &ipipe->config.cgs;
 
@@ -1140,7 +1140,7 @@ static int ipipe_set_cgs_params(struct vpfe_ipipe_device *ipipe, void *param)
 
 static int ipipe_get_cgs_params(struct vpfe_ipipe_device *ipipe, void *param)
 {
-       struct vpfe_ipipe_cgs *cgs_param = (struct vpfe_ipipe_cgs *)param;
+       struct vpfe_ipipe_cgs *cgs_param = param;
        struct vpfe_ipipe_cgs *cgs = &ipipe->config.cgs;
 
        memcpy(cgs_param, cgs, sizeof(struct vpfe_ipipe_cgs));
index 57426199ad7af48203a349afe66eaa407db120bf..01df0683e950734ca66fbc1b3fb7289acfea1a58 100644 (file)
@@ -294,7 +294,7 @@ static void vpfe_detach_irq(struct vpfe_device *vpfe_dev)
  */
 static int vpfe_attach_irq(struct vpfe_device *vpfe_dev)
 {
-       int ret = 0;
+       int ret;
 
        ret = request_irq(vpfe_dev->ccdc_irq0, vpfe_isr, 0,
                          "vpfe_capture0", vpfe_dev);
index 904a4667bbb8bebe3cb43bf5201be9d533ada07a..f2dca69c2bc0ed3ea8704e9d9df68ba4d04fc980 100644 (file)
@@ -244,7 +244,7 @@ exit:
  */
 static long vfd_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 {
-       struct sasem_context *context = NULL;
+       struct sasem_context *context;
 
        context = (struct sasem_context *) file->private_data;
 
@@ -697,16 +697,11 @@ static int sasem_probe(struct usb_interface *interface,
        for (i = 0; i < num_endpoints && !(ir_ep_found && vfd_ep_found); ++i) {
 
                struct usb_endpoint_descriptor *ep;
-               int ep_dir;
-               int ep_type;
 
                ep = &iface_desc->endpoint [i].desc;
-               ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
-               ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
 
                if (!ir_ep_found &&
-                       ep_dir == USB_DIR_IN &&
-                       ep_type == USB_ENDPOINT_XFER_INT) {
+                       usb_endpoint_is_int_in(ep)) {
 
                        rx_endpoint = ep;
                        ir_ep_found = 1;
@@ -715,8 +710,7 @@ static int sasem_probe(struct usb_interface *interface,
                                        "%s: found IR endpoint\n", __func__);
 
                } else if (!vfd_ep_found &&
-                       ep_dir == USB_DIR_OUT &&
-                       ep_type == USB_ENDPOINT_XFER_INT) {
+                       usb_endpoint_is_int_out(ep)) {
 
                        tx_endpoint = ep;
                        vfd_ep_found = 1;
index 0b03cb7c59d5c25c06ff1416ef38e62ba1c08e3d..aa76ccda5b424f73f64776a010afcb9040ecd39f 100644 (file)
@@ -151,7 +151,7 @@ int omap4iss_get_external_info(struct iss_pipeline *pipe,
 
        ctrl = v4l2_ctrl_find(pipe->external->ctrl_handler,
                              V4L2_CID_PIXEL_RATE);
-       if (ctrl == NULL) {
+       if (!ctrl) {
                dev_warn(iss->dev, "no pixel rate control in subdev %s\n",
                         pipe->external->name);
                return -EPIPE;
@@ -422,7 +422,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
        subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
               ? media_entity_to_v4l2_subdev(entity) : NULL;
 
-       if (entity->use_count == 0 && change > 0 && subdev != NULL) {
+       if (entity->use_count == 0 && change > 0 && subdev) {
                int ret;
 
                ret = v4l2_subdev_call(subdev, core, s_power, 1);
@@ -433,7 +433,7 @@ static int iss_pipeline_pm_power_one(struct media_entity *entity, int change)
        entity->use_count += change;
        WARN_ON(entity->use_count < 0);
 
-       if (entity->use_count == 0 && change < 0 && subdev != NULL)
+       if (entity->use_count == 0 && change < 0 && subdev)
                v4l2_subdev_call(subdev, core, s_power, 0);
 
        return 0;
@@ -469,8 +469,8 @@ static int iss_pipeline_pm_power(struct media_entity *entity, int change)
 
        media_entity_graph_walk_start(&graph, first);
 
-       while ((first = media_entity_graph_walk_next(&graph))
-              && first != entity)
+       while ((first = media_entity_graph_walk_next(&graph)) &&
+              first != entity)
                if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
                        iss_pipeline_pm_power_one(first, -change);
 
@@ -541,7 +541,7 @@ static int iss_pipeline_link_notify(struct media_link *link, u32 flags,
        }
 
        if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
-               (flags & MEDIA_LNK_FL_ENABLED)) {
+           (flags & MEDIA_LNK_FL_ENABLED)) {
                ret = iss_pipeline_pm_power(source, sink_use);
                if (ret < 0)
                        return ret;
@@ -590,7 +590,7 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe,
                        break;
 
                pad = media_entity_remote_pad(pad);
-               if (pad == NULL ||
+               if (!pad ||
                    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
                        break;
 
@@ -658,7 +658,7 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
                        break;
 
                pad = media_entity_remote_pad(pad);
-               if (pad == NULL ||
+               if (!pad ||
                    media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
                        break;
 
@@ -919,7 +919,7 @@ static int __iss_subclk_update(struct iss_device *iss)
 }
 
 int omap4iss_subclk_enable(struct iss_device *iss,
-                           enum iss_subclk_resource res)
+                          enum iss_subclk_resource res)
 {
        iss->subclk_resources |= res;
 
@@ -927,7 +927,7 @@ int omap4iss_subclk_enable(struct iss_device *iss,
 }
 
 int omap4iss_subclk_disable(struct iss_device *iss,
-                            enum iss_subclk_resource res)
+                           enum iss_subclk_resource res)
 {
        iss->subclk_resources &= ~res;
 
@@ -1050,7 +1050,7 @@ struct iss_device *omap4iss_get(struct iss_device *iss)
 {
        struct iss_device *__iss = iss;
 
-       if (iss == NULL)
+       if (!iss)
                return NULL;
 
        mutex_lock(&iss->iss_mutex);
@@ -1065,7 +1065,7 @@ struct iss_device *omap4iss_get(struct iss_device *iss)
        iss_enable_interrupts(iss);
 
 out:
-       if (__iss != NULL)
+       if (__iss)
                iss->ref_count++;
        mutex_unlock(&iss->iss_mutex);
 
@@ -1080,7 +1080,7 @@ out:
  */
 void omap4iss_put(struct iss_device *iss)
 {
-       if (iss == NULL)
+       if (!iss)
                return;
 
        mutex_lock(&iss->iss_mutex);
@@ -1137,12 +1137,12 @@ static void iss_unregister_entities(struct iss_device *iss)
  */
 static struct v4l2_subdev *
 iss_register_subdev_group(struct iss_device *iss,
-                    struct iss_subdev_i2c_board_info *board_info)
+                         struct iss_subdev_i2c_board_info *board_info)
 {
        struct v4l2_subdev *sensor = NULL;
        unsigned int first;
 
-       if (board_info->board_info == NULL)
+       if (!board_info->board_info)
                return NULL;
 
        for (first = 1; board_info->board_info; ++board_info, first = 0) {
@@ -1150,7 +1150,7 @@ iss_register_subdev_group(struct iss_device *iss,
                struct i2c_adapter *adapter;
 
                adapter = i2c_get_adapter(board_info->i2c_adapter_id);
-               if (adapter == NULL) {
+               if (!adapter) {
                        dev_err(iss->dev,
                                "%s: Unable to get I2C adapter %d for device %s\n",
                                __func__, board_info->i2c_adapter_id,
@@ -1160,7 +1160,7 @@ iss_register_subdev_group(struct iss_device *iss,
 
                subdev = v4l2_i2c_new_subdev_board(&iss->v4l2_dev, adapter,
                                board_info->board_info, NULL);
-               if (subdev == NULL) {
+               if (!subdev) {
                        dev_err(iss->dev, "Unable to register subdev %s\n",
                                board_info->board_info->type);
                        continue;
@@ -1228,7 +1228,7 @@ static int iss_register_entities(struct iss_device *iss)
                unsigned int pad;
 
                sensor = iss_register_subdev_group(iss, subdevs->subdevs);
-               if (sensor == NULL)
+               if (!sensor)
                        continue;
 
                sensor->host_priv = subdevs;
@@ -1369,7 +1369,7 @@ static int iss_probe(struct platform_device *pdev)
        unsigned int i;
        int ret;
 
-       if (pdata == NULL)
+       if (!pdata)
                return -EINVAL;
 
        iss = devm_kzalloc(&pdev->dev, sizeof(*iss), GFP_KERNEL);
@@ -1406,7 +1406,7 @@ static int iss_probe(struct platform_device *pdev)
        if (ret < 0)
                goto error;
 
-       if (omap4iss_get(iss) == NULL)
+       if (!omap4iss_get(iss))
                goto error;
 
        ret = iss_reset(iss);
index bc83f8246101a4fd726f5314a98190a83c9909d0..c6e6d47ac57f371695d7b02cac96ee9e42cce9ad 100644 (file)
@@ -658,7 +658,7 @@ static void csi2_isr_buffer(struct iss_csi2_device *csi2)
         * Let video queue operation restart engine if there is an underrun
         * condition.
         */
-       if (buffer == NULL)
+       if (!buffer)
                return;
 
        csi2_set_outaddr(csi2, buffer->iss_addr);
@@ -979,7 +979,7 @@ static int csi2_get_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __csi2_get_format(csi2, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        fmt->format = *format;
@@ -1001,7 +1001,7 @@ static int csi2_set_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __csi2_get_format(csi2, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        csi2_try_format(csi2, cfg, fmt->pad, &fmt->format, fmt->which);
index 3b37978a3bdfe0c5d23040cea035018eeea69b1c..f2f5343b4a800984e12b363abbf64d35dbe28855 100644 (file)
@@ -116,8 +116,8 @@ struct iss_csi2_ctrl_cfg {
 #define CSI2_PAD_SOURCE                1
 #define CSI2_PADS_NUM          2
 
-#define CSI2_OUTPUT_IPIPEIF    (1 << 0)
-#define CSI2_OUTPUT_MEMORY     (1 << 1)
+#define CSI2_OUTPUT_IPIPEIF    BIT(0)
+#define CSI2_OUTPUT_MEMORY     BIT(1)
 
 struct iss_csi2_device {
        struct v4l2_subdev subdev;
index f94a59299a83b841b92fd39ed41f747c867a3196..dd0abeffd893f85ed4f7fa8c707c92196ff83645 100644 (file)
@@ -247,8 +247,8 @@ ipipe_try_format(struct iss_ipipe_device *ipipe,
  * return -EINVAL or zero on success
  */
 static int ipipe_enum_mbus_code(struct v4l2_subdev *sd,
-                              struct v4l2_subdev_pad_config *cfg,
-                              struct v4l2_subdev_mbus_code_enum *code)
+                               struct v4l2_subdev_pad_config *cfg,
+                               struct v4l2_subdev_mbus_code_enum *code)
 {
        switch (code->pad) {
        case IPIPE_PAD_SINK:
@@ -274,8 +274,8 @@ static int ipipe_enum_mbus_code(struct v4l2_subdev *sd,
 }
 
 static int ipipe_enum_frame_size(struct v4l2_subdev *sd,
-                               struct v4l2_subdev_pad_config *cfg,
-                               struct v4l2_subdev_frame_size_enum *fse)
+                                struct v4l2_subdev_pad_config *cfg,
+                                struct v4l2_subdev_frame_size_enum *fse)
 {
        struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
        struct v4l2_mbus_framefmt format;
@@ -320,7 +320,7 @@ static int ipipe_get_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __ipipe_get_format(ipipe, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        fmt->format = *format;
@@ -344,7 +344,7 @@ static int ipipe_set_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __ipipe_get_format(ipipe, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        ipipe_try_format(ipipe, cfg, fmt->pad, &fmt->format, fmt->which);
@@ -353,18 +353,18 @@ static int ipipe_set_format(struct v4l2_subdev *sd,
        /* Propagate the format from sink to source */
        if (fmt->pad == IPIPE_PAD_SINK) {
                format = __ipipe_get_format(ipipe, cfg, IPIPE_PAD_SOURCE_VP,
-                                          fmt->which);
+                                           fmt->which);
                *format = fmt->format;
                ipipe_try_format(ipipe, cfg, IPIPE_PAD_SOURCE_VP, format,
-                               fmt->which);
+                                fmt->which);
        }
 
        return 0;
 }
 
 static int ipipe_link_validate(struct v4l2_subdev *sd, struct media_link *link,
-                                struct v4l2_subdev_format *source_fmt,
-                                struct v4l2_subdev_format *sink_fmt)
+                              struct v4l2_subdev_format *source_fmt,
+                              struct v4l2_subdev_format *sink_fmt)
 {
        /* Check if the two ends match */
        if (source_fmt->format.width != sink_fmt->format.width ||
@@ -440,8 +440,8 @@ static const struct v4l2_subdev_internal_ops ipipe_v4l2_internal_ops = {
  * return -EINVAL or zero on success
  */
 static int ipipe_link_setup(struct media_entity *entity,
-                          const struct media_pad *local,
-                          const struct media_pad *remote, u32 flags)
+                           const struct media_pad *local,
+                           const struct media_pad *remote, u32 flags)
 {
        struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
        struct iss_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
@@ -528,7 +528,7 @@ void omap4iss_ipipe_unregister_entities(struct iss_ipipe_device *ipipe)
 }
 
 int omap4iss_ipipe_register_entities(struct iss_ipipe_device *ipipe,
-       struct v4l2_device *vdev)
+                                    struct v4l2_device *vdev)
 {
        int ret;
 
index c22d9041f2a571102aba63c706a8821d7252d17f..d5b441d9cb3130870674634f3594222f6fe5b526 100644 (file)
@@ -21,7 +21,7 @@ enum ipipe_input_entity {
        IPIPE_INPUT_IPIPEIF,
 };
 
-#define IPIPE_OUTPUT_VP                (1 << 0)
+#define IPIPE_OUTPUT_VP                                BIT(0)
 
 /* Sink and source IPIPE pads */
 #define IPIPE_PAD_SINK                         0
@@ -58,7 +58,7 @@ struct iss_ipipe_device {
 struct iss_device;
 
 int omap4iss_ipipe_register_entities(struct iss_ipipe_device *ipipe,
-       struct v4l2_device *vdev);
+                                    struct v4l2_device *vdev);
 void omap4iss_ipipe_unregister_entities(struct iss_ipipe_device *ipipe);
 
 int omap4iss_ipipe_init(struct iss_device *iss);
index c0da13d55865ae32981b99873dac462c56a83bbc..5f9e449e70074a78d8c2ecab35b7c2fdffdece31 100644 (file)
@@ -115,7 +115,7 @@ static void ipipeif_set_outaddr(struct iss_ipipeif_device *ipipeif, u32 addr)
 {
        struct iss_device *iss = to_iss_device(ipipeif);
 
-       /* Save address splitted in Base Address H & L */
+       /* Save address split in Base Address H & L */
        iss_reg_write(iss, OMAP4_ISS_MEM_ISP_ISIF, ISIF_CADU,
                      (addr >> (16 + 5)) & ISIF_CADU_MASK);
        iss_reg_write(iss, OMAP4_ISS_MEM_ISP_ISIF, ISIF_CADL,
@@ -233,7 +233,7 @@ static void ipipeif_isr_buffer(struct iss_ipipeif_device *ipipeif)
        ipipeif_write_enable(ipipeif, 0);
 
        buffer = omap4iss_video_buffer_next(&ipipeif->video_out);
-       if (buffer == NULL)
+       if (!buffer)
                return;
 
        ipipeif_set_outaddr(ipipeif, buffer->iss_addr);
@@ -446,8 +446,8 @@ ipipeif_try_format(struct iss_ipipeif_device *ipipeif,
  * return -EINVAL or zero on success
  */
 static int ipipeif_enum_mbus_code(struct v4l2_subdev *sd,
-                              struct v4l2_subdev_pad_config *cfg,
-                              struct v4l2_subdev_mbus_code_enum *code)
+                                 struct v4l2_subdev_pad_config *cfg,
+                                 struct v4l2_subdev_mbus_code_enum *code)
 {
        struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
        struct v4l2_mbus_framefmt *format;
@@ -480,8 +480,8 @@ static int ipipeif_enum_mbus_code(struct v4l2_subdev *sd,
 }
 
 static int ipipeif_enum_frame_size(struct v4l2_subdev *sd,
-                               struct v4l2_subdev_pad_config *cfg,
-                               struct v4l2_subdev_frame_size_enum *fse)
+                                  struct v4l2_subdev_pad_config *cfg,
+                                  struct v4l2_subdev_frame_size_enum *fse)
 {
        struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
        struct v4l2_mbus_framefmt format;
@@ -526,7 +526,7 @@ static int ipipeif_get_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __ipipeif_get_format(ipipeif, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        fmt->format = *format;
@@ -550,7 +550,7 @@ static int ipipeif_set_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __ipipeif_get_format(ipipeif, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        ipipeif_try_format(ipipeif, cfg, fmt->pad, &fmt->format, fmt->which);
@@ -570,7 +570,7 @@ static int ipipeif_set_format(struct v4l2_subdev *sd,
                                              fmt->which);
                *format = fmt->format;
                ipipeif_try_format(ipipeif, cfg, IPIPEIF_PAD_SOURCE_VP, format,
-                               fmt->which);
+                                  fmt->which);
        }
 
        return 0;
@@ -656,8 +656,8 @@ static const struct v4l2_subdev_internal_ops ipipeif_v4l2_internal_ops = {
  * return -EINVAL or zero on success
  */
 static int ipipeif_link_setup(struct media_entity *entity,
-                          const struct media_pad *local,
-                          const struct media_pad *remote, u32 flags)
+                             const struct media_pad *local,
+                             const struct media_pad *remote, u32 flags)
 {
        struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
        struct iss_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
@@ -778,7 +778,7 @@ void omap4iss_ipipeif_unregister_entities(struct iss_ipipeif_device *ipipeif)
 }
 
 int omap4iss_ipipeif_register_entities(struct iss_ipipeif_device *ipipeif,
-       struct v4l2_device *vdev)
+                                      struct v4l2_device *vdev)
 {
        int ret;
 
index cbdccb982eeee2bce98538cd0cef0383c273be66..c6bd96d9656cf871049c17046bed93839b234412 100644 (file)
@@ -22,8 +22,8 @@ enum ipipeif_input_entity {
        IPIPEIF_INPUT_CSI2B
 };
 
-#define IPIPEIF_OUTPUT_MEMORY          (1 << 0)
-#define IPIPEIF_OUTPUT_VP              (1 << 1)
+#define IPIPEIF_OUTPUT_MEMORY                  BIT(0)
+#define IPIPEIF_OUTPUT_VP                      BIT(1)
 
 /* Sink and source IPIPEIF pads */
 #define IPIPEIF_PAD_SINK                       0
@@ -80,13 +80,13 @@ struct iss_device;
 int omap4iss_ipipeif_init(struct iss_device *iss);
 void omap4iss_ipipeif_cleanup(struct iss_device *iss);
 int omap4iss_ipipeif_register_entities(struct iss_ipipeif_device *ipipeif,
-       struct v4l2_device *vdev);
+                                      struct v4l2_device *vdev);
 void omap4iss_ipipeif_unregister_entities(struct iss_ipipeif_device *ipipeif);
 
 int omap4iss_ipipeif_busy(struct iss_ipipeif_device *ipipeif);
 void omap4iss_ipipeif_isr(struct iss_ipipeif_device *ipipeif, u32 events);
 void omap4iss_ipipeif_restore_context(struct iss_device *iss);
 void omap4iss_ipipeif_max_rate(struct iss_ipipeif_device *ipipeif,
-       unsigned int *max_rate);
+                              unsigned int *max_rate);
 
 #endif /* OMAP4_ISS_IPIPEIF_H */
index d2b6b6ae9174131a05422f4870f00ccd5441e52e..cb415e898acaf91f1798f6d03d4405d16ce2bbf1 100644 (file)
 #define ISS_HL_SYSCONFIG_IDLEMODE_FORCEIDLE            0x0
 #define ISS_HL_SYSCONFIG_IDLEMODE_NOIDLE               0x1
 #define ISS_HL_SYSCONFIG_IDLEMODE_SMARTIDLE            0x2
-#define ISS_HL_SYSCONFIG_SOFTRESET                     (1 << 0)
+#define ISS_HL_SYSCONFIG_SOFTRESET                     BIT(0)
 
 #define ISS_HL_IRQSTATUS_RAW(i)                                (0x20 + (0x10 * (i)))
 #define ISS_HL_IRQSTATUS(i)                            (0x24 + (0x10 * (i)))
 #define ISS_HL_IRQENABLE_SET(i)                                (0x28 + (0x10 * (i)))
 #define ISS_HL_IRQENABLE_CLR(i)                                (0x2c + (0x10 * (i)))
 
-#define ISS_HL_IRQ_HS_VS                               (1 << 17)
-#define ISS_HL_IRQ_SIMCOP(i)                           (1 << (12 + (i)))
-#define ISS_HL_IRQ_BTE                                 (1 << 11)
-#define ISS_HL_IRQ_CBUFF                               (1 << 10)
-#define ISS_HL_IRQ_CCP2(i)                             (1 << ((i) > 3 ? 16 : 14 + (i)))
-#define ISS_HL_IRQ_CSIB                                        (1 << 5)
-#define ISS_HL_IRQ_CSIA                                        (1 << 4)
-#define ISS_HL_IRQ_ISP(i)                              (1 << (i))
+#define ISS_HL_IRQ_HS_VS                       BIT(17)
+#define ISS_HL_IRQ_SIMCOP(i)                   BIT(12 + (i))
+#define ISS_HL_IRQ_BTE                         BIT(11)
+#define ISS_HL_IRQ_CBUFF                       BIT(10)
+#define ISS_HL_IRQ_CCP2(i)                     BIT((i) > 3 ? 16 : 14 + (i))
+#define ISS_HL_IRQ_CSIB                                BIT(5)
+#define ISS_HL_IRQ_CSIA                                BIT(4)
+#define ISS_HL_IRQ_ISP(i)                      BIT(i)
 
 #define ISS_CTRL                                       0x80
 #define ISS_CTRL_CLK_DIV_MASK                          (3 << 4)
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING                        (3 << 0)
 
 #define ISS_CLKCTRL                                    0x84
-#define ISS_CLKCTRL_VPORT2_CLK                         (1 << 30)
-#define ISS_CLKCTRL_VPORT1_CLK                         (1 << 29)
-#define ISS_CLKCTRL_VPORT0_CLK                         (1 << 28)
-#define ISS_CLKCTRL_CCP2                               (1 << 4)
-#define ISS_CLKCTRL_CSI2_B                             (1 << 3)
-#define ISS_CLKCTRL_CSI2_A                             (1 << 2)
-#define ISS_CLKCTRL_ISP                                        (1 << 1)
-#define ISS_CLKCTRL_SIMCOP                             (1 << 0)
+#define ISS_CLKCTRL_VPORT2_CLK                         BIT(30)
+#define ISS_CLKCTRL_VPORT1_CLK                         BIT(29)
+#define ISS_CLKCTRL_VPORT0_CLK                         BIT(28)
+#define ISS_CLKCTRL_CCP2                               BIT(4)
+#define ISS_CLKCTRL_CSI2_B                             BIT(3)
+#define ISS_CLKCTRL_CSI2_A                             BIT(2)
+#define ISS_CLKCTRL_ISP                                        BIT(1)
+#define ISS_CLKCTRL_SIMCOP                             BIT(0)
 
 #define ISS_CLKSTAT                                    0x88
-#define ISS_CLKSTAT_VPORT2_CLK                         (1 << 30)
-#define ISS_CLKSTAT_VPORT1_CLK                         (1 << 29)
-#define ISS_CLKSTAT_VPORT0_CLK                         (1 << 28)
-#define ISS_CLKSTAT_CCP2                               (1 << 4)
-#define ISS_CLKSTAT_CSI2_B                             (1 << 3)
-#define ISS_CLKSTAT_CSI2_A                             (1 << 2)
-#define ISS_CLKSTAT_ISP                                        (1 << 1)
-#define ISS_CLKSTAT_SIMCOP                             (1 << 0)
+#define ISS_CLKSTAT_VPORT2_CLK                         BIT(30)
+#define ISS_CLKSTAT_VPORT1_CLK                         BIT(29)
+#define ISS_CLKSTAT_VPORT0_CLK                         BIT(28)
+#define ISS_CLKSTAT_CCP2                               BIT(4)
+#define ISS_CLKSTAT_CSI2_B                             BIT(3)
+#define ISS_CLKSTAT_CSI2_A                             BIT(2)
+#define ISS_CLKSTAT_ISP                                        BIT(1)
+#define ISS_CLKSTAT_SIMCOP                             BIT(0)
 
 #define ISS_PM_STATUS                                  0x8c
 #define ISS_PM_STATUS_CBUFF_PM_MASK                    (3 << 12)
 #define ISS_PM_STATUS_CSI2_A_PM_MASK                   (3 << 0)
 
 #define REGISTER0                                      0x0
-#define REGISTER0_HSCLOCKCONFIG                                (1 << 24)
+#define REGISTER0_HSCLOCKCONFIG                                BIT(24)
 #define REGISTER0_THS_TERM_MASK                                (0xff << 8)
 #define REGISTER0_THS_TERM_SHIFT                       8
 #define REGISTER0_THS_SETTLE_MASK                      (0xff << 0)
 #define REGISTER0_THS_SETTLE_SHIFT                     0
 
 #define REGISTER1                                      0x4
-#define REGISTER1_RESET_DONE_CTRLCLK                   (1 << 29)
-#define REGISTER1_CLOCK_MISS_DETECTOR_STATUS           (1 << 25)
+#define REGISTER1_RESET_DONE_CTRLCLK                   BIT(29)
+#define REGISTER1_CLOCK_MISS_DETECTOR_STATUS           BIT(25)
 #define REGISTER1_TCLK_TERM_MASK                       (0x3f << 18)
 #define REGISTER1_TCLK_TERM_SHIFT                      18
 #define REGISTER1_DPHY_HS_SYNC_PATTERN_SHIFT           10
 #define CSI2_SYSCONFIG_AUTO_IDLE                       (1 << 0)
 
 #define CSI2_SYSSTATUS                                 0x14
-#define CSI2_SYSSTATUS_RESET_DONE                      (1 << 0)
+#define CSI2_SYSSTATUS_RESET_DONE                      BIT(0)
 
 #define CSI2_IRQSTATUS                                 0x18
 #define CSI2_IRQENABLE                                 0x1c
 
 /* Shared bits across CSI2_IRQENABLE and IRQSTATUS */
 
-#define CSI2_IRQ_OCP_ERR                               (1 << 14)
-#define CSI2_IRQ_SHORT_PACKET                          (1 << 13)
-#define CSI2_IRQ_ECC_CORRECTION                                (1 << 12)
-#define CSI2_IRQ_ECC_NO_CORRECTION                     (1 << 11)
-#define CSI2_IRQ_COMPLEXIO_ERR                         (1 << 9)
-#define CSI2_IRQ_FIFO_OVF                              (1 << 8)
-#define CSI2_IRQ_CONTEXT0                              (1 << 0)
+#define CSI2_IRQ_OCP_ERR                               BIT(14)
+#define CSI2_IRQ_SHORT_PACKET                          BIT(13)
+#define CSI2_IRQ_ECC_CORRECTION                                BIT(12)
+#define CSI2_IRQ_ECC_NO_CORRECTION                     BIT(11)
+#define CSI2_IRQ_COMPLEXIO_ERR                         BIT(9)
+#define CSI2_IRQ_FIFO_OVF                              BIT(8)
+#define CSI2_IRQ_CONTEXT0                              BIT(0)
 
 #define CSI2_CTRL                                      0x40
 #define CSI2_CTRL_MFLAG_LEVH_MASK                      (7 << 20)
 #define CSI2_COMPLEXIO_IRQENABLE                       0x60
 
 /* Shared bits across CSI2_COMPLEXIO_IRQENABLE and IRQSTATUS */
-#define CSI2_COMPLEXIO_IRQ_STATEALLULPMEXIT            (1 << 26)
-#define CSI2_COMPLEXIO_IRQ_STATEALLULPMENTER           (1 << 25)
-#define CSI2_COMPLEXIO_IRQ_STATEULPM5                  (1 << 24)
-#define CSI2_COMPLEXIO_IRQ_STATEULPM4                  (1 << 23)
-#define CSI2_COMPLEXIO_IRQ_STATEULPM3                  (1 << 22)
-#define CSI2_COMPLEXIO_IRQ_STATEULPM2                  (1 << 21)
-#define CSI2_COMPLEXIO_IRQ_STATEULPM1                  (1 << 20)
-#define CSI2_COMPLEXIO_IRQ_ERRCONTROL5                 (1 << 19)
-#define CSI2_COMPLEXIO_IRQ_ERRCONTROL4                 (1 << 18)
-#define CSI2_COMPLEXIO_IRQ_ERRCONTROL3                 (1 << 17)
-#define CSI2_COMPLEXIO_IRQ_ERRCONTROL2                 (1 << 16)
-#define CSI2_COMPLEXIO_IRQ_ERRCONTROL1                 (1 << 15)
-#define CSI2_COMPLEXIO_IRQ_ERRESC5                     (1 << 14)
-#define CSI2_COMPLEXIO_IRQ_ERRESC4                     (1 << 13)
-#define CSI2_COMPLEXIO_IRQ_ERRESC3                     (1 << 12)
-#define CSI2_COMPLEXIO_IRQ_ERRESC2                     (1 << 11)
-#define CSI2_COMPLEXIO_IRQ_ERRESC1                     (1 << 10)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS5               (1 << 9)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS4               (1 << 8)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS3               (1 << 7)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS2               (1 << 6)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS1               (1 << 5)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTHS5                   (1 << 4)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTHS4                   (1 << 3)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTHS3                   (1 << 2)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTHS2                   (1 << 1)
-#define CSI2_COMPLEXIO_IRQ_ERRSOTHS1                   (1 << 0)
+#define CSI2_COMPLEXIO_IRQ_STATEALLULPMEXIT            BIT(26)
+#define CSI2_COMPLEXIO_IRQ_STATEALLULPMENTER           BIT(25)
+#define CSI2_COMPLEXIO_IRQ_STATEULPM5                  BIT(24)
+#define CSI2_COMPLEXIO_IRQ_STATEULPM4                  BIT(23)
+#define CSI2_COMPLEXIO_IRQ_STATEULPM3                  BIT(22)
+#define CSI2_COMPLEXIO_IRQ_STATEULPM2                  BIT(21)
+#define CSI2_COMPLEXIO_IRQ_STATEULPM1                  BIT(20)
+#define CSI2_COMPLEXIO_IRQ_ERRCONTROL5                 BIT(19)
+#define CSI2_COMPLEXIO_IRQ_ERRCONTROL4                 BIT(18)
+#define CSI2_COMPLEXIO_IRQ_ERRCONTROL3                 BIT(17)
+#define CSI2_COMPLEXIO_IRQ_ERRCONTROL2                 BIT(16)
+#define CSI2_COMPLEXIO_IRQ_ERRCONTROL1                 BIT(15)
+#define CSI2_COMPLEXIO_IRQ_ERRESC5                     BIT(14)
+#define CSI2_COMPLEXIO_IRQ_ERRESC4                     BIT(13)
+#define CSI2_COMPLEXIO_IRQ_ERRESC3                     BIT(12)
+#define CSI2_COMPLEXIO_IRQ_ERRESC2                     BIT(11)
+#define CSI2_COMPLEXIO_IRQ_ERRESC1                     BIT(10)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS5               BIT(9)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS4               BIT(8)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS3               BIT(7)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS2               BIT(6)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTSYNCHS1               BIT(5)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTHS5                   BIT(4)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTHS4                   BIT(3)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTHS3                   BIT(2)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTHS2                   BIT(1)
+#define CSI2_COMPLEXIO_IRQ_ERRSOTHS1                   BIT(0)
 
 #define CSI2_DBG_P                                     0x68
 
 #define CSI2_TIMING                                    0x6c
-#define CSI2_TIMING_FORCE_RX_MODE_IO1                  (1 << 15)
-#define CSI2_TIMING_STOP_STATE_X16_IO1                 (1 << 14)
-#define CSI2_TIMING_STOP_STATE_X4_IO1                  (1 << 13)
+#define CSI2_TIMING_FORCE_RX_MODE_IO1                  BIT(15)
+#define CSI2_TIMING_STOP_STATE_X16_IO1                 BIT(14)
+#define CSI2_TIMING_STOP_STATE_X4_IO1                  BIT(13)
 #define CSI2_TIMING_STOP_STATE_COUNTER_IO1_MASK                (0x1fff << 0)
 #define CSI2_TIMING_STOP_STATE_COUNTER_IO1_SHIFT       0
 
 #define CSI2_CTX_CTRL1(i)                              (0x70 + (0x20 * i))
-#define CSI2_CTX_CTRL1_GENERIC                         (1 << 30)
+#define CSI2_CTX_CTRL1_GENERIC                         BIT(30)
 #define CSI2_CTX_CTRL1_TRANSCODE                       (0xf << 24)
 #define CSI2_CTX_CTRL1_FEC_NUMBER_MASK                 (0xff << 16)
 #define CSI2_CTX_CTRL1_COUNT_MASK                      (0xff << 8)
 #define CSI2_CTX_CTRL1_COUNT_SHIFT                     8
-#define CSI2_CTX_CTRL1_EOF_EN                          (1 << 7)
-#define CSI2_CTX_CTRL1_EOL_EN                          (1 << 6)
-#define CSI2_CTX_CTRL1_CS_EN                           (1 << 5)
-#define CSI2_CTX_CTRL1_COUNT_UNLOCK                    (1 << 4)
-#define CSI2_CTX_CTRL1_PING_PONG                       (1 << 3)
-#define CSI2_CTX_CTRL1_CTX_EN                          (1 << 0)
+#define CSI2_CTX_CTRL1_EOF_EN                          BIT(7)
+#define CSI2_CTX_CTRL1_EOL_EN                          BIT(6)
+#define CSI2_CTX_CTRL1_CS_EN                           BIT(5)
+#define CSI2_CTX_CTRL1_COUNT_UNLOCK                    BIT(4)
+#define CSI2_CTX_CTRL1_PING_PONG                       BIT(3)
+#define CSI2_CTX_CTRL1_CTX_EN                          BIT(0)
 
 #define CSI2_CTX_CTRL2(i)                              (0x74 + (0x20 * i))
 #define CSI2_CTX_CTRL2_FRAME_MASK                      (0xffff << 16)
                (0x3fff << CSI2_CTX_CTRL3_ALPHA_SHIFT)
 
 /* Shared bits across CSI2_CTX_IRQENABLE and IRQSTATUS */
-#define CSI2_CTX_IRQ_ECC_CORRECTION                    (1 << 8)
-#define CSI2_CTX_IRQ_LINE_NUMBER                       (1 << 7)
-#define CSI2_CTX_IRQ_FRAME_NUMBER                      (1 << 6)
-#define CSI2_CTX_IRQ_CS                                        (1 << 5)
-#define CSI2_CTX_IRQ_LE                                        (1 << 3)
-#define CSI2_CTX_IRQ_LS                                        (1 << 2)
-#define CSI2_CTX_IRQ_FE                                        (1 << 1)
-#define CSI2_CTX_IRQ_FS                                        (1 << 0)
+#define CSI2_CTX_IRQ_ECC_CORRECTION                    BIT(8)
+#define CSI2_CTX_IRQ_LINE_NUMBER                       BIT(7)
+#define CSI2_CTX_IRQ_FRAME_NUMBER                      BIT(6)
+#define CSI2_CTX_IRQ_CS                                        BIT(5)
+#define CSI2_CTX_IRQ_LE                                        BIT(3)
+#define CSI2_CTX_IRQ_LS                                        BIT(2)
+#define CSI2_CTX_IRQ_FE                                        BIT(1)
+#define CSI2_CTX_IRQ_FS                                        BIT(0)
 
 /* ISS BTE */
 #define BTE_CTRL                                       (0x0030)
 #define ISP5_IRQENABLE_CLR(i)                          (0x0030 + (0x10 * (i)))
 
 /* Bits shared for ISP5_IRQ* registers */
-#define ISP5_IRQ_OCP_ERR                               (1 << 31)
-#define ISP5_IRQ_IPIPE_INT_DPC_RNEW1                   (1 << 29)
-#define ISP5_IRQ_IPIPE_INT_DPC_RNEW0                   (1 << 28)
-#define ISP5_IRQ_IPIPE_INT_DPC_INIT                    (1 << 27)
-#define ISP5_IRQ_IPIPE_INT_EOF                         (1 << 25)
-#define ISP5_IRQ_H3A_INT_EOF                           (1 << 24)
-#define ISP5_IRQ_RSZ_INT_EOF1                          (1 << 23)
-#define ISP5_IRQ_RSZ_INT_EOF0                          (1 << 22)
-#define ISP5_IRQ_RSZ_FIFO_IN_BLK_ERR                   (1 << 19)
-#define ISP5_IRQ_RSZ_FIFO_OVF                          (1 << 18)
-#define ISP5_IRQ_RSZ_INT_CYC_RSZB                      (1 << 17)
-#define ISP5_IRQ_RSZ_INT_CYC_RSZA                      (1 << 16)
-#define ISP5_IRQ_RSZ_INT_DMA                           (1 << 15)
-#define ISP5_IRQ_RSZ_INT_LAST_PIX                      (1 << 14)
-#define ISP5_IRQ_RSZ_INT_REG                           (1 << 13)
-#define ISP5_IRQ_H3A_INT                               (1 << 12)
-#define ISP5_IRQ_AF_INT                                        (1 << 11)
-#define ISP5_IRQ_AEW_INT                               (1 << 10)
-#define ISP5_IRQ_IPIPEIF_IRQ                           (1 << 9)
-#define ISP5_IRQ_IPIPE_INT_HST                         (1 << 8)
-#define ISP5_IRQ_IPIPE_INT_BSC                         (1 << 7)
-#define ISP5_IRQ_IPIPE_INT_DMA                         (1 << 6)
-#define ISP5_IRQ_IPIPE_INT_LAST_PIX                    (1 << 5)
-#define ISP5_IRQ_IPIPE_INT_REG                         (1 << 4)
-#define ISP5_IRQ_ISIF_INT(i)                           (1 << (i))
+#define ISP5_IRQ_OCP_ERR                               BIT(31)
+#define ISP5_IRQ_IPIPE_INT_DPC_RNEW1                   BIT(29)
+#define ISP5_IRQ_IPIPE_INT_DPC_RNEW0                   BIT(28)
+#define ISP5_IRQ_IPIPE_INT_DPC_INIT                    BIT(27)
+#define ISP5_IRQ_IPIPE_INT_EOF                         BIT(25)
+#define ISP5_IRQ_H3A_INT_EOF                           BIT(24)
+#define ISP5_IRQ_RSZ_INT_EOF1                          BIT(23)
+#define ISP5_IRQ_RSZ_INT_EOF0                          BIT(22)
+#define ISP5_IRQ_RSZ_FIFO_IN_BLK_ERR                   BIT(19)
+#define ISP5_IRQ_RSZ_FIFO_OVF                          BIT(18)
+#define ISP5_IRQ_RSZ_INT_CYC_RSZB                      BIT(17)
+#define ISP5_IRQ_RSZ_INT_CYC_RSZA                      BIT(16)
+#define ISP5_IRQ_RSZ_INT_DMA                           BIT(15)
+#define ISP5_IRQ_RSZ_INT_LAST_PIX                      BIT(14)
+#define ISP5_IRQ_RSZ_INT_REG                           BIT(13)
+#define ISP5_IRQ_H3A_INT                               BIT(12)
+#define ISP5_IRQ_AF_INT                                        BIT(11)
+#define ISP5_IRQ_AEW_INT                               BIT(10)
+#define ISP5_IRQ_IPIPEIF_IRQ                           BIT(9)
+#define ISP5_IRQ_IPIPE_INT_HST                         BIT(8)
+#define ISP5_IRQ_IPIPE_INT_BSC                         BIT(7)
+#define ISP5_IRQ_IPIPE_INT_DMA                         BIT(6)
+#define ISP5_IRQ_IPIPE_INT_LAST_PIX                    BIT(5)
+#define ISP5_IRQ_IPIPE_INT_REG                         BIT(4)
+#define ISP5_IRQ_ISIF_INT(i)                           BIT(i)
 
 #define ISP5_CTRL                                      (0x006c)
-#define ISP5_CTRL_MSTANDBY                             (1 << 24)
-#define ISP5_CTRL_VD_PULSE_EXT                         (1 << 23)
-#define ISP5_CTRL_MSTANDBY_WAIT                                (1 << 20)
-#define ISP5_CTRL_BL_CLK_ENABLE                                (1 << 15)
-#define ISP5_CTRL_ISIF_CLK_ENABLE                      (1 << 14)
-#define ISP5_CTRL_H3A_CLK_ENABLE                       (1 << 13)
-#define ISP5_CTRL_RSZ_CLK_ENABLE                       (1 << 12)
-#define ISP5_CTRL_IPIPE_CLK_ENABLE                     (1 << 11)
-#define ISP5_CTRL_IPIPEIF_CLK_ENABLE                   (1 << 10)
-#define ISP5_CTRL_SYNC_ENABLE                          (1 << 9)
-#define ISP5_CTRL_PSYNC_CLK_SEL                                (1 << 8)
+#define ISP5_CTRL_MSTANDBY                             BIT(24)
+#define ISP5_CTRL_VD_PULSE_EXT                         BIT(23)
+#define ISP5_CTRL_MSTANDBY_WAIT                                BIT(20)
+#define ISP5_CTRL_BL_CLK_ENABLE                                BIT(15)
+#define ISP5_CTRL_ISIF_CLK_ENABLE                      BIT(14)
+#define ISP5_CTRL_H3A_CLK_ENABLE                       BIT(13)
+#define ISP5_CTRL_RSZ_CLK_ENABLE                       BIT(12)
+#define ISP5_CTRL_IPIPE_CLK_ENABLE                     BIT(11)
+#define ISP5_CTRL_IPIPEIF_CLK_ENABLE                   BIT(10)
+#define ISP5_CTRL_SYNC_ENABLE                          BIT(9)
+#define ISP5_CTRL_PSYNC_CLK_SEL                                BIT(8)
 
 /* ISS ISP ISIF register offsets */
 #define ISIF_SYNCEN                                    (0x0000)
-#define ISIF_SYNCEN_DWEN                               (1 << 1)
-#define ISIF_SYNCEN_SYEN                               (1 << 0)
+#define ISIF_SYNCEN_DWEN                               BIT(1)
+#define ISIF_SYNCEN_SYEN                               BIT(0)
 
 #define ISIF_MODESET                                   (0x0004)
 #define ISIF_MODESET_INPMOD_MASK                       (3 << 12)
 #define ISIF_LNV_MASK                                  (0x7fff)
 
 #define ISIF_HSIZE                                     (0x0034)
-#define ISIF_HSIZE_ADCR                                        (1 << 12)
+#define ISIF_HSIZE_ADCR                                        BIT(12)
 #define ISIF_HSIZE_HSIZE_MASK                          (0xfff)
 
 #define ISIF_CADU                                      (0x003c)
 #define ISIF_CGAMMAWD_GWDI(bpp)                                ((16 - (bpp)) << 1)
 
 #define ISIF_CCDCFG                                    (0x0088)
-#define ISIF_CCDCFG_Y8POS                              (1 << 11)
+#define ISIF_CCDCFG_Y8POS                              BIT(11)
 
 /* ISS ISP IPIPEIF register offsets */
 #define IPIPEIF_ENABLE                                 (0x0000)
 #define IPIPEIF_CFG1_INPSRC2_SDRAM_YUV                 (3 << 2)
 
 #define IPIPEIF_CFG2                                   (0x0030)
-#define IPIPEIF_CFG2_YUV8P                             (1 << 7)
-#define IPIPEIF_CFG2_YUV8                              (1 << 6)
-#define IPIPEIF_CFG2_YUV16                             (1 << 3)
-#define IPIPEIF_CFG2_VDPOL                             (1 << 2)
-#define IPIPEIF_CFG2_HDPOL                             (1 << 1)
-#define IPIPEIF_CFG2_INTSW                             (1 << 0)
+#define IPIPEIF_CFG2_YUV8P                             BIT(7)
+#define IPIPEIF_CFG2_YUV8                              BIT(6)
+#define IPIPEIF_CFG2_YUV16                             BIT(3)
+#define IPIPEIF_CFG2_VDPOL                             BIT(2)
+#define IPIPEIF_CFG2_HDPOL                             BIT(1)
+#define IPIPEIF_CFG2_INTSW                             BIT(0)
 
 #define IPIPEIF_CLKDIV                                 (0x0040)
 
 /* ISS ISP IPIPE register offsets */
 #define IPIPE_SRC_EN                                   (0x0000)
-#define IPIPE_SRC_EN_EN                                        (1 << 0)
+#define IPIPE_SRC_EN_EN                                        BIT(0)
 
 #define IPIPE_SRC_MODE                                 (0x0004)
-#define IPIPE_SRC_MODE_WRT                             (1 << 1)
-#define IPIPE_SRC_MODE_OST                             (1 << 0)
+#define IPIPE_SRC_MODE_WRT                             BIT(1)
+#define IPIPE_SRC_MODE_OST                             BIT(0)
 
 #define IPIPE_SRC_FMT                                  (0x0008)
 #define IPIPE_SRC_FMT_RAW2YUV                          (0 << 0)
 #define IPIPE_SRC_STA                                  (0x0024)
 
 #define IPIPE_GCK_MMR                                  (0x0028)
-#define IPIPE_GCK_MMR_REG                              (1 << 0)
+#define IPIPE_GCK_MMR_REG                              BIT(0)
 
 #define IPIPE_GCK_PIX                                  (0x002c)
-#define IPIPE_GCK_PIX_G3                               (1 << 3)
-#define IPIPE_GCK_PIX_G2                               (1 << 2)
-#define IPIPE_GCK_PIX_G1                               (1 << 1)
-#define IPIPE_GCK_PIX_G0                               (1 << 0)
+#define IPIPE_GCK_PIX_G3                               BIT(3)
+#define IPIPE_GCK_PIX_G2                               BIT(2)
+#define IPIPE_GCK_PIX_G1                               BIT(1)
+#define IPIPE_GCK_PIX_G0                               BIT(0)
 
 #define IPIPE_DPC_LUT_EN                               (0x0034)
 #define IPIPE_DPC_LUT_SEL                              (0x0038)
 #define IPIPE_YUV_OFT_CR                               (0x02c4)
 
 #define IPIPE_YUV_PHS                                  (0x02c8)
-#define IPIPE_YUV_PHS_LPF                              (1 << 1)
-#define IPIPE_YUV_PHS_POS                              (1 << 0)
+#define IPIPE_YUV_PHS_LPF                              BIT(1)
+#define IPIPE_YUV_PHS_POS                              BIT(0)
 
 #define IPIPE_YEE_EN                                   (0x02d4)
 #define IPIPE_YEE_TYP                                  (0x02d8)
 /* ISS ISP Resizer register offsets */
 #define RSZ_REVISION                                   (0x0000)
 #define RSZ_SYSCONFIG                                  (0x0004)
-#define RSZ_SYSCONFIG_RSZB_CLK_EN                      (1 << 9)
-#define RSZ_SYSCONFIG_RSZA_CLK_EN                      (1 << 8)
+#define RSZ_SYSCONFIG_RSZB_CLK_EN                      BIT(9)
+#define RSZ_SYSCONFIG_RSZA_CLK_EN                      BIT(8)
 
 #define RSZ_IN_FIFO_CTRL                               (0x000c)
 #define RSZ_IN_FIFO_CTRL_THRLD_LOW_MASK                        (0x1ff << 16)
 #define RSZ_FRACDIV_MASK                               (0xffff)
 
 #define RSZ_SRC_EN                                     (0x0020)
-#define RSZ_SRC_EN_SRC_EN                              (1 << 0)
+#define RSZ_SRC_EN_SRC_EN                              BIT(0)
 
 #define RSZ_SRC_MODE                                   (0x0024)
-#define RSZ_SRC_MODE_OST                               (1 << 0)
-#define RSZ_SRC_MODE_WRT                               (1 << 1)
+#define RSZ_SRC_MODE_OST                               BIT(0)
+#define RSZ_SRC_MODE_WRT                               BIT(1)
 
 #define RSZ_SRC_FMT0                                   (0x0028)
-#define RSZ_SRC_FMT0_BYPASS                            (1 << 1)
-#define RSZ_SRC_FMT0_SEL                               (1 << 0)
+#define RSZ_SRC_FMT0_BYPASS                            BIT(1)
+#define RSZ_SRC_FMT0_SEL                               BIT(0)
 
 #define RSZ_SRC_FMT1                                   (0x002c)
-#define RSZ_SRC_FMT1_IN420                             (1 << 1)
+#define RSZ_SRC_FMT1_IN420                             BIT(1)
 
 #define RSZ_SRC_VPS                                    (0x0030)
 #define RSZ_SRC_VSZ                                    (0x0034)
 #define RSZ_DMA_RZB                                    (0x0044)
 #define RSZ_DMA_STA                                    (0x0048)
 #define RSZ_GCK_MMR                                    (0x004c)
-#define RSZ_GCK_MMR_MMR                                        (1 << 0)
+#define RSZ_GCK_MMR_MMR                                        BIT(0)
 
 #define RSZ_GCK_SDR                                    (0x0054)
-#define RSZ_GCK_SDR_CORE                               (1 << 0)
+#define RSZ_GCK_SDR_CORE                               BIT(0)
 
 #define RSZ_IRQ_RZA                                    (0x0058)
 #define RSZ_IRQ_RZA_MASK                               (0x1fff)
 #define RSZ_YUV_C_MAX                                  (0x006c)
 
 #define RSZ_SEQ                                                (0x0074)
-#define RSZ_SEQ_HRVB                                   (1 << 2)
-#define RSZ_SEQ_HRVA                                   (1 << 0)
+#define RSZ_SEQ_HRVB                                   BIT(2)
+#define RSZ_SEQ_HRVA                                   BIT(0)
 
 #define RZA_EN                                         (0x0078)
 #define RZA_MODE                                       (0x007c)
-#define RZA_MODE_ONE_SHOT                              (1 << 0)
+#define RZA_MODE_ONE_SHOT                              BIT(0)
 
 #define RZA_420                                                (0x0080)
 #define RZA_I_VPS                                      (0x0084)
 #define RZB_SDR_C_PTR_E                                        (0x0194)
 
 /* Shared Bitmasks between RZA & RZB */
-#define RSZ_EN_EN                                      (1 << 0)
+#define RSZ_EN_EN                                      BIT(0)
 
-#define RSZ_420_CEN                                    (1 << 1)
-#define RSZ_420_YEN                                    (1 << 0)
+#define RSZ_420_CEN                                    BIT(1)
+#define RSZ_420_YEN                                    BIT(0)
 
 #define RSZ_I_VPS_MASK                                 (0x1fff)
 
 
 #define RSZ_V_DIF_MASK                                 (0x3fff)
 
-#define RSZ_V_TYP_C                                    (1 << 1)
-#define RSZ_V_TYP_Y                                    (1 << 0)
+#define RSZ_V_TYP_C                                    BIT(1)
+#define RSZ_V_TYP_Y                                    BIT(0)
 
 #define RSZ_V_LPF_C_MASK                               (0x3f << 6)
 #define RSZ_V_LPF_C_SHIFT                              6
 
 #define RSZ_H_DIF_MASK                                 (0x3fff)
 
-#define RSZ_H_TYP_C                                    (1 << 1)
-#define RSZ_H_TYP_Y                                    (1 << 0)
+#define RSZ_H_TYP_C                                    BIT(1)
+#define RSZ_H_TYP_Y                                    BIT(0)
 
 #define RSZ_H_LPF_C_MASK                               (0x3f << 6)
 #define RSZ_H_LPF_C_SHIFT                              6
 #define RSZ_H_LPF_Y_MASK                               (0x3f << 0)
 #define RSZ_H_LPF_Y_SHIFT                              0
 
-#define RSZ_DWN_EN_DWN_EN                              (1 << 0)
+#define RSZ_DWN_EN_DWN_EN                              BIT(0)
 
 #endif /* _OMAP4_ISS_REGS_H_ */
index 5030cf3cd34c87c5aec6b30f4cf8f99fbca3b4a9..9c8180bba77ed142af008c846bc26866ab27497f 100644 (file)
@@ -143,7 +143,7 @@ static void resizer_set_outaddr(struct iss_resizer_device *resizer, u32 addr)
        informat = &resizer->formats[RESIZER_PAD_SINK];
        outformat = &resizer->formats[RESIZER_PAD_SOURCE_MEM];
 
-       /* Save address splitted in Base Address H & L */
+       /* Save address split in Base Address H & L */
        iss_reg_write(iss, OMAP4_ISS_MEM_ISP_RESIZER, RZA_SDR_Y_BAD_H,
                      (addr >> 16) & 0xffff);
        iss_reg_write(iss, OMAP4_ISS_MEM_ISP_RESIZER, RZA_SDR_Y_BAD_L,
@@ -168,7 +168,7 @@ static void resizer_set_outaddr(struct iss_resizer_device *resizer, u32 addr)
                        c_addr |= addr & 0x7f;
                }
 
-               /* Save address splitted in Base Address H & L */
+               /* Save address split in Base Address H & L */
                iss_reg_write(iss, OMAP4_ISS_MEM_ISP_RESIZER, RZA_SDR_C_BAD_H,
                              (c_addr >> 16) & 0xffff);
                iss_reg_write(iss, OMAP4_ISS_MEM_ISP_RESIZER, RZA_SDR_C_BAD_L,
@@ -274,7 +274,7 @@ static void resizer_isr_buffer(struct iss_resizer_device *resizer)
        resizer_enable(resizer, 0);
 
        buffer = omap4iss_video_buffer_next(&resizer->video_out);
-       if (buffer == NULL)
+       if (!buffer)
                return;
 
        resizer_set_outaddr(resizer, buffer->iss_addr);
@@ -482,7 +482,6 @@ resizer_try_format(struct iss_resizer_device *resizer,
                fmt->width &= ~15;
                fmt->height = clamp_t(u32, height, 32, fmt->height);
                break;
-
        }
 
        fmt->colorspace = V4L2_COLORSPACE_JPEG;
@@ -497,8 +496,8 @@ resizer_try_format(struct iss_resizer_device *resizer,
  * return -EINVAL or zero on success
  */
 static int resizer_enum_mbus_code(struct v4l2_subdev *sd,
-                              struct v4l2_subdev_pad_config *cfg,
-                              struct v4l2_subdev_mbus_code_enum *code)
+                                 struct v4l2_subdev_pad_config *cfg,
+                                 struct v4l2_subdev_mbus_code_enum *code)
 {
        struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
        struct v4l2_mbus_framefmt *format;
@@ -542,8 +541,8 @@ static int resizer_enum_mbus_code(struct v4l2_subdev *sd,
 }
 
 static int resizer_enum_frame_size(struct v4l2_subdev *sd,
-                               struct v4l2_subdev_pad_config *cfg,
-                               struct v4l2_subdev_frame_size_enum *fse)
+                                  struct v4l2_subdev_pad_config *cfg,
+                                  struct v4l2_subdev_frame_size_enum *fse)
 {
        struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
        struct v4l2_mbus_framefmt format;
@@ -588,7 +587,7 @@ static int resizer_get_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __resizer_get_format(resizer, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        fmt->format = *format;
@@ -612,7 +611,7 @@ static int resizer_set_format(struct v4l2_subdev *sd,
        struct v4l2_mbus_framefmt *format;
 
        format = __resizer_get_format(resizer, cfg, fmt->pad, fmt->which);
-       if (format == NULL)
+       if (!format)
                return -EINVAL;
 
        resizer_try_format(resizer, cfg, fmt->pad, &fmt->format, fmt->which);
@@ -625,7 +624,7 @@ static int resizer_set_format(struct v4l2_subdev *sd,
                                              fmt->which);
                *format = fmt->format;
                resizer_try_format(resizer, cfg, RESIZER_PAD_SOURCE_MEM, format,
-                               fmt->which);
+                                  fmt->which);
        }
 
        return 0;
@@ -711,8 +710,8 @@ static const struct v4l2_subdev_internal_ops resizer_v4l2_internal_ops = {
  * return -EINVAL or zero on success
  */
 static int resizer_link_setup(struct media_entity *entity,
-                          const struct media_pad *local,
-                          const struct media_pad *remote, u32 flags)
+                             const struct media_pad *local,
+                             const struct media_pad *remote, u32 flags)
 {
        struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
        struct iss_resizer_device *resizer = v4l2_get_subdevdata(sd);
@@ -734,7 +733,6 @@ static int resizer_link_setup(struct media_entity *entity,
                else if (remote->entity == &iss->ipipe.subdev.entity)
                        resizer->input = RESIZER_INPUT_IPIPE;
 
-
                break;
 
        case RESIZER_PAD_SOURCE_MEM | MEDIA_ENT_T_DEVNODE:
@@ -822,7 +820,7 @@ void omap4iss_resizer_unregister_entities(struct iss_resizer_device *resizer)
 }
 
 int omap4iss_resizer_register_entities(struct iss_resizer_device *resizer,
-       struct v4l2_device *vdev)
+                                      struct v4l2_device *vdev)
 {
        int ret;
 
index 3727498b06a3adf0c084f8e1770864ca82d4c0ce..1e145abafc656241af648c3d2902c38a85d03b32 100644 (file)
@@ -22,7 +22,7 @@ enum resizer_input_entity {
        RESIZER_INPUT_IPIPEIF
 };
 
-#define RESIZER_OUTPUT_MEMORY          (1 << 0)
+#define RESIZER_OUTPUT_MEMORY                  BIT(0)
 
 /* Sink and source RESIZER pads */
 #define RESIZER_PAD_SINK                       0
@@ -63,13 +63,13 @@ struct iss_device;
 int omap4iss_resizer_init(struct iss_device *iss);
 void omap4iss_resizer_cleanup(struct iss_device *iss);
 int omap4iss_resizer_register_entities(struct iss_resizer_device *resizer,
-       struct v4l2_device *vdev);
+                                      struct v4l2_device *vdev);
 void omap4iss_resizer_unregister_entities(struct iss_resizer_device *resizer);
 
 int omap4iss_resizer_busy(struct iss_resizer_device *resizer);
 void omap4iss_resizer_isr(struct iss_resizer_device *resizer, u32 events);
 void omap4iss_resizer_restore_context(struct iss_device *iss);
 void omap4iss_resizer_max_rate(struct iss_resizer_device *resizer,
-       unsigned int *max_rate);
+                              unsigned int *max_rate);
 
 #endif /* OMAP4_ISS_RESIZER_H */
index 28c067decc27d9c3a695505dde8de3c1536580ab..2a0158bb497420b63f527a45b9bbada740136e37 100644 (file)
@@ -25,7 +25,6 @@
 #include "iss_video.h"
 #include "iss.h"
 
-
 /* -----------------------------------------------------------------------------
  * Helper functions
  */
@@ -191,7 +190,7 @@ iss_video_remote_subdev(struct iss_video *video, u32 *pad)
 
        remote = media_entity_remote_pad(&video->pad);
 
-       if (remote == NULL ||
+       if (!remote ||
            media_entity_type(remote->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
                return NULL;
 
@@ -241,7 +240,7 @@ __iss_video_get_format(struct iss_video *video,
        int ret;
 
        subdev = iss_video_remote_subdev(video, &pad);
-       if (subdev == NULL)
+       if (!subdev)
                return -EINVAL;
 
        memset(&fmt, 0, sizeof(fmt));
@@ -471,7 +470,7 @@ struct iss_buffer *omap4iss_video_buffer_next(struct iss_video *video)
                return NULL;
        }
 
-       if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->input != NULL) {
+       if (video->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && pipe->input) {
                spin_lock(&pipe->lock);
                pipe->state &= ~ISS_PIPELINE_STREAM;
                spin_unlock(&pipe->lock);
@@ -624,7 +623,7 @@ iss_video_try_format(struct file *file, void *fh, struct v4l2_format *format)
                return -EINVAL;
 
        subdev = iss_video_remote_subdev(video, &pad);
-       if (subdev == NULL)
+       if (!subdev)
                return -EINVAL;
 
        iss_video_pix_to_mbus(&format->fmt.pix, &fmt.format);
@@ -806,7 +805,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
                pipe->input = far_end;
                pipe->output = video;
        } else {
-               if (far_end == NULL) {
+               if (!far_end) {
                        ret = -EPIPE;
                        goto err_iss_video_check_format;
                }
@@ -841,7 +840,7 @@ iss_video_streamon(struct file *file, void *fh, enum v4l2_buf_type type)
         * to the stream on command. In memory-to-memory mode, it will be
         * started when buffers are queued on both the input and output.
         */
-       if (pipe->input == NULL) {
+       if (!pipe->input) {
                unsigned long flags;
 
                ret = omap4iss_pipeline_set_stream(pipe,
@@ -974,14 +973,14 @@ static int iss_video_open(struct file *file)
        int ret = 0;
 
        handle = kzalloc(sizeof(*handle), GFP_KERNEL);
-       if (handle == NULL)
+       if (!handle)
                return -ENOMEM;
 
        v4l2_fh_init(&handle->vfh, &video->video);
        v4l2_fh_add(&handle->vfh);
 
        /* If this is the first user, initialise the pipeline. */
-       if (omap4iss_get(video->iss) == NULL) {
+       if (!omap4iss_get(video->iss)) {
                ret = -EBUSY;
                goto done;
        }
@@ -1116,7 +1115,7 @@ int omap4iss_video_init(struct iss_video *video, const char *name)
        mutex_init(&video->stream_lock);
 
        /* Initialize the video device. */
-       if (video->ops == NULL)
+       if (!video->ops)
                video->ops = &iss_video_dummy_ops;
 
        video->video.fops = &iss_video_fops;
index 380c137089d0312e30593524564aedc48fe6b42d..42ff0d8b2eadd30eaf21c41a7860173819e46df1 100644 (file)
@@ -47,7 +47,7 @@ Date:         June 2015
 KernelVersion: 4.3
 Contact:       Christian Gromm <christian.gromm@microchip.com>
 Description:
-               Indicates the type of peripherial interface the current device
+               Indicates the type of peripheral interface the current device
                uses.
 Users:
 
index 0a13d8d0fa392c4842048df1976fd42570456c2e..dc3fb25b52aab246ba9c2d14cf7ca940be3e9e54 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/slab.h>
 #include <linux/device.h>
 #include <linux/cdev.h>
+#include <linux/poll.h>
 #include <linux/kfifo.h>
 #include <linux/uaccess.h>
 #include <linux/idr.h>
@@ -27,6 +28,7 @@ static dev_t aim_devno;
 static struct class *aim_class;
 static struct ida minor_id;
 static unsigned int major;
+static struct most_aim cdev_aim;
 
 struct aim_channel {
        wait_queue_head_t wq;
@@ -44,11 +46,11 @@ struct aim_channel {
        atomic_t access_ref;
        struct list_head list;
 };
+
 #define to_channel(d) container_of(d, struct aim_channel, cdev)
 static struct list_head channel_list;
 static spinlock_t ch_list_lock;
 
-
 static struct aim_channel *get_channel(struct most_interface *iface, int id)
 {
        struct aim_channel *channel, *tmp;
@@ -85,8 +87,8 @@ static int aim_open(struct inode *inode, struct file *filp)
        filp->private_data = channel;
 
        if (((channel->cfg->direction == MOST_CH_RX) &&
-            ((filp->f_flags & O_ACCMODE) != O_RDONLY))
-           || ((channel->cfg->direction == MOST_CH_TX) &&
+            ((filp->f_flags & O_ACCMODE) != O_RDONLY)) ||
+            ((channel->cfg->direction == MOST_CH_TX) &&
                ((filp->f_flags & O_ACCMODE) != O_WRONLY))) {
                pr_info("WARN: Access flags mismatch\n");
                return -EACCES;
@@ -97,7 +99,8 @@ static int aim_open(struct inode *inode, struct file *filp)
                return -EBUSY;
        }
 
-       ret = most_start_channel(channel->iface, channel->channel_id);
+       ret = most_start_channel(channel->iface, channel->channel_id,
+                                &cdev_aim);
        if (ret)
                atomic_dec(&channel->access_ref);
        return ret;
@@ -131,11 +134,11 @@ static int aim_close(struct inode *inode, struct file *filp)
        }
        mutex_unlock(&channel->io_mutex);
 
-       while (0 != kfifo_out((struct kfifo *)&channel->fifo, &mbo, 1))
+       while (kfifo_out((struct kfifo *)&channel->fifo, &mbo, 1))
                most_put_mbo(mbo);
-       if (channel->keep_mbo == true)
+       if (channel->keep_mbo)
                most_put_mbo(channel->stacked_mbo);
-       ret = most_stop_channel(channel->iface, channel->channel_id);
+       ret = most_stop_channel(channel->iface, channel->channel_id, &cdev_aim);
        atomic_dec(&channel->access_ref);
        wake_up_interruptible(&channel->wq);
        return ret;
@@ -165,16 +168,17 @@ static ssize_t aim_write(struct file *filp, const char __user *buf,
        }
        mutex_unlock(&channel->io_mutex);
 
-       mbo = most_get_mbo(channel->iface, channel->channel_id);
+       mbo = most_get_mbo(channel->iface, channel->channel_id, &cdev_aim);
 
-       if (!mbo && channel->dev) {
+       if (!mbo) {
                if ((filp->f_flags & O_NONBLOCK))
                        return -EAGAIN;
                if (wait_event_interruptible(
                            channel->wq,
                            (mbo = most_get_mbo(channel->iface,
-                                               channel->channel_id)) ||
-                           (channel->dev == NULL)))
+                                               channel->channel_id,
+                                               &cdev_aim)) ||
+                           (!channel->dev)))
                        return -ERESTARTSYS;
        }
 
@@ -204,8 +208,7 @@ static ssize_t aim_write(struct file *filp, const char __user *buf,
        }
        return actual_len - retval;
 error:
-       if (mbo)
-               most_put_mbo(mbo);
+       most_put_mbo(mbo);
        return err;
 }
 
@@ -224,18 +227,17 @@ aim_read(struct file *filp, char __user *buf, size_t count, loff_t *offset)
        struct mbo *mbo;
        struct aim_channel *channel = filp->private_data;
 
-       if (channel->keep_mbo == true) {
+       if (channel->keep_mbo) {
                mbo = channel->stacked_mbo;
                channel->keep_mbo = false;
                goto start_copy;
        }
-       while ((0 == kfifo_out(&channel->fifo, &mbo, 1))
-              && (channel->dev != NULL)) {
+       while ((!kfifo_out(&channel->fifo, &mbo, 1)) && (channel->dev)) {
                if (filp->f_flags & O_NONBLOCK)
                        return -EAGAIN;
                if (wait_event_interruptible(channel->wq,
                                             (!kfifo_is_empty(&channel->fifo) ||
-                                             (channel->dev == NULL))))
+                                             (!channel->dev))))
                        return -ERESTARTSYS;
        }
 
@@ -259,7 +261,7 @@ start_copy:
 
        retval = not_copied ? proc_len - not_copied : proc_len;
 
-       if (channel->keep_mbo == true) {
+       if (channel->keep_mbo) {
                channel->mbo_offs = retval;
                channel->stacked_mbo = mbo;
        } else {
@@ -270,6 +272,28 @@ start_copy:
        return retval;
 }
 
+static inline bool __must_check IS_ERR_OR_FALSE(int x)
+{
+       return x <= 0;
+}
+
+static unsigned int aim_poll(struct file *filp, poll_table *wait)
+{
+       struct aim_channel *c = filp->private_data;
+       unsigned int mask = 0;
+
+       poll_wait(filp, &c->wq, wait);
+
+       if (c->cfg->direction == MOST_CH_RX) {
+               if (!kfifo_is_empty(&c->fifo))
+                       mask |= POLLIN | POLLRDNORM;
+       } else {
+               if (!IS_ERR_OR_FALSE(channel_has_mbo(c->iface, c->channel_id)))
+                       mask |= POLLOUT | POLLWRNORM;
+       }
+       return mask;
+}
+
 /**
  * Initialization of struct file_operations
  */
@@ -279,6 +303,7 @@ static const struct file_operations channel_fops = {
        .write = aim_write,
        .open = aim_open,
        .release = aim_close,
+       .poll = aim_poll,
 };
 
 /**
@@ -300,7 +325,7 @@ static int aim_disconnect_channel(struct most_interface *iface, int channel_id)
        }
 
        channel = get_channel(iface, channel_id);
-       if (channel == NULL)
+       if (!channel)
                return -ENXIO;
 
        mutex_lock(&channel->io_mutex);
@@ -337,7 +362,7 @@ static int aim_rx_completion(struct mbo *mbo)
                return -EINVAL;
 
        channel = get_channel(mbo->ifp, mbo->hdm_channel_id);
-       if (channel == NULL)
+       if (!channel)
                return -ENXIO;
 
        kfifo_in(&channel->fifo, &mbo, 1);
@@ -370,7 +395,7 @@ static int aim_tx_completion(struct most_interface *iface, int channel_id)
        }
 
        channel = get_channel(iface, channel_id);
-       if (channel == NULL)
+       if (!channel)
                return -ENXIO;
        wake_up_interruptible(&channel->wq);
        return 0;
@@ -413,7 +438,6 @@ static int aim_probe(struct most_interface *iface, int channel_id,
 
        channel = kzalloc(sizeof(*channel), GFP_KERNEL);
        if (!channel) {
-               pr_info("failed to alloc channel object\n");
                retval = -ENOMEM;
                goto error_alloc_channel;
        }
index c8ab2399faad9b79aab6acbd0ac3dfec5314bc2a..3c7beb03871daa866cc018a663d05d4b0468b3af 100644 (file)
@@ -24,7 +24,6 @@
 #include "mostcore.h"
 #include "networking.h"
 
-
 #define MEP_HDR_LEN 8
 #define MDP_HDR_LEN 16
 #define MAMAC_DATA_LEN (1024 - MDP_HDR_LEN)
@@ -47,8 +46,6 @@
 #define HB(value)              ((u8)((u16)(value) >> 8))
 #define LB(value)              ((u8)(value))
 
-
-
 #define EXTRACT_BIT_SET(bitset_name, value) \
        (((value) >> bitset_name##_SHIFT) & bitset_name##_MASK)
 
@@ -81,7 +78,6 @@ static struct list_head net_devices = LIST_HEAD_INIT(net_devices);
 static struct spinlock list_lock;
 static struct most_aim aim;
 
-
 static int skb_to_mamac(const struct sk_buff *skb, struct mbo *mbo)
 {
        u8 *buff = mbo->virt_address;
@@ -186,7 +182,7 @@ static int most_nd_open(struct net_device *dev)
 {
        struct net_dev_context *nd = dev->ml_priv;
 
-       pr_info("open net device %s\n", dev->name);
+       netdev_info(dev, "open net device\n");
 
        BUG_ON(nd->dev != dev);
 
@@ -195,14 +191,14 @@ static int most_nd_open(struct net_device *dev)
 
        BUG_ON(!nd->tx.linked || !nd->rx.linked);
 
-       if (most_start_channel(nd->iface, nd->rx.ch_id)) {
-               pr_err("most_start_channel() failed\n");
+       if (most_start_channel(nd->iface, nd->rx.ch_id, &aim)) {
+               netdev_err(dev, "most_start_channel() failed\n");
                return -EBUSY;
        }
 
-       if (most_start_channel(nd->iface, nd->tx.ch_id)) {
-               pr_err("most_start_channel() failed\n");
-               most_stop_channel(nd->iface, nd->rx.ch_id);
+       if (most_start_channel(nd->iface, nd->tx.ch_id, &aim)) {
+               netdev_err(dev, "most_start_channel() failed\n");
+               most_stop_channel(nd->iface, nd->rx.ch_id, &aim);
                return -EBUSY;
        }
 
@@ -222,14 +218,14 @@ static int most_nd_stop(struct net_device *dev)
 {
        struct net_dev_context *nd = dev->ml_priv;
 
-       pr_info("stop net device %s\n", dev->name);
+       netdev_info(dev, "stop net device\n");
 
        BUG_ON(nd->dev != dev);
        netif_stop_queue(dev);
 
        if (nd->channels_opened) {
-               most_stop_channel(nd->iface, nd->rx.ch_id);
-               most_stop_channel(nd->iface, nd->tx.ch_id);
+               most_stop_channel(nd->iface, nd->rx.ch_id, &aim);
+               most_stop_channel(nd->iface, nd->tx.ch_id, &aim);
                nd->channels_opened = false;
        }
 
@@ -245,7 +241,7 @@ static netdev_tx_t most_nd_start_xmit(struct sk_buff *skb,
 
        BUG_ON(nd->dev != dev);
 
-       mbo = most_get_mbo(nd->iface, nd->tx.ch_id);
+       mbo = most_get_mbo(nd->iface, nd->tx.ch_id, &aim);
 
        if (!mbo) {
                netif_stop_queue(dev);
@@ -281,7 +277,7 @@ static const struct net_device_ops most_nd_ops = {
 
 static void most_nd_setup(struct net_device *dev)
 {
-       pr_info("setup net device %s\n", dev->name);
+       netdev_info(dev, "setup net device\n");
        ether_setup(dev);
        dev->netdev_ops = &most_nd_ops;
 }
@@ -295,7 +291,7 @@ static void most_net_rm_netdev_safe(struct net_dev_context *nd)
 
        unregister_netdev(nd->dev);
        free_netdev(nd->dev);
-       nd->dev = 0;
+       nd->dev = NULL;
 }
 
 static struct net_dev_context *get_net_dev_context(
@@ -349,7 +345,8 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx,
 
        if (nd->tx.linked || nd->rx.linked) {
                struct net_device *dev =
-                       alloc_netdev(0, "meth%d", NET_NAME_UNKNOWN, most_nd_setup);
+                       alloc_netdev(0, "meth%d", NET_NAME_UNKNOWN,
+                                    most_nd_setup);
 
                if (!dev) {
                        pr_err("no memory for net_device\n");
@@ -357,10 +354,13 @@ static int aim_probe_channel(struct most_interface *iface, int channel_idx,
                }
 
                nd->dev = dev;
+               ch->ch_id = channel_idx;
+               ch->linked = true;
 
                dev->ml_priv = nd;
                if (register_netdev(dev)) {
                        pr_err("registering net device failed\n");
+                       ch->linked = false;
                        free_netdev(dev);
                        return -EINVAL;
                }
@@ -428,7 +428,7 @@ static int aim_rx_data(struct mbo *mbo)
        const u32 zero = 0;
        struct net_dev_context *nd;
        char *buf = mbo->virt_address;
-       uint32_t len = mbo->processed_length;
+       u32 len = mbo->processed_length;
        struct sk_buff *skb;
        struct net_device *dev;
 
@@ -464,7 +464,7 @@ static int aim_rx_data(struct mbo *mbo)
 
        if (nd->is_mamac) {
                /* dest */
-               memcpy(skb_put(skb, ETH_ALEN), dev->dev_addr, ETH_ALEN);
+               ether_addr_copy(skb_put(skb, ETH_ALEN), dev->dev_addr);
 
                /* src */
                memcpy(skb_put(skb, 4), &zero, 4);
@@ -491,15 +491,18 @@ out:
        return 0;
 }
 
+static struct most_aim aim = {
+       .name = "networking",
+       .probe_channel = aim_probe_channel,
+       .disconnect_channel = aim_disconnect_channel,
+       .tx_completion = aim_resume_tx_channel,
+       .rx_completion = aim_rx_data,
+};
+
 static int __init most_net_init(void)
 {
        pr_info("most_net_init()\n");
        spin_lock_init(&list_lock);
-       aim.name = "networking";
-       aim.probe_channel = aim_probe_channel;
-       aim.disconnect_channel = aim_disconnect_channel;
-       aim.tx_completion = aim_resume_tx_channel;
-       aim.rx_completion = aim_rx_data;
        return most_register_aim(&aim);
 }
 
@@ -548,7 +551,7 @@ void most_deliver_netinfo(struct most_interface *iface,
                return;
 
        if (mac_addr)
-               memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
+               ether_addr_copy(dev->dev_addr, mac_addr);
 
        if (nd->link_stat != link_stat) {
                nd->link_stat = link_stat;
index 860302eebda7d1935e557bf608bf427180aab65e..9c645801cff4dbd18c0da93faefe984e6013a688 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
+#include <sound/pcm_params.h>
 #include <linux/sched.h>
 #include <linux/kthread.h>
 #include <mostcore.h>
@@ -26,6 +27,7 @@
 #define DRIVER_NAME "sound"
 
 static struct list_head dev_list;
+static struct most_aim audio_aim;
 
 /**
  * struct channel - private structure to keep channel specific data
@@ -44,6 +46,7 @@ static struct list_head dev_list;
  */
 struct channel {
        struct snd_pcm_substream *substream;
+       struct snd_pcm_hardware pcm_hardware;
        struct most_interface *iface;
        struct most_channel_config *cfg;
        struct snd_card *card;
@@ -65,18 +68,6 @@ struct channel {
                       SNDRV_PCM_INFO_INTERLEAVED | \
                       SNDRV_PCM_INFO_BLOCK_TRANSFER)
 
-/**
- * Initialization of struct snd_pcm_hardware
- */
-static struct snd_pcm_hardware pcm_hardware_template = {
-       .info               = MOST_PCM_INFO,
-       .rates              = SNDRV_PCM_RATE_48000,
-       .rate_min           = 48000,
-       .rate_max           = 48000,
-       .channels_min       = 1,
-       .channels_max       = 8,
-};
-
 #define swap16(val) ( \
        (((u16)(val) << 8) & (u16)0xFF00) | \
        (((u16)(val) >> 8) & (u16)0x00FF))
@@ -240,8 +231,6 @@ static int playback_thread(void *data)
 {
        struct channel *const channel = data;
 
-       pr_info("playback thread started\n");
-
        while (!kthread_should_stop()) {
                struct mbo *mbo = NULL;
                bool period_elapsed = false;
@@ -250,8 +239,9 @@ static int playback_thread(void *data)
                wait_event_interruptible(
                        channel->playback_waitq,
                        kthread_should_stop() ||
-                       (mbo = most_get_mbo(channel->iface, channel->id)));
-
+                       (channel->is_stream_running &&
+                        (mbo = most_get_mbo(channel->iface, channel->id,
+                                            &audio_aim))));
                if (!mbo)
                        continue;
 
@@ -286,32 +276,25 @@ static int pcm_open(struct snd_pcm_substream *substream)
        struct snd_pcm_runtime *runtime = substream->runtime;
        struct most_channel_config *cfg = channel->cfg;
 
-       pr_info("pcm_open(), %s\n", substream->name);
-
        channel->substream = substream;
 
        if (cfg->direction == MOST_CH_TX) {
-               init_waitqueue_head(&channel->playback_waitq);
-               channel->playback_task = kthread_run(&playback_thread, channel,
+               channel->playback_task = kthread_run(playback_thread, channel,
                                                     "most_audio_playback");
-               if (IS_ERR(channel->playback_task))
+               if (IS_ERR(channel->playback_task)) {
+                       pr_err("Couldn't start thread\n");
                        return PTR_ERR(channel->playback_task);
+               }
        }
 
-       if (most_start_channel(channel->iface, channel->id)) {
+       if (most_start_channel(channel->iface, channel->id, &audio_aim)) {
                pr_err("most_start_channel() failed!\n");
                if (cfg->direction == MOST_CH_TX)
                        kthread_stop(channel->playback_task);
                return -EBUSY;
        }
 
-       runtime->hw = pcm_hardware_template;
-       runtime->hw.buffer_bytes_max = cfg->num_buffers * cfg->buffer_size;
-       runtime->hw.period_bytes_min = cfg->buffer_size;
-       runtime->hw.period_bytes_max = cfg->buffer_size;
-       runtime->hw.periods_min = 1;
-       runtime->hw.periods_max = cfg->num_buffers;
-
+       runtime->hw = channel->pcm_hardware;
        return 0;
 }
 
@@ -329,11 +312,9 @@ static int pcm_close(struct snd_pcm_substream *substream)
 {
        struct channel *channel = substream->private_data;
 
-       pr_info("pcm_close(), %s\n", substream->name);
-
        if (channel->cfg->direction == MOST_CH_TX)
                kthread_stop(channel->playback_task);
-       most_stop_channel(channel->iface, channel->id);
+       most_stop_channel(channel->iface, channel->id, &audio_aim);
 
        return 0;
 }
@@ -353,8 +334,13 @@ static int pcm_close(struct snd_pcm_substream *substream)
 static int pcm_hw_params(struct snd_pcm_substream *substream,
                         struct snd_pcm_hw_params *hw_params)
 {
-       pr_info("pcm_hw_params()\n");
+       struct channel *channel = substream->private_data;
 
+       if ((params_channels(hw_params) > channel->pcm_hardware.channels_max) ||
+           (params_channels(hw_params) < channel->pcm_hardware.channels_min)) {
+               pr_err("Requested number of channels not supported.\n");
+               return -EINVAL;
+       }
        return snd_pcm_lib_alloc_vmalloc_buffer(substream,
                                                params_buffer_bytes(hw_params));
 }
@@ -370,8 +356,6 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
  */
 static int pcm_hw_free(struct snd_pcm_substream *substream)
 {
-       pr_info("pcm_hw_free()\n");
-
        return snd_pcm_lib_free_vmalloc_buffer(substream);
 }
 
@@ -441,6 +425,7 @@ static int pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
                channel->is_stream_running = true;
+               wake_up_interruptible(&channel->playback_waitq);
                return 0;
 
        case SNDRV_PCM_TRIGGER_STOP:
@@ -485,8 +470,7 @@ static struct snd_pcm_ops pcm_ops = {
        .mmap       = snd_pcm_lib_mmap_vmalloc,
 };
 
-
-int split_arg_list(char *buf, char **card_name, char **pcm_format)
+static int split_arg_list(char *buf, char **card_name, char **pcm_format)
 {
        *card_name = strsep(&buf, ".");
        if (!*card_name)
@@ -497,31 +481,59 @@ int split_arg_list(char *buf, char **card_name, char **pcm_format)
        return 0;
 }
 
-int audio_set_pcm_format(char *pcm_format, struct most_channel_config *cfg)
+static int audio_set_hw_params(struct snd_pcm_hardware *pcm_hw,
+                              char *pcm_format,
+                              struct most_channel_config *cfg)
 {
+       pcm_hw->info = MOST_PCM_INFO;
+       pcm_hw->rates = SNDRV_PCM_RATE_48000;
+       pcm_hw->rate_min = 48000;
+       pcm_hw->rate_max = 48000;
+       pcm_hw->buffer_bytes_max = cfg->num_buffers * cfg->buffer_size;
+       pcm_hw->period_bytes_min = cfg->buffer_size;
+       pcm_hw->period_bytes_max = cfg->buffer_size;
+       pcm_hw->periods_min = 1;
+       pcm_hw->periods_max = cfg->num_buffers;
+
        if (!strcmp(pcm_format, "1x8")) {
                if (cfg->subbuffer_size != 1)
                        goto error;
                pr_info("PCM format is 8-bit mono\n");
-               pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S8;
+               pcm_hw->channels_min = 1;
+               pcm_hw->channels_max = 1;
+               pcm_hw->formats = SNDRV_PCM_FMTBIT_S8;
        } else if (!strcmp(pcm_format, "2x16")) {
                if (cfg->subbuffer_size != 4)
                        goto error;
                pr_info("PCM format is 16-bit stereo\n");
-               pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S16_LE |
-                                               SNDRV_PCM_FMTBIT_S16_BE;
+               pcm_hw->channels_min = 2;
+               pcm_hw->channels_max = 2;
+               pcm_hw->formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                 SNDRV_PCM_FMTBIT_S16_BE;
        } else if (!strcmp(pcm_format, "2x24")) {
                if (cfg->subbuffer_size != 6)
                        goto error;
                pr_info("PCM format is 24-bit stereo\n");
-               pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S24_3LE |
-                                               SNDRV_PCM_FMTBIT_S24_3BE;
+               pcm_hw->channels_min = 2;
+               pcm_hw->channels_max = 2;
+               pcm_hw->formats = SNDRV_PCM_FMTBIT_S24_3LE |
+                                 SNDRV_PCM_FMTBIT_S24_3BE;
        } else if (!strcmp(pcm_format, "2x32")) {
                if (cfg->subbuffer_size != 8)
                        goto error;
                pr_info("PCM format is 32-bit stereo\n");
-               pcm_hardware_template.formats = SNDRV_PCM_FMTBIT_S32_LE |
-                                               SNDRV_PCM_FMTBIT_S32_BE;
+               pcm_hw->channels_min = 2;
+               pcm_hw->channels_max = 2;
+               pcm_hw->formats = SNDRV_PCM_FMTBIT_S32_LE |
+                                 SNDRV_PCM_FMTBIT_S32_BE;
+       } else if (!strcmp(pcm_format, "6x16")) {
+               if (cfg->subbuffer_size != 12)
+                       goto error;
+               pr_info("PCM format is 16-bit 5.1 multi channel\n");
+               pcm_hw->channels_min = 6;
+               pcm_hw->channels_max = 6;
+               pcm_hw->formats = SNDRV_PCM_FMTBIT_S16_LE |
+                                 SNDRV_PCM_FMTBIT_S16_BE;
        } else {
                pr_err("PCM format %s not supported\n", pcm_format);
                return -EIO;
@@ -559,8 +571,6 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
        char *card_name;
        char *pcm_format;
 
-       pr_info("sound_probe_channel()\n");
-
        if (!iface)
                return -EINVAL;
 
@@ -588,8 +598,6 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
                pr_info("PCM format missing\n");
                return ret;
        }
-       if (audio_set_pcm_format(pcm_format, cfg))
-               return ret;
 
        ret = snd_card_new(NULL, -1, card_name, THIS_MODULE,
                           sizeof(*channel), &card);
@@ -601,9 +609,13 @@ static int audio_probe_channel(struct most_interface *iface, int channel_id,
        channel->cfg = cfg;
        channel->iface = iface;
        channel->id = channel_id;
+       init_waitqueue_head(&channel->playback_waitq);
+
+       if (audio_set_hw_params(&channel->pcm_hardware, pcm_format, cfg))
+               goto err_free_card;
 
        snprintf(card->driver, sizeof(card->driver), "%s", DRIVER_NAME);
-       snprintf(card->shortname, sizeof(card->shortname), "MOST:%d",
+       snprintf(card->shortname, sizeof(card->shortname), "Microchip MOST:%d",
                 card->number);
        snprintf(card->longname, sizeof(card->longname), "%s at %s, ch %d",
                 card->shortname, iface->description, channel_id);
@@ -644,8 +656,6 @@ static int audio_disconnect_channel(struct most_interface *iface,
 {
        struct channel *channel;
 
-       pr_info("sound_disconnect_channel()\n");
-
        channel = get_channel(iface, channel_id);
        if (!channel) {
                pr_err("sound_disconnect_channel(), invalid channel %d\n",
index 28aa948d66093a71a3a8f1df5011ba34662bb01f..69a7524b466c95e83ca5e75a634b332e5ae04f03 100644 (file)
@@ -3,4 +3,3 @@ obj-$(CONFIG_AIM_V4L2) += aim_v4l2.o
 aim_v4l2-objs := video.o
 
 ccflags-y += -Idrivers/staging/most/mostcore/
-ccflags-y += -Idrivers/media/video
index d9687910e4a4138052d8a67721e76bf644d0a804..13abf7c275a4e9809c5e2eb02faf1a135493a5af 100644 (file)
@@ -29,9 +29,9 @@
 
 #include "mostcore.h"
 
-
 #define V4L2_AIM_MAX_INPUT  1
 
+static struct most_aim aim_info;
 
 struct most_video_dev {
        struct most_interface *iface;
@@ -59,11 +59,8 @@ struct aim_fh {
        u32 offs;
 };
 
-
 static struct list_head video_devices = LIST_HEAD_INIT(video_devices);
 static struct spinlock list_lock;
-static struct most_aim aim_info;
-
 
 static inline bool data_ready(struct most_video_dev *mdev)
 {
@@ -75,7 +72,6 @@ static inline struct mbo *get_top_mbo(struct most_video_dev *mdev)
        return list_first_entry(&mdev->pending_mbos, struct mbo, list);
 }
 
-
 static int aim_vdev_open(struct file *filp)
 {
        int ret;
@@ -92,7 +88,7 @@ static int aim_vdev_open(struct file *filp)
                return -EINVAL;
        }
 
-       fh = kzalloc(sizeof(struct aim_fh), GFP_KERNEL);
+       fh = kzalloc(sizeof(*fh), GFP_KERNEL);
        if (!fh)
                return -ENOMEM;
 
@@ -108,7 +104,7 @@ static int aim_vdev_open(struct file *filp)
 
        v4l2_fh_add(&fh->fh);
 
-       ret = most_start_channel(mdev->iface, mdev->ch_idx);
+       ret = most_start_channel(mdev->iface, mdev->ch_idx, &aim_info);
        if (ret) {
                pr_err("most_start_channel() failed\n");
                goto err_rm;
@@ -152,7 +148,7 @@ static int aim_vdev_close(struct file *filp)
                spin_lock(&mdev->list_lock);
        }
        spin_unlock(&mdev->list_lock);
-       most_stop_channel(mdev->iface, mdev->ch_idx);
+       most_stop_channel(mdev->iface, mdev->ch_idx, &aim_info);
        mdev->mute = false;
 
        v4l2_fh_del(&fh->fh);
@@ -243,28 +239,6 @@ static void aim_set_format_struct(struct v4l2_format *f)
 static int aim_set_format(struct most_video_dev *mdev, unsigned int cmd,
                          struct v4l2_format *format)
 {
-#if 0
-       u32 const pixfmt = format->fmt.pix.pixelformat;
-       const char *fmt;
-
-       if (pixfmt != V4L2_PIX_FMT_MPEG) {
-               if (cmd == VIDIOC_TRY_FMT)
-                       fmt = KERN_ERR "try %c%c%c%c failed\n";
-               else
-                       fmt = KERN_ERR "set %c%c%c%c failed\n";
-       } else {
-               if (cmd == VIDIOC_TRY_FMT)
-                       fmt = KERN_ERR "try %c%c%c%c\n";
-               else
-                       fmt = KERN_ERR "set %c%c%c%c\n";
-       }
-       printk(fmt,
-              (pixfmt) & 255,
-              (pixfmt >> 8) & 255,
-              (pixfmt >> 16) & 255,
-              (pixfmt >> 24) & 255);
-#endif
-
        if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_MPEG)
                return -EINVAL;
 
@@ -276,7 +250,6 @@ static int aim_set_format(struct most_video_dev *mdev, unsigned int cmd,
        return 0;
 }
 
-
 static int vidioc_querycap(struct file *file, void  *priv,
                           struct v4l2_capability *cap)
 {
@@ -430,7 +403,7 @@ static struct most_video_dev *get_aim_dev(
                }
        }
        spin_unlock(&list_lock);
-       return 0;
+       return NULL;
 }
 
 static int aim_rx_data(struct mbo *mbo)
@@ -496,7 +469,6 @@ static void aim_unregister_videodev(struct most_video_dev *mdev)
        video_unregister_device(mdev->vdev);
 }
 
-
 static void aim_v4l2_dev_release(struct v4l2_device *v4l2_dev)
 {
        struct most_video_dev *mdev =
@@ -590,14 +562,16 @@ static int aim_disconnect_channel(struct most_interface *iface,
        return 0;
 }
 
+static struct most_aim aim_info = {
+       .name = "v4l",
+       .probe_channel = aim_probe_channel,
+       .disconnect_channel = aim_disconnect_channel,
+       .rx_completion = aim_rx_data,
+};
+
 static int __init aim_init(void)
 {
        spin_lock_init(&list_lock);
-
-       aim_info.name = "v4l";
-       aim_info.probe_channel = aim_probe_channel;
-       aim_info.disconnect_channel = aim_disconnect_channel;
-       aim_info.rx_completion = aim_rx_data;
        return most_register_aim(&aim_info);
 }
 
index fc548769479b7a0c583a5028a38909a51f537caa..28a0e1791600869f247e979aff15759c02eef447 100644 (file)
@@ -9,7 +9,7 @@ config HDM_DIM2
 
        ---help---
          Say Y here if you want to connect via MediaLB to network transceiver.
-         This device driver is platform dependent and needs an addtional
+         This device driver is platform dependent and needs an additional
          platform driver to be installed. For more information contact
          maintainer of this driver.
 
index a54cf2cedac3c4a0608466415f7b14ee3ef2eef7..c915c44f025e55d74fabdabdf83f0095f1e26694 100644 (file)
@@ -19,7 +19,6 @@
 #include "dim2_reg.h"
 #include <linux/stddef.h>
 
-
 /*
  * The number of frames per sub-buffer for synchronous channels.
  * Allowed values: 1, 2, 4, 8, 16, 32, 64.
@@ -51,7 +50,6 @@
  */
 #define DBR_MAP_SIZE 2
 
-
 /* -------------------------------------------------------------------------- */
 /* not configurable area */
 
 #define MLB_CAT 0x80
 #define AHB_CAT 0x88
 
-#define DBR_SIZE  (16*1024) /* specified by IP */
+#define DBR_SIZE  (16 * 1024) /* specified by IP */
 #define DBR_BLOCK_SIZE  (DBR_SIZE / 32 / DBR_MAP_SIZE)
 
-
 /* -------------------------------------------------------------------------- */
 /* generic helper functions and macros */
 
@@ -81,7 +78,6 @@ static inline bool dim_on_error(u8 error_id, const char *error_message)
        return false;
 }
 
-
 /* -------------------------------------------------------------------------- */
 /* types and local variables */
 
@@ -94,7 +90,6 @@ struct lld_global_vars_t {
 
 static struct lld_global_vars_t g = { false };
 
-
 /* -------------------------------------------------------------------------- */
 
 static int dbr_get_mask_size(u16 size)
@@ -134,7 +129,7 @@ static int alloc_dbr(u16 size)
                                return block_idx * DBR_BLOCK_SIZE;
                        }
                        block_idx += mask_size;
-                       /* do shift left with 2 steps for case mask_size == 32 */
+                       /* do shift left with 2 steps in case mask_size == 32 */
                        mask <<= mask_size - 1;
                } while ((mask <<= 1) != 0);
        }
@@ -327,7 +322,6 @@ static void dim2_start_isoc_sync(u8 ch_addr, u8 idx, u32 buf_addr,
        dim2_write_ctr_mask(ADT + ch_addr, mask, adt);
 }
 
-
 static void dim2_clear_ctram(void)
 {
        u32 ctr_addr;
@@ -499,22 +493,6 @@ static void dim2_initialize(bool enable_6pin, u8 mlb_clock)
        DIMCB_IoWrite(&g.dim2->ACTL,
                      ACTL_DMA_MODE_VAL_DMA_MODE_1 << ACTL_DMA_MODE_BIT |
                      true << ACTL_SCE_BIT);
-
-#if 0
-       DIMCB_IoWrite(&g.dim2->MIEN,
-                     bit_mask(MIEN_CTX_BREAK_BIT) |
-                     bit_mask(MIEN_CTX_PE_BIT) |
-                     bit_mask(MIEN_CTX_DONE_BIT) |
-                     bit_mask(MIEN_CRX_BREAK_BIT) |
-                     bit_mask(MIEN_CRX_PE_BIT) |
-                     bit_mask(MIEN_CRX_DONE_BIT) |
-                     bit_mask(MIEN_ATX_BREAK_BIT) |
-                     bit_mask(MIEN_ATX_PE_BIT) |
-                     bit_mask(MIEN_ATX_DONE_BIT) |
-                     bit_mask(MIEN_ARX_BREAK_BIT) |
-                     bit_mask(MIEN_ARX_PE_BIT) |
-                     bit_mask(MIEN_ARX_DONE_BIT));
-#endif
 }
 
 static bool dim2_is_mlb_locked(void)
@@ -530,7 +508,6 @@ static bool dim2_is_mlb_locked(void)
               (DIMCB_IoRead(&g.dim2->MLBC0) & mask0) != 0;
 }
 
-
 /* -------------------------------------------------------------------------- */
 /* channel help routines */
 
@@ -559,7 +536,6 @@ static inline bool service_channel(u8 ch_addr, u8 idx)
        return true;
 }
 
-
 /* -------------------------------------------------------------------------- */
 /* channel init routines */
 
@@ -639,7 +615,8 @@ static bool channel_start(struct dim_channel *ch, u32 buf_addr, u16 buf_size)
        if (ch->packet_length || ch->bytes_per_frame)
                dim2_start_isoc_sync(ch->addr, state->idx1, buf_addr, buf_size);
        else
-               dim2_start_ctrl_async(ch->addr, state->idx1, buf_addr, buf_size);
+               dim2_start_ctrl_async(ch->addr, state->idx1, buf_addr,
+                                     buf_size);
        state->idx1 ^= 1;
 
        return true;
@@ -670,7 +647,6 @@ static bool channel_detach_buffers(struct dim_channel *ch, u16 buffers_number)
        return true;
 }
 
-
 /* -------------------------------------------------------------------------- */
 /* API */
 
@@ -687,7 +663,8 @@ u8 DIM_Startup(void *dim_base_address, u32 mlb_clock)
                return DIM_INIT_ERR_MLB_CLOCK;
 
        g.dim2 = dim_base_address;
-       g.dbr_map[0] = g.dbr_map[1] = 0;
+       g.dbr_map[0] = 0;
+       g.dbr_map[1] = 0;
 
        dim2_initialize(mlb_clock >= 3, mlb_clock);
 
@@ -766,14 +743,14 @@ u8 DIM_InitControl(struct dim_channel *ch, u8 is_tx, u16 ch_address,
                   u16 max_buffer_size)
 {
        return init_ctrl_async(ch, CAT_CT_VAL_CONTROL, is_tx, ch_address,
-                              max_buffer_size * 2);
+                              max_buffer_size);
 }
 
 u8 DIM_InitAsync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
                 u16 max_buffer_size)
 {
        return init_ctrl_async(ch, CAT_CT_VAL_ASYNC, is_tx, ch_address,
-                              max_buffer_size * 2);
+                              max_buffer_size);
 }
 
 u8 DIM_InitIsoc(struct dim_channel *ch, u8 is_tx, u16 ch_address,
@@ -855,11 +832,11 @@ void DIM_ServiceIrq(struct dim_channel *const *channels)
        }
 
        /*
-        * Use while-loop and a flag to make sure the age is changed back at least once,
-        * otherwise the interrupt may never come if CPU generates interrupt on changing age.
-        *
-        * This cycle runs not more than number of channels, because service_interrupts
-        * routine doesn't start the channel again.
+        * Use while-loop and a flag to make sure the age is changed back at
+        * least once, otherwise the interrupt may never come if CPU generates
+        * interrupt on changing age.
+        * This cycle runs not more than number of channels, because
+        * channel_service_interrupt() routine doesn't start the channel again.
         */
        do {
                struct dim_channel *const *ch = channels;
@@ -886,7 +863,7 @@ u8 DIM_ServiceChannel(struct dim_channel *ch)
 }
 
 struct dim_ch_state_t *DIM_GetChannelState(struct dim_channel *ch,
-               struct dim_ch_state_t *state_ptr)
+                                          struct dim_ch_state_t *state_ptr)
 {
        if (!ch || !state_ptr)
                return NULL;
@@ -900,7 +877,8 @@ struct dim_ch_state_t *DIM_GetChannelState(struct dim_channel *ch,
 bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr, u16 buffer_size)
 {
        if (!ch)
-               return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED, "Bad channel");
+               return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED,
+                                   "Bad channel");
 
        return channel_start(ch, buffer_addr, buffer_size);
 }
@@ -908,12 +886,8 @@ bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr, u16 buffer_size)
 bool DIM_DetachBuffers(struct dim_channel *ch, u16 buffers_number)
 {
        if (!ch)
-               return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED, "Bad channel");
+               return dim_on_error(DIM_ERR_DRIVER_NOT_INITIALIZED,
+                                   "Bad channel");
 
        return channel_detach_buffers(ch, buffers_number);
 }
-
-u32 DIM_ReadRegister(u8 register_index)
-{
-       return DIMCB_IoRead((u32 *)g.dim2 + register_index);
-}
index 8929af9712ef6808236b7d176e5ed28218a48946..ebb7d87a45fcfaede6a6222b81fa871f7cae67de 100644 (file)
@@ -105,17 +105,12 @@ bool DIM_EnqueueBuffer(struct dim_channel *ch, u32 buffer_addr,
 
 bool DIM_DetachBuffers(struct dim_channel *ch, u16 buffers_number);
 
-u32 DIM_ReadRegister(u8 register_index);
-
-
 u32 DIMCB_IoRead(u32 *ptr32);
 
 void DIMCB_IoWrite(u32 *ptr32, u32 value);
 
 void DIMCB_OnError(u8 error_id, const char *error_message);
 
-void DIMCB_OnFail(const char *filename, int linenum);
-
 
 #ifdef __cplusplus
 }
index 6a5a3a2775f3d0961ed27d92671ff80759d892cd..b6fe346f73b00d69116654cf9f9850c4220e8346 100644 (file)
@@ -37,7 +37,7 @@
 #define MAX_BUFFERS_PACKET      32
 #define MAX_BUFFERS_STREAMING   32
 #define MAX_BUF_SIZE_PACKET     2048
-#define MAX_BUF_SIZE_STREAMING  (8*1024)
+#define MAX_BUF_SIZE_STREAMING  (8 * 1024)
 
 /* command line parameter to select clock speed */
 static char *clock_speed;
@@ -165,16 +165,6 @@ void DIMCB_OnError(u8 error_id, const char *error_message)
               error_message);
 }
 
-/**
- * DIMCB_OnFail - callback from HAL to report unrecoverable errors
- * @filename: Source file where the error happened
- * @linenum: Line number of the file where the error happened
- */
-void DIMCB_OnFail(const char *filename, int linenum)
-{
-       pr_err("DIMCB_OnFail: file - %s, line no. - %d\n", filename, linenum);
-}
-
 /**
  * startup_dim - initialize the dim2 interface
  * @pdev: platform device
@@ -210,12 +200,11 @@ static int startup_dim(struct platform_device *pdev)
        }
 
        if (dev->clk_speed == -1) {
-               pr_info("Bad or missing clock speed parameter,"
-                       " using default value: 3072fs\n");
+               pr_info("Bad or missing clock speed parameter, using default value: 3072fs\n");
                dev->clk_speed = CLK_3072FS;
-       } else
+       } else {
                pr_info("Selected clock speed: %s\n", clock_speed);
-
+       }
        if (pdata && pdata->init) {
                int ret = pdata->init(pdata, dev->io_base, dev->clk_speed);
 
@@ -248,7 +237,7 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
        unsigned long flags;
        struct dim_ch_state_t st;
 
-       BUG_ON(hdm_ch == 0);
+       BUG_ON(!hdm_ch);
        BUG_ON(!hdm_ch->is_initialized);
 
        spin_lock_irqsave(&dim_lock, flags);
@@ -289,7 +278,7 @@ static int try_start_dim_transfer(struct hdm_channel *hdm_ch)
  */
 static int deliver_netinfo_thread(void *data)
 {
-       struct dim2_hdm *dev = (struct dim2_hdm *)data;
+       struct dim2_hdm *dev = data;
 
        while (!kthread_should_stop()) {
                wait_event_interruptible(dev->netinfo_waitq,
@@ -346,7 +335,7 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
        unsigned long flags;
        u8 *data;
 
-       BUG_ON(hdm_ch == 0);
+       BUG_ON(!hdm_ch);
        BUG_ON(!hdm_ch->is_initialized);
 
        spin_lock_irqsave(&dim_lock, flags);
@@ -369,8 +358,7 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
                spin_lock_irqsave(&dim_lock, flags);
                if (list_empty(head)) {
                        spin_unlock_irqrestore(&dim_lock, flags);
-                       pr_crit("hard error: started_mbo list is empty "
-                               "whereas DIM2 has sent buffers\n");
+                       pr_crit("hard error: started_mbo list is empty whereas DIM2 has sent buffers\n");
                        break;
                }
 
@@ -397,7 +385,8 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
                                        (u32)data[0] * 256 + data[1] + 2;
 
                                mbo->processed_length =
-                                       min(data_size, (u32)mbo->buffer_length);
+                                       min_t(u32, data_size,
+                                             mbo->buffer_length);
                        } else {
                                mbo->processed_length = mbo->buffer_length;
                        }
@@ -410,7 +399,7 @@ static void service_done_flag(struct dim2_hdm *dev, int ch_idx)
 }
 
 static struct dim_channel **get_active_channels(struct dim2_hdm *dev,
-               struct dim_channel **buffer)
+                                               struct dim_channel **buffer)
 {
        int idx = 0;
        int ch_idx;
@@ -419,7 +408,7 @@ static struct dim_channel **get_active_channels(struct dim2_hdm *dev,
                if (dev->hch[ch_idx].is_initialized)
                        buffer[idx++] = &dev->hch[ch_idx].ch;
        }
-       buffer[idx++] = 0;
+       buffer[idx++] = NULL;
 
        return buffer;
 }
@@ -441,7 +430,7 @@ static void dim2_tasklet_fn(unsigned long data)
                        continue;
 
                spin_lock_irqsave(&dim_lock, flags);
-               DIM_ServiceChannel(&(dev->hch[ch_idx].ch));
+               DIM_ServiceChannel(&dev->hch[ch_idx].ch);
                spin_unlock_irqrestore(&dim_lock, flags);
 
                service_done_flag(dev, ch_idx);
@@ -460,7 +449,7 @@ static void dim2_tasklet_fn(unsigned long data)
  */
 static irqreturn_t dim2_ahb_isr(int irq, void *_dev)
 {
-       struct dim2_hdm *dev = (struct dim2_hdm *)_dev;
+       struct dim2_hdm *dev = _dev;
        struct dim_channel *buffer[DMA_CHANNELS + 1];
        unsigned long flags;
 
@@ -557,7 +546,8 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx,
                        pr_warn("%s: fixed buffer size (%d -> %d)\n",
                                hdm_ch->name, buf_size, new_size);
                spin_lock_irqsave(&dim_lock, flags);
-               hal_ret = DIM_InitControl(&hdm_ch->ch, is_tx, ch_addr, buf_size);
+               hal_ret = DIM_InitControl(&hdm_ch->ch, is_tx, ch_addr,
+                                         buf_size);
                break;
        case MOST_CH_ASYNC:
                new_size = DIM_NormCtrlAsyncBufferSize(buf_size);
@@ -575,8 +565,8 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx,
        case MOST_CH_ISOC_AVP:
                new_size = DIM_NormIsocBufferSize(buf_size, sub_size);
                if (new_size == 0) {
-                       pr_err("%s: invalid sub-buffer size or "
-                              "too small buffer size\n", hdm_ch->name);
+                       pr_err("%s: invalid sub-buffer size or too small buffer size\n",
+                              hdm_ch->name);
                        return -EINVAL;
                }
                ccfg->buffer_size = new_size;
@@ -589,8 +579,8 @@ static int configure_channel(struct most_interface *most_iface, int ch_idx,
        case MOST_CH_SYNC:
                new_size = DIM_NormSyncBufferSize(buf_size, sub_size);
                if (new_size == 0) {
-                       pr_err("%s: invalid sub-buffer size or "
-                              "too small buffer size\n", hdm_ch->name);
+                       pr_err("%s: invalid sub-buffer size or too small buffer size\n",
+                              hdm_ch->name);
                        return -EINVAL;
                }
                ccfg->buffer_size = new_size;
@@ -679,7 +669,7 @@ static void request_netinfo(struct most_interface *most_iface, int ch_idx)
                return;
        }
 
-       mbo = most_get_mbo(&dev->most_iface, dev->atx_idx);
+       mbo = most_get_mbo(&dev->most_iface, dev->atx_idx, NULL);
        if (!mbo)
                return;
 
@@ -787,7 +777,8 @@ static int dim2_probe(struct platform_device *pdev)
 
        ret = request_irq(dev->irq_ahb0, dim2_ahb_isr, 0, "mlb_ahb0", dev);
        if (ret) {
-               pr_err("failed to request IRQ: %d, err: %d\n", dev->irq_ahb0, ret);
+               pr_err("failed to request IRQ: %d, err: %d\n",
+                      dev->irq_ahb0, ret);
                goto err_unmap_io;
        }
 #endif
@@ -915,7 +906,7 @@ static int dim2_remove(struct platform_device *pdev)
         * break link to local platform_device_id struct
         * to prevent crash by unload platform device module
         */
-       pdev->id_entry = 0;
+       pdev->id_entry = NULL;
 
        return 0;
 }
@@ -933,30 +924,10 @@ static struct platform_driver dim2_driver = {
        .id_table = dim2_id,
        .driver = {
                .name = "hdm_dim2",
-               .owner = THIS_MODULE,
        },
 };
 
-/**
- * dim2_hdm_init - Driver Registration Routine
- */
-static int __init dim2_hdm_init(void)
-{
-       pr_info("dim2_hdm_init()\n");
-       return platform_driver_register(&dim2_driver);
-}
-
-/**
- * dim2_hdm_exit - Driver Cleanup Routine
- **/
-static void __exit dim2_hdm_exit(void)
-{
-       pr_info("dim2_hdm_exit()\n");
-       platform_driver_unregister(&dim2_driver);
-}
-
-module_init(dim2_hdm_init);
-module_exit(dim2_hdm_exit);
+module_platform_driver(dim2_driver);
 
 MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
 MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
index 6e688323280910573ec187412f5f1a72a9d4ad1a..1c94e3355fcc975ffc4a499f7c02c37f8b170bba 100644 (file)
@@ -18,7 +18,8 @@ struct device;
 
 /* platform dependent data for dim2 interface */
 struct dim2_platform_data {
-       int (*init)(struct dim2_platform_data *pd, void *io_base, int clk_speed);
+       int (*init)(struct dim2_platform_data *pd, void *io_base,
+                   int clk_speed);
        void (*destroy)(struct dim2_platform_data *pd);
        void *priv;
 };
index 8e331a286fc3eb09706f208c6c749f906e4e6594..c5b10c7d2facf0e7757a30101c36d1300429a990 100644 (file)
@@ -21,7 +21,8 @@
 struct bus_attr {
        struct attribute attr;
        ssize_t (*show)(struct medialb_bus *bus, char *buf);
-       ssize_t (*store)(struct medialb_bus *bus, const char *buf, size_t count);
+       ssize_t (*store)(struct medialb_bus *bus, const char *buf,
+                        size_t count);
 };
 
 static ssize_t state_show(struct medialb_bus *bus, char *buf)
index 029ded3f250b90a6fc4380c2234ba0ab8df3fefa..ba0263bb3d12685972669e7d886f4358cb2aac4d 100644 (file)
@@ -35,7 +35,6 @@ enum { CH_RX, CH_TX, NUM_CHANNELS };
 #define list_first_mbo(ptr) \
        list_first_entry(ptr, struct mbo, list)
 
-
 /* IRQ / Polling option */
 static bool polling_req;
 module_param(polling_req, bool, S_IRUGO);
@@ -93,10 +92,9 @@ static int configure_channel(struct most_interface *most_iface,
                return -EPERM;
        }
 
-       if (channel_config->direction == MOST_CH_RX) {
-               if (dev->polling_mode)
-                       schedule_delayed_work(&dev->rx.dwork,
-                                             msecs_to_jiffies(MSEC_PER_SEC / 4));
+       if ((channel_config->direction == MOST_CH_RX) && (dev->polling_mode)) {
+               schedule_delayed_work(&dev->rx.dwork,
+                                     msecs_to_jiffies(MSEC_PER_SEC / 4));
        }
        dev->is_open[ch_idx] = true;
 
@@ -198,7 +196,7 @@ static void do_rx_work(struct hdm_i2c *dev)
        struct mbo *mbo;
        unsigned char msg[MAX_BUF_SIZE_CONTROL];
        int ret, ch_idx = CH_RX;
-       uint16_t pml, data_size;
+       u16 pml, data_size;
 
        /* Read PML (2 bytes) */
        ret = i2c_master_recv(dev->client, msg, 2);
@@ -222,7 +220,8 @@ static void do_rx_work(struct hdm_i2c *dev)
 
        for (;;) {
                /* Conditions to wait for: poisoned channel or free buffer
-                  available for reading  */
+                * available for reading
+                */
                if (wait_event_interruptible(dev->rx.waitq,
                                             !dev->is_open[ch_idx] ||
                                             !list_empty(&dev->rx.list))) {
@@ -269,8 +268,9 @@ static void pending_rx_work(struct work_struct *work)
                        schedule_delayed_work(&dev->rx.dwork,
                                              msecs_to_jiffies(MSEC_PER_SEC
                                                               / scan_rate));
-       } else
+       } else {
                enable_irq(dev->client->irq);
+       }
 }
 
 /*
@@ -364,11 +364,11 @@ static int i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
        dev->polling_mode = polling_req || client->irq <= 0;
        if (!dev->polling_mode) {
                pr_info("Requesting IRQ: %d\n", client->irq);
-               ret = request_irq(client->irq, most_irq_handler, IRQF_SHARED,
+               ret = request_irq(client->irq, most_irq_handler, 0,
                                  client->name, dev);
                if (ret) {
-                       pr_info("IRQ request failed: %d, "
-                               "falling back to polling\n", ret);
+                       pr_info("IRQ request failed: %d, falling back to polling\n",
+                               ret);
                        dev->polling_mode = true;
                }
        }
@@ -416,34 +416,13 @@ MODULE_DEVICE_TABLE(i2c, i2c_id);
 static struct i2c_driver i2c_driver = {
        .driver = {
                .name = "hdm_i2c",
-               .owner = THIS_MODULE,
        },
        .probe = i2c_probe,
        .remove = i2c_remove,
        .id_table = i2c_id,
 };
 
-/**
- * hdm_i2c_init - Driver Registration Routine
- */
-static int __init hdm_i2c_init(void)
-{
-       pr_info("hdm_i2c_init()\n");
-
-       return i2c_add_driver(&i2c_driver);
-}
-
-/**
- * hdm_i2c_exit - Driver Cleanup Routine
- **/
-static void __exit hdm_i2c_exit(void)
-{
-       i2c_del_driver(&i2c_driver);
-       pr_info("hdm_i2c_exit()\n");
-}
-
-module_init(hdm_i2c_init);
-module_exit(hdm_i2c_exit);
+module_i2c_driver(i2c_driver);
 
 MODULE_AUTHOR("Jain Roy Ambi <JainRoy.Ambi@microchip.com>");
 MODULE_AUTHOR("Andrey Shvetsov <andrey.shvetsov@k2l.de>");
index 305303f2f17cd188073069589aadb4f91228c3d6..41690f801fb8c6af9ebf636da98b4128241c9970 100644 (file)
@@ -59,6 +59,8 @@
 #define DRCI_REG_HW_ADDR_HI    0x0145
 #define DRCI_REG_HW_ADDR_MI    0x0146
 #define DRCI_REG_HW_ADDR_LO    0x0147
+#define DRCI_REG_BASE          0x1100
+#define DRCI_COMMAND           0x02
 #define DRCI_READ_REQ          0xA0
 #define DRCI_WRITE_REQ         0xA1
 
@@ -75,6 +77,7 @@ struct buf_anchor {
        struct list_head list;
        struct completion urb_compl;
 };
+
 #define to_buf_anchor(w) container_of(w, struct buf_anchor, clear_work_obj)
 
 /**
@@ -86,6 +89,7 @@ struct most_dci_obj {
        struct kobject kobj;
        struct usb_device *usb_device;
 };
+
 #define to_dci_obj(p) container_of(p, struct most_dci_obj, kobj)
 
 /**
@@ -129,6 +133,7 @@ struct most_dev {
        struct timer_list link_stat_timer;
        struct work_struct poll_work_obj;
 };
+
 #define to_mdev(d) container_of(d, struct most_dev, iface)
 #define to_mdev_from_work(w) container_of(w, struct most_dev, poll_work_obj)
 
@@ -136,36 +141,6 @@ static struct workqueue_struct *schedule_usb_work;
 static void wq_clear_halt(struct work_struct *wq_obj);
 static void wq_netinfo(struct work_struct *wq_obj);
 
-/**
- * trigger_resync_vr - Vendor request to trigger HW re-sync mechanism
- * @dev: usb device
- *
- */
-static void trigger_resync_vr(struct usb_device *dev)
-{
-       int retval;
-       u8 request_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
-       int *data = kzalloc(sizeof(*data), GFP_KERNEL);
-
-       if (!data)
-               goto error;
-       *data = HW_RESYNC;
-       retval = usb_control_msg(dev,
-                                usb_sndctrlpipe(dev, 0),
-                                0,
-                                request_type,
-                                0,
-                                0,
-                                data,
-                                0,
-                                5 * HZ);
-       kfree(data);
-       if (retval >= 0)
-               return;
-error:
-       dev_err(&dev->dev, "Vendor request \"stall\" failed\n");
-}
-
 /**
  * drci_rd_reg - read a DCI register
  * @dev: usb device
@@ -174,17 +149,23 @@ error:
  *
  * This is reads data from INIC's direct register communication interface
  */
-static inline int drci_rd_reg(struct usb_device *dev, u16 reg, void *buf)
+static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf)
 {
-       return usb_control_msg(dev,
-                              usb_rcvctrlpipe(dev, 0),
-                              DRCI_READ_REQ,
-                              USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-                              0x0000,
-                              reg,
-                              buf,
-                              2,
-                              5 * HZ);
+       int retval;
+       u16 *dma_buf = kzalloc(sizeof(u16), GFP_KERNEL);
+       u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
+
+       if (!dma_buf)
+               return -ENOMEM;
+
+       retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
+                                DRCI_READ_REQ, req_type,
+                                0x0000,
+                                reg, dma_buf, sizeof(u16), 5 * HZ);
+       *buf = le16_to_cpu(*dma_buf);
+       kfree(dma_buf);
+
+       return retval;
 }
 
 /**
@@ -220,7 +201,8 @@ static void free_anchored_buffers(struct most_dev *mdev, unsigned int channel)
        unsigned long flags;
 
        spin_lock_irqsave(&mdev->anchor_list_lock[channel], flags);
-       list_for_each_entry_safe(anchor, tmp, &mdev->anchor_list[channel], list) {
+       list_for_each_entry_safe(anchor, tmp, &mdev->anchor_list[channel],
+                                list) {
                struct urb *urb = anchor->urb;
 
                spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
@@ -267,10 +249,11 @@ static unsigned int get_stream_frame_size(struct most_channel_config *cfg)
                if (cfg->packets_per_xact == 0) {
                        pr_warn("Misconfig: Packets per XACT zero\n");
                        frame_size = 0;
-               } else if (cfg->packets_per_xact == 0xFF)
+               } else if (cfg->packets_per_xact == 0xFF) {
                        frame_size = (USB_MTU / sub_size) * sub_size;
-               else
+               } else {
                        frame_size = cfg->packets_per_xact * sub_size;
+               }
                break;
        default:
                pr_warn("Query frame size of non-streaming channel\n");
@@ -308,7 +291,7 @@ static int hdm_poison_channel(struct most_interface *iface, int channel)
 
        mutex_lock(&mdev->io_mutex);
        free_anchored_buffers(mdev, channel);
-       if (mdev->padding_active[channel] == true)
+       if (mdev->padding_active[channel])
                mdev->padding_active[channel] = false;
 
        if (mdev->conf[channel].data_type == MOST_CH_ASYNC) {
@@ -365,7 +348,8 @@ static int hdm_add_padding(struct most_dev *mdev, int channel, struct mbo *mbo)
  * This takes the INIC hardware specific padding bytes off a streaming
  * channel's buffer.
  */
-static int hdm_remove_padding(struct most_dev *mdev, int channel, struct mbo *mbo)
+static int hdm_remove_padding(struct most_dev *mdev, int channel,
+                             struct mbo *mbo)
 {
        unsigned int j, num_frames, frame_size;
        struct most_channel_config *const conf = &mdev->conf[channel];
@@ -411,7 +395,7 @@ static void hdm_write_completion(struct urb *urb)
        dev = &mdev->usb_device->dev;
 
        if ((urb->status == -ENOENT) || (urb->status == -ECONNRESET) ||
-           (mdev->is_channel_healthy[channel] == false)) {
+           (!mdev->is_channel_healthy[channel])) {
                complete(&anchor->urb_compl);
                return;
        }
@@ -453,7 +437,7 @@ static void hdm_write_completion(struct urb *urb)
 }
 
 /**
- * hdm_read_completion - completion funciton for submitted Rx URBs
+ * hdm_read_completion - completion function for submitted Rx URBs
  * @urb: the URB that has been completed
  *
  * This checks the status of the completed URB. In case the URB has been
@@ -568,7 +552,6 @@ static void hdm_read_completion(struct urb *urb)
        struct device *dev;
        unsigned long flags;
        unsigned int channel;
-       struct most_channel_config *conf;
 
        mbo = urb->context;
        anchor = mbo->priv;
@@ -577,13 +560,11 @@ static void hdm_read_completion(struct urb *urb)
        dev = &mdev->usb_device->dev;
 
        if ((urb->status == -ENOENT) || (urb->status == -ECONNRESET) ||
-           (mdev->is_channel_healthy[channel] == false)) {
+           (!mdev->is_channel_healthy[channel])) {
                complete(&anchor->urb_compl);
                return;
        }
 
-       conf = &mdev->conf[channel];
-
        if (unlikely(urb->status && !(urb->status == -ENOENT ||
                                      urb->status == -ECONNRESET ||
                                      urb->status == -ESHUTDOWN))) {
@@ -608,7 +589,7 @@ static void hdm_read_completion(struct urb *urb)
                }
        } else {
                mbo->processed_length = urb->actual_length;
-               if (mdev->padding_active[channel] == false) {
+               if (!mdev->padding_active[channel]) {
                        mbo->status = MBO_SUCCESS;
                } else {
                        if (hdm_remove_padding(mdev, channel, mbo)) {
@@ -644,7 +625,8 @@ static void hdm_read_completion(struct urb *urb)
  *
  * Context: Could in _some_ cases be interrupt!
  */
-static int hdm_enqueue(struct most_interface *iface, int channel, struct mbo *mbo)
+static int hdm_enqueue(struct most_interface *iface, int channel,
+                      struct mbo *mbo)
 {
        struct most_dev *mdev;
        struct buf_anchor *anchor;
@@ -688,7 +670,7 @@ static int hdm_enqueue(struct most_interface *iface, int channel, struct mbo *mb
        list_add_tail(&anchor->list, &mdev->anchor_list[channel]);
        spin_unlock_irqrestore(&mdev->anchor_list_lock[channel], flags);
 
-       if ((mdev->padding_active[channel] == true) &&
+       if ((mdev->padding_active[channel]) &&
            (conf->direction & MOST_CH_TX))
                if (hdm_add_padding(mdev, channel, mbo)) {
                        retval = -EIO;
@@ -714,7 +696,7 @@ static int hdm_enqueue(struct most_interface *iface, int channel, struct mbo *mb
                                  usb_rcvbulkpipe(mdev->usb_device,
                                                  mdev->ep_address[channel]),
                                  virt_address,
-                                 length,
+                                 length + conf->extra_len,
                                  hdm_read_completion,
                                  mbo);
        }
@@ -780,12 +762,6 @@ static int hdm_configure_channel(struct most_interface *iface, int channel,
        mdev->padding_active[channel] = true;
        temp_size = conf->buffer_size;
 
-       if ((conf->data_type != MOST_CH_SYNC) &&
-           (conf->data_type != MOST_CH_ISOC_AVP)) {
-               dev_warn(dev, "Unsupported data type\n");
-               return -EINVAL;
-       }
-
        frame_size = get_stream_frame_size(conf);
        if ((frame_size == 0) || (frame_size > USB_MTU)) {
                dev_warn(dev, "Misconfig: frame size wrong\n");
@@ -798,8 +774,7 @@ static int hdm_configure_channel(struct most_interface *iface, int channel,
                tmp_val = conf->buffer_size / frame_size;
                conf->buffer_size = tmp_val * frame_size;
                dev_notice(dev,
-                          "Channel %d - rouding buffer size to %d bytes, "
-                          "channel config says %d bytes\n",
+                          "Channel %d - rounding buffer size to %d bytes, channel config says %d bytes\n",
                           channel,
                           conf->buffer_size,
                           temp_size);
@@ -826,38 +801,41 @@ exit:
  */
 static int hdm_update_netinfo(struct most_dev *mdev)
 {
-       struct device *dev = &mdev->usb_device->dev;
-       int i;
-       u16 link;
-       u8 addr[6];
+       struct usb_device *usb_device = mdev->usb_device;
+       struct device *dev = &usb_device->dev;
+       u16 hi, mi, lo, link;
 
        if (!is_valid_ether_addr(mdev->hw_addr)) {
-               if (0 > drci_rd_reg(mdev->usb_device,
-                                   DRCI_REG_HW_ADDR_HI, addr)) {
+               if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_HI, &hi) < 0) {
                        dev_err(dev, "Vendor request \"hw_addr_hi\" failed\n");
                        return -1;
                }
-               if (0 > drci_rd_reg(mdev->usb_device,
-                                   DRCI_REG_HW_ADDR_MI, addr + 2)) {
+
+               if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_MI, &mi) < 0) {
                        dev_err(dev, "Vendor request \"hw_addr_mid\" failed\n");
                        return -1;
                }
-               if (0 > drci_rd_reg(mdev->usb_device,
-                                   DRCI_REG_HW_ADDR_LO, addr + 4)) {
+
+               if (drci_rd_reg(usb_device, DRCI_REG_HW_ADDR_LO, &lo) < 0) {
                        dev_err(dev, "Vendor request \"hw_addr_low\" failed\n");
                        return -1;
                }
+
                mutex_lock(&mdev->io_mutex);
-               for (i = 0; i < 6; i++)
-                       mdev->hw_addr[i] = addr[i];
+               mdev->hw_addr[0] = hi >> 8;
+               mdev->hw_addr[1] = hi;
+               mdev->hw_addr[2] = mi >> 8;
+               mdev->hw_addr[3] = mi;
+               mdev->hw_addr[4] = lo >> 8;
+               mdev->hw_addr[5] = lo;
                mutex_unlock(&mdev->io_mutex);
-
        }
-       if (0 > drci_rd_reg(mdev->usb_device, DRCI_REG_NI_STATE, &link)) {
+
+       if (drci_rd_reg(usb_device, DRCI_REG_NI_STATE, &link) < 0) {
                dev_err(dev, "Vendor request \"link status\" failed\n");
                return -1;
        }
-       le16_to_cpus(&link);
+
        mutex_lock(&mdev->io_mutex);
        mdev->link_stat = link;
        mutex_unlock(&mdev->io_mutex);
@@ -919,7 +897,7 @@ static void wq_netinfo(struct work_struct *wq_obj)
        for (i = 0; i < 6; i++)
                prev_hw_addr[i] = mdev->hw_addr[i];
 
-       if (0 > hdm_update_netinfo(mdev))
+       if (hdm_update_netinfo(mdev) < 0)
                return;
        if ((prev_link_stat != mdev->link_stat) ||
            (prev_hw_addr[0] != mdev->hw_addr[0]) ||
@@ -1009,8 +987,8 @@ struct most_dci_attribute {
                         const char *buf,
                         size_t count);
 };
-#define to_dci_attr(a) container_of(a, struct most_dci_attribute, attr)
 
+#define to_dci_attr(a) container_of(a, struct most_dci_attribute, attr)
 
 /**
  * dci_attr_show - show function for dci object
@@ -1107,14 +1085,14 @@ static ssize_t show_value(struct most_dci_obj *dci_obj,
        if (err < 0)
                return err;
 
-       return snprintf(buf, PAGE_SIZE, "%04x\n", le16_to_cpu(tmp_val));
+       return snprintf(buf, PAGE_SIZE, "%04x\n", tmp_val);
 }
 
 static ssize_t store_value(struct most_dci_obj *dci_obj,
                           struct most_dci_attribute *attr,
                           const char *buf, size_t count)
 {
-       u16 v16;
+       u16 val;
        u16 reg_addr;
        int err;
 
@@ -1137,11 +1115,11 @@ static ssize_t store_value(struct most_dci_obj *dci_obj,
        else
                return -EIO;
 
-       err = kstrtou16(buf, 16, &v16);
+       err = kstrtou16(buf, 16, &val);
        if (err)
                return err;
 
-       err = drci_wr_reg(dci_obj->usb_device, reg_addr, cpu_to_le16(v16));
+       err = drci_wr_reg(dci_obj->usb_device, reg_addr, val);
        if (err < 0)
                return err;
 
@@ -1248,6 +1226,7 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
        struct usb_host_interface *usb_iface_desc;
        struct usb_endpoint_descriptor *ep_desc;
        int ret = 0;
+       int err;
 
        usb_iface_desc = interface->cur_altsetting;
        usb_dev = interface_to_usbdev(interface);
@@ -1260,11 +1239,10 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
        num_endpoints = usb_iface_desc->desc.bNumEndpoints;
        mutex_init(&mdev->io_mutex);
        INIT_WORK(&mdev->poll_work_obj, wq_netinfo);
-       init_timer(&mdev->link_stat_timer);
+       setup_timer(&mdev->link_stat_timer, link_stat_timer_handler,
+                   (unsigned long)mdev);
 
        mdev->usb_device = usb_dev;
-       mdev->link_stat_timer.function = link_stat_timer_handler;
-       mdev->link_stat_timer.data = (unsigned long)mdev;
        mdev->link_stat_timer.expires = jiffies + (2 * HZ);
 
        mdev->iface.mod = hdm_usb_fops.owner;
@@ -1328,6 +1306,13 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
                tmp_cap++;
                INIT_LIST_HEAD(&mdev->anchor_list[i]);
                spin_lock_init(&mdev->anchor_list_lock[i]);
+               err = drci_wr_reg(usb_dev,
+                                 DRCI_REG_BASE + DRCI_COMMAND +
+                                 ep_desc->bEndpointAddress * 16,
+                                 1);
+               if (err < 0)
+                       pr_warn("DCI Sync for EP %02x failed",
+                               ep_desc->bEndpointAddress);
        }
        dev_notice(dev, "claimed gadget: Vendor=%4.4x ProdID=%4.4x Bus=%02x Device=%02x\n",
                   le16_to_cpu(usb_dev->descriptor.idVendor),
@@ -1362,7 +1347,6 @@ hdm_probe(struct usb_interface *interface, const struct usb_device_id *id)
 
                kobject_uevent(&mdev->dci->kobj, KOBJ_ADD);
                mdev->dci->usb_device = mdev->usb_device;
-               trigger_resync_vr(usb_dev);
        }
        mutex_unlock(&mdev->io_mutex);
        return 0;
@@ -1432,7 +1416,7 @@ static int __init hdm_usb_init(void)
                return -EIO;
        }
        schedule_usb_work = create_workqueue("hdmu_work");
-       if (schedule_usb_work == NULL) {
+       if (!schedule_usb_work) {
                pr_err("could not create workqueue\n");
                usb_deregister(&hdm_usb);
                return -ENOMEM;
index 7bb16db42893fb614ee81c2bfc4c2dcfcf23c490..19852ca7e59c3ab8f463297fa548985629ba09e3 100644 (file)
@@ -36,15 +36,22 @@ static struct class *most_class;
 static struct device *class_glue_dir;
 static struct ida mdev_id;
 static int modref;
+static int dummy_num_buffers;
+
+struct most_c_aim_obj {
+       struct most_aim *ptr;
+       int refs;
+       int num_buffers;
+};
 
 struct most_c_obj {
        struct kobject kobj;
        struct completion cleanup;
        atomic_t mbo_ref;
        atomic_t mbo_nq_level;
-       uint16_t channel_id;
+       u16 channel_id;
        bool is_poisoned;
-       bool is_started;
+       struct mutex start_mutex;
        int is_starving;
        struct most_interface *iface;
        struct most_inst_obj *inst;
@@ -55,13 +62,14 @@ struct most_c_obj {
        spinlock_t fifo_lock;
        struct list_head halt_fifo;
        struct list_head list;
-       struct most_aim *first_aim;
-       struct most_aim *second_aim;
+       struct most_c_aim_obj aim0;
+       struct most_c_aim_obj aim1;
        struct list_head trash_fifo;
        struct task_struct *hdm_enqueue_task;
        struct mutex stop_task_mutex;
        wait_queue_head_t hdm_fifo_wq;
 };
+
 #define to_c_obj(d) container_of(d, struct most_c_obj, kobj)
 
 struct most_inst_obj {
@@ -73,6 +81,7 @@ struct most_inst_obj {
        struct kobject kobj;
        struct list_head list;
 };
+
 #define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
 
 /**
@@ -108,6 +117,7 @@ struct most_c_attr {
                         const char *buf,
                         size_t count);
 };
+
 #define to_channel_attr(a) container_of(a, struct most_c_attr, attr)
 
 #define MOST_CHNL_ATTR(_name, _mode, _show, _store) \
@@ -190,8 +200,7 @@ static void flush_channel_fifos(struct most_c_obj *c)
        list_for_each_entry_safe(mbo, tmp, &c->fifo, list) {
                list_del(&mbo->list);
                spin_unlock_irqrestore(&c->fifo_lock, flags);
-               if (likely(mbo))
-                       most_free_mbo_coherent(mbo);
+               most_free_mbo_coherent(mbo);
                spin_lock_irqsave(&c->fifo_lock, flags);
        }
        spin_unlock_irqrestore(&c->fifo_lock, flags);
@@ -200,8 +209,7 @@ static void flush_channel_fifos(struct most_c_obj *c)
        list_for_each_entry_safe(mbo, tmp, &c->halt_fifo, list) {
                list_del(&mbo->list);
                spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
-               if (likely(mbo))
-                       most_free_mbo_coherent(mbo);
+               most_free_mbo_coherent(mbo);
                spin_lock_irqsave(&c->fifo_lock, hf_flags);
        }
        spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
@@ -242,8 +250,8 @@ static void most_channel_release(struct kobject *kobj)
 }
 
 static ssize_t show_available_directions(struct most_c_obj *c,
-               struct most_c_attr *attr,
-               char *buf)
+                                        struct most_c_attr *attr,
+                                        char *buf)
 {
        unsigned int i = c->channel_id;
 
@@ -326,7 +334,6 @@ static ssize_t show_channel_starving(struct most_c_obj *c,
        return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving);
 }
 
-
 #define create_show_channel_attribute(val) \
        static MOST_CHNL_ATTR(val, S_IRUGO, show_##val, NULL)
 
@@ -392,11 +399,11 @@ static ssize_t store_set_direction(struct most_c_obj *c,
                                   const char *buf,
                                   size_t count)
 {
-       if (!strcmp(buf, "dir_rx\n"))
+       if (!strcmp(buf, "dir_rx\n")) {
                c->cfg.direction = MOST_CH_RX;
-       else if (!strcmp(buf, "dir_tx\n"))
+       } else if (!strcmp(buf, "dir_tx\n")) {
                c->cfg.direction = MOST_CH_TX;
-       else {
+       else {
                pr_info("WARN: invalid attribute settings\n");
                return -EINVAL;
        }
@@ -423,15 +430,15 @@ static ssize_t store_set_datatype(struct most_c_obj *c,
                                  const char *buf,
                                  size_t count)
 {
-       if (!strcmp(buf, "control\n"))
+       if (!strcmp(buf, "control\n")) {
                c->cfg.data_type = MOST_CH_CONTROL;
-       else if (!strcmp(buf, "async\n"))
+       } else if (!strcmp(buf, "async\n")) {
                c->cfg.data_type = MOST_CH_ASYNC;
-       else if (!strcmp(buf, "sync\n"))
+       } else if (!strcmp(buf, "sync\n")) {
                c->cfg.data_type = MOST_CH_SYNC;
-       else if (!strcmp(buf, "isoc_avp\n"))
+       } else if (!strcmp(buf, "isoc_avp\n")) {
                c->cfg.data_type = MOST_CH_ISOC_AVP;
-       else {
+       else {
                pr_info("WARN: invalid attribute settings\n");
                return -EINVAL;
        }
@@ -488,7 +495,6 @@ create_channel_attribute(set_datatype);
 create_channel_attribute(set_subbuffer_size);
 create_channel_attribute(set_packets_per_xact);
 
-
 /**
  * most_channel_def_attrs - array of default attributes of channel object
  */
@@ -554,12 +560,12 @@ create_most_c_obj(const char *name, struct kobject *parent)
  */
 static void destroy_most_c_obj(struct most_c_obj *c)
 {
-       if (c->first_aim)
-               c->first_aim->disconnect_channel(c->iface, c->channel_id);
-       if (c->second_aim)
-               c->second_aim->disconnect_channel(c->iface, c->channel_id);
-       c->first_aim = NULL;
-       c->second_aim = NULL;
+       if (c->aim0.ptr)
+               c->aim0.ptr->disconnect_channel(c->iface, c->channel_id);
+       if (c->aim1.ptr)
+               c->aim1.ptr->disconnect_channel(c->iface, c->channel_id);
+       c->aim0.ptr = NULL;
+       c->aim1.ptr = NULL;
 
        mutex_lock(&deregister_mutex);
        flush_trash_fifo(c);
@@ -593,6 +599,7 @@ struct most_inst_attribute {
                         const char *buf,
                         size_t count);
 };
+
 #define to_instance_attr(a) \
        container_of(a, struct most_inst_attribute, attr)
 
@@ -715,7 +722,6 @@ static struct kobj_type most_inst_ktype = {
 
 static struct kset *most_inst_kset;
 
-
 /**
  * create_most_inst_obj - creates an instance object
  * @name: name of the object to be created
@@ -775,11 +781,11 @@ struct most_aim_obj {
        char add_link[STRING_SIZE];
        char remove_link[STRING_SIZE];
 };
+
 #define to_aim_obj(d) container_of(d, struct most_aim_obj, kobj)
 
 static struct list_head aim_list;
 
-
 /**
  * struct most_aim_attribute - to access the attributes of AIM object
  * @attr: attributes of an AIM
@@ -796,6 +802,7 @@ struct most_aim_attribute {
                         const char *buf,
                         size_t count);
 };
+
 #define to_aim_attr(a) container_of(a, struct most_aim_attribute, attr)
 
 /**
@@ -933,7 +940,7 @@ most_c_obj *get_channel_by_name(char *mdev, char *mdev_ch)
                        break;
                }
        }
-       if (unlikely(2 > found))
+       if (unlikely(found < 2))
                return ERR_PTR(-EIO);
        return c;
 }
@@ -983,7 +990,8 @@ static ssize_t store_add_link(struct most_aim_obj *aim_obj,
                return ret;
 
        if (!mdev_devnod || *mdev_devnod == 0) {
-               snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev, mdev_ch);
+               snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev,
+                        mdev_ch);
                mdev_devnod = devnod_buf;
        }
 
@@ -991,10 +999,10 @@ static ssize_t store_add_link(struct most_aim_obj *aim_obj,
        if (IS_ERR(c))
                return -ENODEV;
 
-       if (!c->first_aim)
-               aim_ptr = &c->first_aim;
-       else if (!c->second_aim)
-               aim_ptr = &c->second_aim;
+       if (!c->aim0.ptr)
+               aim_ptr = &c->aim0.ptr;
+       else if (!c->aim1.ptr)
+               aim_ptr = &c->aim1.ptr;
        else
                return -ENOSPC;
 
@@ -1048,17 +1056,18 @@ static ssize_t store_remove_link(struct most_aim_obj *aim_obj,
        if (IS_ERR(c))
                return -ENODEV;
 
-       if (c->first_aim == aim_obj->driver)
-               c->first_aim = NULL;
-       if (c->second_aim == aim_obj->driver)
-               c->second_aim = NULL;
+       if (c->aim0.ptr == aim_obj->driver)
+               c->aim0.ptr = NULL;
+       if (c->aim1.ptr == aim_obj->driver)
+               c->aim1.ptr = NULL;
        if (aim_obj->driver->disconnect_channel(c->iface, c->channel_id))
                return -EIO;
        return len;
 }
 
 static struct most_aim_attribute most_aim_attr_remove_link =
-       __ATTR(remove_link, S_IRUGO | S_IWUSR, show_remove_link, store_remove_link);
+       __ATTR(remove_link, S_IRUGO | S_IWUSR, show_remove_link,
+              store_remove_link);
 
 static struct attribute *most_aim_def_attrs[] = {
        &most_aim_attr_add_link.attr,
@@ -1113,7 +1122,6 @@ static void destroy_most_aim_obj(struct most_aim_obj *p)
        kobject_put(&p->kobj);
 }
 
-
 /*                  ___       ___
  *                  ___C O R E___
  */
@@ -1176,8 +1184,8 @@ static int hdm_enqueue_thread(void *data)
 
        while (likely(!kthread_should_stop())) {
                wait_event_interruptible(c->hdm_fifo_wq,
-                                        (mbo = get_hdm_mbo(c))
-                                        || kthread_should_stop());
+                                        (mbo = get_hdm_mbo(c)) ||
+                                        kthread_should_stop());
 
                if (unlikely(!mbo))
                        continue;
@@ -1199,7 +1207,8 @@ static int hdm_enqueue_thread(void *data)
 static int run_enqueue_thread(struct most_c_obj *c, int channel_id)
 {
        struct task_struct *task =
-               kthread_run(&hdm_enqueue_thread, c, "hdm_fifo_%d", channel_id);
+               kthread_run(hdm_enqueue_thread, c, "hdm_fifo_%d",
+                           channel_id);
 
        if (IS_ERR(task))
                return PTR_ERR(task);
@@ -1233,13 +1242,15 @@ static void arm_mbo(struct mbo *mbo)
        }
 
        spin_lock_irqsave(&c->fifo_lock, flags);
+       ++*mbo->num_buffers_ptr;
        list_add_tail(&mbo->list, &c->fifo);
        spin_unlock_irqrestore(&c->fifo_lock, flags);
 
-       if (c->second_aim && c->second_aim->tx_completion)
-               c->second_aim->tx_completion(c->iface, c->channel_id);
-       if (c->first_aim && c->first_aim->tx_completion)
-               c->first_aim->tx_completion(c->iface, c->channel_id);
+       if (c->aim0.refs && c->aim0.ptr->tx_completion)
+               c->aim0.ptr->tx_completion(c->iface, c->channel_id);
+
+       if (c->aim1.refs && c->aim1.ptr->tx_completion)
+               c->aim1.ptr->tx_completion(c->iface, c->channel_id);
 }
 
 /**
@@ -1285,6 +1296,7 @@ static int arm_mbo_chain(struct most_c_obj *c, int dir,
                        goto _error1;
                }
                mbo->complete = compl;
+               mbo->num_buffers_ptr = &dummy_num_buffers;
                if (dir == MOST_CH_RX) {
                        nq_hdm_mbo(mbo);
                        atomic_inc(&c->mbo_nq_level);
@@ -1341,7 +1353,7 @@ static void most_write_completion(struct mbo *mbo)
        c = mbo->context;
        if (mbo->status == MBO_E_INVAL)
                pr_info("WARN: Tx MBO status: invalid\n");
-       if (unlikely((c->is_poisoned == true) || (mbo->status == MBO_E_CLOSE)))
+       if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE)))
                trash_mbo(mbo);
        else
                arm_mbo(mbo);
@@ -1375,6 +1387,22 @@ most_c_obj *get_channel_by_iface(struct most_interface *iface, int id)
        return i->channel[id];
 }
 
+int channel_has_mbo(struct most_interface *iface, int id)
+{
+       struct most_c_obj *c = get_channel_by_iface(iface, id);
+       unsigned long flags;
+       int empty;
+
+       if (unlikely(!c))
+               return -EINVAL;
+
+       spin_lock_irqsave(&c->fifo_lock, flags);
+       empty = list_empty(&c->fifo);
+       spin_unlock_irqrestore(&c->fifo_lock, flags);
+       return !empty;
+}
+EXPORT_SYMBOL_GPL(channel_has_mbo);
+
 /**
  * most_get_mbo - get pointer to an MBO of pool
  * @iface: pointer to interface instance
@@ -1383,28 +1411,45 @@ most_c_obj *get_channel_by_iface(struct most_interface *iface, int id)
  * This attempts to get a free buffer out of the channel fifo.
  * Returns a pointer to MBO on success or NULL otherwise.
  */
-struct mbo *most_get_mbo(struct most_interface *iface, int id)
+struct mbo *most_get_mbo(struct most_interface *iface, int id,
+                        struct most_aim *aim)
 {
        struct mbo *mbo;
        struct most_c_obj *c;
        unsigned long flags;
+       int *num_buffers_ptr;
 
        c = get_channel_by_iface(iface, id);
        if (unlikely(!c))
                return NULL;
+
+       if (c->aim0.refs && c->aim1.refs &&
+           ((aim == c->aim0.ptr && c->aim0.num_buffers <= 0) ||
+            (aim == c->aim1.ptr && c->aim1.num_buffers <= 0)))
+               return NULL;
+
+       if (aim == c->aim0.ptr)
+               num_buffers_ptr = &c->aim0.num_buffers;
+       else if (aim == c->aim1.ptr)
+               num_buffers_ptr = &c->aim1.num_buffers;
+       else
+               num_buffers_ptr = &dummy_num_buffers;
+
        spin_lock_irqsave(&c->fifo_lock, flags);
        if (list_empty(&c->fifo)) {
                spin_unlock_irqrestore(&c->fifo_lock, flags);
                return NULL;
        }
        mbo = list_pop_mbo(&c->fifo);
+       --*num_buffers_ptr;
        spin_unlock_irqrestore(&c->fifo_lock, flags);
+
+       mbo->num_buffers_ptr = num_buffers_ptr;
        mbo->buffer_length = c->cfg.buffer_size;
        return mbo;
 }
 EXPORT_SYMBOL_GPL(most_get_mbo);
 
-
 /**
  * most_put_mbo - return buffer to pool
  * @mbo: buffer object
@@ -1443,11 +1488,12 @@ EXPORT_SYMBOL_GPL(most_put_mbo);
  */
 static void most_read_completion(struct mbo *mbo)
 {
-       struct most_c_obj *c;
+       struct most_c_obj *c = mbo->context;
 
-       c = mbo->context;
-       if (unlikely((c->is_poisoned == true) || (mbo->status == MBO_E_CLOSE)))
-               goto release_mbo;
+       if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE))) {
+               trash_mbo(mbo);
+               return;
+       }
 
        if (mbo->status == MBO_E_INVAL) {
                nq_hdm_mbo(mbo);
@@ -1460,16 +1506,15 @@ static void most_read_completion(struct mbo *mbo)
                c->is_starving = 1;
        }
 
-       if (c->first_aim && c->first_aim->rx_completion &&
-           c->first_aim->rx_completion(mbo) == 0)
+       if (c->aim0.refs && c->aim0.ptr->rx_completion &&
+           c->aim0.ptr->rx_completion(mbo) == 0)
                return;
-       if (c->second_aim && c->second_aim->rx_completion &&
-           c->second_aim->rx_completion(mbo) == 0)
+
+       if (c->aim1.refs && c->aim1.ptr->rx_completion &&
+           c->aim1.ptr->rx_completion(mbo) == 0)
                return;
-       pr_info("WARN: no driver linked with this channel\n");
-       mbo->status = MBO_E_CLOSE;
-release_mbo:
-       trash_mbo(mbo);
+
+       most_put_mbo(mbo);
 }
 
 /**
@@ -1482,7 +1527,8 @@ release_mbo:
  *
  * Returns 0 on success or error code otherwise.
  */
-int most_start_channel(struct most_interface *iface, int id)
+int most_start_channel(struct most_interface *iface, int id,
+                      struct most_aim *aim)
 {
        int num_buffer;
        int ret;
@@ -1491,11 +1537,13 @@ int most_start_channel(struct most_interface *iface, int id)
        if (unlikely(!c))
                return -EINVAL;
 
-       if (c->is_started)
-               return -EBUSY;
+       mutex_lock(&c->start_mutex);
+       if (c->aim0.refs + c->aim1.refs > 0)
+               goto out; /* already started by other aim */
 
        if (!try_module_get(iface->mod)) {
                pr_info("failed to acquire HDM lock\n");
+               mutex_unlock(&c->start_mutex);
                return -ENOLCK;
        }
        modref++;
@@ -1515,7 +1563,7 @@ int most_start_channel(struct most_interface *iface, int id)
        else
                num_buffer = arm_mbo_chain(c, c->cfg.direction,
                                           most_write_completion);
-       if (unlikely(0 == num_buffer)) {
+       if (unlikely(!num_buffer)) {
                pr_info("failed to allocate memory\n");
                ret = -ENOMEM;
                goto error;
@@ -1525,14 +1573,24 @@ int most_start_channel(struct most_interface *iface, int id)
        if (ret)
                goto error;
 
-       c->is_started = true;
        c->is_starving = 0;
+       c->aim0.num_buffers = c->cfg.num_buffers / 2;
+       c->aim1.num_buffers = c->cfg.num_buffers - c->aim0.num_buffers;
        atomic_set(&c->mbo_ref, num_buffer);
+
+out:
+       if (aim == c->aim0.ptr)
+               c->aim0.refs++;
+       if (aim == c->aim1.ptr)
+               c->aim1.refs++;
+       mutex_unlock(&c->start_mutex);
        return 0;
+
 error:
        if (iface->mod)
                module_put(iface->mod);
        modref--;
+       mutex_unlock(&c->start_mutex);
        return ret;
 }
 EXPORT_SYMBOL_GPL(most_start_channel);
@@ -1542,7 +1600,8 @@ EXPORT_SYMBOL_GPL(most_start_channel);
  * @iface: pointer to interface instance
  * @id: channel ID
  */
-int most_stop_channel(struct most_interface *iface, int id)
+int most_stop_channel(struct most_interface *iface, int id,
+                     struct most_aim *aim)
 {
        struct most_c_obj *c;
 
@@ -1554,13 +1613,9 @@ int most_stop_channel(struct most_interface *iface, int id)
        if (unlikely(!c))
                return -EINVAL;
 
-       if (!c->is_started)
-               return 0;
-
-       /* FIXME: we need to know calling AIM to reset only one link */
-       c->first_aim = NULL;
-       c->second_aim = NULL;
-       /* do not go into recursion calling aim->disconnect_channel */
+       mutex_lock(&c->start_mutex);
+       if (c->aim0.refs + c->aim1.refs >= 2)
+               goto out;
 
        mutex_lock(&c->stop_task_mutex);
        if (c->hdm_enqueue_task)
@@ -1571,6 +1626,7 @@ int most_stop_channel(struct most_interface *iface, int id)
        mutex_lock(&deregister_mutex);
        if (atomic_read(&c->inst->tainted)) {
                mutex_unlock(&deregister_mutex);
+               mutex_unlock(&c->start_mutex);
                return -ENODEV;
        }
        mutex_unlock(&deregister_mutex);
@@ -1584,6 +1640,7 @@ int most_stop_channel(struct most_interface *iface, int id)
        if (c->iface->poison_channel(c->iface, c->channel_id)) {
                pr_err("Cannot stop channel %d of mdev %s\n", c->channel_id,
                       c->iface->description);
+               mutex_unlock(&c->start_mutex);
                return -EAGAIN;
        }
        flush_trash_fifo(c);
@@ -1592,13 +1649,20 @@ int most_stop_channel(struct most_interface *iface, int id)
 #ifdef CMPL_INTERRUPTIBLE
        if (wait_for_completion_interruptible(&c->cleanup)) {
                pr_info("Interrupted while clean up ch %d\n", c->channel_id);
+               mutex_unlock(&c->start_mutex);
                return -EINTR;
        }
 #else
        wait_for_completion(&c->cleanup);
 #endif
        c->is_poisoned = false;
-       c->is_started = false;
+
+out:
+       if (aim == c->aim0.ptr)
+               c->aim0.refs--;
+       if (aim == c->aim1.ptr)
+               c->aim1.refs--;
+       mutex_unlock(&c->start_mutex);
        return 0;
 }
 EXPORT_SYMBOL_GPL(most_stop_channel);
@@ -1651,13 +1715,13 @@ int most_deregister_aim(struct most_aim *aim)
        }
        list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
                list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
-                       if (c->first_aim == aim || c->second_aim == aim)
+                       if (c->aim0.ptr == aim || c->aim1.ptr == aim)
                                aim->disconnect_channel(
                                        c->iface, c->channel_id);
-                       if (c->first_aim == aim)
-                               c->first_aim = NULL;
-                       if (c->second_aim == aim)
-                               c->second_aim = NULL;
+                       if (c->aim0.ptr == aim)
+                               c->aim0.ptr = NULL;
+                       if (c->aim1.ptr == aim)
+                               c->aim1.ptr = NULL;
                }
        }
        list_del(&aim_obj->list);
@@ -1732,7 +1796,6 @@ struct kobject *most_register_interface(struct most_interface *iface)
                c->keep_mbo = false;
                c->enqueue_halt = false;
                c->is_poisoned = false;
-               c->is_started = false;
                c->cfg.direction = 0;
                c->cfg.data_type = 0;
                c->cfg.num_buffers = 0;
@@ -1745,6 +1808,7 @@ struct kobject *most_register_interface(struct most_interface *iface)
                INIT_LIST_HEAD(&c->halt_fifo);
                init_completion(&c->cleanup);
                atomic_set(&c->mbo_ref, 0);
+               mutex_init(&c->start_mutex);
                mutex_init(&c->stop_task_mutex);
                list_add_tail(&c->list, &inst->channel_list);
        }
@@ -1791,7 +1855,7 @@ void most_deregister_interface(struct most_interface *iface)
        }
 
        list_for_each_entry(c, &i->channel_list, list) {
-               if (!c->is_started)
+               if (c->aim0.refs + c->aim1.refs <= 0)
                        continue;
 
                mutex_lock(&c->stop_task_mutex);
index 299c7d5aa73ac8ddb08bdb100f6f0688dfeeaf31..e148b324331a4f75335a94972d86f696d1fa6441 100644 (file)
@@ -190,6 +190,7 @@ struct mbo {
        void *priv;
        struct list_head list;
        struct most_interface *ifp;
+       int *num_buffers_ptr;
        u16 hdm_channel_id;
        void *virt_address;
        dma_addr_t bus_address;
@@ -254,7 +255,7 @@ struct most_interface {
  * struct most_aim - identifies MOST device driver to mostcore
  * @name: Driver name
  * @probe_channel: function for core to notify driver about channel connection
- * @disconnect_channel: notification that a certain channel isn't available anymore
+ * @disconnect_channel: callback function to disconnect a certain channel
  * @rx_completion: completion handler for received packets
  * @tx_completion: completion handler for transmitted packets
  * @context: context pointer to be used by mostcore
@@ -307,10 +308,14 @@ void most_stop_enqueue(struct most_interface *iface, int channel_idx);
 void most_resume_enqueue(struct most_interface *iface, int channel_idx);
 int most_register_aim(struct most_aim *aim);
 int most_deregister_aim(struct most_aim *aim);
-struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx);
+struct mbo *most_get_mbo(struct most_interface *iface, int channel_idx,
+                        struct most_aim *);
 void most_put_mbo(struct mbo *mbo);
-int most_start_channel(struct most_interface *iface, int channel_idx);
-int most_stop_channel(struct most_interface *iface, int channel_idx);
+int channel_has_mbo(struct most_interface *iface, int channel_idx);
+int most_start_channel(struct most_interface *iface, int channel_idx,
+                      struct most_aim *);
+int most_stop_channel(struct most_interface *iface, int channel_idx,
+                     struct most_aim *);
 
 
 #endif /* MOST_CORE_H_ */
index b2e6237ae913722e67eaf342d2302b85504d836c..e893d5d8b8628e975982633cdd53d5bf0a5f97f2 100644 (file)
@@ -145,7 +145,7 @@ static int spinand_read_id(struct spi_device *spi_nand, u8 *id)
  *    Once the status turns to be ready, the other status bits also are
  *    valid status bits.
  */
-static int spinand_read_status(struct spi_device *spi_nand, uint8_t *status)
+static int spinand_read_status(struct spi_device *spi_nand, u8 *status)
 {
        struct spinand_cmd cmd = {0};
        int ret;
@@ -186,6 +186,7 @@ static int wait_till_ready(struct spi_device *spi_nand)
 
        return -1;
 }
+
 /**
  * spinand_get_otp- send command 0xf to read the SPI Nand OTP register
  * Description:
@@ -321,7 +322,7 @@ static int spinand_read_page_to_cache(struct spi_device *spi_nand, u16 page_id)
  *   No tRd delay.
  */
 static int spinand_read_from_cache(struct spi_device *spi_nand, u16 page_id,
-               u16 byte_id, u16 len, u8 *rbuf)
+                                  u16 byte_id, u16 len, u8 *rbuf)
 {
        struct spinand_cmd cmd = {0};
        u16 column;
@@ -352,7 +353,7 @@ static int spinand_read_from_cache(struct spi_device *spi_nand, u16 page_id,
  *   Poll to read status to wait for tRD time.
  */
 static int spinand_read_page(struct spi_device *spi_nand, u16 page_id,
-               u16 offset, u16 len, u8 *rbuf)
+                            u16 offset, u16 len, u8 *rbuf)
 {
        int ret;
        u8 status = 0;
@@ -374,14 +375,14 @@ static int spinand_read_page(struct spi_device *spi_nand, u16 page_id,
                ret = spinand_read_status(spi_nand, &status);
                if (ret < 0) {
                        dev_err(&spi_nand->dev,
-                                       "err %d read status register\n", ret);
+                               "err %d read status register\n", ret);
                        return ret;
                }
 
                if ((status & STATUS_OIP_MASK) == STATUS_READY) {
                        if ((status & STATUS_ECC_MASK) == STATUS_ECC_ERROR) {
                                dev_err(&spi_nand->dev, "ecc error, page=%d\n",
-                                               page_id);
+                                       page_id);
                                return 0;
                        }
                        break;
@@ -419,7 +420,8 @@ static int spinand_read_page(struct spi_device *spi_nand, u16 page_id,
  *   Since it is writing the data to cache, there is no tPROG time.
  */
 static int spinand_program_data_to_cache(struct spi_device *spi_nand,
-               u16 page_id, u16 byte_id, u16 len, u8 *wbuf)
+                                        u16 page_id, u16 byte_id,
+                                        u16 len, u8 *wbuf)
 {
        struct spinand_cmd cmd = {0};
        u16 column;
@@ -473,11 +475,11 @@ static int spinand_program_execute(struct spi_device *spi_nand, u16 page_id)
  *   Poll to wait for the tPROG time to finish the transaction.
  */
 static int spinand_program_page(struct spi_device *spi_nand,
-               u16 page_id, u16 offset, u16 len, u8 *buf)
+                               u16 page_id, u16 offset, u16 len, u8 *buf)
 {
        int retval;
        u8 status = 0;
-       uint8_t *wbuf;
+       u8 *wbuf;
 #ifdef CONFIG_MTD_SPINAND_ONDIEECC
        unsigned int i, j;
 
@@ -507,7 +509,7 @@ static int spinand_program_page(struct spi_device *spi_nand,
                dev_err(&spi_nand->dev, "wait timedout!!!\n");
 
        retval = spinand_program_data_to_cache(spi_nand, page_id,
-                       offset, len, wbuf);
+                                              offset, len, wbuf);
        if (retval < 0)
                return retval;
        retval = spinand_program_execute(spi_nand, page_id);
@@ -517,8 +519,7 @@ static int spinand_program_page(struct spi_device *spi_nand,
                retval = spinand_read_status(spi_nand, &status);
                if (retval < 0) {
                        dev_err(&spi_nand->dev,
-                                       "error %d reading status register\n",
-                                       retval);
+                               "error %d reading status register\n", retval);
                        return retval;
                }
 
@@ -593,8 +594,7 @@ static int spinand_erase_block(struct spi_device *spi_nand, u16 block_id)
                retval = spinand_read_status(spi_nand, &status);
                if (retval < 0) {
                        dev_err(&spi_nand->dev,
-                                       "error %d reading status register\n",
-                                       (int) retval);
+                               "error %d reading status register\n", retval);
                        return retval;
                }
 
@@ -612,10 +612,10 @@ static int spinand_erase_block(struct spi_device *spi_nand, u16 block_id)
 
 #ifdef CONFIG_MTD_SPINAND_ONDIEECC
 static int spinand_write_page_hwecc(struct mtd_info *mtd,
-               struct nand_chip *chip, const uint8_t *buf, int oob_required,
-               int page)
+                                   struct nand_chip *chip,
+                                   const u8 *buf, int oob_required, int page)
 {
-       const uint8_t *p = buf;
+       const u8 *p = buf;
        int eccsize = chip->ecc.size;
        int eccsteps = chip->ecc.steps;
 
@@ -625,11 +625,11 @@ static int spinand_write_page_hwecc(struct mtd_info *mtd,
 }
 
 static int spinand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
-               uint8_t *buf, int oob_required, int page)
+                                  u8 *buf, int oob_required, int page)
 {
        int retval;
        u8 status;
-       uint8_t *p = buf;
+       u8 *p = buf;
        int eccsize = chip->ecc.size;
        int eccsteps = chip->ecc.steps;
        struct spinand_info *info = (struct spinand_info *)chip->priv;
@@ -644,8 +644,7 @@ static int spinand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                retval = spinand_read_status(info->spi, &status);
                if (retval < 0) {
                        dev_err(&mtd->dev,
-                                       "error %d reading status register\n",
-                                       retval);
+                               "error %d reading status register\n", retval);
                        return retval;
                }
 
@@ -660,7 +659,6 @@ static int spinand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
                }
        }
        return 0;
-
 }
 #endif
 
@@ -668,7 +666,7 @@ static void spinand_select_chip(struct mtd_info *mtd, int dev)
 {
 }
 
-static uint8_t spinand_read_byte(struct mtd_info *mtd)
+static u8 spinand_read_byte(struct mtd_info *mtd)
 {
        struct spinand_state *state = mtd_to_state(mtd);
        u8 data;
@@ -678,7 +676,6 @@ static uint8_t spinand_read_byte(struct mtd_info *mtd)
        return data;
 }
 
-
 static int spinand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 {
        struct spinand_info *info = (struct spinand_info *)chip->priv;
@@ -696,8 +693,7 @@ static int spinand_wait(struct mtd_info *mtd, struct nand_chip *chip)
                retval = spinand_read_status(info->spi, &status);
                if (retval < 0) {
                        dev_err(&mtd->dev,
-                                       "error %d reading status register\n",
-                                       retval);
+                               "error %d reading status register\n", retval);
                        return retval;
                }
 
@@ -709,16 +705,15 @@ static int spinand_wait(struct mtd_info *mtd, struct nand_chip *chip)
        return 0;
 }
 
-static void spinand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
+static void spinand_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
 {
-
        struct spinand_state *state = mtd_to_state(mtd);
 
        memcpy(state->buf + state->buf_ptr, buf, len);
        state->buf_ptr += len;
 }
 
-static void spinand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
+static void spinand_read_buf(struct mtd_info *mtd, u8 *buf, int len)
 {
        struct spinand_state *state = mtd_to_state(mtd);
 
@@ -739,14 +734,14 @@ static void spinand_reset(struct spi_device *spi_nand)
                pr_info("spinand reset failed!\n");
 
        /* elapse 1ms before issuing any other command */
-       udelay(1000);
+       usleep_range(1000, 2000);
 
        if (wait_till_ready(spi_nand))
                dev_err(&spi_nand->dev, "wait timedout!\n");
 }
 
 static void spinand_cmdfunc(struct mtd_info *mtd, unsigned int command,
-               int column, int page)
+                           int column, int page)
 {
        struct nand_chip *chip = (struct nand_chip *)mtd->priv;
        struct spinand_info *info = (struct spinand_info *)chip->priv;
@@ -792,7 +787,7 @@ static void spinand_cmdfunc(struct mtd_info *mtd, unsigned int command,
        /* PAGEPROG reuses all of the setup from SEQIN and adds the length */
        case NAND_CMD_PAGEPROG:
                spinand_program_page(info->spi, state->row, state->col,
-                               state->buf_ptr, state->buf);
+                                    state->buf_ptr, state->buf);
                break;
        case NAND_CMD_STATUS:
                spinand_get_otp(info->spi, state->buf);
@@ -805,7 +800,7 @@ static void spinand_cmdfunc(struct mtd_info *mtd, unsigned int command,
                if (wait_till_ready(info->spi))
                        dev_err(&info->spi->dev, "WAIT timedout!!!\n");
                /* a minimum of 250us must elapse before issuing RESET cmd*/
-               udelay(250);
+               usleep_range(250, 1000);
                spinand_reset(info->spi);
                break;
        default:
@@ -840,6 +835,7 @@ static int spinand_lock_block(struct spi_device *spi_nand, u8 lock)
 
        return ret;
 }
+
 /*
  * spinand_probe - [spinand Interface]
  * @spi_nand: registered device driver.
@@ -856,7 +852,7 @@ static int spinand_probe(struct spi_device *spi_nand)
        struct mtd_part_parser_data ppdata;
 
        info  = devm_kzalloc(&spi_nand->dev, sizeof(struct spinand_info),
-                       GFP_KERNEL);
+                            GFP_KERNEL);
        if (!info)
                return -ENOMEM;
 
@@ -865,7 +861,7 @@ static int spinand_probe(struct spi_device *spi_nand)
        spinand_lock_block(spi_nand, BL_ALL_UNLOCKED);
 
        state = devm_kzalloc(&spi_nand->dev, sizeof(struct spinand_state),
-                       GFP_KERNEL);
+                            GFP_KERNEL);
        if (!state)
                return -ENOMEM;
 
@@ -876,7 +872,7 @@ static int spinand_probe(struct spi_device *spi_nand)
                return -ENOMEM;
 
        chip = devm_kzalloc(&spi_nand->dev, sizeof(struct nand_chip),
-                       GFP_KERNEL);
+                           GFP_KERNEL);
        if (!chip)
                return -ENOMEM;
 
@@ -941,6 +937,7 @@ static const struct of_device_id spinand_dt[] = {
        { .compatible = "spinand,mt29f", },
        {}
 };
+MODULE_DEVICE_TABLE(of, spinand_dt);
 
 /*
  * Device name structure description
index 6c8e413b5b632d005d3693a985f9bf2e71a943dc..ae62975cf44a7bb4fa37ba008191c6e6968666b2 100644 (file)
 
 /* status */
 #define STATUS_OIP_MASK                        0x01
-#define STATUS_READY                   (0 << 0)
-#define STATUS_BUSY                    (1 << 0)
+#define STATUS_READY                   0
+#define STATUS_BUSY                    BIT(0)
 
 #define STATUS_E_FAIL_MASK             0x04
-#define STATUS_E_FAIL                  (1 << 2)
+#define STATUS_E_FAIL                  BIT(2)
 
 #define STATUS_P_FAIL_MASK             0x08
-#define STATUS_P_FAIL                  (1 << 3)
+#define STATUS_P_FAIL                  BIT(3)
 
 #define STATUS_ECC_MASK                        0x30
-#define STATUS_ECC_1BIT_CORRECTED      (1 << 4)
-#define STATUS_ECC_ERROR               (2 << 4)
-#define STATUS_ECC_RESERVED            (3 << 4)
+#define STATUS_ECC_1BIT_CORRECTED      BIT(4)
+#define STATUS_ECC_ERROR               BIT(5)
+#define STATUS_ECC_RESERVED            (BIT(5) | BIT(4))
 
 /*ECC enable defines*/
 #define OTP_ECC_MASK                   0x10
@@ -84,8 +84,8 @@ struct spinand_info {
 };
 
 struct spinand_state {
-       uint32_t        col;
-       uint32_t        row;
+       u32     col;
+       u32     row;
        int             buf_ptr;
        u8              *buf;
 };
index e914147d737976701f1c87dda632c325e39ff103..7806c2bc3af34299b5bb439e943f56d05cb468a6 100644 (file)
@@ -58,7 +58,6 @@
 #define MAX_NUM_XLS_GMAC       8
 #define MAX_NUM_XLR_GMAC       4
 
-
 static u32 xlr_gmac_offsets[] = {
        NETLOGIC_IO_GMAC_0_OFFSET, NETLOGIC_IO_GMAC_1_OFFSET,
        NETLOGIC_IO_GMAC_2_OFFSET, NETLOGIC_IO_GMAC_3_OFFSET,
index 2f65ec5a615cdf16ab84df59e7033285f9291c21..7ae8874daee884c6437edb44b96efba1410119de 100644 (file)
 #define MAC_CRC_LEN                     4
 #define MAX_NUM_MSGRNG_STN_CC           128
 #define MAX_MSG_SND_ATTEMPTS           100     /* 13 stns x 4 entry msg/stn +
-                                                  headroom */
+                                                * headroom
+                                                */
 
 #define MAC_FRIN_TO_BE_SENT_THRESHOLD   16
 
index 164634d61ac588e60a6d7b2391210a710a78e3c5..802c9597d42104d2f64c490280581d83bb315cae 100644 (file)
@@ -710,7 +710,6 @@ static irqreturn_t nvec_interrupt(int irq, void *dev)
                status & RCVD ? " RCVD" : "",
                status & RNW ? " RNW" : "");
 
-
        /*
         * TODO: A correct fix needs to be found for this.
         *
index 9bd73ea5a1fa62e81cd0f1af68895d77c0a32832..6f2871784ba5955548a7b5f0b2797e22bc5ef109 100644 (file)
@@ -3216,9 +3216,9 @@ static int octeon_usb_urb_enqueue(struct usb_hcd *hcd,
                 * Allocate a structure to use for our private list of
                 * isochronous packets.
                 */
-               iso_packet = kmalloc(urb->number_of_packets *
-                                    sizeof(struct cvmx_usb_iso_packet),
-                                    GFP_ATOMIC);
+               iso_packet = kmalloc_array(urb->number_of_packets,
+                                          sizeof(struct cvmx_usb_iso_packet),
+                                          GFP_ATOMIC);
                if (iso_packet) {
                        int i;
                        /* Fill the list with the data from the URB */
@@ -3743,6 +3743,7 @@ static const struct of_device_id octeon_usb_match[] = {
        },
        {},
 };
+MODULE_DEVICE_TABLE(of, octeon_usb_match);
 
 static struct platform_driver octeon_usb_driver = {
        .driver = {
index 9012dee0c348325a4d25668ff54610d6c1aac52d..8ca17210d9171d720af4528adcb7ef6f13ca6830 100644 (file)
@@ -19,5 +19,3 @@ octeon-ethernet-y += ethernet-rx.o
 octeon-ethernet-y += ethernet-sgmii.o
 octeon-ethernet-y += ethernet-spi.o
 octeon-ethernet-y += ethernet-tx.o
-octeon-ethernet-y += ethernet-xaui.o
-
index f92e0c478e1686f07f6d72795493eb8cf254c372..13e4cee1f86d09865465712b6f42aa7ac4ce8165 100644 (file)
 /* Maximum number of SKBs to try to free per xmit packet. */
 #define MAX_OUT_QUEUE_DEPTH 1000
 
-#define FAU_TOTAL_TX_TO_CLEAN (CVMX_FAU_REG_END - sizeof(uint32_t))
-#define FAU_NUM_PACKET_BUFFERS_TO_FREE (FAU_TOTAL_TX_TO_CLEAN - sizeof(uint32_t))
+#define FAU_TOTAL_TX_TO_CLEAN (CVMX_FAU_REG_END - sizeof(u32))
+#define FAU_NUM_PACKET_BUFFERS_TO_FREE (FAU_TOTAL_TX_TO_CLEAN - sizeof(u32))
 
 #define TOTAL_NUMBER_OF_PORTS       (CVMX_PIP_NUM_INPUT_PORTS+1)
 
-
 #endif /* __ETHERNET_DEFINES_H__ */
index 51dcb611702f1fd1f274e989a57dd14fda85982e..613344b886e1687dff3bd2ba4ebe6a1ca32eae5e 100644 (file)
@@ -207,7 +207,7 @@ static irqreturn_t cvm_oct_rgmii_rml_interrupt(int cpl, void *dev_id)
 
 int cvm_oct_rgmii_open(struct net_device *dev)
 {
-       return cvm_oct_common_open(dev, cvm_oct_rgmii_poll, false);
+       return cvm_oct_common_open(dev, cvm_oct_rgmii_poll);
 }
 
 static void cvm_oct_rgmii_immediate_poll(struct work_struct *work)
index d1a33a927f6d1295f3cadaae26ea78d343ecab87..6aed3cf6c0b43402d11511f47167922f75ca2aec 100644 (file)
@@ -49,6 +49,8 @@ static struct napi_struct cvm_oct_napi;
 
 /**
  * cvm_oct_do_interrupt - interrupt handler.
+ * @cpl: Interrupt number. Unused
+ * @dev_id: Cookie to identify the device. Unused
  *
  * The interrupt occurs whenever the POW has packets in our group.
  *
@@ -102,7 +104,7 @@ static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work)
                    cvmx_read_csr(CVMX_GMXX_RXX_FRM_CTL(index, interface));
                if (gmxx_rxx_frm_ctl.s.pre_chk == 0) {
 
-                       uint8_t *ptr =
+                       u8 *ptr =
                            cvmx_phys_to_ptr(work->packet_ptr.s.addr);
                        int i = 0;
 
@@ -163,8 +165,8 @@ static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work)
 static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
 {
        const int       coreid = cvmx_get_core_num();
-       uint64_t        old_group_mask;
-       uint64_t        old_scratch;
+       u64     old_group_mask;
+       u64     old_scratch;
        int             rx_count = 0;
        int             did_work_request = 0;
        int             packet_not_copied;
@@ -284,7 +286,7 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
                         * entirely stored in the work entry.
                         */
                        if (unlikely(work->word2.s.bufs == 0)) {
-                               uint8_t *ptr = work->packet_data;
+                               u8 *ptr = work->packet_data;
 
                                if (likely(!work->word2.s.not_IP)) {
                                        /*
index 8bceb769166cd04cb057d97ece527e8648e1d92a..7424dc45ad39fd7e94c482fe84edca7de7b480a9 100644 (file)
@@ -27,7 +27,7 @@
 
 int cvm_oct_sgmii_open(struct net_device *dev)
 {
-       return cvm_oct_common_open(dev, cvm_oct_link_poll, true);
+       return cvm_oct_common_open(dev, cvm_oct_link_poll);
 }
 
 int cvm_oct_sgmii_init(struct net_device *dev)
index 9e2116f4c9153827a288dfa8a5701d28cecc0b56..c053c4a47a7eb4b87d2bb6f2d8d541f02f90c274 100644 (file)
@@ -143,8 +143,8 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        cvmx_pko_command_word0_t pko_command;
        union cvmx_buf_ptr hw_buffer;
-       uint64_t old_scratch;
-       uint64_t old_scratch2;
+       u64 old_scratch;
+       u64 old_scratch2;
        int qos;
        int i;
        enum {QUEUE_CORE, QUEUE_HW, QUEUE_DROP} queue_type;
@@ -549,7 +549,7 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
        /* Get a work queue entry */
        cvmx_wqe_t *work = cvmx_fpa_alloc(CVMX_FPA_WQE_POOL);
 
-       if (unlikely(work == NULL)) {
+       if (unlikely(!work)) {
                printk_ratelimited("%s: Failed to allocate a work queue entry\n",
                                   dev->name);
                priv->stats.tx_dropped++;
@@ -576,7 +576,7 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
         * calculation may add a little extra, but that doesn't
         * hurt.
         */
-       copy_location = packet_buffer + sizeof(uint64_t);
+       copy_location = packet_buffer + sizeof(u64);
        copy_location += ((CVMX_HELPER_FIRST_MBUFF_SKIP + 7) & 0xfff8) + 6;
 
        /*
diff --git a/drivers/staging/octeon/ethernet-xaui.c b/drivers/staging/octeon/ethernet-xaui.c
deleted file mode 100644 (file)
index 4b47bcf..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This file is based on code from OCTEON SDK by Cavium Networks.
- *
- * Copyright (c) 2003-2007 Cavium Networks
- *
- * This file is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, Version 2, as
- * published by the Free Software Foundation.
- */
-
-#include <linux/phy.h>
-#include <linux/kernel.h>
-#include <linux/netdevice.h>
-#include <linux/ratelimit.h>
-#include <net/dst.h>
-
-#include <asm/octeon/octeon.h>
-
-#include "ethernet-defines.h"
-#include "octeon-ethernet.h"
-#include "ethernet-util.h"
-#include "ethernet-mdio.h"
-
-#include <asm/octeon/cvmx-helper.h>
-
-#include <asm/octeon/cvmx-gmxx-defs.h>
-
-int cvm_oct_xaui_open(struct net_device *dev)
-{
-       return cvm_oct_common_open(dev, cvm_oct_link_poll, true);
-}
-
-int cvm_oct_xaui_init(struct net_device *dev)
-{
-       struct octeon_ethernet *priv = netdev_priv(dev);
-
-       cvm_oct_common_init(dev);
-       if (!octeon_is_simulation() && priv->phydev == NULL)
-               priv->poll = cvm_oct_link_poll;
-
-       return 0;
-}
index 7274fda0b77b9f4f89939ff3f477d6b25a2a0244..f69fb5cc7cb8fe21dff81f11d196f3d567f8d755 100644 (file)
@@ -86,19 +86,19 @@ int rx_napi_weight = 32;
 module_param(rx_napi_weight, int, 0444);
 MODULE_PARM_DESC(rx_napi_weight, "The NAPI WEIGHT parameter.");
 
-/**
+/*
  * cvm_oct_poll_queue - Workqueue for polling operations.
  */
 struct workqueue_struct *cvm_oct_poll_queue;
 
-/**
+/*
  * cvm_oct_poll_queue_stopping - flag to indicate polling should stop.
  *
  * Set to one right before cvm_oct_poll_queue is destroyed.
  */
 atomic_t cvm_oct_poll_queue_stopping = ATOMIC_INIT(0);
 
-/**
+/*
  * Array of every ethernet device owned by this driver indexed by
  * the ipd input port number.
  */
@@ -364,13 +364,6 @@ static void cvm_oct_common_set_multicast_list(struct net_device *dev)
        }
 }
 
-/**
- * cvm_oct_common_set_mac_address - set the hardware MAC address for a device
- * @dev:    The device in question.
- * @addr:   Address structure to change it too.
-
- * Returns Zero on success
- */
 static int cvm_oct_set_mac_filter(struct net_device *dev)
 {
        struct octeon_ethernet *priv = netdev_priv(dev);
@@ -382,11 +375,11 @@ static int cvm_oct_set_mac_filter(struct net_device *dev)
            && (cvmx_helper_interface_get_mode(interface) !=
                CVMX_HELPER_INTERFACE_MODE_SPI)) {
                int i;
-               uint8_t *ptr = dev->dev_addr;
-               uint64_t mac = 0;
+               u8 *ptr = dev->dev_addr;
+               u64 mac = 0;
 
                for (i = 0; i < 6; i++)
-                       mac = (mac << 8) | (uint64_t)ptr[i];
+                       mac = (mac << 8) | (u64)ptr[i];
 
                gmx_cfg.u64 =
                    cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
@@ -413,6 +406,13 @@ static int cvm_oct_set_mac_filter(struct net_device *dev)
        return 0;
 }
 
+/**
+ * cvm_oct_common_set_mac_address - set the hardware MAC address for a device
+ * @dev:    The device in question.
+ * @addr:   Socket address.
+ *
+ * Returns Zero on success
+ */
 static int cvm_oct_common_set_mac_address(struct net_device *dev, void *addr)
 {
        int r = eth_mac_addr(dev, addr);
@@ -481,7 +481,7 @@ void cvm_oct_common_uninit(struct net_device *dev)
 }
 
 int cvm_oct_common_open(struct net_device *dev,
-                       void (*link_poll)(struct net_device *), bool poll_now)
+                       void (*link_poll)(struct net_device *))
 {
        union cvmx_gmxx_prtx_cfg gmx_cfg;
        struct octeon_ethernet *priv = netdev_priv(dev);
@@ -512,8 +512,7 @@ int cvm_oct_common_open(struct net_device *dev,
                if (!link_info.s.link_up)
                        netif_carrier_off(dev);
                priv->poll = link_poll;
-               if (poll_now)
-                       link_poll(dev);
+               link_poll(dev);
        }
 
        return 0;
@@ -540,6 +539,11 @@ void cvm_oct_link_poll(struct net_device *dev)
        cvm_oct_note_carrier(priv, link_info);
 }
 
+static int cvm_oct_xaui_open(struct net_device *dev)
+{
+       return cvm_oct_common_open(dev, cvm_oct_link_poll);
+}
+
 static const struct net_device_ops cvm_oct_npi_netdev_ops = {
        .ndo_init               = cvm_oct_common_init,
        .ndo_uninit             = cvm_oct_common_uninit,
@@ -554,7 +558,7 @@ static const struct net_device_ops cvm_oct_npi_netdev_ops = {
 #endif
 };
 static const struct net_device_ops cvm_oct_xaui_netdev_ops = {
-       .ndo_init               = cvm_oct_xaui_init,
+       .ndo_init               = cvm_oct_common_init,
        .ndo_uninit             = cvm_oct_common_uninit,
        .ndo_open               = cvm_oct_xaui_open,
        .ndo_stop               = cvm_oct_common_stop,
@@ -674,7 +678,7 @@ static int cvm_oct_probe(struct platform_device *pdev)
        }
 
        cvm_oct_poll_queue = create_singlethread_workqueue("octeon-ethernet");
-       if (cvm_oct_poll_queue == NULL) {
+       if (!cvm_oct_poll_queue) {
                pr_err("octeon-ethernet: Cannot create workqueue");
                return -ENOMEM;
        }
@@ -835,7 +839,7 @@ static int cvm_oct_probe(struct platform_device *pdev)
                                cvm_oct_device[priv->port] = dev;
                                fau -=
                                    cvmx_pko_get_num_queues(priv->port) *
-                                   sizeof(uint32_t);
+                                   sizeof(u32);
                                queue_delayed_work(cvm_oct_poll_queue,
                                                &priv->port_periodic_work, HZ);
                        }
index a242c700bc537ad3c8b4df4478dc56b2f8114973..fdf24d120e7727052e428217d1a0f6193980534f 100644 (file)
@@ -43,7 +43,7 @@ struct octeon_ethernet {
        struct phy_device *phydev;
        unsigned int last_link;
        /* Last negotiated link state */
-       uint64_t link_info;
+       u64 link_info;
        /* Called periodically to check link status */
        void (*poll)(struct net_device *dev);
        struct delayed_work     port_periodic_work;
@@ -62,15 +62,13 @@ int cvm_oct_sgmii_open(struct net_device *dev);
 
 int cvm_oct_spi_init(struct net_device *dev);
 void cvm_oct_spi_uninit(struct net_device *dev);
-int cvm_oct_xaui_init(struct net_device *dev);
-int cvm_oct_xaui_open(struct net_device *dev);
 
 int cvm_oct_common_init(struct net_device *dev);
 void cvm_oct_common_uninit(struct net_device *dev);
 void cvm_oct_adjust_link(struct net_device *dev);
 int cvm_oct_common_stop(struct net_device *dev);
 int cvm_oct_common_open(struct net_device *dev,
-                       void (*link_poll)(struct net_device *), bool poll_now);
+                       void (*link_poll)(struct net_device *));
 void cvm_oct_note_carrier(struct octeon_ethernet *priv,
                          cvmx_helper_link_info_t li);
 void cvm_oct_link_poll(struct net_device *dev);
index d115f5c0e3415dcb8f6084fdcc0636522550501c..f45b2ef05f481fce35c12e62ee4b792f77ae2edf 100644 (file)
@@ -60,7 +60,7 @@ static s32 dcon_read(struct dcon_priv *dcon, u8 reg)
 
 static int dcon_hw_init(struct dcon_priv *dcon, int is_init)
 {
-       uint16_t ver;
+       u16 ver;
        int rc = 0;
 
        ver = dcon_read(dcon, DCON_REG_ID);
@@ -100,7 +100,6 @@ static int dcon_hw_init(struct dcon_priv *dcon, int is_init)
        }
        dcon_write(dcon, DCON_REG_MODE, dcon->disp_mode);
 
-
        /* Set the scanline to interrupt on during resume */
        dcon_write(dcon, DCON_REG_SCAN_INT, resumeline);
 
@@ -238,15 +237,13 @@ static void dcon_sleep(struct dcon_priv *dcon, bool sleep)
  */
 static void dcon_load_holdoff(struct dcon_priv *dcon)
 {
-       struct timespec delta_t, now;
+       ktime_t delta_t, now;
 
        while (1) {
-               getnstimeofday(&now);
-               delta_t = timespec_sub(now, dcon->load_time);
-               if (delta_t.tv_sec != 0 ||
-                       delta_t.tv_nsec > NSEC_PER_MSEC * 20) {
+               now = ktime_get();
+               delta_t = ktime_sub(now, dcon->load_time);
+               if (ktime_to_ns(delta_t) > NSEC_PER_MSEC * 20)
                        break;
-               }
                mdelay(4);
        }
 }
@@ -325,19 +322,19 @@ static void dcon_source_switch(struct work_struct *work)
 
                /* And turn off the DCON */
                pdata->set_dconload(1);
-               getnstimeofday(&dcon->load_time);
+               dcon->load_time = ktime_get();
 
                pr_info("The CPU has control\n");
                break;
        case DCON_SOURCE_DCON:
        {
-               struct timespec delta_t;
+               ktime_t delta_t;
 
                pr_info("dcon_source_switch to DCON\n");
 
                /* Clear DCONLOAD - this implies that the DCON is in control */
                pdata->set_dconload(0);
-               getnstimeofday(&dcon->load_time);
+               dcon->load_time = ktime_get();
 
                wait_event_timeout(dcon->waitq, dcon->switched, HZ/2);
 
@@ -355,14 +352,14 @@ static void dcon_source_switch(struct work_struct *work)
                         * deassert and reassert, and hope for the best.
                         * see http://dev.laptop.org/ticket/9664
                         */
-                       delta_t = timespec_sub(dcon->irq_time, dcon->load_time);
-                       if (dcon->switched && delta_t.tv_sec == 0 &&
-                                       delta_t.tv_nsec < NSEC_PER_MSEC * 20) {
+                       delta_t = ktime_sub(dcon->irq_time, dcon->load_time);
+                       if (dcon->switched && ktime_to_ns(delta_t)
+                           < NSEC_PER_MSEC * 20) {
                                pr_err("missed loading, retrying\n");
                                pdata->set_dconload(1);
                                mdelay(41);
                                pdata->set_dconload(0);
-                               getnstimeofday(&dcon->load_time);
+                               dcon->load_time = ktime_get();
                                mdelay(41);
                        }
                }
@@ -619,7 +616,7 @@ static int dcon_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
        dcon_device = platform_device_alloc("dcon", -1);
 
-       if (dcon_device == NULL) {
+       if (!dcon_device) {
                pr_err("Unable to create the DCON device\n");
                rc = -ENOMEM;
                goto eirq;
@@ -682,7 +679,7 @@ static int dcon_remove(struct i2c_client *client)
 
        backlight_device_unregister(dcon->bl_dev);
 
-       if (dcon_device != NULL)
+       if (dcon_device)
                platform_device_unregister(dcon_device);
        cancel_work_sync(&dcon->switch_source);
 
@@ -725,7 +722,6 @@ static int dcon_resume(struct device *dev)
 
 #endif /* CONFIG_PM */
 
-
 irqreturn_t dcon_interrupt(int irq, void *id)
 {
        struct dcon_priv *dcon = id;
@@ -742,7 +738,7 @@ irqreturn_t dcon_interrupt(int irq, void *id)
        case 2: /* switch to DCON mode */
        case 1: /* switch to CPU mode */
                dcon->switched = true;
-               getnstimeofday(&dcon->irq_time);
+               dcon->irq_time = ktime_get();
                wake_up(&dcon->waitq);
                break;
 
@@ -756,7 +752,7 @@ irqreturn_t dcon_interrupt(int irq, void *id)
                 */
                if (dcon->curr_src != dcon->pending_src && !dcon->switched) {
                        dcon->switched = true;
-                       getnstimeofday(&dcon->irq_time);
+                       dcon->irq_time = ktime_get();
                        wake_up(&dcon->waitq);
                        pr_debug("switching w/ status 0/0\n");
                } else {
index d06e19db1b80c242a97c7ba71a4cb5dec745e37c..215e7ec4dea237b3c6452efe2f3b957fb99507ab 100644 (file)
@@ -79,8 +79,8 @@ struct dcon_priv {
 
        /* Variables used during switches */
        bool switched;
-       struct timespec irq_time;
-       struct timespec load_time;
+       ktime_t irq_time;
+       ktime_t load_time;
 
        /* Current output type; true == mono, false == color */
        bool mono;
index 3e9ee7ee6be2a20d40ce01a4c203c24635c89f7c..79ac19246548afb5a6e5574a97d09dd7cb8ca110 100644 (file)
@@ -71,7 +71,7 @@
 #define KEYPAD_BUFFER          64
 
 /* poll the keyboard this every second */
-#define INPUT_POLL_TIME                (HZ/50)
+#define INPUT_POLL_TIME                (HZ / 50)
 /* a key starts to repeat after this times INPUT_POLL_TIME */
 #define KEYPAD_REP_START       (10)
 /* a key repeats this times INPUT_POLL_TIME */
@@ -576,7 +576,6 @@ static int keypad_enabled = NOT_SET;
 module_param(keypad_enabled, int, 0000);
 MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
 
-
 static const unsigned char *lcd_char_conv;
 
 /* for some LCD drivers (ks0074) we need a charset conversion table. */
@@ -826,7 +825,8 @@ static void lcd_write_cmd_s(int cmd)
        lcd_send_serial(0x1F);  /* R/W=W, RS=0 */
        lcd_send_serial(cmd & 0x0F);
        lcd_send_serial((cmd >> 4) & 0x0F);
-       udelay(40);             /* the shortest command takes at least 40 us */
+       /* the shortest command takes at least 40 us */
+       usleep_range(40, 100);
        spin_unlock_irq(&pprt_lock);
 }
 
@@ -837,7 +837,8 @@ static void lcd_write_data_s(int data)
        lcd_send_serial(0x5F);  /* R/W=W, RS=1 */
        lcd_send_serial(data & 0x0F);
        lcd_send_serial((data >> 4) & 0x0F);
-       udelay(40);             /* the shortest data takes at least 40 us */
+       /* the shortest data takes at least 40 us */
+       usleep_range(40, 100);
        spin_unlock_irq(&pprt_lock);
 }
 
@@ -847,19 +848,20 @@ static void lcd_write_cmd_p8(int cmd)
        spin_lock_irq(&pprt_lock);
        /* present the data to the data port */
        w_dtr(pprt, cmd);
-       udelay(20);     /* maintain the data during 20 us before the strobe */
+       /* maintain the data during 20 us before the strobe */
+       usleep_range(20, 100);
 
        bits.e = BIT_SET;
        bits.rs = BIT_CLR;
        bits.rw = BIT_CLR;
        set_ctrl_bits();
 
-       udelay(40);     /* maintain the strobe during 40 us */
+       usleep_range(40, 100);  /* maintain the strobe during 40 us */
 
        bits.e = BIT_CLR;
        set_ctrl_bits();
 
-       udelay(120);    /* the shortest command takes at least 120 us */
+       usleep_range(120, 500); /* the shortest command takes at least 120 us */
        spin_unlock_irq(&pprt_lock);
 }
 
@@ -869,19 +871,20 @@ static void lcd_write_data_p8(int data)
        spin_lock_irq(&pprt_lock);
        /* present the data to the data port */
        w_dtr(pprt, data);
-       udelay(20);     /* maintain the data during 20 us before the strobe */
+       /* maintain the data during 20 us before the strobe */
+       usleep_range(20, 100);
 
        bits.e = BIT_SET;
        bits.rs = BIT_SET;
        bits.rw = BIT_CLR;
        set_ctrl_bits();
 
-       udelay(40);     /* maintain the strobe during 40 us */
+       usleep_range(40, 100);  /* maintain the strobe during 40 us */
 
        bits.e = BIT_CLR;
        set_ctrl_bits();
 
-       udelay(45);     /* the shortest data takes at least 45 us */
+       usleep_range(45, 100);  /* the shortest data takes at least 45 us */
        spin_unlock_irq(&pprt_lock);
 }
 
@@ -891,7 +894,7 @@ static void lcd_write_cmd_tilcd(int cmd)
        spin_lock_irq(&pprt_lock);
        /* present the data to the control port */
        w_ctr(pprt, cmd);
-       udelay(60);
+       usleep_range(60, 120);
        spin_unlock_irq(&pprt_lock);
 }
 
@@ -901,7 +904,7 @@ static void lcd_write_data_tilcd(int data)
        spin_lock_irq(&pprt_lock);
        /* present the data to the data port */
        w_dtr(pprt, data);
-       udelay(60);
+       usleep_range(60, 120);
        spin_unlock_irq(&pprt_lock);
 }
 
@@ -909,8 +912,10 @@ static void lcd_gotoxy(void)
 {
        lcd_write_cmd(LCD_CMD_SET_DDRAM_ADDR
                      | (lcd.addr.y ? lcd.hwidth : 0)
-                     /* we force the cursor to stay at the end of the
-                        line if it wants to go farther */
+                     /*
+                      * we force the cursor to stay at the end of the
+                      * line if it wants to go farther
+                      */
                      | ((lcd.addr.x < lcd.bwidth) ? lcd.addr.x &
                         (lcd.hwidth - 1) : lcd.bwidth - 1));
 }
@@ -918,7 +923,7 @@ static void lcd_gotoxy(void)
 static void lcd_print(char c)
 {
        if (lcd.addr.x < lcd.bwidth) {
-               if (lcd_char_conv != NULL)
+               if (lcd_char_conv)
                        c = lcd_char_conv[(unsigned char)c];
                lcd_write_data(c);
                lcd.addr.x++;
@@ -942,7 +947,7 @@ static void lcd_clear_fast_s(void)
                lcd_send_serial(0x5F);  /* R/W=W, RS=1 */
                lcd_send_serial(' ' & 0x0F);
                lcd_send_serial((' ' >> 4) & 0x0F);
-               udelay(40);     /* the shortest data takes at least 40 us */
+               usleep_range(40, 100);  /* the shortest data takes at least 40 us */
        }
        spin_unlock_irq(&pprt_lock);
 
@@ -966,7 +971,7 @@ static void lcd_clear_fast_p8(void)
                w_dtr(pprt, ' ');
 
                /* maintain the data during 20 us before the strobe */
-               udelay(20);
+               usleep_range(20, 100);
 
                bits.e = BIT_SET;
                bits.rs = BIT_SET;
@@ -974,13 +979,13 @@ static void lcd_clear_fast_p8(void)
                set_ctrl_bits();
 
                /* maintain the strobe during 40 us */
-               udelay(40);
+               usleep_range(40, 100);
 
                bits.e = BIT_CLR;
                set_ctrl_bits();
 
                /* the shortest data takes at least 45 us */
-               udelay(45);
+               usleep_range(45, 100);
        }
        spin_unlock_irq(&pprt_lock);
 
@@ -1002,7 +1007,7 @@ static void lcd_clear_fast_tilcd(void)
        for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
                /* present the data to the data port */
                w_dtr(pprt, ' ');
-               udelay(60);
+               usleep_range(60, 120);
        }
 
        spin_unlock_irq(&pprt_lock);
@@ -1116,9 +1121,9 @@ static inline int handle_lcd_special_code(void)
                break;
        case '*':
                /* flash back light using the keypad timer */
-               if (scan_timer.function != NULL) {
-                       if (lcd.light_tempo == 0
-                                       && ((lcd.flags & LCD_FLAG_L) == 0))
+               if (scan_timer.function) {
+                       if (lcd.light_tempo == 0 &&
+                           ((lcd.flags & LCD_FLAG_L) == 0))
                                lcd_backlight(1);
                        lcd.light_tempo = FLASH_LIGHT_TEMPO;
                }
@@ -1198,7 +1203,7 @@ static inline int handle_lcd_special_code(void)
                char value;
                int addr;
 
-               if (strchr(esc, ';') == NULL)
+               if (!strchr(esc, ';'))
                        break;
 
                esc++;
@@ -1244,7 +1249,7 @@ static inline int handle_lcd_special_code(void)
        }
        case 'x':       /* gotoxy : LxXXX[yYYY]; */
        case 'y':       /* gotoxy : LyYYY[xXXX]; */
-               if (strchr(esc, ';') == NULL)
+               if (!strchr(esc, ';'))
                        break;
 
                while (*esc) {
@@ -1294,8 +1299,10 @@ static inline int handle_lcd_special_code(void)
                        if (lcd.flags & (LCD_FLAG_L))
                                lcd_backlight(1);
                        else if (lcd.light_tempo == 0)
-                               /* switch off the light only when the tempo
-                                  lighting is gone */
+                               /*
+                                * switch off the light only when the tempo
+                                * lighting is gone
+                                */
                                lcd_backlight(0);
                }
        }
@@ -1323,8 +1330,10 @@ static void lcd_write_char(char c)
                case '\b':
                        /* go back one char and clear it */
                        if (lcd.addr.x > 0) {
-                               /* check if we're not at the
-                                  end of the line */
+                               /*
+                                * check if we're not at the
+                                * end of the line
+                                */
                                if (lcd.addr.x < lcd.bwidth)
                                        /* back one char */
                                        lcd_write_cmd(LCD_CMD_SHIFT);
@@ -1340,8 +1349,10 @@ static void lcd_write_char(char c)
                        lcd_clear_fast();
                        break;
                case '\n':
-                       /* flush the remainder of the current line and
-                          go to the beginning of the next line */
+                       /*
+                        * flush the remainder of the current line and
+                        * go to the beginning of the next line
+                        */
                        for (; lcd.addr.x < lcd.bwidth; lcd.addr.x++)
                                lcd_write_data(' ');
                        lcd.addr.x = 0;
@@ -1364,8 +1375,10 @@ static void lcd_write_char(char c)
                }
        }
 
-       /* now we'll see if we're in an escape mode and if the current
-          escape sequence can be understood. */
+       /*
+        * now we'll see if we're in an escape mode and if the current
+        * escape sequence can be understood.
+        */
        if (lcd.esc_seq.len >= 2) {
                int processed = 0;
 
@@ -1388,8 +1401,10 @@ static void lcd_write_char(char c)
                }
 
                /* LCD special escape codes */
-               /* flush the escape sequence if it's been processed
-                  or if it is getting too long. */
+               /*
+                * flush the escape sequence if it's been processed
+                * or if it is getting too long.
+                */
                if (processed || (lcd.esc_seq.len >= LCD_ESCAPE_LEN))
                        lcd.esc_seq.len = -1;
        } /* escape codes */
@@ -1403,8 +1418,10 @@ static ssize_t lcd_write(struct file *file,
 
        for (; count-- > 0; (*ppos)++, tmp++) {
                if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
-                       /* let's be a little nice with other processes
-                          that need some CPU */
+                       /*
+                        * let's be a little nice with other processes
+                        * that need some CPU
+                        */
                        schedule();
 
                if (get_user(c, tmp))
@@ -1459,8 +1476,10 @@ static void panel_lcd_print(const char *s)
        if (lcd.enabled && lcd.initialized) {
                for (; count-- > 0; tmp++) {
                        if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
-                               /* let's be a little nice with other processes
-                                  that need some CPU */
+                               /*
+                                * let's be a little nice with other processes
+                                * that need some CPU
+                                */
                                schedule();
 
                        lcd_write_char(*tmp);
@@ -1634,9 +1653,11 @@ static void lcd_init(void)
        pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
                    lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
 
-       /* before this line, we must NOT send anything to the display.
+       /*
+        * before this line, we must NOT send anything to the display.
         * Since lcd_init_display() needs to write data, we have to
-        * enable mark the LCD initialized just before. */
+        * enable mark the LCD initialized just before.
+        */
        lcd.initialized = true;
        lcd_init_display();
 
@@ -1770,12 +1791,13 @@ static void phys_scan_contacts(void)
        phys_read |= (pmask_t) gndmask << 40;
 
        if (bitmask != gndmask) {
-               /* since clearing the outputs changed some inputs, we know
+               /*
+                * since clearing the outputs changed some inputs, we know
                 * that some input signals are currently tied to some outputs.
                 * So we'll scan them.
                 */
                for (bit = 0; bit < 8; bit++) {
-                       bitval = 1 << bit;
+                       bitval = BIT(bit);
 
                        if (!(scan_mask_o & bitval))    /* skip unused bits */
                                continue;
@@ -1786,8 +1808,10 @@ static void phys_scan_contacts(void)
                }
                w_dtr(pprt, oldval);    /* disable all outputs */
        }
-       /* this is easy: use old bits when they are flapping,
-        * use new ones when stable */
+       /*
+        * this is easy: use old bits when they are flapping,
+        * use new ones when stable
+        */
        phys_curr = (phys_prev & (phys_read ^ phys_read_prev)) |
                    (phys_read & ~(phys_read ^ phys_read_prev));
 }
@@ -1823,7 +1847,7 @@ static inline int input_state_high(struct logical_input *input)
                if ((input->type == INPUT_TYPE_STD) &&
                    (input->high_timer == 0)) {
                        input->high_timer++;
-                       if (input->u.std.press_fct != NULL)
+                       if (input->u.std.press_fct)
                                input->u.std.press_fct(input->u.std.press_data);
                } else if (input->type == INPUT_TYPE_KBD) {
                        /* will turn on the light */
@@ -1903,7 +1927,7 @@ static inline void input_state_falling(struct logical_input *input)
                if (input->type == INPUT_TYPE_STD) {
                        void (*release_fct)(int) = input->u.std.release_fct;
 
-                       if (release_fct != NULL)
+                       if (release_fct)
                                release_fct(input->u.std.release_data);
                } else if (input->type == INPUT_TYPE_KBD) {
                        char *release_str = input->u.kbd.release_str;
@@ -1987,14 +2011,14 @@ static void panel_scan_timer(void)
 
        if (lcd.enabled && lcd.initialized) {
                if (keypressed) {
-                       if (lcd.light_tempo == 0
-                                       && ((lcd.flags & LCD_FLAG_L) == 0))
+                       if (lcd.light_tempo == 0 &&
+                           ((lcd.flags & LCD_FLAG_L) == 0))
                                lcd_backlight(1);
                        lcd.light_tempo = FLASH_LIGHT_TEMPO;
                } else if (lcd.light_tempo > 0) {
                        lcd.light_tempo--;
-                       if (lcd.light_tempo == 0
-                                       && ((lcd.flags & LCD_FLAG_L) == 0))
+                       if (lcd.light_tempo == 0 &&
+                           ((lcd.flags & LCD_FLAG_L) == 0))
                                lcd_backlight(0);
                }
        }
@@ -2004,7 +2028,7 @@ static void panel_scan_timer(void)
 
 static void init_scan_timer(void)
 {
-       if (scan_timer.function != NULL)
+       if (scan_timer.function)
                return;         /* already started */
 
        setup_timer(&scan_timer, (void *)&panel_scan_timer, 0);
@@ -2039,12 +2063,12 @@ static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value,
                        return 0;       /* input name not found */
                neg = (in & 1); /* odd (lower) names are negated */
                in >>= 1;
-               im |= (1 << in);
+               im |= BIT(in);
 
                name++;
                if (isdigit(*name)) {
                        out = *name - '0';
-                       om |= (1 << out);
+                       om |= BIT(out);
                } else if (*name == '-') {
                        out = 8;
                } else {
@@ -2208,7 +2232,7 @@ static void panel_attach(struct parport *port)
        /* panel_cb.flags = 0 should be PARPORT_DEV_EXCL? */
 
        pprt = parport_register_dev_model(port, "panel", &panel_cb, 0);
-       if (pprt == NULL) {
+       if (!pprt) {
                pr_err("%s: port->number=%d parport=%d, parport_register_device() failed\n",
                       __func__, port->number, parport);
                return;
@@ -2255,10 +2279,10 @@ static void panel_detach(struct parport *port)
                       __func__, port->number, parport);
                return;
        }
-       if (scan_timer.function != NULL)
+       if (scan_timer.function)
                del_timer_sync(&scan_timer);
 
-       if (pprt != NULL) {
+       if (pprt) {
                if (keypad.enabled) {
                        misc_deregister(&keypad_dev);
                        keypad_initialized = 0;
index d7f62359d7430fd0933ca84481db701073aee5b1..ba8765063174c4e05b517cdf45d33c6c5f57cf25 100644 (file)
@@ -1,5 +1,5 @@
 menuconfig STAGING_RDMA
-        bool "RDMA staging drivers"
+        tristate "RDMA staging drivers"
        depends on INFINIBAND
        depends on PCI || BROKEN
        depends on HAS_IOMEM
index 766a71ccefed20975fd9c6fc264f2ab69d071170..35ac536b2d45de624407158ec4546dbf2c66c27f 100644 (file)
@@ -548,7 +548,7 @@ static irqreturn_t c2_interrupt(int irq, void *dev_id)
 {
        unsigned int netisr0, dmaisr;
        int handled = 0;
-       struct c2_dev *c2dev = (struct c2_dev *) dev_id;
+       struct c2_dev *c2dev = dev_id;
 
        /* Process CCILNET interrupts */
        netisr0 = readl(c2dev->regs + C2_NISR0);
@@ -675,11 +675,11 @@ static int c2_up(struct net_device *netdev)
 
        return 0;
 
-      bail1:
+bail1:
        c2_rx_clean(c2_port);
        kfree(c2_port->rx_ring.start);
 
-      bail0:
+bail0:
        pci_free_consistent(c2dev->pcidev, c2_port->mem_size, c2_port->mem,
                            c2_port->dma);
 
index cedda25232be2454b3b2f0902152d96a7b1dfd75..eb7a92b2692facd4e055381ed8b3fb2da64577e1 100644 (file)
@@ -183,7 +183,7 @@ void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
        switch (resource_indicator) {
        case C2_RES_IND_QP:{
 
-               struct c2_qp *qp = (struct c2_qp *)resource_user_context;
+               struct c2_qp *qp = resource_user_context;
                struct iw_cm_id *cm_id = qp->cm_id;
                struct c2wr_ae_active_connect_results *res;
 
@@ -273,7 +273,7 @@ void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
                struct c2wr_ae_connection_request *req =
                        &wr->ae.ae_connection_request;
                struct iw_cm_id *cm_id =
-                       (struct iw_cm_id *)resource_user_context;
+                       resource_user_context;
 
                pr_debug("C2_RES_IND_EP event_id=%d\n", event_id);
                if (event_id != CCAE_CONNECTION_REQUEST) {
@@ -303,7 +303,7 @@ void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
 
        case C2_RES_IND_CQ:{
                struct c2_cq *cq =
-                   (struct c2_cq *) resource_user_context;
+                   resource_user_context;
 
                pr_debug("IB_EVENT_CQ_ERR\n");
                ib_event.device = &c2dev->ibdev;
index 78d247ec69612ba287efde11f7583724e508408d..039872dfabbcaad233fc69c5e69608856e703072 100644 (file)
@@ -131,7 +131,7 @@ void c2_free_mqsp(__be16 *mqsp)
        *mqsp = (__force __be16) head->head;
 
        /* Compute the shared_ptr index */
-       idx = ((unsigned long) mqsp & ~PAGE_MASK) >> 1;
+       idx = (offset_in_page(mqsp)) >> 1;
        idx -= (unsigned long) &(((struct sp_chunk *) 0)->shared_ptr[0]) >> 1;
 
        /* Point this index at the head */
index 23bfa94fbd4e4094b906c83f2504e00bc6ebab21..f8dbdb9e0f66669bb1cd865a619eab7d55bffa6d 100644 (file)
@@ -278,10 +278,7 @@ int c2_llp_service_destroy(struct iw_cm_id *cm_id)
                err = -ENOMEM;
                goto bail0;
        }
-       if ((err = c2_errno(reply)) != 0)
-               goto bail1;
 
- bail1:
        vq_repbuf_free(c2dev, reply);
  bail0:
        vq_req_free(c2dev, vq_req);
index 1b63185b4ad4fa977bc4f211fe159cd32c83aabb..3ef881f2da0fb1557a8e3642d72604196dc97f6d 100644 (file)
@@ -374,13 +374,13 @@ int c2_init_cq(struct c2_dev *c2dev, int entries,
 
        return 0;
 
-      bail3:
+bail3:
        vq_repbuf_free(c2dev, reply);
-      bail2:
+bail2:
        vq_req_free(c2dev, vq_req);
-      bail1:
+bail1:
        c2_free_cq_buf(c2dev, &cq->mq);
-      bail0:
+bail0:
        c2_free_mqsp(cq->mq.shared);
 
        return err;
@@ -429,9 +429,9 @@ void c2_free_cq(struct c2_dev *c2dev, struct c2_cq *cq)
        reply = (struct c2wr_cq_destroy_rep *) (unsigned long) (vq_req->reply_msg);
        if (reply)
                vq_repbuf_free(c2dev, reply);
-      bail1:
+bail1:
        vq_req_free(c2dev, vq_req);
-      bail0:
+bail0:
        if (cq->is_kernel) {
                c2_free_cq_buf(c2dev, &cq->mq);
        }
index 3a17d9b36dbac2b947d7d09318878f00cc2e0403..74b32a9711244f7fddeebe9e498bf55fd0a6b110 100644 (file)
@@ -122,7 +122,7 @@ static void handle_vq(struct c2_dev *c2dev, u32 mq_index)
        struct iw_cm_event cm_event;
        int err;
 
-       reply_vq = (struct c2_mq *) c2dev->qptr_array[mq_index];
+       reply_vq = c2dev->qptr_array[mq_index];
 
        /*
         * get next msg from mq_index into adapter_msg.
index 119c4f3d9791a81c44164737f5c9f147b5455139..25081e2913de1dfd08c719c11142f9e16ca41f23 100644 (file)
@@ -164,7 +164,7 @@ send_pbl_messages(struct c2_dev *c2dev, __be32 stag_index,
        err = c2_errno(reply);
 
        vq_repbuf_free(c2dev, reply);
-      bail0:
+bail0:
        kfree(wr);
        return err;
 }
@@ -304,11 +304,11 @@ c2_nsmr_register_phys_kern(struct c2_dev *c2dev, u64 *addr_list,
 
        return err;
 
-      bail2:
+bail2:
        vq_repbuf_free(c2dev, reply);
-      bail1:
+bail1:
        kfree(wr);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
@@ -371,7 +371,7 @@ int c2_stag_dealloc(struct c2_dev *c2dev, u32 stag_index)
        err = c2_errno(reply);
 
        vq_repbuf_free(c2dev, reply);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
index 0cddc49beae1f47d66e7f310ed3c04d41681856e..7827fb8bdb10185e861a3454f52f83b37604e7f6 100644 (file)
@@ -155,6 +155,7 @@ void c2_mq_req_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size,
        q->hint_count = 0;
        return;
 }
+
 void c2_mq_rep_init(struct c2_mq *q, u32 index, u32 q_size, u32 msg_size,
                    u8 *pool_start, u16 __iomem *peer, u32 type)
 {
index 25c3f008556380eb87678a3129fe2051158cdf82..c707e45887c25004bb8265c93ab137681082f2fe 100644 (file)
@@ -359,7 +359,7 @@ static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
 
        for (i = 0; i < num_phys_buf; i++) {
 
-               if (buffer_list[i].addr & ~PAGE_MASK) {
+               if (offset_in_page(buffer_list[i].addr)) {
                        pr_debug("Unaligned Memory Buffer: 0x%x\n",
                                (unsigned int) buffer_list[i].addr);
                        return ERR_PTR(-EINVAL);
@@ -372,7 +372,7 @@ static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
 
                total_len += buffer_list[i].size;
                pbl_depth += ALIGN(buffer_list[i].size,
-                                  (1 << page_shift)) >> page_shift;
+                                  BIT(page_shift)) >> page_shift;
        }
 
        page_list = vmalloc(sizeof(u64) * pbl_depth);
@@ -387,7 +387,7 @@ static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
                int naddrs;
 
                naddrs = ALIGN(buffer_list[i].size,
-                              (1 << page_shift)) >> page_shift;
+                              BIT(page_shift)) >> page_shift;
                for (k = 0; k < naddrs; k++)
                        page_list[j++] = (buffer_list[i].addr +
                                                     (k << page_shift));
@@ -408,7 +408,7 @@ static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
                (unsigned long long) page_list[0],
                (unsigned long long) page_list[pbl_depth-1]);
        err = c2_nsmr_register_phys_kern(to_c2dev(ib_pd->device), page_list,
-                                        (1 << page_shift), pbl_depth,
+                                        BIT(page_shift), pbl_depth,
                                         total_len, 0, iova_start,
                                         c2_convert_access(acc), mr);
        vfree(page_list);
@@ -462,7 +462,7 @@ static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
        shift = ffs(c2mr->umem->page_size) - 1;
        n = c2mr->umem->nmap;
 
-       pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
+       pages = kmalloc_array(n, sizeof(u64), GFP_KERNEL);
        if (!pages) {
                err = -ENOMEM;
                goto err;
index 4c43ca935cc7ad5cf1686759e7b663a367ea76b8..ca364dbe369c1c579508849c0551ce9fc38fdac6 100644 (file)
@@ -240,7 +240,7 @@ int c2_qp_modify(struct c2_dev *c2dev, struct c2_qp *qp,
        spin_unlock_irqrestore(&qp->lock, flags);
 
        vq_repbuf_free(c2dev, reply);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
 
        pr_debug("%s:%d qp=%p, cur_state=%s\n",
@@ -294,7 +294,7 @@ int c2_qp_set_read_limits(struct c2_dev *c2dev, struct c2_qp *qp,
 
        err = c2_errno(reply);
        vq_repbuf_free(c2dev, reply);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
@@ -373,7 +373,7 @@ static int destroy_qp(struct c2_dev *c2dev, struct c2_qp *qp)
        spin_unlock_irqrestore(&qp->lock, flags);
 
        vq_repbuf_free(c2dev, reply);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
@@ -554,19 +554,19 @@ int c2_alloc_qp(struct c2_dev *c2dev,
 
        return 0;
 
-      bail6:
+bail6:
        iounmap(qp->sq_mq.peer);
-      bail5:
+bail5:
        destroy_qp(c2dev, qp);
-      bail4:
+bail4:
        vq_repbuf_free(c2dev, reply);
-      bail3:
+bail3:
        vq_req_free(c2dev, vq_req);
-      bail2:
+bail2:
        c2_free_mqsp(qp->rq_mq.shared);
-      bail1:
+bail1:
        c2_free_mqsp(qp->sq_mq.shared);
-      bail0:
+bail0:
        c2_free_qpn(c2dev, qp->qpn);
        return err;
 }
index d2a6d961344b7e6f32855fad7b176149964bd43e..d3c0f77767d9a198f651524e13ce54884db9bbc0 100644 (file)
@@ -261,9 +261,9 @@ int c2_add_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask)
        err = c2_errno(reply);
        vq_repbuf_free(c2dev, reply);
 
-      bail1:
+bail1:
        kfree(wr);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
@@ -323,9 +323,9 @@ int c2_del_addr(struct c2_dev *c2dev, __be32 inaddr, __be32 inmask)
        err = c2_errno(reply);
        vq_repbuf_free(c2dev, reply);
 
-      bail1:
+bail1:
        kfree(wr);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
@@ -378,9 +378,9 @@ static int c2_rnic_open(struct c2_dev *c2dev)
 
        c2dev->adapter_handle = reply->rnic_handle;
 
-      bail1:
+bail1:
        vq_repbuf_free(c2dev, reply);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
@@ -430,9 +430,9 @@ static int c2_rnic_close(struct c2_dev *c2dev)
 
        c2dev->adapter_handle = 0;
 
-      bail1:
+bail1:
        vq_repbuf_free(c2dev, reply);
-      bail0:
+bail0:
        vq_req_free(c2dev, vq_req);
        return err;
 }
@@ -589,21 +589,21 @@ int c2_rnic_init(struct c2_dev *c2dev)
        c2_init_qp_table(c2dev);
        return 0;
 
-      bail5:
+bail5:
        c2_rnic_close(c2dev);
-      bail4:
+bail4:
        vq_term(c2dev);
-      bail3:
+bail3:
        dma_free_coherent(&c2dev->pcidev->dev,
                          c2dev->aeq.q_size * c2dev->aeq.msg_size,
                          q2_pages, dma_unmap_addr(&c2dev->aeq, mapping));
-      bail2:
+bail2:
        dma_free_coherent(&c2dev->pcidev->dev,
                          c2dev->rep_vq.q_size * c2dev->rep_vq.msg_size,
                          q1_pages, dma_unmap_addr(&c2dev->rep_vq, mapping));
-      bail1:
+bail1:
        c2_free_mqsp_pool(c2dev, c2dev->kern_mqsp_pool);
-      bail0:
+bail0:
        vfree(c2dev->qptr_array);
 
        return err;
index 9b68b175069b9a1b6f95bfc1beae065b9ee6b682..ea1b5c1203b4e8292ea6aab4e9760b56c7cbe0b0 100644 (file)
@@ -130,7 +130,7 @@ struct ib_cq *ehca_create_cq(struct ib_device *device,
        void *vpage;
        u32 counter;
        u64 rpage, cqx_fec, h_ret;
-       int ipz_rc, i;
+       int rc, i;
        unsigned long flags;
 
        if (attr->flags)
@@ -170,16 +170,17 @@ struct ib_cq *ehca_create_cq(struct ib_device *device,
 
        idr_preload(GFP_KERNEL);
        write_lock_irqsave(&ehca_cq_idr_lock, flags);
-       my_cq->token = idr_alloc(&ehca_cq_idr, my_cq, 0, 0x2000000, GFP_NOWAIT);
+       rc = idr_alloc(&ehca_cq_idr, my_cq, 0, 0x2000000, GFP_NOWAIT);
        write_unlock_irqrestore(&ehca_cq_idr_lock, flags);
        idr_preload_end();
 
-       if (my_cq->token < 0) {
+       if (rc < 0) {
                cq = ERR_PTR(-ENOMEM);
                ehca_err(device, "Can't allocate new idr entry. device=%p",
                         device);
                goto create_cq_exit1;
        }
+       my_cq->token = rc;
 
        /*
         * CQs maximum depth is 4GB-64, but we need additional 20 as buffer
@@ -195,11 +196,11 @@ struct ib_cq *ehca_create_cq(struct ib_device *device,
                goto create_cq_exit2;
        }
 
-       ipz_rc = ipz_queue_ctor(NULL, &my_cq->ipz_queue, param.act_pages,
+       rc = ipz_queue_ctor(NULL, &my_cq->ipz_queue, param.act_pages,
                                EHCA_PAGESIZE, sizeof(struct ehca_cqe), 0, 0);
-       if (!ipz_rc) {
+       if (!rc) {
                ehca_err(device, "ipz_queue_ctor() failed ipz_rc=%i device=%p",
-                        ipz_rc, device);
+                        rc, device);
                cq = ERR_PTR(-EINVAL);
                goto create_cq_exit3;
        }
index aa58e597df0698a4dc3e17d04662f565a5bafbbc..e48981994b107c0794331247a6789e7b2d50a3d5 100644 (file)
@@ -1295,7 +1295,7 @@ static inline u64 read_write_csr(const struct hfi1_devdata *dd, u32 csr,
 static u64 dev_access_u32_csr(const struct cntr_entry *entry,
                            void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
 
        if (vl != CNTR_INVALID_VL)
                return 0;
@@ -1305,7 +1305,7 @@ static u64 dev_access_u32_csr(const struct cntr_entry *entry,
 static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
                            int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
 
        u64 val = 0;
        u64 csr = entry->csr;
@@ -1326,7 +1326,7 @@ static u64 dev_access_u64_csr(const struct cntr_entry *entry, void *context,
 static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
                            int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
        u32 csr = entry->csr;
        int ret = 0;
 
@@ -1350,7 +1350,7 @@ static u64 dc_access_lcb_cntr(const struct cntr_entry *entry, void *context,
 static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
                             int vl, int mode, u64 data)
 {
-       struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
+       struct hfi1_pportdata *ppd = context;
 
        if (vl != CNTR_INVALID_VL)
                return 0;
@@ -1360,7 +1360,7 @@ static u64 port_access_u32_csr(const struct cntr_entry *entry, void *context,
 static u64 port_access_u64_csr(const struct cntr_entry *entry,
                             void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
+       struct hfi1_pportdata *ppd = context;
        u64 val;
        u64 csr = entry->csr;
 
@@ -1400,7 +1400,7 @@ static inline u64 read_write_sw(struct hfi1_devdata *dd, u64 *cntr, int mode,
 static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
                               int vl, int mode, u64 data)
 {
-       struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
+       struct hfi1_pportdata *ppd = context;
 
        if (vl != CNTR_INVALID_VL)
                return 0;
@@ -1410,7 +1410,7 @@ static u64 access_sw_link_dn_cnt(const struct cntr_entry *entry, void *context,
 static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
                               int vl, int mode, u64 data)
 {
-       struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
+       struct hfi1_pportdata *ppd = context;
 
        if (vl != CNTR_INVALID_VL)
                return 0;
@@ -1420,7 +1420,7 @@ static u64 access_sw_link_up_cnt(const struct cntr_entry *entry, void *context,
 static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
                                    void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
+       struct hfi1_pportdata *ppd = context;
 
        if (vl != CNTR_INVALID_VL)
                return 0;
@@ -1431,7 +1431,7 @@ static u64 access_sw_xmit_discards(const struct cntr_entry *entry,
 static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
                                     void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
+       struct hfi1_pportdata *ppd = context;
 
        if (vl != CNTR_INVALID_VL)
                return 0;
@@ -1443,7 +1443,7 @@ static u64 access_xmit_constraint_errs(const struct cntr_entry *entry,
 static u64 access_rcv_constraint_errs(const struct cntr_entry *entry,
                                     void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_pportdata *ppd = (struct hfi1_pportdata *)context;
+       struct hfi1_pportdata *ppd = context;
 
        if (vl != CNTR_INVALID_VL)
                return 0;
@@ -1491,7 +1491,7 @@ static u64 read_write_cpu(struct hfi1_devdata *dd, u64 *z_val,
 static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
                              void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
 
        return read_write_cpu(dd, &dd->z_int_counter, dd->int_counter, vl,
                              mode, data);
@@ -1500,7 +1500,7 @@ static u64 access_sw_cpu_intr(const struct cntr_entry *entry,
 static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
                              void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
 
        return read_write_cpu(dd, &dd->z_rcv_limit, dd->rcv_limit, vl,
                              mode, data);
@@ -1509,7 +1509,7 @@ static u64 access_sw_cpu_rcv_limit(const struct cntr_entry *entry,
 static u64 access_sw_pio_wait(const struct cntr_entry *entry,
                              void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
 
        return dd->verbs_dev.n_piowait;
 }
@@ -1517,7 +1517,7 @@ static u64 access_sw_pio_wait(const struct cntr_entry *entry,
 static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
                              void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
 
        return dd->verbs_dev.n_txwait;
 }
@@ -1525,11 +1525,19 @@ static u64 access_sw_vtx_wait(const struct cntr_entry *entry,
 static u64 access_sw_kmem_wait(const struct cntr_entry *entry,
                               void *context, int vl, int mode, u64 data)
 {
-       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+       struct hfi1_devdata *dd = context;
 
        return dd->verbs_dev.n_kmem_wait;
 }
 
+static u64 access_sw_send_schedule(const struct cntr_entry *entry,
+                              void *context, int vl, int mode, u64 data)
+{
+       struct hfi1_devdata *dd = (struct hfi1_devdata *)context;
+
+       return dd->verbs_dev.n_send_schedule;
+}
+
 #define def_access_sw_cpu(cntr) \
 static u64 access_sw_cpu_##cntr(const struct cntr_entry *entry,                      \
                              void *context, int vl, int mode, u64 data)      \
@@ -1720,6 +1728,8 @@ static struct cntr_entry dev_cntrs[DEV_CNTR_LAST] = {
                            access_sw_pio_wait),
 [C_SW_KMEM_WAIT] = CNTR_ELEM("KmemWait", 0, 0, CNTR_NORMAL,
                            access_sw_kmem_wait),
+[C_SW_SEND_SCHED] = CNTR_ELEM("SendSched", 0, 0, CNTR_NORMAL,
+                           access_sw_send_schedule),
 };
 
 static struct cntr_entry port_cntrs[PORT_CNTR_LAST] = {
@@ -2215,9 +2225,7 @@ static void update_rcverr_timer(unsigned long opaque)
 
 static int init_rcverr(struct hfi1_devdata *dd)
 {
-       init_timer(&dd->rcverr_timer);
-       dd->rcverr_timer.function = update_rcverr_timer;
-       dd->rcverr_timer.data = (unsigned long) dd;
+       setup_timer(&dd->rcverr_timer, update_rcverr_timer, (unsigned long)dd);
        /* Assume the hardware counter has been reset */
        dd->rcv_ovfl_cnt = 0;
        return mod_timer(&dd->rcverr_timer, jiffies + HZ * RCVERR_CHECK_TIME);
@@ -4416,7 +4424,7 @@ static void is_rcv_avail_int(struct hfi1_devdata *dd, unsigned int source)
                rcd = dd->rcd[source];
                if (rcd) {
                        if (source < dd->first_user_ctxt)
-                               rcd->do_interrupt(rcd);
+                               rcd->do_interrupt(rcd, 0);
                        else
                                handle_user_interrupt(rcd);
                        return; /* OK */
@@ -4582,23 +4590,106 @@ static irqreturn_t sdma_interrupt(int irq, void *data)
 }
 
 /*
- * NOTE: this routine expects to be on its own MSI-X interrupt.  If
- * multiple receive contexts share the same MSI-X interrupt, then this
- * routine must check for who received it.
+ * Clear the receive interrupt, forcing the write and making sure
+ * we have data from the chip, pushing everything in front of it
+ * back to the host.
+ */
+static inline void clear_recv_intr(struct hfi1_ctxtdata *rcd)
+{
+       struct hfi1_devdata *dd = rcd->dd;
+       u32 addr = CCE_INT_CLEAR + (8 * rcd->ireg);
+
+       mmiowb();       /* make sure everything before is written */
+       write_csr(dd, addr, rcd->imask);
+       /* force the above write on the chip and get a value back */
+       (void)read_csr(dd, addr);
+}
+
+/* force the receive interrupt */
+static inline void force_recv_intr(struct hfi1_ctxtdata *rcd)
+{
+       write_csr(rcd->dd, CCE_INT_FORCE + (8 * rcd->ireg), rcd->imask);
+}
+
+/* return non-zero if a packet is present */
+static inline int check_packet_present(struct hfi1_ctxtdata *rcd)
+{
+       if (!HFI1_CAP_IS_KSET(DMA_RTAIL))
+               return (rcd->seq_cnt ==
+                               rhf_rcv_seq(rhf_to_cpu(get_rhf_addr(rcd))));
+
+       /* else is RDMA rtail */
+       return (rcd->head != get_rcvhdrtail(rcd));
+}
+
+/*
+ * Receive packet IRQ handler.  This routine expects to be on its own IRQ.
+ * This routine will try to handle packets immediately (latency), but if
+ * it finds too many, it will invoke the thread handler (bandwitdh).  The
+ * chip receive interupt is *not* cleared down until this or the thread (if
+ * invoked) is finished.  The intent is to avoid extra interrupts while we
+ * are processing packets anyway.
  */
 static irqreturn_t receive_context_interrupt(int irq, void *data)
 {
        struct hfi1_ctxtdata *rcd = data;
        struct hfi1_devdata *dd = rcd->dd;
+       int disposition;
+       int present;
 
        trace_hfi1_receive_interrupt(dd, rcd->ctxt);
        this_cpu_inc(*dd->int_counter);
 
-       /* clear the interrupt */
-       write_csr(rcd->dd, CCE_INT_CLEAR + (8*rcd->ireg), rcd->imask);
+       /* receive interrupt remains blocked while processing packets */
+       disposition = rcd->do_interrupt(rcd, 0);
+
+       /*
+        * Too many packets were seen while processing packets in this
+        * IRQ handler.  Invoke the handler thread.  The receive interrupt
+        * remains blocked.
+        */
+       if (disposition == RCV_PKT_LIMIT)
+               return IRQ_WAKE_THREAD;
 
-       /* handle the interrupt */
-       rcd->do_interrupt(rcd);
+       /*
+        * The packet processor detected no more packets.  Clear the receive
+        * interrupt and recheck for a packet packet that may have arrived
+        * after the previous check and interrupt clear.  If a packet arrived,
+        * force another interrupt.
+        */
+       clear_recv_intr(rcd);
+       present = check_packet_present(rcd);
+       if (present)
+               force_recv_intr(rcd);
+
+       return IRQ_HANDLED;
+}
+
+/*
+ * Receive packet thread handler.  This expects to be invoked with the
+ * receive interrupt still blocked.
+ */
+static irqreturn_t receive_context_thread(int irq, void *data)
+{
+       struct hfi1_ctxtdata *rcd = data;
+       int present;
+
+       /* receive interrupt is still blocked from the IRQ handler */
+       (void)rcd->do_interrupt(rcd, 1);
+
+       /*
+        * The packet processor will only return if it detected no more
+        * packets.  Hold IRQs here so we can safely clear the interrupt and
+        * recheck for a packet that may have arrived after the previous
+        * check and the interrupt clear.  If a packet arrived, force another
+        * interrupt.
+        */
+       local_irq_disable();
+       clear_recv_intr(rcd);
+       present = check_packet_present(rcd);
+       if (present)
+               force_recv_intr(rcd);
+       local_irq_enable();
 
        return IRQ_HANDLED;
 }
@@ -5407,6 +5498,8 @@ static int set_local_link_attributes(struct hfi1_pportdata *ppd)
                if (ppd->link_speed_enabled & OPA_LINK_SPEED_12_5G)
                        ppd->local_tx_rate |= 1;
        }
+
+       enable_lane_tx = 0xF; /* enable all four lanes */
        ret = write_tx_settings(dd, enable_lane_tx, tx_polarity_inversion,
                     rx_polarity_inversion, ppd->local_tx_rate);
        if (ret != HCMD_SUCCESS)
@@ -5716,8 +5809,7 @@ void init_qsfp(struct hfi1_pportdata *ppd)
        u64 qsfp_mask;
 
        if (loopback == LOOPBACK_SERDES || loopback == LOOPBACK_LCB ||
-                       ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR ||
-                       !HFI1_CAP_IS_KSET(QSFP_ENABLED)) {
+                       ppd->dd->icode == ICODE_FUNCTIONAL_SIMULATOR) {
                ppd->driver_link_ready = 1;
                return;
        }
@@ -6205,7 +6297,7 @@ static int goto_offline(struct hfi1_pportdata *ppd, u8 rem_reason)
 
        if (do_wait) {
                /* it can take a while for the link to go down */
-               ret = wait_phy_linkstate(dd, PLS_OFFLINE, 5000);
+               ret = wait_phy_linkstate(dd, PLS_OFFLINE, 10000);
                if (ret < 0)
                        return ret;
        }
@@ -8156,9 +8248,8 @@ static int init_cntrs(struct hfi1_devdata *dd)
        struct hfi1_pportdata *ppd;
 
        /* set up the stats timer; the add_timer is done at the end */
-       init_timer(&dd->synth_stats_timer);
-       dd->synth_stats_timer.function = update_synth_timer;
-       dd->synth_stats_timer.data = (unsigned long) dd;
+       setup_timer(&dd->synth_stats_timer, update_synth_timer,
+                   (unsigned long)dd);
 
        /***********************/
        /* per device counters */
@@ -8850,6 +8941,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
                struct hfi1_msix_entry *me = &dd->msix_entries[i];
                const char *err_info;
                irq_handler_t handler;
+               irq_handler_t thread = NULL;
                void *arg;
                int idx;
                struct hfi1_ctxtdata *rcd = NULL;
@@ -8886,6 +8978,7 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
                        rcd->imask = ((u64)1) <<
                                        ((IS_RCVAVAIL_START+idx) % 64);
                        handler = receive_context_interrupt;
+                       thread = receive_context_thread;
                        arg = rcd;
                        snprintf(me->name, sizeof(me->name),
                                DRIVER_NAME"_%d kctxt%d", dd->unit, idx);
@@ -8904,7 +8997,8 @@ static int request_msix_irqs(struct hfi1_devdata *dd)
                /* make sure the name is terminated */
                me->name[sizeof(me->name)-1] = 0;
 
-               ret = request_irq(me->msix.vector, handler, 0, me->name, arg);
+               ret = request_threaded_irq(me->msix.vector, handler, thread, 0,
+                                               me->name, arg);
                if (ret) {
                        dd_dev_err(dd,
                                "unable to allocate %s interrupt, vector %d, index %d, err %d\n",
@@ -8991,7 +9085,6 @@ static int set_up_interrupts(struct hfi1_devdata *dd)
 
        entries = kcalloc(total, sizeof(*entries), GFP_KERNEL);
        if (!entries) {
-               dd_dev_err(dd, "cannot allocate msix table\n");
                ret = -ENOMEM;
                goto fail;
        }
@@ -9328,8 +9421,6 @@ static void reset_cce_csrs(struct hfi1_devdata *dd)
 /* set ASIC CSRs to chip reset defaults */
 static void reset_asic_csrs(struct hfi1_devdata *dd)
 {
-       static DEFINE_MUTEX(asic_mutex);
-       static int called;
        int i;
 
        /*
@@ -9339,15 +9430,8 @@ static void reset_asic_csrs(struct hfi1_devdata *dd)
         * a known first load do the reset and blocking all others.
         */
 
-       /*
-        * These CSRs should only be reset once - the first one here will
-        * do the work.  Use a mutex so that a non-first caller waits until
-        * the first is finished before it can proceed.
-        */
-       mutex_lock(&asic_mutex);
-       if (called)
-               goto done;
-       called = 1;
+       if (!(dd->flags & HFI1_DO_INIT_ASIC))
+               return;
 
        if (dd->icode != ICODE_FPGA_EMULATION) {
                /* emulation does not have an SBus - leave these alone */
@@ -9367,7 +9451,10 @@ static void reset_asic_csrs(struct hfi1_devdata *dd)
        for (i = 0; i < ASIC_NUM_SCRATCH; i++)
                write_csr(dd, ASIC_CFG_SCRATCH + (8 * i), 0);
        write_csr(dd, ASIC_CFG_MUTEX, 0);       /* this will clear it */
+
+       /* We might want to retain this state across FLR if we ever use it */
        write_csr(dd, ASIC_CFG_DRV_STR, 0);
+
        write_csr(dd, ASIC_CFG_THERM_POLL_EN, 0);
        /* ASIC_STS_THERM read-only */
        /* ASIC_CFG_RESET leave alone */
@@ -9414,9 +9501,6 @@ static void reset_asic_csrs(struct hfi1_devdata *dd)
        /* this also writes a NOP command, clearing paging mode */
        write_csr(dd, ASIC_EEP_ADDR_CMD, 0);
        write_csr(dd, ASIC_EEP_DATA, 0);
-
-done:
-       mutex_unlock(&asic_mutex);
 }
 
 /* set MISC CSRs to chip reset defaults */
@@ -9828,6 +9912,7 @@ static void init_chip(struct hfi1_devdata *dd)
                        restore_pci_variables(dd);
                }
 
+               reset_asic_csrs(dd);
        } else {
                dd_dev_info(dd, "Resetting CSRs with writes\n");
                reset_cce_csrs(dd);
@@ -9838,6 +9923,7 @@ static void init_chip(struct hfi1_devdata *dd)
        }
        /* clear the DC reset */
        write_csr(dd, CCE_DC_CTRL, 0);
+
        /* Set the LED off */
        if (is_a0(dd))
                setextled(dd, 0);
@@ -10333,7 +10419,7 @@ static void asic_should_init(struct hfi1_devdata *dd)
 }
 
 /**
- * Allocate an initialize the device structure for the hfi.
+ * Allocate and initialize the device structure for the hfi.
  * @dev: the pci_dev for hfi1_ib device
  * @ent: pci_device_id struct for this dev
  *
@@ -10489,6 +10575,12 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
        else if (dd->rcv_intr_timeout_csr == 0 && rcv_intr_timeout)
                dd->rcv_intr_timeout_csr = 1;
 
+       /* needs to be done before we look for the peer device */
+       read_guid(dd);
+
+       /* should this device init the ASIC block? */
+       asic_should_init(dd);
+
        /* obtain chip sizes, reset chip CSRs */
        init_chip(dd);
 
@@ -10497,11 +10589,6 @@ struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
        if (ret)
                goto bail_cleanup;
 
-       /* needs to be done before we look for the peer device */
-       read_guid(dd);
-
-       asic_should_init(dd);
-
        /* read in firmware */
        ret = hfi1_firmware_init(dd);
        if (ret)
@@ -10716,6 +10803,7 @@ static int thermal_init(struct hfi1_devdata *dd)
 
        acquire_hw_mutex(dd);
        dd_dev_info(dd, "Initializing thermal sensor\n");
+
        /* Thermal Sensor Initialization */
        /*    Step 1: Reset the Thermal SBus Receiver */
        ret = sbus_request_slow(dd, SBUS_THERMAL, 0x0,
index f89a432c7334eef851c8b675f5e7660c2f4fea8d..ebf9041a1c5eaceefe1e7c6f2b015b6d62ba6c32 100644 (file)
@@ -609,6 +609,7 @@ static inline void write_uctxt_csr(struct hfi1_devdata *dd, int ctxt,
 u64 create_pbc(struct hfi1_pportdata *ppd, u64, int, u32, u32);
 
 /* firmware.c */
+#define SBUS_MASTER_BROADCAST 0xfd
 #define NUM_PCIE_SERDES 16     /* number of PCIe serdes on the SBus */
 extern const u8 pcie_serdes_broadcast[];
 extern const u8 pcie_pcs_addrs[2][NUM_PCIE_SERDES];
@@ -786,6 +787,7 @@ enum {
        C_SW_VTX_WAIT,
        C_SW_PIO_WAIT,
        C_SW_KMEM_WAIT,
+       C_SW_SEND_SCHED,
        DEV_CNTR_LAST  /* Must be kept last */
 };
 
index 5f2293729cf908d0a813d949d2a5faaff72bc85a..5e203239c5b043e826e0c5e801665a7a7995e261 100644 (file)
                                  HFI1_CAP_USE_SDMA_HEAD |              \
                                  HFI1_CAP_EXTENDED_PSN |               \
                                  HFI1_CAP_PRINT_UNIMPL |               \
-                                 HFI1_CAP_QSFP_ENABLED |               \
                                  HFI1_CAP_NO_INTEGRITY |               \
                                  HFI1_CAP_PKEY_CHECK) <<               \
                                 HFI1_CAP_USER_SHIFT)
                                 HFI1_CAP_SDMA |                        \
                                 HFI1_CAP_PRINT_UNIMPL |                \
                                 HFI1_CAP_STATIC_RATE_CTRL |            \
-                                HFI1_CAP_QSFP_ENABLED |                \
                                 HFI1_CAP_PKEY_CHECK |                  \
                                 HFI1_CAP_MULTI_PKT_EGR |               \
                                 HFI1_CAP_EXTENDED_PSN |                \
  * to the driver itself, not the software interfaces it supports.
  */
 #ifndef HFI1_DRIVER_VERSION_BASE
-#define HFI1_DRIVER_VERSION_BASE "0.9-248"
+#define HFI1_DRIVER_VERSION_BASE "0.9-294"
 #endif
 
 /* create the final driver version string */
index bc26a5392712d848ecd6df16676788790a8eb50b..58472e5ac4e575dbf6b6a7880a9923358839e573 100644 (file)
@@ -124,7 +124,7 @@ static char *hfi1_devnode(struct device *dev, umode_t *mode)
 }
 
 static const char *hfi1_class_name_user = "hfi1_user";
-const char *class_name_user(void)
+static const char *class_name_user(void)
 {
        return hfi1_class_name_user;
 }
index 3e8d5ac4c626901e52b66aa0f3ba27e1c603bc79..88414d720469f17599b6e98766496529fc1f9a0f 100644 (file)
@@ -607,7 +607,7 @@ static int hfi1_snoop_add(struct hfi1_devdata *dd, const char *name)
 static struct hfi1_devdata *hfi1_dd_from_sc_inode(struct inode *in)
 {
        int unit = iminor(in) - HFI1_SNOOP_CAPTURE_BASE;
-       struct hfi1_devdata *dd = NULL;
+       struct hfi1_devdata *dd;
 
        dd = hfi1_lookup(unit);
        return dd;
@@ -1159,9 +1159,8 @@ static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
                                   filter_cmd.opcode, filter_cmd.length,
                                   filter_cmd.value_ptr);
 
-                       filter_value = kzalloc(
-                                               filter_cmd.length * sizeof(u8),
-                                               GFP_KERNEL);
+                       filter_value = kcalloc(filter_cmd.length, sizeof(u8),
+                                              GFP_KERNEL);
                        if (!filter_value) {
                                pr_alert("Not enough memory\n");
                                ret = -ENOMEM;
@@ -1478,7 +1477,7 @@ static struct snoop_packet *allocate_snoop_packet(u32 hdr_len,
                                                  u32 md_len)
 {
 
-       struct snoop_packet *packet = NULL;
+       struct snoop_packet *packet;
 
        packet = kzalloc(sizeof(struct snoop_packet) + hdr_len + data_len
                         + md_len,
index c0a59001e5cdf0179e69c80da77ccbae6a8be8cb..ce69141b56cb078d0994697f9c393c702e0f3deb 100644 (file)
@@ -302,6 +302,7 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
                qp_num = be32_to_cpu(ohdr->bth[1]) & HFI1_QPN_MASK;
                if (lid < HFI1_MULTICAST_LID_BASE) {
                        struct hfi1_qp *qp;
+                       unsigned long flags;
 
                        rcu_read_lock();
                        qp = hfi1_lookup_qpn(ibp, qp_num);
@@ -314,7 +315,7 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
                         * Handle only RC QPs - for other QP types drop error
                         * packet.
                         */
-                       spin_lock(&qp->r_lock);
+                       spin_lock_irqsave(&qp->r_lock, flags);
 
                        /* Check for valid receive state. */
                        if (!(ib_hfi1_state_ops[qp->state] &
@@ -335,7 +336,7 @@ static void rcv_hdrerr(struct hfi1_ctxtdata *rcd, struct hfi1_pportdata *ppd,
                                break;
                        }
 
-                       spin_unlock(&qp->r_lock);
+                       spin_unlock_irqrestore(&qp->r_lock, flags);
                        rcu_read_unlock();
                } /* Unicast QP */
        } /* Valid packet with TIDErr */
@@ -426,8 +427,7 @@ static inline void init_packet(struct hfi1_ctxtdata *rcd,
        packet->rcd = rcd;
        packet->updegr = 0;
        packet->etail = -1;
-       packet->rhf_addr = (__le32 *) rcd->rcvhdrq + rcd->head +
-                          rcd->dd->rhf_offset;
+       packet->rhf_addr = get_rhf_addr(rcd);
        packet->rhf = rhf_to_cpu(packet->rhf_addr);
        packet->rhqoff = rcd->head;
        packet->numpkt = 0;
@@ -618,10 +618,7 @@ next:
 }
 #endif /* CONFIG_PRESCAN_RXQ */
 
-#define RCV_PKT_OK 0x0
-#define RCV_PKT_MAX 0x1
-
-static inline int process_rcv_packet(struct hfi1_packet *packet)
+static inline int process_rcv_packet(struct hfi1_packet *packet, int thread)
 {
        int ret = RCV_PKT_OK;
 
@@ -663,9 +660,13 @@ static inline int process_rcv_packet(struct hfi1_packet *packet)
        if (packet->rhqoff >= packet->maxcnt)
                packet->rhqoff = 0;
 
-       if (packet->numpkt == MAX_PKT_RECV) {
-               ret = RCV_PKT_MAX;
-               this_cpu_inc(*packet->rcd->dd->rcv_limit);
+       if (unlikely((packet->numpkt & (MAX_PKT_RECV - 1)) == 0)) {
+               if (thread) {
+                       cond_resched();
+               } else {
+                       ret = RCV_PKT_LIMIT;
+                       this_cpu_inc(*packet->rcd->dd->rcv_limit);
+               }
        }
 
        packet->rhf_addr = (__le32 *) packet->rcd->rcvhdrq + packet->rhqoff +
@@ -742,57 +743,63 @@ static inline void process_rcv_qp_work(struct hfi1_packet *packet)
 /*
  * Handle receive interrupts when using the no dma rtail option.
  */
-void handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd)
+int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread)
 {
        u32 seq;
-       int last = 0;
+       int last = RCV_PKT_OK;
        struct hfi1_packet packet;
 
        init_packet(rcd, &packet);
        seq = rhf_rcv_seq(packet.rhf);
-       if (seq != rcd->seq_cnt)
+       if (seq != rcd->seq_cnt) {
+               last = RCV_PKT_DONE;
                goto bail;
+       }
 
        prescan_rxq(&packet);
 
-       while (!last) {
-               last = process_rcv_packet(&packet);
+       while (last == RCV_PKT_OK) {
+               last = process_rcv_packet(&packet, thread);
                seq = rhf_rcv_seq(packet.rhf);
                if (++rcd->seq_cnt > 13)
                        rcd->seq_cnt = 1;
                if (seq != rcd->seq_cnt)
-                       last = 1;
+                       last = RCV_PKT_DONE;
                process_rcv_update(last, &packet);
        }
        process_rcv_qp_work(&packet);
 bail:
        finish_packet(&packet);
+       return last;
 }
 
-void handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd)
+int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread)
 {
        u32 hdrqtail;
-       int last = 0;
+       int last = RCV_PKT_OK;
        struct hfi1_packet packet;
 
        init_packet(rcd, &packet);
        hdrqtail = get_rcvhdrtail(rcd);
-       if (packet.rhqoff == hdrqtail)
+       if (packet.rhqoff == hdrqtail) {
+               last = RCV_PKT_DONE;
                goto bail;
+       }
        smp_rmb();  /* prevent speculative reads of dma'ed hdrq */
 
        prescan_rxq(&packet);
 
-       while (!last) {
-               last = process_rcv_packet(&packet);
+       while (last == RCV_PKT_OK) {
+               last = process_rcv_packet(&packet, thread);
+               hdrqtail = get_rcvhdrtail(rcd);
                if (packet.rhqoff == hdrqtail)
-                       last = 1;
+                       last = RCV_PKT_DONE;
                process_rcv_update(last, &packet);
        }
        process_rcv_qp_work(&packet);
 bail:
        finish_packet(&packet);
-
+       return last;
 }
 
 static inline void set_all_nodma_rtail(struct hfi1_devdata *dd)
@@ -820,12 +827,11 @@ static inline void set_all_dma_rtail(struct hfi1_devdata *dd)
  * Called from interrupt handler for errors or receive interrupt.
  * This is the slow path interrupt handler.
  */
-void handle_receive_interrupt(struct hfi1_ctxtdata *rcd)
+int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread)
 {
-
        struct hfi1_devdata *dd = rcd->dd;
        u32 hdrqtail;
-       int last = 0, needset = 1;
+       int last = RCV_PKT_OK, needset = 1;
        struct hfi1_packet packet;
 
        init_packet(rcd, &packet);
@@ -833,19 +839,23 @@ void handle_receive_interrupt(struct hfi1_ctxtdata *rcd)
        if (!HFI1_CAP_IS_KSET(DMA_RTAIL)) {
                u32 seq = rhf_rcv_seq(packet.rhf);
 
-               if (seq != rcd->seq_cnt)
+               if (seq != rcd->seq_cnt) {
+                       last = RCV_PKT_DONE;
                        goto bail;
+               }
                hdrqtail = 0;
        } else {
                hdrqtail = get_rcvhdrtail(rcd);
-               if (packet.rhqoff == hdrqtail)
+               if (packet.rhqoff == hdrqtail) {
+                       last = RCV_PKT_DONE;
                        goto bail;
+               }
                smp_rmb();  /* prevent speculative reads of dma'ed hdrq */
        }
 
        prescan_rxq(&packet);
 
-       while (!last) {
+       while (last == RCV_PKT_OK) {
 
                if (unlikely(dd->do_drop && atomic_xchg(&dd->drop_packet,
                        DROP_PACKET_OFF) == DROP_PACKET_ON)) {
@@ -859,7 +869,7 @@ void handle_receive_interrupt(struct hfi1_ctxtdata *rcd)
                        packet.rhf = rhf_to_cpu(packet.rhf_addr);
 
                } else {
-                       last = process_rcv_packet(&packet);
+                       last = process_rcv_packet(&packet, thread);
                }
 
                if (!HFI1_CAP_IS_KSET(DMA_RTAIL)) {
@@ -868,7 +878,7 @@ void handle_receive_interrupt(struct hfi1_ctxtdata *rcd)
                        if (++rcd->seq_cnt > 13)
                                rcd->seq_cnt = 1;
                        if (seq != rcd->seq_cnt)
-                               last = 1;
+                               last = RCV_PKT_DONE;
                        if (needset) {
                                dd_dev_info(dd,
                                        "Switching to NO_DMA_RTAIL\n");
@@ -877,7 +887,7 @@ void handle_receive_interrupt(struct hfi1_ctxtdata *rcd)
                        }
                } else {
                        if (packet.rhqoff == hdrqtail)
-                               last = 1;
+                               last = RCV_PKT_DONE;
                        if (needset) {
                                dd_dev_info(dd,
                                            "Switching to DMA_RTAIL\n");
@@ -897,6 +907,7 @@ bail:
         * if no packets were processed.
         */
        finish_packet(&packet);
+       return last;
 }
 
 /*
@@ -1062,9 +1073,9 @@ void hfi1_set_led_override(struct hfi1_pportdata *ppd, unsigned int val)
         */
        if (atomic_inc_return(&ppd->led_override_timer_active) == 1) {
                /* Need to start timer */
-               init_timer(&ppd->led_override_timer);
-               ppd->led_override_timer.function = run_led_override;
-               ppd->led_override_timer.data = (unsigned long) ppd;
+               setup_timer(&ppd->led_override_timer, run_led_override,
+                               (unsigned long)ppd);
+
                ppd->led_override_timer.expires = jiffies + 1;
                add_timer(&ppd->led_override_timer);
        } else {
index 72d38500d8ce4e544cac1141497cbb46a7a4aa71..aae9826ec62bea8e86a6f1f7c4408ff574d72204 100644 (file)
@@ -168,7 +168,7 @@ enum mmap_types {
        HFI1_MMAP_TOKEN_SET(TYPE, type) | \
        HFI1_MMAP_TOKEN_SET(CTXT, ctxt) | \
        HFI1_MMAP_TOKEN_SET(SUBCTXT, subctxt) | \
-       HFI1_MMAP_TOKEN_SET(OFFSET, ((unsigned long)addr & ~PAGE_MASK)))
+       HFI1_MMAP_TOKEN_SET(OFFSET, (offset_in_page(addr))))
 
 #define EXP_TID_SET(field, value)                      \
        (((value) & EXP_TID_TID##field##_MASK) <<       \
@@ -508,7 +508,7 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)
        case PIO_BUFS_SOP:
                memaddr = ((dd->physaddr + TXE_PIO_SEND) +
                                /* chip pio base */
-                          (uctxt->sc->hw_context * (1 << 16))) +
+                          (uctxt->sc->hw_context * BIT(16))) +
                                /* 64K PIO space / ctxt */
                        (type == PIO_BUFS_SOP ?
                                (TXE_PIO_SIZE / 2) : 0); /* sop? */
@@ -607,9 +607,9 @@ static int hfi1_file_mmap(struct file *fp, struct vm_area_struct *vma)
                 * Use the page where this context's flags are. User level
                 * knows where it's own bitmap is within the page.
                 */
-               memaddr = ((unsigned long)dd->events +
-                          ((uctxt->ctxt - dd->first_user_ctxt) *
-                           HFI1_MAX_SHARED_CTXTS)) & PAGE_MASK;
+               memaddr = (unsigned long)(dd->events +
+                                         ((uctxt->ctxt - dd->first_user_ctxt) *
+                                          HFI1_MAX_SHARED_CTXTS)) & PAGE_MASK;
                memlen = PAGE_SIZE;
                /*
                 * v3.7 removes VM_RESERVED but the effect is kept by
@@ -948,6 +948,7 @@ static int find_shared_ctxt(struct file *fp,
                        /* Skip ctxt if it doesn't match the requested one */
                        if (memcmp(uctxt->uuid, uinfo->uuid,
                                   sizeof(uctxt->uuid)) ||
+                           uctxt->jkey != generate_jkey(current_uid()) ||
                            uctxt->subctxt_id != uinfo->subctxt_id ||
                            uctxt->subctxt_cnt != uinfo->subctxt_cnt)
                                continue;
@@ -1335,9 +1336,9 @@ static int get_base_info(struct file *fp, void __user *ubase, __u32 len)
         */
        binfo.user_regbase = HFI1_MMAP_TOKEN(UREGS, uctxt->ctxt,
                                            subctxt_fp(fp), 0);
-       offset = ((((uctxt->ctxt - dd->first_user_ctxt) *
+       offset = offset_in_page((((uctxt->ctxt - dd->first_user_ctxt) *
                    HFI1_MAX_SHARED_CTXTS) + subctxt_fp(fp)) *
-                 sizeof(*dd->events)) & ~PAGE_MASK;
+                 sizeof(*dd->events));
        binfo.events_bufbase = HFI1_MMAP_TOKEN(EVENTS, uctxt->ctxt,
                                              subctxt_fp(fp),
                                              offset);
@@ -1573,7 +1574,7 @@ static int exp_tid_setup(struct file *fp, struct hfi1_tid_info *tinfo)
 
        vaddr = tinfo->vaddr;
 
-       if (vaddr & ~PAGE_MASK) {
+       if (offset_in_page(vaddr)) {
                ret = -EINVAL;
                goto bail;
        }
@@ -2066,6 +2067,7 @@ static const struct file_operations ui_file_ops = {
        .open = ui_open,
        .release = ui_release,
 };
+
 #define UI_OFFSET 192  /* device minor offset for UI devices */
 static int create_ui = 1;
 
index 5c2f2ed8f22436b99ec26c19e8d1653dc60af6af..b4bdcf341aacfe77ea38fae2ebe61968d489b2ab 100644 (file)
@@ -924,9 +924,6 @@ static int load_8051_firmware(struct hfi1_devdata *dd,
        return 0;
 }
 
-/* SBus Master broadcast address */
-#define SBUS_MASTER_BROADCAST 0xfd
-
 /*
  * Write the SBus request register
  *
@@ -1239,34 +1236,20 @@ int load_firmware(struct hfi1_devdata *dd)
 {
        int ret;
 
-       if (fw_sbus_load || fw_fabric_serdes_load) {
+       if (fw_fabric_serdes_load) {
                ret = acquire_hw_mutex(dd);
                if (ret)
                        return ret;
 
                set_sbus_fast_mode(dd);
 
-               /*
-                * The SBus contains part of the fabric firmware and so must
-                * also be downloaded.
-                */
-               if (fw_sbus_load) {
-                       turn_off_spicos(dd, SPICO_SBUS);
-                       ret = load_sbus_firmware(dd, &fw_sbus);
-                       if (ret)
-                               goto clear;
-               }
+               set_serdes_broadcast(dd, all_fabric_serdes_broadcast,
+                               fabric_serdes_broadcast[dd->hfi1_id],
+                               fabric_serdes_addrs[dd->hfi1_id],
+                               NUM_FABRIC_SERDES);
+               turn_off_spicos(dd, SPICO_FABRIC);
+               ret = load_fabric_serdes_firmware(dd, &fw_fabric);
 
-               if (fw_fabric_serdes_load) {
-                       set_serdes_broadcast(dd, all_fabric_serdes_broadcast,
-                                       fabric_serdes_broadcast[dd->hfi1_id],
-                                       fabric_serdes_addrs[dd->hfi1_id],
-                                       NUM_FABRIC_SERDES);
-                       turn_off_spicos(dd, SPICO_FABRIC);
-                       ret = load_fabric_serdes_firmware(dd, &fw_fabric);
-               }
-
-clear:
                clear_sbus_fast_mode(dd);
                release_hw_mutex(dd);
                if (ret)
@@ -1585,7 +1568,7 @@ int load_pcie_firmware(struct hfi1_devdata *dd)
        /* both firmware loads below use the SBus */
        set_sbus_fast_mode(dd);
 
-       if (fw_sbus_load) {
+       if (fw_sbus_load && (dd->flags & HFI1_DO_INIT_ASIC)) {
                turn_off_spicos(dd, SPICO_SBUS);
                ret = load_sbus_firmware(dd, &fw_sbus);
                if (ret)
@@ -1614,6 +1597,10 @@ done:
  */
 void read_guid(struct hfi1_devdata *dd)
 {
+       /* Take the DC out of reset to get a valid GUID value */
+       write_csr(dd, CCE_DC_CTRL, 0);
+       (void) read_csr(dd, CCE_DC_CTRL);
+
        dd->base_guid = read_csr(dd, DC_DC8051_CFG_LOCAL_GUID);
        dd_dev_info(dd, "GUID %llx",
                (unsigned long long)dd->base_guid);
index 8ca171bf3e36c4d8a181a85837cfae9524bfb725..190f7a2f67731451e7c8035e8aaab1704e5aff9e 100644 (file)
@@ -262,7 +262,7 @@ struct hfi1_ctxtdata {
        pid_t pid;
        pid_t subpid[HFI1_MAX_SHARED_CTXTS];
        /* same size as task_struct .comm[], command that opened context */
-       char comm[16];
+       char comm[TASK_COMM_LEN];
        /* so file ops can get at unit */
        struct hfi1_devdata *dd;
        /* so functions that need physical port can get it easily */
@@ -313,7 +313,7 @@ struct hfi1_ctxtdata {
         * be valid. Worst case is we process an extra interrupt and up to 64
         * packets with the wrong interrupt handler.
         */
-       void (*do_interrupt)(struct hfi1_ctxtdata *rcd);
+       int (*do_interrupt)(struct hfi1_ctxtdata *rcd, int threaded);
 };
 
 /*
@@ -1130,9 +1130,21 @@ void hfi1_init_pportdata(struct pci_dev *, struct hfi1_pportdata *,
                         struct hfi1_devdata *, u8, u8);
 void hfi1_free_ctxtdata(struct hfi1_devdata *, struct hfi1_ctxtdata *);
 
-void handle_receive_interrupt(struct hfi1_ctxtdata *);
-void handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd);
-void handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd);
+int handle_receive_interrupt(struct hfi1_ctxtdata *, int);
+int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *, int);
+int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *, int);
+
+/* receive packet handler dispositions */
+#define RCV_PKT_OK      0x0 /* keep going */
+#define RCV_PKT_LIMIT   0x1 /* stop, hit limit, start thread */
+#define RCV_PKT_DONE    0x2 /* stop, no more packets detected */
+
+/* calculate the current RHF address */
+static inline __le32 *get_rhf_addr(struct hfi1_ctxtdata *rcd)
+{
+       return (__le32 *)rcd->rcvhdrq + rcd->head + rcd->dd->rhf_offset;
+}
+
 int hfi1_reset_device(int);
 
 /* return the driver's idea of the logical OPA port state */
index a877eda8c13c72ac5fa67c55bf1bd1eddf50139c..47a1202fcbdf5117e66a8c78da95c80bbffdf459 100644 (file)
@@ -134,11 +134,8 @@ int hfi1_create_ctxts(struct hfi1_devdata *dd)
        dd->assigned_node_id = local_node_id;
 
        dd->rcd = kcalloc(dd->num_rcv_contexts, sizeof(*dd->rcd), GFP_KERNEL);
-       if (!dd->rcd) {
-               dd_dev_err(dd,
-                       "Unable to allocate receive context array, failing\n");
+       if (!dd->rcd)
                goto nomem;
-       }
 
        /* create one or more kernel contexts */
        for (i = 0; i < dd->first_user_ctxt; ++i) {
@@ -293,12 +290,14 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt)
                 * The resulting value will be rounded down to the closest
                 * multiple of dd->rcv_entries.group_size.
                 */
-               rcd->egrbufs.buffers = kzalloc(sizeof(*rcd->egrbufs.buffers) *
-                                              rcd->egrbufs.count, GFP_KERNEL);
+               rcd->egrbufs.buffers = kcalloc(rcd->egrbufs.count,
+                                              sizeof(*rcd->egrbufs.buffers),
+                                              GFP_KERNEL);
                if (!rcd->egrbufs.buffers)
                        goto bail;
-               rcd->egrbufs.rcvtids = kzalloc(sizeof(*rcd->egrbufs.rcvtids) *
-                                              rcd->egrbufs.count, GFP_KERNEL);
+               rcd->egrbufs.rcvtids = kcalloc(rcd->egrbufs.count,
+                                              sizeof(*rcd->egrbufs.rcvtids),
+                                              GFP_KERNEL);
                if (!rcd->egrbufs.rcvtids)
                        goto bail;
                rcd->egrbufs.size = eager_buffer_size;
@@ -318,12 +317,8 @@ struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u32 ctxt)
                if (ctxt < dd->first_user_ctxt) { /* N/A for PSM contexts */
                        rcd->opstats = kzalloc(sizeof(*rcd->opstats),
                                GFP_KERNEL);
-                       if (!rcd->opstats) {
-                               dd_dev_err(dd,
-                                          "ctxt%u: Unable to allocate per ctxt stats buffer\n",
-                                          rcd->ctxt);
+                       if (!rcd->opstats)
                                goto bail;
-                       }
                }
        }
        return rcd;
@@ -418,6 +413,7 @@ static enum hrtimer_restart cca_timer_fn(struct hrtimer *t)
        int sl;
        u16 ccti, ccti_timer, ccti_min;
        struct cc_state *cc_state;
+       unsigned long flags;
 
        cca_timer = container_of(t, struct cca_timer, hrtimer);
        ppd = cca_timer->ppd;
@@ -441,7 +437,7 @@ static enum hrtimer_restart cca_timer_fn(struct hrtimer *t)
        ccti_min = cc_state->cong_setting.entries[sl].ccti_min;
        ccti_timer = cc_state->cong_setting.entries[sl].ccti_timer;
 
-       spin_lock(&ppd->cca_timer_lock);
+       spin_lock_irqsave(&ppd->cca_timer_lock, flags);
 
        ccti = cca_timer->ccti;
 
@@ -450,7 +446,7 @@ static enum hrtimer_restart cca_timer_fn(struct hrtimer *t)
                set_link_ipg(ppd);
        }
 
-       spin_unlock(&ppd->cca_timer_lock);
+       spin_unlock_irqrestore(&ppd->cca_timer_lock, flags);
 
        rcu_read_unlock();
 
@@ -1050,8 +1046,8 @@ struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra)
        if (!hfi1_cpulist_count) {
                u32 count = num_online_cpus();
 
-               hfi1_cpulist = kzalloc(BITS_TO_LONGS(count) *
-                                     sizeof(long), GFP_KERNEL);
+               hfi1_cpulist = kcalloc(BITS_TO_LONGS(count), sizeof(long),
+                                      GFP_KERNEL);
                if (hfi1_cpulist)
                        hfi1_cpulist_count = count;
                else
index b2c1b72d38ce4621e2e0a334eef24823aeaadf74..32f7037361853efaa434f8c4edb39bfd81d7171a 100644 (file)
@@ -1438,7 +1438,7 @@ static int __subn_set_opa_pkeytable(struct opa_smp *smp, u32 am, u8 *data,
 
 static int get_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
 {
-       u64 *val = (u64 *)data;
+       u64 *val = data;
 
        *val++ = read_csr(dd, SEND_SC2VLT0);
        *val++ = read_csr(dd, SEND_SC2VLT1);
@@ -1457,7 +1457,7 @@ static int get_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
 static void filter_sc2vlt(void *data)
 {
        int i;
-       u8 *pd = (u8 *)data;
+       u8 *pd = data;
 
        for (i = 0; i < OPA_MAX_SCS; i++) {
                if (i == 15)
@@ -1469,7 +1469,7 @@ static void filter_sc2vlt(void *data)
 
 static int set_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
 {
-       u64 *val = (u64 *)data;
+       u64 *val = data;
 
        filter_sc2vlt(data);
 
@@ -1478,7 +1478,7 @@ static int set_sc2vlt_tables(struct hfi1_devdata *dd, void *data)
        write_csr(dd, SEND_SC2VLT2, *val++);
        write_csr(dd, SEND_SC2VLT3, *val++);
        write_seqlock_irq(&dd->sc2vl_lock);
-       memcpy(dd->sc2vl, (u64 *)data, sizeof(dd->sc2vl));
+       memcpy(dd->sc2vl, data, sizeof(dd->sc2vl));
        write_sequnlock_irq(&dd->sc2vl_lock);
        return 0;
 }
@@ -1488,7 +1488,7 @@ static int __subn_get_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data,
                                   u32 *resp_len)
 {
        struct hfi1_ibport *ibp = to_iport(ibdev, port);
-       u8 *p = (u8 *)data;
+       u8 *p = data;
        size_t size = ARRAY_SIZE(ibp->sl_to_sc); /* == 32 */
        unsigned i;
 
@@ -1511,7 +1511,7 @@ static int __subn_set_opa_sl_to_sc(struct opa_smp *smp, u32 am, u8 *data,
                                   u32 *resp_len)
 {
        struct hfi1_ibport *ibp = to_iport(ibdev, port);
-       u8 *p = (u8 *)data;
+       u8 *p = data;
        int i;
 
        if (am) {
@@ -1530,7 +1530,7 @@ static int __subn_get_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data,
                                   u32 *resp_len)
 {
        struct hfi1_ibport *ibp = to_iport(ibdev, port);
-       u8 *p = (u8 *)data;
+       u8 *p = data;
        size_t size = ARRAY_SIZE(ibp->sc_to_sl); /* == 32 */
        unsigned i;
 
@@ -1553,7 +1553,7 @@ static int __subn_set_opa_sc_to_sl(struct opa_smp *smp, u32 am, u8 *data,
                                   u32 *resp_len)
 {
        struct hfi1_ibport *ibp = to_iport(ibdev, port);
-       u8 *p = (u8 *)data;
+       u8 *p = data;
        int i;
 
        if (am) {
@@ -3257,7 +3257,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
                return reply((struct ib_mad_hdr *)smp);
        }
 
-       spin_lock(&ppd->cc_log_lock);
+       spin_lock_irq(&ppd->cc_log_lock);
 
        cong_log->log_type = OPA_CC_LOG_TYPE_HFI;
        cong_log->congestion_flags = 0;
@@ -3300,7 +3300,7 @@ static int __subn_get_opa_hfi1_cong_log(struct opa_smp *smp, u32 am,
               sizeof(ppd->threshold_cong_event_map));
        ppd->threshold_event_counter = 0;
 
-       spin_unlock(&ppd->cc_log_lock);
+       spin_unlock_irq(&ppd->cc_log_lock);
 
        if (resp_len)
                *resp_len += sizeof(struct opa_hfi1_cong_log);
index 402bd64141769e263e7bc22e67ca86e197464360..568f185a022dffa5bf24a1af010261a4b4f7b5c0 100644 (file)
@@ -284,20 +284,20 @@ struct ib_mr *hfi1_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
        m = 0;
        n = 0;
        for_each_sg(umem->sg_head.sgl, sg, umem->nmap, entry) {
-                       void *vaddr;
-
-                       vaddr = page_address(sg_page(sg));
-                       if (!vaddr) {
-                               ret = ERR_PTR(-EINVAL);
-                               goto bail;
-                       }
-                       mr->mr.map[m]->segs[n].vaddr = vaddr;
-                       mr->mr.map[m]->segs[n].length = umem->page_size;
-                       n++;
-                       if (n == HFI1_SEGSZ) {
-                               m++;
-                               n = 0;
-                       }
+               void *vaddr;
+
+               vaddr = page_address(sg_page(sg));
+               if (!vaddr) {
+                       ret = ERR_PTR(-EINVAL);
+                       goto bail;
+               }
+               mr->mr.map[m]->segs[n].vaddr = vaddr;
+               mr->mr.map[m]->segs[n].length = umem->page_size;
+               n++;
+               if (n == HFI1_SEGSZ) {
+                       m++;
+                       n = 0;
+               }
        }
        ret = &mr->ibmr;
 
index ac5653c0f65e0fe032327a55706e810a267ea827..a956044459a2b29ea83bc0223c9b470448502dcb 100644 (file)
@@ -946,9 +946,21 @@ int do_pcie_gen3_transition(struct hfi1_devdata *dd)
                            __func__);
        }
 
+retry:
+
+       if (therm) {
+               /*
+                * toggle SPICO_ENABLE to get back to the state
+                * just after the firmware load
+                */
+               sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01,
+                       WRITE_SBUS_RECEIVER, 0x00000040);
+               sbus_request(dd, SBUS_MASTER_BROADCAST, 0x01,
+                       WRITE_SBUS_RECEIVER, 0x00000140);
+       }
+
        /* step 3: download SBus Master firmware */
        /* step 4: download PCIe Gen3 SerDes firmware */
-retry:
        dd_dev_info(dd, "%s: downloading firmware\n", __func__);
        ret = load_pcie_firmware(dd);
        if (ret)
@@ -1187,6 +1199,7 @@ retry:
 
        /* clear the DC reset */
        write_csr(dd, CCE_DC_CTRL, 0);
+
        /* Set the LED off */
        if (is_a0(dd))
                setextled(dd, 0);
index 9991814a8f05d4db8fd920a2e55c7ffb74441cdd..e5c32db4bc67c96f58729a269142190dccb94396 100644 (file)
@@ -435,7 +435,6 @@ int init_send_contexts(struct hfi1_devdata *dd)
                                        sizeof(struct send_context_info),
                                        GFP_KERNEL);
        if (!dd->send_contexts || !dd->hw_to_sw) {
-               dd_dev_err(dd, "Unable to allocate send context arrays\n");
                kfree(dd->hw_to_sw);
                kfree(dd->send_contexts);
                free_credit_return(dd);
@@ -684,10 +683,8 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
                return NULL;
 
        sc = kzalloc_node(sizeof(struct send_context), GFP_KERNEL, numa);
-       if (!sc) {
-               dd_dev_err(dd, "Cannot allocate send context structure\n");
+       if (!sc)
                return NULL;
-       }
 
        spin_lock_irqsave(&dd->sc_lock, flags);
        ret = sc_hw_alloc(dd, type, &sw_index, &hw_context);
@@ -813,8 +810,6 @@ struct send_context *sc_alloc(struct hfi1_devdata *dd, int type,
                sc->sr = kzalloc_node(sizeof(union pio_shadow_ring) *
                                sc->sr_size, GFP_KERNEL, numa);
                if (!sc->sr) {
-                       dd_dev_err(dd,
-                               "Cannot allocate send context shadow ring structure\n");
                        sc_free(sc);
                        return NULL;
                }
@@ -927,10 +922,12 @@ void sc_disable(struct send_context *sc)
 static void sc_wait_for_packet_egress(struct send_context *sc, int pause)
 {
        struct hfi1_devdata *dd = sc->dd;
-       u64 reg;
+       u64 reg = 0;
+       u64 reg_prev;
        u32 loop = 0;
 
        while (1) {
+               reg_prev = reg;
                reg = read_csr(dd, sc->hw_context * 8 +
                               SEND_EGRESS_CTXT_STATUS);
                /* done if egress is stopped */
@@ -939,11 +936,17 @@ static void sc_wait_for_packet_egress(struct send_context *sc, int pause)
                reg = packet_occupancy(reg);
                if (reg == 0)
                        break;
-               if (loop > 100) {
+               /* counter is reset if occupancy count changes */
+               if (reg != reg_prev)
+                       loop = 0;
+               if (loop > 500) {
+                       /* timed out - bounce the link */
                        dd_dev_err(dd,
-                               "%s: context %u(%u) timeout waiting for packets to egress, remaining count %u\n",
+                               "%s: context %u(%u) timeout waiting for packets to egress, remaining count %u, bouncing link\n",
                                __func__, sc->sw_index,
                                sc->hw_context, (u32)reg);
+                       queue_work(dd->pport->hfi1_wq,
+                               &dd->pport->link_bounce_work);
                        break;
                }
                loop++;
index 6b505859b59c8061c8dd66288f94498d5204e472..b9c1575990aa3bf9fd38e7f3da22bb520b6ae328 100644 (file)
@@ -52,6 +52,7 @@
 
 #include <linux/hash.h>
 #include "verbs.h"
+#include "sdma.h"
 
 #define QPN_MAX                 (1 << 24)
 #define QPNMAP_ENTRIES          (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
@@ -116,6 +117,20 @@ static inline struct hfi1_qp *hfi1_lookup_qpn(struct hfi1_ibport *ibp,
        return qp;
 }
 
+/**
+ * clear_ahg - reset ahg status in qp
+ * @qp - qp pointer
+ */
+static inline void clear_ahg(struct hfi1_qp *qp)
+{
+       qp->s_hdr->ahgcount = 0;
+       qp->s_flags &= ~(HFI1_S_AHG_VALID | HFI1_S_AHG_CLEAR);
+       if (qp->s_sde && qp->s_ahgidx >= 0)
+               sdma_ahg_free(qp->s_sde, qp->s_ahgidx);
+       qp->s_ahgidx = -1;
+       qp->s_sde = NULL;
+}
+
 /**
  * hfi1_error_qp - put a QP into the error state
  * @qp: the QP to put into the error state
index 3138936157dbd03ab8207581087124888319aa34..ffdb1d787a80bd3bc657ba33b632c44e0ecfc055 100644 (file)
@@ -403,16 +403,11 @@ static const char *pwr_codes = "1.5W2.0W2.5W3.5W";
 
 int qsfp_mod_present(struct hfi1_pportdata *ppd)
 {
-       if (HFI1_CAP_IS_KSET(QSFP_ENABLED)) {
-               struct hfi1_devdata *dd = ppd->dd;
-               u64 reg;
+       struct hfi1_devdata *dd = ppd->dd;
+       u64 reg;
 
-               reg = read_csr(dd,
-                       dd->hfi1_id ? ASIC_QSFP2_IN : ASIC_QSFP1_IN);
-               return !(reg & QSFP_HFI0_MODPRST_N);
-       }
-       /* always return cable present */
-       return 1;
+       reg = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_IN : ASIC_QSFP1_IN);
+       return !(reg & QSFP_HFI0_MODPRST_N);
 }
 
 /*
index fd0ac608c62dca582bef0ef50604c1a2be6fb644..5fc93bb312f1b900ead7e1b6ae4f7ed643799f75 100644 (file)
@@ -697,6 +697,7 @@ void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct hfi1_qp *qp,
        struct pio_buf *pbuf;
        struct hfi1_ib_header hdr;
        struct hfi1_other_headers *ohdr;
+       unsigned long flags;
 
        /* Don't send ACK or NAK if a RDMA read or atomic is pending. */
        if (qp->s_flags & HFI1_S_RESP_PENDING)
@@ -771,7 +772,7 @@ void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct hfi1_qp *qp,
 
 queue_ack:
        this_cpu_inc(*ibp->rc_qacks);
-       spin_lock(&qp->s_lock);
+       spin_lock_irqsave(&qp->s_lock, flags);
        qp->s_flags |= HFI1_S_ACK_PENDING | HFI1_S_RESP_PENDING;
        qp->s_nak_state = qp->r_nak_state;
        qp->s_ack_psn = qp->r_ack_psn;
@@ -780,7 +781,7 @@ queue_ack:
 
        /* Schedule the send tasklet. */
        hfi1_schedule_send(qp);
-       spin_unlock(&qp->s_lock);
+       spin_unlock_irqrestore(&qp->s_lock, flags);
 }
 
 /**
@@ -926,6 +927,7 @@ static void rc_timeout(unsigned long arg)
                ibp->n_rc_timeouts++;
                qp->s_flags &= ~HFI1_S_TIMER;
                del_timer(&qp->s_timer);
+               trace_hfi1_rc_timeout(qp, qp->s_last_psn + 1);
                restart_rc(qp, qp->s_last_psn + 1, 1);
                hfi1_schedule_send(qp);
        }
@@ -1152,7 +1154,7 @@ static struct hfi1_swqe *do_rc_completion(struct hfi1_qp *qp,
  *
  * This is called from rc_rcv_resp() to process an incoming RC ACK
  * for the given QP.
- * Called at interrupt level with the QP s_lock held.
+ * May be called at interrupt level, with the QP s_lock held.
  * Returns 1 if OK, 0 if current operation should be aborted (NAK).
  */
 static int do_rc_ack(struct hfi1_qp *qp, u32 aeth, u32 psn, int opcode,
@@ -1441,6 +1443,8 @@ static void rc_rcv_resp(struct hfi1_ibport *ibp,
 
        spin_lock_irqsave(&qp->s_lock, flags);
 
+       trace_hfi1_rc_ack(qp, psn);
+
        /* Ignore invalid responses. */
        if (cmp_psn(psn, qp->s_next_psn) >= 0)
                goto ack_done;
@@ -1629,6 +1633,7 @@ static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data,
        u8 i, prev;
        int old_req;
 
+       trace_hfi1_rc_rcv_error(qp, psn);
        if (diff > 0) {
                /*
                 * Packet sequence error.
@@ -1835,11 +1840,12 @@ static void log_cca_event(struct hfi1_pportdata *ppd, u8 sl, u32 rlid,
                          u32 lqpn, u32 rqpn, u8 svc_type)
 {
        struct opa_hfi1_cong_log_event_internal *cc_event;
+       unsigned long flags;
 
        if (sl >= OPA_MAX_SLS)
                return;
 
-       spin_lock(&ppd->cc_log_lock);
+       spin_lock_irqsave(&ppd->cc_log_lock, flags);
 
        ppd->threshold_cong_event_map[sl/8] |= 1 << (sl % 8);
        ppd->threshold_event_counter++;
@@ -1855,7 +1861,7 @@ static void log_cca_event(struct hfi1_pportdata *ppd, u8 sl, u32 rlid,
        /* keep timestamp in units of 1.024 usec */
        cc_event->timestamp = ktime_to_ns(ktime_get()) / 1024;
 
-       spin_unlock(&ppd->cc_log_lock);
+       spin_unlock_irqrestore(&ppd->cc_log_lock, flags);
 }
 
 void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
@@ -1865,6 +1871,7 @@ void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
        u16 ccti, ccti_incr, ccti_timer, ccti_limit;
        u8 trigger_threshold;
        struct cc_state *cc_state;
+       unsigned long flags;
 
        if (sl >= OPA_MAX_SLS)
                return;
@@ -1887,7 +1894,7 @@ void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
        trigger_threshold =
                cc_state->cong_setting.entries[sl].trigger_threshold;
 
-       spin_lock(&ppd->cca_timer_lock);
+       spin_lock_irqsave(&ppd->cca_timer_lock, flags);
 
        if (cca_timer->ccti < ccti_limit) {
                if (cca_timer->ccti + ccti_incr <= ccti_limit)
@@ -1897,7 +1904,7 @@ void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
                set_link_ipg(ppd);
        }
 
-       spin_unlock(&ppd->cca_timer_lock);
+       spin_unlock_irqrestore(&ppd->cca_timer_lock, flags);
 
        ccti = cca_timer->ccti;
 
@@ -1924,7 +1931,7 @@ void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
  *
  * This is called from qp_rcv() to process an incoming RC packet
  * for the given QP.
- * Called at interrupt level.
+ * May be called at interrupt level.
  */
 void hfi1_rc_rcv(struct hfi1_packet *packet)
 {
@@ -2383,7 +2390,7 @@ void hfi1_rc_hdrerr(
        struct hfi1_other_headers *ohdr;
        struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
        int diff;
-       u8 opcode;
+       u32 opcode;
        u32 psn;
 
        /* Check for GRH */
index d614474770b31cf7f3bf4424bb85d010858399d7..49bc9fd7a51aee2c3e0e57717ff2514a02c2e327 100644 (file)
@@ -695,19 +695,6 @@ u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
        return sizeof(struct ib_grh) / sizeof(u32);
 }
 
-/*
- * free_ahg - clear ahg from QP
- */
-void clear_ahg(struct hfi1_qp *qp)
-{
-       qp->s_hdr->ahgcount = 0;
-       qp->s_flags &= ~(HFI1_S_AHG_VALID | HFI1_S_AHG_CLEAR);
-       if (qp->s_sde)
-               sdma_ahg_free(qp->s_sde, qp->s_ahgidx);
-       qp->s_ahgidx = -1;
-       qp->s_sde = NULL;
-}
-
 #define BTH2_OFFSET (offsetof(struct hfi1_pio_header, hdr.u.oth.bth[2]) / 4)
 
 /**
@@ -833,6 +820,9 @@ void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr,
        ohdr->bth[2] = cpu_to_be32(bth2);
 }
 
+/* when sending, force a reschedule every one of these periods */
+#define SEND_RESCHED_TIMEOUT (5 * HZ)  /* 5s in jiffies */
+
 /**
  * hfi1_do_send - perform a send on a QP
  * @work: contains a pointer to the QP
@@ -849,6 +839,7 @@ void hfi1_do_send(struct work_struct *work)
        struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
        int (*make_req)(struct hfi1_qp *qp);
        unsigned long flags;
+       unsigned long timeout;
 
        if ((qp->ibqp.qp_type == IB_QPT_RC ||
             qp->ibqp.qp_type == IB_QPT_UC) &&
@@ -877,6 +868,7 @@ void hfi1_do_send(struct work_struct *work)
 
        spin_unlock_irqrestore(&qp->s_lock, flags);
 
+       timeout = jiffies + SEND_RESCHED_TIMEOUT;
        do {
                /* Check for a constructed packet to be sent. */
                if (qp->s_hdrwords != 0) {
@@ -890,6 +882,13 @@ void hfi1_do_send(struct work_struct *work)
                        /* Record that s_hdr is empty. */
                        qp->s_hdrwords = 0;
                }
+
+               /* allow other tasks to run */
+               if (unlikely(time_after(jiffies, timeout))) {
+                       cond_resched();
+                       ppd->dd->verbs_dev.n_send_schedule++;
+                       timeout = jiffies + SEND_RESCHED_TIMEOUT;
+               }
        } while (make_req(qp));
 }
 
index aecd1a74741c656897f9f4ba367892c2a214e7fa..2a1da218990031f446dc0cbbb36fb5643149d17a 100644 (file)
@@ -55,6 +55,7 @@
 #include <linux/bitops.h>
 #include <linux/timer.h>
 #include <linux/vmalloc.h>
+#include <linux/highmem.h>
 
 #include "hfi.h"
 #include "common.h"
@@ -64,7 +65,8 @@
 #include "trace.h"
 
 /* must be a power of 2 >= 64 <= 32768 */
-#define SDMA_DESCQ_CNT 1024
+#define SDMA_DESCQ_CNT 2048
+#define SDMA_DESC_INTR 64
 #define INVALID_TAIL 0xffff
 
 static uint sdma_descq_cnt = SDMA_DESCQ_CNT;
@@ -79,6 +81,10 @@ uint mod_num_sdma;
 module_param_named(num_sdma, mod_num_sdma, uint, S_IRUGO);
 MODULE_PARM_DESC(num_sdma, "Set max number SDMA engines to use");
 
+static uint sdma_desct_intr = SDMA_DESC_INTR;
+module_param_named(desct_intr, sdma_desct_intr, uint, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(desct_intr, "Number of SDMA descriptor before interrupt");
+
 #define SDMA_WAIT_BATCH_SIZE 20
 /* max wait time for a SDMA engine to indicate it has halted */
 #define SDMA_ERR_HALT_TIMEOUT 10 /* ms */
@@ -303,17 +309,26 @@ static void sdma_wait_for_packet_egress(struct sdma_engine *sde,
        u64 off = 8 * sde->this_idx;
        struct hfi1_devdata *dd = sde->dd;
        int lcnt = 0;
+       u64 reg_prev;
+       u64 reg = 0;
 
        while (1) {
-               u64 reg = read_csr(dd, off + SEND_EGRESS_SEND_DMA_STATUS);
+               reg_prev = reg;
+               reg = read_csr(dd, off + SEND_EGRESS_SEND_DMA_STATUS);
 
                reg &= SDMA_EGRESS_PACKET_OCCUPANCY_SMASK;
                reg >>= SDMA_EGRESS_PACKET_OCCUPANCY_SHIFT;
                if (reg == 0)
                        break;
-               if (lcnt++ > 100) {
-                       dd_dev_err(dd, "%s: engine %u timeout waiting for packets to egress, remaining count %u\n",
+               /* counter is reest if accupancy count changes */
+               if (reg != reg_prev)
+                       lcnt = 0;
+               if (lcnt++ > 500) {
+                       /* timed out - bounce the link */
+                       dd_dev_err(dd, "%s: engine %u timeout waiting for packets to egress, remaining count %u, bouncing link\n",
                                  __func__, sde->this_idx, (u32)reg);
+                       queue_work(dd->pport->hfi1_wq,
+                               &dd->pport->link_bounce_work);
                        break;
                }
                udelay(1);
@@ -369,16 +384,17 @@ static void sdma_flush(struct sdma_engine *sde)
 {
        struct sdma_txreq *txp, *txp_next;
        LIST_HEAD(flushlist);
+       unsigned long flags;
 
        /* flush from head to tail */
        sdma_flush_descq(sde);
-       spin_lock(&sde->flushlist_lock);
+       spin_lock_irqsave(&sde->flushlist_lock, flags);
        /* copy flush list */
        list_for_each_entry_safe(txp, txp_next, &sde->flushlist, list) {
                list_del_init(&txp->list);
                list_add_tail(&txp->list, &flushlist);
        }
-       spin_unlock(&sde->flushlist_lock);
+       spin_unlock_irqrestore(&sde->flushlist_lock, flags);
        /* flush from flush list */
        list_for_each_entry_safe(txp, txp_next, &flushlist, list) {
                int drained = 0;
@@ -741,6 +757,7 @@ u16 sdma_get_descq_cnt(void)
                return SDMA_DESCQ_CNT;
        return count;
 }
+
 /**
  * sdma_select_engine_vl() - select sdma engine
  * @dd: devdata
@@ -966,10 +983,7 @@ static void sdma_clean(struct hfi1_devdata *dd, size_t num_engines)
                        sde->descq = NULL;
                        sde->descq_phys = 0;
                }
-               if (is_vmalloc_addr(sde->tx_ring))
-                       vfree(sde->tx_ring);
-               else
-                       kfree(sde->tx_ring);
+               kvfree(sde->tx_ring);
                sde->tx_ring = NULL;
        }
        spin_lock_irq(&dd->sde_map_lock);
@@ -1038,6 +1052,9 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
                return -ENOMEM;
 
        idle_cnt = ns_to_cclock(dd, idle_cnt);
+       if (!sdma_desct_intr)
+               sdma_desct_intr = SDMA_DESC_INTR;
+
        /* Allocate memory for SendDMA descriptor FIFOs */
        for (this_idx = 0; this_idx < num_engines; ++this_idx) {
                sde = &dd->per_sdma[this_idx];
@@ -1096,10 +1113,8 @@ int sdma_init(struct hfi1_devdata *dd, u8 port)
 
                sde->progress_check_head = 0;
 
-               init_timer(&sde->err_progress_check_timer);
-               sde->err_progress_check_timer.function =
-                                               sdma_err_progress_check;
-               sde->err_progress_check_timer.data = (unsigned long)sde;
+               setup_timer(&sde->err_progress_check_timer,
+                           sdma_err_progress_check, (unsigned long)sde);
 
                sde->descq = dma_zalloc_coherent(
                        &dd->pcidev->dev,
@@ -1540,7 +1555,7 @@ void sdma_engine_interrupt(struct sdma_engine *sde, u64 status)
 {
        trace_hfi1_sdma_engine_interrupt(sde, status);
        write_seqlock(&sde->head_lock);
-       sdma_set_desc_cnt(sde, sde->descq_cnt / 2);
+       sdma_set_desc_cnt(sde, sdma_desct_intr);
        sdma_make_progress(sde, status);
        write_sequnlock(&sde->head_lock);
 }
@@ -2699,27 +2714,134 @@ static void __sdma_process_event(struct sdma_engine *sde,
  * of descriptors in the sdma_txreq is exhausted.
  *
  * The code will bump the allocation up to the max
- * of MAX_DESC (64) descriptors.  There doesn't seem
- * much point in an interim step.
+ * of MAX_DESC (64) descriptors. There doesn't seem
+ * much point in an interim step. The last descriptor
+ * is reserved for coalesce buffer in order to support
+ * cases where input packet has >MAX_DESC iovecs.
  *
  */
-int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
+static int _extend_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
 {
        int i;
 
+       /* Handle last descriptor */
+       if (unlikely((tx->num_desc == (MAX_DESC - 1)))) {
+               /* if tlen is 0, it is for padding, release last descriptor */
+               if (!tx->tlen) {
+                       tx->desc_limit = MAX_DESC;
+               } else if (!tx->coalesce_buf) {
+                       /* allocate coalesce buffer with space for padding */
+                       tx->coalesce_buf = kmalloc(tx->tlen + sizeof(u32),
+                                                  GFP_ATOMIC);
+                       if (!tx->coalesce_buf)
+                               return -ENOMEM;
+
+                       tx->coalesce_idx = 0;
+               }
+               return 0;
+       }
+
+       if (unlikely(tx->num_desc == MAX_DESC))
+               return -ENOMEM;
+
        tx->descp = kmalloc_array(
                        MAX_DESC,
                        sizeof(struct sdma_desc),
                        GFP_ATOMIC);
        if (!tx->descp)
                return -ENOMEM;
-       tx->desc_limit = MAX_DESC;
+
+       /* reserve last descriptor for coalescing */
+       tx->desc_limit = MAX_DESC - 1;
        /* copy ones already built */
        for (i = 0; i < tx->num_desc; i++)
                tx->descp[i] = tx->descs[i];
        return 0;
 }
 
+/*
+ * ext_coal_sdma_tx_descs() - extend or coalesce sdma tx descriptors
+ *
+ * This is called once the initial nominal allocation of descriptors
+ * in the sdma_txreq is exhausted.
+ *
+ * This function calls _extend_sdma_tx_descs to extend or allocate
+ * coalesce buffer. If there is a allocated coalesce buffer, it will
+ * copy the input packet data into the coalesce buffer. It also adds
+ * coalesce buffer descriptor once whe whole packet is received.
+ *
+ * Return:
+ * <0 - error
+ * 0 - coalescing, don't populate descriptor
+ * 1 - continue with populating descriptor
+ */
+int ext_coal_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx,
+                          int type, void *kvaddr, struct page *page,
+                          unsigned long offset, u16 len)
+{
+       int pad_len, rval;
+       dma_addr_t addr;
+
+       rval = _extend_sdma_tx_descs(dd, tx);
+       if (rval) {
+               sdma_txclean(dd, tx);
+               return rval;
+       }
+
+       /* If coalesce buffer is allocated, copy data into it */
+       if (tx->coalesce_buf) {
+               if (type == SDMA_MAP_NONE) {
+                       sdma_txclean(dd, tx);
+                       return -EINVAL;
+               }
+
+               if (type == SDMA_MAP_PAGE) {
+                       kvaddr = kmap(page);
+                       kvaddr += offset;
+               } else if (WARN_ON(!kvaddr)) {
+                       sdma_txclean(dd, tx);
+                       return -EINVAL;
+               }
+
+               memcpy(tx->coalesce_buf + tx->coalesce_idx, kvaddr, len);
+               tx->coalesce_idx += len;
+               if (type == SDMA_MAP_PAGE)
+                       kunmap(page);
+
+               /* If there is more data, return */
+               if (tx->tlen - tx->coalesce_idx)
+                       return 0;
+
+               /* Whole packet is received; add any padding */
+               pad_len = tx->packet_len & (sizeof(u32) - 1);
+               if (pad_len) {
+                       pad_len = sizeof(u32) - pad_len;
+                       memset(tx->coalesce_buf + tx->coalesce_idx, 0, pad_len);
+                       /* padding is taken care of for coalescing case */
+                       tx->packet_len += pad_len;
+                       tx->tlen += pad_len;
+               }
+
+               /* dma map the coalesce buffer */
+               addr = dma_map_single(&dd->pcidev->dev,
+                                     tx->coalesce_buf,
+                                     tx->tlen,
+                                     DMA_TO_DEVICE);
+
+               if (unlikely(dma_mapping_error(&dd->pcidev->dev, addr))) {
+                       sdma_txclean(dd, tx);
+                       return -ENOSPC;
+               }
+
+               /* Add descriptor for coalesce buffer */
+               tx->desc_limit = MAX_DESC;
+               return _sdma_txadd_daddr(dd, SDMA_MAP_SINGLE, tx,
+                                        addr, tx->tlen);
+       }
+
+       return 1;
+}
+
 /* Update sdes when the lmc changes */
 void sdma_update_lmc(struct hfi1_devdata *dd, u64 mask, u32 lid)
 {
@@ -2745,13 +2867,15 @@ int _pad_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx)
 {
        int rval = 0;
 
+       tx->num_desc++;
        if ((unlikely(tx->num_desc == tx->desc_limit))) {
                rval = _extend_sdma_tx_descs(dd, tx);
-               if (rval)
+               if (rval) {
+                       sdma_txclean(dd, tx);
                        return rval;
+               }
        }
-       /* finish the one just added  */
-       tx->num_desc++;
+       /* finish the one just added */
        make_tx_sdma_desc(
                tx,
                SDMA_MAP_NONE,
index 49608690389121181195b76c33027436800c7bba..cc22d2ee2054ff36217a6c91709d98841fe375ad 100644 (file)
@@ -352,6 +352,8 @@ struct sdma_txreq {
        /* private: */
        void *coalesce_buf;
        /* private: */
+       u16 coalesce_idx;
+       /* private: */
        struct iowait *wait;
        /* private: */
        callback_t                  complete;
@@ -735,7 +737,9 @@ static inline void make_tx_sdma_desc(
 }
 
 /* helper to extend txreq */
-int _extend_sdma_tx_descs(struct hfi1_devdata *, struct sdma_txreq *);
+int ext_coal_sdma_tx_descs(struct hfi1_devdata *dd, struct sdma_txreq *tx,
+                          int type, void *kvaddr, struct page *page,
+                          unsigned long offset, u16 len);
 int _pad_sdma_tx_descs(struct hfi1_devdata *, struct sdma_txreq *);
 void sdma_txclean(struct hfi1_devdata *, struct sdma_txreq *);
 
@@ -762,11 +766,6 @@ static inline int _sdma_txadd_daddr(
 {
        int rval = 0;
 
-       if ((unlikely(tx->num_desc == tx->desc_limit))) {
-               rval = _extend_sdma_tx_descs(dd, tx);
-               if (rval)
-                       return rval;
-       }
        make_tx_sdma_desc(
                tx,
                type,
@@ -798,9 +797,7 @@ static inline int _sdma_txadd_daddr(
  *
  * Return:
  * 0 - success, -ENOSPC - mapping fail, -ENOMEM - couldn't
- * extend descriptor array or couldn't allocate coalesce
- * buffer.
- *
+ * extend/coalesce descriptor array
  */
 static inline int sdma_txadd_page(
        struct hfi1_devdata *dd,
@@ -809,17 +806,28 @@ static inline int sdma_txadd_page(
        unsigned long offset,
        u16 len)
 {
-       dma_addr_t addr =
-               dma_map_page(
-                       &dd->pcidev->dev,
-                       page,
-                       offset,
-                       len,
-                       DMA_TO_DEVICE);
+       dma_addr_t addr;
+       int rval;
+
+       if ((unlikely(tx->num_desc == tx->desc_limit))) {
+               rval = ext_coal_sdma_tx_descs(dd, tx, SDMA_MAP_PAGE,
+                                             NULL, page, offset, len);
+               if (rval <= 0)
+                       return rval;
+       }
+
+       addr = dma_map_page(
+                      &dd->pcidev->dev,
+                      page,
+                      offset,
+                      len,
+                      DMA_TO_DEVICE);
+
        if (unlikely(dma_mapping_error(&dd->pcidev->dev, addr))) {
                sdma_txclean(dd, tx);
                return -ENOSPC;
        }
+
        return _sdma_txadd_daddr(
                        dd, SDMA_MAP_PAGE, tx, addr, len);
 }
@@ -846,6 +854,15 @@ static inline int sdma_txadd_daddr(
        dma_addr_t addr,
        u16 len)
 {
+       int rval;
+
+       if ((unlikely(tx->num_desc == tx->desc_limit))) {
+               rval = ext_coal_sdma_tx_descs(dd, tx, SDMA_MAP_NONE,
+                                             NULL, NULL, 0, 0);
+               if (rval <= 0)
+                       return rval;
+       }
+
        return _sdma_txadd_daddr(dd, SDMA_MAP_NONE, tx, addr, len);
 }
 
@@ -862,7 +879,7 @@ static inline int sdma_txadd_daddr(
  * The mapping/unmapping of the kvaddr and len is automatically handled.
  *
  * Return:
- * 0 - success, -ENOSPC - mapping fail, -ENOMEM - couldn't extend
+ * 0 - success, -ENOSPC - mapping fail, -ENOMEM - couldn't extend/coalesce
  * descriptor array
  */
 static inline int sdma_txadd_kvaddr(
@@ -871,16 +888,27 @@ static inline int sdma_txadd_kvaddr(
        void *kvaddr,
        u16 len)
 {
-       dma_addr_t addr =
-               dma_map_single(
-                       &dd->pcidev->dev,
-                       kvaddr,
-                       len,
-                       DMA_TO_DEVICE);
+       dma_addr_t addr;
+       int rval;
+
+       if ((unlikely(tx->num_desc == tx->desc_limit))) {
+               rval = ext_coal_sdma_tx_descs(dd, tx, SDMA_MAP_SINGLE,
+                                             kvaddr, NULL, 0, len);
+               if (rval <= 0)
+                       return rval;
+       }
+
+       addr = dma_map_single(
+                      &dd->pcidev->dev,
+                      kvaddr,
+                      len,
+                      DMA_TO_DEVICE);
+
        if (unlikely(dma_mapping_error(&dd->pcidev->dev, addr))) {
                sdma_txclean(dd, tx);
                return -ENOSPC;
        }
+
        return _sdma_txadd_daddr(
                        dd, SDMA_MAP_SINGLE, tx, addr, len);
 }
index b78c72861ef9e53bd59c88e23a6bba763801330d..1dd6727dd5ef0f6f12075efcbd85a4eecb44230c 100644 (file)
@@ -555,7 +555,7 @@ static ssize_t show_tempsense(struct device *device,
                container_of(device, struct hfi1_ibdev, ibdev.dev);
        struct hfi1_devdata *dd = dd_from_dev(dev);
        struct hfi1_temp temp;
-       int ret = -ENXIO;
+       int ret;
 
        ret = hfi1_tempsense_rd(dd, &temp);
        if (!ret) {
index 70ad7b9fc1ce9faafcacad968d69529cd97a1533..f55b75194847db4edf09e738d301a22d942eecb0 100644 (file)
@@ -126,13 +126,13 @@ const char *parse_everbs_hdrs(
        case OP(RC, ACKNOWLEDGE):
                trace_seq_printf(p, AETH_PRN,
                        be32_to_cpu(eh->aeth) >> 24,
-                       be32_to_cpu(eh->aeth) & HFI1_QPN_MASK);
+                       be32_to_cpu(eh->aeth) & HFI1_MSN_MASK);
                break;
        /* aeth + atomicacketh */
        case OP(RC, ATOMIC_ACKNOWLEDGE):
                trace_seq_printf(p, AETH_PRN " " ATOMICACKETH_PRN,
                        (be32_to_cpu(eh->at.aeth) >> 24) & 0xff,
-                       be32_to_cpu(eh->at.aeth) & HFI1_QPN_MASK,
+                       be32_to_cpu(eh->at.aeth) & HFI1_MSN_MASK,
                        (unsigned long long)ib_u64_get(eh->at.atomic_ack_eth));
                break;
        /* atomiceth */
index d7851c0a017132ea0c9891b40907c0078daced47..57430295c40409d3d2629449ebc73327810267fc 100644 (file)
@@ -1252,37 +1252,61 @@ TRACE_EVENT(hfi1_sdma_state,
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM hfi1_rc
 
-DECLARE_EVENT_CLASS(hfi1_sdma_rc,
+DECLARE_EVENT_CLASS(hfi1_rc_template,
        TP_PROTO(struct hfi1_qp *qp, u32 psn),
        TP_ARGS(qp, psn),
        TP_STRUCT__entry(
                DD_DEV_ENTRY(dd_from_ibdev(qp->ibqp.device))
                __field(u32, qpn)
-               __field(u32, flags)
+               __field(u32, s_flags)
                __field(u32, psn)
-               __field(u32, sending_psn)
-               __field(u32, sending_hpsn)
+               __field(u32, s_psn)
+               __field(u32, s_next_psn)
+               __field(u32, s_sending_psn)
+               __field(u32, s_sending_hpsn)
+               __field(u32, r_psn)
        ),
        TP_fast_assign(
                DD_DEV_ASSIGN(dd_from_ibdev(qp->ibqp.device))
                __entry->qpn = qp->ibqp.qp_num;
-               __entry->flags = qp->s_flags;
+               __entry->s_flags = qp->s_flags;
                __entry->psn = psn;
-               __entry->sending_psn = qp->s_sending_psn;
-               __entry->sending_hpsn = qp->s_sending_hpsn;
+               __entry->s_psn = qp->s_psn;
+               __entry->s_next_psn = qp->s_next_psn;
+               __entry->s_sending_psn = qp->s_sending_psn;
+               __entry->s_sending_hpsn = qp->s_sending_hpsn;
+               __entry->r_psn = qp->r_psn;
        ),
        TP_printk(
-               "[%s] qpn 0x%x flags 0x%x psn 0x%x sending_psn 0x%x sending_hpsn 0x%x",
+               "[%s] qpn 0x%x s_flags 0x%x psn 0x%x s_psn 0x%x s_next_psn 0x%x s_sending_psn 0x%x sending_hpsn 0x%x r_psn 0x%x",
                __get_str(dev),
                __entry->qpn,
-               __entry->flags,
+               __entry->s_flags,
                __entry->psn,
-               __entry->sending_psn,
-               __entry->sending_psn
+               __entry->s_psn,
+               __entry->s_next_psn,
+               __entry->s_sending_psn,
+               __entry->s_sending_hpsn,
+               __entry->r_psn
        )
 );
 
-DEFINE_EVENT(hfi1_sdma_rc, hfi1_rc_sendcomplete,
+DEFINE_EVENT(hfi1_rc_template, hfi1_rc_sendcomplete,
+            TP_PROTO(struct hfi1_qp *qp, u32 psn),
+            TP_ARGS(qp, psn)
+);
+
+DEFINE_EVENT(hfi1_rc_template, hfi1_rc_ack,
+            TP_PROTO(struct hfi1_qp *qp, u32 psn),
+            TP_ARGS(qp, psn)
+);
+
+DEFINE_EVENT(hfi1_rc_template, hfi1_rc_timeout,
+            TP_PROTO(struct hfi1_qp *qp, u32 psn),
+            TP_ARGS(qp, psn)
+);
+
+DEFINE_EVENT(hfi1_rc_template, hfi1_rc_rcv_error,
             TP_PROTO(struct hfi1_qp *qp, u32 psn),
             TP_ARGS(qp, psn)
 );
index 55526613a522a794c17591cf5040883fae19046d..36c838dcf0235790602f924ca490987899642514 100644 (file)
@@ -146,7 +146,8 @@ MODULE_PARM_DESC(sdma_comp_size, "Size of User SDMA completion ring. Default: 12
 #define KDETH_OM_MAX_SIZE  (1 << ((KDETH_OM_LARGE / KDETH_OM_SMALL) + 1))
 
 /* Last packet in the request */
-#define USER_SDMA_TXREQ_FLAGS_LAST_PKT   (1 << 0)
+#define TXREQ_FLAGS_REQ_LAST_PKT   (1 << 0)
+#define TXREQ_FLAGS_IOVEC_LAST_PKT (1 << 0)
 
 #define SDMA_REQ_IN_USE     0
 #define SDMA_REQ_FOR_THREAD 1
@@ -249,13 +250,22 @@ struct user_sdma_request {
        unsigned long flags;
 };
 
+/*
+ * A single txreq could span up to 3 physical pages when the MTU
+ * is sufficiently large (> 4K). Each of the IOV pointers also
+ * needs it's own set of flags so the vector has been handled
+ * independently of each other.
+ */
 struct user_sdma_txreq {
        /* Packet header for the txreq */
        struct hfi1_pkt_header hdr;
        struct sdma_txreq txreq;
        struct user_sdma_request *req;
-       struct user_sdma_iovec *iovec1;
-       struct user_sdma_iovec *iovec2;
+       struct {
+               struct user_sdma_iovec *vec;
+               u8 flags;
+       } iovecs[3];
+       int idx;
        u16 flags;
        unsigned busycount;
        u64 seqnum;
@@ -294,21 +304,6 @@ static int defer_packet_queue(
        unsigned seq);
 static void activate_packet_queue(struct iowait *, int);
 
-static inline int iovec_may_free(struct user_sdma_iovec *iovec,
-                                      void (*free)(struct user_sdma_iovec *))
-{
-       if (ACCESS_ONCE(iovec->offset) == iovec->iov.iov_len) {
-               free(iovec);
-               return 1;
-       }
-       return 0;
-}
-
-static inline void iovec_set_complete(struct user_sdma_iovec *iovec)
-{
-       iovec->offset = iovec->iov.iov_len;
-}
-
 static int defer_packet_queue(
        struct sdma_engine *sde,
        struct iowait *wait,
@@ -378,20 +373,14 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp)
        dd = uctxt->dd;
 
        pq = kzalloc(sizeof(*pq), GFP_KERNEL);
-       if (!pq) {
-               dd_dev_err(dd,
-                          "[%u:%u] Failed to allocate SDMA request struct\n",
-                          uctxt->ctxt, subctxt_fp(fp));
+       if (!pq)
                goto pq_nomem;
-       }
+
        memsize = sizeof(*pq->reqs) * hfi1_sdma_comp_ring_size;
        pq->reqs = kmalloc(memsize, GFP_KERNEL);
-       if (!pq->reqs) {
-               dd_dev_err(dd,
-                          "[%u:%u] Failed to allocate SDMA request queue (%u)\n",
-                          uctxt->ctxt, subctxt_fp(fp), memsize);
+       if (!pq->reqs)
                goto pq_reqs_nomem;
-       }
+
        INIT_LIST_HEAD(&pq->list);
        pq->dd = dd;
        pq->ctxt = uctxt->ctxt;
@@ -417,22 +406,15 @@ int hfi1_user_sdma_alloc_queues(struct hfi1_ctxtdata *uctxt, struct file *fp)
        }
        user_sdma_pkt_fp(fp) = pq;
        cq = kzalloc(sizeof(*cq), GFP_KERNEL);
-       if (!cq) {
-               dd_dev_err(dd,
-                          "[%u:%u] Failed to allocate SDMA completion queue\n",
-                          uctxt->ctxt, subctxt_fp(fp));
+       if (!cq)
                goto cq_nomem;
-       }
 
        memsize = ALIGN(sizeof(*cq->comps) * hfi1_sdma_comp_ring_size,
                        PAGE_SIZE);
        cq->comps = vmalloc_user(memsize);
-       if (!cq->comps) {
-               dd_dev_err(dd,
-                     "[%u:%u] Failed to allocate SDMA completion queue entries\n",
-                     uctxt->ctxt, subctxt_fp(fp));
+       if (!cq->comps)
                goto cq_comps_nomem;
-       }
+
        cq->nentries = hfi1_sdma_comp_ring_size;
        user_sdma_comp_fp(fp) = cq;
 
@@ -486,8 +468,7 @@ int hfi1_user_sdma_free_queues(struct hfi1_filedata *fd)
                        }
                        kfree(pq->reqs);
                }
-               if (pq->txreq_cache)
-                       kmem_cache_destroy(pq->txreq_cache);
+               kmem_cache_destroy(pq->txreq_cache);
                kfree(pq);
                fd->pq = NULL;
        }
@@ -839,11 +820,11 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
                tx->flags = 0;
                tx->req = req;
                tx->busycount = 0;
-               tx->iovec1 = NULL;
-               tx->iovec2 = NULL;
+               tx->idx = -1;
+               memset(tx->iovecs, 0, sizeof(tx->iovecs));
 
                if (req->seqnum == req->info.npkts - 1)
-                       tx->flags |= USER_SDMA_TXREQ_FLAGS_LAST_PKT;
+                       tx->flags |= TXREQ_FLAGS_REQ_LAST_PKT;
 
                /*
                 * Calculate the payload size - this is min of the fragment
@@ -872,7 +853,7 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
                                        goto free_tx;
                        }
 
-                       tx->iovec1 = iovec;
+                       tx->iovecs[++tx->idx].vec = iovec;
                        datalen = compute_data_length(req, tx);
                        if (!datalen) {
                                SDMA_DBG(req,
@@ -962,10 +943,17 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
                                              iovec->pages[pageidx],
                                              offset, len);
                        if (ret) {
+                               int i;
+
                                dd_dev_err(pq->dd,
                                           "SDMA txreq add page failed %d\n",
                                           ret);
-                               iovec_set_complete(iovec);
+                               /* Mark all assigned vectors as complete so they
+                                * are unpinned in the callback. */
+                               for (i = tx->idx; i >= 0; i--) {
+                                       tx->iovecs[i].flags |=
+                                               TXREQ_FLAGS_IOVEC_LAST_PKT;
+                               }
                                goto free_txreq;
                        }
                        iov_offset += len;
@@ -973,8 +961,11 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
                        data_sent += len;
                        if (unlikely(queued < datalen &&
                                     pageidx == iovec->npages &&
-                                    req->iov_idx < req->data_iovs - 1)) {
+                                    req->iov_idx < req->data_iovs - 1 &&
+                                    tx->idx < ARRAY_SIZE(tx->iovecs))) {
                                iovec->offset += iov_offset;
+                               tx->iovecs[tx->idx].flags |=
+                                       TXREQ_FLAGS_IOVEC_LAST_PKT;
                                iovec = &req->iovs[++req->iov_idx];
                                if (!iovec->pages) {
                                        ret = pin_vector_pages(req, iovec);
@@ -982,8 +973,7 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
                                                goto free_txreq;
                                }
                                iov_offset = 0;
-                               tx->iovec2 = iovec;
-
+                               tx->iovecs[++tx->idx].vec = iovec;
                        }
                }
                /*
@@ -995,11 +985,15 @@ static int user_sdma_send_pkts(struct user_sdma_request *req, unsigned maxpkts)
                        req->tidoffset += datalen;
                req->sent += data_sent;
                if (req->data_len) {
-                       if (tx->iovec1 && !tx->iovec2)
-                               tx->iovec1->offset += iov_offset;
-                       else if (tx->iovec2)
-                               tx->iovec2->offset += iov_offset;
+                       tx->iovecs[tx->idx].vec->offset += iov_offset;
+                       /* If we've reached the end of the io vector, mark it
+                        * so the callback can unpin the pages and free it. */
+                       if (tx->iovecs[tx->idx].vec->offset ==
+                           tx->iovecs[tx->idx].vec->iov.iov_len)
+                               tx->iovecs[tx->idx].flags |=
+                                       TXREQ_FLAGS_IOVEC_LAST_PKT;
                }
+
                /*
                 * It is important to increment this here as it is used to
                 * generate the BTH.PSN and, therefore, can't be bulk-updated
@@ -1051,8 +1045,8 @@ static int pin_vector_pages(struct user_sdma_request *req,
        unsigned pinned;
 
        iovec->npages = num_user_pages(&iovec->iov);
-       iovec->pages = kzalloc(sizeof(*iovec->pages) *
-                              iovec->npages, GFP_KERNEL);
+       iovec->pages = kcalloc(iovec->npages, sizeof(*iovec->pages),
+                              GFP_KERNEL);
        if (!iovec->pages) {
                SDMA_DBG(req, "Failed page array alloc");
                ret = -ENOMEM;
@@ -1228,7 +1222,7 @@ static int set_txreq_header(struct user_sdma_request *req,
                                req->seqnum));
 
        /* Set ACK request on last packet */
-       if (unlikely(tx->flags & USER_SDMA_TXREQ_FLAGS_LAST_PKT))
+       if (unlikely(tx->flags & TXREQ_FLAGS_REQ_LAST_PKT))
                hdr->bth[2] |= cpu_to_be32(1UL<<31);
 
        /* Set the new offset */
@@ -1260,7 +1254,7 @@ static int set_txreq_header(struct user_sdma_request *req,
                KDETH_SET(hdr->kdeth.ver_tid_offset, TID,
                          EXP_TID_GET(tidval, IDX));
                /* Clear KDETH.SH only on the last packet */
-               if (unlikely(tx->flags & USER_SDMA_TXREQ_FLAGS_LAST_PKT))
+               if (unlikely(tx->flags & TXREQ_FLAGS_REQ_LAST_PKT))
                        KDETH_SET(hdr->kdeth.ver_tid_offset, SH, 0);
                /*
                 * Set the KDETH.OFFSET and KDETH.OM based on size of
@@ -1304,7 +1298,7 @@ static int set_txreq_header_ahg(struct user_sdma_request *req,
        /* BTH.PSN and BTH.A */
        val32 = (be32_to_cpu(hdr->bth[2]) + req->seqnum) &
                (HFI1_CAP_IS_KSET(EXTENDED_PSN) ? 0x7fffffff : 0xffffff);
-       if (unlikely(tx->flags & USER_SDMA_TXREQ_FLAGS_LAST_PKT))
+       if (unlikely(tx->flags & TXREQ_FLAGS_REQ_LAST_PKT))
                val32 |= 1UL << 31;
        AHG_HEADER_SET(req->ahg, diff, 6, 0, 16, cpu_to_be16(val32 >> 16));
        AHG_HEADER_SET(req->ahg, diff, 6, 16, 16, cpu_to_be16(val32 & 0xffff));
@@ -1345,7 +1339,7 @@ static int set_txreq_header_ahg(struct user_sdma_request *req,
                val = cpu_to_le16(((EXP_TID_GET(tidval, CTRL) & 0x3) << 10) |
                                        (EXP_TID_GET(tidval, IDX) & 0x3ff));
                /* Clear KDETH.SH on last packet */
-               if (unlikely(tx->flags & USER_SDMA_TXREQ_FLAGS_LAST_PKT)) {
+               if (unlikely(tx->flags & TXREQ_FLAGS_REQ_LAST_PKT)) {
                        val |= cpu_to_le16(KDETH_GET(hdr->kdeth.ver_tid_offset,
                                                                INTR) >> 16);
                        val &= cpu_to_le16(~(1U << 13));
@@ -1372,10 +1366,16 @@ static void user_sdma_txreq_cb(struct sdma_txreq *txreq, int status,
        if (unlikely(!req || !pq))
                return;
 
-       if (tx->iovec1)
-               iovec_may_free(tx->iovec1, unpin_vector_pages);
-       if (tx->iovec2)
-               iovec_may_free(tx->iovec2, unpin_vector_pages);
+       /* If we have any io vectors associated with this txreq,
+        * check whether they need to be 'freed'. */
+       if (tx->idx != -1) {
+               int i;
+
+               for (i = tx->idx; i >= 0; i--) {
+                       if (tx->iovecs[i].flags & TXREQ_FLAGS_IOVEC_LAST_PKT)
+                               unpin_vector_pages(tx->iovecs[i].vec);
+               }
+       }
 
        tx_seqnum = tx->seqnum;
        kmem_cache_free(pq->txreq_cache, tx);
index 6e2da7ee6d2f69c9828a1de861a152f25726c017..9beb0aa876f073c8eaad7fd119118b55b77dcf6c 100644 (file)
@@ -129,6 +129,9 @@ static void verbs_sdma_complete(
        int status,
        int drained);
 
+/* Length of buffer to create verbs txreq cache name */
+#define TXREQ_NAME_LEN 24
+
 /*
  * Note that it is OK to post send work requests in the SQE and ERR
  * states; hfi1_do_send() will process them and generate error
@@ -609,6 +612,7 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
        u32 tlen = packet->tlen;
        struct hfi1_pportdata *ppd = rcd->ppd;
        struct hfi1_ibport *ibp = &ppd->ibport_data;
+       unsigned long flags;
        u32 qp_num;
        int lnh;
        u8 opcode;
@@ -651,10 +655,10 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
                        goto drop;
                list_for_each_entry_rcu(p, &mcast->qp_list, list) {
                        packet->qp = p->qp;
-                       spin_lock(&packet->qp->r_lock);
+                       spin_lock_irqsave(&packet->qp->r_lock, flags);
                        if (likely((qp_ok(opcode, packet))))
                                opcode_handler_tbl[opcode](packet);
-                       spin_unlock(&packet->qp->r_lock);
+                       spin_unlock_irqrestore(&packet->qp->r_lock, flags);
                }
                /*
                 * Notify hfi1_multicast_detach() if it is waiting for us
@@ -669,10 +673,10 @@ void hfi1_ib_rcv(struct hfi1_packet *packet)
                        rcu_read_unlock();
                        goto drop;
                }
-               spin_lock(&packet->qp->r_lock);
+               spin_lock_irqsave(&packet->qp->r_lock, flags);
                if (likely((qp_ok(opcode, packet))))
                        opcode_handler_tbl[opcode](packet);
-               spin_unlock(&packet->qp->r_lock);
+               spin_unlock_irqrestore(&packet->qp->r_lock, flags);
                rcu_read_unlock();
        }
        return;
@@ -1211,6 +1215,7 @@ pio_bail:
        }
        return 0;
 }
+
 /*
  * egress_pkey_matches_entry - return 1 if the pkey matches ent (ent
  * being an entry from the ingress partition key table), return 0
@@ -1896,7 +1901,7 @@ static void init_ibport(struct hfi1_pportdata *ppd)
 
 static void verbs_txreq_kmem_cache_ctor(void *obj)
 {
-       struct verbs_txreq *tx = (struct verbs_txreq *)obj;
+       struct verbs_txreq *tx = obj;
 
        memset(tx, 0, sizeof(*tx));
 }
@@ -1915,6 +1920,7 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
        int ret;
        size_t lcpysz = IB_DEVICE_NAME_MAX;
        u16 descq_cnt;
+       char buf[TXREQ_NAME_LEN];
 
        ret = hfi1_qp_init(dev);
        if (ret)
@@ -1968,8 +1974,9 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
 
        descq_cnt = sdma_get_descq_cnt();
 
+       snprintf(buf, sizeof(buf), "hfi1_%u_vtxreq_cache", dd->unit);
        /* SLAB_HWCACHE_ALIGN for AHG */
-       dev->verbs_txreq_cache = kmem_cache_create("hfi1_vtxreq_cache",
+       dev->verbs_txreq_cache = kmem_cache_create(buf,
                                                   sizeof(struct verbs_txreq),
                                                   0, SLAB_HWCACHE_ALIGN,
                                                   verbs_txreq_kmem_cache_ctor);
index 159ec08bfcd8d613e92f54c390df05f1c188d14d..041ad07ee699a05c571b833f0469970da4972cae 100644 (file)
@@ -759,6 +759,7 @@ struct hfi1_ibdev {
        u64 n_piowait;
        u64 n_txwait;
        u64 n_kmem_wait;
+       u64 n_send_schedule;
 
        u32 n_pds_allocated;    /* number of PDs allocated for device */
        spinlock_t n_pds_lock;
@@ -1076,8 +1077,6 @@ int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_ib_header *hdr,
 u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
                  struct ib_global_route *grh, u32 hwords, u32 nwords);
 
-void clear_ahg(struct hfi1_qp *qp);
-
 void hfi1_make_ruc_header(struct hfi1_qp *qp, struct hfi1_other_headers *ohdr,
                          u32 bth0, u32 bth2, int middle);
 
index 871dbe56216a27e75ee64a1e4646ca027dd22a27..2ab22f98e3ba0e81a7d8968aabf97d7601be2d8b 100644 (file)
@@ -33,7 +33,6 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
-#include <linux/sched.h>
 #include <linux/spinlock.h>
 #include <linux/idr.h>
 #include <linux/pci.h>
@@ -490,8 +489,7 @@ static int ipath_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                                "Unable to set DMA mask for unit %u: %d\n",
                                dd->ipath_unit, ret);
                        goto bail_regions;
-               }
-               else {
+               } else {
                        ipath_dbg("No 64bit DMA mask, used 32 bit mask\n");
                        ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
                        if (ret)
@@ -501,8 +499,7 @@ static int ipath_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                                        dd->ipath_unit, ret);
 
                }
-       }
-       else {
+       } else {
                ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
                if (ret)
                        dev_info(&pdev->dev,
@@ -1229,11 +1226,10 @@ reloop:
                        ipath_cdbg(PKT, "typ %x, opcode %x (eager, "
                                   "qp=%x), len %x; ignored\n",
                                   etype, opcode, qp, tlen);
-               }
-               else if (etype == RCVHQ_RCV_TYPE_EXPECTED)
+               } else if (etype == RCVHQ_RCV_TYPE_EXPECTED) {
                        ipath_dbg("Bug: Expected TID, opcode %x; ignored\n",
                                  be32_to_cpu(hdr->bth[0]) >> 24);
-               else {
+               else {
                        /*
                         * error packet, type of error unknown.
                         * Probably type 3, but we don't know, so don't
@@ -1270,8 +1266,9 @@ reloop:
                                pd->port_seq_cnt = 1;
                        if (seq != pd->port_seq_cnt)
                                last = 1;
-               } else if (l == hdrqtail)
+               } else if (l == hdrqtail) {
                        last = 1;
+               }
                /*
                 * update head regs on last packet, and every 16 packets.
                 * Reduce bus traffic, while still trying to prevent
@@ -1821,15 +1818,14 @@ int ipath_create_rcvhdrq(struct ipath_devdata *dd,
                           (unsigned long) pd->port_rcvhdrq_phys,
                           (unsigned long) pd->port_rcvhdrq_size,
                           pd->port_port);
-       }
-       else
+       } else {
                ipath_cdbg(VERBOSE, "reuse port %d rcvhdrq @%p %llx phys; "
                           "hdrtailaddr@%p %llx physical\n",
                           pd->port_port, pd->port_rcvhdrq,
                           (unsigned long long) pd->port_rcvhdrq_phys,
                           pd->port_rcvhdrtail_kvaddr, (unsigned long long)
                           pd->port_rcvhdrqtailaddr_phys);
-
+       }
        /* clear for security and sanity on each use */
        memset(pd->port_rcvhdrq, 0, pd->port_rcvhdrq_size);
        if (pd->port_rcvhdrtail_kvaddr)
@@ -2310,10 +2306,9 @@ void ipath_set_led_override(struct ipath_devdata *dd, unsigned int val)
         */
        if (atomic_inc_return(&dd->ipath_led_override_timer_active) == 1) {
                /* Need to start timer */
-               init_timer(&dd->ipath_led_override_timer);
-               dd->ipath_led_override_timer.function =
-                                                ipath_run_led_override;
-               dd->ipath_led_override_timer.data = (unsigned long) dd;
+               setup_timer(&dd->ipath_led_override_timer,
+                               ipath_run_led_override, (unsigned long)dd);
+
                dd->ipath_led_override_timer.expires = jiffies + 1;
                add_timer(&dd->ipath_led_override_timer);
        } else
index fc7181985e8e8886a48cbbcbfcce3cc499e6b871..ef84107c7ce00c814076591717224db0b1e29ab7 100644 (file)
@@ -411,7 +411,7 @@ bail:
  */
 static int i2c_probe(struct ipath_devdata *dd, int devaddr)
 {
-       int ret = 0;
+       int ret;
 
        ret = eeprom_reset(dd);
        if (ret) {
index 450d1596500512c7f41174dec8d078bb15edb79a..5d9b9dbd8fc44804fbf7a4256782ecc7d4f7630f 100644 (file)
@@ -825,13 +825,13 @@ static void ipath_clean_part_key(struct ipath_portdata *pd,
                                ipath_stats.sps_pkeys[j] =
                                        dd->ipath_pkeys[j] = 0;
                                pchanged++;
+                       } else {
+                               ipath_cdbg(VERBOSE, "p%u key %x matches #%d, "
+                                          "but ref still %d\n", pd->port_port,
+                                          pd->port_pkeys[i], j,
+                                          atomic_read(&dd->ipath_pkeyrefs[j]));
+                               break;
                        }
-                       else ipath_cdbg(
-                               VERBOSE, "p%u key %x matches #%d, "
-                               "but ref still %d\n", pd->port_port,
-                               pd->port_pkeys[i], j,
-                               atomic_read(&dd->ipath_pkeyrefs[j]));
-                       break;
                }
                pd->port_pkeys[i] = 0;
        }
@@ -2046,7 +2046,6 @@ static void unlock_expected_tids(struct ipath_portdata *pd)
 
 static int ipath_close(struct inode *in, struct file *fp)
 {
-       int ret = 0;
        struct ipath_filedata *fd;
        struct ipath_portdata *pd;
        struct ipath_devdata *dd;
@@ -2158,7 +2157,7 @@ static int ipath_close(struct inode *in, struct file *fp)
 
 bail:
        kfree(fd);
-       return ret;
+       return 0;
 }
 
 static int ipath_port_info(struct ipath_portdata *pd, u16 subport,
index 25422a3a72387eb39bd5bac638bcf62a198373bd..796af686700739c8401bd49c9ea97d43f6c3d5de 100644 (file)
@@ -195,16 +195,9 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
                goto bail;
        }
 
-       tmp = kmalloc(count, GFP_KERNEL);
-       if (!tmp) {
-               ret = -ENOMEM;
-               goto bail;
-       }
-
-       if (copy_from_user(tmp, buf, count)) {
-               ret = -EFAULT;
-               goto bail_tmp;
-       }
+       tmp = memdup_user(buf, count);
+       if (IS_ERR(tmp))
+               return PTR_ERR(tmp);
 
        dd = file_inode(file)->i_private;
        if (ipath_eeprom_write(dd, pos, tmp, count)) {
index 7cc305488a3d6bf0868692bf7d8ec268a74cdcd1..5f13572a5e24f051afd39014f5d5c1750477d69b 100644 (file)
@@ -666,9 +666,9 @@ static void ipath_ht_handle_hwerrors(struct ipath_devdata *dd, char *msg,
                 * other reset is possible.
                 */
                dd->ipath_flags &= ~IPATH_INITTED;
-       }
-       else
+       } else {
                *msg = 0; /* recovered from all of them */
+       }
        if (*msg)
                ipath_dev_err(dd, "%s hardware error\n", msg);
        if (isfatal && !ipath_diag_inuse && dd->ipath_freezemsg)
@@ -1134,8 +1134,7 @@ static void ipath_setup_ht_setextled(struct ipath_devdata *dd,
                        extctl &= ~INFINIPATH_EXTC_LEDGBLERR_OFF;
                if (lst == INFINIPATH_IBCS_L_STATE_ACTIVE)
                        extctl |= INFINIPATH_EXTC_LEDGBLOK_ON;
-       }
-       else {
+       } else {
                extctl = dd->ipath_extctrl &
                        ~(INFINIPATH_EXTC_LED1PRIPORT_ON |
                          INFINIPATH_EXTC_LED2PRIPORT_ON);
index be2a60e142b00b0e9af8e2eed5172700d731fbf2..a5eea199f7331ac07e2ee75fac22a5731cda426d 100644 (file)
@@ -210,7 +210,7 @@ static int bringup_link(struct ipath_devdata *dd)
 
 static struct ipath_portdata *create_portdata0(struct ipath_devdata *dd)
 {
-       struct ipath_portdata *pd = NULL;
+       struct ipath_portdata *pd;
 
        pd = kzalloc(sizeof(*pd), GFP_KERNEL);
        if (pd) {
@@ -264,7 +264,7 @@ static int init_chip_first(struct ipath_devdata *dd)
         * Allocate full portcnt array, rather than just cfgports, because
         * cleanup iterates across all possible ports.
         */
-       dd->ipath_pd = kzalloc(sizeof(*dd->ipath_pd) * dd->ipath_portcnt,
+       dd->ipath_pd = kcalloc(dd->ipath_portcnt, sizeof(*dd->ipath_pd),
                               GFP_KERNEL);
 
        if (!dd->ipath_pd) {
@@ -324,10 +324,10 @@ static int init_chip_first(struct ipath_devdata *dd)
                          dd->ipath_pio2kbase, dd->ipath_piobcnt4k,
                          dd->ipath_piosize4k, dd->ipath_pio4kbase,
                          dd->ipath_4kalign);
+       } else {
+               ipath_dbg("%u 2k piobufs @ %p\n",
+                         dd->ipath_piobcnt2k, dd->ipath_pio2kbase);
        }
-       else ipath_dbg("%u 2k piobufs @ %p\n",
-                      dd->ipath_piobcnt2k, dd->ipath_pio2kbase);
-
 done:
        return ret;
 }
@@ -903,9 +903,9 @@ int ipath_init_chip(struct ipath_devdata *dd, int reinit)
                ipath_dev_err(dd, "failed to allocate kernel port's "
                              "rcvhdrq and/or egr bufs\n");
                goto done;
-       }
-       else
+       } else {
                enable_chip(dd, reinit);
+       }
 
        /* after enable_chip, so pioavailshadow setup */
        ipath_chg_pioavailkernel(dd, 0, piobufs, 1);
@@ -950,9 +950,8 @@ int ipath_init_chip(struct ipath_devdata *dd, int reinit)
                 * set up stats retrieval timer, even if we had errors
                 * in last portion of setup
                 */
-               init_timer(&dd->ipath_stats_timer);
-               dd->ipath_stats_timer.function = ipath_get_faststats;
-               dd->ipath_stats_timer.data = (unsigned long) dd;
+               setup_timer(&dd->ipath_stats_timer, ipath_get_faststats,
+                               (unsigned long)dd);
                /* every 5 seconds; */
                dd->ipath_stats_timer.expires = jiffies + 5 * HZ;
                /* takes ~16 seconds to overflow at full IB 4x bandwdith */
@@ -965,9 +964,8 @@ int ipath_init_chip(struct ipath_devdata *dd, int reinit)
                ret = setup_sdma(dd);
 
        /* Set up HoL state */
-       init_timer(&dd->ipath_hol_timer);
-       dd->ipath_hol_timer.function = ipath_hol_event;
-       dd->ipath_hol_timer.data = (unsigned long)dd;
+       setup_timer(&dd->ipath_hol_timer, ipath_hol_event, (unsigned long)dd);
+
        dd->ipath_hol_state = IPATH_HOL_UP;
 
 done:
@@ -988,11 +986,9 @@ done:
                         * to an alternate if necessary and possible
                         */
                        if (!reinit) {
-                               init_timer(&dd->ipath_intrchk_timer);
-                               dd->ipath_intrchk_timer.function =
-                                       verify_interrupt;
-                               dd->ipath_intrchk_timer.data =
-                                       (unsigned long) dd;
+                               setup_timer(&dd->ipath_intrchk_timer,
+                                               verify_interrupt,
+                                               (unsigned long)dd);
                        }
                        dd->ipath_intrchk_timer.expires = jiffies + HZ/2;
                        add_timer(&dd->ipath_intrchk_timer);
index 01ba792791a0afbed1c030f20001271f6af63aa4..0403fa28ed8d8e85cb2279f15744655c374eb77e 100644 (file)
@@ -33,7 +33,6 @@
 
 #include <linux/pci.h>
 #include <linux/delay.h>
-#include <linux/sched.h>
 
 #include "ipath_kernel.h"
 #include "ipath_verbs.h"
@@ -514,15 +513,14 @@ static unsigned handle_frequent_errors(struct ipath_devdata *dd,
                        *noprint = 1;
                        if (!supp_msgs++)
                                nextmsg_time = nc + HZ * 3;
-               }
-               else if (supp_msgs) {
+               } else if (supp_msgs) {
                        handle_supp_msgs(dd, supp_msgs, msg, msgsz);
                        supp_msgs = 0;
                        nmsgs = 0;
                }
-       }
-       else if (!nmsgs++ || time_after(nc, nextmsg_time))
+       } else if (!nmsgs++ || time_after(nc, nextmsg_time)) {
                nextmsg_time = nc + HZ / 2;
+       }
 
        return supp_msgs;
 }
index f0f9471227793f99f386555100ea0254ff39a1f9..66c934a5f8390744673b982a03267365c7372685 100644 (file)
@@ -44,6 +44,7 @@
 #include <linux/mutex.h>
 #include <linux/list.h>
 #include <linux/scatterlist.h>
+#include <linux/sched.h>
 #include <asm/io.h>
 #include <rdma/ib_verbs.h>
 
@@ -162,7 +163,7 @@ struct ipath_portdata {
        struct pid *port_pid;
        struct pid *port_subpid[INFINIPATH_MAX_SUBPORT];
        /* same size as task_struct .comm[] */
-       char port_comm[16];
+       char port_comm[TASK_COMM_LEN];
        /* pkeys set by this use of this port */
        u16 port_pkeys[4];
        /* so file ops can get at unit */
index face87602dc19f2ea915c0bad57f441123d0c9cb..280cd2d638e432b1e8525be52f2d211b910ae7fd 100644 (file)
@@ -32,7 +32,6 @@
  */
 
 #include <linux/err.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 
@@ -1027,7 +1026,7 @@ int ipath_init_qp_table(struct ipath_ibdev *idev, int size)
        idev->qp_table.last = 1;        /* QPN 0 and 1 are special. */
        idev->qp_table.max = size;
        idev->qp_table.nmaps = 1;
-       idev->qp_table.table = kzalloc(size * sizeof(*idev->qp_table.table),
+       idev->qp_table.table = kcalloc(size, sizeof(*idev->qp_table.table),
                                       GFP_KERNEL);
        if (idev->qp_table.table == NULL) {
                ret = -ENOMEM;
index 46af8b03d3d461f23c3bade19230df36e0d67b20..e541a01f1f6122575260e30a7a1dff5445cbdc15 100644 (file)
@@ -31,7 +31,6 @@
  * SOFTWARE.
  */
 
-#include <linux/sched.h>
 #include <linux/spinlock.h>
 
 #include "ipath_verbs.h"
index 17a517766ad27b822ba1b77780601a44f7219a7e..1ffc06abf9da5c56f25cb9a183d5384635713e99 100644 (file)
@@ -400,9 +400,9 @@ static int alloc_sdma(struct ipath_devdata *dd)
        }
        dd->ipath_sdma_head_dma[0] = 0;
 
-       init_timer(&dd->ipath_sdma_vl15_timer);
-       dd->ipath_sdma_vl15_timer.function = vl15_watchdog_timeout;
-       dd->ipath_sdma_vl15_timer.data = (unsigned long)dd;
+       setup_timer(&dd->ipath_sdma_vl15_timer, vl15_watchdog_timeout,
+                       (unsigned long)dd);
+
        atomic_set(&dd->ipath_sdma_vl15_count, 0);
 
        goto done;
index 75558f33f1cb9971c2db3e0a04ba9bf70e993e69..b12b1f6caf59c1a9da7f94461e06411e1894c60e 100644 (file)
@@ -662,8 +662,7 @@ static ssize_t store_enabled(struct device *dev,
                        dd->ipath_flags &= ~IPATH_DISABLED;
                        *dd->ipath_statusp &= ~IPATH_STATUS_ADMIN_DISABLED;
                }
-       }
-       else if (!(dd->ipath_flags & IPATH_DISABLED)) {
+       } else if (!(dd->ipath_flags & IPATH_DISABLED)) {
                dev_info(dev, "Disabling unit %d\n", dd->ipath_unit);
                ipath_shutdown_device(dd);
                dd->ipath_flags |= IPATH_DISABLED;
@@ -1176,9 +1175,9 @@ int ipath_expose_reset(struct device *dev)
        if (!exposed) {
                ret = device_create_file(dev, &dev_attr_reset);
                exposed = 1;
-       }
-       else
+       } else {
                ret = 0;
+       }
 
        return ret;
 }
index 3ffc1565d03d877db7853626f268ee45e8ce4eac..385d9410a51e01478bb5f060c2ecb5d8129ef80f 100644 (file)
@@ -31,7 +31,6 @@
  * SOFTWARE.
  */
 
-#include <linux/sched.h>
 #include <rdma/ib_smi.h>
 
 #include "ipath_verbs.h"
index 1da1252dcdb302ecb84ff0ec26f175cad908ecc4..d29b4daf61f83442b5133261ee01d861195bd1bb 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/mm.h>
 #include <linux/device.h>
 #include <linux/slab.h>
-#include <linux/sched.h>
 
 #include "ipath_kernel.h"
 
index cc04b7ba34882cc7981ec3815af73dc7a0519d91..8c12e3cccc58869d5da210ca13590ec2c1aed436 100644 (file)
@@ -33,7 +33,6 @@
 #include <linux/types.h>
 #include <linux/device.h>
 #include <linux/dmapool.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/list.h>
 #include <linux/highmem.h>
@@ -239,7 +238,7 @@ static int ipath_user_sdma_num_pages(const struct iovec *iov)
 /* truncate length to page boundary */
 static int ipath_user_sdma_page_length(unsigned long addr, unsigned long len)
 {
-       const unsigned long offset = addr & ~PAGE_MASK;
+       const unsigned long offset = offset_in_page(addr);
 
        return ((offset + len) > PAGE_SIZE) ? (PAGE_SIZE - offset) : len;
 }
@@ -298,7 +297,7 @@ static int ipath_user_sdma_pin_pages(const struct ipath_devdata *dd,
                dma_addr_t dma_addr =
                        dma_map_page(&dd->pcidev->dev,
                                     pages[j], 0, flen, DMA_TO_DEVICE);
-               unsigned long fofs = addr & ~PAGE_MASK;
+               unsigned long fofs = offset_in_page(addr);
 
                if (dma_mapping_error(&dd->pcidev->dev, dma_addr)) {
                        ret = -ENOMEM;
index 29e91796fb10965de9d2861fa9aaa4f2e1942a7e..1778dee13f99269c51cc90f6c4d09a6f46a13a21 100644 (file)
@@ -752,9 +752,9 @@ static void ipath_ib_timer(struct ipath_ibdev *dev)
                        dev->ipath_spkts = tc - dev->ipath_spkts;
                        dev->ipath_rpkts = td - dev->ipath_rpkts;
                        dev->ipath_xmit_wait = te - dev->ipath_xmit_wait;
-               }
-               else
+               } else {
                        dev->pma_sample_interval--;
+               }
        }
        spin_unlock_irqrestore(&dev->pending_lock, flags);
 
@@ -1969,9 +1969,8 @@ static int enable_timer(struct ipath_devdata *dd)
                                 dd->ipath_gpio_mask);
        }
 
-       init_timer(&dd->verbs_timer);
-       dd->verbs_timer.function = __verbs_timer;
-       dd->verbs_timer.data = (unsigned long)dd;
+       setup_timer(&dd->verbs_timer, __verbs_timer, (unsigned long)dd);
+
        dd->verbs_timer.expires = jiffies + 1;
        add_timer(&dd->verbs_timer);
 
@@ -2038,8 +2037,8 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
        dev = &idev->ibdev;
 
        if (dd->ipath_sdma_descq_cnt) {
-               tx = kmalloc(dd->ipath_sdma_descq_cnt * sizeof *tx,
-                            GFP_KERNEL);
+               tx = kmalloc_array(dd->ipath_sdma_descq_cnt, sizeof *tx,
+                                  GFP_KERNEL);
                if (tx == NULL) {
                        ret = -ENOMEM;
                        goto err_tx;
@@ -2072,7 +2071,7 @@ int ipath_register_ib_device(struct ipath_devdata *dd)
         * the LKEY).  The remaining bits act as a generation number or tag.
         */
        idev->lk_table.max = 1 << ib_ipath_lkey_table_size;
-       idev->lk_table.table = kzalloc(idev->lk_table.max *
+       idev->lk_table.table = kcalloc(idev->lk_table.max,
                                       sizeof(*idev->lk_table.table),
                                       GFP_KERNEL);
        if (idev->lk_table.table == NULL) {
index 6216ea9238531a9a0c10a6a0dd10a43740db4a12..72d476fa5b8fb15b5183248cf997625ffa9a956f 100644 (file)
@@ -32,7 +32,6 @@
  */
 
 #include <linux/rculist.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 
 #include "ipath_verbs.h"
index 5a38b41494088f27d684ce44293a4bac3585bfe2..94f38793ab47d45557447029491240d1165ca181 100644 (file)
@@ -1,6 +1,6 @@
 config R8188EU
        tristate "Realtek RTL8188EU Wireless LAN NIC driver"
-       depends on WLAN && USB
+       depends on WLAN && USB && CFG80211
        select WIRELESS_EXT
        select WEXT_PRIV
        ---help---
index 31ac15961a00b47ac9fb5a98c11192a41810d3dc..ed723585b50288934d8791f3e347829f5aae3013 100644 (file)
@@ -42,6 +42,7 @@ r8188eu-y :=                          \
                hal/usb_halinit.o       \
                os_dep/ioctl_linux.o    \
                os_dep/mlme_linux.o     \
+               os_dep/mon.o            \
                os_dep/os_intfs.o       \
                os_dep/osdep_service.o  \
                os_dep/recv_linux.o     \
index 5c45f8a8c2cf77053d73456be62bdc159689812c..3cdb40fea5ee7041ed253de939dbd006b786052b 100644 (file)
@@ -1795,7 +1795,7 @@ int rtw_ap_inform_ch_switch(struct adapter *padapter, u8 new_ch, u8 ch_offset)
                plist = plist->next;
 
                issue_action_spct_ch_switch(padapter, psta->hwaddr, new_ch, ch_offset);
-               psta->expire_to = ((pstapriv->expire_to * 2) > 5) ? 5 : (pstapriv->expire_to * 2);
+               psta->expire_to = min_t(unsigned int, pstapriv->expire_to * 2, 5);
        }
        spin_unlock_bh(&pstapriv->asoc_list_lock);
 
index 89b5e48ed68a08fe313406b0b189ab8e999b954c..9b7026e7d55b654cf3861a10d0420341eb7846f1 100644 (file)
@@ -125,7 +125,7 @@ u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
        cmd_obj->padapter = padapter;
 
        res = rtw_cmd_filter(pcmdpriv, cmd_obj);
-       if (_FAIL == res) {
+       if (res == _FAIL) {
                rtw_free_cmd_obj(cmd_obj);
                goto exit;
        }
@@ -199,7 +199,7 @@ _next:
                if (!pcmd)
                        continue;
 
-               if (_FAIL == rtw_cmd_filter(pcmdpriv, pcmd)) {
+               if (rtw_cmd_filter(pcmdpriv, pcmd) == _FAIL) {
                        pcmd->res = H2C_DROPPED;
                        goto post_process;
                }
@@ -553,7 +553,7 @@ u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueu
                res = rtw_enqueue_cmd(cmdpriv, cmdobj);
        } else {
                /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
-               if (H2C_SUCCESS != disconnect_hdl(padapter, (u8 *)param))
+               if (disconnect_hdl(padapter, (u8 *)param) != H2C_SUCCESS)
                        res = _FAIL;
                kfree(param);
        }
@@ -819,7 +819,7 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue)
                res = rtw_enqueue_cmd(pcmdpriv, pcmdobj);
        } else {
                /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
-               if (H2C_SUCCESS != set_chplan_hdl(padapter, (unsigned char *)setChannelPlan_param))
+               if (set_chplan_hdl(padapter, (unsigned char *)setChannelPlan_param) != H2C_SUCCESS)
                        res = _FAIL;
 
                kfree(setChannelPlan_param);
index 993c7db87a1a5b83e79bdd8bc6e23f414a894c05..2c4afb80fc6440bdab25c4196d2b4cb3aed02eb9 100644 (file)
@@ -594,8 +594,7 @@ int proc_set_rx_signal(struct file *file, const char __user *buffer,
                if (is_signal_dbg && num != 2)
                        return count;
 
-               signal_strength = signal_strength > 100 ? 100 : signal_strength;
-               signal_strength = signal_strength < 0 ? 0 : signal_strength;
+               signal_strength = clamp(signal_strength, 0, 100);
 
                padapter->recvpriv.is_signal_dbg = is_signal_dbg;
                padapter->recvpriv.signal_strength_dbg = signal_strength;
index 7b99ea91a9e6caf1e212537f82a2116c473534f6..eb894233a78585dddd379fb02a56bc3b88ba7066 100644 (file)
@@ -268,7 +268,7 @@ static void efuse_read_phymap_from_txpktbuf(
                        aaa = le16_to_cpup((__le16 *)&lo32);
                        len = le16_to_cpu(*((__le16 *)&lo32));
 
-                       limit = (len-2 < limit) ? len-2 : limit;
+                       limit = min_t(u16, len-2, limit);
 
                        DBG_88E("%s len:%u, lenbak:%u, aaa:%u, aaabak:%u\n", __func__, len, lenbak, aaa, aaabak);
 
@@ -396,7 +396,7 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
 
        memset((void *)tmpdata, 0xff, PGPKT_DATA_SIZE);
 
-       if (!(word_en&BIT0)) {
+       if (!(word_en & BIT(0))) {
                tmpaddr = start_addr;
                efuse_OneByteWrite(pAdapter, start_addr++, data[0]);
                efuse_OneByteWrite(pAdapter, start_addr++, data[1]);
@@ -404,9 +404,9 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
                efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[0]);
                efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[1]);
                if ((data[0] != tmpdata[0]) || (data[1] != tmpdata[1]))
-                       badworden &= (~BIT0);
+                       badworden &= (~BIT(0));
        }
-       if (!(word_en&BIT1)) {
+       if (!(word_en & BIT(1))) {
                tmpaddr = start_addr;
                efuse_OneByteWrite(pAdapter, start_addr++, data[2]);
                efuse_OneByteWrite(pAdapter, start_addr++, data[3]);
@@ -414,9 +414,9 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
                efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[2]);
                efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[3]);
                if ((data[2] != tmpdata[2]) || (data[3] != tmpdata[3]))
-                       badworden &= (~BIT1);
+                       badworden &= (~BIT(1));
        }
-       if (!(word_en&BIT2)) {
+       if (!(word_en & BIT(2))) {
                tmpaddr = start_addr;
                efuse_OneByteWrite(pAdapter, start_addr++, data[4]);
                efuse_OneByteWrite(pAdapter, start_addr++, data[5]);
@@ -424,9 +424,9 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
                efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[4]);
                efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[5]);
                if ((data[4] != tmpdata[4]) || (data[5] != tmpdata[5]))
-                       badworden &= (~BIT2);
+                       badworden &= (~BIT(2));
        }
-       if (!(word_en&BIT3)) {
+       if (!(word_en & BIT(3))) {
                tmpaddr = start_addr;
                efuse_OneByteWrite(pAdapter, start_addr++, data[6]);
                efuse_OneByteWrite(pAdapter, start_addr++, data[7]);
@@ -434,7 +434,7 @@ u8 Efuse_WordEnableDataWrite(struct adapter *pAdapter, u16 efuse_addr, u8 word_e
                efuse_OneByteRead(pAdapter, tmpaddr, &tmpdata[6]);
                efuse_OneByteRead(pAdapter, tmpaddr+1, &tmpdata[7]);
                if ((data[6] != tmpdata[6]) || (data[7] != tmpdata[7]))
-                       badworden &= (~BIT3);
+                       badworden &= (~BIT(3));
        }
        return badworden;
 }
@@ -738,18 +738,18 @@ static bool wordEnMatched(struct pgpkt *pTargetPkt, struct pgpkt *pCurPkt,
        u8 match_word_en = 0x0F;        /*  default all words are disabled */
 
        /*  check if the same words are enabled both target and current PG packet */
-       if (((pTargetPkt->word_en & BIT0) == 0) &&
-           ((pCurPkt->word_en & BIT0) == 0))
-               match_word_en &= ~BIT0;                         /*  enable word 0 */
-       if (((pTargetPkt->word_en & BIT1) == 0) &&
-           ((pCurPkt->word_en & BIT1) == 0))
-               match_word_en &= ~BIT1;                         /*  enable word 1 */
-       if (((pTargetPkt->word_en & BIT2) == 0) &&
-           ((pCurPkt->word_en & BIT2) == 0))
-               match_word_en &= ~BIT2;                         /*  enable word 2 */
-       if (((pTargetPkt->word_en & BIT3) == 0) &&
-           ((pCurPkt->word_en & BIT3) == 0))
-               match_word_en &= ~BIT3;                         /*  enable word 3 */
+       if (((pTargetPkt->word_en & BIT(0)) == 0) &&
+           ((pCurPkt->word_en & BIT(0)) == 0))
+               match_word_en &= ~BIT(0);                               /*  enable word 0 */
+       if (((pTargetPkt->word_en & BIT(1)) == 0) &&
+           ((pCurPkt->word_en & BIT(1)) == 0))
+               match_word_en &= ~BIT(1);                               /*  enable word 1 */
+       if (((pTargetPkt->word_en & BIT(2)) == 0) &&
+           ((pCurPkt->word_en & BIT(2)) == 0))
+               match_word_en &= ~BIT(2);                               /*  enable word 2 */
+       if (((pTargetPkt->word_en & BIT(3)) == 0) &&
+           ((pCurPkt->word_en & BIT(3)) == 0))
+               match_word_en &= ~BIT(3);                               /*  enable word 3 */
 
        *pWden = match_word_en;
 
@@ -961,19 +961,19 @@ u8 efuse_OneByteWrite(struct adapter *pAdapter, u16 addr, u8 data)
  */
 void efuse_WordEnableDataRead(u8 word_en, u8 *sourdata, u8 *targetdata)
 {
-       if (!(word_en&BIT(0))) {
+       if (!(word_en & BIT(0))) {
                targetdata[0] = sourdata[0];
                targetdata[1] = sourdata[1];
        }
-       if (!(word_en&BIT(1))) {
+       if (!(word_en & BIT(1))) {
                targetdata[2] = sourdata[2];
                targetdata[3] = sourdata[3];
        }
-       if (!(word_en&BIT(2))) {
+       if (!(word_en & BIT(2))) {
                targetdata[4] = sourdata[4];
                targetdata[5] = sourdata[5];
        }
-       if (!(word_en&BIT(3))) {
+       if (!(word_en & BIT(3))) {
                targetdata[6] = sourdata[6];
                targetdata[7] = sourdata[7];
        }
index c3c582881a091e5294376e3436546e27ee5ed604..742b29c590df92a676732341db82c7984ab6e3aa 100644 (file)
@@ -130,12 +130,12 @@ int rtw_check_network_type(unsigned char *rate, int ratelen, int channel)
        }
 }
 
-u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len, unsigned char *source,
-                               unsigned int *frlen)
+u8 *rtw_set_fixed_ie(void *pbuf, unsigned int len, void *source,
+                    unsigned int *frlen)
 {
-       memcpy((void *)pbuf, (void *)source, len);
+       memcpy(pbuf, source, len);
        *frlen = *frlen + len;
-       return pbuf + len;
+       return ((u8 *)pbuf) + len;
 }
 
 /*  rtw_set_ie will update frame length */
@@ -1103,7 +1103,7 @@ void rtw_macaddr_cfg(u8 *mac_addr)
 
 void dump_ies(u8 *buf, u32 buf_len)
 {
-       u8 *pos = (u8 *)buf;
+       u8 *pos = buf;
        u8 id, len;
 
        while (pos-buf <= buf_len) {
@@ -1119,7 +1119,7 @@ void dump_ies(u8 *buf, u32 buf_len)
 
 void dump_wps_ie(u8 *ie, u32 ie_len)
 {
-       u8 *pos = (u8 *)ie;
+       u8 *pos = ie;
        u16 id;
        u16 len;
        u8 *wps_ie;
@@ -1392,6 +1392,6 @@ static const char *_action_public_str[] = {
 
 const char *action_public_str(u8 action)
 {
-       action = (action >= ACT_PUBLIC_MAX) ? ACT_PUBLIC_MAX : action;
+       action = min_t(u8, action, ACT_PUBLIC_MAX);
        return _action_public_str[action];
 }
index 2b917a18e228734abcc66c4d73712109cb1b44f7..c1b82f71b682b00ebc2fcc9bff4729c78851402d 100644 (file)
@@ -1709,8 +1709,8 @@ int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_
        unsigned        int ielength = 0;
        unsigned int i, j;
 
-       i = 12; /* after the fixed IE */
-       while (i < in_len) {
+       /* i = 12; after the fixed IE */
+       for (i = 12; i < in_len; i += (in_ie[i + 1] + 2) /* to the next IE element */) {
                ielength = initial_out_len;
 
                if (in_ie[i] == 0xDD && in_ie[i+2] == 0x00 && in_ie[i+3] == 0x50  && in_ie[i+4] == 0xF2 && in_ie[i+5] == 0x02 && i+5 < in_len) {
@@ -1726,7 +1726,6 @@ int rtw_restruct_wmm_ie(struct adapter *adapter, u8 *in_ie, u8 *out_ie, uint in_
                        out_ie[initial_out_len + 8] = 0x00;
                        break;
                }
-               i += (in_ie[i+1]+2); /*  to the next IE element */
        }
        return ielength;
 }
index 935b48eef8b1f84a6cf57792985c216277eeb0fc..d900546b672f012da6dc31c24c4a5a465effadc6 100644 (file)
@@ -271,7 +271,8 @@ static s32 dump_mgntframe_and_wait_ack(struct adapter *padapter,
        if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
                return -1;
 
-       _enter_critical_mutex(&pxmitpriv->ack_tx_mutex, NULL);
+       if (mutex_lock_interruptible(&pxmitpriv->ack_tx_mutex))
+               return _FAIL;
        pxmitpriv->ack_tx = true;
 
        pmgntframe->ack_report = 1;
@@ -282,7 +283,7 @@ static s32 dump_mgntframe_and_wait_ack(struct adapter *padapter,
        pxmitpriv->ack_tx = false;
        mutex_unlock(&pxmitpriv->ack_tx_mutex);
 
-        return ret;
+       return ret;
 }
 
 static int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
@@ -417,7 +418,7 @@ static void issue_beacon(struct adapter *padapter, int timeout_ms)
 
        /*  supported rates... */
        rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
-       pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
+       pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, min_t(unsigned int, rate_len, 8), cur_network->SupportedRates, &pattrib->pktlen);
 
        /*  DS parameter set */
        pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
@@ -577,7 +578,7 @@ static void issue_probersp(struct adapter *padapter, unsigned char *da)
 
                /*  supported rates... */
                rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
-               pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pattrib->pktlen);
+               pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, min_t(unsigned int, rate_len, 8), cur_network->SupportedRates, &pattrib->pktlen);
 
                /*  DS parameter set */
                pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pattrib->pktlen);
@@ -812,17 +813,20 @@ static void issue_auth(struct adapter *padapter, struct sta_info *psta,
                        le_val16 = 0;
                }
 
-               pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
+               pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, &le_val16,
+                                         &pattrib->pktlen);
 
                /*  setting auth seq number */
                val16 = (u16)psta->auth_seq;
                le_val16 = cpu_to_le16(val16);
-               pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_val16, &(pattrib->pktlen));
+               pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, &le_val16,
+                                         &pattrib->pktlen);
 
                /*  setting status code... */
                val16 = status;
                le_val16 = cpu_to_le16(val16);
-               pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_val16, &(pattrib->pktlen));
+               pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_,
+                                         &le_val16, &pattrib->pktlen);
 
                /*  added challenging text... */
                if ((psta->auth_seq == 2) && (psta->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1))
@@ -844,23 +848,27 @@ static void issue_auth(struct adapter *padapter, struct sta_info *psta,
                if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
                        val32 = (pmlmeinfo->iv++) | (pmlmeinfo->key_index << 30);
                        le_tmp32 = cpu_to_le32(val32);
-                       pframe = rtw_set_fixed_ie(pframe, 4, (unsigned char *)&le_tmp32, &(pattrib->pktlen));
+                       pframe = rtw_set_fixed_ie(pframe, 4, &le_tmp32,
+                                                 &pattrib->pktlen);
 
                        pattrib->iv_len = 4;
                }
 
                le_tmp16 = cpu_to_le16(val16);
-               pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
+               pframe = rtw_set_fixed_ie(pframe, _AUTH_ALGM_NUM_, &le_tmp16,
+                                         &pattrib->pktlen);
 
                /*  setting auth seq number */
                val16 = pmlmeinfo->auth_seq;
                le_tmp16 = cpu_to_le16(val16);
-               pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
+               pframe = rtw_set_fixed_ie(pframe, _AUTH_SEQ_NUM_, &le_tmp16,
+                                         &pattrib->pktlen);
 
 
                /*  setting status code... */
                le_tmp16 = cpu_to_le16(status);
-               pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, (unsigned char *)&le_tmp16, &(pattrib->pktlen));
+               pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, &le_tmp16,
+                                         &pattrib->pktlen);
 
                /*  then checking to see if sending challenging text... */
                if ((pmlmeinfo->auth_seq == 3) && (pmlmeinfo->state & WIFI_FW_AUTH_STATE) && (use_shared_key == 1)) {
@@ -944,13 +952,14 @@ static void issue_asocrsp(struct adapter *padapter, unsigned short status,
        /* capability */
        val = *(unsigned short *)rtw_get_capability_from_ie(ie);
 
-       pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_ , (unsigned char *)&val, &(pattrib->pktlen));
+       pframe = rtw_set_fixed_ie(pframe, _CAPABILITY_, &val, &pattrib->pktlen);
 
        lestatus = cpu_to_le16(status);
-       pframe = rtw_set_fixed_ie(pframe , _STATUS_CODE_ , (unsigned char *)&lestatus, &(pattrib->pktlen));
+       pframe = rtw_set_fixed_ie(pframe, _STATUS_CODE_, &lestatus,
+                                 &pattrib->pktlen);
 
        leval = cpu_to_le16(pstat->aid | BIT(14) | BIT(15));
-       pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_ , (unsigned char *)&leval, &(pattrib->pktlen));
+       pframe = rtw_set_fixed_ie(pframe, _ASOC_ID_, &leval, &pattrib->pktlen);
 
        if (pstat->bssratelen <= 8) {
                pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, pstat->bssratelen, pstat->bssrateset, &(pattrib->pktlen));
@@ -1172,7 +1181,7 @@ static void issue_assocreq(struct adapter *padapter)
        }
 
        /* vendor specific IE, such as WPA, WMM, WPS */
-       for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength;) {
+       for (i = sizeof(struct ndis_802_11_fixed_ie); i < pmlmeinfo->network.IELength; i += (pIE->Length + 2)) {
                pIE = (struct ndis_802_11_var_ie *)(pmlmeinfo->network.IEs + i);
 
                switch (pIE->ElementID) {
@@ -1193,7 +1202,6 @@ static void issue_assocreq(struct adapter *padapter)
                default:
                        break;
                }
-               i += (pIE->Length + 2);
        }
 
        if (pmlmeinfo->assoc_AP_vendor == HT_IOT_PEER_REALTEK)
@@ -1499,7 +1507,8 @@ static int _issue_deauth(struct adapter *padapter, unsigned char *da, unsigned s
        pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
 
        le_tmp = cpu_to_le16(reason);
-       pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_ , (unsigned char *)&le_tmp, &(pattrib->pktlen));
+       pframe = rtw_set_fixed_ie(pframe, _RSON_CODE_, &le_tmp,
+                                 &pattrib->pktlen);
 
        pattrib->last_txcmdsz = pattrib->pktlen;
 
@@ -1687,11 +1696,13 @@ static void issue_action_BA(struct adapter *padapter, unsigned char *raddr,
 
                        BA_para_set = 0x1002 | ((status & 0xf) << 2); /* immediate ack & 64 buffer size */
                        le_tmp = cpu_to_le16(BA_para_set);
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
+                       pframe = rtw_set_fixed_ie(pframe, 2, &(le_tmp),
+                                                 &pattrib->pktlen);
 
                        BA_timeout_value = 5000;/*  5ms */
                        le_tmp = cpu_to_le16(BA_timeout_value);
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
+                       pframe = rtw_set_fixed_ie(pframe, 2, &(le_tmp),
+                                                 &pattrib->pktlen);
 
                        psta = rtw_get_stainfo(pstapriv, raddr);
                        if (psta != NULL) {
@@ -1704,13 +1715,21 @@ static void issue_action_BA(struct adapter *padapter, unsigned char *raddr,
                                BA_starting_seqctrl = start_seq << 4;
                        }
                        le_tmp = cpu_to_le16(BA_starting_seqctrl);
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
+                       pframe = rtw_set_fixed_ie(pframe, 2, &(le_tmp),
+                                                 &pattrib->pktlen);
                        break;
                case 1: /* ADDBA rsp */
-                       pframe = rtw_set_fixed_ie(pframe, 1, &(pmlmeinfo->ADDBA_req.dialog_token), &(pattrib->pktlen));
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&status), &(pattrib->pktlen));
+               {
+                       struct ADDBA_request *ADDBA_req = &pmlmeinfo->ADDBA_req;
 
-                       BA_para_set = le16_to_cpu(pmlmeinfo->ADDBA_req.BA_para_set) & 0x3f;
+                       pframe = rtw_set_fixed_ie(pframe, 1,
+                                                 &ADDBA_req->dialog_token,
+                                                 &pattrib->pktlen);
+                       pframe = rtw_set_fixed_ie(pframe, 2, &status,
+                                                 &pattrib->pktlen);
+
+                       BA_para_set = le16_to_cpu(ADDBA_req->BA_para_set) &
+                                     0x3f;
                        rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor);
                        switch (max_rx_ampdu_factor) {
                        case MAX_AMPDU_FACTOR_64K:
@@ -1736,17 +1755,23 @@ static void issue_action_BA(struct adapter *padapter, unsigned char *raddr,
                                BA_para_set = BA_para_set | BIT(0);
                        le_tmp = cpu_to_le16(BA_para_set);
 
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(pmlmeinfo->ADDBA_req.BA_timeout_value)), &(pattrib->pktlen));
+                       pframe = rtw_set_fixed_ie(pframe, 2, &(le_tmp),
+                                                 &pattrib->pktlen);
+                       pframe = rtw_set_fixed_ie(pframe, 2,
+                                                 &ADDBA_req->BA_timeout_value,
+                                                 &pattrib->pktlen);
                        break;
+               }
                case 2:/* DELBA */
                        BA_para_set = (status & 0x1F) << 3;
                        le_tmp = cpu_to_le16(BA_para_set);
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
+                       pframe = rtw_set_fixed_ie(pframe, 2, &(le_tmp),
+                                                 &pattrib->pktlen);
 
                        reason_code = 37;/* Requested from peer STA as it does not want to use the mechanism */
                        le_tmp = cpu_to_le16(reason_code);
-                       pframe = rtw_set_fixed_ie(pframe, 2, (unsigned char *)(&(le_tmp)), &(pattrib->pktlen));
+                       pframe = rtw_set_fixed_ie(pframe, 2, &(le_tmp),
+                                                 &pattrib->pktlen);
                        break;
                default:
                        break;
@@ -3213,7 +3238,7 @@ static unsigned int OnAssocReq(struct adapter *padapter,
                        pstat->flags |= WLAN_STA_WPS;
                        copy_len = 0;
                } else {
-                       copy_len = ((wpa_ie_len+2) > sizeof(pstat->wpa_ie)) ? (sizeof(pstat->wpa_ie)) : (wpa_ie_len+2);
+                       copy_len = min_t(int, wpa_ie_len + 2, sizeof(pstat->wpa_ie));
                }
                if (copy_len > 0)
                        memcpy(pstat->wpa_ie, wpa_ie-2, copy_len);
@@ -3483,7 +3508,6 @@ static unsigned int OnAssocRsp(struct adapter *padapter,
        pmlmeinfo->state &= (~WIFI_FW_ASSOC_STATE);
        pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
 
-       /* Update Basic Rate Table for spec, 2010-12-28 , by thomas */
        UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
 
 report_assoc_result:
@@ -3902,7 +3926,7 @@ static unsigned int OnAction(struct adapter *padapter,
 
        category = frame_body[0];
 
-       for (i = 0; i < sizeof(OnAction_tbl)/sizeof(struct action_handler); i++) {
+       for (i = 0; i < ARRAY_SIZE(OnAction_tbl); i++) {
                ptable = &OnAction_tbl[i];
                if (category == ptable->num)
                        ptable->func(padapter, precv_frame);
@@ -4177,10 +4201,13 @@ void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
 
        RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
                 ("+mgt_dispatcher: type(0x%x) subtype(0x%x)\n",
-                 GetFrameType(pframe), GetFrameSubType(pframe)));
+                 (unsigned int)GetFrameType(pframe),
+                 (unsigned int)GetFrameSubType(pframe)));
 
        if (GetFrameType(pframe) != WIFI_MGT_TYPE) {
-               RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("mgt_dispatcher: type(0x%x) error!\n", GetFrameType(pframe)));
+               RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
+                        ("mgt_dispatcher: type(0x%x) error!\n",
+                         (unsigned int)GetFrameType(pframe)));
                return;
        }
 
@@ -5384,9 +5411,8 @@ u8 set_stakey_hdl(struct adapter *padapter, u8 *pbuf)
 
                        cam_id = psta->mac_id + 3;/* 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
 
-                       DBG_88E("Write CAM, mac_addr =%x:%x:%x:%x:%x:%x, cam_entry=%d\n", pparm->addr[0],
-                               pparm->addr[1], pparm->addr[2], pparm->addr[3], pparm->addr[4],
-                               pparm->addr[5], cam_id);
+                       DBG_88E("Write CAM, mac_addr =%pM, cam_entry=%d\n",
+                               pparm->addr, cam_id);
 
                        write_cam(padapter, cam_id, ctrl, pparm->addr, pparm->key);
 
index 44eeb03213e6fec788e4108d7b01fcd6befe4a74..110b8c0b6cd7b734de3abfb0cdd35b40912521ec 100644 (file)
@@ -25,6 +25,7 @@
 #include <drv_types.h>
 #include <recv_osdep.h>
 #include <mlme_osdep.h>
+#include <mon.h>
 #include <wifi.h>
 #include <linux/vmalloc.h>
 
@@ -1276,7 +1277,7 @@ static int validate_recv_frame(struct adapter *adapter,
                int i;
                DBG_88E("#############################\n");
 
-               for (i = 0; i < 64; i = i+8)
+               for (i = 0; i < 64; i += 8)
                        DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
                                *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
                DBG_88E("#############################\n");
@@ -1285,7 +1286,7 @@ static int validate_recv_frame(struct adapter *adapter,
                        int i;
                        DBG_88E("#############################\n");
 
-                       for (i = 0; i < 64; i = i+8)
+                       for (i = 0; i < 64; i += 8)
                                DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
                                        *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
                        DBG_88E("#############################\n");
@@ -1295,7 +1296,7 @@ static int validate_recv_frame(struct adapter *adapter,
                        int i;
                        DBG_88E("#############################\n");
 
-                       for (i = 0; i < 64; i = i+8)
+                       for (i = 0; i < 64; i += 8)
                                DBG_88E("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X:\n", *(ptr+i),
                                        *(ptr+i+1), *(ptr+i+2), *(ptr+i+3), *(ptr+i+4), *(ptr+i+5), *(ptr+i+6), *(ptr+i+7));
                        DBG_88E("#############################\n");
@@ -1329,6 +1330,19 @@ static int validate_recv_frame(struct adapter *adapter,
                break;
        }
 
+       /*
+        * This is the last moment before management and control frames get
+        * discarded. So we need to forward them to the monitor now or never.
+        *
+        * At the same time data frames can still be encrypted if software
+        * decryption is in use. However, decryption can occur not until later
+        * (see recv_func()).
+        *
+        * Hence forward the frame to the monitor anyway to preserve the order
+        * in which frames were received.
+        */
+       rtl88eu_mon_recv_hook(adapter->pmondev, precv_frame);
+
 exit:
 
        return retval;
index 1170dd001c1fefdad93ec400cce4f11086a84759..6983c572b358e356f856ffeed3c05bf8cc54da05 100644 (file)
@@ -52,7 +52,7 @@ static struct ch_freq ch_freq_map[] = {
        {216, 5080},/* Japan, means J16 */
 };
 
-static int ch_freq_map_num = (sizeof(ch_freq_map) / sizeof(struct ch_freq));
+static int ch_freq_map_num = ARRAY_SIZE(ch_freq_map);
 
 u32 rtw_ch2freq(u32 channel)
 {
index b340e4a9d540c586a8b98bd9a1fe352a379cad05..1beeac46bfe7215f0bfe4ef0285813a99f042cc3 100644 (file)
@@ -159,7 +159,8 @@ u32 _rtw_free_sta_priv(struct       sta_priv *pstapriv)
 
                        while (phead != plist) {
                                int i;
-                               psta = container_of(plist, struct sta_info , hash_list);
+                               psta = container_of(plist, struct sta_info,
+                                                   hash_list);
                                plist = plist->next;
 
                                for (i = 0; i < 16; i++) {
@@ -273,7 +274,7 @@ u32 rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
        struct  sta_priv *pstapriv = &padapter->stapriv;
 
 
-       if (psta == NULL)
+       if (!psta)
                goto exit;
 
        pfree_sta_queue = &pstapriv->free_sta_queue;
@@ -304,7 +305,11 @@ u32        rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
        spin_unlock_bh(&pxmitpriv->lock);
 
        list_del_init(&psta->hash_list);
-       RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("\n free number_%d stainfo  with hwaddr=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", pstapriv->asoc_sta_count , psta->hwaddr[0], psta->hwaddr[1], psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4], psta->hwaddr[5]));
+       RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_,
+                ("\n free number_%d stainfo with hwaddr=0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n",
+                pstapriv->asoc_sta_count, psta->hwaddr[0], psta->hwaddr[1],
+                psta->hwaddr[2], psta->hwaddr[3], psta->hwaddr[4],
+                psta->hwaddr[5]));
        pstapriv->asoc_sta_count--;
 
        /*  re-init sta_info; 20061114 */
@@ -433,7 +438,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
        u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
 
-       if (hwaddr == NULL)
+       if (!hwaddr)
                return NULL;
 
        if (IS_MCAST(hwaddr))
@@ -473,7 +478,7 @@ u32 rtw_init_bcmc_stainfo(struct adapter *padapter)
 
        psta = rtw_alloc_stainfo(pstapriv, bcast_addr);
 
-       if (psta == NULL) {
+       if (!psta) {
                res = _FAIL;
                RT_TRACE(_module_rtl871x_sta_mgt_c_, _drv_err_, ("rtw_alloc_stainfo fail"));
                goto exit;
index 077b39a41c60a0d0cc32479a7ca51fcfdcc682ca..59b443255a90992e67e71a5888bbe142e68c26d6 100644 (file)
@@ -1227,7 +1227,7 @@ unsigned int update_basic_rate(unsigned char *ptn, unsigned int ptn_sz)
        unsigned int i, num_of_rate;
        unsigned int mask = 0;
 
-       num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
+       num_of_rate = min_t(unsigned int, ptn_sz, NumRates);
 
        for (i = 0; i < num_of_rate; i++) {
                if ((*(ptn + i)) & 0x80)
@@ -1241,7 +1241,7 @@ unsigned int update_supported_rate(unsigned char *ptn, unsigned int ptn_sz)
        unsigned int i, num_of_rate;
        unsigned int mask = 0;
 
-       num_of_rate = (ptn_sz > NumRates) ? NumRates : ptn_sz;
+       num_of_rate = min_t(unsigned int, ptn_sz, NumRates);
 
        for (i = 0; i < num_of_rate; i++)
                mask |= 0x1 << wifirate2_ratetbl_inx(*(ptn + i));
@@ -1414,13 +1414,15 @@ void update_IOT_info(struct adapter *padapter)
                pmlmeinfo->turboMode_cts2self = 0;
                pmlmeinfo->turboMode_rtsen = 1;
                /* disable high power */
-               Switch_DM_Func(padapter, (~DYNAMIC_BB_DYNAMIC_TXPWR), false);
+               Switch_DM_Func(padapter, (u32)(~DYNAMIC_BB_DYNAMIC_TXPWR),
+                              false);
                break;
        case HT_IOT_PEER_REALTEK:
                /* rtw_write16(padapter, 0x4cc, 0xffff); */
                /* rtw_write16(padapter, 0x546, 0x01c0); */
                /* disable high power */
-               Switch_DM_Func(padapter, (~DYNAMIC_BB_DYNAMIC_TXPWR), false);
+               Switch_DM_Func(padapter, (u32)(~DYNAMIC_BB_DYNAMIC_TXPWR),
+                              false);
                break;
        default:
                pmlmeinfo->turboMode_cts2self = 0;
index 5dc0b90e8ab56f8c6667756f6921d1f509ea5ad0..cabb810369bdf99eae027f8a430d33aaea8a2d46 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <osdep_service.h>
 #include <drv_types.h>
+#include <mon.h>
 #include <wifi.h>
 #include <osdep_intf.h>
 #include <linux/vmalloc.h>
@@ -1100,6 +1101,9 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
                memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
        }
 
+       /* Frame is about to be encrypted. Forward it to the monitor first. */
+       rtl88eu_mon_xmit_hook(padapter->pmondev, pxmitframe, frg_len);
+
        if (xmitframe_addmic(padapter, pxmitframe) == _FAIL) {
                RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n"));
                DBG_88E("xmitframe_addmic(padapter, pxmitframe) == _FAIL\n");
index 2633a13b4e5857b6e2a0cd8f356fe8c1235f5a16..a108e80323271d52925b81966154b3953b6b2941 100644 (file)
@@ -127,7 +127,7 @@ static int odm_RateDown_8188E(struct odm_dm_struct *dm_odm,
 
        ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE,
                        ODM_DBG_TRACE, ("=====>odm_RateDown_8188E()\n"));
-       if (NULL == pRaInfo) {
+       if (!pRaInfo) {
                ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_LOUD,
                                ("odm_RateDown_8188E(): pRaInfo is NULL\n"));
                return -1;
@@ -193,7 +193,7 @@ static int odm_RateUp_8188E(
 
        ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE,
                        ODM_DBG_TRACE, ("=====>odm_RateUp_8188E()\n"));
-       if (NULL == pRaInfo) {
+       if (!pRaInfo) {
                ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_LOUD,
                                ("odm_RateUp_8188E(): pRaInfo is NULL\n"));
                return -1;
@@ -624,7 +624,7 @@ int ODM_RAInfo_Init_all(struct odm_dm_struct *dm_odm)
 
 u8 ODM_RA_GetShortGI_8188E(struct odm_dm_struct *dm_odm, u8 macid)
 {
-       if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
+       if ((!dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
                return 0;
        ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_TRACE,
                     ("macid =%d SGI =%d\n", macid, dm_odm->RAInfo[macid].RateSGI));
@@ -635,7 +635,7 @@ u8 ODM_RA_GetDecisionRate_8188E(struct odm_dm_struct *dm_odm, u8 macid)
 {
        u8 DecisionRate = 0;
 
-       if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
+       if ((!dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
                return 0;
        DecisionRate = dm_odm->RAInfo[macid].DecisionRate;
        ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_TRACE,
@@ -647,7 +647,7 @@ u8 ODM_RA_GetHwPwrStatus_8188E(struct odm_dm_struct *dm_odm, u8 macid)
 {
        u8 PTStage = 5;
 
-       if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
+       if ((!dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
                return 0;
        PTStage = dm_odm->RAInfo[macid].PTStage;
        ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_TRACE,
@@ -659,7 +659,7 @@ void ODM_RA_UpdateRateInfo_8188E(struct odm_dm_struct *dm_odm, u8 macid, u8 Rate
 {
        struct odm_ra_info *pRaInfo = NULL;
 
-       if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
+       if ((!dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
                return;
        ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_LOUD,
                     ("macid =%d RateID = 0x%x RateMask = 0x%x SGIEnable =%d\n",
@@ -676,7 +676,7 @@ void ODM_RA_SetRSSI_8188E(struct odm_dm_struct *dm_odm, u8 macid, u8 Rssi)
 {
        struct odm_ra_info *pRaInfo = NULL;
 
-       if ((NULL == dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
+       if ((!dm_odm) || (macid >= ASSOCIATE_ENTRY_NUM))
                return;
        ODM_RT_TRACE(dm_odm, ODM_COMP_RATE_ADAPTIVE, ODM_DBG_TRACE,
                     (" macid =%d Rssi =%d\n", macid, Rssi));
index 9c7e626aa703e62bb3f9626a2a61ea42fdfd3135..f58a8222c899a8f67b33c87df3b3389f18ca622b 100644 (file)
 
 #include <phy.h>
 
-#define read_next_pair(array, v1, v2, i)               \
-        do {                                           \
-               i += 2;                                 \
-               v1 = array[i];                          \
-               v2 = array[i+1];                        \
-        } while (0)
-
-
 /* AGC_TAB_1T.TXT */
 
 static u32 array_agc_tab_1t_8188e[] = {
@@ -166,12 +158,12 @@ static u32 array_agc_tab_1t_8188e[] = {
 static bool set_baseband_agc_config(struct adapter *adapt)
 {
        u32 i;
-       u32 arraylen = sizeof(array_agc_tab_1t_8188e)/sizeof(u32);
+       const u32 arraylen = ARRAY_SIZE(array_agc_tab_1t_8188e);
        u32 *array = array_agc_tab_1t_8188e;
 
        for (i = 0; i < arraylen; i += 2) {
                u32 v1 = array[i];
-               u32 v2 = array[i+1];
+               u32 v2 = array[i + 1];
 
                if (v1 < 0xCDCDCDCD) {
                        phy_set_bb_reg(adapt, v1, bMaskDWord, v2);
@@ -401,12 +393,12 @@ static void rtl_bb_delay(struct adapter *adapt, u32 addr, u32 data)
 static bool set_baseband_phy_config(struct adapter *adapt)
 {
        u32 i;
-       u32 arraylen = sizeof(array_phy_reg_1t_8188e)/sizeof(u32);
+       const u32 arraylen = ARRAY_SIZE(array_phy_reg_1t_8188e);
        u32 *array = array_phy_reg_1t_8188e;
 
        for (i = 0; i < arraylen; i += 2) {
                u32 v1 = array[i];
-               u32 v2 = array[i+1];
+               u32 v2 = array[i + 1];
 
                if (v1 < 0xCDCDCDCD)
                        rtl_bb_delay(adapt, v1, v2);
@@ -508,53 +500,55 @@ static u32 array_phy_reg_pg_8188e[] = {
 
 };
 
-static void store_pwrindex_offset(struct adapter *Adapter, u32 regaddr, u32 bitmask, u32 data)
+static void store_pwrindex_offset(struct adapter *adapter,
+                                 u32 regaddr, u32 bitmask, u32 data)
 {
-       struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
-        u8 pwrGrpCnt = hal_data->pwrGroupCnt;
+       struct hal_data_8188e *hal_data = GET_HAL_DATA(adapter);
+       u32 * const power_level_offset =
+               hal_data->MCSTxPowerLevelOriginalOffset[hal_data->pwrGroupCnt];
 
        if (regaddr == rTxAGC_A_Rate18_06)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][0] = data;
+               power_level_offset[0] = data;
        if (regaddr == rTxAGC_A_Rate54_24)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][1] = data;
+               power_level_offset[1] = data;
        if (regaddr == rTxAGC_A_CCK1_Mcs32)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][6] = data;
+               power_level_offset[6] = data;
        if (regaddr == rTxAGC_B_CCK11_A_CCK2_11 && bitmask == 0xffffff00)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][7] = data;
+               power_level_offset[7] = data;
        if (regaddr == rTxAGC_A_Mcs03_Mcs00)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][2] = data;
+               power_level_offset[2] = data;
        if (regaddr == rTxAGC_A_Mcs07_Mcs04)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][3] = data;
+               power_level_offset[3] = data;
        if (regaddr == rTxAGC_A_Mcs11_Mcs08)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][4] = data;
+               power_level_offset[4] = data;
        if (regaddr == rTxAGC_A_Mcs15_Mcs12) {
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][5] = data;
+               power_level_offset[5] = data;
                if (hal_data->rf_type == RF_1T1R)
                        hal_data->pwrGroupCnt++;
        }
        if (regaddr == rTxAGC_B_Rate18_06)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][8] = data;
+               power_level_offset[8] = data;
        if (regaddr == rTxAGC_B_Rate54_24)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][9] = data;
+               power_level_offset[9] = data;
        if (regaddr == rTxAGC_B_CCK1_55_Mcs32)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][14] = data;
+               power_level_offset[14] = data;
        if (regaddr == rTxAGC_B_CCK11_A_CCK2_11 && bitmask == 0x000000ff)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][15] = data;
+               power_level_offset[15] = data;
        if (regaddr == rTxAGC_B_Mcs03_Mcs00)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][10] = data;
+               power_level_offset[10] = data;
        if (regaddr == rTxAGC_B_Mcs07_Mcs04)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][11] = data;
+               power_level_offset[11] = data;
        if (regaddr == rTxAGC_B_Mcs11_Mcs08)
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][12] = data;
+               power_level_offset[12] = data;
        if (regaddr == rTxAGC_B_Mcs15_Mcs12) {
-               hal_data->MCSTxPowerLevelOriginalOffset[pwrGrpCnt][13] = data;
+               power_level_offset[13] = data;
                if (hal_data->rf_type != RF_1T1R)
                        hal_data->pwrGroupCnt++;
        }
 }
 
 static void rtl_addr_delay(struct adapter *adapt,
-                       u32 addr, u32 bit_mask, u32 data)
+                          u32 addr, u32 bit_mask, u32 data)
 {
        switch (addr) {
        case 0xfe:
@@ -582,14 +576,14 @@ static void rtl_addr_delay(struct adapter *adapt,
 
 static bool config_bb_with_pgheader(struct adapter *adapt)
 {
-       u32 i = 0;
-       u32 arraylen = sizeof(array_phy_reg_pg_8188e) / sizeof(u32);
+       u32 i;
+       const u32 arraylen = ARRAY_SIZE(array_phy_reg_pg_8188e);
        u32 *array = array_phy_reg_pg_8188e;
 
        for (i = 0; i < arraylen; i += 3) {
                u32 v1 = array[i];
-               u32 v2 = array[i+1];
-               u32 v3 = array[i+2];
+               u32 v2 = array[i + 1];
+               u32 v3 = array[i + 2];
 
                if (v1 < 0xCDCDCDCD)
                        rtl_addr_delay(adapt, v1, v2, v3);
@@ -597,15 +591,15 @@ static bool config_bb_with_pgheader(struct adapter *adapt)
        return true;
 }
 
-static void rtl88e_phy_init_bb_rf_register_definition(struct adapter *Adapter)
+static void rtl88e_phy_init_bb_rf_register_definition(struct adapter *adapter)
 {
-       struct hal_data_8188e           *hal_data = GET_HAL_DATA(Adapter);
+       struct hal_data_8188e           *hal_data = GET_HAL_DATA(adapter);
        struct bb_reg_def               *reg[4];
 
-       reg[RF_PATH_A] = &(hal_data->PHYRegDef[RF_PATH_A]);
-       reg[RF_PATH_B] = &(hal_data->PHYRegDef[RF_PATH_B]);
-       reg[RF_PATH_C] = &(hal_data->PHYRegDef[RF_PATH_C]);
-       reg[RF_PATH_D] = &(hal_data->PHYRegDef[RF_PATH_D]);
+       reg[RF_PATH_A] = &hal_data->PHYRegDef[RF_PATH_A];
+       reg[RF_PATH_B] = &hal_data->PHYRegDef[RF_PATH_B];
+       reg[RF_PATH_C] = &hal_data->PHYRegDef[RF_PATH_C];
+       reg[RF_PATH_D] = &hal_data->PHYRegDef[RF_PATH_D];
 
        reg[RF_PATH_A]->rfintfs = rFPGA0_XAB_RFInterfaceSW;
        reg[RF_PATH_B]->rfintfs = rFPGA0_XAB_RFInterfaceSW;
@@ -688,13 +682,13 @@ static void rtl88e_phy_init_bb_rf_register_definition(struct adapter *Adapter)
 
 static bool config_parafile(struct adapter *adapt)
 {
-       struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(adapt);
+       struct eeprom_priv *eeprom = GET_EEPROM_EFUSE_PRIV(adapt);
        struct hal_data_8188e *hal_data = GET_HAL_DATA(adapt);
 
        set_baseband_phy_config(adapt);
 
        /* If EEPROM or EFUSE autoload OK, We must config by PHY_REG_PG.txt */
-       if (!pEEPROM->bautoload_fail_flag) {
+       if (!eeprom->bautoload_fail_flag) {
                hal_data->pwrGroupCnt = 0;
                config_bb_with_pgheader(adapt);
        }
@@ -713,18 +707,21 @@ bool rtl88eu_phy_bb_config(struct adapter *adapt)
 
        /*  Enable BB and RF */
        regval = usb_read16(adapt, REG_SYS_FUNC_EN);
-       usb_write16(adapt, REG_SYS_FUNC_EN, (u16)(regval|BIT13|BIT0|BIT1));
+       usb_write16(adapt, REG_SYS_FUNC_EN,
+                   (u16)(regval | BIT(13) | BIT(0) | BIT(1)));
 
-       usb_write8(adapt, REG_RF_CTRL, RF_EN|RF_RSTB|RF_SDMRSTB);
+       usb_write8(adapt, REG_RF_CTRL, RF_EN | RF_RSTB | RF_SDMRSTB);
 
-       usb_write8(adapt, REG_SYS_FUNC_EN, FEN_USBA | FEN_USBD | FEN_BB_GLB_RSTn | FEN_BBRSTB);
+       usb_write8(adapt, REG_SYS_FUNC_EN, FEN_USBA |
+                  FEN_USBD | FEN_BB_GLB_RSTn | FEN_BBRSTB);
 
        /*  Config BB and AGC */
        rtstatus = config_parafile(adapt);
 
        /*  write 0x24[16:11] = 0x24[22:17] = crystal_cap */
        crystal_cap = hal_data->CrystalCap & 0x3F;
-       phy_set_bb_reg(adapt, REG_AFE_XTAL_CTRL, 0x7ff800, (crystal_cap | (crystal_cap << 6)));
+       phy_set_bb_reg(adapt, REG_AFE_XTAL_CTRL, 0x7ff800,
+                      (crystal_cap | (crystal_cap << 6)));
 
        return rtstatus;
 }
index a71c54295508b05e245b5de1a7dce1105ba0be69..23aa6d37acac72e7f7b98b57e5d849444cd518b3 100644 (file)
@@ -190,7 +190,6 @@ int rtl88eu_download_fw(struct adapter *adapt)
        struct rtl92c_firmware_header *pfwheader = NULL;
        u8 *pfwdata;
        u32 fwsize;
-       int err;
 
        if (request_firmware(&fw, fw_name, device)) {
                dev_err(device, "Firmware %s not available\n", fw_name);
@@ -229,7 +228,5 @@ int rtl88eu_download_fw(struct adapter *adapt)
        _rtl88e_write_fw(adapt, pfwdata, fwsize);
        _rtl88e_enable_fw_download(adapt, false);
 
-       err = _rtl88e_fw_free_to_go(adapt);
-
-       return err;
+       return _rtl88e_fw_free_to_go(adapt);
 }
index febc83a5adb874318b89383abce87b8681752828..0bc1b215219af17152398886bb51a231189174db 100644 (file)
@@ -123,10 +123,10 @@ bool rtl88eu_phy_mac_config(struct adapter *adapt)
        u32 arraylength;
        u32 *ptrarray;
 
-       arraylength = sizeof(array_MAC_REG_8188E)/sizeof(u32);
+       arraylength = ARRAY_SIZE(array_MAC_REG_8188E);
        ptrarray = array_MAC_REG_8188E;
 
-       for (i = 0; i < arraylength; i = i + 2)
+       for (i = 0; i < arraylength; i += 2)
                usb_write8(adapt, ptrarray[i], (u8)ptrarray[i + 1]);
 
        usb_write8(adapt, REG_MAX_AGGR_NUM, MAX_AGGR_NUM);
index 710fdc3449f835b9ee174778c14b309d2e15ef16..2c25d3b020364e946c78519714fc7273cad1ec57 100644 (file)
@@ -437,7 +437,7 @@ void odm_CommonInfoSelfInit(struct odm_dm_struct *pDM_Odm)
 {
        struct adapter *adapter = pDM_Odm->Adapter;
 
-       pDM_Odm->bCckHighPower = (bool)phy_query_bb_reg(adapter, 0x824, BIT9);
+       pDM_Odm->bCckHighPower = (bool)phy_query_bb_reg(adapter, 0x824, BIT(9));
        pDM_Odm->RFPathRxEnable = (u8)phy_query_bb_reg(adapter, 0xc04, 0x0F);
 
        ODM_InitDebugSetting(pDM_Odm);
@@ -736,8 +736,8 @@ void odm_FalseAlarmCounterStatistics(struct odm_dm_struct *pDM_Odm)
                return;
 
        /* hold ofdm counter */
-       phy_set_bb_reg(adapter, ODM_REG_OFDM_FA_HOLDC_11N, BIT31, 1); /* hold page C counter */
-       phy_set_bb_reg(adapter, ODM_REG_OFDM_FA_RSTD_11N, BIT31, 1); /* hold page D counter */
+       phy_set_bb_reg(adapter, ODM_REG_OFDM_FA_HOLDC_11N, BIT(31), 1); /* hold page C counter */
+       phy_set_bb_reg(adapter, ODM_REG_OFDM_FA_RSTD_11N, BIT(31), 1); /* hold page D counter */
 
        ret_value = phy_query_bb_reg(adapter, ODM_REG_OFDM_FA_TYPE1_11N, bMaskDWord);
        FalseAlmCnt->Cnt_Fast_Fsync = (ret_value&0xffff);
@@ -760,8 +760,8 @@ void odm_FalseAlarmCounterStatistics(struct odm_dm_struct *pDM_Odm)
        FalseAlmCnt->Cnt_BW_USC = (ret_value & 0xffff0000)>>16;
 
        /* hold cck counter */
-       phy_set_bb_reg(adapter, ODM_REG_CCK_FA_RST_11N, BIT12, 1);
-       phy_set_bb_reg(adapter, ODM_REG_CCK_FA_RST_11N, BIT14, 1);
+       phy_set_bb_reg(adapter, ODM_REG_CCK_FA_RST_11N, BIT(12), 1);
+       phy_set_bb_reg(adapter, ODM_REG_CCK_FA_RST_11N, BIT(14), 1);
 
        ret_value = phy_query_bb_reg(adapter, ODM_REG_CCK_FA_LSB_11N, bMaskByte0);
        FalseAlmCnt->Cnt_Cck_fail = ret_value;
@@ -853,7 +853,7 @@ void ODM_RF_Saving(struct odm_dm_struct *pDM_Odm, u8 bForceInNormal)
        }
        if (pDM_PSTable->initialize == 0) {
                pDM_PSTable->Reg874 = (phy_query_bb_reg(adapter, 0x874, bMaskDWord)&0x1CC000)>>14;
-               pDM_PSTable->RegC70 = (phy_query_bb_reg(adapter, 0xc70, bMaskDWord)&BIT3)>>3;
+               pDM_PSTable->RegC70 = (phy_query_bb_reg(adapter, 0xc70, bMaskDWord) & BIT(3))>>3;
                pDM_PSTable->Reg85C = (phy_query_bb_reg(adapter, 0x85c, bMaskDWord)&0xFF000000)>>24;
                pDM_PSTable->RegA74 = (phy_query_bb_reg(adapter, 0xa74, bMaskDWord)&0xF000)>>12;
                pDM_PSTable->initialize = 1;
@@ -881,19 +881,19 @@ void ODM_RF_Saving(struct odm_dm_struct *pDM_Odm, u8 bForceInNormal)
 
        if (pDM_PSTable->PreRFState != pDM_PSTable->CurRFState) {
                if (pDM_PSTable->CurRFState == RF_Save) {
-                       phy_set_bb_reg(adapter, 0x874  , 0x1C0000, 0x2); /* Reg874[20:18]=3'b010 */
-                       phy_set_bb_reg(adapter, 0xc70, BIT3, 0); /* RegC70[3]=1'b0 */
+                       phy_set_bb_reg(adapter, 0x874, 0x1C0000, 0x2); /* Reg874[20:18]=3'b010 */
+                       phy_set_bb_reg(adapter, 0xc70, BIT(3), 0); /* RegC70[3]=1'b0 */
                        phy_set_bb_reg(adapter, 0x85c, 0xFF000000, 0x63); /* Reg85C[31:24]=0x63 */
                        phy_set_bb_reg(adapter, 0x874, 0xC000, 0x2); /* Reg874[15:14]=2'b10 */
                        phy_set_bb_reg(adapter, 0xa74, 0xF000, 0x3); /* RegA75[7:4]=0x3 */
-                       phy_set_bb_reg(adapter, 0x818, BIT28, 0x0); /* Reg818[28]=1'b0 */
-                       phy_set_bb_reg(adapter, 0x818, BIT28, 0x1); /* Reg818[28]=1'b1 */
+                       phy_set_bb_reg(adapter, 0x818, BIT(28), 0x0); /* Reg818[28]=1'b0 */
+                       phy_set_bb_reg(adapter, 0x818, BIT(28), 0x1); /* Reg818[28]=1'b1 */
                } else {
-                       phy_set_bb_reg(adapter, 0x874  , 0x1CC000, pDM_PSTable->Reg874);
-                       phy_set_bb_reg(adapter, 0xc70, BIT3, pDM_PSTable->RegC70);
+                       phy_set_bb_reg(adapter, 0x874, 0x1CC000, pDM_PSTable->Reg874);
+                       phy_set_bb_reg(adapter, 0xc70, BIT(3), pDM_PSTable->RegC70);
                        phy_set_bb_reg(adapter, 0x85c, 0xFF000000, pDM_PSTable->Reg85C);
                        phy_set_bb_reg(adapter, 0xa74, 0xF000, pDM_PSTable->RegA74);
-                       phy_set_bb_reg(adapter, 0x818, BIT28, 0x0);
+                       phy_set_bb_reg(adapter, 0x818, BIT(28), 0x0);
                }
                pDM_PSTable->PreRFState = pDM_PSTable->CurRFState;
        }
@@ -1043,7 +1043,7 @@ void odm_RefreshRateAdaptiveMaskCE(struct odm_dm_struct *pDM_Odm)
        for (i = 0; i < ODM_ASSOCIATE_ENTRY_NUM; i++) {
                struct sta_info *pstat = pDM_Odm->pODM_StaInfo[i];
                if (IS_STA_VALID(pstat)) {
-                       if (ODM_RAStateCheck(pDM_Odm, pstat->rssi_stat.UndecoratedSmoothedPWDB, false , &pstat->rssi_level)) {
+                       if (ODM_RAStateCheck(pDM_Odm, pstat->rssi_stat.UndecoratedSmoothedPWDB, false, &pstat->rssi_level)) {
                                ODM_RT_TRACE(pDM_Odm, ODM_COMP_RA_MASK, ODM_DBG_LOUD,
                                             ("RSSI:%d, RSSI_LEVEL:%d\n",
                                             pstat->rssi_stat.UndecoratedSmoothedPWDB, pstat->rssi_level));
@@ -1188,7 +1188,8 @@ void odm_RSSIMonitorCheckCE(struct odm_dm_struct *pDM_Odm)
                pdmpriv->EntryMinUndecoratedSmoothedPWDB = 0;
 
        FindMinimumRSSI(Adapter);
-       ODM_CmnInfoUpdate(&pHalData->odmpriv , ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM);
+       ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_RSSI_MIN,
+                         pdmpriv->MinUndecoratedPWDBForDM);
 }
 
 /* 3============================================================ */
@@ -1228,7 +1229,7 @@ void odm_TXPowerTrackingCheckCE(struct odm_dm_struct *pDM_Odm)
                return;
 
        if (!pDM_Odm->RFCalibrateInfo.TM_Trigger) {             /* at least delay 1 sec */
-               phy_set_rf_reg(Adapter, RF_PATH_A, RF_T_METER_88E, BIT17 | BIT16, 0x03);
+               phy_set_rf_reg(Adapter, RF_PATH_A, RF_T_METER_88E, BIT(17) | BIT(16), 0x03);
 
                pDM_Odm->RFCalibrateInfo.TM_Trigger = 1;
                return;
index 36afe45d1c9a6dc11102cbbb3ee13cf1df4572c6..28b9f7f591c015c635b8c3fed527c0d48215a46a 100644 (file)
@@ -362,7 +362,7 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm,
                                }
                        }
 
-                       pEntry->rssi_stat.PacketMap = (pEntry->rssi_stat.PacketMap<<1) | BIT0;
+                       pEntry->rssi_stat.PacketMap = (pEntry->rssi_stat.PacketMap<<1) | BIT(0);
 
                } else {
                        RSSI_Ave = pPhyInfo->RxPWDBAll;
@@ -391,10 +391,10 @@ static void odm_Process_RSSIForDM(struct odm_dm_struct *dm_odm,
                        pEntry->rssi_stat.ValidBit++;
 
                for (i = 0; i < pEntry->rssi_stat.ValidBit; i++)
-                       OFDM_pkt += (u8)(pEntry->rssi_stat.PacketMap>>i)&BIT0;
+                       OFDM_pkt += (u8)(pEntry->rssi_stat.PacketMap>>i) & BIT(0);
 
                if (pEntry->rssi_stat.ValidBit == 64) {
-                       Weighting = ((OFDM_pkt<<4) > 64) ? 64 : (OFDM_pkt<<4);
+                       Weighting = min_t(u32, OFDM_pkt << 4, 64);
                        UndecoratedSmoothedPWDB = (Weighting*UndecoratedSmoothedOFDM+(64-Weighting)*UndecoratedSmoothedCCK)>>6;
                } else {
                        if (pEntry->rssi_stat.ValidBit != 0)
index d3c6873925bab8afe7cd6130556b2293cd7b890a..c0242a095c1910c04908bc4700bf885bfd1ae7fa 100644 (file)
@@ -28,26 +28,26 @@ static void dm_rx_hw_antena_div_init(struct odm_dm_struct *dm_odm)
 
        if (*(dm_odm->mp_mode) == 1) {
                dm_odm->AntDivType = CGCS_RX_SW_ANTDIV;
-               phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT7, 0);
-               phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT31, 1);
+               phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 0);
+               phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT(31), 1);
                return;
        }
 
        /* MAC Setting */
        value32 = phy_query_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord);
        phy_set_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord,
-                      value32|(BIT23|BIT25));
+                      value32|(BIT(23) | BIT(25)));
        /* Pin Settings */
-       phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT9|BIT8, 0);
-       phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT10, 0);
-       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT22, 1);
-       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT31, 1);
+       phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT(9) | BIT(8), 0);
+       phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT(10), 0);
+       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT(22), 1);
+       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT(31), 1);
        /* OFDM Settings */
        phy_set_bb_reg(adapter, ODM_REG_ANTDIV_PARA1_11N, bMaskDWord,
                       0x000000a0);
        /* CCK Settings */
-       phy_set_bb_reg(adapter, ODM_REG_BB_PWR_SAV4_11N, BIT7, 1);
-       phy_set_bb_reg(adapter, ODM_REG_CCK_ANTDIV_PARA2_11N, BIT4, 1);
+       phy_set_bb_reg(adapter, ODM_REG_BB_PWR_SAV4_11N, BIT(7), 1);
+       phy_set_bb_reg(adapter, ODM_REG_CCK_ANTDIV_PARA2_11N, BIT(4), 1);
        rtl88eu_dm_update_rx_idle_ant(dm_odm, MAIN_ANT);
        phy_set_bb_reg(adapter, ODM_REG_ANT_MAPPING1_11N, 0xFFFF, 0x0201);
 }
@@ -59,37 +59,37 @@ static void dm_trx_hw_antenna_div_init(struct odm_dm_struct *dm_odm)
 
        if (*(dm_odm->mp_mode) == 1) {
                dm_odm->AntDivType = CGCS_RX_SW_ANTDIV;
-               phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT7, 0);
+               phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 0);
                phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N,
-                              BIT5|BIT4|BIT3, 0);
+                              BIT(5) | BIT(4) | BIT(3), 0);
                return;
        }
 
        /* MAC Setting */
        value32 = phy_query_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord);
        phy_set_bb_reg(adapter, ODM_REG_ANTSEL_PIN_11N, bMaskDWord,
-                      value32|(BIT23|BIT25));
+                      value32|(BIT(23) | BIT(25)));
        /* Pin Settings */
-       phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT9|BIT8, 0);
-       phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT10, 0);
-       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT22, 0);
-       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT31, 1);
+       phy_set_bb_reg(adapter, ODM_REG_PIN_CTRL_11N, BIT(9) | BIT(8), 0);
+       phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N, BIT(10), 0);
+       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT(22), 0);
+       phy_set_bb_reg(adapter, ODM_REG_LNA_SWITCH_11N, BIT(31), 1);
        /* OFDM Settings */
        phy_set_bb_reg(adapter, ODM_REG_ANTDIV_PARA1_11N, bMaskDWord,
                       0x000000a0);
        /* CCK Settings */
-       phy_set_bb_reg(adapter, ODM_REG_BB_PWR_SAV4_11N, BIT7, 1);
-       phy_set_bb_reg(adapter, ODM_REG_CCK_ANTDIV_PARA2_11N, BIT4, 1);
+       phy_set_bb_reg(adapter, ODM_REG_BB_PWR_SAV4_11N, BIT(7), 1);
+       phy_set_bb_reg(adapter, ODM_REG_CCK_ANTDIV_PARA2_11N, BIT(4), 1);
        /* Tx Settings */
-       phy_set_bb_reg(adapter, ODM_REG_TX_ANT_CTRL_11N, BIT21, 0);
+       phy_set_bb_reg(adapter, ODM_REG_TX_ANT_CTRL_11N, BIT(21), 0);
        rtl88eu_dm_update_rx_idle_ant(dm_odm, MAIN_ANT);
 
        /* antenna mapping table */
        if (!dm_odm->bIsMPChip) { /* testchip */
                phy_set_bb_reg(adapter, ODM_REG_RX_DEFUALT_A_11N,
-                              BIT10|BIT9|BIT8, 1);
+                              BIT(10) | BIT(9) | BIT(8), 1);
                phy_set_bb_reg(adapter, ODM_REG_RX_DEFUALT_A_11N,
-                              BIT13|BIT12|BIT11, 2);
+                              BIT(13) | BIT(12) | BIT(11), 2);
        } else { /* MPchip */
                phy_set_bb_reg(adapter, ODM_REG_ANT_MAPPING1_11N, bMaskDWord,
                               0x0201);
@@ -118,40 +118,40 @@ static void dm_fast_training_init(struct odm_dm_struct *dm_odm)
 
        /* MAC Setting */
        value32 = phy_query_bb_reg(adapter, 0x4c, bMaskDWord);
-       phy_set_bb_reg(adapter, 0x4c, bMaskDWord, value32|(BIT23|BIT25));
+       phy_set_bb_reg(adapter, 0x4c, bMaskDWord, value32|(BIT(23) | BIT(25)));
        value32 = phy_query_bb_reg(adapter,  0x7B4, bMaskDWord);
-       phy_set_bb_reg(adapter, 0x7b4, bMaskDWord, value32|(BIT16|BIT17));
+       phy_set_bb_reg(adapter, 0x7b4, bMaskDWord, value32|(BIT(16) | BIT(17)));
 
        /* Match MAC ADDR */
        phy_set_bb_reg(adapter, 0x7b4, 0xFFFF, 0);
        phy_set_bb_reg(adapter, 0x7b0, bMaskDWord, 0);
 
-       phy_set_bb_reg(adapter, 0x870, BIT9|BIT8, 0);
-       phy_set_bb_reg(adapter, 0x864, BIT10, 0);
-       phy_set_bb_reg(adapter, 0xb2c, BIT22, 0);
-       phy_set_bb_reg(adapter, 0xb2c, BIT31, 1);
+       phy_set_bb_reg(adapter, 0x870, BIT(9) | BIT(8), 0);
+       phy_set_bb_reg(adapter, 0x864, BIT(10), 0);
+       phy_set_bb_reg(adapter, 0xb2c, BIT(22), 0);
+       phy_set_bb_reg(adapter, 0xb2c, BIT(31), 1);
        phy_set_bb_reg(adapter, 0xca4, bMaskDWord, 0x000000a0);
 
        /* antenna mapping table */
        if (AntCombination == 2) {
                if (!dm_odm->bIsMPChip) { /* testchip */
-                       phy_set_bb_reg(adapter, 0x858, BIT10|BIT9|BIT8, 1);
-                       phy_set_bb_reg(adapter, 0x858, BIT13|BIT12|BIT11, 2);
+                       phy_set_bb_reg(adapter, 0x858, BIT(10) | BIT(9) | BIT(8), 1);
+                       phy_set_bb_reg(adapter, 0x858, BIT(13) | BIT(12) | BIT(11), 2);
                } else { /* MPchip */
                        phy_set_bb_reg(adapter, 0x914, bMaskByte0, 1);
                        phy_set_bb_reg(adapter, 0x914, bMaskByte1, 2);
                }
        } else if (AntCombination == 7) {
                if (!dm_odm->bIsMPChip) { /* testchip */
-                       phy_set_bb_reg(adapter, 0x858, BIT10|BIT9|BIT8, 0);
-                       phy_set_bb_reg(adapter, 0x858, BIT13|BIT12|BIT11, 1);
-                       phy_set_bb_reg(adapter, 0x878, BIT16, 0);
-                       phy_set_bb_reg(adapter, 0x858, BIT15|BIT14, 2);
-                       phy_set_bb_reg(adapter, 0x878, BIT19|BIT18|BIT17, 3);
-                       phy_set_bb_reg(adapter, 0x878, BIT22|BIT21|BIT20, 4);
-                       phy_set_bb_reg(adapter, 0x878, BIT25|BIT24|BIT23, 5);
-                       phy_set_bb_reg(adapter, 0x878, BIT28|BIT27|BIT26, 6);
-                       phy_set_bb_reg(adapter, 0x878, BIT31|BIT30|BIT29, 7);
+                       phy_set_bb_reg(adapter, 0x858, BIT(10) | BIT(9) | BIT(8), 0);
+                       phy_set_bb_reg(adapter, 0x858, BIT(13) | BIT(12) | BIT(11), 1);
+                       phy_set_bb_reg(adapter, 0x878, BIT(16), 0);
+                       phy_set_bb_reg(adapter, 0x858, BIT(15) | BIT(14), 2);
+                       phy_set_bb_reg(adapter, 0x878, BIT(19) | BIT(18) | BIT(17), 3);
+                       phy_set_bb_reg(adapter, 0x878, BIT(22) | BIT(21) | BIT(20), 4);
+                       phy_set_bb_reg(adapter, 0x878, BIT(25) | BIT(24) | BIT(23), 5);
+                       phy_set_bb_reg(adapter, 0x878, BIT(28) | BIT(27) | BIT(26), 6);
+                       phy_set_bb_reg(adapter, 0x878, BIT(31) | BIT(30) | BIT(29), 7);
                } else { /* MPchip */
                        phy_set_bb_reg(adapter, 0x914, bMaskByte0, 0);
                        phy_set_bb_reg(adapter, 0x914, bMaskByte1, 1);
@@ -165,13 +165,13 @@ static void dm_fast_training_init(struct odm_dm_struct *dm_odm)
        }
 
        /* Default Ant Setting when no fast training */
-       phy_set_bb_reg(adapter, 0x80c, BIT21, 1);
-       phy_set_bb_reg(adapter, 0x864, BIT5|BIT4|BIT3, 0);
-       phy_set_bb_reg(adapter, 0x864, BIT8|BIT7|BIT6, 1);
+       phy_set_bb_reg(adapter, 0x80c, BIT(21), 1);
+       phy_set_bb_reg(adapter, 0x864, BIT(5) | BIT(4) | BIT(3), 0);
+       phy_set_bb_reg(adapter, 0x864, BIT(8) | BIT(7) | BIT(6), 1);
 
        /* Enter Traing state */
-       phy_set_bb_reg(adapter, 0x864, BIT2|BIT1|BIT0, (AntCombination-1));
-       phy_set_bb_reg(adapter, 0xc50, BIT7, 1);
+       phy_set_bb_reg(adapter, 0x864, BIT(2) | BIT(1) | BIT(0), (AntCombination-1));
+       phy_set_bb_reg(adapter, 0xc50, BIT(7), 1);
 }
 
 void rtl88eu_dm_antenna_div_init(struct odm_dm_struct *dm_odm)
@@ -205,18 +205,18 @@ void rtl88eu_dm_update_rx_idle_ant(struct odm_dm_struct *dm_odm, u8 ant)
 
                if (dm_odm->AntDivType == CG_TRX_HW_ANTDIV) {
                        phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N,
-                                      BIT5|BIT4|BIT3, default_ant);
+                                      BIT(5) | BIT(4) | BIT(3), default_ant);
                        phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N,
-                                      BIT8|BIT7|BIT6, optional_ant);
+                                      BIT(8) | BIT(7) | BIT(6), optional_ant);
                        phy_set_bb_reg(adapter, ODM_REG_ANTSEL_CTRL_11N,
-                                      BIT14|BIT13|BIT12, default_ant);
+                                      BIT(14) | BIT(13) | BIT(12), default_ant);
                        phy_set_bb_reg(adapter, ODM_REG_RESP_TX_11N,
-                                      BIT6|BIT7, default_ant);
+                                      BIT(6) | BIT(7), default_ant);
                } else if (dm_odm->AntDivType == CGCS_RX_HW_ANTDIV) {
                        phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N,
-                                      BIT5|BIT4|BIT3, default_ant);
+                                      BIT(5) | BIT(4) | BIT(3), default_ant);
                        phy_set_bb_reg(adapter, ODM_REG_RX_ANT_CTRL_11N,
-                                      BIT8|BIT7|BIT6, optional_ant);
+                                      BIT(8) | BIT(7) | BIT(6), optional_ant);
                }
        }
        dm_fat_tbl->RxIdleAnt = ant;
@@ -231,9 +231,9 @@ static void update_tx_ant_88eu(struct odm_dm_struct *dm_odm, u8 ant, u32 mac_id)
                target_ant = MAIN_ANT_CG_TRX;
        else
                target_ant = AUX_ANT_CG_TRX;
-       dm_fat_tbl->antsel_a[mac_id] = target_ant&BIT0;
-       dm_fat_tbl->antsel_b[mac_id] = (target_ant&BIT1)>>1;
-       dm_fat_tbl->antsel_c[mac_id] = (target_ant&BIT2)>>2;
+       dm_fat_tbl->antsel_a[mac_id] = target_ant & BIT(0);
+       dm_fat_tbl->antsel_b[mac_id] = (target_ant & BIT(1))>>1;
+       dm_fat_tbl->antsel_c[mac_id] = (target_ant & BIT(2))>>2;
 }
 
 void rtl88eu_dm_set_tx_ant_by_tx_info(struct odm_dm_struct *dm_odm,
@@ -292,8 +292,7 @@ static void rtl88eu_dm_hw_ant_div(struct odm_dm_struct *dm_odm)
                                    (dm_fat_tbl->AuxAnt_Sum[i]/dm_fat_tbl->AuxAnt_Cnt[i]) : 0;
                        target_ant = (main_rssi >= aux_rssi) ? MAIN_ANT : AUX_ANT;
                        /* 2 Select max_rssi for DIG */
-                       local_max_rssi = (main_rssi > aux_rssi) ?
-                                         main_rssi : aux_rssi;
+                       local_max_rssi = max(main_rssi, aux_rssi);
                        if ((local_max_rssi > ant_div_max_rssi) &&
                            (local_max_rssi < 40))
                                ant_div_max_rssi = local_max_rssi;
@@ -308,8 +307,7 @@ static void rtl88eu_dm_hw_ant_div(struct odm_dm_struct *dm_odm)
                                 (aux_rssi == 0))
                                aux_rssi = main_rssi;
 
-                       local_min_rssi = (main_rssi > aux_rssi) ?
-                                         aux_rssi : main_rssi;
+                       local_min_rssi = min(main_rssi, aux_rssi);
                        if (local_min_rssi < min_rssi) {
                                min_rssi = local_min_rssi;
                                RxIdleAnt = target_ant;
@@ -344,12 +342,12 @@ void rtl88eu_dm_antenna_diversity(struct odm_dm_struct *dm_odm)
                if (dm_fat_tbl->bBecomeLinked) {
                        ODM_RT_TRACE(dm_odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
                                     ("Need to Turn off HW AntDiv\n"));
-                       phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT7, 0);
+                       phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 0);
                        phy_set_bb_reg(adapter, ODM_REG_CCK_ANTDIV_PARA1_11N,
-                                      BIT15, 0);
+                                      BIT(15), 0);
                        if (dm_odm->AntDivType == CG_TRX_HW_ANTDIV)
                                phy_set_bb_reg(adapter, ODM_REG_TX_ANT_CTRL_11N,
-                                              BIT21, 0);
+                                              BIT(21), 0);
                        dm_fat_tbl->bBecomeLinked = dm_odm->bLinked;
                }
                return;
@@ -357,12 +355,12 @@ void rtl88eu_dm_antenna_diversity(struct odm_dm_struct *dm_odm)
                if (!dm_fat_tbl->bBecomeLinked) {
                        ODM_RT_TRACE(dm_odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
                                     ("Need to Turn on HW AntDiv\n"));
-                       phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT7, 1);
+                       phy_set_bb_reg(adapter, ODM_REG_IGI_A_11N, BIT(7), 1);
                        phy_set_bb_reg(adapter, ODM_REG_CCK_ANTDIV_PARA1_11N,
-                                      BIT15, 1);
+                                      BIT(15), 1);
                        if (dm_odm->AntDivType == CG_TRX_HW_ANTDIV)
                                phy_set_bb_reg(adapter, ODM_REG_TX_ANT_CTRL_11N,
-                                              BIT21, 1);
+                                              BIT(21), 1);
                        dm_fat_tbl->bBecomeLinked = dm_odm->bLinked;
                }
        }
index 2eafa503f3433c38adb5eb83ce57a533bd14fb58..d3e8a8ea18295b2820b8f8a7b2041e66331c4190 100644 (file)
@@ -97,9 +97,9 @@ static u32 rf_serial_read(struct adapter *adapt,
        udelay(10);
 
        if (rfpath == RF_PATH_A)
-               rfpi_enable = (u8)phy_query_bb_reg(adapt, rFPGA0_XA_HSSIParameter1, BIT8);
+               rfpi_enable = (u8)phy_query_bb_reg(adapt, rFPGA0_XA_HSSIParameter1, BIT(8));
        else if (rfpath == RF_PATH_B)
-               rfpi_enable = (u8)phy_query_bb_reg(adapt, rFPGA0_XB_HSSIParameter1, BIT8);
+               rfpi_enable = (u8)phy_query_bb_reg(adapt, rFPGA0_XB_HSSIParameter1, BIT(8));
 
        if (rfpi_enable)
                ret = phy_query_bb_reg(adapt, phyreg->rfLSSIReadBackPi,
@@ -293,7 +293,7 @@ static void phy_set_bw_mode_callback(struct adapter *adapt)
                    (hal_data->nCur40MhzPrimeSC>>1));
                phy_set_bb_reg(adapt, rOFDM1_LSTF, 0xC00,
                               hal_data->nCur40MhzPrimeSC);
-               phy_set_bb_reg(adapt, 0x818, (BIT26 | BIT27),
+               phy_set_bb_reg(adapt, 0x818, (BIT(26) | BIT(27)),
                   (hal_data->nCur40MhzPrimeSC == HAL_PRIME_CHNL_OFFSET_LOWER) ? 2 : 1);
                break;
        default:
@@ -652,7 +652,7 @@ static u8 phy_path_a_iqk(struct adapter *adapt, bool config_pathb)
        reg_e94 = phy_query_bb_reg(adapt, rTx_Power_Before_IQK_A, bMaskDWord);
        reg_e9c = phy_query_bb_reg(adapt, rTx_Power_After_IQK_A, bMaskDWord);
 
-       if (!(reg_eac & BIT28) &&
+       if (!(reg_eac & BIT(28)) &&
            (((reg_e94 & 0x03FF0000)>>16) != 0x142) &&
            (((reg_e9c & 0x03FF0000)>>16) != 0x42))
                result |= 0x01;
@@ -705,7 +705,7 @@ static u8 phy_path_a_rx_iqk(struct adapter *adapt, bool configPathB)
        reg_e94 = phy_query_bb_reg(adapt, rTx_Power_Before_IQK_A, bMaskDWord);
        reg_e9c = phy_query_bb_reg(adapt, rTx_Power_After_IQK_A, bMaskDWord);
 
-       if (!(reg_eac & BIT28) &&
+       if (!(reg_eac & BIT(28)) &&
            (((reg_e94 & 0x03FF0000)>>16) != 0x142) &&
            (((reg_e9c & 0x03FF0000)>>16) != 0x42))
                result |= 0x01;
@@ -753,7 +753,7 @@ static u8 phy_path_a_rx_iqk(struct adapter *adapt, bool configPathB)
        phy_set_bb_reg(adapt, rFPGA0_IQK, bMaskDWord, 0x00000000);
        phy_set_rf_reg(adapt, RF_PATH_A, 0xdf, bRFRegOffsetMask, 0x180);
 
-       if (!(reg_eac & BIT27) && /* if Tx is OK, check whether Rx is OK */
+       if (!(reg_eac & BIT(27)) && /* if Tx is OK, check whether Rx is OK */
            (((reg_ea4 & 0x03FF0000)>>16) != 0x132) &&
            (((reg_eac & 0x03FF0000)>>16) != 0x36))
                result |= 0x02;
@@ -783,14 +783,14 @@ static u8 phy_path_b_iqk(struct adapter *adapt)
        regec4 = phy_query_bb_reg(adapt, rRx_Power_Before_IQK_B_2, bMaskDWord);
        regecc = phy_query_bb_reg(adapt, rRx_Power_After_IQK_B_2, bMaskDWord);
 
-       if (!(regeac & BIT31) &&
+       if (!(regeac & BIT(31)) &&
            (((regeb4 & 0x03FF0000)>>16) != 0x142) &&
            (((regebc & 0x03FF0000)>>16) != 0x42))
                result |= 0x01;
        else
                return result;
 
-       if (!(regeac & BIT30) &&
+       if (!(regeac & BIT(30)) &&
            (((regec4 & 0x03FF0000)>>16) != 0x132) &&
            (((regecc & 0x03FF0000)>>16) != 0x36))
                result |= 0x02;
@@ -959,9 +959,9 @@ static void mac_setting_calibration(struct adapter *adapt, u32 *mac_reg, u32 *ba
        usb_write8(adapt, mac_reg[i], 0x3F);
 
        for (i = 1; i < (IQK_MAC_REG_NUM - 1); i++) {
-               usb_write8(adapt, mac_reg[i], (u8)(backup[i]&(~BIT3)));
+               usb_write8(adapt, mac_reg[i], (u8)(backup[i]&(~BIT(3))));
        }
-       usb_write8(adapt, mac_reg[i], (u8)(backup[i]&(~BIT5)));
+       usb_write8(adapt, mac_reg[i], (u8)(backup[i]&(~BIT(5))));
 }
 
 static void path_a_standby(struct adapter *adapt)
@@ -1013,7 +1013,7 @@ static bool simularity_compare(struct adapter *adapt, s32 resulta[][8],
                        tmp2 = resulta[c2][i];
                }
 
-               diff = (tmp1 > tmp2) ? (tmp1 - tmp2) : (tmp2 - tmp1);
+               diff = abs(tmp1 - tmp2);
 
                if (diff > MAX_TOLERANCE) {
                        if ((i == 2 || i == 6) && !sim_bitmap) {
@@ -1117,15 +1117,15 @@ static void phy_iq_calibrate(struct adapter *adapt, s32 result[][8],
        }
 
        /* BB setting */
-       phy_set_bb_reg(adapt, rFPGA0_RFMOD, BIT24, 0x00);
+       phy_set_bb_reg(adapt, rFPGA0_RFMOD, BIT(24), 0x00);
        phy_set_bb_reg(adapt, rOFDM0_TRxPathEnable, bMaskDWord, 0x03a05600);
        phy_set_bb_reg(adapt, rOFDM0_TRMuxPar, bMaskDWord, 0x000800e4);
        phy_set_bb_reg(adapt, rFPGA0_XCD_RFInterfaceSW, bMaskDWord, 0x22204000);
 
-       phy_set_bb_reg(adapt, rFPGA0_XAB_RFInterfaceSW, BIT10, 0x01);
-       phy_set_bb_reg(adapt, rFPGA0_XAB_RFInterfaceSW, BIT26, 0x01);
-       phy_set_bb_reg(adapt, rFPGA0_XA_RFInterfaceOE, BIT10, 0x00);
-       phy_set_bb_reg(adapt, rFPGA0_XB_RFInterfaceOE, BIT10, 0x00);
+       phy_set_bb_reg(adapt, rFPGA0_XAB_RFInterfaceSW, BIT(10), 0x01);
+       phy_set_bb_reg(adapt, rFPGA0_XAB_RFInterfaceSW, BIT(26), 0x01);
+       phy_set_bb_reg(adapt, rFPGA0_XA_RFInterfaceOE, BIT(10), 0x00);
+       phy_set_bb_reg(adapt, rFPGA0_XB_RFInterfaceOE, BIT(10), 0x00);
 
        if (is2t) {
                phy_set_bb_reg(adapt, rFPGA0_XA_LSSIParameter, bMaskDWord,
index 954cade478db37b3a0394ec1dc37f9b5925fe336..44945427cc3464dbc23c88568985d5ac2b824160 100644 (file)
@@ -188,7 +188,7 @@ static void rtl8188e_config_rf_reg(struct adapter *adapt,
        u32 addr, u32 data)
 {
        u32 content = 0x1000; /*RF Content: radio_a_txt*/
-       u32 maskforphyset = (u32)(content & 0xE000);
+       u32 maskforphyset = content & 0xE000;
 
        rtl_rfreg_delay(adapt, RF90_PATH_A, addr | maskforphyset,
                        RFREG_OFFSET_MASK,
@@ -198,7 +198,7 @@ static void rtl8188e_config_rf_reg(struct adapter *adapt,
 static bool rtl88e_phy_config_rf_with_headerfile(struct adapter *adapt)
 {
        u32 i;
-       u32 array_len = sizeof(Array_RadioA_1T_8188E)/sizeof(u32);
+       u32 array_len = ARRAY_SIZE(Array_RadioA_1T_8188E);
        u32 *array = Array_RadioA_1T_8188E;
 
        for (i = 0; i < array_len; i += 2) {
@@ -214,7 +214,7 @@ static bool rtl88e_phy_config_rf_with_headerfile(struct adapter *adapt)
                                while (v2 != 0xDEAD && v2 != 0xCDEF &&
                                       v2 != 0xCDCD && i < array_len - 2)
                                        READ_NEXT_PAIR(v1, v2, i);
-                                       i -= 2;
+                               i -= 2;
                        } else {
                                READ_NEXT_PAIR(v1, v2, i);
                                while (v2 != 0xDEAD && v2 != 0xCDEF &&
index 0a62bfa210febdc0f6cd58f58ab68c1d498fdc49..580876313e98c709d8a5e2179664b2a58542eb55 100644 (file)
@@ -149,7 +149,7 @@ void rtl8188e_Add_RateATid(struct adapter *pAdapter, u32 bitmap, u8 arg, u8 rssi
 
        init_rate = get_highest_rate_idx(bitmap&0x0fffffff)&0x3f;
 
-       shortGIrate = (arg&BIT(5)) ? true : false;
+       shortGIrate = (arg & BIT(5)) ? true : false;
 
        if (shortGIrate)
                init_rate |= BIT(6);
@@ -277,7 +277,7 @@ static void ConstructBeacon(struct adapter *adapt, u8 *pframe, u32 *pLength)
 
        /*  supported rates... */
        rate_len = rtw_get_rateset_len(cur_network->SupportedRates);
-       pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, ((rate_len > 8) ? 8 : rate_len), cur_network->SupportedRates, &pktlen);
+       pframe = rtw_set_ie(pframe, _SUPPORTEDRATES_IE_, min_t(u32, rate_len, 8), cur_network->SupportedRates, &pktlen);
 
        /*  DS parameter set */
        pframe = rtw_set_ie(pframe, _DSSET_IE_, 1, (unsigned char *)&(cur_network->Configuration.DSConfig), &pktlen);
@@ -467,7 +467,7 @@ static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished)
 
        DBG_88E("%s\n", __func__);
        ReservedPagePacket = kzalloc(1000, GFP_KERNEL);
-       if (ReservedPagePacket == NULL) {
+       if (!ReservedPagePacket) {
                DBG_88E("%s: alloc ReservedPagePacket fail!\n", __func__);
                return;
        }
@@ -537,7 +537,7 @@ static void SetFwRsvdPagePkt(struct adapter *adapt, bool bDLFinished)
 
        TotalPacketLen = BufIndex + QosNullLength;
        pmgntframe = alloc_mgtxmitframe(pxmitpriv);
-       if (pmgntframe == NULL)
+       if (!pmgntframe)
                goto exit;
 
        /*  update attribute */
@@ -577,23 +577,23 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus)
                /*  Do not set TSF again here or vWiFi beacon DMA INT will not work. */
 
                /* Set REG_CR bit 8. DMA beacon by SW. */
-               haldata->RegCR_1 |= BIT0;
+               haldata->RegCR_1 |= BIT(0);
                usb_write8(adapt,  REG_CR+1, haldata->RegCR_1);
 
                /*  Disable Hw protection for a time which revserd for Hw sending beacon. */
                /*  Fix download reserved page packet fail that access collision with the protection time. */
                /*  2010.05.11. Added by tynli. */
                usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(3)));
-               usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)|BIT(4));
+               usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(4));
 
-               if (haldata->RegFwHwTxQCtrl&BIT6) {
+               if (haldata->RegFwHwTxQCtrl & BIT(6)) {
                        DBG_88E("HalDownloadRSVDPage(): There is an Adapter is sending beacon.\n");
                        bSendBeacon = true;
                }
 
                /*  Set FWHW_TXQ_CTRL 0x422[6]=0 to tell Hw the packet is not a real beacon frame. */
-               usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl&(~BIT6)));
-               haldata->RegFwHwTxQCtrl &= (~BIT6);
+               usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl&(~BIT(6))));
+               haldata->RegFwHwTxQCtrl &= (~BIT(6));
 
                /*  Clear beacon valid check bit. */
                rtw_hal_set_hwreg(adapt, HW_VAR_BCN_VALID, NULL);
@@ -626,7 +626,7 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus)
                /*  */
 
                /*  Enable Bcn */
-               usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)|BIT(3));
+               usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL) | BIT(3));
                usb_write8(adapt, REG_BCN_CTRL, usb_read8(adapt, REG_BCN_CTRL)&(~BIT(4)));
 
                /*  To make sure that if there exists an adapter which would like to send beacon. */
@@ -635,8 +635,8 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus)
                /*  the beacon cannot be sent by HW. */
                /*  2010.06.23. Added by tynli. */
                if (bSendBeacon) {
-                       usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl|BIT6));
-                       haldata->RegFwHwTxQCtrl |= BIT6;
+                       usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl | BIT(6)));
+                       haldata->RegFwHwTxQCtrl |= BIT(6);
                }
 
                /*  Update RSVD page location H2C to Fw. */
@@ -647,7 +647,7 @@ void rtl8188e_set_FwJoinBssReport_cmd(struct adapter *adapt, u8 mstatus)
 
                /*  Do not enable HW DMA BCN or it will cause Pcie interface hang by timing issue. 2011.11.24. by tynli. */
                /*  Clear CR[8] or beacon packet will not be send to TxBuf anymore. */
-               haldata->RegCR_1 &= (~BIT0);
+               haldata->RegCR_1 &= (~BIT(0));
                usb_write8(adapt,  REG_CR+1, haldata->RegCR_1);
        }
 }
index a6295ca6a73e8c429d8b44bef8d5c8e811c0e59e..e3e5d6f5d4f9b137a6a175b2a31ae940d47fabf4 100644 (file)
@@ -106,8 +106,8 @@ void _8051Reset88E(struct adapter *padapter)
        u8 u1bTmp;
 
        u1bTmp = usb_read8(padapter, REG_SYS_FUNC_EN+1);
-       usb_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp&(~BIT2));
-       usb_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp|(BIT2));
+       usb_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp&(~BIT(2)));
+       usb_write8(padapter, REG_SYS_FUNC_EN+1, u1bTmp|(BIT(2)));
        DBG_88E("=====> _8051Reset88E(): 8051 reset success .\n");
 }
 
@@ -184,10 +184,10 @@ static void hal_notch_filter_8188e(struct adapter *adapter, bool enable)
 {
        if (enable) {
                DBG_88E("Enable notch filter\n");
-               usb_write8(adapter, rOFDM0_RxDSP+1, usb_read8(adapter, rOFDM0_RxDSP+1) | BIT1);
+               usb_write8(adapter, rOFDM0_RxDSP+1, usb_read8(adapter, rOFDM0_RxDSP+1) | BIT(1));
        } else {
                DBG_88E("Disable notch filter\n");
-               usb_write8(adapter, rOFDM0_RxDSP+1, usb_read8(adapter, rOFDM0_RxDSP+1) & ~BIT1);
+               usb_write8(adapter, rOFDM0_RxDSP+1, usb_read8(adapter, rOFDM0_RxDSP+1) & ~BIT(1));
        }
 }
 void rtl8188e_set_hal_ops(struct hal_ops *pHalFunc)
@@ -372,7 +372,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G,
                                        pwrInfo24G->BW20_Diff[rfPath][TxCount] = EEPROM_DEFAULT_24G_HT20_DIFF;
                                } else {
                                        pwrInfo24G->BW20_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0xf0)>>4;
-                                       if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT3)              /* 4bit sign number to 8 bit sign number */
+                                       if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT(3))            /* 4bit sign number to 8 bit sign number */
                                                pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0;
                                }
 
@@ -380,7 +380,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G,
                                        pwrInfo24G->OFDM_Diff[rfPath][TxCount] =        EEPROM_DEFAULT_24G_OFDM_DIFF;
                                } else {
                                        pwrInfo24G->OFDM_Diff[rfPath][TxCount] =        (PROMContent[eeAddr]&0x0f);
-                                       if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT3)              /* 4bit sign number to 8 bit sign number */
+                                       if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT(3))            /* 4bit sign number to 8 bit sign number */
                                                pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0;
                                }
                                pwrInfo24G->CCK_Diff[rfPath][TxCount] = 0;
@@ -390,7 +390,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G,
                                        pwrInfo24G->BW40_Diff[rfPath][TxCount] =        EEPROM_DEFAULT_DIFF;
                                } else {
                                        pwrInfo24G->BW40_Diff[rfPath][TxCount] =        (PROMContent[eeAddr]&0xf0)>>4;
-                                       if (pwrInfo24G->BW40_Diff[rfPath][TxCount] & BIT3)              /* 4bit sign number to 8 bit sign number */
+                                       if (pwrInfo24G->BW40_Diff[rfPath][TxCount] & BIT(3))            /* 4bit sign number to 8 bit sign number */
                                                pwrInfo24G->BW40_Diff[rfPath][TxCount] |= 0xF0;
                                }
 
@@ -398,7 +398,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G,
                                        pwrInfo24G->BW20_Diff[rfPath][TxCount] =        EEPROM_DEFAULT_DIFF;
                                } else {
                                        pwrInfo24G->BW20_Diff[rfPath][TxCount] =        (PROMContent[eeAddr]&0x0f);
-                                       if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT3)              /* 4bit sign number to 8 bit sign number */
+                                       if (pwrInfo24G->BW20_Diff[rfPath][TxCount] & BIT(3))            /* 4bit sign number to 8 bit sign number */
                                                pwrInfo24G->BW20_Diff[rfPath][TxCount] |= 0xF0;
                                }
                                eeAddr++;
@@ -407,7 +407,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G,
                                        pwrInfo24G->OFDM_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
                                } else {
                                        pwrInfo24G->OFDM_Diff[rfPath][TxCount] =        (PROMContent[eeAddr]&0xf0)>>4;
-                                       if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT3)              /* 4bit sign number to 8 bit sign number */
+                                       if (pwrInfo24G->OFDM_Diff[rfPath][TxCount] & BIT(3))            /* 4bit sign number to 8 bit sign number */
                                                pwrInfo24G->OFDM_Diff[rfPath][TxCount] |= 0xF0;
                                }
 
@@ -415,7 +415,7 @@ static void Hal_ReadPowerValueFromPROM_8188E(struct txpowerinfo24g *pwrInfo24G,
                                        pwrInfo24G->CCK_Diff[rfPath][TxCount] = EEPROM_DEFAULT_DIFF;
                                } else {
                                        pwrInfo24G->CCK_Diff[rfPath][TxCount] = (PROMContent[eeAddr]&0x0f);
-                                       if (pwrInfo24G->CCK_Diff[rfPath][TxCount] & BIT3)               /* 4bit sign number to 8 bit sign number */
+                                       if (pwrInfo24G->CCK_Diff[rfPath][TxCount] & BIT(3))             /* 4bit sign number to 8 bit sign number */
                                                pwrInfo24G->CCK_Diff[rfPath][TxCount] |= 0xF0;
                                }
                                eeAddr++;
@@ -444,6 +444,9 @@ static u8 Hal_GetChnlGroup88E(u8 chnl, u8 *pGroup)
                else if (chnl == 14)            /*  Channel 14 */
                        *pGroup = 5;
        } else {
+
+               /* probably, this branch is suitable only for 5 GHz */
+
                bIn24G = false;
 
                if (chnl <= 40)
@@ -485,13 +488,13 @@ void Hal_ReadPowerSavingMode88E(struct adapter *padapter, u8 *hwinfo, bool AutoL
                /* hw power down mode selection , 0:rf-off / 1:power down */
 
                if (padapter->registrypriv.hwpdn_mode == 2)
-                       padapter->pwrctrlpriv.bHWPowerdown = (hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & BIT4);
+                       padapter->pwrctrlpriv.bHWPowerdown = (hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & BIT(4));
                else
                        padapter->pwrctrlpriv.bHWPowerdown = padapter->registrypriv.hwpdn_mode;
 
                /*  decide hw if support remote wakeup function */
                /*  if hw supported, 8051 (SIE) will generate WeakUP signal(D+/D- toggle) when autoresume */
-               padapter->pwrctrlpriv.bSupportRemoteWakeup = (hwinfo[EEPROM_USB_OPTIONAL_FUNCTION0] & BIT1) ? true : false;
+               padapter->pwrctrlpriv.bSupportRemoteWakeup = (hwinfo[EEPROM_USB_OPTIONAL_FUNCTION0] & BIT(1)) ? true : false;
 
                DBG_88E("%s...bHWPwrPindetect(%x)-bHWPowerdown(%x) , bSupportRemoteWakeup(%x)\n", __func__,
                padapter->pwrctrlpriv.bHWPwrPindetect, padapter->pwrctrlpriv.bHWPowerdown , padapter->pwrctrlpriv.bSupportRemoteWakeup);
index 81d691ddd6c68608a2eb4c07b209a69cbd291a58..564cf53bff1b36970fd36e87b157714e52e69d5c 100644 (file)
@@ -36,7 +36,7 @@ void SwLedOn(struct adapter *padapter, struct LED_871x *pLed)
        if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
                return;
        LedCfg = usb_read8(padapter, REG_LEDCFG2);
-       usb_write8(padapter, REG_LEDCFG2, (LedCfg&0xf0)|BIT5|BIT6); /*  SW control led0 on. */
+       usb_write8(padapter, REG_LEDCFG2, (LedCfg&0xf0) | BIT(5) | BIT(6)); /*  SW control led0 on. */
        pLed->bLedOn = true;
 }
 
@@ -55,12 +55,12 @@ void SwLedOff(struct adapter *padapter, struct LED_871x *pLed)
        if (pHalData->bLedOpenDrain) {
                        /*  Open-drain arrangement for controlling the LED) */
                LedCfg &= 0x90; /*  Set to software control. */
-               usb_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3));
+               usb_write8(padapter, REG_LEDCFG2, (LedCfg | BIT(3)));
                LedCfg = usb_read8(padapter, REG_MAC_PINMUX_CFG);
                LedCfg &= 0xFE;
                usb_write8(padapter, REG_MAC_PINMUX_CFG, LedCfg);
        } else {
-               usb_write8(padapter, REG_LEDCFG2, (LedCfg|BIT3|BIT5|BIT6));
+               usb_write8(padapter, REG_LEDCFG2, (LedCfg | BIT(3) | BIT(5) | BIT(6)));
        }
 exit:
        pLed->bLedOn = false;
index 06d1e654483e2c4426a4c9c25dd0b830275aed2a..d6d009aafcf0475053372ade31af0f1844fe7a30 100644 (file)
@@ -43,7 +43,7 @@ int   rtl8188eu_init_recv_priv(struct adapter *padapter)
 
        precvpriv->pallocated_recv_buf =
                kcalloc(NR_RECVBUFF, sizeof(struct recv_buf), GFP_KERNEL);
-       if (precvpriv->pallocated_recv_buf == NULL) {
+       if (!precvpriv->pallocated_recv_buf) {
                res = _FAIL;
                RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
                                ("alloc recv_buf fail!\n"));
index 594c1da9db23d6d498456828ac0242fd18db4c1a..7c5086ecff1704ca4838113c33f35930774c5177 100644 (file)
@@ -20,6 +20,7 @@
 #define _RTL8188E_XMIT_C_
 #include <osdep_service.h>
 #include <drv_types.h>
+#include <mon.h>
 #include <wifi.h>
 #include <osdep_intf.h>
 #include <usb_ops_linux.h>
@@ -649,7 +650,7 @@ static s32 pre_xmitframe(struct adapter *adapt, struct xmit_frame *pxmitframe)
                goto enqueue;
 
        pxmitbuf = rtw_alloc_xmitbuf(pxmitpriv);
-       if (pxmitbuf == NULL)
+       if (!pxmitbuf)
                goto enqueue;
 
        spin_unlock_bh(&pxmitpriv->lock);
@@ -684,6 +685,9 @@ enqueue:
 
 s32 rtl8188eu_mgnt_xmit(struct adapter *adapt, struct xmit_frame *pmgntframe)
 {
+       struct xmit_priv *xmitpriv = &adapt->xmitpriv;
+
+       rtl88eu_mon_xmit_hook(adapt->pmondev, pmgntframe, xmitpriv->frag_len);
        return rtw_dump_xframe(adapt, pmgntframe);
 }
 
index 1ef878fd997bae0356d6f7d16a4106cfbef32ad8..7e72259f0e4002c3c2bfa39a382ce904cb50a156 100644 (file)
@@ -607,7 +607,7 @@ static void _InitBeaconParameters(struct adapter *Adapter)
 static void _BeaconFunctionEnable(struct adapter *Adapter,
                                  bool Enable, bool Linked)
 {
-       usb_write8(Adapter, REG_BCN_CTRL, (BIT4 | BIT3 | BIT1));
+       usb_write8(Adapter, REG_BCN_CTRL, (BIT(4) | BIT(3) | BIT(1)));
 
        usb_write8(Adapter, REG_RD_CTRL+1, 0x6F);
 }
@@ -632,8 +632,8 @@ static void _InitAntenna_Selection(struct adapter *Adapter)
                return;
        DBG_88E("==>  %s ....\n", __func__);
 
-       usb_write32(Adapter, REG_LEDCFG0, usb_read32(Adapter, REG_LEDCFG0)|BIT23);
-       phy_set_bb_reg(Adapter, rFPGA0_XAB_RFParameter, BIT13, 0x01);
+       usb_write32(Adapter, REG_LEDCFG0, usb_read32(Adapter, REG_LEDCFG0) | BIT(23));
+       phy_set_bb_reg(Adapter, rFPGA0_XAB_RFParameter, BIT(13), 0x01);
 
        if (phy_query_bb_reg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300) == Antenna_A)
                haldata->CurAntenna = Antenna_A;
@@ -664,13 +664,13 @@ enum rt_rf_power_state RfOnOffDetect(struct adapter *adapt)
 
        if (adapt->pwrctrlpriv.bHWPowerdown) {
                val8 = usb_read8(adapt, REG_HSISR);
-               DBG_88E("pwrdown, 0x5c(BIT7)=%02x\n", val8);
-               rfpowerstate = (val8 & BIT7) ? rf_off : rf_on;
+               DBG_88E("pwrdown, 0x5c(BIT(7))=%02x\n", val8);
+               rfpowerstate = (val8 & BIT(7)) ? rf_off : rf_on;
        } else { /*  rf on/off */
-               usb_write8(adapt, REG_MAC_PINMUX_CFG, usb_read8(adapt, REG_MAC_PINMUX_CFG)&~(BIT3));
+               usb_write8(adapt, REG_MAC_PINMUX_CFG, usb_read8(adapt, REG_MAC_PINMUX_CFG)&~(BIT(3)));
                val8 = usb_read8(adapt, REG_GPIO_IO_SEL);
                DBG_88E("GPIO_IN=%02x\n", val8);
-               rfpowerstate = (val8 & BIT3) ? rf_on : rf_off;
+               rfpowerstate = (val8 & BIT(3)) ? rf_on : rf_off;
        }
        return rfpowerstate;
 }      /*  HalDetectPwrDownMode */
@@ -805,7 +805,7 @@ static u32 rtl8188eu_hal_init(struct adapter *Adapter)
        /* Enable TX Report */
        /* Enable Tx Report Timer */
        value8 = usb_read8(Adapter, REG_TX_RPT_CTRL);
-       usb_write8(Adapter,  REG_TX_RPT_CTRL, (value8|BIT1|BIT0));
+       usb_write8(Adapter,  REG_TX_RPT_CTRL, (value8 | BIT(1) | BIT(0)));
        /* Set MAX RPT MACID */
        usb_write8(Adapter,  REG_TX_RPT_CTRL+1, 2);/* FOR sta mode ,0: bc/mc ,1:AP */
        /* Tx RPT Timer. Unit: 32us */
@@ -898,7 +898,7 @@ HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_LCK);
        usb_write8(Adapter, REG_USB_HRPWM, 0);
 
        /* ack for xmit mgmt frames. */
-       usb_write32(Adapter, REG_FWHW_TXQ_CTRL, usb_read32(Adapter, REG_FWHW_TXQ_CTRL)|BIT(12));
+       usb_write32(Adapter, REG_FWHW_TXQ_CTRL, usb_read32(Adapter, REG_FWHW_TXQ_CTRL) | BIT(12));
 
 exit:
 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_END);
@@ -918,7 +918,7 @@ static void CardDisableRTL8188EU(struct adapter *Adapter)
 
        /* Stop Tx Report Timer. 0x4EC[Bit1]=b'0 */
        val8 = usb_read8(Adapter, REG_TX_RPT_CTRL);
-       usb_write8(Adapter, REG_TX_RPT_CTRL, val8&(~BIT1));
+       usb_write8(Adapter, REG_TX_RPT_CTRL, val8&(~BIT(1)));
 
        /*  stop rx */
        usb_write8(Adapter, REG_CR, 0x0);
@@ -944,7 +944,7 @@ static void CardDisableRTL8188EU(struct adapter *Adapter)
        /* YJ,add,111212 */
        /* Disable 32k */
        val8 = usb_read8(Adapter, REG_32K_CTRL);
-       usb_write8(Adapter, REG_32K_CTRL, val8&(~BIT0));
+       usb_write8(Adapter, REG_32K_CTRL, val8&(~BIT(0)));
 
        /*  Card disable power action flow */
        rtl88eu_pwrseqcmdparsing(Adapter, PWR_CUT_ALL_MSK,
@@ -953,9 +953,9 @@ static void CardDisableRTL8188EU(struct adapter *Adapter)
 
        /*  Reset MCU IO Wrapper */
        val8 = usb_read8(Adapter, REG_RSV_CTRL+1);
-       usb_write8(Adapter, REG_RSV_CTRL+1, (val8&(~BIT3)));
+       usb_write8(Adapter, REG_RSV_CTRL+1, (val8&(~BIT(3))));
        val8 = usb_read8(Adapter, REG_RSV_CTRL+1);
-       usb_write8(Adapter, REG_RSV_CTRL+1, val8|BIT3);
+       usb_write8(Adapter, REG_RSV_CTRL+1, val8 | BIT(3));
 
        /* YJ,test add, 111207. For Power Consumption. */
        val8 = usb_read8(Adapter, GPIO_IN);
@@ -1171,10 +1171,10 @@ static void ResumeTxBeacon(struct adapter *adapt)
        /*  2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
        /*  which should be read from register to a global variable. */
 
-       usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) | BIT6);
-       haldata->RegFwHwTxQCtrl |= BIT6;
+       usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) | BIT(6));
+       haldata->RegFwHwTxQCtrl |= BIT(6);
        usb_write8(adapt, REG_TBTT_PROHIBIT+1, 0xff);
-       haldata->RegReg542 |= BIT0;
+       haldata->RegReg542 |= BIT(0);
        usb_write8(adapt, REG_TBTT_PROHIBIT+2, haldata->RegReg542);
 }
 
@@ -1185,10 +1185,10 @@ static void StopTxBeacon(struct adapter *adapt)
        /*  2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
        /*  which should be read from register to a global variable. */
 
-       usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) & (~BIT6));
-       haldata->RegFwHwTxQCtrl &= (~BIT6);
+       usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) & (~BIT(6)));
+       haldata->RegFwHwTxQCtrl &= (~BIT(6));
        usb_write8(adapt, REG_TBTT_PROHIBIT+1, 0x64);
-       haldata->RegReg542 &= ~(BIT0);
+       haldata->RegReg542 &= ~(BIT(0));
        usb_write8(adapt, REG_TBTT_PROHIBIT+2, haldata->RegReg542);
 
         /* todo: CheckFwRsvdPageContent(Adapter);  2010.06.23. Added by tynli. */
@@ -1200,7 +1200,7 @@ static void hw_var_set_opmode(struct adapter *Adapter, u8 variable, u8 *val)
        u8 mode = *((u8 *)val);
 
        /*  disable Port0 TSF update */
-       usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(4));
+       usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(4));
 
        /*  set net_type */
        val8 = usb_read8(Adapter, MSR)&0x0c;
@@ -1378,7 +1378,7 @@ static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
                        usb_write32(Adapter, REG_TSFTR+4, tsf>>32);
 
                        /* enable related TSF function */
-                       usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(3));
+                       usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(3));
 
                        if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
                                ResumeTxBeacon(Adapter);
@@ -1403,10 +1403,10 @@ static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
                usb_write16(Adapter, REG_RXFLTMAP2, 0x00);
 
                /* reset TSF */
-               usb_write8(Adapter, REG_DUAL_TSF_RST, (BIT(0)|BIT(1)));
+               usb_write8(Adapter, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
 
                /* disable update TSF */
-               usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(4));
+               usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(4));
                break;
        case HW_VAR_MLME_SITESURVEY:
                if (*((u8 *)val)) { /* under sitesurvey */
@@ -1418,7 +1418,7 @@ static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
                        usb_write16(Adapter, REG_RXFLTMAP2, 0x00);
 
                        /* disable update TSF */
-                       usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(4));
+                       usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL) | BIT(4));
                } else { /* sitesurvey done */
                        struct mlme_ext_priv    *pmlmeext = &Adapter->mlmeextpriv;
                        struct mlme_ext_info    *pmlmeinfo = &(pmlmeext->mlmext_info);
@@ -1578,7 +1578,7 @@ static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
                }
                break;
        case HW_VAR_CAM_INVALID_ALL:
-               usb_write32(Adapter, RWCAM, BIT(31)|BIT(30));
+               usb_write32(Adapter, RWCAM, BIT(31) | BIT(30));
                break;
        case HW_VAR_CAM_WRITE:
                {
@@ -1795,7 +1795,7 @@ static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
                break;
        case HW_VAR_BCN_VALID:
                /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2, write 1 to clear, Clear by sw */
-               usb_write8(Adapter, REG_TDECTRL+2, usb_read8(Adapter, REG_TDECTRL+2) | BIT0);
+               usb_write8(Adapter, REG_TDECTRL+2, usb_read8(Adapter, REG_TDECTRL+2) | BIT(0));
                break;
        default:
                break;
@@ -1815,7 +1815,7 @@ static void GetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
                break;
        case HW_VAR_BCN_VALID:
                /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2 */
-               val[0] = (BIT0 & usb_read8(Adapter, REG_TDECTRL+2)) ? true : false;
+               val[0] = (BIT(0) & usb_read8(Adapter, REG_TDECTRL+2)) ? true : false;
                break;
        case HW_VAR_DM_FLAG:
                val[0] = podmpriv->SupportAbility;
@@ -2052,7 +2052,7 @@ static void SetBeaconRelatedRegisters8188EUsb(struct adapter *adapt)
 
        ResumeTxBeacon(adapt);
 
-       usb_write8(adapt, bcn_ctrl_reg, usb_read8(adapt, bcn_ctrl_reg)|BIT(1));
+       usb_write8(adapt, bcn_ctrl_reg, usb_read8(adapt, bcn_ctrl_reg) | BIT(1));
 }
 
 static void rtl8188eu_init_default_value(struct adapter *adapt)
index 20e6b40fc35cb082a2a993bc7d172451053aef14..e058162fe2baa7e516253f52e1b0b3ab9c25d33e 100644 (file)
@@ -87,13 +87,13 @@ enum rf_radio_path {
 
 enum wireless_mode {
        WIRELESS_MODE_UNKNOWN = 0x00,
-       WIRELESS_MODE_A                 = BIT2,
-       WIRELESS_MODE_B                 = BIT0,
-       WIRELESS_MODE_G                 = BIT1,
-       WIRELESS_MODE_AUTO              = BIT5,
-       WIRELESS_MODE_N_24G             = BIT3,
-       WIRELESS_MODE_N_5G              = BIT4,
-       WIRELESS_MODE_AC                = BIT6
+       WIRELESS_MODE_A                 = BIT(2),
+       WIRELESS_MODE_B                 = BIT(0),
+       WIRELESS_MODE_G                 = BIT(1),
+       WIRELESS_MODE_AUTO              = BIT(5),
+       WIRELESS_MODE_N_24G             = BIT(3),
+       WIRELESS_MODE_N_5G              = BIT(4),
+       WIRELESS_MODE_AC                = BIT(6)
 };
 
 enum phy_rate_tx_offset_area {
index 8a7ca992674aa3dec069d846b66fd982ee39809c..6a2a147e6d15888386436cbcd8ec536b473a628f 100644 (file)
@@ -20,9 +20,6 @@
 #ifndef __BASIC_TYPES_H__
 #define __BASIC_TYPES_H__
 
-#define SUCCESS        0
-#define FAIL   (-1)
-
 #include <linux/types.h>
 #define NDIS_OID uint
 
@@ -30,9 +27,6 @@ typedef void (*proc_t)(void *);
 
 #define FIELD_OFFSET(s, field) ((ssize_t)&((s *)(0))->field)
 
-#define MEM_ALIGNMENT_OFFSET   (sizeof(size_t))
-#define MEM_ALIGNMENT_PADDING  (sizeof(size_t) - 1)
-
 /* port from fw */
 /*  TODO: Macros Below are Sync from SD7-Driver. It is necessary
  * to check correctness */
index bcc74dcd82077c95423943b43b4425d9a315c7fc..0729bd40b02a1afe0da09debe939131d1279e921 100644 (file)
@@ -131,6 +131,7 @@ struct registry_priv {
        u8      if2name[16];
 
        u8      notch_filter;
+       bool    monitor_enable;
 };
 
 /* For registry parameters */
@@ -209,6 +210,7 @@ struct adapter {
        void (*intf_start)(struct adapter *adapter);
        void (*intf_stop)(struct adapter *adapter);
        struct  net_device *pnetdev;
+       struct  net_device *pmondev;
 
        /*  used by rtw_rereg_nd_name related function */
        struct rereg_nd_name_data {
index e73c6341248eb9acbca4bf320b2bdc884ada61ff..1b1c102924562dbfdbddede204e67f4c8344e08c 100644 (file)
 #include <Hal8188EPhyCfg.h>
 
 enum RTL871X_HCI_TYPE {
-       RTW_PCIE        = BIT0,
-       RTW_USB         = BIT1,
-       RTW_SDIO        = BIT2,
-       RTW_GSPI        = BIT3,
+       RTW_PCIE        = BIT(0),
+       RTW_USB         = BIT(1),
+       RTW_SDIO        = BIT(2),
+       RTW_GSPI        = BIT(3),
 };
 
 enum _CHIP_TYPE {
@@ -226,10 +226,10 @@ enum rt_eeprom_type {
 };
 
 #define RF_CHANGE_BY_INIT      0
-#define RF_CHANGE_BY_IPS       BIT28
-#define RF_CHANGE_BY_PS                BIT29
-#define RF_CHANGE_BY_HW                BIT30
-#define RF_CHANGE_BY_SW                BIT31
+#define RF_CHANGE_BY_IPS       BIT(28)
+#define RF_CHANGE_BY_PS                BIT(29)
+#define RF_CHANGE_BY_HW                BIT(30)
+#define RF_CHANGE_BY_SW                BIT(31)
 
 enum hardware_type {
        HARDWARE_TYPE_RTL8188EU,
index 6400f75707bd54a2ba7ba40277b1364afe8afb0c..f8f5eb6b79769995c29ee1323f07a4e33290142d 100644 (file)
@@ -1092,8 +1092,8 @@ enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
                                          struct rtw_ieee802_11_elems *elems,
                                          int show_errors);
 
-u8 *rtw_set_fixed_ie(unsigned char *pbuf, unsigned int len,
-                    unsigned char *source, unsigned int *frlen);
+u8 *rtw_set_fixed_ie(void *pbuf, unsigned int len,
+                    void *source, unsigned int *frlen);
 u8 *rtw_set_ie(u8 *pbuf, int index, uint len, u8 *source, uint *frlen);
 
 enum secondary_ch_offset {
diff --git a/drivers/staging/rtl8188eu/include/mon.h b/drivers/staging/rtl8188eu/include/mon.h
new file mode 100644 (file)
index 0000000..f31fa68
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * RTL8188EU monitor interface
+ *
+ * Copyright (C) 2015 Jakub Sitnicki
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ */
+
+/*
+ * Monitor interface receives all transmitted and received IEEE 802.11
+ * frames, both Data and Management, and passes them up to userspace
+ * preserving the WLAN headers.
+ */
+
+#ifndef _MON_H_
+#define _MON_H_
+
+struct net_device;
+struct recv_frame;
+struct xmit_frame;
+
+struct net_device *rtl88eu_mon_init(void);
+void rtl88eu_mon_deinit(struct net_device *dev);
+
+void rtl88eu_mon_recv_hook(struct net_device *dev, struct recv_frame *frame);
+void rtl88eu_mon_xmit_hook(struct net_device *dev, struct xmit_frame *frame,
+                          uint frag_len);
+
+#endif /* _MON_H_ */
index 73ef9c7596c1c63862401de5408d9bacb49604e6..bc970caf7edad0a310727c347b9af891c973750b 100644 (file)
@@ -414,31 +414,31 @@ enum odm_common_info_def {
 
 enum odm_ability_def {
        /*  BB ODM section BIT 0-15 */
-       ODM_BB_DIG                      = BIT0,
-       ODM_BB_RA_MASK                  = BIT1,
-       ODM_BB_DYNAMIC_TXPWR            = BIT2,
-       ODM_BB_FA_CNT                   = BIT3,
-       ODM_BB_RSSI_MONITOR             = BIT4,
-       ODM_BB_CCK_PD                   = BIT5,
-       ODM_BB_ANT_DIV                  = BIT6,
-       ODM_BB_PWR_SAVE                 = BIT7,
-       ODM_BB_PWR_TRA                  = BIT8,
-       ODM_BB_RATE_ADAPTIVE            = BIT9,
-       ODM_BB_PATH_DIV                 = BIT10,
-       ODM_BB_PSD                      = BIT11,
-       ODM_BB_RXHP                     = BIT12,
+       ODM_BB_DIG                      = BIT(0),
+       ODM_BB_RA_MASK                  = BIT(1),
+       ODM_BB_DYNAMIC_TXPWR            = BIT(2),
+       ODM_BB_FA_CNT                   = BIT(3),
+       ODM_BB_RSSI_MONITOR             = BIT(4),
+       ODM_BB_CCK_PD                   = BIT(5),
+       ODM_BB_ANT_DIV                  = BIT(6),
+       ODM_BB_PWR_SAVE                 = BIT(7),
+       ODM_BB_PWR_TRA                  = BIT(8),
+       ODM_BB_RATE_ADAPTIVE            = BIT(9),
+       ODM_BB_PATH_DIV                 = BIT(10),
+       ODM_BB_PSD                      = BIT(11),
+       ODM_BB_RXHP                     = BIT(12),
 
        /*  MAC DM section BIT 16-23 */
-       ODM_MAC_EDCA_TURBO              = BIT16,
-       ODM_MAC_EARLY_MODE              = BIT17,
+       ODM_MAC_EDCA_TURBO              = BIT(16),
+       ODM_MAC_EARLY_MODE              = BIT(17),
 
        /*  RF ODM section BIT 24-31 */
-       ODM_RF_TX_PWR_TRACK             = BIT24,
-       ODM_RF_RX_GAIN_TRACK            = BIT25,
-       ODM_RF_CALIBRATION              = BIT26,
+       ODM_RF_TX_PWR_TRACK             = BIT(24),
+       ODM_RF_RX_GAIN_TRACK            = BIT(25),
+       ODM_RF_CALIBRATION              = BIT(26),
 };
 
-#define ODM_RTL8188E           BIT4
+#define ODM_RTL8188E           BIT(4)
 
 /* ODM_CMNINFO_CUT_VER */
 enum odm_cut_version {
@@ -460,14 +460,14 @@ enum odm_fab_Version {
 /*  ODM_CMNINFO_RF_TYPE */
 /*  For example 1T2R (A+AB = BIT0|BIT4|BIT5) */
 enum odm_rf_path {
-       ODM_RF_TX_A     =       BIT0,
-       ODM_RF_TX_B     =       BIT1,
-       ODM_RF_TX_C     =       BIT2,
-       ODM_RF_TX_D     =       BIT3,
-       ODM_RF_RX_A     =       BIT4,
-       ODM_RF_RX_B     =       BIT5,
-       ODM_RF_RX_C     =       BIT6,
-       ODM_RF_RX_D     =       BIT7,
+       ODM_RF_TX_A     =       BIT(0),
+       ODM_RF_TX_B     =       BIT(1),
+       ODM_RF_TX_C     =       BIT(2),
+       ODM_RF_TX_D     =       BIT(3),
+       ODM_RF_RX_A     =       BIT(4),
+       ODM_RF_RX_B     =       BIT(5),
+       ODM_RF_RX_C     =       BIT(6),
+       ODM_RF_RX_D     =       BIT(7),
 };
 
 enum odm_rf_type {
@@ -498,33 +498,33 @@ enum odm_bt_coexist {
 
 /*  ODM_CMNINFO_OP_MODE */
 enum odm_operation_mode {
-       ODM_NO_LINK             = BIT0,
-       ODM_LINK                = BIT1,
-       ODM_SCAN                = BIT2,
-       ODM_POWERSAVE           = BIT3,
-       ODM_AP_MODE             = BIT4,
-       ODM_CLIENT_MODE         = BIT5,
-       ODM_AD_HOC              = BIT6,
-       ODM_WIFI_DIRECT         = BIT7,
-       ODM_WIFI_DISPLAY        = BIT8,
+       ODM_NO_LINK             = BIT(0),
+       ODM_LINK                = BIT(1),
+       ODM_SCAN                = BIT(2),
+       ODM_POWERSAVE           = BIT(3),
+       ODM_AP_MODE             = BIT(4),
+       ODM_CLIENT_MODE         = BIT(5),
+       ODM_AD_HOC              = BIT(6),
+       ODM_WIFI_DIRECT         = BIT(7),
+       ODM_WIFI_DISPLAY        = BIT(8),
 };
 
 /*  ODM_CMNINFO_WM_MODE */
 enum odm_wireless_mode {
        ODM_WM_UNKNOW   = 0x0,
-       ODM_WM_B        = BIT0,
-       ODM_WM_G        = BIT1,
-       ODM_WM_A        = BIT2,
-       ODM_WM_N24G     = BIT3,
-       ODM_WM_N5G      = BIT4,
-       ODM_WM_AUTO     = BIT5,
-       ODM_WM_AC       = BIT6,
+       ODM_WM_B        = BIT(0),
+       ODM_WM_G        = BIT(1),
+       ODM_WM_A        = BIT(2),
+       ODM_WM_N24G     = BIT(3),
+       ODM_WM_N5G      = BIT(4),
+       ODM_WM_AUTO     = BIT(5),
+       ODM_WM_AC       = BIT(6),
 };
 
 /*  ODM_CMNINFO_BAND */
 enum odm_band_type {
-       ODM_BAND_2_4G   = BIT0,
-       ODM_BAND_5G     = BIT1,
+       ODM_BAND_2_4G   = BIT(0),
+       ODM_BAND_5G     = BIT(1),
 };
 
 /*  ODM_CMNINFO_SEC_CHNL_OFFSET */
index 914f831a5b77ee8c50a0d07b5a8f2d402489da5f..e9390963d6ff8b7a3131183601a5e40d0ebe4faf 100644 (file)
 
 /*  Define the tracing components */
 /* BB Functions */
-#define ODM_COMP_DIG                                   BIT0
-#define ODM_COMP_RA_MASK                               BIT1
-#define ODM_COMP_DYNAMIC_TXPWR                         BIT2
-#define ODM_COMP_FA_CNT                                        BIT3
-#define ODM_COMP_RSSI_MONITOR                          BIT4
-#define ODM_COMP_CCK_PD                                        BIT5
-#define ODM_COMP_ANT_DIV                               BIT6
-#define ODM_COMP_PWR_SAVE                              BIT7
-#define ODM_COMP_PWR_TRA                               BIT8
-#define ODM_COMP_RATE_ADAPTIVE                         BIT9
-#define ODM_COMP_PATH_DIV                              BIT10
-#define ODM_COMP_PSD                                   BIT11
-#define ODM_COMP_DYNAMIC_PRICCA                                BIT12
-#define ODM_COMP_RXHP                                  BIT13
+#define ODM_COMP_DIG                                   BIT(0)
+#define ODM_COMP_RA_MASK                               BIT(1)
+#define ODM_COMP_DYNAMIC_TXPWR                         BIT(2)
+#define ODM_COMP_FA_CNT                                        BIT(3)
+#define ODM_COMP_RSSI_MONITOR                          BIT(4)
+#define ODM_COMP_CCK_PD                                        BIT(5)
+#define ODM_COMP_ANT_DIV                               BIT(6)
+#define ODM_COMP_PWR_SAVE                              BIT(7)
+#define ODM_COMP_PWR_TRA                               BIT(8)
+#define ODM_COMP_RATE_ADAPTIVE                         BIT(9)
+#define ODM_COMP_PATH_DIV                              BIT(10)
+#define ODM_COMP_PSD                                   BIT(11)
+#define ODM_COMP_DYNAMIC_PRICCA                                BIT(12)
+#define ODM_COMP_RXHP                                  BIT(13)
 /* MAC Functions */
-#define ODM_COMP_EDCA_TURBO                            BIT16
-#define ODM_COMP_EARLY_MODE                            BIT17
+#define ODM_COMP_EDCA_TURBO                            BIT(16)
+#define ODM_COMP_EARLY_MODE                            BIT(17)
 /* RF Functions */
-#define ODM_COMP_TX_PWR_TRACK                          BIT24
-#define ODM_COMP_RX_GAIN_TRACK                         BIT25
-#define ODM_COMP_CALIBRATION                           BIT26
+#define ODM_COMP_TX_PWR_TRACK                          BIT(24)
+#define ODM_COMP_RX_GAIN_TRACK                         BIT(25)
+#define ODM_COMP_CALIBRATION                           BIT(26)
 /* Common Functions */
-#define ODM_COMP_COMMON                                        BIT30
-#define ODM_COMP_INIT                                  BIT31
+#define ODM_COMP_COMMON                                        BIT(30)
+#define ODM_COMP_INIT                                  BIT(31)
 
 /*------------------------Export Marco Definition---------------------------*/
 #define RT_PRINTK(fmt, args...)                                \
index 89bc46bc71b0076298f04eb341bb1814c4ba80b0..7f10b695cf9d4f581bebc81787b756d6a3497778 100644 (file)
 /*  Bitmap Definition */
 /*  */
 
-#define        BIT_FA_RESET                                    BIT0
+#define        BIT_FA_RESET                                    BIT(0)
 
 
 
index cf9ca685eb7776d69aa634ec6f603d211c3c1930..e24fe8cc3d0b743aa690cca361e9a2bc4c4efa2e 100644 (file)
@@ -67,15 +67,6 @@ static inline struct list_head *get_list_head(struct __queue *queue)
        return &(queue->queue);
 }
 
-static inline int _enter_critical_mutex(struct mutex *pmutex,
-                                       unsigned long *pirqL)
-{
-       int ret;
-
-       ret = mutex_lock_interruptible(pmutex);
-       return ret;
-}
-
 static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
 {
        return  netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 0)) &&
@@ -84,45 +75,6 @@ static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
                netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3));
 }
 
-
-#define BIT0   0x00000001
-#define BIT1   0x00000002
-#define BIT2   0x00000004
-#define BIT3   0x00000008
-#define BIT4   0x00000010
-#define BIT5   0x00000020
-#define BIT6   0x00000040
-#define BIT7   0x00000080
-#define BIT8   0x00000100
-#define BIT9   0x00000200
-#define BIT10  0x00000400
-#define BIT11  0x00000800
-#define BIT12  0x00001000
-#define BIT13  0x00002000
-#define BIT14  0x00004000
-#define BIT15  0x00008000
-#define BIT16  0x00010000
-#define BIT17  0x00020000
-#define BIT18  0x00040000
-#define BIT19  0x00080000
-#define BIT20  0x00100000
-#define BIT21  0x00200000
-#define BIT22  0x00400000
-#define BIT23  0x00800000
-#define BIT24  0x01000000
-#define BIT25  0x02000000
-#define BIT26  0x04000000
-#define BIT27  0x08000000
-#define BIT28  0x10000000
-#define BIT29  0x20000000
-#define BIT30  0x40000000
-#define BIT31  0x80000000
-#define BIT32  0x0100000000
-#define BIT33  0x0200000000
-#define BIT34  0x0400000000
-#define BIT35  0x0800000000
-#define BIT36  0x1000000000
-
 int RTW_STATUS_CODE(int error_code);
 
 #define rtw_update_mem_stat(flag, sz) do {} while (0)
index 43db92dcb8b365b6f463ae65bfd32c0cfe89a747..8c876c6c7a4fd3737652923056324ad90c474c42 100644 (file)
         * comment here
         */                                                             \
        {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT1, BIT1},                 \
+       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(1), BIT(1)},             \
        /* wait till 0x04[17] = 1    power ready*/      \
        {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0|BIT1, 0},                 \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0) | BIT(1), 0},           \
        /* 0x02[1:0] = 0        reset BB*/                              \
        {0x0026, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT7, BIT7},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), BIT(7)},               \
        /*0x24[23] = 2b'01 schmit trigger */                            \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT7, 0},                      \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), 0},                    \
        /* 0x04[15] = 0 disable HWPDN (control by DRV)*/                \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT4|BIT3, 0},                 \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4) | BIT(3), 0},           \
        /*0x04[12:11] = 2b'00 disable WL suspend*/                      \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0, BIT0},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), BIT(0)},               \
        /*0x04[8] = 1 polling until return 0*/                          \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT0, 0},                    \
+       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(0), 0},                  \
        /*wait till 0x04[8] = 0*/                                       \
        {0x0023, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT4, 0},                      \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), 0},                    \
        /*LDO normal mode*/                                             \
        {0x0074, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT4, BIT4},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), BIT(4)},               \
        /*SDIO Driving*/
 
 #define RTL8188E_TRANS_ACT_TO_CARDEMU                                  \
        PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0},                      \
        /*0x1F[7:0] = 0 turn off RF*/                                   \
        {0x0023, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT4, BIT4},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), BIT(4)},               \
        /*LDO Sleep mode*/                                              \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT1, BIT1},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)},               \
        /*0x04[9] = 1 turn off MAC by HW state machine*/                \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT1, 0},                    \
+       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(1), 0},                  \
        /*wait till 0x04[9] = 0 polling until return 0 to disable*/
 
 #define RTL8188E_TRANS_CARDEMU_TO_SUS                                  \
         */                                                             \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,                      \
        PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC,           \
-       PWR_CMD_WRITE, BIT3|BIT4, BIT3},                                \
+       PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3)},                        \
        /* 0x04[12:11] = 2b'01enable WL suspend */                      \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT3|BIT4, BIT3|BIT4},         \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3) | BIT(4)}, \
        /* 0x04[12:11] = 2b'11enable WL suspend for PCIe */             \
        {0x0007, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,                      \
        PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC,           \
-       PWR_CMD_WRITE, 0xFF, BIT7},                                     \
+       PWR_CMD_WRITE, 0xFF, BIT(7)},                                   \
        /* 0x04[31:30] = 2b'10 enable enable bandgap mbias in suspend */\
        {0x0041, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,                      \
        PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC,           \
-       PWR_CMD_WRITE, BIT4, 0},                                        \
+       PWR_CMD_WRITE, BIT(4), 0},                                      \
        /*Clear SIC_EN register 0x40[12] = 1'b0 */                      \
        {0xfe10, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,                      \
        PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC,           \
-       PWR_CMD_WRITE, BIT4, BIT4},                                     \
+       PWR_CMD_WRITE, BIT(4), BIT(4)},                                 \
        /*Set USB suspend enable local register  0xfe10[4]=1 */         \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT0, BIT0},                  \
+       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), BIT(0)},              \
        /*Set SDIO suspend local register*/                             \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT1, 0},                   \
+       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), 0},                 \
        /*wait power state to suspend*/
 
 #define RTL8188E_TRANS_SUS_TO_CARDEMU                                  \
         * comments here
         */                                                             \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT0, 0},                     \
+       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), 0},                   \
        /*Set SDIO suspend local register*/                             \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT1, BIT1},                \
+       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), BIT(1)},            \
        /*wait power state to suspend*/                                 \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT3|BIT4, 0},                 \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3) | BIT(4), 0},           \
        /*0x04[12:11] = 2b'01enable WL suspend*/
 
 #define RTL8188E_TRANS_CARDEMU_TO_CARDDIS                              \
         * comments here
         */                                                             \
        {0x0026, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT7, BIT7},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), BIT(7)},               \
        /*0x24[23] = 2b'01 schmit trigger */                            \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,                      \
        PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC,           \
-       PWR_CMD_WRITE, BIT3|BIT4, BIT3},                                \
+       PWR_CMD_WRITE, BIT(3) | BIT(4), BIT(3)},                        \
        /*0x04[12:11] = 2b'01 enable WL suspend*/                       \
        {0x0007, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,                      \
        PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC,           \
        /* 0x04[31:30] = 2b'10 enable enable bandgap mbias in suspend */\
        {0x0041, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,                      \
        PWR_INTF_USB_MSK|PWR_INTF_SDIO_MSK, PWR_BASEADDR_MAC,           \
-       PWR_CMD_WRITE, BIT4, 0},                                        \
+       PWR_CMD_WRITE, BIT(4), 0},                                      \
        /*Clear SIC_EN register 0x40[12] = 1'b0 */                      \
        {0xfe10, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT4, BIT4},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), BIT(4)},               \
        /*Set USB suspend enable local register  0xfe10[4]=1 */         \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT0, BIT0},                  \
+       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), BIT(0)},              \
        /*Set SDIO suspend local register*/                             \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT1, 0},                   \
+       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), 0},                 \
        /*wait power state to suspend*/
 
 #define RTL8188E_TRANS_CARDDIS_TO_CARDEMU                              \
         * comments here
         */                                                             \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT0, 0},                     \
+       PWR_BASEADDR_SDIO, PWR_CMD_WRITE, BIT(0), 0},                   \
        /*Set SDIO suspend local register*/                             \
        {0x0086, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_SDIO_MSK,   \
-       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT1, BIT1},                \
+       PWR_BASEADDR_SDIO, PWR_CMD_POLLING, BIT(1), BIT(1)},            \
        /*wait power state to suspend*/                                 \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT3|BIT4, 0},                 \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(3) | BIT(4), 0},           \
        /*0x04[12:11] = 2b'01enable WL suspend*/
 
 #define RTL8188E_TRANS_CARDEMU_TO_PDN                                  \
         * comments here
         */                                                             \
        {0x0006, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0, 0},                      \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},                    \
        /* 0x04[16] = 0*/                                               \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT7, BIT7},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), BIT(7)},               \
        /* 0x04[15] = 1*/
 
 #define RTL8188E_TRANS_PDN_TO_CARDEMU                                  \
         * comments here
         */                                                             \
        {0x0005, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT7, 0},                      \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(7), 0},                    \
        /* 0x04[15] = 0*/
 
 /* This is used by driver for LPSRadioOff Procedure, not for FW LPS Step */
        PWR_BASEADDR_MAC, PWR_CMD_POLLING, 0xFF, 0},                    \
        /*Should be zero if no packet is transmitting*/                 \
        {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT0, 0},                      \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(0), 0},                    \
        /*CCK and OFDM are disabled,and clock are gated*/               \
        {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
        PWR_BASEADDR_MAC, PWR_CMD_DELAY, 0,                             \
        {0x0100, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
        PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0x3F},/*Reset MAC TRX*/  \
        {0x0101, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT1, 0},/*check if removed later*/\
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), 0},/*check if removed later*/\
        {0x0553, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT5, BIT5},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(5), BIT(5)},               \
        /*Respond TxOK to scheduler*/
 
 
        {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
        PWR_BASEADDR_MAC, PWR_CMD_DELAY, 0, PWRSEQ_DELAY_MS}, /*Delay*/ \
        {0x0008, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT4, 0},                      \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(4), 0},                    \
        /* 0x08[4] = 0 switch TSF to 40M */                             \
        {0x0109, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT7, 0},                    \
+       PWR_BASEADDR_MAC, PWR_CMD_POLLING, BIT(7), 0},                  \
        /* Polling 0x109[7]=0  TSF in 40M */                            \
        {0x0029, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT6|BIT7, 0},                 \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(6) | BIT(7), 0},           \
        /* 0x29[7:6] = 2b'00  enable BB clock */                        \
        {0x0101, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT1, BIT1},                   \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1), BIT(1)},               \
        /* 0x101[1] = 1 */                                              \
        {0x0100, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
        PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0xFF},                   \
        /* 0x100[7:0] = 0xFF enable WMAC TRX */                         \
        {0x0002, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
-       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT1|BIT0, BIT1|BIT0},         \
+       PWR_BASEADDR_MAC, PWR_CMD_WRITE, BIT(1) | BIT(0), BIT(1) | BIT(0)}, \
        /* 0x02[1:0] = 2b'11 enable BB macro */                         \
        {0x0522, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_ALL_MSK,    \
        PWR_BASEADDR_MAC, PWR_CMD_WRITE, 0xFF, 0}, /*.  0x522 = 0*/
index 2c33eb30d31b3d296233514762ac7223c49c3f83..beeee4a6b0bcb897313634f51038c0e6c72932dc 100644 (file)
 #ifndef __RTL8188E_SPEC_H__
 #define __RTL8188E_SPEC_H__
 
-#ifndef BIT
-#define BIT(x)         (1 << (x))
-#endif
-
-#define BIT0   0x00000001
-#define BIT1   0x00000002
-#define BIT2   0x00000004
-#define BIT3   0x00000008
-#define BIT4   0x00000010
-#define BIT5   0x00000020
-#define BIT6   0x00000040
-#define BIT7   0x00000080
-#define BIT8   0x00000100
-#define BIT9   0x00000200
-#define BIT10  0x00000400
-#define BIT11  0x00000800
-#define BIT12  0x00001000
-#define BIT13  0x00002000
-#define BIT14  0x00004000
-#define BIT15  0x00008000
-#define BIT16  0x00010000
-#define BIT17  0x00020000
-#define BIT18  0x00040000
-#define BIT19  0x00080000
-#define BIT20  0x00100000
-#define BIT21  0x00200000
-#define BIT22  0x00400000
-#define BIT23  0x00800000
-#define BIT24  0x01000000
-#define BIT25  0x02000000
-#define BIT26  0x04000000
-#define BIT27  0x08000000
-#define BIT28  0x10000000
-#define BIT29  0x20000000
-#define BIT30  0x40000000
-#define BIT31  0x80000000
-
 /*        8192C Regsiter offset definition */
 
 #define                HAL_PS_TIMER_INT_DELAY  50      /*   50 microseconds */
 #define        MAX_MSS_DENSITY_1T              0x0A
 
 /*  EEPROM enable when set 1 */
-#define        CmdEEPROM_En                    BIT5
+#define        CmdEEPROM_En                    BIT(5)
 /*  System EEPROM select, 0: boot from E-FUSE, 1: The EEPROM used is 9346 */
-#define        CmdEERPOMSEL                    BIT4
-#define        Cmd9346CR_9356SEL               BIT4
+#define        CmdEERPOMSEL                    BIT(4)
+#define        Cmd9346CR_9356SEL               BIT(4)
 
 /*        8192C GPIO MUX Configuration Register (offset 0x40, 4 byte) */
 #define        GPIOSEL_GPIO                    0
-#define        GPIOSEL_ENBT                    BIT5
+#define        GPIOSEL_ENBT                    BIT(5)
 
 /*        8192C GPIO PIN Control Register (offset 0x44, 4 byte) */
 /*  GPIO pins input value */
 #define        GPIO_MOD                        (REG_GPIO_PIN_CTRL+3)
 
 /* 8723/8188E Host System Interrupt Mask Register (offset 0x58, 32 byte) */
-#define        HSIMR_GPIO12_0_INT_EN           BIT0
-#define        HSIMR_SPS_OCP_INT_EN            BIT5
-#define        HSIMR_RON_INT_EN                BIT6
-#define        HSIMR_PDN_INT_EN                BIT7
-#define        HSIMR_GPIO9_INT_EN              BIT25
+#define        HSIMR_GPIO12_0_INT_EN           BIT(0)
+#define        HSIMR_SPS_OCP_INT_EN            BIT(5)
+#define        HSIMR_RON_INT_EN                BIT(6)
+#define        HSIMR_PDN_INT_EN                BIT(7)
+#define        HSIMR_GPIO9_INT_EN              BIT(25)
 
 /* 8723/8188E Host System Interrupt Status Register (offset 0x5C, 32 byte) */
-#define        HSISR_GPIO12_0_INT              BIT0
-#define        HSISR_SPS_OCP_INT               BIT5
-#define        HSISR_RON_INT_EN                BIT6
-#define        HSISR_PDNINT                    BIT7
-#define        HSISR_GPIO9_INT                 BIT25
+#define        HSISR_GPIO12_0_INT              BIT(0)
+#define        HSISR_SPS_OCP_INT               BIT(5)
+#define        HSISR_RON_INT_EN                BIT(6)
+#define        HSISR_PDNINT                    BIT(7)
+#define        HSISR_GPIO9_INT                 BIT(25)
 
 /*   8192C (MSR) Media Status Register (Offset 0x4C, 8 bits) */
 /*
@@ -537,51 +500,51 @@ Default: 00b.
 
 /*  88E Driver Initialization Offload REG_FDHM0(Offset 0x88, 8 bits) */
 /* IOL config for REG_FDHM0(Reg0x88) */
-#define CMD_INIT_LLT                   BIT0
-#define CMD_READ_EFUSE_MAP             BIT1
-#define CMD_EFUSE_PATCH                        BIT2
-#define CMD_IOCONFIG                   BIT3
-#define CMD_INIT_LLT_ERR               BIT4
-#define CMD_READ_EFUSE_MAP_ERR         BIT5
-#define CMD_EFUSE_PATCH_ERR            BIT6
-#define CMD_IOCONFIG_ERR               BIT7
+#define CMD_INIT_LLT                   BIT(0)
+#define CMD_READ_EFUSE_MAP             BIT(1)
+#define CMD_EFUSE_PATCH                        BIT(2)
+#define CMD_IOCONFIG                   BIT(3)
+#define CMD_INIT_LLT_ERR               BIT(4)
+#define CMD_READ_EFUSE_MAP_ERR         BIT(5)
+#define CMD_EFUSE_PATCH_ERR            BIT(6)
+#define CMD_IOCONFIG_ERR               BIT(7)
 
 /*  6. Adaptive Control Registers  (Offset: 0x0160 - 0x01CF) */
 /*  8192C Response Rate Set Register   (offset 0x181, 24bits) */
-#define        RRSR_1M                         BIT0
-#define        RRSR_2M                         BIT1
-#define        RRSR_5_5M                       BIT2
-#define        RRSR_11M                        BIT3
-#define        RRSR_6M                         BIT4
-#define        RRSR_9M                         BIT5
-#define        RRSR_12M                        BIT6
-#define        RRSR_18M                        BIT7
-#define        RRSR_24M                        BIT8
-#define        RRSR_36M                        BIT9
-#define        RRSR_48M                        BIT10
-#define        RRSR_54M                        BIT11
-#define        RRSR_MCS0                       BIT12
-#define        RRSR_MCS1                       BIT13
-#define        RRSR_MCS2                       BIT14
-#define        RRSR_MCS3                       BIT15
-#define        RRSR_MCS4                       BIT16
-#define        RRSR_MCS5                       BIT17
-#define        RRSR_MCS6                       BIT18
-#define        RRSR_MCS7                       BIT19
+#define        RRSR_1M                         BIT(0)
+#define        RRSR_2M                         BIT(1)
+#define        RRSR_5_5M                       BIT(2)
+#define        RRSR_11M                        BIT(3)
+#define        RRSR_6M                         BIT(4)
+#define        RRSR_9M                         BIT(5)
+#define        RRSR_12M                        BIT(6)
+#define        RRSR_18M                        BIT(7)
+#define        RRSR_24M                        BIT(8)
+#define        RRSR_36M                        BIT(9)
+#define        RRSR_48M                        BIT(10)
+#define        RRSR_54M                        BIT(11)
+#define        RRSR_MCS0                       BIT(12)
+#define        RRSR_MCS1                       BIT(13)
+#define        RRSR_MCS2                       BIT(14)
+#define        RRSR_MCS3                       BIT(15)
+#define        RRSR_MCS4                       BIT(16)
+#define        RRSR_MCS5                       BIT(17)
+#define        RRSR_MCS6                       BIT(18)
+#define        RRSR_MCS7                       BIT(19)
 
 /*  8192C Response Rate Set Register   (offset 0x1BF, 8bits) */
 /*  WOL bit information */
-#define        HAL92C_WOL_PTK_UPDATE_EVENT     BIT0
-#define        HAL92C_WOL_GTK_UPDATE_EVENT     BIT1
+#define        HAL92C_WOL_PTK_UPDATE_EVENT     BIT(0)
+#define        HAL92C_WOL_GTK_UPDATE_EVENT     BIT(1)
 
 /*        8192C BW_OPMODE bits         (Offset 0x203, 8bit) */
-#define        BW_OPMODE_20MHZ                 BIT2
-#define        BW_OPMODE_5G                    BIT1
+#define        BW_OPMODE_20MHZ                 BIT(2)
+#define        BW_OPMODE_5G                    BIT(1)
 
 /*        8192C CAM Config Setting (offset 0x250, 1 byte) */
-#define        CAM_VALID                       BIT15
+#define        CAM_VALID                       BIT(15)
 #define        CAM_NOTVALID                    0x0000
-#define        CAM_USEDK                       BIT5
+#define        CAM_USEDK                       BIT(5)
 
 #define        CAM_CONTENT_COUNT               8
 
@@ -598,69 +561,69 @@ Default: 00b.
 #define        CAM_CONFIG_USEDK                true
 #define        CAM_CONFIG_NO_USEDK             false
 
-#define        CAM_WRITE                       BIT16
+#define        CAM_WRITE                       BIT(16)
 #define        CAM_READ                        0x00000000
-#define        CAM_POLLINIG                    BIT31
+#define        CAM_POLLINIG                    BIT(31)
 
 #define        SCR_UseDK                       0x01
 #define        SCR_TxSecEnable                 0x02
 #define        SCR_RxSecEnable                 0x04
 
 /*  10. Power Save Control Registers    (Offset: 0x0260 - 0x02DF) */
-#define        WOW_PMEN                        BIT0 /*  Power management Enable. */
-#define        WOW_WOMEN                       BIT1 /*  WoW function on or off. */
-#define        WOW_MAGIC                       BIT2 /*  Magic packet */
-#define        WOW_UWF                         BIT3 /*  Unicast Wakeup frame. */
+#define        WOW_PMEN                        BIT(0) /*  Power management Enable. */
+#define        WOW_WOMEN                       BIT(1) /*  WoW function on or off. */
+#define        WOW_MAGIC                       BIT(2) /*  Magic packet */
+#define        WOW_UWF                         BIT(3) /*  Unicast Wakeup frame. */
 
 /*  12. Host Interrupt Status Registers         (Offset: 0x0300 - 0x030F) */
 /*        8188 IMR/ISR bits */
 #define        IMR_DISABLED_88E                0x0
 /*  IMR DW0(0x0060-0063) Bit 0-31 */
-#define        IMR_TXCCK_88E                   BIT30   /*  TXRPT interrupt when CCX bit of the packet is set */
-#define        IMR_PSTIMEOUT_88E               BIT29   /*  Power Save Time Out Interrupt */
-#define        IMR_GTINT4_88E                  BIT28   /*  When GTIMER4 expires, this bit is set to 1 */
-#define        IMR_GTINT3_88E                  BIT27   /*  When GTIMER3 expires, this bit is set to 1 */
-#define        IMR_TBDER_88E                   BIT26   /*  Transmit Beacon0 Error */
-#define        IMR_TBDOK_88E                   BIT25   /*  Transmit Beacon0 OK */
-#define        IMR_TSF_BIT32_TOGGLE_88E        BIT24   /*  TSF Timer BIT32 toggle indication interrupt */
-#define        IMR_BCNDMAINT0_88E              BIT20   /*  Beacon DMA Interrupt 0 */
-#define        IMR_BCNDERR0_88E                BIT16   /*  Beacon Queue DMA Error 0 */
-#define        IMR_HSISR_IND_ON_INT_88E        BIT15   /*  HSISR Indicator (HSIMR & HSISR is true, this bit is set to 1) */
-#define        IMR_BCNDMAINT_E_88E             BIT14   /*  Beacon DMA Interrupt Extension for Win7 */
-#define        IMR_ATIMEND_88E                 BIT12   /*  CTWidnow End or ATIM Window End */
-#define        IMR_HISR1_IND_INT_88E           BIT11   /*  HISR1 Indicator (HISR1 & HIMR1 is true, this bit is set to 1) */
-#define        IMR_C2HCMD_88E                  BIT10   /*  CPU to Host Command INT Status, Write 1 clear */
-#define        IMR_CPWM2_88E                   BIT9    /*  CPU power Mode exchange INT Status, Write 1 clear */
-#define        IMR_CPWM_88E                    BIT8    /*  CPU power Mode exchange INT Status, Write 1 clear */
-#define        IMR_HIGHDOK_88E                 BIT7    /*  High Queue DMA OK */
-#define        IMR_MGNTDOK_88E                 BIT6    /*  Management Queue DMA OK */
-#define        IMR_BKDOK_88E                   BIT5    /*  AC_BK DMA OK */
-#define        IMR_BEDOK_88E                   BIT4    /*  AC_BE DMA OK */
-#define        IMR_VIDOK_88E                   BIT3    /*  AC_VI DMA OK */
-#define        IMR_VODOK_88E                   BIT2    /*  AC_VO DMA OK */
-#define        IMR_RDU_88E                     BIT1    /*  Rx Descriptor Unavailable */
-#define        IMR_ROK_88E                     BIT0    /*  Receive DMA OK */
+#define        IMR_TXCCK_88E                   BIT(30) /*  TXRPT interrupt when CCX bit of the packet is set */
+#define        IMR_PSTIMEOUT_88E               BIT(29) /*  Power Save Time Out Interrupt */
+#define        IMR_GTINT4_88E                  BIT(28) /*  When GTIMER4 expires, this bit is set to 1 */
+#define        IMR_GTINT3_88E                  BIT(27) /*  When GTIMER3 expires, this bit is set to 1 */
+#define        IMR_TBDER_88E                   BIT(26) /*  Transmit Beacon0 Error */
+#define        IMR_TBDOK_88E                   BIT(25) /*  Transmit Beacon0 OK */
+#define        IMR_TSF_BIT32_TOGGLE_88E        BIT(24) /*  TSF Timer BIT32 toggle indication interrupt */
+#define        IMR_BCNDMAINT0_88E              BIT(20) /*  Beacon DMA Interrupt 0 */
+#define        IMR_BCNDERR0_88E                BIT(16) /*  Beacon Queue DMA Error 0 */
+#define        IMR_HSISR_IND_ON_INT_88E        BIT(15) /*  HSISR Indicator (HSIMR & HSISR is true, this bit is set to 1) */
+#define        IMR_BCNDMAINT_E_88E             BIT(14) /*  Beacon DMA Interrupt Extension for Win7 */
+#define        IMR_ATIMEND_88E                 BIT(12) /*  CTWidnow End or ATIM Window End */
+#define        IMR_HISR1_IND_INT_88E           BIT(11) /*  HISR1 Indicator (HISR1 & HIMR1 is true, this bit is set to 1) */
+#define        IMR_C2HCMD_88E                  BIT(10) /*  CPU to Host Command INT Status, Write 1 clear */
+#define        IMR_CPWM2_88E                   BIT(9)  /*  CPU power Mode exchange INT Status, Write 1 clear */
+#define        IMR_CPWM_88E                    BIT(8)  /*  CPU power Mode exchange INT Status, Write 1 clear */
+#define        IMR_HIGHDOK_88E                 BIT(7)  /*  High Queue DMA OK */
+#define        IMR_MGNTDOK_88E                 BIT(6)  /*  Management Queue DMA OK */
+#define        IMR_BKDOK_88E                   BIT(5)  /*  AC_BK DMA OK */
+#define        IMR_BEDOK_88E                   BIT(4)  /*  AC_BE DMA OK */
+#define        IMR_VIDOK_88E                   BIT(3)  /*  AC_VI DMA OK */
+#define        IMR_VODOK_88E                   BIT(2)  /*  AC_VO DMA OK */
+#define        IMR_RDU_88E                     BIT(1)  /*  Rx Descriptor Unavailable */
+#define        IMR_ROK_88E                     BIT(0)  /*  Receive DMA OK */
 
 /*  IMR DW1(0x00B4-00B7) Bit 0-31 */
-#define        IMR_BCNDMAINT7_88E              BIT27   /*  Beacon DMA Interrupt 7 */
-#define        IMR_BCNDMAINT6_88E              BIT26   /*  Beacon DMA Interrupt 6 */
-#define        IMR_BCNDMAINT5_88E              BIT25   /*  Beacon DMA Interrupt 5 */
-#define        IMR_BCNDMAINT4_88E              BIT24   /*  Beacon DMA Interrupt 4 */
-#define        IMR_BCNDMAINT3_88E              BIT23   /*  Beacon DMA Interrupt 3 */
-#define        IMR_BCNDMAINT2_88E              BIT22   /*  Beacon DMA Interrupt 2 */
-#define        IMR_BCNDMAINT1_88E              BIT21   /*  Beacon DMA Interrupt 1 */
-#define        IMR_BCNDERR7_88E                BIT20   /*  Beacon DMA Error Int 7 */
-#define        IMR_BCNDERR6_88E                BIT19   /*  Beacon DMA Error Int 6 */
-#define        IMR_BCNDERR5_88E                BIT18   /*  Beacon DMA Error Int 5 */
-#define        IMR_BCNDERR4_88E                BIT17   /*  Beacon DMA Error Int 4 */
-#define        IMR_BCNDERR3_88E                BIT16   /*  Beacon DMA Error Int 3 */
-#define        IMR_BCNDERR2_88E                BIT15   /*  Beacon DMA Error Int 2 */
-#define        IMR_BCNDERR1_88E                BIT14   /*  Beacon DMA Error Int 1 */
-#define        IMR_ATIMEND_E_88E               BIT13   /*  ATIM Window End Ext for Win7 */
-#define        IMR_TXERR_88E                   BIT11   /*  Tx Err Flag Int Status, write 1 clear. */
-#define        IMR_RXERR_88E                   BIT10   /*  Rx Err Flag INT Status, Write 1 clear */
-#define        IMR_TXFOVW_88E                  BIT9    /*  Transmit FIFO Overflow */
-#define        IMR_RXFOVW_88E                  BIT8    /*  Receive FIFO Overflow */
+#define        IMR_BCNDMAINT7_88E              BIT(27) /*  Beacon DMA Interrupt 7 */
+#define        IMR_BCNDMAINT6_88E              BIT(26) /*  Beacon DMA Interrupt 6 */
+#define        IMR_BCNDMAINT5_88E              BIT(25) /*  Beacon DMA Interrupt 5 */
+#define        IMR_BCNDMAINT4_88E              BIT(24) /*  Beacon DMA Interrupt 4 */
+#define        IMR_BCNDMAINT3_88E              BIT(23) /*  Beacon DMA Interrupt 3 */
+#define        IMR_BCNDMAINT2_88E              BIT(22) /*  Beacon DMA Interrupt 2 */
+#define        IMR_BCNDMAINT1_88E              BIT(21) /*  Beacon DMA Interrupt 1 */
+#define        IMR_BCNDERR7_88E                BIT(20) /*  Beacon DMA Error Int 7 */
+#define        IMR_BCNDERR6_88E                BIT(19) /*  Beacon DMA Error Int 6 */
+#define        IMR_BCNDERR5_88E                BIT(18) /*  Beacon DMA Error Int 5 */
+#define        IMR_BCNDERR4_88E                BIT(17) /*  Beacon DMA Error Int 4 */
+#define        IMR_BCNDERR3_88E                BIT(16) /*  Beacon DMA Error Int 3 */
+#define        IMR_BCNDERR2_88E                BIT(15) /*  Beacon DMA Error Int 2 */
+#define        IMR_BCNDERR1_88E                BIT(14) /*  Beacon DMA Error Int 1 */
+#define        IMR_ATIMEND_E_88E               BIT(13) /*  ATIM Window End Ext for Win7 */
+#define        IMR_TXERR_88E                   BIT(11) /*  Tx Err Flag Int Status, write 1 clear. */
+#define        IMR_RXERR_88E                   BIT(10) /*  Rx Err Flag INT Status, Write 1 clear */
+#define        IMR_TXFOVW_88E                  BIT(9)  /*  Transmit FIFO Overflow */
+#define        IMR_RXFOVW_88E                  BIT(8)  /*  Receive FIFO Overflow */
 
 #define        HAL_NIC_UNPLUG_ISR              0xFFFFFFFF      /*  The value when the NIC is unplugged for PCI. */
 
@@ -696,40 +659,40 @@ Current IOREG MAP
 /*     the correct arragement is VO - Bit0, VI - Bit1, BE - Bit2,
  *     and BK - Bit3. */
 /*     8723 and 88E may be not correct either in the earlier version. */
-#define                StopBecon                       BIT6
-#define                StopHigh                        BIT5
-#define                StopMgt                         BIT4
-#define                StopBK                          BIT3
-#define                StopBE                          BIT2
-#define                StopVI                          BIT1
-#define                StopVO                          BIT0
+#define                StopBecon                       BIT(6)
+#define                StopHigh                        BIT(5)
+#define                StopMgt                         BIT(4)
+#define                StopBK                          BIT(3)
+#define                StopBE                          BIT(2)
+#define                StopVI                          BIT(1)
+#define                StopVO                          BIT(0)
 
 /*        8192C (RCR) Receive Configuration Register(Offset 0x608, 32 bits) */
-#define        RCR_APPFCS              BIT31   /* WMAC append FCS after payload */
-#define        RCR_APP_MIC             BIT30
-#define        RCR_APP_PHYSTS          BIT28
-#define        RCR_APP_ICV             BIT29
-#define        RCR_APP_PHYST_RXFF      BIT28
-#define        RCR_APP_BA_SSN          BIT27   /* Accept BA SSN */
-#define        RCR_ENMBID              BIT24   /* Enable Multiple BssId. */
-#define        RCR_LSIGEN              BIT23
-#define        RCR_MFBEN               BIT22
-#define        RCR_HTC_LOC_CTRL        BIT14   /* MFC<--HTC=1 MFC-->HTC=0 */
-#define        RCR_AMF                 BIT13   /* Accept management type frame */
-#define        RCR_ACF                 BIT12   /* Accept control type frame */
-#define        RCR_ADF                 BIT11   /* Accept data type frame */
-#define        RCR_AICV                BIT9    /* Accept ICV error packet */
-#define        RCR_ACRC32              BIT8    /* Accept CRC32 error packet */
-#define        RCR_CBSSID_BCN          BIT7    /* Accept BSSID match packet
+#define        RCR_APPFCS              BIT(31) /* WMAC append FCS after payload */
+#define        RCR_APP_MIC             BIT(30)
+#define        RCR_APP_PHYSTS          BIT(28)
+#define        RCR_APP_ICV             BIT(29)
+#define        RCR_APP_PHYST_RXFF      BIT(28)
+#define        RCR_APP_BA_SSN          BIT(27) /* Accept BA SSN */
+#define        RCR_ENMBID              BIT(24) /* Enable Multiple BssId. */
+#define        RCR_LSIGEN              BIT(23)
+#define        RCR_MFBEN               BIT(22)
+#define        RCR_HTC_LOC_CTRL        BIT(14)   /* MFC<--HTC=1 MFC-->HTC=0 */
+#define        RCR_AMF                 BIT(13) /* Accept management type frame */
+#define        RCR_ACF                 BIT(12) /* Accept control type frame */
+#define        RCR_ADF                 BIT(11) /* Accept data type frame */
+#define        RCR_AICV                BIT(9)  /* Accept ICV error packet */
+#define        RCR_ACRC32              BIT(8)  /* Accept CRC32 error packet */
+#define        RCR_CBSSID_BCN          BIT(7)  /* Accept BSSID match packet
                                         * (Rx beacon, probe rsp) */
-#define        RCR_CBSSID_DATA         BIT6    /* Accept BSSID match (Data)*/
+#define        RCR_CBSSID_DATA         BIT(6)  /* Accept BSSID match (Data)*/
 #define        RCR_CBSSID              RCR_CBSSID_DATA /* Accept BSSID match */
-#define        RCR_APWRMGT             BIT5    /* Accept power management pkt*/
-#define        RCR_ADD3                BIT4    /* Accept address 3 match pkt */
-#define        RCR_AB                  BIT3    /* Accept broadcast packet */
-#define        RCR_AM                  BIT2    /* Accept multicast packet */
-#define        RCR_APM                 BIT1    /* Accept physical match pkt */
-#define        RCR_AAP                 BIT0    /* Accept all unicast packet */
+#define        RCR_APWRMGT             BIT(5)  /* Accept power management pkt*/
+#define        RCR_ADD3                BIT(4)  /* Accept address 3 match pkt */
+#define        RCR_AB                  BIT(3)  /* Accept broadcast packet */
+#define        RCR_AM                  BIT(2)  /* Accept multicast packet */
+#define        RCR_APM                 BIT(1)  /* Accept physical match pkt */
+#define        RCR_AAP                 BIT(0)  /* Accept all unicast packet */
 #define        RCR_MXDMA_OFFSET        8
 #define        RCR_FIFO_OFFSET         13
 
@@ -1197,56 +1160,56 @@ Current IOREG MAP
 #define SDIO_HIMR_DISABLED                     0
 
 /*  RTL8188E SDIO Host Interrupt Mask Register */
-#define SDIO_HIMR_RX_REQUEST_MSK               BIT0
-#define SDIO_HIMR_AVAL_MSK                     BIT1
-#define SDIO_HIMR_TXERR_MSK                    BIT2
-#define SDIO_HIMR_RXERR_MSK                    BIT3
-#define SDIO_HIMR_TXFOVW_MSK                   BIT4
-#define SDIO_HIMR_RXFOVW_MSK                   BIT5
-#define SDIO_HIMR_TXBCNOK_MSK                  BIT6
-#define SDIO_HIMR_TXBCNERR_MSK                 BIT7
-#define SDIO_HIMR_BCNERLY_INT_MSK              BIT16
-#define SDIO_HIMR_C2HCMD_MSK                   BIT17
-#define SDIO_HIMR_CPWM1_MSK                    BIT18
-#define SDIO_HIMR_CPWM2_MSK                    BIT19
-#define SDIO_HIMR_HSISR_IND_MSK                        BIT20
-#define SDIO_HIMR_GTINT3_IND_MSK               BIT21
-#define SDIO_HIMR_GTINT4_IND_MSK               BIT22
-#define SDIO_HIMR_PSTIMEOUT_MSK                        BIT23
-#define SDIO_HIMR_OCPINT_MSK                   BIT24
-#define SDIO_HIMR_ATIMEND_MSK                  BIT25
-#define SDIO_HIMR_ATIMEND_E_MSK                        BIT26
-#define SDIO_HIMR_CTWEND_MSK                   BIT27
+#define SDIO_HIMR_RX_REQUEST_MSK               BIT(0)
+#define SDIO_HIMR_AVAL_MSK                     BIT(1)
+#define SDIO_HIMR_TXERR_MSK                    BIT(2)
+#define SDIO_HIMR_RXERR_MSK                    BIT(3)
+#define SDIO_HIMR_TXFOVW_MSK                   BIT(4)
+#define SDIO_HIMR_RXFOVW_MSK                   BIT(5)
+#define SDIO_HIMR_TXBCNOK_MSK                  BIT(6)
+#define SDIO_HIMR_TXBCNERR_MSK                 BIT(7)
+#define SDIO_HIMR_BCNERLY_INT_MSK              BIT(16)
+#define SDIO_HIMR_C2HCMD_MSK                   BIT(17)
+#define SDIO_HIMR_CPWM1_MSK                    BIT(18)
+#define SDIO_HIMR_CPWM2_MSK                    BIT(19)
+#define SDIO_HIMR_HSISR_IND_MSK                        BIT(20)
+#define SDIO_HIMR_GTINT3_IND_MSK               BIT(21)
+#define SDIO_HIMR_GTINT4_IND_MSK               BIT(22)
+#define SDIO_HIMR_PSTIMEOUT_MSK                        BIT(23)
+#define SDIO_HIMR_OCPINT_MSK                   BIT(24)
+#define SDIO_HIMR_ATIMEND_MSK                  BIT(25)
+#define SDIO_HIMR_ATIMEND_E_MSK                        BIT(26)
+#define SDIO_HIMR_CTWEND_MSK                   BIT(27)
 
 /* RTL8188E SDIO Specific */
-#define        SDIO_HIMR_MCU_ERR_MSK                   BIT28
-#define        SDIO_HIMR_TSF_BIT32_TOGGLE_MSK          BIT29
+#define        SDIO_HIMR_MCU_ERR_MSK                   BIT(28)
+#define        SDIO_HIMR_TSF_BIT32_TOGGLE_MSK          BIT(29)
 
 /*  SDIO Host Interrupt Service Routine */
-#define SDIO_HISR_RX_REQUEST                   BIT0
-#define SDIO_HISR_AVAL                         BIT1
-#define SDIO_HISR_TXERR                                BIT2
-#define SDIO_HISR_RXERR                                BIT3
-#define SDIO_HISR_TXFOVW                       BIT4
-#define SDIO_HISR_RXFOVW                       BIT5
-#define SDIO_HISR_TXBCNOK                      BIT6
-#define SDIO_HISR_TXBCNERR                     BIT7
-#define SDIO_HISR_BCNERLY_INT                  BIT16
-#define SDIO_HISR_C2HCMD                       BIT17
-#define SDIO_HISR_CPWM1                                BIT18
-#define SDIO_HISR_CPWM2                                BIT19
-#define SDIO_HISR_HSISR_IND                    BIT20
-#define SDIO_HISR_GTINT3_IND                   BIT21
-#define SDIO_HISR_GTINT4_IND                   BIT22
-#define SDIO_HISR_PSTIME                       BIT23
-#define SDIO_HISR_OCPINT                       BIT24
-#define SDIO_HISR_ATIMEND                      BIT25
-#define SDIO_HISR_ATIMEND_E                    BIT26
-#define SDIO_HISR_CTWEND                       BIT27
+#define SDIO_HISR_RX_REQUEST                   BIT(0)
+#define SDIO_HISR_AVAL                         BIT(1)
+#define SDIO_HISR_TXERR                                BIT(2)
+#define SDIO_HISR_RXERR                                BIT(3)
+#define SDIO_HISR_TXFOVW                       BIT(4)
+#define SDIO_HISR_RXFOVW                       BIT(5)
+#define SDIO_HISR_TXBCNOK                      BIT(6)
+#define SDIO_HISR_TXBCNERR                     BIT(7)
+#define SDIO_HISR_BCNERLY_INT                  BIT(16)
+#define SDIO_HISR_C2HCMD                       BIT(17)
+#define SDIO_HISR_CPWM1                                BIT(18)
+#define SDIO_HISR_CPWM2                                BIT(19)
+#define SDIO_HISR_HSISR_IND                    BIT(20)
+#define SDIO_HISR_GTINT3_IND                   BIT(21)
+#define SDIO_HISR_GTINT4_IND                   BIT(22)
+#define SDIO_HISR_PSTIME                       BIT(23)
+#define SDIO_HISR_OCPINT                       BIT(24)
+#define SDIO_HISR_ATIMEND                      BIT(25)
+#define SDIO_HISR_ATIMEND_E                    BIT(26)
+#define SDIO_HISR_CTWEND                       BIT(27)
 
 /* RTL8188E SDIO Specific */
-#define        SDIO_HISR_MCU_ERR                       BIT28
-#define        SDIO_HISR_TSF_BIT32_TOGGLE              BIT29
+#define        SDIO_HISR_MCU_ERR                       BIT(28)
+#define        SDIO_HISR_TSF_BIT32_TOGGLE              BIT(29)
 
 #define MASK_SDIO_HISR_CLEAR                           \
        (SDIO_HISR_TXERR | SDIO_HISR_RXERR | SDIO_HISR_TXFOVW |\
@@ -1256,8 +1219,8 @@ Current IOREG MAP
         SDIO_HISR_PSTIMEOUT | SDIO_HISR_OCPINT)
 
 /*  SDIO HCI Suspend Control Register */
-#define HCI_RESUME_PWR_RDY             BIT1
-#define HCI_SUS_CTRL                   BIT0
+#define HCI_RESUME_PWR_RDY             BIT(1)
+#define HCI_SUS_CTRL                   BIT(0)
 
 /*  SDIO Tx FIFO related */
 /*  The number of Tx FIFO free page */
@@ -1291,33 +1254,33 @@ Current IOREG MAP
 
 /* 2REG_MULTI_FUNC_CTRL(For RTL8723 Only) */
 /*  Enable GPIO[9] as WiFi HW PDn source */
-#define        WL_HWPDN_EN                             BIT0
+#define        WL_HWPDN_EN                             BIT(0)
 /*  WiFi HW PDn polarity control */
-#define        WL_HWPDN_SL                             BIT1
+#define        WL_HWPDN_SL                             BIT(1)
 /*  WiFi function enable */
-#define        WL_FUNC_EN                              BIT2
+#define        WL_FUNC_EN                              BIT(2)
 /*  Enable GPIO[9] as WiFi RF HW PDn source */
-#define        WL_HWROF_EN                             BIT3
+#define        WL_HWROF_EN                             BIT(3)
 /*  Enable GPIO[11] as BT HW PDn source */
-#define        BT_HWPDN_EN                             BIT16
+#define        BT_HWPDN_EN                             BIT(16)
 /*  BT HW PDn polarity control */
-#define        BT_HWPDN_SL                             BIT17
+#define        BT_HWPDN_SL                             BIT(17)
 /*  BT function enable */
-#define        BT_FUNC_EN                              BIT18
+#define        BT_FUNC_EN                              BIT(18)
 /*  Enable GPIO[11] as BT/GPS RF HW PDn source */
-#define        BT_HWROF_EN                             BIT19
+#define        BT_HWROF_EN                             BIT(19)
 /*  Enable GPIO[10] as GPS HW PDn source */
-#define        GPS_HWPDN_EN                            BIT20
+#define        GPS_HWPDN_EN                            BIT(20)
 /*  GPS HW PDn polarity control */
-#define        GPS_HWPDN_SL                            BIT21
+#define        GPS_HWPDN_SL                            BIT(21)
 /*  GPS function enable */
-#define        GPS_FUNC_EN                             BIT22
+#define        GPS_FUNC_EN                             BIT(22)
 
 /* 3 REG_LIFECTRL_CTRL */
-#define        HAL92C_EN_PKT_LIFE_TIME_BK              BIT3
-#define        HAL92C_EN_PKT_LIFE_TIME_BE              BIT2
-#define        HAL92C_EN_PKT_LIFE_TIME_VI              BIT1
-#define        HAL92C_EN_PKT_LIFE_TIME_VO              BIT0
+#define        HAL92C_EN_PKT_LIFE_TIME_BK              BIT(3)
+#define        HAL92C_EN_PKT_LIFE_TIME_BE              BIT(2)
+#define        HAL92C_EN_PKT_LIFE_TIME_VI              BIT(1)
+#define        HAL92C_EN_PKT_LIFE_TIME_VO              BIT(0)
 
 #define        HAL92C_MSDU_LIFE_TIME_UNIT              128     /*  in us */
 
@@ -1327,7 +1290,7 @@ Current IOREG MAP
 #define POLLING_LLT_THRESHOLD                  20
 #define POLLING_READY_TIMEOUT_COUNT            1000
 /*  GPIO BIT */
-#define        HAL_8192C_HW_GPIO_WPS_BIT               BIT2
+#define        HAL_8192C_HW_GPIO_WPS_BIT               BIT(2)
 
 /*     8192C EEPROM/EFUSE share register definition. */
 
index abe7e21e6e2014c3a084b025e69ee44a883cc086..a1aebe6c8452c353b273aff24bb02a66acac348b 100644 (file)
@@ -336,9 +336,6 @@ static const unsigned long K[64] = {
 #define Sigma1(x)       (S(x, 6) ^ S(x, 11) ^ S(x, 25))
 #define Gamma0(x)       (S(x, 7) ^ S(x, 18) ^ R(x, 3))
 #define Gamma1(x)       (S(x, 17) ^ S(x, 19) ^ R(x, 10))
-#ifndef MIN
-#define MIN(x, y) (((x) < (y)) ? (x) : (y))
-#endif
 
 void rtw_secmicsetkey(struct mic_data *pmicdata, u8 *key);
 void rtw_secmicappendbyte(struct mic_data *pmicdata, u8 b);
index 580e850511a739b9cdf101a96104746a47bca927..3a62ed0108754f84d865cff0d68698ab0a7f1330 100644 (file)
@@ -30,13 +30,13 @@ struct sreset_priv {
 #include <rtl8188e_hal.h>
 
 #define        WIFI_STATUS_SUCCESS             0
-#define        USB_VEN_REQ_CMD_FAIL    BIT0
-#define        USB_READ_PORT_FAIL              BIT1
-#define        USB_WRITE_PORT_FAIL             BIT2
-#define        WIFI_MAC_TXDMA_ERROR    BIT3
-#define   WIFI_TX_HANG                         BIT4
-#define        WIFI_RX_HANG                            BIT5
-#define                WIFI_IF_NOT_EXIST                       BIT6
+#define        USB_VEN_REQ_CMD_FAIL            BIT(0)
+#define        USB_READ_PORT_FAIL              BIT(1)
+#define        USB_WRITE_PORT_FAIL             BIT(2)
+#define        WIFI_MAC_TXDMA_ERROR            BIT(3)
+#define   WIFI_TX_HANG                 BIT(4)
+#define        WIFI_RX_HANG                    BIT(5)
+#define                WIFI_IF_NOT_EXIST       BIT(6)
 
 void sreset_init_value(struct adapter *padapter);
 u8 sreset_get_wifi_status(struct adapter *padapter);
index dba8af1ec41e183c8faf5f6973bc5899a4b2a1e0..6cb5beca1672e9de851b0ac56bc8ddd63759966c 100644 (file)
 #ifndef _WIFI_H_
 #define _WIFI_H_
 
-
-#ifdef BIT
-/* error       "BIT define occurred earlier elsewhere!\n" */
-#undef BIT
-#endif
-#define BIT(x) (1 << (x))
-
-
-#define WLAN_ETHHDR_LEN                14
-#define WLAN_ETHADDR_LEN       6
 #define WLAN_IEEE_OUI_LEN      3
-#define WLAN_ADDR_LEN          6
 #define WLAN_CRC_LEN           4
 #define WLAN_BSSID_LEN         6
 #define WLAN_BSS_TS_LEN                8
@@ -47,7 +36,6 @@
 
 #define WLAN_MIN_ETHFRM_LEN    60
 #define WLAN_MAX_ETHFRM_LEN    1514
-#define WLAN_ETHHDR_LEN                14
 
 #define P80211CAPTURE_VERSION  0x80211001
 
index 969574926e21c939defa1e0967a614afeef0421a..a076ede50b2245003e4d41d9f3e054fe7d031d8e 100644 (file)
@@ -457,7 +457,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                                        psta->dot118021XPrivacy = padapter->securitypriv.dot11PrivacyAlgrthm;
 
                                if (param->u.crypt.set_tx == 1) { /* pairwise key */
-                                       memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                       memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                        if (strcmp(param->u.crypt.alg, "TKIP") == 0) { /* set mic key */
                                                memcpy(psta->dot11tkiptxmickey.skey, &(param->u.crypt.key[16]), 8);
@@ -469,7 +469,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
 
                                        rtw_setstakey_cmd(padapter, (unsigned char *)psta, true);
                                } else { /* group key */
-                                       memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                       memcpy(padapter->securitypriv.dot118021XGrpKey[param->u.crypt.idx].skey,  param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16 ));
                                        memcpy(padapter->securitypriv.dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
                                        memcpy(padapter->securitypriv.dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
                                        padapter->securitypriv.binstallGrpkey = true;
@@ -604,7 +604,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie
                                if ((eid == _VENDOR_SPECIFIC_IE_) && (!memcmp(&buf[cnt+2], wps_oui, 4))) {
                                        DBG_88E("SET WPS_IE\n");
 
-                                       padapter->securitypriv.wps_ie_len = ((buf[cnt+1]+2) < (MAX_WPA_IE_LEN<<2)) ? (buf[cnt+1]+2) : (MAX_WPA_IE_LEN<<2);
+                                       padapter->securitypriv.wps_ie_len = min(buf[cnt + 1] + 2, MAX_WPA_IE_LEN << 2);
 
                                        memcpy(padapter->securitypriv.wps_ie, &buf[cnt], padapter->securitypriv.wps_ie_len);
 
@@ -1321,7 +1321,7 @@ static int rtw_wx_set_essid(struct net_device *dev,
        authmode = padapter->securitypriv.ndisauthtype;
        DBG_88E("=>%s\n", __func__);
        if (wrqu->essid.flags && wrqu->essid.length) {
-               len = (wrqu->essid.length < IW_ESSID_MAX_SIZE) ? wrqu->essid.length : IW_ESSID_MAX_SIZE;
+               len = min_t(uint, wrqu->essid.length, IW_ESSID_MAX_SIZE);
 
                if (wrqu->essid.length != 33)
                        DBG_88E("ssid =%s, len =%d\n", extra, wrqu->essid.length);
@@ -2335,7 +2335,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                DBG_88E("%s, set group_key, WEP\n", __func__);
 
                                memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                           param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                           param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
                                if (param->u.crypt.key_len == 13)
@@ -2344,7 +2344,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                DBG_88E("%s, set group_key, TKIP\n", __func__);
                                psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
                                memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                           param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                           param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                                /* set mic key */
                                memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
                                memcpy(psecuritypriv->dot118021XGrprxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[24]), 8);
@@ -2354,7 +2354,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                DBG_88E("%s, set group_key, CCMP\n", __func__);
                                psecuritypriv->dot118021XGrpPrivacy = _AES_;
                                memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                           param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                           param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                        } else {
                                DBG_88E("%s, set group_key, none\n", __func__);
                                psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
@@ -2375,7 +2375,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
        if (psecuritypriv->dot11AuthAlgrthm == dot11AuthAlgrthm_8021X && psta) { /*  psk/802_1x */
                if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
                        if (param->u.crypt.set_tx == 1) {
-                               memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                               memcpy(psta->dot118021x_UncstKey.skey,  param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                if (strcmp(param->u.crypt.alg, "WEP") == 0) {
                                        DBG_88E("%s, set pairwise key, WEP\n", __func__);
@@ -2409,7 +2409,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                        } else { /* group key??? */
                                if (strcmp(param->u.crypt.alg, "WEP") == 0) {
                                        memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                                   param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                                   param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                                        psecuritypriv->dot118021XGrpPrivacy = _WEP40_;
                                        if (param->u.crypt.key_len == 13)
                                                psecuritypriv->dot118021XGrpPrivacy = _WEP104_;
@@ -2417,7 +2417,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                        psecuritypriv->dot118021XGrpPrivacy = _TKIP_;
 
                                        memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                                   param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                                   param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
 
                                        /* set mic key */
                                        memcpy(psecuritypriv->dot118021XGrptxmickey[param->u.crypt.idx].skey, &(param->u.crypt.key[16]), 8);
@@ -2428,7 +2428,7 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param,
                                        psecuritypriv->dot118021XGrpPrivacy = _AES_;
 
                                        memcpy(psecuritypriv->dot118021XGrpKey[param->u.crypt.idx].skey,
-                                                   param->u.crypt.key, (param->u.crypt.key_len > 16 ? 16 : param->u.crypt.key_len));
+                                                   param->u.crypt.key, min_t(u16, param->u.crypt.key_len, 16));
                                } else {
                                        psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
                                }
@@ -2669,7 +2669,7 @@ static int rtw_get_sta_wpaie(struct net_device *dev, struct ieee_param *param)
                        int copy_len;
 
                        wpa_ie_len = psta->wpa_ie[1];
-                       copy_len = ((wpa_ie_len+2) > sizeof(psta->wpa_ie)) ? (sizeof(psta->wpa_ie)) : (wpa_ie_len+2);
+                       copy_len = min_t(int, wpa_ie_len + 2, sizeof(psta->wpa_ie));
                        param->u.wpa_ie.len = copy_len;
                        memcpy(param->u.wpa_ie.reserved, psta->wpa_ie, copy_len);
                } else {
@@ -2974,7 +2974,7 @@ static int rtw_wx_set_priv(struct net_device *dev,
 
                if ((_VENDOR_SPECIFIC_IE_ == probereq_wpsie[0]) &&
                    (!memcmp(&probereq_wpsie[2], wps_oui, 4))) {
-                       cp_sz = probereq_wpsie_len > MAX_WPS_IE_LEN ? MAX_WPS_IE_LEN : probereq_wpsie_len;
+                       cp_sz = min(probereq_wpsie_len, MAX_WPS_IE_LEN);
 
                        pmlmepriv->wps_probe_req_ie_len = 0;
                        kfree(pmlmepriv->wps_probe_req_ie);
@@ -3091,7 +3091,7 @@ static struct iw_statistics *rtw_get_wireless_stats(struct net_device *dev)
 
 struct iw_handler_def rtw_handlers_def = {
        .standard = rtw_handlers,
-       .num_standard = sizeof(rtw_handlers) / sizeof(iw_handler),
+       .num_standard = ARRAY_SIZE(rtw_handlers),
        .get_wireless_stats = rtw_get_wireless_stats,
 };
 
index 218adaa574b58f2f2b8101bb7728f3d34af19d4b..08bfa76f4975cf61c49003cb4f918b2eba36d63a 100644 (file)
@@ -116,14 +116,13 @@ void rtw_report_sec_ie(struct adapter *adapter, u8 authmode, u8 *sec_ie)
                p = buff;
                p += sprintf(p, "ASSOCINFO(ReqIEs =");
                len = sec_ie[1]+2;
-               len =  (len < IW_CUSTOM_MAX) ? len : IW_CUSTOM_MAX;
+               len =  min_t(uint, len, IW_CUSTOM_MAX);
                for (i = 0; i < len; i++)
                        p += sprintf(p, "%02x", sec_ie[i]);
                p += sprintf(p, ")");
                memset(&wrqu, 0, sizeof(wrqu));
                wrqu.data.length = p-buff;
-               wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
-                                  wrqu.data.length : IW_CUSTOM_MAX;
+               wrqu.data.length = min_t(__u16, wrqu.data.length, IW_CUSTOM_MAX);
                wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
                kfree(buff);
        }
@@ -152,7 +151,7 @@ void rtw_indicate_sta_assoc_event(struct adapter *padapter, struct sta_info *pst
        union iwreq_data wrqu;
        struct sta_priv *pstapriv = &padapter->stapriv;
 
-       if (psta == NULL)
+       if (!psta)
                return;
 
        if (psta->aid > NUM_STA)
@@ -176,7 +175,7 @@ void rtw_indicate_sta_disassoc_event(struct adapter *padapter, struct sta_info *
        union iwreq_data wrqu;
        struct sta_priv *pstapriv = &padapter->stapriv;
 
-       if (psta == NULL)
+       if (!psta)
                return;
 
        if (psta->aid > NUM_STA)
diff --git a/drivers/staging/rtl8188eu/os_dep/mon.c b/drivers/staging/rtl8188eu/os_dep/mon.c
new file mode 100644 (file)
index 0000000..63bb875
--- /dev/null
@@ -0,0 +1,195 @@
+/*
+ * RTL8188EU monitor interface
+ *
+ * Copyright (C) 2015 Jakub Sitnicki
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ */
+
+#include <linux/ieee80211.h>
+#include <linux/netdevice.h>
+#include <net/cfg80211.h>
+
+#include <drv_types.h>
+#include <rtw_recv.h>
+#include <rtw_xmit.h>
+#include <mon.h>
+
+/**
+ * unprotect_frame() - unset Protected flag and strip off IV and ICV/MIC
+ */
+static void unprotect_frame(struct sk_buff *skb, int iv_len, int icv_len)
+{
+       struct ieee80211_hdr *hdr;
+       int hdr_len;
+
+       hdr = (struct ieee80211_hdr *)skb->data;
+       hdr_len = ieee80211_hdrlen(hdr->frame_control);
+
+       if (skb->len < hdr_len + iv_len + icv_len)
+               return;
+       if (!ieee80211_has_protected(hdr->frame_control))
+               return;
+
+       hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED);
+
+       memmove(skb->data + iv_len, skb->data, hdr_len);
+       skb_pull(skb, iv_len);
+       skb_trim(skb, skb->len - icv_len);
+}
+
+static void mon_recv_decrypted(struct net_device *dev, const u8 *data,
+                              int data_len, int iv_len, int icv_len)
+{
+       struct sk_buff *skb;
+
+       skb = netdev_alloc_skb(dev, data_len);
+       if (!skb)
+               return;
+       memcpy(skb_put(skb, data_len), data, data_len);
+
+       /*
+        * Frame data is not encrypted. Strip off protection so
+        * userspace doesn't think that it is.
+        */
+       unprotect_frame(skb, iv_len, icv_len);
+
+       skb->ip_summed = CHECKSUM_UNNECESSARY;
+       skb->protocol = eth_type_trans(skb, dev);
+       netif_rx(skb);
+}
+
+static void mon_recv_encrypted(struct net_device *dev, const u8 *data,
+                              int data_len)
+{
+       if (net_ratelimit())
+               netdev_info(dev, "Encrypted packets are not supported");
+}
+
+/**
+ * rtl88eu_mon_recv_hook() - forward received frame to the monitor interface
+ *
+ * Assumes that the frame contains an IV and an ICV/MIC, and that
+ * encrypt field in frame->attrib have been set accordingly.
+ */
+void rtl88eu_mon_recv_hook(struct net_device *dev, struct recv_frame *frame)
+{
+       struct rx_pkt_attrib *attr;
+       int iv_len, icv_len;
+       int data_len;
+       u8 *data;
+
+       if (!dev || !frame)
+               return;
+       if (!netif_running(dev))
+               return;
+
+       attr = &frame->attrib;
+       data = frame->rx_data;
+       data_len = frame->len;
+
+       /* Broadcast and multicast frames don't have attr->{iv,icv}_len set */
+       SET_ICE_IV_LEN(iv_len, icv_len, attr->encrypt);
+
+       if (attr->bdecrypted)
+               mon_recv_decrypted(dev, data, data_len, iv_len, icv_len);
+       else
+               mon_recv_encrypted(dev, data, data_len);
+}
+
+/**
+ * rtl88eu_mon_xmit_hook() - forward trasmitted frame to the monitor interface
+ *
+ * Assumes that:
+ * - frame header contains an IV and frame->attrib.iv_len is set accordingly,
+ * - data is not encrypted and ICV/MIC has not been appended yet.
+ */
+void rtl88eu_mon_xmit_hook(struct net_device *dev, struct xmit_frame *frame,
+                          uint frag_len)
+{
+       struct pkt_attrib *attr;
+       u8 *data;
+       int i, offset;
+
+       if (!dev || !frame)
+               return;
+       if (!netif_running(dev))
+               return;
+
+       attr = &frame->attrib;
+
+       offset = TXDESC_SIZE + frame->pkt_offset * PACKET_OFFSET_SZ;
+       data = frame->buf_addr + offset;
+
+       for (i = 0; i < attr->nr_frags - 1; i++) {
+               mon_recv_decrypted(dev, data, frag_len, attr->iv_len, 0);
+               data += frag_len;
+               data = (u8 *)round_up((size_t)data, 4);
+       }
+       /* Last fragment has different length */
+       mon_recv_decrypted(dev, data, attr->last_txcmdsz, attr->iv_len, 0);
+}
+
+static netdev_tx_t mon_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       dev_kfree_skb(skb);
+       return NETDEV_TX_OK;
+}
+
+static const struct net_device_ops mon_netdev_ops = {
+       .ndo_start_xmit         = mon_xmit,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+};
+
+static void mon_setup(struct net_device *dev)
+{
+       dev->netdev_ops = &mon_netdev_ops;
+       dev->destructor = free_netdev;
+       ether_setup(dev);
+       dev->tx_queue_len = 0;
+       dev->type = ARPHRD_IEEE80211;
+       /*
+        * Use a locally administered address (IEEE 802)
+        * XXX: Copied from mac80211_hwsim driver. Revisit.
+        */
+       eth_zero_addr(dev->dev_addr);
+       dev->dev_addr[0] = 0x12;
+}
+
+struct net_device *rtl88eu_mon_init(void)
+{
+       struct net_device *dev;
+       int err;
+
+       dev = alloc_netdev(0, "mon%d", NET_NAME_UNKNOWN, mon_setup);
+       if (!dev)
+               goto fail;
+
+       err = register_netdev(dev);
+       if (err < 0)
+               goto fail_free_dev;
+
+       return dev;
+
+fail_free_dev:
+       free_netdev(dev);
+fail:
+       return NULL;
+}
+
+void rtl88eu_mon_deinit(struct net_device *dev)
+{
+       if (!dev)
+               return;
+
+       unregister_netdev(dev);
+}
index 2361bce480c3fa51b1b9c4d81aaec8047a92e8e7..d063d02db7f0977e3339070791f440db4541b0e1 100644 (file)
@@ -185,6 +185,10 @@ MODULE_PARM_DESC(rtw_notch_filter, "0:Disable, 1:Enable, 2:Enable only for P2P")
 module_param_named(debug, rtw_debug, int, 0444);
 MODULE_PARM_DESC(debug, "Set debug level (1-9) (default 1)");
 
+static bool rtw_monitor_enable;
+module_param_named(monitor_enable, rtw_monitor_enable, bool, 0444);
+MODULE_PARM_DESC(monitor_enable, "Enable monitor inferface (default: false)");
+
 static int netdev_open(struct net_device *pnetdev);
 static int netdev_close(struct net_device *pnetdev);
 
@@ -604,6 +608,7 @@ static void loadparam(struct adapter *padapter, struct net_device *pnetdev)
        snprintf(registry_par->ifname, 16, "%s", ifname);
        snprintf(registry_par->if2name, 16, "%s", if2name);
        registry_par->notch_filter = (u8)rtw_notch_filter;
+       registry_par->monitor_enable = rtw_monitor_enable;
 }
 
 static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
@@ -1053,7 +1058,8 @@ static int netdev_open(struct net_device *pnetdev)
        int ret;
        struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
 
-       _enter_critical_mutex(&padapter->hw_init_mutex, NULL);
+       if (mutex_lock_interruptible(&padapter->hw_init_mutex))
+               return -ERESTARTSYS;
        ret = _netdev_open(pnetdev);
        mutex_unlock(&padapter->hw_init_mutex);
        return ret;
index acb4eb120b76ccd5b064e49aa64ef7727033a744..466cd76fc1c4f0c8b70a589b96aaf8664993778e 100644 (file)
@@ -52,7 +52,7 @@ void *rtw_malloc2d(int h, int w, int size)
        int j;
 
        void **a = kzalloc(h*sizeof(void *) + h*w*size, GFP_KERNEL);
-       if (a == NULL) {
+       if (!a) {
                pr_info("%s: alloc memory fail!\n", __func__);
                return NULL;
        }
index 3ebb8b206e468ce00cf25a7819b9f72cec8eea7b..d4734baffc8a03f21ae57c0d6525c99c27fc6f11 100644 (file)
@@ -94,7 +94,7 @@ int rtw_recv_indicatepkt(struct adapter *padapter,
        pfree_recv_queue = &(precvpriv->free_recv_queue);
 
        skb = precv_frame->pkt;
-       if (skb == NULL) {
+       if (!skb) {
                RT_TRACE(_module_recv_osdep_c_, _drv_err_,
                         ("rtw_recv_indicatepkt():skb == NULL something wrong!!!!\n"));
                goto _recv_indicatepkt_drop;
index 33bfe054f8677d5d4cc129c9b4111a4d9bf81a72..82a7c27c517ffa22f1f1899a1c5090c0c95b0658 100644 (file)
@@ -26,6 +26,7 @@
 #include <hal_intf.h>
 #include <linux/usb.h>
 #include <linux/vmalloc.h>
+#include <mon.h>
 #include <osdep_intf.h>
 
 #include <usb_ops_linux.h>
@@ -348,6 +349,7 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
 {
        struct adapter *padapter = NULL;
        struct net_device *pnetdev = NULL;
+       struct net_device *pmondev;
        int status = _FAIL;
 
        padapter = (struct adapter *)vzalloc(sizeof(*padapter));
@@ -366,6 +368,13 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
        SET_NETDEV_DEV(pnetdev, dvobj_to_dev(dvobj));
        padapter = rtw_netdev_priv(pnetdev);
 
+       if (padapter->registrypriv.monitor_enable) {
+               pmondev = rtl88eu_mon_init();
+               if (pmondev == NULL)
+                       netdev_warn(pnetdev, "Failed to initialize monitor interface");
+               padapter->pmondev = pmondev;
+       }
+
        /* step 2. hook HalFunc, allocate HalData */
        hal_set_hal_ops(padapter);
 
@@ -458,6 +467,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
                unregister_netdev(pnetdev);
                rtw_proc_remove_one(pnetdev);
        }
+       rtl88eu_mon_deinit(if1->pmondev);
        rtw_cancel_all_timer(if1);
 
        rtw_dev_unload(if1);
index 7e599bc5b2d3c9f515bb2c3bb94eb1e702a8cd12..0fea338d7313fe07b22fac1185a95d8200e5c446 100644 (file)
@@ -249,7 +249,10 @@ static int usbctrl_vendorreq(struct adapter *adapt, u8 request, u16 value, u16 i
                goto exit;
        }
 
-       _enter_critical_mutex(&dvobjpriv->usb_vendor_req_mutex, NULL);
+       if (mutex_lock_interruptible(&dvobjpriv->usb_vendor_req_mutex)) {
+               status = -ERESTARTSYS;
+               goto exit;
+       }
 
        /*  Acquire IO memory for vendorreq */
        pIo_buf = dvobjpriv->usb_vendor_req_buf;
index 5acf9a9dddeb40d9ea69c18599e591b9429e8195..1593e280e06038a1e3776810f2689857f6844267 100644 (file)
@@ -52,7 +52,7 @@ uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
 
 
        len =  rtw_remainder_len(pfile);
-       len = (rlen > len) ? len : rlen;
+       len = min(rlen, len);
 
        if (rmem)
                skb_copy_bits(pfile->pkt, pfile->buf_len-pfile->pkt_len, rmem, len);
index fcf9b3bcf76a9dc39069c943be460a389a778b18..4d8fb4158f6bf11bb7414bc1c44da7beafef8dcf 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 129ebed2e3cc294b96fb79bb6cfb6bd9d58b6486..2c19054cf027330e83449d2e9b763a31009d5fa2 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index dba4584c70067f5b8a4cdaf9bd1e0183987a6b05..34453e38ba9387a5b874243aac15633adbecf050 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index c8f25ade25355c42022de5593df7457cb9b6dc0f..81b3cf6588d418f0df68ed941c4e2c1f3cc070ad 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -36,7 +32,7 @@ void rtl92e_set_bandwidth(struct net_device *dev,
 
        for (eRFPath = 0; eRFPath < priv->NumTotalRFPath; eRFPath++) {
                if (!rtl92e_is_legal_rf_path(dev, eRFPath))
-                               continue;
+                       continue;
 
                switch (Bandwidth) {
                case HT_CHANNEL_WIDTH_20:
@@ -82,7 +78,7 @@ bool rtl92e_config_rf(struct net_device *dev)
        for (eRFPath = (enum rf90_radio_path)RF90_PATH_A;
             eRFPath < priv->NumTotalRFPath; eRFPath++) {
                if (!rtl92e_is_legal_rf_path(dev, eRFPath))
-                               continue;
+                       continue;
 
                pPhyReg = &priv->PHYRegDef[eRFPath];
 
index 3e4363f417286f24f37e13b4be160cd080c6a695..7873a73a2f76e91e3390ca0e7e484897a7ed0d63 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 9ddabf59784c5c6809b2ea3e3a7ad3b26907aad6..f9003a28cae25de9aa9c7325ecc97ee6b3d84821 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
 #include "r8192E_hw.h"
 #include "r8192E_cmdpkt.h"
 
-bool rtl92e_send_cmd_pkt(struct net_device *dev, u8 *code_virtual_address,
-                        u32 packettype, u32 buffer_len)
+bool rtl92e_send_cmd_pkt(struct net_device *dev, u32 type, const void *data,
+                        u32 len)
 {
 
        bool                            rt_status = true;
        struct r8192_priv *priv = rtllib_priv(dev);
-       u16                             frag_threshold;
        u16                             frag_length = 0, frag_offset = 0;
-       struct rt_firmware *pfirmware = priv->pFirmware;
        struct sk_buff          *skb;
        unsigned char           *seg_ptr;
        struct cb_desc *tcb_desc;
@@ -37,22 +31,23 @@ bool rtl92e_send_cmd_pkt(struct net_device *dev, u8 *code_virtual_address,
 
        struct tx_fwinfo_8190pci *pTxFwInfo = NULL;
 
-       RT_TRACE(COMP_CMDPKT, "%s(),buffer_len is %d\n", __func__, buffer_len);
-       rtl92e_init_fw_param(dev);
-       frag_threshold = pfirmware->cmdpacket_frag_thresold;
+       RT_TRACE(COMP_CMDPKT, "%s(),buffer_len is %d\n", __func__, len);
 
        do {
-               if ((buffer_len - frag_offset) > frag_threshold) {
-                       frag_length = frag_threshold;
+               if ((len - frag_offset) > CMDPACKET_FRAG_SIZE) {
+                       frag_length = CMDPACKET_FRAG_SIZE;
                        bLastIniPkt = 0;
 
                } else {
-                       frag_length = (u16)(buffer_len - frag_offset);
+                       frag_length = (u16)(len - frag_offset);
                        bLastIniPkt = 1;
                }
 
-               skb  = dev_alloc_skb(frag_length +
-                                    priv->rtllib->tx_headroom + 4);
+               if (type == DESC_PACKET_TYPE_NORMAL)
+                       skb = dev_alloc_skb(frag_length +
+                                           priv->rtllib->tx_headroom + 4);
+               else
+                       skb = dev_alloc_skb(frag_length + 4);
 
                if (skb == NULL) {
                        rt_status = false;
@@ -62,24 +57,37 @@ bool rtl92e_send_cmd_pkt(struct net_device *dev, u8 *code_virtual_address,
                memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
                tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
                tcb_desc->queue_index = TXCMD_QUEUE;
-               tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_NORMAL;
+               tcb_desc->bCmdOrInit = type;
                tcb_desc->bLastIniPkt = bLastIniPkt;
-               tcb_desc->pkt_size = frag_length;
 
-               seg_ptr = skb_put(skb, priv->rtllib->tx_headroom);
-               pTxFwInfo = (struct tx_fwinfo_8190pci *)seg_ptr;
-               memset(pTxFwInfo, 0, sizeof(struct tx_fwinfo_8190pci));
-               memset(pTxFwInfo, 0x12, 8);
+               if (type == DESC_PACKET_TYPE_NORMAL) {
+                       tcb_desc->pkt_size = frag_length;
 
-               seg_ptr = skb_put(skb, frag_length);
-               memcpy(seg_ptr, code_virtual_address, (u32)frag_length);
+                       seg_ptr = skb_put(skb, priv->rtllib->tx_headroom);
+                       pTxFwInfo = (struct tx_fwinfo_8190pci *)seg_ptr;
+                       memset(pTxFwInfo, 0, sizeof(struct tx_fwinfo_8190pci));
+                       memset(pTxFwInfo, 0x12, 8);
+               } else {
+                       tcb_desc->txbuf_size = (u16)frag_length;
+               }
 
-               priv->rtllib->softmac_hard_start_xmit(skb, dev);
+               seg_ptr = skb_put(skb, frag_length);
+               memcpy(seg_ptr, data, (u32)frag_length);
+
+               if (type == DESC_PACKET_TYPE_INIT &&
+                   (!priv->rtllib->check_nic_enough_desc(dev, TXCMD_QUEUE) ||
+                    (!skb_queue_empty(&priv->rtllib->skb_waitQ[TXCMD_QUEUE])) ||
+                    (priv->rtllib->queue_stop))) {
+                       skb_queue_tail(&priv->rtllib->skb_waitQ[TXCMD_QUEUE],
+                                      skb);
+               } else {
+                       priv->rtllib->softmac_hard_start_xmit(skb, dev);
+               }
 
-               code_virtual_address += frag_length;
+               data += frag_length;
                frag_offset += frag_length;
 
-       } while (frag_offset < buffer_len);
+       } while (frag_offset < len);
 
        rtl92e_writeb(dev, TPPoll, TPPoll_CQ);
 Failed:
index 2a8b165cb8e16518119d1878ba9babd83f286aaf..7dd15d9934816362c240ac5a2389a04ea5deeb56 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -19,6 +15,6 @@
 #ifndef R819XUSB_CMDPKT_H
 #define R819XUSB_CMDPKT_H
 
-bool rtl92e_send_cmd_pkt(struct net_device *dev, u8 *codevirtualaddress,
-                        u32 packettype, u32 buffer_len);
+bool rtl92e_send_cmd_pkt(struct net_device *dev, u32 type, const void *data,
+                        u32 len);
 #endif
index c28cabc23fc05b6e25cb5b506a2238611c401277..e9c4f973bba9761dad747ab70e621ec2b3e23ffd 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -57,7 +53,7 @@ void rtl92e_start_beacon(struct net_device *dev)
        rtl92e_irq_enable(dev);
 }
 
-static void rtl8192e_update_msr(struct net_device *dev)
+static void _rtl92e_update_msr(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 msr;
@@ -108,7 +104,6 @@ void rtl92e_set_reg(struct net_device *dev, u8 variable, u8 *val)
        case HW_VAR_MEDIA_STATUS:
        {
                enum rt_op_mode OpMode = *((enum rt_op_mode *)(val));
-               enum led_ctl_mode LedAction = LED_CTL_NO_LINK;
                u8 btMsr = rtl92e_readb(dev, MSR);
 
                btMsr &= 0xfc;
@@ -116,7 +111,6 @@ void rtl92e_set_reg(struct net_device *dev, u8 variable, u8 *val)
                switch (OpMode) {
                case RT_OP_MODE_INFRASTRUCTURE:
                        btMsr |= MSR_INFRA;
-                       LedAction = LED_CTL_LINK;
                        break;
 
                case RT_OP_MODE_IBSS:
@@ -125,7 +119,6 @@ void rtl92e_set_reg(struct net_device *dev, u8 variable, u8 *val)
 
                case RT_OP_MODE_AP:
                        btMsr |= MSR_AP;
-                       LedAction = LED_CTL_LINK;
                        break;
 
                default:
@@ -312,7 +305,7 @@ void rtl92e_set_reg(struct net_device *dev, u8 variable, u8 *val)
 
 }
 
-static void rtl8192_read_eeprom_info(struct net_device *dev)
+static void _rtl92e_read_eeprom_info(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        const u8 bMac_Tmp_Addr[ETH_ALEN] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x01};
@@ -321,7 +314,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
        u16 i, usValue, IC_Version;
        u16 EEPROMId;
 
-       RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n");
+       RT_TRACE(COMP_INIT, "====> _rtl92e_read_eeprom_info\n");
 
        EEPROMId = rtl92e_eeprom_read(dev, 0);
        if (EEPROMId != RTL8190_EEPROM_ID) {
@@ -640,10 +633,10 @@ void rtl92e_get_eeprom_size(struct net_device *dev)
                          EEPROM_93C46;
        RT_TRACE(COMP_INIT, "<===========%s(), epromtype:%d\n", __func__,
                 priv->epromtype);
-       rtl8192_read_eeprom_info(dev);
+       _rtl92e_read_eeprom_info(dev);
 }
 
-static void rtl8192_hwconfig(struct net_device *dev)
+static void _rtl92e_hwconfig(struct net_device *dev)
 {
        u32 regRATR = 0, regRRSR = 0;
        u8 regBwOpMode = 0, regTmp = 0;
@@ -726,19 +719,19 @@ start:
                rtl92e_writeb(dev, ANAPAR, 0x37);
                mdelay(500);
        }
-       priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
+       priv->pFirmware->status = FW_STATUS_0_INIT;
 
        if (priv->RegRfOff)
                priv->rtllib->eRFPowerState = eRfOff;
 
        ulRegRead = rtl92e_readl(dev, CPU_GEN);
-       if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
+       if (priv->pFirmware->status == FW_STATUS_0_INIT)
                ulRegRead |= CPU_GEN_SYSTEM_RESET;
-       else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
+       else if (priv->pFirmware->status == FW_STATUS_5_READY)
                ulRegRead |= CPU_GEN_FIRMWARE_RESET;
        else
                netdev_err(dev, "%s(): undefined firmware state: %d.\n",
-                          __func__, priv->pFirmware->firmware_status);
+                          __func__, priv->pFirmware->status);
 
        rtl92e_writel(dev, CPU_GEN, ulRegRead);
 
@@ -775,7 +768,7 @@ start:
 
                udelay(500);
        }
-       rtl8192_hwconfig(dev);
+       _rtl92e_hwconfig(dev);
        rtl92e_writeb(dev, CMDR, CR_RE | CR_TE);
 
        rtl92e_writeb(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) |
@@ -958,7 +951,7 @@ end:
        return rtStatus;
 }
 
-static void rtl8192_net_update(struct net_device *dev)
+static void _rtl92e_net_update(struct net_device *dev)
 {
 
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -996,15 +989,15 @@ void rtl92e_link_change(struct net_device *dev)
                return;
 
        if (ieee->state == RTLLIB_LINKED) {
-               rtl8192_net_update(dev);
+               _rtl92e_net_update(dev);
                priv->ops->update_ratr_table(dev);
-               if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) ||
-                   (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
+               if ((ieee->pairwise_key_type == KEY_TYPE_WEP40) ||
+                   (ieee->pairwise_key_type == KEY_TYPE_WEP104))
                        rtl92e_enable_hw_security_config(dev);
        } else {
                rtl92e_writeb(dev, 0x173, 0);
        }
-       rtl8192e_update_msr(dev);
+       _rtl92e_update_msr(dev);
 
        if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
                u32 reg = 0;
@@ -1036,7 +1029,7 @@ void rtl92e_set_monitor_mode(struct net_device *dev, bool bAllowAllDA,
                rtl92e_writel(dev, RCR, priv->ReceiveConfig);
 }
 
-static u8 MRateToHwRate8190Pci(u8 rate)
+static u8 _rtl92e_rate_mgn_to_hw(u8 rate)
 {
        u8  ret = DESC90_RATE1M;
 
@@ -1134,8 +1127,8 @@ static u8 MRateToHwRate8190Pci(u8 rate)
        return ret;
 }
 
-static u8 rtl8192_MapHwQueueToFirmwareQueue(struct net_device *dev, u8 QueueID,
-                                           u8 priority)
+static u8 _rtl92e_hw_queue_to_fw_queue(struct net_device *dev, u8 QueueID,
+                                      u8 priority)
 {
        u8 QueueSelect = 0x0;
 
@@ -1175,7 +1168,7 @@ static u8 rtl8192_MapHwQueueToFirmwareQueue(struct net_device *dev, u8 QueueID,
        return QueueSelect;
 }
 
-static u8 rtl8192_QueryIsShort(u8 TxHT, u8 TxRate, struct cb_desc *tcb_desc)
+static u8 _rtl92e_query_is_short(u8 TxHT, u8 TxRate, struct cb_desc *tcb_desc)
 {
        u8   tmp_Short;
 
@@ -1198,11 +1191,10 @@ void  rtl92e_fill_tx_desc(struct net_device *dev, struct tx_desc *pdesc,
        pTxFwInfo = (struct tx_fwinfo_8190pci *)skb->data;
        memset(pTxFwInfo, 0, sizeof(struct tx_fwinfo_8190pci));
        pTxFwInfo->TxHT = (cb_desc->data_rate & 0x80) ? 1 : 0;
-       pTxFwInfo->TxRate = MRateToHwRate8190Pci((u8)cb_desc->data_rate);
+       pTxFwInfo->TxRate = _rtl92e_rate_mgn_to_hw((u8)cb_desc->data_rate);
        pTxFwInfo->EnableCPUDur = cb_desc->bTxEnableFwCalcDur;
-       pTxFwInfo->Short = rtl8192_QueryIsShort(pTxFwInfo->TxHT,
-                                               pTxFwInfo->TxRate,
-                                               cb_desc);
+       pTxFwInfo->Short = _rtl92e_query_is_short(pTxFwInfo->TxHT,
+                                                 pTxFwInfo->TxRate, cb_desc);
 
        if (pci_dma_mapping_error(priv->pdev, mapping))
                netdev_err(dev, "%s(): DMA Mapping error\n", __func__);
@@ -1220,7 +1212,7 @@ void  rtl92e_fill_tx_desc(struct net_device *dev, struct tx_desc *pdesc,
        pTxFwInfo->CtsEnable = (cb_desc->bCTSEnable) ? 1 : 0;
        pTxFwInfo->RtsSTBC = (cb_desc->bRTSSTBC) ? 1 : 0;
        pTxFwInfo->RtsHT = (cb_desc->rts_rate&0x80) ? 1 : 0;
-       pTxFwInfo->RtsRate = MRateToHwRate8190Pci((u8)cb_desc->rts_rate);
+       pTxFwInfo->RtsRate = _rtl92e_rate_mgn_to_hw((u8)cb_desc->rts_rate);
        pTxFwInfo->RtsBandwidth = 0;
        pTxFwInfo->RtsSubcarrier = cb_desc->RTSSC;
        pTxFwInfo->RtsShort = (pTxFwInfo->RtsHT == 0) ?
@@ -1281,9 +1273,9 @@ void  rtl92e_fill_tx_desc(struct net_device *dev, struct tx_desc *pdesc,
 
        pdesc->PktId = 0x0;
 
-       pdesc->QueueSelect = rtl8192_MapHwQueueToFirmwareQueue(dev,
-                                               cb_desc->queue_index,
-                                               cb_desc->priority);
+       pdesc->QueueSelect = _rtl92e_hw_queue_to_fw_queue(dev,
+                                                         cb_desc->queue_index,
+                                                         cb_desc->priority);
        pdesc->TxFWInfoSize = sizeof(struct tx_fwinfo_8190pci);
 
        pdesc->DISFB = cb_desc->bTxDisableRateFallBack;
@@ -1327,7 +1319,7 @@ void  rtl92e_fill_tx_cmd_desc(struct net_device *dev, struct tx_desc_cmd *entry,
        entry->OWN = 1;
 }
 
-static u8 HwRateToMRate90(bool bIsHT, u8 rate)
+static u8 _rtl92e_rate_hw_to_mgn(bool bIsHT, u8 rate)
 {
        u8  ret_rate = 0x02;
 
@@ -1372,7 +1364,7 @@ static u8 HwRateToMRate90(bool bIsHT, u8 rate)
 
                default:
                        RT_TRACE(COMP_RECV,
-                                "HwRateToMRate90(): Non supportedRate [%x], bIsHT = %d!!!\n",
+                                "_rtl92e_rate_hw_to_mgn(): Non supportedRate [%x], bIsHT = %d!!!\n",
                                 rate, bIsHT);
                        break;
                }
@@ -1433,7 +1425,7 @@ static u8 HwRateToMRate90(bool bIsHT, u8 rate)
 
                default:
                        RT_TRACE(COMP_RECV,
-                                "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",
+                                "_rtl92e_rate_hw_to_mgn(): Non supported Rate [%x], bIsHT = %d!!!\n",
                                 rate, bIsHT);
                        break;
                }
@@ -1442,7 +1434,7 @@ static u8 HwRateToMRate90(bool bIsHT, u8 rate)
        return ret_rate;
 }
 
-static long rtl8192_signal_scale_mapping(struct r8192_priv *priv, long currsig)
+static long _rtl92e_signal_scale_mapping(struct r8192_priv *priv, long currsig)
 {
        long retsig;
 
@@ -1478,7 +1470,7 @@ static long rtl8192_signal_scale_mapping(struct r8192_priv *priv, long currsig)
                        _pdrvinfo->RxRate == DESC90_RATE11M) &&\
                        !_pdrvinfo->RxHT)
 
-static void rtl8192_query_rxphystatus(
+static void _rtl92e_query_rxphystatus(
        struct r8192_priv *priv,
        struct rtllib_rx_stats *pstats,
        struct rx_desc  *pdesc,
@@ -1682,18 +1674,18 @@ static void rtl8192_query_rxphystatus(
 
        if (is_cck_rate) {
                pstats->SignalStrength = precord_stats->SignalStrength =
-                                        (u8)(rtl8192_signal_scale_mapping(priv,
+                                        (u8)(_rtl92e_signal_scale_mapping(priv,
                                         (long)pwdb_all));
 
        } else {
                if (rf_rx_num != 0)
                        pstats->SignalStrength = precord_stats->SignalStrength =
-                                        (u8)(rtl8192_signal_scale_mapping(priv,
+                                        (u8)(_rtl92e_signal_scale_mapping(priv,
                                         (long)(total_rssi /= rf_rx_num)));
        }
 }
 
-static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
+static void _rtl92e_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
                                    struct rtllib_rx_stats *prev_st,
                                    struct rtllib_rx_stats *curr_st)
 {
@@ -1865,11 +1857,11 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
        }
 }
 
-static void rtl8192_TranslateRxSignalStuff(struct net_device *dev,
-                                          struct sk_buff *skb,
-                                          struct rtllib_rx_stats *pstats,
-                                          struct rx_desc *pdesc,
-                                          struct rx_fwinfo *pdrvinfo)
+static void _rtl92e_translate_rx_signal_stats(struct net_device *dev,
+                                             struct sk_buff *skb,
+                                             struct rtllib_rx_stats *pstats,
+                                             struct rx_desc *pdesc,
+                                             struct rx_fwinfo *pdrvinfo)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
        bool bpacket_match_bssid, bpacket_toself;
@@ -1889,7 +1881,7 @@ static void rtl8192_TranslateRxSignalStuff(struct net_device *dev,
        praddr = hdr->addr1;
 
        bpacket_match_bssid =
-               ((RTLLIB_FTYPE_CTL != type) &&
+               ((type != RTLLIB_FTYPE_CTL) &&
                 ether_addr_equal(priv->rtllib->current_network.bssid,
                                  (fc & RTLLIB_FCTL_TODS) ? hdr->addr1 :
                                  (fc & RTLLIB_FCTL_FROMDS) ? hdr->addr2 :
@@ -1903,14 +1895,14 @@ static void rtl8192_TranslateRxSignalStuff(struct net_device *dev,
                priv->stats.numpacket_matchbssid++;
        if (bpacket_toself)
                priv->stats.numpacket_toself++;
-       rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
-       rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo,
+       _rtl92e_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
+       _rtl92e_query_rxphystatus(priv, pstats, pdesc, pdrvinfo,
                                  &previous_stats, bpacket_match_bssid,
                                  bpacket_toself, bPacketBeacon, bToSelfBA);
        rtl92e_copy_mpdu_stats(pstats, &previous_stats);
 }
 
-static void rtl8192_UpdateReceivedRateHistogramStatistics(
+static void _rtl92e_update_received_rate_histogram_stats(
                                           struct net_device *dev,
                                           struct rtllib_rx_stats *pstats)
 {
@@ -2057,11 +2049,11 @@ bool rtl92e_get_rx_stats(struct net_device *dev, struct rtllib_rx_stats *stats,
 
        pDrvInfo = (struct rx_fwinfo *)(skb->data + stats->RxBufShift);
 
-       stats->rate = HwRateToMRate90((bool)pDrvInfo->RxHT,
-                                    (u8)pDrvInfo->RxRate);
+       stats->rate = _rtl92e_rate_hw_to_mgn((bool)pDrvInfo->RxHT,
+                                            (u8)pDrvInfo->RxRate);
        stats->bShortPreamble = pDrvInfo->SPLCP;
 
-       rtl8192_UpdateReceivedRateHistogramStatistics(dev, stats);
+       _rtl92e_update_received_rate_histogram_stats(dev, stats);
 
        stats->bIsAMPDU = (pDrvInfo->PartAggr == 1);
        stats->bFirstMPDU = (pDrvInfo->PartAggr == 1) &&
@@ -2077,8 +2069,7 @@ bool rtl92e_get_rx_stats(struct net_device *dev, struct rtllib_rx_stats *stats,
 
        stats->RxIs40MHzPacket = pDrvInfo->BW;
 
-       rtl8192_TranslateRxSignalStuff(dev, skb, stats, pdesc,
-                                      pDrvInfo);
+       _rtl92e_translate_rx_signal_stats(dev, skb, stats, pdesc, pDrvInfo);
 
        if (pDrvInfo->FirstAGGR == 1 || pDrvInfo->PartAggr == 1)
                RT_TRACE(COMP_RXDESC,
index 6bd6b3a4fcea617ea35255124b3b1fd014541ee1..6bb58193fc5cc735f5bc0732078f120160c773bb 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 5c527c419bc9eeb474ebd01f82ed526324594c7c..9aaa85526eb8d3ae1086f4fadd6ff2e3d018e2f6 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
 #include "r8192E_hw.h"
 #include "r8192E_hwimg.h"
 #include "r8192E_firmware.h"
+#include "r8192E_cmdpkt.h"
 #include <linux/firmware.h>
 
-void rtl92e_init_fw_param(struct net_device *dev)
-{
-       struct r8192_priv *priv = rtllib_priv(dev);
-       struct rt_firmware *pfirmware = priv->pFirmware;
-
-       pfirmware->cmdpacket_frag_thresold = GET_COMMAND_PACKET_FRAG_THRESHOLD(
-                                            MAX_TRANSMIT_BUFFER_SIZE);
-}
-
-static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
-                            u32 buffer_len)
+static bool _rtl92e_wait_for_fw(struct net_device *dev, u32 mask, u32 timeout)
 {
-       struct r8192_priv *priv = rtllib_priv(dev);
-       u16                 frag_threshold;
-       u16                 frag_length, frag_offset = 0;
-       int                 i;
+       unsigned long deadline = jiffies + msecs_to_jiffies(timeout);
 
-       struct rt_firmware *pfirmware = priv->pFirmware;
-       struct sk_buff      *skb;
-       unsigned char       *seg_ptr;
-       struct cb_desc *tcb_desc;
-       u8                  bLastIniPkt;
-
-       rtl92e_init_fw_param(dev);
-       frag_threshold = pfirmware->cmdpacket_frag_thresold;
-       do {
-               if ((buffer_len - frag_offset) > frag_threshold) {
-                       frag_length = frag_threshold;
-                       bLastIniPkt = 0;
-
-               } else {
-                       frag_length = buffer_len - frag_offset;
-                       bLastIniPkt = 1;
-
-               }
-
-               skb  = dev_alloc_skb(frag_length + 4);
-               memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
-               tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
-               tcb_desc->queue_index = TXCMD_QUEUE;
-               tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_INIT;
-               tcb_desc->bLastIniPkt = bLastIniPkt;
-
-               seg_ptr = skb->data;
-               for (i = 0; i < frag_length; i += 4) {
-                       *seg_ptr++ = ((i+0) < frag_length) ?
-                                    code_virtual_address[i+3] : 0;
-                       *seg_ptr++ = ((i+1) < frag_length) ?
-                                    code_virtual_address[i+2] : 0;
-                       *seg_ptr++ = ((i+2) < frag_length) ?
-                                    code_virtual_address[i+1] : 0;
-                       *seg_ptr++ = ((i+3) < frag_length) ?
-                                    code_virtual_address[i+0] : 0;
-               }
-               tcb_desc->txbuf_size = (u16)i;
-               skb_put(skb, i);
-
-               if (!priv->rtllib->check_nic_enough_desc(dev, tcb_desc->queue_index) ||
-                   (!skb_queue_empty(&priv->rtllib->skb_waitQ[tcb_desc->queue_index])) ||
-                   (priv->rtllib->queue_stop)) {
-                       RT_TRACE(COMP_FIRMWARE,
-                                "===================> tx full!\n");
-                       skb_queue_tail(&priv->rtllib->skb_waitQ
-                                       [tcb_desc->queue_index], skb);
-               } else {
-               priv->rtllib->softmac_hard_start_xmit(skb, dev);
-               }
-
-               code_virtual_address += frag_length;
-               frag_offset += frag_length;
-
-       } while (frag_offset < buffer_len);
-
-       rtl92e_writeb(dev, TPPoll, TPPoll_CQ);
-
-       return true;
+       while (time_before(jiffies, deadline)) {
+               if (rtl92e_readl(dev, CPU_GEN) & mask)
+                       return true;
+               mdelay(2);
+       }
+       return false;
 }
 
-static bool CPUcheck_maincodeok_turnonCPU(struct net_device *dev)
+static bool _rtl92e_fw_boot_cpu(struct net_device *dev)
 {
-       bool            rt_status = true;
        u32             CPU_status = 0;
-       unsigned long   timeout;
 
-       timeout = jiffies + msecs_to_jiffies(200);
-       while (time_before(jiffies, timeout)) {
-               CPU_status = rtl92e_readl(dev, CPU_GEN);
-               if (CPU_status & CPU_GEN_PUT_CODE_OK)
-                       break;
-               mdelay(2);
-       }
-
-       if (!(CPU_status&CPU_GEN_PUT_CODE_OK)) {
+       if (!_rtl92e_wait_for_fw(dev, CPU_GEN_PUT_CODE_OK, 200)) {
                netdev_err(dev, "Firmware download failed.\n");
-               goto CPUCheckMainCodeOKAndTurnOnCPU_Fail;
-       } else {
-               RT_TRACE(COMP_FIRMWARE, "Download Firmware: Put code ok!\n");
+               return false;
        }
+       netdev_dbg(dev, "Download Firmware: Put code ok!\n");
 
        CPU_status = rtl92e_readl(dev, CPU_GEN);
        rtl92e_writeb(dev, CPU_GEN,
                      (u8)((CPU_status|CPU_GEN_PWR_STB_CPU)&0xff));
        mdelay(1);
 
-       timeout = jiffies + msecs_to_jiffies(200);
-       while (time_before(jiffies, timeout)) {
-               CPU_status = rtl92e_readl(dev, CPU_GEN);
-               if (CPU_status&CPU_GEN_BOOT_RDY)
-                       break;
-               mdelay(2);
-       }
-
-       if (!(CPU_status&CPU_GEN_BOOT_RDY)) {
+       if (!_rtl92e_wait_for_fw(dev, CPU_GEN_BOOT_RDY, 200)) {
                netdev_err(dev, "Firmware boot failed.\n");
-               goto CPUCheckMainCodeOKAndTurnOnCPU_Fail;
-       }
-
-       RT_TRACE(COMP_FIRMWARE, "Download Firmware: Boot ready!\n");
-
-       return rt_status;
-
-CPUCheckMainCodeOKAndTurnOnCPU_Fail:
-       rt_status = false;
-       return rt_status;
-}
-
-static bool CPUcheck_firmware_ready(struct net_device *dev)
-{
-
-       bool    rt_status = true;
-       u32     CPU_status = 0;
-       unsigned long timeout;
-
-       timeout = jiffies + msecs_to_jiffies(20);
-       while (time_before(jiffies, timeout)) {
-               CPU_status = rtl92e_readl(dev, CPU_GEN);
-               if (CPU_status&CPU_GEN_FIRM_RDY)
-                       break;
-               mdelay(2);
+               return false;
        }
 
-       if (!(CPU_status&CPU_GEN_FIRM_RDY))
-               goto CPUCheckFirmwareReady_Fail;
-       else
-               RT_TRACE(COMP_FIRMWARE, "Download Firmware: Firmware ready!\n");
-
-       return rt_status;
-
-CPUCheckFirmwareReady_Fail:
-       rt_status = false;
-       return rt_status;
+       netdev_dbg(dev, "Download Firmware: Boot ready!\n");
 
+       return true;
 }
 
-static bool firmware_check_ready(struct net_device *dev,
-                                       u8 load_fw_status)
+static bool _rtl92e_fw_check_ready(struct net_device *dev,
+                                  u8 load_fw_status)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_firmware *pfirmware = priv->pFirmware;
@@ -186,43 +66,77 @@ static bool firmware_check_ready(struct net_device *dev,
 
        switch (load_fw_status) {
        case FW_INIT_STEP0_BOOT:
-               pfirmware->firmware_status = FW_STATUS_1_MOVE_BOOT_CODE;
+               pfirmware->status = FW_STATUS_1_MOVE_BOOT_CODE;
                break;
 
        case FW_INIT_STEP1_MAIN:
-               pfirmware->firmware_status = FW_STATUS_2_MOVE_MAIN_CODE;
+               pfirmware->status = FW_STATUS_2_MOVE_MAIN_CODE;
 
-               rt_status = CPUcheck_maincodeok_turnonCPU(dev);
+               rt_status = _rtl92e_fw_boot_cpu(dev);
                if (rt_status)
-                       pfirmware->firmware_status = FW_STATUS_3_TURNON_CPU;
+                       pfirmware->status = FW_STATUS_3_TURNON_CPU;
                else
-                       RT_TRACE(COMP_FIRMWARE,
-                                "CPUcheck_maincodeok_turnonCPU fail!\n");
+                       netdev_dbg(dev, "_rtl92e_fw_boot_cpu fail!\n");
 
                break;
 
        case FW_INIT_STEP2_DATA:
-               pfirmware->firmware_status = FW_STATUS_4_MOVE_DATA_CODE;
+               pfirmware->status = FW_STATUS_4_MOVE_DATA_CODE;
                mdelay(1);
 
-               rt_status = CPUcheck_firmware_ready(dev);
+               rt_status = _rtl92e_wait_for_fw(dev, CPU_GEN_FIRM_RDY, 20);
                if (rt_status)
-                       pfirmware->firmware_status = FW_STATUS_5_READY;
+                       pfirmware->status = FW_STATUS_5_READY;
                else
                        RT_TRACE(COMP_FIRMWARE,
-                                "CPUcheck_firmware_ready fail(%d)!\n",
+                                "_rtl92e_is_fw_ready fail(%d)!\n",
                                 rt_status);
-
                break;
        default:
                rt_status = false;
-               RT_TRACE(COMP_FIRMWARE, "Unknown firmware status");
+               netdev_dbg(dev, "Unknown firmware status");
                break;
        }
 
        return rt_status;
 }
 
+static bool _rtl92e_fw_prepare(struct net_device *dev, struct rt_fw_blob *blob,
+                              const char *name, u8 padding)
+{
+       const struct firmware *fw;
+       int rc, i;
+       bool ret = true;
+
+       rc = request_firmware(&fw, name, &dev->dev);
+       if (rc < 0)
+               return false;
+
+       if (round_up(fw->size, 4) > MAX_FW_SIZE - padding) {
+               netdev_err(dev, "Firmware image %s too big for the device.\n",
+                          name);
+               ret = false;
+               goto out;
+       }
+
+       if (padding)
+               memset(blob->data, 0, padding);
+       if (fw->size % 4)
+               memset(blob->data + padding + fw->size, 0, 4);
+       memcpy(blob->data + padding, fw->data, fw->size);
+
+       blob->size = round_up(fw->size, 4) + padding;
+
+       /* Swap endian - firmware is packaged in invalid endiannes*/
+       for (i = padding; i < blob->size; i += 4) {
+               u32 *data = (u32 *)(blob->data + i);
+               *data = swab32p(data);
+       }
+out:
+       release_firmware(fw);
+       return ret;
+}
+
 bool rtl92e_init_fw(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -236,13 +150,13 @@ bool rtl92e_init_fw(struct net_device *dev)
 
        struct rt_firmware *pfirmware = priv->pFirmware;
 
-       RT_TRACE(COMP_FIRMWARE, " PlatformInitFirmware()==>\n");
+       netdev_dbg(dev, " PlatformInitFirmware()==>\n");
 
-       if (pfirmware->firmware_status == FW_STATUS_0_INIT) {
+       if (pfirmware->status == FW_STATUS_0_INIT) {
                rst_opt = OPT_SYSTEM_RESET;
                starting_state = FW_INIT_STEP0_BOOT;
 
-       } else if (pfirmware->firmware_status == FW_STATUS_5_READY) {
+       } else if (pfirmware->status == FW_STATUS_5_READY) {
                rst_opt = OPT_FIRMWARE_RESET;
                starting_state = FW_INIT_STEP2_DATA;
        } else {
@@ -252,62 +166,38 @@ bool rtl92e_init_fw(struct net_device *dev)
 
        for (i = starting_state; i <= FW_INIT_STEP2_DATA; i++) {
                if (rst_opt == OPT_SYSTEM_RESET) {
-                       if (pfirmware->firmware_buf_size[i] == 0) {
+                       if (pfirmware->blobs[i].size == 0) {
                                const char *fw_name[3] = {
                                        RTL8192E_BOOT_IMG_FW,
                                        RTL8192E_MAIN_IMG_FW,
                                        RTL8192E_DATA_IMG_FW
                                };
-                               const struct firmware *fw_entry;
-                               int rc;
-
-                               rc = request_firmware(&fw_entry,
-                                                     fw_name[i],
-                                                     &priv->pdev->dev);
-                               if (rc < 0) {
-                                       RT_TRACE(COMP_FIRMWARE,
-                                                "request firmware fail!\n");
-                                       goto download_firmware_fail;
-                               }
-                               if (fw_entry->size >
-                                   sizeof(pfirmware->firmware_buf[i])) {
-                                       RT_TRACE(COMP_FIRMWARE,
-                                                "img file size exceed the container struct buffer fail!\n");
+                               int pad = 0;
+
+                               if (i == FW_INIT_STEP1_MAIN)
+                                       pad = 128;
+
+                               if (!_rtl92e_fw_prepare(dev,
+                                                       &pfirmware->blobs[i],
+                                                       fw_name[i],
+                                                       pad))
                                        goto download_firmware_fail;
-                               }
-
-                               if (i != FW_INIT_STEP1_MAIN) {
-                                       memcpy(pfirmware->firmware_buf[i],
-                                              fw_entry->data, fw_entry->size);
-                                       pfirmware->firmware_buf_size[i] =
-                                               fw_entry->size;
-
-                               } else {
-                                       memset(pfirmware->firmware_buf[i],
-                                              0, 128);
-                                       memcpy(&pfirmware->firmware_buf[i][128],
-                                              fw_entry->data, fw_entry->size);
-                                       pfirmware->firmware_buf_size[i] =
-                                               fw_entry->size + 128;
-                               }
-
-                               if (rst_opt == OPT_SYSTEM_RESET)
-                                       release_firmware(fw_entry);
                        }
                }
 
-               mapped_file = pfirmware->firmware_buf[i];
-               file_length = pfirmware->firmware_buf_size[i];
+               mapped_file = pfirmware->blobs[i].data;
+               file_length = pfirmware->blobs[i].size;
 
-               rt_status = fw_download_code(dev, mapped_file, file_length);
+               rt_status = rtl92e_send_cmd_pkt(dev, DESC_PACKET_TYPE_INIT,
+                                               mapped_file, file_length);
                if (!rt_status)
                        goto download_firmware_fail;
 
-               if (!firmware_check_ready(dev, i))
+               if (!_rtl92e_fw_check_ready(dev, i))
                        goto download_firmware_fail;
        }
 
-       RT_TRACE(COMP_FIRMWARE, "Firmware Download Success\n");
+       netdev_dbg(dev, "Firmware Download Success\n");
        return rt_status;
 
 download_firmware_fail:
index fa760f7ac1450eab5c4416f24c6e18f09152af92..b48ec9410c09246396dc9693c4bf6e0c99fd70c5 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -19,8 +15,6 @@
 #ifndef __INC_FIRMWARE_H
 #define __INC_FIRMWARE_H
 
-#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v)   (4*(v/4) - 8)
-
 #define RTL8192E_BOOT_IMG_FW   "RTL8192E/boot.img"
 #define RTL8192E_MAIN_IMG_FW   "RTL8192E/main.img"
 #define RTL8192E_DATA_IMG_FW   "RTL8192E/data.img"
@@ -50,16 +44,17 @@ enum firmware_status {
        FW_STATUS_5_READY = 5,
 };
 
+#define MAX_FW_SIZE 64000
+struct rt_fw_blob {
+       u16 size;
+       u8 data[MAX_FW_SIZE];
+};
+
+#define FW_BLOBS 3
 struct rt_firmware {
-       enum firmware_status firmware_status;
-       u16               cmdpacket_frag_thresold;
-#define RTL8190_MAX_FIRMWARE_CODE_SIZE 64000
-#define MAX_FW_INIT_STEP               3
-       u8 firmware_buf[MAX_FW_INIT_STEP][RTL8190_MAX_FIRMWARE_CODE_SIZE];
-       u16               firmware_buf_size[MAX_FW_INIT_STEP];
+       enum firmware_status status;
+       struct rt_fw_blob blobs[FW_BLOBS];
 };
 
 bool rtl92e_init_fw(struct net_device *dev);
-void rtl92e_init_fw_param(struct net_device *dev);
-
 #endif
index c81832dcf1817bef47f1fc11e22e5ab23612d0f7..d298023ef079a6a636a9914bd614be494cf68770 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 6767b5965c17568cfaddf6498f06d53f494c0df4..29cefb599bab1a869a28cf859ad0715562c20f5e 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 5bd3b3530aa6adf90bfe968633c1f9b93a71f56c..d96b87d77e7a388541c66bf90a370d381ff1b1ce 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 3a15a0f5b479626c49238e7b8807e0cfae7ec952..0b407feb54073348a3a551506723a4553ea89f54 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -17,6 +13,7 @@
  * wlanfae <wlanfae@realtek.com>
 ******************************************************************************/
 
+#include <linux/bitops.h>
 #include "rtl_core.h"
 #include "r8192E_hw.h"
 #include "r8192E_phyreg.h"
@@ -46,22 +43,17 @@ static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
 
 /*************************Define local function prototype**********************/
 
-static u32 phy_FwRFSerialRead(struct net_device *dev,
-                             enum rf90_radio_path eRFPath,
-                             u32 Offset);
-static void phy_FwRFSerialWrite(struct net_device *dev,
-                               enum rf90_radio_path eRFPath,
-                               u32 Offset, u32 Data);
+static u32 _rtl92e_phy_rf_fw_read(struct net_device *dev,
+                                 enum rf90_radio_path eRFPath, u32 Offset);
+static void _rtl92e_phy_rf_fw_write(struct net_device *dev,
+                                   enum rf90_radio_path eRFPath, u32 Offset,
+                                   u32 Data);
 
-static u32 rtl8192_CalculateBitShift(u32 dwBitMask)
+static u32 _rtl92e_calculate_bit_shift(u32 dwBitMask)
 {
-       u32 i;
-
-       for (i = 0; i <= 31; i++) {
-               if (((dwBitMask >> i) & 0x1) == 1)
-                       break;
-       }
-       return i;
+       if (!dwBitMask)
+               return 32;
+       return ffs(dwBitMask) - 1;
 }
 
 u8 rtl92e_is_legal_rf_path(struct net_device *dev, u32 eRFPath)
@@ -88,7 +80,7 @@ void rtl92e_set_bb_reg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask,
 
        if (dwBitMask != bMaskDWord) {
                OriginalValue = rtl92e_readl(dev, dwRegAddr);
-               BitShift = rtl8192_CalculateBitShift(dwBitMask);
+               BitShift = _rtl92e_calculate_bit_shift(dwBitMask);
                NewValue = (((OriginalValue) & (~dwBitMask)) |
                            (dwData << BitShift));
                rtl92e_writel(dev, dwRegAddr, NewValue);
@@ -101,13 +93,14 @@ u32 rtl92e_get_bb_reg(struct net_device *dev, u32 dwRegAddr, u32 dwBitMask)
        u32 Ret = 0, OriginalValue, BitShift;
 
        OriginalValue = rtl92e_readl(dev, dwRegAddr);
-       BitShift = rtl8192_CalculateBitShift(dwBitMask);
+       BitShift = _rtl92e_calculate_bit_shift(dwBitMask);
        Ret = (OriginalValue & dwBitMask) >> BitShift;
 
        return Ret;
 }
-static u32 rtl8192_phy_RFSerialRead(struct net_device *dev,
-                                   enum rf90_radio_path eRFPath, u32 Offset)
+
+static u32 _rtl92e_phy_rf_read(struct net_device *dev,
+                              enum rf90_radio_path eRFPath, u32 Offset)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u32 ret = 0;
@@ -163,9 +156,9 @@ static u32 rtl8192_phy_RFSerialRead(struct net_device *dev,
 
 }
 
-static void rtl8192_phy_RFSerialWrite(struct net_device *dev,
-                                     enum rf90_radio_path eRFPath, u32 Offset,
-                                     u32 Data)
+static void _rtl92e_phy_rf_write(struct net_device *dev,
+                                enum rf90_radio_path eRFPath, u32 Offset,
+                                u32 Data)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u32 DataAndAddr = 0, NewOffset = 0;
@@ -228,29 +221,29 @@ void rtl92e_set_rf_reg(struct net_device *dev, enum rf90_radio_path eRFPath,
        RT_TRACE(COMP_PHY, "FW RF CTRL is not ready now\n");
        if (priv->Rf_Mode == RF_OP_By_FW) {
                if (BitMask != bMask12Bits) {
-                       Original_Value = phy_FwRFSerialRead(dev, eRFPath,
-                                                           RegAddr);
-                       BitShift =  rtl8192_CalculateBitShift(BitMask);
+                       Original_Value = _rtl92e_phy_rf_fw_read(dev, eRFPath,
+                                                               RegAddr);
+                       BitShift =  _rtl92e_calculate_bit_shift(BitMask);
                        New_Value = (((Original_Value) & (~BitMask)) |
                                    (Data << BitShift));
 
-                       phy_FwRFSerialWrite(dev, eRFPath, RegAddr, New_Value);
+                       _rtl92e_phy_rf_fw_write(dev, eRFPath, RegAddr,
+                                               New_Value);
                } else
-                       phy_FwRFSerialWrite(dev, eRFPath, RegAddr, Data);
+                       _rtl92e_phy_rf_fw_write(dev, eRFPath, RegAddr, Data);
                udelay(200);
 
        } else {
                if (BitMask != bMask12Bits) {
-                       Original_Value = rtl8192_phy_RFSerialRead(dev, eRFPath,
-                                                                 RegAddr);
-                       BitShift =  rtl8192_CalculateBitShift(BitMask);
+                       Original_Value = _rtl92e_phy_rf_read(dev, eRFPath,
+                                                            RegAddr);
+                       BitShift =  _rtl92e_calculate_bit_shift(BitMask);
                        New_Value = (((Original_Value) & (~BitMask)) |
                                     (Data << BitShift));
 
-                       rtl8192_phy_RFSerialWrite(dev, eRFPath, RegAddr,
-                                                 New_Value);
+                       _rtl92e_phy_rf_write(dev, eRFPath, RegAddr, New_Value);
                } else
-                       rtl8192_phy_RFSerialWrite(dev, eRFPath, RegAddr, Data);
+                       _rtl92e_phy_rf_write(dev, eRFPath, RegAddr, Data);
        }
 }
 
@@ -266,20 +259,19 @@ u32 rtl92e_get_rf_reg(struct net_device *dev, enum rf90_radio_path eRFPath,
                return  0;
        down(&priv->rf_sem);
        if (priv->Rf_Mode == RF_OP_By_FW) {
-               Original_Value = phy_FwRFSerialRead(dev, eRFPath, RegAddr);
+               Original_Value = _rtl92e_phy_rf_fw_read(dev, eRFPath, RegAddr);
                udelay(200);
        } else {
-               Original_Value = rtl8192_phy_RFSerialRead(dev, eRFPath,
-                                                         RegAddr);
+               Original_Value = _rtl92e_phy_rf_read(dev, eRFPath, RegAddr);
        }
-       BitShift =  rtl8192_CalculateBitShift(BitMask);
+       BitShift =  _rtl92e_calculate_bit_shift(BitMask);
        Readback_Value = (Original_Value & BitMask) >> BitShift;
        up(&priv->rf_sem);
        return Readback_Value;
 }
 
-static u32 phy_FwRFSerialRead(struct net_device *dev,
-                             enum rf90_radio_path eRFPath, u32 Offset)
+static u32 _rtl92e_phy_rf_fw_read(struct net_device *dev,
+                                 enum rf90_radio_path eRFPath, u32 Offset)
 {
        u32             Data = 0;
        u8              time = 0;
@@ -304,9 +296,9 @@ static u32 phy_FwRFSerialRead(struct net_device *dev,
 
 }
 
-static void phy_FwRFSerialWrite(struct net_device *dev,
-                               enum rf90_radio_path eRFPath,
-                               u32 Offset, u32 Data)
+static void _rtl92e_phy_rf_fw_write(struct net_device *dev,
+                                   enum rf90_radio_path eRFPath, u32 Offset,
+                                   u32 Data)
 {
        u8      time = 0;
 
@@ -355,7 +347,7 @@ void rtl92e_config_mac(struct net_device *dev)
 
 }
 
-static void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
+static void _rtl92e_phy_config_bb(struct net_device *dev, u8 ConfigType)
 {
        int i;
        u32 *Rtl819XPHY_REGArray_Table = NULL;
@@ -396,7 +388,7 @@ static void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
        }
 }
 
-static void rtl8192_InitBBRFRegDef(struct net_device *dev)
+static void _rtl92e_init_bb_rf_reg_def(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -545,7 +537,7 @@ bool rtl92e_check_bb_and_rf(struct net_device *dev, enum hw90_block CheckBlock,
        return ret;
 }
 
-static bool rtl8192_BB_Config_ParaFile(struct net_device *dev)
+static bool _rtl92e_bb_config_para_file(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        bool rtStatus = true;
@@ -571,12 +563,12 @@ static bool rtl8192_BB_Config_ParaFile(struct net_device *dev)
                }
        }
        rtl92e_set_bb_reg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
-       rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG);
+       _rtl92e_phy_config_bb(dev, BaseBand_Config_PHY_REG);
 
        dwRegValue = rtl92e_readl(dev, CPU_GEN);
        rtl92e_writel(dev, CPU_GEN, (dwRegValue|CPU_GEN_BB_RST));
 
-       rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB);
+       _rtl92e_phy_config_bb(dev, BaseBand_Config_AGC_TAB);
 
        if (priv->IC_Cut  > VERSION_8190_BD) {
                if (priv->rf_type == RF_2T4R)
@@ -598,8 +590,8 @@ static bool rtl8192_BB_Config_ParaFile(struct net_device *dev)
 }
 bool rtl92e_config_bb(struct net_device *dev)
 {
-       rtl8192_InitBBRFRegDef(dev);
-       return rtl8192_BB_Config_ParaFile(dev);
+       _rtl92e_init_bb_rf_reg_def(dev);
+       return _rtl92e_bb_config_para_file(dev);
 }
 
 void rtl92e_get_tx_power(struct net_device *dev)
@@ -757,8 +749,8 @@ u8 rtl92e_config_rf_path(struct net_device *dev, enum rf90_radio_path eRFPath)
        case RF90_PATH_D:
                for (i = 0; i < RadioD_ArrayLength; i += 2) {
                        if (Rtl819XRadioD_Array[i] == 0xfe) {
-                                       msleep(100);
-                                       continue;
+                               msleep(100);
+                               continue;
                        }
                        rtl92e_set_rf_reg(dev, eRFPath, Rtl819XRadioD_Array[i],
                                          bMask12Bits,
@@ -773,7 +765,8 @@ u8 rtl92e_config_rf_path(struct net_device *dev, enum rf90_radio_path eRFPath)
        return 0;
 
 }
-static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
+
+static void _rtl92e_set_tx_power_level(struct net_device *dev, u8 channel)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8      powerlevel = priv->TxPowerLevelCCK[channel-1];
@@ -796,11 +789,11 @@ static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
        }
 }
 
-static u8 rtl8192_phy_SetSwChnlCmdArray(struct net_device *dev,
-                                       struct sw_chnl_cmd *CmdTable,
-                                       u32 CmdTableIdx, u32 CmdTableSz,
-                                       enum sw_chnl_cmd_id CmdID,
-                                       u32 Para1, u32 Para2, u32 msDelay)
+static u8 _rtl92e_phy_set_sw_chnl_cmd_array(struct net_device *dev,
+                                           struct sw_chnl_cmd *CmdTable,
+                                           u32 CmdTableIdx, u32 CmdTableSz,
+                                           enum sw_chnl_cmd_id CmdID,
+                                           u32 Para1, u32 Para2, u32 msDelay)
 {
        struct sw_chnl_cmd *pCmd;
 
@@ -822,8 +815,8 @@ static u8 rtl8192_phy_SetSwChnlCmdArray(struct net_device *dev,
        return true;
 }
 
-static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
-                                      u8 *stage, u8 *step, u32 *delay)
+static u8 _rtl92e_phy_switch_channel_step(struct net_device *dev, u8 channel,
+                                         u8 *stage, u8 *step, u32 *delay)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -843,19 +836,22 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
 
        {
                PreCommonCmdCnt = 0;
-               rtl8192_phy_SetSwChnlCmdArray(dev, ieee->PreCommonCmd,
-                                       PreCommonCmdCnt++,
-                                       MAX_PRECMD_CNT, CmdID_SetTxPowerLevel,
-                                       0, 0, 0);
-               rtl8192_phy_SetSwChnlCmdArray(dev, ieee->PreCommonCmd,
-                                       PreCommonCmdCnt++,
-                                       MAX_PRECMD_CNT, CmdID_End, 0, 0, 0);
+               _rtl92e_phy_set_sw_chnl_cmd_array(dev, ieee->PreCommonCmd,
+                                                 PreCommonCmdCnt++,
+                                                 MAX_PRECMD_CNT,
+                                                 CmdID_SetTxPowerLevel,
+                                                 0, 0, 0);
+               _rtl92e_phy_set_sw_chnl_cmd_array(dev, ieee->PreCommonCmd,
+                                                 PreCommonCmdCnt++,
+                                                 MAX_PRECMD_CNT, CmdID_End,
+                                                 0, 0, 0);
 
                PostCommonCmdCnt = 0;
 
-               rtl8192_phy_SetSwChnlCmdArray(dev, ieee->PostCommonCmd,
-                                       PostCommonCmdCnt++,
-                                       MAX_POSTCMD_CNT, CmdID_End, 0, 0, 0);
+               _rtl92e_phy_set_sw_chnl_cmd_array(dev, ieee->PostCommonCmd,
+                                                 PostCommonCmdCnt++,
+                                                 MAX_POSTCMD_CNT, CmdID_End,
+                                                 0, 0, 0);
 
                RfDependCmdCnt = 0;
                switch (priv->rf_chip) {
@@ -866,13 +862,19 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
                                           channel);
                                return false;
                        }
-                       rtl8192_phy_SetSwChnlCmdArray(dev, ieee->RfDependCmd,
-                               RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
-                               CmdID_RF_WriteReg, rZebra1_Channel,
-                               RF_CHANNEL_TABLE_ZEBRA[channel], 10);
-                       rtl8192_phy_SetSwChnlCmdArray(dev, ieee->RfDependCmd,
-                               RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
-                               CmdID_End, 0, 0, 0);
+                       _rtl92e_phy_set_sw_chnl_cmd_array(dev,
+                                                         ieee->RfDependCmd,
+                                                         RfDependCmdCnt++,
+                                                         MAX_RFDEPENDCMD_CNT,
+                                                         CmdID_RF_WriteReg,
+                                                         rZebra1_Channel,
+                                                         RF_CHANNEL_TABLE_ZEBRA[channel],
+                                                         10);
+                       _rtl92e_phy_set_sw_chnl_cmd_array(dev,
+                                                         ieee->RfDependCmd,
+                                                         RfDependCmdCnt++,
+                                                         MAX_RFDEPENDCMD_CNT,
+                                                         CmdID_End, 0, 0, 0);
                        break;
 
                case RF_8256:
@@ -882,15 +884,18 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
                                           channel);
                                return false;
                        }
-                       rtl8192_phy_SetSwChnlCmdArray(dev, ieee->RfDependCmd,
-                                RfDependCmdCnt++, MAX_RFDEPENDCMD_CNT,
-                               CmdID_RF_WriteReg, rZebra1_Channel, channel,
-                                10);
-                       rtl8192_phy_SetSwChnlCmdArray(dev, ieee->RfDependCmd,
-
-                                                     RfDependCmdCnt++,
-                                                     MAX_RFDEPENDCMD_CNT,
-                       CmdID_End, 0, 0, 0);
+                       _rtl92e_phy_set_sw_chnl_cmd_array(dev,
+                                                         ieee->RfDependCmd,
+                                                         RfDependCmdCnt++,
+                                                         MAX_RFDEPENDCMD_CNT,
+                                                         CmdID_RF_WriteReg,
+                                                         rZebra1_Channel,
+                                                         channel, 10);
+                       _rtl92e_phy_set_sw_chnl_cmd_array(dev,
+                                                         ieee->RfDependCmd,
+                                                         RfDependCmdCnt++,
+                                                         MAX_RFDEPENDCMD_CNT,
+                                                         CmdID_End, 0, 0, 0);
                        break;
 
                case RF_8258:
@@ -928,7 +933,8 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
                        switch (CurrentCmd->CmdID) {
                        case CmdID_SetTxPowerLevel:
                                if (priv->IC_Cut > (u8)VERSION_8190_BD)
-                                       rtl8192_SetTxPowerLevel(dev, channel);
+                                       _rtl92e_set_tx_power_level(dev,
+                                                                  channel);
                                break;
                        case CmdID_WritePortUlong:
                                rtl92e_writel(dev, CurrentCmd->Para1,
@@ -963,20 +969,22 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
        return false;
 }
 
-static void rtl8192_phy_FinishSwChnlNow(struct net_device *dev, u8 channel)
+static void _rtl92e_phy_switch_channel(struct net_device *dev, u8 channel)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u32 delay = 0;
 
-       while (!rtl8192_phy_SwChnlStepByStep(dev, channel, &priv->SwChnlStage,
-             &priv->SwChnlStep, &delay)) {
+       while (!_rtl92e_phy_switch_channel_step(dev, channel,
+                                               &priv->SwChnlStage,
+                                               &priv->SwChnlStep, &delay)) {
                if (delay > 0)
                        msleep(delay);
                if (!priv->up)
                        break;
        }
 }
-static void rtl8192_SwChnl_WorkItem(struct net_device *dev)
+
+static void _rtl92e_phy_switch_channel_work_item(struct net_device *dev)
 {
 
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -986,7 +994,7 @@ static void rtl8192_SwChnl_WorkItem(struct net_device *dev)
        RT_TRACE(COMP_TRACE, "=====>--%s(), set chan:%d, priv:%p\n", __func__,
                 priv->chan, priv);
 
-       rtl8192_phy_FinishSwChnlNow(dev, priv->chan);
+       _rtl92e_phy_switch_channel(dev, priv->chan);
 
        RT_TRACE(COMP_TRACE, "<== SwChnlCallback819xUsbWorkItem()\n");
 }
@@ -1043,12 +1051,12 @@ u8 rtl92e_set_channel(struct net_device *dev, u8 channel)
        priv->SwChnlStep = 0;
 
        if (priv->up)
-               rtl8192_SwChnl_WorkItem(dev);
+               _rtl92e_phy_switch_channel_work_item(dev);
        priv->SwChnlInProgress = false;
        return true;
 }
 
-static void CCK_Tx_Power_Track_BW_Switch_TSSI(struct net_device *dev)
+static void _rtl92e_cck_tx_power_track_bw_switch_tssi(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -1112,7 +1120,7 @@ static void CCK_Tx_Power_Track_BW_Switch_TSSI(struct net_device *dev)
        }
 }
 
-static void CCK_Tx_Power_Track_BW_Switch_ThermalMeter(struct net_device *dev)
+static void _rtl92e_cck_tx_power_track_bw_switch_thermal(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -1129,38 +1137,38 @@ static void CCK_Tx_Power_Track_BW_Switch_ThermalMeter(struct net_device *dev)
                        priv->Record_CCK_20Mindex = 6;
                priv->CCK_index = priv->Record_CCK_20Mindex;
                RT_TRACE(COMP_POWER_TRACKING,
-                        "20MHz, CCK_Tx_Power_Track_BW_Switch_ThermalMeter(),CCK_index = %d\n",
+                        "20MHz, _rtl92e_cck_tx_power_track_bw_switch_thermal(),CCK_index = %d\n",
                         priv->CCK_index);
        break;
 
        case HT_CHANNEL_WIDTH_20_40:
                priv->CCK_index = priv->Record_CCK_40Mindex;
                RT_TRACE(COMP_POWER_TRACKING,
-                        "40MHz, CCK_Tx_Power_Track_BW_Switch_ThermalMeter(), CCK_index = %d\n",
+                        "40MHz, _rtl92e_cck_tx_power_track_bw_switch_thermal(), CCK_index = %d\n",
                         priv->CCK_index);
        break;
        }
        rtl92e_dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
 }
 
-static void CCK_Tx_Power_Track_BW_Switch(struct net_device *dev)
+static void _rtl92e_cck_tx_power_track_bw_switch(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        if (priv->IC_Cut >= IC_VersionCut_D)
-               CCK_Tx_Power_Track_BW_Switch_TSSI(dev);
+               _rtl92e_cck_tx_power_track_bw_switch_tssi(dev);
        else
-               CCK_Tx_Power_Track_BW_Switch_ThermalMeter(dev);
+               _rtl92e_cck_tx_power_track_bw_switch_thermal(dev);
 }
 
-static void rtl8192_SetBWModeWorkItem(struct net_device *dev)
+static void _rtl92e_set_bw_mode_work_item(struct net_device *dev)
 {
 
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 regBwOpMode;
 
        RT_TRACE(COMP_SWBW,
-                "==>rtl8192_SetBWModeWorkItem()  Switch to %s bandwidth\n",
+                "==>_rtl92e_set_bw_mode_work_item()  Switch to %s bandwidth\n",
                 priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 ?
                         "20MHz" : "40MHz");
 
@@ -1202,7 +1210,7 @@ static void rtl8192_SetBWModeWorkItem(struct net_device *dev)
                        rtl92e_writel(dev, rCCK0_TxFilter2, 0x090e1317);
                        rtl92e_writel(dev, rCCK0_DebugPort, 0x00000204);
                } else {
-                       CCK_Tx_Power_Track_BW_Switch(dev);
+                       _rtl92e_cck_tx_power_track_bw_switch(dev);
                }
 
                rtl92e_set_bb_reg(dev, rFPGA0_AnalogParameter1, 0x00100000, 1);
@@ -1217,7 +1225,7 @@ static void rtl8192_SetBWModeWorkItem(struct net_device *dev)
                        rtl92e_writel(dev, rCCK0_TxFilter2, 0x121c252e);
                        rtl92e_writel(dev, rCCK0_DebugPort, 0x00000409);
                } else {
-                       CCK_Tx_Power_Track_BW_Switch(dev);
+                       _rtl92e_cck_tx_power_track_bw_switch(dev);
                }
 
                rtl92e_set_bb_reg(dev, rCCK0_System, bCCKSideBand,
@@ -1281,7 +1289,7 @@ void rtl92e_set_bw_mode(struct net_device *dev, enum ht_channel_width Bandwidth,
        else
                priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
 
-       rtl8192_SetBWModeWorkItem(dev);
+       _rtl92e_set_bw_mode_work_item(dev);
 
 }
 
@@ -1409,8 +1417,8 @@ void rtl92e_set_rf_off(struct net_device *dev)
 
 }
 
-static bool SetRFPowerState8190(struct net_device *dev,
-                               enum rt_rf_power_state eRFPowerState)
+static bool _rtl92e_set_rf_power_state(struct net_device *dev,
+                                      enum rt_rf_power_state eRFPowerState)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
@@ -1421,14 +1429,15 @@ static bool SetRFPowerState8190(struct net_device *dev,
 
        if (priv->SetRFPowerStateInProgress)
                return false;
-       RT_TRACE(COMP_PS, "===========> SetRFPowerState8190()!\n");
+       RT_TRACE(COMP_PS, "===========> _rtl92e_set_rf_power_state()!\n");
        priv->SetRFPowerStateInProgress = true;
 
        switch (priv->rf_chip) {
        case RF_8256:
                switch (eRFPowerState) {
                case eRfOn:
-                       RT_TRACE(COMP_PS, "SetRFPowerState8190() eRfOn!\n");
+                       RT_TRACE(COMP_PS,
+                                "_rtl92e_set_rf_power_state() eRfOn!\n");
                        if ((priv->rtllib->eRFPowerState == eRfOff) &&
                             RT_IN_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC)) {
                                bool rtstatus = true;
@@ -1495,7 +1504,7 @@ static bool SetRFPowerState8190(struct net_device *dev,
 
                                if (i >= MAX_DOZE_WAITING_TIMES_9x) {
                                        RT_TRACE(COMP_POWER,
-                                                "\n\n\n TimeOut!! SetRFPowerState8190(): eRfOff: %d times TcbBusyQueue[%d] != 0 !!!\n",
+                                                "\n\n\n TimeOut!! _rtl92e_set_rf_power_state(): eRfOff: %d times TcbBusyQueue[%d] != 0 !!!\n",
                                                 MAX_DOZE_WAITING_TIMES_9x,
                                                 QueueID);
                                        break;
@@ -1506,7 +1515,7 @@ static bool SetRFPowerState8190(struct net_device *dev,
 
                case eRfOff:
                        RT_TRACE(COMP_PS,
-                                "SetRFPowerState8190() eRfOff/Sleep !\n");
+                                "_rtl92e_set_rf_power_state() eRfOff/Sleep !\n");
 
                        for (QueueID = 0, i = 0; QueueID < MAX_TX_QUEUE; ) {
                                ring = &priv->tx_ring[QueueID];
@@ -1571,7 +1580,8 @@ static bool SetRFPowerState8190(struct net_device *dev,
        }
 
        priv->SetRFPowerStateInProgress = false;
-       RT_TRACE(COMP_PS, "<=========== SetRFPowerState8190() bResult = %d!\n",
+       RT_TRACE(COMP_PS,
+                "<=========== _rtl92e_set_rf_power_state() bResult = %d!\n",
                 bResult);
        return bResult;
 }
@@ -1594,7 +1604,7 @@ bool rtl92e_set_rf_power_state(struct net_device *dev,
                return bResult;
        }
 
-       bResult = SetRFPowerState8190(dev, eRFPowerState);
+       bResult = _rtl92e_set_rf_power_state(dev, eRFPowerState);
 
        RT_TRACE(COMP_PS,
                 "<--------- rtl92e_set_rf_power_state(): bResult(%d)\n",
index 96015d342009c204594438ccd7b57828d310ef86..9ddfd4e3adb3d988c96c63d1614f18776266f2cb 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 8a1d91e05da927f9b5f0a613880561f71b6364e2..50c79d3dc782f9494ecfcd841247e047f0b98aef 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 29dd93ac5e93fdfd4e3eacc67116023e01746408..803c8b02a0c81a3eb9c0a7bfa5215a6e4737b1f1 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -43,8 +39,8 @@ void rtl92e_enable_hw_security_config(struct net_device *dev)
        struct rtllib_device *ieee = priv->rtllib;
 
        SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
-       if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) ||
-            (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) &&
+       if (((ieee->pairwise_key_type == KEY_TYPE_WEP40) ||
+            (ieee->pairwise_key_type == KEY_TYPE_WEP104)) &&
             (priv->rtllib->auth_mode != 2)) {
                SECR_value |= SCR_RxUseDK;
                SECR_value |= SCR_TxUseDK;
index 9ef8b36fc6b51bfb965ada3322fb3bbdaacb1f61..aa12941dc685b1510e50ce8502702015207218a8 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index d6b46dfd01e133bbb16de5f636ae52e4c812c488..8f989a95a019261556ef10e92a4820764c7bd635 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -73,36 +69,36 @@ static struct pci_device_id rtl8192_pci_id_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl);
 
-static int rtl8192_pci_probe(struct pci_dev *pdev,
-                       const struct pci_device_id *id);
-static void rtl8192_pci_disconnect(struct pci_dev *pdev);
-static irqreturn_t rtl8192_interrupt(int irq, void *netdev);
+static int _rtl92e_pci_probe(struct pci_dev *pdev,
+                            const struct pci_device_id *id);
+static void _rtl92e_pci_disconnect(struct pci_dev *pdev);
+static irqreturn_t _rtl92e_irq(int irq, void *netdev);
 
 static struct pci_driver rtl8192_pci_driver = {
        .name = DRV_NAME,       /* Driver name   */
        .id_table = rtl8192_pci_id_tbl, /* PCI_ID table  */
-       .probe  = rtl8192_pci_probe,    /* probe fn      */
-       .remove  = rtl8192_pci_disconnect,      /* remove fn */
+       .probe  = _rtl92e_pci_probe,    /* probe fn      */
+       .remove  = _rtl92e_pci_disconnect,      /* remove fn */
        .suspend = rtl92e_suspend,      /* PM suspend fn */
        .resume = rtl92e_resume,                 /* PM resume fn  */
 };
 
-static short rtl8192_is_tx_queue_empty(struct net_device *dev);
-static void rtl819x_watchdog_wqcallback(void *data);
-static void watch_dog_timer_callback(unsigned long data);
-static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
+static short _rtl92e_is_tx_queue_empty(struct net_device *dev);
+static void _rtl92e_watchdog_wq_cb(void *data);
+static void _rtl92e_watchdog_timer_cb(unsigned long data);
+static void _rtl92e_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
                                   int rate);
-static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
-static void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb);
-static short rtl8192_tx(struct net_device *dev, struct sk_buff *skb);
-static short rtl8192_pci_initdescring(struct net_device *dev);
-static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv);
-static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
-static void rtl8192_cancel_deferred_work(struct r8192_priv *priv);
-static int _rtl8192_up(struct net_device *dev, bool is_silent_reset);
-static int rtl8192_up(struct net_device *dev);
-static int rtl8192_down(struct net_device *dev, bool shutdownrf);
-static void rtl8192_restart(void *data);
+static int _rtl92e_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
+static void _rtl92e_tx_cmd(struct net_device *dev, struct sk_buff *skb);
+static short _rtl92e_tx(struct net_device *dev, struct sk_buff *skb);
+static short _rtl92e_pci_initdescring(struct net_device *dev);
+static void _rtl92e_irq_tx_tasklet(struct r8192_priv *priv);
+static void _rtl92e_irq_rx_tasklet(struct r8192_priv *priv);
+static void _rtl92e_cancel_deferred_work(struct r8192_priv *priv);
+static int _rtl92e_up(struct net_device *dev, bool is_silent_reset);
+static int _rtl92e_try_up(struct net_device *dev);
+static int _rtl92e_down(struct net_device *dev, bool shutdownrf);
+static void _rtl92e_restart(void *data);
 
 /****************************************************************************
    -----------------------------IO STUFF-------------------------
@@ -272,7 +268,7 @@ bool rtl92e_set_rf_state(struct net_device *dev,
        return bActionAllowed;
 }
 
-static short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
+static short _rtl92e_check_nic_enough_desc(struct net_device *dev, int prio)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
@@ -282,7 +278,7 @@ static short rtl8192_check_nic_enough_desc(struct net_device *dev, int prio)
        return 0;
 }
 
-static void rtl8192_tx_timeout(struct net_device *dev)
+static void _rtl92e_tx_timeout(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -308,7 +304,7 @@ void rtl92e_irq_disable(struct net_device *dev)
        priv->irq_enabled = 0;
 }
 
-static void rtl8192_set_chan(struct net_device *dev, short ch)
+static void _rtl92e_set_chan(struct net_device *dev, short ch)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
@@ -322,7 +318,7 @@ static void rtl8192_set_chan(struct net_device *dev, short ch)
                priv->rf_set_chan(dev, priv->chan);
 }
 
-static void rtl8192_update_cap(struct net_device *dev, u16 cap)
+static void _rtl92e_update_cap(struct net_device *dev, u16 cap)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_network *net = &priv->rtllib->current_network;
@@ -379,7 +375,7 @@ static struct rtllib_qos_parameters def_qos_parameters = {
        {0, 0, 0, 0}
 };
 
-static void rtl8192_update_beacon(void *data)
+static void _rtl92e_update_beacon(void *data)
 {
        struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
                                  update_beacon_wq.work);
@@ -392,10 +388,10 @@ static void rtl8192_update_beacon(void *data)
        ieee->pHTInfo->bCurrentRT2RTLongSlotTime =
                 net->bssht.bdRT2RTLongSlotTime;
        ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode;
-       rtl8192_update_cap(dev, net->capability);
+       _rtl92e_update_cap(dev, net->capability);
 }
 
-static void rtl8192_qos_activate(void *data)
+static void _rtl92e_qos_activate(void *data)
 {
        struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
                                  qos_activate);
@@ -416,9 +412,9 @@ success:
        mutex_unlock(&priv->mutex);
 }
 
-static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
-               int active_network,
-               struct rtllib_network *network)
+static int _rtl92e_qos_handle_probe_response(struct r8192_priv *priv,
+                                            int active_network,
+                                            struct rtllib_network *network)
 {
        int ret = 0;
        u32 size = sizeof(struct rtllib_qos_parameters);
@@ -461,21 +457,21 @@ static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
        return 0;
 }
 
-static int rtl8192_handle_beacon(struct net_device *dev,
-       struct rtllib_beacon *beacon,
-       struct rtllib_network *network)
+static int _rtl92e_handle_beacon(struct net_device *dev,
+                                struct rtllib_beacon *beacon,
+                                struct rtllib_network *network)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
-       rtl8192_qos_handle_probe_response(priv, 1, network);
+       _rtl92e_qos_handle_probe_response(priv, 1, network);
 
        queue_delayed_work_rsl(priv->priv_wq, &priv->update_beacon_wq, 0);
        return 0;
 
 }
 
-static int rtl8192_qos_association_resp(struct r8192_priv *priv,
-       struct rtllib_network *network)
+static int _rtl92e_qos_assoc_resp(struct r8192_priv *priv,
+                                 struct rtllib_network *network)
 {
        unsigned long flags;
        u32 size = sizeof(struct rtllib_qos_parameters);
@@ -521,17 +517,17 @@ static int rtl8192_qos_association_resp(struct r8192_priv *priv,
        return 0;
 }
 
-static int rtl8192_handle_assoc_response(struct net_device *dev,
+static int _rtl92e_handle_assoc_response(struct net_device *dev,
                                 struct rtllib_assoc_response_frame *resp,
                                 struct rtllib_network *network)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
-       rtl8192_qos_association_resp(priv, network);
+       _rtl92e_qos_assoc_resp(priv, network);
        return 0;
 }
 
-static void rtl8192_prepare_beacon(struct r8192_priv *priv)
+static void _rtl92e_prepare_beacon(struct r8192_priv *priv)
 {
        struct net_device *dev = priv->rtllib->dev;
        struct sk_buff *pskb = NULL, *pnewskb = NULL;
@@ -561,7 +557,7 @@ static void rtl8192_prepare_beacon(struct r8192_priv *priv)
        pdesc->OWN = 1;
 }
 
-static void rtl8192_stop_beacon(struct net_device *dev)
+static void _rtl92e_stop_beacon(struct net_device *dev)
 {
 }
 
@@ -658,7 +654,7 @@ void rtl92e_config_rate(struct net_device *dev, u16 *rate_config)
        }
 }
 
-static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
+static void _rtl92e_refresh_support_rate(struct r8192_priv *priv)
 {
        struct rtllib_device *ieee = priv->rtllib;
 
@@ -674,7 +670,7 @@ static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
        }
 }
 
-static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
+static u8 _rtl92e_get_supported_wireless_mode(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 ret = 0;
@@ -699,7 +695,7 @@ static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
 void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
-       u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
+       u8 bSupportMode = _rtl92e_get_supported_wireless_mode(dev);
 
        if ((wireless_mode == WIRELESS_MODE_AUTO) ||
            ((wireless_mode & bSupportMode) == 0)) {
@@ -739,10 +735,10 @@ void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode)
        }
 
        RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
-       rtl8192_refresh_supportrate(priv);
+       _rtl92e_refresh_support_rate(priv);
 }
 
-static int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
+static int _rtl92e_sta_up(struct net_device *dev, bool is_silent_reset)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
@@ -775,7 +771,7 @@ static int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
        if (priv->rtllib->state != RTLLIB_LINKED)
                rtllib_softmac_start_protocol(priv->rtllib, 0);
        rtllib_reset_queue(priv->rtllib);
-       watch_dog_timer_callback((unsigned long) dev);
+       _rtl92e_watchdog_timer_cb((unsigned long)dev);
 
        if (!netif_queue_stopped(dev))
                netif_start_queue(dev);
@@ -785,7 +781,7 @@ static int _rtl8192_sta_up(struct net_device *dev, bool is_silent_reset)
        return 0;
 }
 
-static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
+static int _rtl92e_sta_down(struct net_device *dev, bool shutdownrf)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        unsigned long flags = 0;
@@ -816,7 +812,7 @@ static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
        rtl92e_irq_disable(dev);
 
        del_timer_sync(&priv->watch_dog_timer);
-       rtl8192_cancel_deferred_work(priv);
+       _rtl92e_cancel_deferred_work(priv);
        cancel_delayed_work(&priv->rtllib->hw_wakeup_wq);
 
        rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
@@ -848,28 +844,28 @@ static int rtl8192_sta_down(struct net_device *dev, bool shutdownrf)
        return 0;
 }
 
-static void rtl8192_init_priv_handler(struct net_device *dev)
+static void _rtl92e_init_priv_handler(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
-       priv->rtllib->softmac_hard_start_xmit   = rtl8192_hard_start_xmit;
-       priv->rtllib->set_chan                  = rtl8192_set_chan;
+       priv->rtllib->softmac_hard_start_xmit   = _rtl92e_hard_start_xmit;
+       priv->rtllib->set_chan                  = _rtl92e_set_chan;
        priv->rtllib->link_change               = priv->ops->link_change;
-       priv->rtllib->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
-       priv->rtllib->check_nic_enough_desc     = rtl8192_check_nic_enough_desc;
-       priv->rtllib->handle_assoc_response     = rtl8192_handle_assoc_response;
-       priv->rtllib->handle_beacon             = rtl8192_handle_beacon;
+       priv->rtllib->softmac_data_hard_start_xmit = _rtl92e_hard_data_xmit;
+       priv->rtllib->check_nic_enough_desc     = _rtl92e_check_nic_enough_desc;
+       priv->rtllib->handle_assoc_response     = _rtl92e_handle_assoc_response;
+       priv->rtllib->handle_beacon             = _rtl92e_handle_beacon;
        priv->rtllib->SetWirelessMode           = rtl92e_set_wireless_mode;
        priv->rtllib->LeisurePSLeave            = rtl92e_leisure_ps_leave;
        priv->rtllib->SetBWModeHandler          = rtl92e_set_bw_mode;
        priv->rf_set_chan                       = rtl92e_set_channel;
 
        priv->rtllib->start_send_beacons = rtl92e_start_beacon;
-       priv->rtllib->stop_send_beacons = rtl8192_stop_beacon;
+       priv->rtllib->stop_send_beacons = _rtl92e_stop_beacon;
 
        priv->rtllib->sta_wake_up = rtl92e_hw_wakeup;
        priv->rtllib->enter_sleep_state = rtl92e_enter_sleep;
-       priv->rtllib->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
+       priv->rtllib->ps_is_queue_empty = _rtl92e_is_tx_queue_empty;
 
        priv->rtllib->GetNmodeSupportBySecCfg = rtl92e_get_nmode_support_by_sec;
        priv->rtllib->GetHalfNmodeSupportByAPsHandler =
@@ -888,7 +884,7 @@ static void rtl8192_init_priv_handler(struct net_device *dev)
        priv->rtllib->ScanOperationBackupHandler = rtl92e_scan_op_backup;
 }
 
-static void rtl8192_init_priv_constant(struct net_device *dev)
+static void _rtl92e_init_priv_constant(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
@@ -898,7 +894,7 @@ static void rtl8192_init_priv_constant(struct net_device *dev)
 }
 
 
-static void rtl8192_init_priv_variable(struct net_device *dev)
+static void _rtl92e_init_priv_variable(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 i;
@@ -991,7 +987,7 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
                skb_queue_head_init(&priv->rtllib->skb_aggQ[i]);
 }
 
-static void rtl8192_init_priv_lock(struct r8192_priv *priv)
+static void _rtl92e_init_priv_lock(struct r8192_priv *priv)
 {
        spin_lock_init(&priv->tx_lock);
        spin_lock_init(&priv->irq_th_lock);
@@ -1002,39 +998,39 @@ static void rtl8192_init_priv_lock(struct r8192_priv *priv)
        mutex_init(&priv->mutex);
 }
 
-static void rtl8192_init_priv_task(struct net_device *dev)
+static void _rtl92e_init_priv_task(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        priv->priv_wq = create_workqueue(DRV_NAME);
-       INIT_WORK_RSL(&priv->reset_wq, (void *)rtl8192_restart, dev);
+       INIT_WORK_RSL(&priv->reset_wq, (void *)_rtl92e_restart, dev);
        INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)rtl92e_ips_leave_wq,
                      dev);
        INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq,
-                             (void *)rtl819x_watchdog_wqcallback, dev);
+                             (void *)_rtl92e_watchdog_wq_cb, dev);
        INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq,
                              (void *)rtl92e_dm_txpower_tracking_wq, dev);
        INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq,
                              (void *)rtl92e_dm_rf_pathcheck_wq, dev);
        INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq,
-                             (void *)rtl8192_update_beacon, dev);
-       INIT_WORK_RSL(&priv->qos_activate, (void *)rtl8192_qos_activate, dev);
+                             (void *)_rtl92e_update_beacon, dev);
+       INIT_WORK_RSL(&priv->qos_activate, (void *)_rtl92e_qos_activate, dev);
        INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq,
                              (void *) rtl92e_hw_wakeup_wq, dev);
        INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq,
                              (void *) rtl92e_hw_sleep_wq, dev);
        tasklet_init(&priv->irq_rx_tasklet,
-                    (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
+                    (void(*)(unsigned long))_rtl92e_irq_rx_tasklet,
                     (unsigned long)priv);
        tasklet_init(&priv->irq_tx_tasklet,
-                    (void(*)(unsigned long))rtl8192_irq_tx_tasklet,
+                    (void(*)(unsigned long))_rtl92e_irq_tx_tasklet,
                     (unsigned long)priv);
        tasklet_init(&priv->irq_prepare_beacon_tasklet,
-                    (void(*)(unsigned long))rtl8192_prepare_beacon,
+                    (void(*)(unsigned long))_rtl92e_prepare_beacon,
                     (unsigned long)priv);
 }
 
-static short rtl8192_get_channel_map(struct net_device *dev)
+static short _rtl92e_get_channel_map(struct net_device *dev)
 {
        int i;
 
@@ -1063,25 +1059,25 @@ static short rtl8192_get_channel_map(struct net_device *dev)
        return 0;
 }
 
-static short rtl8192_init(struct net_device *dev)
+static short _rtl92e_init(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        memset(&(priv->stats), 0, sizeof(struct rt_stats));
 
-       rtl8192_init_priv_handler(dev);
-       rtl8192_init_priv_constant(dev);
-       rtl8192_init_priv_variable(dev);
-       rtl8192_init_priv_lock(priv);
-       rtl8192_init_priv_task(dev);
+       _rtl92e_init_priv_handler(dev);
+       _rtl92e_init_priv_constant(dev);
+       _rtl92e_init_priv_variable(dev);
+       _rtl92e_init_priv_lock(priv);
+       _rtl92e_init_priv_task(dev);
        priv->ops->get_eeprom_size(dev);
        priv->ops->init_adapter_variable(dev);
-       rtl8192_get_channel_map(dev);
+       _rtl92e_get_channel_map(dev);
 
        rtl92e_dm_init(dev);
 
        setup_timer(&priv->watch_dog_timer,
-                   watch_dog_timer_callback,
+                   _rtl92e_watchdog_timer_cb,
                    (unsigned long) dev);
 
        setup_timer(&priv->gpio_polling_timer,
@@ -1089,8 +1085,7 @@ static short rtl8192_init(struct net_device *dev)
                    (unsigned long)dev);
 
        rtl92e_irq_disable(dev);
-       if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED,
-           dev->name, dev)) {
+       if (request_irq(dev->irq, _rtl92e_irq, IRQF_SHARED, dev->name, dev)) {
                netdev_err(dev, "Error allocating IRQ %d", dev->irq);
                return -1;
        }
@@ -1098,7 +1093,7 @@ static short rtl8192_init(struct net_device *dev)
        priv->irq = dev->irq;
        RT_TRACE(COMP_INIT, "IRQ %d\n", dev->irq);
 
-       if (rtl8192_pci_initdescring(dev) != 0) {
+       if (_rtl92e_pci_initdescring(dev) != 0) {
                netdev_err(dev, "Endopoints initialization failed");
                free_irq(dev->irq, dev);
                return -1;
@@ -1110,7 +1105,7 @@ static short rtl8192_init(struct net_device *dev)
 /***************************************************************************
        -------------------------------WATCHDOG STUFF---------------------------
 ***************************************************************************/
-static short rtl8192_is_tx_queue_empty(struct net_device *dev)
+static short _rtl92e_is_tx_queue_empty(struct net_device *dev)
 {
        int i = 0;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -1127,11 +1122,10 @@ static short rtl8192_is_tx_queue_empty(struct net_device *dev)
        return 1;
 }
 
-static enum reset_type rtl819x_TxCheckStuck(struct net_device *dev)
+static enum reset_type _rtl92e_tx_check_stuck(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8      QueueID;
-       u8      ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
        bool    bCheckFwTxCnt = false;
        struct rtl8192_tx_ring  *ring = NULL;
        struct sk_buff *skb = NULL;
@@ -1140,13 +1134,10 @@ static enum reset_type rtl819x_TxCheckStuck(struct net_device *dev)
 
        switch (priv->rtllib->ps) {
        case RTLLIB_PS_DISABLED:
-               ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
                break;
        case (RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST):
-               ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
                break;
        default:
-               ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
                break;
        }
        spin_lock_irqsave(&priv->irq_th_lock, flags);
@@ -1187,7 +1178,7 @@ static enum reset_type rtl819x_TxCheckStuck(struct net_device *dev)
        return RESET_TYPE_NORESET;
 }
 
-static enum reset_type rtl819x_RxCheckStuck(struct net_device *dev)
+static enum reset_type _rtl92e_rx_check_stuck(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -1199,7 +1190,7 @@ static enum reset_type rtl819x_RxCheckStuck(struct net_device *dev)
        return RESET_TYPE_NORESET;
 }
 
-static enum reset_type rtl819x_ifcheck_resetornot(struct net_device *dev)
+static enum reset_type _rtl92e_if_check_reset(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        enum reset_type TxResetType = RESET_TYPE_NORESET;
@@ -1209,12 +1200,12 @@ static enum reset_type rtl819x_ifcheck_resetornot(struct net_device *dev)
        rfState = priv->rtllib->eRFPowerState;
 
        if (rfState == eRfOn)
-               TxResetType = rtl819x_TxCheckStuck(dev);
+               TxResetType = _rtl92e_tx_check_stuck(dev);
 
        if (rfState == eRfOn &&
            (priv->rtllib->iw_mode == IW_MODE_INFRA) &&
            (priv->rtllib->state == RTLLIB_LINKED))
-               RxResetType = rtl819x_RxCheckStuck(dev);
+               RxResetType = _rtl92e_rx_check_stuck(dev);
 
        if (TxResetType == RESET_TYPE_NORMAL ||
            RxResetType == RESET_TYPE_NORMAL) {
@@ -1232,11 +1223,7 @@ static enum reset_type rtl819x_ifcheck_resetornot(struct net_device *dev)
 
 }
 
-static void rtl819x_silentreset_mesh_bk(struct net_device *dev, u8 IsPortal)
-{
-}
-
-static void rtl819x_ifsilentreset(struct net_device *dev)
+static void _rtl92e_if_silent_reset(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8      reset_times = 0;
@@ -1244,9 +1231,6 @@ static void rtl819x_ifsilentreset(struct net_device *dev)
        struct rtllib_device *ieee = priv->rtllib;
        unsigned long flag;
 
-       u8 IsPortal = 0;
-
-
        if (priv->ResetProgress == RESET_TYPE_NORESET) {
 
                RT_TRACE(COMP_RESET, "=========>Reset progress!!\n");
@@ -1289,7 +1273,7 @@ RESET_START:
 
                rtl92e_irq_disable(dev);
                del_timer_sync(&priv->watch_dog_timer);
-               rtl8192_cancel_deferred_work(priv);
+               _rtl92e_cancel_deferred_work(priv);
                rtl92e_dm_deinit(dev);
                rtllib_stop_scan_syncro(ieee);
 
@@ -1316,7 +1300,7 @@ RESET_START:
 
                RT_TRACE(COMP_RESET, "%s():<===========up process start\n",
                         __func__);
-               reset_status = _rtl8192_up(dev, true);
+               reset_status = _rtl92e_up(dev, true);
 
                RT_TRACE(COMP_RESET,
                         "%s():<===========up process is finished\n", __func__);
@@ -1356,8 +1340,6 @@ RESET_START:
                        rtllib_start_send_beacons(ieee);
 
                        netif_carrier_on(ieee->dev);
-               } else if (ieee->iw_mode == IW_MODE_MESH) {
-                       rtl819x_silentreset_mesh_bk(dev, IsPortal);
                }
 
                rtl92e_cam_restore(dev);
@@ -1375,7 +1357,7 @@ END:
        }
 }
 
-static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
+static void _rtl92e_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
                                    u32 *TotalRxDataNum)
 {
        u16     SlotIndex;
@@ -1396,7 +1378,7 @@ static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
        }
 }
 
-static void rtl819x_watchdog_wqcallback(void *data)
+static void _rtl92e_watchdog_wq_cb(void *data)
 {
        struct r8192_priv *priv = container_of_dwork_rsl(data,
                                  struct r8192_priv, watch_dog_wq);
@@ -1486,7 +1468,7 @@ static void rtl819x_watchdog_wqcallback(void *data)
                u32     TotalRxBcnNum = 0;
                u32     TotalRxDataNum = 0;
 
-               rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
+               _rtl92e_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
 
                if ((TotalRxBcnNum+TotalRxDataNum) == 0)
                        priv->check_roaming_cnt++;
@@ -1530,7 +1512,7 @@ static void rtl819x_watchdog_wqcallback(void *data)
        spin_lock_irqsave(&priv->tx_lock, flags);
        if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) &&
            (!priv->RFChangeInProgress) && (!pPSC->bSwRfProcessing)) {
-               ResetType = rtl819x_ifcheck_resetornot(dev);
+               ResetType = _rtl92e_if_check_reset(dev);
                check_reset_cnt = 3;
        }
        spin_unlock_irqrestore(&priv->tx_lock, flags);
@@ -1543,14 +1525,14 @@ static void rtl819x_watchdog_wqcallback(void *data)
 
        if (((priv->force_reset) || (!priv->bDisableNormalResetCheck &&
              ResetType == RESET_TYPE_SILENT)))
-               rtl819x_ifsilentreset(dev);
+               _rtl92e_if_silent_reset(dev);
        priv->force_reset = false;
        priv->bForcedSilentReset = false;
        priv->bResetInProgress = false;
        RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
 }
 
-static void watch_dog_timer_callback(unsigned long data)
+static void _rtl92e_watchdog_timer_cb(unsigned long data)
 {
        struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
 
@@ -1579,7 +1561,7 @@ void rtl92e_tx_enable(struct net_device *dev)
 }
 
 
-static void rtl8192_free_rx_ring(struct net_device *dev)
+static void _rtl92e_free_rx_ring(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        int i, rx_queue_idx;
@@ -1607,7 +1589,7 @@ static void rtl8192_free_rx_ring(struct net_device *dev)
        }
 }
 
-static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
+static void _rtl92e_free_tx_ring(struct net_device *dev, unsigned int prio)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
@@ -1627,8 +1609,8 @@ static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
        ring->desc = NULL;
 }
 
-static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
-                           int rate)
+static void _rtl92e_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
+                                  int rate)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
        int ret;
@@ -1648,7 +1630,7 @@ static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
 
        memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
        skb_push(skb, priv->rtllib->tx_headroom);
-       ret = rtl8192_tx(dev, skb);
+       ret = _rtl92e_tx(dev, skb);
        if (ret != 0)
                kfree_skb(skb);
 
@@ -1659,7 +1641,7 @@ static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
        }
 }
 
-static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static int _rtl92e_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
        int ret;
@@ -1677,7 +1659,7 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
        if (queue_index == TXCMD_QUEUE) {
-               rtl8192_tx_cmd(dev, skb);
+               _rtl92e_tx_cmd(dev, skb);
                return 0;
        }
 
@@ -1686,13 +1668,13 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
        tcb_desc->bTxUseDriverAssingedRate = 1;
        tcb_desc->bTxEnableFwCalcDur = 1;
        skb_push(skb, priv->rtllib->tx_headroom);
-       ret = rtl8192_tx(dev, skb);
+       ret = _rtl92e_tx(dev, skb);
        if (ret != 0)
                kfree_skb(skb);
        return ret;
 }
 
-static void rtl8192_tx_isr(struct net_device *dev, int prio)
+static void _rtl92e_tx_isr(struct net_device *dev, int prio)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
@@ -1718,7 +1700,7 @@ static void rtl8192_tx_isr(struct net_device *dev, int prio)
                tasklet_schedule(&priv->irq_tx_tasklet);
 }
 
-static void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
+static void _rtl92e_tx_cmd(struct net_device *dev, struct sk_buff *skb)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtl8192_tx_ring *ring;
@@ -1741,7 +1723,7 @@ static void rtl8192_tx_cmd(struct net_device *dev, struct sk_buff *skb)
        spin_unlock_irqrestore(&priv->irq_th_lock, flags);
 }
 
-static short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
+static short _rtl92e_tx(struct net_device *dev, struct sk_buff *skb)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtl8192_tx_ring  *ring;
@@ -1817,7 +1799,7 @@ static short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
        return 0;
 }
 
-static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
+static short _rtl92e_alloc_rx_ring(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rx_desc *entry = NULL;
@@ -1865,8 +1847,8 @@ static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
        return 0;
 }
 
-static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
-       unsigned int prio, unsigned int entries)
+static int _rtl92e_alloc_tx_ring(struct net_device *dev, unsigned int prio,
+                                unsigned int entries)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
        struct tx_desc *ring;
@@ -1893,18 +1875,18 @@ static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
        return 0;
 }
 
-static short rtl8192_pci_initdescring(struct net_device *dev)
+static short _rtl92e_pci_initdescring(struct net_device *dev)
 {
        u32 ret;
        int i;
        struct r8192_priv *priv = rtllib_priv(dev);
 
-       ret = rtl8192_alloc_rx_desc_ring(dev);
+       ret = _rtl92e_alloc_rx_ring(dev);
        if (ret)
                return ret;
 
        for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
-               ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
+               ret = _rtl92e_alloc_tx_ring(dev, i, priv->txringcount);
                if (ret)
                        goto err_free_rings;
        }
@@ -1912,10 +1894,10 @@ static short rtl8192_pci_initdescring(struct net_device *dev)
        return 0;
 
 err_free_rings:
-       rtl8192_free_rx_ring(dev);
+       _rtl92e_free_rx_ring(dev);
        for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
                if (priv->tx_ring[i].desc)
-                       rtl8192_free_tx_ring(dev, i);
+                       _rtl92e_free_tx_ring(dev, i);
        return 1;
 }
 
@@ -2038,7 +2020,7 @@ void rtl92e_copy_mpdu_stats(struct rtllib_rx_stats *psrc_stats,
 
 
 
-static void rtl8192_rx_normal(struct net_device *dev)
+static void _rtl92e_rx_normal(struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
        struct rtllib_hdr_1addr *rtllib_hdr = NULL;
@@ -2144,7 +2126,7 @@ done:
 
 }
 
-static void rtl8192_tx_resume(struct net_device *dev)
+static void _rtl92e_tx_resume(struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -2161,14 +2143,14 @@ static void rtl8192_tx_resume(struct net_device *dev)
        }
 }
 
-static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv)
+static void _rtl92e_irq_tx_tasklet(struct r8192_priv *priv)
 {
-       rtl8192_tx_resume(priv->rtllib->dev);
+       _rtl92e_tx_resume(priv->rtllib->dev);
 }
 
-static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
+static void _rtl92e_irq_rx_tasklet(struct r8192_priv *priv)
 {
-       rtl8192_rx_normal(priv->rtllib->dev);
+       _rtl92e_rx_normal(priv->rtllib->dev);
 
        rtl92e_writel(priv->rtllib->dev, INTA_MASK,
                      rtl92e_readl(priv->rtllib->dev, INTA_MASK) | IMR_RDU);
@@ -2177,7 +2159,7 @@ static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
 /****************************************************************************
  ---------------------------- NIC START/CLOSE STUFF---------------------------
 *****************************************************************************/
-static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
+static void _rtl92e_cancel_deferred_work(struct r8192_priv *priv)
 {
        cancel_delayed_work(&priv->watch_dog_wq);
        cancel_delayed_work(&priv->update_beacon_wq);
@@ -2186,36 +2168,36 @@ static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
        cancel_work_sync(&priv->qos_activate);
 }
 
-static int _rtl8192_up(struct net_device *dev, bool is_silent_reset)
+static int _rtl92e_up(struct net_device *dev, bool is_silent_reset)
 {
-       if (_rtl8192_sta_up(dev, is_silent_reset) == -1)
+       if (_rtl92e_sta_up(dev, is_silent_reset) == -1)
                return -1;
        return 0;
 }
 
-static int rtl8192_open(struct net_device *dev)
+static int _rtl92e_open(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        int ret;
 
        down(&priv->wx_sem);
-       ret = rtl8192_up(dev);
+       ret = _rtl92e_try_up(dev);
        up(&priv->wx_sem);
        return ret;
 
 }
 
-static int rtl8192_up(struct net_device *dev)
+static int _rtl92e_try_up(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        if (priv->up == 1)
                return -1;
-       return _rtl8192_up(dev, false);
+       return _rtl92e_up(dev, false);
 }
 
 
-static int rtl8192_close(struct net_device *dev)
+static int _rtl92e_close(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        int ret;
@@ -2227,7 +2209,7 @@ static int rtl8192_close(struct net_device *dev)
 
        down(&priv->wx_sem);
 
-       ret = rtl8192_down(dev, true);
+       ret = _rtl92e_down(dev, true);
 
        up(&priv->wx_sem);
 
@@ -2235,9 +2217,9 @@ static int rtl8192_close(struct net_device *dev)
 
 }
 
-static int rtl8192_down(struct net_device *dev, bool shutdownrf)
+static int _rtl92e_down(struct net_device *dev, bool shutdownrf)
 {
-       if (rtl8192_sta_down(dev, shutdownrf) == -1)
+       if (_rtl92e_sta_down(dev, shutdownrf) == -1)
                return -1;
 
        return 0;
@@ -2252,10 +2234,10 @@ void rtl92e_commit(struct net_device *dev)
        rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
        rtl92e_irq_disable(dev);
        priv->ops->stop_adapter(dev, true);
-       _rtl8192_up(dev, false);
+       _rtl92e_up(dev, false);
 }
 
-static void rtl8192_restart(void *data)
+static void _rtl92e_restart(void *data)
 {
        struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv,
                                  reset_wq);
@@ -2268,7 +2250,7 @@ static void rtl8192_restart(void *data)
        up(&priv->wx_sem);
 }
 
-static void r8192_set_multicast(struct net_device *dev)
+static void _rtl92e_set_multicast(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        short promisc;
@@ -2279,7 +2261,7 @@ static void r8192_set_multicast(struct net_device *dev)
 }
 
 
-static int r8192_set_mac_adr(struct net_device *dev, void *mac)
+static int _rtl92e_set_mac_adr(struct net_device *dev, void *mac)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct sockaddr *addr = mac;
@@ -2295,7 +2277,7 @@ static int r8192_set_mac_adr(struct net_device *dev, void *mac)
 }
 
 /* based on ipw2200 driver */
-static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+static int _rtl92e_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
        struct iwreq *wrq = (struct iwreq *)rq;
@@ -2418,7 +2400,7 @@ out:
 }
 
 
-static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
+static irqreturn_t _rtl92e_irq(int irq, void *netdev)
 {
        struct net_device *dev = (struct net_device *) netdev;
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
@@ -2469,10 +2451,10 @@ static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
        if (inta  & IMR_MGNTDOK) {
                RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
                priv->stats.txmanageokint++;
-               rtl8192_tx_isr(dev, MGNT_QUEUE);
+               _rtl92e_tx_isr(dev, MGNT_QUEUE);
                spin_unlock_irqrestore(&priv->irq_th_lock, flags);
                if (priv->rtllib->ack_tx_to_ieee) {
-                       if (rtl8192_is_tx_queue_empty(dev)) {
+                       if (_rtl92e_is_tx_queue_empty(dev)) {
                                priv->rtllib->ack_tx_to_ieee = 0;
                                rtllib_ps_tx_ack(priv->rtllib, 1);
                        }
@@ -2482,11 +2464,11 @@ static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
 
        if (inta & IMR_COMDOK) {
                priv->stats.txcmdpktokint++;
-               rtl8192_tx_isr(dev, TXCMD_QUEUE);
+               _rtl92e_tx_isr(dev, TXCMD_QUEUE);
        }
 
        if (inta & IMR_HIGHDOK)
-               rtl8192_tx_isr(dev, HIGH_QUEUE);
+               _rtl92e_tx_isr(dev, HIGH_QUEUE);
 
        if (inta & IMR_ROK) {
                priv->stats.rxint++;
@@ -2520,28 +2502,28 @@ static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
                RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
                priv->stats.txbkokint++;
                priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, BK_QUEUE);
+               _rtl92e_tx_isr(dev, BK_QUEUE);
        }
 
        if (inta & IMR_BEDOK) {
                RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
                priv->stats.txbeokint++;
                priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, BE_QUEUE);
+               _rtl92e_tx_isr(dev, BE_QUEUE);
        }
 
        if (inta & IMR_VIDOK) {
                RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
                priv->stats.txviokint++;
                priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, VI_QUEUE);
+               _rtl92e_tx_isr(dev, VI_QUEUE);
        }
 
        if (inta & IMR_VODOK) {
                priv->stats.txvookint++;
                RT_TRACE(COMP_INTR, "Vo TX OK interrupt!\n");
                priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, VO_QUEUE);
+               _rtl92e_tx_isr(dev, VO_QUEUE);
        }
 
        spin_unlock_irqrestore(&priv->irq_th_lock, flags);
@@ -2557,19 +2539,19 @@ done:
        ---------------------------- PCI_STUFF---------------------------
 *****************************************************************************/
 static const struct net_device_ops rtl8192_netdev_ops = {
-       .ndo_open = rtl8192_open,
-       .ndo_stop = rtl8192_close,
-       .ndo_tx_timeout = rtl8192_tx_timeout,
-       .ndo_do_ioctl = rtl8192_ioctl,
-       .ndo_set_rx_mode = r8192_set_multicast,
-       .ndo_set_mac_address = r8192_set_mac_adr,
+       .ndo_open = _rtl92e_open,
+       .ndo_stop = _rtl92e_close,
+       .ndo_tx_timeout = _rtl92e_tx_timeout,
+       .ndo_do_ioctl = _rtl92e_ioctl,
+       .ndo_set_rx_mode = _rtl92e_set_multicast,
+       .ndo_set_mac_address = _rtl92e_set_mac_adr,
        .ndo_validate_addr = eth_validate_addr,
        .ndo_change_mtu = eth_change_mtu,
        .ndo_start_xmit = rtllib_xmit,
 };
 
-static int rtl8192_pci_probe(struct pci_dev *pdev,
-                       const struct pci_device_id *id)
+static int _rtl92e_pci_probe(struct pci_dev *pdev,
+                            const struct pci_device_id *id)
 {
        unsigned long ioaddr = 0;
        struct net_device *dev = NULL;
@@ -2667,7 +2649,7 @@ static int rtl8192_pci_probe(struct pci_dev *pdev,
        }
 
        RT_TRACE(COMP_INIT, "Driver probe completed1\n");
-       if (rtl8192_init(dev) != 0) {
+       if (_rtl92e_init(dev) != 0) {
                netdev_warn(dev, "Initialization failed");
                goto err_free_irq;
        }
@@ -2699,7 +2681,7 @@ err_pci_disable:
        return err;
 }
 
-static void rtl8192_pci_disconnect(struct pci_dev *pdev)
+static void _rtl92e_pci_disconnect(struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct r8192_priv *priv;
@@ -2713,16 +2695,16 @@ static void rtl8192_pci_disconnect(struct pci_dev *pdev)
                del_timer_sync(&priv->gpio_polling_timer);
                cancel_delayed_work(&priv->gpio_change_rf_wq);
                priv->polling_timer_on = 0;
-               rtl8192_down(dev, true);
+               _rtl92e_down(dev, true);
                rtl92e_dm_deinit(dev);
                if (priv->pFirmware) {
                        vfree(priv->pFirmware);
                        priv->pFirmware = NULL;
                }
                destroy_workqueue(priv->priv_wq);
-               rtl8192_free_rx_ring(dev);
+               _rtl92e_free_rx_ring(dev);
                for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
-                       rtl8192_free_tx_ring(dev, i);
+                       _rtl92e_free_tx_ring(dev, i);
 
                if (priv->irq) {
                        dev_info(&pdev->dev, "Freeing irq %d\n", dev->irq);
@@ -2784,7 +2766,7 @@ bool rtl92e_disable_nic(struct net_device *dev)
        tmp_state = priv->rtllib->state;
        rtllib_softmac_stop_protocol(priv->rtllib, 0, false);
        priv->rtllib->state = tmp_state;
-       rtl8192_cancel_deferred_work(priv);
+       _rtl92e_cancel_deferred_work(priv);
        rtl92e_irq_disable(dev);
 
        priv->ops->stop_adapter(dev, false);
@@ -2793,24 +2775,7 @@ bool rtl92e_disable_nic(struct net_device *dev)
        return true;
 }
 
-static int __init rtl8192_pci_module_init(void)
-{
-       pr_info("\nLinux kernel driver for RTL8192E WLAN cards\n");
-       pr_info("Copyright (c) 2007-2008, Realsil Wlan Driver\n");
-
-       if (0 != pci_register_driver(&rtl8192_pci_driver)) {
-               /*pci_unregister_driver (&rtl8192_pci_driver);*/
-               return -ENODEV;
-       }
-       return 0;
-}
-
-static void __exit rtl8192_pci_module_exit(void)
-{
-       pci_unregister_driver(&rtl8192_pci_driver);
-
-       RT_TRACE(COMP_DOWN, "Exiting");
-}
+module_pci_driver(rtl8192_pci_driver);
 
 void rtl92e_check_rfctrl_gpio_timer(unsigned long data)
 {
@@ -2827,9 +2792,6 @@ void rtl92e_check_rfctrl_gpio_timer(unsigned long data)
 /***************************************************************************
        ------------------- module init / exit stubs ----------------
 ****************************************************************************/
-module_init(rtl8192_pci_module_init);
-module_exit(rtl8192_pci_module_exit);
-
 MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards");
 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
 MODULE_VERSION(DRV_VERSION);
index cd948bb1384018169b2b6686735ac380e0ff7424..a7777a319c024510590b8097fc07b3e2ce251fd9 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -95,6 +91,8 @@
        (1600 + (MAX_802_11_HEADER_LENGTH + ENCRYPTION_MAX_OVERHEAD) *  \
         MAX_FRAGMENT_COUNT)
 
+#define CMDPACKET_FRAG_SIZE (4 * (MAX_TRANSMIT_BUFFER_SIZE / 4) - 8)
+
 #define DEFAULT_FRAG_THRESHOLD 2342U
 #define MIN_FRAG_THRESHOLD     256U
 #define DEFAULT_BEACONINTERVAL 0x64U
index 1a0c690bfa075d45adb3ca3dcf8efa2d185c73a8..ef03242113be12e3bdebbbf9668f3704dd8a54c8 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -166,62 +162,49 @@ struct drx_path_sel DM_RxPathSelTable;
 
 
 /*---------------------Define local function prototype-----------------------*/
-static void    dm_check_rate_adaptive(struct net_device *dev);
-
-static void    dm_init_bandwidth_autoswitch(struct net_device *dev);
-static void    dm_bandwidth_autoswitch(struct net_device *dev);
-
-
-static void    dm_check_txpower_tracking(struct net_device *dev);
-
-
-
-
+static void _rtl92e_dm_check_rate_adaptive(struct net_device *dev);
 
-static void    dm_bb_initialgain_restore(struct net_device *dev);
+static void _rtl92e_dm_init_bandwidth_autoswitch(struct net_device *dev);
+static void    _rtl92e_dm_bandwidth_autoswitch(struct net_device *dev);
 
 
-static void    dm_bb_initialgain_backup(struct net_device *dev);
+static void    _rtl92e_dm_check_tx_power_tracking(struct net_device *dev);
 
-static void dm_dig_init(struct net_device *dev);
-static void dm_ctrl_initgain_byrssi(struct net_device *dev);
-static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev);
-static void dm_ctrl_initgain_byrssi_by_driverrssi(struct net_device *dev);
-static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(struct net_device *dev);
-static void dm_initial_gain(struct net_device *dev);
-static void dm_pd_th(struct net_device *dev);
-static void dm_cs_ratio(struct net_device *dev);
+static void _rtl92e_dm_bb_initialgain_restore(struct net_device *dev);
+static void _rtl92e_dm_dig_init(struct net_device *dev);
+static void _rtl92e_dm_ctrl_initgain_byrssi(struct net_device *dev);
+static void _rtl92e_dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev);
+static void _rtl92e_dm_ctrl_initgain_byrssi_driver(struct net_device *dev);
+static void _rtl92e_dm_ctrl_initgain_byrssi_false_alarm(struct net_device *dev);
+static void _rtl92e_dm_initial_gain(struct net_device *dev);
+static void _rtl92e_dm_pd_th(struct net_device *dev);
+static void _rtl92e_dm_cs_ratio(struct net_device *dev);
 
-static void dm_init_ctstoself(struct net_device *dev);
-static void dm_Init_WA_Broadcom_IOT(struct net_device *dev);
+static void _rtl92e_dm_init_cts_to_self(struct net_device *dev);
+static void _rtl92e_dm_init_wa_broadcom_iot(struct net_device *dev);
 
-static void    dm_check_edca_turbo(struct net_device *dev);
+static void _rtl92e_dm_check_edca_turbo(struct net_device *dev);
+static void _rtl92e_dm_check_rx_path_selection(struct net_device *dev);
+static void _rtl92e_dm_init_rx_path_selection(struct net_device *dev);
+static void _rtl92e_dm_rx_path_sel_byrssi(struct net_device *dev);
 
-static void dm_check_pbc_gpio(struct net_device *dev);
 
+static void _rtl92e_dm_init_fsync(struct net_device *dev);
+static void _rtl92e_dm_deinit_fsync(struct net_device *dev);
 
-static void dm_check_rx_path_selection(struct net_device *dev);
-static void dm_init_rxpath_selection(struct net_device *dev);
-static void dm_rxpath_sel_byrssi(struct net_device *dev);
-
-
-static void dm_init_fsync(struct net_device *dev);
-static void dm_deInit_fsync(struct net_device *dev);
-
-static void dm_check_txrateandretrycount(struct net_device *dev);
-static  void dm_check_ac_dc_power(struct net_device *dev);
-static void dm_check_fsync(struct net_device *dev);
-static void dm_CheckRfCtrlGPIO(void *data);
-static void dm_fsync_timer_callback(unsigned long data);
+static void _rtl92e_dm_check_txrateandretrycount(struct net_device *dev);
+static  void _rtl92e_dm_check_ac_dc_power(struct net_device *dev);
+static void _rtl92e_dm_check_fsync(struct net_device *dev);
+static void _rtl92e_dm_check_rf_ctrl_gpio(void *data);
+static void _rtl92e_dm_fsync_timer_callback(unsigned long data);
 
 /*---------------------Define local function prototype-----------------------*/
 
-static void    dm_init_dynamic_txpower(struct net_device *dev);
-static void    dm_dynamic_txpower(struct net_device *dev);
-
+static void    _rtl92e_dm_init_dynamic_tx_power(struct net_device *dev);
+static void _rtl92e_dm_dynamic_tx_power(struct net_device *dev);
 
-static void dm_send_rssi_tofw(struct net_device *dev);
-static void    dm_ctstoself(struct net_device *dev);
+static void _rtl92e_dm_send_rssi_to_fw(struct net_device *dev);
+static void _rtl92e_dm_cts_to_self(struct net_device *dev);
 /*---------------------------Define function prototype------------------------*/
 
 void rtl92e_dm_init(struct net_device *dev)
@@ -232,27 +215,27 @@ void rtl92e_dm_init(struct net_device *dev)
 
        priv->undecorated_smoothed_pwdb = -1;
 
-       dm_init_dynamic_txpower(dev);
+       _rtl92e_dm_init_dynamic_tx_power(dev);
 
        rtl92e_init_adaptive_rate(dev);
 
-       dm_dig_init(dev);
+       _rtl92e_dm_dig_init(dev);
        rtl92e_dm_init_edca_turbo(dev);
-       dm_init_bandwidth_autoswitch(dev);
-       dm_init_fsync(dev);
-       dm_init_rxpath_selection(dev);
-       dm_init_ctstoself(dev);
+       _rtl92e_dm_init_bandwidth_autoswitch(dev);
+       _rtl92e_dm_init_fsync(dev);
+       _rtl92e_dm_init_rx_path_selection(dev);
+       _rtl92e_dm_init_cts_to_self(dev);
        if (IS_HARDWARE_TYPE_8192SE(dev))
-               dm_Init_WA_Broadcom_IOT(dev);
+               _rtl92e_dm_init_wa_broadcom_iot(dev);
 
        INIT_DELAYED_WORK_RSL(&priv->gpio_change_rf_wq,
-                             (void *)dm_CheckRfCtrlGPIO, dev);
+                             (void *)_rtl92e_dm_check_rf_ctrl_gpio, dev);
 }
 
 void rtl92e_dm_deinit(struct net_device *dev)
 {
 
-       dm_deInit_fsync(dev);
+       _rtl92e_dm_deinit_fsync(dev);
 
 }
 
@@ -263,27 +246,26 @@ void rtl92e_dm_watchdog(struct net_device *dev)
        if (priv->being_init_adapter)
                return;
 
-       dm_check_ac_dc_power(dev);
+       _rtl92e_dm_check_ac_dc_power(dev);
 
-       dm_check_pbc_gpio(dev);
-       dm_check_txrateandretrycount(dev);
-       dm_check_edca_turbo(dev);
+       _rtl92e_dm_check_txrateandretrycount(dev);
+       _rtl92e_dm_check_edca_turbo(dev);
 
-       dm_check_rate_adaptive(dev);
-       dm_dynamic_txpower(dev);
-       dm_check_txpower_tracking(dev);
+       _rtl92e_dm_check_rate_adaptive(dev);
+       _rtl92e_dm_dynamic_tx_power(dev);
+       _rtl92e_dm_check_tx_power_tracking(dev);
 
-       dm_ctrl_initgain_byrssi(dev);
-       dm_bandwidth_autoswitch(dev);
+       _rtl92e_dm_ctrl_initgain_byrssi(dev);
+       _rtl92e_dm_bandwidth_autoswitch(dev);
 
-       dm_check_rx_path_selection(dev);
-       dm_check_fsync(dev);
+       _rtl92e_dm_check_rx_path_selection(dev);
+       _rtl92e_dm_check_fsync(dev);
 
-       dm_send_rssi_tofw(dev);
-       dm_ctstoself(dev);
+       _rtl92e_dm_send_rssi_to_fw(dev);
+       _rtl92e_dm_cts_to_self(dev);
 }
 
-static void dm_check_ac_dc_power(struct net_device *dev)
+static void _rtl92e_dm_check_ac_dc_power(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        static char *ac_dc_script = "/etc/acpi/wireless-rtl-ac-dc-power.sh";
@@ -348,7 +330,7 @@ void rtl92e_init_adaptive_rate(struct net_device *dev)
 }
 
 
-static void dm_check_rate_adaptive(struct net_device *dev)
+static void _rtl92e_dm_check_rate_adaptive(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_hi_throughput *pHTInfo = priv->rtllib->pHTInfo;
@@ -360,7 +342,7 @@ static void dm_check_rate_adaptive(struct net_device *dev)
 
        if (!priv->up) {
                RT_TRACE(COMP_RATE,
-                        "<---- dm_check_rate_adaptive(): driver is going to unload\n");
+                        "<---- _rtl92e_dm_check_rate_adaptive(): driver is going to unload\n");
                return;
        }
 
@@ -465,7 +447,7 @@ static void dm_check_rate_adaptive(struct net_device *dev)
        }
 }
 
-static void dm_init_bandwidth_autoswitch(struct net_device *dev)
+static void _rtl92e_dm_init_bandwidth_autoswitch(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -475,7 +457,7 @@ static void dm_init_bandwidth_autoswitch(struct net_device *dev)
        priv->rtllib->bandwidth_auto_switch.bautoswitch_enable = false;
 }
 
-static void dm_bandwidth_autoswitch(struct net_device *dev)
+static void _rtl92e_dm_bandwidth_autoswitch(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -551,7 +533,8 @@ static u8   CCKSwingTable_Ch14[CCK_Table_length][8] = {
 #define                Tssi_Report_Value2                      0x13e
 #define                FW_Busy_Flag                            0x13f
 
-static void dm_tx_update_tssi_weak_signal(struct net_device *dev, u8 RF_Type)
+static void _rtl92e_dm_tx_update_tssi_weak_signal(struct net_device *dev,
+                                                 u8 RF_Type)
 {
        struct r8192_priv *p = rtllib_priv(dev);
 
@@ -599,7 +582,8 @@ static void dm_tx_update_tssi_weak_signal(struct net_device *dev, u8 RF_Type)
        }
 }
 
-static void dm_tx_update_tssi_strong_signal(struct net_device *dev, u8 RF_Type)
+static void _rtl92e_dm_tx_update_tssi_strong_signal(struct net_device *dev,
+                                                   u8 RF_Type)
 {
        struct r8192_priv *p = rtllib_priv(dev);
 
@@ -639,7 +623,7 @@ static void dm_tx_update_tssi_strong_signal(struct net_device *dev, u8 RF_Type)
        }
 }
 
-static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
+static void _rtl92e_dm_tx_power_tracking_callback_tssi(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        bool    bHighpowerstate, viviflag = false;
@@ -671,7 +655,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
                tx_cmd.Op               = TXCMD_SET_TX_PWR_TRACKING;
                tx_cmd.Length   = 4;
                tx_cmd.Value            = Value;
-               rtl92e_send_cmd_pkt(dev, (u8 *)&tx_cmd, DESC_PACKET_TYPE_INIT,
+               rtl92e_send_cmd_pkt(dev, DESC_PACKET_TYPE_NORMAL, (u8 *)&tx_cmd,
                                    sizeof(struct dcmd_txcmd));
                mdelay(1);
                for (i = 0; i <= 30; i++) {
@@ -718,7 +702,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
                                         "TSSI_report_value = %d\n",
                                         tmp_report[k]);
 
-                              if (tmp_report[k] <= 20) {
+                               if (tmp_report[k] <= 20) {
                                        viviflag = true;
                                        break;
                                }
@@ -771,9 +755,10 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
                                return;
                        }
                        if (Avg_TSSI_Meas_from_driver < TSSI_13dBm - E_FOR_TX_POWER_TRACK)
-                               dm_tx_update_tssi_weak_signal(dev, RF_Type);
+                               _rtl92e_dm_tx_update_tssi_weak_signal(dev,
+                                                                     RF_Type);
                        else
-                               dm_tx_update_tssi_strong_signal(dev, RF_Type);
+                               _rtl92e_dm_tx_update_tssi_strong_signal(dev, RF_Type);
 
                        if (RF_Type == RF_2T4R) {
                                priv->CCKPresentAttentuation_difference
@@ -844,7 +829,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device *dev)
        rtl92e_writeb(dev, Pw_Track_Flag, 0);
 }
 
-static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device *dev)
+static void _rtl92e_dm_tx_power_tracking_cb_thermal(struct net_device *dev)
 {
 #define ThermalMeterVal        9
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -954,12 +939,12 @@ void rtl92e_dm_txpower_tracking_wq(void *data)
        struct net_device *dev = priv->rtllib->dev;
 
        if (priv->IC_Cut >= IC_VersionCut_D)
-               dm_TXPowerTrackingCallback_TSSI(dev);
+               _rtl92e_dm_tx_power_tracking_callback_tssi(dev);
        else
-               dm_TXPowerTrackingCallback_ThermalMeter(dev);
+               _rtl92e_dm_tx_power_tracking_cb_thermal(dev);
 }
 
-static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev)
+static void _rtl92e_dm_initialize_tx_power_tracking_tssi(struct net_device *dev)
 {
 
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -970,7 +955,7 @@ static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev)
 
 }
 
-static void dm_InitializeTXPowerTracking_ThermalMeter(struct net_device *dev)
+static void _rtl92e_dm_init_tx_power_tracking_thermal(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -990,12 +975,12 @@ void rtl92e_dm_init_txpower_tracking(struct net_device *dev)
        struct r8192_priv *priv = rtllib_priv(dev);
 
        if (priv->IC_Cut >= IC_VersionCut_D)
-               dm_InitializeTXPowerTracking_TSSI(dev);
+               _rtl92e_dm_initialize_tx_power_tracking_tssi(dev);
        else
-               dm_InitializeTXPowerTracking_ThermalMeter(dev);
+               _rtl92e_dm_init_tx_power_tracking_thermal(dev);
 }
 
-static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev)
+static void _rtl92e_dm_check_tx_power_tracking_tssi(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        static u32 tx_power_track_counter;
@@ -1015,7 +1000,8 @@ static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev)
        }
 
 }
-static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
+
+static void _rtl92e_dm_check_tx_power_tracking_thermal(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        static u8       TM_Trigger;
@@ -1034,12 +1020,10 @@ static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
        }
 
        if (!TM_Trigger) {
-               {
                rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
                rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
                rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
                rtl92e_set_rf_reg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
-               }
                TM_Trigger = 1;
                return;
        }
@@ -1049,17 +1033,18 @@ static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
 
 }
 
-static void dm_check_txpower_tracking(struct net_device *dev)
+static void _rtl92e_dm_check_tx_power_tracking(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        if (priv->IC_Cut >= IC_VersionCut_D)
-               dm_CheckTXPowerTracking_TSSI(dev);
+               _rtl92e_dm_check_tx_power_tracking_tssi(dev);
        else
-               dm_CheckTXPowerTracking_ThermalMeter(dev);
+               _rtl92e_dm_check_tx_power_tracking_thermal(dev);
 }
 
-static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool  bInCH14)
+static void _rtl92e_dm_cck_tx_power_adjust_tssi(struct net_device *dev,
+                                               bool bInCH14)
 {
        u32 TempVal;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -1097,8 +1082,8 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool  bInCH14)
        }
 }
 
-static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev,
-                                            bool bInCH14)
+static void _rtl92e_dm_cck_tx_power_adjust_thermal_meter(struct net_device *dev,
+                                                        bool bInCH14)
 {
        u32 TempVal;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -1154,12 +1139,12 @@ void rtl92e_dm_cck_txpower_adjust(struct net_device *dev, bool binch14)
        struct r8192_priv *priv = rtllib_priv(dev);
 
        if (priv->IC_Cut >= IC_VersionCut_D)
-               dm_CCKTxPowerAdjust_TSSI(dev, binch14);
+               _rtl92e_dm_cck_tx_power_adjust_tssi(dev, binch14);
        else
-               dm_CCKTxPowerAdjust_ThermalMeter(dev, binch14);
+               _rtl92e_dm_cck_tx_power_adjust_thermal_meter(dev, binch14);
 }
 
-static void dm_txpower_reset_recovery(struct net_device *dev)
+static void _rtl92e_dm_tx_power_reset_recovery(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -1214,13 +1199,13 @@ void rtl92e_dm_restore_state(struct net_device *dev)
        rtl92e_writel(dev, RATR0, ratr_value);
        rtl92e_writeb(dev, UFWP, 1);
        if (priv->btxpower_trackingInit && priv->btxpower_tracking)
-               dm_txpower_reset_recovery(dev);
+               _rtl92e_dm_tx_power_reset_recovery(dev);
 
-       dm_bb_initialgain_restore(dev);
+       _rtl92e_dm_bb_initialgain_restore(dev);
 
 }
 
-static void dm_bb_initialgain_restore(struct net_device *dev)
+static void _rtl92e_dm_bb_initialgain_restore(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u32 bit_mask = 0x7f;
@@ -1255,22 +1240,13 @@ static void dm_bb_initialgain_restore(struct net_device *dev)
 
 }
 
-
 void rtl92e_dm_backup_state(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
+       u32 bit_mask = bMaskByte0;
 
        priv->bswitch_fsync  = false;
        priv->bfsync_processing = false;
-       dm_bb_initialgain_backup(dev);
-
-}
-
-
-static void dm_bb_initialgain_backup(struct net_device *dev)
-{
-       struct r8192_priv *priv = rtllib_priv(dev);
-       u32 bit_mask = bMaskByte0;
 
        if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
                return;
@@ -1293,10 +1269,9 @@ static void dm_bb_initialgain_backup(struct net_device *dev)
                 priv->initgain_backup.xdagccore1);
        RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xa0a is %x\n",
                 priv->initgain_backup.cca);
-
 }
 
-static void dm_dig_init(struct net_device *dev)
+static void _rtl92e_dm_dig_init(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -1326,16 +1301,16 @@ static void dm_dig_init(struct net_device *dev)
                dm_digtable.rx_gain_range_min = DM_DIG_MIN;
 }
 
-static void dm_ctrl_initgain_byrssi(struct net_device *dev)
+static void _rtl92e_dm_ctrl_initgain_byrssi(struct net_device *dev)
 {
 
        if (dm_digtable.dig_enable_flag == false)
                return;
 
        if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
-               dm_ctrl_initgain_byrssi_by_fwfalse_alarm(dev);
+               _rtl92e_dm_ctrl_initgain_byrssi_false_alarm(dev);
        else if (dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
-               dm_ctrl_initgain_byrssi_by_driverrssi(dev);
+               _rtl92e_dm_ctrl_initgain_byrssi_driver(dev);
        else
                return;
 }
@@ -1358,8 +1333,7 @@ static void dm_ctrl_initgain_byrssi(struct net_device *dev)
  *
  *---------------------------------------------------------------------------*/
 
-static void dm_ctrl_initgain_byrssi_by_driverrssi(
-       struct net_device *dev)
+static void _rtl92e_dm_ctrl_initgain_byrssi_driver(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 i;
@@ -1384,17 +1358,16 @@ static void dm_ctrl_initgain_byrssi_by_driverrssi(
 
 
        dm_digtable.rssi_val = priv->undecorated_smoothed_pwdb;
-       dm_initial_gain(dev);
-       dm_pd_th(dev);
-       dm_cs_ratio(dev);
+       _rtl92e_dm_initial_gain(dev);
+       _rtl92e_dm_pd_th(dev);
+       _rtl92e_dm_cs_ratio(dev);
        if (dm_digtable.dig_algorithm_switch)
                dm_digtable.dig_algorithm_switch = 0;
        dm_digtable.PreSTAConnectState = dm_digtable.CurSTAConnectState;
 
 }
 
-static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
-       struct net_device *dev)
+static void _rtl92e_dm_ctrl_initgain_byrssi_false_alarm(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        static u32 reset_cnt;
@@ -1447,7 +1420,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
 
                if (dm_digtable.dig_state == DM_STA_DIG_ON &&
                    (priv->reset_count == reset_cnt)) {
-                       dm_ctrl_initgain_byrssi_highpwr(dev);
+                       _rtl92e_dm_ctrl_initgain_byrssi_highpwr(dev);
                        return;
                }
                if (priv->reset_count != reset_cnt)
@@ -1478,11 +1451,11 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
 
                rtl92e_set_bb_reg(dev, UFWP, bMaskByte1, 0x1);
        }
-       dm_ctrl_initgain_byrssi_highpwr(dev);
+       _rtl92e_dm_ctrl_initgain_byrssi_highpwr(dev);
 }
 
 
-static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev)
+static void _rtl92e_dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        static u32 reset_cnt_highpwr;
@@ -1501,7 +1474,7 @@ static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev)
                dm_digtable.dig_highpwr_state = DM_STA_DIG_ON;
 
                if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
-                               rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x10);
+                       rtl92e_writeb(dev, (rOFDM0_XATxAFE+3), 0x10);
                else
                        rtl92e_writeb(dev, rOFDM0_RxDetector1, 0x43);
        } else {
@@ -1523,7 +1496,7 @@ static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev)
        reset_cnt_highpwr = priv->reset_count;
 }
 
-static void dm_initial_gain(struct net_device *dev)
+static void _rtl92e_dm_initial_gain(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 initial_gain = 0;
@@ -1580,7 +1553,7 @@ static void dm_initial_gain(struct net_device *dev)
        }
 }
 
-static void dm_pd_th(struct net_device *dev)
+static void _rtl92e_dm_pd_th(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        static u8 initialized, force_write;
@@ -1648,7 +1621,7 @@ static void dm_pd_th(struct net_device *dev)
        }
 }
 
-static void dm_cs_ratio(struct net_device *dev)
+static void _rtl92e_dm_cs_ratio(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        static u8 initialized, force_write;
@@ -1701,7 +1674,7 @@ void rtl92e_dm_init_edca_turbo(struct net_device *dev)
        priv->bis_cur_rdlstate = false;
 }
 
-static void dm_check_edca_turbo(struct net_device *dev)
+static void _rtl92e_dm_check_edca_turbo(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_hi_throughput *pHTInfo = priv->rtllib->pHTInfo;
@@ -1799,14 +1772,14 @@ dm_CheckEdcaTurbo_EXIT:
        lastRxOkCnt = priv->stats.rxbytesunicast;
 }
 
-static void dm_init_ctstoself(struct net_device *dev)
+static void _rtl92e_dm_init_cts_to_self(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv((struct net_device *)dev);
 
        priv->rtllib->bCTSToSelfEnable = true;
 }
 
-static void dm_ctstoself(struct net_device *dev)
+static void _rtl92e_dm_cts_to_self(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv((struct net_device *)dev);
        struct rt_hi_throughput *pHTInfo = priv->rtllib->pHTInfo;
@@ -1833,7 +1806,7 @@ static void dm_ctstoself(struct net_device *dev)
 }
 
 
-static void dm_Init_WA_Broadcom_IOT(struct net_device *dev)
+static void _rtl92e_dm_init_wa_broadcom_iot(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv((struct net_device *)dev);
        struct rt_hi_throughput *pHTInfo = priv->rtllib->pHTInfo;
@@ -1842,11 +1815,7 @@ static   void dm_Init_WA_Broadcom_IOT(struct net_device *dev)
        pHTInfo->WAIotTH = WAIotTHVal;
 }
 
-static void    dm_check_pbc_gpio(struct net_device *dev)
-{
-}
-
-static void dm_CheckRfCtrlGPIO(void *data)
+static void _rtl92e_dm_check_rf_ctrl_gpio(void *data)
 {
        struct r8192_priv *priv = container_of_dwork_rsl(data,
                                  struct r8192_priv, gpio_change_rf_wq);
@@ -1919,10 +1888,10 @@ void rtl92e_dm_rf_pathcheck_wq(void *data)
        if (!DM_RxPathSelTable.Enable)
                return;
 
-       dm_rxpath_sel_byrssi(dev);
+       _rtl92e_dm_rx_path_sel_byrssi(dev);
 }
 
-static void dm_init_rxpath_selection(struct net_device *dev)
+static void _rtl92e_dm_init_rx_path_selection(struct net_device *dev)
 {
        u8 i;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -1945,7 +1914,7 @@ static void dm_init_rxpath_selection(struct net_device *dev)
 #define PWDB_IN_RANGE  ((cur_cck_pwdb < tmp_cck_max_pwdb) &&   \
                        (cur_cck_pwdb > tmp_cck_sec_pwdb))
 
-static void dm_rxpath_sel_byrssi(struct net_device *dev)
+static void _rtl92e_dm_rx_path_sel_byrssi(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 i, max_rssi_index = 0, min_rssi_index = 0;
@@ -2148,7 +2117,7 @@ static void dm_rxpath_sel_byrssi(struct net_device *dev)
        }
 }
 
-static void    dm_check_rx_path_selection(struct net_device *dev)
+static void _rtl92e_dm_check_rx_path_selection(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -2156,7 +2125,7 @@ static    void    dm_check_rx_path_selection(struct net_device *dev)
 }
 
 
-static void dm_init_fsync(struct net_device *dev)
+static void _rtl92e_dm_init_fsync(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -2170,19 +2139,19 @@ static void dm_init_fsync(struct net_device *dev)
        priv->rtllib->fsync_state = Default_Fsync;
        priv->framesyncMonitor = 1;
 
-       setup_timer(&priv->fsync_timer, dm_fsync_timer_callback,
-                  (unsigned long) dev);
+       setup_timer(&priv->fsync_timer, _rtl92e_dm_fsync_timer_callback,
+                   (unsigned long)dev);
 }
 
 
-static void dm_deInit_fsync(struct net_device *dev)
+static void _rtl92e_dm_deinit_fsync(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        del_timer_sync(&priv->fsync_timer);
 }
 
-static void dm_fsync_timer_callback(unsigned long data)
+static void _rtl92e_dm_fsync_timer_callback(unsigned long data)
 {
        struct net_device *dev = (struct net_device *)data;
        struct r8192_priv *priv = rtllib_priv((struct net_device *)data);
@@ -2287,7 +2256,7 @@ static void dm_fsync_timer_callback(unsigned long data)
                 priv->bswitch_fsync);
 }
 
-static void dm_StartHWFsync(struct net_device *dev)
+static void _rtl92e_dm_start_hw_fsync(struct net_device *dev)
 {
        u8 rf_timing = 0x77;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -2299,7 +2268,7 @@ static void dm_StartHWFsync(struct net_device *dev)
        rtl92e_writeb(dev, 0xc3b, 0x41);
 }
 
-static void dm_EndHWFsync(struct net_device *dev)
+static void _rtl92e_dm_end_hw_fsync(struct net_device *dev)
 {
        u8 rf_timing = 0xaa;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -2311,7 +2280,7 @@ static void dm_EndHWFsync(struct net_device *dev)
        rtl92e_writeb(dev, 0xc3b, 0x49);
 }
 
-static void dm_EndSWFsync(struct net_device *dev)
+static void _rtl92e_dm_end_sw_fsync(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -2330,7 +2299,7 @@ static void dm_EndSWFsync(struct net_device *dev)
        rtl92e_writel(dev, rOFDM0_RxDetector2, 0x465c52cd);
 }
 
-static void dm_StartSWFsync(struct net_device *dev)
+static void _rtl92e_dm_start_sw_fsync(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u32                     rateIndex;
@@ -2366,7 +2335,7 @@ static void dm_StartSWFsync(struct net_device *dev)
 
 }
 
-static void dm_check_fsync(struct net_device *dev)
+static void _rtl92e_dm_check_fsync(struct net_device *dev)
 {
 #define        RegC38_Default                  0
 #define        RegC38_NonFsync_Other_AP        1
@@ -2391,12 +2360,12 @@ static void dm_check_fsync(struct net_device *dev)
                if (priv->rtllib->bfsync_enable == 0) {
                        switch (priv->rtllib->fsync_state) {
                        case Default_Fsync:
-                               dm_StartHWFsync(dev);
+                               _rtl92e_dm_start_hw_fsync(dev);
                                priv->rtllib->fsync_state = HW_Fsync;
                                break;
                        case SW_Fsync:
-                               dm_EndSWFsync(dev);
-                               dm_StartHWFsync(dev);
+                               _rtl92e_dm_end_sw_fsync(dev);
+                               _rtl92e_dm_start_hw_fsync(dev);
                                priv->rtllib->fsync_state = HW_Fsync;
                                break;
                        case HW_Fsync:
@@ -2406,12 +2375,12 @@ static void dm_check_fsync(struct net_device *dev)
                } else {
                        switch (priv->rtllib->fsync_state) {
                        case Default_Fsync:
-                               dm_StartSWFsync(dev);
+                               _rtl92e_dm_start_sw_fsync(dev);
                                priv->rtllib->fsync_state = SW_Fsync;
                                break;
                        case HW_Fsync:
-                               dm_EndHWFsync(dev);
-                               dm_StartSWFsync(dev);
+                               _rtl92e_dm_end_hw_fsync(dev);
+                               _rtl92e_dm_start_sw_fsync(dev);
                                priv->rtllib->fsync_state = SW_Fsync;
                                break;
                        case SW_Fsync:
@@ -2430,11 +2399,11 @@ static void dm_check_fsync(struct net_device *dev)
        } else {
                switch (priv->rtllib->fsync_state) {
                case HW_Fsync:
-                       dm_EndHWFsync(dev);
+                       _rtl92e_dm_end_hw_fsync(dev);
                        priv->rtllib->fsync_state = Default_Fsync;
                        break;
                case SW_Fsync:
-                       dm_EndSWFsync(dev);
+                       _rtl92e_dm_end_sw_fsync(dev);
                        priv->rtllib->fsync_state = Default_Fsync;
                        break;
                case Default_Fsync:
@@ -2448,9 +2417,9 @@ static void dm_check_fsync(struct net_device *dev)
                                    RegC38_TH) {
                                        if (reg_c38_State !=
                                            RegC38_NonFsync_Other_AP) {
-                                                       rtl92e_writeb(dev,
-                                                           rOFDM0_RxDetector3,
-                                                           0x90);
+                                               rtl92e_writeb(dev,
+                                                             rOFDM0_RxDetector3,
+                                                             0x90);
 
                                                reg_c38_State =
                                                     RegC38_NonFsync_Other_AP;
@@ -2490,7 +2459,7 @@ static void dm_check_fsync(struct net_device *dev)
 }
 
 /*---------------------------Define function prototype------------------------*/
-static void dm_init_dynamic_txpower(struct net_device *dev)
+static void _rtl92e_dm_init_dynamic_tx_power(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -2501,7 +2470,7 @@ static void dm_init_dynamic_txpower(struct net_device *dev)
        priv->bDynamicTxLowPower = false;
 }
 
-static void dm_dynamic_txpower(struct net_device *dev)
+static void _rtl92e_dm_dynamic_tx_power(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        unsigned int txhipower_threshhold = 0;
@@ -2554,7 +2523,7 @@ static void dm_dynamic_txpower(struct net_device *dev)
 
 }
 
-static void dm_check_txrateandretrycount(struct net_device *dev)
+static void _rtl92e_dm_check_txrateandretrycount(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -2569,7 +2538,7 @@ static void dm_check_txrateandretrycount(struct net_device *dev)
                                                 Tx_Retry_Count_Reg);
 }
 
-static void dm_send_rssi_tofw(struct net_device *dev)
+static void _rtl92e_dm_send_rssi_to_fw(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
index 097f0dc2056dada403493919f883a111d43aa233..756a0dd00d56161adf7687b9b09cdb6e7ffabaeb 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 039ccfd41230276f083db2fd700e928f0fb4947b..162e06c0883c3a885a9b22c544fbe657d276be97 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 8d23aea5fb4f3d11833c5858aa9996011af2860d..d63e8b0c185bdcd733d4760082a86098952cbb04 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 529ea54d16831fdffdf61bf0abf90bc2762ccc8c..f172f776245d073bdedec7611c1b64824a04d70c 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -29,8 +25,8 @@
 
 #include "rtl_core.h"
 
-static void rtl819x_ethtool_get_drvinfo(struct net_device *dev,
-               struct ethtool_drvinfo *info)
+static void _rtl92e_ethtool_get_drvinfo(struct net_device *dev,
+                                       struct ethtool_drvinfo *info)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -39,7 +35,7 @@ static void rtl819x_ethtool_get_drvinfo(struct net_device *dev,
        strlcpy(info->bus_info, pci_name(priv->pdev), sizeof(info->bus_info));
 }
 
-static u32 rtl819x_ethtool_get_link(struct net_device *dev)
+static u32 _rtl92e_ethtool_get_link(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -48,6 +44,6 @@ static u32 rtl819x_ethtool_get_link(struct net_device *dev)
 }
 
 const struct ethtool_ops rtl819x_ethtool_ops = {
-       .get_drvinfo = rtl819x_ethtool_get_drvinfo,
-       .get_link = rtl819x_ethtool_get_link,
+       .get_drvinfo = _rtl92e_ethtool_get_drvinfo,
+       .get_link = _rtl92e_ethtool_get_link,
 };
index 9fcb099e6edd3b28dc26d46e5cc26e0317e656df..2ff52e7dd32ff34ce1a539f44055778a79a854a9 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -25,7 +21,7 @@
 #include "rtl_pci.h"
 #include "rtl_core.h"
 
-static void rtl8192_parse_pci_configuration(struct pci_dev *pdev,
+static void _rtl92e_parse_pci_configuration(struct pci_dev *pdev,
                                            struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
@@ -92,7 +88,7 @@ bool rtl92e_check_adapter(struct pci_dev *pdev, struct net_device *dev)
                return false;
        }
 
-       rtl8192_parse_pci_configuration(pdev, dev);
+       _rtl92e_parse_pci_configuration(pdev, dev);
 
        return true;
 }
index 6246841bde1555f535178a88721bdd44b10bad79..73d357d530d07384265901ab4b66e4bd8ff35346 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index b0268fdc100f4c9e37fb4fedc4f1678118fd6633..b2b5ada69e738024c9772f31d621e74d3fb3856f 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index cdc45f7fb33934a2d419c86e25af73bd8f48c1be..7625e3f31ea8298882fda0503505d6db8bf82d5f 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index f09560d60dc4f2c96add5d3c33c356988506441a..9a4d1bcb881d26add58c98d1fb6be69723fcac74 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -30,7 +26,7 @@
 #include "r8192E_cmdpkt.h"
 #include <linux/jiffies.h>
 
-static void rtl8192_hw_sleep_down(struct net_device *dev)
+static void _rtl92e_hw_sleep(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        unsigned long flags = 0;
@@ -39,7 +35,7 @@ static void rtl8192_hw_sleep_down(struct net_device *dev)
        if (priv->RFChangeInProgress) {
                spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
                RT_TRACE(COMP_DBG,
-                        "rtl8192_hw_sleep_down(): RF Change in progress!\n");
+                        "_rtl92e_hw_sleep(): RF Change in progress!\n");
                return;
        }
        spin_unlock_irqrestore(&priv->rf_ps_lock, flags);
@@ -54,7 +50,7 @@ void rtl92e_hw_sleep_wq(void *data)
                                     struct rtllib_device, hw_sleep_wq);
        struct net_device *dev = ieee->dev;
 
-       rtl8192_hw_sleep_down(dev);
+       _rtl92e_hw_sleep(dev);
 }
 
 void rtl92e_hw_wakeup(struct net_device *dev)
@@ -122,21 +118,21 @@ void rtl92e_enter_sleep(struct net_device *dev, u64 time)
        spin_unlock_irqrestore(&priv->ps_lock, flags);
 }
 
-static void InactivePsWorkItemCallback(struct net_device *dev)
+static void _rtl92e_ps_update_rf_state(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
                                        &(priv->rtllib->PowerSaveControl);
 
-       RT_TRACE(COMP_PS, "InactivePsWorkItemCallback() --------->\n");
+       RT_TRACE(COMP_PS, "_rtl92e_ps_update_rf_state() --------->\n");
        pPSC->bSwRfProcessing = true;
 
-       RT_TRACE(COMP_PS, "InactivePsWorkItemCallback(): Set RF to %s.\n",
+       RT_TRACE(COMP_PS, "_rtl92e_ps_update_rf_state(): Set RF to %s.\n",
                 pPSC->eInactivePowerState == eRfOff ? "OFF" : "ON");
        rtl92e_set_rf_state(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
 
        pPSC->bSwRfProcessing = false;
-       RT_TRACE(COMP_PS, "InactivePsWorkItemCallback() <---------\n");
+       RT_TRACE(COMP_PS, "_rtl92e_ps_update_rf_state() <---------\n");
 }
 
 void rtl92e_ips_enter(struct net_device *dev)
@@ -155,7 +151,7 @@ void rtl92e_ips_enter(struct net_device *dev)
                        pPSC->eInactivePowerState = eRfOff;
                        priv->isRFOff = true;
                        priv->bInPowerSaveMode = true;
-                       InactivePsWorkItemCallback(dev);
+                       _rtl92e_ps_update_rf_state(dev);
                }
        }
 }
@@ -174,7 +170,7 @@ void rtl92e_ips_leave(struct net_device *dev)
                        RT_TRACE(COMP_PS, "rtl92e_ips_leave(): Turn on RF.\n");
                        pPSC->eInactivePowerState = eRfOn;
                        priv->bInPowerSaveMode = false;
-                       InactivePsWorkItemCallback(dev);
+                       _rtl92e_ps_update_rf_state(dev);
                }
        }
 }
@@ -222,8 +218,7 @@ void rtl92e_rtllib_ips_leave(struct net_device *dev)
        up(&priv->rtllib->ips_sem);
 }
 
-static bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev,
-                                           u8 rtPsMode)
+static bool _rtl92e_ps_set_mode(struct net_device *dev, u8 rtPsMode)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -281,8 +276,7 @@ void rtl92e_leisure_ps_enter(struct net_device *dev)
                                                priv->rtllib->SetFwCmdHandler(
                                                        dev, FW_CMD_LPS_ENTER);
                                }
-                               MgntActSet_802_11_PowerSaveMode(dev,
-                                                        RTLLIB_PS_MBCAST |
+                               _rtl92e_ps_set_mode(dev, RTLLIB_PS_MBCAST |
                                                         RTLLIB_PS_UNICAST);
                        }
                } else
@@ -305,8 +299,7 @@ void rtl92e_leisure_ps_leave(struct net_device *dev)
                if (priv->rtllib->ps != RTLLIB_PS_DISABLED) {
                        RT_TRACE(COMP_LPS,
                                 "rtl92e_leisure_ps_leave(): Busy Traffic , Leave 802.11 power save..\n");
-                       MgntActSet_802_11_PowerSaveMode(dev,
-                                        RTLLIB_PS_DISABLED);
+                       _rtl92e_ps_set_mode(dev, RTLLIB_PS_DISABLED);
 
                        if (!pPSC->bFwCtrlLPS) {
                                if (priv->rtllib->SetFwCmdHandler)
index 35fc9e2a3365ba9b7c38a7923b28dd039bb42878..a46f4cffca23da1f69d4a0383158bf771cff1a2b 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 7e3ca7ef997b9f5a5e8a22caf200c7c052e499c2..70df6a1485d6fb0e0a05fff203b4f92d41fe2ec0 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -31,9 +27,9 @@ static u32 rtl8192_rates[] = {
 #define ENETDOWN 1
 #endif
 
-static int r8192_wx_get_freq(struct net_device *dev,
-                            struct iw_request_info *a,
-                            union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_get_freq(struct net_device *dev,
+                              struct iw_request_info *a,
+                              union iwreq_data *wrqu, char *b)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -41,28 +37,27 @@ static int r8192_wx_get_freq(struct net_device *dev,
 }
 
 
-static int r8192_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
-                            union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_get_mode(struct net_device *dev,
+                              struct iw_request_info *a,
+                              union iwreq_data *wrqu, char *b)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        return rtllib_wx_get_mode(priv->rtllib, a, wrqu, b);
 }
 
-static int r8192_wx_get_rate(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_rate(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        return rtllib_wx_get_rate(priv->rtllib, info, wrqu, extra);
 }
 
-
-
-static int r8192_wx_set_rate(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_rate(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        int ret;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -79,10 +74,9 @@ static int r8192_wx_set_rate(struct net_device *dev,
        return ret;
 }
 
-
-static int r8192_wx_set_rts(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_rts(struct net_device *dev,
+                             struct iw_request_info *info,
+                             union iwreq_data *wrqu, char *extra)
 {
        int ret;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -99,18 +93,18 @@ static int r8192_wx_set_rts(struct net_device *dev,
        return ret;
 }
 
-static int r8192_wx_get_rts(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_rts(struct net_device *dev,
+                             struct iw_request_info *info,
+                             union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        return rtllib_wx_get_rts(priv->rtllib, info, wrqu, extra);
 }
 
-static int r8192_wx_set_power(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_power(struct net_device *dev,
+                               struct iw_request_info *info,
+                               union iwreq_data *wrqu, char *extra)
 {
        int ret;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -129,18 +123,18 @@ static int r8192_wx_set_power(struct net_device *dev,
        return ret;
 }
 
-static int r8192_wx_get_power(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_power(struct net_device *dev,
+                               struct iw_request_info *info,
+                               union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        return rtllib_wx_get_power(priv->rtllib, info, wrqu, extra);
 }
 
-static int r8192_wx_set_rawtx(struct net_device *dev,
-                             struct iw_request_info *info,
-                             union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_rawtx(struct net_device *dev,
+                               struct iw_request_info *info,
+                               union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        int ret;
@@ -158,9 +152,9 @@ static int r8192_wx_set_rawtx(struct net_device *dev,
 
 }
 
-static int r8192_wx_force_reset(struct net_device *dev,
-               struct iw_request_info *info,
-               union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_force_reset(struct net_device *dev,
+                                 struct iw_request_info *info,
+                                 union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -174,9 +168,9 @@ static int r8192_wx_force_reset(struct net_device *dev,
 
 }
 
-static int r8192_wx_adapter_power_status(struct net_device *dev,
-               struct iw_request_info *info,
-               union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_adapter_power_status(struct net_device *dev,
+                                          struct iw_request_info *info,
+                                          union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
@@ -204,9 +198,10 @@ static int r8192_wx_adapter_power_status(struct net_device *dev,
        return 0;
 }
 
-static int r8192se_wx_set_lps_awake_interval(struct net_device *dev,
-       struct iw_request_info *info,
-       union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_lps_awake_interval(struct net_device *dev,
+                                            struct iw_request_info *info,
+                                            union iwreq_data *wrqu,
+                                            char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
@@ -222,9 +217,9 @@ static int r8192se_wx_set_lps_awake_interval(struct net_device *dev,
        return 0;
 }
 
-static int r8192se_wx_set_force_lps(struct net_device *dev,
-               struct iw_request_info *info,
-               union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_force_lps(struct net_device *dev,
+                                   struct iw_request_info *info,
+                                   union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -239,9 +234,9 @@ static int r8192se_wx_set_force_lps(struct net_device *dev,
 
 }
 
-static int r8192_wx_set_debugflag(struct net_device *dev,
-                                 struct iw_request_info *info,
-                                 union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_debug(struct net_device *dev,
+                               struct iw_request_info *info,
+                               union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        u8 c = *extra;
@@ -258,8 +253,9 @@ static int r8192_wx_set_debugflag(struct net_device *dev,
        return 0;
 }
 
-static int r8192_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
-                            union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_set_mode(struct net_device *dev,
+                              struct iw_request_info *a,
+                              union iwreq_data *wrqu, char *b)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = netdev_priv_rsl(dev);
@@ -319,7 +315,7 @@ struct  iw_range_with_scan_capa {
        __u8        scan_capa;
 };
 
-static int rtl8192_wx_get_range(struct net_device *dev,
+static int _rtl92e_wx_get_range(struct net_device *dev,
                                struct iw_request_info *info,
                                union iwreq_data *wrqu, char *extra)
 {
@@ -334,10 +330,9 @@ static int rtl8192_wx_get_range(struct net_device *dev,
        /* ~130 Mb/s real (802.11n) */
        range->throughput = 130 * 1000 * 1000;
 
-       if (priv->rf_set_sens != NULL) {
+       if (priv->rf_set_sens != NULL)
                /* signal level threshold range */
                range->sensitivity = priv->max_sens;
-       }
 
        range->max_qual.qual = 100;
        range->max_qual.level = 0;
@@ -391,8 +386,9 @@ static int rtl8192_wx_get_range(struct net_device *dev,
        return 0;
 }
 
-static int r8192_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
-                            union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_set_scan(struct net_device *dev,
+                              struct iw_request_info *a,
+                              union iwreq_data *wrqu, char *b)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -480,8 +476,9 @@ static int r8192_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
 }
 
 
-static int r8192_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
-                            union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_get_scan(struct net_device *dev,
+                              struct iw_request_info *a,
+                              union iwreq_data *wrqu, char *b)
 {
 
        int ret;
@@ -503,9 +500,9 @@ static int r8192_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
        return ret;
 }
 
-static int r8192_wx_set_essid(struct net_device *dev,
-                             struct iw_request_info *a,
-                             union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_set_essid(struct net_device *dev,
+                               struct iw_request_info *a,
+                               union iwreq_data *wrqu, char *b)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        int ret;
@@ -524,9 +521,9 @@ static int r8192_wx_set_essid(struct net_device *dev,
        return ret;
 }
 
-static int r8192_wx_get_essid(struct net_device *dev,
-                             struct iw_request_info *a,
-                             union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_get_essid(struct net_device *dev,
+                               struct iw_request_info *a,
+                               union iwreq_data *wrqu, char *b)
 {
        int ret;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -540,9 +537,9 @@ static int r8192_wx_get_essid(struct net_device *dev,
        return ret;
 }
 
-static int r8192_wx_set_nick(struct net_device *dev,
-                          struct iw_request_info *info,
-                          union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_nick(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -558,9 +555,9 @@ static int r8192_wx_set_nick(struct net_device *dev,
 
 }
 
-static int r8192_wx_get_nick(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_nick(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -572,8 +569,9 @@ static int r8192_wx_get_nick(struct net_device *dev,
        return 0;
 }
 
-static int r8192_wx_set_freq(struct net_device *dev, struct iw_request_info *a,
-                            union iwreq_data *wrqu, char *b)
+static int _rtl92e_wx_set_freq(struct net_device *dev,
+                              struct iw_request_info *a,
+                              union iwreq_data *wrqu, char *b)
 {
        int ret;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -589,9 +587,9 @@ static int r8192_wx_set_freq(struct net_device *dev, struct iw_request_info *a,
        return ret;
 }
 
-static int r8192_wx_get_name(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_name(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -599,9 +597,9 @@ static int r8192_wx_get_name(struct net_device *dev,
 }
 
 
-static int r8192_wx_set_frag(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_frag(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -622,9 +620,9 @@ static int r8192_wx_set_frag(struct net_device *dev,
 }
 
 
-static int r8192_wx_get_frag(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_frag(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -636,10 +634,9 @@ static int r8192_wx_get_frag(struct net_device *dev,
 }
 
 
-static int r8192_wx_set_wap(struct net_device *dev,
-                        struct iw_request_info *info,
-                        union iwreq_data *awrq,
-                        char *extra)
+static int _rtl92e_wx_set_wap(struct net_device *dev,
+                             struct iw_request_info *info,
+                             union iwreq_data *awrq, char *extra)
 {
        int ret;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -658,9 +655,9 @@ static int r8192_wx_set_wap(struct net_device *dev,
 }
 
 
-static int r8192_wx_get_wap(struct net_device *dev,
-                           struct iw_request_info *info,
-                           union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_wap(struct net_device *dev,
+                             struct iw_request_info *info,
+                             union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -668,18 +665,18 @@ static int r8192_wx_get_wap(struct net_device *dev,
 }
 
 
-static int r8192_wx_get_enc(struct net_device *dev,
-                           struct iw_request_info *info,
-                           union iwreq_data *wrqu, char *key)
+static int _rtl92e_wx_get_enc(struct net_device *dev,
+                             struct iw_request_info *info,
+                             union iwreq_data *wrqu, char *key)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
        return rtllib_wx_get_encode(priv->rtllib, info, wrqu, key);
 }
 
-static int r8192_wx_set_enc(struct net_device *dev,
-                           struct iw_request_info *info,
-                           union iwreq_data *wrqu, char *key)
+static int _rtl92e_wx_set_enc(struct net_device *dev,
+                             struct iw_request_info *info,
+                             union iwreq_data *wrqu, char *key)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        int ret;
@@ -773,9 +770,9 @@ end_hw_sec:
        return ret;
 }
 
-static int r8192_wx_set_scan_type(struct net_device *dev,
-                                 struct iw_request_info *aa,
-                                 union iwreq_data *wrqu, char *p)
+static int _rtl92e_wx_set_scan_type(struct net_device *dev,
+                                   struct iw_request_info *aa,
+                                   union iwreq_data *wrqu, char *p)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        int *parms = (int *)p;
@@ -792,7 +789,7 @@ static int r8192_wx_set_scan_type(struct net_device *dev,
 
 
 #define R8192_MAX_RETRY 255
-static int r8192_wx_set_retry(struct net_device *dev,
+static int _rtl92e_wx_set_retry(struct net_device *dev,
                                struct iw_request_info *info,
                                union iwreq_data *wrqu, char *extra)
 {
@@ -818,13 +815,10 @@ static int r8192_wx_set_retry(struct net_device *dev,
                err = -EINVAL;
                goto exit;
        }
-       if (wrqu->retry.flags & IW_RETRY_MAX) {
+       if (wrqu->retry.flags & IW_RETRY_MAX)
                priv->retry_rts = wrqu->retry.value;
-
-       } else {
+       else
                priv->retry_data = wrqu->retry.value;
-       }
-
 
        rtl92e_commit(dev);
 exit:
@@ -833,7 +827,7 @@ exit:
        return err;
 }
 
-static int r8192_wx_get_retry(struct net_device *dev,
+static int _rtl92e_wx_get_retry(struct net_device *dev,
                                struct iw_request_info *info,
                                union iwreq_data *wrqu, char *extra)
 {
@@ -856,9 +850,9 @@ static int r8192_wx_get_retry(struct net_device *dev,
        return 0;
 }
 
-static int r8192_wx_get_sens(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_sens(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
 
@@ -869,9 +863,9 @@ static int r8192_wx_get_sens(struct net_device *dev,
 }
 
 
-static int r8192_wx_set_sens(struct net_device *dev,
-                               struct iw_request_info *info,
-                               union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_sens(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
 
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -897,9 +891,9 @@ exit:
        return err;
 }
 
-static int r8192_wx_set_enc_ext(struct net_device *dev,
-                               struct iw_request_info *info,
-                               union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_encode_ext(struct net_device *dev,
+                                    struct iw_request_info *info,
+                                    union iwreq_data *wrqu, char *extra)
 {
        int ret = 0;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -940,7 +934,7 @@ static int r8192_wx_set_enc_ext(struct net_device *dev,
                        idx--;
                group = ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY;
 
-               if ((!group) || (IW_MODE_ADHOC == ieee->iw_mode) ||
+               if ((!group) || (ieee->iw_mode == IW_MODE_ADHOC) ||
                    (alg ==  KEY_TYPE_WEP40)) {
                        if ((ext->key_len == 13) && (alg == KEY_TYPE_WEP40))
                                alg = KEY_TYPE_WEP104;
@@ -979,9 +973,10 @@ end_hw_sec:
        return ret;
 
 }
-static int r8192_wx_set_auth(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *data, char *extra)
+
+static int _rtl92e_wx_set_auth(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *data, char *extra)
 {
        int ret = 0;
 
@@ -996,9 +991,9 @@ static int r8192_wx_set_auth(struct net_device *dev,
        return ret;
 }
 
-static int r8192_wx_set_mlme(struct net_device *dev,
-                            struct iw_request_info *info,
-                            union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_mlme(struct net_device *dev,
+                              struct iw_request_info *info,
+                              union iwreq_data *wrqu, char *extra)
 {
 
        int ret = 0;
@@ -1014,9 +1009,9 @@ static int r8192_wx_set_mlme(struct net_device *dev,
        return ret;
 }
 
-static int r8192_wx_set_gen_ie(struct net_device *dev,
-                              struct iw_request_info *info,
-                              union iwreq_data *data, char *extra)
+static int _rtl92e_wx_set_gen_ie(struct net_device *dev,
+                                struct iw_request_info *info,
+                                union iwreq_data *data, char *extra)
 {
        int ret = 0;
 
@@ -1031,9 +1026,9 @@ static int r8192_wx_set_gen_ie(struct net_device *dev,
        return ret;
 }
 
-static int r8192_wx_get_gen_ie(struct net_device *dev,
-                              struct iw_request_info *info,
-                              union iwreq_data *data, char *extra)
+static int _rtl92e_wx_get_gen_ie(struct net_device *dev,
+                                struct iw_request_info *info,
+                                union iwreq_data *data, char *extra)
 {
        int ret = 0;
        struct r8192_priv *priv = rtllib_priv(dev);
@@ -1054,9 +1049,9 @@ static int r8192_wx_get_gen_ie(struct net_device *dev,
 
 #define OID_RT_INTEL_PROMISCUOUS_MODE  0xFF0101F6
 
-static int r8192_wx_set_PromiscuousMode(struct net_device *dev,
-               struct iw_request_info *info,
-               union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_set_promisc_mode(struct net_device *dev,
+                                      struct iw_request_info *info,
+                                      union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -1074,7 +1069,7 @@ static int r8192_wx_set_PromiscuousMode(struct net_device *dev,
        bPromiscuousOn = info_buf[1];
        bFilterSourceStationFrame = info_buf[2];
 
-       if (OID_RT_INTEL_PROMISCUOUS_MODE == oid) {
+       if (oid == OID_RT_INTEL_PROMISCUOUS_MODE) {
                ieee->IntelPromiscuousModeInfo.bPromiscuousOn =
                                        (bPromiscuousOn) ? (true) : (false);
                ieee->IntelPromiscuousModeInfo.bFilterSourceStationFrame =
@@ -1095,9 +1090,9 @@ static int r8192_wx_set_PromiscuousMode(struct net_device *dev,
 }
 
 
-static int r8192_wx_get_PromiscuousMode(struct net_device *dev,
-                              struct iw_request_info *info,
-                              union iwreq_data *wrqu, char *extra)
+static int _rtl92e_wx_get_promisc_mode(struct net_device *dev,
+                                      struct iw_request_info *info,
+                                      union iwreq_data *wrqu, char *extra)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -1117,39 +1112,39 @@ static int r8192_wx_get_PromiscuousMode(struct net_device *dev,
 
 #define IW_IOCTL(x) ((x) - SIOCSIWCOMMIT)
 static iw_handler r8192_wx_handlers[] = {
-       [IW_IOCTL(SIOCGIWNAME)] = r8192_wx_get_name,
-       [IW_IOCTL(SIOCSIWFREQ)] = r8192_wx_set_freq,
-       [IW_IOCTL(SIOCGIWFREQ)] = r8192_wx_get_freq,
-       [IW_IOCTL(SIOCSIWMODE)] = r8192_wx_set_mode,
-       [IW_IOCTL(SIOCGIWMODE)] = r8192_wx_get_mode,
-       [IW_IOCTL(SIOCSIWSENS)] = r8192_wx_set_sens,
-       [IW_IOCTL(SIOCGIWSENS)] = r8192_wx_get_sens,
-       [IW_IOCTL(SIOCGIWRANGE)] = rtl8192_wx_get_range,
-       [IW_IOCTL(SIOCSIWAP)] = r8192_wx_set_wap,
-       [IW_IOCTL(SIOCGIWAP)] = r8192_wx_get_wap,
-       [IW_IOCTL(SIOCSIWSCAN)] = r8192_wx_set_scan,
-       [IW_IOCTL(SIOCGIWSCAN)] = r8192_wx_get_scan,
-       [IW_IOCTL(SIOCSIWESSID)] = r8192_wx_set_essid,
-       [IW_IOCTL(SIOCGIWESSID)] = r8192_wx_get_essid,
-       [IW_IOCTL(SIOCSIWNICKN)] = r8192_wx_set_nick,
-       [IW_IOCTL(SIOCGIWNICKN)] = r8192_wx_get_nick,
-       [IW_IOCTL(SIOCSIWRATE)] = r8192_wx_set_rate,
-       [IW_IOCTL(SIOCGIWRATE)] = r8192_wx_get_rate,
-       [IW_IOCTL(SIOCSIWRTS)] = r8192_wx_set_rts,
-       [IW_IOCTL(SIOCGIWRTS)] = r8192_wx_get_rts,
-       [IW_IOCTL(SIOCSIWFRAG)] = r8192_wx_set_frag,
-       [IW_IOCTL(SIOCGIWFRAG)] = r8192_wx_get_frag,
-       [IW_IOCTL(SIOCSIWRETRY)] = r8192_wx_set_retry,
-       [IW_IOCTL(SIOCGIWRETRY)] = r8192_wx_get_retry,
-       [IW_IOCTL(SIOCSIWENCODE)] = r8192_wx_set_enc,
-       [IW_IOCTL(SIOCGIWENCODE)] = r8192_wx_get_enc,
-       [IW_IOCTL(SIOCSIWPOWER)] = r8192_wx_set_power,
-       [IW_IOCTL(SIOCGIWPOWER)] = r8192_wx_get_power,
-       [IW_IOCTL(SIOCSIWGENIE)] = r8192_wx_set_gen_ie,
-       [IW_IOCTL(SIOCGIWGENIE)] = r8192_wx_get_gen_ie,
-       [IW_IOCTL(SIOCSIWMLME)] = r8192_wx_set_mlme,
-       [IW_IOCTL(SIOCSIWAUTH)] = r8192_wx_set_auth,
-       [IW_IOCTL(SIOCSIWENCODEEXT)] = r8192_wx_set_enc_ext,
+       [IW_IOCTL(SIOCGIWNAME)] = _rtl92e_wx_get_name,
+       [IW_IOCTL(SIOCSIWFREQ)] = _rtl92e_wx_set_freq,
+       [IW_IOCTL(SIOCGIWFREQ)] = _rtl92e_wx_get_freq,
+       [IW_IOCTL(SIOCSIWMODE)] = _rtl92e_wx_set_mode,
+       [IW_IOCTL(SIOCGIWMODE)] = _rtl92e_wx_get_mode,
+       [IW_IOCTL(SIOCSIWSENS)] = _rtl92e_wx_set_sens,
+       [IW_IOCTL(SIOCGIWSENS)] = _rtl92e_wx_get_sens,
+       [IW_IOCTL(SIOCGIWRANGE)] = _rtl92e_wx_get_range,
+       [IW_IOCTL(SIOCSIWAP)] = _rtl92e_wx_set_wap,
+       [IW_IOCTL(SIOCGIWAP)] = _rtl92e_wx_get_wap,
+       [IW_IOCTL(SIOCSIWSCAN)] = _rtl92e_wx_set_scan,
+       [IW_IOCTL(SIOCGIWSCAN)] = _rtl92e_wx_get_scan,
+       [IW_IOCTL(SIOCSIWESSID)] = _rtl92e_wx_set_essid,
+       [IW_IOCTL(SIOCGIWESSID)] = _rtl92e_wx_get_essid,
+       [IW_IOCTL(SIOCSIWNICKN)] = _rtl92e_wx_set_nick,
+       [IW_IOCTL(SIOCGIWNICKN)] = _rtl92e_wx_get_nick,
+       [IW_IOCTL(SIOCSIWRATE)] = _rtl92e_wx_set_rate,
+       [IW_IOCTL(SIOCGIWRATE)] = _rtl92e_wx_get_rate,
+       [IW_IOCTL(SIOCSIWRTS)] = _rtl92e_wx_set_rts,
+       [IW_IOCTL(SIOCGIWRTS)] = _rtl92e_wx_get_rts,
+       [IW_IOCTL(SIOCSIWFRAG)] = _rtl92e_wx_set_frag,
+       [IW_IOCTL(SIOCGIWFRAG)] = _rtl92e_wx_get_frag,
+       [IW_IOCTL(SIOCSIWRETRY)] = _rtl92e_wx_set_retry,
+       [IW_IOCTL(SIOCGIWRETRY)] = _rtl92e_wx_get_retry,
+       [IW_IOCTL(SIOCSIWENCODE)] = _rtl92e_wx_set_enc,
+       [IW_IOCTL(SIOCGIWENCODE)] = _rtl92e_wx_get_enc,
+       [IW_IOCTL(SIOCSIWPOWER)] = _rtl92e_wx_set_power,
+       [IW_IOCTL(SIOCGIWPOWER)] = _rtl92e_wx_get_power,
+       [IW_IOCTL(SIOCSIWGENIE)] = _rtl92e_wx_set_gen_ie,
+       [IW_IOCTL(SIOCGIWGENIE)] = _rtl92e_wx_get_gen_ie,
+       [IW_IOCTL(SIOCSIWMLME)] = _rtl92e_wx_set_mlme,
+       [IW_IOCTL(SIOCSIWAUTH)] = _rtl92e_wx_set_auth,
+       [IW_IOCTL(SIOCSIWENCODEEXT)] = _rtl92e_wx_set_encode_ext,
 };
 
 /* the following rule need to be following,
@@ -1192,18 +1187,18 @@ static const struct iw_priv_args r8192_private_args[] = {
 };
 
 static iw_handler r8192_private_handler[] = {
-       (iw_handler)r8192_wx_set_debugflag,   /*SIOCIWSECONDPRIV*/
-       (iw_handler)r8192_wx_set_scan_type,
-       (iw_handler)r8192_wx_set_rawtx,
-       (iw_handler)r8192_wx_force_reset,
+       (iw_handler)_rtl92e_wx_set_debug,   /*SIOCIWSECONDPRIV*/
+       (iw_handler)_rtl92e_wx_set_scan_type,
+       (iw_handler)_rtl92e_wx_set_rawtx,
+       (iw_handler)_rtl92e_wx_force_reset,
        (iw_handler)NULL,
        (iw_handler)NULL,
-       (iw_handler)r8192_wx_adapter_power_status,
+       (iw_handler)_rtl92e_wx_adapter_power_status,
        (iw_handler)NULL,
        (iw_handler)NULL,
        (iw_handler)NULL,
-       (iw_handler)r8192se_wx_set_lps_awake_interval,
-       (iw_handler)r8192se_wx_set_force_lps,
+       (iw_handler)_rtl92e_wx_set_lps_awake_interval,
+       (iw_handler)_rtl92e_wx_set_force_lps,
        (iw_handler)NULL,
        (iw_handler)NULL,
        (iw_handler)NULL,
@@ -1214,11 +1209,11 @@ static iw_handler r8192_private_handler[] = {
        (iw_handler)NULL,
        (iw_handler)NULL,
        (iw_handler)NULL,
-       (iw_handler)r8192_wx_set_PromiscuousMode,
-       (iw_handler)r8192_wx_get_PromiscuousMode,
+       (iw_handler)_rtl92e_wx_set_promisc_mode,
+       (iw_handler)_rtl92e_wx_get_promisc_mode,
 };
 
-static struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev)
+static struct iw_statistics *_rtl92e_get_wireless_stats(struct net_device *dev)
 {
        struct r8192_priv *priv = rtllib_priv(dev);
        struct rtllib_device *ieee = priv->rtllib;
@@ -1230,7 +1225,7 @@ static struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev)
        if (ieee->state < RTLLIB_LINKED) {
                wstats->qual.qual = 10;
                wstats->qual.level = 0;
-               wstats->qual.noise = -100;
+               wstats->qual.noise = 0x100 - 100;       /* -100 dBm */
                wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
                return wstats;
        }
@@ -1253,6 +1248,6 @@ const struct iw_handler_def r8192_wx_handlers_def = {
        .num_private = ARRAY_SIZE(r8192_private_handler),
        .num_private_args = sizeof(r8192_private_args) /
                            sizeof(struct iw_priv_args),
-       .get_wireless_stats = r8192_get_wireless_stats,
+       .get_wireless_stats = _rtl92e_get_wireless_stats,
        .private_args = (struct iw_priv_args *)r8192_private_args,
 };
index 771284019e08804c78034f9189bb71ce91c5d922..7ecf6c5cf58bd2e883deb47f5e0167ff357c70a4 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 89466646515279af44141667d33ad13f09526dc9..5002b4d1fe5148f994c152059b27a221e7939d06 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 78ede4a817fc6a39b81c7b8c21ef2f8d7f112880..c04a020f6d6c4c68850ee5e08cb780d490042e11 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
@@ -113,7 +109,7 @@ static struct sk_buff *rtllib_ADDBA(struct rtllib_device *ieee, u8 *Dst,
        *tag++ = type;
        *tag++ = pBA->DialogToken;
 
-       if (ACT_ADDBARSP == type) {
+       if (type == ACT_ADDBARSP) {
                RT_TRACE(COMP_DBG, "====>to send ADDBARSP\n");
 
                put_unaligned_le16(StatusCode, tag);
@@ -126,7 +122,7 @@ static struct sk_buff *rtllib_ADDBA(struct rtllib_device *ieee, u8 *Dst,
        put_unaligned_le16(pBA->BaTimeoutValue, tag);
        tag += 2;
 
-       if (ACT_ADDBAREQ == type) {
+       if (type == ACT_ADDBAREQ) {
                memcpy(tag, (u8 *)&(pBA->BaStartSeqCtrl), 2);
                tag += 2;
        }
index 51711dcdc8ef40d41f82ad790e60ca343ed73cd1..6eb018f5feaa262f838ee701dfada16d919f2714 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 555745b2a75e47c4224691f5e923722ecb5b2632..dd9c0c8683614cccd20d90dc2915523908be41ca 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index fcc8fabbebb7ab2861a3db0ec0ee4dbadeeab3e1..463122db6d2965149d6fa2f2b4f11bbd67607c31 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index a93348c37f17e1298a87107fd8ff1b165078d4c1..2cabf4026e77ffaf8affa31e1c7243cb57fcae6b 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 7087959443cb40e634519fd12df3e5e991292681..2c8a526773ed7460528ba58ad7d2dfd7da30b792 100644 (file)
@@ -6,10 +6,6 @@
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 17c276d710582b1588babc773a55dda54b9a215a..f1c39c3f9d26c5eb3e9060a495f073b07b371818 100644 (file)
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  * more details.
  *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
- *
  * The full GNU General Public License is included in this distribution in the
  * file called LICENSE.
  *
index 224dc99af13193a3bb15db033c67625862d3fbb9..113fbf7fbb17c9cdb7de6ca3d4a80cef09f3b2b8 100644 (file)
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc., 59
-  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
   The full GNU General Public License is included in this distribution in the
   file called LICENSE.
 
@@ -63,9 +59,8 @@ static inline int rtllib_networks_allocate(struct rtllib_device *ieee)
        if (ieee->networks)
                return 0;
 
-       ieee->networks = kzalloc(
-               MAX_NETWORK_COUNT * sizeof(struct rtllib_network),
-               GFP_KERNEL);
+       ieee->networks = kcalloc(MAX_NETWORK_COUNT,
+                                sizeof(struct rtllib_network), GFP_KERNEL);
        if (!ieee->networks)
                return -ENOMEM;
 
index 09f0820fb3402c2779c706bf18fcd3bec2e19ab0..37343ec3b4841b4e3edcc93b43d8a1c4557fb2cb 100644 (file)
@@ -1200,11 +1200,9 @@ static int rtllib_rx_decrypt(struct rtllib_device *ieee, struct sk_buff *skb,
 
        if (crypt && !(fc & RTLLIB_FCTL_WEP) &&
            rtllib_is_eapol_frame(ieee, skb, hdrlen)) {
-                       struct eapol *eap = (struct eapol *)(skb->data +
-                               24);
-                       netdev_dbg(ieee->dev,
-                                  "RX: IEEE 802.1X EAPOL frame: %s\n",
-                                  eap_get_type(eap->type));
+               struct eapol *eap = (struct eapol *)(skb->data + 24);
+               netdev_dbg(ieee->dev, "RX: IEEE 802.1X EAPOL frame: %s\n",
+                          eap_get_type(eap->type));
        }
 
        if (crypt && !(fc & RTLLIB_FCTL_WEP) && !ieee->open_wep &&
@@ -1532,7 +1530,7 @@ int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
 {
        int ret = 0;
 
-       if ((NULL == ieee) || (NULL == skb) || (NULL == rx_stats)) {
+       if (!ieee || !skb || !rx_stats) {
                pr_info("%s: Input parameters NULL!\n", __func__);
                goto rx_dropped;
        }
@@ -2556,7 +2554,7 @@ static inline int is_beacon(u16 fc)
 
 static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
 {
-       if (MAX_CHANNEL_NUMBER < channel) {
+       if (channel > MAX_CHANNEL_NUMBER) {
                netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
                return 0;
        }
@@ -2569,7 +2567,7 @@ static int IsPassiveChannel(struct rtllib_device *rtllib, u8 channel)
 
 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel)
 {
-       if (MAX_CHANNEL_NUMBER < channel) {
+       if (channel > MAX_CHANNEL_NUMBER) {
                netdev_info(rtllib->dev, "%s(): Invalid Channel\n", __func__);
                return 0;
        }
index 1503cbb3574ef7341594190aeeff7eebbd4231f2..d0fedb0ff132d9cd1acb54cb702589a9d1cf22e9 100644 (file)
@@ -709,7 +709,7 @@ EXPORT_SYMBOL(rtllib_stop_scan);
 void rtllib_stop_scan_syncro(struct rtllib_device *ieee)
 {
        if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) {
-                       ieee->sync_scan_hurryup = 1;
+               ieee->sync_scan_hurryup = 1;
        } else {
                if (ieee->rtllib_stop_hw_scan)
                        ieee->rtllib_stop_hw_scan(ieee->dev);
@@ -858,7 +858,7 @@ static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee,
 
        crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
        encrypt = ieee->host_encrypt && crypt && crypt->ops &&
-               ((0 == strcmp(crypt->ops->name, "R-WEP") || wpa_ie_len));
+               ((strcmp(crypt->ops->name, "R-WEP") == 0 || wpa_ie_len));
        if (ieee->pHTInfo->bCurrentHTSupport) {
                tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap);
                tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap);
@@ -1180,7 +1180,7 @@ inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
        crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
        if (crypt != NULL)
                encrypt = ieee->host_encrypt && crypt && crypt->ops &&
-                         ((0 == strcmp(crypt->ops->name, "R-WEP") ||
+                         ((strcmp(crypt->ops->name, "R-WEP") == 0 ||
                          wpa_ie_len));
        else
                encrypt = 0;
@@ -1520,8 +1520,7 @@ static void rtllib_associate_complete_wq(void *data)
                                     container_of_work_rsl(data,
                                     struct rtllib_device,
                                     associate_complete_wq);
-       struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
-                                       (&(ieee->PowerSaveControl));
+       struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl);
        netdev_info(ieee->dev, "Associated successfully\n");
        if (!ieee->is_silent_reset) {
                netdev_info(ieee->dev, "normal associate\n");
@@ -1974,8 +1973,7 @@ static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time)
 {
        int timeout = ieee->ps_timeout;
        u8 dtim;
-       struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *)
-                                       (&(ieee->PowerSaveControl));
+       struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl);
 
        if (ieee->LPSDelayCnt) {
                ieee->LPSDelayCnt--;
@@ -2229,7 +2227,7 @@ inline int rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb,
             ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED &&
             (ieee->iw_mode == IW_MODE_INFRA)) {
                errcode = assoc_parse(ieee, skb, &aid);
-               if (0 == errcode) {
+               if (!errcode) {
                        struct rtllib_network *network =
                                 kzalloc(sizeof(struct rtllib_network),
                                 GFP_ATOMIC);
@@ -2762,10 +2760,10 @@ void rtllib_disassociate(struct rtllib_device *ieee)
 {
        netif_carrier_off(ieee->dev);
        if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)
-                       rtllib_reset_queue(ieee);
+               rtllib_reset_queue(ieee);
 
        if (ieee->data_hard_stop)
-                       ieee->data_hard_stop(ieee->dev);
+               ieee->data_hard_stop(ieee->dev);
        if (IS_DOT11D_ENABLE(ieee))
                Dot11d_Reset(ieee);
        ieee->state = RTLLIB_NOLINK;
@@ -3480,7 +3478,7 @@ u8 rtllib_ap_sec_type(struct rtllib_device *ieee)
        crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx];
        encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY)
                  || (ieee->host_encrypt && crypt && crypt->ops &&
-                 (0 == strcmp(crypt->ops->name, "R-WEP")));
+                 (strcmp(crypt->ops->name, "R-WEP") == 0));
 
        /* simply judge  */
        if (encrypt && (wpa_ie_len == 0)) {
index b992e4612fd89990c30628b2b21246a0aa2e4773..58fc70ec5f2ffb77b0d80323554abc069f247cb1 100644 (file)
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc., 59
-  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
   The full GNU General Public License is included in this distribution in the
   file called LICENSE.
 
@@ -487,7 +483,7 @@ static void rtllib_query_protectionmode(struct rtllib_device *ieee,
        if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
                tcb_desc->bUseShortPreamble = true;
        if (ieee->iw_mode == IW_MODE_MASTER)
-                       goto NO_PROTECTION;
+               goto NO_PROTECTION;
        return;
 NO_PROTECTION:
        tcb_desc->bRTSEnable    = false;
@@ -635,10 +631,10 @@ static int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
                }
 
                if (skb->len > 282) {
-                       if (ETH_P_IP == ether_type) {
+                       if (ether_type == ETH_P_IP) {
                                const struct iphdr *ip = (struct iphdr *)
                                        ((u8 *)skb->data+14);
-                               if (IPPROTO_UDP == ip->protocol) {
+                               if (ip->protocol == IPPROTO_UDP) {
                                        struct udphdr *udp;
 
                                        udp = (struct udphdr *)((u8 *)ip +
@@ -651,7 +647,7 @@ static int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev)
                                                ieee->LPSDelayCnt = 200;
                                        }
                                }
-                       } else if (ETH_P_ARP == ether_type) {
+                       } else if (ether_type == ETH_P_ARP) {
                                netdev_info(ieee->dev,
                                            "=================>DHCP Protocol start tx ARP pkt!!\n");
                                bdhcp = true;
index 967ba8bc80bb5d760c6cc7e78971311df9a99901..80f7a099dff1efe560101c8fe2df15443e9b813d 100644 (file)
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.
 
-  You should have received a copy of the GNU General Public License along with
-  this program; if not, write to the Free Software Foundation, Inc., 59
-  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
   The full GNU General Public License is included in this distribution in the
   file called LICENSE.
 
index d481a26c25ae704506c84b4220d5945a962e99fa..967ef9a98fc0119d14373aff4a682e7ef3c1643a 100644 (file)
@@ -415,7 +415,7 @@ typedef struct ieee_param {
 /* QOS control */
 #define IEEE80211_QCTL_TID              0x000F
 
-#define        FC_QOS_BIT                                      BIT7
+#define        FC_QOS_BIT                                      BIT(7)
 #define IsDataFrame(pdu)                       ( ((pdu[0] & 0x0C)==0x08) ? true : false )
 #define        IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)) )
 //added by wb. Is this right?
@@ -1565,10 +1565,10 @@ typedef struct _RT_POWER_SAVE_CONTROL {
 } RT_POWER_SAVE_CONTROL, *PRT_POWER_SAVE_CONTROL;
 
 typedef u32 RT_RF_CHANGE_SOURCE;
-#define RF_CHANGE_BY_SW BIT31
-#define RF_CHANGE_BY_HW BIT30
-#define RF_CHANGE_BY_PS BIT29
-#define RF_CHANGE_BY_IPS BIT28
+#define RF_CHANGE_BY_SW                BIT(31)
+#define RF_CHANGE_BY_HW                BIT(30)
+#define RF_CHANGE_BY_PS                BIT(29)
+#define RF_CHANGE_BY_IPS       BIT(28)
 #define RF_CHANGE_BY_INIT      0       // Do not change the RFOff reason. Defined by Bruce, 2008-01-17.
 
 typedef enum
index a66141647f2df522570e98bc868bde41b4f2ff14..27ce4817faeb9de3dfc2dfcf64d67829140d70ea 100644 (file)
@@ -71,10 +71,9 @@ static void *ieee80211_ccmp_init(int key_idx)
                goto fail;
        priv->key_idx = key_idx;
 
-       priv->tfm = (void *)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
+       priv->tfm = (void *)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
        if (IS_ERR(priv->tfm)) {
-               printk(KERN_DEBUG "ieee80211_crypt_ccmp: could not allocate "
-                      "crypto API aes\n");
+               printk(KERN_DEBUG "ieee80211_crypt_ccmp: could not allocate crypto API aes\n");
                priv->tfm = NULL;
                goto fail;
        }
@@ -105,6 +104,7 @@ static void ieee80211_ccmp_deinit(void *priv)
 static inline void xor_block(u8 *b, u8 *a, size_t len)
 {
        int i;
+
        for (i = 0; i < len; i++)
                b[i] ^= a[i];
 }
@@ -125,10 +125,9 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
        fc = le16_to_cpu(hdr->frame_ctl);
        a4_included = ((fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
                       (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS));
-       /*
-       qc_included = ((WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) &&
-                      (WLAN_FC_GET_STYPE(fc) & 0x08));
-       */
+       /* qc_included = ((WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) &&
+        *             (WLAN_FC_GET_STYPE(fc) & 0x08));
+        */
        /* fixed by David :2006.9.6 */
        qc_included = (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA) &&
                       (WLAN_FC_GET_STYPE(fc) & 0x80);
@@ -146,7 +145,8 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
         * Flag (Include authentication header, M=3 (8-octet MIC),
         *       L=1 (2-octet Dlen))
         * Nonce: 0x00 | A2 | PN
-        * Dlen */
+        * Dlen
+        */
        b0[0] = 0x59;
        b0[1] = qc;
        memcpy(b0 + 2, hdr->addr2, ETH_ALEN);
@@ -229,8 +229,7 @@ static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
 
        hdr = (struct rtl_80211_hdr_4addr *) skb->data;
-       if (!tcb_desc->bHwSec)
-       {
+       if (!tcb_desc->bHwSec) {
                int blocks, last, len;
                u8 *mic;
                u8 *b0 = key->tx_b0;
@@ -284,23 +283,22 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
        keyidx = pos[3];
        if (!(keyidx & (1 << 5))) {
                if (net_ratelimit()) {
-                       printk(KERN_DEBUG "CCMP: received packet without ExtIV"
-                              " flag from %pM\n", hdr->addr2);
+                       printk(KERN_DEBUG "CCMP: received packet without ExtIV flag from %pM\n",
+                               hdr->addr2);
                }
                key->dot11RSNAStatsCCMPFormatErrors++;
                return -2;
        }
        keyidx >>= 6;
        if (key->key_idx != keyidx) {
-               printk(KERN_DEBUG "CCMP: RX tkey->key_idx=%d frame "
-                      "keyidx=%d priv=%p\n", key->key_idx, keyidx, priv);
+               printk(KERN_DEBUG "CCMP: RX tkey->key_idx=%d frame keyidx=%d priv=%p\n",
+                       key->key_idx, keyidx, priv);
                return -6;
        }
        if (!key->key_set) {
                if (net_ratelimit()) {
-                       printk(KERN_DEBUG "CCMP: received packet from %pM"
-                              " with keyid=%d that does not have a configured"
-                              " key\n", hdr->addr2, keyidx);
+                       printk(KERN_DEBUG "CCMP: received packet from %pM with keyid=%d that does not have a configured key\n",
+                               hdr->addr2, keyidx);
                }
                return -3;
        }
@@ -315,15 +313,13 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
        if (memcmp(pn, key->rx_pn, CCMP_PN_LEN) <= 0) {
                if (net_ratelimit()) {
-                       printk(KERN_DEBUG "CCMP: replay detected: STA=%pM"
-                              " previous PN %pm received PN %pm\n",
+                       printk(KERN_DEBUG "CCMP: replay detected: STA=%pM previous PN %pm received PN %pm\n",
                               hdr->addr2, key->rx_pn, pn);
                }
                key->dot11RSNAStatsCCMPReplays++;
                return -4;
        }
-       if (!tcb_desc->bHwSec)
-       {
+       if (!tcb_desc->bHwSec) {
                size_t data_len = skb->len - hdr_len - CCMP_HDR_LEN - CCMP_MIC_LEN;
                u8 *mic = skb->data + skb->len - CCMP_MIC_LEN;
                u8 *b0 = key->rx_b0;
@@ -353,8 +349,8 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
                if (memcmp(mic, a, CCMP_MIC_LEN) != 0) {
                        if (net_ratelimit()) {
-                               printk(KERN_DEBUG "CCMP: decrypt failed: STA="
-                               "%pM\n", hdr->addr2);
+                               printk(KERN_DEBUG "CCMP: decrypt failed: STA=%pM\n",
+                                       hdr->addr2);
                        }
                        key->dot11RSNAStatsCCMPDecryptErrors++;
                        return -5;
@@ -429,9 +425,8 @@ static int ieee80211_ccmp_get_key(void *key, int len, u8 *seq, void *priv)
 static char *ieee80211_ccmp_print_stats(char *p, void *priv)
 {
        struct ieee80211_ccmp_data *ccmp = priv;
-       p += sprintf(p, "key[%d] alg=CCMP key_set=%d "
-                    "tx_pn=%pm rx_pn=%pm "
-                    "format_errors=%d replays=%d decrypt_errors=%d\n",
+
+       p += sprintf(p, "key[%d] alg=CCMP key_set=%d tx_pn=%pm rx_pn=%pm format_errors=%d replays=%d decrypt_errors=%d\n",
                     ccmp->key_idx, ccmp->key_set,
                     ccmp->tx_pn, ccmp->rx_pn,
                     ccmp->dot11RSNAStatsCCMPFormatErrors,
index 1f80c52a49c4907cd50f740ad7df03c4ab92a67d..908bc2eb4d29e9842b482eb5ad9d67ae6f119acb 100644 (file)
@@ -185,8 +185,7 @@ static inline u16 Mk16_le(u16 *v)
 }
 
 
-static const u16 Sbox[256] =
-{
+static const u16 Sbox[256] = {
        0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
        0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
        0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
@@ -257,8 +256,10 @@ static void tkip_mixing_phase1(u16 *TTAK, const u8 *TK, const u8 *TA, u32 IV32)
 static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK,
                               u16 IV16)
 {
-       /* Make temporary area overlap WEP seed so that the final copy can be
-        * avoided on little endian hosts. */
+       /*
+        * Make temporary area overlap WEP seed so that the final copy can be
+        * avoided on little endian hosts.
+        */
        u16 *PPK = (u16 *) &WEPSeed[4];
 
        /* Step 1 - make copy of TTAK and bring in TSC */
@@ -284,8 +285,10 @@ static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK,
        PPK[4] += RotR1(PPK[3]);
        PPK[5] += RotR1(PPK[4]);
 
-       /* Step 3 - bring in last of TK bits, assign 24-bit WEP IV value
-        * WEPSeed[0..2] is transmitted as WEP IV */
+       /*
+        * Step 3 - bring in last of TK bits, assign 24-bit WEP IV value
+        * WEPSeed[0..2] is transmitted as WEP IV
+        */
        WEPSeed[0] = Hi8(IV16);
        WEPSeed[1] = (Hi8(IV16) | 0x20) & 0x7F;
        WEPSeed[2] = Lo8(IV16);
@@ -294,6 +297,7 @@ static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK,
 #ifdef __BIG_ENDIAN
        {
                int i;
+
                for (i = 0; i < 6; i++)
                        PPK[i] = (PPK[i] << 8) | (PPK[i] >> 8);
        }
@@ -304,7 +308,7 @@ static void tkip_mixing_phase2(u8 *WEPSeed, const u8 *TK, const u16 *TTAK,
 static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 {
        struct ieee80211_tkip_data *tkey = priv;
-               int len;
+       int len;
        u8 *pos;
        struct rtl_80211_hdr_4addr *hdr;
        cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
@@ -320,17 +324,15 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
        hdr = (struct rtl_80211_hdr_4addr *) skb->data;
 
-       if (!tcb_desc->bHwSec)
-       {
+       if (!tcb_desc->bHwSec) {
                if (!tkey->tx_phase1_done) {
                        tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2,
-                                       tkey->tx_iv32);
+                                          tkey->tx_iv32);
                        tkey->tx_phase1_done = 1;
                }
                tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16);
-       }
-       else
-       tkey->tx_phase1_done = 1;
+       } else
+               tkey->tx_phase1_done = 1;
 
 
        len = skb->len - hdr_len;
@@ -338,14 +340,11 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
        memmove(pos, pos + 8, hdr_len);
        pos += hdr_len;
 
-       if (tcb_desc->bHwSec)
-       {
+       if (tcb_desc->bHwSec) {
                *pos++ = Hi8(tkey->tx_iv16);
                *pos++ = (Hi8(tkey->tx_iv16) | 0x20) & 0x7F;
                *pos++ = Lo8(tkey->tx_iv16);
-       }
-       else
-       {
+       } else {
                *pos++ = rc4key[0];
                *pos++ = rc4key[1];
                *pos++ = rc4key[2];
@@ -357,8 +356,7 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
        *pos++ = (tkey->tx_iv32 >> 16) & 0xff;
        *pos++ = (tkey->tx_iv32 >> 24) & 0xff;
 
-       if (!tcb_desc->bHwSec)
-       {
+       if (!tcb_desc->bHwSec) {
                icv = skb_put(skb, 4);
                crc = ~crc32_le(~0, pos, len);
                icv[0] = crc;
@@ -367,7 +365,7 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
                icv[3] = crc >> 24;
                crypto_blkcipher_setkey(tkey->tx_tfm_arc4, rc4key, 16);
                sg_init_one(&sg, pos, len+4);
-               ret= crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
+               ret = crypto_blkcipher_encrypt(&desc, &sg, &sg, len + 4);
        }
 
        tkey->tx_iv16++;
@@ -398,6 +396,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
        u32 crc;
        struct scatterlist sg;
        int plen;
+
        if (skb->len < hdr_len + 8 + 4)
                return -1;
 
@@ -429,8 +428,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
        iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
        pos += 8;
 
-       if (!tcb_desc->bHwSec)
-       {
+       if (!tcb_desc->bHwSec) {
                if (iv32 < tkey->rx_iv32 ||
                (iv32 == tkey->rx_iv32 && iv16 <= tkey->rx_iv16)) {
                        if (net_ratelimit()) {
@@ -471,8 +469,11 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
                if (memcmp(icv, pos + plen, 4) != 0) {
                        if (iv32 != tkey->rx_iv32) {
-                               /* Previously cached Phase1 result was already lost, so
-                               * it needs to be recalculated for the next packet. */
+                               /*
+                                * Previously cached Phase1 result was already
+                                * lost, so it needs to be recalculated for the
+                                * next packet.
+                                */
                                tkey->rx_phase1_done = 0;
                        }
                        if (net_ratelimit()) {
@@ -485,8 +486,10 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
 
        }
 
-       /* Update real counters only after Michael MIC verification has
-        * completed */
+       /*
+        * Update real counters only after Michael MIC verification has
+        * completed.
+        */
        tkey->rx_iv32_new = iv32;
        tkey->rx_iv16_new = iv16;
 
@@ -571,9 +574,8 @@ static int ieee80211_michael_mic_add(struct sk_buff *skb, int hdr_len, void *pri
 
        // { david, 2006.9.1
        // fix the wpa process with wmm enabled.
-       if(IEEE80211_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl))) {
+       if (IEEE80211_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl)))
                tkey->tx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07;
-       }
        // }
        pos = skb_put(skb, 8);
 
@@ -606,7 +608,7 @@ static void ieee80211_michael_mic_failure(struct net_device *dev,
 }
 
 static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
-                                    int hdr_len, void *priv)
+                                       int hdr_len, void *priv)
 {
        struct ieee80211_tkip_data *tkey = priv;
        u8 mic[8];
@@ -620,17 +622,17 @@ static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
        michael_mic_hdr(skb, tkey->rx_hdr);
        // { david, 2006.9.1
        // fix the wpa process with wmm enabled.
-       if(IEEE80211_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl))) {
+       if (IEEE80211_QOS_HAS_SEQ(le16_to_cpu(hdr->frame_ctl)))
                tkey->rx_hdr[12] = *(skb->data + hdr_len - 2) & 0x07;
-       }
        // }
 
        if (michael_mic(tkey->rx_tfm_michael, &tkey->key[24], tkey->rx_hdr,
-                               skb->data + hdr_len, skb->len - 8 - hdr_len, mic))
+                       skb->data + hdr_len, skb->len - 8 - hdr_len, mic))
                return -1;
        if (memcmp(mic, skb->data + skb->len - 8, 8) != 0) {
                struct rtl_80211_hdr_4addr *hdr;
                hdr = (struct rtl_80211_hdr_4addr *) skb->data;
+
                printk(KERN_DEBUG "%s: Michael MIC verification failed for "
                       "MSDU from %pM keyidx=%d\n",
                       skb->dev ? skb->dev->name : "N/A", hdr->addr2,
@@ -641,8 +643,10 @@ static int ieee80211_michael_mic_verify(struct sk_buff *skb, int keyidx,
                return -1;
        }
 
-       /* Update TSC counters for RX now that the packet verification has
-        * completed. */
+       /*
+        * Update TSC counters for RX now that the packet verification has
+        * completed.
+        */
        tkey->rx_iv32 = tkey->rx_iv32_new;
        tkey->rx_iv16 = tkey->rx_iv16_new;
 
@@ -702,6 +706,7 @@ static int ieee80211_tkip_get_key(void *key, int len, u8 *seq, void *priv)
                /* Return the sequence number of the last transmitted frame. */
                u16 iv16 = tkey->tx_iv16;
                u32 iv32 = tkey->tx_iv32;
+
                if (iv16 == 0)
                        iv32--;
                iv16--;
@@ -720,6 +725,7 @@ static int ieee80211_tkip_get_key(void *key, int len, u8 *seq, void *priv)
 static char *ieee80211_tkip_print_stats(char *p, void *priv)
 {
        struct ieee80211_tkip_data *tkip = priv;
+
        p += sprintf(p, "key[%d] alg=TKIP key_set=%d "
                     "tx_pn=%02x%02x%02x%02x%02x%02x "
                     "rx_pn=%02x%02x%02x%02x%02x%02x "
index 31233d895ee9414c2206697d0d7e1dc3b1ae8613..425b2ddfc9167a9e7b98705348a1cd3e0f8679d4 100644 (file)
@@ -48,7 +48,7 @@
 #include <linux/types.h>
 #include <linux/wireless.h>
 #include <linux/etherdevice.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <net/arp.h>
 
 #include "ieee80211.h"
index 0aa9021cb95e751e0c2f6c2f9f3963e5638d2ef6..130c852ffa02a9671c0d370169c94f1ec176e004 100644 (file)
@@ -492,14 +492,10 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
 //     }
        if ((*last_seq == seq) &&
            time_after(*last_time + IEEE_PACKET_RETRY_TIME, jiffies)) {
-               if (*last_frag == frag){
-                       //printk(KERN_WARNING "[1] go drop!\n");
+               if (*last_frag == frag)
                        goto drop;
-
-               }
                if (*last_frag + 1 != frag)
                        /* out-of-order fragment */
-                       //printk(KERN_WARNING "[2] go drop!\n");
                        goto drop;
        } else
                *last_seq = seq;
@@ -510,7 +506,6 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
 
 drop:
 //     BUG_ON(!(fc & IEEE80211_FCTL_RETRY));
-//     printk("DUP\n");
 
        return 1;
 }
@@ -578,14 +573,12 @@ void ieee80211_indicate_packets(struct ieee80211_device *ieee, struct ieee80211_
 
                /* Indicat the packets to upper layer */
                        if (sub_skb) {
-                               //printk("0skb_len(%d)\n", skb->len);
                                sub_skb->protocol = eth_type_trans(sub_skb, ieee->dev);
                                memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
                                sub_skb->dev = ieee->dev;
                                sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
                                //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
                                ieee->last_rx_ps_time = jiffies;
-                               //printk("1skb_len(%d)\n", skb->len);
                                netif_rx(sub_skb);
                        }
                }
@@ -795,7 +788,6 @@ static u8 parse_subframe(struct sk_buff *skb,
        if (rx_stats->bContainHTC) {
                LLCOffset += sHTCLng;
        }
-       //printk("ChkLength = %d\n", LLCOffset);
        // Null packet, don't indicate it to upper layer
        ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
 
@@ -907,7 +899,6 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
        struct net_device *wds = NULL;
        struct sk_buff *skb2 = NULL;
        struct net_device *wds = NULL;
-       int frame_authorized = 0;
        int from_assoc_ap = 0;
        void *sta = NULL;
 #endif
@@ -1114,10 +1105,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
                switch (hostap_handle_sta_rx(ieee, dev, skb, rx_stats,
                                             wds != NULL)) {
                case AP_RX_CONTINUE_NOT_AUTHORIZED:
-                       frame_authorized = 0;
-                       break;
                case AP_RX_CONTINUE:
-                       frame_authorized = 1;
                        break;
                case AP_RX_DROP:
                        goto rx_dropped;
@@ -1340,14 +1328,12 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
                                }
 
                                /* Indicat the packets to upper layer */
-                               //printk("0skb_len(%d)\n", skb->len);
                                sub_skb->protocol = eth_type_trans(sub_skb, dev);
                                memset(sub_skb->cb, 0, sizeof(sub_skb->cb));
                                sub_skb->dev = dev;
                                sub_skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
                                //skb->ip_summed = CHECKSUM_UNNECESSARY; /* 802.11 crc not sufficient */
                                ieee->last_rx_ps_time = jiffies;
-                               //printk("1skb_len(%d)\n", skb->len);
                                netif_rx(sub_skb);
                        }
                }
@@ -1758,8 +1744,6 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
 
                        offset = (info_element->data[2] >> 1)*2;
 
-                       //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
-
                        if(ieee->assoc_id < 8*offset ||
                                ieee->assoc_id > 8*(offset + info_element->len -3))
 
@@ -2070,7 +2054,6 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
                case MFIE_TYPE_COUNTRY:
                        IEEE80211_DEBUG_SCAN("MFIE_TYPE_COUNTRY: %d bytes\n",
                                             info_element->len);
-                       //printk("=====>Receive <%s> Country IE\n",network->ssid);
                        ieee80211_extract_country_ie(ieee, info_element, network, network->bssid);//addr2 is same as addr3 when from an AP
                        break;
 /* TODO */
index 39e9892c3fa6a8ba04f82a6d9e9967c294aad20b..38c3eb78094e6b0113d68c7e7994781493a1b909 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/random.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <linux/etherdevice.h>
 
 #include "dot11d.h"
@@ -277,7 +277,6 @@ inline void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee
                        printk("%s():insert to waitqueue!\n",__func__);
                        skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index], skb);
                } else {
-                       //printk("TX packet!\n");
                        ieee->softmac_hard_start_xmit(skb, ieee->dev);
                        //dev_kfree_skb_any(skb);//edit by thomas
                }
@@ -418,7 +417,6 @@ static void ieee80211_send_probe_requests(struct ieee80211_device *ieee)
                ieee80211_send_probe(ieee);
        }
 }
-EXPORT_SYMBOL(ieee80211_send_probe_requests);
 
 /* this performs syncro scan blocking the caller until all channels
  * in the allowed channel map has been checked.
@@ -467,13 +465,9 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
                /* this prevent excessive time wait when we
                 * need to wait for a syncro scan to end..
                 */
-               if(ieee->state < IEEE80211_LINKED)
-                       ;
-               else
-               if (ieee->sync_scan_hurryup)
+               if (ieee->state >= IEEE80211_LINKED && ieee->sync_scan_hurryup)
                        goto out;
 
-
                msleep_interruptible_rsl(IEEE80211_SOFTMAC_SCAN_TIME);
 
        }
@@ -1273,7 +1267,6 @@ static void ieee80211_associate_step1(struct ieee80211_device *ieee)
        else{
                ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATING ;
                IEEE80211_DEBUG_MGMT("Sending authentication request\n");
-               //printk(KERN_WARNING "Sending authentication request\n");
                softmac_mgmt_xmit(skb, ieee);
                //BUGON when you try to add_timer twice, using mod_timer may be better, john0709
                if (!timer_pending(&ieee->associate_timer)) {
@@ -1465,10 +1458,8 @@ inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee
                                }
                                memcpy(&ieee->current_network, net, sizeof(struct ieee80211_network));
 
-                               if (!ssidbroad) {
-                                       strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
-                                       ieee->current_network.ssid_len = tmp_ssid_len;
-                               }
+                               strncpy(ieee->current_network.ssid, tmp_ssid, IW_ESSID_MAX_SIZE);
+                               ieee->current_network.ssid_len = tmp_ssid_len;
                                printk(KERN_INFO"Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d\n",ieee->current_network.ssid,ieee->current_network.channel, ieee->current_network.qos_data.supported, ieee->pHTInfo->bEnableHT, ieee->current_network.bssht.bdSupportHT);
 
                                //ieee->pHTInfo->IOTAction = 0;
@@ -1736,11 +1727,9 @@ static short ieee80211_sta_ps_sleep(struct ieee80211_device *ieee, u32 *time_h,
                return 0;
        */
        dtim = ieee->current_network.dtim_data;
-       //printk("DTIM\n");
        if(!(dtim & IEEE80211_DTIM_VALID))
                return 0;
        timeout = ieee->current_network.beacon_interval; //should we use ps_timeout value or beacon_interval
-       //printk("VALID\n");
        ieee->current_network.dtim_data = IEEE80211_DTIM_INVALID;
 
        if(dtim & ((IEEE80211_DTIM_UCAST | IEEE80211_DTIM_MBCAST)& ieee->ps))
index 3e502520648ea2a8ffcbdaa3bdd3cc431a69acdb..aad288a1f9e3ab39fe2de6f21dac2fb11d224725 100644 (file)
@@ -32,7 +32,7 @@ int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info
                             union iwreq_data *wrqu, char *b)
 {
        int ret;
-       struct iw_freq *fwrq = & wrqu->freq;
+       struct iw_freq *fwrq = &wrqu->freq;
 
        down(&ieee->wx_sem);
 
@@ -57,11 +57,11 @@ int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info
                }
        }
 
-       if (fwrq->e > 0 || fwrq->m > 14 || fwrq->m < 1 ){
+       if (fwrq->e > 0 || fwrq->m > 14 || fwrq->m < 1{
                ret = -EOPNOTSUPP;
                goto out;
 
-       }else { /* Set the channel */
+       } else { /* Set the channel */
 
                if (!(GET_DOT11D_INFO(ieee)->channel_map)[fwrq->m]) {
                        ret = -EINVAL;
@@ -70,11 +70,10 @@ int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info
                ieee->current_network.channel = fwrq->m;
                ieee->set_chan(ieee->dev, ieee->current_network.channel);
 
-               if(ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
-                       if(ieee->state == IEEE80211_LINKED){
-
-                       ieee80211_stop_send_beacons(ieee);
-                       ieee80211_start_send_beacons(ieee);
+               if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
+                       if (ieee->state == IEEE80211_LINKED) {
+                               ieee80211_stop_send_beacons(ieee);
+                               ieee80211_start_send_beacons(ieee);
                        }
        }
 
@@ -89,15 +88,15 @@ int ieee80211_wx_get_freq(struct ieee80211_device *ieee,
                             struct iw_request_info *a,
                             union iwreq_data *wrqu, char *b)
 {
-       struct iw_freq *fwrq = & wrqu->freq;
+       struct iw_freq *fwrq = &wrqu->freq;
 
        if (ieee->current_network.channel == 0)
                return -1;
-       //NM 0.7.0 will not accept channel any more.
+       /* NM 0.7.0 will not accept channel any more. */
        fwrq->m = ieee80211_wlan_frequencies[ieee->current_network.channel-1] * 100000;
        fwrq->e = 1;
-//     fwrq->m = ieee->current_network.channel;
-//     fwrq->e = 0;
+       /* fwrq->m = ieee->current_network.channel; */
+       /* fwrq->e = 0; */
 
        return 0;
 }
@@ -141,7 +140,7 @@ int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
        int ret = 0;
        unsigned long flags;
 
-       short ifup = ieee->proto_started;//dev->flags & IFF_UP;
+       short ifup = ieee->proto_started; /* dev->flags & IFF_UP; */
        struct sockaddr *temp = (struct sockaddr *)awrq;
 
        ieee->sync_scan_hurryup = 1;
@@ -179,7 +178,7 @@ out:
 }
 EXPORT_SYMBOL(ieee80211_wx_set_wap);
 
- int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b)
+int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a, union iwreq_data *wrqu, char *b)
 {
        int len, ret = 0;
        unsigned long flags;
@@ -191,14 +190,14 @@ EXPORT_SYMBOL(ieee80211_wx_set_wap);
        spin_lock_irqsave(&ieee->lock, flags);
 
        if (ieee->current_network.ssid[0] == '\0' ||
-               ieee->current_network.ssid_len == 0){
+               ieee->current_network.ssid_len == 0) {
                ret = -1;
                goto out;
        }
 
        if (ieee->state != IEEE80211_LINKED &&
                ieee->state != IEEE80211_LINKED_SCANNING &&
-               ieee->ssid_set == 0){
+               ieee->ssid_set == 0) {
                ret = -1;
                goto out;
        }
@@ -223,7 +222,7 @@ int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
        u32 target_rate = wrqu->bitrate.value;
 
        ieee->rate = target_rate/100000;
-       //FIXME: we might want to limit rate also in management protocols.
+       /* FIXME: we might want to limit rate also in management protocols. */
        return 0;
 }
 EXPORT_SYMBOL(ieee80211_wx_set_rate);
@@ -233,6 +232,7 @@ int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
                             union iwreq_data *wrqu, char *extra)
 {
        u32 tmp_rate;
+
        tmp_rate = TxCountToDataRate(ieee, ieee->softmac_stats.CurrentShowTxate);
 
        wrqu->bitrate.value = tmp_rate * 500000;
@@ -247,8 +247,7 @@ int ieee80211_wx_set_rts(struct ieee80211_device *ieee,
 {
        if (wrqu->rts.disabled || !wrqu->rts.fixed)
                ieee->rts = DEFAULT_RTS_THRESHOLD;
-       else
-       {
+       else {
                if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
                                wrqu->rts.value > MAX_RTS_THRESHOLD)
                        return -EINVAL;
@@ -280,16 +279,14 @@ int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info
        if (wrqu->mode == ieee->iw_mode)
                goto out;
 
-       if (wrqu->mode == IW_MODE_MONITOR){
-
+       if (wrqu->mode == IW_MODE_MONITOR)
                ieee->dev->type = ARPHRD_IEEE80211;
-       }else{
+       else
                ieee->dev->type = ARPHRD_ETHER;
-       }
 
-       if (!ieee->proto_started){
+       if (!ieee->proto_started) {
                ieee->iw_mode = wrqu->mode;
-       }else{
+       } else {
                ieee80211_stop_protocol(ieee);
                ieee->iw_mode = wrqu->mode;
                ieee80211_start_protocol(ieee);
@@ -305,10 +302,10 @@ void ieee80211_wx_sync_scan_wq(struct work_struct *work)
 {
        struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wx_sync_scan_wq);
        short chan;
-       HT_EXTCHNL_OFFSET chan_offset=0;
-       HT_CHANNEL_WIDTH bandwidth=0;
+       HT_EXTCHNL_OFFSET chan_offset = 0;
+       HT_CHANNEL_WIDTH bandwidth = 0;
        int b40M = 0;
-       static int count;
+
        chan = ieee->current_network.channel;
        netif_carrier_off(ieee->dev);
 
@@ -344,20 +341,18 @@ void ieee80211_wx_sync_scan_wq(struct work_struct *work)
        ieee->InitialGainHandler(ieee->dev, IG_Restore);
        ieee->state = IEEE80211_LINKED;
        ieee->link_change(ieee->dev);
-       // To prevent the immediately calling watch_dog after scan.
-       if (ieee->LinkDetectInfo.NumRecvBcnInPeriod==0||ieee->LinkDetectInfo.NumRecvDataInPeriod==0 )
-       {
+       /* To prevent the immediately calling watch_dog after scan. */
+       if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 || ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) {
                ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1;
-               ieee->LinkDetectInfo.NumRecvDataInPeriod= 1;
+               ieee->LinkDetectInfo.NumRecvDataInPeriod = 1;
        }
        if (ieee->data_hard_resume)
                ieee->data_hard_resume(ieee->dev);
 
-       if(ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
+       if (ieee->iw_mode == IW_MODE_ADHOC || ieee->iw_mode == IW_MODE_MASTER)
                ieee80211_start_send_beacons(ieee);
 
        netif_carrier_on(ieee->dev);
-       count = 0;
        up(&ieee->wx_sem);
 
 }
@@ -401,16 +396,16 @@ int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
        proto_started = ieee->proto_started;
 
        if (wrqu->essid.length > IW_ESSID_MAX_SIZE) {
-               ret= -E2BIG;
+               ret = -E2BIG;
                goto out;
        }
 
        if (ieee->iw_mode == IW_MODE_MONITOR) {
-               ret= -1;
+               ret = -1;
                goto out;
        }
 
-       if(proto_started)
+       if (proto_started)
                ieee80211_stop_protocol(ieee);
 
 
@@ -420,13 +415,12 @@ int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
        spin_lock_irqsave(&ieee->lock, flags);
 
        if (wrqu->essid.flags && wrqu->essid.length) {
-               //first flush current network.ssid
+               /* first flush current network.ssid */
                len = ((wrqu->essid.length-1) < IW_ESSID_MAX_SIZE) ? (wrqu->essid.length-1) : IW_ESSID_MAX_SIZE;
                strncpy(ieee->current_network.ssid, extra, len+1);
                ieee->current_network.ssid_len = len+1;
                ieee->ssid_set = 1;
-       }
-       else{
+       } else {
                ieee->ssid_set = 0;
                ieee->current_network.ssid[0] = '\0';
                ieee->current_network.ssid_len = 0;
@@ -441,7 +435,7 @@ out:
 }
 EXPORT_SYMBOL(ieee80211_wx_set_essid);
 
- int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
+int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
                             union iwreq_data *wrqu, char *b)
 {
 
@@ -450,7 +444,7 @@ EXPORT_SYMBOL(ieee80211_wx_set_essid);
 }
 EXPORT_SYMBOL(ieee80211_wx_get_mode);
 
- int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
+int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
                               struct iw_request_info *info,
                               union iwreq_data *wrqu, char *extra)
 {
@@ -461,7 +455,7 @@ EXPORT_SYMBOL(ieee80211_wx_get_mode);
 
        down(&ieee->wx_sem);
 
-       if(enable)
+       if (enable)
                ieee->raw_tx = 1;
        else
                ieee->raw_tx = 0;
@@ -469,8 +463,7 @@ EXPORT_SYMBOL(ieee80211_wx_get_mode);
        printk(KERN_INFO"raw TX is %s\n",
              ieee->raw_tx ? "enabled" : "disabled");
 
-       if (ieee->iw_mode == IW_MODE_MONITOR)
-       {
+       if (ieee->iw_mode == IW_MODE_MONITOR) {
                if (prev == 0 && ieee->raw_tx) {
                        if (ieee->data_hard_resume)
                                ieee->data_hard_resume(ieee->dev);
@@ -478,7 +471,7 @@ EXPORT_SYMBOL(ieee80211_wx_get_mode);
                        netif_carrier_on(ieee->dev);
                }
 
-               if(prev && ieee->raw_tx == 1)
+               if (prev && ieee->raw_tx == 1)
                        netif_carrier_off(ieee->dev);
        }
 
@@ -520,6 +513,7 @@ int ieee80211_wx_set_power(struct ieee80211_device *ieee,
                                 union iwreq_data *wrqu, char *extra)
 {
        int ret = 0;
+
        down(&ieee->wx_sem);
 
        if (wrqu->power.disabled) {
@@ -527,15 +521,15 @@ int ieee80211_wx_set_power(struct ieee80211_device *ieee,
                goto exit;
        }
        if (wrqu->power.flags & IW_POWER_TIMEOUT) {
-               //ieee->ps_period = wrqu->power.value / 1000;
+               /* ieee->ps_period = wrqu->power.value / 1000; */
                ieee->ps_timeout = wrqu->power.value / 1000;
        }
 
        if (wrqu->power.flags & IW_POWER_PERIOD) {
 
-               //ieee->ps_timeout = wrqu->power.value / 1000;
+               /* ieee->ps_timeout = wrqu->power.value / 1000; */
                ieee->ps_period = wrqu->power.value / 1000;
-               //wrq->value / 1024;
+               /* wrq->value / 1024; */
 
        }
        switch (wrqu->power.flags & IW_POWER_MODE) {
@@ -550,7 +544,7 @@ int ieee80211_wx_set_power(struct ieee80211_device *ieee,
                break;
 
        case IW_POWER_ON:
-       //      ieee->ps = IEEE80211_PS_DISABLED;
+               /* ieee->ps = IEEE80211_PS_DISABLED; */
                break;
 
        default:
@@ -583,14 +577,14 @@ int ieee80211_wx_get_power(struct ieee80211_device *ieee,
                wrqu->power.flags = IW_POWER_TIMEOUT;
                wrqu->power.value = ieee->ps_timeout * 1000;
        } else {
-//             ret = -EOPNOTSUPP;
-//             goto exit;
+               /* ret = -EOPNOTSUPP; */
+               /* goto exit; */
                wrqu->power.flags = IW_POWER_PERIOD;
                wrqu->power.value = ieee->ps_period * 1000;
-//ieee->current_network.dtim_period * ieee->current_network.beacon_interval * 1024;
+               /* ieee->current_network.dtim_period * ieee->current_network.beacon_interval * 1024; */
        }
 
-       if ((ieee->ps & (IEEE80211_PS_MBCAST | IEEE80211_PS_UNICAST)) == (IEEE80211_PS_MBCAST | IEEE80211_PS_UNICAST))
+       if ((ieee->ps & (IEEE80211_PS_MBCAST | IEEE80211_PS_UNICAST)) == (IEEE80211_PS_MBCAST | IEEE80211_PS_UNICAST))
                wrqu->power.flags |= IW_POWER_ALL_R;
        else if (ieee->ps & IEEE80211_PS_MBCAST)
                wrqu->power.flags |= IW_POWER_MULTICAST_R;
index fff8d583c62faa4501163d19da20a7f43f580671..1ab0aead298b30f662ff5f7b01f41af5ed56dc75 100644 (file)
@@ -48,7 +48,7 @@
 #include <linux/types.h>
 #include <linux/wireless.h>
 #include <linux/etherdevice.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <linux/if_vlan.h>
 
 #include "ieee80211.h"
index ae1b3cf2866cc9c85e1ca57ce821b31d8899642b..208be5fc527ae18e77ece946c25df9c05254e568 100644 (file)
@@ -522,7 +522,6 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
        struct ieee80211_security sec = {
                .flags = 0,
        };
-       //printk("======>encoding flag:%x,ext flag:%x, ext alg:%d\n", encoding->flags,ext->ext_flags, ext->alg);
        idx = encoding->flags & IW_ENCODE_INDEX;
        if (idx) {
                if (idx < 1 || idx > WEP_KEYS)
@@ -538,7 +537,6 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
                group_key = 1;
        } else {
                /* some Cisco APs use idx>0 for unicast in dynamic WEP */
-               //printk("not group key, flags:%x, ext->alg:%d\n", ext->ext_flags, ext->alg);
                if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP)
                        return -EINVAL;
                if (ieee->iw_mode == IW_MODE_INFRA)
@@ -567,7 +565,6 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
                        sec.level = SEC_LEVEL_0;
                        sec.flags |= SEC_LEVEL;
                }
-               //printk("disabled: flag:%x\n", encoding->flags);
                goto done;
        }
 
@@ -638,7 +635,6 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
                goto done;
        }
  //skip_host_crypt:
-       //printk("skip_host_crypt:ext_flags:%x\n", ext->ext_flags);
        if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
                ieee->tx_keyidx = idx;
                sec.active_key = idx;
@@ -760,7 +756,6 @@ int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
        switch (data->flags & IW_AUTH_INDEX) {
        case IW_AUTH_WPA_VERSION:
             /*need to support wpa2 here*/
-               //printk("wpa version:%x\n", data->value);
                break;
        case IW_AUTH_CIPHER_PAIRWISE:
        case IW_AUTH_CIPHER_GROUP:
@@ -791,16 +786,13 @@ int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
                else if(data->value & IW_AUTH_ALG_LEAP){
                        ieee->open_wep = 1;
                        ieee->auth_mode = 2;
-                       //printk("hahahaa:LEAP\n");
                }
                else
                        return -EINVAL;
-               //printk("open_wep:%d\n", ieee->open_wep);
                break;
 
        case IW_AUTH_WPA_ENABLED:
                ieee->wpa_enabled = (data->value)?1:0;
-               //printk("enalbe wpa:%d\n", ieee->wpa_enabled);
                break;
 
        case IW_AUTH_RX_UNENCRYPTED_EAPOL:
index 9fbce912a74b689ce1a1d605c4ef4e670cd25e0c..49c23c720f78ce0cb2272a1979f877fef7de0885 100644 (file)
@@ -1,39 +1,6 @@
 #ifndef __INC_QOS_TYPE_H
 #define __INC_QOS_TYPE_H
 
-#define BIT0                    0x00000001
-#define BIT1                    0x00000002
-#define BIT2                    0x00000004
-#define BIT3                    0x00000008
-#define BIT4                    0x00000010
-#define BIT5                    0x00000020
-#define BIT6                    0x00000040
-#define BIT7                    0x00000080
-#define BIT8                    0x00000100
-#define BIT9                    0x00000200
-#define BIT10                   0x00000400
-#define BIT11                   0x00000800
-#define BIT12                   0x00001000
-#define BIT13                   0x00002000
-#define BIT14                   0x00004000
-#define BIT15                   0x00008000
-#define BIT16                   0x00010000
-#define BIT17                   0x00020000
-#define BIT18                   0x00040000
-#define BIT19                   0x00080000
-#define BIT20                   0x00100000
-#define BIT21                   0x00200000
-#define BIT22                   0x00400000
-#define BIT23                   0x00800000
-#define BIT24                   0x01000000
-#define BIT25                   0x02000000
-#define BIT26                   0x04000000
-#define BIT27                   0x08000000
-#define BIT28                   0x10000000
-#define BIT29                   0x20000000
-#define BIT30                   0x40000000
-#define BIT31                   0x80000000
-
 #define        MAX_WMMELE_LENGTH       64
 
 //
@@ -375,17 +342,17 @@ typedef struct _ACM{
 
 typedef        u8              AC_UAPSD, *PAC_UAPSD;
 
-#define        GET_VO_UAPSD(_apsd) ((_apsd) & BIT0)
-#define        SET_VO_UAPSD(_apsd) ((_apsd) |= BIT0)
+#define        GET_VO_UAPSD(_apsd) ((_apsd) & BIT(0))
+#define        SET_VO_UAPSD(_apsd) ((_apsd) |= BIT(0))
 
-#define        GET_VI_UAPSD(_apsd) ((_apsd) & BIT1)
-#define        SET_VI_UAPSD(_apsd) ((_apsd) |= BIT1)
+#define        GET_VI_UAPSD(_apsd) ((_apsd) & BIT(1))
+#define        SET_VI_UAPSD(_apsd) ((_apsd) |= BIT(1))
 
-#define        GET_BK_UAPSD(_apsd) ((_apsd) & BIT2)
-#define        SET_BK_UAPSD(_apsd) ((_apsd) |= BIT2)
+#define        GET_BK_UAPSD(_apsd) ((_apsd) & BIT(2))
+#define        SET_BK_UAPSD(_apsd) ((_apsd) |= BIT(2))
 
-#define        GET_BE_UAPSD(_apsd) ((_apsd) & BIT3)
-#define        SET_BE_UAPSD(_apsd) ((_apsd) |= BIT3)
+#define        GET_BE_UAPSD(_apsd) ((_apsd) & BIT(3))
+#define        SET_BE_UAPSD(_apsd) ((_apsd) |= BIT(3))
 
 
 //typedef struct _TCLASS{
index 785fd027a00d2f0b7ca6f919f7e008df1e6441b4..ee1c72267811ee46b54d9cb891e5dbc661f9aacf 100644 (file)
 #define MAX_KEY_LEN     61
 #define KEY_BUF_SIZE    5
 
-#define BIT0            0x00000001
-#define BIT1            0x00000002
-#define BIT2            0x00000004
-#define BIT3            0x00000008
-#define BIT4            0x00000010
-#define BIT5            0x00000020
-#define BIT6            0x00000040
-#define BIT7            0x00000080
-#define BIT8            0x00000100
-#define BIT9            0x00000200
-#define BIT10           0x00000400
-#define BIT11           0x00000800
-#define BIT12           0x00001000
-#define BIT13           0x00002000
-#define BIT14           0x00004000
-#define BIT15           0x00008000
-#define BIT16           0x00010000
-#define BIT17           0x00020000
-#define BIT18           0x00040000
-#define BIT19           0x00080000
-#define BIT20           0x00100000
-#define BIT21           0x00200000
-#define BIT22           0x00400000
-#define BIT23           0x00800000
-#define BIT24           0x01000000
-#define BIT25           0x02000000
-#define BIT26           0x04000000
-#define BIT27           0x08000000
-#define BIT28           0x10000000
-#define BIT29           0x20000000
-#define BIT30           0x40000000
-#define BIT31           0x80000000
-
 #define        Rx_Smooth_Factor                20
 #define DMESG(x, a...)
 #define DMESGW(x, a...)
@@ -87,44 +54,44 @@ extern u32 rt_global_debug_component;
                        pr_debug("RTL8192U: " x "\n", ##args);  \
        } while (0)
 
-#define COMP_TRACE              BIT0  /* Function call tracing. */
-#define COMP_DBG                BIT1
-#define COMP_INIT               BIT2  /* Driver initialization/halt/reset. */
+#define COMP_TRACE              BIT(0)  /* Function call tracing. */
+#define COMP_DBG                BIT(1)
+#define COMP_INIT               BIT(2)  /* Driver initialization/halt/reset. */
 
 
-#define COMP_RECV               BIT3  /* Receive data path. */
-#define COMP_SEND               BIT4  /* Send data path. */
-#define COMP_IO                 BIT5
+#define COMP_RECV               BIT(3)  /* Receive data path. */
+#define COMP_SEND               BIT(4)  /* Send data path. */
+#define COMP_IO                 BIT(5)
 /* 802.11 Power Save mode or System/Device Power state. */
-#define COMP_POWER              BIT6
+#define COMP_POWER              BIT(6)
 /* 802.11 link related: join/start BSS, leave BSS. */
-#define COMP_EPROM              BIT7
-#define COMP_SWBW               BIT8  /* Bandwidth switch. */
-#define COMP_POWER_TRACKING     BIT9  /* 8190 TX Power Tracking */
-#define COMP_TURBO              BIT10 /* Turbo Mode */
-#define COMP_QOS                BIT11
-#define COMP_RATE               BIT12 /* Rate Adaptive mechanism */
-#define COMP_RM                 BIT13 /* Radio Measurement */
-#define COMP_DIG                BIT14
-#define COMP_PHY                BIT15
-#define COMP_CH                 BIT16 /* Channel setting debug */
-#define COMP_TXAGC              BIT17 /* Tx power */
-#define COMP_HIPWR              BIT18 /* High Power Mechanism */
-#define COMP_HALDM              BIT19 /* HW Dynamic Mechanism */
-#define COMP_SEC                BIT20 /* Event handling */
-#define COMP_LED                BIT21
-#define COMP_RF                 BIT22
-#define COMP_RXDESC             BIT23 /* Rx desc information for SD3 debug */
+#define COMP_EPROM              BIT(7)
+#define COMP_SWBW               BIT(8)  /* Bandwidth switch. */
+#define COMP_POWER_TRACKING     BIT(9)  /* 8190 TX Power Tracking */
+#define COMP_TURBO              BIT(10) /* Turbo Mode */
+#define COMP_QOS                BIT(11)
+#define COMP_RATE               BIT(12) /* Rate Adaptive mechanism */
+#define COMP_RM                 BIT(13) /* Radio Measurement */
+#define COMP_DIG                BIT(14)
+#define COMP_PHY                BIT(15)
+#define COMP_CH                 BIT(16) /* Channel setting debug */
+#define COMP_TXAGC              BIT(17) /* Tx power */
+#define COMP_HIPWR              BIT(18) /* High Power Mechanism */
+#define COMP_HALDM              BIT(19) /* HW Dynamic Mechanism */
+#define COMP_SEC                BIT(20) /* Event handling */
+#define COMP_LED                BIT(21)
+#define COMP_RF                 BIT(22)
+#define COMP_RXDESC             BIT(23) /* Rx desc information for SD3 debug */
 
 /* 11n or 8190 specific code */
 
-#define COMP_FIRMWARE           BIT24 /* Firmware downloading */
-#define COMP_HT                 BIT25 /* 802.11n HT related information */
-#define COMP_AMSDU              BIT26 /* A-MSDU Debugging */
-#define COMP_SCAN               BIT27
-#define COMP_DOWN               BIT29 /* rm driver module */
-#define COMP_RESET              BIT30 /* Silent reset */
-#define COMP_ERR                BIT31 /* Error out, always on */
+#define COMP_FIRMWARE           BIT(24) /* Firmware downloading */
+#define COMP_HT                 BIT(25) /* 802.11n HT related information */
+#define COMP_AMSDU              BIT(26) /* A-MSDU Debugging */
+#define COMP_SCAN               BIT(27)
+#define COMP_DOWN               BIT(29) /* rm driver module */
+#define COMP_RESET              BIT(30) /* Silent reset */
+#define COMP_ERR                BIT(31) /* Error out, always on */
 
 #define RTL819x_DEBUG
 #ifdef RTL819x_DEBUG
@@ -335,11 +302,11 @@ typedef struct _tx_fwinfo_819x_usb {
        u32     PacketID:13;
 } tx_fwinfo_819x_usb, *ptx_fwinfo_819x_usb;
 
-typedef struct rtl8192_rx_info {
+struct rtl8192_rx_info {
        struct urb *urb;
        struct net_device *dev;
        u8 out_pipe;
-} rtl8192_rx_info ;
+};
 
 typedef struct rx_desc_819x_usb {
        /* DOWRD 0 */
index 6f6fe38081bcefff290d832db78818dac63ec7a7..e06864f64beb82963eb0e116cf88a1ec88c939d6 100644 (file)
@@ -37,17 +37,17 @@ unsigned int __fixunsdfsi(double d)
 
 double __adddf3(double a, double b)
 {
-       return a+b;
+       return a + b;
 }
 
 double __addsf3(float a, float b)
 {
-       return a+b;
+       return a + b;
 }
 
 double __subdf3(double a, double b)
 {
-       return a-b;
+       return a - b;
 }
 
 double __extendsfdf2(float a)
@@ -58,13 +58,13 @@ double __extendsfdf2(float a)
 
 #define CONFIG_RTL8192_IO_MAP
 
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include "r8192U_hw.h"
 #include "r8192U.h"
 #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */
 #include "r8180_93cx6.h"   /* Card EEPROM */
 #include "r8192U_wx.h"
-#include "r819xU_phy.h" //added by WB 4.30.2008
+#include "r819xU_phy.h"
 #include "r819xU_phyreg.h"
 #include "r819xU_cmdpkt.h"
 #include "r8192U_dm.h"
@@ -72,13 +72,13 @@ double __extendsfdf2(float a)
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
-// FIXME: check if 2.6.7 is ok
+/* FIXME: check if 2.6.7 is ok */
 
 #include "dot11d.h"
-//set here to open your trace code. //WB
+/* set here to open your trace code. */
 u32 rt_global_debug_component = COMP_DOWN      |
                                COMP_SEC        |
-                               COMP_ERR; //always open err flags on
+                               COMP_ERR; /* always open err flags on */
 
 #define TOTAL_CAM_ENTRY 32
 #define CAM_CONTENT_COUNT 8
@@ -109,14 +109,14 @@ MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
 MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
 
 static char *ifname = "wlan%d";
-static int hwwep = 1;  //default use hw. set 0 to use software security
+static int hwwep = 1;  /* default use hw. set 0 to use software security */
 static int channels = 0x3fff;
 
 
 
-module_param(ifname, charp, S_IRUGO|S_IWUSR);
-module_param(hwwep, int, S_IRUGO|S_IWUSR);
-module_param(channels, int, S_IRUGO|S_IWUSR);
+module_param(ifname, charp, S_IRUGO | S_IWUSR);
+module_param(hwwep, int, S_IRUGO | S_IWUSR);
+module_param(channels, int, S_IRUGO | S_IWUSR);
 
 MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
 MODULE_PARM_DESC(hwwep, " Try to use hardware security support. ");
@@ -143,23 +143,35 @@ struct CHANNEL_LIST {
 };
 
 static struct CHANNEL_LIST ChannelPlan[] = {
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165}, 24},             //FCC
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11},                                                      //IC
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21},      //ETSI
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},    //Spain. Change to ETSI.
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},      //France. Change to ETSI.
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},  //MKK                                   //MKK
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},//MKK1
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},      //Israel.
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},                  // For 11a , TELEC
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},    //MIC
-       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}                                   //For Global Domain. 1-11:active scan, 12-14 passive scan. //+YJ, 080626
+       /* FCC */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165}, 24},
+       /* IC */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11},
+       /* ETSI */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40, 44, 48, 52, 56, 60, 64}, 21},
+       /* Spain. Change to ETSI. */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
+       /* France. Change to ETSI. */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
+       /* MKK */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
+       /* MKK1 */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
+       /* Israel. */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13},
+       /* For 11a , TELEC */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
+       /* MIC */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36, 40, 44, 48, 52, 56, 60, 64}, 22},
+       /* For Global Domain. 1-11:active scan, 12-14 passive scan. */
+       {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14}
 };
 
 static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
 {
        int i, max_chan = -1, min_chan = -1;
        struct ieee80211_device *ieee = priv->ieee80211;
+
        switch (channel_plan) {
        case COUNTRY_CODE_FCC:
        case COUNTRY_CODE_IC:
@@ -173,17 +185,20 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
        case COUNTRY_CODE_MIC:
                Dot11d_Init(ieee);
                ieee->bGlobalDomain = false;
-               //actually 8225 & 8256 rf chips only support B,G,24N mode
+               /* actually 8225 & 8256 rf chips only support B,G,24N mode */
                if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) {
                        min_chan = 1;
                        max_chan = 14;
                } else {
-                       RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __func__);
+                       RT_TRACE(COMP_ERR,
+                                "unknown rf chip, can't set channel map in function:%s()\n",
+                                __func__);
                }
                if (ChannelPlan[channel_plan].Len != 0) {
-                       // Clear old channel map
-                       memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
-                       // Set new channel map
+                       /* Clear old channel map */
+                       memset(GET_DOT11D_INFO(ieee)->channel_map, 0,
+                              sizeof(GET_DOT11D_INFO(ieee)->channel_map));
+                       /* Set new channel map */
                        for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
                                if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
                                        break;
@@ -193,7 +208,10 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
                break;
 
        case COUNTRY_CODE_GLOBAL_DOMAIN:
-               GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings.
+               /* this flag enabled to follow 11d country IE setting,
+                * otherwise, it shall follow global domain settings.
+                */
+               GET_DOT11D_INFO(ieee)->bEnabled = 0;
                Dot11d_Reset(ieee);
                ieee->bGlobalDomain = true;
                break;
@@ -209,10 +227,13 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv *priv)
 static void CamResetAllEntry(struct net_device *dev)
 {
        u32 ulcommand = 0;
-       //2004/02/11  In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA associate to AP.
-       // However, ResetKey is called on OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest
-       // In this condition, Cam can not be reset because upper layer will not set this static key again.
-       ulcommand |= BIT31|BIT30;
+       /* In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA
+        * associate to AP. However, ResetKey is called on
+        * OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest. In this
+        * condition, Cam can not be reset because upper layer will not set
+        * this static key again.
+        */
+       ulcommand |= BIT(31) | BIT(30);
        write_nic_dword(dev, RWCAM, ulcommand);
 
 }
@@ -221,14 +242,14 @@ static void CamResetAllEntry(struct net_device *dev)
 void write_cam(struct net_device *dev, u8 addr, u32 data)
 {
        write_nic_dword(dev, WCAMI, data);
-       write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff));
+       write_nic_dword(dev, RWCAM, BIT(31) | BIT(16) | (addr & 0xff));
 }
 
 u32 read_cam(struct net_device *dev, u8 addr)
 {
        u32 data;
 
-       write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff));
+       write_nic_dword(dev, RWCAM, 0x80000000 | (addr & 0xff));
        read_nic_dword(dev, 0xa8, &data);
        return data;
 }
@@ -238,13 +259,20 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+       if (!usbdata)
+               return;
+       *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
                                 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
-                                indx|0xfe00, 0, &data, 1, HZ / 2);
+                                indx | 0xfe00, 0, usbdata, 1, HZ / 2);
+       kfree(usbdata);
 
        if (status < 0)
-               netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n", status);
+               netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n",
+                          status);
 }
 
 int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
@@ -252,10 +280,16 @@ int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u8 *usbdata = kzalloc(sizeof(u8), GFP_KERNEL);
+
+       if (!usbdata)
+               return -ENOMEM;
 
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                                 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
-                                indx|0xfe00, 0, data, 1, HZ / 2);
+                                indx | 0xfe00, 0, usbdata, 1, HZ / 2);
+       *data = *usbdata;
+       kfree(usbdata);
 
        if (status < 0) {
                netdev_err(dev, "%s failure status: %d\n", __func__, status);
@@ -264,17 +298,24 @@ int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
 
        return 0;
 }
-//as 92U has extend page from 4 to 16, so modify functions below.
+/* as 92U has extend page from 4 to 16, so modify functions below. */
 void write_nic_byte(struct net_device *dev, int indx, u8 data)
 {
        int status;
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+       if (!usbdata)
+               return;
+       *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
                                 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
-                                (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
+                                (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
+                                usbdata, 1, HZ / 2);
+       kfree(usbdata);
 
        if (status < 0)
                netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
@@ -290,10 +331,17 @@ void write_nic_word(struct net_device *dev, int indx, u16 data)
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u16 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+       if (!usbdata)
+               return;
+       *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
                                 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
-                                (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 2, HZ / 2);
+                                (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
+                                usbdata, 2, HZ / 2);
+       kfree(usbdata);
 
        if (status < 0)
                netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
@@ -308,14 +356,22 @@ void write_nic_dword(struct net_device *dev, int indx, u32 data)
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u32 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
+
+       if (!usbdata)
+               return;
+       *usbdata = data;
 
        status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
                                 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
-                                (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 4, HZ / 2);
+                                (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
+                                usbdata, 4, HZ / 2);
+       kfree(usbdata);
 
 
        if (status < 0)
-               netdev_err(dev, "write_nic_dword TimeOut! status: %d\n", status);
+               netdev_err(dev, "write_nic_dword TimeOut! status: %d\n",
+                          status);
 
 }
 
@@ -326,10 +382,17 @@ int read_nic_byte(struct net_device *dev, int indx, u8 *data)
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u8 *usbdata = kzalloc(sizeof(u8), GFP_KERNEL);
+
+       if (!usbdata)
+               return -ENOMEM;
 
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                                 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
-                                (indx&0xff)|0xff00, (indx>>8)&0x0f, data, 1, HZ / 2);
+                                (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
+                                usbdata, 1, HZ / 2);
+       *data = *usbdata;
+       kfree(usbdata);
 
        if (status < 0) {
                netdev_err(dev, "%s failure status: %d\n", __func__, status);
@@ -346,11 +409,17 @@ int read_nic_word(struct net_device *dev, int indx, u16 *data)
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u16 *usbdata = kzalloc(sizeof(u16), GFP_KERNEL);
+
+       if (!usbdata)
+               return -ENOMEM;
 
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                                 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
-                                (indx&0xff)|0xff00, (indx>>8)&0x0f,
-                                data, 2, HZ / 2);
+                                (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
+                                usbdata, 2, HZ / 2);
+       *data = *usbdata;
+       kfree(usbdata);
 
        if (status < 0) {
                netdev_err(dev, "%s failure status: %d\n", __func__, status);
@@ -365,10 +434,16 @@ static int read_nic_word_E(struct net_device *dev, int indx, u16 *data)
        int status;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u16 *usbdata = kzalloc(sizeof(u16), GFP_KERNEL);
+
+       if (!usbdata)
+               return -ENOMEM;
 
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                                 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
-                                indx|0xfe00, 0, data, 2, HZ / 2);
+                                indx | 0xfe00, 0, usbdata, 2, HZ / 2);
+       *data = *usbdata;
+       kfree(usbdata);
 
        if (status < 0) {
                netdev_err(dev, "%s failure status: %d\n", __func__, status);
@@ -384,11 +459,17 @@ int read_nic_dword(struct net_device *dev, int indx, u32 *data)
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct usb_device *udev = priv->udev;
+       u32 *usbdata = kzalloc(sizeof(u32), GFP_KERNEL);
+
+       if (!usbdata)
+               return -ENOMEM;
 
        status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
                                 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
-                                (indx&0xff)|0xff00, (indx>>8)&0x0f,
-                                data, 4, HZ / 2);
+                                (indx & 0xff) | 0xff00, (indx >> 8) & 0x0f,
+                                usbdata, 4, HZ / 2);
+       *data = *usbdata;
+       kfree(usbdata);
 
        if (status < 0) {
                netdev_err(dev, "%s failure status: %d\n", __func__, status);
@@ -427,6 +508,7 @@ static int proc_get_stats_ap(struct seq_file *m, void *v)
 
        list_for_each_entry(target, &ieee->network_list, list) {
                const char *wpa = "non_WPA";
+
                if (target->wpa_ie_len > 0 || target->rsn_ie_len > 0)
                        wpa = "WPA";
 
@@ -448,7 +530,7 @@ static int proc_get_registers(struct seq_file *m, void *v)
                seq_printf(m, "\nD:  %2x > ", n);
 
                for (i = 0; i < 16 && n <= max; i++, n++) {
-                       read_nic_byte(dev, 0x000|n, &byte_rd);
+                       read_nic_byte(dev, 0x000 | n, &byte_rd);
                        seq_printf(m, "%2x ", byte_rd);
                }
        }
@@ -458,7 +540,7 @@ static int proc_get_registers(struct seq_file *m, void *v)
                seq_printf(m, "\nD:  %2x > ", n);
 
                for (i = 0; i < 16 && n <= max; i++, n++) {
-                       read_nic_byte(dev, 0x100|n, &byte_rd);
+                       read_nic_byte(dev, 0x100 | n, &byte_rd);
                        seq_printf(m, "%2x ", byte_rd);
                }
        }
@@ -468,7 +550,7 @@ static int proc_get_registers(struct seq_file *m, void *v)
                seq_printf(m, "\nD:  %2x > ", n);
 
                for (i = 0; i < 16 && n <= max; i++, n++) {
-                       read_nic_byte(dev, 0x300|n, &byte_rd);
+                       read_nic_byte(dev, 0x300 | n, &byte_rd);
                        seq_printf(m, "%2x ", byte_rd);
                }
        }
@@ -600,7 +682,8 @@ static void rtl8192_proc_init_one(struct net_device *dev)
        if (rtl8192_proc) {
                dir = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
                if (!dir) {
-                       RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
+                       RT_TRACE(COMP_ERR,
+                                "Unable to initialize /proc/net/rtl8192/%s\n",
                                 dev->name);
                        return;
                }
@@ -608,8 +691,8 @@ static void rtl8192_proc_init_one(struct net_device *dev)
                for (f = rtl8192_proc_files; f->name[0]; f++) {
                        if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir,
                                              &rtl8192_proc_fops, f->show)) {
-                               RT_TRACE(COMP_ERR, "Unable to initialize "
-                                        "/proc/net/rtl8192/%s/%s\n",
+                               RT_TRACE(COMP_ERR,
+                                        "Unable to initialize /proc/net/rtl8192/%s/%s\n",
                                         dev->name, f->name);
                                return;
                        }
@@ -657,14 +740,14 @@ void rtl8192_update_msr(struct net_device *dev)
        if (priv->ieee80211->state == IEEE80211_LINKED) {
 
                if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
-                       msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
+                       msr |= (MSR_LINK_MANAGED << MSR_LINK_SHIFT);
                else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
-                       msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
+                       msr |= (MSR_LINK_ADHOC << MSR_LINK_SHIFT);
                else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
-                       msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
+                       msr |= (MSR_LINK_MASTER << MSR_LINK_SHIFT);
 
        } else {
-               msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
+               msr |= (MSR_LINK_NONE << MSR_LINK_SHIFT);
        }
 
        write_nic_byte(dev, MSR, msr);
@@ -673,12 +756,13 @@ void rtl8192_update_msr(struct net_device *dev)
 void rtl8192_set_chan(struct net_device *dev, short ch)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+
        RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch);
        priv->chan = ch;
 
        /* this hack should avoid frame TX during channel setting*/
 
-       //need to implement rf set channel here WB
+       /* need to implement rf set channel here */
 
        if (priv->rf_set_chan)
                priv->rf_set_chan(dev, priv->chan);
@@ -712,12 +796,13 @@ static int rtl8192_rx_initiate(struct net_device *dev)
                        break;
                }
                usb_fill_bulk_urb(entry, priv->udev,
-                                 usb_rcvbulkpipe(priv->udev, 3), skb_tail_pointer(skb),
+                                 usb_rcvbulkpipe(priv->udev, 3),
+                                 skb_tail_pointer(skb),
                                  RX_URB_SIZE, rtl8192_rx_isr, skb);
-               info = (struct rtl8192_rx_info *) skb->cb;
+               info = (struct rtl8192_rx_info *)skb->cb;
                info->urb = entry;
                info->dev = dev;
-               info->out_pipe = 3; //denote rx normal packet queue
+               info->out_pipe = 3; /* denote rx normal packet queue */
                skb_queue_tail(&priv->rx_queue, skb);
                usb_submit_urb(entry, GFP_KERNEL);
        }
@@ -733,12 +818,13 @@ static int rtl8192_rx_initiate(struct net_device *dev)
                        break;
                }
                usb_fill_bulk_urb(entry, priv->udev,
-                                 usb_rcvbulkpipe(priv->udev, 9), skb_tail_pointer(skb),
+                                 usb_rcvbulkpipe(priv->udev, 9),
+                                 skb_tail_pointer(skb),
                                  RX_URB_SIZE, rtl8192_rx_isr, skb);
-               info = (struct rtl8192_rx_info *) skb->cb;
+               info = (struct rtl8192_rx_info *)skb->cb;
                info->urb = entry;
                info->dev = dev;
-               info->out_pipe = 9; //denote rx cmd packet queue
+               info->out_pipe = 9; /* denote rx cmd packet queue */
                skb_queue_tail(&priv->rx_queue, skb);
                usb_submit_urb(entry, GFP_KERNEL);
        }
@@ -780,15 +866,15 @@ void rtl8192_set_rxconf(struct net_device *dev)
 
 
        rxconf = rxconf & ~RX_FIFO_THRESHOLD_MASK;
-       rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
+       rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE << RX_FIFO_THRESHOLD_SHIFT);
        rxconf = rxconf & ~MAX_RX_DMA_MASK;
-       rxconf = rxconf | ((u32)7<<RCR_MXDMA_OFFSET);
+       rxconf = rxconf | ((u32)7 << RCR_MXDMA_OFFSET);
 
        rxconf = rxconf | RCR_ONLYERLPKT;
 
        write_nic_dword(dev, RCR, rxconf);
 }
-//wait to be removed
+/* wait to be removed */
 void rtl8192_rx_enable(struct net_device *dev)
 {
        rtl8192_rx_initiate(dev);
@@ -809,12 +895,12 @@ void rtl8192_rtx_disable(struct net_device *dev)
        struct rtl8192_rx_info *info;
 
        read_nic_byte(dev, CMDR, &cmd);
-       write_nic_byte(dev, CMDR, cmd & ~(CR_TE|CR_RE));
+       write_nic_byte(dev, CMDR, cmd & ~(CR_TE | CR_RE));
        force_pci_posting(dev);
        mdelay(10);
 
        while ((skb = __skb_dequeue(&priv->rx_queue))) {
-               info = (struct rtl8192_rx_info *) skb->cb;
+               info = (struct rtl8192_rx_info *)skb->cb;
                if (!info->urb)
                        continue;
 
@@ -872,14 +958,16 @@ inline u16 rtl8192_rate2rate(short rate)
 /* The prototype of rx_isr has changed since one version of Linux Kernel */
 static void rtl8192_rx_isr(struct urb *urb)
 {
-       struct sk_buff *skb = (struct sk_buff *) urb->context;
+       struct sk_buff *skb = (struct sk_buff *)urb->context;
        struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
        struct net_device *dev = info->dev;
        struct r8192_priv *priv = ieee80211_priv(dev);
        int out_pipe = info->out_pipe;
        int err;
+
        if (!priv->up)
                return;
+
        if (unlikely(urb->status)) {
                info->urb = NULL;
                priv->stats.rxstaterr++;
@@ -902,10 +990,11 @@ static void rtl8192_rx_isr(struct urb *urb)
        }
 
        usb_fill_bulk_urb(urb, priv->udev,
-                         usb_rcvbulkpipe(priv->udev, out_pipe), skb_tail_pointer(skb),
+                         usb_rcvbulkpipe(priv->udev, out_pipe),
+                         skb_tail_pointer(skb),
                          RX_URB_SIZE, rtl8192_rx_isr, skb);
 
-       info = (struct rtl8192_rx_info *) skb->cb;
+       info = (struct rtl8192_rx_info *)skb->cb;
        info->urb = urb;
        info->dev = dev;
        info->out_pipe = out_pipe;
@@ -915,7 +1004,9 @@ static void rtl8192_rx_isr(struct urb *urb)
        skb_queue_tail(&priv->rx_queue, skb);
        err = usb_submit_urb(urb, GFP_ATOMIC);
        if (err && err != EPERM)
-               netdev_err(dev, "can not submit rxurb, err is %x, URB status is %x\n", err, urb->status);
+               netdev_err(dev,
+                          "can not submit rxurb, err is %x, URB status is %x\n",
+                          err, urb->status);
 }
 
 static u32 rtl819xusb_rx_command_packet(struct net_device *dev,
@@ -933,19 +1024,20 @@ static u32 rtl819xusb_rx_command_packet(struct net_device *dev,
 
 static void rtl8192_data_hard_stop(struct net_device *dev)
 {
-       //FIXME !!
+       /* FIXME !! */
 }
 
 
 static void rtl8192_data_hard_resume(struct net_device *dev)
 {
-       // FIXME !!
+       /* FIXME !! */
 }
 
 /* this function TX data frames when the ieee80211 stack requires this.
  * It checks also if we need to stop the ieee tx queue, eventually do it
  */
-static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
+static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
+                                  int rate)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        int ret;
@@ -987,8 +1079,6 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
                skb_push(skb, USB_HWDESC_HEADER_LEN);
                rtl819xU_tx_cmd(dev, skb);
                ret = 1;
-               spin_unlock_irqrestore(&priv->tx_lock, flags);
-               return ret;
        } else {
                skb_push(skb, priv->ieee80211->tx_headroom);
                ret = rtl8192_tx(dev, skb);
@@ -999,9 +1089,6 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
        return ret;
 }
 
-
-void rtl8192_try_wake_queue(struct net_device *dev, int pri);
-
 static void rtl8192_tx_isr(struct urb *tx_urb)
 {
        struct sk_buff *skb = (struct sk_buff *)tx_urb->context;
@@ -1017,7 +1104,8 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
                        dev->trans_start = jiffies;
                        priv->stats.txoktotal++;
                        priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
-                       priv->stats.txbytesunicast += (skb->len - priv->ieee80211->tx_headroom);
+                       priv->stats.txbytesunicast +=
+                               (skb->len - priv->ieee80211->tx_headroom);
                } else {
                        priv->ieee80211->stats.tx_errors++;
                        /* TODO */
@@ -1031,16 +1119,17 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
                atomic_dec(&priv->tx_pending[queue_index]);
        }
 
-       //
-       // Handle HW Beacon:
-       // We had transfer our beacon frame to host controller at this moment.
-       //
-       //
-       // Caution:
-       // Handling the wait queue of command packets.
-       // For Tx command packets, we must not do TCB fragment because it is not handled right now.
-       // We must cut the packets to match the size of TX_CMD_PKT before we send it.
-       //
+       /*
+        * Handle HW Beacon:
+        * We had transfer our beacon frame to host controller at this moment.
+        *
+        *
+        * Caution:
+        * Handling the wait queue of command packets.
+        * For Tx command packets, we must not do TCB fragment because it is
+        * not handled right now. We must cut the packets to match the size of
+        * TX_CMD_PKT before we send it.
+        */
 
        /* Handle MPDU in wait queue. */
        if (queue_index != BEACON_QUEUE) {
@@ -1049,9 +1138,10 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
                    (!(priv->ieee80211->queue_stop))) {
                        skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]));
                        if (skb)
-                               priv->ieee80211->softmac_hard_start_xmit(skb, dev);
+                               priv->ieee80211->softmac_hard_start_xmit(skb,
+                                                                        dev);
 
-                       return; //modified by david to avoid further processing AMSDU
+                       return; /* avoid further processing AMSDU */
                }
        }
 
@@ -1062,10 +1152,11 @@ static void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
        struct r8192_priv *priv = ieee80211_priv(dev);
        struct ieee80211_network *net;
        u8 i = 0, basic_rate = 0;
+
        net = &priv->ieee80211->current_network;
 
        for (i = 0; i < net->rates_len; i++) {
-               basic_rate = net->rates[i]&0x7f;
+               basic_rate = net->rates[i] & 0x7f;
                switch (basic_rate) {
                case MGN_1M:
                        *rate_config |= RRSR_1M;
@@ -1106,7 +1197,7 @@ static void rtl8192_config_rate(struct net_device *dev, u16 *rate_config)
                }
        }
        for (i = 0; i < net->rates_ex_len; i++) {
-               basic_rate = net->rates_ex[i]&0x7f;
+               basic_rate = net->rates_ex[i] & 0x7f;
                switch (basic_rate) {
                case MGN_1M:
                        *rate_config |= RRSR_1M;
@@ -1157,17 +1248,21 @@ static void rtl8192_update_cap(struct net_device *dev, u16 cap)
        u32 tmp = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
        struct ieee80211_network *net = &priv->ieee80211->current_network;
+
        priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
        tmp = priv->basic_rate;
        if (priv->short_preamble)
                tmp |= BRSR_AckShortPmb;
        write_nic_dword(dev, RRSR, tmp);
 
-       if (net->mode & (IEEE_G|IEEE_N_24G)) {
+       if (net->mode & (IEEE_G | IEEE_N_24G)) {
                u8 slot_time = 0;
-               if ((cap & WLAN_CAPABILITY_SHORT_SLOT) && (!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime)) /* short slot time */
+
+               if ((cap & WLAN_CAPABILITY_SHORT_SLOT) &&
+                   (!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
+                       /* short slot time */
                        slot_time = SHORT_SLOT_TIME;
-               else //long slot time
+               else    /* long slot time */
                        slot_time = NON_SHORT_SLOT_TIME;
                priv->slot_time = slot_time;
                write_nic_byte(dev, SLOT_TIME, slot_time);
@@ -1181,13 +1276,14 @@ static void rtl8192_net_update(struct net_device *dev)
        struct ieee80211_network *net;
        u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
        u16 rate_config = 0;
+
        net = &priv->ieee80211->current_network;
 
        rtl8192_config_rate(dev, &rate_config);
        priv->basic_rate = rate_config & 0x15f;
 
        write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]);
-       write_nic_word(dev, BSSIDR+4, ((u16 *)net->bssid)[2]);
+       write_nic_word(dev, BSSIDR + 4, ((u16 *)net->bssid)[2]);
 
        rtl8192_update_msr(dev);
        if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
@@ -1196,9 +1292,9 @@ static void rtl8192_net_update(struct net_device *dev)
                write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
                write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
                write_nic_byte(dev, BCN_ERR_THRESH, 100);
-               BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
-               // TODO: BcnIFS may required to be changed on ASIC
-               BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
+               BcnTimeCfg |= (BcnCW << BCN_TCFG_CW_SHIFT);
+               /* TODO: BcnIFS may required to be changed on ASIC */
+               BcnTimeCfg |= BcnIFS << BCN_TCFG_IFS;
 
                write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
        }
@@ -1207,8 +1303,9 @@ static void rtl8192_net_update(struct net_device *dev)
 
 }
 
-//temporary hw beacon is not used any more.
-//open it when necessary
+/* temporary hw beacon is not used any more.
+ * open it when necessary
+ */
 void rtl819xusb_beacon_tx(struct net_device *dev, u16  tx_rate)
 {
 
@@ -1221,53 +1318,6 @@ inline u8 rtl8192_IsWirelessBMode(u16 rate)
                return 0;
 }
 
-u16 N_DBPSOfRate(u16 DataRate);
-
-
-u16 N_DBPSOfRate(u16 DataRate)
-{
-       u16 N_DBPS = 24;
-
-       switch (DataRate) {
-       case 60:
-               N_DBPS = 24;
-               break;
-
-       case 90:
-               N_DBPS = 36;
-               break;
-
-       case 120:
-               N_DBPS = 48;
-               break;
-
-       case 180:
-               N_DBPS = 72;
-               break;
-
-       case 240:
-               N_DBPS = 96;
-               break;
-
-       case 360:
-               N_DBPS = 144;
-               break;
-
-       case 480:
-               N_DBPS = 192;
-               break;
-
-       case 540:
-               N_DBPS = 216;
-               break;
-
-       default:
-               break;
-       }
-
-       return N_DBPS;
-}
-
 short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -1287,28 +1337,29 @@ short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
 
        memset(pdesc, 0, USB_HWDESC_HEADER_LEN);
        /* Tx descriptor ought to be set according to the skb->cb */
-       pdesc->FirstSeg = 1;//bFirstSeg;
-       pdesc->LastSeg = 1;//bLastSeg;
+       pdesc->FirstSeg = 1;
+       pdesc->LastSeg = 1;
        pdesc->CmdInit = tcb_desc->bCmdOrInit;
        pdesc->TxBufferSize = tcb_desc->txbuf_size;
        pdesc->OWN = 1;
        pdesc->LINIP = tcb_desc->bLastIniPkt;
 
-       //----------------------------------------------------------------------------
-       // Fill up USB_OUT_CONTEXT.
-       //----------------------------------------------------------------------------
+       /*---------------------------------------------------------------------
+        * Fill up USB_OUT_CONTEXT.
+        *---------------------------------------------------------------------
+        */
        idx_pipe = 0x04;
-       usb_fill_bulk_urb(tx_urb, priv->udev, usb_sndbulkpipe(priv->udev, idx_pipe),
+       usb_fill_bulk_urb(tx_urb, priv->udev,
+                         usb_sndbulkpipe(priv->udev, idx_pipe),
                          skb->data, skb->len, rtl8192_tx_isr, skb);
 
        status = usb_submit_urb(tx_urb, GFP_ATOMIC);
 
-       if (!status) {
+       if (!status)
                return 0;
-       } else {
-               DMESGE("Error TX CMD URB, error %d", status);
-               return -1;
-       }
+
+       DMESGE("Error TX CMD URB, error %d", status);
+       return -1;
 }
 
 /*
@@ -1320,7 +1371,7 @@ short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
 */
 static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
 {
-       u8 QueueSelect = 0x0;       //defualt set to
+       u8 QueueSelect = 0x0;       /* defualt set to */
 
        switch (QueueID) {
        case BE_QUEUE:
@@ -1346,8 +1397,8 @@ static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
                QueueSelect = QSLT_BEACON;
                break;
 
-               // TODO: 2006.10.30 mark other queue selection until we verify it is OK
-               // TODO: Remove Assertions
+               /* TODO: mark other queue selection until we verify it is OK */
+               /* TODO: Remove Assertions */
        case TXCMD_QUEUE:
                QueueSelect = QSLT_CMD;
                break;
@@ -1356,7 +1407,9 @@ static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
                break;
 
        default:
-               RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
+               RT_TRACE(COMP_ERR,
+                        "TransmitTCB(): Impossible Queue Selection: %d\n",
+                        QueueID);
                break;
        }
        return QueueSelect;
@@ -1453,7 +1506,7 @@ static u8 MRateToHwRate8190Pci(u8 rate)
        case MGN_MCS15:
                ret = DESC90_RATEMCS15;
                break;
-       case (0x80|0x20):
+       case (0x80 | 0x20):
                ret = DESC90_RATEMCS32;
                break;
 
@@ -1468,7 +1521,9 @@ static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
 {
        u8   tmp_Short;
 
-       tmp_Short = (TxHT == 1) ? ((tcb_desc->bUseShortGI) ? 1 : 0) : ((tcb_desc->bUseShortPreamble) ? 1 : 0);
+       tmp_Short = (TxHT == 1) ?
+                       ((tcb_desc->bUseShortGI) ? 1 : 0) :
+                       ((tcb_desc->bUseShortPreamble) ? 1 : 0);
 
        if (TxHT == 1 && TxRate != DESC90_RATEMCS15)
                tmp_Short = 0;
@@ -1478,7 +1533,6 @@ static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
 
 static void tx_zero_isr(struct urb *tx_urb)
 {
-       return;
 }
 
 /*
@@ -1491,12 +1545,14 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
        struct r8192_priv *priv = ieee80211_priv(dev);
        cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
        tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data;
-       tx_fwinfo_819x_usb *tx_fwinfo = (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);
+       tx_fwinfo_819x_usb *tx_fwinfo =
+               (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);
        struct usb_device *udev = priv->udev;
        int pend;
        int status;
        struct urb *tx_urb = NULL, *tx_urb_zero = NULL;
        unsigned int idx_pipe;
+
        pend = atomic_read(&priv->tx_pending[tcb_desc->queue_index]);
        /* we are locked here so the two atomic_read and inc are executed
         * without interleaves
@@ -1517,15 +1573,16 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
        /* Fill Tx firmware info */
        memset(tx_fwinfo, 0, sizeof(tx_fwinfo_819x_usb));
        /* DWORD 0 */
-       tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80) ? 1 : 0;
+       tx_fwinfo->TxHT = (tcb_desc->data_rate & 0x80) ? 1 : 0;
        tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
        tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
-       tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
+       tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate,
+                                       tcb_desc);
        if (tcb_desc->bAMPDUEnable) { /* AMPDU enabled */
                tx_fwinfo->AllowAggregation = 1;
                /* DWORD 1 */
                tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
-               tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
+               tx_fwinfo->RxAMD = tcb_desc->ampdu_density & 0x07;
        } else {
                tx_fwinfo->AllowAggregation = 0;
                /* DWORD 1 */
@@ -1537,18 +1594,19 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
        tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable) ? 1 : 0;
        tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable) ? 1 : 0;
        tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC) ? 1 : 0;
-       tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80) ? 1 : 0;
+       tx_fwinfo->RtsHT = (tcb_desc->rts_rate & 0x80) ? 1 : 0;
        tx_fwinfo->RtsRate =  MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
        tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->RTSSC) : 0;
        tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT == 1) ? ((tcb_desc->bRTSBW) ? 1 : 0) : 0;
        tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT == 0) ? (tcb_desc->bRTSUseShortPreamble ? 1 : 0) :
-                             (tcb_desc->bRTSUseShortGI ? 1 : 0);
+                             (tcb_desc->bRTSUseShortGI ? 1 : 0);
 
        /* Set Bandwidth and sub-channel settings. */
        if (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) {
                if (tcb_desc->bPacketBW) {
                        tx_fwinfo->TxBandwidth = 1;
-                       tx_fwinfo->TxSubCarrier = 0;    //By SD3's Jerry suggestion, use duplicated mode
+                       /* use duplicated mode */
+                       tx_fwinfo->TxSubCarrier = 0;
                } else {
                        tx_fwinfo->TxBandwidth = 0;
                        tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
@@ -1599,8 +1657,10 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
        tx_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
        tx_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
 
-       /* Fill fields that are required to be initialized in all of the descriptors */
-       //DWORD 0
+       /* Fill fields that are required to be initialized in
+        * all of the descriptors
+        */
+       /* DWORD 0 */
        tx_desc->FirstSeg = 1;
        tx_desc->LastSeg = 1;
        tx_desc->OWN = 1;
@@ -1616,9 +1676,14 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
 
        status = usb_submit_urb(tx_urb, GFP_ATOMIC);
        if (!status) {
-               //we need to send 0 byte packet whenever 512N bytes/64N(HIGN SPEED/NORMAL SPEED) bytes packet has been transmitted. Otherwise, it will be halt to wait for another packet. WB. 2008.08.27
+               /* We need to send 0 byte packet whenever
+                * 512N bytes/64N(HIGN SPEED/NORMAL SPEED) bytes packet has
+                * been transmitted. Otherwise, it will be halt to wait for
+                * another packet.
+                */
                bool bSend0Byte = false;
                u8 zero = 0;
+
                if (udev->speed == USB_SPEED_HIGH) {
                        if (skb->len > 0 && skb->len % 512 == 0)
                                bSend0Byte = true;
@@ -1629,43 +1694,49 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
                if (bSend0Byte) {
                        tx_urb_zero = usb_alloc_urb(0, GFP_ATOMIC);
                        if (!tx_urb_zero) {
-                               RT_TRACE(COMP_ERR, "can't alloc urb for zero byte\n");
+                               RT_TRACE(COMP_ERR,
+                                        "can't alloc urb for zero byte\n");
                                return -ENOMEM;
                        }
                        usb_fill_bulk_urb(tx_urb_zero, udev,
-                                         usb_sndbulkpipe(udev, idx_pipe), &zero,
-                                         0, tx_zero_isr, dev);
+                                         usb_sndbulkpipe(udev, idx_pipe),
+                                         &zero, 0, tx_zero_isr, dev);
                        status = usb_submit_urb(tx_urb_zero, GFP_ATOMIC);
                        if (status) {
-                               RT_TRACE(COMP_ERR, "Error TX URB for zero byte %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status);
+                               RT_TRACE(COMP_ERR,
+                                        "Error TX URB for zero byte %d, error %d",
+                                        atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
+                                        status);
                                return -1;
                        }
                }
                dev->trans_start = jiffies;
                atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
                return 0;
-       } else {
-               RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
-                        status);
-               return -1;
        }
+
+       RT_TRACE(COMP_ERR, "Error TX URB %d, error %d",
+                atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
+                status);
+       return -1;
 }
 
 static short rtl8192_usb_initendpoints(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
 
-       priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB+1),
+       priv->rx_urb = kmalloc(sizeof(struct urb *) * (MAX_RX_URB + 1),
                               GFP_KERNEL);
        if (priv->rx_urb == NULL)
                return -ENOMEM;
 
 #ifndef JACKSON_NEW_RX
-       for (i = 0; i < (MAX_RX_URB+1); i++) {
+       for (i = 0; i < (MAX_RX_URB + 1); i++) {
 
                priv->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
 
-               priv->rx_urb[i]->transfer_buffer = kmalloc(RX_URB_SIZE, GFP_KERNEL);
+               priv->rx_urb[i]->transfer_buffer =
+                       kmalloc(RX_URB_SIZE, GFP_KERNEL);
 
                priv->rx_urb[i]->transfer_buffer_length = RX_URB_SIZE;
        }
@@ -1715,7 +1786,7 @@ static void rtl8192_usb_deleteendpoints(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
 
        if (priv->rx_urb) {
-               for (i = 0; i < (MAX_RX_URB+1); i++) {
+               for (i = 0; i < (MAX_RX_URB + 1); i++) {
                        usb_kill_urb(priv->rx_urb[i]);
                        usb_free_urb(priv->rx_urb[i]);
                }
@@ -1724,10 +1795,9 @@ static void rtl8192_usb_deleteendpoints(struct net_device *dev)
        }
        kfree(priv->oldaddr);
        priv->oldaddr = NULL;
-       if (priv->pp_rxskb) {
-               kfree(priv->pp_rxskb);
-               priv->pp_rxskb = NULL;
-       }
+
+       kfree(priv->pp_rxskb);
+       priv->pp_rxskb = NULL;
 }
 #else
 void rtl8192_usb_deleteendpoints(struct net_device *dev)
@@ -1738,7 +1808,7 @@ void rtl8192_usb_deleteendpoints(struct net_device *dev)
 #ifndef JACKSON_NEW_RX
 
        if (priv->rx_urb) {
-               for (i = 0; i < (MAX_RX_URB+1); i++) {
+               for (i = 0; i < (MAX_RX_URB + 1); i++) {
                        usb_kill_urb(priv->rx_urb[i]);
                        kfree(priv->rx_urb[i]->transfer_buffer);
                        usb_free_urb(priv->rx_urb[i]);
@@ -1752,11 +1822,9 @@ void rtl8192_usb_deleteendpoints(struct net_device *dev)
        priv->rx_urb = NULL;
        kfree(priv->oldaddr);
        priv->oldaddr = NULL;
-       if (priv->pp_rxskb) {
-               kfree(priv->pp_rxskb);
-               priv->pp_rxskb = 0;
 
-       }
+       kfree(priv->pp_rxskb);
+       priv->pp_rxskb = 0;
 
 #endif
 }
@@ -1767,16 +1835,22 @@ static void rtl8192_link_change(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
        struct ieee80211_device *ieee = priv->ieee80211;
+
        if (ieee->state == IEEE80211_LINKED) {
                rtl8192_net_update(dev);
                rtl8192_update_ratr_table(dev);
-               //add this as in pure N mode, wep encryption will use software way, but there is no chance to set this as wep will not set group key in wext. WB.2008.07.08
-               if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
+               /* Add this as in pure N mode, wep encryption will use software
+                * way, but there is no chance to set this as wep will not set
+                * group key in wext.
+                */
+               if (KEY_TYPE_WEP40 == ieee->pairwise_key_type ||
+                   KEY_TYPE_WEP104 == ieee->pairwise_key_type)
                        EnableHWSecurityConfig8192(dev);
        }
        /*update timing params*/
        if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) {
                u32 reg = 0;
+
                read_nic_dword(dev, RCR, &reg);
                if (priv->ieee80211->state == IEEE80211_LINKED)
                        priv->ReceiveConfig = reg |= RCR_CBSSID;
@@ -1797,25 +1871,30 @@ static struct ieee80211_qos_parameters def_qos_parameters = {
 
 static void rtl8192_update_beacon(struct work_struct *work)
 {
-       struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
+       struct r8192_priv *priv = container_of(work, struct r8192_priv,
+                                              update_beacon_wq.work);
        struct net_device *dev = priv->ieee80211->dev;
        struct ieee80211_device *ieee = priv->ieee80211;
        struct ieee80211_network *net = &ieee->current_network;
 
        if (ieee->pHTInfo->bCurrentHTSupport)
                HTUpdateSelfAndPeerSetting(ieee, net);
-       ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
+       ieee->pHTInfo->bCurrentRT2RTLongSlotTime =
+               net->bssht.bdRT2RTLongSlotTime;
        rtl8192_update_cap(dev, net->capability);
 }
 /*
 * background support to run QoS activate functionality
 */
-static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, EDCAPARA_VI, EDCAPARA_VO};
+static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK,
+                            EDCAPARA_VI, EDCAPARA_VO};
 static void rtl8192_qos_activate(struct work_struct *work)
 {
-       struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
+       struct r8192_priv *priv = container_of(work, struct r8192_priv,
+                                              qos_activate);
        struct net_device *dev = priv->ieee80211->dev;
-       struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
+       struct ieee80211_qos_parameters *qos_parameters =
+               &priv->ieee80211->current_network.qos_data.parameters;
        u8 mode = priv->ieee80211->current_network.mode;
        u32  u1bAIFS;
        u32 u4bAcParam;
@@ -1827,13 +1906,18 @@ static void rtl8192_qos_activate(struct work_struct *work)
        mutex_lock(&priv->mutex);
        if (priv->ieee80211->state != IEEE80211_LINKED)
                goto success;
-       RT_TRACE(COMP_QOS, "qos active process with associate response received\n");
-       /* It better set slot time at first */
-       /* For we just support b/g mode at present, let the slot time at 9/20 selection */
-       /* update the ac parameter to related registers */
+       RT_TRACE(COMP_QOS,
+                "qos active process with associate response received\n");
+       /* It better set slot time at first
+        *
+        * For we just support b/g mode at present, let the slot time at
+        * 9/20 selection
+        *
+        * update the ac parameter to related registers
+        */
        for (i = 0; i <  QOS_QUEUE_NUM; i++) {
-               //Mode G/A: slotTimeTimer = 9; Mode B: 20
-               u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
+               /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */
+               u1bAIFS = qos_parameters->aifs[i] * ((mode & (IEEE_G | IEEE_N_24G)) ? 9 : 20) + aSifsTime;
                u1bAIFS <<= AC_PARAM_AIFS_OFFSET;
                op_limit = (u32)le16_to_cpu(qos_parameters->tx_op_limit[i]);
                op_limit <<= AC_PARAM_TXOP_LIMIT_OFFSET;
@@ -1859,7 +1943,7 @@ static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
        if (priv->ieee80211->state != IEEE80211_LINKED)
                return ret;
 
-       if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
+       if (priv->ieee80211->iw_mode != IW_MODE_INFRA)
                return ret;
 
        if (network->flags & NETWORK_HAS_QOS_MASK) {
@@ -1874,8 +1958,8 @@ static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
                        network->qos_data.old_param_count =
                                network->qos_data.param_count;
                        queue_work(priv->priv_wq, &priv->qos_activate);
-                       RT_TRACE(COMP_QOS, "QoS parameters change call "
-                                "qos_activate\n");
+                       RT_TRACE(COMP_QOS,
+                                "QoS parameters change call qos_activate\n");
                }
        } else {
                memcpy(&priv->ieee80211->current_network.qos_data.parameters,
@@ -1883,7 +1967,8 @@ static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
 
                if ((network->qos_data.active == 1) && (active_network == 1)) {
                        queue_work(priv->priv_wq, &priv->qos_activate);
-                       RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
+                       RT_TRACE(COMP_QOS,
+                                "QoS was disabled call qos_activate\n");
                }
                network->qos_data.active = 0;
                network->qos_data.supported = 0;
@@ -1923,7 +2008,7 @@ static int rtl8192_qos_association_resp(struct r8192_priv *priv,
        if (priv->ieee80211->state != IEEE80211_LINKED)
                return 0;
 
-       if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
+       if (priv->ieee80211->iw_mode != IW_MODE_INFRA)
                return 0;
 
        spin_lock_irqsave(&priv->ieee80211->lock, flags);
@@ -1948,7 +2033,9 @@ static int rtl8192_qos_association_resp(struct r8192_priv *priv,
 
        spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
 
-       RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__, network->flags, priv->ieee80211->current_network.qos_data.active);
+       RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__,
+                network->flags,
+                priv->ieee80211->current_network.qos_data.active);
        if (set_qos_param == 1)
                queue_work(priv->priv_wq, &priv->qos_activate);
 
@@ -1957,11 +2044,13 @@ static int rtl8192_qos_association_resp(struct r8192_priv *priv,
 }
 
 
-static int rtl8192_handle_assoc_response(struct net_device *dev,
-                                        struct ieee80211_assoc_response_frame *resp,
-                                        struct ieee80211_network *network)
+static int rtl8192_handle_assoc_response(
+               struct net_device *dev,
+               struct ieee80211_assoc_response_frame *resp,
+               struct ieee80211_network *network)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
+
        rtl8192_qos_association_resp(priv, network);
        return 0;
 }
@@ -1974,6 +2063,7 @@ static void rtl8192_update_ratr_table(struct net_device *dev)
        u8 *pMcsRate = ieee->dot11HTOperationalRateSet;
        u32 ratr_value = 0;
        u8 rate_index = 0;
+
        rtl8192_config_rate(dev, (u16 *)(&ratr_value));
        ratr_value |= (*(u16 *)(pMcsRate)) << 12;
        switch (ieee->mode) {
@@ -2003,9 +2093,10 @@ static void rtl8192_update_ratr_table(struct net_device *dev)
        ratr_value &= 0x0FFFFFFF;
        if (ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz)
                ratr_value |= 0x80000000;
-       else if (!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz)
+       else if (!ieee->pHTInfo->bCurTxBW40MHz &&
+                ieee->pHTInfo->bCurShortGI20MHz)
                ratr_value |= 0x80000000;
-       write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
+       write_nic_dword(dev, RATR0 + rate_index * 4, ratr_value);
        write_nic_byte(dev, UFWP, 1);
 }
 
@@ -2021,8 +2112,12 @@ static bool GetNmodeSupportBySecCfg8192(struct net_device *dev)
        int encrypt;
 
        crypt = ieee->crypt[ieee->tx_keyidx];
-       //we use connecting AP's capability instead of only security config on our driver to distinguish whether it should use N mode or G mode
-       encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name, "WEP")));
+       /* we use connecting AP's capability instead of only security config
+        * on our driver to distinguish whether it should use N mode or G mode
+        */
+       encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) ||
+                 (ieee->host_encrypt && crypt && crypt->ops &&
+                  (0 == strcmp(crypt->ops->name, "WEP")));
 
        /* simply judge  */
        if (encrypt && (wpa_ie_len == 0)) {
@@ -2051,9 +2146,13 @@ static bool GetHalfNmodeSupportByAPs819xUsb(struct net_device *dev)
 static void rtl8192_refresh_supportrate(struct r8192_priv *priv)
 {
        struct ieee80211_device *ieee = priv->ieee80211;
-       //we do not consider set support rate for ABG mode, only HT MCS rate is set here.
-       if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
-               memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
+       /* We do not consider set support rate for ABG mode, only
+        * HT MCS rate is set here.
+        */
+       if (ieee->mode == WIRELESS_MODE_N_24G ||
+           ieee->mode == WIRELESS_MODE_N_5G)
+               memcpy(ieee->Regdot11HTOperationalRateSet,
+                      ieee->RegHTSuppRateSet, 16);
        else
                memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
 }
@@ -2062,14 +2161,15 @@ static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8 ret = 0;
+
        switch (priv->rf_chip) {
        case RF_8225:
        case RF_8256:
        case RF_PSEUDO_11N:
-               ret = WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B;
+               ret = WIRELESS_MODE_N_24G | WIRELESS_MODE_G | WIRELESS_MODE_B;
                break;
        case RF_8258:
-               ret = WIRELESS_MODE_A|WIRELESS_MODE_N_5G;
+               ret = WIRELESS_MODE_A | WIRELESS_MODE_N_5G;
                break;
        default:
                ret = WIRELESS_MODE_B;
@@ -2082,7 +2182,8 @@ static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
 
-       if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode) == 0)) {
+       if (wireless_mode == WIRELESS_MODE_AUTO ||
+           (wireless_mode & bSupportMode) == 0) {
                if (bSupportMode & WIRELESS_MODE_N_24G) {
                        wireless_mode = WIRELESS_MODE_N_24G;
                } else if (bSupportMode & WIRELESS_MODE_N_5G) {
@@ -2094,16 +2195,24 @@ static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
                } else if ((bSupportMode & WIRELESS_MODE_B)) {
                        wireless_mode = WIRELESS_MODE_B;
                } else {
-                       RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __func__, bSupportMode);
+                       RT_TRACE(COMP_ERR,
+                                "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
+                                __func__, bSupportMode);
                        wireless_mode = WIRELESS_MODE_B;
                }
        }
-#ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we should wait for FPGA
-       ActUpdateChannelAccessSetting(pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting);
+#ifdef TO_DO_LIST
+       /* TODO: this function doesn't work well at this time,
+        * we should wait for FPGA
+        */
+       ActUpdateChannelAccessSetting(
+                       pAdapter, pHalData->CurrentWirelessMode,
+                       &pAdapter->MgntInfo.Info8185.ChannelAccessSetting);
 #endif
        priv->ieee80211->mode = wireless_mode;
 
-       if ((wireless_mode == WIRELESS_MODE_N_24G) ||  (wireless_mode == WIRELESS_MODE_N_5G))
+       if (wireless_mode == WIRELESS_MODE_N_24G ||
+           wireless_mode == WIRELESS_MODE_N_5G)
                priv->ieee80211->pHTInfo->bEnableHT = 1;
        else
                priv->ieee80211->pHTInfo->bEnableHT = 0;
@@ -2111,43 +2220,47 @@ static void rtl8192_SetWirelessMode(struct net_device *dev, u8 wireless_mode)
        rtl8192_refresh_supportrate(priv);
 
 }
-//init priv variables here. only non_zero value should be initialized here.
+/* init priv variables here. only non_zero value should be initialized here. */
 static void rtl8192_init_priv_variable(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
        u8 i;
+
        priv->card_8192 = NIC_8192U;
-       priv->chan = 1; //set to channel 1
-       priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
+       priv->chan = 1; /* set to channel 1 */
+       priv->ieee80211->mode = WIRELESS_MODE_AUTO; /* SET AUTO */
        priv->ieee80211->iw_mode = IW_MODE_INFRA;
        priv->ieee80211->ieee_up = 0;
        priv->retry_rts = DEFAULT_RETRY_RTS;
        priv->retry_data = DEFAULT_RETRY_DATA;
        priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
-       priv->ieee80211->rate = 110; //11 mbps
+       priv->ieee80211->rate = 110; /* 11 mbps */
        priv->ieee80211->short_slot = 1;
        priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
        priv->CckPwEnl = 6;
-       //for silent reset
+       /* for silent reset */
        priv->IrpPendingCount = 1;
        priv->ResetProgress = RESET_TYPE_NORESET;
        priv->bForcedSilentReset = false;
        priv->bDisableNormalResetCheck = false;
        priv->force_reset = false;
 
-       priv->ieee80211->FwRWRF = 0;    //we don't use FW read/write RF until stable firmware is available.
-       priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
+       /* we don't use FW read/write RF until stable firmware is available. */
+       priv->ieee80211->FwRWRF = 0;
+       priv->ieee80211->current_network.beacon_interval =
+               DEFAULT_BEACONINTERVAL;
        priv->ieee80211->softmac_features  = IEEE_SOFTMAC_SCAN |
                IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
                IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
-               IEEE_SOFTMAC_BEACONS;//added by amy 080604
+               IEEE_SOFTMAC_BEACONS;
 
        priv->ieee80211->active_scan = 1;
-       priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
+       priv->ieee80211->modulation =
+               IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
        priv->ieee80211->host_encrypt = 1;
        priv->ieee80211->host_decrypt = 1;
-       priv->ieee80211->start_send_beacons = NULL; //-by amy 080604
-       priv->ieee80211->stop_send_beacons = NULL;  //-by amy 080604
+       priv->ieee80211->start_send_beacons = NULL;
+       priv->ieee80211->stop_send_beacons = NULL;
        priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
        priv->ieee80211->set_chan = rtl8192_set_chan;
        priv->ieee80211->link_change = rtl8192_link_change;
@@ -2160,15 +2273,15 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
        priv->ieee80211->tx_headroom = TX_PACKET_SHIFT_BYTES;
        priv->ieee80211->qos_support = 1;
 
-       //added by WB
        priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
        priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
        priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
-       //added by david
+
        priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8192;
-       priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xUsb;
+       priv->ieee80211->GetHalfNmodeSupportByAPsHandler =
+               GetHalfNmodeSupportByAPs819xUsb;
        priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
-       //added by amy
+
        priv->ieee80211->InitialGainHandler = InitialGain819xUsb;
        priv->card_type = USB;
 #ifdef TO_DO_LIST
@@ -2182,30 +2295,55 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
        priv->EarlyRxThreshold = 7;
        priv->enable_gpio0 = 0;
        priv->TransmitConfig =
-               (TCR_MXDMA_2048<<TCR_MXDMA_OFFSET)|  // Max DMA Burst Size per Tx DMA Burst, 7: reserved.
-               (priv->ShortRetryLimit<<TCR_SRL_OFFSET)|        // Short retry limit
-               (priv->LongRetryLimit<<TCR_LRL_OFFSET) |        // Long retry limit
-               (false ? TCR_SAT : 0);  // FALSE: HW provides PLCP length and LENGEXT, TRUE: SW provides them
+               /* Max DMA Burst Size per Tx DMA Burst, 7: reserved. */
+               (TCR_MXDMA_2048 << TCR_MXDMA_OFFSET)      |
+               /* Short retry limit */
+               (priv->ShortRetryLimit << TCR_SRL_OFFSET) |
+               /* Long retry limit */
+               (priv->LongRetryLimit << TCR_LRL_OFFSET)  |
+               /* FALSE: HW provides PLCP length and LENGEXT
+                * TRUE: SW provides them
+                */
+               (false ? TCR_SAT : 0);
 #ifdef TO_DO_LIST
        if (Adapter->bInHctTest)
-               pHalData->ReceiveConfig =       pHalData->CSMethod |
-                                               RCR_AMF | RCR_ADF |     //accept management/data
-                                               //guangan200710
-                                               RCR_ACF |       //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
-                                               RCR_AB | RCR_AM | RCR_APM |             //accept BC/MC/UC
-                                               RCR_AICV | RCR_ACRC32 |                 //accept ICV/CRC error packet
-                                               ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
-                                               (pHalData->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
-                                               (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt : 0);
+               pHalData->ReceiveConfig =
+                       pHalData->CSMethod |
+                       /* accept management/data */
+                       RCR_AMF | RCR_ADF |
+                       /* accept control frame for SW
+                        * AP needs PS-poll
+                        */
+                       RCR_ACF |
+                       /* accept BC/MC/UC */
+                       RCR_AB | RCR_AM | RCR_APM |
+                       /* accept ICV/CRC error
+                        * packet
+                        */
+                       RCR_AICV | RCR_ACRC32 |
+                       /* Max DMA Burst Size per Tx
+                        * DMA Burst, 7: unlimited.
+                        */
+                       ((u32)7 << RCR_MXDMA_OFFSET) |
+                       /* Rx FIFO Threshold,
+                        * 7: No Rx threshold.
+                        */
+                       (pHalData->EarlyRxThreshold << RCR_FIFO_OFFSET) |
+                       (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt : 0);
        else
 
 #endif
        priv->ReceiveConfig     =
-               RCR_AMF | RCR_ADF |             //accept management/data
-               RCR_ACF |                       //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
-               RCR_AB | RCR_AM | RCR_APM |     //accept BC/MC/UC
-               ((u32)7<<RCR_MXDMA_OFFSET)| // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
-               (priv->EarlyRxThreshold<<RX_FIFO_THRESHOLD_SHIFT) | // Rx FIFO Threshold, 7: No Rx threshold.
+               /* accept management/data */
+               RCR_AMF | RCR_ADF |
+               /* accept control frame for SW AP needs PS-poll */
+               RCR_ACF |
+               /* accept BC/MC/UC */
+               RCR_AB | RCR_AM | RCR_APM |
+               /* Max DMA Burst Size per Rx DMA Burst, 7: unlimited. */
+               ((u32)7 << RCR_MXDMA_OFFSET) |
+               /* Rx FIFO Threshold, 7: No Rx threshold. */
+               (priv->EarlyRxThreshold << RX_FIFO_THRESHOLD_SHIFT) |
                (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT : 0);
 
        priv->AcmControl = 0;
@@ -2225,11 +2363,11 @@ static void rtl8192_init_priv_variable(struct net_device *dev)
        priv->rf_set_chan = rtl8192_phy_SwChnl;
 }
 
-//init lock here
+/* init lock here */
 static void rtl8192_init_priv_lock(struct r8192_priv *priv)
 {
        spin_lock_init(&priv->tx_lock);
-       spin_lock_init(&priv->irq_lock);//added by thomas
+       spin_lock_init(&priv->irq_lock);
        sema_init(&priv->wx_sem, 1);
        sema_init(&priv->rf_sem, 1);
        mutex_init(&priv->mutex);
@@ -2238,7 +2376,7 @@ static void rtl8192_init_priv_lock(struct r8192_priv *priv)
 static void rtl819x_watchdog_wqcallback(struct work_struct *work);
 
 static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
-//init tasklet and wait_queue here. only 2.6 above kernel is considered
+/* init tasklet and wait_queue here. only 2.6 above kernel is considered */
 #define DRV_NAME "wlan0"
 static void rtl8192_init_priv_task(struct net_device *dev)
 {
@@ -2248,11 +2386,16 @@ static void rtl8192_init_priv_task(struct net_device *dev)
 
        INIT_WORK(&priv->reset_wq, rtl8192_restart);
 
-       INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
-       INIT_DELAYED_WORK(&priv->txpower_tracking_wq,  dm_txpower_trackingcallback);
-       INIT_DELAYED_WORK(&priv->rfpath_check_wq,  dm_rf_pathcheck_workitemcallback);
-       INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
-       INIT_DELAYED_WORK(&priv->initialgain_operate_wq, InitialGainOperateWorkItemCallBack);
+       INIT_DELAYED_WORK(&priv->watch_dog_wq,
+                         rtl819x_watchdog_wqcallback);
+       INIT_DELAYED_WORK(&priv->txpower_tracking_wq,
+                         dm_txpower_trackingcallback);
+       INIT_DELAYED_WORK(&priv->rfpath_check_wq,
+                         dm_rf_pathcheck_workitemcallback);
+       INIT_DELAYED_WORK(&priv->update_beacon_wq,
+                         rtl8192_update_beacon);
+       INIT_DELAYED_WORK(&priv->initialgain_operate_wq,
+                         InitialGainOperateWorkItemCallBack);
        INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
 
        tasklet_init(&priv->irq_rx_tasklet,
@@ -2264,15 +2407,21 @@ static void rtl8192_get_eeprom_size(struct net_device *dev)
 {
        u16 curCR = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
+
        RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
        read_nic_word_E(dev, EPROM_CMD, &curCR);
-       RT_TRACE(COMP_EPROM, "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
-       //whether need I consider BIT5?
-       priv->epromtype = (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
-       RT_TRACE(COMP_EPROM, "<===========%s(), epromtype:%d\n", __func__, priv->epromtype);
+       RT_TRACE(COMP_EPROM,
+                "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
+       /* whether need I consider BIT(5?) */
+       priv->epromtype =
+               (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
+       RT_TRACE(COMP_EPROM,
+                "<===========%s(), epromtype:%d\n", __func__, priv->epromtype);
 }
 
-//used to swap endian. as ntohl & htonl are not necessary to swap endian, so use this instead.
+/* used to swap endian. as ntohl & htonl are not necessary
+ * to swap endian, so use this instead.
+ */
 static inline u16 endian_swap(u16 *data)
 {
        u16 tmp = *data;
@@ -2287,24 +2436,27 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
        u16 tmpValue = 0;
        int i;
+
        RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
-       wEPROM_ID = eprom_read(dev, 0); //first read EEPROM ID out;
+       wEPROM_ID = eprom_read(dev, 0); /* first read EEPROM ID out; */
        RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
 
-       if (wEPROM_ID != RTL8190_EEPROM_ID) {
-               RT_TRACE(COMP_ERR, "EEPROM ID is invalid(is 0x%x(should be 0x%x)\n", wEPROM_ID, RTL8190_EEPROM_ID);
-       } else {
+       if (wEPROM_ID != RTL8190_EEPROM_ID)
+               RT_TRACE(COMP_ERR,
+                        "EEPROM ID is invalid(is 0x%x(should be 0x%x)\n",
+                        wEPROM_ID, RTL8190_EEPROM_ID);
+       else
                bLoad_From_EEPOM = true;
-       }
 
        if (bLoad_From_EEPOM) {
-               tmpValue = eprom_read(dev, EEPROM_VID>>1);
+               tmpValue = eprom_read(dev, EEPROM_VID >> 1);
                priv->eeprom_vid = endian_swap(&tmpValue);
-               priv->eeprom_pid = eprom_read(dev, EEPROM_PID>>1);
-               tmpValue = eprom_read(dev, EEPROM_ChannelPlan>>1);
-               priv->eeprom_ChannelPlan = (tmpValue & 0xff00)>>8;
+               priv->eeprom_pid = eprom_read(dev, EEPROM_PID >> 1);
+               tmpValue = eprom_read(dev, EEPROM_ChannelPlan >> 1);
+               priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8;
                priv->btxpowerdata_readfromEEPORM = true;
-               priv->eeprom_CustomerID = eprom_read(dev, (EEPROM_Customer_ID>>1)) >>8;
+               priv->eeprom_CustomerID =
+                       eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
        } else {
                priv->eeprom_vid = 0;
                priv->eeprom_pid = 0;
@@ -2312,75 +2464,81 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
                priv->eeprom_ChannelPlan = 0;
                priv->eeprom_CustomerID = 0;
        }
-       RT_TRACE(COMP_EPROM, "vid:0x%4x, pid:0x%4x, CustomID:0x%2x, ChanPlan:0x%x\n", priv->eeprom_vid, priv->eeprom_pid, priv->eeprom_CustomerID, priv->eeprom_ChannelPlan);
-       //set channelplan from eeprom
+       RT_TRACE(COMP_EPROM,
+                "vid:0x%4x, pid:0x%4x, CustomID:0x%2x, ChanPlan:0x%x\n",
+                priv->eeprom_vid, priv->eeprom_pid, priv->eeprom_CustomerID,
+                priv->eeprom_ChannelPlan);
+       /* set channelplan from eeprom */
        priv->ChannelPlan = priv->eeprom_ChannelPlan;
        if (bLoad_From_EEPOM) {
                int i;
+
                for (i = 0; i < 6; i += 2) {
                        u16 tmp = 0;
-                       tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i)>>1));
+
+                       tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
                        *(u16 *)(&dev->dev_addr[i]) = tmp;
                }
        } else {
                memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
-               //should I set IDR0 here?
+               /* should I set IDR0 here? */
        }
        RT_TRACE(COMP_EPROM, "MAC addr:%pM\n", dev->dev_addr);
-       priv->rf_type = RTL819X_DEFAULT_RF_TYPE; //default 1T2R
+       priv->rf_type = RTL819X_DEFAULT_RF_TYPE; /* default 1T2R */
        priv->rf_chip = RF_8256;
 
        if (priv->card_8192_version == (u8)VERSION_819xU_A) {
-               //read Tx power gain offset of legacy OFDM to HT rate
+               /* read Tx power gain offset of legacy OFDM to HT rate */
                if (bLoad_From_EEPOM)
-                       priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff>>1))&0xff00) >> 8;
+                       priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff >> 1)) & 0xff00) >> 8;
                else
                        priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
                RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
-               //read ThermalMeter from EEPROM
+               /* read ThermalMeter from EEPROM */
                if (bLoad_From_EEPOM)
-                       priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter>>1))&0x00ff);
+                       priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter >> 1)) & 0x00ff);
                else
                        priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
                RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
-               //vivi, for tx power track
-               priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
-               //read antenna tx power offset of B/C/D to A from EEPROM
+               /* for tx power track */
+               priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
+               /* read antenna tx power offset of B/C/D to A from EEPROM */
                if (bLoad_From_EEPOM)
-                       priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff>>1))&0x0f00)>>8;
+                       priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff >> 1)) & 0x0f00) >> 8;
                else
                        priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
                RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
-               // Read CrystalCap from EEPROM
+               /* Read CrystalCap from EEPROM */
                if (bLoad_From_EEPOM)
-                       priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap>>1))&0x0f);
+                       priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap >> 1)) & 0x0f);
                else
                        priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
                RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
-               //get per-channel Tx power level
+               /* get per-channel Tx power level */
                if (bLoad_From_EEPOM)
-                       priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver>>1))&0xff00)>>8;
+                       priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1)) & 0xff00) >> 8;
                else
                        priv->EEPROM_Def_Ver = 1;
                RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
                if (priv->EEPROM_Def_Ver == 0) { /* old eeprom definition */
                        int i;
+
                        if (bLoad_From_EEPOM)
-                               priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK>>1))&0xff) >> 8;
+                               priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1)) & 0xff) >> 8;
                        else
                                priv->EEPROMTxPowerLevelCCK = 0x10;
                        RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
                        for (i = 0; i < 3; i++) {
                                if (bLoad_From_EEPOM) {
-                                       tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G+i)>>1);
-                                       if (((EEPROM_TxPwIndex_OFDM_24G+i) % 2) == 0)
+                                       tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1);
+                                       if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0)
                                                tmpValue = tmpValue & 0x00ff;
                                        else
                                                tmpValue = (tmpValue & 0xff00) >> 8;
                                } else {
                                        tmpValue = 0x10;
                                }
-                               priv->EEPROMTxPowerLevelOFDM24G[i] = (u8) tmpValue;
+                               priv->EEPROMTxPowerLevelOFDM24G[i] = (u8)tmpValue;
                                RT_TRACE(COMP_EPROM, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK);
                        }
                } else if (priv->EEPROM_Def_Ver == 1) {
@@ -2394,7 +2552,7 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
                        priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
 
                        if (bLoad_From_EEPOM)
-                               tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2)>>1);
+                               tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1);
                        else
                                tmpValue = 0x1010;
                        *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
@@ -2405,14 +2563,13 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
                                tmpValue = 0x1010;
                        *((u16 *)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
                        if (bLoad_From_EEPOM)
-                               tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1+2)>>1);
+                               tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1 + 2) >> 1);
                        else
                                tmpValue = 0x10;
                        priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue;
-               }//endif EEPROM_Def_Ver == 1
+               } /* endif EEPROM_Def_Ver == 1 */
 
-               //update HAL variables
-               //
+               /* update HAL variables */
                for (i = 0; i < 14; i++) {
                        if (i <= 3)
                                priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
@@ -2440,18 +2597,20 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
                        }
                }
                priv->TxPowerDiff = priv->EEPROMPwDiff;
-               // Antenna B gain offset to antenna A, bit0~3
+               /* Antenna B gain offset to antenna A, bit0~3 */
                priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
-               // Antenna C gain offset to antenna A, bit4~7
-               priv->AntennaTxPwDiff[1] = (priv->EEPROMTxPowerDiff & 0xf0)>>4;
-               // CrystalCap, bit12~15
+               /* Antenna C gain offset to antenna A, bit4~7 */
+               priv->AntennaTxPwDiff[1] =
+                       (priv->EEPROMTxPowerDiff & 0xf0) >> 4;
+               /* CrystalCap, bit12~15 */
                priv->CrystalCap = priv->EEPROMCrystalCap;
-               // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
-               // 92U does not enable TX power tracking.
+               /* ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
+                * 92U does not enable TX power tracking.
+                */
                priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
-       }//end if VersionID == VERSION_819xU_A
+       } /* end if VersionID == VERSION_819xU_A */
 
-       //added by vivi, for dlink led, 20080416
+       /* for dlink led */
        switch (priv->eeprom_CustomerID) {
        case EEPROM_CID_RUNTOP:
                priv->CustomerID = RT_CID_819x_RUNTOP;
@@ -2483,16 +2642,15 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
        }
 
 
-       if (priv->rf_type == RF_1T2R) {
+       if (priv->rf_type == RF_1T2R)
                RT_TRACE(COMP_EPROM, "\n1T2R config\n");
-       } else {
+       else
                RT_TRACE(COMP_EPROM, "\n2T4R config\n");
-       }
 
-       // 2008/01/16 MH We can only know RF type in the function. So we have to init
-       // DIG RATR table again.
+       /* We can only know RF type in the function. So we have to init
+        * DIG RATR table again.
+        */
        init_rate_adaptive(dev);
-       //we need init DIG RATR table here again.
 
        RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__);
 }
@@ -2500,8 +2658,10 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
 static short rtl8192_get_channel_map(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
+
        if (priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN) {
-               netdev_err(dev, "rtl8180_init: Error channel plan! Set to default.\n");
+               netdev_err(dev,
+                          "rtl8180_init: Error channel plan! Set to default.\n");
                priv->ChannelPlan = 0;
        }
        RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan);
@@ -2521,11 +2681,13 @@ static short rtl8192_init(struct net_device *dev)
        {
                int i = 0;
                u8 queuetopipe[] = {3, 2, 1, 0, 4, 8, 7, 6, 5};
+
                memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
        }
 #else
        {
                u8 queuetopipe[] = {3, 2, 1, 0, 4, 4, 0, 4, 4};
+
                memcpy(priv->txqueue_to_outpipemap, queuetopipe, 9);
        }
 #endif
@@ -2561,8 +2723,7 @@ static void rtl8192_hwconfig(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
        u32 ratr_value = 0;
 
-       // Set RRSR, RATR, and BW_OPMODE registers
-       //
+       /* Set RRSR, RATR, and BW_OPMODE registers */
        switch (priv->ieee80211->mode) {
        case WIRELESS_MODE_B:
                regBwOpMode = BW_OPMODE_20MHZ;
@@ -2570,7 +2731,7 @@ static void rtl8192_hwconfig(struct net_device *dev)
                regRRSR = RATE_ALL_CCK;
                break;
        case WIRELESS_MODE_A:
-               regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
+               regBwOpMode = BW_OPMODE_5G | BW_OPMODE_20MHZ;
                regRATR = RATE_ALL_OFDM_AG;
                regRRSR = RATE_ALL_OFDM_AG;
                break;
@@ -2585,25 +2746,28 @@ static void rtl8192_hwconfig(struct net_device *dev)
                        regBwOpMode = BW_OPMODE_20MHZ;
                        regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                        regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
-               }
-               else
+               } else
 #endif
                {
                        regBwOpMode = BW_OPMODE_20MHZ;
-                       regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
+                       regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
+                                 RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
                        regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                }
                break;
        case WIRELESS_MODE_N_24G:
-               // It support CCK rate by default.
-               // CCK rate will be filtered out only when associated AP does not support it.
+               /* It support CCK rate by default. CCK rate will be filtered
+                * out only when associated AP does not support it.
+                */
                regBwOpMode = BW_OPMODE_20MHZ;
-               regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
+               regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
+                         RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
                regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
                break;
        case WIRELESS_MODE_N_5G:
                regBwOpMode = BW_OPMODE_5G;
-               regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
+               regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS |
+                         RATE_ALL_OFDM_2SS;
                regRRSR = RATE_ALL_OFDM_AG;
                break;
        }
@@ -2618,25 +2782,23 @@ static void rtl8192_hwconfig(struct net_device *dev)
        regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
        write_nic_dword(dev, RRSR, regRRSR);
 
-       //
-       // Set Retry Limit here
-       //
+       /* Set Retry Limit here */
        write_nic_word(dev, RETRY_LIMIT,
                       priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT |
                       priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
-       // Set Contention Window here
+       /* Set Contention Window here */
 
-       // Set Tx AGC
+       /* Set Tx AGC */
 
-       // Set Tx Antenna including Feedback control
+       /* Set Tx Antenna including Feedback control */
 
-       // Set Auto Rate fallback control
+       /* Set Auto Rate fallback control */
 
 
 }
 
 
-//InitializeAdapter and PhyCfg
+/* InitializeAdapter and PhyCfg */
 static bool rtl8192_adapter_start(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -2644,9 +2806,10 @@ static bool rtl8192_adapter_start(struct net_device *dev)
        bool init_status = true;
        u8 SECR_value = 0x0;
        u8 tmp;
+
        RT_TRACE(COMP_INIT, "====>%s()\n", __func__);
        priv->Rf_Mode = RF_OP_By_SW_3wire;
-       //for ASIC power on sequence
+       /* for ASIC power on sequence */
        write_nic_byte_E(dev, 0x5f, 0x80);
        mdelay(50);
        write_nic_byte_E(dev, 0x5f, 0xf0);
@@ -2655,66 +2818,74 @@ static bool rtl8192_adapter_start(struct net_device *dev)
        write_nic_byte(dev, 0x17, 0x37);
        mdelay(10);
        priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
-       //config CPUReset Register
-       //Firmware Reset or not?
+       /* config CPUReset Register */
+       /* Firmware Reset or not? */
        read_nic_dword(dev, CPU_GEN, &dwRegRead);
        if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
-               dwRegRead |= CPU_GEN_SYSTEM_RESET; //do nothing here?
+               dwRegRead |= CPU_GEN_SYSTEM_RESET; /* do nothing here? */
        else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
                dwRegRead |= CPU_GEN_FIRMWARE_RESET;
        else
-               RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __func__,   priv->pFirmware->firmware_status);
+               RT_TRACE(COMP_ERR,
+                        "ERROR in %s(): undefined firmware state(%d)\n",
+                        __func__,   priv->pFirmware->firmware_status);
 
        write_nic_dword(dev, CPU_GEN, dwRegRead);
-       //config BB.
+       /* config BB. */
        rtl8192_BBConfig(dev);
 
-       //Loopback mode or not
+       /* Loopback mode or not */
        priv->LoopbackMode = RTL819xU_NO_LOOPBACK;
 
        read_nic_dword(dev, CPU_GEN, &dwRegRead);
        if (priv->LoopbackMode == RTL819xU_NO_LOOPBACK)
-               dwRegRead = (dwRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET;
+               dwRegRead = (dwRegRead & CPU_GEN_NO_LOOPBACK_MSK) |
+                           CPU_GEN_NO_LOOPBACK_SET;
        else if (priv->LoopbackMode == RTL819xU_MAC_LOOPBACK)
                dwRegRead |= CPU_CCK_LOOPBACK;
        else
-               RT_TRACE(COMP_ERR, "Serious error in %s(): wrong loopback mode setting(%d)\n", __func__,  priv->LoopbackMode);
+               RT_TRACE(COMP_ERR,
+                        "Serious error in %s(): wrong loopback mode setting(%d)\n",
+                        __func__,  priv->LoopbackMode);
 
        write_nic_dword(dev, CPU_GEN, dwRegRead);
 
-       //after reset cpu, we need wait for a seconds to write in register.
+       /* after reset cpu, we need wait for a seconds to write in register. */
        udelay(500);
 
-       //xiong add for new bitfile:usb suspend reset pin set to 1. //do we need?
+       /* add for new bitfile:usb suspend reset pin set to 1. Do we need? */
        read_nic_byte_E(dev, 0x5f, &tmp);
-       write_nic_byte_E(dev, 0x5f, tmp|0x20);
+       write_nic_byte_E(dev, 0x5f, tmp | 0x20);
 
-       //Set Hardware
+       /* Set Hardware */
        rtl8192_hwconfig(dev);
 
-       //turn on Tx/Rx
-       write_nic_byte(dev, CMDR, CR_RE|CR_TE);
+       /* turn on Tx/Rx */
+       write_nic_byte(dev, CMDR, CR_RE | CR_TE);
 
-       //set IDR0 here
+       /* set IDR0 here */
        write_nic_dword(dev, MAC0, ((u32 *)dev->dev_addr)[0]);
        write_nic_word(dev, MAC4, ((u16 *)(dev->dev_addr + 4))[0]);
 
-       //set RCR
+       /* set RCR */
        write_nic_dword(dev, RCR, priv->ReceiveConfig);
 
-       //Initialize Number of Reserved Pages in Firmware Queue
-       write_nic_dword(dev, RQPN1,  NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
-                       NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
-                       NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
-                       NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
-       write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |
-                       NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
-       write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
-                       NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT);
-       write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
-
-       //Set AckTimeout
-       // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
+       /* Initialize Number of Reserved Pages in Firmware Queue */
+       write_nic_dword(dev, RQPN1,
+               NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
+               NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
+               NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
+               NUM_OF_PAGE_IN_FW_QUEUE_VO << RSVD_FW_QUEUE_PAGE_VO_SHIFT);
+       write_nic_dword(dev, RQPN2,
+               NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |
+               NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
+       write_nic_dword(dev, RQPN3,
+               APPLIED_RESERVED_QUEUE_IN_FW |
+               NUM_OF_PAGE_IN_FW_QUEUE_BCN << RSVD_FW_QUEUE_PAGE_BCN_SHIFT);
+       write_nic_dword(dev, RATR0 + 4 * 7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
+
+       /* Set AckTimeout */
+       /* TODO: (it value is only for FPGA version). need to be changed!! */
        write_nic_byte(dev, ACK_TIMEOUT, 0x30);
 
        if (priv->ResetProgress == RESET_TYPE_NORESET)
@@ -2727,58 +2898,77 @@ static bool rtl8192_adapter_start(struct net_device *dev)
                write_nic_byte(dev, SECR, SECR_value);
        }
 
-       //Beacon related
+       /* Beacon related */
        write_nic_word(dev, ATIMWND, 2);
        write_nic_word(dev, BCN_INTERVAL, 100);
 
 #define DEFAULT_EDCA 0x005e4332
        {
                int i;
+
                for (i = 0; i < QOS_QUEUE_NUM; i++)
                        write_nic_dword(dev, WDCAPARA_ADD[i], DEFAULT_EDCA);
        }
 
        rtl8192_phy_configmac(dev);
 
-       if (priv->card_8192_version == (u8) VERSION_819xU_A) {
+       if (priv->card_8192_version == (u8)VERSION_819xU_A) {
                rtl8192_phy_getTxPower(dev);
                rtl8192_phy_setTxPower(dev, priv->chan);
        }
 
-       //Firmware download
+       /* Firmware download */
        init_status = init_firmware(dev);
        if (!init_status) {
-               RT_TRACE(COMP_ERR, "ERR!!! %s(): Firmware download is failed\n", __func__);
+               RT_TRACE(COMP_ERR, "ERR!!! %s(): Firmware download is failed\n",
+                        __func__);
                return init_status;
        }
        RT_TRACE(COMP_INIT, "%s():after firmware download\n", __func__);
-       //
+
 #ifdef TO_DO_LIST
        if (Adapter->ResetProgress == RESET_TYPE_NORESET) {
                if (pMgntInfo->RegRfOff) { /* User disable RF via registry. */
-                       RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
+                       RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
+                                ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
                        MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
-                       // Those actions will be discard in MgntActSet_RF_State because of the same state
+                       /* Those actions will be discard in MgntActSet_RF_State
+                        * because of the same state
+                        */
                        for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
-                               PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
-               } else if (pMgntInfo->RfOffReason > RF_CHANGE_BY_PS) { /* H/W or S/W RF OFF before sleep. */
-                       RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n", pMgntInfo->RfOffReason));
-                       MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
+                               PHY_SetRFReg(Adapter,
+                                            (RF90_RADIO_PATH_E)eRFPath,
+                                            0x4, 0xC00, 0x0);
+               } else if (pMgntInfo->RfOffReason > RF_CHANGE_BY_PS) {
+                       /* H/W or S/W RF OFF before sleep. */
+                       RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
+                                ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n",
+                                 pMgntInfo->RfOffReason));
+                       MgntActSet_RF_State(Adapter,
+                                           eRfOff,
+                                           pMgntInfo->RfOffReason);
                } else {
                        pHalData->eRFPowerState = eRfOn;
                        pMgntInfo->RfOffReason = 0;
-                       RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): RF is on ----------\n"));
+                       RT_TRACE((COMP_INIT | COMP_RF), DBG_LOUD,
+                                ("InitializeAdapter819xUsb(): RF is on ----------\n"));
                }
        } else {
                if (pHalData->eRFPowerState == eRfOff) {
-                       MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
-                       // Those actions will be discard in MgntActSet_RF_State because of the same state
+                       MgntActSet_RF_State(Adapter,
+                                           eRfOff,
+                                           pMgntInfo->RfOffReason);
+                       /* Those actions will be discard in MgntActSet_RF_State
+                        * because of the same state
+                        */
                        for (eRFPath = 0; eRFPath < pHalData->NumTotalRFPath; eRFPath++)
-                               PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
+                               PHY_SetRFReg(Adapter,
+                                            (RF90_RADIO_PATH_E)eRFPath,
+                                            0x4, 0xC00, 0x0);
                }
        }
 #endif
-       //config RF.
+       /* config RF. */
        if (priv->ResetProgress == RESET_TYPE_NORESET) {
                rtl8192_phy_RFConfig(dev);
                RT_TRACE(COMP_INIT, "%s():after phy RF config\n", __func__);
@@ -2786,7 +2976,7 @@ static bool rtl8192_adapter_start(struct net_device *dev)
 
 
        if (priv->ieee80211->FwRWRF)
-               // We can force firmware to do RF-R/W
+               /* We can force firmware to do RF-R/W */
                priv->Rf_Mode = RF_OP_By_FW;
        else
                priv->Rf_Mode = RF_OP_By_SW_3wire;
@@ -2798,8 +2988,9 @@ static bool rtl8192_adapter_start(struct net_device *dev)
        rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
 
        if (priv->ResetProgress == RESET_TYPE_NORESET) {
-               //if D or C cut
+               /* if D or C cut */
                u8 tmpvalue;
+
                read_nic_byte(dev, 0x301, &tmpvalue);
                if (tmpvalue == 0x03) {
                        priv->bDcut = true;
@@ -2812,28 +3003,36 @@ static bool rtl8192_adapter_start(struct net_device *dev)
 
                if (priv->bDcut) {
                        u32 i, TempCCk;
-                       u32 tmpRegA = rtl8192_QueryBBReg(dev, rOFDM0_XATxIQImbalance, bMaskDWord);
+                       u32 tmpRegA = rtl8192_QueryBBReg(dev,
+                                                        rOFDM0_XATxIQImbalance,
+                                                        bMaskDWord);
+
                        for (i = 0; i < TxBBGainTableLength; i++) {
                                if (tmpRegA == priv->txbbgain_table[i].txbbgain_value) {
                                        priv->rfa_txpowertrackingindex = (u8)i;
-                                       priv->rfa_txpowertrackingindex_real = (u8)i;
-                                       priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex;
+                                       priv->rfa_txpowertrackingindex_real =
+                                               (u8)i;
+                                       priv->rfa_txpowertracking_default =
+                                               priv->rfa_txpowertrackingindex;
                                        break;
                                }
                        }
 
-                       TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
+                       TempCCk = rtl8192_QueryBBReg(dev,
+                                                    rCCK0_TxFilter1,
+                                                    bMaskByte2);
 
                        for (i = 0; i < CCKTxBBGainTableLength; i++) {
 
                                if (TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) {
-                                       priv->cck_present_attentuation_20Mdefault = (u8) i;
+                                       priv->cck_present_attentuation_20Mdefault = (u8)i;
                                        break;
                                }
                        }
                        priv->cck_present_attentuation_40Mdefault = 0;
                        priv->cck_present_attentuation_difference = 0;
-                       priv->cck_present_attentuation = priv->cck_present_attentuation_20Mdefault;
+                       priv->cck_present_attentuation =
+                               priv->cck_present_attentuation_20Mdefault;
 
                }
        }
@@ -2863,8 +3062,11 @@ static bool HalTxCheckStuck819xUsb(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
        u16             RegTxCounter;
        bool            bStuck = false;
+
        read_nic_word(dev, 0x128, &RegTxCounter);
-       RT_TRACE(COMP_RESET, "%s():RegTxCounter is %d,TxCounter is %d\n", __func__, RegTxCounter, priv->TxCounter);
+       RT_TRACE(COMP_RESET,
+                "%s():RegTxCounter is %d,TxCounter is %d\n", __func__,
+                RegTxCounter, priv->TxCounter);
        if (priv->TxCounter == RegTxCounter)
                bStuck = true;
 
@@ -2883,9 +3085,7 @@ static RESET_TYPE TxCheckStuck(struct net_device *dev)
        u8                      QueueID;
        bool                    bCheckFwTxCnt = false;
 
-       //
-       // Decide such threshold according to current power save mode
-       //
+       /* Decide such threshold according to current power save mode */
 
        for (QueueID = 0; QueueID <= BEACON_QUEUE; QueueID++) {
                if (QueueID == TXCMD_QUEUE)
@@ -2897,7 +3097,8 @@ static RESET_TYPE TxCheckStuck(struct net_device *dev)
        }
        if (bCheckFwTxCnt) {
                if (HalTxCheckStuck819xUsb(dev)) {
-                       RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
+                       RT_TRACE(COMP_RESET,
+                                "TxCheckStuck(): Fw indicates no Tx condition!\n");
                        return RESET_TYPE_SILENT;
                }
        }
@@ -2910,32 +3111,36 @@ static bool HalRxCheckStuck819xUsb(struct net_device *dev)
        struct r8192_priv *priv = ieee80211_priv(dev);
        bool bStuck = false;
        static u8       rx_chk_cnt;
+
        read_nic_word(dev, 0x130, &RegRxCounter);
-       RT_TRACE(COMP_RESET, "%s(): RegRxCounter is %d,RxCounter is %d\n", __func__, RegRxCounter, priv->RxCounter);
-       // If rssi is small, we should check rx for long time because of bad rx.
-       // or maybe it will continuous silent reset every 2 seconds.
+       RT_TRACE(COMP_RESET,
+                "%s(): RegRxCounter is %d,RxCounter is %d\n", __func__,
+                RegRxCounter, priv->RxCounter);
+       /* If rssi is small, we should check rx for long time because of bad rx.
+        * or maybe it will continuous silent reset every 2 seconds.
+        */
        rx_chk_cnt++;
-       if (priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5)) {
-               rx_chk_cnt = 0; //high rssi, check rx stuck right now.
-       } else if (priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
+       if (priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High + 5)) {
+               rx_chk_cnt = 0; /* high rssi, check rx stuck right now. */
+       } else if (priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High + 5) &&
                   ((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_40M) ||
                    (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb >= RateAdaptiveTH_Low_20M))) {
                if (rx_chk_cnt < 2)
                        return bStuck;
-               else
-                       rx_chk_cnt = 0;
+
+               rx_chk_cnt = 0;
        } else if (((priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_40M) ||
                    (priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 && priv->undecorated_smoothed_pwdb < RateAdaptiveTH_Low_20M)) &&
                     priv->undecorated_smoothed_pwdb >= VeryLowRSSI) {
                if (rx_chk_cnt < 4)
                        return bStuck;
-               else
-                       rx_chk_cnt = 0;
+
+               rx_chk_cnt = 0;
        } else {
                if (rx_chk_cnt < 8)
                        return bStuck;
-               else
-                       rx_chk_cnt = 0;
+
+               rx_chk_cnt = 0;
        }
 
        if (priv->RxCounter == RegRxCounter)
@@ -2965,17 +3170,18 @@ static RESET_TYPE RxCheckStuck(struct net_device *dev)
 
 
 /**
-*      This function is called by Checkforhang to check whether we should ask OS to reset driver
-*
-*      \param pAdapter The adapter context for this miniport
-*
-*      Note:NIC with USB interface sholud not call this function because we cannot scan descriptor
-*      to judge whether there is tx stuck.
-*      Note: This function may be required to be rewrite for Vista OS.
-*      <<<Assumption: Tx spinlock has been acquired >>>
-*
-*      8185 and 8185b does not implement this function. This is added by Emily at 2006.11.24
-*/
+ * This function is called by Checkforhang to check whether we should
+ * ask OS to reset driver
+ *
+ * \param pAdapter     The adapter context for this miniport
+ *
+ * Note:NIC with USB interface sholud not call this function because we
+ * cannot scan descriptor to judge whether there is tx stuck.
+ * Note: This function may be required to be rewrite for Vista OS.
+ * <<<Assumption: Tx spinlock has been acquired >>>
+ *
+ * 8185 and 8185b does not implement this function.
+ */
 static RESET_TYPE rtl819x_ifcheck_resetornot(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -2988,19 +3194,25 @@ static RESET_TYPE rtl819x_ifcheck_resetornot(struct net_device *dev)
        TxResetType = TxCheckStuck(dev);
        if (rfState != eRfOff ||
            (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) {
-               // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
-               // in turned off state. Driver should check whether Rx stuck and do silent reset. And
-               // if driver is in firmware download failure status, driver should initialize RF in the following
-               // silent reset procedure Emily, 2008.01.21
-
-               // Driver should not check RX stuck in IBSS mode because it is required to
-               // set Check BSSID in order to send beacon, however, if check BSSID is
-               // set, STA cannot hear any packet at all. Emily, 2008.04.12
+               /* If driver is in the status of firmware download failure,
+                * driver skips RF initialization and RF is in turned off
+                * state. Driver should check whether Rx stuck and do silent
+                * reset. And if driver is in firmware download failure status,
+                * driver should initialize RF in the following silent reset
+                * procedure
+                *
+                * Driver should not check RX stuck in IBSS mode because it is
+                * required to set Check BSSID in order to send beacon,
+                * however, if check BSSID is set, STA cannot hear any packet
+                * at all.
+                */
                RxResetType = RxCheckStuck(dev);
        }
-       if (TxResetType == RESET_TYPE_NORMAL || RxResetType == RESET_TYPE_NORMAL) {
+       if (TxResetType == RESET_TYPE_NORMAL ||
+           RxResetType == RESET_TYPE_NORMAL) {
                return RESET_TYPE_NORMAL;
-       } else if (TxResetType == RESET_TYPE_SILENT || RxResetType == RESET_TYPE_SILENT) {
+       } else if (TxResetType == RESET_TYPE_SILENT ||
+                  RxResetType == RESET_TYPE_SILENT) {
                RT_TRACE(COMP_RESET, "%s():silent reset\n", __func__);
                return RESET_TYPE_SILENT;
        } else {
@@ -3029,7 +3241,7 @@ static void CamRestoreAllEntry(struct net_device *dev)
        static u8       CAM_CONST_BROAD[] = {
                0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 
-       RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
+       RT_TRACE(COMP_SEC, "CamRestoreAllEntry:\n");
 
 
        if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40) ||
@@ -3085,12 +3297,11 @@ static void CamRestoreAllEntry(struct net_device *dev)
                               CAM_CONST_ADDR[0], 0, NULL);
        }
 }
-//////////////////////////////////////////////////////////////
-// This function is used to fix Tx/Rx stop bug temporarily.
-// This function will do "system reset" to NIC when Tx or Rx is stuck.
-// The method checking Tx/Rx stuck of this function is supported by FW,
-// which reports Tx and Rx counter to register 0x128 and 0x130.
-//////////////////////////////////////////////////////////////
+/* This function is used to fix Tx/Rx stop bug temporarily.
+ * This function will do "system reset" to NIC when Tx or Rx is stuck.
+ * The method checking Tx/Rx stuck of this function is supported by FW,
+ * which reports Tx and Rx counter to register 0x128 and 0x130.
+ */
 static void rtl819x_ifsilentreset(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -3099,24 +3310,28 @@ static void rtl819x_ifsilentreset(struct net_device *dev)
        struct ieee80211_device *ieee = priv->ieee80211;
 
 
-       // 2007.07.20. If we need to check CCK stop, please uncomment this line.
-       //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
+       /* If we need to check CCK stop, please uncomment this line. */
+       /* bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter); */
 
        if (priv->ResetProgress == RESET_TYPE_NORESET) {
 RESET_START:
 
-               RT_TRACE(COMP_RESET, "=========>Reset progress!! \n");
+               RT_TRACE(COMP_RESET, "=========>Reset progress!!\n");
 
-               // Set the variable for reset.
+               /* Set the variable for reset. */
                priv->ResetProgress = RESET_TYPE_SILENT;
                down(&priv->wx_sem);
                if (priv->up == 0) {
-                       RT_TRACE(COMP_ERR, "%s():the driver is not up! return\n", __func__);
+                       RT_TRACE(COMP_ERR,
+                                "%s():the driver is not up! return\n",
+                                __func__);
                        up(&priv->wx_sem);
                        return;
                }
                priv->up = 0;
-               RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n", __func__);
+               RT_TRACE(COMP_RESET,
+                        "%s():======>start to down the driver\n",
+                        __func__);
 
                rtl8192_rtx_disable(dev);
                rtl8192_cancel_deferred_work(priv);
@@ -3138,28 +3353,40 @@ RESET_START:
                        ieee80211_softmac_stop_protocol(priv->ieee80211);
                }
                up(&priv->wx_sem);
-               RT_TRACE(COMP_RESET, "%s():<==========down process is finished\n", __func__);
-               RT_TRACE(COMP_RESET, "%s():===========>start up the driver\n", __func__);
+               RT_TRACE(COMP_RESET,
+                        "%s():<==========down process is finished\n",
+                        __func__);
+               RT_TRACE(COMP_RESET,
+                        "%s():===========>start up the driver\n",
+                        __func__);
                reset_status = _rtl8192_up(dev);
 
-               RT_TRACE(COMP_RESET, "%s():<===========up process is finished\n", __func__);
+               RT_TRACE(COMP_RESET,
+                        "%s():<===========up process is finished\n",
+                        __func__);
                if (reset_status == -EAGAIN) {
                        if (reset_times < 3) {
                                reset_times++;
                                goto RESET_START;
                        } else {
-                               RT_TRACE(COMP_ERR, " ERR!!! %s():  Reset Failed!!\n", __func__);
+                               RT_TRACE(COMP_ERR,
+                                        " ERR!!! %s():  Reset Failed!!\n",
+                                        __func__);
                        }
                }
                ieee->is_silent_reset = 1;
                EnableHWSecurityConfig8192(dev);
-               if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA) {
-                       ieee->set_chan(ieee->dev, ieee->current_network.channel);
+               if (ieee->state == IEEE80211_LINKED &&
+                   ieee->iw_mode == IW_MODE_INFRA) {
+                       ieee->set_chan(ieee->dev,
+                                      ieee->current_network.channel);
 
                        queue_work(ieee->wq, &ieee->associate_complete_wq);
 
-               } else if (ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC) {
-                       ieee->set_chan(ieee->dev, ieee->current_network.channel);
+               } else if (ieee->state == IEEE80211_LINKED &&
+                          ieee->iw_mode == IW_MODE_ADHOC) {
+                       ieee->set_chan(ieee->dev,
+                                      ieee->current_network.channel);
                        ieee->link_change(ieee->dev);
 
                        ieee80211_start_send_beacons(ieee);
@@ -3177,9 +3404,11 @@ RESET_START:
                priv->bForcedSilentReset = false;
                priv->bResetInProgress = false;
 
-               // For test --> force write UFWP.
+               /* For test --> force write UFWP. */
                write_nic_byte(dev, UFWP, 1);
-               RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
+               RT_TRACE(COMP_RESET,
+                        "Reset finished!! ====>[%d]\n",
+                        priv->reset_count);
        }
 }
 
@@ -3192,9 +3421,12 @@ static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
        *TotalRxBcnNum = 0;
        *TotalRxDataNum = 0;
 
-       SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
-       priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
-       priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
+       SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++) %
+                   (priv->ieee80211->LinkDetectInfo.SlotNum);
+       priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] =
+               priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
+       priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] =
+               priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
        for (i = 0; i < priv->ieee80211->LinkDetectInfo.SlotNum; i++) {
                *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
                *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
@@ -3204,8 +3436,10 @@ static void rtl819x_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum,
 
 static void rtl819x_watchdog_wqcallback(struct work_struct *work)
 {
-       struct delayed_work *dwork = container_of(work, struct delayed_work, work);
-       struct r8192_priv *priv = container_of(dwork, struct r8192_priv, watch_dog_wq);
+       struct delayed_work *dwork = container_of(work,
+                                                 struct delayed_work, work);
+       struct r8192_priv *priv = container_of(dwork,
+                                              struct r8192_priv, watch_dog_wq);
        struct net_device *dev = priv->ieee80211->dev;
        struct ieee80211_device *ieee = priv->ieee80211;
        RESET_TYPE      ResetType = RESET_TYPE_NORESET;
@@ -3218,45 +3452,55 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
                return;
        hal_dm_watchdog(dev);
 
-       //to get busy traffic condition
+       /* to get busy traffic condition */
        if (ieee->state == IEEE80211_LINKED) {
                if (ieee->LinkDetectInfo.NumRxOkInPeriod > 666 ||
-                   ieee->LinkDetectInfo.NumTxOkInPeriod > 666 ) {
+                   ieee->LinkDetectInfo.NumTxOkInPeriod > 666) {
                        bBusyTraffic = true;
                }
                ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
                ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
                ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
        }
-       //added by amy for AP roaming
-       if (priv->ieee80211->state == IEEE80211_LINKED && priv->ieee80211->iw_mode == IW_MODE_INFRA) {
+       /* for AP roaming */
+       if (priv->ieee80211->state == IEEE80211_LINKED &&
+           priv->ieee80211->iw_mode == IW_MODE_INFRA) {
 
                rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
-               if ((TotalRxBcnNum+TotalRxDataNum) == 0) {
+               if ((TotalRxBcnNum + TotalRxDataNum) == 0) {
 #ifdef TODO
                        if (rfState == eRfOff)
                                RT_TRACE(COMP_ERR, "========>%s()\n", __func__);
 #endif
-                       netdev_dbg(dev, "===>%s(): AP is power off, connect another one\n", __func__);
+                       netdev_dbg(dev,
+                                  "===>%s(): AP is power off, connect another one\n",
+                                  __func__);
                        priv->ieee80211->state = IEEE80211_ASSOCIATING;
                        notify_wx_assoc_event(priv->ieee80211);
-                       RemovePeerTS(priv->ieee80211, priv->ieee80211->current_network.bssid);
+                       RemovePeerTS(priv->ieee80211,
+                                    priv->ieee80211->current_network.bssid);
                        priv->ieee80211->link_change(dev);
-                       queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
+                       queue_work(priv->ieee80211->wq,
+                                  &priv->ieee80211->associate_procedure_wq);
 
                }
        }
        priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod = 0;
        priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod = 0;
-       //check if reset the driver
+       /* check if reset the driver */
        if (check_reset_cnt++ >= 3) {
                ResetType = rtl819x_ifcheck_resetornot(dev);
                check_reset_cnt = 3;
        }
+       /* This is control by OID set in Pomelo */
        if ((priv->force_reset) || (priv->ResetProgress == RESET_TYPE_NORESET &&
            (priv->bForcedSilentReset ||
-           (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_SILENT)))) { /* This is control by OID set in Pomelo */
-               RT_TRACE(COMP_RESET, "%s():priv->force_reset is %d,priv->ResetProgress is %d, priv->bForcedSilentReset is %d,priv->bDisableNormalResetCheck is %d,ResetType is %d\n", __func__, priv->force_reset, priv->ResetProgress, priv->bForcedSilentReset, priv->bDisableNormalResetCheck, ResetType);
+           (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_SILENT)))) {
+               RT_TRACE(COMP_RESET,
+                        "%s():priv->force_reset is %d,priv->ResetProgress is %d, priv->bForcedSilentReset is %d,priv->bDisableNormalResetCheck is %d,ResetType is %d\n",
+                        __func__, priv->force_reset, priv->ResetProgress,
+                        priv->bForcedSilentReset,
+                        priv->bDisableNormalResetCheck, ResetType);
                rtl819x_ifsilentreset(dev);
        }
        priv->force_reset = false;
@@ -3268,20 +3512,24 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
 
 static void watch_dog_timer_callback(unsigned long data)
 {
-       struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
+       struct r8192_priv *priv = ieee80211_priv((struct net_device *)data);
+
        queue_delayed_work(priv->priv_wq, &priv->watch_dog_wq, 0);
-       mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
+       mod_timer(&priv->watch_dog_timer,
+                 jiffies + msecs_to_jiffies(IEEE80211_WATCH_DOG_TIME));
 }
 static int _rtl8192_up(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
        int init_status = 0;
+
        priv->up = 1;
        priv->ieee80211->ieee_up = 1;
        RT_TRACE(COMP_INIT, "Bringing up iface");
        init_status = rtl8192_adapter_start(dev);
        if (!init_status) {
-               RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization failed!\n", __func__);
+               RT_TRACE(COMP_ERR, "ERR!!! %s(): initialization failed!\n",
+                        __func__);
                priv->up = priv->ieee80211->ieee_up = 0;
                return -EAGAIN;
        }
@@ -3290,7 +3538,7 @@ static int _rtl8192_up(struct net_device *dev)
        if (priv->ieee80211->state != IEEE80211_LINKED)
                ieee80211_softmac_start_protocol(priv->ieee80211);
        ieee80211_reset_queue(priv->ieee80211);
-       watch_dog_timer_callback((unsigned long) dev);
+       watch_dog_timer_callback((unsigned long)dev);
        if (!netif_queue_stopped(dev))
                netif_start_queue(dev);
        else
@@ -3304,6 +3552,7 @@ static int rtl8192_open(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
        int ret;
+
        down(&priv->wx_sem);
        ret = rtl8192_up(dev);
        up(&priv->wx_sem);
@@ -3364,14 +3613,17 @@ int rtl8192_down(struct net_device *dev)
        for (i = 0; i < MAX_QUEUE_SIZE; i++)
                skb_queue_purge(&priv->ieee80211->skb_drv_aggQ[i]);
 
-       //as cancel_delayed_work will del work->timer, so if work is not defined as struct delayed_work, it will corrupt
+       /* as cancel_delayed_work will del work->timer, so if work is not
+        * defined as struct delayed_work, it will corrupt
+        */
        rtl8192_cancel_deferred_work(priv);
        deinit_hal_dm(dev);
        del_timer_sync(&priv->watch_dog_timer);
 
 
        ieee80211_softmac_stop_protocol(priv->ieee80211);
-       memset(&priv->ieee80211->current_network, 0, offsetof(struct ieee80211_network, list));
+       memset(&priv->ieee80211->current_network, 0,
+              offsetof(struct ieee80211_network, list));
        RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__);
 
        return 0;
@@ -3382,6 +3634,7 @@ void rtl8192_commit(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
        int reset_status = 0;
+
        if (priv->up == 0)
                return;
        priv->up = 0;
@@ -3398,7 +3651,8 @@ void rtl8192_commit(struct net_device *dev)
 
 static void rtl8192_restart(struct work_struct *work)
 {
-       struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
+       struct r8192_priv *priv = container_of(work, struct r8192_priv,
+                                              reset_wq);
        struct net_device *dev = priv->ieee80211->dev;
 
        down(&priv->wx_sem);
@@ -3430,7 +3684,7 @@ static int r8192_set_mac_adr(struct net_device *dev, void *mac)
 
        down(&priv->wx_sem);
 
-       memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
+       ether_addr_copy(dev->dev_addr, addr->sa_data);
 
        schedule_work(&priv->reset_wq);
        up(&priv->wx_sem);
@@ -3466,7 +3720,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
        switch (cmd) {
        case RTL_IOCTL_WPA_SUPPLICANT:
-               //parse here for HW security
+               /* parse here for HW security */
                if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) {
                        if (ipw->u.crypt.set_tx) {
                                if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) {
@@ -3485,11 +3739,22 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                                if (ieee->pairwise_key_type) {
                                        memcpy((u8 *)key, ipw->u.crypt.key, 16);
                                        EnableHWSecurityConfig8192(dev);
-                                       //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
-                                       //added by WB.
-                                       setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
+                                       /* We fill both index entry and 4th
+                                        * entry for pairwise key as in IPW
+                                        * interface, adhoc will only get here,
+                                        * so we need index entry for its
+                                        * default key serching!
+                                        */
+                                       setKey(dev, 4, ipw->u.crypt.idx,
+                                              ieee->pairwise_key_type,
+                                              (u8 *)ieee->ap_mac_addr,
+                                              0, key);
                                        if (ieee->auth_mode != 2)
-                                               setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8 *)ieee->ap_mac_addr, 0, key);
+                                               setKey(dev, ipw->u.crypt.idx,
+                                                      ipw->u.crypt.idx,
+                                                      ieee->pairwise_key_type,
+                                                      (u8 *)ieee->ap_mac_addr,
+                                                      0, key);
                                }
                        } else {
                                memcpy((u8 *)key, ipw->u.crypt.key, 16);
@@ -3508,15 +3773,21 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
                                if (ieee->group_key_type) {
                                        setKey(dev, ipw->u.crypt.idx,
-                                              ipw->u.crypt.idx,                //KeyIndex
-                                              ieee->group_key_type,    //KeyType
-                                              broadcast_addr,  //MacAddr
-                                              0,               //DefaultKey
-                                              key);            //KeyContent
+                                              /* KeyIndex */
+                                              ipw->u.crypt.idx,
+                                              /* KeyType */
+                                              ieee->group_key_type,
+                                              /* MacAddr */
+                                              broadcast_addr,
+                                              /* DefaultKey */
+                                              0,
+                                              /* KeyContent */
+                                              key);
                                }
                        }
                }
-               ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
+               ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211,
+                                                    &wrq->u.data);
                break;
 
        default:
@@ -3536,107 +3807,111 @@ static u8 HwRateToMRate90(bool bIsHT, u8 rate)
 
        if (!bIsHT) {
                switch (rate) {
-                       case DESC90_RATE1M:
-                               ret_rate = MGN_1M;
-                               break;
-                       case DESC90_RATE2M:
-                               ret_rate = MGN_2M;
-                               break;
-                       case DESC90_RATE5_5M:
-                               ret_rate = MGN_5_5M;
-                               break;
-                       case DESC90_RATE11M:
-                               ret_rate = MGN_11M;
-                               break;
-                       case DESC90_RATE6M:
-                               ret_rate = MGN_6M;
-                               break;
-                       case DESC90_RATE9M:
-                               ret_rate = MGN_9M;
-                               break;
-                       case DESC90_RATE12M:
-                               ret_rate = MGN_12M;
-                               break;
-                       case DESC90_RATE18M:
-                               ret_rate = MGN_18M;
-                               break;
-                       case DESC90_RATE24M:
-                               ret_rate = MGN_24M;
-                               break;
-                       case DESC90_RATE36M:
-                               ret_rate = MGN_36M;
-                               break;
-                       case DESC90_RATE48M:
-                               ret_rate = MGN_48M;
-                               break;
-                       case DESC90_RATE54M:
-                               ret_rate = MGN_54M;
-                               break;
+               case DESC90_RATE1M:
+                       ret_rate = MGN_1M;
+                       break;
+               case DESC90_RATE2M:
+                       ret_rate = MGN_2M;
+                       break;
+               case DESC90_RATE5_5M:
+                       ret_rate = MGN_5_5M;
+                       break;
+               case DESC90_RATE11M:
+                       ret_rate = MGN_11M;
+                       break;
+               case DESC90_RATE6M:
+                       ret_rate = MGN_6M;
+                       break;
+               case DESC90_RATE9M:
+                       ret_rate = MGN_9M;
+                       break;
+               case DESC90_RATE12M:
+                       ret_rate = MGN_12M;
+                       break;
+               case DESC90_RATE18M:
+                       ret_rate = MGN_18M;
+                       break;
+               case DESC90_RATE24M:
+                       ret_rate = MGN_24M;
+                       break;
+               case DESC90_RATE36M:
+                       ret_rate = MGN_36M;
+                       break;
+               case DESC90_RATE48M:
+                       ret_rate = MGN_48M;
+                       break;
+               case DESC90_RATE54M:
+                       ret_rate = MGN_54M;
+                       break;
 
-                       default:
-                               ret_rate = 0xff;
-                               RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
-                               break;
+               default:
+                       ret_rate = 0xff;
+                       RT_TRACE(COMP_RECV,
+                                "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",
+                                rate, bIsHT);
+                       break;
                }
 
        } else {
                switch (rate) {
-                       case DESC90_RATEMCS0:
-                               ret_rate = MGN_MCS0;
-                               break;
-                       case DESC90_RATEMCS1:
-                               ret_rate = MGN_MCS1;
-                               break;
-                       case DESC90_RATEMCS2:
-                               ret_rate = MGN_MCS2;
-                               break;
-                       case DESC90_RATEMCS3:
-                               ret_rate = MGN_MCS3;
-                               break;
-                       case DESC90_RATEMCS4:
-                               ret_rate = MGN_MCS4;
-                               break;
-                       case DESC90_RATEMCS5:
-                               ret_rate = MGN_MCS5;
-                               break;
-                       case DESC90_RATEMCS6:
-                               ret_rate = MGN_MCS6;
-                               break;
-                       case DESC90_RATEMCS7:
-                               ret_rate = MGN_MCS7;
-                               break;
-                       case DESC90_RATEMCS8:
-                               ret_rate = MGN_MCS8;
-                               break;
-                       case DESC90_RATEMCS9:
-                               ret_rate = MGN_MCS9;
-                               break;
-                       case DESC90_RATEMCS10:
-                               ret_rate = MGN_MCS10;
-                               break;
-                       case DESC90_RATEMCS11:
-                               ret_rate = MGN_MCS11;
-                               break;
-                       case DESC90_RATEMCS12:
-                               ret_rate = MGN_MCS12;
-                               break;
-                       case DESC90_RATEMCS13:
-                               ret_rate = MGN_MCS13;
-                               break;
-                       case DESC90_RATEMCS14:
-                               ret_rate = MGN_MCS14;
-                               break;
-                       case DESC90_RATEMCS15:
-                               ret_rate = MGN_MCS15;
-                               break;
-                       case DESC90_RATEMCS32:
-                               ret_rate = 0x80|0x20;
-                               break;
+               case DESC90_RATEMCS0:
+                       ret_rate = MGN_MCS0;
+                       break;
+               case DESC90_RATEMCS1:
+                       ret_rate = MGN_MCS1;
+                       break;
+               case DESC90_RATEMCS2:
+                       ret_rate = MGN_MCS2;
+                       break;
+               case DESC90_RATEMCS3:
+                       ret_rate = MGN_MCS3;
+                       break;
+               case DESC90_RATEMCS4:
+                       ret_rate = MGN_MCS4;
+                       break;
+               case DESC90_RATEMCS5:
+                       ret_rate = MGN_MCS5;
+                       break;
+               case DESC90_RATEMCS6:
+                       ret_rate = MGN_MCS6;
+                       break;
+               case DESC90_RATEMCS7:
+                       ret_rate = MGN_MCS7;
+                       break;
+               case DESC90_RATEMCS8:
+                       ret_rate = MGN_MCS8;
+                       break;
+               case DESC90_RATEMCS9:
+                       ret_rate = MGN_MCS9;
+                       break;
+               case DESC90_RATEMCS10:
+                       ret_rate = MGN_MCS10;
+                       break;
+               case DESC90_RATEMCS11:
+                       ret_rate = MGN_MCS11;
+                       break;
+               case DESC90_RATEMCS12:
+                       ret_rate = MGN_MCS12;
+                       break;
+               case DESC90_RATEMCS13:
+                       ret_rate = MGN_MCS13;
+                       break;
+               case DESC90_RATEMCS14:
+                       ret_rate = MGN_MCS14;
+                       break;
+               case DESC90_RATEMCS15:
+                       ret_rate = MGN_MCS15;
+                       break;
+               case DESC90_RATEMCS32:
+                       ret_rate = 0x80 | 0x20;
+                       break;
 
-                       default:
-                               ret_rate = 0xff;
-                               RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
-                               break;
+               default:
+                       ret_rate = 0xff;
+                       RT_TRACE(COMP_RECV,
+                                "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",
+                                rate, bIsHT);
+                       break;
                }
        }
 
@@ -3672,13 +3947,12 @@ static void UpdateRxPktTimeStamp8190(struct net_device *dev,
        }
 }
 
-//by amy 080606
-
-static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
+/* 0-100 index. */
+static long rtl819x_translate_todbm(u8 signal_strength_index)
 {
-       long    signal_power; // in dBm.
+       long    signal_power; /* in dBm. */
 
-       // Translate to dBm (x=0.5y-95).
+       /* Translate to dBm (x=0.5y-95). */
        signal_power = (long)((signal_strength_index + 1) >> 1);
        signal_power -= 95;
 
@@ -3686,10 +3960,11 @@ static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index.
 }
 
 
-/* 2008/01/22 MH We can not declare RSSI/EVM total value of sliding window to
-    be a local static. Otherwise, it may increase when we return from S3/S4. The
-    value will be kept in memory or disk. Declare the value in the adaptor
-    and it will be reinitialized when returned from S3/S4. */
+/* We can not declare RSSI/EVM total value of sliding window to
+ * be a local static. Otherwise, it may increase when we return from S3/S4. The
+ * value will be kept in memory or disk. Declare the value in the adaptor
+ * and it will be reinitialized when returned from S3/S4.
+ */
 static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
                                    struct ieee80211_rx_stats *pprevious_stats,
                                    struct ieee80211_rx_stats *pcurrent_stats)
@@ -3701,23 +3976,24 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
        static u32 slide_evm_index, slide_evm_statistics;
        static u32 last_rssi, last_evm;
 
-       static u32 slide_beacon_adc_pwdb_index, slide_beacon_adc_pwdb_statistics;
+       static u32 slide_beacon_adc_pwdb_index;
+       static u32 slide_beacon_adc_pwdb_statistics;
        static u32 last_beacon_adc_pwdb;
 
        struct rtl_80211_hdr_3addr *hdr;
        u16 sc;
        unsigned int frag, seq;
+
        hdr = (struct rtl_80211_hdr_3addr *)buffer;
        sc = le16_to_cpu(hdr->seq_ctl);
        frag = WLAN_GET_SEQ_FRAG(sc);
        seq = WLAN_GET_SEQ_SEQ(sc);
-       //cosa add 04292008 to record the sequence number
+       /* to record the sequence number */
        pcurrent_stats->Seq_Num = seq;
-       //
-       // Check whether we should take the previous packet into accounting
-       //
+
+       /* Check whether we should take the previous packet into accounting */
        if (!pprevious_stats->bIsAMPDU) {
-               // if previous packet is not aggregated packet
+               /* if previous packet is not aggregated packet */
                bcheck = true;
        }
 
@@ -3728,17 +4004,17 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
        }
        priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
 
-       priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
+       priv->stats.slide_signal_strength[slide_rssi_index++] =
+               pprevious_stats->SignalStrength;
        if (slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
                slide_rssi_index = 0;
 
-       // <1> Showed on UI for user, in dbm
-       tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
+       /* <1> Showed on UI for user, in dbm */
+       tmp_val = priv->stats.slide_rssi_total / slide_rssi_statistics;
        priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
        pcurrent_stats->rssi = priv->stats.signal_strength;
-       //
-       // If the previous packet does not match the criteria, neglect it
-       //
+
+       /* If the previous packet does not match the criteria, neglect it */
        if (!pprevious_stats->bPacketMatchBSSID) {
                if (!pprevious_stats->bToSelfBA)
                        return;
@@ -3748,44 +4024,47 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
                return;
 
 
-       //rtl8190_process_cck_rxpathsel(priv,pprevious_stats);//only rtl8190 supported
+       /* only rtl8190 supported
+        * rtl8190_process_cck_rxpathsel(priv,pprevious_stats);
+        */
 
-       //
-       // Check RSSI
-       //
+       /* Check RSSI */
        priv->stats.num_process_phyinfo++;
 
        /* record the general signal strength to the sliding window. */
 
 
-       // <2> Showed on UI for engineering
-       // hardware does not provide rssi information for each rf path in CCK
-       if (!pprevious_stats->bIsCCK && (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA)) {
+       /* <2> Showed on UI for engineering
+        * hardware does not provide rssi information for each rf path in CCK
+        */
+       if (!pprevious_stats->bIsCCK &&
+           (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA)) {
                for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++) {
-                       if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
+                       if (!rtl8192_phy_CheckIsLegalRFPath(
+                                       priv->ieee80211->dev, rfpath))
                                continue;
 
-                       //Fixed by Jacken 2008-03-20
                        if (priv->stats.rx_rssi_percentage[rfpath] == 0)
-                               priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
+                               priv->stats.rx_rssi_percentage[rfpath] =
+                                       pprevious_stats->RxMIMOSignalStrength[rfpath];
                        if (pprevious_stats->RxMIMOSignalStrength[rfpath]  > priv->stats.rx_rssi_percentage[rfpath]) {
                                priv->stats.rx_rssi_percentage[rfpath] =
-                                       ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
-                                        (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
+                                       ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) +
+                                        (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor);
                                priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath]  + 1;
                        } else {
                                priv->stats.rx_rssi_percentage[rfpath] =
-                                       ((priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
-                                        (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
+                                       ((priv->stats.rx_rssi_percentage[rfpath] * (Rx_Smooth_Factor - 1)) +
+                                        (pprevious_stats->RxMIMOSignalStrength[rfpath])) / (Rx_Smooth_Factor);
                        }
-                       RT_TRACE(COMP_DBG, "priv->stats.rx_rssi_percentage[rfPath]  = %d \n", priv->stats.rx_rssi_percentage[rfpath]);
+                       RT_TRACE(COMP_DBG,
+                                "priv->stats.rx_rssi_percentage[rfPath]  = %d\n",
+                                priv->stats.rx_rssi_percentage[rfpath]);
                }
        }
 
 
-       //
-       // Check PWDB.
-       //
+       /* Check PWDB. */
        RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
                 pprevious_stats->bIsCCK ? "CCK" : "OFDM",
                 pprevious_stats->RxPWDBAll);
@@ -3802,7 +4081,7 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
                slide_beacon_adc_pwdb_index++;
                if (slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
                        slide_beacon_adc_pwdb_index = 0;
-               pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
+               pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total / slide_beacon_adc_pwdb_statistics;
                if (pprevious_stats->RxPWDBAll >= 3)
                        pprevious_stats->RxPWDBAll -= 3;
        }
@@ -3812,56 +4091,67 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
                 pprevious_stats->RxPWDBAll);
 
 
-       if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
-               if (priv->undecorated_smoothed_pwdb < 0)        /* initialize */
-                       priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
+       if (pprevious_stats->bPacketToSelf ||
+           pprevious_stats->bPacketBeacon ||
+           pprevious_stats->bToSelfBA) {
+               if (priv->undecorated_smoothed_pwdb < 0)
+                       /* initialize */
+                       priv->undecorated_smoothed_pwdb =
+                               pprevious_stats->RxPWDBAll;
                if (pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) {
                        priv->undecorated_smoothed_pwdb =
-                               (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
-                                (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
+                               (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) +
+                                (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor);
                        priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
                } else {
                        priv->undecorated_smoothed_pwdb =
-                               (((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
-                                (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
+                               (((priv->undecorated_smoothed_pwdb) * (Rx_Smooth_Factor - 1)) +
+                                (pprevious_stats->RxPWDBAll)) / (Rx_Smooth_Factor);
                }
 
        }
 
-       //
-       // Check EVM
-       //
+       /* Check EVM */
        /* record the general EVM to the sliding window. */
        if (pprevious_stats->SignalQuality) {
-               if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
+               if (pprevious_stats->bPacketToSelf ||
+                   pprevious_stats->bPacketBeacon ||
+                   pprevious_stats->bToSelfBA) {
                        if (slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX) {
                                slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
                                last_evm = priv->stats.slide_evm[slide_evm_index];
                                priv->stats.slide_evm_total -= last_evm;
                        }
 
-                       priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
+                       priv->stats.slide_evm_total +=
+                               pprevious_stats->SignalQuality;
 
-                       priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
+                       priv->stats.slide_evm[slide_evm_index++] =
+                               pprevious_stats->SignalQuality;
                        if (slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
                                slide_evm_index = 0;
 
-                       // <1> Showed on UI for user, in percentage.
-                       tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
+                       /* <1> Showed on UI for user, in percentage. */
+                       tmp_val = priv->stats.slide_evm_total /
+                                 slide_evm_statistics;
                        priv->stats.signal_quality = tmp_val;
-                       //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
+                       /* Showed on UI for user in Windows Vista,
+                        * for Link quality.
+                        */
                        priv->stats.last_signal_strength_inpercent = tmp_val;
                }
 
-               // <2> Showed on UI for engineering
-               if (pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) {
+               /* <2> Showed on UI for engineering */
+               if (pprevious_stats->bPacketToSelf ||
+                   pprevious_stats->bPacketBeacon ||
+                   pprevious_stats->bToSelfBA) {
                        for (nspatial_stream = 0; nspatial_stream < 2; nspatial_stream++) { /* 2 spatial stream */
                                if (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1) {
                                        if (priv->stats.rx_evm_percentage[nspatial_stream] == 0) /* initialize */
                                                priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
                                        priv->stats.rx_evm_percentage[nspatial_stream] =
-                                               ((priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
-                                                (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
+                                               ((priv->stats.rx_evm_percentage[nspatial_stream] * (Rx_Smooth_Factor - 1)) +
+                                                (pprevious_stats->RxMIMOSignalQuality[nspatial_stream] * 1)) / (Rx_Smooth_Factor);
                                }
                        }
                }
@@ -3880,11 +4170,6 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
  * Output:             NONE
  *
  * Return:             0-100 percentage
- *
- * Revised History:
- *     When            Who             Remark
- *     05/26/2008      amy             Create Version 0 porting from windows code.
- *
  *---------------------------------------------------------------------------*/
 static u8 rtl819x_query_rxpwrpercentage(char antpower)
 {
@@ -3913,16 +4198,12 @@ static u8 rtl819x_evm_dbtopercentage(char value)
                ret_val = 100;
        return ret_val;
 }
-//
-//     Description:
-//     We want good-looking for signal strength/quality
-//     2007/7/19 01:09, by cosa.
-//
+/* We want good-looking for signal strength/quality */
 static long rtl819x_signal_scale_mapping(long currsig)
 {
        long retsig;
 
-       // Step 1. Scale mapping.
+       /* Step 1. Scale mapping. */
        if (currsig >= 61 && currsig <= 100)
                retsig = 90 + ((currsig - 60) / 4);
        else if (currsig >= 41 && currsig <= 60)
@@ -3975,24 +4256,25 @@ static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
        phy_sts_ofdm_819xusb_t *pofdm_buf;
        phy_sts_cck_819xusb_t   *pcck_buf;
        phy_ofdm_rx_status_rxsc_sgien_exintfflag *prxsc;
-       u8                              *prxpkt;
-       u8                              i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
-       char                            rx_pwr[4], rx_pwr_all = 0;
-       char                            rx_snrX, rx_evmX;
-       u8                              evm, pwdb_all;
-       u32                             RSSI, total_rssi = 0;
-       u8                              is_cck_rate = 0;
-       u8                              rf_rx_num = 0;
-       u8                              sq;
+       u8      *prxpkt;
+       u8      i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
+       char    rx_pwr[4], rx_pwr_all = 0;
+       char    rx_snrX, rx_evmX;
+       u8      evm, pwdb_all;
+       u32     RSSI, total_rssi = 0;
+       u8      is_cck_rate = 0;
+       u8      rf_rx_num = 0;
+       u8      sq;
 
 
        priv->stats.numqry_phystatus++;
 
        is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
 
-       // Record it for next packet processing
+       /* Record it for next packet processing */
        memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
-       pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
+       pstats->bPacketMatchBSSID =
+               precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
        pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
        pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;
        pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
@@ -4013,13 +4295,11 @@ static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
        precord_stats->RxMIMOSignalQuality[1] = -1;
 
        if (is_cck_rate) {
-               //
-               // (1)Hardware does not provide RSSI for CCK
-               //
+               /* (1)Hardware does not provide RSSI for CCK */
 
-               //
-               // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
-               //
+               /* (2)PWDB, Average PWDB cacluated by hardware
+                * (for rate adaptive)
+                */
                u8 report;
 
                priv->stats.numqry_phystatusCCK++;
@@ -4028,9 +4308,6 @@ static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
                        report = pcck_buf->cck_agc_rpt & 0xc0;
                        report >>= 6;
                        switch (report) {
-                               //Fixed by Jacken from Bryant 2008-03-20
-                               //Original value is -38 , -26 , -14 , -2
-                               //Fixed value is -35 , -23 , -11 , 6
                        case 0x3:
                                rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
                                break;
@@ -4049,16 +4326,16 @@ static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
                        report >>= 5;
                        switch (report) {
                        case 0x3:
-                               rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
+                               rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
                                break;
                        case 0x2:
-                               rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
+                               rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
                                break;
                        case 0x1:
-                               rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
+                               rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
                                break;
                        case 0x0:
-                               rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
+                               rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f) << 1);
                                break;
                        }
                }
@@ -4067,9 +4344,7 @@ static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
                pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
                pstats->RecvSignalPower = pwdb_all;
 
-               //
-               // (3) Get Signal Quality (EVM)
-               //
+               /* (3) Get Signal Quality (EVM) */
 
                if (pstats->RxPWDBAll > 40) {
                        sq = 100;
@@ -4081,32 +4356,33 @@ static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
                        else if (pcck_buf->sq_rpt < 20)
                                sq = 100;
                        else
-                               sq = ((64-sq) * 100) / 44;
+                               sq = ((64 - sq) * 100) / 44;
                }
                pstats->SignalQuality = precord_stats->SignalQuality = sq;
-               pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
-               pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
+               pstats->RxMIMOSignalQuality[0] =
+                       precord_stats->RxMIMOSignalQuality[0] = sq;
+               pstats->RxMIMOSignalQuality[1] =
+                       precord_stats->RxMIMOSignalQuality[1] = -1;
 
        } else {
                priv->stats.numqry_phystatusHT++;
-               //
-               // (1)Get RSSI for HT rate
-               //
+
+               /* (1)Get RSSI for HT rate */
                for (i = RF90_PATH_A; i < priv->NumTotalRFPath; i++) {
-                       // 2008/01/30 MH we will judge RF RX path now.
+                       /* We will judge RF RX path now. */
                        if (priv->brfpath_rxenable[i])
                                rf_rx_num++;
                        else
                                continue;
 
-                       if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, i))
+                       if (!rtl8192_phy_CheckIsLegalRFPath(
+                                       priv->ieee80211->dev, i))
                                continue;
 
-                       //Fixed by Jacken from Bryant 2008-03-20
-                       //Original value is 106
-                       rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
+                       rx_pwr[i] =
+                               ((pofdm_buf->trsw_gain_X[i] & 0x3F) * 2) - 106;
 
-                       //Get Rx snr value in DB
+                       /* Get Rx snr value in DB */
                        tmp_rxsnr =     pofdm_buf->rxsnr_X[i];
                        rx_snrX = (char)(tmp_rxsnr);
                        rx_snrX /= 2;
@@ -4117,69 +4393,87 @@ static void rtl8192_query_rxphystatus(struct r8192_priv *priv,
                        total_rssi += RSSI;
 
                        /* Record Signal Strength for next packet */
-                       pstats->RxMIMOSignalStrength[i] = (u8) RSSI;
-                       precord_stats->RxMIMOSignalStrength[i] = (u8) RSSI;
+                       pstats->RxMIMOSignalStrength[i] = (u8)RSSI;
+                       precord_stats->RxMIMOSignalStrength[i] = (u8)RSSI;
                }
 
 
-               //
-               // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
-               //
-               //Fixed by Jacken from Bryant 2008-03-20
-               //Original value is 106
-               rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1)& 0x7f) -106;
+               /* (2)PWDB, Average PWDB cacluated by hardware
+                * (for rate adaptive)
+                */
+               rx_pwr_all = (((pofdm_buf->pwdb_all) >> 1) & 0x7f) - 106;
                pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
 
                pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
                pstats->RxPower = precord_stats->RxPower =  rx_pwr_all;
 
-               //
-               // (3)EVM of HT rate
-               //
+               /* (3)EVM of HT rate */
                if (pdrvinfo->RxHT && pdrvinfo->RxRate >= DESC90_RATEMCS8 &&
                    pdrvinfo->RxRate <= DESC90_RATEMCS15)
-                       max_spatial_stream = 2; //both spatial stream make sense
+                       /* both spatial stream make sense */
+                       max_spatial_stream = 2;
                else
-                       max_spatial_stream = 1; //only spatial stream 1 makes sense
+                       /* only spatial stream 1 makes sense */
+                       max_spatial_stream = 1;
 
                for (i = 0; i < max_spatial_stream; i++) {
                        tmp_rxevm =     pofdm_buf->rxevm_X[i];
                        rx_evmX = (char)(tmp_rxevm);
 
-                       // Do not use shift operation like "rx_evmX >>= 1" because the compiler of free build environment
-                       // will set the most significant bit to "zero" when doing shifting operation which may change a negative
-                       // value to positive one, then the dbm value (which is supposed to be negative)  is not correct anymore.
-                       rx_evmX /= 2;   //dbm
+                       /* Do not use shift operation like "rx_evmX >>= 1"
+                        * because the compiler of free build environment will
+                        * set the most significant bit to "zero" when doing
+                        * shifting operation which may change a negative value
+                        * to positive one, then the dbm value (which is
+                        * supposed to be negative) is not correct anymore.
+                        */
+                       rx_evmX /= 2;   /* dbm */
 
                        evm = rtl819x_evm_dbtopercentage(rx_evmX);
-                       if (i == 0) /* Fill value in RFD, Get the first spatial stream only */
-                               pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
-                       pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
+                       if (i == 0)
+                               /* Fill value in RFD, Get the first spatial
+                                * stream only
+                                */
+                               pstats->SignalQuality =
+                                       precord_stats->SignalQuality =
+                                       (u8)(evm & 0xff);
+                       pstats->RxMIMOSignalQuality[i] =
+                               precord_stats->RxMIMOSignalQuality[i] =
+                               (u8)(evm & 0xff);
                }
 
 
                /* record rx statistics for debug */
                rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
-               prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
+               prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)
+                       &rxsc_sgien_exflg;
                if (pdrvinfo->BW)       /* 40M channel */
-                       priv->stats.received_bwtype[1+prxsc->rxsc]++;
-               else                            //20M channel
+                       priv->stats.received_bwtype[1 + prxsc->rxsc]++;
+               else                    /* 20M channel */
                        priv->stats.received_bwtype[0]++;
        }
 
-       //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
-       //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
+       /* UI BSS List signal strength(in percentage), make it good looking,
+        * from 0~100. It is assigned to the BSS List in
+        * GetValueFromBeaconOrProbeRsp().
+        */
        if (is_cck_rate) {
-               pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));
+               pstats->SignalStrength =
+                       precord_stats->SignalStrength =
+                       (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));
        } else {
-               // We can judge RX path number now.
-               if (rf_rx_num != 0)
-                       pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi /= rf_rx_num)));
+               /* We can judge RX path number now. */
+               if (rf_rx_num != 0) {
+                       pstats->SignalStrength =
+                               precord_stats->SignalStrength =
+                               (u8)(rtl819x_signal_scale_mapping((long)(total_rssi /= rf_rx_num)));
+               }
        }
 }      /* QueryRxPhyStatus8190Pci */
 
-static void rtl8192_record_rxdesc_forlateruse(struct ieee80211_rx_stats *psrc_stats,
-                                             struct ieee80211_rx_stats *ptarget_stats)
+static void rtl8192_record_rxdesc_forlateruse(
+               struct ieee80211_rx_stats *psrc_stats,
+               struct ieee80211_rx_stats *ptarget_stats)
 {
        ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
        ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
@@ -4191,17 +4485,19 @@ static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
                                          struct ieee80211_rx_stats *pstats,
                                          rx_drvinfo_819x_usb  *pdrvinfo)
 {
-       // TODO: We must only check packet for current MAC address. Not finish
-       rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
+       /* TODO: We must only check packet for current MAC address.
+        * Not finish
+        */
+       struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
        struct net_device *dev = info->dev;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        bool bpacket_match_bssid, bpacket_toself;
        bool bPacketBeacon = false, bToSelfBA = false;
        static struct ieee80211_rx_stats  previous_stats;
-       struct rtl_80211_hdr_3addr *hdr;//by amy
+       struct rtl_80211_hdr_3addr *hdr;
        u16 fc, type;
 
-       // Get Signal Quality for only RX data queue (but not command queue)
+       /* Get Signal Quality for only RX data queue (but not command queue) */
 
        u8 *tmp_buf;
        u8  *praddr;
@@ -4218,7 +4514,8 @@ static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
        bpacket_match_bssid = (IEEE80211_FTYPE_CTL != type) &&
                               (eqMacAddr(priv->ieee80211->current_network.bssid,  (fc & IEEE80211_FCTL_TODS) ? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS) ? hdr->addr2 : hdr->addr3))
                               && (!pstats->bHwError) && (!pstats->bCRC) && (!pstats->bICV);
-       bpacket_toself =  bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
+       bpacket_toself =  bpacket_match_bssid &
+                         (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
 
        if (WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BEACON)
                bPacketBeacon = true;
@@ -4233,13 +4530,14 @@ static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
                priv->stats.numpacket_matchbssid++;
        if (bpacket_toself)
                priv->stats.numpacket_toself++;
-       //
-       // Process PHY information for previous packet (RSSI/PWDB/EVM)
-       //
-       // Because phy information is contained in the last packet of AMPDU only, so driver
-       // should process phy information of previous packet
+       /* Process PHY information for previous packet (RSSI/PWDB/EVM)
+        * Because phy information is contained in the last packet of AMPDU
+        * only, so driver should process phy information of previous packet
+        */
        rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
-       rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats, bpacket_match_bssid, bpacket_toself, bPacketBeacon, bToSelfBA);
+       rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats,
+                                 bpacket_match_bssid, bpacket_toself,
+                                 bPacketBeacon, bToSelfBA);
        rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
 
 }
@@ -4263,9 +4561,11 @@ UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
                                          struct ieee80211_rx_stats *stats)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
-       u32 rcvType = 1;   //0: Total, 1:OK, 2:CRC, 3:ICV
+       /* 0: Total, 1:OK, 2:CRC, 3:ICV */
+       u32 rcvType = 1;
        u32 rateIndex;
-       u32 preamble_guardinterval;  //1: short preamble/GI, 0: long preamble/GI
+       /* 1: short preamble/GI, 0: long preamble/GI */
+       u32 preamble_guardinterval;
 
 
        if (stats->bCRC)
@@ -4274,9 +4574,9 @@ UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
                rcvType = 3;
 
        if (stats->bShortPreamble)
-               preamble_guardinterval = 1;// short
+               preamble_guardinterval = 1; /* short */
        else
-               preamble_guardinterval = 0;// long
+               preamble_guardinterval = 0; /* long */
 
        switch (stats->rate) {
        /* CCK rate */
@@ -4371,7 +4671,7 @@ UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
                break;
        }
        priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
-       priv->stats.received_rate_histogram[0][rateIndex]++; //total
+       priv->stats.received_rate_histogram[0][rateIndex]++; /* total */
        priv->stats.received_rate_histogram[rcvType][rateIndex]++;
 }
 
@@ -4380,14 +4680,12 @@ static void query_rxdesc_status(struct sk_buff *skb,
                                struct ieee80211_rx_stats *stats,
                                bool bIsRxAggrSubframe)
 {
-       rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
+       struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
        struct net_device *dev = info->dev;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        rx_drvinfo_819x_usb  *driver_info = NULL;
 
-       //
-       //Get Rx Descriptor Information
-       //
+       /* Get Rx Descriptor Information */
        rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
 
        stats->Length = desc->Length;
@@ -4395,7 +4693,7 @@ static void query_rxdesc_status(struct sk_buff *skb,
        stats->RxBufShift = 0;
        stats->bICV = desc->ICV;
        stats->bCRC = desc->CRC32;
-       stats->bHwError = stats->bCRC|stats->bICV;
+       stats->bHwError = stats->bCRC | stats->bICV;
        /* RTL8190 set this bit to indicate that Hw does not decrypt packet */
        stats->Decrypted = !desc->SWDec;
 
@@ -4403,29 +4701,36 @@ static void query_rxdesc_status(struct sk_buff *skb,
            (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
                stats->bHwError = false;
        else
-               stats->bHwError = stats->bCRC|stats->bICV;
+               stats->bHwError = stats->bCRC | stats->bICV;
 
        if (stats->Length < 24 || stats->Length > MAX_8192U_RX_SIZE)
                stats->bHwError |= 1;
-       //
-       //Get Driver Info
-       //
-       // TODO: Need to verify it on FGPA platform
-       //Driver info are written to the RxBuffer following rx desc
+       /* Get Driver Info */
+       /* TODO: Need to verify it on FGPA platform
+        * Driver info are written to the RxBuffer following rx desc
+        */
        if (stats->RxDrvInfoSize != 0) {
-               driver_info = (rx_drvinfo_819x_usb *)(skb->data + sizeof(rx_desc_819x_usb) +
-                                                     stats->RxBufShift);
+               driver_info = (rx_drvinfo_819x_usb *)(
+                               skb->data
+                               + sizeof(rx_desc_819x_usb)
+                               + stats->RxBufShift
+                             );
                /* unit: 0.5M */
                /* TODO */
                if (!stats->bHwError) {
                        u8      ret_rate;
-                       ret_rate = HwRateToMRate90(driver_info->RxHT, driver_info->RxRate);
+
+                       ret_rate = HwRateToMRate90(driver_info->RxHT,
+                                                  driver_info->RxRate);
                        if (ret_rate == 0xff) {
-                               // Abnormal Case: Receive CRC OK packet with Rx descriptor indicating non supported rate.
-                               // Special Error Handling here, 2008.05.16, by Emily
+                               /* Abnormal Case: Receive CRC OK packet with Rx
+                                * descriptor indicating non supported rate.
+                                * Special Error Handling here
+                                */
 
                                stats->bHwError = 1;
-                               stats->rate = MGN_1M;   //Set 1M rate by default
+                               /* Set 1M rate by default */
+                               stats->rate = MGN_1M;
                        } else {
                                stats->rate = ret_rate;
                        }
@@ -4439,25 +4744,22 @@ static void query_rxdesc_status(struct sk_buff *skb,
                UpdateReceivedRateHistogramStatistics8190(dev, stats);
 
                stats->bIsAMPDU = (driver_info->PartAggr == 1);
-               stats->bFirstMPDU = (driver_info->PartAggr == 1) && (driver_info->FirstAGGR == 1);
+               stats->bFirstMPDU = (driver_info->PartAggr == 1) &&
+                                   (driver_info->FirstAGGR == 1);
                stats->TimeStampLow = driver_info->TSFL;
-               // xiong mask it, 070514
 
                UpdateRxPktTimeStamp8190(dev, stats);
 
-               //
-               // Rx A-MPDU
-               //
+               /* Rx A-MPDU */
                if (driver_info->FirstAGGR == 1 || driver_info->PartAggr == 1)
-                       RT_TRACE(COMP_RXDESC, "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
+                       RT_TRACE(COMP_RXDESC,
+                               "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
                                 driver_info->FirstAGGR, driver_info->PartAggr);
 
        }
 
        skb_pull(skb, sizeof(rx_desc_819x_usb));
-       //
-       // Get Total offset of MPDU Frame Body
-       //
+       /* Get Total offset of MPDU Frame Body */
        if ((stats->RxBufShift + stats->RxDrvInfoSize) > 0) {
                stats->bShift = 1;
                skb_pull(skb, stats->RxBufShift + stats->RxDrvInfoSize);
@@ -4471,12 +4773,12 @@ static void query_rxdesc_status(struct sk_buff *skb,
 
 static void rtl8192_rx_nomal(struct sk_buff *skb)
 {
-       rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
+       struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
        struct net_device *dev = info->dev;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct ieee80211_rx_stats stats = {
                .signal = 0,
-               .noise = -98,
+               .noise = 0x100 - 98,
                .rate = 0,
                .freq = IEEE80211_24GHZ_BAND,
        };
@@ -4497,9 +4799,9 @@ static void rtl8192_rx_nomal(struct sk_buff *skb)
                ieee80211_hdr = (struct rtl_80211_hdr_1addr *)skb->data;
                unicast_packet = false;
                if (is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
-                       //TODO
+                       /* TODO */
                } else if (is_multicast_ether_addr(ieee80211_hdr->addr1)) {
-                       //TODO
+                       /* TODO */
                } else {
                        /* unicast packet */
                        unicast_packet = true;
@@ -4520,28 +4822,30 @@ static void rtl8192_rx_nomal(struct sk_buff *skb)
 
 }
 
-static void rtl819xusb_process_received_packet(struct net_device *dev,
-                                              struct ieee80211_rx_stats *pstats)
+static void rtl819xusb_process_received_packet(
+               struct net_device *dev,
+               struct ieee80211_rx_stats *pstats)
 {
        u8      *frame;
        u16     frame_len = 0;
        struct r8192_priv *priv = ieee80211_priv(dev);
 
-       // Get shifted bytes of Starting address of 802.11 header. 2006.09.28, by Emily
-       //porting by amy 080508
+       /* Get shifted bytes of Starting address of 802.11 header. */
        pstats->virtual_address += get_rxpacket_shiftbytes_819xusb(pstats);
        frame = pstats->virtual_address;
        frame_len = pstats->packetlength;
-#ifdef TODO    // by amy about HCT
+#ifdef TODO    /* about HCT */
        if (!Adapter->bInHctTest)
                CountRxErrStatistics(Adapter, pRfd);
 #endif
-#ifdef ENABLE_PS  //by amy for adding ps function in future
+#ifdef ENABLE_PS  /* for adding ps function in future */
        RT_RF_POWER_STATE rtState;
-       // When RF is off, we should not count the packet for hw/sw synchronize
-       // reason, ie. there may be a duration while sw switch is changed and hw
-       // switch is being changed. 2006.12.04, by shien chang.
-       Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (u8 *)(&rtState));
+       /* When RF is off, we should not count the packet for hw/sw synchronize
+        * reason, ie. there may be a duration while sw switch is changed and
+        * hw switch is being changed.
+        */
+       Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE,
+                                        (u8 *)(&rtState));
        if (rtState == eRfOff)
                return;
 #endif
@@ -4550,8 +4854,7 @@ static void rtl819xusb_process_received_packet(struct net_device *dev,
 #ifdef TODO
        RmMonitorSignalStrength(Adapter, pRfd);
 #endif
-       /* 2007/01/16 MH Add RX command packet handle here. */
-       /* 2007/03/01 MH We have to release RFD and return if rx pkt is cmd pkt. */
+       /* We have to release RFD and return if rx pkt is cmd pkt. */
        if (rtl819xusb_rx_command_packet(dev, pstats))
                return;
 
@@ -4567,14 +4870,12 @@ static void query_rx_cmdpkt_desc_status(struct sk_buff *skb,
 {
        rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
 
-       //
-       //Get Rx Descriptor Information
-       //
+       /* Get Rx Descriptor Information */
        stats->virtual_address = (u8 *)skb->data;
        stats->Length = desc->Length;
        stats->RxDrvInfoSize = 0;
        stats->RxBufShift = 0;
-       stats->packetlength = stats->Length-scrclng;
+       stats->packetlength = stats->Length - scrclng;
        stats->fraglength = stats->packetlength;
        stats->fragoffset = 0;
        stats->ntotalfrag = 1;
@@ -4588,7 +4889,7 @@ static void rtl8192_rx_cmd(struct sk_buff *skb)
        /* TODO */
        struct ieee80211_rx_stats stats = {
                .signal = 0,
-               .noise = -98,
+               .noise = 0x100 - 98,
                .rate = 0,
                .freq = IEEE80211_24GHZ_BAND,
        };
@@ -4596,12 +4897,9 @@ static void rtl8192_rx_cmd(struct sk_buff *skb)
        if ((skb->len >= (20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
 
                query_rx_cmdpkt_desc_status(skb, &stats);
-               // this is to be done by amy 080508     prfd->queue_id = 1;
-
+               /* prfd->queue_id = 1; */
 
-               //
-               //  Process the command packet received.
-               //
+               /* Process the command packet received. */
 
                rtl819xusb_process_received_packet(dev, &stats);
 
@@ -4666,6 +4964,7 @@ static int rtl8192_usb_probe(struct usb_interface *intf,
        struct r8192_priv *priv = NULL;
        struct usb_device *udev = interface_to_usbdev(intf);
        int ret;
+
        RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
 
        dev = alloc_ieee80211(sizeof(struct r8192_priv));
@@ -4680,14 +4979,16 @@ static int rtl8192_usb_probe(struct usb_interface *intf,
 
        dev->netdev_ops = &rtl8192_netdev_ops;
 
-       dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
+       dev->wireless_handlers =
+               (struct iw_handler_def *)&r8192_wx_handlers_def;
 
        dev->type = ARPHRD_ETHER;
 
-       dev->watchdog_timeo = HZ*3;     //modified by john, 0805
+       dev->watchdog_timeo = HZ * 3;
 
        if (dev_alloc_name(dev, ifname) < 0) {
-               RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
+               RT_TRACE(COMP_INIT,
+                        "Oops: devname already taken! Trying wlan%%d...\n");
                ifname = "wlan%d";
                dev_alloc_name(dev, ifname);
        }
@@ -4726,7 +5027,9 @@ fail:
        return ret;
 }
 
-//detach all the work and timer structure declared or inititialize in r8192U_init function.
+/* detach all the work and timer structure declared or inititialize
+ * in r8192U_init function.
+ */
 static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
 {
 
@@ -4740,13 +5043,13 @@ static void rtl8192_cancel_deferred_work(struct r8192_priv *priv)
 static void rtl8192_usb_disconnect(struct usb_interface *intf)
 {
        struct net_device *dev = usb_get_intfdata(intf);
-
        struct r8192_priv *priv = ieee80211_priv(dev);
-       if (dev) {
 
+       if (dev) {
                unregister_netdev(dev);
 
-               RT_TRACE(COMP_DOWN, "=============>wlan driver to be removed\n");
+               RT_TRACE(COMP_DOWN,
+                        "=============>wlan driver to be removed\n");
                rtl8192_proc_remove_one(dev);
 
                rtl8192_down(dev);
@@ -4755,7 +5058,6 @@ static void rtl8192_usb_disconnect(struct usb_interface *intf)
                rtl8192_usb_deleteendpoints(dev);
                destroy_workqueue(priv->priv_wq);
                mdelay(10);
-
        }
        free_ieee80211(dev);
        RT_TRACE(COMP_DOWN, "wlan driver removed\n");
@@ -4832,6 +5134,7 @@ void EnableHWSecurityConfig8192(struct net_device *dev)
        u8 SECR_value = 0x0;
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct ieee80211_device *ieee = priv->ieee80211;
+
        SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
        if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2)) {
                SECR_value |= SCR_RxUseDK;
@@ -4840,17 +5143,23 @@ void EnableHWSecurityConfig8192(struct net_device *dev)
                SECR_value |= SCR_RxUseDK;
                SECR_value |= SCR_TxUseDK;
        }
-       //add HWSec active enable here.
-       //default using hwsec. when peer AP is in N mode only and pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates it), use software security. when peer AP is in b,g,n mode mixed and pairwise_key_type is none_aes, use g mode hw security. WB on 2008.7.4
+       /* add HWSec active enable here.
+        * default using hwsec. when peer AP is in N mode only and
+        * pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates
+        * it), use software security. when peer AP is in b,g,n mode mixed and
+        * pairwise_key_type is none_aes, use g mode hw security.
+        */
 
        ieee->hwsec_active = 1;
 
-       if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep) { /* add hwsec_support flag to totol control hw_sec on/off */
+       /* add hwsec_support flag to totol control hw_sec on/off */
+       if ((ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE) || !hwwep) {
                ieee->hwsec_active = 0;
                SECR_value &= ~SCR_RxDecEnable;
        }
-       RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __func__,
-                ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
+       RT_TRACE(COMP_SEC, "%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n",
+                __func__, ieee->hwsec_active, ieee->pairwise_key_type,
+                SECR_value);
        write_nic_byte(dev, SECR,  SECR_value);
 }
 
@@ -4862,39 +5171,42 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
        u32 TargetContent = 0;
        u16 usConfig = 0;
        u8 i;
+
        if (EntryNo >= TOTAL_CAM_ENTRY)
                RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
 
-       RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev, EntryNo, KeyIndex, KeyType, MacAddr);
+       RT_TRACE(COMP_SEC,
+                "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n",
+                dev, EntryNo, KeyIndex, KeyType, MacAddr);
 
        if (DefaultKey)
-               usConfig |= BIT15 | (KeyType<<2);
+               usConfig |= BIT(15) | (KeyType << 2);
        else
-               usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
+               usConfig |= BIT(15) | (KeyType << 2) | KeyIndex;
 
 
        for (i = 0; i < CAM_CONTENT_COUNT; i++) {
-               TargetCommand  = i+CAM_CONTENT_COUNT*EntryNo;
-               TargetCommand |= BIT31|BIT16;
+               TargetCommand  = i + CAM_CONTENT_COUNT * EntryNo;
+               TargetCommand |= BIT(31) | BIT(16);
 
                if (i == 0) { /* MAC|Config */
-                       TargetContent = (u32)(*(MacAddr+0)) << 16|
-                                       (u32)(*(MacAddr+1)) << 24|
+                       TargetContent = (u32)(*(MacAddr + 0)) << 16 |
+                                       (u32)(*(MacAddr + 1)) << 24 |
                                        (u32)usConfig;
 
                        write_nic_dword(dev, WCAMI, TargetContent);
                        write_nic_dword(dev, RWCAM, TargetCommand);
                } else if (i == 1) { /* MAC */
-                       TargetContent = (u32)(*(MacAddr+2))      |
-                                       (u32)(*(MacAddr+3)) <<  8|
-                                       (u32)(*(MacAddr+4)) << 16|
-                                       (u32)(*(MacAddr+5)) << 24;
+                       TargetContent = (u32)(*(MacAddr + 2))    |
+                                       (u32)(*(MacAddr + 3)) <<  8 |
+                                       (u32)(*(MacAddr + 4)) << 16 |
+                                       (u32)(*(MacAddr + 5)) << 24;
                        write_nic_dword(dev, WCAMI, TargetContent);
                        write_nic_dword(dev, RWCAM, TargetCommand);
                } else {
-                       //Key Material
+                       /* Key Material */
                        if (KeyContent != NULL) {
-                               write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)));
+                               write_nic_dword(dev, WCAMI, (u32)(*(KeyContent + i - 2)));
                                write_nic_dword(dev, RWCAM, TargetCommand);
                        }
                }
index 5277f2eec0339537000c716ec9d65fda75cb2d99..375ec96b94695a18243a114c01bdf0d4dc18e23b 100644 (file)
@@ -325,21 +325,26 @@ static void dm_check_rate_adaptive(struct net_device *dev)
                        (!pHTInfo->bCurTxBW40MHz && pHTInfo->bCurShortGI20MHz);
 
                pra->upper_rssi_threshold_ratr =
-                               (pra->upper_rssi_threshold_ratr & (~BIT31)) | ((bshort_gi_enabled) ? BIT31:0);
+                               (pra->upper_rssi_threshold_ratr & (~BIT(31))) |
+                               ((bshort_gi_enabled) ? BIT(31) : 0);
 
                pra->middle_rssi_threshold_ratr =
-                               (pra->middle_rssi_threshold_ratr & (~BIT31)) | ((bshort_gi_enabled) ? BIT31:0);
+                               (pra->middle_rssi_threshold_ratr & (~BIT(31))) |
+                               ((bshort_gi_enabled) ? BIT(31) : 0);
 
                if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) {
                        pra->low_rssi_threshold_ratr =
-                               (pra->low_rssi_threshold_ratr_40M & (~BIT31)) | ((bshort_gi_enabled) ? BIT31:0);
+                             (pra->low_rssi_threshold_ratr_40M & (~BIT(31))) |
+                             ((bshort_gi_enabled) ? BIT(31) : 0);
                } else {
                        pra->low_rssi_threshold_ratr =
-                       (pra->low_rssi_threshold_ratr_20M & (~BIT31)) | ((bshort_gi_enabled) ? BIT31:0);
+                       (pra->low_rssi_threshold_ratr_20M & (~BIT(31))) |
+                       ((bshort_gi_enabled) ? BIT(31) : 0);
                }
                /* cosa add for test */
                pra->ping_rssi_ratr =
-                               (pra->ping_rssi_ratr & (~BIT31)) | ((bshort_gi_enabled) ? BIT31:0);
+                               (pra->ping_rssi_ratr & (~BIT(31))) |
+                               ((bshort_gi_enabled) ? BIT(31) : 0);
 
                /* 2007/10/08 MH We support RA smooth scheme now. When it is the first
                   time to link with AP. We will not change upper/lower threshold. If
@@ -2378,7 +2383,7 @@ static    void    dm_check_pbc_gpio(struct net_device *dev)
        if (tmp1byte == 0xff)
                return;
 
-       if (tmp1byte&BIT6 || tmp1byte&BIT0) {
+       if (tmp1byte & BIT(6) || tmp1byte & BIT(0)) {
                /*
                 * Here we only set bPbcPressed to TRUE
                 * After trigger PBC, the variable will be set to FALSE
index a93694ff0c422229cefa346d088f9dee128edc88..e07d65d04dbcb829ff048c2d86e2a271489d327b 100644 (file)
@@ -55,17 +55,17 @@ typedef enum _BaseBand_Config_Type{
 #define BB_ANTATTEN_CHAN14     0x0c
 #define BB_ANTENNA_B 0x40
 
-#define BB_HOST_BANG (1<<30)
-#define BB_HOST_BANG_EN (1<<2)
-#define BB_HOST_BANG_CLK (1<<1)
-#define BB_HOST_BANG_RW (1<<3)
+#define BB_HOST_BANG           BIT(30)
+#define BB_HOST_BANG_EN                BIT(2)
+#define BB_HOST_BANG_CLK       BIT(1)
+#define BB_HOST_BANG_RW                BIT(3)
 #define BB_HOST_BANG_DATA       1
 
 //#if (RTL819X_FPGA_VER & RTL819X_FPGA_VIVI_070920)
 #define AFR                    0x010
-#define AFR_CardBEn            (1<<0)
-#define AFR_CLKRUN_SEL         (1<<1)
-#define AFR_FuncRegEn          (1<<2)
+#define AFR_CardBEn            BIT(0)
+#define AFR_CLKRUN_SEL         BIT(1)
+#define AFR_FuncRegEn          BIT(2)
 #define RTL8190_EEPROM_ID      0x8129
 #define EEPROM_VID             0x02
 #define EEPROM_PID             0x04
@@ -126,38 +126,39 @@ enum _RTL8192Usb_HW {
 #define TCR_LRL_OFFSET         0
 #define TCR_SRL_OFFSET         8
 #define TCR_MXDMA_OFFSET       21
-#define TCR_SAT                        BIT24           // Enable Rate depedent ack timeout timer
+#define TCR_SAT                        BIT(24) // Enable Rate depedent ack timeout timer
        RCR                     = 0x044, // Receive Configuration Register
-#define MAC_FILTER_MASK ((1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<5) | \
-               (1<<12) | (1<<18) | (1<<19) | (1<<20) | (1<<21) | (1<<22) | (1<<23))
-#define RX_FIFO_THRESHOLD_MASK ((1<<13) | (1<<14) | (1<<15))
+#define MAC_FILTER_MASK (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(5) | \
+                        BIT(12) | BIT(18) | BIT(19) | BIT(20) | BIT(21) | \
+                        BIT(22) | BIT(23))
+#define RX_FIFO_THRESHOLD_MASK (BIT(13) | BIT(14) | BIT(15))
 #define RX_FIFO_THRESHOLD_SHIFT 13
 #define RX_FIFO_THRESHOLD_128 3
 #define RX_FIFO_THRESHOLD_256 4
 #define RX_FIFO_THRESHOLD_512 5
 #define RX_FIFO_THRESHOLD_1024 6
 #define RX_FIFO_THRESHOLD_NONE 7
-#define MAX_RX_DMA_MASK ((1<<8) | (1<<9) | (1<<10))
+#define MAX_RX_DMA_MASK        (BIT(8) | BIT(9) | BIT(10))
 #define RCR_MXDMA_OFFSET       8
 #define RCR_FIFO_OFFSET                13
-#define RCR_ONLYERLPKT         BIT31                   // Early Receiving based on Packet Size.
-#define RCR_ENCS2              BIT30                   // Enable Carrier Sense Detection Method 2
-#define RCR_ENCS1              BIT29                   // Enable Carrier Sense Detection Method 1
-#define RCR_ENMBID             BIT27                   // Enable Multiple BssId.
-#define RCR_ACKTXBW            (BIT24|BIT25)           // TXBW Setting of ACK frames
-#define RCR_CBSSID             BIT23                   // Accept BSSID match packet
-#define RCR_APWRMGT            BIT22                   // Accept power management packet
-#define        RCR_ADD3                BIT21                   // Accept address 3 match packet
-#define RCR_AMF                        BIT20                   // Accept management type frame
-#define RCR_ACF                        BIT19                   // Accept control type frame
-#define RCR_ADF                        BIT18                   // Accept data type frame
-#define RCR_RXFTH              BIT13                   // Rx FIFO Threshold
-#define RCR_AICV               BIT12                   // Accept ICV error packet
-#define        RCR_ACRC32              BIT5                    // Accept CRC32 error packet
-#define        RCR_AB                  BIT3                    // Accept broadcast packet
-#define        RCR_AM                  BIT2                    // Accept multicast packet
-#define        RCR_APM                 BIT1                    // Accept physical match packet
-#define        RCR_AAP                 BIT0                    // Accept all unicast packet
+#define RCR_ONLYERLPKT         BIT(31)                 // Early Receiving based on Packet Size.
+#define RCR_ENCS2              BIT(30)                 // Enable Carrier Sense Detection Method 2
+#define RCR_ENCS1              BIT(29)                 // Enable Carrier Sense Detection Method 1
+#define RCR_ENMBID             BIT(27)                 // Enable Multiple BssId.
+#define RCR_ACKTXBW            (BIT(24) | BIT(25))     // TXBW Setting of ACK frames
+#define RCR_CBSSID             BIT(23)                 // Accept BSSID match packet
+#define RCR_APWRMGT            BIT(22)                 // Accept power management packet
+#define        RCR_ADD3                BIT(21)                 // Accept address 3 match packet
+#define RCR_AMF                        BIT(20)                 // Accept management type frame
+#define RCR_ACF                        BIT(19)                 // Accept control type frame
+#define RCR_ADF                        BIT(18)                 // Accept data type frame
+#define RCR_RXFTH              BIT(13)                 // Rx FIFO Threshold
+#define RCR_AICV               BIT(12)                 // Accept ICV error packet
+#define        RCR_ACRC32              BIT(5)                  // Accept CRC32 error packet
+#define        RCR_AB                  BIT(3)                  // Accept broadcast packet
+#define        RCR_AM                  BIT(2)                  // Accept multicast packet
+#define        RCR_APM                 BIT(1)                  // Accept physical match packet
+#define        RCR_AAP                 BIT(0)                  // Accept all unicast packet
        SLOT_TIME               = 0x049, // Slot Time Register
        ACK_TIMEOUT             = 0x04c, // Ack Timeout Register
        PIFS_TIME               = 0x04d, // PIFS time
@@ -180,12 +181,12 @@ enum _RTL8192Usb_HW {
        WCAMI                   = 0x0A4, // Software write CAM input content
        RCAMO                   = 0x0A8, // Software read/write CAM config
        SECR                    = 0x0B0, //Security Configuration Register
-#define        SCR_TxUseDK             BIT0                    //Force Tx Use Default Key
-#define SCR_RxUseDK            BIT1                    //Force Rx Use Default Key
-#define SCR_TxEncEnable                BIT2                    //Enable Tx Encryption
-#define SCR_RxDecEnable                BIT3                    //Enable Rx Decryption
-#define SCR_SKByA2             BIT4                    //Search kEY BY A2
-#define SCR_NoSKMC             BIT5                    //No Key Search for Multicast
+#define        SCR_TxUseDK             BIT(0)                  //Force Tx Use Default Key
+#define SCR_RxUseDK            BIT(1)                  //Force Rx Use Default Key
+#define SCR_TxEncEnable                BIT(2)                  //Enable Tx Encryption
+#define SCR_RxDecEnable                BIT(3)                  //Enable Rx Decryption
+#define SCR_SKByA2             BIT(4)                  //Search kEY BY A2
+#define SCR_NoSKMC             BIT(5)                  //No Key Search for Multicast
 #define SCR_UseDK              0x01
 #define SCR_TxSecEnable                0x02
 #define SCR_RxSecEnable                0x04
@@ -226,13 +227,13 @@ enum _RTL8192Usb_HW {
 ////       8190 AcmHwCtrl bits                                    (offset 0x171, 1 byte)
 ////----------------------------------------------------------------------------
 //
-#define AcmHw_HwEn              BIT0
-#define AcmHw_BeqEn             BIT1
-#define AcmHw_ViqEn             BIT2
-#define AcmHw_VoqEn             BIT3
-#define AcmHw_BeqStatus         BIT4
-#define AcmHw_ViqStatus         BIT5
-#define AcmHw_VoqStatus         BIT6
+#define AcmHw_HwEn              BIT(0)
+#define AcmHw_BeqEn             BIT(1)
+#define AcmHw_ViqEn             BIT(2)
+#define AcmHw_VoqEn             BIT(3)
+#define AcmHw_BeqStatus         BIT(4)
+#define AcmHw_ViqStatus         BIT(5)
+#define AcmHw_VoqStatus         BIT(6)
 
        AcmFwCtrl               = 0x172, // ACM Firmware Control Register
        AES_11N_FIX             = 0x173,
@@ -281,18 +282,18 @@ enum _RTL8192Usb_HW {
        NHM_RPI_COUNTER5        = 0x269, // Noise Histogram RPI counter5, the fraction of signal strength in (NHM_THRESHOLD4, NHM_THRESHOLD5].
        NHM_RPI_COUNTER6        = 0x26A, // Noise Histogram RPI counter6, the fraction of signal strength in (NHM_THRESHOLD5, NHM_THRESHOLD6].
        NHM_RPI_COUNTER7        = 0x26B, // Noise Histogram RPI counter7, the fraction of signal strength in (NHM_THRESHOLD6, NHM_THRESHOLD7].
-#define        BW_OPMODE_11J                   BIT0
-#define        BW_OPMODE_5G                    BIT1
-#define        BW_OPMODE_20MHZ                 BIT2
+#define        BW_OPMODE_11J                   BIT(0)
+#define        BW_OPMODE_5G                    BIT(1)
+#define        BW_OPMODE_20MHZ                 BIT(2)
        BW_OPMODE               = 0x300, // Bandwidth operation mode
        MSR                     = 0x303, // Media Status register
-#define MSR_LINK_MASK      ((1<<0)|(1<<1))
+#define MSR_LINK_MASK      (BIT(0)|BIT(1))
 #define MSR_LINK_MANAGED   2
 #define MSR_LINK_NONE      0
 #define MSR_LINK_SHIFT     0
 #define MSR_LINK_ADHOC     1
 #define MSR_LINK_MASTER    3
-#define MSR_LINK_ENEDCA           (1<<4)
+#define MSR_LINK_ENEDCA           BIT(4)
        RETRY_LIMIT             = 0x304, // Retry Limit [15:8]-short, [7:0]-long
 #define RETRY_LIMIT_SHORT_SHIFT 8
 #define RETRY_LIMIT_LONG_SHIFT 0
@@ -304,27 +305,27 @@ enum _RTL8192Usb_HW {
 #define RRSR_RSC_LOWSUBCHNL            0x400000
 #define RRSR_RSC_UPSUBCHANL            0x200000
 #define RRSR_SHORT                                     0x800000
-#define RRSR_1M                                                BIT0
-#define RRSR_2M                                                BIT1
-#define RRSR_5_5M                                      BIT2
-#define RRSR_11M                                       BIT3
-#define RRSR_6M                                                BIT4
-#define RRSR_9M                                                BIT5
-#define RRSR_12M                                       BIT6
-#define RRSR_18M                                       BIT7
-#define RRSR_24M                                       BIT8
-#define RRSR_36M                                       BIT9
-#define RRSR_48M                                       BIT10
-#define RRSR_54M                                       BIT11
-#define RRSR_MCS0                                      BIT12
-#define RRSR_MCS1                                      BIT13
-#define RRSR_MCS2                                      BIT14
-#define RRSR_MCS3                                      BIT15
-#define RRSR_MCS4                                      BIT16
-#define RRSR_MCS5                                      BIT17
-#define RRSR_MCS6                                      BIT18
-#define RRSR_MCS7                                      BIT19
-#define BRSR_AckShortPmb                       BIT23           // CCK ACK: use Short Preamble or not.
+#define RRSR_1M                                                BIT(0)
+#define RRSR_2M                                                BIT(1)
+#define RRSR_5_5M                                      BIT(2)
+#define RRSR_11M                                       BIT(3)
+#define RRSR_6M                                                BIT(4)
+#define RRSR_9M                                                BIT(5)
+#define RRSR_12M                                       BIT(6)
+#define RRSR_18M                                       BIT(7)
+#define RRSR_24M                                       BIT(8)
+#define RRSR_36M                                       BIT(9)
+#define RRSR_48M                                       BIT(10)
+#define RRSR_54M                                       BIT(11)
+#define RRSR_MCS0                                      BIT(12)
+#define RRSR_MCS1                                      BIT(13)
+#define RRSR_MCS2                                      BIT(14)
+#define RRSR_MCS3                                      BIT(15)
+#define RRSR_MCS4                                      BIT(16)
+#define RRSR_MCS5                                      BIT(17)
+#define RRSR_MCS6                                      BIT(18)
+#define RRSR_MCS7                                      BIT(19)
+#define BRSR_AckShortPmb                       BIT(23)         // CCK ACK: use Short Preamble or not.
        RATR0                   = 0x320, // Rate Adaptive Table register1
        UFWP                    = 0x318,
        DRIVER_RSSI             = 0x32c,                                        // Driver tell Firmware current RSSI
@@ -380,10 +381,10 @@ enum _RTL8192Usb_HW {
        MacBlkCtrl              = 0x403, // Mac block on/off control register
 
        EPROM_CMD               = 0xfe58,
-#define Cmd9346CR_9356SEL      (1<<4)
-#define EPROM_CMD_RESERVED_MASK (1<<5)
+#define Cmd9346CR_9356SEL      BIT(4)
+#define EPROM_CMD_RESERVED_MASK BIT(5)
 #define EPROM_CMD_OPERATING_MODE_SHIFT 6
-#define EPROM_CMD_OPERATING_MODE_MASK ((1<<7)|(1<<6))
+#define EPROM_CMD_OPERATING_MODE_MASK (BIT(7) | BIT(6))
 #define EPROM_CMD_CONFIG 0x3
 #define EPROM_CMD_NORMAL 0
 #define EPROM_CMD_LOAD 1
index 83597051a4485b5f541052cc80abea7981805b79..4911fef2e2e5f39026f78dedd06c3b8088100463 100644 (file)
@@ -263,12 +263,12 @@ static int rtl8180_wx_get_range(struct net_device *dev,
        range->max_qual.qual = 100;
        /* TODO: Find real max RSSI and stick here */
        range->max_qual.level = 0;
-       range->max_qual.noise = -98;
+       range->max_qual.noise = 0x100 - 98;
        range->max_qual.updated = 7; /* Updated all three */
 
        range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
        /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
-       range->avg_qual.level = 20 + -98;
+       range->avg_qual.level = 0x100 - 78;
        range->avg_qual.noise = 0;
        range->avg_qual.updated = 7; /* Updated all three */
 
index cc8029a15df4d1b46cc9c7eed6450389a8131b4f..f490e253ee50204a6d37bd939099227824d3583a 100644 (file)
@@ -9,9 +9,9 @@
 #define                CMPK_TX_RAHIS_SIZE              sizeof(cmpk_tx_rahis_t)
 
 /* 2008/05/08 amy For USB constant. */
-#define ISR_TxBcnOk            BIT27           /* Transmit Beacon OK */
-#define ISR_TxBcnErr           BIT26           /* Transmit Beacon Error */
-#define ISR_BcnTimerIntr       BIT13           /* Beacon Timer Interrupt */
+#define ISR_TxBcnOk            BIT(27)         /* Transmit Beacon OK */
+#define ISR_TxBcnErr           BIT(26)         /* Transmit Beacon Error */
+#define ISR_BcnTimerIntr       BIT(13)         /* Beacon Timer Interrupt */
 
 
 /* Define element ID of command packet. */
index e5dbaca9e518e9cd8ca5ede123cbaa294bfb6e6e..70656441c14553570c54375d5fc4158aa32c1f02 100644 (file)
@@ -1110,7 +1110,7 @@ bool rtl8192_SetRFPowerState(struct net_device *dev,
                case eRfOn:
                        /* RF-A, RF-B */
                        /* enable RF-Chip A/B - 0x860[4] */
-                       rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4,
+                       rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT(4),
                                         0x1);
                        /* analog to digital on - 0x88c[9:8] */
                        rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300,
@@ -1135,7 +1135,7 @@ bool rtl8192_SetRFPowerState(struct net_device *dev,
                case eRfOff:
                        /* RF-A, RF-B */
                        /* disable RF-Chip A/B - 0x860[4] */
-                       rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4,
+                       rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT(4),
                                         0x0);
                        /* analog to digital off, for power save */
                        rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00,
index e62543d22b861716f5c04a973c1e93aac194d685..3d64feeb80e76dcc84703776e102aa340bbc575e 100644 (file)
  * Larry Finger <Larry.Finger@lwfinger.net>
  *
  ******************************************************************************/
-/*---------------------------------------------------------------------
-
-       For type defines and data structure defines
-
------------------------------------------------------------------------*/
+/* ---------------------------------------------------------------------
+ *
+ *     For type defines and data structure defines
+ *
+ * ---------------------------------------------------------------------
+ */
 #ifndef __DRV_TYPES_H__
 #define __DRV_TYPES_H__
 
index 0a1c6313e78156b708e570591fca431b0981f33e..8008efe5686dc46827545d91ee5ad9a7d69c0e67 100644 (file)
@@ -122,15 +122,15 @@ static void fill_fwpriv(struct _adapter *padapter, struct fw_priv *pfwpriv)
 static void update_fwhdr(struct fw_hdr *pfwhdr, const u8 *pmappedfw)
 {
        pfwhdr->signature = le16_to_cpu(*(u16 *)pmappedfw);
-       pfwhdr->version = le16_to_cpu(*(u16 *)(pmappedfw+2));
+       pfwhdr->version = le16_to_cpu(*(u16 *)(pmappedfw + 2));
        /* define the size of boot loader */
-       pfwhdr->dmem_size = le32_to_cpu(*(uint *)(pmappedfw+4));
+       pfwhdr->dmem_size = le32_to_cpu(*(uint *)(pmappedfw + 4));
        /* define the size of FW in IMEM */
-       pfwhdr->img_IMEM_size = le32_to_cpu(*(uint *)(pmappedfw+8));
+       pfwhdr->img_IMEM_size = le32_to_cpu(*(uint *)(pmappedfw + 8));
        /* define the size of FW in SRAM */
-       pfwhdr->img_SRAM_size = le32_to_cpu(*(uint *)(pmappedfw+12));
+       pfwhdr->img_SRAM_size = le32_to_cpu(*(uint *)(pmappedfw + 12));
        /* define the size of DMEM variable */
-       pfwhdr->fw_priv_sz = le32_to_cpu(*(uint *)(pmappedfw+16));
+       pfwhdr->fw_priv_sz = le32_to_cpu(*(uint *)(pmappedfw + 16));
 }
 
 static u8 chk_fwhdr(struct fw_hdr *pfwhdr, u32 ulfilelength)
@@ -177,8 +177,8 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
                maxlen = (fwhdr.img_IMEM_size > fwhdr.img_SRAM_size) ?
                          fwhdr.img_IMEM_size : fwhdr.img_SRAM_size;
                maxlen += txdscp_sz;
-               ptmpchar = kmalloc(maxlen + FWBUFF_ALIGN_SZ, GFP_ATOMIC);
-               if (ptmpchar == NULL)
+               ptmpchar = kmalloc(maxlen + FWBUFF_ALIGN_SZ, GFP_KERNEL);
+               if (!ptmpchar)
                        return ret;
 
                ptx_desc = (struct tx_desc *)(ptmpchar + FWBUFF_ALIGN_SZ -
@@ -191,9 +191,9 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
                imem_sz = fwhdr.img_IMEM_size;
                do {
                        memset(ptx_desc, 0, TXDESC_SIZE);
-                       if (imem_sz >  MAX_DUMP_FWSZ/*49152*/)
+                       if (imem_sz >  MAX_DUMP_FWSZ/*49152*/) {
                                dump_imem_sz = MAX_DUMP_FWSZ;
-                       else {
+                       else {
                                dump_imem_sz = imem_sz;
                                ptx_desc->txdw0 |= cpu_to_le32(BIT(28));
                        }
@@ -209,7 +209,7 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
                i = 10;
                tmp16 = r8712_read16(padapter, TCR);
                while (((tmp16 & _IMEM_CODE_DONE) == 0) && (i > 0)) {
-                       udelay(10);
+                       usleep_range(10, 1000);
                        tmp16 = r8712_read16(padapter, TCR);
                        i--;
                }
@@ -230,14 +230,14 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
                                                       0x0000ffff);
                        memcpy(ppayload, ptr, dump_emem_sz);
                        r8712_write_mem(padapter, RTL8712_DMA_VOQ,
-                                 dump_emem_sz+TXDESC_SIZE, (u8 *)ptx_desc);
+                                 dump_emem_sz + TXDESC_SIZE, (u8 *)ptx_desc);
                        ptr += dump_emem_sz;
                        emem_sz -= dump_emem_sz;
                } while (emem_sz > 0);
                i = 5;
                tmp16 = r8712_read16(padapter, TCR);
                while (((tmp16 & _EMEM_CODE_DONE) == 0) && (i > 0)) {
-                       udelay(10);
+                       usleep_range(10, 1000);
                        tmp16 = r8712_read16(padapter, TCR);
                        i--;
                }
@@ -246,15 +246,15 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
 
                /* 3.Enable CPU */
                tmp8 = r8712_read8(padapter, SYS_CLKR);
-               r8712_write8(padapter, SYS_CLKR, tmp8|BIT(2));
+               r8712_write8(padapter, SYS_CLKR, tmp8 | BIT(2));
                tmp8_a = r8712_read8(padapter, SYS_CLKR);
-               if (tmp8_a != (tmp8|BIT(2)))
+               if (tmp8_a != (tmp8 | BIT(2)))
                        goto exit_fail;
 
                tmp8 = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               r8712_write8(padapter, SYS_FUNC_EN+1, tmp8|BIT(2));
+               r8712_write8(padapter, SYS_FUNC_EN + 1, tmp8 | BIT(2));
                tmp8_a = r8712_read8(padapter, SYS_FUNC_EN + 1);
-               if (tmp8_a != (tmp8|BIT(2)))
+               if (tmp8_a != (tmp8 | BIT(2)))
                        goto exit_fail;
 
                r8712_read32(padapter, TCR);
@@ -278,7 +278,7 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
                }
                /* 5.Download DMEM code size and Load EMEM Code Section */
                memset(ptx_desc, 0, TXDESC_SIZE);
-               ptx_desc->txdw0 |= cpu_to_le32(fwhdr.fw_priv_sz&0x0000ffff);
+               ptx_desc->txdw0 |= cpu_to_le32(fwhdr.fw_priv_sz & 0x0000ffff);
                ptx_desc->txdw0 |= cpu_to_le32(BIT(28));
                memcpy(ppayload, &fwhdr.fwpriv, fwhdr.fw_priv_sz);
                r8712_write_mem(padapter, RTL8712_DMA_VOQ,
@@ -309,8 +309,9 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
                }
                if (i == 0)
                        goto exit_fail;
-       } else
+       } else {
                goto exit_fail;
+       }
        ret = _SUCCESS;
 
 exit_fail:
@@ -335,10 +336,10 @@ uint rtl8712_hal_init(struct _adapter *padapter)
        netdev_info(padapter->pnetdev, "2 RCR=0x%x\n",
                    r8712_read32(padapter, RCR));
        val32 = r8712_read32(padapter, RCR);
-       r8712_write32(padapter, RCR, (val32|BIT(25))); /* Append PHY status */
+       r8712_write32(padapter, RCR, (val32 | BIT(25))); /* Append PHY status */
        val32 = 0;
        val32 = r8712_read32(padapter, 0x10250040);
-       r8712_write32(padapter,  0x10250040, (val32&0x00FFFFFF));
+       r8712_write32(padapter,  0x10250040, (val32 & 0x00FFFFFF));
        /* for usb rx aggregation */
        r8712_write8(padapter, 0x102500B5, r8712_read8(padapter, 0x102500B5) |
               BIT(0)); /* page = 128bytes */
@@ -362,33 +363,33 @@ uint rtl8712_hal_deinit(struct _adapter *padapter)
        /* Turn off BB */
        msleep(20);
        /* Turn off MAC */
-       r8712_write8(padapter, SYS_CLKR+1, 0x38); /* Switch Control Path */
-       r8712_write8(padapter, SYS_FUNC_EN+1, 0x70);
+       r8712_write8(padapter, SYS_CLKR + 1, 0x38); /* Switch Control Path */
+       r8712_write8(padapter, SYS_FUNC_EN + 1, 0x70);
        r8712_write8(padapter, PMC_FSM, 0x06);  /* Enable Loader Data Keep */
        r8712_write8(padapter, SYS_ISO_CTRL, 0xF9); /* Isolation signals from
                                                     * CORE, PLL */
-       r8712_write8(padapter, SYS_ISO_CTRL+1, 0xe8); /* Enable EFUSE 1.2V */
+       r8712_write8(padapter, SYS_ISO_CTRL + 1, 0xe8); /* Enable EFUSE 1.2V */
        r8712_write8(padapter, AFE_PLL_CTRL, 0x00); /* Disable AFE PLL. */
        r8712_write8(padapter, LDOA15_CTRL, 0x54);  /* Disable A15V */
-       r8712_write8(padapter, SYS_FUNC_EN+1, 0x50); /* Disable E-Fuse 1.2V */
+       r8712_write8(padapter, SYS_FUNC_EN + 1, 0x50); /* Disable E-Fuse 1.2V */
        r8712_write8(padapter, LDOV12D_CTRL, 0x24); /* Disable LDO12(for CE) */
        r8712_write8(padapter, AFE_MISC, 0x30); /* Disable AFE BG&MB */
        /* Option for Disable 1.6V LDO. */
        r8712_write8(padapter, SPS0_CTRL, 0x56); /* Disable 1.6V LDO */
-       r8712_write8(padapter, SPS0_CTRL+1, 0x43);  /* Set SW PFM */
+       r8712_write8(padapter, SPS0_CTRL + 1, 0x43);  /* Set SW PFM */
        return _SUCCESS;
 }
 
 uint rtl871x_hal_init(struct _adapter *padapter)
 {
        padapter->hw_init_completed = false;
-       if (padapter->halpriv.hal_bus_init == NULL)
+       if (!padapter->halpriv.hal_bus_init)
                return _FAIL;
        if (padapter->halpriv.hal_bus_init(padapter) != _SUCCESS)
                return _FAIL;
-       if (rtl8712_hal_init(padapter) == _SUCCESS)
+       if (rtl8712_hal_init(padapter) == _SUCCESS) {
                padapter->hw_init_completed = true;
-       else {
+       else {
                padapter->hw_init_completed = false;
                return _FAIL;
        }
index c5527c1ccaa6d7103e52f18eba0375d0e5051ba7..974ca021ccef9923df15fcfc7bd8f5d976f71e3c 100644 (file)
@@ -107,9 +107,10 @@ u8 *r8712_set_ie(u8 *pbuf, sint index, uint len, u8 *source, uint *frlen)
        return pbuf + len + 2;
 }
 
-/*----------------------------------------------------------------------------
-index: the information element id index, limit is the limit for search
------------------------------------------------------------------------------*/
+/* ---------------------------------------------------------------------------
+ * index: the information element id index, limit is the limit for search
+ * ---------------------------------------------------------------------------
+ */
 u8 *r8712_get_ie(u8 *pbuf, sint index, sint *len, sint limit)
 {
        sint tmp, i;
@@ -303,8 +304,9 @@ int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
                *group_cipher = r8712_get_wpa_cipher_suite(pos);
                pos += WPA_SELECTOR_LEN;
                left -= WPA_SELECTOR_LEN;
-       } else if (left > 0)
+       } else if (left > 0) {
                return _FAIL;
+       }
        /*pairwise_cipher*/
        if (left >= 2) {
                count = le16_to_cpu(*(u16 *)pos);
@@ -317,8 +319,9 @@ int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
                        pos += WPA_SELECTOR_LEN;
                        left -= WPA_SELECTOR_LEN;
                }
-       } else if (left == 1)
+       } else if (left == 1) {
                return _FAIL;
+       }
        return _SUCCESS;
 }
 
@@ -333,7 +336,8 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
                /* No RSN IE - fail silently */
                return _FAIL;
        }
-       if ((*rsn_ie != _WPA2_IE_ID_) || (*(rsn_ie+1) != (u8)(rsn_ie_len - 2)))
+       if ((*rsn_ie != _WPA2_IE_ID_) ||
+           (*(rsn_ie + 1) != (u8)(rsn_ie_len - 2)))
                return _FAIL;
        pos = rsn_ie;
        pos += 4;
@@ -343,8 +347,9 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
                *group_cipher = r8712_get_wpa2_cipher_suite(pos);
                pos += RSN_SELECTOR_LEN;
                left -= RSN_SELECTOR_LEN;
-       } else if (left > 0)
+       } else if (left > 0) {
                return _FAIL;
+       }
        /*pairwise_cipher*/
        if (left >= 2) {
                count = le16_to_cpu(*(u16 *)pos);
@@ -357,8 +362,9 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
                        pos += RSN_SELECTOR_LEN;
                        left -= RSN_SELECTOR_LEN;
                }
-       } else if (left == 1)
+       } else if (left == 1) {
                return _FAIL;
+       }
        return _SUCCESS;
 }
 
@@ -376,16 +382,17 @@ int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
                if ((authmode == _WPA_IE_ID_) &&
                    (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
                        memcpy(wpa_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
-                       *wpa_len = in_ie[cnt+1]+2;
+                       *wpa_len = in_ie[cnt + 1] + 2;
                        cnt += in_ie[cnt + 1] + 2;  /*get next */
                } else {
                        if (authmode == _WPA2_IE_ID_) {
                                memcpy(rsn_ie, &in_ie[cnt],
                                        in_ie[cnt + 1] + 2);
-                               *rsn_len = in_ie[cnt+1] + 2;
-                               cnt += in_ie[cnt+1] + 2;  /*get next*/
-                       } else
-                               cnt += in_ie[cnt+1] + 2;   /*get next*/
+                               *rsn_len = in_ie[cnt + 1] + 2;
+                               cnt += in_ie[cnt + 1] + 2;  /*get next*/
+                       } else {
+                               cnt += in_ie[cnt + 1] + 2;   /*get next*/
+                       }
                }
        }
        return *rsn_len + *wpa_len;
@@ -402,14 +409,14 @@ int r8712_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
        while (cnt < in_len) {
                eid = in_ie[cnt];
                if ((eid == _WPA_IE_ID_) &&
-                   (!memcmp(&in_ie[cnt+2], wps_oui, 4))) {
-                       memcpy(wps_ie, &in_ie[cnt], in_ie[cnt+1]+2);
-                       *wps_ielen = in_ie[cnt+1]+2;
-                       cnt += in_ie[cnt+1]+2;
+                   (!memcmp(&in_ie[cnt + 2], wps_oui, 4))) {
+                       memcpy(wps_ie, &in_ie[cnt], in_ie[cnt + 1] + 2);
+                       *wps_ielen = in_ie[cnt + 1] + 2;
+                       cnt += in_ie[cnt + 1] + 2;
                        match = true;
                        break;
                }
-                       cnt += in_ie[cnt+1]+2; /* goto next */
+                       cnt += in_ie[cnt + 1] + 2; /* goto next */
        }
        return match;
 }
index 6e813a9c1aa26d7ad76c3ff5f7c102064727ea5b..d374824c4f330a6d316d44b74b833593b40f56f9 100644 (file)
@@ -120,12 +120,13 @@ struct ieee_param {
 
 #define IEEE80211_DATA_LEN             2304
 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
-   6.2.1.1.2.
-
-   The figure in section 7.1.2 suggests a body size of up to 2312
-   bytes is allowed, which is a bit confusing, I suspect this
-   represents the 2304 bytes of real data, plus a possible 8 bytes of
-   WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
+ * 6.2.1.1.2.
+ *
+ * The figure in section 7.1.2 suggests a body size of up to 2312
+ * bytes is allowed, which is a bit confusing, I suspect this
+ * represents the 2304 bytes of real data, plus a possible 8 bytes of
+ * WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro)
+ */
 
 #define IEEE80211_HLEN                 30
 #define IEEE80211_FRAME_LEN            (IEEE80211_DATA_LEN + IEEE80211_HLEN)
@@ -405,7 +406,8 @@ struct ieee80211_snap_hdr {
 
 /* NOTE: This data is for statistical purposes; not all hardware provides this
  *       information for frames received.  Not setting these will not cause
- *       any adverse affects. */
+ *       any adverse affects.
+ */
 struct ieee80211_rx_stats {
        s8 rssi;
        u8 signal;
@@ -420,7 +422,8 @@ struct ieee80211_rx_stats {
 /* IEEE 802.11 requires that STA supports concurrent reception of at least
  * three fragmented frames. This define can be increased to support more
  * concurrent frames, but it should be noted that each entry can consume about
- * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
+ * 2 kB of RAM and increasing cache size will slow down frame reassembly.
+ */
 #define IEEE80211_FRAG_CACHE_LEN 4
 
 struct ieee80211_frag_entry {
@@ -510,19 +513,19 @@ struct ieee80211_security {
 } __packed;
 
 /*
-
- 802.11 data frame from AP
-
-      ,-------------------------------------------------------------------.
-Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
-      |------|------|---------|---------|---------|------|---------|------|
-Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
-      |      | tion | (BSSID) |         |         | ence |  data   |      |
-      `-------------------------------------------------------------------'
-
-Total: 28-2340 bytes
-
-*/
+ *
802.11 data frame from AP
+ *
*       ,-------------------------------------------------------------------.
+ * Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
*       |------|------|---------|---------|---------|------|---------|------|
+ * Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
*       |      | tion | (BSSID) |         |         | ence |  data   |      |
*       `-------------------------------------------------------------------'
+ *
+ * Total: 28-2340 bytes
+ *
+ */
 
 struct ieee80211_header_data {
        u16 frame_ctl;
@@ -628,7 +631,8 @@ struct ieee80211_txb {
 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
  * only use 8, and then use extended rates for the remaining supported
  * rates.  Other APs, however, stick all of their supported rates on the
- * main rates information element... */
+ * main rates information element...
+ */
 #define MAX_RATES_LENGTH                  ((u8)12)
 #define MAX_RATES_EX_LENGTH               ((u8)16)
 #define MAX_NETWORK_COUNT                  128
index 8c5a475f05e7a546598071a84be324182af273c2..e4e4bdee78bed7b0aa375eabb6e2d07fc3b96fb2 100644 (file)
@@ -122,7 +122,8 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
                            r8712_use_tkipkey_handler,
                            (unsigned long)adapter);
                /* Restore the PMK information to securitypriv structure
-                * for the following connection. */
+                * for the following connection.
+                */
                memcpy(&adapter->securitypriv.PMKIDList[0],
                        &backupPMKIDList[0],
                        sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
@@ -162,7 +163,7 @@ void r8712_report_sec_ie(struct _adapter *adapter, u8 authmode, u8 *sec_ie)
                        p += sprintf(p, "%02x", sec_ie[i]);
                p += sprintf(p, ")");
                memset(&wrqu, 0, sizeof(wrqu));
-               wrqu.data.length = p-buff;
+               wrqu.data.length = p - buff;
                wrqu.data.length = (wrqu.data.length < IW_CUSTOM_MAX) ?
                                   wrqu.data.length : IW_CUSTOM_MAX;
                wireless_send_event(adapter->pnetdev, IWEVCUSTOM, &wrqu, buff);
index 5d551a1ba3dc4452fb9492d454b3f0cebda09a4f..b89e2d3c4fe19da60e73211b1841bd6442a1a85e 100644 (file)
@@ -97,7 +97,7 @@ static char *initmac;
  */
 static int wifi_test;
 
-module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
+module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO | S_IWUSR);
 module_param(wifi_test, int, 0644);
 module_param(initmac, charp, 0644);
 module_param(video_mode, int, 0644);
@@ -177,7 +177,7 @@ static int r871x_net_set_mac_address(struct net_device *pnetdev, void *p)
        struct _adapter *padapter = netdev_priv(pnetdev);
        struct sockaddr *addr = p;
 
-       if (padapter->bup == false)
+       if (!padapter->bup)
                ether_addr_copy(pnetdev->dev_addr, addr->sa_data);
        return 0;
 }
@@ -333,7 +333,7 @@ u8 r8712_init_drv_sw(struct _adapter *padapter)
 
 u8 r8712_free_drv_sw(struct _adapter *padapter)
 {
-       struct net_device *pnetdev = (struct net_device *)padapter->pnetdev;
+       struct net_device *pnetdev = padapter->pnetdev;
 
        r8712_free_cmd_priv(&padapter->cmdpriv);
        r8712_free_evt_priv(&padapter->evtpriv);
@@ -366,7 +366,8 @@ static void enable_video_mode(struct _adapter *padapter, int cbw40_value)
 
        if (cbw40_value) {
                /* if the driver supports the 40M bandwidth,
-                * we can enable the bit 9.*/
+                * we can enable the bit 9.
+                */
                intcmd |= 0x200;
        }
        r8712_fw_cmd(padapter, intcmd);
@@ -383,7 +384,7 @@ static int netdev_open(struct net_device *pnetdev)
        struct _adapter *padapter = netdev_priv(pnetdev);
 
        mutex_lock(&padapter->mutex_start);
-       if (padapter->bup == false) {
+       if (!padapter->bup) {
                padapter->bDriverStopped = false;
                padapter->bSurpriseRemoved = false;
                padapter->bup = true;
index 0a7f58c59df521aab10911520a39810be8ff38b2..076d5083c723685839f7a1beab4880efeec22db4 100644 (file)
@@ -60,10 +60,6 @@ struct       __queue {
 #define LIST_CONTAINOR(ptr, type, member) \
        ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
 
-#ifndef BIT
-       #define BIT(x)  (1 << (x))
-#endif
-
 static inline u32 _down_sema(struct semaphore *sema)
 {
        if (down_interruptible(sema))
index 4201ce776e0c710f0bb37af249eb271c826f28f8..2f5460dbda8bc0aa053622da7bc1503271e2bf75 100644 (file)
@@ -127,7 +127,8 @@ void r8712_recv_indicatepkt(struct _adapter *padapter,
        skb->protocol = eth_type_trans(skb, padapter->pnetdev);
        netif_rx(skb);
        precv_frame->u.hdr.pkt = NULL; /* pointers to NULL before
-                                       * r8712_free_recvframe() */
+                                       * r8712_free_recvframe()
+                                       */
        r8712_free_recvframe(precv_frame, pfree_recv_queue);
        return;
 _recv_indicatepkt_drop:
index 007f0a3ab13d5729739d17048e78ffc4b1ed3fdb..9b9160947943de687c8ae99ff5b7c08adcd555f1 100644 (file)
@@ -62,12 +62,14 @@ static void check_hw_pbc(struct _adapter *padapter)
        tmp1byte = r8712_read8(padapter, GPIO_CTRL);
        if (tmp1byte == 0xff)
                return;
-       if (tmp1byte&HAL_8192S_HW_GPIO_WPS_BIT) {
+       if (tmp1byte & HAL_8192S_HW_GPIO_WPS_BIT) {
                /* Here we only set bPbcPressed to true
-                * After trigger PBC, the variable will be set to false */
+                * After trigger PBC, the variable will be set to false
+                */
                DBG_8712("CheckPbcGPIO - PBC is pressed !!!!\n");
                /* 0 is the default value and it means the application monitors
-                * the HW PBC doesn't provide its pid to driver. */
+                * the HW PBC doesn't provide its pid to driver.
+                */
                if (padapter->pid == 0)
                        return;
                kill_pid(find_vpid(padapter->pid), SIGUSR1, 1);
@@ -76,13 +78,14 @@ static void check_hw_pbc(struct _adapter *padapter)
 
 /* query rx phy status from fw.
  * Adhoc mode: beacon.
- * Infrastructure mode: beacon , data. */
+ * Infrastructure mode: beacon , data.
+ */
 static void query_fw_rx_phy_status(struct _adapter *padapter)
 {
        u32 val32 = 0;
        int pollingcnts = 50;
 
-       if (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == true) {
+       if (check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
                r8712_write32(padapter, IOCMD_CTRL_REG, 0xf4000001);
                msleep(100);
                /* Wait FW complete IO Cmd */
@@ -257,7 +260,8 @@ static struct cmd_obj *cmd_hdl_filter(struct _adapter *padapter,
                /* Before set JoinBss_CMD to FW, driver must ensure FW is in
                 * PS_MODE_ACTIVE. Directly write rpwm to radio on and assign
                 * new pwr_mode to Driver, instead of use workitem to change
-                * state. */
+                * state.
+                */
                if (padapter->pwrctrlpriv.pwr_mode > PS_MODE_ACTIVE) {
                        padapter->pwrctrlpriv.pwr_mode = PS_MODE_ACTIVE;
                        _enter_pwrlock(&(padapter->pwrctrlpriv.lock));
@@ -320,8 +324,7 @@ int r8712_cmd_thread(void *context)
        while (1) {
                if ((_down_sema(&(pcmdpriv->cmd_queue_sema))) == _FAIL)
                        break;
-               if ((padapter->bDriverStopped == true) ||
-                   (padapter->bSurpriseRemoved == true))
+               if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
                        break;
                if (r8712_register_cmd_alive(padapter) != _SUCCESS)
                        continue;
@@ -336,14 +339,13 @@ _next:
                memset(pdesc, 0, TXDESC_SIZE);
                pcmd = cmd_hdl_filter(padapter, pcmd);
                if (pcmd) { /* if pcmd != NULL, cmd will be handled by f/w */
-                       struct dvobj_priv *pdvobj = (struct dvobj_priv *)
-                                                   &padapter->dvobjpriv;
+                       struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
                        u8 blnPending = 0;
 
                        pcmdpriv->cmd_issued_cnt++;
                        cmdsz = round_up(pcmd->cmdsz, 8);
                        wr_sz = TXDESC_SIZE + 8 + cmdsz;
-                       pdesc->txdw0 |= cpu_to_le32((wr_sz-TXDESC_SIZE) &
+                       pdesc->txdw0 |= cpu_to_le32((wr_sz - TXDESC_SIZE) &
                                                     0x0000ffff);
                        if (pdvobj->ishighspeed) {
                                if ((wr_sz % 512) == 0)
@@ -372,8 +374,8 @@ _next:
                        pcmdbuf += 2; /* 8 bytes alignment */
                        memcpy((u8 *)pcmdbuf, pcmd->parmbuf, pcmd->cmdsz);
                        while (check_cmd_fifo(padapter, wr_sz) == _FAIL) {
-                               if ((padapter->bDriverStopped == true) ||
-                                   (padapter->bSurpriseRemoved == true))
+                               if (padapter->bDriverStopped ||
+                                   padapter->bSurpriseRemoved)
                                        break;
                                msleep(100);
                                continue;
@@ -403,10 +405,12 @@ _next:
                        if (list_empty(&pcmdpriv->cmd_queue.queue)) {
                                r8712_unregister_cmd_alive(padapter);
                                continue;
-                       } else
+                       } else {
                                goto _next;
-               } else
+                       }
+               } else {
                        goto _next;
+               }
                flush_signals_thread();
        }
        /* free all cmd_obj resources */
@@ -439,20 +443,20 @@ void r8712_event_handle(struct _adapter *padapter, uint *peventbuf)
        }
        /* checking if event code is valid */
        if (evt_code >= MAX_C2HEVT) {
-               pevt_priv->event_seq = ((evt_seq+1) & 0x7f);
+               pevt_priv->event_seq = ((evt_seq + 1) & 0x7f);
                goto _abort_event_;
        } else if ((evt_code == GEN_EVT_CODE(_Survey)) &&
                   (evt_sz > sizeof(struct wlan_bssid_ex))) {
-               pevt_priv->event_seq = ((evt_seq+1)&0x7f);
+               pevt_priv->event_seq = ((evt_seq + 1) & 0x7f);
                goto _abort_event_;
        }
        /* checking if event size match the event parm size */
        if ((wlanevents[evt_code].parmsize) &&
            (wlanevents[evt_code].parmsize != evt_sz)) {
-               pevt_priv->event_seq = ((evt_seq+1)&0x7f);
+               pevt_priv->event_seq = ((evt_seq + 1) & 0x7f);
                goto _abort_event_;
        } else if ((evt_sz == 0) && (evt_code != GEN_EVT_CODE(_WPS_PBC))) {
-               pevt_priv->event_seq = ((evt_seq+1)&0x7f);
+               pevt_priv->event_seq = ((evt_seq + 1) & 0x7f);
                goto _abort_event_;
        }
        pevt_priv->event_seq++; /* update evt_seq */
index 8dffe101becf2dc4e9f67176e8a009c952f97229..b7dda903001f438163c419badeaf69db44e6c88d 100644 (file)
@@ -21,7 +21,8 @@
 #define __RTL8712_CMDCTRL_BITDEF_H__
 
 /*
- * 2. Command Control Registers         (Offset: 0x0040 - 0x004F)*/
+ * 2. Command Control Registers         (Offset: 0x0040 - 0x004F)
+ */
 /*--------------------------------------------------------------------------*/
 /*       8192S (CMD) command register bits     (Offset 0x40, 16 bits)*/
 /*--------------------------------------------------------------------------*/
index d9571699949898eb4b1aa6eaa4feaf5f7e4d633a..eaa93fbb95a30d2d72624140dc96053135c853c0 100644 (file)
@@ -39,7 +39,7 @@ static void efuse_reg_ctrl(struct _adapter *padapter, u8 bPowerOn)
 {
        u8 tmpu8 = 0;
 
-       if (true == bPowerOn) {
+       if (bPowerOn) {
                /* -----------------e-fuse pwr & clk reg ctrl ---------------
                 * Enable LDOE25 Macro Block
                 */
@@ -80,12 +80,13 @@ static u8 efuse_one_byte_read(struct _adapter *padapter, u16 addr, u8 *data)
        u8 tmpidx = 0, bResult;
 
        /* -----------------e-fuse reg ctrl --------------------------------- */
-       r8712_write8(padapter, EFUSE_CTRL+1, (u8)(addr&0xFF)); /* address */
-       r8712_write8(padapter, EFUSE_CTRL+2, ((u8)((addr>>8)&0x03)) |
-              (r8712_read8(padapter, EFUSE_CTRL+2)&0xFC));
-       r8712_write8(padapter, EFUSE_CTRL+3, 0x72); /* read cmd */
+       r8712_write8(padapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
+       r8712_write8(padapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
+              (r8712_read8(padapter, EFUSE_CTRL + 2) & 0xFC));
+       r8712_write8(padapter, EFUSE_CTRL + 3, 0x72); /* read cmd */
        /* wait for complete */
-       while (!(0x80 & r8712_read8(padapter, EFUSE_CTRL+3)) && (tmpidx < 100))
+       while (!(0x80 & r8712_read8(padapter, EFUSE_CTRL + 3)) &&
+              (tmpidx < 100))
                tmpidx++;
        if (tmpidx < 100) {
                *data = r8712_read8(padapter, EFUSE_CTRL);
@@ -102,13 +103,14 @@ static u8 efuse_one_byte_write(struct _adapter *padapter, u16 addr, u8 data)
        u8 tmpidx = 0, bResult;
 
        /* -----------------e-fuse reg ctrl -------------------------------- */
-       r8712_write8(padapter, EFUSE_CTRL+1, (u8)(addr&0xFF)); /* address */
-       r8712_write8(padapter, EFUSE_CTRL+2, ((u8)((addr>>8)&0x03)) |
-              (r8712_read8(padapter, EFUSE_CTRL+2)&0xFC));
+       r8712_write8(padapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
+       r8712_write8(padapter, EFUSE_CTRL + 2, ((u8)((addr >> 8) & 0x03)) |
+              (r8712_read8(padapter, EFUSE_CTRL + 2) & 0xFC));
        r8712_write8(padapter, EFUSE_CTRL, data); /* data */
-       r8712_write8(padapter, EFUSE_CTRL+3, 0xF2); /* write cmd */
+       r8712_write8(padapter, EFUSE_CTRL + 3, 0xF2); /* write cmd */
        /* wait for complete */
-       while ((0x80 &  r8712_read8(padapter, EFUSE_CTRL+3)) && (tmpidx < 100))
+       while ((0x80 &  r8712_read8(padapter, EFUSE_CTRL + 3)) &&
+              (tmpidx < 100))
                tmpidx++;
        if (tmpidx < 100)
                bResult = true;
@@ -123,13 +125,13 @@ static u8 efuse_one_byte_rw(struct _adapter *padapter, u8 bRead, u16 addr,
        u8 tmpidx = 0, tmpv8 = 0, bResult;
 
        /* -----------------e-fuse reg ctrl --------------------------------- */
-       r8712_write8(padapter, EFUSE_CTRL+1, (u8)(addr&0xFF)); /* address */
+       r8712_write8(padapter, EFUSE_CTRL + 1, (u8)(addr & 0xFF)); /* address */
        tmpv8 = ((u8)((addr >> 8) & 0x03)) |
                 (r8712_read8(padapter, EFUSE_CTRL + 2) & 0xFC);
-       r8712_write8(padapter, EFUSE_CTRL+2, tmpv8);
-       if (true == bRead) {
-               r8712_write8(padapter, EFUSE_CTRL+3,  0x72); /* read cmd */
-               while (!(0x80 & r8712_read8(padapter, EFUSE_CTRL+3)) &&
+       r8712_write8(padapter, EFUSE_CTRL + 2, tmpv8);
+       if (bRead) {
+               r8712_write8(padapter, EFUSE_CTRL + 3,  0x72); /* read cmd */
+               while (!(0x80 & r8712_read8(padapter, EFUSE_CTRL + 3)) &&
                       (tmpidx < 100))
                        tmpidx++;
                if (tmpidx < 100) {
@@ -141,8 +143,8 @@ static u8 efuse_one_byte_rw(struct _adapter *padapter, u8 bRead, u16 addr,
                }
        } else {
                r8712_write8(padapter, EFUSE_CTRL, *data); /* data */
-               r8712_write8(padapter, EFUSE_CTRL+3, 0xF2); /* write cmd */
-               while ((0x80 & r8712_read8(padapter, EFUSE_CTRL+3)) &&
+               r8712_write8(padapter, EFUSE_CTRL + 3, 0xF2); /* write cmd */
+               while ((0x80 & r8712_read8(padapter, EFUSE_CTRL + 3)) &&
                       (tmpidx < 100))
                        tmpidx++;
                if (tmpidx < 100)
@@ -158,13 +160,14 @@ static u8 efuse_is_empty(struct _adapter *padapter, u8 *empty)
        u8 value, ret = true;
 
        /* read one byte to check if E-Fuse is empty */
-       if (efuse_one_byte_rw(padapter, true, 0, &value) == true) {
+       if (efuse_one_byte_rw(padapter, true, 0, &value)) {
                if (0xFF == value)
                        *empty = true;
                else
                        *empty = false;
-       } else
+       } else {
                ret = false;
+       }
        return ret;
 }
 
@@ -207,7 +210,7 @@ static void pgpacket_copy_data(const u8 word_en, const u8 *sourdata,
        u8 word_idx, byte_idx;
 
        for (word_idx = 0; word_idx < PGPKG_MAX_WORDS; word_idx++) {
-               if (!(word_en&BIT(word_idx))) {
+               if (!(word_en & BIT(word_idx))) {
                        byte_idx = word_idx * 2;
                        targetdata[byte_idx] = sourdata[tmpindex++];
                        targetdata[byte_idx + 1] = sourdata[tmpindex++];
@@ -229,8 +232,9 @@ u16 r8712_efuse_get_current_size(struct _adapter *padapter)
                        word_cnts = calculate_word_cnts(hworden);
                        /* read next header */
                        efuse_addr = efuse_addr + (word_cnts * 2) + 1;
-               } else
+               } else {
                        bContinual = false;
+               }
        }
        return efuse_addr;
 }
@@ -248,10 +252,9 @@ u8 r8712_efuse_pg_packet_read(struct _adapter *padapter, u8 offset, u8 *data)
                return false;
        if (offset > 0x0f)
                return false;
-       memset(data, 0xFF, sizeof(u8)*PGPKT_DATA_SIZE);
+       memset(data, 0xFF, sizeof(u8) * PGPKT_DATA_SIZE);
        while (efuse_addr < efuse_available_max_size) {
-               if (efuse_one_byte_read(padapter, efuse_addr, &efuse_data) ==
-                   true) {
+               if (efuse_one_byte_read(padapter, efuse_addr, &efuse_data)) {
                        if (efuse_data == 0xFF)
                                break;
                        hoffset = (efuse_data >> 4) & 0x0F;
@@ -262,15 +265,16 @@ u8 r8712_efuse_pg_packet_read(struct _adapter *padapter, u8 offset, u8 *data)
                                for (tmpidx = 0; tmpidx < word_cnts * 2;
                                     tmpidx++) {
                                        if (efuse_one_byte_read(padapter,
-                                           efuse_addr+1+tmpidx, &efuse_data) ==
-                                            true) {
+                                           efuse_addr + 1 + tmpidx,
+                                           &efuse_data)) {
                                                tmpdata[tmpidx] = efuse_data;
-                                       } else
+                                       } else {
                                                ret = false;
+                                       }
                                }
                                pgpacket_copy_data(hworden, tmpdata, data);
                        }
-                       efuse_addr += 1 + (word_cnts*2);
+                       efuse_addr += 1 + (word_cnts * 2);
                } else {
                        ret = false;
                        break;
@@ -295,14 +299,14 @@ static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
        /* retrieve original data */
        addr = 0;
        while (addr < header_addr) {
-               if (efuse_one_byte_read(padapter, addr++, &value) == false) {
+               if (!efuse_one_byte_read(padapter, addr++, &value)) {
                        ret = false;
                        break;
                }
                offset = GET_EFUSE_OFFSET(value);
                word_en = GET_EFUSE_WORD_EN(value);
                if (pkt.offset != offset) {
-                       addr += calculate_word_cnts(word_en)*2;
+                       addr += calculate_word_cnts(word_en) * 2;
                        continue;
                }
                for (i = 0; i < PGPKG_MAX_WORDS; i++) {
@@ -310,15 +314,15 @@ static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
                                if (BIT(i) & pkt.word_en) {
                                        if (efuse_one_byte_read(
                                                        padapter, addr,
-                                                       &value) == true)
-                                               pkt.data[i*2] = value;
+                                                       &value))
+                                               pkt.data[i * 2] = value;
                                        else
                                                return false;
                                        if (efuse_one_byte_read(
                                                        padapter,
                                                        addr + 1,
-                                                       &value) == true)
-                                               pkt.data[i*2 + 1] =
+                                                       &value))
+                                               pkt.data[i * 2 + 1] =
                                                        value;
                                        else
                                                return false;
@@ -333,27 +337,26 @@ static u8 fix_header(struct _adapter *padapter, u8 header, u16 header_addr)
        /* fill original data */
        for (i = 0; i < PGPKG_MAX_WORDS; i++) {
                if (BIT(i) & pkt.word_en) {
-                       efuse_one_byte_write(padapter, addr, pkt.data[i*2]);
-                       efuse_one_byte_write(padapter, addr+1,
-                                       pkt.data[i*2 + 1]);
+                       efuse_one_byte_write(padapter, addr, pkt.data[i * 2]);
+                       efuse_one_byte_write(padapter, addr + 1,
+                                            pkt.data[i * 2 + 1]);
                        /* additional check */
-                       if (efuse_one_byte_read(padapter, addr, &value)
-                               == false)
+                       if (!efuse_one_byte_read(padapter, addr, &value)) {
                                ret = false;
-                       else if (pkt.data[i*2] != value) {
+                       } else if (pkt.data[i * 2] != value) {
                                ret = false;
                                if (0xFF == value) /* write again */
                                        efuse_one_byte_write(padapter, addr,
                                                        pkt.data[i * 2]);
                        }
-                       if (efuse_one_byte_read(padapter, addr+1, &value) ==
-                               false)
+                       if (!efuse_one_byte_read(padapter, addr + 1, &value)) {
                                ret = false;
-                       else if (pkt.data[i*2 + 1] != value) {
+                       } else if (pkt.data[i * 2 + 1] != value) {
                                ret = false;
                                if (0xFF == value) /* write again */
-                                       efuse_one_byte_write(padapter, addr+1,
-                                                       pkt.data[i*2 + 1]);
+                                       efuse_one_byte_write(padapter, addr + 1,
+                                                            pkt.data[i * 2 +
+                                                                     1]);
                        }
                }
                addr += 2;
@@ -388,8 +391,8 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
                efuse_one_byte_write(padapter, efuse_addr, pg_header); /*hdr*/
                sub_repeat = 0;
                /* check if what we read is what we write */
-               while (efuse_one_byte_read(padapter, efuse_addr,
-                                          &efuse_data) == false) {
+               while (!efuse_one_byte_read(padapter, efuse_addr,
+                                           &efuse_data)) {
                        if (++sub_repeat > _REPEAT_THRESHOLD_) {
                                bResult = false; /* continue to blind write */
                                break; /* continue to blind write */
@@ -402,14 +405,15 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
 
                        /* go to next address */
                        efuse_addr++;
-                       for (i = 0; i < target_word_cnts*2; i++) {
+                       for (i = 0; i < target_word_cnts * 2; i++) {
                                efuse_one_byte_write(padapter,
                                                     efuse_addr + i,
                                                     *(data + i));
-                               if (efuse_one_byte_read(padapter,
-                                   efuse_addr + i, &efuse_data) == false)
+                               if (!efuse_one_byte_read(padapter,
+                                                        efuse_addr + i,
+                                                        &efuse_data))
                                        bResult = false;
-                               else if (*(data+i) != efuse_data) /* fail */
+                               else if (*(data + i) != efuse_data) /* fail */
                                        bResult = false;
                        }
                        break;
@@ -437,10 +441,10 @@ u8 r8712_efuse_access(struct _adapter *padapter, u8 bRead, u16 start_addr,
 
        if (start_addr > EFUSE_MAX_SIZE)
                return false;
-       if ((bRead == false) && ((start_addr + cnts) >
+       if (!bRead && ((start_addr + cnts) >
           efuse_available_max_size))
                return false;
-       if ((false == bRead) && (r8712_efuse_reg_init(padapter) == false))
+       if (!bRead && !r8712_efuse_reg_init(padapter))
                return false;
        /* -----------------e-fuse one byte read / write ---------------------*/
        for (i = 0; i < cnts; i++) {
@@ -450,10 +454,10 @@ u8 r8712_efuse_access(struct _adapter *padapter, u8 bRead, u16 start_addr,
                }
                res = efuse_one_byte_rw(padapter, bRead, start_addr + i,
                      data + i);
-               if ((false == bRead) && (false == res))
+               if (!bRead && !res)
                        break;
        }
-       if (false == bRead)
+       if (!bRead)
                r8712_efuse_reg_uninit(padapter);
        return res;
 }
@@ -466,8 +470,7 @@ u8 r8712_efuse_map_read(struct _adapter *padapter, u16 addr, u16 cnts, u8 *data)
 
        if ((addr + cnts) > EFUSE_MAP_MAX_SIZE)
                return false;
-       if ((efuse_is_empty(padapter, &offset) == true) && (offset ==
-            true)) {
+       if (efuse_is_empty(padapter, &offset) && offset) {
                for (i = 0; i < cnts; i++)
                        data[i] = 0xFF;
                return ret;
@@ -504,13 +507,14 @@ u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
        empty = r8712_read8(padapter, EFUSE_CLK_CTRL);
        if (empty != 0x03)
                return false;
-       if (efuse_is_empty(padapter, &empty) == true) {
-               if (true == empty)
+       if (efuse_is_empty(padapter, &empty)) {
+               if (empty)
                        memset(pktdata, 0xFF, PGPKT_DATA_SIZE);
-       } else
+       } else {
                return false;
+       }
        offset = (addr >> 3) & 0xF;
-       if (empty == false)
+       if (!empty)
                if (!r8712_efuse_pg_packet_read(padapter, offset, pktdata))
                        return false;
        word_en = 0xF;
@@ -541,8 +545,8 @@ u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
                                break;
                        }
 
-                       if ((data[idx] != pktdata[i]) || (data[idx+1] !=
-                            pktdata[i+1])) {
+                       if ((data[idx] != pktdata[i]) || (data[idx + 1] !=
+                            pktdata[i + 1])) {
                                word_en &= ~BIT(i >> 1);
                                newdata[j++] = data[idx];
                                newdata[j++] = data[idx + 1];
@@ -554,13 +558,13 @@ u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
                }
 
                if (word_en != 0xF)
-                       if (r8712_efuse_pg_packet_write(padapter, offset,
-                           word_en, newdata) == false)
+                       if (!r8712_efuse_pg_packet_write(padapter, offset,
+                                                        word_en, newdata))
                                return false;
                if (idx == cnts)
                        break;
                offset++;
-               if (empty == false)
+               if (!empty)
                        if (!r8712_efuse_pg_packet_read(padapter, offset,
                            pktdata))
                                return false;
index 138ea453d9df864ed312fb0c9e3c0b97da8d171a..44c906097530a76b6d1a52e267b44221557db0fe 100644 (file)
@@ -64,7 +64,8 @@
 
 #define                GPIOMUX_EN      BIT(3)  /* When this bit is set to "1",
                                         * GPIO PINs will switch to MAC
-                                        * GPIO Function*/
+                                        * GPIO Function
+                                        */
 #define                GPIOSEL_GPIO    0       /* UART or JTAG or pure GPIO*/
 #define                GPIOSEL_PHYDBG  1       /* PHYDBG*/
 #define                GPIOSEL_BT      2       /* BT_coex*/
index 4c51fa373b5455d8055c60b8a77bcc780b91c20b..57d5d2db3c7755035c1584b06ad27b0d1f3c9e08 100644 (file)
@@ -68,12 +68,14 @@ struct fw_priv {   /*8-bytes alignment required*/
        unsigned char signature_0;  /*0x12: CE product, 0x92: IT product*/
        unsigned char signature_1;  /*0x87: CE product, 0x81: IT product*/
        unsigned char hci_sel; /*0x81: PCI-AP, 01:PCIe, 02: 92S-U, 0x82: USB-AP,
-                           * 0x12: 72S-U, 03:SDIO*/
+                           * 0x12: 72S-U, 03:SDIO
+                           */
        unsigned char chip_version; /*the same value as register value*/
        unsigned char customer_ID_0; /*customer  ID low byte*/
        unsigned char customer_ID_1; /*customer  ID high byte*/
        unsigned char rf_config;  /*0x11:  1T1R, 0x12: 1T2R, 0x92: 1T2R turbo,
-                            * 0x22: 2T2R*/
+                            * 0x22: 2T2R
+                            */
        unsigned char usb_ep_num;  /* 4: 4EP, 6: 6EP, 11: 11EP*/
        /*--- long word 1 ----*/
        unsigned char regulatory_class_0; /*regulatory class bit map 0*/
@@ -97,7 +99,8 @@ struct fw_priv {   /*8-bytes alignment required*/
        unsigned char qos_en;    /*1: QoS enable*/
        unsigned char bw_40MHz_en;   /*1: 40MHz BW enable*/
        unsigned char AMSDU2AMPDU_en;   /*1: 4181 convert AMSDU to AMPDU,
-                                  * 0: disable*/
+                                  * 0: disable
+                                  */
        unsigned char AMPDU_en;   /*1: 11n AMPDU enable*/
        unsigned char rate_control_offload; /*1: FW offloads,0: driver handles*/
        unsigned char aggregation_offload;  /*1: FW offloads,0: driver handles*/
@@ -125,8 +128,9 @@ struct fw_priv {   /*8-bytes alignment required*/
 
 struct fw_hdr {/*8-byte alignment required*/
        unsigned short  signature;
-       unsigned short  version;        /*0x8000 ~ 0x8FFF for FPGA version,
-                                        *0x0000 ~ 0x7FFF for ASIC version,*/
+       unsigned short  version;        /* 0x8000 ~ 0x8FFF for FPGA version,
+                                        * 0x0000 ~ 0x7FFF for ASIC version,
+                                        */
        unsigned int            dmem_size;    /*define the size of boot loader*/
        unsigned int            img_IMEM_size; /*define the size of FW in IMEM*/
        unsigned int            img_SRAM_size; /*define the size of FW in SRAM*/
index 921fcffb3065cb6d6e917fcac6971cc354699092..4148d48ece622cbfd1352add58a47f8b5602a5f5 100644 (file)
@@ -36,7 +36,7 @@
 
 u8 r8712_read8(struct _adapter *adapter, u32 addr)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
        u8 (*_read8)(struct intf_hdl *pintfhdl, u32 addr);
 
@@ -46,7 +46,7 @@ u8 r8712_read8(struct _adapter *adapter, u32 addr)
 
 u16 r8712_read16(struct _adapter *adapter, u32 addr)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
        u16 (*_read16)(struct intf_hdl *pintfhdl, u32 addr);
 
@@ -56,7 +56,7 @@ u16 r8712_read16(struct _adapter *adapter, u32 addr)
 
 u32 r8712_read32(struct _adapter *adapter, u32 addr)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
        u32 (*_read32)(struct intf_hdl *pintfhdl, u32 addr);
 
@@ -66,7 +66,7 @@ u32 r8712_read32(struct _adapter *adapter, u32 addr)
 
 void r8712_write8(struct _adapter *adapter, u32 addr, u8 val)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
        void (*_write8)(struct intf_hdl *pintfhdl, u32 addr, u8 val);
 
@@ -76,7 +76,7 @@ void r8712_write8(struct _adapter *adapter, u32 addr, u8 val)
 
 void r8712_write16(struct _adapter *adapter, u32 addr, u16 val)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
        void (*_write16)(struct intf_hdl *pintfhdl, u32 addr, u16 val);
 
@@ -86,8 +86,8 @@ void r8712_write16(struct _adapter *adapter, u32 addr, u16 val)
 
 void r8712_write32(struct _adapter *adapter, u32 addr, u32 val)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
-       struct intf_hdl *pintfhdl = (struct intf_hdl *)(&(pio_queue->intf));
+       struct io_queue *pio_queue = adapter->pio_queue;
+       struct intf_hdl *pintfhdl  = &(pio_queue->intf);
 
        void (*_write32)(struct intf_hdl *pintfhdl, u32 addr, u32 val);
 
@@ -97,13 +97,12 @@ void r8712_write32(struct _adapter *adapter, u32 addr, u32 val)
 
 void r8712_read_mem(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
 
        void (*_read_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
                          u8 *pmem);
-       if ((adapter->bDriverStopped == true) ||
-           (adapter->bSurpriseRemoved == true))
+       if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
                return;
        _read_mem = pintfhdl->io_ops._read_mem;
        _read_mem(pintfhdl, addr, cnt, pmem);
@@ -111,7 +110,7 @@ void r8712_read_mem(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
 
 void r8712_write_mem(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
        void (*_write_mem)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
                           u8 *pmem);
@@ -122,13 +121,12 @@ void r8712_write_mem(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
 
 void r8712_read_port(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
 
        u32 (*_read_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
                          u8 *pmem);
-       if ((adapter->bDriverStopped == true) ||
-           (adapter->bSurpriseRemoved == true))
+       if (adapter->bDriverStopped || adapter->bSurpriseRemoved)
                return;
        _read_port = pintfhdl->io_ops._read_port;
        _read_port(pintfhdl, addr, cnt, pmem);
@@ -136,7 +134,7 @@ void r8712_read_port(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
 
 void r8712_write_port(struct _adapter *adapter, u32 addr, u32 cnt, u8 *pmem)
 {
-       struct io_queue *pio_queue = (struct io_queue *)adapter->pio_queue;
+       struct io_queue *pio_queue = adapter->pio_queue;
        struct intf_hdl *pintfhdl = &(pio_queue->intf);
 
        u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
index ada8d5dafd492e97a1b4d9457d25e4a485e67556..9055827cccf8d883d47f04e388a6530fdde7cd0c 100644 (file)
@@ -122,8 +122,7 @@ static void SwLedOn(struct _adapter *padapter, struct LED_871x *pLed)
 {
        u8      LedCfg;
 
-       if ((padapter->bSurpriseRemoved == true) ||
-           (padapter->bDriverStopped == true))
+       if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
                return;
        LedCfg = r8712_read8(padapter, LEDCFG);
        switch (pLed->LedPin) {
@@ -131,11 +130,11 @@ static void SwLedOn(struct _adapter *padapter, struct LED_871x *pLed)
                break;
        case LED_PIN_LED0:
                /* SW control led0 on.*/
-               r8712_write8(padapter, LEDCFG, LedCfg&0xf0);
+               r8712_write8(padapter, LEDCFG, LedCfg & 0xf0);
                break;
        case LED_PIN_LED1:
                /* SW control led1 on.*/
-               r8712_write8(padapter, LEDCFG, LedCfg&0x0f);
+               r8712_write8(padapter, LEDCFG, LedCfg & 0x0f);
                break;
        default:
                break;
@@ -151,8 +150,7 @@ static void SwLedOff(struct _adapter *padapter, struct LED_871x *pLed)
 {
        u8      LedCfg;
 
-       if ((padapter->bSurpriseRemoved == true) ||
-           (padapter->bDriverStopped == true))
+       if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
                return;
        LedCfg = r8712_read8(padapter, LEDCFG);
        switch (pLed->LedPin) {
@@ -160,11 +158,11 @@ static void SwLedOff(struct _adapter *padapter, struct LED_871x *pLed)
                break;
        case LED_PIN_LED0:
                LedCfg &= 0xf0; /* Set to software control.*/
-               r8712_write8(padapter, LEDCFG, (LedCfg|BIT(3)));
+               r8712_write8(padapter, LEDCFG, (LedCfg | BIT(3)));
                break;
        case LED_PIN_LED1:
                LedCfg &= 0x0f; /* Set to software control.*/
-               r8712_write8(padapter, LEDCFG, (LedCfg|BIT(7)));
+               r8712_write8(padapter, LEDCFG, (LedCfg | BIT(7)));
                break;
        default:
                break;
@@ -222,11 +220,11 @@ static void SwLedBlink(struct LED_871x *pLed)
                        bStopBlinking = true;
                break;
        case LED_BLINK_StartToBlink:
-               if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) &&
+               if (check_fwstate(pmlmepriv, _FW_LINKED) &&
                    (pmlmepriv->fw_state & WIFI_STATION_STATE))
                        bStopBlinking = true;
-               if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) &&
-                  ((pmlmepriv->fw_state & WIFI_ADHOC_STATE) ||
+               if (check_fwstate(pmlmepriv, _FW_LINKED) &&
+                   ((pmlmepriv->fw_state & WIFI_ADHOC_STATE) ||
                    (pmlmepriv->fw_state & WIFI_ADHOC_MASTER_STATE)))
                        bStopBlinking = true;
                else if (pLed->BlinkTimes == 0)
@@ -241,11 +239,10 @@ static void SwLedBlink(struct LED_871x *pLed)
                break;
        }
        if (bStopBlinking) {
-               if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) &&
-                   (pLed->bLedOn == false))
+               if (check_fwstate(pmlmepriv, _FW_LINKED) &&
+                   !pLed->bLedOn)
                        SwLedOn(padapter, pLed);
-               else if ((check_fwstate(pmlmepriv, _FW_LINKED) ==
-                        true) &&  pLed->bLedOn == true)
+               else if (check_fwstate(pmlmepriv, _FW_LINKED) &&  pLed->bLedOn)
                        SwLedOff(padapter, pLed);
                pLed->BlinkTimes = 0;
                pLed->bLedBlinkInProgress = false;
@@ -296,18 +293,20 @@ static void SwLedBlink1(struct LED_871x *pLed)
        else
                SwLedOff(padapter, pLed);
        if (peeprompriv->CustomerID == RT_CID_DEFAULT) {
-               if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+               if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                        if (!pLed1->bSWLedCtrl) {
                                SwLedOn(padapter, pLed1);
                                pLed1->bSWLedCtrl = true;
-                       } else if (!pLed1->bLedOn)
+                       } else if (!pLed1->bLedOn) {
                                SwLedOn(padapter, pLed1);
+                       }
                } else {
                        if (!pLed1->bSWLedCtrl) {
                                SwLedOff(padapter, pLed1);
                                pLed1->bSWLedCtrl = true;
-                       } else if (pLed1->bLedOn)
+                       } else if (pLed1->bLedOn) {
                                SwLedOff(padapter, pLed1);
+                       }
                }
        }
        switch (pLed->CurrLedState) {
@@ -332,7 +331,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
                if (pLed->BlinkTimes == 0)
                        bStopBlinking = true;
                if (bStopBlinking) {
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+                       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                                pLed->bLedLinkBlinkInProgress = true;
                                pLed->CurrLedState = LED_BLINK_NORMAL;
                                if (pLed->bLedOn)
@@ -366,7 +365,7 @@ static void SwLedBlink1(struct LED_871x *pLed)
                if (pLed->BlinkTimes == 0)
                        bStopBlinking = true;
                if (bStopBlinking) {
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+                       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                                pLed->bLedLinkBlinkInProgress = true;
                                pLed->CurrLedState = LED_BLINK_NORMAL;
                                if (pLed->bLedOn)
@@ -410,8 +409,9 @@ static void SwLedBlink1(struct LED_871x *pLed)
                        mod_timer(&pLed->BlinkTimer, jiffies +
                                  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
                        bStopBlinking = false;
-               } else
+               } else {
                        bStopBlinking = true;
+               }
                if (bStopBlinking) {
                        pLed->bLedLinkBlinkInProgress = true;
                        pLed->CurrLedState = LED_BLINK_NORMAL;
@@ -446,7 +446,7 @@ static void SwLedBlink2(struct LED_871x *pLed)
                if (pLed->BlinkTimes == 0)
                        bStopBlinking = true;
                if (bStopBlinking) {
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+                       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                                pLed->CurrLedState = LED_ON;
                                pLed->BlinkingLedState = LED_ON;
                                SwLedOn(padapter, pLed);
@@ -470,7 +470,7 @@ static void SwLedBlink2(struct LED_871x *pLed)
                if (pLed->BlinkTimes == 0)
                        bStopBlinking = true;
                if (bStopBlinking) {
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+                       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                                pLed->CurrLedState = LED_ON;
                                pLed->BlinkingLedState = LED_ON;
                                SwLedOn(padapter, pLed);
@@ -512,7 +512,7 @@ static void SwLedBlink3(struct LED_871x *pLed)
                if (pLed->BlinkTimes == 0)
                        bStopBlinking = true;
                if (bStopBlinking) {
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+                       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                                pLed->CurrLedState = LED_ON;
                                pLed->BlinkingLedState = LED_ON;
                                if (!pLed->bLedOn)
@@ -538,7 +538,7 @@ static void SwLedBlink3(struct LED_871x *pLed)
                if (pLed->BlinkTimes == 0)
                        bStopBlinking = true;
                if (bStopBlinking) {
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+                       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                                pLed->CurrLedState = LED_ON;
                                pLed->BlinkingLedState = LED_ON;
                                if (!pLed->bLedOn)
@@ -573,8 +573,9 @@ static void SwLedBlink3(struct LED_871x *pLed)
                        mod_timer(&pLed->BlinkTimer, jiffies +
                                  msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
                        bStopBlinking = false;
-               } else
+               } else {
                        bStopBlinking = true;
+               }
                if (bStopBlinking) {
                        pLed->CurrLedState = LED_ON;
                        pLed->BlinkingLedState = LED_ON;
@@ -827,8 +828,7 @@ static void BlinkTimerCallback(unsigned long data)
 
        /* This fixed the crash problem on Fedora 12 when trying to do the
         * insmod;ifconfig up;rmmod commands. */
-       if ((pLed->padapter->bSurpriseRemoved == true) ||
-           (pLed->padapter->bDriverStopped == true))
+       if (pLed->padapter->bSurpriseRemoved || pLed->padapter->bDriverStopped)
                return;
        schedule_work(&pLed->BlinkWorkItem);
 }
@@ -893,15 +893,15 @@ static void SwLedControlMode1(struct _adapter *padapter,
        switch (LedAction) {
        case LED_CTL_START_TO_LINK:
        case LED_CTL_NO_LINK:
-               if (pLed->bLedNoLinkBlinkInProgress == false) {
+               if (!pLed->bLedNoLinkBlinkInProgress) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                          IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedLinkBlinkInProgress == true) {
+                       if (pLed->bLedLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -916,15 +916,15 @@ static void SwLedControlMode1(struct _adapter *padapter,
                }
                break;
        case LED_CTL_LINK:
-               if (pLed->bLedLinkBlinkInProgress == false) {
+               if (!pLed->bLedLinkBlinkInProgress) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                            IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -939,21 +939,21 @@ static void SwLedControlMode1(struct _adapter *padapter,
                }
                break;
        case LED_CTL_SITE_SURVEY:
-               if ((psitesurveyctrl->traffic_busy) &&
-                   (check_fwstate(pmlmepriv, _FW_LINKED) == true))
+               if (psitesurveyctrl->traffic_busy &&
+                   check_fwstate(pmlmepriv, _FW_LINKED))
                        ; /* dummy branch */
-                else if (pLed->bLedScanBlinkInProgress == false) {
+                else if (!pLed->bLedScanBlinkInProgress) {
                        if (IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedLinkBlinkInProgress == true) {
+                       if (pLed->bLedLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                 pLed->bLedLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -970,15 +970,15 @@ static void SwLedControlMode1(struct _adapter *padapter,
                break;
        case LED_CTL_TX:
        case LED_CTL_RX:
-               if (pLed->bLedBlinkInProgress == false) {
+               if (!pLed->bLedBlinkInProgress) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                            IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedLinkBlinkInProgress == true) {
+                       if (pLed->bLedLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedLinkBlinkInProgress = false;
                        }
@@ -996,20 +996,20 @@ static void SwLedControlMode1(struct _adapter *padapter,
 
        case LED_CTL_START_WPS: /*wait until xinpin finish */
        case LED_CTL_START_WPS_BOTTON:
-                if (pLed->bLedWPSBlinkInProgress == false) {
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+                if (!pLed->bLedWPSBlinkInProgress) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedLinkBlinkInProgress == true) {
+                       if (pLed->bLedLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                 pLed->bLedLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
-                       if (pLed->bLedScanBlinkInProgress == true) {
+                       if (pLed->bLedScanBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedScanBlinkInProgress = false;
                        }
@@ -1024,19 +1024,19 @@ static void SwLedControlMode1(struct _adapter *padapter,
                }
                break;
        case LED_CTL_STOP_WPS:
-               if (pLed->bLedNoLinkBlinkInProgress == true) {
+               if (pLed->bLedNoLinkBlinkInProgress) {
                        del_timer(&pLed->BlinkTimer);
                        pLed->bLedNoLinkBlinkInProgress = false;
                }
-               if (pLed->bLedLinkBlinkInProgress == true) {
+               if (pLed->bLedLinkBlinkInProgress) {
                        del_timer(&pLed->BlinkTimer);
                         pLed->bLedLinkBlinkInProgress = false;
                }
-               if (pLed->bLedBlinkInProgress == true) {
+               if (pLed->bLedBlinkInProgress) {
                        del_timer(&pLed->BlinkTimer);
                        pLed->bLedBlinkInProgress = false;
                }
-               if (pLed->bLedScanBlinkInProgress == true) {
+               if (pLed->bLedScanBlinkInProgress) {
                        del_timer(&pLed->BlinkTimer);
                        pLed->bLedScanBlinkInProgress = false;
                }
@@ -1111,11 +1111,11 @@ static void SwLedControlMode2(struct _adapter *padapter,
        case LED_CTL_SITE_SURVEY:
                 if (pmlmepriv->sitesurveyctrl.traffic_busy)
                        ; /* dummy branch */
-                else if (pLed->bLedScanBlinkInProgress == false) {
+                else if (!pLed->bLedScanBlinkInProgress) {
                        if (IS_LED_WPS_BLINKING(pLed))
                                return;
 
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -1133,8 +1133,8 @@ static void SwLedControlMode2(struct _adapter *padapter,
 
        case LED_CTL_TX:
        case LED_CTL_RX:
-               if ((pLed->bLedBlinkInProgress == false) &&
-                  (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
+               if (!pLed->bLedBlinkInProgress &&
+                   check_fwstate(pmlmepriv, _FW_LINKED)) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                           IS_LED_WPS_BLINKING(pLed))
                                return;
@@ -1168,12 +1168,12 @@ static void SwLedControlMode2(struct _adapter *padapter,
 
        case LED_CTL_START_WPS: /*wait until xinpin finish*/
        case LED_CTL_START_WPS_BOTTON:
-               if (pLed->bLedWPSBlinkInProgress == false) {
-                       if (pLed->bLedBlinkInProgress == true) {
+               if (!pLed->bLedWPSBlinkInProgress) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
-                       if (pLed->bLedScanBlinkInProgress == true) {
+                       if (pLed->bLedScanBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedScanBlinkInProgress = false;
                        }
@@ -1244,10 +1244,10 @@ static void SwLedControlMode3(struct _adapter *padapter,
        case LED_CTL_SITE_SURVEY:
                if (pmlmepriv->sitesurveyctrl.traffic_busy)
                        ; /* dummy branch */
-               else if (pLed->bLedScanBlinkInProgress == false) {
+               else if (!pLed->bLedScanBlinkInProgress) {
                        if (IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -1264,8 +1264,8 @@ static void SwLedControlMode3(struct _adapter *padapter,
                break;
        case LED_CTL_TX:
        case LED_CTL_RX:
-               if ((pLed->bLedBlinkInProgress == false) &&
-                   (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
+               if (!pLed->bLedBlinkInProgress &&
+                   check_fwstate(pmlmepriv, _FW_LINKED)) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                            IS_LED_WPS_BLINKING(pLed))
                                return;
@@ -1298,12 +1298,12 @@ static void SwLedControlMode3(struct _adapter *padapter,
                break;
        case LED_CTL_START_WPS: /* wait until xinpin finish */
        case LED_CTL_START_WPS_BOTTON:
-               if (pLed->bLedWPSBlinkInProgress == false) {
-                       if (pLed->bLedBlinkInProgress == true) {
+               if (!pLed->bLedWPSBlinkInProgress) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
-                       if (pLed->bLedScanBlinkInProgress == true) {
+                       if (pLed->bLedScanBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedScanBlinkInProgress = false;
                        }
@@ -1321,8 +1321,9 @@ static void SwLedControlMode3(struct _adapter *padapter,
                if (pLed->bLedWPSBlinkInProgress) {
                        del_timer(&pLed->BlinkTimer);
                        pLed->bLedWPSBlinkInProgress = false;
-               } else
+               } else {
                        pLed->bLedWPSBlinkInProgress = true;
+               }
                pLed->CurrLedState = LED_BLINK_WPS_STOP;
                if (pLed->bLedOn) {
                        pLed->BlinkingLedState = LED_OFF;
@@ -1395,15 +1396,15 @@ static void SwLedControlMode4(struct _adapter *padapter,
                                mod_timer(&pLed->BlinkTimer,
                                          jiffies + msecs_to_jiffies(0));
                }
-               if (pLed->bLedStartToLinkBlinkInProgress == false) {
+               if (!pLed->bLedStartToLinkBlinkInProgress) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                            IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
@@ -1434,11 +1435,11 @@ static void SwLedControlMode4(struct _adapter *padapter,
                                                  jiffies + msecs_to_jiffies(0));
                        }
                }
-               if (pLed->bLedNoLinkBlinkInProgress == false) {
+               if (!pLed->bLedNoLinkBlinkInProgress) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                            IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -1453,17 +1454,17 @@ static void SwLedControlMode4(struct _adapter *padapter,
                }
                break;
        case LED_CTL_SITE_SURVEY:
-               if ((pmlmepriv->sitesurveyctrl.traffic_busy) &&
-                   (check_fwstate(pmlmepriv, _FW_LINKED) == true))
+               if (pmlmepriv->sitesurveyctrl.traffic_busy &&
+                   check_fwstate(pmlmepriv, _FW_LINKED))
                        ;
-               else if (pLed->bLedScanBlinkInProgress == false) {
+               else if (!pLed->bLedScanBlinkInProgress) {
                        if (IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -1480,11 +1481,11 @@ static void SwLedControlMode4(struct _adapter *padapter,
                break;
        case LED_CTL_TX:
        case LED_CTL_RX:
-               if (pLed->bLedBlinkInProgress == false) {
+               if (!pLed->bLedBlinkInProgress) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK ||
                            IS_LED_WPS_BLINKING(pLed))
                                return;
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
@@ -1510,16 +1511,16 @@ static void SwLedControlMode4(struct _adapter *padapter,
                                mod_timer(&pLed->BlinkTimer,
                                          jiffies + msecs_to_jiffies(0));
                }
-               if (pLed->bLedWPSBlinkInProgress == false) {
-                       if (pLed->bLedNoLinkBlinkInProgress == true) {
+               if (!pLed->bLedWPSBlinkInProgress) {
+                       if (pLed->bLedNoLinkBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedNoLinkBlinkInProgress = false;
                        }
-                       if (pLed->bLedBlinkInProgress == true) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
-                       if (pLed->bLedScanBlinkInProgress == true) {
+                       if (pLed->bLedScanBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedScanBlinkInProgress = false;
                        }
@@ -1666,11 +1667,11 @@ static void SwLedControlMode5(struct _adapter *padapter,
                          jiffies + msecs_to_jiffies(0));
                break;
        case LED_CTL_SITE_SURVEY:
-               if ((pmlmepriv->sitesurveyctrl.traffic_busy) &&
-                   (check_fwstate(pmlmepriv, _FW_LINKED) == true))
+               if (pmlmepriv->sitesurveyctrl.traffic_busy &&
+                   check_fwstate(pmlmepriv, _FW_LINKED))
                        ; /* dummy branch */
-               else if (pLed->bLedScanBlinkInProgress == false) {
-                       if (pLed->bLedBlinkInProgress == true) {
+               else if (!pLed->bLedScanBlinkInProgress) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -1687,7 +1688,7 @@ static void SwLedControlMode5(struct _adapter *padapter,
                break;
        case LED_CTL_TX:
        case LED_CTL_RX:
-               if (pLed->bLedBlinkInProgress == false) {
+               if (!pLed->bLedBlinkInProgress) {
                        if (pLed->CurrLedState == LED_SCAN_BLINK)
                                return;
                        pLed->bLedBlinkInProgress = true;
@@ -1737,8 +1738,8 @@ static void SwLedControlMode6(struct _adapter *padapter,
                break;
        case LED_CTL_TX:
        case LED_CTL_RX:
-               if (pLed->bLedBlinkInProgress == false &&
-                  (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
+               if (!pLed->bLedBlinkInProgress &&
+                   check_fwstate(pmlmepriv, _FW_LINKED)) {
                        if (IS_LED_WPS_BLINKING(pLed))
                                return;
                        pLed->bLedBlinkInProgress = true;
@@ -1754,8 +1755,8 @@ static void SwLedControlMode6(struct _adapter *padapter,
                break;
        case LED_CTL_START_WPS: /*wait until xinpin finish*/
        case LED_CTL_START_WPS_BOTTON:
-               if (pLed->bLedWPSBlinkInProgress == false) {
-                       if (pLed->bLedBlinkInProgress == true) {
+               if (!pLed->bLedWPSBlinkInProgress) {
+                       if (pLed->bLedBlinkInProgress) {
                                del_timer(&pLed->BlinkTimer);
                                pLed->bLedBlinkInProgress = false;
                        }
@@ -1805,7 +1806,7 @@ void LedControl871x(struct _adapter *padapter, enum LED_CTL_MODE LedAction)
 {
        struct led_priv *ledpriv = &(padapter->ledpriv);
 
-       if (ledpriv->bRegUseLed == false)
+       if (!ledpriv->bRegUseLed)
                return;
        switch (ledpriv->LedStrategy) {
        case SW_LED_MODE0:
index 4fa2540a6c3470c29cb364ef89372f1d583ab083..d187508dd1e0af956454d07b31f8bd4a1a176af5 100644 (file)
@@ -89,7 +89,7 @@ int r8712_init_recv_priv(struct recv_priv *precvpriv, struct _adapter *padapter)
                       RECVBUFF_ALIGN_SZ);
                if (pskb) {
                        tmpaddr = (addr_t)pskb->data;
-                       alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
+                       alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
                        skb_reserve(pskb, (RECVBUFF_ALIGN_SZ - alignment));
                        skb_queue_tail(&precvpriv->free_recv_skb_queue, pskb);
                }
@@ -158,9 +158,9 @@ int r8712_free_recvframe(union recv_frame *precvframe,
 static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib,
                                           struct recv_stat *prxstat)
 {
-       u16 drvinfo_sz = 0;
+       u16 drvinfo_sz;
 
-       drvinfo_sz = (le32_to_cpu(prxstat->rxdw0)&0x000f0000)>>16;
+       drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16;
        drvinfo_sz <<= 3;
        /*TODO:
         * Offset 0 */
@@ -180,8 +180,9 @@ static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib,
                        pattrib->ip_chkrpt = 1; /* correct */
                else
                        pattrib->ip_chkrpt = 0; /* incorrect */
-       } else
+       } else {
                pattrib->tcpchk_valid = 0; /* invalid */
+       }
        pattrib->mcs_rate = (u8)((le32_to_cpu(prxstat->rxdw3)) & 0x3f);
        pattrib->htc = (u8)((le32_to_cpu(prxstat->rxdw3) >> 14) & 0x1);
        /*Offset 16*/
@@ -217,7 +218,7 @@ static union recv_frame *recvframe_defrag(struct _adapter *adapter,
        curfragnum++;
        plist = &defrag_q->queue;
        plist = plist->next;
-       while (end_of_queue_search(phead, plist) == false) {
+       while (!end_of_queue_search(phead, plist)) {
                pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u);
                pnfhdr = &pnextrframe->u.hdr;
                /*check the fragment sequence  (2nd ~n fragment frame) */
@@ -414,8 +415,9 @@ static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe)
                        if ((pattrib->tcpchk_valid == 1) &&
                            (pattrib->tcp_chkrpt == 1)) {
                                sub_skb->ip_summed = CHECKSUM_UNNECESSARY;
-                       } else
+                       } else {
                                sub_skb->ip_summed = CHECKSUM_NONE;
+                       }
                        netif_rx(sub_skb);
                }
        }
@@ -489,7 +491,7 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 
        phead = &ppending_recvframe_queue->queue;
        plist = phead->next;
-       while (end_of_queue_search(phead, plist) == false) {
+       while (!end_of_queue_search(phead, plist)) {
                pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u);
                pnextattrib = &pnextrframe->u.hdr.attrib;
                if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
@@ -519,7 +521,7 @@ int r8712_recv_indicatepkts_in_order(struct _adapter *padapter,
        phead = &ppending_recvframe_queue->queue;
        plist = phead->next;
        /* Handling some condition for forced indicate case.*/
-       if (bforced == true) {
+       if (bforced) {
                if (list_empty(phead))
                        return true;
 
@@ -541,8 +543,8 @@ int r8712_recv_indicatepkts_in_order(struct _adapter *padapter,
                                  (preorder_ctrl->indicate_seq + 1) % 4096;
                        /*indicate this recv_frame*/
                        if (!pattrib->amsdu) {
-                               if ((padapter->bDriverStopped == false) &&
-                                   (padapter->bSurpriseRemoved == false)) {
+                               if (!padapter->bDriverStopped &&
+                                   !padapter->bSurpriseRemoved) {
                                        /* indicate this recv_frame */
                                        r8712_recv_indicatepkt(padapter,
                                                               prframe);
@@ -576,12 +578,13 @@ static int recv_indicatepkt_reorder(struct _adapter *padapter,
                /* s1. */
                r8712_wlanhdr_to_ethhdr(prframe);
                if (pattrib->qos != 1) {
-                       if ((padapter->bDriverStopped == false) &&
-                          (padapter->bSurpriseRemoved == false)) {
+                       if (!padapter->bDriverStopped &&
+                           !padapter->bSurpriseRemoved) {
                                r8712_recv_indicatepkt(padapter, prframe);
                                return _SUCCESS;
-                       } else
+                       } else {
                                return _FAIL;
+                       }
                }
        }
        spin_lock_irqsave(&ppending_recvframe_queue->lock, irql);
@@ -643,20 +646,20 @@ static int r8712_process_recv_indicatepkts(struct _adapter *padapter,
        if (phtpriv->ht_option == 1) { /*B/G/N Mode*/
                if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS) {
                        /* including perform A-MPDU Rx Ordering Buffer Control*/
-                       if ((padapter->bDriverStopped == false) &&
-                           (padapter->bSurpriseRemoved == false))
+                       if (!padapter->bDriverStopped &&
+                           !padapter->bSurpriseRemoved)
                                return _FAIL;
                }
        } else { /*B/G mode*/
                retval = r8712_wlanhdr_to_ethhdr(prframe);
                if (retval != _SUCCESS)
                        return retval;
-               if ((padapter->bDriverStopped == false) &&
-                   (padapter->bSurpriseRemoved == false)) {
+               if (!padapter->bDriverStopped && !padapter->bSurpriseRemoved) {
                        /* indicate this recv_frame */
                        r8712_recv_indicatepkt(padapter, prframe);
-               } else
+               } else {
                        return _FAIL;
+               }
        }
        return retval;
 }
@@ -813,16 +816,16 @@ static void query_rx_phy_status(struct _adapter *padapter,
                /*
                 * (3) Get Signal Quality (EVM)
                 */
-               if (pwdb_all > 40)
+               if (pwdb_all > 40) {
                        sq = 100;
-               else {
+               else {
                        sq = pcck_buf->sq_rpt;
                        if (pcck_buf->sq_rpt > 64)
                                sq = 0;
                        else if (pcck_buf->sq_rpt < 20)
                                sq = 100;
                        else
-                               sq = ((64-sq) * 100) / 44;
+                               sq = ((64 - sq) * 100) / 44;
                }
                prframe->u.hdr.attrib.signal_qual = sq;
                prframe->u.hdr.attrib.rx_mimo_signal_qual[0] = sq;
@@ -962,12 +965,12 @@ int recv_func(struct _adapter *padapter, void *pcontext)
        prframe = (union recv_frame *)pcontext;
        orig_prframe = prframe;
        pattrib = &prframe->u.hdr.attrib;
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
+       if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
                if (pattrib->crc_err == 1)
                        padapter->mppriv.rx_crcerrpktcount++;
                else
                        padapter->mppriv.rx_pktcount++;
-               if (check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE) == false) {
+               if (!check_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE)) {
                        /* free this recv_frame */
                        r8712_free_recvframe(orig_prframe, pfree_recv_queue);
                        goto _exit_recv_func;
@@ -1019,8 +1022,8 @@ static int recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
        pfree_recv_queue = &(precvpriv->free_recv_queue);
        pbuf = pskb->data;
        prxstat = (struct recv_stat *)pbuf;
-       pkt_cnt = (le32_to_cpu(prxstat->rxdw2)>>16)&0xff;
-       pkt_len =  le32_to_cpu(prxstat->rxdw0)&0x00003fff;
+       pkt_cnt = (le32_to_cpu(prxstat->rxdw2) >> 16) & 0xff;
+       pkt_len =  le32_to_cpu(prxstat->rxdw0) & 0x00003fff;
        transfer_len = pskb->len;
        /* Test throughput with Netgear 3700 (No security) with Chariot 3T3R
         * pairs. The packet count will be a big number so that the containing
@@ -1032,7 +1035,7 @@ static int recvbuf2recvframe(struct _adapter *padapter, struct sk_buff *pskb)
        }
        do {
                prxstat = (struct recv_stat *)pbuf;
-               pkt_len =  le32_to_cpu(prxstat->rxdw0)&0x00003fff;
+               pkt_len =  le32_to_cpu(prxstat->rxdw0) & 0x00003fff;
                /* more fragment bit */
                mf = (le32_to_cpu(prxstat->rxdw1) >> 27) & 0x1;
                /* ragmentation number */
index 86206d34a40e1044ed7270abc15130bea3494e88..b21a60e9f8a9b9d7e30b405f93c986ca70f1d62d 100644 (file)
@@ -96,13 +96,13 @@ static u32 get_ff_hwaddr(struct xmit_frame *pxmitframe)
        u32 addr = 0;
        struct pkt_attrib *pattrib = &pxmitframe->attrib;
        struct _adapter *padapter = pxmitframe->padapter;
-       struct dvobj_priv *pdvobj = (struct dvobj_priv *)&padapter->dvobjpriv;
+       struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
 
-       if (pxmitframe->frame_tag == TXAGG_FRAMETAG)
+       if (pxmitframe->frame_tag == TXAGG_FRAMETAG) {
                addr = RTL8712_DMA_H2CCMD;
-       else if (pxmitframe->frame_tag == MGNT_FRAMETAG)
+       } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
                addr = RTL8712_DMA_MGTQ;
-       else if (pdvobj->nr_endpoint == 6) {
+       else if (pdvobj->nr_endpoint == 6) {
                switch (pattrib->priority) {
                case 0:
                case 3:
@@ -168,7 +168,7 @@ static struct xmit_frame *dequeue_one_xmitframe(struct xmit_priv *pxmitpriv,
 
        xmitframe_phead = &pframe_queue->queue;
        xmitframe_plist = xmitframe_phead->next;
-       if ((end_of_queue_search(xmitframe_phead, xmitframe_plist)) == false) {
+       if (!end_of_queue_search(xmitframe_phead, xmitframe_plist)) {
                pxmitframe = LIST_CONTAINOR(xmitframe_plist,
                             struct xmit_frame, list);
                list_del_init(&pxmitframe->list);
@@ -208,7 +208,7 @@ static struct xmit_frame *dequeue_xframe_ex(struct xmit_priv *pxmitpriv,
                phwxmit = phwxmit_i + inx[i];
                sta_phead = &phwxmit->sta_queue->queue;
                sta_plist = sta_phead->next;
-               while ((end_of_queue_search(sta_phead, sta_plist)) == false) {
+               while (!end_of_queue_search(sta_phead, sta_plist)) {
                        ptxservq = LIST_CONTAINOR(sta_plist, struct tx_servq,
                                  tx_pending);
                        pframe_queue = &ptxservq->sta_pending;
@@ -237,11 +237,11 @@ void r8712_do_queue_select(struct _adapter *padapter,
                           struct pkt_attrib *pattrib)
 {
        unsigned int qsel = 0;
-       struct dvobj_priv *pdvobj = (struct dvobj_priv *)&padapter->dvobjpriv;
+       struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
 
-       if (pdvobj->nr_endpoint == 6)
+       if (pdvobj->nr_endpoint == 6) {
                qsel = (unsigned int) pattrib->priority;
-       else if (pdvobj->nr_endpoint == 4) {
+       else if (pdvobj->nr_endpoint == 4) {
                qsel = (unsigned int) pattrib->priority;
                if (qsel == 0 || qsel == 3)
                        qsel = 3;
@@ -264,13 +264,14 @@ u8 r8712_construct_txaggr_cmd_desc(struct xmit_buf *pxmitbuf)
 
        /* Fill up TxCmd Descriptor according as USB FW Tx Aaggregation info.*/
        /* dw0 */
-       ptx_desc->txdw0 = cpu_to_le32(CMD_HDR_SZ&0xffff);
+       ptx_desc->txdw0 = cpu_to_le32(CMD_HDR_SZ & 0xffff);
        ptx_desc->txdw0 |=
-               cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ)<<OFFSET_SHT)&0x00ff0000);
+               cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) &
+                           0x00ff0000);
        ptx_desc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
 
        /* dw1 */
-       ptx_desc->txdw1 |= cpu_to_le32((0x13<<QSEL_SHT)&0x00001f00);
+       ptx_desc->txdw1 |= cpu_to_le32((0x13 << QSEL_SHT) & 0x00001f00);
 
        return _SUCCESS;
 }
@@ -322,12 +323,14 @@ u8 r8712_append_mpdu_unit(struct xmit_buf *pxmitbuf,
                int i;
 
                for (i = 0; i < padding_sz; i++)
-                       *(pxmitframe->buf_addr+TXDESC_SIZE+last_txcmdsz+i) = 0;
+                       *(pxmitframe->buf_addr + TXDESC_SIZE + last_txcmdsz +
+                         i) = 0;
        }
        /* Add the new mpdu's length */
-       ptx_desc->txdw0 = cpu_to_le32((ptx_desc->txdw0&0xffff0000) |
-               ((ptx_desc->txdw0&0x0000ffff)+
-                       ((TXDESC_SIZE+last_txcmdsz+padding_sz)&0x0000ffff)));
+       ptx_desc->txdw0 = cpu_to_le32((ptx_desc->txdw0 & 0xffff0000) |
+               ((ptx_desc->txdw0 & 0x0000ffff) +
+                       ((TXDESC_SIZE + last_txcmdsz + padding_sz) &
+                        0x0000ffff)));
 
        return _SUCCESS;
 }
@@ -341,7 +344,7 @@ u8 r8712_xmitframe_aggr_1st(struct xmit_buf *pxmitbuf,
        pxmitbuf->priv_data = pxmitframe;
        pxmitframe->pxmit_urb[0] = pxmitbuf->pxmit_urb[0];
        /* buffer addr assoc */
-       pxmitframe->buf_addr = pxmitbuf->pbuf+TXDESC_SIZE+CMD_HDR_SZ;
+       pxmitframe->buf_addr = pxmitbuf->pbuf + TXDESC_SIZE + CMD_HDR_SZ;
        /*RTL8712_DMA_H2CCMD */
        r8712_construct_txaggr_cmd_desc(pxmitbuf);
        r8712_construct_txaggr_cmd_hdr(pxmitbuf);
@@ -374,37 +377,40 @@ u8 r8712_dump_aggr_xframe(struct xmit_buf *pxmitbuf,
                        struct xmit_frame *pxmitframe)
 {
        struct _adapter *padapter = pxmitframe->padapter;
-       struct dvobj_priv *pdvobj = (struct dvobj_priv *) &padapter->dvobjpriv;
-       struct tx_desc *ptxdesc = (struct tx_desc *)pxmitbuf->pbuf;
+       struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
+       struct tx_desc *ptxdesc = pxmitbuf->pbuf;
        struct cmd_hdr *pcmd_hdr = (struct cmd_hdr *)
                (pxmitbuf->pbuf + TXDESC_SIZE);
        u16 total_length = (u16) (ptxdesc->txdw0 & 0xffff);
 
        /* use 1st xmitframe as media */
        xmitframe_xmitbuf_attach(pxmitframe, pxmitbuf);
-       pcmd_hdr->cmd_dw0 = cpu_to_le32(((total_length-CMD_HDR_SZ)&0x0000ffff)|
-                                       (pcmd_hdr->cmd_dw0&0xffff0000));
+       pcmd_hdr->cmd_dw0 = cpu_to_le32(((total_length - CMD_HDR_SZ) &
+                                        0x0000ffff) | (pcmd_hdr->cmd_dw0 &
+                                                       0xffff0000));
 
        /* urb length in cmd_dw1 */
        pcmd_hdr->cmd_dw1 = cpu_to_le32((pxmitbuf->aggr_nr & 0xff)|
-                                       ((total_length+TXDESC_SIZE) << 16));
+                                       ((total_length + TXDESC_SIZE) << 16));
        pxmitframe->last[0] = 1;
        pxmitframe->bpending[0] = false;
        pxmitframe->mem_addr = pxmitbuf->pbuf;
 
-       if ((pdvobj->ishighspeed && ((total_length+TXDESC_SIZE)%0x200) == 0) ||
-               ((!pdvobj->ishighspeed &&
-                       ((total_length+TXDESC_SIZE)%0x40) == 0))) {
+       if ((pdvobj->ishighspeed && ((total_length + TXDESC_SIZE) % 0x200) ==
+            0) || ((!pdvobj->ishighspeed && ((total_length + TXDESC_SIZE) %
+                                             0x40) == 0))) {
                ptxdesc->txdw0 |= cpu_to_le32
-                       (((TXDESC_SIZE+OFFSET_SZ+8)<<OFFSET_SHT)&0x00ff0000);
+                       (((TXDESC_SIZE + OFFSET_SZ + 8) << OFFSET_SHT) &
+                        0x00ff0000);
                /*32 bytes for TX Desc + 8 bytes pending*/
        } else {
                ptxdesc->txdw0 |= cpu_to_le32
-                       (((TXDESC_SIZE+OFFSET_SZ)<<OFFSET_SHT)&0x00ff0000);
+                       (((TXDESC_SIZE + OFFSET_SZ) << OFFSET_SHT) &
+                        0x00ff0000);
                /*default = 32 bytes for TX Desc*/
        }
        r8712_write_port(pxmitframe->padapter, RTL8712_DMA_H2CCMD,
-                       total_length+TXDESC_SIZE, (u8 *)pxmitframe);
+                       total_length + TXDESC_SIZE, (u8 *)pxmitframe);
 
        return _SUCCESS;
 }
@@ -420,9 +426,9 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
        struct security_priv *psecuritypriv = &padapter->securitypriv;
        struct pkt_attrib *pattrib = &pxmitframe->attrib;
        struct tx_desc *ptxdesc = (struct tx_desc *)pmem;
-       struct dvobj_priv *pdvobj = (struct dvobj_priv *)&padapter->dvobjpriv;
+       struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
 #ifdef CONFIG_R8712_TX_AGGR
-       struct cmd_priv *pcmdpriv = (struct cmd_priv *)&padapter->cmdpriv;
+       struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
 #endif
        u8 blnSetTxDescOffset;
        sint bmcst = IS_MCAST(pattrib->ra);
@@ -432,7 +438,7 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
        memcpy(&txdesc_mp, ptxdesc, sizeof(struct tx_desc));
        memset(ptxdesc, 0, sizeof(struct tx_desc));
        /* offset 0 */
-       ptxdesc->txdw0 |= cpu_to_le32(sz&0x0000ffff);
+       ptxdesc->txdw0 |= cpu_to_le32(sz & 0x0000ffff);
        if (pdvobj->ishighspeed) {
                if (((sz + TXDESC_SIZE) % 512) == 0)
                        blnSetTxDescOffset = 1;
@@ -446,42 +452,42 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
        }
        if (blnSetTxDescOffset) {
                /* 32 bytes for TX Desc + 8 bytes pending */
-               ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ + 8) <<
+               ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ + 8) <<
                              OFFSET_SHT) & 0x00ff0000);
        } else {
                /* default = 32 bytes for TX Desc */
-               ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE+OFFSET_SZ) <<
+               ptxdesc->txdw0 |= cpu_to_le32(((TXDESC_SIZE + OFFSET_SZ) <<
                                  OFFSET_SHT) & 0x00ff0000);
        }
        ptxdesc->txdw0 |= cpu_to_le32(OWN | FSG | LSG);
        if (pxmitframe->frame_tag == DATA_FRAMETAG) {
                /* offset 4 */
-               ptxdesc->txdw1 |= cpu_to_le32((pattrib->mac_id)&0x1f);
+               ptxdesc->txdw1 |= cpu_to_le32((pattrib->mac_id) & 0x1f);
 
 #ifdef CONFIG_R8712_TX_AGGR
                /* dirty workaround, need to check if it is aggr cmd. */
                if ((u8 *)pmem != (u8 *)pxmitframe->pxmitbuf->pbuf) {
                        ptxdesc->txdw0 |= cpu_to_le32
-                               ((0x3 << TYPE_SHT)&TYPE_MSK);
+                               ((0x3 << TYPE_SHT) & TYPE_MSK);
                        qsel = (uint)(pattrib->qsel & 0x0000001f);
                        if (qsel == 2)
                                qsel = 0;
                        ptxdesc->txdw1 |= cpu_to_le32
                                ((qsel << QSEL_SHT) & 0x00001f00);
                        ptxdesc->txdw2 = cpu_to_le32
-                               ((qsel << RTS_RC_SHT)&0x001f0000);
+                               ((qsel << RTS_RC_SHT) & 0x001f0000);
                        ptxdesc->txdw6 |= cpu_to_le32
-                               ((0x5 << RSVD6_SHT)&RSVD6_MSK);
+                               ((0x5 << RSVD6_SHT) & RSVD6_MSK);
                } else {
                        ptxdesc->txdw0 |= cpu_to_le32
-                               ((0x3 << TYPE_SHT)&TYPE_MSK);
+                               ((0x3 << TYPE_SHT) & TYPE_MSK);
                        ptxdesc->txdw1 |= cpu_to_le32
                                ((0x13 << QSEL_SHT) & 0x00001f00);
                        qsel = (uint)(pattrib->qsel & 0x0000001f);
                        if (qsel == 2)
                                qsel = 0;
                        ptxdesc->txdw2 = cpu_to_le32
-                               ((qsel << RTS_RC_SHT)&0x0001f000);
+                               ((qsel << RTS_RC_SHT) & 0x0001f000);
                        ptxdesc->txdw7 |= cpu_to_le32
                                (pcmdpriv->cmd_seq << 24);
                        pcmdpriv->cmd_seq++;
@@ -593,7 +599,7 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
                ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
        } else {
                /* offset 4 */
-               qsel = (uint)(pattrib->priority&0x0000001f);
+               qsel = (uint)(pattrib->priority & 0x0000001f);
                ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
                /*offset 8*/
                /*offset 12*/
index ef7182961002e8c45394a6a208cfe9bf850023e3..562a102031277aa25672d33a2637835a54c81ed5 100644 (file)
@@ -70,7 +70,7 @@ static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
                return _FAIL;
        pcmdpriv->cmd_buf = pcmdpriv->cmd_allocated_buf  +  CMDBUFF_ALIGN_SZ -
                            ((addr_t)(pcmdpriv->cmd_allocated_buf) &
-                           (CMDBUFF_ALIGN_SZ-1));
+                           (CMDBUFF_ALIGN_SZ - 1));
        pcmdpriv->rsp_allocated_buf = kmalloc(MAX_RSPSZ + 4, GFP_ATOMIC);
        if (pcmdpriv->rsp_allocated_buf == NULL)
                return _FAIL;
@@ -137,9 +137,9 @@ static struct cmd_obj *_dequeue_cmd(struct  __queue *queue)
        struct cmd_obj *obj;
 
        spin_lock_irqsave(&(queue->lock), irqL);
-       if (list_empty(&(queue->queue)))
+       if (list_empty(&(queue->queue))) {
                obj = NULL;
-       else {
+       else {
                obj = LIST_CONTAINOR(queue->queue.next,
                                     struct cmd_obj, list);
                list_del_init(&obj->list);
@@ -172,7 +172,7 @@ u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
 {
        int res;
 
-       if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true)
+       if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
                return _FAIL;
        res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj);
        up(&pcmdpriv->cmd_queue_sema);
@@ -186,7 +186,7 @@ u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct cmd_obj *obj)
 
        if (obj == NULL)
                return _SUCCESS;
-       if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag == true)
+       if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
                return _FAIL;
        queue = &pcmdpriv->cmd_queue;
        spin_lock_irqsave(&queue->lock, irqL);
@@ -485,7 +485,7 @@ u8 r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
                return _FAIL;
 
        /* for hidden ap to set fw_state here */
-       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_ADHOC_STATE) !=
+       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_ADHOC_STATE) !=
            true) {
                switch (ndis_network_mode) {
                case Ndis802_11IBSS:
@@ -508,18 +508,18 @@ u8 r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
        memcpy(psecnetwork, &pnetwork->network, sizeof(*psecnetwork));
        psecuritypriv->authenticator_ie[0] = (unsigned char)
                                             psecnetwork->IELength;
-       if ((psecnetwork->IELength-12) < (256 - 1))
+       if ((psecnetwork->IELength - 12) < (256 - 1))
                memcpy(&psecuritypriv->authenticator_ie[1],
-                       &psecnetwork->IEs[12], psecnetwork->IELength-12);
+                       &psecnetwork->IEs[12], psecnetwork->IELength - 12);
        else
                memcpy(&psecuritypriv->authenticator_ie[1],
-                       &psecnetwork->IEs[12], (256-1));
+                       &psecnetwork->IEs[12], (256 - 1));
        psecnetwork->IELength = 0;
        /* If the driver wants to use the bssid to create the connection.
         * If not,  we copy the connecting AP's MAC address to it so that
         * the driver just has the bssid information for PMKIDList searching.
         */
-       if (pmlmepriv->assoc_by_bssid == false)
+       if (!pmlmepriv->assoc_by_bssid)
                ether_addr_copy(&pmlmepriv->assoc_bssid[0],
                                &pnetwork->network.MacAddress[0]);
        psecnetwork->IELength = r8712_restruct_sec_ie(padapter,
@@ -538,8 +538,9 @@ u8 r8712_joinbss_cmd(struct _adapter  *padapter, struct wlan_network *pnetwork)
                if (psecnetwork->IELength != tmp_len) {
                        psecnetwork->IELength = tmp_len;
                        pqospriv->qos_option = 1; /* WMM IE in beacon */
-               } else
+               } else {
                        pqospriv->qos_option = 0; /* no WMM IE in beacon */
+               }
        }
        if (pregistrypriv->ht_enable) {
                /* For WEP mode, we will use the bg mode to do the connection
@@ -679,7 +680,7 @@ u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
        else
                GET_ENCRY_ALGO(psecuritypriv, sta,
                               psetstakey_para->algorithm, false);
-       if (unicast_key == true)
+       if (unicast_key)
                memcpy(&psetstakey_para->key, &sta->x_UncstKey, 16);
        else
                memcpy(&psetstakey_para->key,
index 50339e67da071015a0e4c00a4693693fab08efcb..4e713610ad8b344e481ace1872bba9cc2a0672f8 100644 (file)
@@ -49,7 +49,7 @@ static void shift_out_bits(struct _adapter *padapter, u16 data, u16 count)
 {
        u16 x, mask;
 
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                goto out;
        mask = 0x01 << (count - 1);
        x = r8712_read8(padapter, EE_9346CR);
@@ -58,7 +58,7 @@ static void shift_out_bits(struct _adapter *padapter, u16 data, u16 count)
                x &= ~_EEDI;
                if (data & mask)
                        x |= _EEDI;
-               if (padapter->bSurpriseRemoved == true)
+               if (padapter->bSurpriseRemoved)
                        goto out;
                r8712_write8(padapter, EE_9346CR, (u8)x);
                udelay(CLOCK_RATE);
@@ -66,7 +66,7 @@ static void shift_out_bits(struct _adapter *padapter, u16 data, u16 count)
                down_clk(padapter, &x);
                mask >>= 1;
        } while (mask);
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                goto out;
        x &= ~_EEDI;
        r8712_write8(padapter, EE_9346CR, (u8)x);
@@ -77,7 +77,7 @@ static u16 shift_in_bits(struct _adapter *padapter)
 {
        u16 x, d = 0, i;
 
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                goto out;
        x = r8712_read8(padapter, EE_9346CR);
        x &= ~(_EEDO | _EEDI);
@@ -85,7 +85,7 @@ static u16 shift_in_bits(struct _adapter *padapter)
        for (i = 0; i < 16; i++) {
                d <<= 1;
                up_clk(padapter, &x);
-               if (padapter->bSurpriseRemoved == true)
+               if (padapter->bSurpriseRemoved)
                        goto out;
                x = r8712_read8(padapter, EE_9346CR);
                x &= ~(_EEDI);
@@ -129,17 +129,17 @@ static void eeprom_clean(struct _adapter *padapter)
 {
        u16 x;
 
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                return;
        x = r8712_read8(padapter, EE_9346CR);
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                return;
        x &= ~(_EECS | _EEDI);
        r8712_write8(padapter, EE_9346CR, (u8)x);
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                return;
        up_clk(padapter, &x);
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                return;
        down_clk(padapter, &x);
 }
@@ -206,11 +206,11 @@ u16 r8712_eeprom_read16(struct _adapter *padapter, u16 reg) /*ReadEEprom*/
        tmp8_clk_new = tmp8_clk_ori | 0x20;
        if (tmp8_clk_new != tmp8_clk_ori)
                r8712_write8(padapter, 0x10250003, tmp8_clk_new);
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                goto out;
        /* select EEPROM, reset bits, set _EECS */
        x = r8712_read8(padapter, EE_9346CR);
-       if (padapter->bSurpriseRemoved == true)
+       if (padapter->bSurpriseRemoved)
                goto out;
        x &= ~(_EEDI | _EEDO | _EESK | _EEM0);
        x |= _EEM1 | _EECS;
index e4e5b13cb9279d4ad3e62adf8e8a3ea74a6185a9..fbbc63570eabc397223009cca5e64a2aa63c7643 100644 (file)
@@ -150,7 +150,7 @@ alloc_io_queue_fail:
 
 void r8712_free_io_queue(struct _adapter *adapter)
 {
-       struct io_queue *pio_queue = (struct io_queue *)(adapter->pio_queue);
+       struct io_queue *pio_queue = adapter->pio_queue;
 
        if (pio_queue) {
                kfree(pio_queue->pallocated_free_ioreqs_buf);
index 070cc03ce3746b6bdf65c69089619d7082710ea5..26dd24cddd3856f78b4c39901e50f08a08dbaf2b 100644 (file)
@@ -232,14 +232,6 @@ struct io_queue {
        struct  intf_hdl intf;
 };
 
-static inline u32 _RND4(u32 sz)
-{
-       u32     val;
-
-       val = ((sz >> 2) + ((sz & 3) ? 1 : 0)) << 2;
-       return val;
-}
-
 u8 r8712_read8(struct _adapter *adapter, u32 addr);
 u16 r8712_read16(struct _adapter *adapter, u32 addr);
 u32 r8712_read32(struct _adapter *adapter, u32 addr);
index 143be0fdc578ead8afcf361d9d0a7ebeabc995ec..edfc6805e0128e6c6001756342babff0b63e6593 100644 (file)
@@ -72,32 +72,6 @@ static const char * const iw_operation_mode[] = {
         "Monitor"
 };
 
-/**
- * hwaddr_aton - Convert ASCII string to MAC address
- * @txt: MAC address as a string (e.g., "00:11:22:33:44:55")
- * @addr: Buffer for the MAC address (ETH_ALEN = 6 bytes)
- * Returns: 0 on success, -1 on failure (e.g., string not a MAC address)
- */
-static int hwaddr_aton_i(const char *txt, u8 *addr)
-{
-       int i;
-
-       for (i = 0; i < 6; i++) {
-               int a, b;
-
-               a = hex_to_bin(*txt++);
-               if (a < 0)
-                       return -1;
-               b = hex_to_bin(*txt++);
-               if (b < 0)
-                       return -1;
-               *addr++ = (a << 4) | b;
-               if (i < 5 && *txt++ != ':')
-                       return -1;
-       }
-       return 0;
-}
-
 void r8712_indicate_wx_assoc_event(struct _adapter *padapter)
 {
        union iwreq_data wrqu;
@@ -140,16 +114,17 @@ static inline void handle_pairwise_key(struct sta_info *psta,
 static inline void handle_group_key(struct ieee_param *param,
                                    struct _adapter *padapter)
 {
-       if (0 < param->u.crypt.idx &&
+       if (param->u.crypt.idx > 0 &&
            param->u.crypt.idx < 3) {
                /* group key idx is 1 or 2 */
                memcpy(padapter->securitypriv.XGrpKey[param->u.crypt.
-                       idx-1].skey, param->u.crypt.key, (param->u.crypt.key_len
-                       > 16 ? 16 : param->u.crypt.key_len));
+                       idx - 1].skey, param->u.crypt.key,
+                       (param->u.crypt.key_len > 16 ? 16 :
+                        param->u.crypt.key_len));
                memcpy(padapter->securitypriv.XGrptxmickey[param->
-                       u.crypt.idx-1].skey, &(param->u.crypt.key[16]), 8);
+                       u.crypt.idx - 1].skey, &(param->u.crypt.key[16]), 8);
                memcpy(padapter->securitypriv. XGrprxmickey[param->
-                       u.crypt.idx-1].skey, &(param->u.crypt.key[24]), 8);
+                       u.crypt.idx - 1].skey, &(param->u.crypt.key[24]), 8);
                padapter->securitypriv.binstallGrpkey = true;
                r8712_set_key(padapter, &padapter->securitypriv,
                        param->u.crypt.idx);
@@ -204,17 +179,17 @@ static inline char *translate_scan(struct _adapter *padapter,
        /* Add the protocol name */
        iwe.cmd = SIOCGIWNAME;
        if (r8712_is_cckratesonly_included(pnetwork->network.rates)) {
-               if (ht_cap == true)
+               if (ht_cap)
                        snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bn");
                else
                        snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b");
        } else if (r8712_is_cckrates_included(pnetwork->network.rates)) {
-               if (ht_cap == true)
+               if (ht_cap)
                        snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bgn");
                else
                        snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11bg");
        } else {
-               if (ht_cap == true)
+               if (ht_cap)
                        snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11gn");
                else
                        snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g");
@@ -225,7 +200,7 @@ static inline char *translate_scan(struct _adapter *padapter,
        memcpy((u8 *)&cap, r8712_get_capability_from_ie(pnetwork->network.IEs),
                2);
        cap = le16_to_cpu(cap);
-       if (cap & (WLAN_CAPABILITY_IBSS|WLAN_CAPABILITY_BSS)) {
+       if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
                if (cap & WLAN_CAPABILITY_BSS)
                        iwe.u.mode = (u32)IW_MODE_MASTER;
                else
@@ -336,7 +311,7 @@ static inline char *translate_scan(struct _adapter *padapter,
 
                if (r8712_get_wps_ie(pnetwork->network.IEs,
                    pnetwork->network.IELength,
-                   wps_ie, &wps_ielen) == true) {
+                   wps_ie, &wps_ielen)) {
                        if (wps_ielen > 2) {
                                iwe.cmd = IWEVGENIE;
                                iwe.u.data.length = (u16)wps_ielen;
@@ -382,8 +357,9 @@ static int wpa_set_auth_algs(struct net_device *dev, u32 value)
                                                 Ndis802_11AuthModeOpen;
                        padapter->securitypriv.AuthAlgrthm = 0;
                }
-       } else
+       } else {
                ret = -EINVAL;
+       }
        return ret;
 }
 
@@ -407,8 +383,9 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                        /* for large key indices, set the default (0) */
                        param->u.crypt.idx = 0;
                }
-       } else
+       } else {
                return -EINVAL;
+       }
        if (strcmp(param->u.crypt.alg, "WEP") == 0) {
                netdev_info(dev, "r8712u: %s: crypt.alg = WEP\n", __func__);
                padapter->securitypriv.ndisencryptstatus =
@@ -437,8 +414,9 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                                padapter->securitypriv.XGrpPrivacy =
                                         _WEP104_;
                        }
-               } else
+               } else {
                        return -EINVAL;
+               }
                pwep->KeyIndex = wep_key_idx;
                pwep->KeyIndex |= 0x80000000;
                memcpy(pwep->KeyMaterial, param->u.crypt.key, pwep->KeyLength);
@@ -469,7 +447,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
                struct sta_priv *pstapriv = &padapter->stapriv;
 
                if (check_fwstate(pmlmepriv, WIFI_STATION_STATE |
-                   WIFI_MP_STATE) == true) { /* sta mode */
+                   WIFI_MP_STATE)) { /* sta mode */
                        psta = r8712_get_stainfo(pstapriv,
                                                 get_bssid(pmlmepriv));
                        if (psta) {
@@ -598,10 +576,10 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
                                eid = buf[cnt];
 
                                if ((eid == _VENDOR_SPECIFIC_IE_) &&
-                                   (!memcmp(&buf[cnt+2], wps_oui, 4))) {
+                                   (!memcmp(&buf[cnt + 2], wps_oui, 4))) {
                                        netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE\n");
                                        padapter->securitypriv.wps_ie_len =
-                                           ((buf[cnt+1] + 2) <
+                                           ((buf[cnt + 1] + 2) <
                                            (MAX_WPA_IE_LEN << 2)) ?
                                            (buf[cnt + 1] + 2) :
                                            (MAX_WPA_IE_LEN << 2);
@@ -611,10 +589,11 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
                                        padapter->securitypriv.wps_phase =
                                                                 true;
                                        netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE, wps_phase==true\n");
-                                       cnt += buf[cnt+1]+2;
+                                       cnt += buf[cnt + 1] + 2;
                                        break;
-                               } else
+                               } else {
                                        cnt += buf[cnt + 1] + 2;
+                               }
                        }
                }
        }
@@ -635,7 +614,7 @@ static int r8711_wx_get_name(struct net_device *dev,
        struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
        u8 *prates;
 
-       if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE) ==
+       if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE) ==
            true) {
                /* parsing HT_CAP_IE */
                p = r8712_get_ie(&pcur_bss->IEs[12], _HT_CAPABILITY_IE_,
@@ -643,30 +622,31 @@ static int r8711_wx_get_name(struct net_device *dev,
                if (p && ht_ielen > 0)
                        ht_cap = true;
                prates = pcur_bss->rates;
-               if (r8712_is_cckratesonly_included(prates) == true) {
-                       if (ht_cap == true)
+               if (r8712_is_cckratesonly_included(prates)) {
+                       if (ht_cap)
                                snprintf(wrqu->name, IFNAMSIZ,
                                         "IEEE 802.11bn");
                        else
                                snprintf(wrqu->name, IFNAMSIZ,
                                         "IEEE 802.11b");
-               } else if ((r8712_is_cckrates_included(prates)) == true) {
-                       if (ht_cap == true)
+               } else if (r8712_is_cckrates_included(prates)) {
+                       if (ht_cap)
                                snprintf(wrqu->name, IFNAMSIZ,
                                         "IEEE 802.11bgn");
                        else
                                snprintf(wrqu->name, IFNAMSIZ,
                                         "IEEE 802.11bg");
                } else {
-                       if (ht_cap == true)
+                       if (ht_cap)
                                snprintf(wrqu->name, IFNAMSIZ,
                                         "IEEE 802.11gn");
                        else
                                snprintf(wrqu->name, IFNAMSIZ,
                                         "IEEE 802.11g");
                }
-       } else
+       } else {
                snprintf(wrqu->name, IFNAMSIZ, "unassociated");
+       }
        return 0;
 }
 
@@ -700,14 +680,14 @@ static int r8711_wx_set_freq(struct net_device *dev,
                fwrq->m = c + 1;
        }
        /* Setting by channel number */
-       if ((fwrq->m > 14) || (fwrq->e > 0))
+       if ((fwrq->m > 14) || (fwrq->e > 0)) {
                rc = -EOPNOTSUPP;
-       else {
+       else {
                int channel = fwrq->m;
 
-               if ((channel < 1) || (channel > 14))
+               if ((channel < 1) || (channel > 14)) {
                        rc = -EINVAL;
-               else {
+               else {
                        /* Yes ! We can set it !!! */
                        padapter->registrypriv.channel = channel;
                }
@@ -723,9 +703,9 @@ static int r8711_wx_get_freq(struct net_device *dev,
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
 
-       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                wrqu->freq.m = ieee80211_wlan_frequencies[
-                              pcur_bss->Configuration.DSConfig-1] * 100000;
+                              pcur_bss->Configuration.DSConfig - 1] * 100000;
                wrqu->freq.e = 1;
                wrqu->freq.i = pcur_bss->Configuration.DSConfig;
        } else {
@@ -772,12 +752,12 @@ static int r8711_wx_get_mode(struct net_device *dev, struct iw_request_info *a,
        struct _adapter *padapter = netdev_priv(dev);
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
-       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)
+       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
                wrqu->mode = IW_MODE_INFRA;
        else if (check_fwstate(pmlmepriv,
-                WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE) == true)
+                WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE))
                wrqu->mode = IW_MODE_ADHOC;
-       else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
+       else if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
                wrqu->mode = IW_MODE_MASTER;
        else
                wrqu->mode = IW_MODE_AUTO;
@@ -797,13 +777,13 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
        int intReturn = false;
 
 /*
      There are the BSSID information in the bssid.sa_data array.
      If cmd is IW_PMKSA_FLUSH, it means the wpa_supplicant wants to clear
      all the PMKID information. If cmd is IW_PMKSA_ADD, it means the
      wpa_supplicant wants to add a PMKID/BSSID to driver.
      If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to
      remove a PMKID/BSSID from driver.
-*/
*     There are the BSSID information in the bssid.sa_data array.
*     If cmd is IW_PMKSA_FLUSH, it means the wpa_supplicant wants to clear
*     all the PMKID information. If cmd is IW_PMKSA_ADD, it means the
*     wpa_supplicant wants to add a PMKID/BSSID to driver.
*     If cmd is IW_PMKSA_REMOVE, it means the wpa_supplicant wants to
*     remove a PMKID/BSSID from driver.
+ */
        if (pPMK == NULL)
                return -EINVAL;
        memcpy(strIssueBssid, pPMK->bssid.sa_data, ETH_ALEN);
@@ -818,7 +798,8 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
                        if (!memcmp(psecuritypriv->PMKIDList[j].Bssid,
                            strIssueBssid, ETH_ALEN)) {
                                /* BSSID is matched, the same AP => rewrite
-                                * with new PMKID. */
+                                * with new PMKID.
+                                */
                                netdev_info(dev, "r8712u: %s: BSSID exists in the PMKList.\n",
                                            __func__);
                                memcpy(psecuritypriv->PMKIDList[j].PMKID,
@@ -850,7 +831,8 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
                        if (!memcmp(psecuritypriv->PMKIDList[j].Bssid,
                            strIssueBssid, ETH_ALEN)) {
                                /* BSSID is matched, the same AP => Remove
-                                * this PMKID information and reset it. */
+                                * this PMKID information and reset it.
+                                */
                                eth_zero_addr(psecuritypriv->PMKIDList[j].Bssid);
                                psecuritypriv->PMKIDList[j].bUsed = false;
                                break;
@@ -909,7 +891,7 @@ static int r8711_wx_get_range(struct net_device *dev,
        range->max_qual.updated = 7; /* Updated all three */
        range->avg_qual.qual = 92; /* > 8% missed beacons is 'bad' */
        /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
-       range->avg_qual.level = 20 + -98;
+       range->avg_qual.level = 0x100 - 78;
        range->avg_qual.noise = 0;
        range->avg_qual.updated = 7; /* Updated all three */
        range->num_bitrates = RATE_COUNT;
@@ -957,24 +939,24 @@ static int r871x_wx_set_priv(struct net_device *dev,
        if (IS_ERR(ext))
                return PTR_ERR(ext);
 
-       if (0 == strcasecmp(ext, "RSSI")) {
+       if (!strcasecmp(ext, "RSSI")) {
                /*Return received signal strength indicator in -db for */
                /* current AP */
                /*<ssid> Rssi xx */
                struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
                struct wlan_network *pcur_network = &pmlmepriv->cur_network;
                /*static u8 xxxx; */
-               if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+               if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                        sprintf(ext, "%s rssi %d",
                                pcur_network->network.Ssid.Ssid,
                                /*(xxxx=xxxx+10) */
-                               ((padapter->recvpriv.fw_rssi)>>1)-95
+                               ((padapter->recvpriv.fw_rssi) >> 1) - 95
                                /*pcur_network->network.Rssi */
                                );
                } else {
                        sprintf(ext, "OK");
                }
-       } else if (0 == strcasecmp(ext, "LINKSPEED")) {
+       } else if (!strcasecmp(ext, "LINKSPEED")) {
                /*Return link speed in MBPS */
                /*LinkSpeed xx */
                union iwreq_data wrqd;
@@ -982,30 +964,30 @@ static int r871x_wx_set_priv(struct net_device *dev,
                int mbps;
 
                ret_inner = r8711_wx_get_rate(dev, info, &wrqd, extra);
-               if (0 != ret_inner)
+               if (ret_inner != 0)
                        mbps = 0;
                else
                        mbps = wrqd.bitrate.value / 1000000;
                sprintf(ext, "LINKSPEED %d", mbps);
-       } else if (0 == strcasecmp(ext, "MACADDR")) {
+       } else if (!strcasecmp(ext, "MACADDR")) {
                /*Return mac address of the station */
                /* Macaddr = xx:xx:xx:xx:xx:xx */
                sprintf(ext, "MACADDR = %pM", dev->dev_addr);
-       } else if (0 == strcasecmp(ext, "SCAN-ACTIVE")) {
+       } else if (!strcasecmp(ext, "SCAN-ACTIVE")) {
                /*Set scan type to active */
                /*OK if successful */
                struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
                pmlmepriv->passive_mode = 1;
                sprintf(ext, "OK");
-       } else if (0 == strcasecmp(ext, "SCAN-PASSIVE")) {
+       } else if (!strcasecmp(ext, "SCAN-PASSIVE")) {
                /*Set scan type to passive */
                /*OK if successful */
                struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
                pmlmepriv->passive_mode = 0;
                sprintf(ext, "OK");
-       } else if (0 == strncmp(ext, "DCE-E", 5)) {
+       } else if (!strncmp(ext, "DCE-E", 5)) {
                /*Set scan type to passive */
                /*OK if successful */
                r8712_disconnectCtrlEx_cmd(padapter
@@ -1015,7 +997,7 @@ static int r871x_wx_set_priv(struct net_device *dev,
                        , 5000 /*u32 firstStageTO */
                );
                sprintf(ext, "OK");
-       } else if (0 == strncmp(ext, "DCE-D", 5)) {
+       } else if (!strncmp(ext, "DCE-D", 5)) {
                /*Set scan type to passive */
                /*OK if successfu */
                r8712_disconnectCtrlEx_cmd(padapter
@@ -1031,7 +1013,7 @@ static int r871x_wx_set_priv(struct net_device *dev,
                goto FREE_EXT;
        }
        if (copy_to_user(dwrq->pointer, ext,
-                               min(dwrq->length, (__u16)(strlen(ext)+1))))
+                               min(dwrq->length, (__u16)(strlen(ext) + 1))))
                ret = -EFAULT;
 
 FREE_EXT:
@@ -1068,9 +1050,9 @@ static int r8711_wx_set_wap(struct net_device *dev,
        struct wlan_network *pnetwork = NULL;
        enum NDIS_802_11_AUTHENTICATION_MODE    authmode;
 
-       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true)
+       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
                return -EBUSY;
-       if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true)
+       if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
                return ret;
        if (temp->sa_family != ARPHRD_ETHER)
                return -EINVAL;
@@ -1079,7 +1061,7 @@ static int r8711_wx_set_wap(struct net_device *dev,
        phead = &queue->queue;
        pmlmepriv->pscanned = phead->next;
        while (1) {
-               if (end_of_queue_search(phead, pmlmepriv->pscanned) == true)
+               if (end_of_queue_search(phead, pmlmepriv->pscanned))
                        break;
                pnetwork = LIST_CONTAINOR(pmlmepriv->pscanned,
                           struct wlan_network, list);
@@ -1093,9 +1075,9 @@ static int r8711_wx_set_wap(struct net_device *dev,
        }
        spin_unlock_irqrestore(&queue->lock, irqL);
        if (!ret) {
-               if (!r8712_set_802_11_authentication_mode(padapter, authmode))
+               if (!r8712_set_802_11_authentication_mode(padapter, authmode)) {
                        ret = -ENOMEM;
-               else {
+               else {
                        if (!r8712_set_802_11_bssid(padapter, temp->sa_data))
                                ret = -1;
                }
@@ -1161,17 +1143,17 @@ static int r8711_wx_set_scan(struct net_device *dev,
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        u8 status = true;
 
-       if (padapter->bDriverStopped == true) {
+       if (padapter->bDriverStopped) {
                netdev_info(dev, "In %s: bDriverStopped=%d\n",
                            __func__, padapter->bDriverStopped);
                return -1;
        }
-       if (padapter->bup == false)
+       if (!padapter->bup)
                return -ENETDOWN;
-       if (padapter->hw_init_completed == false)
+       if (!padapter->hw_init_completed)
                return -1;
-       if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) ||
-           (pmlmepriv->sitesurveyctrl.traffic_busy == true))
+       if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) ||
+           (pmlmepriv->sitesurveyctrl.traffic_busy))
                return 0;
        if (wrqu->data.length == sizeof(struct iw_scan_req)) {
                struct iw_scan_req *req = (struct iw_scan_req *)extra;
@@ -1188,16 +1170,18 @@ static int r8711_wx_set_scan(struct net_device *dev,
                        spin_lock_irqsave(&pmlmepriv->lock, irqL);
                        if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
                             _FW_UNDER_LINKING)) ||
-                           (pmlmepriv->sitesurveyctrl.traffic_busy == true)) {
+                           (pmlmepriv->sitesurveyctrl.traffic_busy)) {
                                if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
                                        status = false;
-                       } else
+                       } else {
                                status = r8712_sitesurvey_cmd(padapter, &ssid);
+                       }
                        spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
                }
-       } else
+       } else {
                status = r8712_set_802_11_bssid_list_scan(padapter);
-       if (status == false)
+       }
+       if (!status)
                return -1;
        return 0;
 }
@@ -1218,7 +1202,8 @@ static int r8711_wx_get_scan(struct net_device *dev,
 
        if (padapter->bDriverStopped)
                return -EINVAL;
-       while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) {
+       while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
+                            _FW_UNDER_LINKING)) {
                msleep(30);
                cnt++;
                if (cnt > 100)
@@ -1228,7 +1213,7 @@ static int r8711_wx_get_scan(struct net_device *dev,
        phead = &queue->queue;
        plist = phead->next;
        while (1) {
-               if (end_of_queue_search(phead, plist) == true)
+               if (end_of_queue_search(phead, plist))
                        break;
                if ((stop - ev) < SCAN_ITEM_SIZE) {
                        ret = -E2BIG;
@@ -1328,7 +1313,7 @@ static int r8711_wx_get_essid(struct net_device *dev,
        struct wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
        u32 len, ret = 0;
 
-       if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
+       if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
                len = pcur_bss->Ssid.SsidLength;
                wrqu->essid.length = len;
                memcpy(extra, pcur_bss->Ssid.Ssid, len);
@@ -1403,8 +1388,9 @@ set_rate:
                        datarates[i] = mpdatarate[i];
                        if (fixed == 0)
                                break;
-               } else
+               } else {
                        datarates[i] = 0xff;
+               }
        }
        if (r8712_setdatarate_cmd(padapter, datarates) != _SUCCESS)
                ret = -ENOMEM;
@@ -1428,7 +1414,7 @@ static int r8711_wx_get_rate(struct net_device *dev,
        u16 mcs_rate = 0;
 
        i = 0;
-       if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
+       if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
                p = r8712_get_ie(&pcur_bss->IEs[12],
                                 _HT_CAPABILITY_IE_, &ht_ielen,
                    pcur_bss->IELength - 12);
@@ -1448,13 +1434,13 @@ static int r8711_wx_get_rate(struct net_device *dev,
                        if (rate > max_rate)
                                max_rate = rate;
                        wrqu->bitrate.fixed = 0;        /* no auto select */
-                       wrqu->bitrate.value = rate*500000;
+                       wrqu->bitrate.value = rate * 500000;
                        i++;
                }
-               if (ht_cap == true) {
+               if (ht_cap) {
                        if (mcs_rate & 0x8000 /* MCS15 */
                                &&
-                               RTL8712_RF_2T2R == rf_type)
+                               rf_type == RTL8712_RF_2T2R)
                                max_rate = (bw_40MHz) ? ((short_GI) ? 300 :
                                            270) : ((short_GI) ? 144 : 130);
                        else /* default MCS7 */
@@ -1463,8 +1449,9 @@ static int r8711_wx_get_rate(struct net_device *dev,
                        max_rate *= 2; /* Mbps/2 */
                }
                wrqu->bitrate.value = max_rate * 500000;
-       } else
+       } else {
                return -ENOLINK;
+       }
        return 0;
 }
 
@@ -1485,9 +1472,9 @@ static int r8711_wx_set_frag(struct net_device *dev,
 {
        struct _adapter *padapter = netdev_priv(dev);
 
-       if (wrqu->frag.disabled)
+       if (wrqu->frag.disabled) {
                padapter->xmitpriv.frag_len = MAX_FRAG_THRESHOLD;
-       else {
+       else {
                if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
                    wrqu->frag.value > MAX_FRAG_THRESHOLD)
                        return -EINVAL;
@@ -1587,7 +1574,8 @@ static int r8711_wx_set_enc(struct net_device *dev,
        } else {
                wep.KeyLength = 0;
                if (keyindex_provided == 1) { /* set key_id only, no given
-                                              * KeyMaterial(erq->length==0).*/
+                                              * KeyMaterial(erq->length==0).
+                                              */
                        padapter->securitypriv.PrivacyKeyIndex = key;
                        switch (padapter->securitypriv.DefKeylen[key]) {
                        case 5:
@@ -1622,7 +1610,7 @@ static int r8711_wx_get_enc(struct net_device *dev,
        struct iw_point *erq = &(wrqu->encoding);
        struct  mlme_priv       *pmlmepriv = &(padapter->mlmepriv);
 
-       if (check_fwstate(pmlmepriv, _FW_LINKED) == false) {
+       if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
                if (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
                        erq->length = 0;
                        erq->flags |= IW_ENCODE_DISABLED;
@@ -1811,8 +1799,7 @@ static int r871x_wx_set_enc_ext(struct net_device *dev,
        if (param == NULL)
                return -ENOMEM;
        param->cmd = IEEE_CMD_SET_ENCRYPTION;
-       memset(param->sta_addr, 0xff, ETH_ALEN);
-
+       eth_broadcast_addr(param->sta_addr);
        strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN);
        if (pext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
                param->u.crypt.set_tx = 0;
@@ -1868,7 +1855,7 @@ static int r8711_wx_write32(struct net_device *dev,
        u32 data32;
 
        get_user(addr, (u32 __user *)wrqu->data.pointer);
-       data32 = ((u32)wrqu->data.length<<16) | (u32)wrqu->data.flags;
+       data32 = ((u32)wrqu->data.length << 16) | (u32)wrqu->data.flags;
        r8712_write32(padapter, addr, data32);
        return 0;
 }
@@ -1922,9 +1909,9 @@ static int r871x_mp_ioctl_hdl(struct net_device *dev,
                ret = -EINVAL;
                goto _r871x_mp_ioctl_hdl_exit;
        }
-       if (phandler->oid == 0 && phandler->handler)
+       if (phandler->oid == 0 && phandler->handler) {
                status = phandler->handler(&oid_par);
-       else if (phandler->handler) {
+       else if (phandler->handler) {
                oid_par.adapter_context = padapter;
                oid_par.oid = phandler->oid;
                oid_par.information_buf = poidparam->data;
@@ -1981,7 +1968,8 @@ static int r871x_get_ap_info(struct net_device *dev,
 
        if (padapter->bDriverStopped || (pdata == NULL))
                return -EINVAL;
-       while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) {
+       while (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
+                            _FW_UNDER_LINKING)) {
                msleep(30);
                cnt++;
                if (cnt > 100)
@@ -1991,16 +1979,17 @@ static int r871x_get_ap_info(struct net_device *dev,
        if (pdata->length >= 32) {
                if (copy_from_user(data, pdata->pointer, 32))
                        return -EINVAL;
-       } else
+       } else {
                 return -EINVAL;
+       }
        spin_lock_irqsave(&(pmlmepriv->scanned_queue.lock), irqL);
        phead = &queue->queue;
        plist = phead->next;
        while (1) {
-               if (end_of_queue_search(phead, plist) == true)
+               if (end_of_queue_search(phead, plist))
                        break;
                pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
-               if (hwaddr_aton_i(data, bssid)) {
+               if (!mac_pton(data, bssid)) {
                        netdev_info(dev, "r8712u: Invalid BSSID '%s'.\n",
                                    (u8 *)data);
                        spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock),
@@ -2008,16 +1997,16 @@ static int r871x_get_ap_info(struct net_device *dev,
                        return -EINVAL;
                }
                netdev_info(dev, "r8712u: BSSID:%pM\n", bssid);
-               if (!memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN)) {
+               if (ether_addr_equal(bssid, pnetwork->network.MacAddress)) {
                        /* BSSID match, then check if supporting wpa/wpa2 */
                        pbuf = r8712_get_wpa_ie(&pnetwork->network.IEs[12],
-                              &wpa_ielen, pnetwork->network.IELength-12);
+                              &wpa_ielen, pnetwork->network.IELength - 12);
                        if (pbuf && (wpa_ielen > 0)) {
                                pdata->flags = 1;
                                break;
                        }
                        pbuf = r8712_get_wpa2_ie(&pnetwork->network.IEs[12],
-                              &wpa_ielen, pnetwork->network.IELength-12);
+                              &wpa_ielen, pnetwork->network.IELength - 12);
                        if (pbuf && (wpa_ielen > 0)) {
                                pdata->flags = 2;
                                break;
@@ -2102,7 +2091,7 @@ static int wpa_set_param(struct net_device *dev, u8 name, u32 value)
        switch (name) {
        case IEEE_PARAM_WPA_ENABLED:
                padapter->securitypriv.AuthAlgrthm = 2; /* 802.1x */
-               switch ((value)&0xff) {
+               switch ((value) & 0xff) {
                case 1: /* WPA */
                        padapter->securitypriv.ndisauthtype =
                                Ndis802_11AuthModeWPAPSK; /* WPA_PSK */
@@ -2241,7 +2230,8 @@ static iw_handler r8711_handlers[] = {
        r8711_wx_set_wap,               /* SIOCSIWAP */
        r8711_wx_get_wap,               /* SIOCGIWAP */
        r871x_wx_set_mlme,              /* request MLME operation;
-                                        *  uses struct iw_mlme */
+                                        *  uses struct iw_mlme
+                                        */
        dummy,                          /* SIOCGIWAPLIST -- deprecated */
        r8711_wx_set_scan,              /* SIOCSIWSCAN */
        r8711_wx_get_scan,              /* SIOCGIWSCAN */
index ac0baff7f090e5f12e9d552fb8162ec4d398e2f2..7c346a405a20766f193292f4d381266bd381aec1 100644 (file)
@@ -58,8 +58,9 @@ uint oid_rt_get_small_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
                *(u32 *)poid_par_priv->information_buf =
                                padapter->recvpriv.rx_smallpacket_crcerr;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -74,8 +75,9 @@ uint oid_rt_get_middle_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
                *(u32 *)poid_par_priv->information_buf =
                                padapter->recvpriv.rx_middlepacket_crcerr;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -90,8 +92,9 @@ uint oid_rt_get_large_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
                *(u32 *)poid_par_priv->information_buf =
                                 padapter->recvpriv.rx_largepacket_crcerr;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -122,8 +125,9 @@ uint oid_rt_get_rx_total_packet_hdl(struct oid_par_priv *poid_par_priv)
                                         padapter->recvpriv.rx_pkts +
                                         padapter->recvpriv.rx_drop;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -152,8 +156,9 @@ uint oid_rt_get_rx_icv_err_hdl(struct oid_par_priv *poid_par_priv)
                *(uint *)poid_par_priv->information_buf =
                                         padapter->recvpriv.rx_icv_err;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -182,8 +187,9 @@ uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv)
                        preamblemode = 2;
                *(u32 *)poid_par_priv->information_buf = preamblemode;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -239,8 +245,9 @@ uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv
                        padapter->registrypriv.preamble = PREAMBLE_SHORT;
                *(u32 *)poid_par_priv->information_buf = preamblemode;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -269,8 +276,9 @@ uint oid_rt_get_total_tx_bytes_hdl(struct oid_par_priv
                *(u32 *)poid_par_priv->information_buf =
                                                 padapter->xmitpriv.tx_bytes;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -287,8 +295,9 @@ uint oid_rt_get_total_rx_bytes_hdl(struct oid_par_priv
                                           padapter->recvpriv.rx_bytes;
                *poid_par_priv->bytes_rw = poid_par_priv->
                                           information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -324,8 +333,8 @@ uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv)
 
        if (poid_par_priv->type_of_oid != QUERY_OID)
                return RNDIS_STATUS_NOT_ACCEPTED;
-       if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) ||
-           (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true))
+       if (check_fwstate(pmlmepriv, _FW_LINKED) ||
+           check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))
                pnic_Config = &pmlmepriv->cur_network.network.Configuration;
        else
                pnic_Config = &padapter->registrypriv.dev_network.
@@ -364,8 +373,9 @@ uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv
                ulInfo |= 0x0400; /* WIRELESS_MODE_A */
                *(u32 *) poid_par_priv->information_buf = ulInfo;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                return RNDIS_STATUS_INVALID_LENGTH;
+       }
        return RNDIS_STATUS_SUCCESS;
 }
 
@@ -451,8 +461,9 @@ uint oid_rt_pro_rf_write_registry_hdl(struct oid_par_priv*
                        (unsigned long)(*((unsigned long *)
                                        poid_par_priv->information_buf + 2))))
                        status = RNDIS_STATUS_NOT_ACCEPTED;
-       } else
+       } else {
                status = RNDIS_STATUS_INVALID_LENGTH;
+       }
        return status;
 }
 
@@ -464,10 +475,11 @@ uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv)
 
        if (poid_par_priv->type_of_oid != SET_OID) /* QUERY_OID */
                return RNDIS_STATUS_NOT_ACCEPTED;
-       if (poid_par_priv->information_buf_len == (sizeof(unsigned long)*3)) {
-               if (Adapter->mppriv.act_in_progress == true)
+       if (poid_par_priv->information_buf_len == (sizeof(unsigned long) *
+                                                  3)) {
+               if (Adapter->mppriv.act_in_progress) {
                        status = RNDIS_STATUS_NOT_ACCEPTED;
-               else {
+               else {
                        /* init workparam */
                        Adapter->mppriv.act_in_progress = true;
                        Adapter->mppriv.workparam.bcompleted = false;
@@ -489,8 +501,9 @@ uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv)
                            io_value))
                                status = RNDIS_STATUS_NOT_ACCEPTED;
                }
-       } else
+       } else {
                status = RNDIS_STATUS_INVALID_LENGTH;
+       }
        return status;
 }
 
@@ -515,11 +528,11 @@ uint oid_rt_get_connect_state_hdl(struct oid_par_priv *poid_par_priv)
         * nStatus==2   AdHocMode
         * nStatus==3   NotAssociated
         */
-       if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true)
+       if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING))
                ulInfo = CHECKINGSTATUS;
-       else if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
+       else if (check_fwstate(pmlmepriv, _FW_LINKED))
                ulInfo = ASSOCIATED;
-       else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)
+       else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))
                ulInfo = ADHOCMODE;
        else
                ulInfo = NOTASSOCIATED;
index 22262b3558bacd5db51f174cd416fdbc0f332c4e..f772675ae9cd2000ca2103c86ee4f84091a838d1 100644 (file)
@@ -136,12 +136,12 @@ u8 r8712_set_802_11_bssid(struct _adapter *padapter, u8 *bssid)
        }
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
        if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY |
-           _FW_UNDER_LINKING) == true) {
+           _FW_UNDER_LINKING)) {
                status = check_fwstate(pmlmepriv, _FW_UNDER_LINKING);
                goto _Abort_Set_BSSID;
        }
        if (check_fwstate(pmlmepriv,
-           _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == true) {
+           _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
                if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid,
                    ETH_ALEN)) {
                        if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE))
@@ -149,7 +149,7 @@ u8 r8712_set_802_11_bssid(struct _adapter *padapter, u8 *bssid)
                                                * WIFI_ADHOC_MASTER_STATE */
                } else {
                        r8712_disassoc_cmd(padapter);
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
+                       if (check_fwstate(pmlmepriv, _FW_LINKED))
                                r8712_ind_disconnect(padapter);
                        r8712_free_assoc_resources(padapter);
                        if ((check_fwstate(pmlmepriv,
@@ -180,11 +180,11 @@ void r8712_set_802_11_ssid(struct _adapter *padapter,
        if (!padapter->hw_init_completed)
                return;
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
-       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) {
+       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING)) {
                check_fwstate(pmlmepriv, _FW_UNDER_LINKING);
                goto _Abort_Set_SSID;
        }
-       if (check_fwstate(pmlmepriv, _FW_LINKED|WIFI_ADHOC_MASTER_STATE)) {
+       if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE)) {
                if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
                    (!memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid,
                    ssid->SsidLength))) {
@@ -197,7 +197,7 @@ void r8712_set_802_11_ssid(struct _adapter *padapter,
                                         */
                                        r8712_disassoc_cmd(padapter);
                                        if (check_fwstate(pmlmepriv,
-                                           _FW_LINKED) == true)
+                                           _FW_LINKED))
                                                r8712_ind_disconnect(padapter);
                                        r8712_free_assoc_resources(padapter);
                                        if (check_fwstate(pmlmepriv,
@@ -207,24 +207,25 @@ void r8712_set_802_11_ssid(struct _adapter *padapter,
                                                set_fwstate(pmlmepriv,
                                                            WIFI_ADHOC_STATE);
                                        }
-                               } else
+                               } else {
                                        goto _Abort_Set_SSID; /* driver is in
                                                  * WIFI_ADHOC_MASTER_STATE */
+                               }
                        }
                } else {
                        r8712_disassoc_cmd(padapter);
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
+                       if (check_fwstate(pmlmepriv, _FW_LINKED))
                                r8712_ind_disconnect(padapter);
                        r8712_free_assoc_resources(padapter);
                        if (check_fwstate(pmlmepriv,
-                           WIFI_ADHOC_MASTER_STATE) == true) {
+                           WIFI_ADHOC_MASTER_STATE)) {
                                _clr_fwstate_(pmlmepriv,
                                              WIFI_ADHOC_MASTER_STATE);
                                set_fwstate(pmlmepriv, WIFI_ADHOC_STATE);
                        }
                }
        }
-       if (padapter->securitypriv.btkip_countermeasure == true)
+       if (padapter->securitypriv.btkip_countermeasure)
                goto _Abort_Set_SSID;
        if (!validate_ssid(ssid))
                goto _Abort_Set_SSID;
@@ -248,13 +249,13 @@ void r8712_set_802_11_infrastructure_mode(struct _adapter *padapter,
 
        if (*pold_state != networktype) {
                spin_lock_irqsave(&pmlmepriv->lock, irqL);
-               if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) ||
+               if (check_fwstate(pmlmepriv, _FW_LINKED) ||
                    (*pold_state == Ndis802_11IBSS))
                        r8712_disassoc_cmd(padapter);
                if (check_fwstate(pmlmepriv,
-                   _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == true)
+                   _FW_LINKED | WIFI_ADHOC_MASTER_STATE))
                        r8712_free_assoc_resources(padapter);
-               if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) ||
+               if (check_fwstate(pmlmepriv, _FW_LINKED) ||
                    (*pold_state == Ndis802_11Infrastructure) ||
                    (*pold_state == Ndis802_11IBSS)) {
                        /* will clr Linked_state before this function,
@@ -291,7 +292,7 @@ u8 r8712_set_802_11_disassociate(struct _adapter *padapter)
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
-       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                r8712_disassoc_cmd(padapter);
                r8712_ind_disconnect(padapter);
                r8712_free_assoc_resources(padapter);
@@ -312,8 +313,8 @@ u8 r8712_set_802_11_bssid_list_scan(struct _adapter *padapter)
        if (!padapter->hw_init_completed)
                return false;
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
-       if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) ||
-           (pmlmepriv->sitesurveyctrl.traffic_busy == true)) {
+       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING) ||
+           pmlmepriv->sitesurveyctrl.traffic_busy) {
                /* Scan or linking is in progress, do nothing. */
                ret = (u8)check_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
        } else {
index fc5dbea08cb490d53cda38f81c3e3404fac09b6a..a4a002b5512890109f48d39cd84db8248c705d90 100644 (file)
@@ -62,8 +62,8 @@ static sint _init_mlme_priv(struct _adapter *padapter)
        _init_queue(&(pmlmepriv->scanned_queue));
        set_scanned_network_val(pmlmepriv, 0);
        memset(&pmlmepriv->assoc_ssid, 0, sizeof(struct ndis_802_11_ssid));
-       pbuf = kmalloc(MAX_BSS_CNT * (sizeof(struct wlan_network)),
-                      GFP_ATOMIC);
+       pbuf = kmalloc_array(MAX_BSS_CNT, sizeof(struct wlan_network),
+                            GFP_ATOMIC);
        if (pbuf == NULL)
                return _FAIL;
        pmlmepriv->free_bss_buf = pbuf;
@@ -110,7 +110,7 @@ static void _free_network(struct mlme_priv *pmlmepriv,
 
        if (pnetwork == NULL)
                return;
-       if (pnetwork->fixed == true)
+       if (pnetwork->fixed)
                return;
        curr_time = jiffies;
        delta_time = (curr_time - (u32)pnetwork->last_scanned) / HZ;
@@ -130,7 +130,7 @@ static void _free_network_nolock(struct mlme_priv *pmlmepriv,
 
        if (pnetwork == NULL)
                return;
-       if (pnetwork->fixed == true)
+       if (pnetwork->fixed)
                return;
        list_del_init(&pnetwork->list);
        list_add_tail(&pnetwork->list, &free_queue->queue);
@@ -176,7 +176,7 @@ static void _free_network_queue(struct _adapter *padapter)
        spin_lock_irqsave(&scanned_queue->lock, irqL);
        phead = &scanned_queue->queue;
        plist = phead->next;
-       while (end_of_queue_search(phead, plist) == false) {
+       while (!end_of_queue_search(phead, plist)) {
                pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
                plist = plist->next;
                _free_network(pmlmepriv, pnetwork);
@@ -189,10 +189,11 @@ sint r8712_if_up(struct _adapter *padapter)
        sint res;
 
        if (padapter->bDriverStopped || padapter->bSurpriseRemoved ||
-           (check_fwstate(&padapter->mlmepriv, _FW_LINKED) == false)) {
+           !check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
                res = false;
-       } else
+       } else {
                res = true;
+       }
        return res;
 }
 
@@ -204,8 +205,8 @@ void r8712_generate_random_ibss(u8 *pibss)
        pibss[1] = 0x11;
        pibss[2] = 0x87;
        pibss[3] = (u8)(curtime & 0xff);
-       pibss[4] = (u8)((curtime>>8) & 0xff);
-       pibss[5] = (u8)((curtime>>16) & 0xff);
+       pibss[4] = (u8)((curtime >> 8) & 0xff);
+       pibss[5] = (u8)((curtime >> 16) & 0xff);
 }
 
 uint r8712_get_wlan_bssid_ex_sz(struct wlan_bssid_ex *bss)
@@ -354,8 +355,9 @@ static void update_network(struct wlan_bssid_ex *dst,
                padapter->recvpriv.signal = (u8)tmpVal;
 
                src->Rssi = padapter->recvpriv.signal;
-       } else
+       } else {
                src->Rssi = (src->Rssi + dst->Rssi) / 2;
+       }
        memcpy((u8 *)dst, (u8 *)src, r8712_get_wlan_bssid_ex_sz(src));
 }
 
@@ -392,7 +394,7 @@ static void update_scanned_network(struct _adapter *adapter,
        plist = phead->next;
 
        while (1) {
-               if (end_of_queue_search(phead, plist) == true)
+               if (end_of_queue_search(phead, plist))
                        break;
 
                pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
@@ -409,7 +411,7 @@ static void update_scanned_network(struct _adapter *adapter,
 
        /* If we didn't find a match, then get a new network slot to initialize
         * with this beacon's information */
-       if (end_of_queue_search(phead, plist) == true) {
+       if (end_of_queue_search(phead, plist)) {
                if (list_empty(&pmlmepriv->free_bss_pool.queue)) {
                        /* If there are no more slots, expire the oldest */
                        pnetwork = oldest;
@@ -468,10 +470,10 @@ static int is_desired_network(struct _adapter *adapter,
        int bselected = true;
        struct  security_priv *psecuritypriv = &adapter->securitypriv;
 
-       if (psecuritypriv->wps_phase == true) {
+       if (psecuritypriv->wps_phase) {
                if (r8712_get_wps_ie(pnetwork->network.IEs,
                    pnetwork->network.IELength, wps_ie,
-                   &wps_ielen) == true)
+                   &wps_ielen))
                        return true;
                else
                        return false;
@@ -479,7 +481,7 @@ static int is_desired_network(struct _adapter *adapter,
        if ((psecuritypriv->PrivacyAlgrthm != _NO_PRIVACY_) &&
                    (pnetwork->network.Privacy == 0))
                bselected = false;
-       if (check_fwstate(&adapter->mlmepriv, WIFI_ADHOC_STATE) == true) {
+       if (check_fwstate(&adapter->mlmepriv, WIFI_ADHOC_STATE)) {
                if (pnetwork->network.InfrastructureMode !=
                        adapter->mlmepriv.cur_network.network.
                        InfrastructureMode)
@@ -533,7 +535,7 @@ void r8712_survey_event_callback(struct _adapter *adapter, u8 *pbuf)
                return;
        spin_lock_irqsave(&pmlmepriv->lock2, flags);
        /* update IBSS_network 's timestamp */
-       if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) {
+       if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
                if (!memcmp(&(pmlmepriv->cur_network.network.MacAddress),
                    pnetwork->MacAddress, ETH_ALEN)) {
                        struct wlan_network *ibss_wlan = NULL;
@@ -551,10 +553,10 @@ void r8712_survey_event_callback(struct _adapter *adapter, u8 *pbuf)
                }
        }
        /* lock pmlmepriv->lock when you accessing network_q */
-       if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == false) {
-               if (pnetwork->Ssid.Ssid[0] != 0)
+       if (!check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
+               if (pnetwork->Ssid.Ssid[0] != 0) {
                        rtl8711_add_network(adapter, pnetwork);
-               else {
+               else {
                        pnetwork->Ssid.SsidLength = 8;
                        memcpy(pnetwork->Ssid.Ssid, "<hidden>", 8);
                        rtl8711_add_network(adapter, pnetwork);
@@ -571,15 +573,15 @@ void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf)
 
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
 
-       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) {
+       if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
                del_timer(&pmlmepriv->scan_to_timer);
 
                _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
        }
 
-       if (pmlmepriv->to_join == true) {
-               if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) {
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == false) {
+       if (pmlmepriv->to_join) {
+               if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
+                       if (!check_fwstate(pmlmepriv, _FW_LINKED)) {
                                set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
 
                                if (r8712_select_and_join_from_scan(pmlmepriv)
@@ -633,7 +635,7 @@ void r8712_free_assoc_resources(struct _adapter *adapter)
        pwlan = r8712_find_network(&pmlmepriv->scanned_queue,
                                   tgt_network->network.MacAddress);
 
-       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE|WIFI_AP_STATE)) {
+       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_AP_STATE)) {
                struct sta_info *psta;
 
                psta = r8712_get_stainfo(&adapter->stapriv,
@@ -645,7 +647,7 @@ void r8712_free_assoc_resources(struct _adapter *adapter)
        }
 
        if (check_fwstate(pmlmepriv,
-           WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE))
+           WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE | WIFI_AP_STATE))
                r8712_free_all_stainfo(adapter);
        if (pwlan)
                pwlan->fixed = false;
@@ -679,7 +681,7 @@ void r8712_ind_disconnect(struct _adapter *padapter)
 {
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 
-       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                _clr_fwstate_(pmlmepriv, _FW_LINKED);
                padapter->ledpriv.LedControlHandler(padapter, LED_CTL_NO_LINK);
                r8712_os_indicate_disconnect(padapter);
@@ -717,10 +719,11 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
                pnetwork = kmalloc(sizeof(struct wlan_network), GFP_ATOMIC);
                if (!pnetwork)
                        return;
-               memcpy((u8 *)pnetwork+16, (u8 *)pbuf + 8,
-                       sizeof(struct wlan_network) - 16);
-       } else
+               memcpy((u8 *)pnetwork + 16, (u8 *)pbuf + 8,
+                      sizeof(struct wlan_network) - 16);
+       } else {
                pnetwork = (struct wlan_network *)pbuf;
+       }
 
 #ifdef __BIG_ENDIAN
        /* endian_convert */
@@ -764,15 +767,15 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
        if (pnetwork->network.Length > sizeof(struct wlan_bssid_ex))
                goto ignore_joinbss_callback;
        if (pnetwork->join_res > 0) {
-               if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) {
+               if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
                        /*s1. find ptarget_wlan*/
-                       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
-                               if (the_same_macaddr == true)
+                       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
+                               if (the_same_macaddr) {
                                        ptarget_wlan =
                                            r8712_find_network(&pmlmepriv->
                                            scanned_queue,
                                            cur_network->network.MacAddress);
-                               else {
+                               else {
                                        pcur_wlan =
                                             r8712_find_network(&pmlmepriv->
                                             scanned_queue,
@@ -813,7 +816,7 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
 
                        /*s2. find ptarget_sta & update ptarget_sta*/
                        if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
-                               if (the_same_macaddr == true) {
+                               if (the_same_macaddr) {
                                        ptarget_sta =
                                                 r8712_get_stainfo(pstapriv,
                                                 pnetwork->network.MacAddress);
@@ -821,10 +824,11 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
                                                ptarget_sta =
                                                 r8712_alloc_stainfo(pstapriv,
                                                 pnetwork->network.MacAddress);
-                               } else
+                               } else {
                                        ptarget_sta =
                                                 r8712_alloc_stainfo(pstapriv,
                                                 pnetwork->network.MacAddress);
+                               }
                                if (ptarget_sta) /*update ptarget_sta*/ {
                                        ptarget_sta->aid = pnetwork->join_res;
                                        ptarget_sta->qos_option = 1;
@@ -897,14 +901,14 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
                        update_ht_cap(adapter, cur_network->network.IEs,
                                      cur_network->network.IELength);
                        /*indicate connect*/
-                       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
-                               == true)
+                       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
                                r8712_indicate_connect(adapter);
                        del_timer(&pmlmepriv->assoc_timer);
-               } else
+               } else {
                        goto ignore_joinbss_callback;
+               }
        } else {
-               if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) {
+               if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
                        mod_timer(&pmlmepriv->assoc_timer,
                                  jiffies + msecs_to_jiffies(1));
                        _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
@@ -924,7 +928,7 @@ void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf)
        struct stassoc_event *pstassoc  = (struct stassoc_event *)pbuf;
 
        /* to do: */
-       if (r8712_access_ctrl(&adapter->acl_list, pstassoc->macaddr) == false)
+       if (!r8712_access_ctrl(&adapter->acl_list, pstassoc->macaddr))
                return;
        psta = r8712_get_stainfo(&adapter->stapriv, pstassoc->macaddr);
        if (psta != NULL) {
@@ -946,8 +950,8 @@ void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf)
                psta->XPrivacy = adapter->securitypriv.PrivacyAlgrthm;
        psta->ieee8021x_blocked = false;
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
-       if ((check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true) ||
-           (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)) {
+       if (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
+           check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
                if (adapter->stapriv.asoc_sta_count == 2) {
                        /* a sta + bc/mc_stainfo (not Ibss_stainfo) */
                        r8712_indicate_connect(adapter);
@@ -969,7 +973,7 @@ void r8712_stadel_event_callback(struct _adapter *adapter, u8 *pbuf)
        struct wlan_network *tgt_network = &pmlmepriv->cur_network;
 
        spin_lock_irqsave(&pmlmepriv->lock, irqL2);
-       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
+       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
                r8712_ind_disconnect(adapter);
                r8712_free_assoc_resources(adapter);
        }
@@ -1046,7 +1050,7 @@ void r8712_got_addbareq_event_callback(struct _adapter *adapter, u8 *pbuf)
 
 void r8712_wpspbc_event_callback(struct _adapter *adapter, u8 *pbuf)
 {
-       if (adapter->securitypriv.wps_hw_pbc_pressed == false)
+       if (!adapter->securitypriv.wps_hw_pbc_pressed)
                adapter->securitypriv.wps_hw_pbc_pressed = true;
 }
 
@@ -1081,7 +1085,7 @@ void _r8712_join_timeout_handler(struct _adapter *adapter)
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
        _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
        pmlmepriv->to_join = false;
-       if (check_fwstate(pmlmepriv, _FW_LINKED) == true) {
+       if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                r8712_os_indicate_disconnect(adapter);
                _clr_fwstate_(pmlmepriv, _FW_LINKED);
        }
@@ -1131,8 +1135,8 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
        phead = &queue->queue;
        pmlmepriv->pscanned = phead->next;
        while (1) {
-               if (end_of_queue_search(phead, pmlmepriv->pscanned) == true) {
-                       if ((pmlmepriv->assoc_by_rssi == true) &&
+               if (end_of_queue_search(phead, pmlmepriv->pscanned)) {
+                       if ((pmlmepriv->assoc_by_rssi) &&
                            (pnetwork_max_rssi != NULL)) {
                                pnetwork = pnetwork_max_rssi;
                                goto ask_for_joinbss;
@@ -1144,7 +1148,7 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
                if (pnetwork == NULL)
                        return _FAIL;
                pmlmepriv->pscanned = pmlmepriv->pscanned->next;
-               if (pmlmepriv->assoc_by_bssid == true) {
+               if (pmlmepriv->assoc_by_bssid) {
                        dst_ssid = pnetwork->network.MacAddress;
                        src_ssid = pmlmepriv->assoc_bssid;
                        if (!memcmp(dst_ssid, src_ssid, ETH_ALEN)) {
@@ -1164,23 +1168,25 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
                                }
                                goto ask_for_joinbss;
                        }
-               } else if (pmlmepriv->assoc_ssid.SsidLength == 0)
+               } else if (pmlmepriv->assoc_ssid.SsidLength == 0) {
                        goto ask_for_joinbss;
+               }
                dst_ssid = pnetwork->network.Ssid.Ssid;
                src_ssid = pmlmepriv->assoc_ssid.Ssid;
                if ((pnetwork->network.Ssid.SsidLength ==
                    pmlmepriv->assoc_ssid.SsidLength) &&
                    (!memcmp(dst_ssid, src_ssid,
                     pmlmepriv->assoc_ssid.SsidLength))) {
-                       if (pmlmepriv->assoc_by_rssi == true) {
+                       if (pmlmepriv->assoc_by_rssi) {
                                /* if the ssid is the same, select the bss
                                 *  which has the max rssi*/
                                if (pnetwork_max_rssi) {
                                        if (pnetwork->network.Rssi >
                                            pnetwork_max_rssi->network.Rssi)
                                                pnetwork_max_rssi = pnetwork;
-                               } else
+                               } else {
                                        pnetwork_max_rssi = pnetwork;
+                               }
                        } else if (is_desired_network(adapter, pnetwork)) {
                                if (check_fwstate(pmlmepriv, _FW_LINKED)) {
                                        r8712_disassoc_cmd(adapter);
@@ -1190,7 +1196,7 @@ int r8712_select_and_join_from_scan(struct mlme_priv *pmlmepriv)
                        }
                }
        }
-       return _FAIL;
+
 ask_for_joinbss:
        return r8712_joinbss_cmd(adapter, pnetwork);
 }
@@ -1408,7 +1414,7 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
        while (cnt < in_len) {
                if (in_ie[cnt] == authmode) {
                        if ((authmode == _WPA_IE_ID_) &&
-                           (!memcmp(&in_ie[cnt+2], &wpa_oui[0], 4))) {
+                           (!memcmp(&in_ie[cnt + 2], &wpa_oui[0], 4))) {
                                memcpy(&sec_ie[0], &in_ie[cnt],
                                        in_ie[cnt + 1] + 2);
                                match = true;
@@ -1426,10 +1432,10 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
                                memcpy(&bkup_ie[0], &in_ie[cnt],
                                        in_ie[cnt + 1] + 2);
                }
-               cnt += in_ie[cnt+1] + 2; /*get next*/
+               cnt += in_ie[cnt + 1] + 2; /*get next*/
        }
        /*restruct WPA IE or WPA2 IE in sec_ie[] */
-       if (match == true) {
+       if (match) {
                if (sec_ie[0] == _WPA_IE_ID_) {
                        /* parsing SSN IE to select required encryption
                         * algorithm, and set the bc/mc encryption algorithm */
@@ -1486,7 +1492,7 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
                                        /*select the uncst_oui and remove
                                         * the other uncst_oui*/
                                        cnt = sec_ie[12];
-                                       remove_cnt = (cnt-1) * 4;
+                                       remove_cnt = (cnt - 1) * 4;
                                        sec_ie[12] = 0x01;
                                        memcpy(&sec_ie[14], &uncst_oui[0], 4);
                                        /*remove the other unicast suit*/
@@ -1547,7 +1553,7 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
                                        /*select the uncst_oui and remove the
                                         * other uncst_oui*/
                                        cnt = sec_ie[8];
-                                       remove_cnt = (cnt-1)*4;
+                                       remove_cnt = (cnt - 1) * 4;
                                        sec_ie[8] = 0x01;
                                        memcpy(&sec_ie[10], &uncst_oui[0], 4);
                                        /*remove the other unicast suit*/
@@ -1555,7 +1561,7 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
                                                &sec_ie[14 + remove_cnt],
                                                (sec_ie[1] - 14 + 2 -
                                                remove_cnt));
-                                       sec_ie[1] = sec_ie[1]-remove_cnt;
+                                       sec_ie[1] = sec_ie[1] - remove_cnt;
                                }
                                break;
                        }
@@ -1566,8 +1572,8 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
                memcpy(out_ie, in_ie, 12);
                ielength = 12;
                /*copy RSN or SSN*/
-               if (match == true) {
-                       memcpy(&out_ie[ielength], &sec_ie[0], sec_ie[1]+2);
+               if (match) {
+                       memcpy(&out_ie[ielength], &sec_ie[0], sec_ie[1] + 2);
                        ielength += sec_ie[1] + 2;
                        if (authmode == _WPA2_IE_ID_) {
                                /*the Pre-Authentication bit should be zero*/
@@ -1580,9 +1586,9 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
                /*copy fixed ie only*/
                memcpy(out_ie, in_ie, 12);
                ielength = 12;
-               if (psecuritypriv->wps_phase == true) {
-                       memcpy(out_ie+ielength, psecuritypriv->wps_ie,
-                               psecuritypriv->wps_ie_len);
+               if (psecuritypriv->wps_phase) {
+                       memcpy(out_ie + ielength, psecuritypriv->wps_ie,
+                              psecuritypriv->wps_ie_len);
                        ielength += psecuritypriv->wps_ie_len;
                }
        }
@@ -1696,11 +1702,11 @@ unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
        struct ht_priv *phtpriv = &pmlmepriv->htpriv;
 
        phtpriv->ht_option = 0;
-       p = r8712_get_ie(in_ie+12, _HT_CAPABILITY_IE_, &ielen, in_len-12);
+       p = r8712_get_ie(in_ie + 12, _HT_CAPABILITY_IE_, &ielen, in_len - 12);
        if (p && (ielen > 0)) {
                if (pqospriv->qos_option == 0) {
                        out_len = *pout_len;
-                       r8712_set_ie(out_ie+out_len, _VENDOR_SPECIFIC_IE_,
+                       r8712_set_ie(out_ie + out_len, _VENDOR_SPECIFIC_IE_,
                                     _WMM_IE_Length_, WMM_IE, pout_len);
                        pqospriv->qos_option = 1;
                }
@@ -1714,7 +1720,7 @@ unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
                                    IEEE80211_HT_CAP_DSSSCCK40;
                ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR &
                                0x03) | (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
-               r8712_set_ie(out_ie+out_len, _HT_CAPABILITY_IE_,
+               r8712_set_ie(out_ie + out_len, _HT_CAPABILITY_IE_,
                             sizeof(struct ieee80211_ht_cap),
                             (unsigned char *)&ht_capie, pout_len);
                phtpriv->ht_option = 1;
@@ -1738,7 +1744,7 @@ static void update_ht_cap(struct _adapter *padapter, u8 *pie, uint ie_len)
        if (!phtpriv->ht_option)
                return;
        /* maybe needs check if ap supports rx ampdu. */
-       if ((phtpriv->ampdu_enable == false) &&
+       if (!phtpriv->ampdu_enable &&
            (pregistrypriv->ampdu_enable == 1))
                phtpriv->ampdu_enable = true;
        /*check Max Rx A-MPDU Size*/
@@ -1748,11 +1754,11 @@ static void update_ht_cap(struct _adapter *padapter, u8 *pie, uint ie_len)
                                &len, ie_len -
                                sizeof(struct NDIS_802_11_FIXED_IEs));
        if (p && len > 0) {
-               pht_capie = (struct ieee80211_ht_cap *)(p+2);
+               pht_capie = (struct ieee80211_ht_cap *)(p + 2);
                max_ampdu_sz = (pht_capie->ampdu_params_info &
                                IEEE80211_HT_CAP_AMPDU_FACTOR);
                /* max_ampdu_sz (kbytes); */
-               max_ampdu_sz = 1 << (max_ampdu_sz+3);
+               max_ampdu_sz = 1 << (max_ampdu_sz + 3);
                phtpriv->rx_ampdu_maxlen = max_ampdu_sz;
        }
        /* for A-MPDU Rx reordering buffer control for bmc_sta & sta_info
@@ -1780,7 +1786,7 @@ static void update_ht_cap(struct _adapter *padapter, u8 *pie, uint ie_len)
        len = 0;
        p = r8712_get_ie(pie + sizeof(struct NDIS_802_11_FIXED_IEs),
                   _HT_ADD_INFO_IE_, &len,
-                  ie_len-sizeof(struct NDIS_802_11_FIXED_IEs));
+                  ie_len - sizeof(struct NDIS_802_11_FIXED_IEs));
 }
 
 void r8712_issue_addbareq_cmd(struct _adapter *padapter, int priority)
@@ -1788,8 +1794,8 @@ void r8712_issue_addbareq_cmd(struct _adapter *padapter, int priority)
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct ht_priv   *phtpriv = &pmlmepriv->htpriv;
 
-       if ((phtpriv->ht_option == 1) && (phtpriv->ampdu_enable == true)) {
-               if (phtpriv->baddbareq_issued[priority] == false) {
+       if ((phtpriv->ht_option == 1) && (phtpriv->ampdu_enable)) {
+               if (!phtpriv->baddbareq_issued[priority]) {
                        r8712_addbareq_cmd(padapter, (u8)priority);
                        phtpriv->baddbareq_issued[priority] = true;
                }
index 08d6c986c11e26f5afe8f3eaab963ab31b54f949..61e0eb745d21f6c18553d43f6804809959ff3b8c 100644 (file)
@@ -153,7 +153,7 @@ static inline void clr_fwstate(struct mlme_priv *pmlmepriv, sint state)
        unsigned long irqL;
 
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
-       if (check_fwstate(pmlmepriv, state) == true)
+       if (check_fwstate(pmlmepriv, state))
                pmlmepriv->fw_state ^= state;
        spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
 }
index 26201ea3cca6594e6a2405821a0337426927d2a3..44da4fe893810532a40852f5a5c32da6cb03cb18 100644 (file)
@@ -211,19 +211,18 @@ static u32 bitshift(u32 bitmask)
        u32 i;
 
        for (i = 0; i <= 31; i++)
-               if (((bitmask>>i) &  0x1) == 1)
+               if (((bitmask >> i) &  0x1) == 1)
                        break;
        return i;
 }
 
 static u32 get_bb_reg(struct _adapter *pAdapter, u16 offset, u32 bitmask)
 {
-       u32 org_value, bit_shift, new_value;
+       u32 org_value, bit_shift;
 
        org_value = r8712_bb_reg_read(pAdapter, offset);
        bit_shift = bitshift(bitmask);
-       new_value = (org_value & bitmask) >> bit_shift;
-       return new_value;
+       return (org_value & bitmask) >> bit_shift;
 }
 
 static u8 set_bb_reg(struct _adapter *pAdapter,
@@ -237,20 +236,20 @@ static u8 set_bb_reg(struct _adapter *pAdapter,
                org_value = r8712_bb_reg_read(pAdapter, offset);
                bit_shift = bitshift(bitmask);
                new_value = ((org_value & (~bitmask)) | (value << bit_shift));
-       } else
+       } else {
                new_value = value;
+       }
        return r8712_bb_reg_write(pAdapter, offset, new_value);
 }
 
 static u32 get_rf_reg(struct _adapter *pAdapter, u8 path, u8 offset,
                      u32 bitmask)
 {
-       u32 org_value, bit_shift, new_value;
+       u32 org_value, bit_shift;
 
        org_value = r8712_rf_reg_read(pAdapter, path, offset);
        bit_shift = bitshift(bitmask);
-       new_value = (org_value & bitmask) >> bit_shift;
-       return new_value;
+       return (org_value & bitmask) >> bit_shift;
 }
 
 static u8 set_rf_reg(struct _adapter *pAdapter, u8 path, u8 offset, u32 bitmask,
@@ -262,8 +261,9 @@ static u8 set_rf_reg(struct _adapter *pAdapter, u8 path, u8 offset, u32 bitmask,
                org_value = r8712_rf_reg_read(pAdapter, path, offset);
                bit_shift = bitshift(bitmask);
                new_value = ((org_value & (~bitmask)) | (value << bit_shift));
-       } else
+       } else {
                new_value = value;
+       }
        return r8712_rf_reg_write(pAdapter, path, offset, new_value);
 }
 
@@ -305,7 +305,8 @@ static void SetOFDMTxPower(struct _adapter *pAdapter, u8 TxPower)
 {
        u32 TxAGC = 0;
 
-       TxAGC |= ((TxPower<<24)|(TxPower<<16)|(TxPower<<8)|TxPower);
+       TxAGC |= ((TxPower << 24) | (TxPower << 16) | (TxPower << 8) |
+                 TxPower);
        set_bb_reg(pAdapter, rTxAGC_Rate18_06, bTxAGCRate18_06, TxAGC);
        set_bb_reg(pAdapter, rTxAGC_Rate54_24, bTxAGCRate54_24, TxAGC);
        set_bb_reg(pAdapter, rTxAGC_Mcs03_Mcs00, bTxAGCRateMCS3_MCS0, TxAGC);
@@ -326,12 +327,12 @@ void r8712_SetTxAGCOffset(struct _adapter *pAdapter, u32 ulTxAGCOffset)
 {
        u32 TxAGCOffset_B, TxAGCOffset_C, TxAGCOffset_D, tmpAGC;
 
-       TxAGCOffset_B = (ulTxAGCOffset&0x000000ff);
-       TxAGCOffset_C = (ulTxAGCOffset & 0x0000ff00)>>8;
-       TxAGCOffset_D = (ulTxAGCOffset & 0x00ff0000)>>16;
-       tmpAGC = (TxAGCOffset_D<<8 | TxAGCOffset_C<<4 | TxAGCOffset_B);
+       TxAGCOffset_B = (ulTxAGCOffset & 0x000000ff);
+       TxAGCOffset_C = (ulTxAGCOffset & 0x0000ff00) >> 8;
+       TxAGCOffset_D = (ulTxAGCOffset & 0x00ff0000) >> 16;
+       tmpAGC = (TxAGCOffset_D << 8 | TxAGCOffset_C << 4 | TxAGCOffset_B);
        set_bb_reg(pAdapter, rFPGA0_TxGainStage,
-                       (bXBTxAGC|bXCTxAGC|bXDTxAGC), tmpAGC);
+                       (bXBTxAGC | bXCTxAGC | bXDTxAGC), tmpAGC);
 }
 
 void r8712_SetDataRate(struct _adapter *pAdapter)
@@ -377,7 +378,7 @@ void r8712_SwitchBandwidth(struct _adapter *pAdapter)
                 * Set Control channel to upper or lower. These settings are
                 * required only for 40MHz */
                set_bb_reg(pAdapter, rCCK0_System, bCCKSideBand,
-                          (HAL_PRIME_CHNL_OFFSET_DONT_CARE>>1));
+                          (HAL_PRIME_CHNL_OFFSET_DONT_CARE >> 1));
                set_bb_reg(pAdapter, rOFDM1_LSTF, 0xC00,
                           HAL_PRIME_CHNL_OFFSET_DONT_CARE);
                set_bb_reg(pAdapter, rFPGA0_AnalogParameter2, bMaskDWord, 0x18);
@@ -490,12 +491,6 @@ void r8712_SwitchAntenna(struct _adapter *pAdapter)
        set_bb_reg(pAdapter, rCCK0_AFESetting, bMaskByte3, cck_ant_sel_val);
 }
 
-void r8712_SetCrystalCap(struct _adapter *pAdapter)
-{
-       set_bb_reg(pAdapter, rFPGA0_AnalogParameter1, bXtalCap,
-                  pAdapter->mppriv.curr_crystalcap);
-}
-
 static void TriggerRFThermalMeter(struct _adapter *pAdapter)
 {
        /* 0x24: RF Reg[6:5] */
index 75893f225dc0af63d1cf221020a7625b918b50e4..3f3b2e73b7d266dc48f548a907fcc2515813e16f 100644 (file)
@@ -272,7 +272,6 @@ void r8712_SetTxAGCOffset(struct _adapter *pAdapter, u32 ulTxAGCOffset);
 void r8712_SetDataRate(struct _adapter *pAdapter);
 void r8712_SwitchBandwidth(struct _adapter *pAdapter);
 void r8712_SwitchAntenna(struct _adapter *pAdapter);
-void r8712_SetCrystalCap(struct _adapter *pAdapter);
 void r8712_GetThermalMeter(struct _adapter *pAdapter, u32 *value);
 void r8712_SetContinuousTx(struct _adapter *pAdapter, u8 bStart);
 void r8712_SetSingleCarrierTx(struct _adapter *pAdapter, u8 bStart);
index 77f01bf1ca3c023e04653e7c1e5290ad4efb398d..b98a596757f5ae206a0022b6de190aef9c4fe1f6 100644 (file)
@@ -56,8 +56,9 @@ uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv)
                                         Adapter->registrypriv.wireless_mode;
                        *poid_par_priv->bytes_rw =
                                        poid_par_priv->information_buf_len;
-               } else
+               } else {
                        status = RNDIS_STATUS_INVALID_LENGTH;
+               }
        } else {
                status = RNDIS_STATUS_NOT_ACCEPTED;
        }
@@ -178,10 +179,11 @@ static int mp_start_test(struct _adapter *padapter)
        if (length % 4) {
                /*round up to multiple of 4 bytes.*/
                bssid.Length = ((length >> 2) + 1) << 2;
-       } else
+       } else {
                bssid.Length = length;
+       }
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
+       if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
                goto end_of_mp_start_test;
        /*init mp_start_test status*/
        pmppriv->prev_fw_state = get_fwstate(pmlmepriv);
@@ -223,7 +225,7 @@ static int mp_stop_test(struct _adapter *padapter)
        unsigned long irqL;
 
        spin_lock_irqsave(&pmlmepriv->lock, irqL);
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == false)
+       if (!check_fwstate(pmlmepriv, WIFI_MP_STATE))
                goto end_of_mp_stop_test;
        /* 3 1. disconnect psudo AdHoc */
        r8712_os_indicate_disconnect(padapter);
@@ -247,9 +249,9 @@ int mp_start_joinbss(struct _adapter *padapter, struct ndis_802_11_ssid *pssid)
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        unsigned char res = _SUCCESS;
 
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == false)
+       if (!check_fwstate(pmlmepriv, WIFI_MP_STATE))
                return _FAIL;
-       if (check_fwstate(pmlmepriv, _FW_LINKED) == false)
+       if (!check_fwstate(pmlmepriv, _FW_LINKED))
                return _FAIL;
        _clr_fwstate_(pmlmepriv, _FW_LINKED);
        res = r8712_setassocsta_cmd(padapter, pmppriv->network_macaddr);
@@ -293,7 +295,7 @@ uint oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv)
        r8712_write8(Adapter, MSR, 1); /* Link in ad hoc network, 0x1025004C */
        r8712_write8(Adapter, RCR, 0); /* RCR : disable all pkt, 0x10250048 */
        /* RCR disable Check BSSID, 0x1025004a */
-       r8712_write8(Adapter, RCR+2, 0x57);
+       r8712_write8(Adapter, RCR + 2, 0x57);
        /* disable RX filter map , mgt frames will put in RX FIFO 0 */
        r8712_write16(Adapter, RXFLTMAP0, 0x0);
        val8 = r8712_read8(Adapter, EE_9346CR);
@@ -388,8 +390,9 @@ uint oid_rt_pro_query_tx_packet_sent_hdl(
                *(u32 *)poid_par_priv->information_buf =
                                        Adapter->mppriv.tx_pktcount;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                status = RNDIS_STATUS_INVALID_LENGTH;
+       }
        return status;
 }
 
@@ -408,8 +411,9 @@ uint oid_rt_pro_query_rx_packet_received_hdl(
                *(u32 *)poid_par_priv->information_buf =
                                        Adapter->mppriv.rx_pktcount;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                status = RNDIS_STATUS_INVALID_LENGTH;
+       }
        return status;
 }
 
@@ -428,8 +432,9 @@ uint oid_rt_pro_query_rx_packet_crc32_error_hdl(
                *(u32 *)poid_par_priv->information_buf =
                                        Adapter->mppriv.rx_crcerrpktcount;
                *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
-       } else
+       } else {
                status = RNDIS_STATUS_INVALID_LENGTH;
+       }
        return status;
 }
 
@@ -457,8 +462,9 @@ uint oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv
        if (poid_par_priv->information_buf_len == sizeof(u32)) {
                Adapter->mppriv.rx_pktcount = 0;
                Adapter->mppriv.rx_crcerrpktcount = 0;
-       } else
+       } else {
                status = RNDIS_STATUS_INVALID_LENGTH;
+       }
        return status;
 }
 
@@ -684,7 +690,7 @@ uint oid_rt_get_thermal_meter_hdl(struct oid_par_priv *poid_par_priv)
        if (poid_par_priv->type_of_oid != QUERY_OID)
                return RNDIS_STATUS_NOT_ACCEPTED;
 
-       if (Adapter->mppriv.act_in_progress == true)
+       if (Adapter->mppriv.act_in_progress)
                return RNDIS_STATUS_NOT_ACCEPTED;
 
        if (poid_par_priv->information_buf_len < sizeof(u8))
@@ -728,7 +734,7 @@ uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv)
        if ((addr > 511) || (cnts < 1) || (cnts > 512) || (addr + cnts) >
             EFUSE_MAX_SIZE)
                return RNDIS_STATUS_NOT_ACCEPTED;
-       if (r8712_efuse_access(Adapter, true, addr, cnts, data) == false)
+       if (!r8712_efuse_access(Adapter, true, addr, cnts, data))
                status = RNDIS_STATUS_FAILURE;
        *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
        return status;
@@ -756,7 +762,7 @@ uint oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv)
        if ((addr > 511) || (cnts < 1) || (cnts > 512) ||
            (addr + cnts) > r8712_efuse_get_max_size(Adapter))
                return RNDIS_STATUS_NOT_ACCEPTED;
-       if (r8712_efuse_access(Adapter, false, addr, cnts, data) == false)
+       if (!r8712_efuse_access(Adapter, false, addr, cnts, data))
                status = RNDIS_STATUS_FAILURE;
        return status;
 }
@@ -824,7 +830,7 @@ uint oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv)
                        status = RNDIS_STATUS_FAILURE;
        } else {
                /* SET_OID */
-               if (r8712_efuse_reg_init(Adapter) == true) {
+               if (r8712_efuse_reg_init(Adapter)) {
                        if (r8712_efuse_map_write(Adapter, 0,
                            EFUSE_MAP_MAX_SIZE, data))
                                *poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE;
@@ -879,7 +885,7 @@ uint oid_rt_set_rx_packet_type_hdl(struct oid_par_priv
                rcr_val32 |= (RCR_AB | RCR_AM | RCR_APM | RCR_AAP | RCR_ACRC32);
                break;
        case RX_PKT_PHY_MATCH:
-               rcr_val32 |= (RCR_APM|RCR_ACRC32);
+               rcr_val32 |= (RCR_APM | RCR_ACRC32);
                break;
        default:
                rcr_val32 &= ~(RCR_AAP |
index 9bc04f474d18d7c79311c8bd6fc80b48015a6550..bf10d6db50e8ba1e638cd3124d83710477d5203d 100644 (file)
@@ -44,8 +44,7 @@ void r8712_set_rpwm(struct _adapter *padapter, u8 val8)
                if (pwrpriv->rpwm_retry == 0)
                        return;
        }
-       if ((padapter->bDriverStopped == true) ||
-           (padapter->bSurpriseRemoved == true))
+       if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
                return;
        rpwm = val8 | pwrpriv->tog;
        switch (val8) {
@@ -129,8 +128,7 @@ static void _rpwm_check_handler (struct _adapter *padapter)
 {
        struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
 
-       if (padapter->bDriverStopped == true ||
-           padapter->bSurpriseRemoved == true)
+       if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
                return;
        if (pwrpriv->cpwm != pwrpriv->rpwm)
                schedule_work(&pwrpriv->rpwm_workitem);
index 046a46c4cd7ff1e2f392f827ab6272569b5bff90..4ff53015518703159ab42fa5799c2a09048a1928 100644 (file)
@@ -83,7 +83,7 @@ sint _r8712_init_recv_priv(struct recv_priv *precvpriv,
        precvpriv->precv_frame_buf = precvpriv->pallocated_frame_buf +
                                    RXFRAME_ALIGN_SZ -
                                    ((addr_t)(precvpriv->pallocated_frame_buf) &
-                                   (RXFRAME_ALIGN_SZ-1));
+                                   (RXFRAME_ALIGN_SZ - 1));
        precvframe = (union recv_frame *)precvpriv->precv_frame_buf;
        for (i = 0; i < NR_RECVFRAME; i++) {
                INIT_LIST_HEAD(&(precvframe->u.list));
@@ -112,9 +112,9 @@ union recv_frame *r8712_alloc_recvframe(struct  __queue *pfree_recv_queue)
        struct recv_priv *precvpriv;
 
        spin_lock_irqsave(&pfree_recv_queue->lock, irqL);
-       if (list_empty(&pfree_recv_queue->queue))
+       if (list_empty(&pfree_recv_queue->queue)) {
                precvframe = NULL;
-       else {
+       else {
                phead = &pfree_recv_queue->queue;
                plist = phead->next;
                precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
@@ -147,7 +147,7 @@ void r8712_free_recvframe_queue(struct  __queue *pframequeue,
        spin_lock(&pframequeue->lock);
        phead = &pframequeue->queue;
        plist = phead->next;
-       while (end_of_queue_search(phead, plist) == false) {
+       while (!end_of_queue_search(phead, plist)) {
                precvframe = LIST_CONTAINOR(plist, union recv_frame, u);
                plist = plist->next;
                r8712_free_recvframe(precvframe, pfree_recv_queue);
@@ -178,10 +178,11 @@ sint r8712_recvframe_chkmic(struct _adapter *adapter,
                                idx = iv[3];
                                mickey = &psecuritypriv->XGrprxmickey[(((idx >>
                                         6) & 0x3)) - 1].skey[0];
-                               if (psecuritypriv->binstallGrpkey == false)
+                               if (!psecuritypriv->binstallGrpkey)
                                        return _FAIL;
-                       } else
+                       } else {
                                mickey = &stainfo->tkiprxmickey.skey[0];
+                       }
                        /*icv_len included the mic code*/
                        datalen = precvframe->u.hdr.len - prxattrib->hdrlen -
                                  prxattrib->iv_len - prxattrib->icv_len - 8;
@@ -197,16 +198,15 @@ sint r8712_recvframe_chkmic(struct _adapter *adapter,
                                if (miccode[i] != *(pframemic + i))
                                        bmic_err = true;
                        }
-                       if (bmic_err == true) {
-                               if (prxattrib->bdecrypted == true)
+                       if (bmic_err) {
+                               if (prxattrib->bdecrypted)
                                        r8712_handle_tkip_mic_err(adapter,
                                                (u8)IS_MCAST(prxattrib->ra));
                                res = _FAIL;
                        } else {
                                /* mic checked ok */
-                               if ((psecuritypriv->bcheck_grpkey ==
-                                    false) && (IS_MCAST(prxattrib->ra) ==
-                                    true))
+                               if (!psecuritypriv->bcheck_grpkey &&
+                                   IS_MCAST(prxattrib->ra))
                                        psecuritypriv->bcheck_grpkey = true;
                        }
                        recvframe_pull_tail(precvframe, 8);
@@ -224,7 +224,7 @@ union recv_frame *r8712_decryptor(struct _adapter *padapter,
        union recv_frame *return_packet = precv_frame;
 
        if ((prxattrib->encrypt > 0) && ((prxattrib->bdecrypted == 0) ||
-          (psecuritypriv->sw_decrypt == true))) {
+           psecuritypriv->sw_decrypt)) {
                psecuritypriv->hw_decrypted = false;
                switch (prxattrib->encrypt) {
                case _WEP40_:
@@ -240,8 +240,9 @@ union recv_frame *r8712_decryptor(struct _adapter *padapter,
                default:
                                break;
                }
-       } else if (prxattrib->bdecrypted == 1)
+       } else if (prxattrib->bdecrypted == 1) {
                psecuritypriv->hw_decrypted = true;
+       }
        return return_packet;
 }
 /*###set the security information in the recv_frame */
@@ -271,9 +272,9 @@ union recv_frame *r8712_portctrl(struct _adapter *adapter,
                if ((psta != NULL) && (psta->ieee8021x_blocked)) {
                        /* blocked
                         * only accept EAPOL frame */
-                       if (ether_type == 0x888e)
+                       if (ether_type == 0x888e) {
                                prtnframe = precv_frame;
-                       else {
+                       else {
                                /*free this frame*/
                                r8712_free_recvframe(precv_frame,
                                         &adapter->recvpriv.free_recv_queue);
@@ -290,8 +291,9 @@ union recv_frame *r8712_portctrl(struct _adapter *adapter,
                                prtnframe = precv_frame;
                        }
                }
-       } else
+       } else {
                prtnframe = precv_frame;
+       }
        return prtnframe;
 }
 
@@ -299,7 +301,7 @@ static sint recv_decache(union recv_frame *precv_frame, u8 bretry,
                  struct stainfo_rxcache *prxcache)
 {
        sint tid = precv_frame->u.hdr.attrib.priority;
-       u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num&0xffff) << 4) |
+       u16 seq_ctrl = ((precv_frame->u.hdr.attrib.seq_num & 0xffff) << 4) |
                        (precv_frame->u.hdr.attrib.frag_num & 0xf);
 
        if (tid > 15)
@@ -324,8 +326,8 @@ static sint sta2sta_data_frame(struct _adapter *adapter,
        u8 *sta_addr = NULL;
        sint bmcast = IS_MCAST(pattrib->dst);
 
-       if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
-           (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
+       if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
+           check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
                /* filter packets that SA is myself or multicast or broadcast */
                if (!memcmp(myhwaddr, pattrib->src, ETH_ALEN))
                        return _FAIL;
@@ -336,13 +338,13 @@ static sint sta2sta_data_frame(struct _adapter *adapter,
                    (memcmp(pattrib->bssid, mybssid, ETH_ALEN)))
                        return _FAIL;
                sta_addr = pattrib->src;
-       } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
+       } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
                /* For Station mode, sa and bssid should always be BSSID,
                 * and DA is my mac-address */
                if (memcmp(pattrib->bssid, pattrib->src, ETH_ALEN))
                        return _FAIL;
               sta_addr = pattrib->bssid;
-        } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
+       } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
                if (bmcast) {
                        /* For AP mode, if DA == MCAST, then BSSID should
                         * be also MCAST */
@@ -355,21 +357,22 @@ static sint sta2sta_data_frame(struct _adapter *adapter,
                                return _FAIL;
                        sta_addr = pattrib->src;
                }
-         } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
+       } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
                memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
                memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
                memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
                memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
                memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
                sta_addr = mybssid;
-         } else
+       } else {
                ret  = _FAIL;
+       }
        if (bmcast)
                *psta = r8712_get_bcmc_stainfo(adapter);
        else
                *psta = r8712_get_stainfo(pstapriv, sta_addr); /* get ap_info */
        if (*psta == NULL) {
-               if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
+               if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
                        adapter->mppriv.rx_pktloss++;
                return _FAIL;
        }
@@ -388,8 +391,8 @@ static sint ap2sta_data_frame(struct _adapter *adapter,
        u8 *myhwaddr = myid(&adapter->eeprompriv);
        sint bmcast = IS_MCAST(pattrib->dst);
 
-       if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)
-            && (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
+       if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) &&
+           check_fwstate(pmlmepriv, _FW_LINKED)) {
                /* if NULL-frame, drop packet */
                if ((GetFrameSubType(ptr)) == WIFI_DATA_NULL)
                        return _FAIL;
@@ -419,8 +422,8 @@ static sint ap2sta_data_frame(struct _adapter *adapter,
                       *psta = r8712_get_stainfo(pstapriv, pattrib->bssid);
                if (*psta == NULL)
                        return _FAIL;
-       } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
-                  (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
+       } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) &&
+                  check_fwstate(pmlmepriv, _FW_LINKED)) {
                memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
                memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
                memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
@@ -430,8 +433,9 @@ static sint ap2sta_data_frame(struct _adapter *adapter,
                *psta = r8712_get_stainfo(pstapriv, pattrib->bssid);
                if (*psta == NULL)
                        return _FAIL;
-       } else
+       } else {
                return _FAIL;
+       }
        return _SUCCESS;
 }
 
@@ -444,7 +448,7 @@ static sint sta2ap_data_frame(struct _adapter *adapter,
        struct  mlme_priv *pmlmepriv = &adapter->mlmepriv;
        unsigned char *mybssid  = get_bssid(pmlmepriv);
 
-       if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
+       if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
                /* For AP mode, if DA is non-MCAST, then it must be BSSID,
                 * and bssid == BSSID
                 * For AP mode, RA=BSSID, TX=STA(SRC_ADDR), A3=DST_ADDR */
@@ -630,10 +634,10 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
        rmv_len = pattrib->hdrlen + pattrib->iv_len +
                  (bsnaphdr ? SNAP_SIZE : 0);
        len = precvframe->u.hdr.len - rmv_len;
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
+       if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
                ptr += rmv_len;
                *ptr = 0x87;
-               *(ptr+1) = 0x12;
+               *(ptr + 1) = 0x12;
                /* append rx status for mp test packets */
                ptr = recvframe_pull(precvframe, (rmv_len -
                      sizeof(struct ethhdr) + 2) - 24);
@@ -644,7 +648,7 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
                      sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
 
        memcpy(ptr, pattrib->dst, ETH_ALEN);
-       memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
+       memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN);
        if (!bsnaphdr) {
                len = htons(len);
                memcpy(ptr + 12, &len, 2);
index 862792826dc5f73839eb28a6f8dd35742cd1a6b8..09242425dad4d622bd7baad5322c0eaf890ba843 100644 (file)
@@ -175,22 +175,22 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
 
        if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL)
                return;
-       pframe = ((struct xmit_frame *)pxmitframe)->buf_addr+TXDESC_OFFSET;
+       pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET;
        /*start to encrypt each fragment*/
        if ((pattrib->encrypt == _WEP40_) || (pattrib->encrypt == _WEP104_)) {
                keylength = psecuritypriv->DefKeylen[psecuritypriv->
                            PrivacyKeyIndex];
                for (curfragnum = 0; curfragnum < pattrib->nr_frags;
                     curfragnum++) {
-                       iv = pframe+pattrib->hdrlen;
+                       iv = pframe + pattrib->hdrlen;
                        memcpy(&wepkey[0], iv, 3);
                        memcpy(&wepkey[3], &psecuritypriv->DefKey[
                                psecuritypriv->PrivacyKeyIndex].skey[0],
                                keylength);
-                       payload = pframe+pattrib->iv_len+pattrib->hdrlen;
+                       payload = pframe + pattrib->iv_len + pattrib->hdrlen;
                        if ((curfragnum + 1) == pattrib->nr_frags) {
-                               length = pattrib->last_txcmdsz-pattrib->
-                                        hdrlen-pattrib->iv_len -
+                               length = pattrib->last_txcmdsz - pattrib->
+                                        hdrlen - pattrib->iv_len -
                                         pattrib->icv_len;
                                *((u32 *)crc) = cpu_to_le32(getcrc32(
                                                payload, length));
@@ -200,14 +200,15 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
                                arcfour_encrypt(&mycontext, payload + length,
                                                crc, 4);
                        } else {
-                               length = pxmitpriv->frag_len-pattrib->hdrlen -
-                                        pattrib->iv_len-pattrib->icv_len;
+                               length = pxmitpriv->frag_len -
+                                        pattrib->hdrlen - pattrib->iv_len -
+                                        pattrib->icv_len;
                                *((u32 *)crc) = cpu_to_le32(getcrc32(
                                                payload, length));
                                arcfour_init(&mycontext, wepkey, 3 + keylength);
                                arcfour_encrypt(&mycontext, payload, payload,
                                                length);
-                               arcfour_encrypt(&mycontext, payload+length,
+                               arcfour_encrypt(&mycontext, payload + length,
                                                crc, 4);
                                pframe += pxmitpriv->frag_len;
                                pframe = (u8 *)RND4((addr_t)(pframe));
@@ -241,8 +242,8 @@ void r8712_wep_decrypt(struct _adapter  *padapter, u8 *precvframe)
                        psecuritypriv->PrivacyKeyIndex].skey[0],
                        keylength);
                length = ((union recv_frame *)precvframe)->
-                          u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len;
-               payload = pframe+prxattrib->iv_len+prxattrib->hdrlen;
+                          u.hdr.len - prxattrib->hdrlen - prxattrib->iv_len;
+               payload = pframe + prxattrib->iv_len + prxattrib->hdrlen;
                /* decrypt payload include icv */
                arcfour_init(&mycontext, wepkey, 3 + keylength);
                arcfour_encrypt(&mycontext, payload, payload,  length);
@@ -495,11 +496,11 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, u32 iv32)
        /* Now compute an unbalanced Feistel cipher with 80-bit block */
        /* size on the 80-bit block P1K[], using the 128-bit key TK[] */
        for (i = 0; i < PHASE1_LOOP_CNT; i++) {  /* Each add is mod 2**16 */
-               p1k[0] += _S_(p1k[4] ^ TK16((i&1) + 0));
-               p1k[1] += _S_(p1k[0] ^ TK16((i&1) + 2));
-               p1k[2] += _S_(p1k[1] ^ TK16((i&1) + 4));
-               p1k[3] += _S_(p1k[2] ^ TK16((i&1) + 6));
-               p1k[4] += _S_(p1k[3] ^ TK16((i&1) + 0));
+               p1k[0] += _S_(p1k[4] ^ TK16((i & 1) + 0));
+               p1k[1] += _S_(p1k[0] ^ TK16((i & 1) + 2));
+               p1k[2] += _S_(p1k[1] ^ TK16((i & 1) + 4));
+               p1k[3] += _S_(p1k[2] ^ TK16((i & 1) + 6));
+               p1k[4] += _S_(p1k[3] ^ TK16((i & 1) + 0));
                p1k[4] +=  (unsigned short)i;   /* avoid "slide attacks" */
        }
 }
@@ -587,7 +588,7 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
        if (((struct xmit_frame *)pxmitframe)->buf_addr == NULL)
                return _FAIL;
 
-       pframe = ((struct xmit_frame *)pxmitframe)->buf_addr+TXDESC_OFFSET;
+       pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + TXDESC_OFFSET;
        /* 4 start to encrypt each fragment */
        if (pattrib->encrypt == _TKIP_) {
                if (pattrib->psta)
@@ -600,7 +601,7 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
                        for (curfragnum = 0; curfragnum < pattrib->nr_frags;
                             curfragnum++) {
                                iv = pframe + pattrib->hdrlen;
-                               payload = pframe+pattrib->iv_len +
+                               payload = pframe + pattrib->iv_len +
                                          pattrib->hdrlen;
                                GET_TKIP_PN(iv, txpn);
                                pnl = (u16)(txpn.val);
@@ -612,7 +613,8 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
                                if ((curfragnum + 1) == pattrib->nr_frags) {
                                        /* 4 the last fragment */
                                        length = pattrib->last_txcmdsz -
-                                            pattrib->hdrlen-pattrib->iv_len -
+                                            pattrib->hdrlen -
+                                            pattrib->iv_len -
                                             pattrib->icv_len;
                                        *((u32 *)crc) = cpu_to_le32(
                                                getcrc32(payload, length));
@@ -622,22 +624,25 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
                                        arcfour_encrypt(&mycontext, payload +
                                                        length, crc, 4);
                                } else {
-                                       length = pxmitpriv->frag_len-pattrib->
-                                                hdrlen-pattrib->
-                                                iv_len-pattrib->icv_len;
+                                       length = pxmitpriv->frag_len -
+                                                pattrib->hdrlen -
+                                                pattrib->iv_len -
+                                                pattrib->icv_len;
                                        *((u32 *)crc) = cpu_to_le32(getcrc32(
                                                        payload, length));
                                        arcfour_init(&mycontext, rc4key, 16);
                                        arcfour_encrypt(&mycontext, payload,
                                                         payload, length);
                                        arcfour_encrypt(&mycontext,
-                                                       payload+length, crc, 4);
+                                                       payload + length, crc,
+                                                       4);
                                        pframe += pxmitpriv->frag_len;
                                        pframe = (u8 *)RND4((addr_t)(pframe));
                                }
                        }
-               } else
+               } else {
                        res = _FAIL;
+               }
        }
        return res;
 }
@@ -666,8 +671,9 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
                stainfo = r8712_get_stainfo(&padapter->stapriv,
                                            &prxattrib->ta[0]);
                if (stainfo != NULL) {
-                       iv = pframe+prxattrib->hdrlen;
-                       payload = pframe+prxattrib->iv_len + prxattrib->hdrlen;
+                       iv = pframe + prxattrib->hdrlen;
+                       payload = pframe + prxattrib->iv_len +
+                                 prxattrib->hdrlen;
                        length = ((union recv_frame *)precvframe)->
                                 u.hdr.len - prxattrib->hdrlen -
                                 prxattrib->iv_len;
@@ -675,10 +681,11 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
                                idx = iv[3];
                                prwskey = &psecuritypriv->XGrpKey[
                                         ((idx >> 6) & 0x3) - 1].skey[0];
-                               if (psecuritypriv->binstallGrpkey == false)
+                               if (!psecuritypriv->binstallGrpkey)
                                        return _FAIL;
-                       } else
+                       } else {
                                prwskey = &stainfo->x_UncstKey.skey[0];
+                       }
                        GET_TKIP_PN(iv, txpn);
                        pnl = (u16)(txpn.val);
                        pnh = (u32)(txpn.val >> 16);
@@ -696,8 +703,9 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
                            crc[1] != payload[length - 3] ||
                            crc[0] != payload[length - 4])
                                return _FAIL;
-               } else
+               } else {
                        return _FAIL;
+               }
        }
        return _SUCCESS;
 }
@@ -851,7 +859,7 @@ static void mix_column(u8 *in, u8 *out)
        andf7[3] = in[3] & 0x7f;
        for (i = 3; i > 0; i--) {   /* logical shift left 1 bit */
                andf7[i] = andf7[i] << 1;
-               if ((andf7[i-1] & 0x80) == 0x80)
+               if ((andf7[i - 1] & 0x80) == 0x80)
                        andf7[i] = (andf7[i] | 0x01);
        }
        andf7[0] = andf7[0] << 1;
@@ -1069,14 +1077,15 @@ static sint aes_cipher(u8 *key, uint    hdrlen,
                        if (hdrlen !=  WLAN_HDR_A3_QOS_LEN)
                                hdrlen += 2;
                        qc_exists = 1;
-       } else
+       } else {
                qc_exists = 0;
+       }
        pn_vector[0] = pframe[hdrlen];
-       pn_vector[1] = pframe[hdrlen+1];
-       pn_vector[2] = pframe[hdrlen+4];
-       pn_vector[3] = pframe[hdrlen+5];
-       pn_vector[4] = pframe[hdrlen+6];
-       pn_vector[5] = pframe[hdrlen+7];
+       pn_vector[1] = pframe[hdrlen + 1];
+       pn_vector[2] = pframe[hdrlen + 4];
+       pn_vector[3] = pframe[hdrlen + 5];
+       pn_vector[4] = pframe[hdrlen + 6];
+       pn_vector[5] = pframe[hdrlen + 7];
        construct_mic_iv(mic_iv, qc_exists, a4_exists, pframe, plen, pn_vector);
        construct_mic_header1(mic_header1, hdrlen, pframe);
        construct_mic_header2(mic_header2, pframe, a4_exists, qc_exists);
@@ -1108,7 +1117,7 @@ static sint aes_cipher(u8 *key, uint      hdrlen,
                mic[j] = aes_out[j];
        /* Insert MIC into payload */
        for (j = 0; j < 8; j++)
-               pframe[payload_index+j] = mic[j];
+               pframe[payload_index + j] = mic[j];
        payload_index = hdrlen + 8;
        for (i = 0; i < num_blocks; i++) {
                construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
@@ -1121,11 +1130,11 @@ static sint aes_cipher(u8 *key, uint    hdrlen,
        if (payload_remainder > 0) {  /* If short final block, then pad it,*/
                                      /* encrypt and copy unpadded part back */
                construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
-                                     pframe, pn_vector, num_blocks+1);
+                                     pframe, pn_vector, num_blocks + 1);
                for (j = 0; j < 16; j++)
                        padded_buffer[j] = 0x00;
                for (j = 0; j < payload_remainder; j++)
-                       padded_buffer[j] = pframe[payload_index+j];
+                       padded_buffer[j] = pframe[payload_index + j];
                aes128k128d(key, ctr_preload, aes_out);
                bitwise_xor(aes_out, padded_buffer, chain_buffer);
                for (j = 0; j < payload_remainder; j++)
@@ -1137,7 +1146,7 @@ static sint aes_cipher(u8 *key, uint      hdrlen,
        for (j = 0; j < 16; j++)
                padded_buffer[j] = 0x00;
        for (j = 0; j < 8; j++)
-               padded_buffer[j] = pframe[j+hdrlen+8+plen];
+               padded_buffer[j] = pframe[j + hdrlen + 8 + plen];
        aes128k128d(key, ctr_preload, aes_out);
        bitwise_xor(aes_out, padded_buffer, chain_buffer);
        for (j = 0; j < 8; j++)
@@ -1188,8 +1197,9 @@ u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe)
                                        pframe = (u8 *)RND4((addr_t)(pframe));
                                }
                        }
-               } else
+               } else {
                        res = _FAIL;
+               }
        }
        return res;
 }
@@ -1224,13 +1234,13 @@ static sint aes_decipher(u8 *key, uint  hdrlen,
        /* start to decrypt the payload */
        /*(plen including llc, payload and mic) */
        num_blocks = (plen - 8) / 16;
-       payload_remainder = (plen-8) % 16;
+       payload_remainder = (plen - 8) % 16;
        pn_vector[0] = pframe[hdrlen];
-       pn_vector[1] = pframe[hdrlen+1];
-       pn_vector[2] = pframe[hdrlen+4];
-       pn_vector[3] = pframe[hdrlen+5];
-       pn_vector[4] = pframe[hdrlen+6];
-       pn_vector[5] = pframe[hdrlen+7];
+       pn_vector[1] = pframe[hdrlen + 1];
+       pn_vector[2] = pframe[hdrlen + 4];
+       pn_vector[3] = pframe[hdrlen + 5];
+       pn_vector[4] = pframe[hdrlen + 6];
+       pn_vector[5] = pframe[hdrlen + 7];
        if ((hdrlen == WLAN_HDR_A3_LEN) || (hdrlen ==  WLAN_HDR_A3_QOS_LEN))
                a4_exists = 0;
        else
@@ -1264,7 +1274,7 @@ static sint aes_decipher(u8 *key, uint    hdrlen,
        if (payload_remainder > 0) {  /* If short final block, pad it,*/
                /* encrypt it and copy the unpadded part back   */
                construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
-                                     pframe, pn_vector, num_blocks+1);
+                                     pframe, pn_vector, num_blocks + 1);
                for (j = 0; j < 16; j++)
                        padded_buffer[j] = 0x00;
                for (j = 0; j < payload_remainder; j++)
@@ -1277,12 +1287,12 @@ static sint aes_decipher(u8 *key, uint  hdrlen,
        /* start to calculate the mic */
        memcpy((void *)message, pframe, (hdrlen + plen + 8));
        pn_vector[0] = pframe[hdrlen];
-       pn_vector[1] = pframe[hdrlen+1];
-       pn_vector[2] = pframe[hdrlen+4];
-       pn_vector[3] = pframe[hdrlen+5];
-       pn_vector[4] = pframe[hdrlen+6];
-       pn_vector[5] = pframe[hdrlen+7];
-       construct_mic_iv(mic_iv, qc_exists, a4_exists, message, plen-8,
+       pn_vector[1] = pframe[hdrlen + 1];
+       pn_vector[2] = pframe[hdrlen + 4];
+       pn_vector[3] = pframe[hdrlen + 5];
+       pn_vector[4] = pframe[hdrlen + 6];
+       pn_vector[5] = pframe[hdrlen + 7];
+       construct_mic_iv(mic_iv, qc_exists, a4_exists, message, plen - 8,
                         pn_vector);
        construct_mic_header1(mic_header1, hdrlen, message);
        construct_mic_header2(mic_header2, message, a4_exists, qc_exists);
@@ -1314,7 +1324,7 @@ static sint aes_decipher(u8 *key, uint    hdrlen,
                mic[j] = aes_out[j];
        /* Insert MIC into payload */
        for (j = 0; j < 8; j++)
-               message[payload_index+j] = mic[j];
+               message[payload_index + j] = mic[j];
        payload_index = hdrlen + 8;
        for (i = 0; i < num_blocks; i++) {
                construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
@@ -1327,7 +1337,7 @@ static sint aes_decipher(u8 *key, uint    hdrlen,
        if (payload_remainder > 0) { /* If short final block, pad it,*/
                                     /* encrypt and copy unpadded part back */
                construct_ctr_preload(ctr_preload, a4_exists, qc_exists,
-                                     message, pn_vector, num_blocks+1);
+                                     message, pn_vector, num_blocks + 1);
                for (j = 0; j < 16; j++)
                        padded_buffer[j] = 0x00;
                for (j = 0; j < payload_remainder; j++)
@@ -1370,21 +1380,24 @@ u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
                                            &prxattrib->ta[0]);
                if (stainfo != NULL) {
                        if (IS_MCAST(prxattrib->ra)) {
-                               iv = pframe+prxattrib->hdrlen;
+                               iv = pframe + prxattrib->hdrlen;
                                idx = iv[3];
                                prwskey = &psecuritypriv->XGrpKey[
                                          ((idx >> 6) & 0x3) - 1].skey[0];
-                               if (psecuritypriv->binstallGrpkey == false)
+                               if (!psecuritypriv->binstallGrpkey)
                                        return _FAIL;
 
-                       } else
+                       } else {
                                prwskey = &stainfo->x_UncstKey.skey[0];
+                       }
                        length = ((union recv_frame *)precvframe)->
-                                u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len;
+                                u.hdr.len - prxattrib->hdrlen -
+                                prxattrib->iv_len;
                        aes_decipher(prwskey, prxattrib->hdrlen, pframe,
                                     length);
-               } else
+               } else {
                        return _FAIL;
+               }
        }
        return _SUCCESS;
 }
index 6ae8cdc1bfd1c5320f8f3ecdc2f20e4df47dfedf..162e61c6ea06e4f3a3737f489af4fcdf9b77ac0a 100644 (file)
@@ -83,7 +83,7 @@ static void mfree_all_stainfo(struct sta_priv *pstapriv)
        spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
        phead = &pstapriv->free_sta_queue.queue;
        plist = phead->next;
-       while ((end_of_queue_search(phead, plist)) == false)
+       while (!end_of_queue_search(phead, plist))
                plist = plist->next;
 
        spin_unlock_irqrestore(&pstapriv->sta_hash_lock, irqL);
@@ -117,9 +117,9 @@ struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
 
        pfree_sta_queue = &pstapriv->free_sta_queue;
        spin_lock_irqsave(&(pfree_sta_queue->lock), flags);
-       if (list_empty(&pfree_sta_queue->queue))
+       if (list_empty(&pfree_sta_queue->queue)) {
                psta = NULL;
-       else {
+       else {
                psta = LIST_CONTAINOR(pfree_sta_queue->queue.next,
                                      struct sta_info, list);
                list_del_init(&(psta->list));
@@ -222,7 +222,7 @@ void r8712_free_all_stainfo(struct _adapter *padapter)
        for (index = 0; index < NUM_STA; index++) {
                phead = &(pstapriv->sta_hash[index]);
                plist = phead->next;
-               while ((end_of_queue_search(phead, plist)) == false) {
+               while (!end_of_queue_search(phead, plist)) {
                        psta = LIST_CONTAINOR(plist,
                                              struct sta_info, hash_list);
                        plist = plist->next;
@@ -247,7 +247,7 @@ struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
        spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
        phead = &(pstapriv->sta_hash[index]);
        plist = phead->next;
-       while ((end_of_queue_search(phead, plist)) == false) {
+       while (!end_of_queue_search(phead, plist)) {
                psta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
                if ((!memcmp(psta->hwaddr, hwaddr, ETH_ALEN))) {
                        /* if found the matched address */
index 2e4fa88951ad88f4a622fe9a81e9641ca69ba7ea..68d65d230fe3e0a25645f32c2d3875323b0105a4 100644 (file)
@@ -217,8 +217,8 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
        memcpy(pattrib->dst, &etherhdr.h_dest, ETH_ALEN);
        memcpy(pattrib->src, &etherhdr.h_source, ETH_ALEN);
        pattrib->pctrl = 0;
-       if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true) ||
-           (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) {
+       if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
+           check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)) {
                memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
                memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
        } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
@@ -227,7 +227,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
        } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
                memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
                memcpy(pattrib->ta, get_bssid(pmlmepriv), ETH_ALEN);
-       } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
+       } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
                /*firstly, filter packet not belongs to mp*/
                if (pattrib->ether_type != 0x8712)
                        return _FAIL;
@@ -267,7 +267,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
                psta = r8712_get_bcmc_stainfo(padapter);
                pattrib->mac_id = 4;
        } else {
-               if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
+               if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
                        psta = r8712_get_stainfo(pstapriv,
                                                 get_bssid(pmlmepriv));
                        pattrib->mac_id = 5;
@@ -293,20 +293,21 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
        /* get ether_hdr_len */
        pattrib->pkt_hdrlen = ETH_HLEN;
 
-       if (pqospriv->qos_option)
+       if (pqospriv->qos_option) {
                r8712_set_qos(&pktfile, pattrib);
-       else {
+       else {
                pattrib->hdrlen = WLAN_HDR_A3_LEN;
                pattrib->subtype = WIFI_DATA_TYPE;
                pattrib->priority = 0;
        }
-       if (psta->ieee8021x_blocked == true) {
+       if (psta->ieee8021x_blocked) {
                pattrib->encrypt = 0;
                if ((pattrib->ether_type != 0x888e) &&
-                   (check_fwstate(pmlmepriv, WIFI_MP_STATE) == false))
+                   !check_fwstate(pmlmepriv, WIFI_MP_STATE))
                        return _FAIL;
-       } else
+       } else {
                GET_ENCRY_ALGO(psecuritypriv, psta, pattrib->encrypt, bmcast);
+       }
        switch (pattrib->encrypt) {
        case _WEP40_:
        case _WEP104_:
@@ -330,14 +331,14 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
        }
 
        if (pattrib->encrypt &&
-           ((padapter->securitypriv.sw_encrypt == true) ||
-            (psecuritypriv->hw_decrypted == false)))
+           (padapter->securitypriv.sw_encrypt ||
+           !psecuritypriv->hw_decrypted))
                pattrib->bswenc = true;
        else
                pattrib->bswenc = false;
        /* if in MP_STATE, update pkt_attrib from mp_txcmd, and overwrite
         * some settings above.*/
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
+       if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
                pattrib->priority = (txdesc.txdw1 >> QSEL_SHT) & 0x1f;
        return _SUCCESS;
 }
@@ -389,7 +390,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
                        if (pframe[1] & 1) {   /* ToDS==1 */
                                r8712_secmicappend(&micdata,
                                                   &pframe[16], 6); /*DA*/
-                               if (pframe[1]&2)  /* From Ds==1 */
+                               if (pframe[1] & 2)  /* From Ds==1 */
                                        r8712_secmicappend(&micdata,
                                                           &pframe[24], 6);
                                else
@@ -398,7 +399,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
                        } else {        /* ToDS==0 */
                                r8712_secmicappend(&micdata,
                                                   &pframe[4], 6); /* DA */
-                               if (pframe[1]&2)  /* From Ds==1 */
+                               if (pframe[1] & 2)  /* From Ds==1 */
                                        r8712_secmicappend(&micdata,
                                                           &pframe[16], 6);
                                else
@@ -413,8 +414,8 @@ static sint xmitframe_addmic(struct _adapter *padapter,
                        for (curfragnum = 0; curfragnum < pattrib->nr_frags;
                             curfragnum++) {
                                payload = (u8 *)RND4((addr_t)(payload));
-                               payload = payload+pattrib->
-                                         hdrlen+pattrib->iv_len;
+                               payload = payload + pattrib->
+                                         hdrlen + pattrib->iv_len;
                                if ((curfragnum + 1) == pattrib->nr_frags) {
                                        length = pattrib->last_txcmdsz -
                                                  pattrib->hdrlen -
@@ -423,10 +424,10 @@ static sint xmitframe_addmic(struct _adapter *padapter,
                                                  ? pattrib->icv_len : 0);
                                        r8712_secmicappend(&micdata, payload,
                                                           length);
-                                       payload = payload+length;
+                                       payload = payload + length;
                                } else{
                                        length = pxmitpriv->frag_len -
-                                           pattrib->hdrlen-pattrib->iv_len -
+                                           pattrib->hdrlen - pattrib->iv_len -
                                            ((psecuritypriv->sw_encrypt) ?
                                            pattrib->icv_len : 0);
                                        r8712_secmicappend(&micdata, payload,
@@ -440,7 +441,7 @@ static sint xmitframe_addmic(struct _adapter *padapter,
                         * last_txcmdsz */
                        memcpy(payload, &(mic[0]), 8);
                        pattrib->last_txcmdsz += 8;
-                       payload = payload-pattrib->last_txcmdsz + 8;
+                       payload = payload - pattrib->last_txcmdsz + 8;
                }
        }
        return _SUCCESS;
@@ -483,34 +484,35 @@ static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr,
        memset(hdr, 0, WLANHDR_OFFSET);
        SetFrameSubType(fctrl, pattrib->subtype);
        if (pattrib->subtype & WIFI_DATA_TYPE) {
-               if (check_fwstate(pmlmepriv,  WIFI_STATION_STATE) == true) {
+               if (check_fwstate(pmlmepriv,  WIFI_STATION_STATE)) {
                        /* to_ds = 1, fr_ds = 0; */
                        SetToDs(fctrl);
                        memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv),
                                ETH_ALEN);
                        memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
                        memcpy(pwlanhdr->addr3, pattrib->dst, ETH_ALEN);
-               } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
+               } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
                        /* to_ds = 0, fr_ds = 1; */
                        SetFrDs(fctrl);
                        memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
                        memcpy(pwlanhdr->addr2, get_bssid(pmlmepriv),
                                ETH_ALEN);
                        memcpy(pwlanhdr->addr3, pattrib->src, ETH_ALEN);
-               } else if ((check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) == true)
-                          || (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)
-                          == true)) {
+               } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
+                          check_fwstate(pmlmepriv,
+                                        WIFI_ADHOC_MASTER_STATE)) {
                        memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
                        memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
                        memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv),
                                ETH_ALEN);
-               } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
+               } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
                        memcpy(pwlanhdr->addr1, pattrib->dst, ETH_ALEN);
                        memcpy(pwlanhdr->addr2, pattrib->src, ETH_ALEN);
                        memcpy(pwlanhdr->addr3, get_bssid(pmlmepriv),
                                ETH_ALEN);
-               } else
+               } else {
                        return _FAIL;
+               }
 
                if (pattrib->encrypt)
                        SetPrivacy(fctrl);
@@ -526,9 +528,9 @@ static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr,
                        struct sta_info *psta;
                        sint bmcst = IS_MCAST(pattrib->ra);
 
-                       if (pattrib->psta)
+                       if (pattrib->psta) {
                                psta = pattrib->psta;
-                       else {
+                       else {
                                if (bmcst)
                                        psta = r8712_get_bcmc_stainfo(padapter);
                                else
@@ -609,7 +611,7 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
                return _FAIL;
        _r8712_open_pktfile(pkt, &pktfile);
        _r8712_pktfile_read(&pktfile, NULL, (uint) pattrib->pkt_hdrlen);
-       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) {
+       if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
                /* truncate TXDESC_SIZE bytes txcmd if at mp mode for 871x */
                if (pattrib->ether_type == 0x8712) {
                        /* take care -  update_txdesc overwrite this */
@@ -680,7 +682,7 @@ sint r8712_xmitframe_coalesce(struct _adapter *padapter, _pkt *pkt,
                        pframe += pattrib->icv_len;
                }
                frg_inx++;
-               if (bmcst || (r8712_endofpktfile(&pktfile) == true)) {
+               if (bmcst || r8712_endofpktfile(&pktfile)) {
                        pattrib->nr_frags = frg_inx;
                        pattrib->last_txcmdsz = pattrib->hdrlen +
                                                pattrib->iv_len +
@@ -719,17 +721,18 @@ void r8712_update_protection(struct _adapter *padapter, u8 *ie, uint ie_len)
        case AUTO_VCS:
        default:
                perp = r8712_get_ie(ie, _ERPINFO_IE_, &erp_len, ie_len);
-               if (perp == NULL)
+               if (perp == NULL) {
                        pxmitpriv->vcs = NONE_VCS;
-               else {
+               else {
                        protection = (*(perp + 2)) & BIT(1);
                        if (protection) {
                                if (pregistrypriv->vcs_type == RTS_CTS)
                                        pxmitpriv->vcs = RTS_CTS;
                                else
                                        pxmitpriv->vcs = CTS_TO_SELF;
-                       } else
+                       } else {
                                pxmitpriv->vcs = NONE_VCS;
+                       }
                }
                break;
        }
@@ -743,9 +746,9 @@ struct xmit_buf *r8712_alloc_xmitbuf(struct xmit_priv *pxmitpriv)
        struct  __queue *pfree_xmitbuf_queue = &pxmitpriv->free_xmitbuf_queue;
 
        spin_lock_irqsave(&pfree_xmitbuf_queue->lock, irqL);
-       if (list_empty(&pfree_xmitbuf_queue->queue))
+       if (list_empty(&pfree_xmitbuf_queue->queue)) {
                pxmitbuf = NULL;
-       else {
+       else {
                phead = &pfree_xmitbuf_queue->queue;
                plist = phead->next;
                pxmitbuf = LIST_CONTAINOR(plist, struct xmit_buf, list);
@@ -797,9 +800,9 @@ struct xmit_frame *r8712_alloc_xmitframe(struct xmit_priv *pxmitpriv)
        struct  __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
 
        spin_lock_irqsave(&pfree_xmit_queue->lock, irqL);
-       if (list_empty(&pfree_xmit_queue->queue))
+       if (list_empty(&pfree_xmit_queue->queue)) {
                pxframe =  NULL;
-       else {
+       else {
                phead = &pfree_xmit_queue->queue;
                plist = phead->next;
                pxframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
@@ -855,7 +858,7 @@ void r8712_free_xmitframe_queue(struct xmit_priv *pxmitpriv,
        spin_lock_irqsave(&(pframequeue->lock), irqL);
        phead = &pframequeue->queue;
        plist = phead->next;
-       while (end_of_queue_search(phead, plist) == false) {
+       while (!end_of_queue_search(phead, plist)) {
                pxmitframe = LIST_CONTAINOR(plist, struct xmit_frame, list);
                plist = plist->next;
                r8712_free_xmitframe(pxmitpriv, pxmitframe);
@@ -876,19 +879,19 @@ static inline struct tx_servq *get_sta_pending(struct _adapter *padapter,
        case 2:
                ptxservq = &(psta->sta_xmitpriv.bk_q);
                *ppstapending = &padapter->xmitpriv.bk_pending;
-               (phwxmits+3)->accnt++;
+               (phwxmits + 3)->accnt++;
                break;
        case 4:
        case 5:
                ptxservq = &(psta->sta_xmitpriv.vi_q);
                *ppstapending = &padapter->xmitpriv.vi_pending;
-               (phwxmits+1)->accnt++;
+               (phwxmits + 1)->accnt++;
                break;
        case 6:
        case 7:
                ptxservq = &(psta->sta_xmitpriv.vo_q);
                *ppstapending = &padapter->xmitpriv.vo_pending;
-               (phwxmits+0)->accnt++;
+               (phwxmits + 0)->accnt++;
                break;
        case 0:
        case 3:
@@ -917,13 +920,13 @@ sint r8712_xmit_classifier(struct _adapter *padapter,
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        sint bmcst = IS_MCAST(pattrib->ra);
 
-       if (pattrib->psta)
+       if (pattrib->psta) {
                psta = pattrib->psta;
-       else {
-               if (bmcst)
+       else {
+               if (bmcst) {
                        psta = r8712_get_bcmc_stainfo(padapter);
-               else {
-                       if (check_fwstate(pmlmepriv, WIFI_MP_STATE) == true)
+               else {
+                       if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
                                psta = r8712_get_stainfo(pstapriv,
                                       get_bssid(pmlmepriv));
                        else
index b4ae11a78b46e98b673d4b8e1dd76e529743829c..ad21df16c2bd0600d548bdaf00b0f32adf472119 100644 (file)
@@ -167,12 +167,12 @@ u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
                r8712_write8(padapter, CR + 1, 0x37);
                /* Fix the RX FIFO issue(usb error), */
                val8 = r8712_read8(padapter, 0x1025FE5c);
-               r8712_write8(padapter, 0x1025FE5c, (val8|BIT(7)));
+               r8712_write8(padapter, 0x1025FE5c, (val8 | BIT(7)));
                val8 = r8712_read8(padapter, 0x102500ab);
-               r8712_write8(padapter, 0x102500ab, (val8|BIT(6)|BIT(7)));
+               r8712_write8(padapter, 0x102500ab, (val8 | BIT(6) | BIT(7)));
                /* For power save, used this in the bit file after 970621 */
                val8 = r8712_read8(padapter, SYS_CLKR);
-               r8712_write8(padapter, SYS_CLKR, val8&(~CPU_CLKSEL));
+               r8712_write8(padapter, SYS_CLKR, val8 & (~CPU_CLKSEL));
        } else if (pregistrypriv->chip_version == RTL8712_2ndCUT ||
                  pregistrypriv->chip_version == RTL8712_3rdCUT) {
                /* Initialization for power on sequence,
@@ -280,13 +280,14 @@ u8 r8712_usb_hal_bus_init(struct _adapter *padapter)
 
                if (PollingCnt <= 0) {
                        val8 = r8712_read8(padapter, CR);
-                       r8712_write8(padapter, CR, val8&(~_TXDMA_EN));
+                       r8712_write8(padapter, CR, val8 & (~_TXDMA_EN));
                        udelay(2); /* PlatformStallExecution(2); */
                        /* Reset TxDMA */
-                       r8712_write8(padapter, CR, val8|_TXDMA_EN);
+                       r8712_write8(padapter, CR, val8 | _TXDMA_EN);
                }
-       } else
+       } else {
                ret = _FAIL;
+       }
        return ret;
 }
 
index f8b5b332e7c3dc1160b7a22b54d8e2bd9eb5964f..c71333fbe823b40d74ba317c5d80fd7bf61afc7a 100644 (file)
@@ -144,6 +144,7 @@ static struct usb_device_id rtl871x_usb_id_tbl[] = {
        {USB_DEVICE(0x0DF6, 0x0058)},
        {USB_DEVICE(0x0DF6, 0x0049)},
        {USB_DEVICE(0x0DF6, 0x004C)},
+       {USB_DEVICE(0x0DF6, 0x006C)},
        {USB_DEVICE(0x0DF6, 0x0064)},
        /* Skyworth */
        {USB_DEVICE(0x14b2, 0x3300)},
@@ -301,7 +302,7 @@ void rtl871x_intf_stop(struct _adapter *padapter)
 
 void r871x_dev_unload(struct _adapter *padapter)
 {
-       if (padapter->bup == true) {
+       if (padapter->bup) {
                /*s1.*/
                padapter->bDriverStopped = true;
 
@@ -330,8 +331,7 @@ static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
        u16 vid, pid;
        u32 flags;
        int i;
-       int num = sizeof(specific_device_id_tbl) /
-                 sizeof(struct specific_device_id);
+       int num = ARRAY_SIZE(specific_device_id_tbl);
 
        for (i = 0; i < num; i++) {
                vid = specific_device_id_tbl[i].idVendor;
@@ -339,7 +339,7 @@ static void disable_ht_for_spec_devid(const struct usb_device_id *pdid,
                flags = specific_device_id_tbl[i].flags;
 
                if ((pdid->idVendor == vid) && (pdid->idProduct == pid) &&
-                   (flags&SPEC_DEV_ID_DISABLE_HT)) {
+                   (flags & SPEC_DEV_ID_DISABLE_HT)) {
                        padapter->registrypriv.ht_enable = 0;
                        padapter->registrypriv.cbw40_enable = 0;
                        padapter->registrypriv.ampdu_enable = 0;
@@ -395,9 +395,9 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
        /* step 3.
         * initialize the dvobj_priv
         */
-       if (!padapter->dvobj_init)
-                       goto error;
-       else {
+       if (!padapter->dvobj_init) {
+               goto error;
+       else {
                status = padapter->dvobj_init(padapter);
                if (status != _SUCCESS)
                        goto error;
@@ -426,7 +426,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
                        /* The following operations prevent Efuse leakage by
                         * turning on 2.5V.
                         */
-                       tmpU1b = r8712_read8(padapter, EFUSE_TEST+3);
+                       tmpU1b = r8712_read8(padapter, EFUSE_TEST + 3);
                        r8712_write8(padapter, EFUSE_TEST + 3, tmpU1b | 0x80);
                        msleep(20);
                        r8712_write8(padapter, EFUSE_TEST + 3,
@@ -553,8 +553,9 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
                                padapter->ledpriv.bRegUseLed = false;
                                break;
                        }
-               } else
+               } else {
                        AutoloadFail = false;
+               }
                if (((mac[0] == 0xff) && (mac[1] == 0xff) &&
                     (mac[2] == 0xff) && (mac[3] == 0xff) &&
                     (mac[4] == 0xff) && (mac[5] == 0xff)) ||
@@ -611,7 +612,7 @@ static void r871xu_dev_remove(struct usb_interface *pusb_intf)
                release_firmware(padapter->fw);
                /* never exit with a firmware callback pending */
                wait_for_completion(&padapter->rtl8712_fw_ready);
-               if (drvpriv.drv_registered == true)
+               if (drvpriv.drv_registered)
                        padapter->bSurpriseRemoved = true;
                unregister_netdev(pnetdev); /* will call netdev_close() */
                flush_scheduled_work();
index c03508d935f2bb46263db5bf87e36ef6938af598..856f257bb77e488178984a2f9d8477e82c8260f2 100644 (file)
@@ -47,11 +47,11 @@ static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
        request = 0x05;
        requesttype = 0x01; /* read_in */
        index = 0;
-       wvalue = (u16)(addr&0x0000ffff);
+       wvalue = (u16)(addr & 0x0000ffff);
        len = 1;
        r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
                          requesttype);
-       return (u8)(le32_to_cpu(data)&0x0ff);
+       return (u8)(le32_to_cpu(data) & 0x0ff);
 }
 
 static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
@@ -67,11 +67,11 @@ static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
        request = 0x05;
        requesttype = 0x01; /* read_in */
        index = 0;
-       wvalue = (u16)(addr&0x0000ffff);
+       wvalue = (u16)(addr & 0x0000ffff);
        len = 2;
        r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
                          requesttype);
-       return (u16)(le32_to_cpu(data)&0xffff);
+       return (u16)(le32_to_cpu(data) & 0xffff);
 }
 
 static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
@@ -87,7 +87,7 @@ static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
        request = 0x05;
        requesttype = 0x01; /* read_in */
        index = 0;
-       wvalue = (u16)(addr&0x0000ffff);
+       wvalue = (u16)(addr & 0x0000ffff);
        len = 4;
        r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
                          requesttype);
@@ -107,10 +107,10 @@ static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
        request = 0x05;
        requesttype = 0x00; /* write_out */
        index = 0;
-       wvalue = (u16)(addr&0x0000ffff);
+       wvalue = (u16)(addr & 0x0000ffff);
        len = 1;
        data = val;
-       data = cpu_to_le32(data&0x000000ff);
+       data = cpu_to_le32(data & 0x000000ff);
        r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
                          requesttype);
 }
@@ -128,10 +128,10 @@ static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
        request = 0x05;
        requesttype = 0x00; /* write_out */
        index = 0;
-       wvalue = (u16)(addr&0x0000ffff);
+       wvalue = (u16)(addr & 0x0000ffff);
        len = 2;
        data = val;
-       data = cpu_to_le32(data&0x0000ffff);
+       data = cpu_to_le32(data & 0x0000ffff);
        r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
                          requesttype);
 }
@@ -149,7 +149,7 @@ static void usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
        request = 0x05;
        requesttype = 0x00; /* write_out */
        index = 0;
-       wvalue = (u16)(addr&0x0000ffff);
+       wvalue = (u16)(addr & 0x0000ffff);
        len = 4;
        data = cpu_to_le32(val);
        r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
index c3a4e3f26b403de0d126374578906604627fed5a..489a9e6d52fc39c14a82612aca78804b0511b296 100644 (file)
@@ -144,8 +144,9 @@ static unsigned int ffaddr2pipehdl(struct dvobj_priv *pdvobj, u32 addr)
                        pipe = usb_sndbulkpipe(pusbd, 0x0d);
                        break;
                }
-       } else
+       } else {
           pipe = 0;
+       }
        return pipe;
 }
 
@@ -170,7 +171,7 @@ void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
        unsigned int pipe;
        struct _adapter *padapter = (struct _adapter *)pintfhdl->adapter;
        struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
-       struct io_queue *pio_queue = (struct io_queue *)padapter->pio_queue;
+       struct io_queue *pio_queue = padapter->pio_queue;
        struct dvobj_priv *pdvobj = (struct dvobj_priv *)pintfpriv->intf_dev;
        struct usb_device *pusbd = pdvobj->pusbdev;
        struct urb *piorw_urb = pintfpriv->piorw_urb;
@@ -259,16 +260,16 @@ u32 r8712_usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
        struct recv_buf *precvbuf = (struct recv_buf *)rmem;
        struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
        struct dvobj_priv *pdvobj = (struct dvobj_priv *)pintfpriv->intf_dev;
-       struct _adapter *adapter = (struct _adapter *)pdvobj->padapter;
+       struct _adapter *adapter = pdvobj->padapter;
        struct recv_priv *precvpriv = &adapter->recvpriv;
        struct usb_device *pusbd = pdvobj->pusbdev;
 
        if (adapter->bDriverStopped || adapter->bSurpriseRemoved ||
            adapter->pwrctrlpriv.pnp_bstop_trx)
                return _FAIL;
-       if (!precvbuf->reuse == false || !precvbuf->pskb) {
+       if (precvbuf->reuse || !precvbuf->pskb) {
                precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue);
-               if (NULL != precvbuf->pskb)
+               if (precvbuf->pskb != NULL)
                        precvbuf->reuse = true;
        }
        if (precvbuf != NULL) {
@@ -280,7 +281,7 @@ u32 r8712_usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
                        if (!precvbuf->pskb)
                                return _FAIL;
                        tmpaddr = (addr_t)precvbuf->pskb->data;
-                       alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
+                       alignment = tmpaddr & (RECVBUFF_ALIGN_SZ - 1);
                        skb_reserve(precvbuf->pskb,
                                    (RECVBUFF_ALIGN_SZ - alignment));
                        precvbuf->phead = precvbuf->pskb->head;
@@ -306,8 +307,9 @@ u32 r8712_usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
                err = usb_submit_urb(purb, GFP_ATOMIC);
                if ((err) && (err != (-EPERM)))
                        ret = _FAIL;
-       } else
+       } else {
                ret = _FAIL;
+       }
        return ret;
 }
 
@@ -330,13 +332,13 @@ void r8712_xmit_bh(void *priv)
        struct _adapter *padapter = (struct _adapter *)priv;
        struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
 
-       if ((padapter->bDriverStopped == true) ||
-           (padapter->bSurpriseRemoved == true)) {
+       if (padapter->bDriverStopped ||
+           padapter->bSurpriseRemoved) {
                netdev_err(padapter->pnetdev, "xmit_bh => bDriverStopped or bSurpriseRemoved\n");
                return;
        }
        ret = r8712_xmitframe_complete(padapter, pxmitpriv, NULL);
-       if (ret == false)
+       if (!ret)
                return;
        tasklet_hi_schedule(&pxmitpriv->xmit_tasklet);
 }
@@ -400,7 +402,7 @@ u32 r8712_usb_write_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
        u32 ret, bwritezero;
        struct urb *purb = NULL;
        struct _adapter *padapter = (struct _adapter *)pintfhdl->adapter;
-       struct dvobj_priv *pdvobj = (struct dvobj_priv   *)&padapter->dvobjpriv;
+       struct dvobj_priv *pdvobj = &padapter->dvobjpriv;
        struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
        struct xmit_frame *pxmitframe = (struct xmit_frame *)wmem;
        struct usb_device *pusbd = pdvobj->pusbdev;
@@ -410,7 +412,7 @@ u32 r8712_usb_write_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
            (padapter->pwrctrlpriv.pnp_bstop_trx))
                return _FAIL;
        for (i = 0; i < 8; i++) {
-               if (pxmitframe->bpending[i] == false) {
+               if (!pxmitframe->bpending[i]) {
                        spin_lock_irqsave(&pxmitpriv->lock, irqL);
                        pxmitpriv->txirp_cnt++;
                        pxmitframe->bpending[i]  = true;
@@ -449,7 +451,7 @@ u32 r8712_usb_write_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
        }
        /* translate DMA FIFO addr to pipehandle */
        pipe = ffaddr2pipehdl(pdvobj, addr);
-       if (pxmitpriv->free_xmitbuf_cnt%NR_XMITBUFF == 0)
+       if (pxmitpriv->free_xmitbuf_cnt % NR_XMITBUFF == 0)
                purb->transfer_flags  &=  (~URB_NO_INTERRUPT);
        else
                purb->transfer_flags  |=  URB_NO_INTERRUPT;
index 17f513122f48b79ec71ed03df80893af4a94b533..7a352c45344ff7e1e6915b716c9b5dc1463fbf0f 100644 (file)
 
 #include <linux/compiler.h>
 
-#ifdef BIT
-#undef BIT
-#endif
-#define BIT(x) (1 << (x))
-
-#define WLAN_ETHHDR_LEN                14
-#define WLAN_ETHADDR_LEN       6
 #define WLAN_IEEE_OUI_LEN      3
-#define WLAN_ADDR_LEN          6
 #define WLAN_CRC_LEN           4
 #define WLAN_BSSID_LEN         6
 #define WLAN_BSS_TS_LEN                8
@@ -52,7 +44,6 @@
 
 #define WLAN_MIN_ETHFRM_LEN    60
 #define WLAN_MAX_ETHFRM_LEN    1514
-#define WLAN_ETHHDR_LEN                14
 
 #define P80211CAPTURE_VERSION  0x80211001
 
index d15fb1ad45b9f9128f924a96b56e32243aa12987..d3981836ce26f322153bdd7838e1b77f59d70880 100644 (file)
@@ -166,7 +166,7 @@ int r8712_xmit_entry(_pkt *pkt, struct  net_device *pnetdev)
        struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
        int ret = 0;
 
-       if (r8712_if_up(padapter) == false) {
+       if (!r8712_if_up(padapter)) {
                ret = 0;
                goto _xmit_entry_drop;
        }
@@ -181,7 +181,7 @@ int r8712_xmit_entry(_pkt *pkt, struct  net_device *pnetdev)
        }
        padapter->ledpriv.LedControlHandler(padapter, LED_CTL_TX);
        pxmitframe->pkt = pkt;
-       if (r8712_pre_xmit(padapter, pxmitframe) == true) {
+       if (r8712_pre_xmit(padapter, pxmitframe)) {
                /*dump xmitframe directly or drop xframe*/
                dev_kfree_skb_any(pkt);
                pxmitframe->pkt = NULL;
index 65b209a20c29a283fc95a193108dc3d8763782d8..1aa9b267c30eb4fa3e33932aab304293190b52b8 100644 (file)
 #include <rtl8723a_cmd.h>
 #include <rtl8723a_hal.h>
 #include <asm/unaligned.h>
-
-extern unsigned char WMM_OUI23A[];
-extern unsigned char WPS_OUI23A[];
-extern unsigned char P2P_OUI23A[];
+#include <rtw_mlme_ext.h>
 
 void init_mlme_ap_info23a(struct rtw_adapter *padapter)
 {
@@ -132,11 +129,11 @@ static void update_BCNTIM(struct rtw_adapter *padapter)
 
        *dst_ie++ = tim_ielen;
 
-       *dst_ie++ = 0;/* DTIM count */
-       *dst_ie++ = 1;/* DTIM period */
+       *dst_ie++ = 0; /* DTIM count */
+       *dst_ie++ = 1; /* DTIM period */
 
-       if (pstapriv->tim_bitmap & BIT(0))/* for bc/mc frames */
-               *dst_ie++ = BIT(0);/* bitmap ctrl */
+       if (pstapriv->tim_bitmap & BIT(0)) /* for bc/mc frames */
+               *dst_ie++ = BIT(0);        /* bitmap ctrl */
        else
                *dst_ie++ = 0;
 
@@ -239,11 +236,16 @@ void      expire_timeout_chk23a(struct rtw_adapter *padapter)
 
                        if (psta->state & WIFI_SLEEP_STATE) {
                                if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
-                                       /* to check if alive by another methods if station is at ps mode. */
+                                       /*
+                                        * check if alive by another method
+                                        * if station is at ps mode.
+                                        */
                                        psta->expire_to = pstapriv->expire_to;
                                        psta->state |= WIFI_STA_ALIVE_CHK_STATE;
-
-                                       /* to update bcn with tim_bitmap for this station */
+                                       /*
+                                        * update bcn with tim_bitmap
+                                        * for this station
+                                        */
                                        pstapriv->tim_bitmap |= CHKBIT(psta->aid);
                                        update_beacon23a(padapter, WLAN_EID_TIM, NULL, false);
 
@@ -264,7 +266,10 @@ void       expire_timeout_chk23a(struct rtw_adapter *padapter)
                                  psta->hwaddr, psta->state);
                        updated = ap_free_sta23a(padapter, psta, false, WLAN_REASON_DEAUTH_LEAVING);
                } else {
-                       /* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
+                       /*
+                        * TODO: Aging mechanism to digest frames in
+                        * sleep_q to avoid running out of xmitframe
+                        */
                        if (psta->sleepq_len > (NR_XMITFRAME/pstapriv->asoc_list_cnt)
                                && padapter->xmitpriv.free_xmitframe_cnt < ((NR_XMITFRAME/pstapriv->asoc_list_cnt)/2)
                        ) {
@@ -285,13 +290,16 @@ void      expire_timeout_chk23a(struct rtw_adapter *padapter)
 
                u8 backup_oper_channel = 0;
                struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
-               /* switch to correct channel of current network  before issue keep-alive frames */
+               /*
+                * switch to correct channel of current
+                * network before issue keep-alive frames
+                */
                if (rtw_get_oper_ch23a(padapter) != pmlmeext->cur_channel) {
                        backup_oper_channel = rtw_get_oper_ch23a(padapter);
                        SelectChannel23a(padapter, pmlmeext->cur_channel);
                }
 
-       /* issue null data to check sta alive*/
+       /* issue null data to check sta alive */
        for (i = 0; i < chk_alive_num; i++) {
 
                int ret = _FAIL;
@@ -332,7 +340,7 @@ void        expire_timeout_chk23a(struct rtw_adapter *padapter)
 
        }
 
-       if (backup_oper_channel > 0) /* back to the original operation channel */
+       if (backup_oper_channel > 0) /* back to original operation channel */
                SelectChannel23a(padapter, backup_oper_channel);
 }
 
@@ -369,9 +377,9 @@ void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_l
                rf_type = rtl8723a_get_rf_type(padapter);
 
                if (rf_type == RF_2T2R)
-                       limit = 16;/*  2R */
+                       limit = 16; /* 2R */
                else
-                       limit = 8;/*   1R */
+                       limit = 8;  /* 1R */
 
                for (i = 0; i < limit; i++) {
                        if (psta_ht->ht_cap.mcs.rx_mask[i / 8] & BIT(i % 8))
@@ -403,11 +411,11 @@ void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_l
        init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
 
        if (psta->aid < NUM_STA) {
-               u8 arg = 0;
+               u8 arg;
 
                arg = psta->mac_id&0x1f;
 
-               arg |= BIT(7);/* support entry 2~31 */
+               arg |= BIT(7); /* support entry 2~31 */
 
                if (shortGIrate == true)
                        arg |= BIT(5);
@@ -446,7 +454,7 @@ static void update_bmc_sta(struct rtw_adapter *padapter)
        struct sta_info *psta = rtw_get_bcmc_stainfo23a(padapter);
 
        if (psta) {
-               psta->aid = 0;/* default set to 0 */
+               psta->aid = 0; /* default set to 0 */
                psta->mac_id = psta->aid + 1;
 
                psta->qos_option = 0;
@@ -473,7 +481,7 @@ static void update_bmc_sta(struct rtw_adapter *padapter)
                if (pcur_network->DSConfig > 14) {
                        /* force to A mode. 5G doesn't support CCK rates */
                        network_type = WIRELESS_11A;
-                       tx_ra_bitmap = 0x150; /*  6, 12, 24 Mbps */
+                       tx_ra_bitmap = 0x150; /* 6, 12, 24 Mbps */
                } else {
                        /* force to b mode */
                        network_type = WIRELESS_11B;
@@ -487,7 +495,7 @@ static void update_bmc_sta(struct rtw_adapter *padapter)
                rtl8723a_SetHalODMVar(padapter, HAL_ODM_STA_INFO, psta, true);
 
                {
-                       u8 arg = 0;
+                       u8 arg;
 
                        arg = psta->mac_id&0x1f;
 
@@ -516,13 +524,13 @@ static void update_bmc_sta(struct rtw_adapter *padapter)
                DBG_8723A("add_RATid23a_bmc_sta error!\n");
 }
 
-/* notes: */
-/* AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode */
-/* MAC_ID = AID+1 for sta in ap/adhoc mode */
-/* MAC_ID = 1 for bc/mc for sta/ap/adhoc */
-/* MAC_ID = 0 for bssid for sta/ap/adhoc */
-/* CAM_ID = 0~3 for default key, cmd_id = macid + 3, macid = aid+1; */
-
+/*
+ * AID: 1~MAX for sta and 0 for bc/mc in ap/adhoc mode
+ * MAC_ID = AID+1 for sta in ap/adhoc mode
+ * MAC_ID = 1 for bc/mc for sta/ap/adhoc
+ * MAC_ID = 0 for bssid for sta/ap/adhoc
+ * CAM_ID = 0~3 for default key, cmd_id = macid + 3, macid = aid + 1;
+ */
 void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info *psta)
 {
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -556,7 +564,7 @@ void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info
                if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SGI_20|IEEE80211_HT_CAP_SGI_40))
                        phtpriv_sta->sgi = true;
 
-               /*  bwmode */
+               /* bwmode */
                if ((phtpriv_sta->ht_cap.cap_info & phtpriv_ap->ht_cap.cap_info) & cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
                        /* phtpriv_sta->bwmode = HT_CHANNEL_WIDTH_40; */
                        phtpriv_sta->bwmode = pmlmeext->cur_bwmode;
@@ -575,10 +583,10 @@ void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info
        }
 
        /* Rx AMPDU */
-       send_delba23a(padapter, 0, psta->hwaddr);/*  recipient */
+       send_delba23a(padapter, 0, psta->hwaddr); /* recipient */
 
        /* TX AMPDU */
-       send_delba23a(padapter, 1, psta->hwaddr);/*  originator */
+       send_delba23a(padapter, 1, psta->hwaddr); /* originator */
        phtpriv_sta->agg_enable_bitmap = 0x0;/* reset */
        phtpriv_sta->candidate_tid_bitmap = 0x0;/* reset */
 
@@ -599,11 +607,10 @@ static void update_hw_ht_param(struct rtw_adapter *padapter)
        struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
 
        DBG_8723A("%s\n", __func__);
-
-       /* handle A-MPDU parameter field */
        /*
-               AMPDU_para [1:0]:Max AMPDU Len => 0:8k , 1:16k, 2:32k, 3:64k
-               AMPDU_para [4:2]:Min MPDU Start Spacing
+        * handle A-MPDU parameter field
+        * AMPDU_para [1:0]:Max AMPDU Len => 0:8k, 1:16k, 2:32k, 3:64k
+        * AMPDU_para [4:2]:Min MPDU Start Spacing
        */
        max_AMPDU_len = pmlmeinfo->ht_cap.ampdu_params_info &
                IEEE80211_HT_AMPDU_PARM_FACTOR;
@@ -614,7 +621,7 @@ static void update_hw_ht_param(struct rtw_adapter *padapter)
        rtl8723a_set_ampdu_min_space(padapter, min_MPDU_spacing);
        rtl8723a_set_ampdu_factor(padapter, max_AMPDU_len);
 
-       /*  Config SM Power Save setting */
+       /* Config SM Power Save setting */
        pmlmeinfo->SM_PS = (le16_to_cpu(pmlmeinfo->ht_cap.cap_info) &
                            IEEE80211_HT_CAP_SM_PS) >> 2;
        if (pmlmeinfo->SM_PS == WLAN_HT_CAP_SM_PS_STATIC)
@@ -641,13 +648,17 @@ static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
        cur_bwmode = HT_CHANNEL_WIDTH_20;
        cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
 
-       /* check if there is wps ie, */
-       /* if there is wpsie in beacon, the hostapd will update beacon twice when stating hostapd, */
-       /* and at first time the security ie (RSN/WPA IE) will not include in beacon. */
-       if (NULL == cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
-                                           WLAN_OUI_TYPE_MICROSOFT_WPS,
-                                           pnetwork->IEs,
-                                           pnetwork->IELength))
+       /*
+        * check if there is wps ie
+        * if there is wpsie in beacon the hostapd will
+        * update beacon twice when stating hostapd
+        * and at first time the security
+        * ie (RSN/WPA IE) will not include in beacon
+        */
+       if (!cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
+                                    WLAN_OUI_TYPE_MICROSOFT_WPS,
+                                    pnetwork->IEs,
+                                    pnetwork->IELength))
                pmlmeext->bstart_bss = true;
 
        /* todo: update wmm, ht cap */
@@ -663,8 +674,11 @@ static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
        }
 
        if (pmlmepriv->cur_network.join_res != true) {
-               /* setting only at  first time */
-               /* WEP Key will be set before this function, do not clear CAM. */
+               /*
+                * setting only at first time
+                * WEP Key will be set before this
+                * function, do not clear CAM.
+                */
                if (psecuritypriv->dot11PrivacyAlgrthm !=
                    WLAN_CIPHER_SUITE_WEP40 &&
                    psecuritypriv->dot11PrivacyAlgrthm !=
@@ -679,13 +693,13 @@ static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
        hw_var_set_bssid(padapter, pnetwork->MacAddress);
 
        /* Set EDCA param reg */
-       acparm = 0x002F3217; /*  VO */
+       acparm = 0x002F3217; /* VO */
        rtl8723a_set_ac_param_vo(padapter, acparm);
-       acparm = 0x005E4317; /*  VI */
+       acparm = 0x005E4317; /* VI */
        rtl8723a_set_ac_param_vi(padapter, acparm);
        acparm = 0x005ea42b;
        rtl8723a_set_ac_param_be(padapter, acparm);
-       acparm = 0x0000A444; /*  BK */
+       acparm = 0x0000A444; /* BK */
        rtl8723a_set_ac_param_bk(padapter, acparm);
 
        /* Set Security */
@@ -722,8 +736,10 @@ static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
                        switch (pht_info->ht_param &
                                IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
                        case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
-                               /* pmlmeext->cur_ch_offset =
-                                  HAL_PRIME_CHNL_OFFSET_LOWER; */
+                               /*
+                                * pmlmeext->cur_ch_offset =
+                                * HAL_PRIME_CHNL_OFFSET_LOWER;
+                                */
                                cur_ch_offset = HAL_PRIME_CHNL_OFFSET_LOWER;
                                break;
                        case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
@@ -735,7 +751,10 @@ static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
                        }
                }
        }
-       /* TODO: need to judge the phy parameters on concurrent mode for single phy */
+       /*
+        * TODO: need to judge the phy parameters
+        * on concurrent mode for single phy
+        */
        set_channel_bwmode23a(padapter, cur_channel, cur_ch_offset, cur_bwmode);
 
        DBG_8723A("CH =%d, BW =%d, offset =%d\n", cur_channel, cur_bwmode,
@@ -886,7 +905,7 @@ int rtw_check_beacon_data23a(struct rtw_adapter *padapter,
                                         &pairwise_cipher, NULL) == _SUCCESS) {
                        psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_8021X;
 
-                       psecuritypriv->dot8021xalg = 1;/* psk,  todo:802.1x */
+                       psecuritypriv->dot8021xalg = 1; /* psk, todo:802.1x */
                        psecuritypriv->wpa_psk |= BIT(1);
 
                        psecuritypriv->wpa2_group_cipher = group_cipher;
@@ -919,8 +938,8 @@ int rtw_check_beacon_data23a(struct rtw_adapter *padapter,
                        break;
                }
 
-               if ((p == NULL) || (ie_len == 0))
-                               break;
+               if (!p || !ie_len)
+                       break;
        }
 
        /* wmm */
@@ -934,7 +953,7 @@ int rtw_check_beacon_data23a(struct rtw_adapter *padapter,
                        if ((p) && !memcmp(p+2, WMM_PARA_IE, 6)) {
                                pmlmepriv->qos_option = 1;
 
-                               *(p+8) |= BIT(7);/* QoS Info, support U-APSD */
+                               *(p + 8) |= BIT(7);/* QoS Info:support U-APSD */
 
                                /* disable all ACM bits since the WMM admission
                                 * control is not supported
@@ -1135,11 +1154,6 @@ int rtw_acl_remove_sta23a(struct rtw_adapter *padapter, u8 *addr)
        return 0;
 }
 
-static void update_bcn_fixed_ie(struct rtw_adapter *padapter)
-{
-       DBG_8723A("%s\n", __func__);
-}
-
 static void update_bcn_erpinfo_ie(struct rtw_adapter *padapter)
 {
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -1173,21 +1187,6 @@ static void update_bcn_erpinfo_ie(struct rtw_adapter *padapter)
        }
 }
 
-static void update_bcn_htcap_ie(struct rtw_adapter *padapter)
-{
-       DBG_8723A("%s\n", __func__);
-}
-
-static void update_bcn_htinfo_ie(struct rtw_adapter *padapter)
-{
-       DBG_8723A("%s\n", __func__);
-}
-
-static void update_bcn_rsn_ie(struct rtw_adapter *padapter)
-{
-       DBG_8723A("%s\n", __func__);
-}
-
 static void update_bcn_wpa_ie(struct rtw_adapter *padapter)
 {
        DBG_8723A("%s\n", __func__);
@@ -1244,11 +1243,6 @@ void update_beacon23a(struct rtw_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
        spin_lock_bh(&pmlmepriv->bcn_update_lock);
 
        switch (ie_id) {
-       case 0xFF:
-               /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
-               update_bcn_fixed_ie(padapter);
-               break;
-
        case WLAN_EID_TIM:
                update_BCNTIM(padapter);
                break;
@@ -1257,18 +1251,6 @@ void update_beacon23a(struct rtw_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
                update_bcn_erpinfo_ie(padapter);
                break;
 
-       case WLAN_EID_HT_CAPABILITY:
-               update_bcn_htcap_ie(padapter);
-               break;
-
-       case WLAN_EID_RSN:
-               update_bcn_rsn_ie(padapter);
-               break;
-
-       case WLAN_EID_HT_OPERATION:
-               update_bcn_htinfo_ie(padapter);
-               break;
-
        case WLAN_EID_VENDOR_SPECIFIC:
                update_bcn_vendor_spec_ie(padapter, oui);
                break;
@@ -1286,16 +1268,16 @@ void update_beacon23a(struct rtw_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
 }
 
 /*
-op_mode
-Set to 0 (HT pure) under the following conditions
      - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
      - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
-Set to 1 (HT non-member protection) if there may be non-HT STAs
      in both the primary and the secondary channel
-Set to 2 if only HT STAs are associated in BSS,
      however and at least one 20 MHz HT STA is associated
-Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
      (currently non-GF HT station is considered as non-HT STA also)
+ * op_mode
+ * Set to 0 (HT pure) under the following conditions
*     - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
*     - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
+ * Set to 1 (HT non-member protection) if there may be non-HT STAs
*     in both the primary and the secondary channel
+ * Set to 2 if only HT STAs are associated in BSS,
*     however and at least one 20 MHz HT STA is associated
+ * Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
*     (currently non-GF HT station is considered as non-HT STA also)
 */
 static int rtw_ht_operation_update(struct rtw_adapter *padapter)
 {
@@ -1338,7 +1320,8 @@ static int rtw_ht_operation_update(struct rtw_adapter *padapter)
                op_mode_changes++;
        }
 
-       /* Note: currently we switch to the MIXED op mode if HT non-greenfield
+       /*
+        * Note: currently we switch to the MIXED op mode if HT non-greenfield
         * station is associated. Probably it's a theoretical case, since
         * it looks like all known HT STAs support greenfield.
         */
@@ -1389,7 +1372,7 @@ void associated_clients_update23a(struct rtw_adapter *padapter, u8 updated)
        }
 }
 
-/* called > TSR LEVEL for USB or SDIO Interface*/
+/* called > TSR LEVEL for USB or SDIO Interface */
 void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info *psta)
 {
        u8 beacon_updated = false;
@@ -1607,16 +1590,16 @@ u8 ap_free_sta23a(struct rtw_adapter *padapter, struct sta_info *psta, bool acti
 
        if (active) {
                /* tear down Rx AMPDU */
-               send_delba23a(padapter, 0, psta->hwaddr);/*  recipient */
+               send_delba23a(padapter, 0, psta->hwaddr); /* recipient */
 
                /* tear down TX AMPDU */
-               send_delba23a(padapter, 1, psta->hwaddr);/* originator */
+               send_delba23a(padapter, 1, psta->hwaddr); /* originator */
 
                issue_deauth23a(padapter, psta->hwaddr, reason);
        }
 
-       psta->htpriv.agg_enable_bitmap = 0x0;/* reset */
-       psta->htpriv.candidate_tid_bitmap = 0x0;/* reset */
+       psta->htpriv.agg_enable_bitmap = 0x0;    /* reset */
+       psta->htpriv.candidate_tid_bitmap = 0x0; /* reset */
 
        /* report_del_sta_event23a(padapter, psta->hwaddr, reason); */
 
@@ -1717,7 +1700,7 @@ int rtw_sta_flush23a(struct rtw_adapter *padapter)
        return 0;
 }
 
-/* called > TSR LEVEL for USB or SDIO Interface*/
+/* called > TSR LEVEL for USB or SDIO Interface */
 void sta_info_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
 {
        int flags = psta->flags;
@@ -1746,7 +1729,7 @@ void sta_info_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
        update_sta_info23a_apmode23a(padapter, psta);
 }
 
-/* called >= TSR LEVEL for USB or SDIO Interface*/
+/* called >= TSR LEVEL for USB or SDIO Interface */
 void ap_sta_info_defer_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
 {
        if (psta->state & _FW_LINKED) {
@@ -1870,7 +1853,10 @@ void stop_ap_mode23a(struct rtw_adapter *padapter)
        pmlmepriv->update_bcn = false;
        pmlmeext->bstart_bss = false;
 
-       /* reset and init security priv , this can refine with rtw_reset_securitypriv23a */
+       /*
+        * reset and init security priv , this can
+        * refine with rtw_reset_securitypriv23a
+        */
        memset((unsigned char *)&padapter->securitypriv, 0, sizeof(struct security_priv));
        padapter->securitypriv.ndisauthtype = Ndis802_11AuthModeOpen;
        padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
index 46aea16cbf7887c429c200aa3b11cb413b265c3e..3035bb864c39be184e505b267aa3cda1fbefc64c 100644 (file)
@@ -236,7 +236,8 @@ int rtw_enqueue_cmd23a(struct cmd_priv *pcmdpriv, struct cmd_obj *cmd_obj)
        res = queue_work(pcmdpriv->wq, &cmd_obj->work);
 
        if (!res) {
-               printk(KERN_ERR "%s: Call to queue_work() failed\n", __func__);
+               netdev_err(pcmdpriv->padapter->pnetdev,
+                          "%s: Call to queue_work() failed\n", __func__);
                res = _FAIL;
        } else
                res = _SUCCESS;
@@ -620,7 +621,7 @@ int rtw_disassoc_cmd23a(struct rtw_adapter *padapter, u32 deauth_timeout_ms,
        } else {
                /* no need to enqueue, do the cmd hdl directly and
                   free cmd parameter */
-               if (H2C_SUCCESS != disconnect_hdl23a(padapter, (u8 *)param))
+               if (disconnect_hdl23a(padapter, (u8 *)param) != H2C_SUCCESS)
                        res = _FAIL;
                kfree(param);
        }
@@ -1342,6 +1343,7 @@ void rtw_createbss_cmd23a_callback(struct rtw_adapter *padapter,
        struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
        struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)pcmd->parmbuf;
        struct wlan_network *tgt_network = &pmlmepriv->cur_network;
+       struct rtw_queue *scanned_queue = &pmlmepriv->scanned_queue;
 
        if (pcmd->res != H2C_SUCCESS) {
                RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
@@ -1371,19 +1373,19 @@ void rtw_createbss_cmd23a_callback(struct rtw_adapter *padapter,
                spin_unlock_bh(&pmlmepriv->lock);
        } else {
                pwlan = rtw_alloc_network(pmlmepriv, GFP_KERNEL);
-               spin_lock_bh(&pmlmepriv->scanned_queue.lock);
+               spin_lock_bh(&scanned_queue->lock);
                if (!pwlan) {
-                       pwlan = rtw_get_oldest_wlan_network23a(&pmlmepriv->scanned_queue);
+                       pwlan = rtw_get_oldest_wlan_network23a(scanned_queue);
                        if (!pwlan) {
                                RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_,
                                         "Error:  can't get pwlan in rtw23a_joinbss_event_cb\n");
-                               spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
+                               spin_unlock_bh(&scanned_queue->lock);
                                goto createbss_cmd_fail;
                        }
                        pwlan->last_scanned = jiffies;
                } else {
                        list_add_tail(&pwlan->list,
-                                     &pmlmepriv->scanned_queue.queue);
+                                     &scanned_queue->queue);
                }
 
                pnetwork->Length = get_wlan_bssid_ex_sz(pnetwork);
@@ -1402,9 +1404,9 @@ void rtw_createbss_cmd23a_callback(struct rtw_adapter *padapter,
 
                clr_fwstate(pmlmepriv, _FW_UNDER_LINKING);
 
-               spin_unlock_bh(&pmlmepriv->scanned_queue.lock);
                /*  we will set _FW_LINKED when there is one more sat to
                    join us (rtw_stassoc_event_callback23a) */
+               spin_unlock_bh(&scanned_queue->lock);
        }
 
 createbss_cmd_fail:
index 92a34db3bd4e3a245b3d486ecf643a2497516843..906b5782d1658c07994bcdcd63feb388544157cd 100644 (file)
 #include <rtl8723a_hal.h>
 #include <usb_ops_linux.h>
 
-/*------------------------Define local variable------------------------------*/
-
-/*  */
 #define REG_EFUSE_CTRL         0x0030
-#define EFUSE_CTRL                     REG_EFUSE_CTRL          /*  E-Fuse Control. */
-/*  */
+#define EFUSE_CTRL             REG_EFUSE_CTRL  /* E-Fuse Control */
 
 #define VOLTAGE_V25            0x03
 #define LDOE25_SHIFT           28
 
-/*-----------------------------------------------------------------------------
- * Function:   Efuse_PowerSwitch
- *
- * Overview:   When we want to enable write operation, we should change to
- *                             pwr on state. When we stop write, we should switch to 500k mode
- *                             and disable LDO 2.5V.
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 11/17/2008  MHC             Create Version 0.
- *
- *---------------------------------------------------------------------------*/
+/*
+ * When we want to enable write operation, we should change to
+ * pwr on state. When we stop write, we should switch to 500k mode
+ * and disable LDO 2.5V.
+ */
 static void Efuse_PowerSwitch(struct rtw_adapter *padapter,
                              u8 bWrite, u8 PwrState)
 {
@@ -58,22 +41,26 @@ static void Efuse_PowerSwitch(struct rtw_adapter *padapter,
        if (PwrState == true) {
                rtl8723au_write8(padapter, REG_EFUSE_ACCESS, EFUSE_ACCESS_ON);
 
-               /*  1.2V Power: From VDDON with Power
-                   Cut(0x0000h[15]), default valid */
+               /*
+                * 1.2V Power: From VDDON with Power
+                * Cut(0x0000h[15]), default valid
+                */
                tmpV16 = rtl8723au_read16(padapter, REG_SYS_ISO_CTRL);
                if (!(tmpV16 & PWC_EV12V)) {
                        tmpV16 |= PWC_EV12V;
                        rtl8723au_write16(padapter, REG_SYS_ISO_CTRL, tmpV16);
                }
-               /*  Reset: 0x0000h[28], default valid */
+               /* Reset: 0x0000h[28], default valid */
                tmpV16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN);
                if (!(tmpV16 & FEN_ELDR)) {
                        tmpV16 |= FEN_ELDR;
                        rtl8723au_write16(padapter, REG_SYS_FUNC_EN, tmpV16);
                }
 
-               /*  Clock: Gated(0x0008h[5]) 8M(0x0008h[1]) clock
-                   from ANA, default valid */
+               /*
+                * Clock: Gated(0x0008h[5]) 8M(0x0008h[1])
+                * clock from ANA, default valid
+                */
                tmpV16 = rtl8723au_read16(padapter, REG_SYS_CLKR);
                if ((!(tmpV16 & LOADER_CLK_EN)) || (!(tmpV16 & ANA8M))) {
                        tmpV16 |= (LOADER_CLK_EN | ANA8M);
@@ -100,8 +87,7 @@ static void Efuse_PowerSwitch(struct rtw_adapter *padapter,
        }
 }
 
-u16
-Efuse_GetCurrentSize23a(struct rtw_adapter *pAdapter, u8 efuseType)
+u16 Efuse_GetCurrentSize23a(struct rtw_adapter *pAdapter, u8 efuseType)
 {
        u16 ret = 0;
 
@@ -113,26 +99,19 @@ Efuse_GetCurrentSize23a(struct rtw_adapter *pAdapter, u8 efuseType)
        return ret;
 }
 
-/*  11/16/2008 MH Add description. Get current efuse area enabled word!!. */
-u8
-Efuse_CalculateWordCnts23a(u8 word_en)
+/* Get current efuse area enabled word */
+u8 Efuse_CalculateWordCnts23a(u8 word_en)
 {
        return hweight8((~word_en) & 0xf);
 }
 
-/*  */
-/*     Description: */
-/*             Execute E-Fuse read byte operation. */
-/*             Referred from SD1 Richard. */
-/*  */
-/*     Assumption: */
-/*             1. Boot from E-Fuse and successfully auto-load. */
-/*             2. PASSIVE_LEVEL (USB interface) */
-/*  */
-/*     Created by Roger, 2008.10.21. */
-/*  */
-void
-ReadEFuseByte23a(struct rtw_adapter *Adapter, u16 _offset, u8 *pbuf)
+/*
+ * Description: Execute E-Fuse read byte operation.
+ *
+ * Assumptions: 1. Boot from E-Fuse and successfully auto-load.
+ *              2. PASSIVE_LEVEL (USB interface)
+ */
+void ReadEFuseByte23a(struct rtw_adapter *Adapter, u16 _offset, u8 *pbuf)
 {
        u32     value32;
        u8      readbyte;
@@ -156,19 +135,21 @@ ReadEFuseByte23a(struct rtw_adapter *Adapter, u16 _offset, u8 *pbuf)
                retry++;
        }
 
-       /*  20100205 Joseph: Add delay suggested by SD1 Victor. */
-       /*  This fix the problem that Efuse read error in high temperature condition. */
-       /*  Designer says that there shall be some delay after ready bit is set, or the */
-       /*  result will always stay on last data we read. */
+       /*
+        * Added suggested delay. This fixes the problem that
+        * Efuse read error in high temperature condition.
+        * Designer says that there shall be some delay after
+        * ready bit is set, or the result will always stay
+        * on last data we read.
+        */
        udelay(50);
        value32 = rtl8723au_read32(Adapter, EFUSE_CTRL);
 
        *pbuf = (u8)(value32 & 0xff);
 }
 
-void
-EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
-                           u8 type, void *pOut)
+void EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
+                                u8 type, void *pOut)
 {
        u8 *pu1Tmp;
        u16 *pu2Tmp;
@@ -249,24 +230,8 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
        }
 }
 
-/*-----------------------------------------------------------------------------
- * Function:   EFUSE_Read1Byte23a
- *
- * Overview:   Copy from WMAC fot EFUSE read 1 byte.
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 09/23/2008  MHC             Copy from WMAC.
- *
- *---------------------------------------------------------------------------*/
-u8
-EFUSE_Read1Byte23a(struct rtw_adapter *Adapter, u16 Address)
+/* Copy from WMAC for EFUSE read 1 byte. */
+u8 EFUSE_Read1Byte23a(struct rtw_adapter *Adapter, u16 Address)
 {
        u8      data;
        u8      Bytetemp = {0x00};
@@ -306,29 +271,10 @@ EFUSE_Read1Byte23a(struct rtw_adapter *Adapter, u16 Address)
                return data;
        } else
                return 0xFF;
-}/* EFUSE_Read1Byte23a */
-
-/*-----------------------------------------------------------------------------
- * Function:   EFUSE_Write1Byte
- *
- * Overview:   Copy from WMAC fot EFUSE write 1 byte.
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 09/23/2008  MHC             Copy from WMAC.
- *
- *---------------------------------------------------------------------------*/
+}
 
-void
-EFUSE_Write1Byte(struct rtw_adapter *Adapter, u16 Address, u8 Value);
-void
-EFUSE_Write1Byte(struct rtw_adapter *Adapter, u16 Address, u8 Value)
+/* Copy from WMAC fot EFUSE write 1 byte. */
+void EFUSE_Write1Byte(struct rtw_adapter *Adapter, u16 Address, u8 Value)
 {
        u8      Bytetemp = {0x00};
        u8      temp = {0x00};
@@ -367,24 +313,25 @@ EFUSE_Write1Byte(struct rtw_adapter *Adapter, u16 Address, u8 Value)
                        }
                }
        }
-}/* EFUSE_Write1Byte */
+}
 
-/*  11/16/2008 MH Read one byte from real Efuse. */
-int
-efuse_OneByteRead23a(struct rtw_adapter *pAdapter, u16 addr, u8 *data)
+/* Read one byte from real Efuse. */
+int efuse_OneByteRead23a(struct rtw_adapter *pAdapter, u16 addr, u8 *data)
 {
        u8      tmpidx = 0;
        int     bResult;
 
-       /*  -----------------e-fuse reg ctrl --------------------------------- */
+       /*  -----------------e-fuse reg ctrl ---------------------------- */
        /* address */
-       rtl8723au_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
-       rtl8723au_write8(pAdapter, EFUSE_CTRL+2, ((u8)((addr>>8) &0x03)) |
-       (rtl8723au_read8(pAdapter, EFUSE_CTRL+2)&0xFC));
+       rtl8723au_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff));
+       rtl8723au_write8(pAdapter, EFUSE_CTRL + 2,
+                        ((u8)((addr >> 8) & 0x03)) |
+                        (rtl8723au_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC));
 
-       rtl8723au_write8(pAdapter, EFUSE_CTRL+3,  0x72);/* read cmd */
+       rtl8723au_write8(pAdapter, EFUSE_CTRL + 3, 0x72); /* read cmd */
 
-       while(!(0x80 &rtl8723au_read8(pAdapter, EFUSE_CTRL+3)) && (tmpidx<100))
+       while (!(0x80 & rtl8723au_read8(pAdapter, EFUSE_CTRL + 3)) &&
+              (tmpidx < 100))
                tmpidx++;
        if (tmpidx < 100) {
                *data = rtl8723au_read8(pAdapter, EFUSE_CTRL);
@@ -396,26 +343,26 @@ efuse_OneByteRead23a(struct rtw_adapter *pAdapter, u16 addr, u8 *data)
        return bResult;
 }
 
-/*  11/16/2008 MH Write one byte to reald Efuse. */
-int
-efuse_OneByteWrite23a(struct rtw_adapter *pAdapter, u16 addr, u8 data)
+/* Write one byte to reald Efuse. */
+int efuse_OneByteWrite23a(struct rtw_adapter *pAdapter, u16 addr, u8 data)
 {
        u8      tmpidx = 0;
        int     bResult;
 
        /* return       0; */
 
-       /*  -----------------e-fuse reg ctrl --------------------------------- */
+       /*  -----------------e-fuse reg ctrl ------------------------- */
        /* address */
-       rtl8723au_write8(pAdapter, EFUSE_CTRL+1, (u8)(addr&0xff));
-       rtl8723au_write8(pAdapter, EFUSE_CTRL+2,
-       (rtl8723au_read8(pAdapter, EFUSE_CTRL+2)&0xFC)|(u8)((addr>>8)&0x03));
-       rtl8723au_write8(pAdapter, EFUSE_CTRL, data);/* data */
+       rtl8723au_write8(pAdapter, EFUSE_CTRL + 1, (u8)(addr & 0xff));
+       rtl8723au_write8(pAdapter, EFUSE_CTRL + 2,
+                        (rtl8723au_read8(pAdapter, EFUSE_CTRL + 2) & 0xFC) |
+                        (u8)((addr >> 8) & 0x03));
+       rtl8723au_write8(pAdapter, EFUSE_CTRL, data); /* data */
 
-       rtl8723au_write8(pAdapter, EFUSE_CTRL+3, 0xF2);/* write cmd */
+       rtl8723au_write8(pAdapter, EFUSE_CTRL + 3, 0xF2); /* write cmd */
 
-       while((0x80 & rtl8723au_read8(pAdapter, EFUSE_CTRL+3)) &&
-             (tmpidx<100)) {
+       while ((0x80 & rtl8723au_read8(pAdapter, EFUSE_CTRL + 3)) &&
+              (tmpidx < 100)) {
                tmpidx++;
        }
 
@@ -427,27 +374,8 @@ efuse_OneByteWrite23a(struct rtw_adapter *pAdapter, u16 addr, u8 data)
        return bResult;
 }
 
-/*-----------------------------------------------------------------------------
- * Function:   efuse_WordEnableDataRead23a
- *
- * Overview:   Read allowed word in current efuse section data.
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 11/16/2008  MHC             Create Version 0.
- * 11/21/2008  MHC             Fix Write bug when we only enable late word.
- *
- *---------------------------------------------------------------------------*/
-void
-efuse_WordEnableDataRead23a(u8 word_en,
-                        u8     *sourdata,
-                        u8     *targetdata)
+/* Read allowed word in current efuse section data. */
+void efuse_WordEnableDataRead23a(u8 word_en, u8 *sourdata, u8 *targetdata)
 {
        if (!(word_en&BIT(0))) {
                targetdata[0] = sourdata[0];
@@ -477,15 +405,13 @@ static int efuse_write8(struct rtw_adapter *padapter, u16 address, u8 *value)
        return efuse_OneByteWrite23a(padapter, address, *value);
 }
 
-/*
- * read/write raw efuse data
- */
+/* read/write raw efuse data */
 int rtw_efuse_access23a(struct rtw_adapter *padapter, u8 bWrite, u16 start_addr,
                        u16 cnts, u8 *data)
 {
        int i = 0;
        u16 real_content_len = 0, max_available_size = 0;
-       int res = _FAIL ;
+       int res = _FAIL;
        int (*rw8)(struct rtw_adapter *, u16, u8*);
 
        EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
@@ -507,7 +433,7 @@ int rtw_efuse_access23a(struct rtw_adapter *padapter, u8 bWrite, u16 start_addr,
 
        Efuse_PowerSwitch(padapter, bWrite, true);
 
-       /*  e-fuse one byte read / write */
+       /* e-fuse one byte read/write */
        for (i = 0; i < cnts; i++) {
                if (start_addr >= real_content_len) {
                        res = _FAIL;
@@ -523,16 +449,17 @@ int rtw_efuse_access23a(struct rtw_adapter *padapter, u8 bWrite, u16 start_addr,
 
        return res;
 }
-/*  */
+
 u16 efuse_GetMaxSize23a(struct rtw_adapter *padapter)
 {
        u16 max_size;
+
        EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI,
                                 TYPE_AVAILABLE_EFUSE_BYTES_TOTAL,
                                 (void *)&max_size);
        return max_size;
 }
-/*  */
+
 int rtw_efuse_map_read23a(struct rtw_adapter *padapter,
                          u16 addr, u16 cnts, u8 *data)
 {
@@ -573,26 +500,8 @@ int rtw_BT_efuse_map_read23a(struct rtw_adapter *padapter,
        return _SUCCESS;
 }
 
-/*-----------------------------------------------------------------------------
- * Function:   Efuse_ReadAllMap
- *
- * Overview:   Read All Efuse content
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 11/11/2008  MHC             Create Version 0.
- *
- *---------------------------------------------------------------------------*/
-void
-Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse);
-void
-Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse)
+/* Read All Efuse content */
+void Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse)
 {
        u16     mapLen = 0;
 
@@ -606,45 +515,32 @@ Efuse_ReadAllMap(struct rtw_adapter *pAdapter, u8 efuseType, u8 *Efuse)
        Efuse_PowerSwitch(pAdapter, false, false);
 }
 
-/*-----------------------------------------------------------------------------
- * Function:   efuse_ShadowRead1Byte
- *                     efuse_ShadowRead2Byte
- *                     efuse_ShadowRead4Byte
- *
- * Overview:   Read from efuse init map by one/two/four bytes !!!!!
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 11/12/2008  MHC             Create Version 0.
+/*
+ * Functions:  efuse_ShadowRead1Byte
+ *             efuse_ShadowRead2Byte
+ *             efuse_ShadowRead4Byte
  *
- *---------------------------------------------------------------------------*/
-static void
-efuse_ShadowRead1Byte(struct rtw_adapter *pAdapter, u16 Offset, u8 *Value)
+ * Read from efuse init map by one/two/four bytes
+ */
+static void efuse_ShadowRead1Byte(struct rtw_adapter *pAdapter, u16 Offset,
+                                 u8 *Value)
 {
        struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
 
        *Value = pEEPROM->efuse_eeprom_data[Offset];
-}      /*  EFUSE_ShadowRead23a1Byte */
+}
 
-/* Read Two Bytes */
-static void
-efuse_ShadowRead2Byte(struct rtw_adapter *pAdapter, u16 Offset, u16 *Value)
+static void efuse_ShadowRead2Byte(struct rtw_adapter *pAdapter, u16 Offset,
+                                 u16 *Value)
 {
        struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
 
        *Value = pEEPROM->efuse_eeprom_data[Offset];
        *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
-}      /*  EFUSE_ShadowRead23a2Byte */
+}
 
-/* Read Four Bytes */
-static void
-efuse_ShadowRead4Byte(struct rtw_adapter *pAdapter, u16 Offset, u32 *Value)
+static void efuse_ShadowRead4Byte(struct rtw_adapter *pAdapter, u16 Offset,
+                                 u32 *Value)
 {
        struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
 
@@ -652,24 +548,9 @@ efuse_ShadowRead4Byte(struct rtw_adapter *pAdapter, u16 Offset, u32 *Value)
        *Value |= pEEPROM->efuse_eeprom_data[Offset+1]<<8;
        *Value |= pEEPROM->efuse_eeprom_data[Offset+2]<<16;
        *Value |= pEEPROM->efuse_eeprom_data[Offset+3]<<24;
-}      /*  efuse_ShadowRead4Byte */
+}
 
-/*-----------------------------------------------------------------------------
- * Function:   EFUSE_ShadowMapUpdate23a
- *
- * Overview:   Transfer current EFUSE content to shadow init and modify map.
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 11/13/2008  MHC             Create Version 0.
- *
- *---------------------------------------------------------------------------*/
+/* Transfer current EFUSE content to shadow init and modify map. */
 void EFUSE_ShadowMapUpdate23a(struct rtw_adapter *pAdapter, u8 efuseType)
 {
        struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(pAdapter);
@@ -683,28 +564,11 @@ void EFUSE_ShadowMapUpdate23a(struct rtw_adapter *pAdapter, u8 efuseType)
        else
                Efuse_ReadAllMap(pAdapter, efuseType,
                                 pEEPROM->efuse_eeprom_data);
+}
 
-}/*  EFUSE_ShadowMapUpdate23a */
-
-/*-----------------------------------------------------------------------------
- * Function:   EFUSE_ShadowRead23a
- *
- * Overview:   Read from efuse init map !!!!!
- *
- * Input:       NONE
- *
- * Output:      NONE
- *
- * Return:      NONE
- *
- * Revised History:
- * When                        Who             Remark
- * 11/12/2008  MHC             Create Version 0.
- *
- *---------------------------------------------------------------------------*/
-void
-EFUSE_ShadowRead23a(struct rtw_adapter *pAdapter,
-                   u8 Type, u16 Offset, u32 *Value)
+/* Read from efuse init map */
+void EFUSE_ShadowRead23a(struct rtw_adapter *pAdapter, u8 Type,
+                        u16 Offset, u32 *Value)
 {
        if (Type == 1)
                efuse_ShadowRead1Byte(pAdapter, Offset, (u8 *)Value);
@@ -712,4 +576,4 @@ EFUSE_ShadowRead23a(struct rtw_adapter *pAdapter,
                efuse_ShadowRead2Byte(pAdapter, Offset, (u16 *)Value);
        else if (Type == 4)
                efuse_ShadowRead4Byte(pAdapter, Offset, (u32 *)Value);
-}      /*  EFUSE_ShadowRead23a */
+}
index cdd7bc402ece86a778059a83fc866acfab182489..07a6490a83d61d1bdf9317934df242efba7e7798 100644 (file)
@@ -348,9 +348,9 @@ int rtw_generate_ie23a(struct registry_priv *pregistrypriv)
 {
        u8      wireless_mode;
        int     sz = 0, rateLen;
-       struct wlan_bssid_ex*   pdev_network = &pregistrypriv->dev_network;
-       u8*     ie = pdev_network->IEs;
-       u16 cap;
+       struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network;
+       u8      *ie = pdev_network->IEs;
+       u16     cap;
 
        pdev_network->tsf = 0;
 
@@ -444,7 +444,8 @@ static int rtw_get_wpa2_cipher_suite(const u8 *s)
        return 0;
 }
 
-int rtw_parse_wpa_ie23a(const u8* wpa_ie, int wpa_ie_len, int *group_cipher, int *pairwise_cipher, int *is_8021x)
+int rtw_parse_wpa_ie23a(const u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
+                       int *pairwise_cipher, int *is_8021x)
 {
        int i, ret = _SUCCESS;
        int left, count;
index be9a3d560a437ac2bb2c193c72e4d83ae3a5cf7c..d28f29a938108bcb5dd8f20442a9d8f8ac2adca8 100644 (file)
@@ -1715,7 +1715,7 @@ OnAssocReq23a(struct rtw_adapter *padapter, struct recv_frame *precv_frame)
        spin_unlock_bh(&pstapriv->asoc_list_lock);
 
        /*  now the station is qualified to join our BSS... */
-       if (pstat && pstat->state & WIFI_FW_ASSOC_SUCCESS &&
+       if (pstat->state & WIFI_FW_ASSOC_SUCCESS &&
            status == WLAN_STATUS_SUCCESS) {
                /* 1 bss_cap_update & sta_info_update23a */
                bss_cap_update_on_sta_join23a(padapter, pstat);
@@ -5934,11 +5934,8 @@ int set_stakey_hdl23a(struct rtw_adapter *padapter, const u8 *pbuf)
                           macid = aid+1; */
                        cam_id = psta->mac_id + 3;
 
-                       DBG_8723A("Write CAM, mac_addr =%x:%x:%x:%x:%x:%x, "
-                                 "cam_entry =%d\n", pparm->addr[0],
-                                 pparm->addr[1], pparm->addr[2],
-                                 pparm->addr[3], pparm->addr[4],
-                                 pparm->addr[5], cam_id);
+                       DBG_8723A("Write CAM, mac_addr =%pM, "
+                                 "cam_entry =%d\n", pparm->addr, cam_id);
 
                        rtl8723a_cam_write(padapter, cam_id, ctrl,
                                           pparm->addr, pparm->key);
index ad0549c66529057dac8fe4ed5264df7666c95e39..404b61898d08b5a989475cc4527c83fb7450853c 100644 (file)
@@ -626,7 +626,7 @@ void process23a_pwrbit_data(struct rtw_adapter *padapter,
        struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
        struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
        struct sta_priv *pstapriv = &padapter->stapriv;
-       struct sta_info *psta = NULL;
+       struct sta_info *psta;
 
        psta = rtw_get_stainfo23a(pstapriv, pattrib->src);
 
@@ -653,7 +653,7 @@ void process_wmmps_data(struct rtw_adapter *padapter,
 #ifdef CONFIG_8723AU_AP_MODE
        struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
        struct sta_priv *pstapriv = &padapter->stapriv;
-       struct sta_info *psta = NULL;
+       struct sta_info *psta;
 
        psta = rtw_get_stainfo23a(pstapriv, pattrib->src);
 
@@ -2151,7 +2151,7 @@ int process_recv_indicatepkts(struct rtw_adapter *padapter,
 static int recv_func_prehandle(struct rtw_adapter *padapter,
                               struct recv_frame *rframe)
 {
-       int ret = _SUCCESS;
+       int ret;
 
        /* check the frame crtl field and decache */
        ret = validate_recv_frame(padapter, rframe);
index 3d40bab1d9c8f1d934f0e49cbdd14bdf632a6e26..038b57b3afe27314aee0759c56dc2b6d026e27d4 100644 (file)
@@ -245,8 +245,8 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
        arcfour_encrypt(&mycontext, payload, payload, length);
 
        /* calculate icv and compare the icv */
-       actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
-       expected_crc = le32_to_cpu(get_unaligned_le32(&payload[length - 4]));
+       actual_crc = getcrc32(payload, length - 4);
+       expected_crc = get_unaligned_le32(&payload[length - 4]);
 
        if (actual_crc != expected_crc) {
                RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
@@ -608,7 +608,6 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
        u8 hw_hdr_offset = 0;
        struct arc4context mycontext;
        int curfragnum, length;
-       u32 prwskeylen;
        u8 *pframe, *payload, *iv, *prwskey;
        union pn48 dot11txpn;
        struct sta_info *stainfo;
@@ -655,8 +654,6 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
        else
                prwskey = &stainfo->dot118021x_UncstKey.skey[0];
 
-       prwskeylen = 16;
-
        /* 4 start to encrypt each fragment */
        for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
                iv = pframe + pattrib->hdrlen;
@@ -719,7 +716,6 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
        u32 actual_crc, expected_crc;
        struct arc4context mycontext;
        int length;
-       u32 prwskeylen;
        u8 *pframe, *payload, *iv, *prwskey;
        union pn48 dot11txpn;
        struct sta_info *stainfo;
@@ -749,12 +745,10 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
                        goto exit;
                }
                prwskey = psecuritypriv->dot118021XGrpKey[prxattrib->key_index].skey;
-               prwskeylen = 16;
        } else {
                RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
                         "%s: stainfo!= NULL!!!\n", __func__);
                prwskey = &stainfo->dot118021x_UncstKey.skey[0];
-               prwskeylen = 16;
        }
 
        iv = pframe + prxattrib->hdrlen;
@@ -773,8 +767,8 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
        arcfour_init(&mycontext, rc4key, 16);
        arcfour_encrypt(&mycontext, payload, payload, length);
 
-       actual_crc = le32_to_cpu(getcrc32(payload, length - 4));
-       expected_crc = le32_to_cpu(get_unaligned_le32(&payload[length - 4]));
+       actual_crc = getcrc32(payload, length - 4);
+       expected_crc = get_unaligned_le32(&payload[length - 4]);
 
        if (actual_crc != expected_crc) {
                RT_TRACE(_module_rtl871x_security_c_, _drv_err_,
@@ -1288,7 +1282,6 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
 {      /* exclude ICV */
        /* Intermediate Buffers */
        int curfragnum, length;
-       u32 prwskeylen;
        u8 *pframe, *prwskey;
        u8 hw_hdr_offset = 0;
        struct sta_info *stainfo;
@@ -1335,8 +1328,6 @@ int rtw_aes_encrypt23a(struct rtw_adapter *padapter,
        else
                prwskey = &stainfo->dot118021x_UncstKey.skey[0];
 
-       prwskeylen = 16;
-
        for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
                /* 4 the last fragment */
                if ((curfragnum + 1) == pattrib->nr_frags) {
index 3c1315fc02e5a9cb20385a2ed5ed1f9301657a57..cc2b84be97746fd966d2c9e36c60798f05b3cf96 100644 (file)
@@ -525,7 +525,7 @@ void WMMOnAssocRsp23a(struct rtw_adapter *padapter)
        else
                aSifsTime = 16;
 
-               for (i = 0; i < 4; i++) {
+       for (i = 0; i < 4; i++) {
                ACI = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 5) & 0x03;
                ACM = (pmlmeinfo->WMM_param.ac_param[i].ACI_AIFSN >> 4) & 0x01;
 
@@ -1212,7 +1212,7 @@ unsigned int update_supported_rate23a(unsigned char *ptn, unsigned int ptn_sz)
 
 unsigned int update_MSC_rate23a(struct ieee80211_ht_cap *pHT_caps)
 {
-       unsigned int mask = 0;
+       unsigned int mask;
 
        mask = pHT_caps->mcs.rx_mask[0] << 12 |
                pHT_caps->mcs.rx_mask[1] << 20;
index cf15f80836badfd625e63e7a3d241686a6f0fb9a..d5c48a56d4aca7b63c892d5f20670f2177eba610 100644 (file)
@@ -72,7 +72,6 @@ if ((BTCoexDbgLevel == _bt_dbg_on_)) {\
 #define DCMD_Printf(...)
 #define RT_ASSERT(...)
 
-#define rsprintf snprintf
 
 #define GetDefaultAdapter(padapter)    padapter
 
@@ -1455,7 +1454,7 @@ bthci_StartBeaconAndConnect(
        }
 
        if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_CREATOR) {
-               rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
+               snprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
                padapter->eeprompriv.mac_addr[0],
                padapter->eeprompriv.mac_addr[1],
                padapter->eeprompriv.mac_addr[2],
@@ -1463,7 +1462,7 @@ bthci_StartBeaconAndConnect(
                padapter->eeprompriv.mac_addr[4],
                padapter->eeprompriv.mac_addr[5]);
        } else if (pBTInfo->BtAsocEntry[CurrentAssocNum].AMPRole == AMP_BTAP_JOINER) {
-               rsprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
+               snprintf((char *)pBTInfo->BtAsocEntry[CurrentAssocNum].BTSsidBuf, 32, "AMP-%02x-%02x-%02x-%02x-%02x-%02x",
                pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[0],
                pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[1],
                pBTInfo->BtAsocEntry[CurrentAssocNum].BTRemoteMACAddr[2],
@@ -5550,7 +5549,7 @@ static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
 {
        struct hal_data_8723a *pHalData;
        struct btdm_8723a_1ant *pBtdm8723;
-       static s8 up, dn, m = 1, n = 3, WaitCount;
+       static s8 up, dn, m = 1, WaitCount;
        s8 ret;
 
        pHalData = GET_HAL_DATA(padapter);
@@ -5561,7 +5560,6 @@ static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
                up = 0;
                dn = 0;
                m = 1;
-               n = 3;
                WaitCount = 0;
        } else {
                WaitCount++;
@@ -5576,8 +5574,6 @@ static s8 btdm_1AntTdmaJudgement(struct rtw_adapter *padapter, u8 retry)
                if (up >= 3*m) {
                        /*  retry = 0 in consecutive 3m*(2s), add WiFi duration */
                        ret = 1;
-
-                       n = 3;
                        up = 0;
                        dn = 0;
                        WaitCount = 0;
@@ -5648,7 +5644,7 @@ static void btdm_1AntTdmaDurationAdjustForACL(struct rtw_adapter *padapter)
                    (pBtdm8723->curPsTdma != 11)) {
                        btdm_1AntSetPSTDMA(padapter, true, 0, true, pBtdm8723->psTdmaDuAdjType);
                } else {
-                       s32 judge = 0;
+                       s32 judge;
 
                        judge = btdm_1AntTdmaJudgement(padapter, pHalData->bt_coexist.halCoex8723.btRetryCnt);
                        if (judge == -1) {
@@ -9079,7 +9075,7 @@ static void btdm_BTCoexist8723AHandler(struct rtw_adapter *padapter)
 u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
 {
        struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
-       u32     counters = 0;
+       u32     counters;
 
        counters = pHalData->bt_coexist.halCoex8723.highPriorityTx+
                pHalData->bt_coexist.halCoex8723.highPriorityRx;
@@ -9089,7 +9085,7 @@ u32 BTDM_BtTxRxCounterH(struct rtw_adapter *padapter)
 u32 BTDM_BtTxRxCounterL(struct rtw_adapter *padapter)
 {
        struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
-       u32     counters = 0;
+       u32     counters;
 
        counters = pHalData->bt_coexist.halCoex8723.lowPriorityTx+
                pHalData->bt_coexist.halCoex8723.lowPriorityRx;
@@ -9301,7 +9297,7 @@ static void BTDM_AdjustForBtOperation8723A(struct rtw_adapter *padapter)
 static void BTDM_FwC2hBtRssi8723A(struct rtw_adapter *padapter, u8 *tmpBuf)
 {
        struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
-       u8 percent = 0, u1tmp = 0;
+       u8 percent, u1tmp;
 
        u1tmp = tmpBuf[0];
        percent = u1tmp*2+10;
@@ -9377,47 +9373,47 @@ static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
        u32 u4Tmp[4];
        u8 antNum = Ant_x2;
 
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
        DCMD_Printf(btCoexDbgBuf);
 
        if (!rtl8723a_BT_coexist(padapter)) {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");
                DCMD_Printf(btCoexDbgBuf);
                return;
        }
 
        antNum = btdm_BtWifiAntNum(padapter);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/%d ", "Ant mechanism PG/Now run :", \
                ((pHalData->bt_coexist.BT_Ant_Num == Ant_x2) ? 2 : 1), ((antNum == Ant_x2) ? 2 : 1));
        DCMD_Printf(btCoexDbgBuf);
 
        if (pBtMgnt->ExtConfig.bManualControl) {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");
                DCMD_Printf(btCoexDbgBuf);
        } else {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
                        ((pBtMgnt->bSupportProfile) ? "Yes" : "No"), pBtMgnt->ExtConfig.HCIExtensionVer);
                DCMD_Printf(btCoexDbgBuf);
        }
 
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = / %d", "Dot11 channel / BT channel", \
                pBtMgnt->BTChannel);
                DCMD_Printf(btCoexDbgBuf);
 
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %d / %d / %d", "Wifi/BT/HS rssi", \
                BTDM_GetRxSS(padapter),
                pHalData->bt_coexist.halCoex8723.btRssi,
                pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB);
                        DCMD_Printf(btCoexDbgBuf);
 
        if (!pBtMgnt->ExtConfig.bManualControl) {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\n %-35s = %s / %s ", "WIfi status",
                        ((BTDM_Legacy(padapter)) ? "Legacy" : (((BTDM_IsHT40(padapter)) ? "HT40" : "HT20"))),
                        ((!BTDM_IsWifiBusy(padapter)) ? "idle" : ((BTDM_IsWifiUplink(padapter)) ? "uplink" : "downlink")));
                DCMD_Printf(btCoexDbgBuf);
 
                if (pBtMgnt->bSupportProfile) {
-                       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
+                       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
                                ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_SCO)) ? 1 : 0),
                                ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_HID)) ? 1 : 0),
                                ((BTHCI_CheckProfileExist(padapter, BT_PROFILE_PAN)) ? 1 : 0),
@@ -9426,19 +9422,19 @@ static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
 
                        for (i = 0; i < pBtMgnt->ExtConfig.NumberOfHandle; i++) {
                                if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
-                                       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
+                                       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role",
                                                BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
                                                BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec],
                                                BtLinkRoleString[pBtMgnt->ExtConfig.linkInfo[i].linkRole]);
                                        DCMD_Printf(btCoexDbgBuf);
 
                                        btInfoExt = pHalData->bt_coexist.halCoex8723.btInfoExt;
-                                       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
+                                       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "A2DP rate", \
                                                 (btInfoExt & BIT(0)) ?
                                                 "Basic rate" : "EDR rate");
                                        DCMD_Printf(btCoexDbgBuf);
                                } else {
-                                       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
+                                       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
                                                BtProfileString[pBtMgnt->ExtConfig.linkInfo[i].BTProfile],
                                                BtSpecString[pBtMgnt->ExtConfig.linkInfo[i].BTCoreSpec]);
                                        DCMD_Printf(btCoexDbgBuf);
@@ -9449,29 +9445,29 @@ static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
 
        /*  Sw mechanism */
        if (!pBtMgnt->ExtConfig.bManualControl) {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw BT Coex mechanism]============");
                DCMD_Printf(btCoexDbgBuf);
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "AGC Table", \
                        pBtCoex->btdm2Ant.bCurAgcTableEn);
                DCMD_Printf(btCoexDbgBuf);
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "ADC Backoff", \
                        pBtCoex->btdm2Ant.bCurAdcBackOff);
                DCMD_Printf(btCoexDbgBuf);
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Low penalty RA", \
                        pBtCoex->btdm2Ant.bCurLowPenaltyRa);
                DCMD_Printf(btCoexDbgBuf);
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "RF Rx LPF Shrink", \
                        pBtCoex->btdm2Ant.bCurRfRxLpfShrink);
                DCMD_Printf(btCoexDbgBuf);
        }
        u4Tmp[0] = PHY_QueryRFReg(padapter, PathA, 0x1e, 0xff0);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "RF-A, 0x1e[11:4]/original val", \
                u4Tmp[0], pHalData->bt_coexist.BtRfRegOrigin1E);
        DCMD_Printf(btCoexDbgBuf);
 
        /*  Fw mechanism */
        if (!pBtMgnt->ExtConfig.bManualControl) {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw BT Coex mechanism]============");
                DCMD_Printf(btCoexDbgBuf);
        }
        if (!pBtMgnt->ExtConfig.bManualControl) {
@@ -9479,57 +9475,57 @@ static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
                        psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm1Ant.curPsTdma;
                else
                        psTdmaCase = pHalData->bt_coexist.halCoex8723.btdm2Ant.curPsTdma;
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA(0x3a)", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA(0x3a)", \
                        pHalData->bt_coexist.fw3aVal[0], pHalData->bt_coexist.fw3aVal[1],
                        pHalData->bt_coexist.fw3aVal[2], pHalData->bt_coexist.fw3aVal[3],
                        pHalData->bt_coexist.fw3aVal[4], psTdmaCase);
                DCMD_Printf(btCoexDbgBuf);
 
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "Decrease Bt Power", \
                        pBtCoex->btdm2Ant.bCurDecBtPwr);
                DCMD_Printf(btCoexDbgBuf);
        }
        u1Tmp = rtl8723au_read8(padapter, 0x778);
        u1Tmp1 = rtl8723au_read8(padapter, 0x783);
        u1Tmp2 = rtl8723au_read8(padapter, 0x796);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
                u1Tmp, u1Tmp1, u1Tmp2);
        DCMD_Printf(btCoexDbgBuf);
 
        if (!pBtMgnt->ExtConfig.bManualControl) {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "Sw DacSwing Ctrl/Val", \
                        pBtCoex->btdm2Ant.bCurDacSwingOn, pBtCoex->btdm2Ant.curDacSwingLvl);
                DCMD_Printf(btCoexDbgBuf);
        }
        u4Tmp[0] =  rtl8723au_read32(padapter, 0x880);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \
                u4Tmp[0]);
        DCMD_Printf(btCoexDbgBuf);
 
        /*  Hw mechanism */
        if (!pBtMgnt->ExtConfig.bManualControl) {
-               rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
+               snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw BT Coex mechanism]============");
                DCMD_Printf(btCoexDbgBuf);
        }
 
        u1Tmp = rtl8723au_read8(padapter, 0x40);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \
                u1Tmp);
        DCMD_Printf(btCoexDbgBuf);
 
        u4Tmp[0] = rtl8723au_read32(padapter, 0x550);
        u1Tmp = rtl8723au_read8(padapter, 0x522);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x", "0x550(bcn contrl)/0x522", \
                u4Tmp[0], u1Tmp);
        DCMD_Printf(btCoexDbgBuf);
 
        u4Tmp[0] = rtl8723au_read32(padapter, 0x484);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
                u4Tmp[0]);
        DCMD_Printf(btCoexDbgBuf);
 
        u4Tmp[0] = rtl8723au_read32(padapter, 0x50);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \
                u4Tmp[0]);
        DCMD_Printf(btCoexDbgBuf);
 
@@ -9537,7 +9533,7 @@ static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
        u4Tmp[1] = rtl8723au_read32(padapter, 0xda4);
        u4Tmp[2] = rtl8723au_read32(padapter, 0xda8);
        u4Tmp[3] = rtl8723au_read32(padapter, 0xdac);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
                u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);
        DCMD_Printf(btCoexDbgBuf);
 
@@ -9545,27 +9541,27 @@ static void BTDM_Display8723ABtCoexInfo(struct rtw_adapter *padapter)
        u4Tmp[1] = rtl8723au_read32(padapter, 0x6c4);
        u4Tmp[2] = rtl8723au_read32(padapter, 0x6c8);
        u1Tmp = rtl8723au_read8(padapter, 0x6cc);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
                u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp);
        DCMD_Printf(btCoexDbgBuf);
 
        /* u4Tmp = rtl8723au_read32(padapter, 0x770); */
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x770(Hi pri Rx[31:16]/Tx[15:0])", \
                pHalData->bt_coexist.halCoex8723.highPriorityRx,
                pHalData->bt_coexist.halCoex8723.highPriorityTx);
        DCMD_Printf(btCoexDbgBuf);
        /* u4Tmp = rtl8723au_read32(padapter, 0x774); */
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d", "0x774(Lo pri Rx[31:16]/Tx[15:0])", \
                pHalData->bt_coexist.halCoex8723.lowPriorityRx,
                pHalData->bt_coexist.halCoex8723.lowPriorityTx);
        DCMD_Printf(btCoexDbgBuf);
 
        /*  Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang */
        u1Tmp = rtl8723au_read8(padapter, 0x41b);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (hang chk == 0xf)", \
                u1Tmp);
        DCMD_Printf(btCoexDbgBuf);
-       rsprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
+       snprintf(btCoexDbgBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
                pHalData->LastHMEBoxNum);
        DCMD_Printf(btCoexDbgBuf);
 }
index 9733aa6ef908c419999d2ad69c16ff9dc5911bff..1662c03c1323f97137729cad9e22e720f11b44cc 100644 (file)
@@ -127,8 +127,7 @@ int rtl8723a_set_raid_cmd(struct rtw_adapter *padapter, u32 mask, u8 arg)
        u8 buf[5];
 
        memset(buf, 0, 5);
-       mask = cpu_to_le32(mask);
-       memcpy(buf, &mask, 4);
+       put_unaligned_le32(mask, buf);
        buf[4]  = arg;
 
        FillH2CCmd(padapter, MACID_CONFIG_EID, 5, buf);
index cf2388f4f6e75b9d047aaac669e8d8f6cbb0632a..ecf54ee47f7c979e23e97a70fcfbbc4e12729bf5 100644 (file)
@@ -249,13 +249,13 @@ int rtl8723a_FirmwareDownload(struct rtw_adapter *padapter)
                goto Exit;
        }
        firmware_buf = kmemdup(fw->data, fw->size, GFP_KERNEL);
+       fw_size = fw->size;
+       release_firmware(fw);
        if (!firmware_buf) {
                rtStatus = _FAIL;
                goto Exit;
        }
        buf = firmware_buf;
-       fw_size = fw->size;
-       release_firmware(fw);
 
        /*  To Check Fw header. Added by tynli. 2009.12.04. */
        pFwHdr = (struct rt_8723a_firmware_hdr *)firmware_buf;
@@ -1497,29 +1497,6 @@ void Hal_EfuseParseIDCode(struct rtw_adapter *padapter, u8 *hwinfo)
                 "EEPROM ID = 0x%04x\n", EEPROMId);
 }
 
-static void Hal_EEValueCheck(u8 EEType, void *pInValue, void *pOutValue)
-{
-       switch (EEType) {
-       case EETYPE_TX_PWR:
-       {
-               u8 *pIn, *pOut;
-               pIn = (u8 *) pInValue;
-               pOut = (u8 *) pOutValue;
-               if (*pIn <= 63)
-                       *pOut = *pIn;
-               else {
-                       RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
-                                "EETYPE_TX_PWR, value =%d is invalid, set to default = 0x%x\n",
-                                *pIn, EEPROM_Default_TxPowerLevel);
-                       *pOut = EEPROM_Default_TxPowerLevel;
-               }
-       }
-               break;
-       default:
-               break;
-       }
-}
-
 static void
 Hal_ReadPowerValueFromPROM_8723A(struct txpowerinfo *pwrInfo,
                                 u8 *PROMContent, bool AutoLoadFail)
@@ -1555,16 +1532,19 @@ Hal_ReadPowerValueFromPROM_8723A(struct txpowerinfo *pwrInfo,
                for (group = 0; group < MAX_CHNL_GROUP; group++) {
                        eeAddr =
                            EEPROM_CCK_TX_PWR_INX_8723A + (rfPath * 3) + group;
-                       /* pwrInfo->CCKIndex[rfPath][group] =
-                          PROMContent[eeAddr]; */
-                       Hal_EEValueCheck(EETYPE_TX_PWR, &PROMContent[eeAddr],
-                                        &pwrInfo->CCKIndex[rfPath][group]);
+
+                       pwrInfo->CCKIndex[rfPath][group] = PROMContent[eeAddr];
+                       if (pwrInfo->CCKIndex[rfPath][group] > 63)
+                               pwrInfo->CCKIndex[rfPath][group] =
+                                       EEPROM_Default_TxPowerLevel;
+
                        eeAddr = EEPROM_HT40_1S_TX_PWR_INX_8723A +
                                (rfPath * 3) + group;
-                       /* pwrInfo->HT40_1SIndex[rfPath][group] =
-                          PROMContent[eeAddr]; */
-                       Hal_EEValueCheck(EETYPE_TX_PWR, &PROMContent[eeAddr],
-                                        &pwrInfo->HT40_1SIndex[rfPath][group]);
+                       pwrInfo->HT40_1SIndex[rfPath][group] =
+                               PROMContent[eeAddr];
+                       if (pwrInfo->HT40_1SIndex[rfPath][group] > 63)
+                               pwrInfo->HT40_1SIndex[rfPath][group] =
+                                       EEPROM_Default_TxPowerLevel;
                }
        }
 
index 7fa97808b9511ad6e74b3b2c511a6f30a8756ce1..06a6c3eeeb330f1cd1f35587cb16ae93b8af0a4f 100644 (file)
@@ -748,36 +748,6 @@ PHY_BBConfig8723A(struct rtw_adapter *Adapter)
        return rtStatus;
 }
 
-static void getTxPowerIndex(struct rtw_adapter *Adapter,
-                           u8 channel, u8 *cckPowerLevel,  u8 *ofdmPowerLevel)
-{
-       struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
-       u8 index = (channel - 1);
-       /*  1. CCK */
-       cckPowerLevel[RF_PATH_A] = pHalData->TxPwrLevelCck[RF_PATH_A][index];
-       cckPowerLevel[RF_PATH_B] = pHalData->TxPwrLevelCck[RF_PATH_B][index];
-
-       /*  2. OFDM for 1S or 2S */
-       if (GET_RF_TYPE(Adapter) == RF_1T2R || GET_RF_TYPE(Adapter) == RF_1T1R) {
-               /*  Read HT 40 OFDM TX power */
-               ofdmPowerLevel[RF_PATH_A] =
-                       pHalData->TxPwrLevelHT40_1S[RF_PATH_A][index];
-               ofdmPowerLevel[RF_PATH_B] =
-                       pHalData->TxPwrLevelHT40_1S[RF_PATH_B][index];
-       } else if (GET_RF_TYPE(Adapter) == RF_2T2R) {
-               /*  Read HT 40 OFDM TX power */
-               ofdmPowerLevel[RF_PATH_A] =
-                       pHalData->TxPwrLevelHT40_2S[RF_PATH_A][index];
-               ofdmPowerLevel[RF_PATH_B] =
-                       pHalData->TxPwrLevelHT40_2S[RF_PATH_B][index];
-       }
-}
-
-static void ccxPowerIndexCheck(struct rtw_adapter *Adapter, u8 channel,
-                              u8 *cckPowerLevel, u8 *ofdmPowerLevel)
-{
-}
-
 /*-----------------------------------------------------------------------------
  * Function:    SetTxPowerLevel8723A()
  *
@@ -795,19 +765,30 @@ static void ccxPowerIndexCheck(struct rtw_adapter *Adapter, u8 channel,
 void PHY_SetTxPowerLevel8723A(struct rtw_adapter *Adapter, u8 channel)
 {
        struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
-       u8 cckPowerLevel[2], ofdmPowerLevel[2]; /*  [0]:RF-A, [1]:RF-B */
+       u8 cckpwr[2], ofdmpwr[2];       /*  [0]:RF-A, [1]:RF-B */
+       int i = channel - 1;
 
        if (pHalData->bTXPowerDataReadFromEEPORM == false)
                return;
 
-       getTxPowerIndex(Adapter, channel, &cckPowerLevel[0],
-                       &ofdmPowerLevel[0]);
+       /*  1. CCK */
+       cckpwr[RF_PATH_A] = pHalData->TxPwrLevelCck[RF_PATH_A][i];
+       cckpwr[RF_PATH_B] = pHalData->TxPwrLevelCck[RF_PATH_B][i];
 
-       ccxPowerIndexCheck(Adapter, channel, &cckPowerLevel[0],
-                          &ofdmPowerLevel[0]);
+       /*  2. OFDM for 1S or 2S */
+       if (GET_RF_TYPE(Adapter) == RF_1T2R ||
+           GET_RF_TYPE(Adapter) == RF_1T1R) {
+               /*  Read HT 40 OFDM TX power */
+               ofdmpwr[RF_PATH_A] = pHalData->TxPwrLevelHT40_1S[RF_PATH_A][i];
+               ofdmpwr[RF_PATH_B] = pHalData->TxPwrLevelHT40_1S[RF_PATH_B][i];
+       } else if (GET_RF_TYPE(Adapter) == RF_2T2R) {
+               /*  Read HT 40 OFDM TX power */
+               ofdmpwr[RF_PATH_A] = pHalData->TxPwrLevelHT40_2S[RF_PATH_A][i];
+               ofdmpwr[RF_PATH_B] = pHalData->TxPwrLevelHT40_2S[RF_PATH_B][i];
+       }
 
-       rtl823a_phy_rf6052setccktxpower(Adapter, &cckPowerLevel[0]);
-       rtl8723a_PHY_RF6052SetOFDMTxPower(Adapter, &ofdmPowerLevel[0], channel);
+       rtl823a_phy_rf6052setccktxpower(Adapter, &cckpwr[0]);
+       rtl8723a_PHY_RF6052SetOFDMTxPower(Adapter, &ofdmpwr[0], channel);
 }
 
 /*-----------------------------------------------------------------------------
index 11d635d2eac8ef348c9942db83a69b44f26c4aba..ce0d8d89478707153e462089cf439a3bb2c828d9 100644 (file)
@@ -103,34 +103,24 @@ void rtl823a_phy_rf6052setccktxpower(struct rtw_adapter *Adapter,
        struct dm_priv *pdmpriv = &pHalData->dmpriv;
        struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
        u32 TxAGC[2] = {0, 0}, tmpval = 0;
-       bool TurboScanOff = false;
        u8 idx1, idx2;
        u8 *ptr;
 
-       /*  According to SD3 eechou's suggestion, we need to disable
-           turbo scan for RU. */
-       /*  Otherwise, external PA will be broken if power index > 0x20. */
-       if (pHalData->EEPROMRegulatory != 0 || pHalData->ExternalPA)
-               TurboScanOff = true;
-
        if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
                TxAGC[RF_PATH_A] = 0x3f3f3f3f;
                TxAGC[RF_PATH_B] = 0x3f3f3f3f;
 
-               TurboScanOff = true;/* disable turbo scan */
-
-               if (TurboScanOff) {
-                       for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) {
-                               TxAGC[idx1] = pPowerlevel[idx1] |
-                                       (pPowerlevel[idx1] << 8) |
-                                       (pPowerlevel[idx1] << 16) |
-                                       (pPowerlevel[idx1] << 24);
-                               /*  2010/10/18 MH For external PA module.
-                                   We need to limit power index to be less
-                                   than 0x20. */
-                               if (TxAGC[idx1] > 0x20 && pHalData->ExternalPA)
-                                       TxAGC[idx1] = 0x20;
-                       }
+               for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) {
+                       TxAGC[idx1] = pPowerlevel[idx1] |
+                               (pPowerlevel[idx1] << 8) |
+                               (pPowerlevel[idx1] << 16) |
+                               (pPowerlevel[idx1] << 24);
+                       /*
+                        * 2010/10/18 MH For external PA module. We need
+                        * to limit power index to be less than 0x20.
+                        */
+                       if (TxAGC[idx1] > 0x20 && pHalData->ExternalPA)
+                               TxAGC[idx1] = 0x20;
                }
        } else {
 /*  20100427 Joseph: Driver dynamic Tx power shall not affect Tx
@@ -194,7 +184,7 @@ static void getPowerBase(struct rtw_adapter *Adapter, u8 *pPowerLevel,
                         u8 Channel, u32 *OfdmBase, u32 *MCSBase)
 {
        struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
-       u32 powerBase0, powerBase1;
+       u32 ofdm, mcs;
        u8 Legacy_pwrdiff = 0;
        s8 HT20_pwrdiff = 0;
        u8 i, powerlevel[2];
@@ -202,11 +192,10 @@ static void getPowerBase(struct rtw_adapter *Adapter, u8 *pPowerLevel,
        for (i = 0; i < 2; i++) {
                powerlevel[i] = pPowerLevel[i];
                Legacy_pwrdiff = pHalData->TxPwrLegacyHtDiff[i][Channel-1];
-               powerBase0 = powerlevel[i] + Legacy_pwrdiff;
+               ofdm = powerlevel[i] + Legacy_pwrdiff;
 
-               powerBase0 = powerBase0 << 24 | powerBase0 << 16 |
-                       powerBase0 << 8 | powerBase0;
-               *(OfdmBase + i) = powerBase0;
+               ofdm = ofdm << 24 | ofdm << 16 | ofdm << 8 | ofdm;
+               *(OfdmBase + i) = ofdm;
        }
 
        for (i = 0; i < 2; i++) {
@@ -215,10 +204,9 @@ static void getPowerBase(struct rtw_adapter *Adapter, u8 *pPowerLevel,
                        HT20_pwrdiff = pHalData->TxPwrHt20Diff[i][Channel-1];
                        powerlevel[i] += HT20_pwrdiff;
                }
-               powerBase1 = powerlevel[i];
-               powerBase1 = powerBase1 << 24 | powerBase1 << 16 |
-                       powerBase1 << 8 | powerBase1;
-               *(MCSBase + i) = powerBase1;
+               mcs = powerlevel[i];
+               mcs = mcs << 24 | mcs << 16 | mcs << 8 | mcs;
+               *(MCSBase + i) = mcs;
        }
 }
 
index 68156a13d00f014b2daf3f903a9067b3a6898d12..9926b0790e7599da880c3d2091ada6ebeaacbe32 100644 (file)
@@ -834,12 +834,11 @@ static void phy_SsPwrSwitch92CU(struct rtw_adapter *Adapter,
                        rtl8723au_read32(Adapter, rOFDM0_TRxPathEnable);
                Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF2] =
                        rtl8723au_read32(Adapter, rFPGA0_RFMOD);
-               if (pHalData->rf_type ==  RF_2T2R) {
+               if (pHalData->rf_type ==  RF_2T2R)
                        PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
                                     0x380038, 0);
-               } else if (pHalData->rf_type ==  RF_1T1R) {
+               else if (pHalData->rf_type ==  RF_1T1R)
                        PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, 0x38, 0);
-               }
                PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 0);
                PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 1);
 
index 4dcc9253be5155d2ff84be68bc422de1a5bcd5cb..d1fa95d28904bc044eee3c0d8d7e1707e708f09b 100644 (file)
@@ -725,11 +725,9 @@ void rtw_disassoc_cmd23a_callback(struct rtw_adapter  *padapter, struct cmd_obj
 void rtw_joinbss_cmd23a_callback(struct rtw_adapter  *padapter, struct cmd_obj *pcmd);
 void rtw_createbss_cmd23a_callback(struct rtw_adapter  *padapter, struct cmd_obj *pcmd);
 void rtw_getbbrfreg_cmdrsp_callback23a(struct rtw_adapter  *padapter, struct cmd_obj *pcmd);
-void rtw_readtssi_cmdrsp_callback(struct rtw_adapter*  padapter,  struct cmd_obj *pcmd);
 
 void rtw_setstaKey_cmdrsp_callback23a(struct rtw_adapter  *padapter,  struct cmd_obj *pcmd);
 void rtw_setassocsta_cmdrsp_callback23a(struct rtw_adapter  *padapter,  struct cmd_obj *pcmd);
-void rtw_getrttbl_cmdrsp_callback(struct rtw_adapter  *padapter,  struct cmd_obj *pcmd);
 
 struct _cmd_callback {
        u32     cmd_code;
index b4e45436a4b9f261261ff1817a7b5a8184147425..1fe8e3e0a3fbeb743da0ddb13b3eb9b343f2dba9 100644 (file)
@@ -647,8 +647,6 @@ static void rtsx_release_resources(struct rtsx_dev *dev)
        wait_timeout(200);
 
        if (dev->rtsx_resv_buf) {
-               dma_free_coherent(&(dev->pci->dev), RTSX_RESV_BUF_LEN,
-                               dev->rtsx_resv_buf, dev->rtsx_resv_buf_addr);
                dev->chip->host_cmds_ptr = NULL;
                dev->chip->host_sg_tbl_ptr = NULL;
        }
@@ -918,8 +916,8 @@ static int rtsx_probe(struct pci_dev *pci,
        dev_info(&pci->dev, "Original address: 0x%lx, remapped address: 0x%lx\n",
                 (unsigned long)(dev->addr), (unsigned long)(dev->remap_addr));
 
-       dev->rtsx_resv_buf = dma_alloc_coherent(&(pci->dev), RTSX_RESV_BUF_LEN,
-                       &(dev->rtsx_resv_buf_addr), GFP_KERNEL);
+       dev->rtsx_resv_buf = dmam_alloc_coherent(&pci->dev, RTSX_RESV_BUF_LEN,
+                       &dev->rtsx_resv_buf_addr, GFP_KERNEL);
        if (dev->rtsx_resv_buf == NULL) {
                dev_err(&pci->dev, "alloc dma buffer fail\n");
                err = -ENXIO;
index 0df3b9d97134c59e61cd939bc5d26771872e713f..c0ce659a5aa6716c937bd2e17688e27c33c41293 100644 (file)
@@ -521,13 +521,14 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
                }
        }
 
-       /* Disable cd_pwr_save (u_force_rst_core_en=0, u_cd_rst_core_en=0)
-             0xFE5B
-             bit[1]    u_cd_rst_core_en        rst_value = 0
-             bit[2]    u_force_rst_core_en     rst_value = 0
-             bit[5]    u_mac_phy_rst_n_dbg     rst_value = 1
-             bit[4]    u_non_sticky_rst_n_dbg  rst_value = 0
-       */
+       /*
+        * Disable cd_pwr_save (u_force_rst_core_en=0, u_cd_rst_core_en=0)
+        *    0xFE5B
+        *    bit[1]    u_cd_rst_core_en        rst_value = 0
+        *    bit[2]    u_force_rst_core_en     rst_value = 0
+        *    bit[5]    u_mac_phy_rst_n_dbg     rst_value = 1
+        *    bit[4]    u_non_sticky_rst_n_dbg  rst_value = 0
+        */
        retval = rtsx_write_register(chip, CHANGE_LINK_STATE, 0x16, 0x10);
        if (retval) {
                rtsx_trace(chip);
@@ -2153,12 +2154,13 @@ int rtsx_pre_handle_interrupt(struct rtsx_chip *chip)
                                clear_bit(SD_NR, &chip->need_reset);
                        }
                } else {
-                       /* If multi-luns, it's possible that
-                          when plugging/unplugging one card
-                          there is another card which still
-                          exists in the slot. In this case,
-                          all existed cards should be reset.
-                       */
+                       /*
+                        * If multi-luns, it's possible that
+                        * when plugging/unplugging one card
+                        * there is another card which still
+                        * exists in the slot. In this case,
+                        * all existed cards should be reset.
+                        */
                        if (exit_ss && (status & SD_EXIST))
                                set_bit(SD_NR, &chip->need_reinit);
                }
index 5bfce076f7c88b1f42eea8306b1417823b1520fc..36f849fbba5ee5cb0c186dd6984e79d9ac866aae 100644 (file)
@@ -1,28 +1,27 @@
 /*
-Copyright (c) 2010 Werner Dittmann
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-*/
+ * Copyright (c) 2010 Werner Dittmann
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
 
 #include <linux/string.h>
 #include "skein_api.h"
@@ -51,7 +50,7 @@ int skein_init(struct skein_ctx *ctx, size_t hash_bit_len)
         * memory available.  The beauty of C :-) .
         */
        x = ctx->m.s256.x;
-       x_len = ctx->skein_size/8;
+       x_len = ctx->skein_size / 8;
        /*
         * If size is the same and hash bit length is zero then reuse
         * the save chaining variables.
@@ -92,7 +91,7 @@ int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len,
        skein_assert_ret(ctx, SKEIN_FAIL);
 
        x = ctx->m.s256.x;
-       x_len = ctx->skein_size/8;
+       x_len = ctx->skein_size / 8;
 
        skein_assert_ret(hash_bit_len, SKEIN_BAD_HASHLEN);
 
@@ -128,7 +127,7 @@ int skein_mac_init(struct skein_ctx *ctx, const u8 *key, size_t key_len,
 void skein_reset(struct skein_ctx *ctx)
 {
        size_t x_len = 0;
-       u64 *x = NULL;
+       u64 *x;
 
        /*
         * The following two lines rely of the fact that the real Skein
@@ -136,7 +135,7 @@ void skein_reset(struct skein_ctx *ctx)
         * memory available.  The beautiy of C :-) .
         */
        x = ctx->m.s256.x;
-       x_len = ctx->skein_size/8;
+       x_len = ctx->skein_size / 8;
        /* Restore the chaing variable, reset byte counter */
        memcpy(x, ctx->x_save, x_len);
 
@@ -213,7 +212,7 @@ int skein_update_bits(struct skein_ctx *ctx, const u8 *msg,
        /* partial byte bit mask */
        mask = (u8) (1u << (7 - (msg_bit_cnt & 7)));
        /* apply bit padding on final byte (in the buffer) */
-       up[length-1]  = (u8)((up[length-1] & (0-mask))|mask);
+       up[length - 1]  = (u8)((up[length - 1] & (0 - mask)) | mask);
 
        return SKEIN_SUCCESS;
 }
index 7da8b386a28c4ee0b345f63040644559373b3114..5df7905825da5dcae87fc331dd2cc454a3e0395f 100644 (file)
@@ -1,28 +1,28 @@
-/*
-Copyright (c) 2010 Werner Dittmann
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
+/**
+ * Copyright (c) 2010 Werner Dittmann
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
 
-*/
+ */
 
 #ifndef SKEINAPI_H
 #define SKEINAPI_H
index 7e700a6b5788a99d904ac2bf73083b4411c86f60..25a01ca76953bd40d61275d1974a120ff7bbfaf8 100644 (file)
@@ -75,8 +75,10 @@ int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len)
 
 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
 /* init the context for a MAC and/or tree hash operation */
-/* [identical to skein_256_init() when key_bytes == 0 && \
- *     tree_info == SKEIN_CFG_TREE_INFO_SEQUENTIAL] */
+/*
+ * [identical to skein_256_init() when key_bytes == 0 && \
+ *     tree_info == SKEIN_CFG_TREE_INFO_SEQUENTIAL]
+ */
 int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len,
                       u64 tree_info, const u8 *key, size_t key_bytes)
 {
@@ -86,7 +88,7 @@ int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len,
        } cfg; /* config block */
 
        skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN);
-       skein_assert_ret(key_bytes == 0 || key != NULL, SKEIN_FAIL);
+       skein_assert_ret(key_bytes == 0 || key, SKEIN_FAIL);
 
        /* compute the initial chaining values ctx->x[], based on key */
        if (key_bytes == 0) { /* is there a key? */
@@ -301,8 +303,10 @@ int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len)
 
 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
 /* init the context for a MAC and/or tree hash operation */
-/* [identical to skein_512_init() when key_bytes == 0 && \
- *     tree_info == SKEIN_CFG_TREE_INFO_SEQUENTIAL] */
+/*
+ * [identical to skein_512_init() when key_bytes == 0 && \
+ *     tree_info == SKEIN_CFG_TREE_INFO_SEQUENTIAL]
+ */
 int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len,
                       u64 tree_info, const u8 *key, size_t key_bytes)
 {
@@ -312,7 +316,7 @@ int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len,
        } cfg;                              /* config block */
 
        skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN);
-       skein_assert_ret(key_bytes == 0 || key != NULL, SKEIN_FAIL);
+       skein_assert_ret(key_bytes == 0 || key, SKEIN_FAIL);
 
        /* compute the initial chaining values ctx->x[], based on key */
        if (key_bytes == 0) { /* is there a key? */
@@ -520,8 +524,10 @@ int skein_1024_init(struct skein_1024_ctx *ctx, size_t hash_bit_len)
 
 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
 /* init the context for a MAC and/or tree hash operation */
-/* [identical to skein_1024_init() when key_bytes == 0 && \
- *     tree_info == SKEIN_CFG_TREE_INFO_SEQUENTIAL] */
+/*
+ * [identical to skein_1024_init() when key_bytes == 0 && \
+ *     tree_info == SKEIN_CFG_TREE_INFO_SEQUENTIAL]
+ */
 int skein_1024_init_ext(struct skein_1024_ctx *ctx, size_t hash_bit_len,
                        u64 tree_info, const u8 *key, size_t key_bytes)
 {
@@ -531,7 +537,7 @@ int skein_1024_init_ext(struct skein_1024_ctx *ctx, size_t hash_bit_len,
        } cfg;                              /* config block */
 
        skein_assert_ret(hash_bit_len > 0, SKEIN_BAD_HASHLEN);
-       skein_assert_ret(key_bytes == 0 || key != NULL, SKEIN_FAIL);
+       skein_assert_ret(key_bytes == 0 || key, SKEIN_FAIL);
 
        /* compute the initial chaining values ctx->x[], based on key */
        if (key_bytes == 0) { /* is there a key? */
index b0cd9357348fcc8a53e5ac8da5792867ab66f356..45b47327e02444c94f56c3c385e54b031bd04418 100644 (file)
 #error "Invalid SKEIN_UNROLL_256" /* sanity check on unroll count */
 #endif
 #endif
-#define ROUND256(p0, p1, p2, p3, ROT, r_num) \
-do {                                         \
-       X##p0 += X##p1;                      \
-       X##p1 = rotl_64(X##p1, ROT##_0);     \
-       X##p1 ^= X##p0;                      \
-       X##p2 += X##p3;                      \
-       X##p3 = rotl_64(X##p3, ROT##_1);     \
-       X##p3 ^= X##p2;                      \
-} while (0)
+#define ROUND256(p0, p1, p2, p3, ROT, r_num)         \
+       do {                                         \
+               X##p0 += X##p1;                      \
+               X##p1 = rotl_64(X##p1, ROT##_0);     \
+               X##p1 ^= X##p0;                      \
+               X##p2 += X##p3;                      \
+               X##p3 = rotl_64(X##p3, ROT##_1);     \
+               X##p3 ^= X##p2;                      \
+       } while (0)
 
 #if SKEIN_UNROLL_256 == 0
 #define R256(p0, p1, p2, p3, ROT, r_num) /* fully unrolled */ \
        ROUND256(p0, p1, p2, p3, ROT, r_num)
 
-#define I256(R)                                                           \
-do {                                                                      \
-       /* inject the key schedule value */                               \
-       X0   += ks[((R) + 1) % 5];                                        \
-       X1   += ks[((R) + 2) % 5] + ts[((R) + 1) % 3];                    \
-       X2   += ks[((R) + 3) % 5] + ts[((R) + 2) % 3];                    \
-       X3   += ks[((R) + 4) % 5] + (R) + 1;                              \
-} while (0)
+#define I256(R)                                                         \
+       do {                                                            \
+               /* inject the key schedule value */                     \
+               X0   += ks[((R) + 1) % 5];                              \
+               X1   += ks[((R) + 2) % 5] + ts[((R) + 1) % 3];          \
+               X2   += ks[((R) + 3) % 5] + ts[((R) + 2) % 3];          \
+               X3   += ks[((R) + 4) % 5] + (R) + 1;                    \
+       } while (0)
 #else
 /* looping version */
 #define R256(p0, p1, p2, p3, ROT, r_num) ROUND256(p0, p1, p2, p3, ROT, r_num)
 
-#define I256(R) \
-do { \
-       /* inject the key schedule value */ \
-       X0 += ks[r + (R) + 0]; \
-       X1 += ks[r + (R) + 1] + ts[r + (R) + 0];                          \
-       X2 += ks[r + (R) + 2] + ts[r + (R) + 1];                          \
-       X3 += ks[r + (R) + 3] + r + (R);                                  \
-       /* rotate key schedule */                                         \
-       ks[r + (R) + 4] = ks[r + (R) - 1];                                \
-       ts[r + (R) + 2] = ts[r + (R) - 1];                                \
-} while (0)
-#endif
-#define R256_8_ROUNDS(R)                                 \
-do {                                                     \
-               R256(0, 1, 2, 3, R_256_0, 8 * (R) + 1);  \
-               R256(0, 3, 2, 1, R_256_1, 8 * (R) + 2);  \
-               R256(0, 1, 2, 3, R_256_2, 8 * (R) + 3);  \
-               R256(0, 3, 2, 1, R_256_3, 8 * (R) + 4);  \
-               I256(2 * (R));                           \
-               R256(0, 1, 2, 3, R_256_4, 8 * (R) + 5);  \
-               R256(0, 3, 2, 1, R_256_5, 8 * (R) + 6);  \
-               R256(0, 1, 2, 3, R_256_6, 8 * (R) + 7);  \
-               R256(0, 3, 2, 1, R_256_7, 8 * (R) + 8);  \
-               I256(2 * (R) + 1);                       \
-} while (0)
+#define I256(R)                                         \
+       do {                                            \
+               /* inject the key schedule value */     \
+               X0 += ks[r + (R) + 0];                  \
+               X1 += ks[r + (R) + 1] + ts[r + (R) + 0];\
+               X2 += ks[r + (R) + 2] + ts[r + (R) + 1];\
+               X3 += ks[r + (R) + 3] + r + (R);        \
+               /* rotate key schedule */               \
+               ks[r + (R) + 4] = ks[r + (R) - 1];      \
+               ts[r + (R) + 2] = ts[r + (R) - 1];      \
+       } while (0)
+#endif
+#define R256_8_ROUNDS(R)                                \
+       do {                                            \
+               R256(0, 1, 2, 3, R_256_0, 8 * (R) + 1); \
+               R256(0, 3, 2, 1, R_256_1, 8 * (R) + 2); \
+               R256(0, 1, 2, 3, R_256_2, 8 * (R) + 3); \
+               R256(0, 3, 2, 1, R_256_3, 8 * (R) + 4); \
+               I256(2 * (R));                          \
+               R256(0, 1, 2, 3, R_256_4, 8 * (R) + 5); \
+               R256(0, 3, 2, 1, R_256_5, 8 * (R) + 6); \
+               R256(0, 1, 2, 3, R_256_6, 8 * (R) + 7); \
+               R256(0, 3, 2, 1, R_256_7, 8 * (R) + 8); \
+               I256(2 * (R) + 1);                      \
+       } while (0)
 
 #define R256_UNROLL_R(NN)                     \
        ((SKEIN_UNROLL_256 == 0 &&            \
@@ -133,71 +133,71 @@ do {                                                     \
 #error "Invalid SKEIN_UNROLL_512" /* sanity check on unroll count */
 #endif
 #endif
-#define ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) \
-do {                                                         \
-       X##p0 += X##p1;                                      \
-       X##p1 = rotl_64(X##p1, ROT##_0);                     \
-       X##p1 ^= X##p0;                                      \
-       X##p2 += X##p3;                                      \
-       X##p3 = rotl_64(X##p3, ROT##_1);                     \
-       X##p3 ^= X##p2;                                      \
-       X##p4 += X##p5;                                      \
-       X##p5 = rotl_64(X##p5, ROT##_2);                     \
-       X##p5 ^= X##p4;                                      \
-       X##p6 += X##p7; X##p7 = rotl_64(X##p7, ROT##_3);     \
-       X##p7 ^= X##p6;                                      \
-} while (0)
+#define ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num)    \
+       do {                                                    \
+               X##p0 += X##p1;                                 \
+               X##p1 = rotl_64(X##p1, ROT##_0);                \
+               X##p1 ^= X##p0;                                 \
+               X##p2 += X##p3;                                 \
+               X##p3 = rotl_64(X##p3, ROT##_1);                \
+               X##p3 ^= X##p2;                                 \
+               X##p4 += X##p5;                                 \
+               X##p5 = rotl_64(X##p5, ROT##_2);                \
+               X##p5 ^= X##p4;                                 \
+               X##p6 += X##p7; X##p7 = rotl_64(X##p7, ROT##_3);\
+               X##p7 ^= X##p6;                                 \
+       } while (0)
 
 #if SKEIN_UNROLL_512 == 0
 #define R512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) /* unrolled */ \
        ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num)
 
-#define I512(R)                                                           \
-do {                                                                      \
-       /* inject the key schedule value */                               \
-       X0   += ks[((R) + 1) % 9];                                        \
-       X1   += ks[((R) + 2) % 9];                                        \
-       X2   += ks[((R) + 3) % 9];                                        \
-       X3   += ks[((R) + 4) % 9];                                        \
-       X4   += ks[((R) + 5) % 9];                                        \
-       X5   += ks[((R) + 6) % 9] + ts[((R) + 1) % 3];                    \
-       X6   += ks[((R) + 7) % 9] + ts[((R) + 2) % 3];                    \
-       X7   += ks[((R) + 8) % 9] + (R) + 1;                              \
-} while (0)
+#define I512(R)                                                         \
+       do {                                                            \
+               /* inject the key schedule value */                     \
+               X0   += ks[((R) + 1) % 9];                              \
+               X1   += ks[((R) + 2) % 9];                              \
+               X2   += ks[((R) + 3) % 9];                              \
+               X3   += ks[((R) + 4) % 9];                              \
+               X4   += ks[((R) + 5) % 9];                              \
+               X5   += ks[((R) + 6) % 9] + ts[((R) + 1) % 3];          \
+               X6   += ks[((R) + 7) % 9] + ts[((R) + 2) % 3];          \
+               X7   += ks[((R) + 8) % 9] + (R) + 1;                    \
+       } while (0)
 
 #else /* looping version */
 #define R512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num)                 \
        ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num)             \
 
-#define I512(R)                                                           \
-do {                                                                      \
-       /* inject the key schedule value */                               \
-       X0   += ks[r + (R) + 0];                                          \
-       X1   += ks[r + (R) + 1];                                          \
-       X2   += ks[r + (R) + 2];                                          \
-       X3   += ks[r + (R) + 3];                                          \
-       X4   += ks[r + (R) + 4];                                          \
-       X5   += ks[r + (R) + 5] + ts[r + (R) + 0];                        \
-       X6   += ks[r + (R) + 6] + ts[r + (R) + 1];                        \
-       X7   += ks[r + (R) + 7] + r + (R);                                \
-       /* rotate key schedule */                                         \
-       ks[r + (R) + 8] = ks[r + (R) - 1];                                \
-       ts[r + (R) + 2] = ts[r + (R) - 1];                                \
-} while (0)
+#define I512(R)                                                         \
+       do {                                                            \
+               /* inject the key schedule value */                     \
+               X0   += ks[r + (R) + 0];                                \
+               X1   += ks[r + (R) + 1];                                \
+               X2   += ks[r + (R) + 2];                                \
+               X3   += ks[r + (R) + 3];                                \
+               X4   += ks[r + (R) + 4];                                \
+               X5   += ks[r + (R) + 5] + ts[r + (R) + 0];              \
+               X6   += ks[r + (R) + 6] + ts[r + (R) + 1];              \
+               X7   += ks[r + (R) + 7] + r + (R);                      \
+               /* rotate key schedule */                               \
+               ks[r + (R) + 8] = ks[r + (R) - 1];                      \
+               ts[r + (R) + 2] = ts[r + (R) - 1];                      \
+       } while (0)
 #endif /* end of looped code definitions */
-#define R512_8_ROUNDS(R)  /* do 8 full rounds */                      \
-do {                                                                  \
-               R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_0, 8 * (R) + 1);   \
-               R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_1, 8 * (R) + 2);   \
-               R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_2, 8 * (R) + 3);   \
-               R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_3, 8 * (R) + 4);   \
-               I512(2 * (R));                              \
-               R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_4, 8 * (R) + 5);   \
-               R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_5, 8 * (R) + 6);   \
-               R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_6, 8 * (R) + 7);   \
-               R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_7, 8 * (R) + 8);   \
-               I512(2 * (R) + 1);        /* and key injection */     \
-} while (0)
+#define R512_8_ROUNDS(R)  /* do 8 full rounds */                        \
+       do {                                                            \
+               R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_0, 8 * (R) + 1);     \
+               R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_1, 8 * (R) + 2);     \
+               R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_2, 8 * (R) + 3);     \
+               R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_3, 8 * (R) + 4);     \
+               I512(2 * (R));                                          \
+               R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_4, 8 * (R) + 5);     \
+               R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_5, 8 * (R) + 6);     \
+               R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_6, 8 * (R) + 7);     \
+               R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_7, 8 * (R) + 8);     \
+               I512(2 * (R) + 1); /* and key injection */              \
+       } while (0)
 #define R512_UNROLL_R(NN)                             \
                ((SKEIN_UNROLL_512 == 0 &&            \
                SKEIN_512_ROUNDS_TOTAL/8 > (NN)) ||   \
@@ -212,7 +212,7 @@ do {                                                                  \
 #undef  RCNT
 #define RCNT  (SKEIN_1024_ROUNDS_TOTAL/8)
 #ifdef SKEIN_LOOP /* configure how much to unroll the loop */
-#define SKEIN_UNROLL_1024 ((SKEIN_LOOP)%10)
+#define SKEIN_UNROLL_1024 ((SKEIN_LOOP) % 10)
 #else
 #define SKEIN_UNROLL_1024 (0)
 #endif
@@ -224,32 +224,32 @@ do {                                                                  \
 #endif
 #define ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
                  pF, ROT, r_num)                                             \
-do {                                                                          \
-       X##p0 += X##p1;                                                       \
-       X##p1 = rotl_64(X##p1, ROT##_0);                                      \
-       X##p1 ^= X##p0;                                                       \
-       X##p2 += X##p3;                                                       \
-       X##p3 = rotl_64(X##p3, ROT##_1);                                      \
-       X##p3 ^= X##p2;                                                       \
-       X##p4 += X##p5;                                                       \
-       X##p5 = rotl_64(X##p5, ROT##_2);                                      \
-       X##p5 ^= X##p4;                                                       \
-       X##p6 += X##p7;                                                       \
-       X##p7 = rotl_64(X##p7, ROT##_3);                                      \
-       X##p7 ^= X##p6;                                                       \
-       X##p8 += X##p9;                                                       \
-       X##p9 = rotl_64(X##p9, ROT##_4);                                      \
-       X##p9 ^= X##p8;                                                       \
-       X##pA += X##pB;                                                       \
-       X##pB = rotl_64(X##pB, ROT##_5);                                      \
-       X##pB ^= X##pA;                                                       \
-       X##pC += X##pD;                                                       \
-       X##pD = rotl_64(X##pD, ROT##_6);                                      \
-       X##pD ^= X##pC;                                                       \
-       X##pE += X##pF;                                                       \
-       X##pF = rotl_64(X##pF, ROT##_7);                                      \
-       X##pF ^= X##pE;                                                       \
-} while (0)
+       do {                                                                  \
+               X##p0 += X##p1;                                               \
+               X##p1 = rotl_64(X##p1, ROT##_0);                              \
+               X##p1 ^= X##p0;                                               \
+               X##p2 += X##p3;                                               \
+               X##p3 = rotl_64(X##p3, ROT##_1);                              \
+               X##p3 ^= X##p2;                                               \
+               X##p4 += X##p5;                                               \
+               X##p5 = rotl_64(X##p5, ROT##_2);                              \
+               X##p5 ^= X##p4;                                               \
+               X##p6 += X##p7;                                               \
+               X##p7 = rotl_64(X##p7, ROT##_3);                              \
+               X##p7 ^= X##p6;                                               \
+               X##p8 += X##p9;                                               \
+               X##p9 = rotl_64(X##p9, ROT##_4);                              \
+               X##p9 ^= X##p8;                                               \
+               X##pA += X##pB;                                               \
+               X##pB = rotl_64(X##pB, ROT##_5);                              \
+               X##pB ^= X##pA;                                               \
+               X##pC += X##pD;                                               \
+               X##pD = rotl_64(X##pD, ROT##_6);                              \
+               X##pD ^= X##pC;                                               \
+               X##pE += X##pF;                                               \
+               X##pF = rotl_64(X##pF, ROT##_7);                              \
+               X##pF ^= X##pE;                                               \
+       } while (0)
 
 #if SKEIN_UNROLL_1024 == 0
 #define R1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, pF, \
@@ -257,82 +257,82 @@ do {                                                                          \
        ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
                  pF, ROT, rn)                                                \
 
-#define I1024(R)                                                          \
-do {                                                                      \
-       /* inject the key schedule value */                               \
-       X00 += ks[((R) + 1) % 17];                                        \
-       X01 += ks[((R) + 2) % 17];                                        \
-       X02 += ks[((R) + 3) % 17];                                        \
-       X03 += ks[((R) + 4) % 17];                                        \
-       X04 += ks[((R) + 5) % 17];                                        \
-       X05 += ks[((R) + 6) % 17];                                        \
-       X06 += ks[((R) + 7) % 17];                                        \
-       X07 += ks[((R) + 8) % 17];                                        \
-       X08 += ks[((R) + 9) % 17];                                        \
-       X09 += ks[((R) + 10) % 17];                                       \
-       X10 += ks[((R) + 11) % 17];                                       \
-       X11 += ks[((R) + 12) % 17];                                       \
-       X12 += ks[((R) + 13) % 17];                                       \
-       X13 += ks[((R) + 14) % 17] + ts[((R) + 1) % 3];                   \
-       X14 += ks[((R) + 15) % 17] + ts[((R) + 2) % 3];                   \
-       X15 += ks[((R) + 16) % 17] + (R) + 1;                             \
-} while (0)
+#define I1024(R)                                                \
+       do {                                                    \
+               /* inject the key schedule value */             \
+               X00 += ks[((R) + 1) % 17];                      \
+               X01 += ks[((R) + 2) % 17];                      \
+               X02 += ks[((R) + 3) % 17];                      \
+               X03 += ks[((R) + 4) % 17];                      \
+               X04 += ks[((R) + 5) % 17];                      \
+               X05 += ks[((R) + 6) % 17];                      \
+               X06 += ks[((R) + 7) % 17];                      \
+               X07 += ks[((R) + 8) % 17];                      \
+               X08 += ks[((R) + 9) % 17];                      \
+               X09 += ks[((R) + 10) % 17];                     \
+               X10 += ks[((R) + 11) % 17];                     \
+               X11 += ks[((R) + 12) % 17];                     \
+               X12 += ks[((R) + 13) % 17];                     \
+               X13 += ks[((R) + 14) % 17] + ts[((R) + 1) % 3]; \
+               X14 += ks[((R) + 15) % 17] + ts[((R) + 2) % 3]; \
+               X15 += ks[((R) + 16) % 17] + (R) + 1;           \
+       } while (0)
 #else /* looping version */
 #define R1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, pF, \
              ROT, rn)                                                        \
        ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
                  pF, ROT, rn)                                                \
 
-#define I1024(R)                                                           \
-do {                                                                       \
-       /* inject the key schedule value */                                \
-       X00 += ks[r + (R) + 0];                                            \
-       X01 += ks[r + (R) + 1];                                            \
-       X02 += ks[r + (R) + 2];                                            \
-       X03 += ks[r + (R) + 3];                                            \
-       X04 += ks[r + (R) + 4];                                            \
-       X05 += ks[r + (R) + 5];                                            \
-       X06 += ks[r + (R) + 6];                                            \
-       X07 += ks[r + (R) + 7];                                            \
-       X08 += ks[r + (R) + 8];                                            \
-       X09 += ks[r + (R) + 9];                                            \
-       X10 += ks[r + (R) + 10];                                           \
-       X11 += ks[r + (R) + 11];                                           \
-       X12 += ks[r + (R) + 12];                                           \
-       X13 += ks[r + (R) + 13] + ts[r + (R) + 0];                         \
-       X14 += ks[r + (R) + 14] + ts[r + (R) + 1];                         \
-       X15 += ks[r + (R) + 15] + r + (R);                                 \
-       /* rotate key schedule */                                          \
-       ks[r + (R) + 16] = ks[r + (R) - 1];                                \
-       ts[r + (R) + 2] = ts[r + (R) - 1];                                 \
-} while (0)
-
-#endif
-#define R1024_8_ROUNDS(R)                                                     \
-do {                                                                          \
-       R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, \
-             R1024_0, 8*(R) + 1);                                            \
-       R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, 05, 08, 01, \
-             R1024_1, 8*(R) + 2);                                            \
-       R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, 11, 10, 09, \
-             R1024_2, 8*(R) + 3);                                            \
-       R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, 03, 12, 07, \
-             R1024_3, 8*(R) + 4);                                            \
-       I1024(2*(R));                                                         \
-       R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, \
-             R1024_4, 8*(R) + 5);                                            \
-       R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, 05, 08, 01, \
-             R1024_5, 8*(R) + 6);                                            \
-       R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, 11, 10, 09, \
-             R1024_6, 8*(R) + 7);                                            \
-       R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, 03, 12, 07, \
-             R1024_7, 8*(R) + 8);                                            \
-       I1024(2*(R)+1);                                                       \
-} while (0)
+#define I1024(R)                                                        \
+       do {                                                            \
+               /* inject the key schedule value */                     \
+               X00 += ks[r + (R) + 0];                                 \
+               X01 += ks[r + (R) + 1];                                 \
+               X02 += ks[r + (R) + 2];                                 \
+               X03 += ks[r + (R) + 3];                                 \
+               X04 += ks[r + (R) + 4];                                 \
+               X05 += ks[r + (R) + 5];                                 \
+               X06 += ks[r + (R) + 6];                                 \
+               X07 += ks[r + (R) + 7];                                 \
+               X08 += ks[r + (R) + 8];                                 \
+               X09 += ks[r + (R) + 9];                                 \
+               X10 += ks[r + (R) + 10];                                \
+               X11 += ks[r + (R) + 11];                                \
+               X12 += ks[r + (R) + 12];                                \
+               X13 += ks[r + (R) + 13] + ts[r + (R) + 0];              \
+               X14 += ks[r + (R) + 14] + ts[r + (R) + 1];              \
+               X15 += ks[r + (R) + 15] + r + (R);                      \
+               /* rotate key schedule */                               \
+               ks[r + (R) + 16] = ks[r + (R) - 1];                     \
+               ts[r + (R) + 2] = ts[r + (R) - 1];                      \
+       } while (0)
+
+#endif
+#define R1024_8_ROUNDS(R)                                                 \
+       do {                                                              \
+               R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, \
+                     13, 14, 15, R1024_0, 8*(R) + 1);                    \
+               R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, \
+                     05, 08, 01, R1024_1, 8*(R) + 2);                    \
+               R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, \
+                     11, 10, 09, R1024_2, 8*(R) + 3);                    \
+               R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, \
+                     03, 12, 07, R1024_3, 8*(R) + 4);                    \
+               I1024(2*(R));                                             \
+               R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, \
+                     13, 14, 15, R1024_4, 8*(R) + 5);                    \
+               R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, \
+                     05, 08, 01, R1024_5, 8*(R) + 6);                    \
+               R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, \
+                     11, 10, 09, R1024_6, 8*(R) + 7);                    \
+               R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, \
+                     03, 12, 07, R1024_7, 8*(R) + 8);                    \
+               I1024(2*(R)+1);                                           \
+       } while (0)
 
 #define R1024_UNROLL_R(NN)                              \
                ((SKEIN_UNROLL_1024 == 0 &&             \
-               SKEIN_1024_ROUNDS_TOTAL/8 > (NN)) ||  \
+               SKEIN_1024_ROUNDS_TOTAL/8 > (NN)) ||    \
                (SKEIN_UNROLL_1024 > (NN)))
 
 #if  (SKEIN_UNROLL_1024 > 14)
index 899078f1b8bcf244aed0a091e6cc2b9ade0f4b23..e29b9abaa4e635a9a608c1a7d65b519ce810de30 100644 (file)
 #include <crypto/internal/hash.h>
 #include "skein_base.h"
 
-
 static int skein256_init(struct shash_desc *desc)
 {
-       return skein_256_init((struct skein_256_ctx *) shash_desc_ctx(desc),
+       return skein_256_init((struct skein_256_ctx *)shash_desc_ctx(desc),
                        SKEIN256_DIGEST_BIT_SIZE);
 }
 
index 00b8af63e7fff45abcd5a6f872646616c1017524..c95b3abad6468de68e46a2a585556741bb4c8c16 100644 (file)
@@ -93,10 +93,10 @@ struct slic_rcvbuf_info {
        u32     lastid;
 };
 /*
- SLIC Handle structure.  Used to restrict handle values to
- 32 bits by using an index rather than an address.
- Simplifies ucode in 64-bit systems
-*/
SLIC Handle structure.  Used to restrict handle values to
32 bits by using an index rather than an address.
Simplifies ucode in 64-bit systems
+ */
 struct slic_handle_word {
        union {
                struct {
@@ -166,7 +166,6 @@ struct slic_cmdqueue {
 #define SLIC_MAX_CARDS              32
 #define SLIC_MAX_PORTS              4        /* Max # of ports per card   */
 
-
 struct mcast_address {
        unsigned char address[6];
        struct mcast_address *next;
@@ -334,10 +333,11 @@ struct physcard {
        struct physcard *next;
        uint                adapters_allocd;
 
-/*  the following is not currently needed
-       u32              bridge_busnum;
-       u32              bridge_cfg[NUM_CFG_SPACES][NUM_CFG_REG_ULONGS];
-*/
+/*
+ * the following is not currently needed
+ *     u32              bridge_busnum;
+ *     u32              bridge_cfg[NUM_CFG_SPACES][NUM_CFG_REG_ULONGS];
+ */
 };
 
 struct base_driver {
@@ -447,7 +447,7 @@ struct adapter {
        *  SLIC Handles
        */
        /* Object handles*/
-       struct slic_handle slic_handles[SLIC_CMDQ_MAXCMDS+1];
+       struct slic_handle slic_handles[SLIC_CMDQ_MAXCMDS + 1];
        /* Free object handles*/
        struct slic_handle *pfree_slic_handles;
        /* Object handle list lock*/
@@ -485,7 +485,6 @@ struct adapter {
        struct slicnet_stats     slic_stats;
 };
 
-
 #define UPDATE_STATS(largestat, newstat, oldstat)                        \
 {                                                                        \
        if ((newstat) < (oldstat))                                       \
@@ -514,6 +513,6 @@ struct adapter {
 #define FLUSH          true
 #define DONT_FLUSH     false
 
-#define SIOCSLICSETINTAGG        (SIOCDEVPRIVATE+10)
+#define SIOCSLICSETINTAGG        (SIOCDEVPRIVATE + 10)
 
 #endif /*  __SLIC_DRIVER_H__ */
index 21cd02b8b7ebcadc81e5e6fcffb71672255bb3a9..9723b4a104f79733ed055a07e45839019bc5dd26 100644 (file)
@@ -307,9 +307,11 @@ struct slic_regs {
 
        u32     slic_hbar;      /* Header buffer address reg */
        u32     pad4;
-       /* 31-8 - phy addr of set of contiguous hdr buffers
-           7-0 - number of buffers passed
-          Buffers are 256 bytes long on 256-byte boundaries. */
+       /*
+        * 31-8 - phy addr of set of contiguous hdr buffers
+        *  7-0 - number of buffers passed
+        * Buffers are 256 bytes long on 256-byte boundaries.
+        */
 #define SLIC_HBAR              0x0020
 #define SLIC_HBAR_CNT_MSK      0x000000FF
 
@@ -321,10 +323,12 @@ struct slic_regs {
 #define SLIC_DBAR_SIZE         2048
 
        u32     slic_cbar;      /* Xmt Cmd buf addr regs.*/
-       /* 1 per XMT interface
-          31-5 - phy addr of host command buffer
-           4-0 - length of cmd in multiples of 32 bytes
-          Buffers are 32 bytes up to 512 bytes long */
+       /*
+        * 1 per XMT interface
+        * 31-5 - phy addr of host command buffer
+        *  4-0 - length of cmd in multiples of 32 bytes
+        * Buffers are 32 bytes up to 512 bytes long
+        */
 #define SLIC_CBAR              0x0030
 #define SLIC_CBAR_LEN_MSK      0x0000001F
 #define SLIC_CBAR_ALIGN                0x00000020
@@ -336,9 +340,11 @@ struct slic_regs {
 
        u32     slic_rbar;      /* Response buffer address reg.*/
        u32     pad7;
-        /*31-8 - phy addr of set of contiguous response buffers
-         7-0 - number of buffers passed
-        Buffers are 32 bytes long on 32-byte boundaries.*/
+       /*
+        * 31-8 - phy addr of set of contiguous response buffers
+        * 7-0 - number of buffers passed
+        * Buffers are 32 bytes long on 32-byte boundaries.
+        */
 #define SLIC_RBAR              0x0038
 #define SLIC_RBAR_CNT_MSK      0x000000FF
 #define SLIC_RBAR_SIZE         32
@@ -430,7 +436,8 @@ struct slic_regs {
 #define SLIC_LOW_POWER 0x00e0
 
        u32     slic_quiesce;   /* force slic into quiescent state
-                                  before soft reset */
+                                * before soft reset
+                                */
        u32     pad30;
 #define SLIC_QUIESCE   0x00e8
 
@@ -718,7 +725,8 @@ struct slic_eeprom {
        u16 DSize2Pci;          /* 15 DRAM size to PCI (bytes * 64K) */
        u16 RSize2Pci;          /* 16 ROM extension size to PCI (bytes * 4k) */
        u8 NetIntPin1;          /* 17 Network Interface Pin 1
-                                   (simba/leone only) */
+                                *  (simba/leone only)
+                                */
        u8 NetIntPin2;          /* Network Interface Pin 2 (simba/leone only)*/
        union {
                u8 NetIntPin3;  /* 18 Network Interface Pin 3 (simba only) */
@@ -748,7 +756,8 @@ struct slic_eeprom {
        union oemfru OemFru;    /* optional OEM FRU information */
        u8      Pad[4];         /* Pad to 128 bytes - includes 2 cksum bytes
                                 * (if OEM FRU info exists) and two unusable
-                                * bytes at the end */
+                                * bytes at the end
+                                */
 };
 
 /* SLIC EEPROM structure for Oasis */
@@ -772,7 +781,8 @@ struct oslic_eeprom {
        u16 FlashSize;          /* 14 Flash size (bytes / 4K) */
        u16 DSize2Pci;          /* 15 DRAM size to PCI (bytes / 64K) */
        u16 RSize2Pci;          /* 16 Flash (ROM extension) size to PCI
-                                       (bytes / 4K) */
+                                *      (bytes / 4K)
+                                */
        u16 DeviceId1;          /* 17 Device Id (function 1) */
        u16 DeviceId2;          /* 18 Device Id (function 2) */
        u16 CfgByte6;           /* 19 Device Status Config Bytes 6-7 */
index 858597087ba7d0bf809984dfb0dca9a0a2d9a811..b23a2d1f61a23f7e4a6abb7fca26c2f0c18c9830 100644 (file)
@@ -54,7 +54,6 @@
  *       IS-NIC driver.
  */
 
-
 #define KLUDGE_FOR_4GB_BOUNDARY         1
 #define DEBUG_MICROCODE                 1
 #define DBG                             1
@@ -159,17 +158,20 @@ static void slic_mcast_set_bit(struct adapter *adapter, char *address)
        unsigned char crcpoly;
 
        /* Get the CRC polynomial for the mac address */
-       /* we use bits 1-8 (lsb), bitwise reversed,
-        * msb (= lsb bit 0 before bitrev) is automatically discarded */
-       crcpoly = ether_crc(ETH_ALEN, address)>>23;
+       /*
+        * we use bits 1-8 (lsb), bitwise reversed,
+        * msb (= lsb bit 0 before bitrev) is automatically discarded
+        */
+       crcpoly = ether_crc(ETH_ALEN, address) >> 23;
 
-       /* We only have space on the SLIC for 64 entries.  Lop
+       /*
+        * We only have space on the SLIC for 64 entries.  Lop
         * off the top two bits. (2^6 = 64)
         */
        crcpoly &= 0x3F;
 
        /* OR in the new bit into our 64 bit mask. */
-       adapter->mcastmask |= (u64) 1 << crcpoly;
+       adapter->mcastmask |= (u64)1 << crcpoly;
 }
 
 static void slic_mcast_set_mask(struct adapter *adapter)
@@ -177,7 +179,8 @@ static void slic_mcast_set_mask(struct adapter *adapter)
        __iomem struct slic_regs *slic_regs = adapter->slic_regs;
 
        if (adapter->macopts & (MAC_ALLMCAST | MAC_PROMISC)) {
-               /* Turn on all multicast addresses. We have to do this for
+               /*
+                * Turn on all multicast addresses. We have to do this for
                 * promiscuous mode as well as ALLMCAST mode.  It saves the
                 * Microcode from having to keep state about the MAC
                 * configuration.
@@ -186,7 +189,8 @@ static void slic_mcast_set_mask(struct adapter *adapter)
                slic_reg32_write(&slic_regs->slic_mcasthigh, 0xFFFFFFFF,
                                 FLUSH);
        } else {
-               /* Commit our multicast mast to the SLIC by writing to the
+               /*
+                * Commit our multicast mast to the SLIC by writing to the
                 * multicast address mask registers
                 */
                slic_reg32_write(&slic_regs->slic_mcastlow,
@@ -243,7 +247,8 @@ static void slic_link_config(struct adapter *adapter,
 
        if ((linkspeed == LINK_AUTOSPEED) || (linkspeed == LINK_1000MB)) {
                if (adapter->flags & ADAPT_FLAGS_FIBERMEDIA) {
-                       /*  We've got a fiber gigabit interface, and register
+                       /*
+                        * We've got a fiber gigabit interface, and register
                         *  4 is different in fiber mode than in copper mode
                         */
 
@@ -261,16 +266,22 @@ static void slic_link_config(struct adapter *adapter,
                                      PCR_AUTONEG_RST));
                                slic_reg32_write(wphy, phy_config, FLUSH);
                        } else {        /* forced 1000 Mb FD*/
-                               /* power down phy to break link
-                                  this may not work) */
+                               /*
+                                * power down phy to break link
+                                * this may not work)
+                                */
                                phy_config = (MIICR_REG_PCR | PCR_POWERDOWN);
                                slic_reg32_write(wphy, phy_config, FLUSH);
-                               /* wait, Marvell says 1 sec,
-                                  try to get away with 10 ms  */
+                               /*
+                                * wait, Marvell says 1 sec,
+                                * try to get away with 10 ms
+                                */
                                mdelay(10);
 
-                               /* disable auto-neg, set speed/duplex,
-                                  soft reset phy, powerup */
+                               /*
+                                * disable auto-neg, set speed/duplex,
+                                * soft reset phy, powerup
+                                */
                                phy_config =
                                    (MIICR_REG_PCR |
                                     (PCR_RESET | PCR_SPEED_1000 |
@@ -279,7 +290,8 @@ static void slic_link_config(struct adapter *adapter,
                        }
                } else {        /* copper gigabit */
 
-                       /* Auto-Negotiate or 1000 Mb must be auto negotiated
+                       /*
+                        * Auto-Negotiate or 1000 Mb must be auto negotiated
                         * We've got a copper gigabit interface, and
                         * register 4 is different in copper mode than
                         * in fiber mode
@@ -291,8 +303,10 @@ static void slic_link_config(struct adapter *adapter,
                                     (PAR_ADV100FD | PAR_ADV100HD | PAR_ADV10FD
                                      | PAR_ADV10HD));
                        } else {
-                       /* linkspeed == LINK_1000MB -
-                          don't advertise 10/100 Mb modes  */
+                       /*
+                        * linkspeed == LINK_1000MB -
+                        * don't advertise 10/100 Mb modes
+                        */
                                phy_advreg = MIICR_REG_4;
                        }
                        /* enable PAUSE frames  */
@@ -305,8 +319,10 @@ static void slic_link_config(struct adapter *adapter,
                        slic_reg32_write(wphy, phy_gctlreg, FLUSH);
 
                        if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
-                               /* if a Marvell PHY
-                                  enable auto crossover */
+                               /*
+                                * if a Marvell PHY
+                                * enable auto crossover
+                                */
                                phy_config =
                                    (MIICR_REG_16 | (MRV_REG16_XOVERON));
                                slic_reg32_write(wphy, phy_config, FLUSH);
@@ -337,8 +353,10 @@ static void slic_link_config(struct adapter *adapter,
                        duplex = PCR_DUPLEX_FULL;
 
                if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
-                       /* if a Marvell PHY
-                          disable auto crossover  */
+                       /*
+                        * if a Marvell PHY
+                        * disable auto crossover
+                        */
                        phy_config = (MIICR_REG_16 | (MRV_REG16_XOVEROFF));
                        slic_reg32_write(wphy, phy_config, FLUSH);
                }
@@ -351,9 +369,11 @@ static void slic_link_config(struct adapter *adapter,
                mdelay(10);
 
                if (adapter->subsysid != SLIC_1GB_CICADA_SUBSYS_ID) {
-                       /* if a Marvell PHY
-                          disable auto-neg, set speed,
-                          soft reset phy, powerup */
+                       /*
+                        * if a Marvell PHY
+                        * disable auto-neg, set speed,
+                        * soft reset phy, powerup
+                        */
                        phy_config =
                            (MIICR_REG_PCR | (PCR_RESET | speed | duplex));
                        slic_reg32_write(wphy, phy_config, FLUSH);
@@ -530,11 +550,13 @@ static int slic_card_download(struct adapter *adapter)
                        index += 4;
 
                        /* Check SRAM location zero. If it is non-zero. Abort.*/
-/*                     failure = readl((u32 __iomem *)&slic_regs->slic_reset);
-                       if (failure) {
-                               release_firmware(fw);
-                               return -EIO;
-                       }*/
+                    /*
+                     * failure = readl((u32 __iomem *)&slic_regs->slic_reset);
+                     * if (failure) {
+                     * release_firmware(fw);
+                     * return -EIO;
+                     * }
+                     */
                }
        }
        release_firmware(fw);
@@ -542,8 +564,10 @@ static int slic_card_download(struct adapter *adapter)
        mdelay(10);
        slic_reg32_write(&slic_regs->slic_wcs, SLIC_WCS_START, FLUSH);
 
-       /* stall for 20 ms, long enough for ucode to init card
-          and reach mainloop */
+       /*
+        * stall for 20 ms, long enough for ucode to init card
+        * and reach mainloop
+        */
        mdelay(20);
 
        return 0;
@@ -593,19 +617,21 @@ static void slic_mac_address_config(struct adapter *adapter)
        u32 value2;
        __iomem struct slic_regs *slic_regs = adapter->slic_regs;
 
-       value = ntohl(*(__be32 *) &adapter->currmacaddr[2]);
+       value = ntohl(*(__be32 *)&adapter->currmacaddr[2]);
        slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
        slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
 
-       value2 = (u32) ((adapter->currmacaddr[0] << 8 |
+       value2 = (u32)((adapter->currmacaddr[0] << 8 |
                             adapter->currmacaddr[1]) & 0xFFFF);
 
        slic_reg32_write(&slic_regs->slic_wraddrah, value2, FLUSH);
        slic_reg32_write(&slic_regs->slic_wraddrbh, value2, FLUSH);
 
-       /* Write our multicast mask out to the card.  This is done */
-       /* here in addition to the slic_mcast_addr_set routine     */
-       /* because ALL_MCAST may have been enabled or disabled     */
+       /*
+        * Write our multicast mask out to the card.  This is done
+        * here in addition to the slic_mcast_addr_set routine
+        * because ALL_MCAST may have been enabled or disabled
+        */
        slic_mcast_set_mask(adapter);
 }
 
@@ -886,10 +912,10 @@ static void slic_upr_start(struct adapter *adapter)
        struct slic_upr *upr;
        __iomem struct slic_regs *slic_regs = adapter->slic_regs;
 /*
   char * ptr1;
   char * ptr2;
   uint cmdoffset;
-*/
*  char * ptr1;
*  char * ptr2;
*  uint cmdoffset;
+ */
        upr = adapter->upr_list;
        if (!upr)
                return;
@@ -971,7 +997,7 @@ static void slic_link_upr_complete(struct adapter *adapter, u32 isr)
 #else
                slic_upr_queue_request(adapter,
                                       SLIC_UPR_RLSR,
-                                      (u32) &pshmem->linkstatus,
+                                      (u32)&pshmem->linkstatus,
                                       SLIC_GET_ADDR_HIGH(pshmem), 0, 0);
 #endif
                return;
@@ -1041,7 +1067,7 @@ static void slic_upr_request_complete(struct adapter *adapter, u32 isr)
        case SLIC_UPR_STATS:
                {
                        struct slic_stats *slicstats =
-                           (struct slic_stats *) &adapter->pshmem->inicstats;
+                           (struct slic_stats *)&adapter->pshmem->inicstats;
                        struct slic_stats *newstats = slicstats;
                        struct slic_stats  *old = &adapter->inicstats_prev;
                        struct slicnet_stats *stst = &adapter->slic_stats;
@@ -1147,8 +1173,7 @@ static u16 slic_eeprom_cksum(void *eeprom, unsigned len)
        }
 
        if (len > 0)
-               checksum += *(u8 *) wp;
-
+               checksum += *(u8 *)wp;
 
        while (checksum >> 16)
                checksum = (checksum & 0xFFFF) + ((checksum >> 16) & 0xFFFF);
@@ -1246,7 +1271,7 @@ static void slic_cmdqmem_free(struct adapter *adapter)
                if (cmdqmem->pages[i]) {
                        pci_free_consistent(adapter->pcidev,
                                            PAGE_SIZE,
-                                           (void *) cmdqmem->pages[i],
+                                           (void *)cmdqmem->pages[i],
                                            cmdqmem->dma_pages[i]);
                }
        }
@@ -1309,7 +1334,7 @@ static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
        unsigned long flags;
 
        cmdaddr = page;
-       cmd = (struct slic_hostcmd *)cmdaddr;
+       cmd = cmdaddr;
        cmdcnt = 0;
 
        phys_addr = virt_to_bus((void *)page);
@@ -1326,8 +1351,8 @@ static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
                adapter->pfree_slic_handles = pslic_handle->next;
                spin_unlock_irqrestore(&adapter->handle_lock, flags);
                pslic_handle->type = SLIC_HANDLE_CMD;
-               pslic_handle->address = (void *) cmd;
-               pslic_handle->offset = (ushort) adapter->slic_handle_ix++;
+               pslic_handle->address = (void *)cmd;
+               pslic_handle->offset = (ushort)adapter->slic_handle_ix++;
                pslic_handle->other_handle = NULL;
                pslic_handle->next = NULL;
 
@@ -1342,7 +1367,7 @@ static void slic_cmdq_addcmdpage(struct adapter *adapter, u32 *page)
                phys_addrl += SLIC_HOSTCMD_SIZE;
                cmdaddr += SLIC_HOSTCMD_SIZE;
 
-               cmd = (struct slic_hostcmd *)cmdaddr;
+               cmd = cmdaddr;
                cmdcnt++;
        }
 
@@ -1717,14 +1742,14 @@ static u32 slic_rcvqueue_reinsert(struct adapter *adapter, struct sk_buff *skb)
  * will also complete asynchronously.
  *
  */
-static void slic_link_event_handler(struct adapter *adapter)
+static int slic_link_event_handler(struct adapter *adapter)
 {
        int status;
        struct slic_shmem *pshmem;
 
        if (adapter->state != ADAPT_UP) {
                /* Adapter is not operational.  Ignore.  */
-               return;
+               return -ENODEV;
        }
 
        pshmem = (struct slic_shmem *)(unsigned long)adapter->phys_shmem;
@@ -1737,9 +1762,10 @@ static void slic_link_event_handler(struct adapter *adapter)
                                  0, 0);
 #else
        status = slic_upr_request(adapter, SLIC_UPR_RLSR,
-               (u32) &pshmem->linkstatus,      /* no 4GB wrap guaranteed */
+               (u32)&pshmem->linkstatus,       /* no 4GB wrap guaranteed */
                                  0, 0, 0);
 #endif
+       return status;
 }
 
 static void slic_init_cleanup(struct adapter *adapter)
@@ -1804,7 +1830,7 @@ static void slic_mcast_set_list(struct net_device *dev)
        struct netdev_hw_addr *ha;
 
        netdev_for_each_mc_addr(ha, dev) {
-               addresses = (char *) &ha->addr;
+               addresses = (char *)&ha->addr;
                status = slic_mcast_add_list(adapter, addresses);
                if (status != 0)
                        break;
@@ -1852,8 +1878,8 @@ static void slic_xmit_build_request(struct adapter *adapter,
        ihcmd->u.slic_buffers.bufs[0].paddrh = SLIC_GET_ADDR_HIGH(phys_addr);
        ihcmd->u.slic_buffers.bufs[0].length = skb->len;
 #if BITS_PER_LONG == 64
-       hcmd->cmdsize = (u32) ((((u64)&ihcmd->u.slic_buffers.bufs[1] -
-                                    (u64) hcmd) + 31) >> 5);
+       hcmd->cmdsize = (u32)((((u64)&ihcmd->u.slic_buffers.bufs[1] -
+                                    (u64)hcmd) + 31) >> 5);
 #else
        hcmd->cmdsize = (((u32)&ihcmd->u.slic_buffers.bufs[1] -
                                       (u32)hcmd) + 31) >> 5;
@@ -2050,11 +2076,10 @@ static void slic_xmit_complete(struct adapter *adapter)
                adapter->xmit_completes++;
                adapter->card->events++;
                /*
-                Get the complete host command buffer
-               */
+                Get the complete host command buffer
+                */
                slic_handle_word.handle_token = rspbuf->hosthandle;
                hcmd =
-                   (struct slic_hostcmd *)
                        adapter->slic_handles[slic_handle_word.handle_index].
                                                                        address;
 /*      hcmd = (struct slic_hostcmd *) rspbuf->hosthandle; */
@@ -2109,7 +2134,8 @@ static void slic_interrupt_card_up(u32 isr, struct adapter *adapter,
 
                if (isr & ISR_LEVENT) {
                        adapter->linkevent_interrupts++;
-                       slic_link_event_handler(adapter);
+                       if (slic_link_event_handler(adapter))
+                               adapter->linkevent_interrupts--;
                }
 
                if ((isr & ISR_UPC) || (isr & ISR_UPCERR) ||
@@ -2130,10 +2156,9 @@ static void slic_interrupt_card_up(u32 isr, struct adapter *adapter,
        }
 }
 
-
 static irqreturn_t slic_interrupt(int irq, void *dev_id)
 {
-       struct net_device *dev = (struct net_device *)dev_id;
+       struct net_device *dev = dev_id;
        struct adapter *adapter = netdev_priv(dev);
        u32 isr;
 
@@ -2227,7 +2252,6 @@ xmit_fail:
        goto xmit_done;
 }
 
-
 static void slic_adapter_freeresources(struct adapter *adapter)
 {
        slic_init_cleanup(adapter);
@@ -2378,7 +2402,22 @@ static int slic_if_init(struct adapter *adapter, unsigned long *flags)
        slic_reg32_write(&slic_regs->slic_icr, ICR_INT_ON, FLUSH);
 
        slic_link_config(adapter, LINK_AUTOSPEED, LINK_AUTOD);
-       slic_link_event_handler(adapter);
+       rc = slic_link_event_handler(adapter);
+       if (rc) {
+               /* disable interrupts then clear pending events */
+               slic_reg32_write(&slic_regs->slic_icr, ICR_INT_OFF, FLUSH);
+               slic_reg32_write(&slic_regs->slic_isr, 0, FLUSH);
+               if (adapter->pingtimerset) {
+                       del_timer(&adapter->pingtimer);
+                       adapter->pingtimerset = 0;
+               }
+               if (card->loadtimerset) {
+                       del_timer(&card->loadtimer);
+                       card->loadtimerset = 0;
+               }
+               adapter->state = ADAPT_DOWN;
+               slic_adapter_freeresources(adapter);
+       }
 
 err:
        return rc;
@@ -2608,7 +2647,8 @@ static int slic_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                                else
                                        duplex = 0;
                                slic_link_config(adapter, speed, duplex);
-                               slic_link_event_handler(adapter);
+                               if (slic_link_event_handler(adapter))
+                                       return -EFAULT;
                        }
                }
                return 0;
@@ -2736,7 +2776,7 @@ static int slic_card_init(struct sliccard *card, struct adapter *adapter)
                /* Oasis card */
                case SLIC_2GB_DEVICE_ID:
                        /* extract EEPROM data and pointers to EEPROM data */
-                       pOeeprom = (struct oslic_eeprom *) peeprom;
+                       pOeeprom = (struct oslic_eeprom *)peeprom;
                        eecodesize = pOeeprom->EecodeSize;
                        dramsize = pOeeprom->DramSize;
                        pmac = pOeeprom->MacInfo;
@@ -2745,10 +2785,12 @@ static int slic_card_init(struct sliccard *card, struct adapter *adapter)
                        oemfruformat = pOeeprom->OemFruFormat;
                        poemfru = &pOeeprom->OemFru;
                        macaddrs = 2;
-                       /* Minor kludge for Oasis card
-                            get 2 MAC addresses from the
-                            EEPROM to ensure that function 1
-                            gets the Port 1 MAC address */
+                       /*
+                        * Minor kludge for Oasis card
+                        * get 2 MAC addresses from the
+                        * EEPROM to ensure that function 1
+                        * gets the Port 1 MAC address
+                        */
                        break;
                default:
                        /* extract EEPROM data and pointers to EEPROM data */
@@ -2769,16 +2811,16 @@ static int slic_card_init(struct sliccard *card, struct adapter *adapter)
                    (eecodesize >= MIN_EECODE_SIZE)) {
 
                        ee_chksum =
-                           *(u16 *) ((char *) peeprom + (eecodesize - 2));
+                           *(u16 *)((char *)peeprom + (eecodesize - 2));
                        /*
-                           calculate the EEPROM checksum
-                       */
+                        *  calculate the EEPROM checksum
+                        */
                        calc_chksum = slic_eeprom_cksum(peeprom,
                                                        eecodesize - 2);
                        /*
-                           if the ucdoe chksum flag bit worked,
-                           we wouldn't need this
-                       */
+                        *  if the ucdoe chksum flag bit worked,
+                        *  we wouldn't need this
+                        */
                        if (ee_chksum == calc_chksum)
                                card->config.EepromValid = true;
                }
@@ -2863,7 +2905,7 @@ static void slic_init_adapter(struct net_device *netdev,
        adapter->busnumber = pcidev->bus->number;
        adapter->slotnumber = ((pcidev->devfn >> 3) & 0x1F);
        adapter->functionnumber = (pcidev->devfn & 0x7);
-       adapter->slic_regs = (__iomem struct slic_regs *)memaddr;
+       adapter->slic_regs = memaddr;
        adapter->irq = pcidev->irq;
 /*     adapter->netdev = netdev;*/
        adapter->chipid = chip_idx;
@@ -2877,11 +2919,11 @@ static void slic_init_adapter(struct net_device *netdev,
 
        adapter->card_size = 1;
        /*
-         Initialize slic_handle array
-       */
+        * Initialize slic_handle array
+        */
        /*
-        Start with 1.  0 is an invalid host handle.
-       */
+        Start with 1.  0 is an invalid host handle.
+        */
        for (index = 1, pslic_handle = &adapter->slic_handles[1];
             index < SLIC_CMDQ_MAXCMDS; index++, pslic_handle++) {
 
@@ -2932,11 +2974,11 @@ static u32 slic_card_locate(struct adapter *adapter)
        }
 
        hostid_reg =
-           (u16 __iomem *) (((u8 __iomem *) (adapter->slic_regs)) +
+           (u16 __iomem *)(((u8 __iomem *)(adapter->slic_regs)) +
            rdhostid_offset);
 
        /* read the 16 bit hostid from SRAM */
-       card_hostid = (ushort) readw(hostid_reg);
+       card_hostid = (ushort)readw(hostid_reg);
 
        /* Initialize a new card structure if need be */
        if (card_hostid == SLIC_HOSTID_DEFAULT) {
@@ -3082,7 +3124,6 @@ static int slic_entry_probe(struct pci_dev *pcidev,
        mmio_start = pci_resource_start(pcidev, 0);
        mmio_len = pci_resource_len(pcidev, 0);
 
-
 /*     memmapped_ioaddr =  (u32)ioremap_nocache(mmio_start, mmio_len);*/
        memmapped_ioaddr = ioremap(mmio_start, mmio_len);
        if (!memmapped_ioaddr) {
@@ -3118,7 +3159,7 @@ static int slic_entry_probe(struct pci_dev *pcidev,
 
        slic_adapter_set_hwaddr(adapter);
 
-       netdev->base_addr = (unsigned long) memmapped_ioaddr;
+       netdev->base_addr = (unsigned long)memmapped_ioaddr;
        netdev->irq = adapter->irq;
        netdev->netdev_ops = &slic_netdev_ops;
 
index 5e6798ea9468af13a15bdbf366a6b61387c9144e..0331d34458ae42d7411cada92fe971de3b85907c 100644 (file)
@@ -1,15 +1,9 @@
+#include <linux/sizes.h>
+
 #include "ddk750_help.h"
 #include "ddk750_reg.h"
 #include "ddk750_chip.h"
 #include "ddk750_power.h"
-typedef struct _pllcalparam {
-       unsigned char power;/* d : 0~ 6*/
-       unsigned char pod;
-       unsigned char od;
-       unsigned char value;/* value of  2 power d (2^d) */
-}
-pllcalparam;
-
 
 logical_chip_type_t getChipType(void)
 {
@@ -33,82 +27,36 @@ logical_chip_type_t getChipType(void)
        return chip;
 }
 
-
-inline unsigned int twoToPowerOfx(unsigned long x)
-{
-       unsigned long i;
-       unsigned long result = 1;
-
-       for (i = 1; i <= x; i++)
-               result *= 2;
-       return result;
-}
-
-inline unsigned int calcPLL(pll_value_t *pPLL)
-{
-       return (pPLL->inputFreq * pPLL->M / pPLL->N / twoToPowerOfx(pPLL->OD) / twoToPowerOfx(pPLL->POD));
-}
-
-unsigned int getPllValue(clock_type_t clockType, pll_value_t *pPLL)
+static unsigned int get_mxclk_freq(void)
 {
-       unsigned int ulPllReg = 0;
-
-       pPLL->inputFreq = DEFAULT_INPUT_CLOCK;
-       pPLL->clockType = clockType;
-
-       switch (clockType) {
-       case MXCLK_PLL:
-               ulPllReg = PEEK32(MXCLK_PLL_CTRL);
-               break;
-       case PRIMARY_PLL:
-               ulPllReg = PEEK32(PANEL_PLL_CTRL);
-               break;
-       case SECONDARY_PLL:
-               ulPllReg = PEEK32(CRT_PLL_CTRL);
-               break;
-       case VGA0_PLL:
-               ulPllReg = PEEK32(VGA_PLL0_CTRL);
-               break;
-       case VGA1_PLL:
-               ulPllReg = PEEK32(VGA_PLL1_CTRL);
-               break;
-       }
-
-       pPLL->M = FIELD_GET(ulPllReg, PANEL_PLL_CTRL, M);
-       pPLL->N = FIELD_GET(ulPllReg, PANEL_PLL_CTRL, N);
-       pPLL->OD = FIELD_GET(ulPllReg, PANEL_PLL_CTRL, OD);
-       pPLL->POD = FIELD_GET(ulPllReg, PANEL_PLL_CTRL, POD);
-
-       return calcPLL(pPLL);
-}
-
+       unsigned int pll_reg;
+       unsigned int M, N, OD, POD;
 
-unsigned int getChipClock(void)
-{
-       pll_value_t pll;
-#if 1
        if (getChipType() == SM750LE)
                return MHz(130);
-#endif
 
-       return getPllValue(MXCLK_PLL, &pll);
-}
+       pll_reg = PEEK32(MXCLK_PLL_CTRL);
+       M = FIELD_GET(pll_reg, PANEL_PLL_CTRL, M);
+       N = FIELD_GET(pll_reg, PANEL_PLL_CTRL, N);
+       OD = FIELD_GET(pll_reg, PANEL_PLL_CTRL, OD);
+       POD = FIELD_GET(pll_reg, PANEL_PLL_CTRL, POD);
 
+       return DEFAULT_INPUT_CLOCK * M / N / (1 << OD) / (1 << POD);
+}
 
 /*
  * This function set up the main chip clock.
  *
  * Input: Frequency to be set.
  */
-void setChipClock(unsigned int frequency)
+static void setChipClock(unsigned int frequency)
 {
        pll_value_t pll;
        unsigned int ulActualMxClk;
-#if 1
+
        /* Cheok_0509: For SM750LE, the chip clock is fixed. Nothing to set. */
        if (getChipType() == SM750LE)
                return;
-#endif
 
        if (frequency) {
                /*
@@ -129,16 +77,14 @@ void setChipClock(unsigned int frequency)
        }
 }
 
-
-
-void setMemoryClock(unsigned int frequency)
+static void setMemoryClock(unsigned int frequency)
 {
        unsigned int ulReg, divisor;
- #if 1
+
        /* Cheok_0509: For SM750LE, the memory clock is fixed. Nothing to set. */
        if (getChipType() == SM750LE)
                return;
-#endif
+
        if (frequency) {
                /* Set the frequency to the maximum frequency that the DDR Memory can take
                which is 336MHz. */
@@ -146,7 +92,7 @@ void setMemoryClock(unsigned int frequency)
                        frequency = MHz(336);
 
                /* Calculate the divisor */
-               divisor = (unsigned int) roundedDiv(getChipClock(), frequency);
+               divisor = roundedDiv(get_mxclk_freq(), frequency);
 
                /* Set the corresponding divisor in the register. */
                ulReg = PEEK32(CURRENT_GATE);
@@ -170,7 +116,6 @@ void setMemoryClock(unsigned int frequency)
        }
 }
 
-
 /*
  * This function set up the master clock (MCLK).
  *
@@ -179,14 +124,14 @@ void setMemoryClock(unsigned int frequency)
  * NOTE:
  *      The maximum frequency the engine can run is 168MHz.
  */
-void setMasterClock(unsigned int frequency)
+static void setMasterClock(unsigned int frequency)
 {
        unsigned int ulReg, divisor;
-#if 1
+
        /* Cheok_0509: For SM750LE, the memory clock is fixed. Nothing to set. */
        if (getChipType() == SM750LE)
                return;
-#endif
+
        if (frequency) {
                /* Set the frequency to the maximum frequency that the SM750 engine can
                run, which is about 190 MHz. */
@@ -194,7 +139,7 @@ void setMasterClock(unsigned int frequency)
                        frequency = MHz(190);
 
                /* Calculate the divisor */
-               divisor = (unsigned int) roundedDiv(getChipClock(), frequency);
+               divisor = roundedDiv(get_mxclk_freq(), frequency);
 
                /* Set the corresponding divisor in the register. */
                ulReg = PEEK32(CURRENT_GATE);
@@ -218,7 +163,6 @@ void setMasterClock(unsigned int frequency)
                }
 }
 
-
 unsigned int ddk750_getVMSize(void)
 {
        unsigned int reg;
@@ -226,7 +170,7 @@ unsigned int ddk750_getVMSize(void)
 
        /* sm750le only use 64 mb memory*/
        if (getChipType() == SM750LE)
-               return MB(64);
+               return SZ_64M;
 
        /* for 750,always use power mode0*/
        reg = PEEK32(MODE0_GATE);
@@ -237,36 +181,23 @@ unsigned int ddk750_getVMSize(void)
        reg = FIELD_GET(PEEK32(MISC_CTRL), MISC_CTRL, LOCALMEM_SIZE);
        switch (reg) {
        case MISC_CTRL_LOCALMEM_SIZE_8M:
-               data = MB(8);  break; /* 8  Mega byte */
+               data = SZ_8M;  break; /* 8  Mega byte */
        case MISC_CTRL_LOCALMEM_SIZE_16M:
-               data = MB(16); break; /* 16 Mega byte */
+               data = SZ_16M; break; /* 16 Mega byte */
        case MISC_CTRL_LOCALMEM_SIZE_32M:
-               data = MB(32); break; /* 32 Mega byte */
+               data = SZ_32M; break; /* 32 Mega byte */
        case MISC_CTRL_LOCALMEM_SIZE_64M:
-               data = MB(64); break; /* 64 Mega byte */
+               data = SZ_64M; break; /* 64 Mega byte */
        default:
                data = 0;
                break;
        }
        return data;
-
 }
 
 int ddk750_initHw(initchip_param_t *pInitParam)
 {
-
        unsigned int ulReg;
-#if 0
-       /* move the code to map regiter function. */
-       if (getChipType() == SM718) {
-               /* turn on big endian bit*/
-               ulReg = PEEK32(0x74);
-               /* now consider register definition in a big endian pattern*/
-               POKE32(0x74, ulReg|0x80000000);
-       }
-
-#endif
-
 
        if (pInitParam->powerMode != 0)
                pInitParam->powerMode = 0;
@@ -333,37 +264,6 @@ int ddk750_initHw(initchip_param_t *pInitParam)
                ulReg = FIELD_SET(ulReg, ALPHA_DISPLAY_CTRL, PLANE, DISABLE);
                POKE32(ALPHA_DISPLAY_CTRL, ulReg);
 
-#if 0
-               /* Disable LCD hardware cursor, if a former application left it on */
-               ulReg = PEEK32(PANEL_HWC_ADDRESS);
-               ulReg = FIELD_SET(ulReg, PANEL_HWC_ADDRESS, ENABLE, DISABLE);
-               POKE32(PANEL_HWC_ADDRESS, ulReg);
-
-               /* Disable CRT hardware cursor, if a former application left it on */
-               ulReg = PEEK32(CRT_HWC_ADDRESS);
-               ulReg = FIELD_SET(ulReg, CRT_HWC_ADDRESS, ENABLE, DISABLE);
-               POKE32(CRT_HWC_ADDRESS, ulReg);
-
-               /* Disable ZV Port 0, if a former application left it on */
-               ulReg = PEEK32(ZV0_CAPTURE_CTRL);
-               ulReg = FIELD_SET(ulReg, ZV0_CAPTURE_CTRL, CAP, DISABLE);
-               POKE32(ZV0_CAPTURE_CTRL, ulReg);
-
-               /* Disable ZV Port 1, if a former application left it on */
-               ulReg = PEEK32(ZV1_CAPTURE_CTRL);
-               ulReg = FIELD_SET(ulReg, ZV1_CAPTURE_CTRL, CAP, DISABLE);
-               POKE32(ZV1_CAPTURE_CTRL, ulReg);
-
-               /* Disable ZV Port Power, if a former application left it on */
-               enableZVPort(0);
-               /* Disable DMA Channel, if a former application left it on */
-               ulReg = PEEK32(DMA_ABORT_INTERRUPT);
-               ulReg = FIELD_SET(ulReg, DMA_ABORT_INTERRUPT, ABORT_1, ABORT);
-               POKE32(DMA_ABORT_INTERRUPT, ulReg);
-
-               /* Disable i2c */
-               enableI2C(0);
-#endif
                /* Disable DMA Channel, if a former application left it on */
                ulReg = PEEK32(DMA_ABORT_INTERRUPT);
                ulReg = FIELD_SET(ulReg, DMA_ABORT_INTERRUPT, ABORT_1, ABORT);
@@ -378,17 +278,6 @@ int ddk750_initHw(initchip_param_t *pInitParam)
        return 0;
 }
 
-#if 0
-
-unsigned int absDiff(unsigned int a, unsigned int b)
-{
-       if (a > b)
-               return(a - b);
-       else
-               return(b - a);
-}
-
-#endif
 /*
        monk liu @ 4/6/2011:
                   re-write the calculatePLL function of ddk750.
@@ -407,57 +296,29 @@ unsigned int absDiff(unsigned int a, unsigned int b)
 */
 unsigned int calcPllValue(unsigned int request_orig, pll_value_t *pll)
 {
-       /* used for primary and secondary channel pixel clock pll */
-       static pllcalparam xparm_PIXEL[] = {
-               /* 2^0 = 1*/                    {0, 0, 0, 1},
-               /* 2^ 1 =2*/                    {1, 0, 1, 2},
-               /* 2^ 2  = 4*/          {2, 0, 2, 4},
-                                                       {3, 0, 3, 8},
-                                                       {4, 1, 3, 16},
-                                                       {5, 2, 3, 32},
-               /* 2^6 = 64  */         {6, 3, 3, 64},
-                                                       };
-
-       /* used for MXCLK (chip clock) */
-       static pllcalparam xparm_MXCLK[] = {
-               /* 2^0 = 1*/                    {0, 0, 0, 1},
-               /* 2^ 1 =2*/                    {1, 0, 1, 2},
-               /* 2^ 2  = 4*/          {2, 0, 2, 4},
-                                                       {3, 0, 3, 8},
-                                                       };
-
        /* as sm750 register definition, N located in 2,15 and M located in 1,255       */
        int N, M, X, d;
-       int xcnt;
-       int miniDiff;
+       int mini_diff;
        unsigned int RN, quo, rem, fl_quo;
        unsigned int input, request;
        unsigned int tmpClock, ret;
-       pllcalparam *xparm;
+       const int max_OD = 3;
+       int max_d;
 
-#if 1
        if (getChipType() == SM750LE) {
                /* SM750LE don't have prgrammable PLL and M/N values to work on.
                Just return the requested clock. */
                return request_orig;
        }
-#endif
 
        ret = 0;
-       miniDiff = ~0;
+       mini_diff = ~0;
        request = request_orig / 1000;
        input = pll->inputFreq / 1000;
 
        /* for MXCLK register , no POD provided, so need be treated differently */
-
-       if (pll->clockType != MXCLK_PLL) {
-               xparm = &xparm_PIXEL[0];
-               xcnt = sizeof(xparm_PIXEL)/sizeof(xparm_PIXEL[0]);
-       } else {
-               xparm = &xparm_MXCLK[0];
-               xcnt = sizeof(xparm_MXCLK)/sizeof(xparm_MXCLK[0]);
-       }
-
+       if (pll->clockType == MXCLK_PLL)
+               max_d = 3;
 
        for (N = 15; N > 1; N--) {
                /* RN will not exceed maximum long if @request <= 285 MHZ (for 32bit cpu) */
@@ -466,23 +327,25 @@ unsigned int calcPllValue(unsigned int request_orig, pll_value_t *pll)
                rem = RN % input;/* rem always small than 14318181 */
                fl_quo = (rem * 10000 / input);
 
-               for (d = xcnt - 1; d >= 0; d--) {
-                       X = xparm[d].value;
-                       M = quo*X;
+               for (d = max_d; d >= 0; d--) {
+                       X = (1 << d);
+                       M = quo * X;
                        M += fl_quo * X / 10000;
                        /* round step */
-                       M += (fl_quo*X % 10000) > 5000?1:0;
+                       M += (fl_quo * X % 10000) > 5000 ? 1 : 0;
                        if (M < 256 && M > 0) {
                                unsigned int diff;
 
                                tmpClock = pll->inputFreq * M / N / X;
                                diff = absDiff(tmpClock, request_orig);
-                               if (diff < miniDiff) {
+                               if (diff < mini_diff) {
                                        pll->M = M;
                                        pll->N = N;
-                                       pll->OD = xparm[d].od;
-                                       pll->POD = xparm[d].pod;
-                                       miniDiff = diff;
+                                       pll->POD = 0;
+                                       if (d > max_OD)
+                                               pll->POD = d - max_OD;
+                                       pll->OD = d - pll->POD;
+                                       mini_diff = diff;
                                        ret = tmpClock;
                                }
                        }
@@ -491,106 +354,6 @@ unsigned int calcPllValue(unsigned int request_orig, pll_value_t *pll)
        return ret;
 }
 
-unsigned int calcPllValue2(
-unsigned int ulRequestClk, /* Required pixel clock in Hz unit */
-pll_value_t *pPLL           /* Structure to hold the value to be set in PLL */
-)
-{
-       unsigned int M, N, OD, POD = 0, diff, pllClk, odPower, podPower;
-       unsigned int bestDiff = 0xffffffff; /* biggest 32 bit unsigned number */
-       unsigned int ret;
-    /* Init PLL structure to know states */
-       pPLL->M = 0;
-       pPLL->N = 0;
-       pPLL->OD = 0;
-       pPLL->POD = 0;
-
-    /* Sanity check: None at the moment */
-
-    /* Convert everything in Khz range in order to avoid calculation overflow */
-       pPLL->inputFreq /= 1000;
-       ulRequestClk /= 1000;
-
-#ifndef VALIDATION_CHIP
-    /* The maximum of post divider is 8. */
-       for (POD = 0; POD <= 3; POD++)
-#endif
-               {
-
-#ifndef VALIDATION_CHIP
-       /* MXCLK_PLL does not have post divider. */
-       if ((POD > 0) && (pPLL->clockType == MXCLK_PLL))
-               break;
-#endif
-
-       /* Work out 2 to the power of POD */
-       podPower = twoToPowerOfx(POD);
-
-       /* OD has only 2 bits [15:14] and its value must between 0 to 3 */
-       for (OD = 0; OD <= 3; OD++) {
-               /* Work out 2 to the power of OD */
-               odPower = twoToPowerOfx(OD);
-
-#ifdef VALIDATION_CHIP
-       if (odPower > 4)
-               podPower = 4;
-       else
-               podPower = odPower;
-#endif
-
-               /* N has 4 bits [11:8] and its value must between 2 and 15.
-               The N == 1 will behave differently --> Result is not correct. */
-       for (N = 2; N <= 15; N++) {
-               /* The formula for PLL is ulRequestClk = inputFreq * M / N / (2^OD)
-               In the following steps, we try to work out a best M value given the others are known.
-               To avoid decimal calculation, we use 1000 as multiplier for up to 3 decimal places of accuracy.
-               */
-               M = ulRequestClk * N * odPower * 1000 / pPLL->inputFreq;
-               M = roundedDiv(M, 1000);
-
-               /* M field has only 8 bits, reject value bigger than 8 bits */
-               if (M < 256) {
-                       /* Calculate the actual clock for a given M & N */
-                       pllClk = pPLL->inputFreq * M / N / odPower / podPower;
-
-                       /* How much are we different from the requirement */
-                       diff = absDiff(pllClk, ulRequestClk);
-
-                       if (diff < bestDiff) {
-                               bestDiff = diff;
-
-                               /* Store M and N values */
-                               pPLL->M  = M;
-                               pPLL->N  = N;
-                               pPLL->OD = OD;
-
-#ifdef VALIDATION_CHIP
-                       if (OD > 2)
-                               POD = 2;
-                       else
-                               POD = OD;
-#endif
-
-                       pPLL->POD = POD;
-                       }
-               }
-       }
-       }
-       }
-
-    /* Restore input frequency from Khz to hz unit */
-       ulRequestClk *= 1000;
-       pPLL->inputFreq = DEFAULT_INPUT_CLOCK; /* Default reference clock */
-
-    /* Return actual frequency that the PLL can set */
-       ret = calcPLL(pPLL);
-       return ret;
-}
-
-
-
-
-
 unsigned int formatPllReg(pll_value_t *pPLL)
 {
        unsigned int ulPllReg = 0;
index 6ff043608fe95c8be833fabd7f8cc972990ff220..0891384ef3e5b284e19efb6731b43be1b51be526 100644 (file)
@@ -16,7 +16,6 @@ typedef enum _logical_chip_type_t {
 }
 logical_chip_type_t;
 
-
 typedef enum _clock_type_t {
        MXCLK_PLL,
        PRIMARY_PLL,
@@ -70,19 +69,11 @@ typedef struct _initchip_param_t {
 }
 initchip_param_t;
 
-
 logical_chip_type_t getChipType(void);
 unsigned int calcPllValue(unsigned int request, pll_value_t *pll);
-unsigned int calcPllValue2(unsigned int, pll_value_t *);
 unsigned int formatPllReg(pll_value_t *pPLL);
 void ddk750_set_mmio(void __iomem *, unsigned short, char);
 unsigned int ddk750_getVMSize(void);
 int ddk750_initHw(initchip_param_t *);
-unsigned int getPllValue(clock_type_t clockType, pll_value_t *pPLL);
-unsigned int getChipClock(void);
-void setChipClock(unsigned int);
-void setMemoryClock(unsigned int frequency);
-void setMasterClock(unsigned int frequency);
-
 
 #endif
index 8348113482d998754218d859d6b618a7a32a949c..84f6e8b8c0e251542cfdd63b8b34a26aa50b6797 100644 (file)
@@ -6,7 +6,7 @@
 
 #define primaryWaitVerticalSync(delay) waitNextVerticalSync(0, delay)
 
-static void setDisplayControl(int ctrl, int dispState)
+static void setDisplayControl(int ctrl, int disp_state)
 {
        /* state != 0 means turn on both timing & plane en_bit */
        unsigned long ulDisplayCtrlReg, ulReservedBits;
@@ -18,7 +18,7 @@ static void setDisplayControl(int ctrl, int dispState)
        if (!ctrl) {
                ulDisplayCtrlReg = PEEK32(PANEL_DISPLAY_CTRL);
                /* Turn on/off the Panel display control */
-               if (dispState) {
+               if (disp_state) {
                        /* Timing should be enabled first before enabling the plane
                         * because changing at the same time does not guarantee that
                         * the plane will also enabled or disabled.
@@ -70,7 +70,7 @@ static void setDisplayControl(int ctrl, int dispState)
                /* Set the secondary display control */
                ulDisplayCtrlReg = PEEK32(CRT_DISPLAY_CTRL);
 
-               if (dispState) {
+               if (disp_state) {
                        /* Timing should be enabled first before enabling the plane because changing at the
                           same time does not guarantee that the plane will also enabled or disabled.
                           */
@@ -117,7 +117,6 @@ static void setDisplayControl(int ctrl, int dispState)
        }
 }
 
-
 static void waitNextVerticalSync(int ctrl, int delay)
 {
        unsigned int status;
@@ -189,7 +188,6 @@ static void swPanelPowerSequence(int disp, int delay)
        POKE32(PANEL_DISPLAY_CTRL, reg);
        primaryWaitVerticalSync(delay);
 
-
        reg = PEEK32(PANEL_DISPLAY_CTRL);
        reg = FIELD_VALUE(reg, PANEL_DISPLAY_CTRL, DATA, disp);
        POKE32(PANEL_DISPLAY_CTRL, reg);
@@ -200,7 +198,6 @@ static void swPanelPowerSequence(int disp, int delay)
        POKE32(PANEL_DISPLAY_CTRL, reg);
        primaryWaitVerticalSync(delay);
 
-
        reg = PEEK32(PANEL_DISPLAY_CTRL);
        reg = FIELD_VALUE(reg, PANEL_DISPLAY_CTRL, FPEN, disp);
        POKE32(PANEL_DISPLAY_CTRL, reg);
@@ -231,55 +228,22 @@ void ddk750_setLogicalDispOut(disp_output_t output)
 
        if (output & PRI_TP_USAGE) {
                /* set primary timing and plane en_bit */
-               setDisplayControl(0, (output&PRI_TP_MASK)>>PRI_TP_OFFSET);
+               setDisplayControl(0, (output & PRI_TP_MASK) >> PRI_TP_OFFSET);
        }
 
        if (output & SEC_TP_USAGE) {
                /* set secondary timing and plane en_bit*/
-               setDisplayControl(1, (output&SEC_TP_MASK)>>SEC_TP_OFFSET);
+               setDisplayControl(1, (output & SEC_TP_MASK) >> SEC_TP_OFFSET);
        }
 
        if (output & PNL_SEQ_USAGE) {
                /* set  panel sequence */
-               swPanelPowerSequence((output&PNL_SEQ_MASK)>>PNL_SEQ_OFFSET, 4);
+               swPanelPowerSequence((output & PNL_SEQ_MASK) >> PNL_SEQ_OFFSET, 4);
        }
 
        if (output & DAC_USAGE)
-               setDAC((output & DAC_MASK)>>DAC_OFFSET);
+               setDAC((output & DAC_MASK) >> DAC_OFFSET);
 
        if (output & DPMS_USAGE)
                ddk750_setDPMS((output & DPMS_MASK) >> DPMS_OFFSET);
 }
-
-
-int ddk750_initDVIDisp(void)
-{
-       /* Initialize DVI. If the dviInit fail and the VendorID or the DeviceID are
-          not zeroed, then set the failure flag. If it is zeroe, it might mean
-          that the system is in Dual CRT Monitor configuration. */
-
-       /* De-skew enabled with default 111b value.
-          This will fix some artifacts problem in some mode on board 2.2.
-          Somehow this fix does not affect board 2.1.
-        */
-       if ((dviInit(1,  /* Select Rising Edge */
-                    1,  /* Select 24-bit bus */
-                    0,  /* Select Single Edge clock */
-                    1,  /* Enable HSync as is */
-                    1,  /* Enable VSync as is */
-                    1,  /* Enable De-skew */
-                    7,  /* Set the de-skew setting to maximum setup */
-                    1,  /* Enable continuous Sync */
-                    1,  /* Enable PLL Filter */
-                    4   /* Use the recommended value for PLL Filter value */
-                    ) != 0) && (dviGetVendorID() != 0x0000) && (dviGetDeviceID() != 0x0000)) {
-               return (-1);
-       }
-
-       /* TODO: Initialize other display component */
-
-       /* Success */
-       return 0;
-
-}
-
index abccf84a8c9a752f4d6ae663171890853e85bc93..ca35aa1df9d780c064bbe4e8ac6366f3c228e208 100644 (file)
@@ -17,7 +17,7 @@
        0: both off
 */
 #define PRI_TP_OFFSET 4
-#define PRI_TP_MASK (1 << PRI_TP_OFFSET)
+#define PRI_TP_MASK BIT(PRI_TP_OFFSET)
 #define PRI_TP_USAGE (PRI_TP_MASK << 16)
 #define PRI_TP_ON ((0x1 << PRI_TP_OFFSET)|PRI_TP_USAGE)
 #define PRI_TP_OFF ((0x0 << PRI_TP_OFFSET)|PRI_TP_USAGE)
        80000[27:24]
 */
 #define PNL_SEQ_OFFSET 6
-#define PNL_SEQ_MASK (1 << PNL_SEQ_OFFSET)
+#define PNL_SEQ_MASK BIT(PNL_SEQ_OFFSET)
 #define PNL_SEQ_USAGE (PNL_SEQ_MASK << 16)
-#define PNL_SEQ_ON ((1 << PNL_SEQ_OFFSET)|PNL_SEQ_USAGE)
+#define PNL_SEQ_ON (BIT(PNL_SEQ_OFFSET)|PNL_SEQ_USAGE)
 #define PNL_SEQ_OFF ((0 << PNL_SEQ_OFFSET)|PNL_SEQ_USAGE)
 
 /* dual digital output
        80000[19]
 */
 #define DUAL_TFT_OFFSET 8
-#define DUAL_TFT_MASK (1 << DUAL_TFT_OFFSET)
+#define DUAL_TFT_MASK BIT(DUAL_TFT_OFFSET)
 #define DUAL_TFT_USAGE (DUAL_TFT_MASK << 16)
-#define DUAL_TFT_ON ((1 << DUAL_TFT_OFFSET)|DUAL_TFT_USAGE)
+#define DUAL_TFT_ON (BIT(DUAL_TFT_OFFSET)|DUAL_TFT_USAGE)
 #define DUAL_TFT_OFF ((0 << DUAL_TFT_OFFSET)|DUAL_TFT_USAGE)
 
 /* secondary timing & plane enable bit
@@ -46,7 +46,7 @@
        0: both off
 */
 #define SEC_TP_OFFSET 5
-#define SEC_TP_MASK (1 << SEC_TP_OFFSET)
+#define SEC_TP_MASK BIT(SEC_TP_OFFSET)
 #define SEC_TP_USAGE (SEC_TP_MASK << 16)
 #define SEC_TP_ON  ((0x1 << SEC_TP_OFFSET)|SEC_TP_USAGE)
 #define SEC_TP_OFF ((0x0 << SEC_TP_OFFSET)|SEC_TP_USAGE)
@@ -65,7 +65,7 @@
        4[20]
 */
 #define DAC_OFFSET 7
-#define DAC_MASK (1 << DAC_OFFSET)
+#define DAC_MASK BIT(DAC_OFFSET)
 #define DAC_USAGE (DAC_MASK << 16)
 #define DAC_ON ((0x0 << DAC_OFFSET)|DAC_USAGE)
 #define DAC_OFF ((0x1 << DAC_OFFSET)|DAC_USAGE)
        LCD1 means panel path TFT1  & panel path DVI (so enable DAC)
        CRT means crt path DSUB
 */
-#if 0
-typedef enum _disp_output_t {
-       NO_DISPLAY = DPMS_OFF,
-
-       LCD1_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|DPMS_OFF|DAC_ON,
-       LCD1_SEC = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|DPMS_OFF|DAC_ON,
-
-       LCD2_PRI = CRT_2_PRI|PRI_TP_ON|DUAL_TFT_ON|DPMS_OFF,
-       LCD2_SEC = CRT_2_SEC|SEC_TP_ON|DUAL_TFT_ON|DPMS_OFF,
-
-       DSUB_PRI = CRT_2_PRI|PRI_TP_ON|DAC_ON,
-       DSUB_SEC = CRT_2_SEC|SEC_TP_ON|DAC_ON,
-
-       LCD1_DSUB_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|
-                                       CRT_2_PRI|SEC_TP_OFF|DAC_ON,
-
-       LCD1_DSUB_SEC = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|
-                                       CRT_2_SEC|PRI_TP_OFF|DAC_ON,
-
-       /* LCD1 show primary and DSUB show secondary */
-       LCD1_DSUB_DUAL = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|
-                                        CRT_2_SEC|SEC_TP_ON|DAC_ON,
-
-       /* LCD1 show secondary and DSUB show primary */
-       LCD1_DSUB_DUAL_SWAP = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|
-                                                       CRT_2_PRI|PRI_TP_ON|DAC_ON,
-
-       LCD1_LCD2_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|
-                                       CRT_2_PRI|SEC_TP_OFF|DPMS_OFF|DUAL_TFT_ON,
-
-       LCD1_LCD2_SEC = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|
-                                       CRT_2_SEC|PRI_TP_OFF|DPMS_OFF|DUAL_TFT_ON,
-
-       LCD1_LCD2_DSUB_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|DAC_ON|
-                                               CRT_2_PRI|SEC_TP_OFF|DPMS_ON|DUAL_TFT_ON,
-
-       LCD1_LCD2_DSUB_SEC = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|DAC_ON|
-                                               CRT_2_SEC|PRI_TP_OFF|DPMS_ON|DUAL_TFT_ON,
-
-
-}
-disp_output_t;
-#else
 typedef enum _disp_output_t {
        do_LCD1_PRI = PNL_2_PRI|PRI_TP_ON|PNL_SEQ_ON|DAC_ON,
        do_LCD1_SEC = PNL_2_SEC|SEC_TP_ON|PNL_SEQ_ON|DAC_ON,
-#if 0
-       do_LCD2_PRI = CRT_2_PRI|PRI_TP_ON,
-       do_LCD2_SEC = CRT_2_SEC|SEC_TP_ON,
-#else
        do_LCD2_PRI = CRT_2_PRI|PRI_TP_ON|DUAL_TFT_ON,
        do_LCD2_SEC = CRT_2_SEC|SEC_TP_ON|DUAL_TFT_ON,
-#endif
        /*
        do_DSUB_PRI = CRT_2_PRI|PRI_TP_ON|DPMS_ON|DAC_ON,
        do_DSUB_SEC = CRT_2_SEC|SEC_TP_ON|DPMS_ON|DAC_ON,
        */
-#if 0
-       do_CRT_PRI = CRT_2_PRI|PRI_TP_ON,
-       do_CRT_SEC = CRT_2_SEC|SEC_TP_ON,
-#else
        do_CRT_PRI = CRT_2_PRI|PRI_TP_ON|DPMS_ON|DAC_ON,
        do_CRT_SEC = CRT_2_SEC|SEC_TP_ON|DPMS_ON|DAC_ON,
-#endif
 }
 disp_output_t;
-#endif
 
 void ddk750_setLogicalDispOut(disp_output_t);
-int ddk750_initDVIDisp(void);
 
 #endif
index 3b06aed431bd23b24746492002107f80c92e890b..5be814eed7353cb67da0066702ea420bb1b1e584 100644 (file)
@@ -4,20 +4,13 @@
 #ifndef USE_INTERNAL_REGISTER_ACCESS
 
 #include <linux/ioport.h>
-#include <asm/io.h>
-#include <asm/uaccess.h>
+#include <linux/io.h>
+#include <linux/uaccess.h>
 #include "sm750_help.h"
 
-
-#if 0
-/* if 718 big endian turned on,be aware that don't use this driver for general use,only for ppc big-endian */
-#warning "big endian on target cpu and enable nature big endian support of 718 capability !"
-#define PEEK32(addr)                   __raw_readl(mmio750 + addr)
-#define POKE32(addr, data)             __raw_writel(data, mmio750 + addr)
-#else /* software control endianness */
+/* software control endianness */
 #define PEEK32(addr) readl(addr + mmio750)
 #define POKE32(addr, data) writel(data, addr + mmio750)
-#endif
 
 extern void __iomem *mmio750;
 extern char revId750;
index 5ddac430aea2ef321d8a5c2bf189f7535b8299b6..7be2111284f4bd0bccaeebb158625d7c3426076b 100644 (file)
@@ -8,9 +8,8 @@
 #define MAX_HWI2C_FIFO                  16
 #define HWI2C_WAIT_TIMEOUT              0xF0000
 
-
-int hwI2CInit(
-unsigned char busSpeedMode
+int sm750_hw_i2c_init(
+unsigned char bus_speed_mode
 )
 {
        unsigned int value;
@@ -29,7 +28,7 @@ unsigned char busSpeedMode
 
        /* Enable the I2C Controller and set the bus speed mode */
        value = PEEK32(I2C_CTRL);
-       if (busSpeedMode == 0)
+       if (bus_speed_mode == 0)
                value = FIELD_SET(value, I2C_CTRL, MODE, STANDARD);
        else
                value = FIELD_SET(value, I2C_CTRL, MODE, FAST);
@@ -39,8 +38,7 @@ unsigned char busSpeedMode
        return 0;
 }
 
-
-void hwI2CClose(void)
+void sm750_hw_i2c_close(void)
 {
        unsigned int value;
 
@@ -59,14 +57,14 @@ void hwI2CClose(void)
        POKE32(GPIO_MUX, value);
 }
 
-
-static long hwI2CWaitTXDone(void)
+static long hw_i2c_wait_tx_done(void)
 {
        unsigned int timeout;
 
        /* Wait until the transfer is completed. */
        timeout = HWI2C_WAIT_TIMEOUT;
-       while ((FIELD_GET(PEEK32(I2C_STATUS), I2C_STATUS, TX) != I2C_STATUS_TX_COMPLETED) &&
+       while ((FIELD_GET(PEEK32(I2C_STATUS),
+                         I2C_STATUS, TX) != I2C_STATUS_TX_COMPLETED) &&
               (timeout != 0))
                timeout--;
 
@@ -76,38 +74,39 @@ static long hwI2CWaitTXDone(void)
        return 0;
 }
 
-
-
 /*
  *  This function writes data to the i2c slave device registers.
  *
  *  Parameters:
- *      deviceAddress   - i2c Slave device address
+ *      addr            - i2c Slave device address
  *      length          - Total number of bytes to be written to the device
- *      pBuffer         - The buffer that contains the data to be written to the
+ *      buf             - The buffer that contains the data to be written to the
  *                     i2c device.
  *
  *  Return Value:
  *      Total number of bytes those are actually written.
  */
-static unsigned int hwI2CWriteData(
-       unsigned char deviceAddress,
+static unsigned int hw_i2c_write_data(
+       unsigned char addr,
        unsigned int length,
-       unsigned char *pBuffer
+       unsigned char *buf
 )
 {
        unsigned char count, i;
-       unsigned int totalBytes = 0;
+       unsigned int total_bytes = 0;
 
        /* Set the Device Address */
-       POKE32(I2C_SLAVE_ADDRESS, deviceAddress & ~0x01);
+       POKE32(I2C_SLAVE_ADDRESS, addr & ~0x01);
 
        /* Write data.
         * Note:
         *      Only 16 byte can be accessed per i2c start instruction.
         */
        do {
-               /* Reset I2C by writing 0 to I2C_RESET register to clear the previous status. */
+               /*
+                * Reset I2C by writing 0 to I2C_RESET register to
+                * clear the previous status.
+                */
                POKE32(I2C_RESET, 0);
 
                /* Set the number of bytes to be written */
@@ -119,61 +118,62 @@ static unsigned int hwI2CWriteData(
 
                /* Move the data to the I2C data register */
                for (i = 0; i <= count; i++)
-                       POKE32(I2C_DATA0 + i, *pBuffer++);
+                       POKE32(I2C_DATA0 + i, *buf++);
 
                /* Start the I2C */
-               POKE32(I2C_CTRL, FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START));
+               POKE32(I2C_CTRL,
+                      FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START));
 
                /* Wait until the transfer is completed. */
-               if (hwI2CWaitTXDone() != 0)
+               if (hw_i2c_wait_tx_done() != 0)
                        break;
 
                /* Substract length */
                length -= (count + 1);
 
                /* Total byte written */
-               totalBytes += (count + 1);
+               total_bytes += (count + 1);
 
        } while (length > 0);
 
-       return totalBytes;
+       return total_bytes;
 }
 
-
-
-
 /*
  *  This function reads data from the slave device and stores them
  *  in the given buffer
  *
  *  Parameters:
- *      deviceAddress   - i2c Slave device address
+ *      addr            - i2c Slave device address
  *      length          - Total number of bytes to be read
- *      pBuffer         - Pointer to a buffer to be filled with the data read
+ *      buf             - Pointer to a buffer to be filled with the data read
  *                     from the slave device. It has to be the same size as the
  *                     length to make sure that it can keep all the data read.
  *
  *  Return Value:
  *      Total number of actual bytes read from the slave device
  */
-static unsigned int hwI2CReadData(
-       unsigned char deviceAddress,
+static unsigned int hw_i2c_read_data(
+       unsigned char addr,
        unsigned int length,
-       unsigned char *pBuffer
+       unsigned char *buf
 )
 {
        unsigned char count, i;
-       unsigned int totalBytes = 0;
+       unsigned int total_bytes = 0;
 
        /* Set the Device Address */
-       POKE32(I2C_SLAVE_ADDRESS, deviceAddress | 0x01);
+       POKE32(I2C_SLAVE_ADDRESS, addr | 0x01);
 
        /* Read data and save them to the buffer.
         * Note:
         *      Only 16 byte can be accessed per i2c start instruction.
         */
        do {
-               /* Reset I2C by writing 0 to I2C_RESET register to clear all the status. */
+               /*
+                * Reset I2C by writing 0 to I2C_RESET register to
+                * clear all the status.
+                */
                POKE32(I2C_RESET, 0);
 
                /* Set the number of bytes to be read */
@@ -184,30 +184,28 @@ static unsigned int hwI2CReadData(
                POKE32(I2C_BYTE_COUNT, count);
 
                /* Start the I2C */
-               POKE32(I2C_CTRL, FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START));
+               POKE32(I2C_CTRL,
+                      FIELD_SET(PEEK32(I2C_CTRL), I2C_CTRL, CTRL, START));
 
                /* Wait until transaction done. */
-               if (hwI2CWaitTXDone() != 0)
+               if (hw_i2c_wait_tx_done() != 0)
                        break;
 
                /* Save the data to the given buffer */
                for (i = 0; i <= count; i++)
-                       *pBuffer++ = PEEK32(I2C_DATA0 + i);
+                       *buf++ = PEEK32(I2C_DATA0 + i);
 
                /* Substract length by 16 */
                length -= (count + 1);
 
                /* Number of bytes read. */
-               totalBytes += (count + 1);
+               total_bytes += (count + 1);
 
        } while (length > 0);
 
-       return totalBytes;
+       return total_bytes;
 }
 
-
-
-
 /*
  *  This function reads the slave device's register
  *
@@ -219,23 +217,19 @@ static unsigned int hwI2CReadData(
  *  Return Value:
  *      Register value
  */
-unsigned char hwI2CReadReg(
-       unsigned char deviceAddress,
-       unsigned char registerIndex
+unsigned char sm750_hw_i2c_read_reg(
+       unsigned char addr,
+       unsigned char reg
 )
 {
        unsigned char value = (0xFF);
 
-       if (hwI2CWriteData(deviceAddress, 1, &registerIndex) == 1)
-               hwI2CReadData(deviceAddress, 1, &value);
+       if (hw_i2c_write_data(addr, 1, &reg) == 1)
+               hw_i2c_read_data(addr, 1, &value);
 
        return value;
 }
 
-
-
-
-
 /*
  *  This function writes a value to the slave device's register
  *
@@ -249,21 +243,20 @@ unsigned char hwI2CReadReg(
  *          0   - Success
  *         -1   - Fail
  */
-int hwI2CWriteReg(
-       unsigned char deviceAddress,
-       unsigned char registerIndex,
+int sm750_hw_i2c_write_reg(
+       unsigned char addr,
+       unsigned char reg,
        unsigned char data
 )
 {
        unsigned char value[2];
 
-       value[0] = registerIndex;
+       value[0] = reg;
        value[1] = data;
-       if (hwI2CWriteData(deviceAddress, 2, value) == 2)
+       if (hw_i2c_write_data(addr, 2, value) == 2)
                return 0;
 
        return (-1);
 }
 
-
 #endif
index 0b830ba65eec48f4625a2f77126590fffde8d4da..46e22dce2570e8fd466d38bc68e628237b12debe 100644 (file)
@@ -2,9 +2,10 @@
 #define DDK750_HWI2C_H__
 
 /* hwi2c functions */
-int hwI2CInit(unsigned char busSpeedMode);
-void hwI2CClose(void);
+int sm750_hw_i2c_init(unsigned char bus_speed_mode);
+void sm750_hw_i2c_close(void);
 
-unsigned char hwI2CReadReg(unsigned char deviceAddress, unsigned char registerIndex);
-int hwI2CWriteReg(unsigned char deviceAddress, unsigned char registerIndex, unsigned char data);
+unsigned char sm750_hw_i2c_read_reg(unsigned char addr, unsigned char reg);
+int sm750_hw_i2c_write_reg(unsigned char addr, unsigned char reg,
+                          unsigned char data);
 #endif
index 2399b175ade0f222757a1485ffdde2d09c72e4be..fa35926680ab86e88b1db7be6919bd6ee1c02f58 100644 (file)
@@ -168,14 +168,13 @@ static int programModeRegisters(mode_parameter_t *pModeParam, pll_value_t *pll)
                */
 
                POKE32(PANEL_DISPLAY_CTRL, ulTmpValue|ulReg);
-#if 1
+
                while ((PEEK32(PANEL_DISPLAY_CTRL) & ~ulReservedBits) != (ulTmpValue|ulReg)) {
                        cnt++;
                        if (cnt > 1000)
                                break;
                        POKE32(PANEL_DISPLAY_CTRL, ulTmpValue|ulReg);
                }
-#endif
        } else {
                ret = -1;
        }
index e580dab2b625d128ee10b6959387c62b30213f7a..667e4f82254425b89503e194d0f807c13b030703 100644 (file)
@@ -17,7 +17,7 @@ void ddk750_setDPMS(DPMS_t state)
        }
 }
 
-unsigned int getPowerMode(void)
+static unsigned int getPowerMode(void)
 {
        if (getChipType() == SM750LE)
                return 0;
@@ -108,7 +108,7 @@ void setCurrentGate(unsigned int gate)
  */
 void enable2DEngine(unsigned int enable)
 {
-       uint32_t gate;
+       u32 gate;
 
        gate = PEEK32(CURRENT_GATE);
        if (enable) {
@@ -122,53 +122,9 @@ void enable2DEngine(unsigned int enable)
        setCurrentGate(gate);
 }
 
-
-/*
- * This function enable/disable the ZV Port.
- */
-void enableZVPort(unsigned int enable)
-{
-       uint32_t gate;
-
-       /* Enable ZV Port Gate */
-       gate = PEEK32(CURRENT_GATE);
-       if (enable) {
-               gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, ON);
-#if 1
-               /* Using Software I2C */
-               gate = FIELD_SET(gate, CURRENT_GATE, GPIO, ON);
-#else
-               /* Using Hardware I2C */
-               gate = FIELD_SET(gate, CURRENT_GATE, I2C,    ON);
-#endif
-       } else {
-               /* Disable ZV Port Gate. There is no way to know whether the
-               GPIO pins are being used or not. Therefore, do not disable the
-               GPIO gate. */
-               gate = FIELD_SET(gate, CURRENT_GATE, ZVPORT, OFF);
-       }
-
-       setCurrentGate(gate);
-}
-
-
-void enableSSP(unsigned int enable)
-{
-       uint32_t gate;
-
-       /* Enable SSP Gate */
-       gate = PEEK32(CURRENT_GATE);
-       if (enable)
-               gate = FIELD_SET(gate, CURRENT_GATE, SSP, ON);
-       else
-               gate = FIELD_SET(gate, CURRENT_GATE, SSP, OFF);
-
-       setCurrentGate(gate);
-}
-
 void enableDMA(unsigned int enable)
 {
-       uint32_t gate;
+       u32 gate;
 
        /* Enable DMA Gate */
        gate = PEEK32(CURRENT_GATE);
@@ -185,7 +141,7 @@ void enableDMA(unsigned int enable)
  */
 void enableGPIO(unsigned int enable)
 {
-       uint32_t gate;
+       u32 gate;
 
        /* Enable GPIO Gate */
        gate = PEEK32(CURRENT_GATE);
@@ -197,29 +153,12 @@ void enableGPIO(unsigned int enable)
        setCurrentGate(gate);
 }
 
-/*
- * This function enable/disable the PWM Engine
- */
-void enablePWM(unsigned int enable)
-{
-       uint32_t gate;
-
-       /* Enable PWM Gate */
-       gate = PEEK32(CURRENT_GATE);
-       if (enable)
-               gate = FIELD_SET(gate, CURRENT_GATE, PWM, ON);
-       else
-               gate = FIELD_SET(gate, CURRENT_GATE, PWM, OFF);
-
-       setCurrentGate(gate);
-}
-
 /*
  * This function enable/disable the I2C Engine
  */
 void enableI2C(unsigned int enable)
 {
-       uint32_t gate;
+       u32 gate;
 
        /* Enable I2C Gate */
        gate = PEEK32(CURRENT_GATE);
index b7cf6b281fb651fde508d3b177799d8e66084cde..6e804d990cfff8ee41ffa23d4e148e2683a3f0ca 100644 (file)
@@ -19,8 +19,6 @@ DPMS_t;
 
 void ddk750_setDPMS(DPMS_t);
 
-unsigned int getPowerMode(void);
-
 /*
  * This function sets the current power mode
  */
@@ -36,11 +34,6 @@ void setCurrentGate(unsigned int gate);
  */
 void enable2DEngine(unsigned int enable);
 
-/*
- * This function enable/disable the ZV Port
- */
-void enableZVPort(unsigned int enable);
-
 /*
  * This function enable/disable the DMA Engine
  */
@@ -51,20 +44,10 @@ void enableDMA(unsigned int enable);
  */
 void enableGPIO(unsigned int enable);
 
-/*
- * This function enable/disable the PWM Engine
- */
-void enablePWM(unsigned int enable);
-
 /*
  * This function enable/disable the I2C Engine
  */
 void enableI2C(unsigned int enable);
 
-/*
- * This function enable/disable the SSP.
- */
-void enableSSP(unsigned int enable);
-
 
 #endif
index 2995625c3d62635b80938d1309158a99b30b7e22..16a01c25442c93772e9784622898cbfb432474dd 100644 (file)
 #define CRT_HWC_COLOR_3                               0x08023C
 #define CRT_HWC_COLOR_3_RGB565                        15:0
 
-/* Old Definitions +++. Need to be removed if no application use it. */
-#if 0
-    #define CRT_HWC_COLOR_01                          0x080238
-    #define CRT_HWC_COLOR_01_1_RED                    31:27
-    #define CRT_HWC_COLOR_01_1_GREEN                  26:21
-    #define CRT_HWC_COLOR_01_1_BLUE                   20:16
-    #define CRT_HWC_COLOR_01_0_RED                    15:11
-    #define CRT_HWC_COLOR_01_0_GREEN                  10:5
-    #define CRT_HWC_COLOR_01_0_BLUE                   4:0
-
-    #define CRT_HWC_COLOR_2                           0x08023C
-    #define CRT_HWC_COLOR_2_RED                       15:11
-    #define CRT_HWC_COLOR_2_GREEN                     10:5
-    #define CRT_HWC_COLOR_2_BLUE                      4:0
-#endif
-/* Old Definitions --- */
-
 /* This vertical expansion below start at 0x080240 ~ 0x080264 */
 #define CRT_VERTICAL_EXPANSION                        0x080240
 #ifndef VALIDATION_CHIP
 /* Panel Palette register starts at 0x080C00 ~ 0x080FFC */
 #define CRT_PALETTE_RAM                               0x080C00
 
-/* 2D registers
- * move their defination into general lynx_accel.h file
- * because all smi graphic chip share the same drawing engine
- * register format */
-#if 0
-#define DE_SOURCE                                       0x100000
-#define DE_SOURCE_WRAP                                  31:31
-#define DE_SOURCE_WRAP_DISABLE                          0
-#define DE_SOURCE_WRAP_ENABLE                           1
-
-/*
- * The following definitions are used in different setting
- */
-
-/* Use these definitions in XY addressing mode or linear addressing mode. */
-#define DE_SOURCE_X_K1                                  27:16
-#define DE_SOURCE_Y_K2                                  11:0
-
-/* Use this definition in host write mode for mono. The Y_K2 is not used
-   in host write mode. */
-#define DE_SOURCE_X_K1_MONO                             20:16
-
-/* Use these definitions in Bresenham line drawing mode. */
-#define DE_SOURCE_X_K1_LINE                             29:16
-#define DE_SOURCE_Y_K2_LINE                             13:0
-
-#define DE_DESTINATION                                  0x100004
-#define DE_DESTINATION_WRAP                             31:31
-#define DE_DESTINATION_WRAP_DISABLE                     0
-#define DE_DESTINATION_WRAP_ENABLE                      1
-#if 1
-    #define DE_DESTINATION_X                            27:16
-    #define DE_DESTINATION_Y                            11:0
-#else
-    #define DE_DESTINATION_X                            28:16
-    #define DE_DESTINATION_Y                            15:0
-#endif
-
-#define DE_DIMENSION                                    0x100008
-#define DE_DIMENSION_X                                  28:16
-#define DE_DIMENSION_Y_ET                               15:0
-
-#define DE_CONTROL                                      0x10000C
-#define DE_CONTROL_STATUS                               31:31
-#define DE_CONTROL_STATUS_STOP                          0
-#define DE_CONTROL_STATUS_START                         1
-#define DE_CONTROL_PATTERN                              30:30
-#define DE_CONTROL_PATTERN_MONO                         0
-#define DE_CONTROL_PATTERN_COLOR                        1
-#define DE_CONTROL_UPDATE_DESTINATION_X                 29:29
-#define DE_CONTROL_UPDATE_DESTINATION_X_DISABLE         0
-#define DE_CONTROL_UPDATE_DESTINATION_X_ENABLE          1
-#define DE_CONTROL_QUICK_START                          28:28
-#define DE_CONTROL_QUICK_START_DISABLE                  0
-#define DE_CONTROL_QUICK_START_ENABLE                   1
-#define DE_CONTROL_DIRECTION                            27:27
-#define DE_CONTROL_DIRECTION_LEFT_TO_RIGHT              0
-#define DE_CONTROL_DIRECTION_RIGHT_TO_LEFT              1
-#define DE_CONTROL_MAJOR                                26:26
-#define DE_CONTROL_MAJOR_X                              0
-#define DE_CONTROL_MAJOR_Y                              1
-#define DE_CONTROL_STEP_X                               25:25
-#define DE_CONTROL_STEP_X_POSITIVE                      0
-#define DE_CONTROL_STEP_X_NEGATIVE                      1
-#define DE_CONTROL_STEP_Y                               24:24
-#define DE_CONTROL_STEP_Y_POSITIVE                      0
-#define DE_CONTROL_STEP_Y_NEGATIVE                      1
-#define DE_CONTROL_STRETCH                              23:23
-#define DE_CONTROL_STRETCH_DISABLE                      0
-#define DE_CONTROL_STRETCH_ENABLE                       1
-#define DE_CONTROL_HOST                                 22:22
-#define DE_CONTROL_HOST_COLOR                           0
-#define DE_CONTROL_HOST_MONO                            1
-#define DE_CONTROL_LAST_PIXEL                           21:21
-#define DE_CONTROL_LAST_PIXEL_OFF                       0
-#define DE_CONTROL_LAST_PIXEL_ON                        1
-#define DE_CONTROL_COMMAND                              20:16
-#define DE_CONTROL_COMMAND_BITBLT                       0
-#define DE_CONTROL_COMMAND_RECTANGLE_FILL               1
-#define DE_CONTROL_COMMAND_DE_TILE                      2
-#define DE_CONTROL_COMMAND_TRAPEZOID_FILL               3
-#define DE_CONTROL_COMMAND_ALPHA_BLEND                  4
-#define DE_CONTROL_COMMAND_RLE_STRIP                    5
-#define DE_CONTROL_COMMAND_SHORT_STROKE                 6
-#define DE_CONTROL_COMMAND_LINE_DRAW                    7
-#define DE_CONTROL_COMMAND_HOST_WRITE                   8
-#define DE_CONTROL_COMMAND_HOST_READ                    9
-#define DE_CONTROL_COMMAND_HOST_WRITE_BOTTOM_UP         10
-#define DE_CONTROL_COMMAND_ROTATE                       11
-#define DE_CONTROL_COMMAND_FONT                         12
-#define DE_CONTROL_COMMAND_TEXTURE_LOAD                 15
-#define DE_CONTROL_ROP_SELECT                           15:15
-#define DE_CONTROL_ROP_SELECT_ROP3                      0
-#define DE_CONTROL_ROP_SELECT_ROP2                      1
-#define DE_CONTROL_ROP2_SOURCE                          14:14
-#define DE_CONTROL_ROP2_SOURCE_BITMAP                   0
-#define DE_CONTROL_ROP2_SOURCE_PATTERN                  1
-#define DE_CONTROL_MONO_DATA                            13:12
-#define DE_CONTROL_MONO_DATA_NOT_PACKED                 0
-#define DE_CONTROL_MONO_DATA_8_PACKED                   1
-#define DE_CONTROL_MONO_DATA_16_PACKED                  2
-#define DE_CONTROL_MONO_DATA_32_PACKED                  3
-#define DE_CONTROL_REPEAT_ROTATE                        11:11
-#define DE_CONTROL_REPEAT_ROTATE_DISABLE                0
-#define DE_CONTROL_REPEAT_ROTATE_ENABLE                 1
-#define DE_CONTROL_TRANSPARENCY_MATCH                   10:10
-#define DE_CONTROL_TRANSPARENCY_MATCH_OPAQUE            0
-#define DE_CONTROL_TRANSPARENCY_MATCH_TRANSPARENT       1
-#define DE_CONTROL_TRANSPARENCY_SELECT                  9:9
-#define DE_CONTROL_TRANSPARENCY_SELECT_SOURCE           0
-#define DE_CONTROL_TRANSPARENCY_SELECT_DESTINATION      1
-#define DE_CONTROL_TRANSPARENCY                         8:8
-#define DE_CONTROL_TRANSPARENCY_DISABLE                 0
-#define DE_CONTROL_TRANSPARENCY_ENABLE                  1
-#define DE_CONTROL_ROP                                  7:0
-
-/* Pseudo fields. */
-
-#define DE_CONTROL_SHORT_STROKE_DIR                     27:24
-#define DE_CONTROL_SHORT_STROKE_DIR_225                 0
-#define DE_CONTROL_SHORT_STROKE_DIR_135                 1
-#define DE_CONTROL_SHORT_STROKE_DIR_315                 2
-#define DE_CONTROL_SHORT_STROKE_DIR_45                  3
-#define DE_CONTROL_SHORT_STROKE_DIR_270                 4
-#define DE_CONTROL_SHORT_STROKE_DIR_90                  5
-#define DE_CONTROL_SHORT_STROKE_DIR_180                 8
-#define DE_CONTROL_SHORT_STROKE_DIR_0                   10
-#define DE_CONTROL_ROTATION                             25:24
-#define DE_CONTROL_ROTATION_0                           0
-#define DE_CONTROL_ROTATION_270                         1
-#define DE_CONTROL_ROTATION_90                          2
-#define DE_CONTROL_ROTATION_180                         3
-
-#define DE_PITCH                                        0x100010
-#define DE_PITCH_DESTINATION                            28:16
-#define DE_PITCH_SOURCE                                 12:0
-
-#define DE_FOREGROUND                                   0x100014
-#define DE_FOREGROUND_COLOR                             31:0
-
-#define DE_BACKGROUND                                   0x100018
-#define DE_BACKGROUND_COLOR                             31:0
-
-#define DE_STRETCH_FORMAT                               0x10001C
-#define DE_STRETCH_FORMAT_PATTERN_XY                    30:30
-#define DE_STRETCH_FORMAT_PATTERN_XY_NORMAL             0
-#define DE_STRETCH_FORMAT_PATTERN_XY_OVERWRITE          1
-#define DE_STRETCH_FORMAT_PATTERN_Y                     29:27
-#define DE_STRETCH_FORMAT_PATTERN_X                     25:23
-#define DE_STRETCH_FORMAT_PIXEL_FORMAT                  21:20
-#define DE_STRETCH_FORMAT_PIXEL_FORMAT_8                0
-#define DE_STRETCH_FORMAT_PIXEL_FORMAT_16               1
-#define DE_STRETCH_FORMAT_PIXEL_FORMAT_32               2
-#define DE_STRETCH_FORMAT_ADDRESSING                    19:16
-#define DE_STRETCH_FORMAT_ADDRESSING_XY                 0
-#define DE_STRETCH_FORMAT_ADDRESSING_LINEAR             15
-#define DE_STRETCH_FORMAT_SOURCE_HEIGHT                 11:0
-
-#define DE_COLOR_COMPARE                                0x100020
-#define DE_COLOR_COMPARE_COLOR                          23:0
-
-#define DE_COLOR_COMPARE_MASK                           0x100024
-#define DE_COLOR_COMPARE_MASK_MASKS                     23:0
-
-#define DE_MASKS                                        0x100028
-#define DE_MASKS_BYTE_MASK                              31:16
-#define DE_MASKS_BIT_MASK                               15:0
-
-#define DE_CLIP_TL                                      0x10002C
-#define DE_CLIP_TL_TOP                                  31:16
-#define DE_CLIP_TL_STATUS                               13:13
-#define DE_CLIP_TL_STATUS_DISABLE                       0
-#define DE_CLIP_TL_STATUS_ENABLE                        1
-#define DE_CLIP_TL_INHIBIT                              12:12
-#define DE_CLIP_TL_INHIBIT_OUTSIDE                      0
-#define DE_CLIP_TL_INHIBIT_INSIDE                       1
-#define DE_CLIP_TL_LEFT                                 11:0
-
-#define DE_CLIP_BR                                      0x100030
-#define DE_CLIP_BR_BOTTOM                               31:16
-#define DE_CLIP_BR_RIGHT                                12:0
-
-#define DE_MONO_PATTERN_LOW                             0x100034
-#define DE_MONO_PATTERN_LOW_PATTERN                     31:0
-
-#define DE_MONO_PATTERN_HIGH                            0x100038
-#define DE_MONO_PATTERN_HIGH_PATTERN                    31:0
-
-#define DE_WINDOW_WIDTH                                 0x10003C
-#define DE_WINDOW_WIDTH_DESTINATION                     28:16
-#define DE_WINDOW_WIDTH_SOURCE                          12:0
-
-#define DE_WINDOW_SOURCE_BASE                           0x100040
-#define DE_WINDOW_SOURCE_BASE_EXT                       27:27
-#define DE_WINDOW_SOURCE_BASE_EXT_LOCAL                 0
-#define DE_WINDOW_SOURCE_BASE_EXT_EXTERNAL              1
-#define DE_WINDOW_SOURCE_BASE_CS                        26:26
-#define DE_WINDOW_SOURCE_BASE_CS_0                      0
-#define DE_WINDOW_SOURCE_BASE_CS_1                      1
-#define DE_WINDOW_SOURCE_BASE_ADDRESS                   25:0
-
-#define DE_WINDOW_DESTINATION_BASE                      0x100044
-#define DE_WINDOW_DESTINATION_BASE_EXT                  27:27
-#define DE_WINDOW_DESTINATION_BASE_EXT_LOCAL            0
-#define DE_WINDOW_DESTINATION_BASE_EXT_EXTERNAL         1
-#define DE_WINDOW_DESTINATION_BASE_CS                   26:26
-#define DE_WINDOW_DESTINATION_BASE_CS_0                 0
-#define DE_WINDOW_DESTINATION_BASE_CS_1                 1
-#define DE_WINDOW_DESTINATION_BASE_ADDRESS              25:0
-
-#define DE_ALPHA                                        0x100048
-#define DE_ALPHA_VALUE                                  7:0
-
-#define DE_WRAP                                         0x10004C
-#define DE_WRAP_X                                       31:16
-#define DE_WRAP_Y                                       15:0
-
-#define DE_STATUS                                       0x100050
-#define DE_STATUS_CSC                                   1:1
-#define DE_STATUS_CSC_CLEAR                             0
-#define DE_STATUS_CSC_NOT_ACTIVE                        0
-#define DE_STATUS_CSC_ACTIVE                            1
-#define DE_STATUS_2D                                    0:0
-#define DE_STATUS_2D_CLEAR                              0
-#define DE_STATUS_2D_NOT_ACTIVE                         0
-#define DE_STATUS_2D_ACTIVE                             1
-#endif
 /* Color Space Conversion registers. */
 
 #define CSC_Y_SOURCE_BASE                               0x1000C8
index 0bdf3db11df04af03186360a0232b2853bcdf693..241b77b927ee65469c54e64cf141e629af191aaa 100644 (file)
@@ -11,8 +11,8 @@
 #define USE_HW_I2C
 
 #ifdef USE_HW_I2C
-    #define i2cWriteReg hwI2CWriteReg
-    #define i2cReadReg  hwI2CReadReg
+    #define i2cWriteReg sm750_hw_i2c_write_reg
+    #define i2cReadReg  sm750_hw_i2c_read_reg
 #else
     #define i2cWriteReg swI2CWriteReg
     #define i2cReadReg  swI2CReadReg
@@ -130,9 +130,9 @@ long sii164InitChip(
        /* Initialize the i2c bus */
 #ifdef USE_HW_I2C
        /* Use fast mode. */
-       hwI2CInit(1);
+       sm750_hw_i2c_init(1);
 #else
-       swI2CInit(DEFAULT_I2C_SCL, DEFAULT_I2C_SDA);
+       sm750_sw_i2c_init(DEFAULT_I2C_SCL, DEFAULT_I2C_SDA);
 #endif
 
        /* Check if SII164 Chip exists */
index 5133bccf17bd6da3a99df1ec38adf1722d43f2fb..8d644a7cba52f5c534246fffb9d57cf31e76800a 100644 (file)
@@ -15,7 +15,6 @@
 #include "ddk750_swi2c.h"
 #include "ddk750_power.h"
 
-
 /*******************************************************************
  * I2C Software Master Driver:
  * ===========================
@@ -55,8 +54,8 @@
  ******************************************************************/
 
 /* GPIO pins used for this I2C. It ranges from 0 to 63. */
-static unsigned char g_i2cClockGPIO = DEFAULT_I2C_SCL;
-static unsigned char g_i2cDataGPIO = DEFAULT_I2C_SDA;
+static unsigned char sw_i2c_clk_gpio = DEFAULT_I2C_SCL;
+static unsigned char sw_i2c_data_gpio = DEFAULT_I2C_SDA;
 
 /*
  *  Below is the variable declaration for the GPIO pin register usage
@@ -70,19 +69,19 @@ static unsigned char g_i2cDataGPIO = DEFAULT_I2C_SDA;
  */
 
 /* i2c Clock GPIO Register usage */
-static unsigned long g_i2cClkGPIOMuxReg = GPIO_MUX;
-static unsigned long g_i2cClkGPIODataReg = GPIO_DATA;
-static unsigned long g_i2cClkGPIODataDirReg = GPIO_DATA_DIRECTION;
+static unsigned long sw_i2c_clk_gpio_mux_reg = GPIO_MUX;
+static unsigned long sw_i2c_clk_gpio_data_reg = GPIO_DATA;
+static unsigned long sw_i2c_clk_gpio_data_dir_reg = GPIO_DATA_DIRECTION;
 
 /* i2c Data GPIO Register usage */
-static unsigned long g_i2cDataGPIOMuxReg = GPIO_MUX;
-static unsigned long g_i2cDataGPIODataReg = GPIO_DATA;
-static unsigned long g_i2cDataGPIODataDirReg = GPIO_DATA_DIRECTION;
+static unsigned long sw_i2c_data_gpio_mux_reg = GPIO_MUX;
+static unsigned long sw_i2c_data_gpio_data_reg = GPIO_DATA;
+static unsigned long sw_i2c_data_gpio_data_dir_reg = GPIO_DATA_DIRECTION;
 
 /*
  *  This function puts a delay between command
  */
-static void swI2CWait(void)
+static void sw_i2c_wait(void)
 {
        /* find a bug:
         * peekIO method works well before suspend/resume
@@ -91,20 +90,17 @@ static void swI2CWait(void)
         * never finish.
         * use non-ultimate for loop below is safe
         * */
-#if 0
+
     /* Change wait algorithm to use PCI bus clock,
        it's more reliable than counter loop ..
        write 0x61 to 0x3ce and read from 0x3cf
        */
-       while (peekIO(0x3ce, 0x61) & 0x10);
-#else
-       int i, Temp;
+       int i, tmp;
 
        for (i = 0; i < 600; i++) {
-               Temp = i;
-               Temp += i;
+               tmp = i;
+               tmp += i;
        }
-#endif
 }
 
 /*
@@ -119,25 +115,28 @@ static void swI2CWait(void)
  *      signal because the i2c will fail when other device try to drive the
  *      signal due to SM50x will drive the signal to always high.
  */
-void swI2CSCL(unsigned char value)
+static void sw_i2c_scl(unsigned char value)
 {
-       unsigned long ulGPIOData;
-       unsigned long ulGPIODirection;
+       unsigned long gpio_data;
+       unsigned long gpio_dir;
 
-       ulGPIODirection = PEEK32(g_i2cClkGPIODataDirReg);
+       gpio_dir = PEEK32(sw_i2c_clk_gpio_data_dir_reg);
        if (value) {    /* High */
-               /* Set direction as input. This will automatically pull the signal up. */
-               ulGPIODirection &= ~(1 << g_i2cClockGPIO);
-               POKE32(g_i2cClkGPIODataDirReg, ulGPIODirection);
+               /*
+                * Set direction as input. This will automatically
+                * pull the signal up.
+                */
+               gpio_dir &= ~(1 << sw_i2c_clk_gpio);
+               POKE32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir);
        } else {        /* Low */
                /* Set the signal down */
-               ulGPIOData = PEEK32(g_i2cClkGPIODataReg);
-               ulGPIOData &= ~(1 << g_i2cClockGPIO);
-               POKE32(g_i2cClkGPIODataReg, ulGPIOData);
+               gpio_data = PEEK32(sw_i2c_clk_gpio_data_reg);
+               gpio_data &= ~(1 << sw_i2c_clk_gpio);
+               POKE32(sw_i2c_clk_gpio_data_reg, gpio_data);
 
                /* Set direction as output */
-               ulGPIODirection |= (1 << g_i2cClockGPIO);
-               POKE32(g_i2cClkGPIODataDirReg, ulGPIODirection);
+               gpio_dir |= (1 << sw_i2c_clk_gpio);
+               POKE32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir);
        }
 }
 
@@ -153,25 +152,28 @@ void swI2CSCL(unsigned char value)
  *      signal because the i2c will fail when other device try to drive the
  *      signal due to SM50x will drive the signal to always high.
  */
-void swI2CSDA(unsigned char value)
+static void sw_i2c_sda(unsigned char value)
 {
-       unsigned long ulGPIOData;
-       unsigned long ulGPIODirection;
+       unsigned long gpio_data;
+       unsigned long gpio_dir;
 
-       ulGPIODirection = PEEK32(g_i2cDataGPIODataDirReg);
+       gpio_dir = PEEK32(sw_i2c_data_gpio_data_dir_reg);
        if (value) {    /* High */
-               /* Set direction as input. This will automatically pull the signal up. */
-               ulGPIODirection &= ~(1 << g_i2cDataGPIO);
-               POKE32(g_i2cDataGPIODataDirReg, ulGPIODirection);
+               /*
+                * Set direction as input. This will automatically
+                * pull the signal up.
+                */
+               gpio_dir &= ~(1 << sw_i2c_data_gpio);
+               POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
        } else {        /* Low */
                /* Set the signal down */
-               ulGPIOData = PEEK32(g_i2cDataGPIODataReg);
-               ulGPIOData &= ~(1 << g_i2cDataGPIO);
-               POKE32(g_i2cDataGPIODataReg, ulGPIOData);
+               gpio_data = PEEK32(sw_i2c_data_gpio_data_reg);
+               gpio_data &= ~(1 << sw_i2c_data_gpio);
+               POKE32(sw_i2c_data_gpio_data_reg, gpio_data);
 
                /* Set direction as output */
-               ulGPIODirection |= (1 << g_i2cDataGPIO);
-               POKE32(g_i2cDataGPIODataDirReg, ulGPIODirection);
+               gpio_dir |= (1 << sw_i2c_data_gpio);
+               POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
        }
 }
 
@@ -181,21 +183,22 @@ void swI2CSDA(unsigned char value)
  *  Return Value:
  *      The SDA data bit sent by the Slave
  */
-static unsigned char swI2CReadSDA(void)
+static unsigned char sw_i2c_read_sda(void)
 {
-       unsigned long ulGPIODirection;
-       unsigned long ulGPIOData;
+       unsigned long gpio_dir;
+       unsigned long gpio_data;
+       unsigned long dir_mask = 1 << sw_i2c_data_gpio;
 
        /* Make sure that the direction is input (High) */
-       ulGPIODirection = PEEK32(g_i2cDataGPIODataDirReg);
-       if ((ulGPIODirection & (1 << g_i2cDataGPIO)) != (~(1 << g_i2cDataGPIO))) {
-               ulGPIODirection &= ~(1 << g_i2cDataGPIO);
-               POKE32(g_i2cDataGPIODataDirReg, ulGPIODirection);
+       gpio_dir = PEEK32(sw_i2c_data_gpio_data_dir_reg);
+       if ((gpio_dir & dir_mask) != ~dir_mask) {
+               gpio_dir &= ~(1 << sw_i2c_data_gpio);
+               POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
        }
 
        /* Now read the SDA line */
-       ulGPIOData = PEEK32(g_i2cDataGPIODataReg);
-       if (ulGPIOData & (1 << g_i2cDataGPIO))
+       gpio_data = PEEK32(sw_i2c_data_gpio_data_reg);
+       if (gpio_data & (1 << sw_i2c_data_gpio))
                return 1;
        else
                return 0;
@@ -204,7 +207,7 @@ static unsigned char swI2CReadSDA(void)
 /*
  *  This function sends ACK signal
  */
-static void swI2CAck(void)
+static void sw_i2c_ack(void)
 {
        return;  /* Single byte read is ok without it. */
 }
@@ -212,23 +215,23 @@ static void swI2CAck(void)
 /*
  *  This function sends the start command to the slave device
  */
-static void swI2CStart(void)
+static void sw_i2c_start(void)
 {
        /* Start I2C */
-       swI2CSDA(1);
-       swI2CSCL(1);
-       swI2CSDA(0);
+       sw_i2c_sda(1);
+       sw_i2c_scl(1);
+       sw_i2c_sda(0);
 }
 
 /*
  *  This function sends the stop command to the slave device
  */
-static void swI2CStop(void)
+static void sw_i2c_stop(void)
 {
        /* Stop the I2C */
-       swI2CSCL(1);
-       swI2CSDA(0);
-       swI2CSDA(1);
+       sw_i2c_scl(1);
+       sw_i2c_sda(0);
+       sw_i2c_sda(1);
 }
 
 /*
@@ -241,7 +244,7 @@ static void swI2CStop(void)
  *       0   - Success
  *      -1   - Fail to write byte
  */
-static long swI2CWriteByte(unsigned char data)
+static long sw_i2c_write_byte(unsigned char data)
 {
        unsigned char value = data;
        int i;
@@ -249,47 +252,47 @@ static long swI2CWriteByte(unsigned char data)
        /* Sending the data bit by bit */
        for (i = 0; i < 8; i++) {
                /* Set SCL to low */
-               swI2CSCL(0);
+               sw_i2c_scl(0);
 
                /* Send data bit */
                if ((value & 0x80) != 0)
-                       swI2CSDA(1);
+                       sw_i2c_sda(1);
                else
-                       swI2CSDA(0);
+                       sw_i2c_sda(0);
 
-               swI2CWait();
+               sw_i2c_wait();
 
                /* Toggle clk line to one */
-               swI2CSCL(1);
-               swI2CWait();
+               sw_i2c_scl(1);
+               sw_i2c_wait();
 
                /* Shift byte to be sent */
                value = value << 1;
        }
 
        /* Set the SCL Low and SDA High (prepare to get input) */
-       swI2CSCL(0);
-       swI2CSDA(1);
+       sw_i2c_scl(0);
+       sw_i2c_sda(1);
 
        /* Set the SCL High for ack */
-       swI2CWait();
-       swI2CSCL(1);
-       swI2CWait();
+       sw_i2c_wait();
+       sw_i2c_scl(1);
+       sw_i2c_wait();
 
        /* Read SDA, until SDA==0 */
        for (i = 0; i < 0xff; i++) {
-               if (!swI2CReadSDA())
+               if (!sw_i2c_read_sda())
                        break;
 
-               swI2CSCL(0);
-               swI2CWait();
-               swI2CSCL(1);
-               swI2CWait();
+               sw_i2c_scl(0);
+               sw_i2c_wait();
+               sw_i2c_scl(1);
+               sw_i2c_wait();
        }
 
        /* Set the SCL Low and SDA High */
-       swI2CSCL(0);
-       swI2CSDA(1);
+       sw_i2c_scl(0);
+       sw_i2c_sda(1);
 
        if (i < 0xff)
                return 0;
@@ -307,31 +310,31 @@ static long swI2CWriteByte(unsigned char data)
  *  Return Value:
  *      One byte data read from the Slave device
  */
-static unsigned char swI2CReadByte(unsigned char ack)
+static unsigned char sw_i2c_read_byte(unsigned char ack)
 {
        int i;
        unsigned char data = 0;
 
        for (i = 7; i >= 0; i--) {
                /* Set the SCL to Low and SDA to High (Input) */
-               swI2CSCL(0);
-               swI2CSDA(1);
-               swI2CWait();
+               sw_i2c_scl(0);
+               sw_i2c_sda(1);
+               sw_i2c_wait();
 
                /* Set the SCL High */
-               swI2CSCL(1);
-               swI2CWait();
+               sw_i2c_scl(1);
+               sw_i2c_wait();
 
                /* Read data bits from SDA */
-               data |= (swI2CReadSDA() << i);
+               data |= (sw_i2c_read_sda() << i);
        }
 
        if (ack)
-               swI2CAck();
+               sw_i2c_ack();
 
        /* Set the SCL Low and SDA High */
-       swI2CSCL(0);
-       swI2CSDA(1);
+       sw_i2c_scl(0);
+       sw_i2c_sda(1);
 
        return data;
 }
@@ -340,37 +343,37 @@ static unsigned char swI2CReadByte(unsigned char ack)
  * This function initializes GPIO port for SW I2C communication.
  *
  * Parameters:
- *      i2cClkGPIO      - The GPIO pin to be used as i2c SCL
- *      i2cDataGPIO     - The GPIO pin to be used as i2c SDA
+ *      clk_gpio      - The GPIO pin to be used as i2c SCL
+ *      data_gpio     - The GPIO pin to be used as i2c SDA
  *
  * Return Value:
  *      -1   - Fail to initialize the i2c
  *       0   - Success
  */
-static long swI2CInit_SM750LE(unsigned char i2cClkGPIO,
-                             unsigned char i2cDataGPIO)
+static long sm750le_i2c_init(unsigned char clk_gpio,
+                            unsigned char data_gpio)
 {
        int i;
 
        /* Initialize the GPIO pin for the i2c Clock Register */
-       g_i2cClkGPIODataReg = GPIO_DATA_SM750LE;
-       g_i2cClkGPIODataDirReg = GPIO_DATA_DIRECTION_SM750LE;
+       sw_i2c_clk_gpio_data_reg = GPIO_DATA_SM750LE;
+       sw_i2c_clk_gpio_data_dir_reg = GPIO_DATA_DIRECTION_SM750LE;
 
        /* Initialize the Clock GPIO Offset */
-       g_i2cClockGPIO = i2cClkGPIO;
+       sw_i2c_clk_gpio = clk_gpio;
 
        /* Initialize the GPIO pin for the i2c Data Register */
-       g_i2cDataGPIODataReg = GPIO_DATA_SM750LE;
-       g_i2cDataGPIODataDirReg = GPIO_DATA_DIRECTION_SM750LE;
+       sw_i2c_data_gpio_data_reg = GPIO_DATA_SM750LE;
+       sw_i2c_data_gpio_data_dir_reg = GPIO_DATA_DIRECTION_SM750LE;
 
        /* Initialize the Data GPIO Offset */
-       g_i2cDataGPIO = i2cDataGPIO;
+       sw_i2c_data_gpio = data_gpio;
 
        /* Note that SM750LE don't have GPIO MUX and power is always on */
 
        /* Clear the i2c lines. */
        for (i = 0; i < 9; i++)
-               swI2CStop();
+               sw_i2c_stop();
 
        return 0;
 }
@@ -379,55 +382,58 @@ static long swI2CInit_SM750LE(unsigned char i2cClkGPIO,
  * This function initializes the i2c attributes and bus
  *
  * Parameters:
- *      i2cClkGPIO      - The GPIO pin to be used as i2c SCL
- *      i2cDataGPIO     - The GPIO pin to be used as i2c SDA
+ *      clk_gpio      - The GPIO pin to be used as i2c SCL
+ *      data_gpio     - The GPIO pin to be used as i2c SDA
  *
  * Return Value:
  *      -1   - Fail to initialize the i2c
  *       0   - Success
  */
-long swI2CInit(
-       unsigned char i2cClkGPIO,
-       unsigned char i2cDataGPIO
+long sm750_sw_i2c_init(
+       unsigned char clk_gpio,
+       unsigned char data_gpio
 )
 {
        int i;
 
-       /* Return 0 if the GPIO pins to be used is out of range. The range is only from [0..63] */
-       if ((i2cClkGPIO > 31) || (i2cDataGPIO > 31))
+       /*
+        * Return 0 if the GPIO pins to be used is out of range. The
+        * range is only from [0..63]
+        */
+       if ((clk_gpio > 31) || (data_gpio > 31))
                return -1;
 
        if (getChipType() == SM750LE)
-               return swI2CInit_SM750LE(i2cClkGPIO, i2cDataGPIO);
+               return sm750le_i2c_init(clk_gpio, data_gpio);
 
        /* Initialize the GPIO pin for the i2c Clock Register */
-       g_i2cClkGPIOMuxReg = GPIO_MUX;
-       g_i2cClkGPIODataReg = GPIO_DATA;
-       g_i2cClkGPIODataDirReg = GPIO_DATA_DIRECTION;
+       sw_i2c_clk_gpio_mux_reg = GPIO_MUX;
+       sw_i2c_clk_gpio_data_reg = GPIO_DATA;
+       sw_i2c_clk_gpio_data_dir_reg = GPIO_DATA_DIRECTION;
 
        /* Initialize the Clock GPIO Offset */
-       g_i2cClockGPIO = i2cClkGPIO;
+       sw_i2c_clk_gpio = clk_gpio;
 
        /* Initialize the GPIO pin for the i2c Data Register */
-       g_i2cDataGPIOMuxReg = GPIO_MUX;
-       g_i2cDataGPIODataReg = GPIO_DATA;
-       g_i2cDataGPIODataDirReg = GPIO_DATA_DIRECTION;
+       sw_i2c_data_gpio_mux_reg = GPIO_MUX;
+       sw_i2c_data_gpio_data_reg = GPIO_DATA;
+       sw_i2c_data_gpio_data_dir_reg = GPIO_DATA_DIRECTION;
 
        /* Initialize the Data GPIO Offset */
-       g_i2cDataGPIO = i2cDataGPIO;
+       sw_i2c_data_gpio = data_gpio;
 
        /* Enable the GPIO pins for the i2c Clock and Data (GPIO MUX) */
-       POKE32(g_i2cClkGPIOMuxReg,
-                       PEEK32(g_i2cClkGPIOMuxReg) & ~(1 << g_i2cClockGPIO));
-       POKE32(g_i2cDataGPIOMuxReg,
-                       PEEK32(g_i2cDataGPIOMuxReg) & ~(1 << g_i2cDataGPIO));
+       POKE32(sw_i2c_clk_gpio_mux_reg,
+              PEEK32(sw_i2c_clk_gpio_mux_reg) & ~(1 << sw_i2c_clk_gpio));
+       POKE32(sw_i2c_data_gpio_mux_reg,
+              PEEK32(sw_i2c_data_gpio_mux_reg) & ~(1 << sw_i2c_data_gpio));
 
        /* Enable GPIO power */
        enableGPIO(1);
 
        /* Clear the i2c lines. */
        for (i = 0; i < 9; i++)
-               swI2CStop();
+               sw_i2c_stop();
 
        return 0;
 }
@@ -436,36 +442,36 @@ long swI2CInit(
  *  This function reads the slave device's register
  *
  *  Parameters:
- *      deviceAddress   - i2c Slave device address which register
+ *      addr   - i2c Slave device address which register
  *                        to be read from
- *      registerIndex   - Slave device's register to be read
+ *      reg    - Slave device's register to be read
  *
  *  Return Value:
  *      Register value
  */
-unsigned char swI2CReadReg(
-       unsigned char deviceAddress,
-       unsigned char registerIndex
+unsigned char sm750_sw_i2c_read_reg(
+       unsigned char addr,
+       unsigned char reg
 )
 {
        unsigned char data;
 
        /* Send the Start signal */
-       swI2CStart();
+       sw_i2c_start();
 
        /* Send the device address */
-       swI2CWriteByte(deviceAddress);
+       sw_i2c_write_byte(addr);
 
        /* Send the register index */
-       swI2CWriteByte(registerIndex);
+       sw_i2c_write_byte(reg);
 
        /* Get the bus again and get the data from the device read address */
-       swI2CStart();
-       swI2CWriteByte(deviceAddress + 1);
-       data = swI2CReadByte(1);
+       sw_i2c_start();
+       sw_i2c_write_byte(addr + 1);
+       data = sw_i2c_read_byte(1);
 
        /* Stop swI2C and release the bus */
-       swI2CStop();
+       sw_i2c_stop();
 
        return data;
 }
@@ -474,37 +480,37 @@ unsigned char swI2CReadReg(
  *  This function writes a value to the slave device's register
  *
  *  Parameters:
- *      deviceAddress   - i2c Slave device address which register
+ *      addr            - i2c Slave device address which register
  *                        to be written
- *      registerIndex   - Slave device's register to be written
+ *      reg             - Slave device's register to be written
  *      data            - Data to be written to the register
  *
  *  Result:
  *          0   - Success
  *         -1   - Fail
  */
-long swI2CWriteReg(
-       unsigned char deviceAddress,
-       unsigned char registerIndex,
+long sm750_sw_i2c_write_reg(
+       unsigned char addr,
+       unsigned char reg,
        unsigned char data
 )
 {
-       long returnValue = 0;
+       long ret = 0;
 
        /* Send the Start signal */
-       swI2CStart();
+       sw_i2c_start();
 
        /* Send the device address and read the data. All should return success
           in order for the writing processed to be successful
        */
-       if ((swI2CWriteByte(deviceAddress) != 0) ||
-           (swI2CWriteByte(registerIndex) != 0) ||
-           (swI2CWriteByte(data) != 0)) {
-               returnValue = -1;
+       if ((sw_i2c_write_byte(addr) != 0) ||
+           (sw_i2c_write_byte(reg) != 0) ||
+           (sw_i2c_write_byte(data) != 0)) {
+               ret = -1;
        }
 
        /* Stop i2c and release the bus */
-       swI2CStop();
+       sw_i2c_stop();
 
-       return returnValue;
+       return ret;
 }
index 4af2b7aa1f1775544d58f57c0943b7de3d8880e9..b53629cda0956c43fff775e07a08771f5b733a38 100644 (file)
  *      -1   - Fail to initialize the i2c
  *       0   - Success
  */
-long swI2CInit(
-       unsigned char i2cClkGPIO,
-       unsigned char i2cDataGPIO
+long sm750_sw_i2c_init(
+       unsigned char clk_gpio,
+       unsigned char data_gpio
 );
 
 /*
  *  This function reads the slave device's register
  *
  *  Parameters:
- *      deviceAddress   - i2c Slave device address which register
+ *      addr   - i2c Slave device address which register
  *                        to be read from
- *      registerIndex   - Slave device's register to be read
+ *      reg    - Slave device's register to be read
  *
  *  Return Value:
  *      Register value
  */
-unsigned char swI2CReadReg(
-       unsigned char deviceAddress,
-       unsigned char registerIndex
+unsigned char sm750_sw_i2c_read_reg(
+       unsigned char addr,
+       unsigned char reg
 );
 
 /*
  *  This function writes a value to the slave device's register
  *
  *  Parameters:
- *      deviceAddress   - i2c Slave device address which register
+ *      addr            - i2c Slave device address which register
  *                        to be written
- *      registerIndex   - Slave device's register to be written
+ *      reg             - Slave device's register to be written
  *      data            - Data to be written to the register
  *
  *  Result:
  *          0   - Success
  *         -1   - Fail
  */
-long swI2CWriteReg(
-       unsigned char deviceAddress,
-       unsigned char registerIndex,
+long sm750_sw_i2c_write_reg(
+       unsigned char addr,
+       unsigned char reg,
        unsigned char data
 );
 
-/*
- *  These two functions toggle the data on the SCL and SDA I2C lines.
- *  The use of these two functions is not recommended unless it is necessary.
- */
-
-/*
- *  This function set/reset the SCL GPIO pin
- *
- *  Parameters:
- *      value  - Bit value to set to the SCL or SDA (0 = low, 1 = high)
- */
-void swI2CSCL(unsigned char value);
-
-/*
- *  This function set/reset the SDA GPIO pin
- *
- *  Parameters:
- *      value  - Bit value to set to the SCL or SDA (0 = low, 1 = high)
- */
-void swI2CSDA(unsigned char value);
-
 #endif  /* _SWI2C_H_ */
index 07f8afd2defeb82da3b0f7fa502c2ffc661d666e..860e1c288ad5ee2116b7a99c2ec6863566e1dd48 100644 (file)
@@ -1,31 +1,28 @@
-#include<linux/kernel.h>
-#include<linux/module.h>
-#include<linux/errno.h>
-#include<linux/string.h>
-#include<linux/mm.h>
-#include<linux/slab.h>
-#include<linux/delay.h>
-#include<linux/fb.h>
-#include<linux/ioport.h>
-#include<linux/init.h>
-#include<linux/pci.h>
-#include<linux/mm_types.h>
-#include<linux/vmalloc.h>
-#include<linux/pagemap.h>
-#include<linux/screen_info.h>
-#include<linux/vmalloc.h>
-#include<linux/pagemap.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fb.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/mm_types.h>
+#include <linux/vmalloc.h>
+#include <linux/pagemap.h>
+#include <linux/screen_info.h>
+#include <linux/vmalloc.h>
+#include <linux/pagemap.h>
 #include <linux/console.h>
 #include <asm/fb.h>
 #include "sm750.h"
-#include "sm750_hw.h"
 #include "sm750_accel.h"
 #include "sm750_cursor.h"
 
 #include "modedb.h"
 
-int smi_indent;
-
 /*
  * #ifdef __BIG_ENDIAN
  * ssize_t lynxfb_ops_write(struct fb_info *info, const char __user *buf,
@@ -35,10 +32,6 @@ int smi_indent;
  * #endif
  */
 
-typedef void (*PROC_SPEC_SETUP)(struct lynx_share*, char *);
-typedef int (*PROC_SPEC_MAP)(struct lynx_share*, struct pci_dev*);
-typedef int (*PROC_SPEC_INITHW)(struct lynx_share*, struct pci_dev*);
-
 /* common var for all device */
 static int g_hwcursor = 1;
 static int g_noaccel;
@@ -129,16 +122,16 @@ static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor)
                return -ENXIO;
        }
 
-       cursor->disable(cursor);
+       hw_cursor_disable(cursor);
        if (fbcursor->set & FB_CUR_SETSIZE)
-               cursor->setSize(cursor,
-                               fbcursor->image.width,
-                               fbcursor->image.height);
+               hw_cursor_setSize(cursor,
+                                 fbcursor->image.width,
+                                 fbcursor->image.height);
 
        if (fbcursor->set & FB_CUR_SETPOS)
-               cursor->setPos(cursor,
-                              fbcursor->image.dx - info->var.xoffset,
-                              fbcursor->image.dy - info->var.yoffset);
+               hw_cursor_setPos(cursor,
+                                fbcursor->image.dx - info->var.xoffset,
+                                fbcursor->image.dy - info->var.yoffset);
 
        if (fbcursor->set & FB_CUR_SETCMAP) {
                /* get the 16bit color of kernel means */
@@ -152,18 +145,18 @@ static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor)
                      ((info->cmap.green[fbcursor->image.bg_color] & 0xfc00) >> 5) |
                      ((info->cmap.blue[fbcursor->image.bg_color] & 0xf800) >> 11);
 
-               cursor->setColor(cursor, fg, bg);
+               hw_cursor_setColor(cursor, fg, bg);
        }
 
        if (fbcursor->set & (FB_CUR_SETSHAPE | FB_CUR_SETIMAGE)) {
-               cursor->setData(cursor,
-                               fbcursor->rop,
-                               fbcursor->image.data,
-                               fbcursor->mask);
+               hw_cursor_setData(cursor,
+                                 fbcursor->rop,
+                                 fbcursor->image.data,
+                                 fbcursor->mask);
        }
 
        if (fbcursor->enable)
-               cursor->enable(cursor);
+               hw_cursor_enable(cursor);
 
        return 0;
 }
@@ -172,7 +165,7 @@ static void lynxfb_ops_fillrect(struct fb_info *info,
                                const struct fb_fillrect *region)
 {
        struct lynxfb_par *par;
-       struct lynx_share *share;
+       struct sm750_dev *sm750_dev;
        unsigned int base, pitch, Bpp, rop;
        u32 color;
 
@@ -180,7 +173,7 @@ static void lynxfb_ops_fillrect(struct fb_info *info,
                return;
 
        par = info->par;
-       share = par->share;
+       sm750_dev = par->dev;
 
        /*
         * each time 2d function begin to work,below three variable always need
@@ -198,27 +191,27 @@ static void lynxfb_ops_fillrect(struct fb_info *info,
         * If not use spin_lock,system will die if user load driver
         * and immediately unload driver frequently (dual)
         */
-       if (share->dual)
-               spin_lock(&share->slock);
-
-       share->accel.de_fillrect(&share->accel,
-                                base, pitch, Bpp,
-                                region->dx, region->dy,
-                                region->width, region->height,
-                                color, rop);
-       if (share->dual)
-               spin_unlock(&share->slock);
+       if (sm750_dev->dual)
+               spin_lock(&sm750_dev->slock);
+
+       sm750_dev->accel.de_fillrect(&sm750_dev->accel,
+                                    base, pitch, Bpp,
+                                    region->dx, region->dy,
+                                    region->width, region->height,
+                                    color, rop);
+       if (sm750_dev->dual)
+               spin_unlock(&sm750_dev->slock);
 }
 
 static void lynxfb_ops_copyarea(struct fb_info *info,
                                const struct fb_copyarea *region)
 {
        struct lynxfb_par *par;
-       struct lynx_share *share;
+       struct sm750_dev *sm750_dev;
        unsigned int base, pitch, Bpp;
 
        par = info->par;
-       share = par->share;
+       sm750_dev = par->dev;
 
        /*
         * each time 2d function begin to work,below three variable always need
@@ -232,15 +225,16 @@ static void lynxfb_ops_copyarea(struct fb_info *info,
         * If not use spin_lock, system will die if user load driver
         * and immediately unload driver frequently (dual)
         */
-       if (share->dual)
-               spin_lock(&share->slock);
-
-       share->accel.de_copyarea(&share->accel,
-                                base, pitch, region->sx, region->sy,
-                                base, pitch, Bpp, region->dx, region->dy,
-                                region->width, region->height, HW_ROP2_COPY);
-       if (share->dual)
-               spin_unlock(&share->slock);
+       if (sm750_dev->dual)
+               spin_lock(&sm750_dev->slock);
+
+       sm750_dev->accel.de_copyarea(&sm750_dev->accel,
+                                    base, pitch, region->sx, region->sy,
+                                    base, pitch, Bpp, region->dx, region->dy,
+                                    region->width, region->height,
+                                    HW_ROP2_COPY);
+       if (sm750_dev->dual)
+               spin_unlock(&sm750_dev->slock);
 }
 
 static void lynxfb_ops_imageblit(struct fb_info *info,
@@ -249,10 +243,10 @@ static void lynxfb_ops_imageblit(struct fb_info *info,
        unsigned int base, pitch, Bpp;
        unsigned int fgcol, bgcol;
        struct lynxfb_par *par;
-       struct lynx_share *share;
+       struct sm750_dev *sm750_dev;
 
        par = info->par;
-       share = par->share;
+       sm750_dev = par->dev;
        /*
         * each time 2d function begin to work,below three variable always need
         * be set, seems we can put them together in some place
@@ -280,17 +274,17 @@ static void lynxfb_ops_imageblit(struct fb_info *info,
         * If not use spin_lock, system will die if user load driver
         * and immediately unload driver frequently (dual)
         */
-       if (share->dual)
-               spin_lock(&share->slock);
-
-       share->accel.de_imageblit(&share->accel,
-                                 image->data, image->width >> 3, 0,
-                                 base, pitch, Bpp,
-                                 image->dx, image->dy,
-                                 image->width, image->height,
-                                 fgcol, bgcol, HW_ROP2_COPY);
-       if (share->dual)
-               spin_unlock(&share->slock);
+       if (sm750_dev->dual)
+               spin_lock(&sm750_dev->slock);
+
+       sm750_dev->accel.de_imageblit(&sm750_dev->accel,
+                                     image->data, image->width >> 3, 0,
+                                     base, pitch, Bpp,
+                                     image->dx, image->dy,
+                                     image->width, image->height,
+                                     fgcol, bgcol, HW_ROP2_COPY);
+       if (sm750_dev->dual)
+               spin_unlock(&sm750_dev->slock);
 }
 
 static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,
@@ -304,13 +298,12 @@ static int lynxfb_ops_pan_display(struct fb_var_screeninfo *var,
 
        par = info->par;
        crtc = &par->crtc;
-       return crtc->proc_panDisplay(crtc, var, info);
+       return hw_sm750_pan_display(crtc, var, info);
 }
 
 static int lynxfb_ops_set_par(struct fb_info *info)
 {
        struct lynxfb_par *par;
-       struct lynx_share *share;
        struct lynxfb_crtc *crtc;
        struct lynxfb_output *output;
        struct fb_var_screeninfo *var;
@@ -323,7 +316,6 @@ static int lynxfb_ops_set_par(struct fb_info *info)
 
        ret = 0;
        par = info->par;
-       share = par->share;
        crtc = &par->crtc;
        output = &par->output;
        var = &info->var;
@@ -331,7 +323,7 @@ static int lynxfb_ops_set_par(struct fb_info *info)
 
        /* fix structur is not so FIX ... */
        line_length = var->xres_virtual * var->bits_per_pixel / 8;
-       line_length = PADDING(crtc->line_pad, line_length);
+       line_length = ALIGN(line_length, crtc->line_pad);
        fix->line_length = line_length;
        pr_info("fix->line_length = %d\n", fix->line_length);
 
@@ -384,9 +376,9 @@ static int lynxfb_ops_set_par(struct fb_info *info)
                pr_err("pixel bpp format not satisfied\n.");
                return ret;
        }
-       ret = crtc->proc_setMode(crtc, var, fix);
+       ret = hw_sm750_crtc_setMode(crtc, var, fix);
        if (!ret)
-               ret = output->proc_setMode(output, var, fix);
+               ret = hw_sm750_output_setMode(output, var, fix);
        return ret;
 }
 
@@ -402,14 +394,14 @@ static inline unsigned int chan_to_field(unsigned int chan,
 static int lynxfb_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
        struct fb_info *info;
-       struct lynx_share *share;
+       struct sm750_dev *sm750_dev;
        int ret;
 
        if (mesg.event == pdev->dev.power.power_state.event)
                return 0;
 
        ret = 0;
-       share = pci_get_drvdata(pdev);
+       sm750_dev = pci_get_drvdata(pdev);
        switch (mesg.event) {
        case PM_EVENT_FREEZE:
        case PM_EVENT_PRETHAW:
@@ -419,11 +411,11 @@ static int lynxfb_suspend(struct pci_dev *pdev, pm_message_t mesg)
 
        console_lock();
        if (mesg.event & PM_EVENT_SLEEP) {
-               info = share->fbinfo[0];
+               info = sm750_dev->fbinfo[0];
                if (info)
                        /* 1 means do suspend */
                        fb_set_suspend(info, 1);
-               info = share->fbinfo[1];
+               info = sm750_dev->fbinfo[1];
                if (info)
                        /* 1 means do suspend */
                        fb_set_suspend(info, 1);
@@ -434,10 +426,6 @@ static int lynxfb_suspend(struct pci_dev *pdev, pm_message_t mesg)
                        return ret;
                }
 
-               /* set chip to sleep mode */
-               if (share->suspend)
-                       (*share->suspend)(share);
-
                pci_disable_device(pdev);
                ret = pci_set_power_state(pdev, pci_choose_state(pdev, mesg));
                if (ret) {
@@ -454,7 +442,7 @@ static int lynxfb_suspend(struct pci_dev *pdev, pm_message_t mesg)
 static int lynxfb_resume(struct pci_dev *pdev)
 {
        struct fb_info *info;
-       struct lynx_share *share;
+       struct sm750_dev *sm750_dev;
 
        struct lynxfb_par *par;
        struct lynxfb_crtc *crtc;
@@ -463,7 +451,7 @@ static int lynxfb_resume(struct pci_dev *pdev)
        int ret;
 
        ret = 0;
-       share = pci_get_drvdata(pdev);
+       sm750_dev = pci_get_drvdata(pdev);
 
        console_lock();
 
@@ -482,12 +470,10 @@ static int lynxfb_resume(struct pci_dev *pdev)
                }
                pci_set_master(pdev);
        }
-       if (share->resume)
-               (*share->resume)(share);
 
-       hw_sm750_inithw(share, pdev);
+       hw_sm750_inithw(sm750_dev, pdev);
 
-       info = share->fbinfo[0];
+       info = sm750_dev->fbinfo[0];
 
        if (info) {
                par = info->par;
@@ -499,7 +485,7 @@ static int lynxfb_resume(struct pci_dev *pdev)
                fb_set_suspend(info, 0);
        }
 
-       info = share->fbinfo[1];
+       info = sm750_dev->fbinfo[1];
 
        if (info) {
                par = info->par;
@@ -511,6 +497,7 @@ static int lynxfb_resume(struct pci_dev *pdev)
                fb_set_suspend(info, 0);
        }
 
+       pdev->dev.power.power_state.event = PM_EVENT_RESUME;
        console_unlock();
        return ret;
 }
@@ -522,33 +509,17 @@ static int lynxfb_ops_check_var(struct fb_var_screeninfo *var,
        struct lynxfb_par *par;
        struct lynxfb_crtc *crtc;
        struct lynxfb_output *output;
-       struct lynx_share *share;
-       int ret;
        resource_size_t request;
 
        par = info->par;
        crtc = &par->crtc;
        output = &par->output;
-       share = par->share;
-       ret = 0;
 
        pr_debug("check var:%dx%d-%d\n",
                 var->xres,
                 var->yres,
                 var->bits_per_pixel);
 
-       switch (var->bits_per_pixel) {
-       case 8:
-       case 16:
-       case 24: /* support 24 bpp for only lynx712/722/720 */
-       case 32:
-               break;
-       default:
-               pr_err("bpp %d not supported\n", var->bits_per_pixel);
-               ret = -EINVAL;
-               goto exit;
-       }
-
        switch (var->bits_per_pixel) {
        case 8:
                info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
@@ -583,8 +554,8 @@ static int lynxfb_ops_check_var(struct fb_var_screeninfo *var,
                info->fix.visual = FB_VISUAL_TRUECOLOR;
                break;
        default:
-               ret = -EINVAL;
-               break;
+               pr_err("bpp %d not supported\n", var->bits_per_pixel);
+               return -EINVAL;
        }
        var->height = var->width = -1;
        var->accel_flags = 0;/* FB_ACCELF_TEXT; */
@@ -593,18 +564,14 @@ static int lynxfb_ops_check_var(struct fb_var_screeninfo *var,
        request = var->xres_virtual * (var->bits_per_pixel >> 3);
        /* defaulty crtc->channel go with par->index */
 
-       request = PADDING(crtc->line_pad, request);
+       request = ALIGN(request, crtc->line_pad);
        request = request * var->yres_virtual;
        if (crtc->vidmem_size < request) {
                pr_err("not enough video memory for mode\n");
                return -ENOMEM;
        }
 
-       ret = output->proc_checkMode(output, var);
-       if (!ret)
-               ret = crtc->proc_checkMode(crtc, var);
-exit:
-       return ret;
+       return hw_sm750_crtc_checkMode(crtc, var);
 }
 
 static int lynxfb_ops_setcolreg(unsigned regno,
@@ -637,7 +604,7 @@ static int lynxfb_ops_setcolreg(unsigned regno,
                red >>= 8;
                green >>= 8;
                blue >>= 8;
-               ret = crtc->proc_setColReg(crtc, regno, red, green, blue);
+               ret = hw_sm750_setColReg(crtc, regno, red, green, blue);
                goto exit;
        }
 
@@ -675,68 +642,57 @@ static int lynxfb_ops_blank(int blank, struct fb_info *info)
 static int sm750fb_set_drv(struct lynxfb_par *par)
 {
        int ret;
-       struct lynx_share *share;
-       struct sm750_share *spec_share;
+       struct sm750_dev *sm750_dev;
        struct lynxfb_output *output;
        struct lynxfb_crtc *crtc;
 
        ret = 0;
 
-       share = par->share;
-       spec_share = container_of(share, struct sm750_share, share);
+       sm750_dev = par->dev;
        output = &par->output;
        crtc = &par->crtc;
 
-       crtc->vidmem_size = (share->dual) ? share->vidmem_size >> 1 :
-                            share->vidmem_size;
+       crtc->vidmem_size = (sm750_dev->dual) ? sm750_dev->vidmem_size >> 1 :
+                            sm750_dev->vidmem_size;
        /* setup crtc and output member */
-       spec_share->hwCursor = g_hwcursor;
+       sm750_dev->hwCursor = g_hwcursor;
 
-       crtc->proc_setMode = hw_sm750_crtc_setMode;
-       crtc->proc_checkMode = hw_sm750_crtc_checkMode;
-       crtc->proc_setColReg = hw_sm750_setColReg;
-       crtc->proc_panDisplay = hw_sm750_pan_display;
-       crtc->clear = hw_sm750_crtc_clear;
        crtc->line_pad = 16;
        crtc->xpanstep = 8;
        crtc->ypanstep = 1;
        crtc->ywrapstep = 0;
 
-       output->proc_setMode = hw_sm750_output_setMode;
-       output->proc_checkMode = hw_sm750_output_checkMode;
-
-       output->proc_setBLANK = (share->revid == SM750LE_REVISION_ID) ?
+       output->proc_setBLANK = (sm750_dev->revid == SM750LE_REVISION_ID) ?
                                 hw_sm750le_setBLANK : hw_sm750_setBLANK;
-       output->clear = hw_sm750_output_clear;
        /* chip specific phase */
-       share->accel.de_wait = (share->revid == SM750LE_REVISION_ID) ?
-                               hw_sm750le_deWait : hw_sm750_deWait;
-       switch (spec_share->state.dataflow) {
+       sm750_dev->accel.de_wait = (sm750_dev->revid == SM750LE_REVISION_ID) ?
+                                   hw_sm750le_deWait : hw_sm750_deWait;
+       switch (sm750_dev->dataflow) {
        case sm750_simul_pri:
                output->paths = sm750_pnc;
                crtc->channel = sm750_primary;
                crtc->oScreen = 0;
-               crtc->vScreen = share->pvMem;
+               crtc->vScreen = sm750_dev->pvMem;
                pr_info("use simul primary mode\n");
                break;
        case sm750_simul_sec:
                output->paths = sm750_pnc;
                crtc->channel = sm750_secondary;
                crtc->oScreen = 0;
-               crtc->vScreen = share->pvMem;
+               crtc->vScreen = sm750_dev->pvMem;
                break;
        case sm750_dual_normal:
                if (par->index == 0) {
                        output->paths = sm750_panel;
                        crtc->channel = sm750_primary;
                        crtc->oScreen = 0;
-                       crtc->vScreen = share->pvMem;
+                       crtc->vScreen = sm750_dev->pvMem;
                } else {
                        output->paths = sm750_crt;
                        crtc->channel = sm750_secondary;
                        /* not consider of padding stuffs for oScreen,need fix */
-                       crtc->oScreen = (share->vidmem_size >> 1);
-                       crtc->vScreen = share->pvMem + crtc->oScreen;
+                       crtc->oScreen = (sm750_dev->vidmem_size >> 1);
+                       crtc->vScreen = sm750_dev->pvMem + crtc->oScreen;
                }
                break;
        case sm750_dual_swap:
@@ -744,13 +700,13 @@ static int sm750fb_set_drv(struct lynxfb_par *par)
                        output->paths = sm750_panel;
                        crtc->channel = sm750_secondary;
                        crtc->oScreen = 0;
-                       crtc->vScreen = share->pvMem;
+                       crtc->vScreen = sm750_dev->pvMem;
                } else {
                        output->paths = sm750_crt;
                        crtc->channel = sm750_primary;
                        /* not consider of padding stuffs for oScreen,need fix */
-                       crtc->oScreen = (share->vidmem_size >> 1);
-                       crtc->vScreen = share->pvMem + crtc->oScreen;
+                       crtc->oScreen = (sm750_dev->vidmem_size >> 1);
+                       crtc->vScreen = sm750_dev->pvMem + crtc->oScreen;
                }
                break;
        default:
@@ -777,7 +733,7 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
 {
        int i;
        struct lynxfb_par *par;
-       struct lynx_share *share;
+       struct sm750_dev *sm750_dev;
        struct lynxfb_crtc *crtc;
        struct lynxfb_output *output;
        struct fb_var_screeninfo *var;
@@ -801,7 +757,7 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
 
        ret = 0;
        par = (struct lynxfb_par *)info->par;
-       share = par->share;
+       sm750_dev = par->dev;
        crtc = &par->crtc;
        output = &par->output;
        var = &info->var;
@@ -818,28 +774,22 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
         * must be set after crtc member initialized
         */
        crtc->cursor.offset = crtc->oScreen + crtc->vidmem_size - 1024;
-       crtc->cursor.mmio = share->pvReg + 0x800f0 + (int)crtc->channel * 0x140;
+       crtc->cursor.mmio = sm750_dev->pvReg +
+               0x800f0 + (int)crtc->channel * 0x140;
 
        pr_info("crtc->cursor.mmio = %p\n", crtc->cursor.mmio);
        crtc->cursor.maxH = crtc->cursor.maxW = 64;
        crtc->cursor.size = crtc->cursor.maxH * crtc->cursor.maxW * 2 / 8;
-       crtc->cursor.disable = hw_cursor_disable;
-       crtc->cursor.enable = hw_cursor_enable;
-       crtc->cursor.setColor = hw_cursor_setColor;
-       crtc->cursor.setPos = hw_cursor_setPos;
-       crtc->cursor.setSize = hw_cursor_setSize;
-       crtc->cursor.setData = hw_cursor_setData;
-       crtc->cursor.vstart = share->pvMem + crtc->cursor.offset;
-
-       crtc->cursor.share = share;
-               memset_io(crtc->cursor.vstart, 0, crtc->cursor.size);
+       crtc->cursor.vstart = sm750_dev->pvMem + crtc->cursor.offset;
+
+       memset_io(crtc->cursor.vstart, 0, crtc->cursor.size);
        if (!g_hwcursor) {
                lynxfb_ops.fb_cursor = NULL;
-               crtc->cursor.disable(&crtc->cursor);
+               hw_cursor_disable(&crtc->cursor);
        }
 
        /* set info->fbops, must be set before fb_find_mode */
-       if (!share->accel_off) {
+       if (!sm750_dev->accel_off) {
                /* use 2d acceleration */
                lynxfb_ops.fb_fillrect = lynxfb_ops_fillrect;
                lynxfb_ops.fb_copyarea = lynxfb_ops_copyarea;
@@ -903,8 +853,8 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
        par->info = info;
 
        /* set info */
-       line_length = PADDING(crtc->line_pad,
-                             (var->xres_virtual * var->bits_per_pixel / 8));
+       line_length = ALIGN((var->xres_virtual * var->bits_per_pixel / 8),
+                           crtc->line_pad);
 
        info->pseudo_palette = &par->pseudo_palette[0];
        info->screen_base = crtc->vScreen;
@@ -922,7 +872,7 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
 
        strlcpy(fix->id, fixId[index], sizeof(fix->id));
 
-       fix->smem_start = crtc->oScreen + share->vidmem_start;
+       fix->smem_start = crtc->oScreen + sm750_dev->vidmem_start;
        pr_info("fix->smem_start = %lx\n", fix->smem_start);
        /*
         * according to mmap experiment from user space application,
@@ -935,9 +885,9 @@ static int lynxfb_set_fbinfo(struct fb_info *info, int index)
        pr_info("fix->smem_len = %x\n", fix->smem_len);
        info->screen_size = fix->smem_len;
        fix->line_length = line_length;
-       fix->mmio_start = share->vidreg_start;
+       fix->mmio_start = sm750_dev->vidreg_start;
        pr_info("fix->mmio_start = %lx\n", fix->mmio_start);
-       fix->mmio_len = share->vidreg_size;
+       fix->mmio_len = sm750_dev->vidreg_size;
        pr_info("fix->mmio_len = %x\n", fix->mmio_len);
        switch (var->bits_per_pixel) {
        case 8:
@@ -976,27 +926,19 @@ exit:
 }
 
 /*     chip specific g_option configuration routine */
-static void sm750fb_setup(struct lynx_share *share, char *src)
+static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
 {
-       struct sm750_share *spec_share;
        char *opt;
-#ifdef CAP_EXPENSION
-       char *exp_res;
-#endif
        int swap;
 
-       spec_share = container_of(share, struct sm750_share, share);
-#ifdef CAP_EXPENSIION
-       exp_res = NULL;
-#endif
        swap = 0;
 
-       spec_share->state.initParm.chip_clk = 0;
-       spec_share->state.initParm.mem_clk = 0;
-       spec_share->state.initParm.master_clk = 0;
-       spec_share->state.initParm.powerMode = 0;
-       spec_share->state.initParm.setAllEngOff = 0;
-       spec_share->state.initParm.resetMemory = 1;
+       sm750_dev->initParm.chip_clk = 0;
+       sm750_dev->initParm.mem_clk = 0;
+       sm750_dev->initParm.master_clk = 0;
+       sm750_dev->initParm.powerMode = 0;
+       sm750_dev->initParm.setAllEngOff = 0;
+       sm750_dev->initParm.resetMemory = 1;
 
        /* defaultly turn g_hwcursor on for both view */
        g_hwcursor = 3;
@@ -1013,17 +955,13 @@ static void sm750fb_setup(struct lynx_share *share, char *src)
                if (!strncmp(opt, "swap", strlen("swap")))
                        swap = 1;
                else if (!strncmp(opt, "nocrt", strlen("nocrt")))
-                       spec_share->state.nocrt = 1;
+                       sm750_dev->nocrt = 1;
                else if (!strncmp(opt, "36bit", strlen("36bit")))
-                       spec_share->state.pnltype = sm750_doubleTFT;
+                       sm750_dev->pnltype = sm750_doubleTFT;
                else if (!strncmp(opt, "18bit", strlen("18bit")))
-                       spec_share->state.pnltype = sm750_dualTFT;
+                       sm750_dev->pnltype = sm750_dualTFT;
                else if (!strncmp(opt, "24bit", strlen("24bit")))
-                       spec_share->state.pnltype = sm750_24TFT;
-#ifdef CAP_EXPANSION
-               else if (!strncmp(opt, "exp:", strlen("exp:")))
-                       exp_res = opt + strlen("exp:");
-#endif
+                       sm750_dev->pnltype = sm750_24TFT;
                else if (!strncmp(opt, "nohwc0", strlen("nohwc0")))
                        g_hwcursor &= ~0x1;
                else if (!strncmp(opt, "nohwc1", strlen("nohwc1")))
@@ -1042,33 +980,25 @@ static void sm750fb_setup(struct lynx_share *share, char *src)
                        }
                }
        }
-#ifdef CAP_EXPANSION
-       if (getExpRes(exp_res,
-                     &spec_share->state.xLCD,
-                     &spec_share->state.yLCD)) {
-               /* seems exp_res is not valid */
-               spec_share->state.xLCD = spec_share->state.yLCD = 0;
-       }
-#endif
 
 NO_PARAM:
-       if (share->revid != SM750LE_REVISION_ID) {
-               if (share->dual) {
+       if (sm750_dev->revid != SM750LE_REVISION_ID) {
+               if (sm750_dev->dual) {
                        if (swap)
-                               spec_share->state.dataflow = sm750_dual_swap;
+                               sm750_dev->dataflow = sm750_dual_swap;
                        else
-                               spec_share->state.dataflow = sm750_dual_normal;
+                               sm750_dev->dataflow = sm750_dual_normal;
                } else {
                        if (swap)
-                               spec_share->state.dataflow = sm750_simul_sec;
+                               sm750_dev->dataflow = sm750_simul_sec;
                        else
-                               spec_share->state.dataflow = sm750_simul_pri;
+                               sm750_dev->dataflow = sm750_simul_pri;
                }
        } else {
                /* SM750LE only have one crt channel */
-               spec_share->state.dataflow = sm750_simul_sec;
+               sm750_dev->dataflow = sm750_simul_sec;
                /* sm750le do not have complex attributes */
-               spec_share->state.nocrt = 0;
+               sm750_dev->nocrt = 0;
        }
 }
 
@@ -1076,10 +1006,7 @@ static int lynxfb_pci_probe(struct pci_dev *pdev,
                            const struct pci_device_id *ent)
 {
        struct fb_info *info[] = {NULL, NULL};
-       struct lynx_share *share = NULL;
-
-       struct sm750_share *spec_share = NULL;
-       size_t spec_offset = 0;
+       struct sm750_dev *sm750_dev = NULL;
        int fbidx;
 
        /* enable device */
@@ -1088,69 +1015,62 @@ static int lynxfb_pci_probe(struct pci_dev *pdev,
                goto err_enable;
        }
 
-       /*
-        * though offset of share in sm750_share is 0,
-        * we use this marcro as the same
-        */
-       spec_offset = offsetof(struct sm750_share, share);
-
-       spec_share = kzalloc(sizeof(*spec_share), GFP_KERNEL);
-       if (!spec_share) {
+       sm750_dev = kzalloc(sizeof(*sm750_dev), GFP_KERNEL);
+       if (!sm750_dev) {
                pr_err("Could not allocate memory for share.\n");
                goto err_share;
        }
 
-       /* setting share structure */
-       share = (struct lynx_share *)(&(spec_share->share));
-       share->fbinfo[0] = share->fbinfo[1] = NULL;
-       share->devid = pdev->device;
-       share->revid = pdev->revision;
-
-       pr_info("share->revid = %02x\n", share->revid);
-       share->pdev = pdev;
-       share->mtrr_off = g_nomtrr;
-       share->mtrr.vram = 0;
-       share->accel_off = g_noaccel;
-       share->dual = g_dualview;
-       spin_lock_init(&share->slock);
-
-       if (!share->accel_off) {
+       sm750_dev->fbinfo[0] = sm750_dev->fbinfo[1] = NULL;
+       sm750_dev->devid = pdev->device;
+       sm750_dev->revid = pdev->revision;
+
+       pr_info("share->revid = %02x\n", sm750_dev->revid);
+       sm750_dev->pdev = pdev;
+       sm750_dev->mtrr_off = g_nomtrr;
+       sm750_dev->mtrr.vram = 0;
+       sm750_dev->accel_off = g_noaccel;
+       sm750_dev->dual = g_dualview;
+       spin_lock_init(&sm750_dev->slock);
+
+       if (!sm750_dev->accel_off) {
                /*
                 * hook deInit and 2d routines, notes that below hw_xxx
                 * routine can work on most of lynx chips
                 * if some chip need specific function,
                 * please hook it in smXXX_set_drv routine
                 */
-               share->accel.de_init = hw_de_init;
-               share->accel.de_fillrect = hw_fillrect;
-               share->accel.de_copyarea = hw_copyarea;
-               share->accel.de_imageblit = hw_imageblit;
+               sm750_dev->accel.de_init = hw_de_init;
+               sm750_dev->accel.de_fillrect = hw_fillrect;
+               sm750_dev->accel.de_copyarea = hw_copyarea;
+               sm750_dev->accel.de_imageblit = hw_imageblit;
                pr_info("enable 2d acceleration\n");
        } else {
                pr_info("disable 2d acceleration\n");
        }
 
        /* call chip specific setup routine  */
-       sm750fb_setup(share, g_settings);
+       sm750fb_setup(sm750_dev, g_settings);
 
        /* call chip specific mmap routine */
-       if (hw_sm750_map(share, pdev)) {
+       if (hw_sm750_map(sm750_dev, pdev)) {
                pr_err("Memory map failed\n");
                goto err_map;
        }
 
-       if (!share->mtrr_off)
-               share->mtrr.vram = arch_phys_wc_add(share->vidmem_start,
-                                                   share->vidmem_size);
+       if (!sm750_dev->mtrr_off)
+               sm750_dev->mtrr.vram = arch_phys_wc_add(sm750_dev->vidmem_start,
+                                                       sm750_dev->vidmem_size);
 
-       memset_io(share->pvMem, 0, share->vidmem_size);
+       memset_io(sm750_dev->pvMem, 0, sm750_dev->vidmem_size);
 
-       pr_info("sm%3x mmio address = %p\n", share->devid, share->pvReg);
+       pr_info("sm%3x mmio address = %p\n", sm750_dev->devid,
+               sm750_dev->pvReg);
 
-       pci_set_drvdata(pdev, share);
+       pci_set_drvdata(pdev, sm750_dev);
 
        /* call chipInit routine */
-       hw_sm750_inithw(share, pdev);
+       hw_sm750_inithw(sm750_dev, pdev);
 
        /* allocate frame buffer info structor according to g_dualview */
        fbidx = 0;
@@ -1167,9 +1087,9 @@ ALLOC_FB:
                int errno;
 
                pr_info("framebuffer #%d alloc okay\n", fbidx);
-               share->fbinfo[fbidx] = info[fbidx];
+               sm750_dev->fbinfo[fbidx] = info[fbidx];
                par = info[fbidx]->par;
-               par->share = share;
+               par->dev = sm750_dev;
 
                /* set fb_info structure */
                if (lynxfb_set_fbinfo(info[fbidx], fbidx)) {
@@ -1197,7 +1117,7 @@ ALLOC_FB:
 
        /* no dual view by far */
        fbidx++;
-       if (share->dual && fbidx < 2)
+       if (sm750_dev->dual && fbidx < 2)
                goto ALLOC_FB;
 
        return 0;
@@ -1212,7 +1132,7 @@ err_info0_set:
        framebuffer_release(info[0]);
 err_info0_alloc:
 err_map:
-       kfree(spec_share);
+       kfree(sm750_dev);
 err_share:
 err_enable:
        return -ENODEV;
@@ -1221,34 +1141,29 @@ err_enable:
 static void lynxfb_pci_remove(struct pci_dev *pdev)
 {
        struct fb_info *info;
-       struct lynx_share *share;
-       void *spec_share;
+       struct sm750_dev *sm750_dev;
        struct lynxfb_par *par;
        int cnt;
 
        cnt = 2;
-       share = pci_get_drvdata(pdev);
+       sm750_dev = pci_get_drvdata(pdev);
 
        while (cnt-- > 0) {
-               info = share->fbinfo[cnt];
+               info = sm750_dev->fbinfo[cnt];
                if (!info)
                        continue;
                par = info->par;
 
                unregister_framebuffer(info);
-               /* clean crtc & output allocations */
-               par->crtc.clear(&par->crtc);
-               par->output.clear(&par->output);
                /* release frame buffer */
                framebuffer_release(info);
        }
-       arch_phys_wc_del(share->mtrr.vram);
+       arch_phys_wc_del(sm750_dev->mtrr.vram);
 
-       iounmap(share->pvReg);
-       iounmap(share->pvMem);
-       spec_share = container_of(share, struct sm750_share, share);
+       iounmap(sm750_dev->pvReg);
+       iounmap(sm750_dev->pvMem);
        kfree(g_settings);
-       kfree(spec_share);
+       kfree(sm750_dev);
        pci_set_drvdata(pdev, NULL);
 }
 
index 5bc445571b48fe62c5933370daded21430d05934..b0a93cdc7292a27137da5869d83b7517f51876de 100644 (file)
@@ -1,18 +1,51 @@
 #ifndef LYNXDRV_H_
 #define LYNXDRV_H_
 
-
-
 #define FB_ACCEL_SMI 0xab
-/* please use revision id to distinguish sm750le and sm750*/
-#define SPC_SM750 0
 
-#define MB(x) ((x)<<20)
 #define MHZ(x) ((x) * 1000000)
-/* align should be 2,4,8,16 */
-#define PADDING(align, data) (((data)+(align)-1)&(~((align) - 1)))
-extern int smi_indent;
 
+#define DEFAULT_SM750_CHIP_CLOCK       290
+#define DEFAULT_SM750LE_CHIP_CLOCK     333
+#ifndef SM750LE_REVISION_ID
+#define SM750LE_REVISION_ID ((unsigned char)0xfe)
+#endif
+
+enum sm750_pnltype {
+       sm750_24TFT = 0,        /* 24bit tft */
+       sm750_dualTFT = 2,      /* dual 18 bit tft */
+       sm750_doubleTFT = 1,    /* 36 bit double pixel tft */
+};
+
+/* vga channel is not concerned  */
+enum sm750_dataflow {
+       sm750_simul_pri,        /* primary => all head */
+       sm750_simul_sec,        /* secondary => all head */
+       sm750_dual_normal,      /* primary => panel head and secondary => crt */
+       sm750_dual_swap,        /* primary => crt head and secondary => panel */
+};
+
+enum sm750_channel {
+       sm750_primary = 0,
+       /* enum value equal to the register filed data */
+       sm750_secondary = 1,
+};
+
+enum sm750_path {
+       sm750_panel = 1,
+       sm750_crt = 2,
+       sm750_pnc = 3,  /* panel and crt */
+};
+
+struct init_status {
+       ushort powerMode;
+       /* below three clocks are in unit of MHZ*/
+       ushort chip_clk;
+       ushort mem_clk;
+       ushort master_clk;
+       ushort setAllEngOff;
+       ushort resetMemory;
+};
 
 struct lynx_accel {
        /* base virtual address of DPR registers */
@@ -38,10 +71,7 @@ struct lynx_accel {
 
 };
 
-/* lynx_share stands for a presentation of two frame buffer
-   that use one smi adaptor , it is similar to a basic class of C++
-*/
-struct lynx_share {
+struct sm750_dev {
        /* common members */
        u16 devid;
        u8 revid;
@@ -50,10 +80,10 @@ struct lynx_share {
        struct lynx_accel accel;
        int accel_off;
        int dual;
-               int mtrr_off;
-               struct{
-                       int vram;
-               } mtrr;
+       int mtrr_off;
+       struct{
+               int vram;
+       } mtrr;
        /* all smi graphic adaptor got below attributes */
        unsigned long vidmem_start;
        unsigned long vidreg_start;
@@ -63,9 +93,19 @@ struct lynx_share {
        unsigned char __iomem *pvMem;
        /* locks*/
        spinlock_t slock;
-       /* function pointers */
-       void (*suspend)(struct lynx_share *);
-       void (*resume)(struct lynx_share *);
+
+       struct init_status initParm;
+       enum sm750_pnltype pnltype;
+       enum sm750_dataflow dataflow;
+       int nocrt;
+
+       /*
+        * 0: no hardware cursor
+        * 1: primary crtc hw cursor enabled,
+        * 2: secondary crtc hw cursor enabled
+        * 3: both ctrc hw cursor enabled
+        */
+       int hwCursor;
 };
 
 struct lynx_cursor {
@@ -81,15 +121,6 @@ struct lynx_cursor {
        int offset;
        /* mmio addr of hw cursor */
        volatile char __iomem *mmio;
-       /* the lynx_share of this adaptor */
-       struct lynx_share *share;
-       /* proc_routines */
-       void (*enable)(struct lynx_cursor *);
-       void (*disable)(struct lynx_cursor *);
-       void (*setSize)(struct lynx_cursor *, int, int);
-       void (*setPos)(struct lynx_cursor *, int, int);
-       void (*setColor)(struct lynx_cursor *, u32, u32);
-       void (*setData)(struct lynx_cursor *, u16, const u8*, const u8*);
 };
 
 struct lynxfb_crtc {
@@ -108,17 +139,6 @@ struct lynxfb_crtc {
 
        void *priv;
 
-       int (*proc_setMode)(struct lynxfb_crtc*,
-                                               struct fb_var_screeninfo*,
-                                               struct fb_fix_screeninfo*);
-
-       int (*proc_checkMode)(struct lynxfb_crtc*, struct fb_var_screeninfo*);
-       int (*proc_setColReg)(struct lynxfb_crtc*, ushort, ushort, ushort, ushort);
-       void (*clear)(struct lynxfb_crtc *);
-       /* pan display */
-       int (*proc_panDisplay)(struct lynxfb_crtc *,
-                              const struct fb_var_screeninfo *,
-                              const struct fb_info *);
        /* cursor information */
        struct lynx_cursor cursor;
 };
@@ -140,13 +160,7 @@ struct lynxfb_output {
        */
        void *priv;
 
-       int (*proc_setMode)(struct lynxfb_output*,
-                                               struct fb_var_screeninfo*,
-                                               struct fb_fix_screeninfo*);
-
-       int (*proc_checkMode)(struct lynxfb_output*, struct fb_var_screeninfo*);
        int (*proc_setBLANK)(struct lynxfb_output*, int);
-       void  (*clear)(struct lynxfb_output *);
 };
 
 struct lynxfb_par {
@@ -156,20 +170,9 @@ struct lynxfb_par {
        struct lynxfb_crtc crtc;
        struct lynxfb_output output;
        struct fb_info *info;
-       struct lynx_share *share;
+       struct sm750_dev *dev;
 };
 
-#ifndef offsetof
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
-
-#define PS_TO_HZ(ps)   \
-                       ({ \
-                       unsigned long long hz = 1000*1000*1000*1000ULL; \
-                       do_div(hz, ps); \
-                       (unsigned long)hz; })
-
 static inline unsigned long ps_to_hz(unsigned int psvalue)
 {
        unsigned long long numerator = 1000*1000*1000*1000ULL;
@@ -178,5 +181,22 @@ static inline unsigned long ps_to_hz(unsigned int psvalue)
        return (unsigned long)numerator;
 }
 
+int hw_sm750_map(struct sm750_dev *sm750_dev, struct pci_dev *pdev);
+int hw_sm750_inithw(struct sm750_dev*, struct pci_dev *);
+void hw_sm750_initAccel(struct sm750_dev *);
+int hw_sm750_deWait(void);
+int hw_sm750le_deWait(void);
+
+int hw_sm750_output_setMode(struct lynxfb_output*, struct fb_var_screeninfo*,
+                           struct fb_fix_screeninfo*);
+int hw_sm750_crtc_checkMode(struct lynxfb_crtc*, struct fb_var_screeninfo*);
+int hw_sm750_crtc_setMode(struct lynxfb_crtc*, struct fb_var_screeninfo*,
+                         struct fb_fix_screeninfo*);
+int hw_sm750_setColReg(struct lynxfb_crtc*, ushort, ushort, ushort, ushort);
+int hw_sm750_setBLANK(struct lynxfb_output*, int);
+int hw_sm750le_setBLANK(struct lynxfb_output*, int);
+int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
+                        const struct fb_var_screeninfo *var,
+                        const struct fb_info *info);
 
 #endif
index 1dd06a2e4edeb1a826278fd7df103a8a4bfe7c4d..43e59725920ceec84d14b98cd4d3115eac2f3e6a 100644 (file)
@@ -1,19 +1,19 @@
-#include<linux/module.h>
-#include<linux/kernel.h>
-#include<linux/errno.h>
-#include<linux/string.h>
-#include<linux/mm.h>
-#include<linux/slab.h>
-#include<linux/delay.h>
-#include<linux/fb.h>
-#include<linux/ioport.h>
-#include<linux/init.h>
-#include<linux/pci.h>
-#include<linux/vmalloc.h>
-#include<linux/pagemap.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fb.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/vmalloc.h>
+#include <linux/pagemap.h>
 #include <linux/console.h>
-#include<linux/platform_device.h>
-#include<linux/screen_info.h>
+#include <linux/platform_device.h>
+#include <linux/screen_info.h>
 
 #include "sm750.h"
 #include "sm750_accel.h"
@@ -233,20 +233,10 @@ unsigned int rop2)   /* ROP value */
         */
        write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase); /* dpr44 */
 
-#if 0
     /* Program pitch (distance between the 1st points of two adjacent lines).
        Note that input pitch is BYTE value, but the 2D Pitch register uses
        pixel values. Need Byte to pixel conversion.
     */
-       if (Bpp == 3) {
-                       sx *= 3;
-                       dx *= 3;
-                       width *= 3;
-               write_dpr(accel, DE_PITCH,
-                               FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) |
-                               FIELD_VALUE(0, DE_PITCH, SOURCE,      sPitch)); /* dpr10 */
-       } else
-#endif
        {
                write_dpr(accel, DE_PITCH,
                                FIELD_VALUE(0, DE_PITCH, DESTINATION, (dPitch/Bpp)) |
@@ -344,21 +334,10 @@ int hw_imageblit(struct lynx_accel *accel,
         It is an address offset (128 bit aligned) from the beginning of frame buffer.
         */
        write_dpr(accel, DE_WINDOW_DESTINATION_BASE, dBase);
-#if 0
     /* Program pitch (distance between the 1st points of two adjacent lines).
        Note that input pitch is BYTE value, but the 2D Pitch register uses
        pixel values. Need Byte to pixel conversion.
     */
-       if (bytePerPixel == 3) {
-               dx *= 3;
-               width *= 3;
-               startBit *= 3;
-               write_dpr(accel, DE_PITCH,
-                               FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch) |
-                               FIELD_VALUE(0, DE_PITCH, SOURCE,      dPitch)); /* dpr10 */
-
-       } else
-#endif
        {
                write_dpr(accel, DE_PITCH,
                                FIELD_VALUE(0, DE_PITCH, DESTINATION, dPitch/bytePerPixel) |
index a94a4bbff45096e24de516f3d5cc29f8bf49fe4d..3b7ce9275f5108c9f26d949566ceafa2b7e16736 100644 (file)
@@ -1,19 +1,19 @@
-#include<linux/module.h>
-#include<linux/kernel.h>
-#include<linux/errno.h>
-#include<linux/string.h>
-#include<linux/mm.h>
-#include<linux/slab.h>
-#include<linux/delay.h>
-#include<linux/fb.h>
-#include<linux/ioport.h>
-#include<linux/init.h>
-#include<linux/pci.h>
-#include<linux/vmalloc.h>
-#include<linux/pagemap.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fb.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/vmalloc.h>
+#include <linux/pagemap.h>
 #include <linux/console.h>
-#include<linux/platform_device.h>
-#include<linux/screen_info.h>
+#include <linux/platform_device.h>
+#include <linux/screen_info.h>
 
 #include "sm750.h"
 #include "sm750_help.h"
@@ -129,26 +129,6 @@ void hw_cursor_setData(struct lynx_cursor *cursor,
                mask = *pmsk++;
                data = 0;
 
-               /* either method below works well,
-                * but method 2 shows no lag
-                * and method 1 seems a bit wrong*/
-#if 0
-               if (rop == ROP_XOR)
-                       opr = mask ^ color;
-               else
-                       opr = mask & color;
-
-               for (j = 0; j < 8; j++) {
-
-                       if (opr & (0x80 >> j)) {
-                               /* use fg color,id = 2 */
-                               data |= 2 << (j*2);
-                       } else {
-                               /* use bg color,id = 1 */
-                               data |= 1 << (j*2);
-                       }
-               }
-#else
                for (j = 0; j < 8; j++) {
                        if (mask & (0x80>>j)) {
                                if (rop == ROP_XOR)
@@ -160,15 +140,10 @@ void hw_cursor_setData(struct lynx_cursor *cursor,
                                data |= ((opr & (0x80>>j))?2:1)<<(j*2);
                        }
                }
-#endif
                iowrite16(data, pbuffer);
 
                /* assume pitch is 1,2,4,8,...*/
-#if 0
-               if (!((i+1)&(pitch-1)))   /* below line equal to is line */
-#else
                if ((i+1) % pitch == 0)
-#endif
                {
                        /* need a return */
                        pstart += offset;
@@ -209,29 +184,10 @@ void hw_cursor_setData2(struct lynx_cursor *cursor,
                mask = *pmsk++;
                data = 0;
 
-               /* either method below works well, but method 2 shows no lag */
-#if 0
-               if (rop == ROP_XOR)
-                       opr = mask ^ color;
-               else
-                       opr = mask & color;
-
-               for (j = 0; j < 8; j++) {
-
-                       if (opr & (0x80 >> j)) {
-                               /* use fg color,id = 2 */
-                               data |= 2 << (j*2);
-                       } else {
-                               /* use bg color,id = 1 */
-                               data |= 1 << (j*2);
-                       }
-               }
-#else
                for (j = 0; j < 8; j++) {
                        if (mask & (1<<j))
                                data |= ((color & (1<<j))?1:2)<<(j*2);
                }
-#endif
                iowrite16(data, pbuffer);
 
                /* assume pitch is 1,2,4,8,...*/
index 8dc6bd22f5db87e3a4349e1f67d56116b66d6311..c070cf25a7d670b26c2e36cb4cf8e9f164930ea9 100644 (file)
@@ -1,20 +1,6 @@
 #ifndef LYNX_HELP_H__
 #define LYNX_HELP_H__
 
-/*  FIELD MACROS */
-#define _LSB(f)             (0 ? f)
-#define _MSB(f)             (1 ? f)
-#define _COUNT(f)           (_MSB(f) - _LSB(f) + 1)
-
-#define RAW_MASK(f)         (0xFFFFFFFF >> (32 - _COUNT(f)))
-#define GET_MASK(f)         (RAW_MASK(f) << _LSB(f))
-#define GET_FIELD(d, f)     (((d) >> _LSB(f)) & RAW_MASK(f))
-#define TEST_FIELD(d, f, v) (GET_FIELD(d, f) == f ## _ ## v)
-#define SET_FIELD(d, f, v)  (((d) & ~GET_MASK(f)) | \
-                           (((f ## _ ## v) & RAW_MASK(f)) << _LSB(f)))
-#define SET_FIELDV(d, f, v) (((d) & ~GET_MASK(f)) | \
-                           (((v) & RAW_MASK(f)) << _LSB(f)))
-
 /* Internal macros */
 #define _F_START(f)             (0 ? f)
 #define _F_END(f)               (1 ? f)
@@ -43,7 +29,7 @@
 
 #define FIELD_CLEAR(reg, field) \
 ( \
-       ~ _F_MASK(reg ## _ ## field) \
+       ~_F_MASK(reg ## _ ## field) \
 )
 
 /* Field Macros */
 #define FIELD_END(field)                (1 ? field)
 #define FIELD_SIZE(field)               (1 + FIELD_END(field) - FIELD_START(field))
 #define FIELD_MASK(field)               (((1 << (FIELD_SIZE(field)-1)) | ((1 << (FIELD_SIZE(field)-1)) - 1)) << FIELD_START(field))
-#define FIELD_NORMALIZE(reg, field)     (((reg) & FIELD_MASK(field)) >> FIELD_START(field))
-#define FIELD_DENORMALIZE(field, value) (((value) << FIELD_START(field)) & FIELD_MASK(field))
-
-#define FIELD_INIT(reg, field, value)   FIELD_DENORMALIZE(reg ## _ ## field, \
-                                                         reg ## _ ## field ## _ ## value)
-#define FIELD_INIT_VAL(reg, field, value) \
-       (FIELD_DENORMALIZE(reg ## _ ## field, value))
-#define FIELD_VAL_SET(x, r, f, v)       x = x & ~FIELD_MASK(r ## _ ## f) \
-                                       | FIELD_DENORMALIZE(r ## _ ## f, r ## _ ## f ## _ ## v)
-
-#define RGB(r, g, b) \
-( \
-       (unsigned long) (((r) << 16) | ((g) << 8) | (b)) \
-)
-
-#define RGB16(r, g, b) \
-( \
-       (unsigned short) ((((r) & 0xF8) << 8) | (((g) & 0xFC) << 3) | (((b) & 0xF8) >> 3)) \
-)
 
 static inline unsigned int absDiff(unsigned int a, unsigned int b)
 {
@@ -81,8 +48,6 @@ static inline unsigned int absDiff(unsigned int a, unsigned int b)
 
 /* n / d + 1 / 2 = (2n + d) / 2d */
 #define roundedDiv(num, denom) ((2 * (num) + (denom)) / (2 * (denom)))
-#define MB(x) ((x)<<20)
-#define KB(x) ((x)<<10)
 #define MHz(x) ((x) * 1000000)
 
 
index 7317ba9b7fe5c1b289280c23a8cacd1586b9c8e6..41822c6c0380fa1da2456adad317b3e731e8a4d7 100644 (file)
@@ -1,42 +1,39 @@
 #include <linux/version.h>
-#include<linux/module.h>
-#include<linux/kernel.h>
-#include<linux/errno.h>
-#include<linux/string.h>
-#include<linux/mm.h>
-#include<linux/slab.h>
-#include<linux/delay.h>
-#include<linux/fb.h>
-#include<linux/ioport.h>
-#include<linux/init.h>
-#include<linux/pci.h>
-#include<linux/vmalloc.h>
-#include<linux/pagemap.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/fb.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/vmalloc.h>
+#include <linux/pagemap.h>
 #include <linux/console.h>
 #ifdef CONFIG_MTRR
 #include <asm/mtrr.h>
 #endif
-#include<linux/platform_device.h>
-#include<linux/screen_info.h>
+#include <linux/platform_device.h>
+#include <linux/screen_info.h>
+#include <linux/sizes.h>
 
 #include "sm750.h"
-#include "sm750_hw.h"
 #include "ddk750.h"
 #include "sm750_accel.h"
 
-int hw_sm750_map(struct lynx_share *share, struct pci_dev *pdev)
+int hw_sm750_map(struct sm750_dev *sm750_dev, struct pci_dev *pdev)
 {
        int ret;
-       struct sm750_share *spec_share;
 
-
-       spec_share = container_of(share, struct sm750_share, share);
        ret = 0;
 
-       share->vidreg_start  = pci_resource_start(pdev, 1);
-       share->vidreg_size = MB(2);
+       sm750_dev->vidreg_start  = pci_resource_start(pdev, 1);
+       sm750_dev->vidreg_size = SZ_2M;
 
-       pr_info("mmio phyAddr = %lx\n", share->vidreg_start);
+       pr_info("mmio phyAddr = %lx\n", sm750_dev->vidreg_start);
 
        /* reserve the vidreg space of smi adaptor
         * if you do this, u need to add release region code
@@ -50,48 +47,41 @@ int hw_sm750_map(struct lynx_share *share, struct pci_dev *pdev)
        }
 
        /* now map mmio and vidmem*/
-       share->pvReg = ioremap_nocache(share->vidreg_start, share->vidreg_size);
-       if (!share->pvReg) {
+       sm750_dev->pvReg = ioremap_nocache(sm750_dev->vidreg_start,
+                                          sm750_dev->vidreg_size);
+       if (!sm750_dev->pvReg) {
                pr_err("mmio failed\n");
                ret = -EFAULT;
                goto exit;
        } else {
-               pr_info("mmio virtual addr = %p\n", share->pvReg);
+               pr_info("mmio virtual addr = %p\n", sm750_dev->pvReg);
        }
 
 
-       share->accel.dprBase = share->pvReg + DE_BASE_ADDR_TYPE1;
-       share->accel.dpPortBase = share->pvReg + DE_PORT_ADDR_TYPE1;
+       sm750_dev->accel.dprBase = sm750_dev->pvReg + DE_BASE_ADDR_TYPE1;
+       sm750_dev->accel.dpPortBase = sm750_dev->pvReg + DE_PORT_ADDR_TYPE1;
 
-       ddk750_set_mmio(share->pvReg, share->devid, share->revid);
+       ddk750_set_mmio(sm750_dev->pvReg, sm750_dev->devid, sm750_dev->revid);
 
-       share->vidmem_start = pci_resource_start(pdev, 0);
+       sm750_dev->vidmem_start = pci_resource_start(pdev, 0);
        /* don't use pdev_resource[x].end - resource[x].start to
         * calculate the resource size,its only the maximum available
         * size but not the actual size,use
-        * @hw_sm750_getVMSize function can be safe.
+        * @ddk750_getVMSize function can be safe.
         * */
-       share->vidmem_size = hw_sm750_getVMSize(share);
+       sm750_dev->vidmem_size = ddk750_getVMSize();
        pr_info("video memory phyAddr = %lx, size = %u bytes\n",
-       share->vidmem_start, share->vidmem_size);
+               sm750_dev->vidmem_start, sm750_dev->vidmem_size);
 
        /* reserve the vidmem space of smi adaptor */
-#if 0
-       ret = pci_request_region(pdev, 0, _moduleName_);
-       if (ret) {
-               pr_err("Can not request PCI regions.\n");
-               goto exit;
-       }
-#endif
-
-       share->pvMem = ioremap_wc(share->vidmem_start, share->vidmem_size);
-
-       if (!share->pvMem) {
+       sm750_dev->pvMem = ioremap_wc(sm750_dev->vidmem_start,
+                                     sm750_dev->vidmem_size);
+       if (!sm750_dev->pvMem) {
                pr_err("Map video memory failed\n");
                ret = -EFAULT;
                goto exit;
        } else {
-               pr_info("video memory vaddr = %p\n", share->pvMem);
+               pr_info("video memory vaddr = %p\n", sm750_dev->pvMem);
        }
 exit:
        return ret;
@@ -99,13 +89,11 @@ exit:
 
 
 
-int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
+int hw_sm750_inithw(struct sm750_dev *sm750_dev, struct pci_dev *pdev)
 {
-       struct sm750_share *spec_share;
        struct init_status *parm;
 
-       spec_share = container_of(share, struct sm750_share, share);
-       parm = &spec_share->state.initParm;
+       parm = &sm750_dev->initParm;
        if (parm->chip_clk == 0)
                parm->chip_clk = (getChipType() == SM750LE) ?
                                                DEFAULT_SM750LE_CHIP_CLOCK :
@@ -116,22 +104,16 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
        if (parm->master_clk == 0)
                parm->master_clk = parm->chip_clk/3;
 
-       ddk750_initHw((initchip_param_t *)&spec_share->state.initParm);
+       ddk750_initHw((initchip_param_t *)&sm750_dev->initParm);
        /* for sm718,open pci burst */
-       if (share->devid == 0x718) {
+       if (sm750_dev->devid == 0x718) {
                POKE32(SYSTEM_CTRL,
                                FIELD_SET(PEEK32(SYSTEM_CTRL), SYSTEM_CTRL, PCI_BURST, ON));
        }
 
-       /* sm750 use sii164, it can be setup with default value
-        * by on power, so initDVIDisp can be skipped */
-#if 0
-       ddk750_initDVIDisp();
-#endif
-
        if (getChipType() != SM750LE) {
                /* does user need CRT ?*/
-               if (spec_share->state.nocrt) {
+               if (sm750_dev->nocrt) {
                        POKE32(MISC_CTRL,
                                        FIELD_SET(PEEK32(MISC_CTRL),
                                        MISC_CTRL,
@@ -153,7 +135,7 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
                                        DPMS, VPHP));
                }
 
-               switch (spec_share->state.pnltype) {
+               switch (sm750_dev->pnltype) {
                case sm750_doubleTFT:
                case sm750_24TFT:
                case sm750_dualTFT:
@@ -161,7 +143,7 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
                        FIELD_VALUE(PEEK32(PANEL_DISPLAY_CTRL),
                                                PANEL_DISPLAY_CTRL,
                                                TFT_DISP,
-                                               spec_share->state.pnltype));
+                                               sm750_dev->pnltype));
                break;
                }
        } else {
@@ -169,49 +151,31 @@ int hw_sm750_inithw(struct lynx_share *share, struct pci_dev *pdev)
                /* Set up GPIO for software I2C to program DVI chip in the
                   Xilinx SP605 board, in order to have video signal.
                 */
-       swI2CInit(0, 1);
+       sm750_sw_i2c_init(0, 1);
 
 
        /* Customer may NOT use CH7301 DVI chip, which has to be
           initialized differently.
        */
-       if (swI2CReadReg(0xec, 0x4a) == 0x95) {
+       if (sm750_sw_i2c_read_reg(0xec, 0x4a) == 0x95) {
                /* The following register values for CH7301 are from
                   Chrontel app note and our experiment.
                */
                        pr_info("yes,CH7301 DVI chip found\n");
-               swI2CWriteReg(0xec, 0x1d, 0x16);
-               swI2CWriteReg(0xec, 0x21, 0x9);
-               swI2CWriteReg(0xec, 0x49, 0xC0);
+               sm750_sw_i2c_write_reg(0xec, 0x1d, 0x16);
+               sm750_sw_i2c_write_reg(0xec, 0x21, 0x9);
+               sm750_sw_i2c_write_reg(0xec, 0x49, 0xC0);
                        pr_info("okay,CH7301 DVI chip setup done\n");
        }
        }
 
        /* init 2d engine */
-       if (!share->accel_off)
-               hw_sm750_initAccel(share);
-
-       return 0;
-}
-
-
-resource_size_t hw_sm750_getVMSize(struct lynx_share *share)
-{
-       resource_size_t ret;
-
-       ret = ddk750_getVMSize();
-       return ret;
-}
-
-
-
-int hw_sm750_output_checkMode(struct lynxfb_output *output, struct fb_var_screeninfo *var)
-{
+       if (!sm750_dev->accel_off)
+               hw_sm750_initAccel(sm750_dev);
 
        return 0;
 }
 
-
 int hw_sm750_output_setMode(struct lynxfb_output *output,
                                                                        struct fb_var_screeninfo *var, struct fb_fix_screeninfo *fix)
 {
@@ -254,25 +218,19 @@ int hw_sm750_output_setMode(struct lynxfb_output *output,
        return ret;
 }
 
-void hw_sm750_output_clear(struct lynxfb_output *output)
-{
-
-       return;
-}
-
 int hw_sm750_crtc_checkMode(struct lynxfb_crtc *crtc, struct fb_var_screeninfo *var)
 {
-       struct lynx_share *share;
-
+       struct sm750_dev *sm750_dev;
+       struct lynxfb_par *par = container_of(crtc, struct lynxfb_par, crtc);
 
-       share = container_of(crtc, struct lynxfb_par, crtc)->share;
+       sm750_dev = par->dev;
 
        switch (var->bits_per_pixel) {
        case 8:
        case 16:
                break;
        case 32:
-               if (share->revid == SM750LE_REVISION_ID) {
+               if (sm750_dev->revid == SM750LE_REVISION_ID) {
                        pr_debug("750le do not support 32bpp\n");
                        return -EINVAL;
                }
@@ -297,15 +255,15 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
        u32 reg;
        mode_parameter_t modparm;
        clock_type_t clock;
-       struct lynx_share *share;
+       struct sm750_dev *sm750_dev;
        struct lynxfb_par *par;
 
 
        ret = 0;
        par = container_of(crtc, struct lynxfb_par, crtc);
-       share = par->share;
-#if 1
-       if (!share->accel_off) {
+       sm750_dev = par->dev;
+
+       if (!sm750_dev->accel_off) {
                /* set 2d engine pixel format according to mode bpp */
                switch (var->bits_per_pixel) {
                case 8:
@@ -319,9 +277,8 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
                        fmt = 2;
                        break;
                }
-               hw_set2dformat(&share->accel, fmt);
+               hw_set2dformat(&sm750_dev->accel, fmt);
        }
-#endif
 
        /* set timing */
        modparm.pixel_clock = ps_to_hz(var->pixclock);
@@ -359,7 +316,7 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
 
                reg = var->xres * (var->bits_per_pixel >> 3);
                /* crtc->channel is not equal to par->index on numeric,be aware of that */
-               reg = PADDING(crtc->line_pad, reg);
+               reg = ALIGN(reg, crtc->line_pad);
 
                POKE32(PANEL_FB_WIDTH,
                        FIELD_VALUE(0, PANEL_FB_WIDTH, WIDTH, reg)|
@@ -391,7 +348,7 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
                POKE32(CRT_FB_ADDRESS, crtc->oScreen);
                reg = var->xres * (var->bits_per_pixel >> 3);
                /* crtc->channel is not equal to par->index on numeric,be aware of that */
-               reg = PADDING(crtc->line_pad, reg);
+               reg = ALIGN(reg, crtc->line_pad);
 
                POKE32(CRT_FB_WIDTH,
                        FIELD_VALUE(0, CRT_FB_WIDTH, WIDTH, reg)|
@@ -409,12 +366,6 @@ exit:
        return ret;
 }
 
-void hw_sm750_crtc_clear(struct lynxfb_crtc *crtc)
-{
-
-       return;
-}
-
 int hw_sm750_setColReg(struct lynxfb_crtc *crtc, ushort index,
                                                                ushort red, ushort green, ushort blue)
 {
@@ -429,41 +380,23 @@ int hw_sm750le_setBLANK(struct lynxfb_output *output, int blank)
        int dpms, crtdb;
 
        switch (blank) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_UNBLANK:
-#else
-       case VESA_NO_BLANKING:
-#endif
                dpms = CRT_DISPLAY_CTRL_DPMS_0;
                crtdb = CRT_DISPLAY_CTRL_BLANK_OFF;
                break;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_NORMAL:
                dpms = CRT_DISPLAY_CTRL_DPMS_0;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
                break;
-#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_VSYNC_SUSPEND:
-#else
-       case VESA_VSYNC_SUSPEND:
-#endif
                dpms = CRT_DISPLAY_CTRL_DPMS_2;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
                break;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_HSYNC_SUSPEND:
-#else
-       case VESA_HSYNC_SUSPEND:
-#endif
                dpms = CRT_DISPLAY_CTRL_DPMS_1;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
                break;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_POWERDOWN:
-#else
-       case VESA_POWERDOWN:
-#endif
                dpms = CRT_DISPLAY_CTRL_DPMS_3;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
                break;
@@ -485,47 +418,29 @@ int hw_sm750_setBLANK(struct lynxfb_output *output, int blank)
        dpms = pps = crtdb = 0;
 
        switch (blank) {
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_UNBLANK:
-#else
-       case VESA_NO_BLANKING:
-#endif
                pr_info("flag = FB_BLANK_UNBLANK\n");
                dpms = SYSTEM_CTRL_DPMS_VPHP;
                pps = PANEL_DISPLAY_CTRL_DATA_ENABLE;
                crtdb = CRT_DISPLAY_CTRL_BLANK_OFF;
                break;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_NORMAL:
                pr_info("flag = FB_BLANK_NORMAL\n");
                dpms = SYSTEM_CTRL_DPMS_VPHP;
                pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
                break;
-#endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_VSYNC_SUSPEND:
-#else
-       case VESA_VSYNC_SUSPEND:
-#endif
                dpms = SYSTEM_CTRL_DPMS_VNHP;
                pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
                break;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_HSYNC_SUSPEND:
-#else
-       case VESA_HSYNC_SUSPEND:
-#endif
                dpms = SYSTEM_CTRL_DPMS_VPHN;
                pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
                break;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 10)
        case FB_BLANK_POWERDOWN:
-#else
-       case VESA_POWERDOWN:
-#endif
                dpms = SYSTEM_CTRL_DPMS_VNHN;
                pps = PANEL_DISPLAY_CTRL_DATA_DISABLE;
                crtdb = CRT_DISPLAY_CTRL_BLANK_ON;
@@ -545,7 +460,7 @@ int hw_sm750_setBLANK(struct lynxfb_output *output, int blank)
 }
 
 
-void hw_sm750_initAccel(struct lynx_share *share)
+void hw_sm750_initAccel(struct sm750_dev *sm750_dev)
 {
        u32 reg;
 
@@ -572,7 +487,7 @@ void hw_sm750_initAccel(struct lynx_share *share)
        }
 
        /* call 2d init */
-       share->accel.de_init(&share->accel);
+       sm750_dev->accel.de_init(&sm750_dev->accel);
 }
 
 int hw_sm750le_deWait(void)
diff --git a/drivers/staging/sm750fb/sm750_hw.h b/drivers/staging/sm750fb/sm750_hw.h
deleted file mode 100644 (file)
index 3781a1a..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-#ifndef LYNX_HW750_H__
-#define LYNX_HW750_H__
-
-
-#define DEFAULT_SM750_CHIP_CLOCK       290
-#define DEFAULT_SM750LE_CHIP_CLOCK     333
-#ifndef SM750LE_REVISION_ID
-#define SM750LE_REVISION_ID (unsigned char)0xfe
-#endif
-
-
-enum sm750_pnltype {
-
-       sm750_24TFT = 0,/* 24bit tft */
-
-       sm750_dualTFT = 2,/* dual 18 bit tft */
-
-       sm750_doubleTFT = 1,/* 36 bit double pixel tft */
-};
-
-/* vga channel is not concerned  */
-enum sm750_dataflow {
-       sm750_simul_pri,/* primary => all head */
-
-       sm750_simul_sec,/* secondary => all head */
-
-       sm750_dual_normal,/* primary => panel head and secondary => crt */
-
-       sm750_dual_swap,/* primary => crt head and secondary => panel */
-};
-
-
-enum sm750_channel {
-       sm750_primary = 0,
-       /* enum value equal to the register filed data */
-       sm750_secondary = 1,
-};
-
-enum sm750_path {
-       sm750_panel = 1,
-       sm750_crt = 2,
-       sm750_pnc = 3,/* panel and crt */
-};
-
-struct init_status {
-       ushort powerMode;
-       /* below three clocks are in unit of MHZ*/
-       ushort chip_clk;
-       ushort mem_clk;
-       ushort master_clk;
-       ushort setAllEngOff;
-       ushort resetMemory;
-};
-
-struct sm750_state {
-       struct init_status initParm;
-       enum sm750_pnltype pnltype;
-       enum sm750_dataflow dataflow;
-       int nocrt;
-       int xLCD;
-       int yLCD;
-};
-
-/* sm750_share stands for a presentation of two frame buffer
-   that use one sm750 adaptor, it is similar to the super class of lynx_share
-   in C++
- */
-
-struct sm750_share {
-       /* it's better to put lynx_share struct to the first place of sm750_share */
-       struct lynx_share share;
-       struct sm750_state state;
-       int hwCursor;
-       /* 0: no hardware cursor
-          1: primary crtc hw cursor enabled,
-          2: secondary crtc hw cursor enabled
-          3: both ctrc hw cursor enabled
-       */
-};
-
-int hw_sm750_map(struct lynx_share *share, struct pci_dev *pdev);
-int hw_sm750_inithw(struct lynx_share*, struct pci_dev *);
-void hw_sm750_initAccel(struct lynx_share *);
-int hw_sm750_deWait(void);
-int hw_sm750le_deWait(void);
-
-resource_size_t hw_sm750_getVMSize(struct lynx_share *);
-int hw_sm750_output_checkMode(struct lynxfb_output*, struct fb_var_screeninfo*);
-int hw_sm750_output_setMode(struct lynxfb_output*, struct fb_var_screeninfo*, struct fb_fix_screeninfo*);
-int hw_sm750_crtc_checkMode(struct lynxfb_crtc*, struct fb_var_screeninfo*);
-int hw_sm750_crtc_setMode(struct lynxfb_crtc*, struct fb_var_screeninfo*, struct fb_fix_screeninfo*);
-int hw_sm750_setColReg(struct lynxfb_crtc*, ushort, ushort, ushort, ushort);
-int hw_sm750_setBLANK(struct lynxfb_output*, int);
-int hw_sm750le_setBLANK(struct lynxfb_output*, int);
-void hw_sm750_crtc_clear(struct lynxfb_crtc *);
-void hw_sm750_output_clear(struct lynxfb_output *);
-int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
-                        const struct fb_var_screeninfo *var,
-                        const struct fb_info *info);
-
-#endif
index d4d45989b6050a33051fbf66c46866596bc97e28..8565c2343968a80695887ed798ce3a4a52a5df44 100644 (file)
@@ -101,6 +101,7 @@ EXPORT_SYMBOL_GPL(synth_buffer_peek);
 
 void synth_buffer_clear(void)
 {
-       buff_in = buff_out = synth_buffer;
+       buff_in = synth_buffer;
+       buff_out = synth_buffer;
 }
 EXPORT_SYMBOL_GPL(synth_buffer_clear);
index 71c728acf4ca1c28892fa1beebbb5cdea2095f6a..d1ffdf4c0c4bdab4d60bc0aeb22334a9efd380d0 100644 (file)
@@ -22,7 +22,7 @@ static ssize_t speakup_file_write(struct file *fp, const char __user *buffer,
        unsigned long flags;
        u_char buf[256];
 
-       if (synth == NULL)
+       if (!synth)
                return -ENODEV;
        while (count > 0) {
                bytes = min(count, sizeof(buf));
@@ -45,7 +45,7 @@ static ssize_t speakup_file_read(struct file *fp, char __user *buf,
 
 static int speakup_file_open(struct inode *ip, struct file *fp)
 {
-       if (synth == NULL)
+       if (!synth)
                return -ENODEV;
        if (xchg(&dev_opened, 1))
                return -EBUSY;
index f061747546a66d364980a06ba7759e0235f78cc8..12f880ed4ddfc7d13a0566c21baf0e8ac7aaff57 100644 (file)
@@ -389,7 +389,7 @@ static struct msg_group_t all_groups[] = {
        },
 };
 
-static const  int num_groups = sizeof(all_groups) / sizeof(struct msg_group_t);
+static const  int num_groups = ARRAY_SIZE(all_groups);
 
 char *spk_msg_get(enum msg_index_t index)
 {
index 958add4839bc56be14fe261945b395374172751c..fdfeb42b2b8f72db1d8f019b695cf0a5dc8e432d 100644 (file)
@@ -368,7 +368,7 @@ static ssize_t synth_show(struct kobject *kobj, struct kobj_attribute *attr,
 {
        int rv;
 
-       if (synth == NULL)
+       if (!synth)
                rv = sprintf(buf, "%s\n", "none");
        else
                rv = sprintf(buf, "%s\n", synth->name);
@@ -459,14 +459,14 @@ static ssize_t punc_show(struct kobject *kobj, struct kobj_attribute *attr,
        unsigned long flags;
 
        p_header = spk_var_header_by_name(attr->attr.name);
-       if (p_header == NULL) {
+       if (!p_header) {
                pr_warn("p_header is null, attr->attr.name is %s\n",
                        attr->attr.name);
                return -EINVAL;
        }
 
        var = spk_get_punc_var(p_header->var_id);
-       if (var == NULL) {
+       if (!var) {
                pr_warn("var is null, p_header->var_id is %i\n",
                                p_header->var_id);
                return -EINVAL;
@@ -501,14 +501,14 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr,
                return -EINVAL;
 
        p_header = spk_var_header_by_name(attr->attr.name);
-       if (p_header == NULL) {
+       if (!p_header) {
                pr_warn("p_header is null, attr->attr.name is %s\n",
                        attr->attr.name);
                return -EINVAL;
        }
 
        var = spk_get_punc_var(p_header->var_id);
-       if (var == NULL) {
+       if (!var) {
                pr_warn("var is null, p_header->var_id is %i\n",
                                p_header->var_id);
                return -EINVAL;
@@ -546,7 +546,7 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
        unsigned long flags;
 
        param = spk_var_header_by_name(attr->attr.name);
-       if (param == NULL)
+       if (!param)
                return -EINVAL;
 
        spin_lock_irqsave(&speakup_info.spinlock, flags);
@@ -622,9 +622,9 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
        unsigned long flags;
 
        param = spk_var_header_by_name(attr->attr.name);
-       if (param == NULL)
+       if (!param)
                return -EINVAL;
-       if (param->data == NULL)
+       if (!param->data)
                return 0;
        ret = 0;
        cp = (char *)buf;
index 66ac999a032320791db2e307fabc98221920ca90..3b5835b2812849f0c32055f065ef0be6a0c4d0d0 100644 (file)
@@ -101,7 +101,7 @@ static void start_serial_interrupt(int irq)
 {
        int rv;
 
-       if (synth->read_buff_add == NULL)
+       if (!synth->read_buff_add)
                return;
 
        rv = request_irq(irq, synth_readbuf_handler, IRQF_SHARED,
@@ -127,7 +127,7 @@ void spk_stop_serial_interrupt(void)
        if (speakup_info.port_tts == 0)
                return;
 
-       if (synth->read_buff_add == NULL)
+       if (!synth->read_buff_add)
                return;
 
        /* Turn off interrupts */
index ea89e36ecd0d3eb544d1858ef5b1492116c3f706..a9a68723295549dea1970c4279ebd3edb3a4ca30 100644 (file)
@@ -162,7 +162,7 @@ static void synth_version(struct spk_synth *synth)
 
 static int synth_probe(struct spk_synth *synth)
 {
-       int failed = 0;
+       int failed;
 
        failed = spk_serial_synth_probe(synth);
        if (failed == 0)
index b5a23d42f4d5dc49fa2ad17fbea65685e9e95f3b..09063b82326f1ace88be13bd1e00dfa221ac31d9 100644 (file)
@@ -291,10 +291,9 @@ static void do_catch_up(struct spk_synth *synth)
 
 static void synth_flush(struct spk_synth *synth)
 {
-       if (in_escape) {
+       if (in_escape)
                /* if in command output ']' so we don't get an error */
                spk_serial_out(']');
-       }
        in_escape = 0;
        is_flushing = 1;
        spk_serial_out(SYNTH_CLEAR);
index 366358b600a17ce1575a214d9e8d3af3902b28ac..b2eb5b133a5d5599083c91e2b1fd1238b008da2e 100644 (file)
@@ -19,7 +19,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * this code is specificly written as a driver for the speakup screenreview
- * package and is not a general device driver.  */
+ * package and is not a general device driver.
+ */
 
 #include <linux/unistd.h>
 #include <linux/miscdevice.h> /* for misc_register, and SYNTH_MINOR */
index 1ef3795b865d32ae3dbbbcf807034affa1676da1..9bb281d3655697963ae29f351adcaf35ebbfd977 100644 (file)
@@ -1,26 +1,26 @@
 /* spk_priv.h
-   review functions for the speakup screen review package.
-   originally written by: Kirk Reiser and Andy Berdan.
+ * review functions for the speakup screen review package.
+ * originally written by: Kirk Reiser and Andy Berdan.
+ *
+ * extensively modified by David Borowski.
+ *
+ * Copyright (C) 1998  Kirk Reiser.
+ * Copyright (C) 2003  David Borowski.
 
-  extensively modified by David Borowski.
-
-    Copyright (C) 1998  Kirk Reiser.
-    Copyright (C) 2003  David Borowski.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 #ifndef _SPEAKUP_PRIVATE_H
 #define _SPEAKUP_PRIVATE_H
 
index 95c473a7e65f1cc3d1354e136eb532140ca9f93e..3116ef78c196ce258c8e9e144fd9a25cb76175c2 100644 (file)
@@ -1,26 +1,26 @@
 /* spk_priv.h
  review functions for the speakup screen review package.
  originally written by: Kirk Reiser and Andy Berdan.
-
-  extensively modified by David Borowski.
-
   Copyright (C) 1998  Kirk Reiser.
   Copyright (C) 2003  David Borowski.
-
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
* review functions for the speakup screen review package.
* originally written by: Kirk Reiser and Andy Berdan.
+ *
* extensively modified by David Borowski.
+ *
* Copyright (C) 1998  Kirk Reiser.
* Copyright (C) 2003  David Borowski.
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 #ifndef _SPEAKUP_KEYINFO_H
 #define _SPEAKUP_KEYINFO_H
index 75bf40c14c793930bc8f8903ffff3a09f0647386..ab4fe8de415f0e8d7429a065befab879b6b4e5b5 100644 (file)
@@ -90,7 +90,7 @@ void speakup_register_var(struct var_t *var)
        struct st_var_header *p_header;
 
        BUG_ON(!var || var->var_id < 0 || var->var_id >= MAXVARS);
-       if (var_ptrs[0] == NULL) {
+       if (!var_ptrs[0]) {
                for (i = 0; i < MAXVARS; i++) {
                        p_header = &var_headers[i];
                        var_ptrs[p_header->var_id] = p_header;
@@ -130,7 +130,7 @@ struct st_var_header *spk_get_var_header(enum var_id_t var_id)
        if (var_id < 0 || var_id >= MAXVARS)
                return NULL;
        p_header = var_ptrs[var_id];
-       if (p_header->data == NULL)
+       if (!p_header->data)
                return NULL;
        return p_header;
 }
@@ -163,7 +163,7 @@ struct punc_var_t *spk_get_punc_var(enum var_id_t var_id)
        struct punc_var_t *where;
 
        where = punc_vars;
-       while ((where->var_id != -1) && (rv == NULL)) {
+       while ((where->var_id != -1) && (!rv)) {
                if (where->var_id == var_id)
                        rv = where;
                else
@@ -183,7 +183,7 @@ int spk_set_num_var(int input, struct st_var_header *var, int how)
        char *cp;
        struct var_t *var_data = var->data;
 
-       if (var_data == NULL)
+       if (!var_data)
                return -ENODATA;
 
        if (how == E_NEW_DEFAULT) {
@@ -221,9 +221,9 @@ int spk_set_num_var(int input, struct st_var_header *var, int how)
        if (var_data->u.n.multiplier != 0)
                val *= var_data->u.n.multiplier;
        val += var_data->u.n.offset;
-       if (var->var_id < FIRST_SYNTH_VAR || synth == NULL)
+       if (var->var_id < FIRST_SYNTH_VAR || !synth)
                return ret;
-       if (synth->synth_adjust != NULL) {
+       if (synth->synth_adjust) {
                int status = synth->synth_adjust(var);
 
                return (status != 0) ? status : ret;
@@ -247,7 +247,7 @@ int spk_set_string_var(const char *page, struct st_var_header *var, int len)
 {
        struct var_t *var_data = var->data;
 
-       if (var_data == NULL)
+       if (!var_data)
                return -ENODATA;
        if (len > MAXVARLEN)
                return -E2BIG;
@@ -288,7 +288,7 @@ int spk_set_mask_bits(const char *input, const int which, const int how)
                        if (*cp < SPACE)
                                break;
                        if (mask < PUNC) {
-                               if (!(spk_chartab[*cp]&PUNC))
+                               if (!(spk_chartab[*cp] & PUNC))
                                        break;
                        } else if (spk_chartab[*cp]&B_NUM)
                                break;
@@ -313,7 +313,7 @@ char *spk_strlwr(char *s)
 {
        char *p;
 
-       if (s == NULL)
+       if (!s)
                return NULL;
 
        for (p = s; *p; p++)
@@ -323,7 +323,7 @@ char *spk_strlwr(char *s)
 
 char *spk_s2uchar(char *start, char *dest)
 {
-       int val = 0;
+       int val;
 
        val = simple_strtoul(skip_spaces(start), &start, 10);
        if (*start == ',')
index 1f9ba8beb06173adad9041b823498c41313d79b1..824d460911ec3d90ee14feba60bd0e06a9c50eac 100644 (file)
@@ -1138,4 +1138,3 @@ module_i2c_driver(synaptics_rmi4_driver);
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("naveen.gaddipati@stericsson.com, js.ha@stericsson.com");
 MODULE_DESCRIPTION("synaptics rmi4 i2c touch Driver");
-MODULE_ALIAS("i2c:synaptics_rmi4_ts");
index 28f8f1233fc68f60dff01dfe665ed8bdbecbb1f9..b0498ff3240581c9e63f7b144428a0ab04798021 100644 (file)
@@ -1,3 +1,5 @@
+This file describes sysfs entries beneath /devices/platform/visorchipset.
+
 What:          install/error
 Date:          7/18/2014
 KernelVersion:         TBD
index 8d078e4de3b8694d629ac6fc421e405e856597b8..c2d8dd4a2e41a8ac1040acb1b090a66ff3305c75 100644 (file)
+1. Overview
+-----------
 
-Overview
-
-This document describes the driver set for Unisys Secure Partitioning (s-Par®).
+This document describes the driver set for Unisys Secure Partitioning
+(s-Par(R)).
 
 s-Par is firmware that provides hardware partitioning capabilities for
 splitting large-scale Intel x86 servers into multiple isolated
 partitions. s-Par provides a set of para-virtualized device drivers to
 allow guest partitions on the same server to share devices that would
-normally be unsharable; specifically, PCI network interfaces and host
-bus adapters that do not support shared access via SR-IOV. The shared
-device is owned and managed by a small, single-purpose service
-partition, which communicates with each guest partition sharing that
-device through an area of shared memory called a channel. Additional
-drivers provide support interfaces for communicating with s-Par
-services, logging and diagnostics, and accessing the Linux console
-from the s-Par user interface.
-
-The driver stack consists of a set of support modules, a set of bus
-modules, and a set of device driver modules. The support modules
-handle a number of common functions across each of the other
-drivers. The bus modules provide organization for the device driver
-modules, which provide the shared device functionality.
-
-These drivers are for the Unisys virtual PCI hardware model where the
-hypervisor need not intervene (other than normal interrupt handling)
-in the interactions between the client drivers and the virtual adapter
-firmware in the adapter service partition.
-
-Driver Descriptions
-
-Device Modules
-
-The modules in this section handle shared devices and the virtual
-buses required to support them. These modules use functions in and
-depend on the modules described in the support modules section.
-
-visorchipset
-
-The visorchipset module receives device creation and destruction
-events from the Command service partition of s-Par, as well as
-controlling registration of shared device drivers with the s-Par
-driver core. The events received are used to populate other s-Par
-modules with their assigned shared devices. Visorchipset is required
-for shared device drivers to function properly. Visorchipset also
-stores information for handling dump disk device creation during
-kdump.
-
-In operation, the visorchipset module processes device creation and
-destruction messages sent by s-Par's Command service partition through
-a channel. These messages result in creation (or destruction) of each
-virtual bus and virtual device. Each bus and device is also associated
-with a communication channel, which is used to communicate with one or
-more IO service partitions to perform device IO on behalf of the
-guest.
-
-virthba
-
-The virthba module provides access to a shared SCSI host bus adapter
-and one or more disk devices, by proxying SCSI commands between the
-guest and the service partition that owns the shared SCSI adapter,
-using a channel between the guest and the service partition. The disks
-that appear on the shared bus are defined by the s-Par configuration
-and enforced by the service partition, while the guest driver handles
-sending commands and handling responses. Each disk is shared as a
-whole to a guest. Sharing the bus adapter in this way provides
-resiliency; should the device encounter an error, only the service
+normally be unsharable, specifically:
+
+* visornic - network interface
+* visorhba - scsi disk adapter
+* visorinput - keyboard and mouse
+
+These drivers conform to the standard Linux bus/device model described
+within Documentation/driver-model/, and utilize a driver named visorbus to
+present the virtual busses involved. Drivers in the 'visor*' driver set are
+commonly referred to as "guest drivers" or "client drivers".  All drivers
+except visorbus expose a device of a specific usable class to the Linux guest
+environment (e.g., block, network, or input), and are collectively referred
+to as "function drivers".
+
+The back-end for each device is owned and managed by a small,
+single-purpose service partition in the s-Par firmware, which communicates
+with each guest partition sharing that device through an area of shared memory
+called a "channel". In s-Par nomenclature, the back-end is often referred to
+as the "service partition", "IO partition" (for virtual network and scsi disk
+devices), or "console partition" (for virtual keyboard and mouse devices).
+
+Each virtual device requires exactly 1 dedicated channel, which the guest
+driver and back-end use to communicate.  The hypervisor need not intervene
+(other than normal interrupt handling) in the interactions that occur across
+this channel.
+
+NOT covered in this document:
+
+* s-Par also supports sharing physical PCI adapters via SR-IOV, but
+  because this requires no specific support in the guest partitions, it will
+  not be discussed in this document.  Shared SR-IOV devices should be used
+  wherever possible for highest performance.
+
+* Because the s-Par back-end provides a standard EFI framebuffer to each
+  guest, the already-existing efifb Linux driver is used to provide guest
+  video access. Thus, the only s-Par-unique support that is necessary to
+  provide a guest graphics console are for keyboard and mouse (via visorinput).
+
+
+2. Driver Descriptions
+----------------------
+
+2.1. visorbus
+-------------
+
+2.1.1. Overview
+---------------
+
+The visorbus driver handles the virtual busses on which all of the virtual
+devices reside. It provides a registration function named
+visorbus_register_visor_driver() that is called by each of the function
+drivers at initialization time, which the function driver uses to tell
+visorbus about the device classes (via specifying a list of device type
+GUIDs) it wants to handle. For use by function drivers, visorbus provides
+implementation for struct visor_driver and struct visor_device, as well
+as utility functions for communicating with the back-end.
+
+visorbus is associated with ACPI id "PNP0A07" in modules.alias, so if built
+as a module it will typically be loaded automatically via standard udev or
+systemd (God help us) configurations.
+
+visorbus can similarly force auto-loading of function drivers for virtual
+devices it discovers, as it includes a MODALIAS environment variable of this
+form in the hotplug uevent environment when each virtual device is
+discovered:
+
+    visorbus:<device type GUID>
+
+visorbus notifies each function driver when a device of its registered class
+arrives and departs, by calling the function driver's probe() and remove()
+methods.
+
+The actual struct device objects that correspond to each virtual bus and
+each virtual device are created and owned by visorbus.  These device objects
+are created in response to messages from the s-Par back-end received on a
+special control channel called the "controlvm channel" (each guest partition
+has access to exactly 1 controlvm channel), and have a lifetime that is
+independent of the function drivers that control them.
+
+2.1.2. "struct visor device" Function Driver Interfaces
+-------------------------------------------------------
+
+The interface between visorbus and its function drivers is defined in
+visorbus.h, and described below.
+
+When a visor function driver loads, it calls visorbus_register_visor_driver()
+to register itself with visorbus. The significant information passed in this
+exchange is as follows:
+
+* the GUID(s) of the channel type(s) that are handled by this driver, as
+  well as a "friendly name" identifying each (this will be published under
+  /sys/devices/visorbus<x>/dev<y>)
+
+* the addresses of callback functions to be called whenever a virtual
+  device/channel with the appropriate channel-type GUID(s) appears or
+  disappears
+
+* the address of a "channel_interrupt" function, which will be automatically
+  called at specific intervals to enable the driver to poll the device
+  channel for activity
+
+The following functions implemented within each function driver will be
+called automatically by the visorbus driver at appropriate times:
+
+* The probe() function notifies about the creation of each new virtual
+  device/channel instance.
+
+* The remove() function notifies about the destruction of a virtual
+  device/channel instance.
+
+* The channel_interrupt() function is called at frequent intervals to
+  give the function driver an opportunity to poll the virtual device channel
+  for requests.  Information is passed to this function to enable the
+  function driver to use the visorchannel_signalinsert() and
+  visorchannel_signalremove() functions to respond to and initiate activity
+  over the channel.  (Note that since it is the visorbus driver that
+  determines when this is called, it is very easy to switch to
+  interrupt-driven mechanisms when available for particular virtual device
+  types.)
+
+* The pause() function is called should it ever be necessary to direct the
+  function driver to temporarily stop accessing the device channel.  An
+  example of when this is needed is when the service partition implementing
+  the back-end of the virtual device needs to be recovered.  After a
+  successful return of pause(), the function driver must not access the
+  device channel until a subsequent resume() occurs.
+
+* The resume() function is the "book-end" to pause(), and is described above.
+
+If/when a function driver creates a Linux device (that needs to be accessed
+from usermode), it calls visorbus_registerdevnode(), passing the major and
+minor number of the device.  (Of course not all function drivers will need
+to do this.)  This simply creates the appropriate "devmajorminor" sysfs entry
+described below, so that a hotplug script can use it to create a device node.
+
+2.1.3. sysfs Advertised Information
+-----------------------------------
+
+Because visorbus is a standard Linux bus driver in the model described in
+Documentation/driver-model/, the hierarchy of s-Par virtual devices is
+published in the sysfs tree beneath /bus/visorbus/, e.g.,
+/sys/bus/visorbus/devices/ might look like:
+
+    vbus1:dev1 -> ../../../devices/visorbus1/vbus1:dev1
+    vbus1:dev2 -> ../../../devices/visorbus1/vbus1:dev2
+    vbus1:dev3 -> ../../../devices/visorbus1/vbus1:dev3
+    vbus2:dev0 -> ../../../devices/visorbus2/vbus2:dev0
+    vbus2:dev1 -> ../../../devices/visorbus2/vbus2:dev1
+    vbus2:dev2 -> ../../../devices/visorbus2/vbus2:dev2
+    visorbus1 -> ../../../devices/visorbus1
+    visorbus2 -> ../../../devices/visorbus2
+
+visor_device notes:
+
+* Each visorbus<n> entry denotes the existence of a struct visor_device
+  denoting virtual bus #<n>.  A unique s-Par channel exists for each such
+  virtual bus.
+
+* Virtual bus numbers uniquely identify s-Par back-end service partitions.
+  In this example, bus 1 corresponds to the s-Par console partition
+  (controls keyboard, video, and mouse), whereas bus 2 corresponds to the
+  s-Par IO partition (controls network and disk).
+
+* Each vbus<x>:dev<y> entry denotes the existence of a struct visor_device
+  denoting virtual device #<y> outboard of virtual bus #<x>.  A unique s-Par
+  channel exists for each such virtual device.
+
+* If a function driver has loaded and claimed a particular device, the
+  bus/visorbus/devices/vbus<x>:dev<y>/driver symlink will indicate that
+  function driver.
+
+Every active visorbus device will have a sysfs subtree under:
+
+    /sys/devices/visorbus<x>/vbus<x>:dev<y>/
+
+The following files exist under /sys/devices/visorbus<x>/vbus<x>:dev<y>:
+
+    subsystem                 link to sysfs tree that describes the
+                              visorbus bus type; e.g.:
+                                  ../../../bus/visorbus
+
+    driver                    link to sysfs tree that describes the
+                              function driver controlling this device;
+                              e.g.:
+                                  ../../../bus/visorbus/drivers/visorhba
+                              Note that this "driver" link will not exist
+                              if the appropriate function driver has not
+                              been loaded yet.
+
+    devmajorminor
+
+        <devname>             if applicable, each file here identifies (via
+        ...                   its file contents) the
+                              "<major>:<minor>" needed for a device node to
+                              enable access from usermode.  There is exactly
+                              one file here for each different device node
+                              that can be accessed (from usermode).  Note
+                              that this info is provided by a particular
+                              function driver, so these will not exist
+                              until AFTER the appropriate function driver
+                              controlling this device class is loaded.
+
+    channel                   properties of the device channel (all in
+                              ascii text format)
+
+        clientpartition       handle identifying the guest (client) side
+                              of this channel, e.g. 0x10000000.
+
+        nbytes                total size of this channel in bytes
+
+        physaddr              the guest physical address for the base of
+                              the channel
+
+        typeguid              a GUID identifying the channel type, in
+                              xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx notation
+
+        typename              a "friendly name" for this channel type, e.g.,
+                              "keyboard".  Note that this name is provided by
+                              a particular function driver, so "typename"
+                              will return an empty string until AFTER the
+                              appropriate function driver controlling this
+                              channel type is loaded
+
+        zoneguid              a GUID identifying the channel zone, in
+                              xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx notation
+
+
+2.2. visorhba
+-------------
+
+The visorhba driver registers with visorbus as the function driver to
+handle virtual scsi disk devices, specified using the
+SPAR_VHBA_CHANNEL_PROTOCOL_UUID type in the visorbus_register_visor_driver()
+call. visorhba uses scsi_add_host() to expose a Linux block device
+(e.g., /sys/block/) in the guest environment for each s-Par virtual device.
+
+visorhba provides access to a shared SCSI host bus adapter and one or more
+disk devices, by proxying SCSI commands between the guest and the service
+partition that owns the shared SCSI adapter, using a channel between the
+guest and the service partition. The disks that appear on the shared bus
+are defined by the s-Par configuration and enforced by the service partition,
+while the guest driver handles sending commands and handling responses. Each
+disk is shared as a whole to a guest. Sharing the bus adapter in this way
+provides resiliency; should the device encounter an error, only the service
 partition is rebooted, and the device is reinitialized. This allows
 guests to continue running and to recover from the error.
 
-virtnic
+When compiled as a module, visorhba can be autoloaded by visorbus in
+standard udev/systemd environments, as it includes the modules.alias
+definition:
+
+    "visorbus:"+SPAR_VHBA_CHANNEL_PROTOCOL_UUID_STR
+
+i.e.:
+
+    alias visorbus:414815ed-c58c-11da-95a9-00e08161165f visorhba
+
 
-The virtnic module provides a paravirtualized network interface to a
+2.3. visornic
+-------------
+
+The visornic driver registers with visorbus as the function driver to
+handle virtual network devices, specified using the
+SPAR_VNIC_CHANNEL_PROTOCOL_UUID type in the visorbus_register_visor_driver()
+call. visornic uses register_netdev() to expose a Linux device of class net
+(e.g., /sys/class/net/) in the guest environment for each s-Par virtual
+device.
+
+visornic provides a paravirtualized network interface to a
 guest by proxying buffer information between the guest and the service
 partition that owns the shared network interface, using a channel
 between the guest and the service partition. The connectivity of this
@@ -79,96 +285,72 @@ partitions is defined by the s-Par configuration and enforced by the
 service partition; the guest driver handles communication and link
 status.
 
-visorserial
-
-The visorserial module allows the console of the linux guest to be
-accessed via the s-Par console serial channel. It creates devices in
-/dev/visorserialclientX which behave like a serial terminal and are
-connected to the diagnostics system in s-Par. By assigning a getty to
-the terminal in the guest, a user could log into and access the guest
-from the s-Par diagnostics SWITCH RUN terminal.
-
-visorbus
-
-The visorbus module handles the bus functions for most functional
-drivers except visorserial, visordiag, virthba, and virtnic. It
-maintains the sysfs subtree /sys/devices/visorbus*/. It is responsible
-for device creation and destruction of the devices on its bus.
-
-visorclientbus
-
-The visorclientbus module forwards the bus functions for virthba, and
-virtnic to the virtpci driver.
-
-virtpci
-
-The virtpci module handles the bus functions for virthba, and virtnic.
-
-s-Par Integration Modules
-
-The modules in this section provide integration with s-Par guest
-partition services like diagnostics and remote desktop. These modules
-depend on functions in the modules described in the support modules
-section.
-
-visorvideoclient
-
-The visorvideoclient module provides functionality for video support
-for the Unisys s-Par Partition Desktop application. The guest OS must
-also have the UEFI GOP protocol enabled for the partition desktop to
-function.  visorconinclient The visorconinclient module provides
-keyboard and mouse support for the Unisys s-Par Partition Desktop
-application.
+When compiled as a module, visornic can be autoloaded by visorbus in
+standard udev/systemd environments, as it includes the modules.alias
+definition:
 
-sparstop
+    "visorbus:"+SPAR_VNIC_CHANNEL_PROTOCOL_UUID_STR
 
-The sparstop module handles requests from the Unisys s-Par platform to
-shutdown the linux guest. It allows a program on the guest to perform
-clean-up functions on the guest before the guest is shut down or
-rebooted using ACPI.
+i.e.:
 
-visordiag
+    alias visorbus:8cd5994d-c58e-11da-95a9-00e08161165f visornic
 
-This driver provides the ability for the guest to write information
-into the s-Par diagnostics subsystem. It creates a set of devices
-named /dev/visordiag.X which can be written to by the guest to add
-text to the s-Par system log.
 
-Support Modules
+2.4. visorinput
+---------------
 
-The modules described in this section provide functions and
-abstractions to support the modules described in the previous
-sections, to avoid having duplicated functionality.
+The visorinput driver registers with visorbus as the function driver to
+handle human input devices, specified using the
+SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID and SPAR_MOUSE_CHANNEL_PROTOCOL_UUID
+types in the visorbus_register_visor_driver() call. visorinput uses
+input_register_device() to expose devices of class input
+(e.g., /sys/class/input/) for virtual keyboard and virtual mouse devices.
+A s-Par virtual keyboard device maps 1-to-1 with a Linux input device
+named "visor Keyboard", while a s-Par virtual mouse device has 2 Linux input
+devices created for it: 1 named "visor Wheel", and 1 named "visor Mouse".
 
-visornoop
+By registering as input class devices, modern versions of X will
+automatically find and properly use s-Par virtual keyboard and mouse devices.
+As the s-Par back-end reports keyboard and mouse activity via events on the
+virtual device channel, the visorinput driver delivers the activity to the
+Linux environment by calling input_report_key() and input_report_abs().
 
-The visornoop module is a placeholder that responds to device
-create/destroy messages that are currently not in use by linux guests.
+You can interact with the guest console using the usyscon Partition Desktop
+(a.k.a., "pd") application, provided as part of s-Par.  After installing the
+usyscon Partition Desktop into a Linux environment via the
+usyscon_partitiondesktop-*.rpm, or into a Windows environment via
+PartitionDesktop.msi, you will be able to launch a console for your guest
+Linux environment by clicking the console icon in the s-Par web UI.
 
-visoruislib
+When compiled as a module, visorinput can be autoloaded by visorbus in
+standard udev/systemd environments, as it includes the modules.alias
+definition:
 
-The visoruislib module is a support library, used to handle requests
-from virtpci.
+    "visorbus:"+SPAR_MOUSE_CHANNEL_PROTOCOL_UUID_STR
+    "visorbus:"+SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID_STR
 
-visorchannelstub
+i.e.:
 
-The visorchannelstub module provides support routines for storing and
-retrieving data from a channel.
+    alias visorbus:c73416d0-b0b8-44af-b304-9d2ae99f1b3d visorinput
+    alias visorbus:addf07d4-94a9-46e2-81c3-61abcdbdbd87 visorinput
 
-visorchannel
 
-The visorchannel module is a support library that abstracts reading
-and writing a channel in memory.
+3. Minimum Required Driver Set
+------------------------------
 
-visorutil
+visorbus is required for every Linux guest running under s-Par.
 
-The visorutil module is a support library required by all other s-Par
-driver modules. Among its features it abstracts reading, writing, and
-manipulating a block of memory.
+visorhba is typically required for a Linux guest running under s-Par, as it
+is required if your guest boot disk is a virtual device provided by the s-Par
+back-end, which is the default configuration.  However, for advanced
+configurations where the Linux guest boots via an SR-IOV-provided HBA or
+SAN disk for example, visorhba is not technically required.
 
-Minimum Required Driver Set
+visornic is typically required for a Linux guest running under s-Par, as it
+is required if your guest network interface is a virtual device provided by
+the s-Par back-end, which is the default configuration.  However, for
+configurations where the Linux guest is provided with an SR-IOV NIC
+for example, visornic is not technically required.
 
-The drivers required to boot a Linux guest are visorchipset, visorbus,
-visorvideoclient, visorconinclient, visoruislib, visorchannelstub,
-visorchannel, and visorutil. The other drivers are required by the
-product configurations that are currently being marketed.
+visorinput is only required for a Linux guest running under s-Par if you
+require graphics-mode access to your guest console.
index 624abe66c20c25f9685f607273ec6b14c003ea50..4f1f5e624604dc00ee0f29f1d298d31b6a47b361 100644 (file)
@@ -13,5 +13,7 @@ if UNISYSSPAR
 
 source "drivers/staging/unisys/visorbus/Kconfig"
 source "drivers/staging/unisys/visornic/Kconfig"
+source "drivers/staging/unisys/visorinput/Kconfig"
+source "drivers/staging/unisys/visorhba/Kconfig"
 
 endif # UNISYSSPAR
index a515ebc4f8ecfaa36e4dd622b5791bdb4d4c1eab..20eb098538d3fa9c3498c7e4df70232c994cf679 100644 (file)
@@ -3,3 +3,5 @@
 #
 obj-$(CONFIG_UNISYS_VISORBUS)          += visorbus/
 obj-$(CONFIG_UNISYS_VISORNIC)          += visornic/
+obj-$(CONFIG_UNISYS_VISORINPUT)                += visorinput/
+obj-$(CONFIG_UNISYS_VISORHBA)          += visorhba/
index 034ac61c44f22870c4ab1b20c0588f3cccec37a0..d863f266bf76f433a755053069024b5b86eb831d 100644 (file)
@@ -1,19 +1,14 @@
 TODO:
-       -checkpatch warnings
-       -move /proc entries to /sys
-       -proper major number(s)
-       -add other drivers needed for full functionality:
-               -visorclientbus
-               -visorbus
-               -visordiag
-               -virtnic
-               -visornoop
-               -visorserial
-               -visorvideoclient
-               -visorconinclient
-               -sparstop
-       -move individual drivers into proper driver subsystems
-               
+       - enhance visornic to use channel_interrupt() hook instead of a
+         kernel thread
+       - enhance visorhba to use channel_interrupt() hook instead of a
+         kernel thread
+       - teach visorbus to handle virtual interrupts triggered by s-Par
+         back-end, and call function driver's channel_interrupt() function
+         when they occur
+       - enhance debugfs interfaces (e.g., per device, etc.)
+       - upgrade/remove deprecated workqueue operations
+       - move individual drivers into proper driver subsystems
 
 Patches to:
        Greg Kroah-Hartman <gregkh@linuxfoundation.org>
index da0b5387f884347ccd365cd7d53aa3baa1b39b75..c6c24423a7f0a84abbedf6d52b3f61ea4c462371 100644 (file)
@@ -32,7 +32,7 @@
  */
 #define __SUPERVISOR_CHANNEL_H__
 
-#define SIGNATURE_16(A, B) ((A) | (B<<8))
+#define SIGNATURE_16(A, B) ((A) | (B << 8))
 #define SIGNATURE_32(A, B, C, D) \
        (SIGNATURE_16(A, B) | (SIGNATURE_16(C, D) << 16))
 #define SIGNATURE_64(A, B, C, D, E, F, G, H) \
 #define lengthof(TYPE, MEMBER) (sizeof(((TYPE *)0)->MEMBER))
 #endif
 #ifndef COVERQ
-#define COVERQ(v, d)  (((v)+(d)-1) / (d))
+#define COVERQ(v, d)  (((v) + (d) - 1) / (d))
 #endif
 #ifndef COVER
-#define COVER(v, d)   ((d)*COVERQ(v, d))
+#define COVER(v, d)   ((d) * COVERQ(v, d))
 #endif
 
 #define ULTRA_CHANNEL_PROTOCOL_SIGNATURE  SIGNATURE_32('E', 'C', 'N', 'L')
@@ -152,7 +152,6 @@ ULTRA_CHANNELCLI_STRING(u32 v)
 #define ULTRA_IO_DRIVER_DISABLES_INTS (0x1ULL << 5)
 #define ULTRA_IO_DRIVER_SUPPORTS_ENHANCED_RCVBUF_CHECKING (0x1ULL << 6)
 
-#pragma pack(push, 1)          /* both GCC and VC now allow this pragma */
 /* Common Channel Header */
 struct channel_header {
        u64 signature;          /* Signature */
@@ -192,7 +191,7 @@ struct channel_header {
        u8 filler[1];           /* Pad out to 128 byte cacheline */
        /* Please add all new single-byte values below here */
        u8 recover_channel;
-};
+} __packed;
 
 #define ULTRA_CHANNEL_ENABLE_INTS (0x1ULL << 0)
 
@@ -230,9 +229,7 @@ struct signal_queue_header {
                                 * to denote trouble with client's
                                 * fields */
        u8 filler[12];          /* Pad out to 64 byte cacheline */
-};
-
-#pragma pack(pop)
+} __packed;
 
 #define spar_signal_init(chan, QHDRFLD, QDATAFLD, QDATATYPE, ver, typ) \
        do {                                                            \
@@ -241,11 +238,11 @@ struct signal_queue_header {
                chan->QHDRFLD.chtype = typ;                             \
                chan->QHDRFLD.size = sizeof(chan->QDATAFLD);            \
                chan->QHDRFLD.signal_size = sizeof(QDATATYPE);          \
-               chan->QHDRFLD.sig_base_offset = (u64)(chan->QDATAFLD) \
+               chan->QHDRFLD.sig_base_offset = (u64)(chan->QDATAFLD) - \
                        (u64)(&chan->QHDRFLD);                          \
                chan->QHDRFLD.max_slots =                               \
-                       sizeof(chan->QDATAFLD)/sizeof(QDATATYPE);       \
-               chan->QHDRFLD.max_signals = chan->QHDRFLD.max_slots-1;  \
+                       sizeof(chan->QDATAFLD) / sizeof(QDATATYPE);     \
+               chan->QHDRFLD.max_signals = chan->QHDRFLD.max_slots - 1;\
        } while (0)
 
 /* Generic function useful for validating any type of channel when it is
index d2d35685d69f732d88de0a4f632f66da07ffaaec..6e813c77b97e44478afbe52f242626cb0b4c7a2f 100644 (file)
 #ifndef _DIAG_CHANNEL_H_
 #define _DIAG_CHANNEL_H_
 
-#define MAX_MODULE_NAME_SIZE 128       /* Maximum length of module name... */
-#define MAX_ADDITIONAL_INFO_SIZE 256   /* Maximum length of any additional
-                                        * info accompanying event...
-                                        */
-
 /* Levels of severity for diagnostic events, in order from lowest severity to
  * highest (i.e. fatal errors are the most severe, and should always be logged,
  * but info events rarely need to be logged except during debugging). The
index a559812342dc4b91825693281c2add52ae0eddd1..14e656ff73ecde3d825b8d30c7d1019905082e43 100644 (file)
@@ -147,6 +147,10 @@ struct phys_info {
        u16 pi_len;
 } __packed;
 
+#define MIN_NUMSIGNALS 64
+
+/* structs with pragma pack  */
+
 struct guest_phys_info {
        u64 address;
        u64 length;
@@ -183,7 +187,7 @@ struct vhba_config_max {    /* 20 bytes */
 } __packed;
 
 struct uiscmdrsp_scsi {
-       void *scsicmd;          /* the handle to the cmd that was received -
+       u64 handle;             /* the handle to the cmd that was received -
                                 * send it back as is in the rsp packet.  */
        u8 cmnd[MAX_CMND_SIZE]; /* the cdb for the command */
        u32 bufflen;            /* length of data to be transferred out or in */
@@ -437,24 +441,22 @@ struct uiscmdrsp_scsitaskmgmt {
        struct uisscsi_dest vdest;
 
            /* the vdisk for which this task mgmt is generated */
-       void *scsicmd;
+       u64 handle;
 
-           /* This is some handle that the guest has saved off for its own use.
+           /* This is a handle that the guest has saved off for its own use.
             * Its value is preserved by iopart & returned as is in the task
             * mgmt rsp.
             */
-       void *notify;
+       u64 notify_handle;
 
           /* For linux guests, this is a pointer to wait_queue_head that a
            * thread is waiting on to see if the taskmgmt command has completed.
-           * For windows guests, this is a pointer to a location that a waiting
-           * thread is testing to see if the taskmgmt command has completed.
            * When the rsp is received by guest, the thread receiving the
            * response uses this to notify the thread waiting for taskmgmt
            * command completion.  Its value is preserved by iopart & returned
            * as is in the task mgmt rsp.
            */
-       void *notifyresult;
+       u64 notifyresult_handle;
 
            /* this is a handle to location in guest where the result of the
             * taskmgmt command (result field) is to saved off when the response
@@ -486,24 +488,22 @@ struct uiscmdrsp_vdiskmgmt {
        struct uisscsi_dest vdest;
 
            /* the vdisk for which this task mgmt is generated */
-       void *scsicmd;
+       u64 handle;
 
-           /* This is some handle that the guest has saved off for its own use.
+           /* This is a handle that the guest has saved off for its own use.
             * Its value is preserved by iopart & returned as is in the task
             * mgmt rsp.
             */
-       void *notify;
+       u64 notify_handle;
 
            /* For linux guests, this is a pointer to wait_queue_head that a
             * thread is waiting on to see if the tskmgmt command has completed.
-            * For win32 guests, this is a pointer to a location that a waiting
-            * thread is testing to see if the taskmgmt command has completed.
             * When the rsp is received by guest, the thread receiving the
             * response uses this to notify the thread waiting for taskmgmt
             * command completion.  Its value is preserved by iopart & returned
             * as is in the task mgmt rsp.
             */
-       void *notifyresult;
+       u64 notifyresult_handle;
 
            /* this is a handle to location in guest where the result of the
             * taskmgmt command (result field) is to saved off when the response
index 4e19c28dc3d0e1653243013ae69c0f7884092ab3..0b3335a4b2064ab8e1738f74f5f0962508228ee9 100644 (file)
 #include <linux/seq_file.h>
 #include <linux/slab.h>
 
-
 /* PERIODIC_WORK an opaque structure to users.
  * Fields are declared only in the implementation .c files.
  */
 struct periodic_work;
 
-struct periodic_work *visor_periodic_work_create(ulong jiffy_interval,
-                                       struct workqueue_struct *workqueue,
-                                       void (*workfunc)(void *),
-                                       void *workfuncarg,
-                                       const char *devnam);
+struct periodic_work *
+visor_periodic_work_create(ulong jiffy_interval,
+                          struct workqueue_struct *workqueue,
+                          void (*workfunc)(void *),
+                          void *workfuncarg,
+                          const char *devnam);
 void visor_periodic_work_destroy(struct periodic_work *pw);
 bool visor_periodic_work_nextperiod(struct periodic_work *pw);
 bool visor_periodic_work_start(struct periodic_work *pw);
index a3631c3591f61cc088479ae90563e5e1f88752ff..115b7aa9560a8a1c231c27c22f6cfc134f5d1550 100644 (file)
@@ -86,8 +86,8 @@ bool visor_periodic_work_nextperiod(struct periodic_work *pw)
                pw->want_to_stop = false;
                rc = true;  /* yes, true; see visor_periodic_work_stop() */
                goto unlock;
-       } else if (queue_delayed_work(pw->workqueue, &pw->work,
-                                     pw->jiffy_interval) < 0) {
+       } else if (!queue_delayed_work(pw->workqueue, &pw->work,
+                                      pw->jiffy_interval)) {
                pw->is_scheduled = false;
                rc = false;
                goto unlock;
@@ -117,8 +117,8 @@ bool visor_periodic_work_start(struct periodic_work *pw)
                goto unlock;
        }
        INIT_DELAYED_WORK(&pw->work, &periodic_work_func);
-       if (queue_delayed_work(pw->workqueue, &pw->work,
-                              pw->jiffy_interval) < 0) {
+       if (!queue_delayed_work(pw->workqueue, &pw->work,
+                               pw->jiffy_interval)) {
                rc = false;
                goto unlock;
        }
index 2693c46afdc0bd7b284cb11254d8d31c5987c1b0..a4e117f101cfeb7ef6d7c5d06b3d24c5e5dc6497 100644 (file)
@@ -279,7 +279,7 @@ visorchannel_clear(struct visorchannel *channel, ulong offset, u8 ch,
        int written = 0;
        u8 *buf;
 
-       buf = (u8 *) __get_free_page(GFP_KERNEL);
+       buf = (u8 *)__get_free_page(GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
@@ -301,7 +301,7 @@ visorchannel_clear(struct visorchannel *channel, ulong offset, u8 ch,
        err = 0;
 
 cleanup:
-       free_page((unsigned long) buf);
+       free_page((unsigned long)buf);
        return err;
 }
 EXPORT_SYMBOL_GPL(visorchannel_clear);
@@ -332,7 +332,7 @@ EXPORT_SYMBOL_GPL(visorchannel_get_header);
  */
 #define SIG_WRITE_FIELD(channel, queue, sig_hdr, FIELD)                         \
        (visorchannel_write(channel,                                     \
-                           SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)\
+                           SIG_QUEUE_OFFSET(&channel->chan_hdr, queue) +\
                            offsetof(struct signal_queue_header, FIELD), \
                            &((sig_hdr)->FIELD),                         \
                            sizeof((sig_hdr)->FIELD)) >= 0)
@@ -468,7 +468,7 @@ signalinsert_inner(struct visorchannel *channel, u32 queue, void *msg)
                                   SIG_QUEUE_OFFSET(&channel->chan_hdr, queue) +
                                   offsetof(struct signal_queue_header,
                                            num_overflows),
-                                  &(sig_hdr.num_overflows),
+                                  &sig_hdr.num_overflows,
                                   sizeof(sig_hdr.num_overflows));
                return false;
        }
index 94419c36d2affdc2e3f54775fee102d701d7fe86..07594f43853d93dac0526f87b49321a29c9bcf6e 100644 (file)
@@ -696,7 +696,7 @@ struct visor_busdev {
 static int match_visorbus_dev_by_id(struct device *dev, void *data)
 {
        struct visor_device *vdev = to_visor_device(dev);
-       struct visor_busdev *id = (struct visor_busdev *)data;
+       struct visor_busdev *id = data;
        u32 bus_no = id->bus_no;
        u32 dev_no = id->dev_no;
 
index 7abd27a618f8d12f97e646c5d1f7b7ca541c497d..c8d8483bd4df78609f3d0561b0d6be7f9020845c 100644 (file)
@@ -46,21 +46,13 @@ enum vmcall_monitor_interface_method_tuple { /* VMCALL identification tuples  */
 
        VMCALL_IO_CONTROLVM_ADDR = 0x0501,      /* used by all Guests, not just
                                                 * IO */
-       VMCALL_IO_DIAG_ADDR = 0x0508,
-       VMCALL_IO_VISORSERIAL_ADDR = 0x0509,
        VMCALL_QUERY_GUEST_VIRTUAL_TIME_OFFSET = 0x0708, /* Allow caller to
                                                          * query virtual time
                                                          * offset */
-       VMCALL_CHANNEL_VERSION_MISMATCH = 0x0709,
        VMCALL_POST_CODE_LOGEVENT = 0x070B,     /* LOGEVENT Post Code (RDX) with
                                                 * specified subsystem mask (RCX
                                                 * - monitor_subsystems.h) and
                                                 * severity (RDX) */
-       VMCALL_GENERIC_SURRENDER_QUANTUM_FOREVER = 0x0802, /* Yield the
-                                                           * remainder & all
-                                                           * future quantums of
-                                                           * the caller */
-       VMCALL_MEASUREMENT_DO_NOTHING = 0x0901,
        VMCALL_UPDATE_PHYSICAL_TIME = 0x0a02    /* Allow
                                                 * ULTRA_SERVICE_CAPABILITY_TIME
                                                 * capable guest to make
@@ -90,9 +82,6 @@ enum vmcall_monitor_interface_method_tuple { /* VMCALL identification tuples  */
 
 /* Structures for IO VMCALLs */
 
-/* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */
-/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
-#pragma pack(push, 1)
 /* Parameters to VMCALL_IO_CONTROLVM_ADDR interface */
 struct vmcall_io_controlvm_addr_params {
            /* The Guest-relative physical address of the ControlVm channel.
@@ -102,47 +91,6 @@ struct vmcall_io_controlvm_addr_params {
            * in with the appropriate address. */
        u32 channel_bytes;      /* contents provided by this VMCALL (OUT) */
        u8 unused[4];           /* Unused Bytes in the 64-Bit Aligned Struct */
-};
-
-#pragma pack(pop)
-/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
-
-/* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */
-/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
-#pragma pack(push, 1)
-/* Parameters to VMCALL_IO_DIAG_ADDR interface */
-struct vmcall_io_diag_addr_params {
-           /* The Guest-relative physical address of the diagnostic channel.
-           * This VMCall fills this in with the appropriate address. */
-       u64 address;    /* contents provided by this VMCALL (OUT) */
-};
-
-#pragma pack(pop)
-/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
-
-/* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */
-/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
-#pragma pack(push, 1)
-/* Parameters to VMCALL_IO_VISORSERIAL_ADDR interface */
-struct vmcall_io_visorserial_addr_params {
-           /* The Guest-relative physical address of the serial console
-           * channel.  This VMCall fills this in with the appropriate
-           * address. */
-       u64 address;    /* contents provided by this VMCALL (OUT) */
-};
-
-#pragma pack(pop)
-/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
-
-/* Parameters to VMCALL_CHANNEL_MISMATCH interface */
-struct vmcall_channel_version_mismatch_params {
-       u8 chname[32];  /* Null terminated string giving name of channel
-                                * (IN) */
-       u8 item_name[32];       /* Null terminated string giving name of
-                                * mismatched item (IN) */
-       u32 line_no;            /* line# where invoked. (IN) */
-       u8 file_name[36];       /* source code where invoked - Null terminated
-                                * string (IN) */
-};
+} __packed;
 
 #endif /* __IOMONINTF_H__ */
diff --git a/drivers/staging/unisys/visorhba/Kconfig b/drivers/staging/unisys/visorhba/Kconfig
new file mode 100644 (file)
index 0000000..241d803
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# Unisys visorhba configuration
+#
+
+config UNISYS_VISORHBA
+       tristate "Unisys visorhba driver"
+       depends on UNISYSSPAR && UNISYS_VISORBUS && SCSI
+       ---help---
+       The Unisys visorhba driver provides support for s-Par HBA
+       devices exposed on the s-Par visorbus. When a message is sent
+       to visorbus to create a HBA device, the probe function of
+       visorhba is called to create the scsi device.
+       If you say Y here, you will enable the Unisys visorhba driver.
+
diff --git a/drivers/staging/unisys/visorhba/Makefile b/drivers/staging/unisys/visorhba/Makefile
new file mode 100644 (file)
index 0000000..a8a8e0e
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# Makefile for Unisys channel
+#
+
+obj-$(CONFIG_UNISYS_VISORHBA)  += visorhba.o
+
+visorhba-y := visorhba_main.o
+
+ccflags-y += -Idrivers/staging/unisys/include
+
diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c
new file mode 100644 (file)
index 0000000..c119f20
--- /dev/null
@@ -0,0 +1,1241 @@
+/* Copyright (c) 2012 - 2015 UNISYS CORPORATION
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ */
+
+#include <linux/debugfs.h>
+#include <linux/skbuff.h>
+#include <linux/kthread.h>
+#include <scsi/scsi.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
+
+#include "visorbus.h"
+#include "iochannel.h"
+
+/* The Send and Receive Buffers of the IO Queue may both be full */
+
+#define IOS_ERROR_THRESHOLD    1000
+/* MAX_BUF = 6 lines x 10 MAXVHBA x 80 characters
+ *         = 4800 bytes ~ 2^13 = 8192 bytes
+ */
+#define MAX_BUF                        8192
+#define MAX_PENDING_REQUESTS   (MIN_NUMSIGNALS * 2)
+#define VISORHBA_ERROR_COUNT   30
+#define VISORHBA_OPEN_MAX      1
+
+static int visorhba_queue_command_lck(struct scsi_cmnd *scsicmd,
+                                     void (*visorhba_cmnd_done)
+                                           (struct scsi_cmnd *));
+#ifdef DEF_SCSI_QCMD
+static DEF_SCSI_QCMD(visorhba_queue_command)
+#else
+#define visorhba_queue_command visorhba_queue_command_lck
+#endif
+static int visorhba_probe(struct visor_device *dev);
+static void visorhba_remove(struct visor_device *dev);
+static int visorhba_pause(struct visor_device *dev,
+                         visorbus_state_complete_func complete_func);
+static int visorhba_resume(struct visor_device *dev,
+                          visorbus_state_complete_func complete_func);
+
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+                                size_t len, loff_t *offset);
+static struct dentry *visorhba_debugfs_dir;
+static const struct file_operations debugfs_info_fops = {
+       .read = info_debugfs_read,
+};
+
+/* GUIDS for HBA channel type supported by this driver */
+static struct visor_channeltype_descriptor visorhba_channel_types[] = {
+       /* Note that the only channel type we expect to be reported by the
+        * bus driver is the SPAR_VHBA channel.
+        */
+       { SPAR_VHBA_CHANNEL_PROTOCOL_UUID, "sparvhba" },
+       { NULL_UUID_LE, NULL }
+};
+
+/* This is used to tell the visor bus driver which types of visor devices
+ * we support, and what functions to call when a visor device that we support
+ * is attached or removed.
+ */
+static struct visor_driver visorhba_driver = {
+       .name = "visorhba",
+       .owner = THIS_MODULE,
+       .channel_types = visorhba_channel_types,
+       .probe = visorhba_probe,
+       .remove = visorhba_remove,
+       .pause = visorhba_pause,
+       .resume = visorhba_resume,
+       .channel_interrupt = NULL,
+};
+MODULE_DEVICE_TABLE(visorbus, visorhba_channel_types);
+MODULE_ALIAS("visorbus:" SPAR_VHBA_CHANNEL_PROTOCOL_UUID_STR);
+
+struct visor_thread_info {
+       struct task_struct *task;
+       struct completion has_stopped;
+       int id;
+};
+
+struct visordisk_info {
+       u32 valid;
+       u32 channel, id, lun;   /* Disk Path */
+       atomic_t ios_threshold;
+       atomic_t error_count;
+       struct visordisk_info *next;
+};
+
+struct scsipending {
+       struct uiscmdrsp cmdrsp;
+       void *sent;             /* The Data being tracked */
+       char cmdtype;           /* Type of pointer that is being stored */
+};
+
+/* Work Data for dar_work_queue */
+struct diskaddremove {
+       u8 add;                 /* 0-remove, 1-add */
+       struct Scsi_Host *shost; /* Scsi Host for this visorhba instance */
+       u32 channel, id, lun;   /* Disk Path */
+       struct diskaddremove *next;
+};
+
+/* Each scsi_host has a host_data area that contains this struct. */
+struct visorhba_devdata {
+       struct Scsi_Host *scsihost;
+       struct visor_device *dev;
+       struct list_head dev_info_list;
+       /* Tracks the requests that have been forwarded to
+        * the IOVM and haven't returned yet
+        */
+       struct scsipending pending[MAX_PENDING_REQUESTS];
+       /* Start search for next pending free slot here */
+       unsigned int nextinsert;
+       spinlock_t privlock; /* lock to protect data in devdata */
+       bool serverdown;
+       bool serverchangingstate;
+       unsigned long long acquire_failed_cnt;
+       unsigned long long interrupts_rcvd;
+       unsigned long long interrupts_notme;
+       unsigned long long interrupts_disabled;
+       u64 __iomem *flags_addr;
+       atomic_t interrupt_rcvd;
+       wait_queue_head_t rsp_queue;
+       struct visordisk_info head;
+       unsigned int max_buff_len;
+       int devnum;
+       struct visor_thread_info threadinfo;
+       int thread_wait_ms;
+};
+
+struct visorhba_devices_open {
+       struct visorhba_devdata *devdata;
+};
+
+static struct visorhba_devices_open visorhbas_open[VISORHBA_OPEN_MAX];
+
+#define for_each_vdisk_match(iter, list, match)                          \
+       for (iter = &list->head; iter->next; iter = iter->next) \
+               if ((iter->channel == match->channel) &&                  \
+                   (iter->id == match->id) &&                    \
+                   (iter->lun == match->lun))
+/**
+ *     visor_thread_start - starts a thread for the device
+ *     @thrinfo: The thread to start
+ *     @threadfn: Function the thread starts
+ *     @thrcontext: Context to pass to the thread, i.e. devdata
+ *     @name: string describing name of thread
+ *
+ *     Starts a thread for the device.
+ *
+ *     Return 0 on success;
+ */
+static int visor_thread_start(struct visor_thread_info *thrinfo,
+                             int (*threadfn)(void *),
+                             void *thrcontext, char *name)
+{
+       /* used to stop the thread */
+       init_completion(&thrinfo->has_stopped);
+       thrinfo->task = kthread_run(threadfn, thrcontext, name);
+       if (IS_ERR(thrinfo->task)) {
+               thrinfo->id = 0;
+               return PTR_ERR(thrinfo->task);
+       }
+       thrinfo->id = thrinfo->task->pid;
+       return 0;
+}
+
+/**
+ *     add_scsipending_entry - save off io command that is pending in
+ *                             Service Partition
+ *     @devdata: Pointer to devdata
+ *     @cmdtype: Specifies the type of command pending
+ *     @new:   The command to be saved
+ *
+ *     Saves off the io command that is being handled by the Service
+ *     Partition so that it can be handled when it completes. If new is
+ *     NULL it is assumed the entry refers only to the cmdrsp.
+ *     Returns insert_location where entry was added,
+ *     SCSI_MLQUEUE_DEVICE_BUSY if it can't
+ */
+static int add_scsipending_entry(struct visorhba_devdata *devdata,
+                                char cmdtype, void *new)
+{
+       unsigned long flags;
+       struct scsipending *entry;
+       int insert_location;
+
+       spin_lock_irqsave(&devdata->privlock, flags);
+       insert_location = devdata->nextinsert;
+       while (devdata->pending[insert_location].sent) {
+               insert_location = (insert_location + 1) % MAX_PENDING_REQUESTS;
+               if (insert_location == (int)devdata->nextinsert) {
+                       spin_unlock_irqrestore(&devdata->privlock, flags);
+                       return -1;
+               }
+       }
+
+       entry = &devdata->pending[insert_location];
+       memset(&entry->cmdrsp, 0, sizeof(entry->cmdrsp));
+       entry->cmdtype = cmdtype;
+       if (new)
+               entry->sent = new;
+       else /* wants to send cmdrsp */
+               entry->sent = &entry->cmdrsp;
+       devdata->nextinsert = (insert_location + 1) % MAX_PENDING_REQUESTS;
+       spin_unlock_irqrestore(&devdata->privlock, flags);
+
+       return insert_location;
+}
+
+/**
+ *     del_scsipending_enty - removes an entry from the pending array
+ *     @devdata: Device holding the pending array
+ *     @del: Entry to remove
+ *
+ *     Removes the entry pointed at by del and returns it.
+ *     Returns the scsipending entry pointed at
+ */
+static void *del_scsipending_ent(struct visorhba_devdata *devdata,
+                                int del)
+{
+       unsigned long flags;
+       void *sent = NULL;
+
+       if (del < MAX_PENDING_REQUESTS) {
+               spin_lock_irqsave(&devdata->privlock, flags);
+               sent = devdata->pending[del].sent;
+
+               devdata->pending[del].cmdtype = 0;
+               devdata->pending[del].sent = NULL;
+               spin_unlock_irqrestore(&devdata->privlock, flags);
+       }
+
+       return sent;
+}
+
+/**
+ *     get_scsipending_cmdrsp - return the cmdrsp stored in a pending entry
+ *     #ddata: Device holding the pending array
+ *     @ent: Entry that stores the cmdrsp
+ *
+ *     Each scsipending entry has a cmdrsp in it. The cmdrsp is only valid
+ *     if the "sent" field is not NULL
+ *     Returns a pointer to the cmdrsp.
+ */
+static struct uiscmdrsp *get_scsipending_cmdrsp(struct visorhba_devdata *ddata,
+                                               int ent)
+{
+       if (ddata->pending[ent].sent)
+               return &ddata->pending[ent].cmdrsp;
+
+       return NULL;
+}
+
+/**
+ *     forward_taskmgmt_command - send taskmegmt command to the Service
+ *                                Partition
+ *     @tasktype: Type of taskmgmt command
+ *     @scsidev: Scsidev that issued command
+ *
+ *     Create a cmdrsp packet and send it to the Serivce Partition
+ *     that will service this request.
+ *     Returns whether the command was queued successfully or not.
+ */
+static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
+                                   struct scsi_cmnd *scsicmd)
+{
+       struct uiscmdrsp *cmdrsp;
+       struct scsi_device *scsidev = scsicmd->device;
+       struct visorhba_devdata *devdata =
+               (struct visorhba_devdata *)scsidev->host->hostdata;
+       int notifyresult = 0xffff;
+       wait_queue_head_t notifyevent;
+       int scsicmd_id = 0;
+
+       if (devdata->serverdown || devdata->serverchangingstate)
+               return FAILED;
+
+       scsicmd_id = add_scsipending_entry(devdata, CMD_SCSITASKMGMT_TYPE,
+                                          NULL);
+       if (scsicmd_id < 0)
+               return FAILED;
+
+       cmdrsp = get_scsipending_cmdrsp(devdata, scsicmd_id);
+
+       init_waitqueue_head(&notifyevent);
+
+       /* issue TASK_MGMT_ABORT_TASK */
+       cmdrsp->cmdtype = CMD_SCSITASKMGMT_TYPE;
+       /* specify the event that has to be triggered when this */
+       /* cmd is complete */
+       cmdrsp->scsitaskmgmt.notify_handle = (u64)&notifyevent;
+       cmdrsp->scsitaskmgmt.notifyresult_handle = (u64)&notifyresult;
+
+       /* save destination */
+       cmdrsp->scsitaskmgmt.tasktype = tasktype;
+       cmdrsp->scsitaskmgmt.vdest.channel = scsidev->channel;
+       cmdrsp->scsitaskmgmt.vdest.id = scsidev->id;
+       cmdrsp->scsitaskmgmt.vdest.lun = scsidev->lun;
+       cmdrsp->scsitaskmgmt.handle = scsicmd_id;
+
+       if (!visorchannel_signalinsert(devdata->dev->visorchannel,
+                                      IOCHAN_TO_IOPART,
+                                      cmdrsp))
+               goto err_del_scsipending_ent;
+
+       /* It can take the Service Partition up to 35 seconds to complete
+        * an IO in some cases, so wait 45 seconds and error out
+        */
+       if (!wait_event_timeout(notifyevent, notifyresult != 0xffff,
+                               msecs_to_jiffies(45000)))
+               goto err_del_scsipending_ent;
+
+       if (tasktype == TASK_MGMT_ABORT_TASK)
+               scsicmd->result = (DID_ABORT << 16);
+       else
+               scsicmd->result = (DID_RESET << 16);
+
+       scsicmd->scsi_done(scsicmd);
+
+       return SUCCESS;
+
+err_del_scsipending_ent:
+       del_scsipending_ent(devdata, scsicmd_id);
+       return FAILED;
+}
+
+/**
+ *     visorhba_abort_handler - Send TASK_MGMT_ABORT_TASK
+ *     @scsicmd: The scsicmd that needs aborted
+ *
+ *     Returns SUCCESS if inserted, failure otherwise
+ *
+ */
+static int visorhba_abort_handler(struct scsi_cmnd *scsicmd)
+{
+       /* issue TASK_MGMT_ABORT_TASK */
+       struct scsi_device *scsidev;
+       struct visordisk_info *vdisk;
+       struct visorhba_devdata *devdata;
+
+       scsidev = scsicmd->device;
+       devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
+       for_each_vdisk_match(vdisk, devdata, scsidev) {
+               if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
+                       atomic_inc(&vdisk->error_count);
+               else
+                       atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+       }
+       return forward_taskmgmt_command(TASK_MGMT_ABORT_TASK, scsicmd);
+}
+
+/**
+ *     visorhba_device_reset_handler - Send TASK_MGMT_LUN_RESET
+ *     @scsicmd: The scsicmd that needs aborted
+ *
+ *     Returns SUCCESS if inserted, failure otherwise
+ */
+static int visorhba_device_reset_handler(struct scsi_cmnd *scsicmd)
+{
+       /* issue TASK_MGMT_LUN_RESET */
+       struct scsi_device *scsidev;
+       struct visordisk_info *vdisk;
+       struct visorhba_devdata *devdata;
+
+       scsidev = scsicmd->device;
+       devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
+       for_each_vdisk_match(vdisk, devdata, scsidev) {
+               if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
+                       atomic_inc(&vdisk->error_count);
+               else
+                       atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+       }
+       return forward_taskmgmt_command(TASK_MGMT_LUN_RESET, scsicmd);
+}
+
+/**
+ *     visorhba_bus_reset_handler - Send TASK_MGMT_TARGET_RESET for each
+ *                                  target on the bus
+ *     @scsicmd: The scsicmd that needs aborted
+ *
+ *     Returns SUCCESS
+ */
+static int visorhba_bus_reset_handler(struct scsi_cmnd *scsicmd)
+{
+       struct scsi_device *scsidev;
+       struct visordisk_info *vdisk;
+       struct visorhba_devdata *devdata;
+
+       scsidev = scsicmd->device;
+       devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
+       for_each_vdisk_match(vdisk, devdata, scsidev) {
+               if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT)
+                       atomic_inc(&vdisk->error_count);
+               else
+                       atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+       }
+       return forward_taskmgmt_command(TASK_MGMT_BUS_RESET, scsicmd);
+}
+
+/**
+ *     visorhba_host_reset_handler - Not supported
+ *     @scsicmd: The scsicmd that needs aborted
+ *
+ *     Not supported, return SUCCESS
+ *     Returns SUCCESS
+ */
+static int
+visorhba_host_reset_handler(struct scsi_cmnd *scsicmd)
+{
+       /* issue TASK_MGMT_TARGET_RESET for each target on each bus for host */
+       return SUCCESS;
+}
+
+/**
+ *     visorhba_get_info
+ *     @shp: Scsi host that is requesting information
+ *
+ *     Returns string with info
+ */
+static const char *visorhba_get_info(struct Scsi_Host *shp)
+{
+       /* Return version string */
+       return "visorhba";
+}
+
+/**
+ *     visorhba_queue_command_lck -- queues command to the Service Partition
+ *     @scsicmd: Command to be queued
+ *     @vsiorhba_cmnd_done: Done command to call when scsicmd is returned
+ *
+ *     Queues to scsicmd to the ServicePartition after converting it to a
+ *     uiscmdrsp structure.
+ *
+ *     Returns success if queued to the Service Partition, otherwise
+ *     failure.
+ */
+static int
+visorhba_queue_command_lck(struct scsi_cmnd *scsicmd,
+                          void (*visorhba_cmnd_done)(struct scsi_cmnd *))
+{
+       struct uiscmdrsp *cmdrsp;
+       struct scsi_device *scsidev = scsicmd->device;
+       int insert_location;
+       unsigned char op;
+       unsigned char *cdb = scsicmd->cmnd;
+       struct Scsi_Host *scsihost = scsidev->host;
+       unsigned int i;
+       struct visorhba_devdata *devdata =
+               (struct visorhba_devdata *)scsihost->hostdata;
+       struct scatterlist *sg = NULL;
+       struct scatterlist *sglist = NULL;
+       int err = 0;
+
+       if (devdata->serverdown || devdata->serverchangingstate)
+               return SCSI_MLQUEUE_DEVICE_BUSY;
+
+       insert_location = add_scsipending_entry(devdata, CMD_SCSI_TYPE,
+                                               (void *)scsicmd);
+
+       if (insert_location < 0)
+               return SCSI_MLQUEUE_DEVICE_BUSY;
+
+       cmdrsp = get_scsipending_cmdrsp(devdata, insert_location);
+
+       cmdrsp->cmdtype = CMD_SCSI_TYPE;
+       /* save the pending insertion location. Deletion from pending
+        * will return the scsicmd pointer for completion
+        */
+       cmdrsp->scsi.handle = insert_location;
+
+       /* save done function that we have call when cmd is complete */
+       scsicmd->scsi_done = visorhba_cmnd_done;
+       /* save destination */
+       cmdrsp->scsi.vdest.channel = scsidev->channel;
+       cmdrsp->scsi.vdest.id = scsidev->id;
+       cmdrsp->scsi.vdest.lun = scsidev->lun;
+       /* save datadir */
+       cmdrsp->scsi.data_dir = scsicmd->sc_data_direction;
+       memcpy(cmdrsp->scsi.cmnd, cdb, MAX_CMND_SIZE);
+
+       cmdrsp->scsi.bufflen = scsi_bufflen(scsicmd);
+
+       /* keep track of the max buffer length so far. */
+       if (cmdrsp->scsi.bufflen > devdata->max_buff_len)
+               devdata->max_buff_len = cmdrsp->scsi.bufflen;
+
+       if (scsi_sg_count(scsicmd) > MAX_PHYS_INFO) {
+               err = SCSI_MLQUEUE_DEVICE_BUSY;
+               goto err_del_scsipending_ent;
+       }
+
+       /* convert buffer to phys information  */
+       /* buffer is scatterlist - copy it out */
+       sglist = scsi_sglist(scsicmd);
+
+       for_each_sg(sglist, sg, scsi_sg_count(scsicmd), i) {
+               cmdrsp->scsi.gpi_list[i].address = sg_phys(sg);
+               cmdrsp->scsi.gpi_list[i].length = sg->length;
+       }
+       cmdrsp->scsi.guest_phys_entries = scsi_sg_count(scsicmd);
+
+       op = cdb[0];
+       if (!visorchannel_signalinsert(devdata->dev->visorchannel,
+                                      IOCHAN_TO_IOPART,
+                                      cmdrsp)) {
+               /* queue must be full and we aren't going to wait */
+               err = SCSI_MLQUEUE_DEVICE_BUSY;
+               goto err_del_scsipending_ent;
+       }
+       return 0;
+
+err_del_scsipending_ent:
+       del_scsipending_ent(devdata, insert_location);
+       return err;
+}
+
+/**
+ *     visorhba_slave_alloc - called when new disk is discovered
+ *     @scsidev: New disk
+ *
+ *     Create a new visordisk_info structure and add it to our
+ *     list of vdisks.
+ *
+ *     Returns success when created, otherwise error.
+ */
+static int visorhba_slave_alloc(struct scsi_device *scsidev)
+{
+       /* this is called by the midlayer before scan for new devices --
+        * LLD can alloc any struct & do init if needed.
+        */
+       struct visordisk_info *vdisk;
+       struct visordisk_info *tmpvdisk;
+       struct visorhba_devdata *devdata;
+       struct Scsi_Host *scsihost = (struct Scsi_Host *)scsidev->host;
+
+       devdata = (struct visorhba_devdata *)scsihost->hostdata;
+       if (!devdata)
+               return 0; /* even though we errored, treat as success */
+
+       for_each_vdisk_match(vdisk, devdata, scsidev)
+               return 0; /* already allocated return success */
+
+       tmpvdisk = kzalloc(sizeof(*tmpvdisk), GFP_ATOMIC);
+       if (!tmpvdisk)
+               return -ENOMEM;
+
+       tmpvdisk->channel = scsidev->channel;
+       tmpvdisk->id = scsidev->id;
+       tmpvdisk->lun = scsidev->lun;
+       vdisk->next = tmpvdisk;
+       return 0;
+}
+
+/**
+ *     visorhba_slave_destroy - disk is going away
+ *     @scsidev: scsi device going away
+ *
+ *     Disk is going away, clean up resources.
+ *     Returns void.
+ */
+static void visorhba_slave_destroy(struct scsi_device *scsidev)
+{
+       /* midlevel calls this after device has been quiesced and
+        * before it is to be deleted.
+        */
+       struct visordisk_info *vdisk, *delvdisk;
+       struct visorhba_devdata *devdata;
+       struct Scsi_Host *scsihost = (struct Scsi_Host *)scsidev->host;
+
+       devdata = (struct visorhba_devdata *)scsihost->hostdata;
+       for_each_vdisk_match(vdisk, devdata, scsidev) {
+               delvdisk = vdisk->next;
+               vdisk->next = delvdisk->next;
+               kfree(delvdisk);
+               return;
+       }
+}
+
+static struct scsi_host_template visorhba_driver_template = {
+       .name = "Unisys Visor HBA",
+       .info = visorhba_get_info,
+       .queuecommand = visorhba_queue_command,
+       .eh_abort_handler = visorhba_abort_handler,
+       .eh_device_reset_handler = visorhba_device_reset_handler,
+       .eh_bus_reset_handler = visorhba_bus_reset_handler,
+       .eh_host_reset_handler = visorhba_host_reset_handler,
+       .shost_attrs = NULL,
+#define visorhba_MAX_CMNDS 128
+       .can_queue = visorhba_MAX_CMNDS,
+       .sg_tablesize = 64,
+       .this_id = -1,
+       .slave_alloc = visorhba_slave_alloc,
+       .slave_destroy = visorhba_slave_destroy,
+       .use_clustering = ENABLE_CLUSTERING,
+};
+
+/**
+ *     info_debugfs_read - debugfs interface to dump visorhba states
+ *     @file: Debug file
+ *     @buf: buffer to send back to user
+ *     @len: len that can be written to buf
+ *     @offset: offset into buf
+ *
+ *     Dumps information about the visorhba driver and devices
+ *     TODO: Make this per vhba
+ *     Returns bytes_read
+ */
+static ssize_t info_debugfs_read(struct file *file, char __user *buf,
+                                size_t len, loff_t *offset)
+{
+       ssize_t bytes_read = 0;
+       int str_pos = 0;
+       u64 phys_flags_addr;
+       int i;
+       struct visorhba_devdata *devdata;
+       char *vbuf;
+
+       if (len > MAX_BUF)
+               len = MAX_BUF;
+       vbuf = kzalloc(len, GFP_KERNEL);
+       if (!vbuf)
+               return -ENOMEM;
+
+       for (i = 0; i < VISORHBA_OPEN_MAX; i++) {
+               if (!visorhbas_open[i].devdata)
+                       continue;
+
+               devdata = visorhbas_open[i].devdata;
+
+               str_pos += scnprintf(vbuf + str_pos,
+                               len - str_pos, "max_buff_len:%u\n",
+                               devdata->max_buff_len);
+
+               str_pos += scnprintf(vbuf + str_pos, len - str_pos,
+                               "\ninterrupts_rcvd = %llu, interrupts_disabled = %llu\n",
+                               devdata->interrupts_rcvd,
+                               devdata->interrupts_disabled);
+               str_pos += scnprintf(vbuf + str_pos,
+                               len - str_pos, "\ninterrupts_notme = %llu,\n",
+                               devdata->interrupts_notme);
+               phys_flags_addr = virt_to_phys((__force  void *)
+                                              devdata->flags_addr);
+               str_pos += scnprintf(vbuf + str_pos, len - str_pos,
+                               "flags_addr = %p, phys_flags_addr=0x%016llx, FeatureFlags=%llu\n",
+                               devdata->flags_addr, phys_flags_addr,
+                               (__le64)readq(devdata->flags_addr));
+               str_pos += scnprintf(vbuf + str_pos,
+                       len - str_pos, "acquire_failed_cnt:%llu\n",
+                       devdata->acquire_failed_cnt);
+               str_pos += scnprintf(vbuf + str_pos, len - str_pos, "\n");
+       }
+
+       bytes_read = simple_read_from_buffer(buf, len, offset, vbuf, str_pos);
+       kfree(vbuf);
+       return bytes_read;
+}
+
+/**
+ *     visorhba_serverdown_complete - Called when we are done cleaning up
+ *                                    from serverdown
+ *     @work: work structure for this serverdown request
+ *
+ *     Called when we are done cleanning up from serverdown, stop processing
+ *     queue, fail pending IOs.
+ *     Returns void when finished cleaning up
+ */
+static void visorhba_serverdown_complete(struct visorhba_devdata *devdata)
+{
+       int i;
+       struct scsipending *pendingdel = NULL;
+       struct scsi_cmnd *scsicmd = NULL;
+       struct uiscmdrsp *cmdrsp;
+       unsigned long flags;
+
+       /* Stop using the IOVM response queue (queue should be drained
+        * by the end)
+        */
+       kthread_stop(devdata->threadinfo.task);
+
+       /* Fail commands that weren't completed */
+       spin_lock_irqsave(&devdata->privlock, flags);
+       for (i = 0; i < MAX_PENDING_REQUESTS; i++) {
+               pendingdel = &devdata->pending[i];
+               switch (pendingdel->cmdtype) {
+               case CMD_SCSI_TYPE:
+                       scsicmd = pendingdel->sent;
+                       scsicmd->result = DID_RESET << 16;
+                       if (scsicmd->scsi_done)
+                               scsicmd->scsi_done(scsicmd);
+                       break;
+               case CMD_SCSITASKMGMT_TYPE:
+                       cmdrsp = pendingdel->sent;
+                       cmdrsp->scsitaskmgmt.notifyresult_handle
+                                                       = TASK_MGMT_FAILED;
+                       wake_up_all((wait_queue_head_t *)
+                                   cmdrsp->scsitaskmgmt.notify_handle);
+                       break;
+               case CMD_VDISKMGMT_TYPE:
+                       cmdrsp = pendingdel->sent;
+                       cmdrsp->vdiskmgmt.notifyresult_handle
+                                                       = VDISK_MGMT_FAILED;
+                       wake_up_all((wait_queue_head_t *)
+                                   cmdrsp->vdiskmgmt.notify_handle);
+                       break;
+               default:
+                       break;
+               }
+               pendingdel->cmdtype = 0;
+               pendingdel->sent = NULL;
+       }
+       spin_unlock_irqrestore(&devdata->privlock, flags);
+
+       devdata->serverdown = true;
+       devdata->serverchangingstate = false;
+}
+
+/**
+ *     visorhba_serverdown - Got notified that the IOVM is down
+ *     @devdata: visorhba that is being serviced by downed IOVM.
+ *
+ *     Something happened to the IOVM, return immediately and
+ *     schedule work cleanup work.
+ *     Return SUCCESS or EINVAL
+ */
+static int visorhba_serverdown(struct visorhba_devdata *devdata)
+{
+       if (!devdata->serverdown && !devdata->serverchangingstate) {
+               devdata->serverchangingstate = true;
+               visorhba_serverdown_complete(devdata);
+       } else if (devdata->serverchangingstate) {
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/**
+ *     do_scsi_linuxstat - scsi command returned linuxstat
+ *     @cmdrsp: response from IOVM
+ *     @scsicmd: Command issued.
+ *
+ *     Don't log errors for disk-not-present inquiries
+ *     Returns void
+ */
+static void
+do_scsi_linuxstat(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd)
+{
+       struct visorhba_devdata *devdata;
+       struct visordisk_info *vdisk;
+       struct scsi_device *scsidev;
+       struct sense_data *sd;
+
+       scsidev = scsicmd->device;
+       memcpy(scsicmd->sense_buffer, cmdrsp->scsi.sensebuf, MAX_SENSE_SIZE);
+       sd = (struct sense_data *)scsicmd->sense_buffer;
+
+       /* Do not log errors for disk-not-present inquiries */
+       if ((cmdrsp->scsi.cmnd[0] == INQUIRY) &&
+           (host_byte(cmdrsp->scsi.linuxstat) == DID_NO_CONNECT) &&
+           (cmdrsp->scsi.addlstat == ADDL_SEL_TIMEOUT))
+               return;
+       /* Okay see what our error_count is here.... */
+       devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
+       for_each_vdisk_match(vdisk, devdata, scsidev) {
+               if (atomic_read(&vdisk->error_count) < VISORHBA_ERROR_COUNT) {
+                       atomic_inc(&vdisk->error_count);
+                       atomic_set(&vdisk->ios_threshold, IOS_ERROR_THRESHOLD);
+               }
+       }
+}
+
+/**
+ *     do_scsi_nolinuxstat - scsi command didn't have linuxstat
+ *     @cmdrsp: response from IOVM
+ *     @scsicmd: Command issued.
+ *
+ *     Handle response when no linuxstat was returned
+ *     Returns void
+ */
+static void
+do_scsi_nolinuxstat(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd)
+{
+       struct scsi_device *scsidev;
+       unsigned char buf[36];
+       struct scatterlist *sg;
+       unsigned int i;
+       char *this_page;
+       char *this_page_orig;
+       int bufind = 0;
+       struct visordisk_info *vdisk;
+       struct visorhba_devdata *devdata;
+
+       scsidev = scsicmd->device;
+       if ((cmdrsp->scsi.cmnd[0] == INQUIRY) &&
+           (cmdrsp->scsi.bufflen >= MIN_INQUIRY_RESULT_LEN)) {
+               if (cmdrsp->scsi.no_disk_result == 0)
+                       return;
+
+               /* Linux scsi code wants a device at Lun 0
+                * to issue report luns, but we don't want
+                * a disk there so we'll present a processor
+                * there.
+                */
+               SET_NO_DISK_INQUIRY_RESULT(buf, cmdrsp->scsi.bufflen,
+                                          scsidev->lun,
+                                          DEV_DISK_CAPABLE_NOT_PRESENT,
+                                          DEV_NOT_CAPABLE);
+
+               if (scsi_sg_count(scsicmd) == 0) {
+                       memcpy(scsi_sglist(scsicmd), buf,
+                              cmdrsp->scsi.bufflen);
+                       return;
+               }
+
+               sg = scsi_sglist(scsicmd);
+               for (i = 0; i < scsi_sg_count(scsicmd); i++) {
+                       this_page_orig = kmap_atomic(sg_page(sg + i));
+                       this_page = (void *)((unsigned long)this_page_orig |
+                                            sg[i].offset);
+                       memcpy(this_page, buf + bufind, sg[i].length);
+                       kunmap_atomic(this_page_orig);
+               }
+       } else {
+               devdata = (struct visorhba_devdata *)scsidev->host->hostdata;
+               for_each_vdisk_match(vdisk, devdata, scsidev) {
+                       if (atomic_read(&vdisk->ios_threshold) > 0) {
+                               atomic_dec(&vdisk->ios_threshold);
+                               if (atomic_read(&vdisk->ios_threshold) == 0)
+                                       atomic_set(&vdisk->error_count, 0);
+                       }
+               }
+       }
+}
+
+/**
+ *     complete_scsi_command - complete a scsi command
+ *     @uiscmdrsp: Response from Service Partition
+ *     @scsicmd: The scsi command
+ *
+ *     Response returned by the Service Partition, finish it and send
+ *     completion to the scsi midlayer.
+ *     Returns void.
+ */
+static void
+complete_scsi_command(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd)
+{
+       /* take what we need out of cmdrsp and complete the scsicmd */
+       scsicmd->result = cmdrsp->scsi.linuxstat;
+       if (cmdrsp->scsi.linuxstat)
+               do_scsi_linuxstat(cmdrsp, scsicmd);
+       else
+               do_scsi_nolinuxstat(cmdrsp, scsicmd);
+
+       scsicmd->scsi_done(scsicmd);
+}
+
+/* DELETE VDISK TASK MGMT COMMANDS */
+static inline void complete_vdiskmgmt_command(struct uiscmdrsp *cmdrsp)
+{
+       /* copy the result of the taskmgmt and
+        * wake up the error handler that is waiting for this
+        */
+       cmdrsp->vdiskmgmt.notifyresult_handle = cmdrsp->vdiskmgmt.result;
+       wake_up_all((wait_queue_head_t *)cmdrsp->vdiskmgmt.notify_handle);
+}
+
+/**
+ *     complete_taskmgmt_command - complete task management
+ *     @cmdrsp: Response from the IOVM
+ *
+ *     Service Partition returned the result of the task management
+ *     command. Wake up anyone waiting for it.
+ *     Returns void
+ */
+static inline void complete_taskmgmt_command(struct uiscmdrsp *cmdrsp)
+{
+       /* copy the result of the taskgmgt and
+        * wake up the error handler that is waiting for this
+        */
+       cmdrsp->vdiskmgmt.notifyresult_handle = cmdrsp->vdiskmgmt.result;
+       wake_up_all((wait_queue_head_t *)cmdrsp->scsitaskmgmt.notify_handle);
+}
+
+static struct work_struct dar_work_queue;
+static struct diskaddremove *dar_work_queue_head;
+static spinlock_t dar_work_queue_lock; /* Lock to protet dar_work_queue_head */
+static unsigned short dar_work_queue_sched;
+
+/**
+ *     queue_disk_add_remove - IOSP has sent us a add/remove request
+ *     @dar: disk add/remove request
+ *
+ *     Queue the work needed to add/remove a disk.
+ *     Returns void
+ */
+static inline void queue_disk_add_remove(struct diskaddremove *dar)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&dar_work_queue_lock, flags);
+       if (!dar_work_queue_head) {
+               dar_work_queue_head = dar;
+               dar->next = NULL;
+       } else {
+               dar->next = dar_work_queue_head;
+               dar_work_queue_head = dar;
+       }
+       if (!dar_work_queue_sched) {
+               schedule_work(&dar_work_queue);
+               dar_work_queue_sched = 1;
+       }
+       spin_unlock_irqrestore(&dar_work_queue_lock, flags);
+}
+
+/**
+ *     process_disk_notify - IOSP has sent a process disk notify event
+ *     @shost: Scsi hot
+ *     @cmdrsp: Response from the IOSP
+ *
+ *     Queue it to the work queue.
+ *     Return void.
+ */
+static void process_disk_notify(struct Scsi_Host *shost,
+                               struct uiscmdrsp *cmdrsp)
+{
+       struct diskaddremove *dar;
+
+       dar = kzalloc(sizeof(*dar), GFP_ATOMIC);
+       if (dar) {
+               dar->add = cmdrsp->disknotify.add;
+               dar->shost = shost;
+               dar->channel = cmdrsp->disknotify.channel;
+               dar->id = cmdrsp->disknotify.id;
+               dar->lun = cmdrsp->disknotify.lun;
+               queue_disk_add_remove(dar);
+       }
+}
+
+/**
+ *     drain_queue - pull responses out of iochannel
+ *     @cmdrsp: Response from the IOSP
+ *     @devdata: device that owns this iochannel
+ *
+ *     Pulls responses out of the iochannel and process the responses.
+ *     Restuns void
+ */
+static void
+drain_queue(struct uiscmdrsp *cmdrsp, struct visorhba_devdata *devdata)
+{
+       struct scsi_cmnd *scsicmd;
+       struct Scsi_Host *shost = devdata->scsihost;
+
+       while (1) {
+               if (!visorchannel_signalremove(devdata->dev->visorchannel,
+                                              IOCHAN_FROM_IOPART,
+                                              cmdrsp))
+                       break; /* queue empty */
+
+               if (cmdrsp->cmdtype == CMD_SCSI_TYPE) {
+                       /* scsicmd location is returned by the
+                        * deletion
+                        */
+                       scsicmd = del_scsipending_ent(devdata,
+                                                     cmdrsp->scsi.handle);
+                       if (!scsicmd)
+                               break;
+                       /* complete the orig cmd */
+                       complete_scsi_command(cmdrsp, scsicmd);
+               } else if (cmdrsp->cmdtype == CMD_SCSITASKMGMT_TYPE) {
+                       if (!del_scsipending_ent(devdata,
+                                                cmdrsp->scsitaskmgmt.handle))
+                               break;
+                       complete_taskmgmt_command(cmdrsp);
+               } else if (cmdrsp->cmdtype == CMD_NOTIFYGUEST_TYPE) {
+                       /* The vHba pointer has no meaning in a
+                        * guest partition. Let's be safe and set it
+                        * to NULL now. Do not use it here!
+                        */
+                       cmdrsp->disknotify.v_hba = NULL;
+                       process_disk_notify(shost, cmdrsp);
+               } else if (cmdrsp->cmdtype == CMD_VDISKMGMT_TYPE) {
+                       if (!del_scsipending_ent(devdata,
+                                                cmdrsp->vdiskmgmt.handle))
+                               break;
+                       complete_vdiskmgmt_command(cmdrsp);
+               }
+               /* cmdrsp is now available for resuse */
+       }
+}
+
+/**
+ *     process_incoming_rsps - Process responses from IOSP
+ *     @v: void pointer to visorhba_devdata
+ *
+ *     Main function for the thread that processes the responses
+ *     from the IO Service Partition. When the queue is empty, wait
+ *     to check to see if it is full again.
+ */
+static int process_incoming_rsps(void *v)
+{
+       struct visorhba_devdata *devdata = v;
+       struct uiscmdrsp *cmdrsp = NULL;
+       const int size = sizeof(*cmdrsp);
+
+       cmdrsp = kmalloc(size, GFP_ATOMIC);
+       if (!cmdrsp)
+               return -ENOMEM;
+
+       while (1) {
+               if (kthread_should_stop())
+                       break;
+               wait_event_interruptible_timeout(
+                       devdata->rsp_queue, (atomic_read(
+                                            &devdata->interrupt_rcvd) == 1),
+                               msecs_to_jiffies(devdata->thread_wait_ms));
+               /* drain queue */
+               drain_queue(cmdrsp, devdata);
+       }
+       kfree(cmdrsp);
+       return 0;
+}
+
+/**
+ *     visorhba_pause - function to handle visorbus pause messages
+ *     @dev: device that is pausing.
+ *     @complete_func: function to call when finished
+ *
+ *     Something has happened to the IO Service Partition that is
+ *     handling this device. Quiet this device and reset commands
+ *     so that the Service Partition can be corrected.
+ *     Returns SUCCESS
+ */
+static int visorhba_pause(struct visor_device *dev,
+                         visorbus_state_complete_func complete_func)
+{
+       struct visorhba_devdata *devdata = dev_get_drvdata(&dev->device);
+
+       visorhba_serverdown(devdata);
+       complete_func(dev, 0);
+       return 0;
+}
+
+/**
+ *     visorhba_resume - function called when the IO Service Partition is back
+ *     @dev: device that is pausing.
+ *     @complete_func: function to call when finished
+ *
+ *     Yay! The IO Service Partition is back, the channel has been wiped
+ *     so lets re-establish connection and start processing responses.
+ *     Returns 0 on success, error on failure.
+ */
+static int visorhba_resume(struct visor_device *dev,
+                          visorbus_state_complete_func complete_func)
+{
+       struct visorhba_devdata *devdata;
+
+       devdata = dev_get_drvdata(&dev->device);
+       if (!devdata)
+               return -EINVAL;
+
+       if (devdata->serverdown && !devdata->serverchangingstate)
+               devdata->serverchangingstate = 1;
+
+       visor_thread_start(&devdata->threadinfo, process_incoming_rsps,
+                          devdata, "vhba_incming");
+
+       devdata->serverdown = false;
+       devdata->serverchangingstate = false;
+
+       return 0;
+}
+
+/**
+ *     visorhba_probe - device has been discovered, do acquire
+ *     @dev: visor_device that was discovered
+ *
+ *     A new HBA was discovered, do the initial connections of it.
+ *     Return 0 on success, otherwise error.
+ */
+static int visorhba_probe(struct visor_device *dev)
+{
+       struct Scsi_Host *scsihost;
+       struct vhba_config_max max;
+       struct visorhba_devdata *devdata = NULL;
+       int i, err, channel_offset;
+       u64 features;
+
+       scsihost = scsi_host_alloc(&visorhba_driver_template,
+                                  sizeof(*devdata));
+       if (!scsihost)
+               return -ENODEV;
+
+       channel_offset = offsetof(struct spar_io_channel_protocol,
+                                 vhba.max);
+       err = visorbus_read_channel(dev, channel_offset, &max,
+                                   sizeof(struct vhba_config_max));
+       if (err < 0)
+               goto err_scsi_host_put;
+
+       scsihost->max_id = (unsigned)max.max_id;
+       scsihost->max_lun = (unsigned)max.max_lun;
+       scsihost->cmd_per_lun = (unsigned)max.cmd_per_lun;
+       scsihost->max_sectors =
+           (unsigned short)(max.max_io_size >> 9);
+       scsihost->sg_tablesize =
+           (unsigned short)(max.max_io_size / PAGE_SIZE);
+       if (scsihost->sg_tablesize > MAX_PHYS_INFO)
+               scsihost->sg_tablesize = MAX_PHYS_INFO;
+       err = scsi_add_host(scsihost, &dev->device);
+       if (err < 0)
+               goto err_scsi_host_put;
+
+       devdata = (struct visorhba_devdata *)scsihost->hostdata;
+       for (i = 0; i < VISORHBA_OPEN_MAX; i++) {
+               if (!visorhbas_open[i].devdata) {
+                       visorhbas_open[i].devdata = devdata;
+                       break;
+               }
+       }
+
+       devdata->dev = dev;
+       dev_set_drvdata(&dev->device, devdata);
+
+       init_waitqueue_head(&devdata->rsp_queue);
+       spin_lock_init(&devdata->privlock);
+       devdata->serverdown = false;
+       devdata->serverchangingstate = false;
+       devdata->scsihost = scsihost;
+
+       channel_offset = offsetof(struct spar_io_channel_protocol,
+                                 channel_header.features);
+       err = visorbus_read_channel(dev, channel_offset, &features, 8);
+       if (err)
+               goto err_scsi_remove_host;
+       features |= ULTRA_IO_CHANNEL_IS_POLLING;
+       err = visorbus_write_channel(dev, channel_offset, &features, 8);
+       if (err)
+               goto err_scsi_remove_host;
+
+       devdata->thread_wait_ms = 2;
+       visor_thread_start(&devdata->threadinfo, process_incoming_rsps,
+                          devdata, "vhba_incoming");
+
+       scsi_scan_host(scsihost);
+
+       return 0;
+
+err_scsi_remove_host:
+       scsi_remove_host(scsihost);
+
+err_scsi_host_put:
+       scsi_host_put(scsihost);
+       return err;
+}
+
+/**
+ *     visorhba_remove - remove a visorhba device
+ *     @dev: Device to remove
+ *
+ *     Removes the visorhba device.
+ *     Returns void.
+ */
+static void visorhba_remove(struct visor_device *dev)
+{
+       struct visorhba_devdata *devdata = dev_get_drvdata(&dev->device);
+       struct Scsi_Host *scsihost = NULL;
+
+       if (!devdata)
+               return;
+
+       scsihost = devdata->scsihost;
+       kthread_stop(devdata->threadinfo.task);
+       scsi_remove_host(scsihost);
+       scsi_host_put(scsihost);
+
+       dev_set_drvdata(&dev->device, NULL);
+}
+
+/**
+ *     visorhba_init           - driver init routine
+ *
+ *     Initialize the visorhba driver and register it with visorbus
+ *     to handle s-Par virtual host bus adapter.
+ */
+static int visorhba_init(void)
+{
+       struct dentry *ret;
+       int rc = -ENOMEM;
+
+       visorhba_debugfs_dir = debugfs_create_dir("visorhba", NULL);
+       if (!visorhba_debugfs_dir)
+               return -ENOMEM;
+
+       ret = debugfs_create_file("info", S_IRUSR, visorhba_debugfs_dir, NULL,
+                                 &debugfs_info_fops);
+
+       if (!ret) {
+               rc = -EIO;
+               goto cleanup_debugfs;
+       }
+
+       rc = visorbus_register_visor_driver(&visorhba_driver);
+       if (rc)
+               goto cleanup_debugfs;
+
+       return rc;
+
+cleanup_debugfs:
+       debugfs_remove_recursive(visorhba_debugfs_dir);
+
+       return rc;
+}
+
+/**
+ *     visorhba_cleanup        - driver exit routine
+ *
+ *     Unregister driver from the bus and free up memory.
+ */
+static void visorhba_exit(void)
+{
+       visorbus_unregister_visor_driver(&visorhba_driver);
+       debugfs_remove_recursive(visorhba_debugfs_dir);
+}
+
+module_init(visorhba_init);
+module_exit(visorhba_exit);
+
+MODULE_AUTHOR("Unisys");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("s-Par hba driver");
diff --git a/drivers/staging/unisys/visorinput/Kconfig b/drivers/staging/unisys/visorinput/Kconfig
new file mode 100644 (file)
index 0000000..d83deb4
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# Unisys visorinput configuration
+#
+
+config UNISYS_VISORINPUT
+       tristate "Unisys visorinput driver"
+       depends on UNISYSSPAR && UNISYS_VISORBUS && FB
+       ---help---
+       If you say Y here, you will enable the Unisys visorinput driver.
+
diff --git a/drivers/staging/unisys/visorinput/Makefile b/drivers/staging/unisys/visorinput/Makefile
new file mode 100644 (file)
index 0000000..beedca7
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# Makefile for Unisys visorinput
+#
+
+obj-$(CONFIG_UNISYS_VISORINPUT)        += visorinput.o
+
+ccflags-y += -Idrivers/staging/unisys/include
diff --git a/drivers/staging/unisys/visorinput/ultrainputreport.h b/drivers/staging/unisys/visorinput/ultrainputreport.h
new file mode 100644 (file)
index 0000000..3e6a52f
--- /dev/null
@@ -0,0 +1,74 @@
+/* Copyright (C) 2010 - 2015 UNISYS CORPORATION
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ */
+
+#ifndef __SPAR_ULTRAINPUTREPORT_H__
+#define __SPAR_ULTRAINPUTREPORT_H__
+
+#include <linux/types.h>
+
+#include "ultrainputreport.h"
+
+/* Identifies mouse and keyboard activity which is specified by the firmware to
+ *  the host using the cmsimpleinput protocol.  @ingroup coretypes
+ */
+enum ultra_inputaction {
+       inputaction_none = 0,
+       inputaction_xy_motion = 1,      /* only motion; arg1=x, arg2=y */
+       inputaction_mouse_button_down = 2, /* arg1: 1=left,2=center,3=right */
+       inputaction_mouse_button_up = 3, /* arg1: 1=left,2=center,3=right */
+       inputaction_mouse_button_click = 4, /* arg1: 1=left,2=center,3=right */
+       inputaction_mouse_button_dclick = 5, /* arg1: 1=left,2=center,
+                                               3=right */
+       inputaction_wheel_rotate_away = 6, /* arg1: wheel rotation away from
+                                             user */
+       inputaction_wheel_rotate_toward = 7, /* arg1: wheel rotation toward
+                                               user */
+       inputaction_set_max_xy = 8,     /* set screen maxXY; arg1=x, arg2=y */
+       inputaction_key_down = 64,      /* arg1: scancode, as follows:
+                                          If arg1 <= 0xff, it's a 1-byte
+                                          scancode and arg1 is that scancode.
+                                          If arg1 > 0xff, it's a 2-byte
+                                          scanecode, with the 1st byte in the
+                                          low 8 bits, and the 2nd byte in the
+                                          high 8 bits.  E.g., the right ALT key
+                                          would appear as x'38e0'. */
+       inputaction_key_up = 65,        /* arg1: scancode (in same format as
+                                          inputaction_keyDown) */
+       inputaction_set_locking_key_state = 66,
+                                       /* arg1: scancode (in same format
+                                                as inputaction_keyDown);
+                                                MUST refer to one of the
+                                                locking keys, like capslock,
+                                                numlock, or scrolllock
+                                          arg2: 1 iff locking key should be
+                                                in the LOCKED position
+                                                (e.g., light is ON) */
+       inputaction_key_down_up = 67,   /* arg1: scancode (in same format
+                                                as inputaction_keyDown) */
+       inputaction_last
+};
+
+struct ultra_inputactivity {
+       u16 action;
+       u16 arg1;
+       u16 arg2;
+       u16 arg3;
+} __packed;
+
+struct ultra_inputreport {
+       u64 seq_no;
+       struct ultra_inputactivity activity;
+} __packed;
+
+#endif
diff --git a/drivers/staging/unisys/visorinput/visorinput.c b/drivers/staging/unisys/visorinput/visorinput.c
new file mode 100644 (file)
index 0000000..5c16f66
--- /dev/null
@@ -0,0 +1,715 @@
+/* visorinput.c
+ *
+ * Copyright (C) 2011 - 2015 UNISYS CORPORATION
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
+ * NON INFRINGEMENT.  See the GNU General Public License for more
+ * details.
+ */
+
+/*
+ * This driver lives in a generic guest Linux partition, and registers to
+ * receive keyboard and mouse channels from the visorbus driver.  It reads
+ * inputs from such channels, and delivers it to the Linux OS in the
+ * standard way the Linux expects for input drivers.
+ */
+
+#include <linux/buffer_head.h>
+#include <linux/fb.h>
+#include <linux/fs.h>
+#include <linux/input.h>
+#include <linux/uaccess.h>
+#include <linux/kernel.h>
+#include <linux/uuid.h>
+
+#include "version.h"
+#include "visorbus.h"
+#include "channel.h"
+#include "ultrainputreport.h"
+
+/* Keyboard channel {c73416d0-b0b8-44af-b304-9d2ae99f1b3d} */
+#define SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID                            \
+       UUID_LE(0xc73416d0, 0xb0b8, 0x44af,                             \
+               0xb3, 0x4, 0x9d, 0x2a, 0xe9, 0x9f, 0x1b, 0x3d)
+#define SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID_STR "c73416d0-b0b8-44af-b304-9d2ae99f1b3d"
+
+/* Mouse channel {addf07d4-94a9-46e2-81c3-61abcdbdbd87} */
+#define SPAR_MOUSE_CHANNEL_PROTOCOL_UUID  \
+       UUID_LE(0xaddf07d4, 0x94a9, 0x46e2, \
+               0x81, 0xc3, 0x61, 0xab, 0xcd, 0xbd, 0xbd, 0x87)
+#define SPAR_MOUSE_CHANNEL_PROTOCOL_UUID_STR \
+       "addf07d4-94a9-46e2-81c3-61abcdbdbd87"
+
+#define PIXELS_ACROSS_DEFAULT  800
+#define PIXELS_DOWN_DEFAULT    600
+#define KEYCODE_TABLE_BYTES    256
+
+enum visorinput_device_type {
+       visorinput_keyboard,
+       visorinput_mouse,
+};
+
+/*
+ * This is the private data that we store for each device.
+ * A pointer to this struct is maintained via
+ * dev_get_drvdata() / dev_set_drvdata() for each struct device.
+ */
+struct visorinput_devdata {
+       struct visor_device *dev;
+       struct rw_semaphore lock_visor_dev; /* lock for dev */
+       struct input_dev *visorinput_dev;
+       bool paused;
+       unsigned int keycode_table_bytes; /* size of following array */
+       /* for keyboard devices: visorkbd_keycode[] + visorkbd_ext_keycode[] */
+       unsigned char keycode_table[0];
+};
+
+static const uuid_le spar_keyboard_channel_protocol_uuid =
+       SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID;
+static const uuid_le spar_mouse_channel_protocol_uuid =
+       SPAR_MOUSE_CHANNEL_PROTOCOL_UUID;
+
+/*
+ * Borrowed from drivers/input/keyboard/atakbd.c
+ * This maps 1-byte scancodes to keycodes.
+ */
+static const unsigned char visorkbd_keycode[KEYCODE_TABLE_BYTES] = {
+       /* American layout */
+       [0] = KEY_GRAVE,
+       [1] = KEY_ESC,
+       [2] = KEY_1,
+       [3] = KEY_2,
+       [4] = KEY_3,
+       [5] = KEY_4,
+       [6] = KEY_5,
+       [7] = KEY_6,
+       [8] = KEY_7,
+       [9] = KEY_8,
+       [10] = KEY_9,
+       [11] = KEY_0,
+       [12] = KEY_MINUS,
+       [13] = KEY_EQUAL,
+       [14] = KEY_BACKSPACE,
+       [15] = KEY_TAB,
+       [16] = KEY_Q,
+       [17] = KEY_W,
+       [18] = KEY_E,
+       [19] = KEY_R,
+       [20] = KEY_T,
+       [21] = KEY_Y,
+       [22] = KEY_U,
+       [23] = KEY_I,
+       [24] = KEY_O,
+       [25] = KEY_P,
+       [26] = KEY_LEFTBRACE,
+       [27] = KEY_RIGHTBRACE,
+       [28] = KEY_ENTER,
+       [29] = KEY_LEFTCTRL,
+       [30] = KEY_A,
+       [31] = KEY_S,
+       [32] = KEY_D,
+       [33] = KEY_F,
+       [34] = KEY_G,
+       [35] = KEY_H,
+       [36] = KEY_J,
+       [37] = KEY_K,
+       [38] = KEY_L,
+       [39] = KEY_SEMICOLON,
+       [40] = KEY_APOSTROPHE,
+       [41] = KEY_GRAVE,       /* FIXME, '#' */
+       [42] = KEY_LEFTSHIFT,
+       [43] = KEY_BACKSLASH,   /* FIXME, '~' */
+       [44] = KEY_Z,
+       [45] = KEY_X,
+       [46] = KEY_C,
+       [47] = KEY_V,
+       [48] = KEY_B,
+       [49] = KEY_N,
+       [50] = KEY_M,
+       [51] = KEY_COMMA,
+       [52] = KEY_DOT,
+       [53] = KEY_SLASH,
+       [54] = KEY_RIGHTSHIFT,
+       [55] = KEY_KPASTERISK,
+       [56] = KEY_LEFTALT,
+       [57] = KEY_SPACE,
+       [58] = KEY_CAPSLOCK,
+       [59] = KEY_F1,
+       [60] = KEY_F2,
+       [61] = KEY_F3,
+       [62] = KEY_F4,
+       [63] = KEY_F5,
+       [64] = KEY_F6,
+       [65] = KEY_F7,
+       [66] = KEY_F8,
+       [67] = KEY_F9,
+       [68] = KEY_F10,
+       [69] = KEY_NUMLOCK,
+       [70] = KEY_SCROLLLOCK,
+       [71] = KEY_KP7,
+       [72] = KEY_KP8,
+       [73] = KEY_KP9,
+       [74] = KEY_KPMINUS,
+       [75] = KEY_KP4,
+       [76] = KEY_KP5,
+       [77] = KEY_KP6,
+       [78] = KEY_KPPLUS,
+       [79] = KEY_KP1,
+       [80] = KEY_KP2,
+       [81] = KEY_KP3,
+       [82] = KEY_KP0,
+       [83] = KEY_KPDOT,
+       [86] = KEY_102ND, /* enables UK backslash+pipe key,
+                          * and FR lessthan+greaterthan key
+                          */
+       [87] = KEY_F11,
+       [88] = KEY_F12,
+       [90] = KEY_KPLEFTPAREN,
+       [91] = KEY_KPRIGHTPAREN,
+       [92] = KEY_KPASTERISK,  /* FIXME */
+       [93] = KEY_KPASTERISK,
+       [94] = KEY_KPPLUS,
+       [95] = KEY_HELP,
+       [96] = KEY_KPENTER,
+       [97] = KEY_RIGHTCTRL,
+       [98] = KEY_KPSLASH,
+       [99] = KEY_KPLEFTPAREN,
+       [100] = KEY_KPRIGHTPAREN,
+       [101] = KEY_KPSLASH,
+       [102] = KEY_HOME,
+       [103] = KEY_UP,
+       [104] = KEY_PAGEUP,
+       [105] = KEY_LEFT,
+       [106] = KEY_RIGHT,
+       [107] = KEY_END,
+       [108] = KEY_DOWN,
+       [109] = KEY_PAGEDOWN,
+       [110] = KEY_INSERT,
+       [111] = KEY_DELETE,
+       [112] = KEY_MACRO,
+       [113] = KEY_MUTE
+};
+
+/*
+ * This maps the <xx> in extended scancodes of the form "0xE0 <xx>" into
+ * keycodes.
+ */
+static const unsigned char visorkbd_ext_keycode[KEYCODE_TABLE_BYTES] = {
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x00 */
+       0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x10 */
+       0, 0, 0, 0, KEY_KPENTER, KEY_RIGHTCTRL, 0, 0,               /* 0x18 */
+       0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x20 */
+       KEY_RIGHTALT, 0, 0, 0, 0, 0, 0, 0,                          /* 0x28 */
+       0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x30 */
+       KEY_RIGHTALT /* AltGr */, 0, 0, 0, 0, 0, 0, 0,              /* 0x38 */
+       0, 0, 0, 0, 0, 0, 0, KEY_HOME,                              /* 0x40 */
+       KEY_UP, KEY_PAGEUP, 0, KEY_LEFT, 0, KEY_RIGHT, 0, KEY_END,  /* 0x48 */
+       KEY_DOWN, KEY_PAGEDOWN, KEY_INSERT, KEY_DELETE, 0, 0, 0, 0, /* 0x50 */
+       0, 0, 0, 0, 0, 0, 0, 0,                                     /* 0x58 */
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x60 */
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             /* 0x70 */
+};
+
+static int visorinput_open(struct input_dev *visorinput_dev)
+{
+       struct visorinput_devdata *devdata = input_get_drvdata(visorinput_dev);
+
+       if (!devdata) {
+               pr_err("%s input_get_drvdata(%p) returned NULL\n",
+                      __func__, visorinput_dev);
+               return -EINVAL;
+       }
+       dev_dbg(&visorinput_dev->dev, "%s opened\n", __func__);
+       visorbus_enable_channel_interrupts(devdata->dev);
+       return 0;
+}
+
+static void visorinput_close(struct input_dev *visorinput_dev)
+{
+       struct visorinput_devdata *devdata = input_get_drvdata(visorinput_dev);
+
+       if (!devdata) {
+               pr_err("%s input_get_drvdata(%p) returned NULL\n",
+                      __func__, visorinput_dev);
+               return;
+       }
+       dev_dbg(&visorinput_dev->dev, "%s closed\n", __func__);
+       visorbus_disable_channel_interrupts(devdata->dev);
+}
+
+/*
+ * register_client_keyboard() initializes and returns a Linux input node that
+ * we can use to deliver keyboard inputs to Linux.  We of course do this when
+ * we see keyboard inputs coming in on a keyboard channel.
+ */
+static struct input_dev *
+register_client_keyboard(void *devdata,  /* opaque on purpose */
+                        unsigned char *keycode_table)
+
+{
+       int i, error;
+       struct input_dev *visorinput_dev;
+
+       visorinput_dev = input_allocate_device();
+       if (!visorinput_dev)
+               return NULL;
+
+       visorinput_dev->name = "visor Keyboard";
+       visorinput_dev->phys = "visorkbd:input0";
+       visorinput_dev->id.bustype = BUS_VIRTUAL;
+       visorinput_dev->id.vendor = 0x0001;
+       visorinput_dev->id.product = 0x0001;
+       visorinput_dev->id.version = 0x0100;
+
+       visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) |
+                                  BIT_MASK(EV_REP) |
+                                  BIT_MASK(EV_LED);
+       visorinput_dev->ledbit[0] = BIT_MASK(LED_CAPSL) |
+                                   BIT_MASK(LED_SCROLLL) |
+                                   BIT_MASK(LED_NUML);
+       visorinput_dev->keycode = keycode_table;
+       visorinput_dev->keycodesize = 1; /* sizeof(unsigned char) */
+       visorinput_dev->keycodemax = KEYCODE_TABLE_BYTES;
+
+       for (i = 1; i < visorinput_dev->keycodemax; i++)
+               set_bit(keycode_table[i], visorinput_dev->keybit);
+       for (i = 1; i < visorinput_dev->keycodemax; i++)
+               set_bit(keycode_table[i + KEYCODE_TABLE_BYTES],
+                       visorinput_dev->keybit);
+
+       visorinput_dev->open = visorinput_open;
+       visorinput_dev->close = visorinput_close;
+       input_set_drvdata(visorinput_dev, devdata); /* pre input_register! */
+
+       error = input_register_device(visorinput_dev);
+       if (error) {
+               input_free_device(visorinput_dev);
+               return NULL;
+       }
+       return visorinput_dev;
+}
+
+static struct input_dev *
+register_client_mouse(void *devdata /* opaque on purpose */)
+{
+       int error;
+       struct input_dev *visorinput_dev = NULL;
+       int xres, yres;
+       struct fb_info *fb0;
+
+       visorinput_dev = input_allocate_device();
+       if (!visorinput_dev)
+               return NULL;
+
+       visorinput_dev->name = "visor Mouse";
+       visorinput_dev->phys = "visormou:input0";
+       visorinput_dev->id.bustype = BUS_VIRTUAL;
+       visorinput_dev->id.vendor = 0x0001;
+       visorinput_dev->id.product = 0x0002;
+       visorinput_dev->id.version = 0x0100;
+
+       visorinput_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+       set_bit(BTN_LEFT, visorinput_dev->keybit);
+       set_bit(BTN_RIGHT, visorinput_dev->keybit);
+       set_bit(BTN_MIDDLE, visorinput_dev->keybit);
+
+       if (registered_fb[0]) {
+               fb0 = registered_fb[0];
+               xres = fb0->var.xres_virtual;
+               yres = fb0->var.yres_virtual;
+       } else {
+               xres = PIXELS_ACROSS_DEFAULT;
+               yres = PIXELS_DOWN_DEFAULT;
+       }
+       input_set_abs_params(visorinput_dev, ABS_X, 0, xres, 0, 0);
+       input_set_abs_params(visorinput_dev, ABS_Y, 0, yres, 0, 0);
+
+       visorinput_dev->open = visorinput_open;
+       visorinput_dev->close = visorinput_close;
+       input_set_drvdata(visorinput_dev, devdata); /* pre input_register! */
+
+       error = input_register_device(visorinput_dev);
+       if (error) {
+               input_free_device(visorinput_dev);
+               return NULL;
+       }
+
+       input_set_capability(visorinput_dev, EV_REL, REL_WHEEL);
+
+       return visorinput_dev;
+}
+
+static struct visorinput_devdata *
+devdata_create(struct visor_device *dev, enum visorinput_device_type devtype)
+{
+       struct visorinput_devdata *devdata = NULL;
+       unsigned int extra_bytes = 0;
+
+       if (devtype == visorinput_keyboard)
+               /* allocate room for devdata->keycode_table, filled in below */
+               extra_bytes = KEYCODE_TABLE_BYTES * 2;
+       devdata = kzalloc(sizeof(*devdata) + extra_bytes, GFP_KERNEL);
+       if (!devdata)
+               return NULL;
+       devdata->dev = dev;
+
+       /*
+        * This is an input device in a client guest partition,
+        * so we need to create whatever input nodes are necessary to
+        * deliver our inputs to the guest OS.
+        */
+       switch (devtype) {
+       case visorinput_keyboard:
+               devdata->keycode_table_bytes = extra_bytes;
+               memcpy(devdata->keycode_table, visorkbd_keycode,
+                      KEYCODE_TABLE_BYTES);
+               memcpy(devdata->keycode_table + KEYCODE_TABLE_BYTES,
+                      visorkbd_ext_keycode, KEYCODE_TABLE_BYTES);
+               devdata->visorinput_dev = register_client_keyboard
+                       (devdata, devdata->keycode_table);
+               if (!devdata->visorinput_dev)
+                       goto cleanups_register;
+               break;
+       case visorinput_mouse:
+               devdata->visorinput_dev = register_client_mouse(devdata);
+               if (!devdata->visorinput_dev)
+                       goto cleanups_register;
+               break;
+       }
+
+       init_rwsem(&devdata->lock_visor_dev);
+
+       return devdata;
+
+cleanups_register:
+       kfree(devdata);
+       return NULL;
+}
+
+static int
+visorinput_probe(struct visor_device *dev)
+{
+       struct visorinput_devdata *devdata = NULL;
+       uuid_le guid;
+       enum visorinput_device_type devtype;
+
+       guid = visorchannel_get_uuid(dev->visorchannel);
+       if (uuid_le_cmp(guid, spar_mouse_channel_protocol_uuid) == 0)
+               devtype = visorinput_mouse;
+       else if (uuid_le_cmp(guid, spar_keyboard_channel_protocol_uuid) == 0)
+               devtype = visorinput_keyboard;
+       else
+               return -ENODEV;
+       devdata = devdata_create(dev, devtype);
+       if (!devdata)
+               return -ENOMEM;
+       dev_set_drvdata(&dev->device, devdata);
+       return 0;
+}
+
+static void
+unregister_client_input(struct input_dev *visorinput_dev)
+{
+       if (visorinput_dev)
+               input_unregister_device(visorinput_dev);
+}
+
+static void
+visorinput_remove(struct visor_device *dev)
+{
+       struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
+
+       if (!devdata)
+               return;
+
+       visorbus_disable_channel_interrupts(dev);
+
+       /*
+        * due to above, at this time no thread of execution will be
+        * in visorinput_channel_interrupt()
+        */
+
+       down_write(&devdata->lock_visor_dev);
+       dev_set_drvdata(&dev->device, NULL);
+       unregister_client_input(devdata->visorinput_dev);
+       up_write(&devdata->lock_visor_dev);
+       kfree(devdata);
+}
+
+/*
+ * Make it so the current locking state of the locking key indicated by
+ * <keycode> is as indicated by <desired_state> (1=locked, 0=unlocked).
+ */
+static void
+handle_locking_key(struct input_dev *visorinput_dev,
+                  int keycode, int desired_state)
+{
+       int led;
+
+       switch (keycode) {
+       case KEY_CAPSLOCK:
+               led = LED_CAPSL;
+               break;
+       case KEY_SCROLLLOCK:
+               led = LED_SCROLLL;
+               break;
+       case KEY_NUMLOCK:
+               led = LED_NUML;
+               break;
+       default:
+               led = -1;
+               break;
+       }
+       if (led >= 0) {
+               int old_state = (test_bit(led, visorinput_dev->led) != 0);
+
+               if (old_state != desired_state) {
+                       input_report_key(visorinput_dev, keycode, 1);
+                       input_sync(visorinput_dev);
+                       input_report_key(visorinput_dev, keycode, 0);
+                       input_sync(visorinput_dev);
+                       __change_bit(led, visorinput_dev->led);
+               }
+       }
+}
+
+/*
+ * <scancode> is either a 1-byte scancode, or an extended 16-bit scancode
+ * with 0xE0 in the low byte and the extended scancode value in the next
+ * higher byte.
+ */
+static int
+scancode_to_keycode(int scancode)
+{
+       int keycode;
+
+       if (scancode > 0xff)
+               keycode = visorkbd_ext_keycode[(scancode >> 8) & 0xff];
+       else
+               keycode = visorkbd_keycode[scancode];
+       return keycode;
+}
+
+static int
+calc_button(int x)
+{
+       switch (x) {
+       case 1:
+               return BTN_LEFT;
+       case 2:
+               return BTN_MIDDLE;
+       case 3:
+               return BTN_RIGHT;
+       default:
+               return -1;
+       }
+}
+
+/*
+ * This is used only when this driver is active as an input driver in the
+ * client guest partition.  It is called periodically so we can obtain inputs
+ * from the channel, and deliver them to the guest OS.
+ */
+static void
+visorinput_channel_interrupt(struct visor_device *dev)
+{
+       struct ultra_inputreport r;
+       int scancode, keycode;
+       struct input_dev *visorinput_dev;
+       int xmotion, ymotion, zmotion, button;
+       int i;
+
+       struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
+
+       if (!devdata)
+               return;
+
+       down_write(&devdata->lock_visor_dev);
+       if (devdata->paused) /* don't touch device/channel when paused */
+               goto out_locked;
+
+       visorinput_dev = devdata->visorinput_dev;
+       if (!visorinput_dev)
+               goto out_locked;
+
+       while (visorchannel_signalremove(dev->visorchannel, 0, &r)) {
+               scancode = r.activity.arg1;
+               keycode = scancode_to_keycode(scancode);
+               switch (r.activity.action) {
+               case inputaction_key_down:
+                       input_report_key(visorinput_dev, keycode, 1);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_key_up:
+                       input_report_key(visorinput_dev, keycode, 0);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_key_down_up:
+                       input_report_key(visorinput_dev, keycode, 1);
+                       input_sync(visorinput_dev);
+                       input_report_key(visorinput_dev, keycode, 0);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_set_locking_key_state:
+                       handle_locking_key(visorinput_dev, keycode,
+                                          r.activity.arg2);
+                       break;
+               case inputaction_xy_motion:
+                       xmotion = r.activity.arg1;
+                       ymotion = r.activity.arg2;
+                       input_report_abs(visorinput_dev, ABS_X, xmotion);
+                       input_report_abs(visorinput_dev, ABS_Y, ymotion);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_mouse_button_down:
+                       button = calc_button(r.activity.arg1);
+                       if (button < 0)
+                               break;
+                       input_report_key(visorinput_dev, button, 1);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_mouse_button_up:
+                       button = calc_button(r.activity.arg1);
+                       if (button < 0)
+                               break;
+                       input_report_key(visorinput_dev, button, 0);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_mouse_button_click:
+                       button = calc_button(r.activity.arg1);
+                       if (button < 0)
+                               break;
+                       input_report_key(visorinput_dev, button, 1);
+
+                       input_sync(visorinput_dev);
+                       input_report_key(visorinput_dev, button, 0);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_mouse_button_dclick:
+                       button = calc_button(r.activity.arg1);
+                       if (button < 0)
+                               break;
+                       for (i = 0; i < 2; i++) {
+                               input_report_key(visorinput_dev, button, 1);
+                               input_sync(visorinput_dev);
+                               input_report_key(visorinput_dev, button, 0);
+                               input_sync(visorinput_dev);
+                       }
+                       break;
+               case inputaction_wheel_rotate_away:
+                       zmotion = r.activity.arg1;
+                       input_report_rel(visorinput_dev, REL_WHEEL, 1);
+                       input_sync(visorinput_dev);
+                       break;
+               case inputaction_wheel_rotate_toward:
+                       zmotion = r.activity.arg1;
+                       input_report_rel(visorinput_dev, REL_WHEEL, -1);
+                       input_sync(visorinput_dev);
+                       break;
+               }
+       }
+out_locked:
+       up_write(&devdata->lock_visor_dev);
+}
+
+static int
+visorinput_pause(struct visor_device *dev,
+                visorbus_state_complete_func complete_func)
+{
+       int rc;
+       struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
+
+       if (!devdata) {
+               rc = -ENODEV;
+               goto out;
+       }
+
+       down_write(&devdata->lock_visor_dev);
+       if (devdata->paused) {
+               rc = -EBUSY;
+               goto out_locked;
+       }
+       devdata->paused = true;
+       complete_func(dev, 0);
+       rc = 0;
+out_locked:
+       up_write(&devdata->lock_visor_dev);
+out:
+       return rc;
+}
+
+static int
+visorinput_resume(struct visor_device *dev,
+                 visorbus_state_complete_func complete_func)
+{
+       int rc;
+       struct visorinput_devdata *devdata = dev_get_drvdata(&dev->device);
+
+       if (!devdata) {
+               rc = -ENODEV;
+               goto out;
+       }
+       down_write(&devdata->lock_visor_dev);
+       if (!devdata->paused) {
+               rc = -EBUSY;
+               goto out_locked;
+       }
+       devdata->paused = false;
+       complete_func(dev, 0);
+       rc = 0;
+out_locked:
+       up_write(&devdata->lock_visor_dev);
+out:
+       return rc;
+}
+
+/* GUIDS for all channel types supported by this driver. */
+static struct visor_channeltype_descriptor visorinput_channel_types[] = {
+       { SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID, "keyboard"},
+       { SPAR_MOUSE_CHANNEL_PROTOCOL_UUID, "mouse"},
+       { NULL_UUID_LE, NULL }
+};
+
+static struct visor_driver visorinput_driver = {
+       .name = "visorinput",
+       .vertag = NULL,
+       .owner = THIS_MODULE,
+       .channel_types = visorinput_channel_types,
+       .probe = visorinput_probe,
+       .remove = visorinput_remove,
+       .channel_interrupt = visorinput_channel_interrupt,
+       .pause = visorinput_pause,
+       .resume = visorinput_resume,
+};
+
+static int
+visorinput_init(void)
+{
+       return visorbus_register_visor_driver(&visorinput_driver);
+}
+
+static void
+visorinput_cleanup(void)
+{
+       visorbus_unregister_visor_driver(&visorinput_driver);
+}
+
+module_init(visorinput_init);
+module_exit(visorinput_cleanup);
+
+MODULE_DEVICE_TABLE(visorbus, visorinput_channel_types);
+
+MODULE_AUTHOR("Unisys");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("s-Par human input driver for guest Linux");
+MODULE_VERSION(VERSION);
+
+MODULE_ALIAS("visorbus:" SPAR_MOUSE_CHANNEL_PROTOCOL_UUID_STR);
+MODULE_ALIAS("visorbus:" SPAR_KEYBOARD_CHANNEL_PROTOCOL_UUID_STR);
index 9d3c1e28206240705b74d3913f653be01c4ef6f1..296b11cea247fdad0070fbeafae3cbff95b402f2 100644 (file)
@@ -37,9 +37,6 @@
  */
 #define MAX_BUF 163840
 
-static spinlock_t dev_num_pool_lock;
-static void *dev_num_pool;     /**< pool to grab device numbers from */
-
 static int visornic_probe(struct visor_device *dev);
 static void visornic_remove(struct visor_device *dev);
 static int visornic_pause(struct visor_device *dev,
@@ -113,20 +110,17 @@ struct chanstat {
 };
 
 struct visornic_devdata {
-       int devnum;
        unsigned short enabled;         /* 0 disabled 1 enabled to receive */
        unsigned short enab_dis_acked;  /* NET_RCV_ENABLE/DISABLE acked by
                                         * IOPART
                                         */
        struct visor_device *dev;
-       char name[99];
-       struct list_head list_all;   /* < link within list_all_devices list */
        struct net_device *netdev;
        struct net_device_stats net_stats;
        atomic_t interrupt_rcvd;
        wait_queue_head_t rsp_queue;
        struct sk_buff **rcvbuf;
-       u64 uniquenum; /* TODO figure out why not used */
+       u64 incarnation_id;             /* lets IOPART know about re-birth */
        unsigned short old_flags;       /* flags as they were prior to
                                         * set_multicast_list
                                         */
@@ -201,12 +195,6 @@ struct visornic_devdata {
        struct uiscmdrsp cmdrsp[SIZEOF_CMDRSP];
 };
 
-
-/* List of all visornic_devdata structs,
- * linked via the list_all member
- */
-static LIST_HEAD(list_all_devices);
-static DEFINE_SPINLOCK(lock_all_devices);
 static int visornic_poll(struct napi_struct *napi, int budget);
 static void poll_for_irq(unsigned long v);
 
@@ -443,7 +431,7 @@ post_skb(struct uiscmdrsp *cmdrsp,
        cmdrsp->net.rcvpost.frag.pi_off =
                (unsigned long)skb->data & PI_PAGE_MASK;
        cmdrsp->net.rcvpost.frag.pi_len = skb->len;
-       cmdrsp->net.rcvpost.unique_num = devdata->uniquenum;
+       cmdrsp->net.rcvpost.unique_num = devdata->incarnation_id;
 
        if ((cmdrsp->net.rcvpost.frag.pi_off + skb->len) <= PI_PAGE_SIZE) {
                cmdrsp->net.type = NET_RCV_POST;
@@ -1373,25 +1361,11 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
 static struct visornic_devdata *
 devdata_initialize(struct visornic_devdata *devdata, struct visor_device *dev)
 {
-       int devnum = -1;
-
        if (!devdata)
                return NULL;
        memset(devdata, '\0', sizeof(struct visornic_devdata));
-       spin_lock(&dev_num_pool_lock);
-       devnum = find_first_zero_bit(dev_num_pool, MAXDEVICES);
-       set_bit(devnum, dev_num_pool);
-       spin_unlock(&dev_num_pool_lock);
-       if (devnum == MAXDEVICES)
-               devnum = -1;
-       if (devnum < 0)
-               return NULL;
-       devdata->devnum = devnum;
        devdata->dev = dev;
-       strncpy(devdata->name, dev_name(&dev->device), sizeof(devdata->name));
-       spin_lock(&lock_all_devices);
-       list_add_tail(&devdata->list_all, &list_all_devices);
-       spin_unlock(&lock_all_devices);
+       devdata->incarnation_id = get_jiffies_64();
        return devdata;
 }
 
@@ -1404,12 +1378,6 @@ devdata_initialize(struct visornic_devdata *devdata, struct visor_device *dev)
  */
 static void devdata_release(struct visornic_devdata *devdata)
 {
-       spin_lock(&dev_num_pool_lock);
-       clear_bit(devdata->devnum, dev_num_pool);
-       spin_unlock(&dev_num_pool_lock);
-       spin_lock(&lock_all_devices);
-       list_del(&devdata->list_all);
-       spin_unlock(&lock_all_devices);
        kfree(devdata->rcvbuf);
        kfree(devdata->cmdrsp_rcv);
        kfree(devdata->xmit_cmdrsp);
@@ -1621,7 +1589,21 @@ send_rcv_posts_if_needed(struct visornic_devdata *devdata)
 }
 
 /**
- *     draing_queue    - drains the response queue
+ *     drain_resp_queue  - drains and ignores all messages from the resp queue
+ *     @cmdrsp: io channel command response message
+ *     @devdata: visornic device to drain
+ */
+static void
+drain_resp_queue(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata)
+{
+       while (visorchannel_signalremove(devdata->dev->visorchannel,
+                                        IOCHAN_FROM_IOPART,
+                                        cmdrsp))
+               ;
+}
+
+/**
+ *     service_resp_queue      - drains the response queue
  *     @cmdrsp: io channel command response message
  *     @devdata: visornic device to drain
  *
@@ -1810,6 +1792,8 @@ static int visornic_probe(struct visor_device *dev)
                err = -ENOMEM;
                goto cleanup_netdev;
        }
+       /* don't trust messages laying around in the channel */
+       drain_resp_queue(devdata->cmdrsp, devdata);
 
        devdata->netdev = netdev;
        dev_set_drvdata(&dev->device, devdata);
@@ -1830,8 +1814,8 @@ static int visornic_probe(struct visor_device *dev)
                goto cleanup_netdev;
        }
 
-       devdata->rcvbuf = kzalloc(sizeof(struct sk_buff *) *
-                                 devdata->num_rcv_bufs, GFP_KERNEL);
+       devdata->rcvbuf = kcalloc(devdata->num_rcv_bufs,
+                                 sizeof(struct sk_buff *), GFP_KERNEL);
        if (!devdata->rcvbuf) {
                err = -ENOMEM;
                goto cleanup_rcvbuf;
@@ -1901,6 +1885,7 @@ static int visornic_probe(struct visor_device *dev)
        }
 
        features |= ULTRA_IO_CHANNEL_IS_POLLING;
+       features |= ULTRA_IO_DRIVER_SUPPORTS_ENHANCED_RCVBUF_CHECKING;
        err = visorbus_write_channel(dev, channel_offset, &features, 8);
        if (err) {
                dev_err(&dev->device,
@@ -1964,7 +1949,6 @@ static void host_side_disappeared(struct visornic_devdata *devdata)
        unsigned long flags;
 
        spin_lock_irqsave(&devdata->priv_lock, flags);
-       sprintf(devdata->name, "<dev#%d-history>", devdata->devnum);
        devdata->dev = NULL;   /* indicate device destroyed */
        spin_unlock_irqrestore(&devdata->priv_lock, flags);
 }
@@ -2126,11 +2110,6 @@ static int visornic_init(void)
        if (!visornic_timeout_reset_workqueue)
                goto cleanup_workqueue;
 
-       spin_lock_init(&dev_num_pool_lock);
-       dev_num_pool = kzalloc(BITS_TO_LONGS(MAXDEVICES), GFP_KERNEL);
-       if (!dev_num_pool)
-               goto cleanup_workqueue;
-
        err = visorbus_register_visor_driver(&visornic_driver);
        if (!err)
                return 0;
@@ -2160,9 +2139,6 @@ static void visornic_cleanup(void)
                destroy_workqueue(visornic_timeout_reset_workqueue);
        }
        debugfs_remove_recursive(visornic_debugfs_dir);
-
-       kfree(dev_num_pool);
-       dev_num_pool = NULL;
 }
 
 module_init(visornic_init);
index 9e61f2df3a00a283d8de53371ef91c3b23e3b4d1..1e6c0c4a0307079e480395344d569db27810de5a 100644 (file)
@@ -2089,9 +2089,19 @@ bool BBbVT3253Init(struct vnt_private *priv)
                                byVT3253B0_UW2451[ii][0],
                                byVT3253B0_UW2451[ii][1]);
 
-               /* Init ANT B select,TX Config CR09 = 0x61->0x45, 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted) */
+               /* Init ANT B select,
+                * TX Config CR09 = 0x61->0x45,
+                * 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted)
+                */
+
                /*bResult &= BBbWriteEmbedded(dwIoBase,0x09,0x41);*/
-               /* Init ANT B select,RX Config CR10 = 0x28->0x2A, 0x2A->0x28(VC1/VC2 define, make the ANT_A, ANT_B inverted) */
+
+               /* Init ANT B select,
+                * RX Config CR10 = 0x28->0x2A,
+                * 0x2A->0x28(VC1/VC2 define,
+                * make the ANT_A, ANT_B inverted)
+                */
+
                /*bResult &= BBbWriteEmbedded(dwIoBase,0x0a,0x28);*/
                /* Select VC1/VC2, CR215 = 0x02->0x06 */
                bResult &= BBbWriteEmbedded(priv, 0xd7, 0x06);
index c7b75dfc2d5f27cc9c2c882ac1becdf9b6b0c487..b6730a8068fd4e3a602f59b98394382c018ea9a5 100644 (file)
@@ -197,13 +197,13 @@ s_vCalculateOFDMRParameter(
  *
  * Parameters:
  *  In:
- *      pDevice             - The adapter to be set
+ *      priv             - The adapter to be set
  *  Out:
  *      none
  *
  * Return Value: None.
  */
-bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
+bool CARDbSetPhyParameter(struct vnt_private *priv, u8 bb_type)
 {
        unsigned char byCWMaxMin = 0;
        unsigned char bySlot = 0;
@@ -214,79 +214,79 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
 
        /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
        if (bb_type == BB_TYPE_11A) {
-               if (pDevice->byRFType == RF_AIROHA7230) {
+               if (priv->byRFType == RF_AIROHA7230) {
                        /* AL7230 use single PAPE and connect to PAPE_2.4G */
-                       MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
-                       pDevice->abyBBVGA[0] = 0x20;
-                       pDevice->abyBBVGA[2] = 0x10;
-                       pDevice->abyBBVGA[3] = 0x10;
-                       BBbReadEmbedded(pDevice, 0xE7, &byData);
+                       MACvSetBBType(priv->PortOffset, BB_TYPE_11G);
+                       priv->abyBBVGA[0] = 0x20;
+                       priv->abyBBVGA[2] = 0x10;
+                       priv->abyBBVGA[3] = 0x10;
+                       BBbReadEmbedded(priv, 0xE7, &byData);
                        if (byData == 0x1C)
-                               BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
+                               BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
 
-               } else if (pDevice->byRFType == RF_UW2452) {
-                       MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
-                       pDevice->abyBBVGA[0] = 0x18;
-                       BBbReadEmbedded(pDevice, 0xE7, &byData);
+               } else if (priv->byRFType == RF_UW2452) {
+                       MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
+                       priv->abyBBVGA[0] = 0x18;
+                       BBbReadEmbedded(priv, 0xE7, &byData);
                        if (byData == 0x14) {
-                               BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
-                               BBbWriteEmbedded(pDevice, 0xE1, 0x57);
+                               BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
+                               BBbWriteEmbedded(priv, 0xE1, 0x57);
                        }
                } else {
-                       MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
+                       MACvSetBBType(priv->PortOffset, BB_TYPE_11A);
                }
-               BBbWriteEmbedded(pDevice, 0x88, 0x03);
+               BBbWriteEmbedded(priv, 0x88, 0x03);
                bySlot = C_SLOT_SHORT;
                bySIFS = C_SIFS_A;
-               byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
+               byDIFS = C_SIFS_A + 2 * C_SLOT_SHORT;
                byCWMaxMin = 0xA4;
        } else if (bb_type == BB_TYPE_11B) {
-               MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
-               if (pDevice->byRFType == RF_AIROHA7230) {
-                       pDevice->abyBBVGA[0] = 0x1C;
-                       pDevice->abyBBVGA[2] = 0x00;
-                       pDevice->abyBBVGA[3] = 0x00;
-                       BBbReadEmbedded(pDevice, 0xE7, &byData);
+               MACvSetBBType(priv->PortOffset, BB_TYPE_11B);
+               if (priv->byRFType == RF_AIROHA7230) {
+                       priv->abyBBVGA[0] = 0x1C;
+                       priv->abyBBVGA[2] = 0x00;
+                       priv->abyBBVGA[3] = 0x00;
+                       BBbReadEmbedded(priv, 0xE7, &byData);
                        if (byData == 0x20)
-                               BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
+                               BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
 
-               } else if (pDevice->byRFType == RF_UW2452) {
-                       pDevice->abyBBVGA[0] = 0x14;
-                       BBbReadEmbedded(pDevice, 0xE7, &byData);
+               } else if (priv->byRFType == RF_UW2452) {
+                       priv->abyBBVGA[0] = 0x14;
+                       BBbReadEmbedded(priv, 0xE7, &byData);
                        if (byData == 0x18) {
-                               BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
-                               BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
+                               BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
+                               BBbWriteEmbedded(priv, 0xE1, 0xD3);
                        }
                }
-               BBbWriteEmbedded(pDevice, 0x88, 0x02);
+               BBbWriteEmbedded(priv, 0x88, 0x02);
                bySlot = C_SLOT_LONG;
                bySIFS = C_SIFS_BG;
                byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
                byCWMaxMin = 0xA5;
        } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
-               MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
-               if (pDevice->byRFType == RF_AIROHA7230) {
-                       pDevice->abyBBVGA[0] = 0x1C;
-                       pDevice->abyBBVGA[2] = 0x00;
-                       pDevice->abyBBVGA[3] = 0x00;
-                       BBbReadEmbedded(pDevice, 0xE7, &byData);
+               MACvSetBBType(priv->PortOffset, BB_TYPE_11G);
+               if (priv->byRFType == RF_AIROHA7230) {
+                       priv->abyBBVGA[0] = 0x1C;
+                       priv->abyBBVGA[2] = 0x00;
+                       priv->abyBBVGA[3] = 0x00;
+                       BBbReadEmbedded(priv, 0xE7, &byData);
                        if (byData == 0x20)
-                               BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
+                               BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
 
-               } else if (pDevice->byRFType == RF_UW2452) {
-                       pDevice->abyBBVGA[0] = 0x14;
-                       BBbReadEmbedded(pDevice, 0xE7, &byData);
+               } else if (priv->byRFType == RF_UW2452) {
+                       priv->abyBBVGA[0] = 0x14;
+                       BBbReadEmbedded(priv, 0xE7, &byData);
                        if (byData == 0x18) {
-                               BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
-                               BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
+                               BBbWriteEmbedded(priv, 0xE7, priv->abyBBVGA[0]);
+                               BBbWriteEmbedded(priv, 0xE1, 0xD3);
                        }
                }
-               BBbWriteEmbedded(pDevice, 0x88, 0x08);
+               BBbWriteEmbedded(priv, 0x88, 0x08);
                bySIFS = C_SIFS_BG;
 
-               if (pDevice->bShortSlotTime) {
+               if (priv->bShortSlotTime) {
                        bySlot = C_SLOT_SHORT;
-                       byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
+                       byDIFS = C_SIFS_BG + 2 * C_SLOT_SHORT;
                } else {
                        bySlot = C_SLOT_LONG;
                        byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
@@ -295,14 +295,14 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
                byCWMaxMin = 0xa4;
 
                for (i = RATE_54M; i >= RATE_6M; i--) {
-                       if (pDevice->basic_rates & ((u32)(0x1 << i))) {
+                       if (priv->basic_rates & ((u32)(0x1 << i))) {
                                byCWMaxMin |= 0x1;
                                break;
                        }
                }
        }
 
-       if (pDevice->byRFType == RF_RFMD2959) {
+       if (priv->byRFType == RF_RFMD2959) {
                /*
                 * bcs TX_PE will reserve 3 us hardware's processing
                 * time here is 2 us.
@@ -316,32 +316,32 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
                 */
        }
 
-       if (pDevice->bySIFS != bySIFS) {
-               pDevice->bySIFS = bySIFS;
-               VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
+       if (priv->bySIFS != bySIFS) {
+               priv->bySIFS = bySIFS;
+               VNSvOutPortB(priv->PortOffset + MAC_REG_SIFS, priv->bySIFS);
        }
-       if (pDevice->byDIFS != byDIFS) {
-               pDevice->byDIFS = byDIFS;
-               VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
+       if (priv->byDIFS != byDIFS) {
+               priv->byDIFS = byDIFS;
+               VNSvOutPortB(priv->PortOffset + MAC_REG_DIFS, priv->byDIFS);
        }
-       if (pDevice->byEIFS != C_EIFS) {
-               pDevice->byEIFS = C_EIFS;
-               VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
+       if (priv->byEIFS != C_EIFS) {
+               priv->byEIFS = C_EIFS;
+               VNSvOutPortB(priv->PortOffset + MAC_REG_EIFS, priv->byEIFS);
        }
-       if (pDevice->bySlot != bySlot) {
-               pDevice->bySlot = bySlot;
-               VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
+       if (priv->bySlot != bySlot) {
+               priv->bySlot = bySlot;
+               VNSvOutPortB(priv->PortOffset + MAC_REG_SLOT, priv->bySlot);
 
-               BBvSetShortSlotTime(pDevice);
+               BBvSetShortSlotTime(priv);
        }
-       if (pDevice->byCWMaxMin != byCWMaxMin) {
-               pDevice->byCWMaxMin = byCWMaxMin;
-               VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
+       if (priv->byCWMaxMin != byCWMaxMin) {
+               priv->byCWMaxMin = byCWMaxMin;
+               VNSvOutPortB(priv->PortOffset + MAC_REG_CWMAXMIN0, priv->byCWMaxMin);
        }
 
-       pDevice->byPacketType = CARDbyGetPktType(pDevice);
+       priv->byPacketType = CARDbyGetPktType(priv);
 
-       CARDvSetRSPINF(pDevice, bb_type);
+       CARDvSetRSPINF(priv, bb_type);
 
        return true;
 }
@@ -352,7 +352,7 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be sync.
+ *      priv         - The adapter to be sync.
  *      byRxRate        - data rate of receive beacon
  *      qwBSSTimestamp  - Rx BCN's TSF
  *      qwLocalTSF      - Local TSF
@@ -361,21 +361,21 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
  *
  * Return Value: none
  */
-bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
+bool CARDbUpdateTSF(struct vnt_private *priv, unsigned char byRxRate,
                    u64 qwBSSTimestamp)
 {
        u64 local_tsf;
        u64 qwTSFOffset = 0;
 
-       CARDbGetCurrentTSF(pDevice, &local_tsf);
+       CARDbGetCurrentTSF(priv, &local_tsf);
 
        if (qwBSSTimestamp != local_tsf) {
                qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp,
                                                local_tsf);
                /* adjust TSF, HW's TSF add TSF Offset reg */
-               VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
-               VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
-               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
+               VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
+               VNSvOutPortD(priv->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
+               MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
        }
        return true;
 }
@@ -386,29 +386,29 @@ bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be set.
+ *      priv         - The adapter to be set.
  *      wBeaconInterval - Beacon Interval
  *  Out:
  *      none
  *
  * Return Value: true if succeed; otherwise false
  */
-bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
+bool CARDbSetBeaconPeriod(struct vnt_private *priv,
                          unsigned short wBeaconInterval)
 {
        u64 qwNextTBTT = 0;
 
-       CARDbGetCurrentTSF(pDevice, &qwNextTBTT); /* Get Local TSF counter */
+       CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
 
        qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
 
        /* set HW beacon interval */
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
-       pDevice->wBeaconInterval = wBeaconInterval;
+       VNSvOutPortW(priv->PortOffset + MAC_REG_BI, wBeaconInterval);
+       priv->wBeaconInterval = wBeaconInterval;
        /* Set NextTBTT */
-       VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
-       VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
-       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
+       VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
+       VNSvOutPortD(priv->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
+       MACvRegBitsOn(priv->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
 
        return true;
 }
@@ -418,41 +418,41 @@ bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be turned off
+ *      priv         - The adapter to be turned off
  *  Out:
  *      none
  *
  * Return Value: true if success; otherwise false
  */
-bool CARDbRadioPowerOff(struct vnt_private *pDevice)
+bool CARDbRadioPowerOff(struct vnt_private *priv)
 {
        bool bResult = true;
 
-       if (pDevice->bRadioOff == true)
+       if (priv->bRadioOff)
                return true;
 
-       switch (pDevice->byRFType) {
+       switch (priv->byRFType) {
        case RF_RFMD2959:
-               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
-               MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
+               MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
+               MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
                break;
 
        case RF_AIROHA:
        case RF_AL2230S:
        case RF_AIROHA7230:
-               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
-               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
+               MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
+               MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
                break;
 
        }
 
-       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
+       MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
 
-       BBvSetDeepSleep(pDevice, pDevice->byLocalID);
+       BBvSetDeepSleep(priv, priv->byLocalID);
 
-       pDevice->bRadioOff = true;
+       priv->bRadioOff = true;
        pr_debug("chester power off\n");
-       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET);  /* LED issue */
+       MACvRegBitsOn(priv->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET);  /* LED issue */
        return bResult;
 }
 
@@ -461,89 +461,89 @@ bool CARDbRadioPowerOff(struct vnt_private *pDevice)
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be turned on
+ *      priv         - The adapter to be turned on
  *  Out:
  *      none
  *
  * Return Value: true if success; otherwise false
  */
-bool CARDbRadioPowerOn(struct vnt_private *pDevice)
+bool CARDbRadioPowerOn(struct vnt_private *priv)
 {
        bool bResult = true;
 
        pr_debug("chester power on\n");
-       if (pDevice->bRadioControlOff == true) {
-               if (pDevice->bHWRadioOff == true)
+       if (priv->bRadioControlOff) {
+               if (priv->bHWRadioOff)
                        pr_debug("chester bHWRadioOff\n");
-               if (pDevice->bRadioControlOff == true)
+               if (priv->bRadioControlOff)
                        pr_debug("chester bRadioControlOff\n");
                return false; }
 
-       if (pDevice->bRadioOff == false) {
+       if (!priv->bRadioOff) {
                pr_debug("chester pbRadioOff\n");
                return true; }
 
-       BBvExitDeepSleep(pDevice, pDevice->byLocalID);
+       BBvExitDeepSleep(priv, priv->byLocalID);
 
-       MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
+       MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
 
-       switch (pDevice->byRFType) {
+       switch (priv->byRFType) {
        case RF_RFMD2959:
-               MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
-               MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
+               MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
+               MACvWordRegBitsOff(priv->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
                break;
 
        case RF_AIROHA:
        case RF_AL2230S:
        case RF_AIROHA7230:
-               MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
+               MACvWordRegBitsOn(priv->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
                                                                            SOFTPWRCTL_SWPE3));
                break;
 
        }
 
-       pDevice->bRadioOff = false;
+       priv->bRadioOff = false;
        pr_debug("chester power on\n");
-       MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
+       MACvRegBitsOff(priv->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
        return bResult;
 }
 
 void
 CARDvSafeResetTx(
-       struct vnt_private *pDevice
+       struct vnt_private *priv
 )
 {
        unsigned int uu;
        struct vnt_tx_desc *pCurrTD;
 
        /* initialize TD index */
-       pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
-       pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
+       priv->apTailTD[0] = priv->apCurrTD[0] = &(priv->apTD0Rings[0]);
+       priv->apTailTD[1] = priv->apCurrTD[1] = &(priv->apTD1Rings[0]);
 
        for (uu = 0; uu < TYPE_MAXTD; uu++)
-               pDevice->iTDUsed[uu] = 0;
+               priv->iTDUsed[uu] = 0;
 
-       for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
-               pCurrTD = &(pDevice->apTD0Rings[uu]);
+       for (uu = 0; uu < priv->opts.tx_descs[0]; uu++) {
+               pCurrTD = &(priv->apTD0Rings[uu]);
                pCurrTD->td0.owner = OWNED_BY_HOST;
                /* init all Tx Packet pointer to NULL */
        }
-       for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
-               pCurrTD = &(pDevice->apTD1Rings[uu]);
+       for (uu = 0; uu < priv->opts.tx_descs[1]; uu++) {
+               pCurrTD = &(priv->apTD1Rings[uu]);
                pCurrTD->td0.owner = OWNED_BY_HOST;
                /* init all Tx Packet pointer to NULL */
        }
 
        /* set MAC TD pointer */
-       MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
-                             (pDevice->td0_pool_dma));
+       MACvSetCurrTXDescAddr(TYPE_TXDMA0, priv->PortOffset,
+                             (priv->td0_pool_dma));
 
-       MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
-                             (pDevice->td1_pool_dma));
+       MACvSetCurrTXDescAddr(TYPE_AC0DMA, priv->PortOffset,
+                             (priv->td1_pool_dma));
 
        /* set MAC Beacon TX pointer */
-       MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
-                                (pDevice->tx_beacon_dma));
+       MACvSetCurrBCNTxDescAddr(priv->PortOffset,
+                                (priv->tx_beacon_dma));
 }
 
 /*
@@ -552,7 +552,7 @@ CARDvSafeResetTx(
  *
  * Parameters:
  *  In:
- *      pDevice     - Pointer to the adapter
+ *      priv     - Pointer to the adapter
  *  Out:
  *      none
  *
@@ -560,41 +560,41 @@ CARDvSafeResetTx(
  */
 void
 CARDvSafeResetRx(
-       struct vnt_private *pDevice
+       struct vnt_private *priv
 )
 {
        unsigned int uu;
-       PSRxDesc    pDesc;
+       struct vnt_rx_desc *pDesc;
 
        /* initialize RD index */
-       pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
-       pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
+       priv->pCurrRD[0] = &(priv->aRD0Ring[0]);
+       priv->pCurrRD[1] = &(priv->aRD1Ring[0]);
 
        /* init state, all RD is chip's */
-       for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
-               pDesc = &(pDevice->aRD0Ring[uu]);
-               pDesc->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
-               pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
-               pDesc->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
+       for (uu = 0; uu < priv->opts.rx_descs0; uu++) {
+               pDesc = &(priv->aRD0Ring[uu]);
+               pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
+               pDesc->rd0.owner = OWNED_BY_NIC;
+               pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
        }
 
        /* init state, all RD is chip's */
-       for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
-               pDesc = &(pDevice->aRD1Ring[uu]);
-               pDesc->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
-               pDesc->m_rd0RD0.f1Owner = OWNED_BY_NIC;
-               pDesc->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
+       for (uu = 0; uu < priv->opts.rx_descs1; uu++) {
+               pDesc = &(priv->aRD1Ring[uu]);
+               pDesc->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
+               pDesc->rd0.owner = OWNED_BY_NIC;
+               pDesc->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
        }
 
        /* set perPkt mode */
-       MACvRx0PerPktMode(pDevice->PortOffset);
-       MACvRx1PerPktMode(pDevice->PortOffset);
+       MACvRx0PerPktMode(priv->PortOffset);
+       MACvRx1PerPktMode(priv->PortOffset);
        /* set MAC RD pointer */
-       MACvSetCurrRx0DescAddr(pDevice->PortOffset,
-                              pDevice->rd0_pool_dma);
+       MACvSetCurrRx0DescAddr(priv->PortOffset,
+                              priv->rd0_pool_dma);
 
-       MACvSetCurrRx1DescAddr(pDevice->PortOffset,
-                              pDevice->rd1_pool_dma);
+       MACvSetCurrRx1DescAddr(priv->PortOffset,
+                              priv->rd1_pool_dma);
 }
 
 /*
@@ -602,20 +602,20 @@ CARDvSafeResetRx(
  *
  * Parameters:
  *  In:
- *      pDevice             - The adapter to be set
+ *      priv             - The adapter to be set
  *      wRateIdx            - Receiving data rate
  *  Out:
  *      none
  *
  * Return Value: response Control frame rate
  */
-static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
+static unsigned short CARDwGetCCKControlRate(struct vnt_private *priv,
                                             unsigned short wRateIdx)
 {
        unsigned int ui = (unsigned int) wRateIdx;
 
        while (ui > RATE_1M) {
-               if (pDevice->basic_rates & ((u32)0x1 << ui))
+               if (priv->basic_rates & ((u32)0x1 << ui))
                        return (unsigned short)ui;
 
                ui--;
@@ -628,28 +628,28 @@ static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
  *
  * Parameters:
  *  In:
- *      pDevice             - The adapter to be set
+ *      priv             - The adapter to be set
  *      wRateIdx            - Receiving data rate
  *  Out:
  *      none
  *
  * Return Value: response Control frame rate
  */
-static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
+static unsigned short CARDwGetOFDMControlRate(struct vnt_private *priv,
                                              unsigned short wRateIdx)
 {
        unsigned int ui = (unsigned int) wRateIdx;
 
-       pr_debug("BASIC RATE: %X\n", pDevice->basic_rates);
+       pr_debug("BASIC RATE: %X\n", priv->basic_rates);
 
-       if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
+       if (!CARDbIsOFDMinBasicRate((void *)priv)) {
                pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
                if (wRateIdx > RATE_24M)
                        wRateIdx = RATE_24M;
                return wRateIdx;
        }
        while (ui > RATE_11M) {
-               if (pDevice->basic_rates & ((u32)0x1 << ui)) {
+               if (priv->basic_rates & ((u32)0x1 << ui)) {
                        pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
                        return (unsigned short)ui;
                }
@@ -664,162 +664,162 @@ static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
  *
  * Parameters:
  *  In:
- *      pDevice             - The adapter to be set
+ *      priv             - The adapter to be set
  *  Out:
  *      none
  *
  * Return Value: None.
  */
-void CARDvSetRSPINF(struct vnt_private *pDevice, u8 bb_type)
+void CARDvSetRSPINF(struct vnt_private *priv, u8 bb_type)
 {
        union vnt_phy_field_swap phy;
        unsigned char byTxRate, byRsvTime;      /* For OFDM */
        unsigned long flags;
 
-       spin_lock_irqsave(&pDevice->lock, flags);
+       spin_lock_irqsave(&priv->lock, flags);
 
        /* Set to Page1 */
-       MACvSelectPage1(pDevice->PortOffset);
+       MACvSelectPage1(priv->PortOffset);
 
        /* RSPINF_b_1 */
-       vnt_get_phy_field(pDevice, 14,
-                         CARDwGetCCKControlRate(pDevice, RATE_1M),
+       vnt_get_phy_field(priv, 14,
+                         CARDwGetCCKControlRate(priv, RATE_1M),
                          PK_TYPE_11B, &phy.field_read);
 
         /* swap over to get correct write order */
        swap(phy.swap[0], phy.swap[1]);
 
-       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
+       VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
 
        /* RSPINF_b_2 */
-       vnt_get_phy_field(pDevice, 14,
-                         CARDwGetCCKControlRate(pDevice, RATE_2M),
+       vnt_get_phy_field(priv, 14,
+                         CARDwGetCCKControlRate(priv, RATE_2M),
                          PK_TYPE_11B, &phy.field_read);
 
        swap(phy.swap[0], phy.swap[1]);
 
-       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
+       VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
 
        /* RSPINF_b_5 */
-       vnt_get_phy_field(pDevice, 14,
-                         CARDwGetCCKControlRate(pDevice, RATE_5M),
+       vnt_get_phy_field(priv, 14,
+                         CARDwGetCCKControlRate(priv, RATE_5M),
                          PK_TYPE_11B, &phy.field_read);
 
        swap(phy.swap[0], phy.swap[1]);
 
-       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
+       VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
 
        /* RSPINF_b_11 */
-       vnt_get_phy_field(pDevice, 14,
-                         CARDwGetCCKControlRate(pDevice, RATE_11M),
+       vnt_get_phy_field(priv, 14,
+                         CARDwGetCCKControlRate(priv, RATE_11M),
                          PK_TYPE_11B, &phy.field_read);
 
        swap(phy.swap[0], phy.swap[1]);
 
-       VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
+       VNSvOutPortD(priv->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
 
        /* RSPINF_a_6 */
        s_vCalculateOFDMRParameter(RATE_6M,
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_9 */
        s_vCalculateOFDMRParameter(RATE_9M,
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_12 */
        s_vCalculateOFDMRParameter(RATE_12M,
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_18 */
        s_vCalculateOFDMRParameter(RATE_18M,
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_24 */
        s_vCalculateOFDMRParameter(RATE_24M,
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_36 */
-       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv, RATE_36M),
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_48 */
-       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv, RATE_48M),
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_54 */
-       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv, RATE_54M),
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
        /* RSPINF_a_72 */
-       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
+       s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)priv, RATE_54M),
                                   bb_type,
                                   &byTxRate,
                                   &byRsvTime);
-       VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
+       VNSvOutPortW(priv->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
        /* Set to Page0 */
-       MACvSelectPage0(pDevice->PortOffset);
+       MACvSelectPage0(priv->PortOffset);
 
-       spin_unlock_irqrestore(&pDevice->lock, flags);
+       spin_unlock_irqrestore(&priv->lock, flags);
 }
 
-void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
+void CARDvUpdateBasicTopRate(struct vnt_private *priv)
 {
        unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
        unsigned char ii;
 
        /* Determines the highest basic rate. */
        for (ii = RATE_54M; ii >= RATE_6M; ii--) {
-               if ((pDevice->basic_rates) & ((u32)(1 << ii))) {
+               if ((priv->basic_rates) & ((u32)(1 << ii))) {
                        byTopOFDM = ii;
                        break;
                }
        }
-       pDevice->byTopOFDMBasicRate = byTopOFDM;
+       priv->byTopOFDMBasicRate = byTopOFDM;
 
        for (ii = RATE_11M;; ii--) {
-               if ((pDevice->basic_rates) & ((u32)(1 << ii))) {
+               if ((priv->basic_rates) & ((u32)(1 << ii))) {
                        byTopCCK = ii;
                        break;
                }
                if (ii == RATE_1M)
                        break;
        }
-       pDevice->byTopCCKBasicRate = byTopCCK;
+       priv->byTopCCKBasicRate = byTopCCK;
 }
 
-bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
+bool CARDbIsOFDMinBasicRate(struct vnt_private *priv)
 {
        int ii;
 
        for (ii = RATE_54M; ii >= RATE_6M; ii--) {
-               if ((pDevice->basic_rates) & ((u32)(1 << ii)))
+               if ((priv->basic_rates) & ((u32)BIT(ii)))
                        return true;
        }
        return false;
 }
 
-unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
+unsigned char CARDbyGetPktType(struct vnt_private *priv)
 {
 
-       if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B)
-               return (unsigned char)pDevice->byBBType;
-       else if (CARDbIsOFDMinBasicRate((void *)pDevice))
+       if (priv->byBBType == BB_TYPE_11A || priv->byBBType == BB_TYPE_11B)
+               return (unsigned char)priv->byBBType;
+       else if (CARDbIsOFDMinBasicRate((void *)priv))
                return PK_TYPE_11GA;
        else
                return PK_TYPE_11GB;
@@ -830,7 +830,7 @@ unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be set
+ *      priv         - The adapter to be set
  *      wLoopbackMode   - Loopback mode to be set
  *  Out:
  *      none
@@ -859,17 +859,17 @@ void CARDvSetLoopbackMode(struct vnt_private *priv, unsigned short wLoopbackMode
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be reset
+ *      priv         - The adapter to be reset
  *  Out:
  *      none
  *
  * Return Value: none
  */
-bool CARDbSoftwareReset(struct vnt_private *pDevice)
+bool CARDbSoftwareReset(struct vnt_private *priv)
 {
 
        /* reset MAC */
-       if (!MACbSafeSoftwareReset(pDevice->PortOffset))
+       if (!MACbSafeSoftwareReset(priv->PortOffset))
                return false;
 
        return true;
@@ -881,7 +881,7 @@ bool CARDbSoftwareReset(struct vnt_private *pDevice)
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be sync.
+ *      priv         - The adapter to be sync.
  *      qwTSF1          - Rx BCN's TSF
  *      qwTSF2          - Local TSF
  *  Out:
@@ -892,7 +892,7 @@ bool CARDbSoftwareReset(struct vnt_private *pDevice)
 u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
 {
        u64 qwTSFOffset = 0;
-       unsigned short wRxBcnTSFOffst = 0;
+       unsigned short wRxBcnTSFOffst;
 
        wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
 
@@ -909,7 +909,7 @@ u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be read
+ *      priv         - The adapter to be read
  *  Out:
  *      qwCurrTSF       - Current TSF counter
  *
@@ -995,7 +995,7 @@ void CARDvSetFirstNextTBTT(struct vnt_private *priv, unsigned short wBeaconInter
  *
  * Parameters:
  *  In:
- *      pDevice         - The adapter to be set
+ *      priv         - The adapter to be set
  *      qwTSF           - Current TSF counter
  *      wBeaconInterval - Beacon Interval
  *  Out:
index 3c9007e34c0ff30c644d923a2a040bcf146f456b..9fbc7172484e689bbe8d86961391c50ba57ea93a 100644 (file)
  * leads error.
  */
 
-typedef struct tagDEVICE_RD_INFO {
+struct vnt_rd_info {
        struct sk_buff *skb;
        dma_addr_t  skb_dma;
-} DEVICE_RD_INFO,   *PDEVICE_RD_INFO;
+};
 
+struct vnt_rdes0 {
+       volatile __le16 res_count;
 #ifdef __BIG_ENDIAN
-
-typedef struct tagRDES0 {
-       volatile __le16 wResCount;
        union {
-               volatile u16    f15Reserved;
+               volatile u16 f15_reserved;
                struct {
-                       volatile u8 f8Reserved1;
-                       volatile u8 f1Owner:1;
-                       volatile u8 f7Reserved:7;
-               } __attribute__ ((__packed__));
-       } __attribute__ ((__packed__));
-} __attribute__ ((__packed__))
-SRDES0, *PSRDES0;
-
+                       volatile u8 f8_reserved1;
+                       volatile u8 owner:1;
+                       volatile u8 f7_reserved:7;
+               } __packed;
+       } __packed;
 #else
-
-typedef struct tagRDES0 {
-       __le16         wResCount;
-       unsigned short f15Reserved:15;
-       unsigned short f1Owner:1;
-} __attribute__ ((__packed__))
-SRDES0;
-
+       u16 f15_reserved:15;
+       u16 owner:1;
 #endif
+} __packed;
 
-typedef struct tagRDES1 {
-       __le16         wReqCount;
-       unsigned short wReserved;
-} __attribute__ ((__packed__))
-SRDES1;
+struct vnt_rdes1 {
+       __le16 req_count;
+       u16 reserved;
+} __packed;
 
 /* Rx descriptor*/
-typedef struct tagSRxDesc {
-       volatile SRDES0 m_rd0RD0;
-       volatile SRDES1 m_rd1RD1;
+struct vnt_rx_desc {
+       volatile struct vnt_rdes0 rd0;
+       volatile struct vnt_rdes1 rd1;
        volatile __le32 buff_addr;
        volatile __le32 next_desc;
-       struct tagSRxDesc *next __aligned(8);
-       volatile PDEVICE_RD_INFO pRDInfo __aligned(8);
-} __attribute__ ((__packed__))
-SRxDesc, *PSRxDesc;
-typedef const SRxDesc *PCSRxDesc;
+       struct vnt_rx_desc *next __aligned(8);
+       struct vnt_rd_info *rd_info __aligned(8);
+} __packed;
 
 struct vnt_tdes0 {
        volatile u8 tsr0;
index c9fa6ef42d340d6cb5e48343e503cbdaec43e7c4..55405e058196f878821e851c50ce855f383e139b 100644 (file)
 
 #include <linux/module.h>
 #include <linux/types.h>
-#include <linux/mm.h>
-#include <linux/errno.h>
-#include <linux/ioport.h>
 #include <linux/pci.h>
-#include <linux/kernel.h>
-#include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
-#include <linux/delay.h>
-#include <linux/timer.h>
-#include <linux/slab.h>
 #include <linux/interrupt.h>
-#include <linux/string.h>
-#include <linux/wait.h>
-#include <linux/if_arp.h>
-#include <linux/sched.h>
-#include <linux/io.h>
-#include <linux/if.h>
 #include <linux/crc32.h>
-#include <linux/uaccess.h>
-#include <linux/proc_fs.h>
-#include <linux/inetdevice.h>
-#include <linux/reboot.h>
-#include <linux/ethtool.h>
-/* Include Wireless Extension definition and check version - Jean II */
 #include <net/mac80211.h>
-#include <linux/wireless.h>
-#include <net/iw_handler.h>    /* New driver API */
-
-#ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-#define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
-#endif
 
 /* device specific */
 
 #define RATE_36M       9
 #define RATE_48M       10
 #define RATE_54M       11
-#define RATE_AUTO      12
 #define MAX_RATE       12
 
-#define MAC_MAX_CONTEXT_REG     (256+128)
-
-#define MAX_MULTICAST_ADDRESS_NUM       32
-#define MULTICAST_ADDRESS_LIST_SIZE     (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
-
-#define DUPLICATE_RX_CACHE_LENGTH       5
-
-#define NUM_KEY_ENTRY                   11
-
-#define TX_WEP_NONE                     0
-#define TX_WEP_OTF                      1
-#define TX_WEP_SW                       2
-#define TX_WEP_SWOTP                    3
-#define TX_WEP_OTPSW                    4
-#define TX_WEP_SW232                    5
-
-#define KEYSEL_WEP40                    0
-#define KEYSEL_WEP104                   1
-#define KEYSEL_TKIP                     2
-#define KEYSEL_CCMP                     3
-
 #define AUTO_FB_NONE            0
 #define AUTO_FB_0               1
 #define AUTO_FB_1               2
 #define ANT_RXD_TXB             4
 #define ANT_UNKNOWN             0xFF
 
-#define MAXCHECKHANGCNT         4
-
 #define BB_VGA_LEVEL            4
 #define BB_VGA_CHANGE_THRESHOLD 16
 
-#ifndef RUN_AT
-#define RUN_AT(x)                       (jiffies+(x))
-#endif
-
 #define MAKE_BEACON_RESERVED   10  /* (us) */
 
-/* DMA related */
-#define RESERV_AC0DMA                   4
-
 /* BUILD OBJ mode */
 
-#define        AVAIL_TD(p, q)  ((p)->sOpts.nTxDescs[(q)] - ((p)->iTDUsed[(q)]))
-
-#define        NUM                             64
+#define        AVAIL_TD(p, q)  ((p)->opts.tx_descs[(q)] - ((p)->iTDUsed[(q)]))
 
 /* 0:11A 1:11B 2:11G */
 #define BB_TYPE_11A    0
 #define PK_TYPE_11GB    2
 #define PK_TYPE_11GA    3
 
-typedef struct __chip_info_tbl {
-       CHIP_TYPE   chip_id;
-       char *name;
-       int         io_size;
-       int         nTxQueue;
-       u32         flags;
-} CHIP_INFO, *PCHIP_INFO;
-
-typedef enum {
-       OWNED_BY_HOST = 0,
-       OWNED_BY_NIC = 1
-} DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE;
-
-/* flags for options */
-#define     DEVICE_FLAGS_IP_ALIGN        0x00000001UL
-#define     DEVICE_FLAGS_PREAMBLE_TYPE   0x00000002UL
-#define     DEVICE_FLAGS_OP_MODE         0x00000004UL
-#define     DEVICE_FLAGS_PS_MODE         0x00000008UL
-#define                DEVICE_FLAGS_80211h_MODE         0x00000010UL
-#define                DEVICE_FLAGS_DiversityANT        0x00000020UL
-
-/* flags for driver status */
-#define     DEVICE_FLAGS_OPENED          0x00010000UL
-#define     DEVICE_FLAGS_WOL_ENABLED     0x00080000UL
-/* flags for capabilities */
-#define     DEVICE_FLAGS_TX_ALIGN        0x01000000UL
-#define     DEVICE_FLAGS_HAVE_CAM        0x02000000UL
-#define     DEVICE_FLAGS_FLOW_CTRL       0x04000000UL
-
-/* flags for MII status */
-#define     DEVICE_LINK_FAIL             0x00000001UL
-#define     DEVICE_SPEED_10              0x00000002UL
-#define     DEVICE_SPEED_100             0x00000004UL
-#define     DEVICE_SPEED_1000            0x00000008UL
-#define     DEVICE_DUPLEX_FULL           0x00000010UL
-#define     DEVICE_AUTONEG_ENABLE        0x00000020UL
-#define     DEVICE_FORCED_BY_EEPROM      0x00000040UL
-/* for device_set_media_duplex */
-#define     DEVICE_LINK_CHANGE           0x00000001UL
-
-typedef struct __device_opt {
-       int         nRxDescs0;          /* Number of RX descriptors0 */
-       int         nRxDescs1;          /* Number of RX descriptors1 */
-       int         nTxDescs[2];        /* Number of TX descriptors 0, 1 */
-       int         int_works;          /* interrupt limits */
-       int         short_retry;
-       int         long_retry;
-       int         bbp_type;
-       u32         flags;
-} OPTIONS, *POPTIONS;
+#define OWNED_BY_HOST  0
+#define        OWNED_BY_NIC    1
+
+struct vnt_options {
+       int rx_descs0;          /* Number of RX descriptors0 */
+       int rx_descs1;          /* Number of RX descriptors1 */
+       int tx_descs[2];        /* Number of TX descriptors 0, 1 */
+       int int_works;          /* interrupt limits */
+       int short_retry;
+       int long_retry;
+       int bbp_type;
+       u32 flags;
+};
 
 struct vnt_private {
        struct pci_dev *pcid;
@@ -235,21 +139,14 @@ struct vnt_private {
        unsigned char *tx1_bufs;
        unsigned char *tx_beacon_bufs;
 
-       CHIP_TYPE                   chip_id;
-
        void __iomem                *PortOffset;
        u32                         memaddr;
        u32                         ioaddr;
-       u32                         io_size;
 
-       unsigned char byRevId;
        unsigned char byRxMode;
-       unsigned short SubSystemID;
-       unsigned short SubVendorID;
 
        spinlock_t                  lock;
 
-       int                         nTxQueues;
        volatile int                iTDUsed[TYPE_MAXTD];
 
        struct vnt_tx_desc *apCurrTD[TYPE_MAXTD];
@@ -258,17 +155,16 @@ struct vnt_private {
        struct vnt_tx_desc *apTD0Rings;
        struct vnt_tx_desc *apTD1Rings;
 
-       volatile PSRxDesc           aRD0Ring;
-       volatile PSRxDesc           aRD1Ring;
-       volatile PSRxDesc           pCurrRD[TYPE_MAXRD];
+       struct vnt_rx_desc *aRD0Ring;
+       struct vnt_rx_desc *aRD1Ring;
+       struct vnt_rx_desc *pCurrRD[TYPE_MAXRD];
 
-       OPTIONS                     sOpts;
+       struct vnt_options opts;
 
        u32                         flags;
 
        u32                         rx_buf_sz;
        u8 rx_rate;
-       int                         multicast_limit;
 
        u32                         rx_bytes;
 
@@ -410,13 +306,4 @@ struct vnt_private {
        struct ieee80211_low_level_stats low_stats;
 };
 
-static inline PDEVICE_RD_INFO alloc_rd_info(void)
-{
-       return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
-}
-
-static inline struct vnt_td_info *alloc_td_info(void)
-{
-       return kzalloc(sizeof(struct vnt_td_info), GFP_ATOMIC);
-}
 #endif
index 0d8f123c57fe22cebe800d7c282e6808bb046b3c..fefbf826c622380380e47fd7d55e3cfc812e924b 100644 (file)
@@ -28,9 +28,7 @@
  *
  *   vt6655_probe - module initial (insmod) driver entry
  *   vt6655_remove - module remove entry
- *   vt6655_init_info - device structure resource allocation function
  *   device_free_info - device structure resource free function
- *   device_get_pci_info - get allocated pci io/mem resource
  *   device_print_info - print out resource
  *   device_rx_srv - rx service function
  *   device_alloc_rx_buf - rx buffer pre-allocated function
@@ -128,103 +126,84 @@ DEVICE_PARAM(BasebandType, "baseband type");
 /*
  * Static vars definitions
  */
-static CHIP_INFO chip_info_table[] = {
-       { VT3253,       "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
-         256, 1,     DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
-       {0, NULL}
-};
-
 static const struct pci_device_id vt6655_pci_id_table[] = {
-       { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
+       { PCI_VDEVICE(VIA, 0x3253) },
        { 0, }
 };
 
 /*---------------------  Static Functions  --------------------------*/
 
 static int  vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
-static void vt6655_init_info(struct pci_dev *pcid,
-                            struct vnt_private **ppDevice, PCHIP_INFO);
-static void device_free_info(struct vnt_private *pDevice);
-static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
-static void device_print_info(struct vnt_private *pDevice);
-
-static void device_init_rd0_ring(struct vnt_private *pDevice);
-static void device_init_rd1_ring(struct vnt_private *pDevice);
-static void device_init_td0_ring(struct vnt_private *pDevice);
-static void device_init_td1_ring(struct vnt_private *pDevice);
-
-static int  device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
-static int  device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
-static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
-static void device_init_registers(struct vnt_private *pDevice);
+static void device_free_info(struct vnt_private *priv);
+static void device_print_info(struct vnt_private *priv);
+
+static void device_init_rd0_ring(struct vnt_private *priv);
+static void device_init_rd1_ring(struct vnt_private *priv);
+static void device_init_td0_ring(struct vnt_private *priv);
+static void device_init_td1_ring(struct vnt_private *priv);
+
+static int  device_rx_srv(struct vnt_private *priv, unsigned int idx);
+static int  device_tx_srv(struct vnt_private *priv, unsigned int idx);
+static bool device_alloc_rx_buf(struct vnt_private *, struct vnt_rx_desc *);
+static void device_init_registers(struct vnt_private *priv);
 static void device_free_tx_buf(struct vnt_private *, struct vnt_tx_desc *);
-static void device_free_td0_ring(struct vnt_private *pDevice);
-static void device_free_td1_ring(struct vnt_private *pDevice);
-static void device_free_rd0_ring(struct vnt_private *pDevice);
-static void device_free_rd1_ring(struct vnt_private *pDevice);
-static void device_free_rings(struct vnt_private *pDevice);
+static void device_free_td0_ring(struct vnt_private *priv);
+static void device_free_td1_ring(struct vnt_private *priv);
+static void device_free_rd0_ring(struct vnt_private *priv);
+static void device_free_rd1_ring(struct vnt_private *priv);
+static void device_free_rings(struct vnt_private *priv);
 
 /*---------------------  Export Variables  --------------------------*/
 
 /*---------------------  Export Functions  --------------------------*/
 
-static char *get_chip_name(int chip_id)
-{
-       int i;
-
-       for (i = 0; chip_info_table[i].name != NULL; i++)
-               if (chip_info_table[i].chip_id == chip_id)
-                       break;
-       return chip_info_table[i].name;
-}
-
 static void vt6655_remove(struct pci_dev *pcid)
 {
-       struct vnt_private *pDevice = pci_get_drvdata(pcid);
+       struct vnt_private *priv = pci_get_drvdata(pcid);
 
-       if (pDevice == NULL)
+       if (priv == NULL)
                return;
-       device_free_info(pDevice);
+       device_free_info(priv);
 }
 
-static void device_get_options(struct vnt_private *pDevice)
+static void device_get_options(struct vnt_private *priv)
 {
-       POPTIONS pOpts = &(pDevice->sOpts);
+       struct vnt_options *opts = &priv->opts;
 
-       pOpts->nRxDescs0 = RX_DESC_DEF0;
-       pOpts->nRxDescs1 = RX_DESC_DEF1;
-       pOpts->nTxDescs[0] = TX_DESC_DEF0;
-       pOpts->nTxDescs[1] = TX_DESC_DEF1;
-       pOpts->int_works = INT_WORKS_DEF;
+       opts->rx_descs0 = RX_DESC_DEF0;
+       opts->rx_descs1 = RX_DESC_DEF1;
+       opts->tx_descs[0] = TX_DESC_DEF0;
+       opts->tx_descs[1] = TX_DESC_DEF1;
+       opts->int_works = INT_WORKS_DEF;
 
-       pOpts->short_retry = SHORT_RETRY_DEF;
-       pOpts->long_retry = LONG_RETRY_DEF;
-       pOpts->bbp_type = BBP_TYPE_DEF;
+       opts->short_retry = SHORT_RETRY_DEF;
+       opts->long_retry = LONG_RETRY_DEF;
+       opts->bbp_type = BBP_TYPE_DEF;
 }
 
 static void
-device_set_options(struct vnt_private *pDevice)
+device_set_options(struct vnt_private *priv)
 {
-       pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
-       pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
-       pDevice->byBBType = pDevice->sOpts.bbp_type;
-       pDevice->byPacketType = pDevice->byBBType;
-       pDevice->byAutoFBCtrl = AUTO_FB_0;
-       pDevice->bUpdateBBVGA = true;
-       pDevice->byPreambleType = 0;
-
-       pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
-       pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
-       pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
-       pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
-       pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
+       priv->byShortRetryLimit = priv->opts.short_retry;
+       priv->byLongRetryLimit = priv->opts.long_retry;
+       priv->byBBType = priv->opts.bbp_type;
+       priv->byPacketType = priv->byBBType;
+       priv->byAutoFBCtrl = AUTO_FB_0;
+       priv->bUpdateBBVGA = true;
+       priv->byPreambleType = 0;
+
+       pr_debug(" byShortRetryLimit= %d\n", (int)priv->byShortRetryLimit);
+       pr_debug(" byLongRetryLimit= %d\n", (int)priv->byLongRetryLimit);
+       pr_debug(" byPreambleType= %d\n", (int)priv->byPreambleType);
+       pr_debug(" byShortPreamble= %d\n", (int)priv->byShortPreamble);
+       pr_debug(" byBBType= %d\n", (int)priv->byBBType);
 }
 
 /*
  * Initialisation of MAC & BBP registers
  */
 
-static void device_init_registers(struct vnt_private *pDevice)
+static void device_init_registers(struct vnt_private *priv)
 {
        unsigned long flags;
        unsigned int ii;
@@ -232,48 +211,45 @@ static void device_init_registers(struct vnt_private *pDevice)
        unsigned char byCCKPwrdBm = 0;
        unsigned char byOFDMPwrdBm = 0;
 
-       MACbShutdown(pDevice->PortOffset);
-       BBvSoftwareReset(pDevice);
+       MACbShutdown(priv->PortOffset);
+       BBvSoftwareReset(priv);
 
        /* Do MACbSoftwareReset in MACvInitialize */
-       MACbSoftwareReset(pDevice->PortOffset);
+       MACbSoftwareReset(priv->PortOffset);
 
-       pDevice->bAES = false;
+       priv->bAES = false;
 
        /* Only used in 11g type, sync with ERP IE */
-       pDevice->bProtectMode = false;
-
-       pDevice->bNonERPPresent = false;
-       pDevice->bBarkerPreambleMd = false;
-       pDevice->wCurrentRate = RATE_1M;
-       pDevice->byTopOFDMBasicRate = RATE_24M;
-       pDevice->byTopCCKBasicRate = RATE_1M;
+       priv->bProtectMode = false;
 
-       /* Target to IF pin while programming to RF chip. */
-       pDevice->byRevId = 0;
+       priv->bNonERPPresent = false;
+       priv->bBarkerPreambleMd = false;
+       priv->wCurrentRate = RATE_1M;
+       priv->byTopOFDMBasicRate = RATE_24M;
+       priv->byTopCCKBasicRate = RATE_1M;
 
        /* init MAC */
-       MACvInitialize(pDevice->PortOffset);
+       MACvInitialize(priv->PortOffset);
 
        /* Get Local ID */
-       VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
+       VNSvInPortB(priv->PortOffset + MAC_REG_LOCALID, &priv->byLocalID);
 
-       spin_lock_irqsave(&pDevice->lock, flags);
+       spin_lock_irqsave(&priv->lock, flags);
 
-       SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
+       SROMvReadAllContents(priv->PortOffset, priv->abyEEPROM);
 
-       spin_unlock_irqrestore(&pDevice->lock, flags);
+       spin_unlock_irqrestore(&priv->lock, flags);
 
        /* Get Channel range */
-       pDevice->byMinChannel = 1;
-       pDevice->byMaxChannel = CB_MAX_CHANNEL;
+       priv->byMinChannel = 1;
+       priv->byMaxChannel = CB_MAX_CHANNEL;
 
        /* Get Antena */
-       byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
+       byValue = SROMbyReadEmbedded(priv->PortOffset, EEP_OFS_ANTENNA);
        if (byValue & EEP_ANTINV)
-               pDevice->bTxRxAntInv = true;
+               priv->bTxRxAntInv = true;
        else
-               pDevice->bTxRxAntInv = false;
+               priv->bTxRxAntInv = false;
 
        byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
        /* if not set default is All */
@@ -281,545 +257,498 @@ static void device_init_registers(struct vnt_private *pDevice)
                byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
 
        if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
-               pDevice->byAntennaCount = 2;
-               pDevice->byTxAntennaMode = ANT_B;
-               pDevice->dwTxAntennaSel = 1;
-               pDevice->dwRxAntennaSel = 1;
+               priv->byAntennaCount = 2;
+               priv->byTxAntennaMode = ANT_B;
+               priv->dwTxAntennaSel = 1;
+               priv->dwRxAntennaSel = 1;
 
-               if (pDevice->bTxRxAntInv)
-                       pDevice->byRxAntennaMode = ANT_A;
+               if (priv->bTxRxAntInv)
+                       priv->byRxAntennaMode = ANT_A;
                else
-                       pDevice->byRxAntennaMode = ANT_B;
+                       priv->byRxAntennaMode = ANT_B;
        } else  {
-               pDevice->byAntennaCount = 1;
-               pDevice->dwTxAntennaSel = 0;
-               pDevice->dwRxAntennaSel = 0;
+               priv->byAntennaCount = 1;
+               priv->dwTxAntennaSel = 0;
+               priv->dwRxAntennaSel = 0;
 
                if (byValue & EEP_ANTENNA_AUX) {
-                       pDevice->byTxAntennaMode = ANT_A;
+                       priv->byTxAntennaMode = ANT_A;
 
-                       if (pDevice->bTxRxAntInv)
-                               pDevice->byRxAntennaMode = ANT_B;
+                       if (priv->bTxRxAntInv)
+                               priv->byRxAntennaMode = ANT_B;
                        else
-                               pDevice->byRxAntennaMode = ANT_A;
+                               priv->byRxAntennaMode = ANT_A;
                } else {
-                       pDevice->byTxAntennaMode = ANT_B;
+                       priv->byTxAntennaMode = ANT_B;
 
-                       if (pDevice->bTxRxAntInv)
-                               pDevice->byRxAntennaMode = ANT_A;
+                       if (priv->bTxRxAntInv)
+                               priv->byRxAntennaMode = ANT_A;
                        else
-                               pDevice->byRxAntennaMode = ANT_B;
+                               priv->byRxAntennaMode = ANT_B;
                }
        }
 
        /* Set initial antenna mode */
-       BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
-       BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
+       BBvSetTxAntennaMode(priv, priv->byTxAntennaMode);
+       BBvSetRxAntennaMode(priv, priv->byRxAntennaMode);
 
        /* zonetype initial */
-       pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
+       priv->byOriginalZonetype = priv->abyEEPROM[EEP_OFS_ZONETYPE];
 
-       if (!pDevice->bZoneRegExist)
-               pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
+       if (!priv->bZoneRegExist)
+               priv->byZoneType = priv->abyEEPROM[EEP_OFS_ZONETYPE];
 
-       pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
+       pr_debug("priv->byZoneType = %x\n", priv->byZoneType);
 
        /* Init RF module */
-       RFbInit(pDevice);
+       RFbInit(priv);
 
        /* Get Desire Power Value */
-       pDevice->byCurPwr = 0xFF;
-       pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
-       pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
+       priv->byCurPwr = 0xFF;
+       priv->byCCKPwr = SROMbyReadEmbedded(priv->PortOffset, EEP_OFS_PWR_CCK);
+       priv->byOFDMPwrG = SROMbyReadEmbedded(priv->PortOffset, EEP_OFS_PWR_OFDMG);
 
        /* Load power Table */
        for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
-               pDevice->abyCCKPwrTbl[ii + 1] =
-                       SROMbyReadEmbedded(pDevice->PortOffset,
+               priv->abyCCKPwrTbl[ii + 1] =
+                       SROMbyReadEmbedded(priv->PortOffset,
                                           (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
-               if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
-                       pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
+               if (priv->abyCCKPwrTbl[ii + 1] == 0)
+                       priv->abyCCKPwrTbl[ii+1] = priv->byCCKPwr;
 
-               pDevice->abyOFDMPwrTbl[ii + 1] =
-                       SROMbyReadEmbedded(pDevice->PortOffset,
+               priv->abyOFDMPwrTbl[ii + 1] =
+                       SROMbyReadEmbedded(priv->PortOffset,
                                           (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
-               if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
-                       pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
+               if (priv->abyOFDMPwrTbl[ii + 1] == 0)
+                       priv->abyOFDMPwrTbl[ii + 1] = priv->byOFDMPwrG;
 
-               pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
-               pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
+               priv->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
+               priv->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
        }
 
        /* recover 12,13 ,14channel for EUROPE by 11 channel */
        for (ii = 11; ii < 14; ii++) {
-               pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
-               pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
+               priv->abyCCKPwrTbl[ii] = priv->abyCCKPwrTbl[10];
+               priv->abyOFDMPwrTbl[ii] = priv->abyOFDMPwrTbl[10];
        }
 
        /* Load OFDM A Power Table */
        for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
-               pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
-                       SROMbyReadEmbedded(pDevice->PortOffset,
+               priv->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
+                       SROMbyReadEmbedded(priv->PortOffset,
                                           (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
 
-               pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
-                       SROMbyReadEmbedded(pDevice->PortOffset,
+               priv->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
+                       SROMbyReadEmbedded(priv->PortOffset,
                                           (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
        }
 
-       if (pDevice->byLocalID > REV_ID_VT3253_B1) {
-               MACvSelectPage1(pDevice->PortOffset);
+       if (priv->byLocalID > REV_ID_VT3253_B1) {
+               MACvSelectPage1(priv->PortOffset);
 
-               VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
+               VNSvOutPortB(priv->PortOffset + MAC_REG_MSRCTL + 1,
                             (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
 
-               MACvSelectPage0(pDevice->PortOffset);
+               MACvSelectPage0(priv->PortOffset);
        }
 
        /* use relative tx timeout and 802.11i D4 */
-       MACvWordRegBitsOn(pDevice->PortOffset,
+       MACvWordRegBitsOn(priv->PortOffset,
                          MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
 
        /* set performance parameter by registry */
-       MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
-       MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
+       MACvSetShortRetryLimit(priv->PortOffset, priv->byShortRetryLimit);
+       MACvSetLongRetryLimit(priv->PortOffset, priv->byLongRetryLimit);
 
        /* reset TSF counter */
-       VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
+       VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
        /* enable TSF counter */
-       VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
+       VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
 
        /* initialize BBP registers */
-       BBbVT3253Init(pDevice);
+       BBbVT3253Init(priv);
 
-       if (pDevice->bUpdateBBVGA) {
-               pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
-               pDevice->byBBVGANew = pDevice->byBBVGACurrent;
-               BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
+       if (priv->bUpdateBBVGA) {
+               priv->byBBVGACurrent = priv->abyBBVGA[0];
+               priv->byBBVGANew = priv->byBBVGACurrent;
+               BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
        }
 
-       BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
-       BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
+       BBvSetRxAntennaMode(priv, priv->byRxAntennaMode);
+       BBvSetTxAntennaMode(priv, priv->byTxAntennaMode);
 
        /* Set BB and packet type at the same time. */
        /* Set Short Slot Time, xIFS, and RSPINF. */
-       pDevice->wCurrentRate = RATE_54M;
+       priv->wCurrentRate = RATE_54M;
 
-       pDevice->bRadioOff = false;
+       priv->bRadioOff = false;
 
-       pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
+       priv->byRadioCtl = SROMbyReadEmbedded(priv->PortOffset,
                                                 EEP_OFS_RADIOCTL);
-       pDevice->bHWRadioOff = false;
+       priv->bHWRadioOff = false;
 
-       if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
+       if (priv->byRadioCtl & EEP_RADIOCTL_ENABLE) {
                /* Get GPIO */
-               MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
+               MACvGPIOIn(priv->PortOffset, &priv->byGPIO);
 
-               if (((pDevice->byGPIO & GPIO0_DATA) &&
-                    !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
-                    (!(pDevice->byGPIO & GPIO0_DATA) &&
-                    (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
-                       pDevice->bHWRadioOff = true;
+               if (((priv->byGPIO & GPIO0_DATA) &&
+                    !(priv->byRadioCtl & EEP_RADIOCTL_INV)) ||
+                    (!(priv->byGPIO & GPIO0_DATA) &&
+                    (priv->byRadioCtl & EEP_RADIOCTL_INV)))
+                       priv->bHWRadioOff = true;
        }
 
-       if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
-               CARDbRadioPowerOff(pDevice);
+       if (priv->bHWRadioOff || priv->bRadioControlOff)
+               CARDbRadioPowerOff(priv);
 
        /* get Permanent network address */
-       SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
-       pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
+       SROMvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
+       pr_debug("Network address = %pM\n", priv->abyCurrentNetAddr);
 
        /* reset Tx pointer */
-       CARDvSafeResetRx(pDevice);
+       CARDvSafeResetRx(priv);
        /* reset Rx pointer */
-       CARDvSafeResetTx(pDevice);
+       CARDvSafeResetTx(priv);
 
-       if (pDevice->byLocalID <= REV_ID_VT3253_A1)
-               MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
+       if (priv->byLocalID <= REV_ID_VT3253_A1)
+               MACvRegBitsOn(priv->PortOffset, MAC_REG_RCR, RCR_WPAERR);
 
        /* Turn On Rx DMA */
-       MACvReceive0(pDevice->PortOffset);
-       MACvReceive1(pDevice->PortOffset);
+       MACvReceive0(priv->PortOffset);
+       MACvReceive1(priv->PortOffset);
 
        /* start the adapter */
-       MACvStart(pDevice->PortOffset);
-}
-
-static void device_print_info(struct vnt_private *pDevice)
-{
-       dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
-
-       dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
-                pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
-                (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
+       MACvStart(priv->PortOffset);
 }
 
-static void vt6655_init_info(struct pci_dev *pcid,
-                            struct vnt_private **ppDevice,
-                            PCHIP_INFO pChip_info)
+static void device_print_info(struct vnt_private *priv)
 {
-       memset(*ppDevice, 0, sizeof(**ppDevice));
-
-       (*ppDevice)->pcid = pcid;
-       (*ppDevice)->chip_id = pChip_info->chip_id;
-       (*ppDevice)->io_size = pChip_info->io_size;
-       (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
-       (*ppDevice)->multicast_limit = 32;
-
-       spin_lock_init(&((*ppDevice)->lock));
-}
-
-static bool device_get_pci_info(struct vnt_private *pDevice,
-                               struct pci_dev *pcid)
-{
-       u16 pci_cmd;
-       u8  b;
-       unsigned int cis_addr;
-
-       pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
-       pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
-       pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
-       pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
-
-       pci_set_master(pcid);
-
-       pDevice->memaddr = pci_resource_start(pcid, 0);
-       pDevice->ioaddr = pci_resource_start(pcid, 1);
-
-       cis_addr = pci_resource_start(pcid, 2);
-
-       pDevice->pcid = pcid;
-
-       pci_read_config_byte(pcid, PCI_COMMAND, &b);
-       pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
-
-       return true;
+       dev_info(&priv->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
+                priv->abyCurrentNetAddr, (unsigned long)priv->ioaddr,
+                (unsigned long)priv->PortOffset, priv->pcid->irq);
 }
 
-static void device_free_info(struct vnt_private *pDevice)
+static void device_free_info(struct vnt_private *priv)
 {
-       if (!pDevice)
+       if (!priv)
                return;
 
-       if (pDevice->mac_hw)
-               ieee80211_unregister_hw(pDevice->hw);
+       if (priv->mac_hw)
+               ieee80211_unregister_hw(priv->hw);
 
-       if (pDevice->PortOffset)
-               iounmap(pDevice->PortOffset);
+       if (priv->PortOffset)
+               iounmap(priv->PortOffset);
 
-       if (pDevice->pcid)
-               pci_release_regions(pDevice->pcid);
+       if (priv->pcid)
+               pci_release_regions(priv->pcid);
 
-       if (pDevice->hw)
-               ieee80211_free_hw(pDevice->hw);
+       if (priv->hw)
+               ieee80211_free_hw(priv->hw);
 }
 
-static bool device_init_rings(struct vnt_private *pDevice)
+static bool device_init_rings(struct vnt_private *priv)
 {
        void *vir_pool;
 
        /*allocate all RD/TD rings a single pool*/
-       vir_pool = dma_zalloc_coherent(&pDevice->pcid->dev,
-                                        pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
-                                        pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
-                                        pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
-                                        pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc),
-                                        &pDevice->pool_dma, GFP_ATOMIC);
+       vir_pool = dma_zalloc_coherent(&priv->pcid->dev,
+                                      priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc) +
+                                      priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc) +
+                                      priv->opts.tx_descs[0] * sizeof(struct vnt_tx_desc) +
+                                      priv->opts.tx_descs[1] * sizeof(struct vnt_tx_desc),
+                                      &priv->pool_dma, GFP_ATOMIC);
        if (vir_pool == NULL) {
-               dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
+               dev_err(&priv->pcid->dev, "allocate desc dma memory failed\n");
                return false;
        }
 
-       pDevice->aRD0Ring = vir_pool;
-       pDevice->aRD1Ring = vir_pool +
-               pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
-
-       pDevice->rd0_pool_dma = pDevice->pool_dma;
-       pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
-               pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
-
-       pDevice->tx0_bufs = dma_zalloc_coherent(&pDevice->pcid->dev,
-                                                 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
-                                                 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
-                                                 CB_BEACON_BUF_SIZE +
-                                                 CB_MAX_BUF_SIZE,
-                                                 &pDevice->tx_bufs_dma0,
-                                                 GFP_ATOMIC);
-       if (pDevice->tx0_bufs == NULL) {
-               dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
-
-               dma_free_coherent(&pDevice->pcid->dev,
-                                   pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
-                                   pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
-                                   pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
-                                   pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc),
-                                   vir_pool, pDevice->pool_dma
-                       );
+       priv->aRD0Ring = vir_pool;
+       priv->aRD1Ring = vir_pool +
+               priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc);
+
+       priv->rd0_pool_dma = priv->pool_dma;
+       priv->rd1_pool_dma = priv->rd0_pool_dma +
+               priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc);
+
+       priv->tx0_bufs = dma_zalloc_coherent(&priv->pcid->dev,
+                                            priv->opts.tx_descs[0] * PKT_BUF_SZ +
+                                            priv->opts.tx_descs[1] * PKT_BUF_SZ +
+                                            CB_BEACON_BUF_SIZE +
+                                            CB_MAX_BUF_SIZE,
+                                            &priv->tx_bufs_dma0,
+                                            GFP_ATOMIC);
+       if (priv->tx0_bufs == NULL) {
+               dev_err(&priv->pcid->dev, "allocate buf dma memory failed\n");
+
+               dma_free_coherent(&priv->pcid->dev,
+                                 priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc) +
+                                 priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc) +
+                                 priv->opts.tx_descs[0] * sizeof(struct vnt_tx_desc) +
+                                 priv->opts.tx_descs[1] * sizeof(struct vnt_tx_desc),
+                                 vir_pool, priv->pool_dma);
                return false;
        }
 
-       pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
-               pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
+       priv->td0_pool_dma = priv->rd1_pool_dma +
+               priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc);
 
-       pDevice->td1_pool_dma = pDevice->td0_pool_dma +
-               pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc);
+       priv->td1_pool_dma = priv->td0_pool_dma +
+               priv->opts.tx_descs[0] * sizeof(struct vnt_tx_desc);
 
        /* vir_pool: pvoid type */
-       pDevice->apTD0Rings = vir_pool
-               + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
-               + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
+       priv->apTD0Rings = vir_pool
+               + priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc)
+               + priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc);
 
-       pDevice->apTD1Rings = vir_pool
-               + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
-               + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
-               + pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc);
+       priv->apTD1Rings = vir_pool
+               + priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc)
+               + priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc)
+               + priv->opts.tx_descs[0] * sizeof(struct vnt_tx_desc);
 
-       pDevice->tx1_bufs = pDevice->tx0_bufs +
-               pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
+       priv->tx1_bufs = priv->tx0_bufs +
+               priv->opts.tx_descs[0] * PKT_BUF_SZ;
 
-       pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
-               pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
+       priv->tx_beacon_bufs = priv->tx1_bufs +
+               priv->opts.tx_descs[1] * PKT_BUF_SZ;
 
-       pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
+       priv->pbyTmpBuff = priv->tx_beacon_bufs +
                CB_BEACON_BUF_SIZE;
 
-       pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
-               pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
+       priv->tx_bufs_dma1 = priv->tx_bufs_dma0 +
+               priv->opts.tx_descs[0] * PKT_BUF_SZ;
 
-       pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
-               pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
+       priv->tx_beacon_dma = priv->tx_bufs_dma1 +
+               priv->opts.tx_descs[1] * PKT_BUF_SZ;
 
        return true;
 }
 
-static void device_free_rings(struct vnt_private *pDevice)
+static void device_free_rings(struct vnt_private *priv)
 {
-       dma_free_coherent(&pDevice->pcid->dev,
-                           pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
-                           pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
-                           pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
-                           pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc)
-                           ,
-                           pDevice->aRD0Ring, pDevice->pool_dma
-               );
-
-       if (pDevice->tx0_bufs)
-               dma_free_coherent(&pDevice->pcid->dev,
-                                   pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
-                                   pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
-                                   CB_BEACON_BUF_SIZE +
-                                   CB_MAX_BUF_SIZE,
-                                   pDevice->tx0_bufs, pDevice->tx_bufs_dma0
-                       );
+       dma_free_coherent(&priv->pcid->dev,
+                         priv->opts.rx_descs0 * sizeof(struct vnt_rx_desc) +
+                         priv->opts.rx_descs1 * sizeof(struct vnt_rx_desc) +
+                         priv->opts.tx_descs[0] * sizeof(struct vnt_tx_desc) +
+                         priv->opts.tx_descs[1] * sizeof(struct vnt_tx_desc),
+                         priv->aRD0Ring, priv->pool_dma);
+
+       if (priv->tx0_bufs)
+               dma_free_coherent(&priv->pcid->dev,
+                                 priv->opts.tx_descs[0] * PKT_BUF_SZ +
+                                 priv->opts.tx_descs[1] * PKT_BUF_SZ +
+                                 CB_BEACON_BUF_SIZE +
+                                 CB_MAX_BUF_SIZE,
+                                 priv->tx0_bufs, priv->tx_bufs_dma0);
 }
 
-static void device_init_rd0_ring(struct vnt_private *pDevice)
+static void device_init_rd0_ring(struct vnt_private *priv)
 {
        int i;
-       dma_addr_t      curr = pDevice->rd0_pool_dma;
-       PSRxDesc        pDesc;
+       dma_addr_t      curr = priv->rd0_pool_dma;
+       struct vnt_rx_desc *desc;
 
        /* Init the RD0 ring entries */
-       for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
-               pDesc = &(pDevice->aRD0Ring[i]);
-               pDesc->pRDInfo = alloc_rd_info();
+       for (i = 0; i < priv->opts.rx_descs0;
+            i ++, curr += sizeof(struct vnt_rx_desc)) {
+               desc = &priv->aRD0Ring[i];
+               desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_ATOMIC);
 
-               if (!device_alloc_rx_buf(pDevice, pDesc))
-                       dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
+               if (!device_alloc_rx_buf(priv, desc))
+                       dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
 
-               pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
-               pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
+               desc->next = &(priv->aRD0Ring[(i+1) % priv->opts.rx_descs0]);
+               desc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_rx_desc));
        }
 
        if (i > 0)
-               pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
-       pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
+               priv->aRD0Ring[i-1].next_desc = cpu_to_le32(priv->rd0_pool_dma);
+       priv->pCurrRD[0] = &priv->aRD0Ring[0];
 }
 
-static void device_init_rd1_ring(struct vnt_private *pDevice)
+static void device_init_rd1_ring(struct vnt_private *priv)
 {
        int i;
-       dma_addr_t      curr = pDevice->rd1_pool_dma;
-       PSRxDesc        pDesc;
+       dma_addr_t      curr = priv->rd1_pool_dma;
+       struct vnt_rx_desc *desc;
 
        /* Init the RD1 ring entries */
-       for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
-               pDesc = &(pDevice->aRD1Ring[i]);
-               pDesc->pRDInfo = alloc_rd_info();
+       for (i = 0; i < priv->opts.rx_descs1;
+            i ++, curr += sizeof(struct vnt_rx_desc)) {
+               desc = &priv->aRD1Ring[i];
+               desc->rd_info = kzalloc(sizeof(*desc->rd_info), GFP_ATOMIC);
 
-               if (!device_alloc_rx_buf(pDevice, pDesc))
-                       dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
+               if (!device_alloc_rx_buf(priv, desc))
+                       dev_err(&priv->pcid->dev, "can not alloc rx bufs\n");
 
-               pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
-               pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
+               desc->next = &(priv->aRD1Ring[(i+1) % priv->opts.rx_descs1]);
+               desc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_rx_desc));
        }
 
        if (i > 0)
-               pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
-       pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
+               priv->aRD1Ring[i-1].next_desc = cpu_to_le32(priv->rd1_pool_dma);
+       priv->pCurrRD[1] = &priv->aRD1Ring[0];
 }
 
-static void device_free_rd0_ring(struct vnt_private *pDevice)
+static void device_free_rd0_ring(struct vnt_private *priv)
 {
        int i;
 
-       for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
-               PSRxDesc        pDesc = &(pDevice->aRD0Ring[i]);
-               PDEVICE_RD_INFO  pRDInfo = pDesc->pRDInfo;
+       for (i = 0; i < priv->opts.rx_descs0; i++) {
+               struct vnt_rx_desc *desc = &(priv->aRD0Ring[i]);
+               struct vnt_rd_info *rd_info = desc->rd_info;
 
-               dma_unmap_single(&pDevice->pcid->dev, pRDInfo->skb_dma,
-                                pDevice->rx_buf_sz, DMA_FROM_DEVICE);
+               dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
+                                priv->rx_buf_sz, DMA_FROM_DEVICE);
 
-               dev_kfree_skb(pRDInfo->skb);
+               dev_kfree_skb(rd_info->skb);
 
-               kfree(pDesc->pRDInfo);
+               kfree(desc->rd_info);
        }
 }
 
-static void device_free_rd1_ring(struct vnt_private *pDevice)
+static void device_free_rd1_ring(struct vnt_private *priv)
 {
        int i;
 
-       for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
-               PSRxDesc        pDesc = &(pDevice->aRD1Ring[i]);
-               PDEVICE_RD_INFO  pRDInfo = pDesc->pRDInfo;
+       for (i = 0; i < priv->opts.rx_descs1; i++) {
+               struct vnt_rx_desc *desc = &priv->aRD1Ring[i];
+               struct vnt_rd_info *rd_info = desc->rd_info;
 
-               dma_unmap_single(&pDevice->pcid->dev, pRDInfo->skb_dma,
-                                pDevice->rx_buf_sz, DMA_FROM_DEVICE);
+               dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
+                                priv->rx_buf_sz, DMA_FROM_DEVICE);
 
-               dev_kfree_skb(pRDInfo->skb);
+               dev_kfree_skb(rd_info->skb);
 
-               kfree(pDesc->pRDInfo);
+               kfree(desc->rd_info);
        }
 }
 
-static void device_init_td0_ring(struct vnt_private *pDevice)
+static void device_init_td0_ring(struct vnt_private *priv)
 {
        int i;
        dma_addr_t  curr;
-       struct vnt_tx_desc *pDesc;
+       struct vnt_tx_desc *desc;
 
-       curr = pDevice->td0_pool_dma;
-       for (i = 0; i < pDevice->sOpts.nTxDescs[0];
+       curr = priv->td0_pool_dma;
+       for (i = 0; i < priv->opts.tx_descs[0];
             i++, curr += sizeof(struct vnt_tx_desc)) {
-               pDesc = &(pDevice->apTD0Rings[i]);
-               pDesc->td_info = alloc_td_info();
+               desc = &priv->apTD0Rings[i];
+               desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_ATOMIC);
 
-               if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
-                       pDesc->td_info->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
-                       pDesc->td_info->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
-               }
-               pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
-               pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
+               desc->td_info->buf = priv->tx0_bufs + i * PKT_BUF_SZ;
+               desc->td_info->buf_dma = priv->tx_bufs_dma0 + i * PKT_BUF_SZ;
+
+               desc->next = &(priv->apTD0Rings[(i+1) % priv->opts.tx_descs[0]]);
+               desc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
        }
 
        if (i > 0)
-               pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
-       pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
+               priv->apTD0Rings[i-1].next_desc = cpu_to_le32(priv->td0_pool_dma);
+       priv->apTailTD[0] = priv->apCurrTD[0] = &priv->apTD0Rings[0];
 }
 
-static void device_init_td1_ring(struct vnt_private *pDevice)
+static void device_init_td1_ring(struct vnt_private *priv)
 {
        int i;
        dma_addr_t  curr;
-       struct vnt_tx_desc *pDesc;
+       struct vnt_tx_desc *desc;
 
        /* Init the TD ring entries */
-       curr = pDevice->td1_pool_dma;
-       for (i = 0; i < pDevice->sOpts.nTxDescs[1];
+       curr = priv->td1_pool_dma;
+       for (i = 0; i < priv->opts.tx_descs[1];
             i++, curr += sizeof(struct vnt_tx_desc)) {
-               pDesc = &(pDevice->apTD1Rings[i]);
-               pDesc->td_info = alloc_td_info();
+               desc = &priv->apTD1Rings[i];
+               desc->td_info = kzalloc(sizeof(*desc->td_info), GFP_ATOMIC);
 
-               if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
-                       pDesc->td_info->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
-                       pDesc->td_info->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
-               }
-               pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
-               pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
+               desc->td_info->buf = priv->tx1_bufs + i * PKT_BUF_SZ;
+               desc->td_info->buf_dma = priv->tx_bufs_dma1 + i * PKT_BUF_SZ;
+
+               desc->next = &(priv->apTD1Rings[(i + 1) % priv->opts.tx_descs[1]]);
+               desc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
        }
 
        if (i > 0)
-               pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
-       pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
+               priv->apTD1Rings[i-1].next_desc = cpu_to_le32(priv->td1_pool_dma);
+       priv->apTailTD[1] = priv->apCurrTD[1] = &priv->apTD1Rings[0];
 }
 
-static void device_free_td0_ring(struct vnt_private *pDevice)
+static void device_free_td0_ring(struct vnt_private *priv)
 {
        int i;
 
-       for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
-               struct vnt_tx_desc *pDesc = &pDevice->apTD0Rings[i];
-               struct vnt_td_info *pTDInfo = pDesc->td_info;
+       for (i = 0; i < priv->opts.tx_descs[0]; i++) {
+               struct vnt_tx_desc *desc = &priv->apTD0Rings[i];
+               struct vnt_td_info *td_info = desc->td_info;
 
-               dev_kfree_skb(pTDInfo->skb);
-               kfree(pDesc->td_info);
+               dev_kfree_skb(td_info->skb);
+               kfree(desc->td_info);
        }
 }
 
-static void device_free_td1_ring(struct vnt_private *pDevice)
+static void device_free_td1_ring(struct vnt_private *priv)
 {
        int i;
 
-       for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
-               struct vnt_tx_desc *pDesc = &pDevice->apTD1Rings[i];
-               struct vnt_td_info *pTDInfo = pDesc->td_info;
+       for (i = 0; i < priv->opts.tx_descs[1]; i++) {
+               struct vnt_tx_desc *desc = &priv->apTD1Rings[i];
+               struct vnt_td_info *td_info = desc->td_info;
 
-               dev_kfree_skb(pTDInfo->skb);
-               kfree(pDesc->td_info);
+               dev_kfree_skb(td_info->skb);
+               kfree(desc->td_info);
        }
 }
 
 /*-----------------------------------------------------------------*/
 
-static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
+static int device_rx_srv(struct vnt_private *priv, unsigned int idx)
 {
-       PSRxDesc    pRD;
+       struct vnt_rx_desc *rd;
        int works = 0;
 
-       for (pRD = pDevice->pCurrRD[uIdx];
-            pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
-            pRD = pRD->next) {
+       for (rd = priv->pCurrRD[idx];
+            rd->rd0.owner == OWNED_BY_HOST;
+            rd = rd->next) {
                if (works++ > 15)
                        break;
 
-               if (!pRD->pRDInfo->skb)
+               if (!rd->rd_info->skb)
                        break;
 
-               if (vnt_receive_frame(pDevice, pRD)) {
-                       if (!device_alloc_rx_buf(pDevice, pRD)) {
-                               dev_err(&pDevice->pcid->dev,
+               if (vnt_receive_frame(priv, rd)) {
+                       if (!device_alloc_rx_buf(priv, rd)) {
+                               dev_err(&priv->pcid->dev,
                                        "can not allocate rx buf\n");
                                break;
                        }
                }
-               pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
+               rd->rd0.owner = OWNED_BY_NIC;
        }
 
-       pDevice->pCurrRD[uIdx] = pRD;
+       priv->pCurrRD[idx] = rd;
 
        return works;
 }
 
-static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
+static bool device_alloc_rx_buf(struct vnt_private *priv,
+                               struct vnt_rx_desc *rd)
 {
-       PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
+       struct vnt_rd_info *rd_info = rd->rd_info;
 
-       pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
-       if (pRDInfo->skb == NULL)
+       rd_info->skb = dev_alloc_skb((int)priv->rx_buf_sz);
+       if (rd_info->skb == NULL)
                return false;
 
-       pRDInfo->skb_dma =
-               dma_map_single(&pDevice->pcid->dev,
-                              skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
-                              pDevice->rx_buf_sz, DMA_FROM_DEVICE);
+       rd_info->skb_dma =
+               dma_map_single(&priv->pcid->dev,
+                              skb_put(rd_info->skb, skb_tailroom(rd_info->skb)),
+                              priv->rx_buf_sz, DMA_FROM_DEVICE);
 
-       *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
+       *((unsigned int *)&rd->rd0) = 0; /* FIX cast */
 
-       pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
-       pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
-       pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
-       pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
+       rd->rd0.res_count = cpu_to_le16(priv->rx_buf_sz);
+       rd->rd0.owner = OWNED_BY_NIC;
+       rd->rd1.req_count = cpu_to_le16(priv->rx_buf_sz);
+       rd->buff_addr = cpu_to_le32(rd_info->skb_dma);
 
        return true;
 }
@@ -900,77 +829,77 @@ static int vnt_int_report_rate(struct vnt_private *priv,
        return 0;
 }
 
-static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
+static int device_tx_srv(struct vnt_private *priv, unsigned int idx)
 {
-       struct vnt_tx_desc *pTD;
+       struct vnt_tx_desc *desc;
        int                      works = 0;
        unsigned char byTsr0;
        unsigned char byTsr1;
 
-       for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
-               if (pTD->td0.owner == OWNED_BY_NIC)
+       for (desc = priv->apTailTD[idx]; priv->iTDUsed[idx] > 0; desc = desc->next) {
+               if (desc->td0.owner == OWNED_BY_NIC)
                        break;
                if (works++ > 15)
                        break;
 
-               byTsr0 = pTD->td0.tsr0;
-               byTsr1 = pTD->td0.tsr1;
+               byTsr0 = desc->td0.tsr0;
+               byTsr1 = desc->td0.tsr1;
 
                /* Only the status of first TD in the chain is correct */
-               if (pTD->td1.tcr & TCR_STP) {
-                       if ((pTD->td_info->flags & TD_FLAGS_NETIF_SKB) != 0) {
+               if (desc->td1.tcr & TCR_STP) {
+                       if ((desc->td_info->flags & TD_FLAGS_NETIF_SKB) != 0) {
                                if (!(byTsr1 & TSR1_TERR)) {
                                        if (byTsr0 != 0) {
                                                pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
-                                                        (int)uIdx, byTsr1,
+                                                        (int)idx, byTsr1,
                                                         byTsr0);
                                        }
                                } else {
                                        pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
-                                                (int)uIdx, byTsr1, byTsr0);
+                                                (int)idx, byTsr1, byTsr0);
                                }
                        }
 
                        if (byTsr1 & TSR1_TERR) {
-                               if ((pTD->td_info->flags & TD_FLAGS_PRIV_SKB) != 0) {
+                               if ((desc->td_info->flags & TD_FLAGS_PRIV_SKB) != 0) {
                                        pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
-                                                (int)uIdx, byTsr1, byTsr0);
+                                                (int)idx, byTsr1, byTsr0);
                                }
                        }
 
-                       vnt_int_report_rate(pDevice, pTD->td_info, byTsr0, byTsr1);
+                       vnt_int_report_rate(priv, desc->td_info, byTsr0, byTsr1);
 
-                       device_free_tx_buf(pDevice, pTD);
-                       pDevice->iTDUsed[uIdx]--;
+                       device_free_tx_buf(priv, desc);
+                       priv->iTDUsed[idx]--;
                }
        }
 
-       pDevice->apTailTD[uIdx] = pTD;
+       priv->apTailTD[idx] = desc;
 
        return works;
 }
 
-static void device_error(struct vnt_private *pDevice, unsigned short status)
+static void device_error(struct vnt_private *priv, unsigned short status)
 {
        if (status & ISR_FETALERR) {
-               dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
+               dev_err(&priv->pcid->dev, "Hardware fatal error\n");
 
-               MACbShutdown(pDevice->PortOffset);
+               MACbShutdown(priv->PortOffset);
                return;
        }
 }
 
-static void device_free_tx_buf(struct vnt_private *pDevice,
-                              struct vnt_tx_desc *pDesc)
+static void device_free_tx_buf(struct vnt_private *priv,
+                              struct vnt_tx_desc *desc)
 {
-       struct vnt_td_info *pTDInfo = pDesc->td_info;
-       struct sk_buff *skb = pTDInfo->skb;
+       struct vnt_td_info *td_info = desc->td_info;
+       struct sk_buff *skb = td_info->skb;
 
        if (skb)
-               ieee80211_tx_status_irqsafe(pDevice->hw, skb);
+               ieee80211_tx_status_irqsafe(priv->hw, skb);
 
-       pTDInfo->skb = NULL;
-       pTDInfo->flags = 0;
+       td_info->skb = NULL;
+       td_info->flags = 0;
 }
 
 static void vnt_check_bb_vga(struct vnt_private *priv)
@@ -1128,7 +1057,7 @@ static void vnt_interrupt_process(struct vnt_private *priv)
                MACvReceive0(priv->PortOffset);
                MACvReceive1(priv->PortOffset);
 
-               if (max_count > priv->sOpts.int_works)
+               if (max_count > priv->opts.int_works)
                        break;
        }
 
@@ -1172,6 +1101,7 @@ static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
 
        if (AVAIL_TD(priv, dma_idx) < 1) {
                spin_unlock_irqrestore(&priv->lock, flags);
+               ieee80211_stop_queues(priv->hw);
                return -ENOMEM;
        }
 
@@ -1223,13 +1153,8 @@ static void vnt_tx_80211(struct ieee80211_hw *hw,
 {
        struct vnt_private *priv = hw->priv;
 
-       ieee80211_stop_queues(hw);
-
-       if (vnt_tx_packet(priv, skb)) {
+       if (vnt_tx_packet(priv, skb))
                ieee80211_free_txskb(hw, skb);
-
-               ieee80211_wake_queues(hw);
-       }
 }
 
 static int vnt_start(struct ieee80211_hw *hw)
@@ -1649,7 +1574,6 @@ static int vnt_init(struct vnt_private *priv)
 static int
 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
 {
-       PCHIP_INFO  pChip_info = (PCHIP_INFO)ent->driver_data;
        struct vnt_private *priv;
        struct ieee80211_hw *hw;
        struct wiphy *wiphy;
@@ -1668,8 +1592,9 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
        }
 
        priv = hw->priv;
+       priv->pcid = pcid;
 
-       vt6655_init_info(pcid, &priv, pChip_info);
+       spin_lock_init(&priv->lock);
 
        priv->hw = hw;
 
@@ -1683,60 +1608,12 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
        dev_dbg(&pcid->dev,
                "Before get pci_info memaddr is %x\n", priv->memaddr);
 
-       if (!device_get_pci_info(priv, pcid)) {
-               dev_err(&pcid->dev, ": Failed to find PCI device.\n");
-               device_free_info(priv);
-               return -ENODEV;
-       }
-
-#ifdef DEBUG
-       dev_dbg(&pcid->dev,
-               "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
-               priv->memaddr, priv->ioaddr, priv->io_size);
-       {
-               int i;
-               u32 bar, len;
-               u32 address[] = {
-                       PCI_BASE_ADDRESS_0,
-                       PCI_BASE_ADDRESS_1,
-                       PCI_BASE_ADDRESS_2,
-                       PCI_BASE_ADDRESS_3,
-                       PCI_BASE_ADDRESS_4,
-                       PCI_BASE_ADDRESS_5,
-                       0};
-               for (i = 0; address[i]; i++) {
-                       pci_read_config_dword(pcid, address[i], &bar);
-
-                       dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
-
-                       if (!bar) {
-                               dev_dbg(&pcid->dev,
-                                       "bar %d not implemented\n", i);
-                               continue;
-                       }
-
-                       if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
-                               /* This is IO */
-
-                               len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
-                               len = len & ~(len - 1);
-
-                               dev_dbg(&pcid->dev,
-                                       "IO space:  len in IO %x, BAR %d\n",
-                                       len, i);
-                       } else {
-                               len = bar & 0xfffffff0;
-                               len = ~len + 1;
-
-                               dev_dbg(&pcid->dev,
-                                       "len in MEM %x, BAR %d\n", len, i);
-                       }
-               }
-       }
-#endif
+       pci_set_master(pcid);
 
+       priv->memaddr = pci_resource_start(pcid, 0);
+       priv->ioaddr = pci_resource_start(pcid, 1);
        priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
-                                  priv->io_size);
+                                  256);
        if (!priv->PortOffset) {
                dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
                device_free_info(priv);
@@ -1776,11 +1653,6 @@ vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
 
        device_get_options(priv);
        device_set_options(priv);
-       /* Mask out the options cannot be set to the chip */
-       priv->sOpts.flags &= pChip_info->flags;
-
-       /* Enable the chip specified capabilities */
-       priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
 
        wiphy = priv->hw->wiphy;
 
index e14eed160a191fd5405ea900ea720bcbbeda230e..700032e9c477e8c0584815f4cfc6bf8365d886ff 100644 (file)
@@ -132,9 +132,9 @@ static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb,
        return true;
 }
 
-bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd)
+bool vnt_receive_frame(struct vnt_private *priv, struct vnt_rx_desc *curr_rd)
 {
-       PDEVICE_RD_INFO rd_info = curr_rd->pRDInfo;
+       struct vnt_rd_info *rd_info = curr_rd->rd_info;
        struct sk_buff *skb;
        u16 frame_size;
 
@@ -143,8 +143,8 @@ bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd)
        dma_unmap_single(&priv->pcid->dev, rd_info->skb_dma,
                         priv->rx_buf_sz, DMA_FROM_DEVICE);
 
-       frame_size = le16_to_cpu(curr_rd->m_rd1RD1.wReqCount)
-                       - le16_to_cpu(curr_rd->m_rd0RD0.wResCount);
+       frame_size = le16_to_cpu(curr_rd->rd1.req_count)
+                       - le16_to_cpu(curr_rd->rd0.res_count);
 
        if ((frame_size > 2364) || (frame_size < 33)) {
                /* Frame Size error drop this packet.*/
index ad495719a2512c6d83e9bf58d3b18457ea6829d7..e80b30816968652b60865a1829e1bd9e7eb01fcb 100644 (file)
@@ -31,6 +31,6 @@
 
 #include "device.h"
 
-bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd);
+bool vnt_receive_frame(struct vnt_private *priv, struct vnt_rx_desc *curr_rd);
 
 #endif /* __RXTX_H__ */
index 3dfd333475c020718359f6fe832349ba9aeea70d..688c3be168d10bb14b5a09c7ca663e65f92a1513 100644 (file)
@@ -689,9 +689,8 @@ void MACvSetCurrAC0DescAddrEx(void __iomem *dwIoBase,
                if (!(byData & DMACTL_RUN))
                        break;
        }
-       if (ww == W_MAX_TIMEOUT) {
+       if (ww == W_MAX_TIMEOUT)
                pr_debug(" DBG_PORT80(0x26)\n");
-       }
        VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
        if (byOrgDMACtl & DMACTL_RUN)
                VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
index c537321444be1ba5dde589127b9e3450827af65b..4c22bb318c794727f905b015eeeb92ef4dd45084 100644 (file)
@@ -768,7 +768,7 @@ bool RFvWriteWakeProgSyn(struct vnt_private *priv, unsigned char byRFType,
  */
 bool RFbSetPower(
        struct vnt_private *priv,
-       unsigned int uRATE,
+       unsigned int rate,
        u16 uCH
 )
 {
@@ -782,7 +782,7 @@ bool RFbSetPower(
        if ((uCH < 1) || (uCH > CB_MAX_CHANNEL))
                return false;
 
-       switch (uRATE) {
+       switch (rate) {
        case RATE_1M:
        case RATE_2M:
        case RATE_5M:
@@ -818,7 +818,7 @@ bool RFbSetPower(
        if (priv->byCurPwr == byPwr)
                return true;
 
-       bResult = RFbRawSetPower(priv, byPwr, uRATE);
+       bResult = RFbRawSetPower(priv, byPwr, rate);
        if (bResult)
                priv->byCurPwr = byPwr;
 
@@ -842,7 +842,7 @@ bool RFbSetPower(
 bool RFbRawSetPower(
        struct vnt_private *priv,
        unsigned char byPwr,
-       unsigned int uRATE
+       unsigned int rate
 )
 {
        bool bResult = true;
@@ -854,7 +854,7 @@ bool RFbRawSetPower(
        switch (priv->byRFType) {
        case RF_AIROHA:
                bResult &= IFRFbWriteEmbedded(priv, dwAL2230PowerTable[byPwr]);
-               if (uRATE <= RATE_11M)
+               if (rate <= RATE_11M)
                        bResult &= IFRFbWriteEmbedded(priv, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
                else
                        bResult &= IFRFbWriteEmbedded(priv, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
@@ -863,7 +863,7 @@ bool RFbRawSetPower(
 
        case RF_AL2230S:
                bResult &= IFRFbWriteEmbedded(priv, dwAL2230PowerTable[byPwr]);
-               if (uRATE <= RATE_11M) {
+               if (rate <= RATE_11M) {
                        bResult &= IFRFbWriteEmbedded(priv, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
                        bResult &= IFRFbWriteEmbedded(priv, 0x00299B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
                } else {
index b5fc3eed06fb71e7b7dd8f294f4b1c8c392d67e1..e9c786995506cce2d8b05427f9714b32a1142735 100644 (file)
@@ -79,11 +79,11 @@ bool RFbInit(
        struct vnt_private *
 );
 bool RFvWriteWakeProgSyn(struct vnt_private *, unsigned char byRFType, u16);
-bool RFbSetPower(struct vnt_private *, unsigned int uRATE, u16);
+bool RFbSetPower(struct vnt_private *, unsigned int rate, u16);
 bool RFbRawSetPower(
        struct vnt_private *,
        unsigned char byPwr,
-       unsigned int uRATE
+       unsigned int rate
 );
 
 void
index 5875d655dd5545af326ab776ce5bc394f2580ea4..b668db6a45fbd98efd1aa8d6dba85d096086e61d 100644 (file)
@@ -78,7 +78,7 @@ static const unsigned short wFB_Opt0[2][5] = {
 };
 static const unsigned short wFB_Opt1[2][5] = {
        {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, /* fallback_rate0 */
-       {RATE_6M , RATE_6M,  RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
+       {RATE_6M RATE_6M,  RATE_12M, RATE_12M, RATE_18M}, /* fallback_rate1 */
 };
 
 #define RTSDUR_BB       0
@@ -566,7 +566,7 @@ s_uFillDataHead(
                        return buf->duration_a;
                } /* if (byFBOption == AUTO_FB_NONE) */
        } else if (byPktType == PK_TYPE_11A) {
-               if ((byFBOption != AUTO_FB_NONE)) {
+               if (byFBOption != AUTO_FB_NONE) {
                        /* Auto Fallback */
                        struct vnt_tx_datahead_a_fb *buf = pTxDataHead;
                        /* Get SignalField, ServiceField & Length */
@@ -1008,7 +1008,7 @@ s_vGenerateTxParameter(
                        buf->rrv_time = vnt_rxtx_rsvtime_le16(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK);
                }
        } else if (byPktType == PK_TYPE_11B) {
-               if ((pvRTS != NULL)) {/* RTS_need, non PCF mode */
+               if (pvRTS != NULL) {/* RTS_need, non PCF mode */
                        struct vnt_rrv_time_ab *buf = pvRrvTime;
 
                        buf->rts_rrv_time = s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate);
index 26b16772fc40b9690c7a54c15f1b2a18a07df8a0..e5be261f2e69cb11319282d46e4f567257ab6102 100644 (file)
@@ -527,7 +527,6 @@ void vnt_set_short_slot_time(struct vnt_private *priv)
 
 void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
 {
-
        vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data);
 
        /* patch for 3253B0 Baseband with Cardbus module */
@@ -811,7 +810,6 @@ void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning)
                        cr_206 = 0x38;
                }
                break;
-
        }
 
        if (ed_inx == priv->bb_pre_ed_index && !scanning)
index a215563de07db6587562011afcd09df548578b0a..927243ebcb5641df7978a22939e309d4382b03b4 100644 (file)
@@ -82,7 +82,7 @@ void vnt_set_channel(struct vnt_private *priv, u32 connection_channel)
                                        connection_channel, 0, 0, NULL);
 
        vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_CHANNEL,
-               (u8)(connection_channel|0x80));
+               (u8)(connection_channel | 0x80));
 }
 
 /*
@@ -285,7 +285,6 @@ void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type)
        vnt_get_phy_field(priv, 14,
                vnt_get_cck_rate(priv, RATE_11M), PK_TYPE_11B, &phy[3]);
 
-
        /*RSPINF_a_6*/
        vnt_calculate_ofdm_rate(RATE_6M, bb_type, &tx_rate[0], &rsv_time[0]);
 
@@ -473,7 +472,7 @@ int vnt_ofdm_min_rate(struct vnt_private *priv)
        int ii;
 
        for (ii = RATE_54M; ii >= RATE_6M; ii--) {
-               if ((priv->basic_rates) & ((u16)(1 << ii)))
+               if ((priv->basic_rates) & ((u16)BIT(ii)))
                        return true;
        }
 
@@ -508,7 +507,7 @@ u8 vnt_get_pkt_type(struct vnt_private *priv)
 u64 vnt_get_tsf_offset(u8 rx_rate, u64 tsf1, u64 tsf2)
 {
        u64 tsf_offset = 0;
-       u16 rx_bcn_offset = 0;
+       u16 rx_bcn_offset;
 
        rx_bcn_offset = cwRXBCNTSFOff[rx_rate % MAX_RATE];
 
index 635d931de409084b98666a34057f6babfd925009..dec36f296f3d07f6b0d7a8e07dd9a6a2f9167eb9 100644 (file)
@@ -389,6 +389,8 @@ struct vnt_private {
        u8 bb_pre_ed_rssi;
        u8 bb_pre_ed_index;
 
+       u16 wake_up_count;
+
        /* command timer */
        struct delayed_work run_command_work;
 
index 2ef70e4701f69af603c3c55ad3bb8e1f7a542e60..14b8ebc6508d68acbad02d0ca4b3af642e940f36 100644 (file)
@@ -149,10 +149,18 @@ void vnt_int_process_data(struct vnt_private *priv)
                                priv->op_mode == NL80211_IFTYPE_AP)
                        vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
 
-               if (int_data->isr0 & ISR_TBTT) {
-                       if (priv->hw->conf.flags & IEEE80211_CONF_PS)
+               if (int_data->isr0 & ISR_TBTT &&
+                   priv->hw->conf.flags & IEEE80211_CONF_PS) {
+                       if (!priv->wake_up_count)
+                               priv->wake_up_count =
+                                       priv->hw->conf.listen_interval;
+
+                       --priv->wake_up_count;
+
+                       /* Turn on wake up to listen next beacon */
+                       if (priv->wake_up_count == 1)
                                vnt_schedule_command(priv,
-                                                       WLAN_CMD_TBTT_WAKEUP);
+                                                    WLAN_CMD_TBTT_WAKEUP);
                }
                priv->current_tsf = le64_to_cpu(int_data->tsf);
 
index af572d71813531fa89453f5692ef834cb0bd856b..01e642db311e5cc4d977ab262c6c912dbe23351b 100644 (file)
@@ -507,13 +507,8 @@ static void vnt_tx_80211(struct ieee80211_hw *hw,
 {
        struct vnt_private *priv = hw->priv;
 
-       ieee80211_stop_queues(hw);
-
-       if (vnt_tx_packet(priv, skb)) {
+       if (vnt_tx_packet(priv, skb))
                ieee80211_free_txskb(hw, skb);
-
-               ieee80211_wake_queues(hw);
-       }
 }
 
 static int vnt_start(struct ieee80211_hw *hw)
@@ -757,6 +752,26 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
                        vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
                }
        }
+
+       if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
+           priv->op_mode != NL80211_IFTYPE_AP) {
+               if (conf->assoc && conf->beacon_rate) {
+                       vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
+                                           TFTCTL_TSFCNTREN);
+
+                       vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
+                                      conf->sync_tsf, priv->current_tsf);
+
+                       vnt_mac_set_beacon_interval(priv, conf->beacon_int);
+
+                       vnt_reset_next_tbtt(priv, conf->beacon_int);
+               } else {
+                       vnt_clear_current_tsf(priv);
+
+                       vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL,
+                                            TFTCTL_TSFCNTREN);
+               }
+       }
 }
 
 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
@@ -982,6 +997,7 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
        ieee80211_hw_set(priv->hw, SIGNAL_DBM);
        ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
        ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
+       ieee80211_hw_set(priv->hw, SUPPORTS_PS);
 
        priv->hw->max_signal = 100;
 
index 0ffbaed5d7744ccb119d9d3dfa4f12e5b0634ad3..13afce27951c965fb4861956796071941dfbd045 100644 (file)
@@ -59,10 +59,9 @@ void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
        /* set period of power up before TBTT */
        vnt_mac_write_word(priv, MAC_REG_PWBT, C_PWBT);
 
-       if (priv->op_mode != NL80211_IFTYPE_ADHOC) {
+       if (priv->op_mode != NL80211_IFTYPE_ADHOC)
                /* set AID */
                vnt_mac_write_word(priv, MAC_REG_AIDATIM, aid);
-       }
 
        /* Warren:06-18-2004,the sequence must follow
         * PSEN->AUTOSLEEP->GO2DOZE
@@ -85,11 +84,10 @@ void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval)
 
                /* first time set listen next beacon */
                vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
-       } else {
+       } else
 
                /* always listen beacon */
                vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_ALBCN);
-       }
 
        dev_dbg(&priv->usb->dev,  "PS:Power Saving Mode Enable...\n");
 }
@@ -109,7 +107,7 @@ void vnt_disable_power_saving(struct vnt_private *priv)
 
        /* disable power saving hw function */
        vnt_control_out(priv, MESSAGE_TYPE_DISABLE_PS, 0,
-                                               0, 0, NULL);
+                       0, 0, NULL);
 
        /* clear AutoSleep */
        vnt_mac_reg_bits_off(priv, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
@@ -134,7 +132,7 @@ int vnt_next_tbtt_wakeup(struct vnt_private *priv)
        struct ieee80211_conf *conf = &hw->conf;
        int wake_up = false;
 
-       if (conf->listen_interval == 1) {
+       if (conf->listen_interval > 1) {
                /* Turn on wake up to listen next beacon */
                vnt_mac_reg_bits_on(priv, MAC_REG_PSCTL, PSCTL_LNBCN);
                wake_up = true;
index da075f4852989840568e9cca434a975822dc8efd..efb54f53b4f9eddd496a987078055041f559a895 100644 (file)
@@ -101,9 +101,12 @@ static struct vnt_usb_send_context
                }
        }
 
-       if (ii == priv->num_tx_context)
+       if (ii == priv->num_tx_context) {
                dev_dbg(&priv->usb->dev, "%s No Free Tx Context\n", __func__);
 
+               ieee80211_stop_queues(priv->hw);
+       }
+
        return NULL;
 }
 
index a5912dde9b31e1bff79322f3238e4ba202247185..c975c3b870938eb582d022785e9a0bdb0144e7fc 100644 (file)
@@ -168,7 +168,6 @@ static void vnt_submit_rx_urb_complete(struct urb *urb)
 {
        struct vnt_rcb *rcb = urb->context;
        struct vnt_private *priv = rcb->priv;
-       unsigned long flags;
 
        switch (urb->status) {
        case 0:
@@ -184,8 +183,6 @@ static void vnt_submit_rx_urb_complete(struct urb *urb)
        }
 
        if (urb->actual_length) {
-               spin_lock_irqsave(&priv->lock, flags);
-
                if (vnt_rx_data(priv, rcb, urb->actual_length)) {
                        rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
                        if (!rcb->skb) {
@@ -193,7 +190,6 @@ static void vnt_submit_rx_urb_complete(struct urb *urb)
                                        "Failed to re-alloc rx skb\n");
 
                                rcb->in_use = false;
-                               spin_unlock_irqrestore(&priv->lock, flags);
                                return;
                        }
                } else {
@@ -203,8 +199,6 @@ static void vnt_submit_rx_urb_complete(struct urb *urb)
 
                urb->transfer_buffer = skb_put(rcb->skb,
                                                skb_tailroom(rcb->skb));
-
-               spin_unlock_irqrestore(&priv->lock, flags);
        }
 
        if (usb_submit_urb(urb, GFP_ATOMIC)) {
index 51bbf468fe45aa17679f7401bf1e02c4be0d1b52..ee51b4278088994f5cb50df7ed7a99dfcbef2f84 100644 (file)
@@ -1,15 +1,16 @@
-config WILC1000
-       tristate "WILC1000 support (WiFi only)"
-       depends on BROKEN
-       depends on !S390
+config WILC1000_DRIVER
+       bool "WILC1000 support (WiFi only)"
        depends on CFG80211 && WEXT_CORE && INET
-       depends on MMC || SPI
        ---help---
          This module only support IEEE 802.11n WiFi.
 
+if WILC1000_DRIVER
+
+config WILC1000
+       tristate
+
 choice
         prompt "Memory Allocation"
-        depends on WILC1000
         default WILC1000_PREALLOCATE_AT_LOADING_DRIVER
 
 config WILC1000_PREALLOCATE_AT_LOADING_DRIVER
@@ -30,12 +31,12 @@ endchoice
 
 choice
        prompt "Bus Type"
-       depends on WILC1000
        default WILC1000_SDIO
 
-       config WILC1000_SDIO
+config WILC1000_SDIO
        bool "SDIO support"
        depends on MMC
+       select WILC1000
        ---help---
          This module adds support for the SDIO interface of adapters using
          WILC1000 chipset. The Atmel WILC1000 SDIO is a full speed interface.
@@ -46,8 +47,9 @@ choice
          To use this interface, pin9 (SDIO_SPI_CFG) must be grounded. Select
          this if your platform is using the SDIO bus.
 
-       config WILC1000_SPI
+config WILC1000_SPI
        depends on SPI
+       select WILC1000
        bool "SPI support"
        ---help---
          This module adds support for the SPI interface of adapters using
@@ -61,7 +63,7 @@ endchoice
 
 config WILC1000_HW_OOB_INTR
        bool "Use out of band interrupt"
-       depends on WILC1000 && WILC1000_SDIO
+       depends on WILC1000_SDIO
        default n
        ---help---
          This option enables out-of-band interrupt support for the WILC1000
@@ -69,3 +71,5 @@ config WILC1000_HW_OOB_INTR
          mechanism for SDIO host controllers that don't support SDIO interrupt.
          Select this option If the SDIO host controller in your platform
          doesn't support SDIO time devision interrupt.
+
+endif
index 6be8a920706a1065534d1d0bca1cc1472618c10e..64c2f1b83dfbebedf7f67150a949253ee7e7ad4e 100644 (file)
@@ -1,6 +1,4 @@
 obj-$(CONFIG_WILC1000) += wilc1000.o
-obj-$(CONFIG_WILC1000_PREALLOCATE_DURING_SYSTEM_BOOT) += wilc_exported_buf.o
-
 
 ccflags-$(CONFIG_WILC1000_SDIO) += -DWILC_SDIO -DCOMPLEMENT_BOOT
 ccflags-$(CONFIG_WILC1000_HW_OOB_INTR) += -DWILC_SDIO_IRQ_GPIO
@@ -11,14 +9,9 @@ ccflags-y += -DSTA_FIRMWARE=\"atmel/wilc1000_fw.bin\" \
                -DP2P_CONCURRENCY_FIRMWARE=\"atmel/wilc1000_p2p_fw.bin\"
 
 ccflags-y += -I$(src)/ -D__CHECK_ENDIAN__ -DWILC_ASIC_A0 \
-               -DPLL_WORKAROUND -DCONNECT_DIRECT  -DAGING_ALG \
-               -DWILC_PARSE_SCAN_IN_HOST -DDISABLE_PWRSAVE_AND_SCAN_DURING_IP \
-               -Wno-unused-function -DUSE_WIRELESS -DWILC_DEBUGFS
+               -Wno-unused-function -DWILC_DEBUGFS
 #ccflags-y += -DTCP_ACK_FILTER
 
-ccflags-$(CONFIG_WILC1000_PREALLOCATE_DURING_SYSTEM_BOOT) += -DMEMORY_STATIC \
-                                                               -DWILC_PREALLOC_AT_BOOT
-
 ccflags-$(CONFIG_WILC1000_PREALLOCATE_AT_LOADING_DRIVER) += -DMEMORY_STATIC \
                                                                -DWILC_PREALLOC_AT_INSMOD
 
@@ -26,9 +19,10 @@ ccflags-$(CONFIG_WILC1000_DYNAMICALLY_ALLOCATE_MEMROY) += -DWILC_NORMAL_ALLOC
 
 
 wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
-                       wilc_memory.o wilc_msgqueue.o \
+                       wilc_msgqueue.o \
                        coreconfigurator.o host_interface.o \
-                       wilc_sdio.o wilc_spi.o wilc_wlan_cfg.o wilc_debugfs.o
+                       wilc_sdio.o wilc_spi.o wilc_wlan_cfg.o wilc_debugfs.o \
+                       wilc_wlan.o
 
 wilc1000-$(CONFIG_WILC1000_SDIO) += linux_wlan_sdio.o
 wilc1000-$(CONFIG_WILC1000_SPI) += linux_wlan_spi.o
index 16a0abc970c001d5a3f26ce1f2bf81e86df90f85..e10c6ffa698a6f541ad4e40c7007ddc4852b50cd 100644 (file)
@@ -8,47 +8,29 @@
  *  @version   1.0
  */
 
-
-/*****************************************************************************/
-/* File Includes                                                             */
-/*****************************************************************************/
 #include "coreconfigurator.h"
-/*****************************************************************************/
-/* Constants                                                                 */
-/*****************************************************************************/
-#define INLINE static __inline
-#define PHY_802_11n
-#define MAX_CFG_PKTLEN     1450
-#define MSG_HEADER_LEN     4
-#define QUERY_MSG_TYPE     'Q'
-#define WRITE_MSG_TYPE     'W'
-#define RESP_MSG_TYPE      'R'
-#define WRITE_RESP_SUCCESS 1
-#define INVALID         255
-#define MAC_ADDR_LEN    6
+#include "wilc_wlan_if.h"
+#include "wilc_wlan.h"
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/etherdevice.h>
 #define TAG_PARAM_OFFSET       (MAC_HDR_LEN + TIME_STAMP_LEN + \
                                                        BEACON_INTERVAL_LEN + CAP_INFO_LEN)
-
-/*****************************************************************************/
-/* Function Macros                                                           */
-/*****************************************************************************/
-
-
-/*****************************************************************************/
-/* Type Definitions                                                          */
-/*****************************************************************************/
+#define ADDR1 4
+#define ADDR2 10
+#define ADDR3 16
 
 /* Basic Frame Type Codes (2-bit) */
-typedef enum {
+enum basic_frame_type {
        FRAME_TYPE_CONTROL     = 0x04,
        FRAME_TYPE_DATA        = 0x08,
        FRAME_TYPE_MANAGEMENT  = 0x00,
        FRAME_TYPE_RESERVED    = 0x0C,
        FRAME_TYPE_FORCE_32BIT = 0xFFFFFFFF
-} tenuBasicFrmType;
+};
 
 /* Frame Type and Subtype Codes (6-bit) */
-typedef enum {
+enum sub_frame_type {
        ASSOC_REQ             = 0x00,
        ASSOC_RSP             = 0x10,
        REASSOC_REQ           = 0x20,
@@ -85,18 +67,10 @@ typedef enum {
        BLOCKACK_REQ          = 0x84,
        BLOCKACK              = 0x94,
        FRAME_SUBTYPE_FORCE_32BIT  = 0xFFFFFFFF
-} tenuFrmSubtype;
-
-/* Basic Frame Classes */
-typedef enum {
-       CLASS1_FRAME_TYPE      = 0x00,
-       CLASS2_FRAME_TYPE      = 0x01,
-       CLASS3_FRAME_TYPE      = 0x02,
-       FRAME_CLASS_FORCE_32BIT  = 0xFFFFFFFF
-} tenuFrameClass;
+};
 
 /* Element ID  of various Information Elements */
-typedef enum {
+enum info_element_id {
        ISSID               = 0,   /* Service Set Identifier         */
        ISUPRATES           = 1,   /* Supported Rates                */
        IFHPARMS            = 2,   /* FH parameter set               */
@@ -137,343 +111,13 @@ typedef enum {
        IWMM                = 221, /* WMM parameters                 */
        IWPAELEMENT         = 221, /* WPA Information Element        */
        INFOELEM_ID_FORCE_32BIT  = 0xFFFFFFFF
-} tenuInfoElemID;
-
-
-typedef struct {
-       char *pcRespBuffer;
-       s32 s32MaxRespBuffLen;
-       s32 s32BytesRead;
-       bool bRespRequired;
-} tstrConfigPktInfo;
-
-
-
-/*****************************************************************************/
-/* Extern Variable Declarations                                              */
-/*****************************************************************************/
-
-
-/*****************************************************************************/
-/* Extern Function Declarations                                              */
-/*****************************************************************************/
-extern s32 SendRawPacket(s8 *ps8Packet, s32 s32PacketLen);
-extern void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length);
-extern void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length);
-extern void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length);
-/*****************************************************************************/
-/* Global Variables                                                          */
-/*****************************************************************************/
-static struct semaphore SemHandleSendPkt;
-static struct semaphore SemHandlePktResp;
-
-
-static tstrConfigPktInfo gstrConfigPktInfo;
-
-static u8 g_seqno;
-
-static s16 g_wid_num          = -1;
-
-static u16 Res_Len;
-
-static u8 g_oper_mode    = SET_CFG;
-
-/* WID Switches */
-static tstrWID gastrWIDs[] = {
-       {WID_FIRMWARE_VERSION,          WID_STR},
-       {WID_PHY_VERSION,               WID_STR},
-       {WID_HARDWARE_VERSION,          WID_STR},
-       {WID_BSS_TYPE,                  WID_CHAR},
-       {WID_QOS_ENABLE,                WID_CHAR},
-       {WID_11I_MODE,                  WID_CHAR},
-       {WID_CURRENT_TX_RATE,           WID_CHAR},
-       {WID_LINKSPEED,                 WID_CHAR},
-       {WID_RTS_THRESHOLD,             WID_SHORT},
-       {WID_FRAG_THRESHOLD,            WID_SHORT},
-       {WID_SSID,                      WID_STR},
-       {WID_BSSID,                     WID_ADR},
-       {WID_BEACON_INTERVAL,           WID_SHORT},
-       {WID_POWER_MANAGEMENT,          WID_CHAR},
-       {WID_LISTEN_INTERVAL,           WID_CHAR},
-       {WID_DTIM_PERIOD,               WID_CHAR},
-       {WID_CURRENT_CHANNEL,           WID_CHAR},
-       {WID_TX_POWER_LEVEL_11A,        WID_CHAR},
-       {WID_TX_POWER_LEVEL_11B,        WID_CHAR},
-       {WID_PREAMBLE,                  WID_CHAR},
-       {WID_11G_OPERATING_MODE,        WID_CHAR},
-       {WID_MAC_ADDR,                  WID_ADR},
-       {WID_IP_ADDRESS,                WID_ADR},
-       {WID_ACK_POLICY,                WID_CHAR},
-       {WID_PHY_ACTIVE_REG,            WID_CHAR},
-       {WID_AUTH_TYPE,                 WID_CHAR},
-       {WID_REKEY_POLICY,              WID_CHAR},
-       {WID_REKEY_PERIOD,              WID_INT},
-       {WID_REKEY_PACKET_COUNT,        WID_INT},
-       {WID_11I_PSK,                   WID_STR},
-       {WID_1X_KEY,                    WID_STR},
-       {WID_1X_SERV_ADDR,              WID_IP},
-       {WID_SUPP_USERNAME,             WID_STR},
-       {WID_SUPP_PASSWORD,             WID_STR},
-       {WID_USER_CONTROL_ON_TX_POWER,  WID_CHAR},
-       {WID_MEMORY_ADDRESS,            WID_INT},
-       {WID_MEMORY_ACCESS_32BIT,       WID_INT},
-       {WID_MEMORY_ACCESS_16BIT,       WID_SHORT},
-       {WID_MEMORY_ACCESS_8BIT,        WID_CHAR},
-       {WID_SITE_SURVEY_RESULTS,       WID_STR},
-       {WID_PMKID_INFO,                WID_STR},
-       {WID_ASSOC_RES_INFO,            WID_STR},
-       {WID_MANUFACTURER,              WID_STR}, /* 4 Wids added for the CAPI tool*/
-       {WID_MODEL_NAME,                WID_STR},
-       {WID_MODEL_NUM,                 WID_STR},
-       {WID_DEVICE_NAME,               WID_STR},
-       {WID_SSID_PROBE_REQ,            WID_STR},
-
-#ifdef MAC_802_11N
-       {WID_11N_ENABLE,                WID_CHAR},
-       {WID_11N_CURRENT_TX_MCS,        WID_CHAR},
-       {WID_TX_POWER_LEVEL_11N,        WID_CHAR},
-       {WID_11N_OPERATING_MODE,        WID_CHAR},
-       {WID_11N_SMPS_MODE,             WID_CHAR},
-       {WID_11N_PROT_MECH,             WID_CHAR},
-       {WID_11N_ERP_PROT_TYPE,         WID_CHAR},
-       {WID_11N_HT_PROT_TYPE,          WID_CHAR},
-       {WID_11N_PHY_ACTIVE_REG_VAL,    WID_INT},
-       {WID_11N_PRINT_STATS,           WID_CHAR},
-       {WID_11N_AUTORATE_TABLE,        WID_BIN_DATA},
-       {WID_HOST_CONFIG_IF_TYPE,       WID_CHAR},
-       {WID_HOST_DATA_IF_TYPE,         WID_CHAR},
-       {WID_11N_SIG_QUAL_VAL,          WID_SHORT},
-       {WID_11N_IMMEDIATE_BA_ENABLED,  WID_CHAR},
-       {WID_11N_TXOP_PROT_DISABLE,     WID_CHAR},
-       {WID_11N_SHORT_GI_20MHZ_ENABLE, WID_CHAR},
-       {WID_SHORT_SLOT_ALLOWED,        WID_CHAR},
-       {WID_11W_ENABLE,                WID_CHAR},
-       {WID_11W_MGMT_PROT_REQ,         WID_CHAR},
-       {WID_2040_ENABLE,               WID_CHAR},
-       {WID_2040_COEXISTENCE,          WID_CHAR},
-       {WID_USER_SEC_CHANNEL_OFFSET,   WID_CHAR},
-       {WID_2040_CURR_CHANNEL_OFFSET,  WID_CHAR},
-       {WID_2040_40MHZ_INTOLERANT,     WID_CHAR},
-       {WID_HUT_RESTART,               WID_CHAR},
-       {WID_HUT_NUM_TX_PKTS,           WID_INT},
-       {WID_HUT_FRAME_LEN,             WID_SHORT},
-       {WID_HUT_TX_FORMAT,             WID_CHAR},
-       {WID_HUT_BANDWIDTH,             WID_CHAR},
-       {WID_HUT_OP_BAND,               WID_CHAR},
-       {WID_HUT_STBC,                  WID_CHAR},
-       {WID_HUT_ESS,                   WID_CHAR},
-       {WID_HUT_ANTSET,                WID_CHAR},
-       {WID_HUT_HT_OP_MODE,            WID_CHAR},
-       {WID_HUT_RIFS_MODE,             WID_CHAR},
-       {WID_HUT_SMOOTHING_REC,         WID_CHAR},
-       {WID_HUT_SOUNDING_PKT,          WID_CHAR},
-       {WID_HUT_HT_CODING,             WID_CHAR},
-       {WID_HUT_TEST_DIR,              WID_CHAR},
-       {WID_HUT_TXOP_LIMIT,            WID_SHORT},
-       {WID_HUT_DEST_ADDR,             WID_ADR},
-       {WID_HUT_TX_PATTERN,            WID_BIN_DATA},
-       {WID_HUT_TX_TIME_TAKEN,         WID_INT},
-       {WID_HUT_PHY_TEST_MODE,         WID_CHAR},
-       {WID_HUT_PHY_TEST_RATE_HI,      WID_CHAR},
-       {WID_HUT_PHY_TEST_RATE_LO,      WID_CHAR},
-       {WID_HUT_TX_TEST_TIME,          WID_INT},
-       {WID_HUT_LOG_INTERVAL,          WID_INT},
-       {WID_HUT_DISABLE_RXQ_REPLENISH, WID_CHAR},
-       {WID_HUT_TEST_ID,               WID_STR},
-       {WID_HUT_KEY_ORIGIN,            WID_CHAR},
-       {WID_HUT_BCST_PERCENT,          WID_CHAR},
-       {WID_HUT_GROUP_CIPHER_TYPE,     WID_CHAR},
-       {WID_HUT_STATS,                 WID_BIN_DATA},
-       {WID_HUT_TSF_TEST_MODE,         WID_CHAR},
-       {WID_HUT_SIG_QUAL_AVG,          WID_SHORT},
-       {WID_HUT_SIG_QUAL_AVG_CNT,      WID_SHORT},
-       {WID_HUT_TSSI_VALUE,            WID_CHAR},
-       {WID_HUT_MGMT_PERCENT,          WID_CHAR},
-       {WID_HUT_MGMT_BCST_PERCENT,     WID_CHAR},
-       {WID_HUT_MGMT_ALLOW_HT,         WID_CHAR},
-       {WID_HUT_UC_MGMT_TYPE,          WID_CHAR},
-       {WID_HUT_BC_MGMT_TYPE,          WID_CHAR},
-       {WID_HUT_UC_MGMT_FRAME_LEN,     WID_SHORT},
-       {WID_HUT_BC_MGMT_FRAME_LEN,     WID_SHORT},
-       {WID_HUT_11W_MFP_REQUIRED_TX,   WID_CHAR},
-       {WID_HUT_11W_MFP_PEER_CAPABLE,  WID_CHAR},
-       {WID_HUT_11W_TX_IGTK_ID,        WID_CHAR},
-       {WID_HUT_FC_TXOP_MOD,           WID_CHAR},
-       {WID_HUT_FC_PROT_TYPE,          WID_CHAR},
-       {WID_HUT_SEC_CCA_ASSERT,        WID_CHAR},
-#endif /* MAC_802_11N */
 };
 
-u16 g_num_total_switches = (sizeof(gastrWIDs) / sizeof(tstrWID));
-/*****************************************************************************/
-/* Static Function Declarations                                              */
-/*****************************************************************************/
-
-
-
-/*****************************************************************************/
-/* Functions                                                                 */
-/*****************************************************************************/
-INLINE u8 ascii_hex_to_dec(u8 num)
-{
-       if ((num >= '0') && (num <= '9'))
-               return (num - '0');
-       else if ((num >= 'A') && (num <= 'F'))
-               return (10 + (num - 'A'));
-       else if ((num >= 'a') && (num <= 'f'))
-               return (10 + (num - 'a'));
-
-       return INVALID;
-}
-
-INLINE u8 get_hex_char(u8 inp)
-{
-       u8 *d2htab = "0123456789ABCDEF";
-
-       return d2htab[inp & 0xF];
-}
-
-/* This function extracts the MAC address held in a string in standard format */
-/* into another buffer as integers.                                           */
-INLINE u16 extract_mac_addr(char *str, u8 *buff)
-{
-       *buff = 0;
-       while (*str != '\0') {
-               if ((*str == ':') || (*str == '-'))
-                       *(++buff) = 0;
-               else
-                       *buff = (*buff << 4) + ascii_hex_to_dec(*str);
-
-               str++;
-       }
-
-       return MAC_ADDR_LEN;
-}
-
-/* This function creates MAC address in standard format from a buffer of      */
-/* integers.                                                                  */
-INLINE void create_mac_addr(u8 *str, u8 *buff)
-{
-       u32 i = 0;
-       u32 j = 0;
-
-       for (i = 0; i < MAC_ADDR_LEN; i++) {
-               str[j++] = get_hex_char((u8)((buff[i] >> 4) & 0x0F));
-               str[j++] = get_hex_char((u8)(buff[i] & 0x0F));
-               str[j++] = ':';
-       }
-       str[--j] = '\0';
-}
-
-/* This function converts the IP address string in dotted decimal format to */
-/* unsigned integer. This functionality is similar to the library function  */
-/* inet_addr() but is reimplemented here since I could not confirm that     */
-/* inet_addr is platform independent.                                       */
-/* ips=>IP Address String in dotted decimal format                          */
-/* ipn=>Pointer to IP Address in integer format                             */
-INLINE u8 conv_ip_to_int(u8 *ips, u32 *ipn)
-{
-       u8 i   = 0;
-       u8 ipb = 0;
-       *ipn = 0;
-       /* Integer to string for each component */
-       while (ips[i] != '\0') {
-               if (ips[i] == '.') {
-                       *ipn = ((*ipn) << 8) | ipb;
-                       ipb = 0;
-               } else {
-                       ipb = ipb * 10 + ascii_hex_to_dec(ips[i]);
-               }
-
-               i++;
-       }
-
-       /* The last byte of the IP address is read in here */
-       *ipn = ((*ipn) << 8) | ipb;
-
-       return 0;
-}
-
-/* This function converts the IP address from integer format to dotted    */
-/* decimal string format. Alternative to std library fn inet_ntoa().      */
-/* ips=>Buffer to hold IP Address String dotted decimal format (Min 17B)  */
-/* ipn=>IP Address in integer format                                      */
-INLINE u8 conv_int_to_ip(u8 *ips, u32 ipn)
-{
-       u8 i   = 0;
-       u8 ipb = 0;
-       u8 cnt = 0;
-       u8 ipbsize = 0;
-
-       for (cnt = 4; cnt > 0; cnt--) {
-               ipb = (ipn >> (8 * (cnt - 1))) & 0xFF;
-
-               if (ipb >= 100)
-                       ipbsize = 2;
-               else if (ipb >= 10)
-                       ipbsize = 1;
-               else
-                       ipbsize = 0;
-
-               switch (ipbsize) {
-               case 2:
-                       ips[i++] = get_hex_char(ipb / 100);
-                       ipb %= 100;
-
-               case 1:
-                       ips[i++] = get_hex_char(ipb / 10);
-                       ipb %= 10;
-
-               default:
-                       ips[i++] = get_hex_char(ipb);
-               }
-
-               if (cnt > 1)
-                       ips[i++] = '.';
-       }
-
-       ips[i] = '\0';
-
-       return i;
-}
-
-INLINE tenuWIDtype get_wid_type(u32 wid_num)
-{
-       /* Check for iconfig specific WID types first */
-       if ((wid_num == WID_BSSID) ||
-           (wid_num == WID_MAC_ADDR) ||
-           (wid_num == WID_IP_ADDRESS) ||
-           (wid_num == WID_HUT_DEST_ADDR)) {
-               return WID_ADR;
-       }
-
-       if ((WID_1X_SERV_ADDR == wid_num) ||
-           (WID_STACK_IP_ADDR == wid_num) ||
-           (WID_STACK_NETMASK_ADDR == wid_num)) {
-               return WID_IP;
-       }
-
-       /* Next check for standard WID types */
-       if (wid_num < 0x1000)
-               return WID_CHAR;
-       else if (wid_num < 0x2000)
-               return WID_SHORT;
-       else if (wid_num < 0x3000)
-               return WID_INT;
-       else if (wid_num < 0x4000)
-               return WID_STR;
-       else if (wid_num < 0x5000)
-               return WID_BIN_DATA;
-
-       return WID_UNDEF;
-}
-
-
 /* This function extracts the beacon period field from the beacon or probe   */
 /* response frame.                                                           */
-INLINE u16 get_beacon_period(u8 *data)
+static inline u16 get_beacon_period(u8 *data)
 {
-       u16 bcn_per = 0;
+       u16 bcn_per;
 
        bcn_per  = data[0];
        bcn_per |= (data[1] << 8);
@@ -481,7 +125,7 @@ INLINE u16 get_beacon_period(u8 *data)
        return bcn_per;
 }
 
-INLINE u32 get_beacon_timestamp_lo(u8 *data)
+static inline u32 get_beacon_timestamp_lo(u8 *data)
 {
        u32 time_stamp = 0;
        u32 index    = MAC_HDR_LEN;
@@ -494,7 +138,7 @@ INLINE u32 get_beacon_timestamp_lo(u8 *data)
        return time_stamp;
 }
 
-INLINE u32 get_beacon_timestamp_hi(u8 *data)
+static inline u32 get_beacon_timestamp_hi(u8 *data)
 {
        u32 time_stamp = 0;
        u32 index    = (MAC_HDR_LEN + 4);
@@ -507,26 +151,18 @@ INLINE u32 get_beacon_timestamp_hi(u8 *data)
        return time_stamp;
 }
 
-/* This function extracts the 'frame type' bits from the MAC header of the   */
-/* input frame.                                                              */
-/* Returns the value in the LSB of the returned value.                       */
-INLINE tenuBasicFrmType get_type(u8 *header)
-{
-       return ((tenuBasicFrmType)(header[0] & 0x0C));
-}
-
 /* This function extracts the 'frame type and sub type' bits from the MAC    */
 /* header of the input frame.                                                */
 /* Returns the value in the LSB of the returned value.                       */
-INLINE tenuFrmSubtype get_sub_type(u8 *header)
+static inline enum sub_frame_type get_sub_type(u8 *header)
 {
-       return ((tenuFrmSubtype)(header[0] & 0xFC));
+       return ((enum sub_frame_type)(header[0] & 0xFC));
 }
 
 /* This function extracts the 'to ds' bit from the MAC header of the input   */
 /* frame.                                                                    */
 /* Returns the value in the LSB of the returned value.                       */
-INLINE u8 get_to_ds(u8 *header)
+static inline u8 get_to_ds(u8 *header)
 {
        return (header[1] & 0x01);
 }
@@ -534,47 +170,41 @@ INLINE u8 get_to_ds(u8 *header)
 /* This function extracts the 'from ds' bit from the MAC header of the input */
 /* frame.                                                                    */
 /* Returns the value in the LSB of the returned value.                       */
-INLINE u8 get_from_ds(u8 *header)
+static inline u8 get_from_ds(u8 *header)
 {
        return ((header[1] & 0x02) >> 1);
 }
 
-/* This function extracts the MAC Address in 'address1' field of the MAC     */
-/* header and updates the MAC Address in the allocated 'addr' variable.      */
-INLINE void get_address1(u8 *pu8msa, u8 *addr)
-{
-       memcpy(addr, pu8msa + 4, 6);
-}
-
-/* This function extracts the MAC Address in 'address2' field of the MAC     */
-/* header and updates the MAC Address in the allocated 'addr' variable.      */
-INLINE void get_address2(u8 *pu8msa, u8 *addr)
-{
-       memcpy(addr, pu8msa + 10, 6);
-}
-
-/* This function extracts the MAC Address in 'address3' field of the MAC     */
-/* header and updates the MAC Address in the allocated 'addr' variable.      */
-INLINE void get_address3(u8 *pu8msa, u8 *addr)
-{
-       memcpy(addr, pu8msa + 16, 6);
-}
-
 /* This function extracts the BSSID from the incoming WLAN packet based on   */
-/* the 'from ds' bit, and updates the MAC Address in the allocated 'addr'    */
+/* the 'from ds' bit, and updates the MAC Address in the allocated 'data'    */
 /* variable.                                                                 */
-INLINE void get_BSSID(u8 *data, u8 *bssid)
+static inline void get_BSSID(u8 *data, u8 *bssid)
 {
        if (get_from_ds(data) == 1)
-               get_address2(data, bssid);
+               /*
+                * Extract the MAC Address in 'address2' field of the MAC
+                * header and update the MAC Address in the allocated 'data'
+                *  variable.
+                */
+               ether_addr_copy(data, bssid + ADDR2);
        else if (get_to_ds(data) == 1)
-               get_address1(data, bssid);
+               /*
+                * Extract the MAC Address in 'address1' field of the MAC
+                * header and update the MAC Address in the allocated 'data'
+                * variable.
+                */
+               ether_addr_copy(data, bssid + ADDR1);
        else
-               get_address3(data, bssid);
+               /*
+                * Extract the MAC Address in 'address3' field of the MAC
+                * header and update the MAC Address in the allocated 'data'
+                * variable.
+                */
+               ether_addr_copy(data, bssid + ADDR3);
 }
 
 /* This function extracts the SSID from a beacon/probe response frame        */
-INLINE void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
+static inline void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
 {
        u8 len = 0;
        u8 i   = 0;
@@ -600,11 +230,11 @@ INLINE void get_ssid(u8 *data, u8 *ssid, u8 *p_ssid_len)
 
 /* This function extracts the capability info field from the beacon or probe */
 /* response frame.                                                           */
-INLINE u16 get_cap_info(u8 *data)
+static inline u16 get_cap_info(u8 *data)
 {
        u16 cap_info = 0;
        u16 index    = MAC_HDR_LEN;
-       tenuFrmSubtype st;
+       enum sub_frame_type st;
 
        st = get_sub_type(data);
 
@@ -621,9 +251,9 @@ INLINE u16 get_cap_info(u8 *data)
 
 /* This function extracts the capability info field from the Association */
 /* response frame.                                                                       */
-INLINE u16 get_assoc_resp_cap_info(u8 *data)
+static inline u16 get_assoc_resp_cap_info(u8 *data)
 {
-       u16 cap_info = 0;
+       u16 cap_info;
 
        cap_info  = data[0];
        cap_info |= (data[1] << 8);
@@ -631,11 +261,11 @@ INLINE u16 get_assoc_resp_cap_info(u8 *data)
        return cap_info;
 }
 
-/* This funcion extracts the association status code from the incoming       */
+/* This function extracts the association status code from the incoming       */
 /* association response frame and returns association status code            */
-INLINE u16 get_asoc_status(u8 *data)
+static inline u16 get_asoc_status(u8 *data)
 {
-       u16 asoc_status = 0;
+       u16 asoc_status;
 
        asoc_status = data[3];
        asoc_status = (asoc_status << 8) | data[2];
@@ -645,9 +275,9 @@ INLINE u16 get_asoc_status(u8 *data)
 
 /* This function extracts association ID from the incoming association       */
 /* response frame                                                                                           */
-INLINE u16 get_asoc_id(u8 *data)
+static inline u16 get_asoc_id(u8 *data)
 {
-       u16 asoc_id = 0;
+       u16 asoc_id;
 
        asoc_id  = data[4];
        asoc_id |= (data[5] << 8);
@@ -655,32 +285,9 @@ INLINE u16 get_asoc_id(u8 *data)
        return asoc_id;
 }
 
-/**
- *  @brief              initializes the Core Configurator
- *  @details
- *  @return     Error code indicating success/failure
- *  @note
- *  @author    mabubakr
- *  @date              1 Mar 2012
- *  @version           1.0
- */
-
-s32 CoreConfiguratorInit(void)
-{
-       s32 s32Error = WILC_SUCCESS;
-       PRINT_D(CORECONFIG_DBG, "CoreConfiguratorInit()\n");
-
-       sema_init(&SemHandleSendPkt, 1);
-       sema_init(&SemHandlePktResp, 0);
-
-
-       memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo));
-       return s32Error;
-}
-
 u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
 {
-       u16 u16index = 0;
+       u16 u16index;
 
        /*************************************************************************/
        /*                       Beacon Frame - Frame Body                       */
@@ -698,11 +305,10 @@ u8 *get_tim_elm(u8 *pu8msa, u16 u16RxLen, u16 u16TagParamOffset)
        while (u16index < (u16RxLen - FCS_LEN)) {
                if (pu8msa[u16index] == ITIM)
                        return &pu8msa[u16index];
-               else
-                       u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
+               u16index += (IE_HDR_LEN + pu8msa[u16index + 1]);
        }
 
-       return 0;
+       return NULL;
 }
 
 /* This function gets the current channel information from
@@ -715,9 +321,8 @@ u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen)
        while (index < (u16RxLen - FCS_LEN)) {
                if (pu8msa[index] == IDSPARMS)
                        return pu8msa[index + 2];
-               else
-                       /* Increment index by length information and header */
-                       index += pu8msa[index + 1] + IE_HDR_LEN;
+               /* Increment index by length information and header */
+               index += pu8msa[index + 1] + IE_HDR_LEN;
        }
 
        /* Return current channel information from the MIB, if beacon/probe  */
@@ -726,23 +331,6 @@ u8 get_current_channel_802_11n(u8 *pu8msa, u16 u16RxLen)
        return 0;  /* no MIB here */
 }
 
-u8 get_current_channel(u8 *pu8msa, u16 u16RxLen)
-{
-#ifdef PHY_802_11n
-#ifdef FIVE_GHZ_BAND
-       /* Get the current channel as its not set in */
-       /* 802.11a beacons/probe response            */
-       return (get_rf_channel() + 1);
-#else /* FIVE_GHZ_BAND */
-       /* Extract current channel information from */
-       /* the beacon/probe response frame          */
-       return get_current_channel_802_11n(pu8msa, u16RxLen);
-#endif /* FIVE_GHZ_BAND */
-#else
-       return 0;
-#endif /* PHY_802_11n */
-}
-
 /**
  *  @brief                      parses the received 'N' message
  *  @details
@@ -754,9 +342,8 @@ u8 get_current_channel(u8 *pu8msa, u16 u16RxLen)
  *  @date                      1 Mar 2012
  *  @version           1.0
  */
-s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
+s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 {
-       s32 s32Error = WILC_SUCCESS;
        tstrNetworkInfo *pstrNetworkInfo = NULL;
        u8 u8MsgType = 0;
        u8 u8MsgID = 0;
@@ -764,14 +351,14 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 
        u16 u16WidID = (u16)WID_NIL;
        u16 u16WidLen  = 0;
-       u8  *pu8WidVal = 0;
+       u8  *pu8WidVal = NULL;
 
        u8MsgType = pu8MsgBuffer[0];
 
        /* Check whether the received message type is 'N' */
        if ('N' != u8MsgType) {
                PRINT_ER("Received Message format incorrect.\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+               return -EFAULT;
        }
 
        /* Extract message ID */
@@ -791,21 +378,19 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 
        /* parse the WID value of the WID "WID_NEWORK_INFO" */
        {
-               u8  *pu8msa = 0;
+               u8  *pu8msa = NULL;
                u16 u16RxLen = 0;
-               u8 *pu8TimElm = 0;
-               u8 *pu8IEs = 0;
+               u8 *pu8TimElm = NULL;
+               u8 *pu8IEs = NULL;
                u16 u16IEsLen = 0;
                u8 u8index = 0;
                u32 u32Tsf_Lo;
                u32 u32Tsf_Hi;
 
-               pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_KERNEL);
+               pstrNetworkInfo = kzalloc(sizeof(tstrNetworkInfo), GFP_KERNEL);
                if (!pstrNetworkInfo)
                        return -ENOMEM;
 
-               memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo));
-
                pstrNetworkInfo->s8rssi = pu8WidVal[0];
 
                /* Assign a pointer to msa "Mac Header Start Address" */
@@ -817,11 +402,9 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 
                /* Get the cap_info */
                pstrNetworkInfo->u16CapInfo = get_cap_info(pu8msa);
-               #ifdef WILC_P2P
                /* Get time-stamp [Low only 32 bit] */
                pstrNetworkInfo->u32Tsf = get_beacon_timestamp_lo(pu8msa);
                PRINT_D(CORECONFIG_DBG, "TSF :%x\n", pstrNetworkInfo->u32Tsf);
-               #endif
 
                /* Get full time-stamp [Low and High 64 bit] */
                u32Tsf_Lo = get_beacon_timestamp_lo(pu8msa);
@@ -830,36 +413,37 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
                pstrNetworkInfo->u64Tsf = u32Tsf_Lo | ((u64)u32Tsf_Hi << 32);
 
                /* Get SSID */
-               get_ssid(pu8msa, pstrNetworkInfo->au8ssid, &(pstrNetworkInfo->u8SsidLen));
+               get_ssid(pu8msa, pstrNetworkInfo->au8ssid, &pstrNetworkInfo->u8SsidLen);
 
                /* Get BSSID */
                get_BSSID(pu8msa, pstrNetworkInfo->au8bssid);
 
-               /* Get the current channel */
-               pstrNetworkInfo->u8channel = get_current_channel(pu8msa, (u16RxLen + FCS_LEN));
+               /*
+                * Extract current channel information from
+                * the beacon/probe response frame
+                */
+               pstrNetworkInfo->u8channel = get_current_channel_802_11n(pu8msa,
+                                                       u16RxLen + FCS_LEN);
 
                /* Get beacon period */
-               u8index = (MAC_HDR_LEN + TIME_STAMP_LEN);
+               u8index = MAC_HDR_LEN + TIME_STAMP_LEN;
 
                pstrNetworkInfo->u16BeaconPeriod = get_beacon_period(pu8msa + u8index);
 
                u8index += BEACON_INTERVAL_LEN + CAP_INFO_LEN;
 
                /* Get DTIM Period */
-               pu8TimElm = get_tim_elm(pu8msa, (u16RxLen + FCS_LEN), u8index);
-               if (pu8TimElm != 0)
+               pu8TimElm = get_tim_elm(pu8msa, u16RxLen + FCS_LEN, u8index);
+               if (pu8TimElm != NULL)
                        pstrNetworkInfo->u8DtimPeriod = pu8TimElm[3];
                pu8IEs = &pu8msa[MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN];
                u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
 
                if (u16IEsLen > 0) {
-                       pstrNetworkInfo->pu8IEs = kmalloc(u16IEsLen, GFP_KERNEL);
+                       pstrNetworkInfo->pu8IEs = kmemdup(pu8IEs, u16IEsLen,
+                                                         GFP_KERNEL);
                        if (!pstrNetworkInfo->pu8IEs)
                                return -ENOMEM;
-
-                       memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen);
-
-                       memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen);
                }
                pstrNetworkInfo->u16IEsLen = u16IEsLen;
 
@@ -867,8 +451,7 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 
        *ppstrNetworkInfo = pstrNetworkInfo;
 
-ERRORHANDLER:
-       return s32Error;
+       return 0;
 }
 
 /**
@@ -883,21 +466,21 @@ ERRORHANDLER:
  */
 s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo)
 {
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
 
        if (pstrNetworkInfo != NULL) {
                if (pstrNetworkInfo->pu8IEs != NULL) {
                        kfree(pstrNetworkInfo->pu8IEs);
                        pstrNetworkInfo->pu8IEs = NULL;
                } else {
-                       s32Error = WILC_FAIL;
+                       s32Error = -EFAULT;
                }
 
                kfree(pstrNetworkInfo);
                pstrNetworkInfo = NULL;
 
        } else {
-               s32Error = WILC_FAIL;
+               s32Error = -EFAULT;
        }
 
        return s32Error;
@@ -917,18 +500,16 @@ s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo)
 s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
                               tstrConnectRespInfo **ppstrConnectRespInfo)
 {
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
        tstrConnectRespInfo *pstrConnectRespInfo = NULL;
        u16 u16AssocRespLen = 0;
-       u8 *pu8IEs = 0;
+       u8 *pu8IEs = NULL;
        u16 u16IEsLen = 0;
 
-       pstrConnectRespInfo = kmalloc(sizeof(tstrConnectRespInfo), GFP_KERNEL);
+       pstrConnectRespInfo = kzalloc(sizeof(tstrConnectRespInfo), GFP_KERNEL);
        if (!pstrConnectRespInfo)
                return -ENOMEM;
 
-       memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo));
-
        /* u16AssocRespLen = pu8Buffer[0]; */
        u16AssocRespLen = (u16)u32BufferLen;
 
@@ -946,19 +527,15 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
                pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
                u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
 
-               pstrConnectRespInfo->pu8RespIEs = kmalloc(u16IEsLen, GFP_KERNEL);
+               pstrConnectRespInfo->pu8RespIEs = kmemdup(pu8IEs, u16IEsLen, GFP_KERNEL);
                if (!pstrConnectRespInfo->pu8RespIEs)
                        return -ENOMEM;
 
-               memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen);
-
-               memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen);
                pstrConnectRespInfo->u16RespIEsLen = u16IEsLen;
        }
 
        *ppstrConnectRespInfo = pstrConnectRespInfo;
 
-
        return s32Error;
 }
 
@@ -974,993 +551,26 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
  */
 s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo)
 {
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
 
        if (pstrConnectRespInfo != NULL) {
                if (pstrConnectRespInfo->pu8RespIEs != NULL) {
                        kfree(pstrConnectRespInfo->pu8RespIEs);
                        pstrConnectRespInfo->pu8RespIEs = NULL;
                } else {
-                       s32Error = WILC_FAIL;
+                       s32Error = -EFAULT;
                }
 
                kfree(pstrConnectRespInfo);
                pstrConnectRespInfo = NULL;
 
        } else {
-               s32Error = WILC_FAIL;
+               s32Error = -EFAULT;
        }
 
        return s32Error;
 }
 
-#ifndef CONNECT_DIRECT
-s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
-                              wid_site_survey_reslts_s **ppstrSurveyResults,
-                              u32 *pu32SurveyResultsCount)
-{
-       s32 s32Error = WILC_SUCCESS;
-       wid_site_survey_reslts_s *pstrSurveyResults = NULL;
-       u32 u32SurveyResultsCount = 0;
-       u32 u32SurveyBytesLength = 0;
-       u8 *pu8BufferPtr;
-       u32 u32RcvdSurveyResultsNum = 2;
-       u8 u8ReadSurveyResFragNum;
-       u32 i;
-       u32 j;
-
-       for (i = 0; i < u32RcvdSurveyResultsNum; i++) {
-               u32SurveyBytesLength = ppu8RcvdSiteSurveyResults[i][0];
-
-
-               for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) {
-                       u32SurveyResultsCount++;
-               }
-       }
-
-       pstrSurveyResults = kmalloc_array(u32SurveyResultsCount,
-                               sizeof(wid_site_survey_reslts_s), GFP_KERNEL);
-       if (!pstrSurveyResults)
-               return -ENOMEM;
-
-       memset((void *)(pstrSurveyResults), 0, u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s));
-
-       u32SurveyResultsCount = 0;
-
-       for (i = 0; i < u32RcvdSurveyResultsNum; i++) {
-               pu8BufferPtr = ppu8RcvdSiteSurveyResults[i];
-
-               u32SurveyBytesLength = pu8BufferPtr[0];
-
-               /* TODO: mostafa: pu8BufferPtr[1] contains the fragment num */
-               u8ReadSurveyResFragNum = pu8BufferPtr[1];
-
-               pu8BufferPtr += 2;
-
-               for (j = 0; j < u32SurveyBytesLength; j += SURVEY_RESULT_LENGTH) {
-                       memcpy(&pstrSurveyResults[u32SurveyResultsCount], pu8BufferPtr, SURVEY_RESULT_LENGTH);
-                       pu8BufferPtr += SURVEY_RESULT_LENGTH;
-                       u32SurveyResultsCount++;
-               }
-       }
-
-ERRORHANDLER:
-       *ppstrSurveyResults = pstrSurveyResults;
-       *pu32SurveyResultsCount = u32SurveyResultsCount;
-
-       return s32Error;
-}
-
-
-s32 DeallocateSurveyResults(wid_site_survey_reslts_s *pstrSurveyResults)
-{
-       s32 s32Error = WILC_SUCCESS;
-
-       if (pstrSurveyResults != NULL) {
-               kfree(pstrSurveyResults);
-       }
-
-       return s32Error;
-}
-#endif
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ProcessCharWid                                         */
-/*                                                                           */
-/*  Description   : This function processes a WID of type WID_CHAR and       */
-/*                  updates the cfg packet with the supplied value.          */
-/*                                                                           */
-/*  Inputs        : 1) Pointer to WID cfg structure                          */
-/*                  2) Value to set                                          */
-/*                                                                           */
-/*  Globals       :                                                          */
-/*                                                                           */
-/*  Processing    :                                                          */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : None                                                     */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-void ProcessCharWid(char *pcPacket, s32 *ps32PktLen,
-                   tstrWID *pstrWID, s8 *ps8WidVal)
-{
-       u8 *pu8val = (u8 *)ps8WidVal;
-       u8 u8val = 0;
-       s32 s32PktLen = *ps32PktLen;
-       if (pstrWID == NULL) {
-               PRINT_WRN(CORECONFIG_DBG, "Can't set CHAR val 0x%x ,NULL structure\n", u8val);
-               return;
-       }
-
-       /* WID */
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid >> 8) & 0xFF;
-       if (g_oper_mode == SET_CFG) {
-               u8val = *pu8val;
-
-               /* Length */
-               pcPacket[s32PktLen++] = sizeof(u8);
-
-
-               /* Value */
-               pcPacket[s32PktLen++] = u8val;
-       }
-       *ps32PktLen = s32PktLen;
-}
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ProcessShortWid                                        */
-/*                                                                           */
-/*  Description   : This function processes a WID of type WID_SHORT and      */
-/*                  updates the cfg packet with the supplied value.          */
-/*                                                                           */
-/*  Inputs        : 1) Pointer to WID cfg structure                          */
-/*                  2) Value to set                                          */
-/*                                                                           */
-/*  Globals       :                                                          */
-/*                                                                           */
-/*  Processing    :                                                          */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : None                                                     */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-void ProcessShortWid(char *pcPacket, s32 *ps32PktLen,
-                    tstrWID *pstrWID, s8 *ps8WidVal)
-{
-       u16 *pu16val = (u16 *)ps8WidVal;
-       u16 u16val = 0;
-       s32 s32PktLen = *ps32PktLen;
-       if (pstrWID == NULL) {
-               PRINT_WRN(CORECONFIG_DBG, "Can't set SHORT val 0x%x ,NULL structure\n", u16val);
-               return;
-       }
-
-       /* WID */
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
-       pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
-
-       if (g_oper_mode == SET_CFG) {
-               u16val = *pu16val;
-
-               /* Length */
-               pcPacket[s32PktLen++] = sizeof(u16);
-
-               /* Value */
-               pcPacket[s32PktLen++] = (u8)(u16val & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u16val >> 8) & 0xFF);
-       }
-       *ps32PktLen = s32PktLen;
-}
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ProcessIntWid                                          */
-/*                                                                           */
-/*  Description   : This function processes a WID of type WID_INT and        */
-/*                  updates the cfg packet with the supplied value.          */
-/*                                                                           */
-/*  Inputs        : 1) Pointer to WID cfg structure                          */
-/*                  2) Value to set                                          */
-/*                                                                           */
-/*  Globals       :                                                          */
-/*                                                                           */
-/*  Processing    :                                                          */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : None                                                     */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-void ProcessIntWid(char *pcPacket, s32 *ps32PktLen,
-                  tstrWID *pstrWID, s8 *ps8WidVal)
-{
-       u32 *pu32val = (u32 *)ps8WidVal;
-       u32 u32val = 0;
-       s32 s32PktLen = *ps32PktLen;
-       if (pstrWID == NULL) {
-               PRINT_WRN(CORECONFIG_DBG, "Can't set INT val 0x%x , NULL structure\n", u32val);
-               return;
-       }
-
-       /* WID */
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
-       pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
-
-       if (g_oper_mode == SET_CFG) {
-               u32val = *pu32val;
-
-               /* Length */
-               pcPacket[s32PktLen++] = sizeof(u32);
-
-               /* Value */
-               pcPacket[s32PktLen++] = (u8)(u32val & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u32val >> 8) & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u32val >> 16) & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u32val >> 24) & 0xFF);
-       }
-       *ps32PktLen = s32PktLen;
-}
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ProcessIPwid                                           */
-/*                                                                           */
-/*  Description   : This function processes a WID of type WID_IP and         */
-/*                  updates the cfg packet with the supplied value.          */
-/*                                                                           */
-/*  Inputs        : 1) Pointer to WID cfg structure                          */
-/*                  2) Value to set                                          */
-/*                                                                           */
-/*  Globals       :                                                          */
-/*                                                                           */
-/*                                                                           */
-/*  Processing    :                                                          */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : None                                                     */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-void ProcessIPwid(char *pcPacket, s32 *ps32PktLen,
-                 tstrWID *pstrWID, u8 *pu8ip)
-{
-       u32 u32val = 0;
-       s32 s32PktLen = *ps32PktLen;
-
-       if (pstrWID == NULL) {
-               PRINT_WRN(CORECONFIG_DBG, "Can't set IP Addr , NULL structure\n");
-               return;
-       }
-
-       /* WID */
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
-       pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
-
-       if (g_oper_mode == SET_CFG) {
-               /* Length */
-               pcPacket[s32PktLen++] = sizeof(u32);
-
-               /* Convert the IP Address String to Integer */
-               conv_ip_to_int(pu8ip, &u32val);
-
-               /* Value */
-               pcPacket[s32PktLen++] = (u8)(u32val & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u32val >> 8) & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u32val >> 16) & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u32val >> 24) & 0xFF);
-       }
-       *ps32PktLen = s32PktLen;
-}
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ProcessStrWid                                          */
-/*                                                                           */
-/*  Description   : This function processes a WID of type WID_STR and        */
-/*                  updates the cfg packet with the supplied value.          */
-/*                                                                           */
-/*  Inputs        : 1) Pointer to WID cfg structure                          */
-/*                  2) Value to set                                          */
-/*                                                                           */
-/*  Globals       :                                                          */
-/*                                                                           */
-/*  Processing    :                                                          */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : None                                                     */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-void ProcessStrWid(char *pcPacket, s32 *ps32PktLen,
-                  tstrWID *pstrWID, u8 *pu8val, s32 s32ValueSize)
-{
-       u16 u16MsgLen = 0;
-       u16 idx    = 0;
-       s32 s32PktLen = *ps32PktLen;
-       if (pstrWID == NULL) {
-               PRINT_WRN(CORECONFIG_DBG, "Can't set STR val, NULL structure\n");
-               return;
-       }
-
-       /* WID */
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
-       pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
-
-       if (g_oper_mode == SET_CFG) {
-               /* Message Length */
-               u16MsgLen = (u16)s32ValueSize;
-
-               /* Length */
-               pcPacket[s32PktLen++] = (u8)u16MsgLen;
-
-               /* Value */
-               for (idx = 0; idx < u16MsgLen; idx++)
-                       pcPacket[s32PktLen++] = pu8val[idx];
-       }
-       *ps32PktLen = s32PktLen;
-}
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ProcessAdrWid                                          */
-/*                                                                           */
-/*  Description   : This function processes a WID of type WID_ADR and        */
-/*                  updates the cfg packet with the supplied value.          */
-/*                                                                           */
-/*  Inputs        : 1) Pointer to WID cfg structure                          */
-/*                  2) Value to set                                          */
-/*                                                                           */
-/*  Globals       :                                                          */
-/*                                                                           */
-/*  Processing    :                                                          */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : None                                                     */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-void ProcessAdrWid(char *pcPacket, s32 *ps32PktLen,
-                  tstrWID *pstrWID, u8 *pu8val)
-{
-       u16 u16MsgLen = 0;
-       s32 s32PktLen = *ps32PktLen;
-
-       if (pstrWID == NULL) {
-               PRINT_WRN(CORECONFIG_DBG, "Can't set Addr WID, NULL structure\n");
-               return;
-       }
-
-       /* WID */
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
-       pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
-
-       if (g_oper_mode == SET_CFG) {
-               /* Message Length */
-               u16MsgLen = MAC_ADDR_LEN;
-
-               /* Length */
-               pcPacket[s32PktLen++] = (u8)u16MsgLen;
-
-               /* Value */
-               extract_mac_addr(pu8val, pcPacket + s32PktLen);
-               s32PktLen += u16MsgLen;
-       }
-       *ps32PktLen = s32PktLen;
-}
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ProcessBinWid                                          */
-/*                                                                           */
-/*  Description   : This function processes a WID of type WID_BIN_DATA and        */
-/*                  updates the cfg packet with the supplied value.          */
-/*                                                                           */
-/*  Inputs        : 1) Pointer to WID cfg structure                          */
-/*                  2) Name of file containing the binary data in text mode  */
-/*                                                                           */
-/*  Globals       :                                                          */
-/*                                                                           */
-/*  Processing    : The binary data is expected to be supplied through a     */
-/*                  file in text mode. This file is expected to be in the    */
-/*                  finject format. It is parsed, converted to binary format */
-/*                  and copied into g_cfg_pkt for further processing. This   */
-/*                  is obviously a round-about way of processing involving   */
-/*                  multiple (re)conversions between bin & ascii formats.    */
-/*                  But it is done nevertheless to retain uniformity and for */
-/*                  ease of debugging.                                       */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : None                                                     */
-/*                                                                           */
-
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-void ProcessBinWid(char *pcPacket, s32 *ps32PktLen,
-                  tstrWID *pstrWID, u8 *pu8val, s32 s32ValueSize)
-{
-       u16 u16MsgLen = 0;
-       u16 idx    = 0;
-       s32 s32PktLen = *ps32PktLen;
-       u8 u8checksum = 0;
-
-       if (pstrWID == NULL) {
-               PRINT_WRN(CORECONFIG_DBG, "Can't set BIN val, NULL structure\n");
-               return;
-       }
-
-       /* WID */
-       pcPacket[s32PktLen++] = (u8)(pstrWID->u16WIDid & 0xFF);
-       pcPacket[s32PktLen++] = (u8)((pstrWID->u16WIDid >> 8) & 0xFF);
-
-       if (g_oper_mode == SET_CFG) {
-               /* Message Length */
-               u16MsgLen = (u16)s32ValueSize;
-
-               /* Length */
-               /* pcPacket[s32PktLen++] = (u8)u16MsgLen; */
-               pcPacket[s32PktLen++] = (u8)(u16MsgLen  & 0xFF);
-               pcPacket[s32PktLen++] = (u8)((u16MsgLen >> 8) & 0xFF);
-
-               /* Value */
-               for (idx = 0; idx < u16MsgLen; idx++)
-                       pcPacket[s32PktLen++] = pu8val[idx];
-
-               /* checksum */
-               for (idx = 0; idx < u16MsgLen; idx++)
-                       u8checksum += pcPacket[MSG_HEADER_LEN + idx + 4];
-
-               pcPacket[s32PktLen++] = u8checksum;
-       }
-       *ps32PktLen = s32PktLen;
-}
-
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : further_process_response                                 */
-/*                                                                           */
-/*  Description   : This function parses the response frame got from the     */
-/*                  device.                                                  */
-/*                                                                           */
-/*  Inputs        : 1) The received response frame                           */
-/*                  2) WID                                                   */
-/*                  3) WID Length                                            */
-/*                  4) Output file handle                                    */
-/*                  5) Process Wid Number(i.e wid from --widn switch)        */
-/*                  6) Index the array in the Global Wid Structure.          */
-/*                                                                           */
-/*  Globals       : g_wid_num, gastrWIDs                                     */
-/*                                                                           */
-/*  Processing    : This function parses the response of the device depending*/
-/*                  WID type and writes it to the output file in Hex or      */
-/*                  decimal notation depending on the --getx or --get switch.*/
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : 0 on Success & -2 on Failure                             */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2009   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-s32 further_process_response(u8 *resp,
-                                    u16 u16WIDid,
-                                    u16 cfg_len,
-                                    bool process_wid_num,
-                                    u32 cnt,
-                                    tstrWID *pstrWIDresult)
-{
-       u32 retval = 0;
-       u32 idx = 0;
-       u8 cfg_chr  = 0;
-       u16 cfg_sht  = 0;
-       u32 cfg_int  = 0;
-       u8 cfg_str[256] = {0};
-       tenuWIDtype enuWIDtype = WID_UNDEF;
-
-       if (process_wid_num)
-               enuWIDtype = get_wid_type(g_wid_num);
-       else
-               enuWIDtype = gastrWIDs[cnt].enuWIDtype;
-
-
-       switch (enuWIDtype) {
-       case WID_CHAR:
-               cfg_chr = resp[idx];
-               /*Set local copy of WID*/
-               *(pstrWIDresult->ps8WidVal) = cfg_chr;
-               break;
-
-       case WID_SHORT:
-       {
-               u16 *pu16val = (u16 *)(pstrWIDresult->ps8WidVal);
-               cfg_sht = MAKE_WORD16(resp[idx], resp[idx + 1]);
-               /*Set local copy of WID*/
-               /* pstrWIDresult->ps8WidVal = (s8*)(s32)cfg_sht; */
-               *pu16val = cfg_sht;
-               break;
-       }
-
-       case WID_INT:
-       {
-               u32 *pu32val = (u32 *)(pstrWIDresult->ps8WidVal);
-               cfg_int = MAKE_WORD32(
-                               MAKE_WORD16(resp[idx], resp[idx + 1]),
-                               MAKE_WORD16(resp[idx + 2], resp[idx + 3])
-                               );
-               /*Set local copy of WID*/
-               /* pstrWIDresult->ps8WidVal = (s8*)cfg_int; */
-               *pu32val = cfg_int;
-               break;
-       }
-
-       case WID_STR:
-               memcpy(cfg_str, resp + idx, cfg_len);
-               /* cfg_str[cfg_len] = '\0'; //mostafa: no need currently for NULL termination */
-               if (pstrWIDresult->s32ValueSize >= cfg_len) {
-                       memcpy(pstrWIDresult->ps8WidVal, cfg_str, cfg_len); /* mostafa: no need currently for the extra NULL byte */
-                       pstrWIDresult->s32ValueSize = cfg_len;
-               } else {
-                       PRINT_ER("allocated WID buffer length is smaller than the received WID Length\n");
-                       retval = -2;
-               }
-
-               break;
-
-       case WID_ADR:
-               create_mac_addr(cfg_str, resp + idx);
-
-               strncpy(pstrWIDresult->ps8WidVal, cfg_str, strlen(cfg_str));
-               pstrWIDresult->ps8WidVal[strlen(cfg_str)] = '\0';
-               break;
-
-       case WID_IP:
-               cfg_int = MAKE_WORD32(
-                               MAKE_WORD16(resp[idx], resp[idx + 1]),
-                               MAKE_WORD16(resp[idx + 2], resp[idx + 3])
-                               );
-               conv_int_to_ip(cfg_str, cfg_int);
-               break;
-
-       case WID_BIN_DATA:
-               if (pstrWIDresult->s32ValueSize >= cfg_len) {
-                       memcpy(pstrWIDresult->ps8WidVal, resp + idx, cfg_len);
-                       pstrWIDresult->s32ValueSize = cfg_len;
-               } else {
-                       PRINT_ER("Allocated WID buffer length is smaller than the received WID Length Err(%d)\n", retval);
-                       retval = -2;
-               }
-               break;
-
-       default:
-               PRINT_ER("ERROR: Check config database: Error(%d)\n", retval);
-               retval = -2;
-               break;
-       }
-
-       return retval;
-}
-
-/*****************************************************************************/
-/*                                                                           */
-/*  Function Name : ParseResponse                                           */
-/*                                                                           */
-/*  Description   : This function parses the command-line options and        */
-/*                  creates the config packets which can be sent to the WLAN */
-/*                  station.                                                 */
-/*                                                                           */
-/*  Inputs        : 1) The received response frame                           */
-/*                                                                           */
-/*  Globals       : g_opt_list, gastrWIDs                                       */
-/*                                                                           */
-/*  Processing    : This function parses the options and creates different   */
-/*                  types of packets depending upon the WID-type             */
-/*                  corresponding to the option.                             */
-/*                                                                           */
-/*  Outputs       : None                                                     */
-/*                                                                           */
-/*  Returns       : 0 on Success & -1 on Failure                             */
-/*                                                                           */
-/*  Issues        : None                                                     */
-/*                                                                           */
-/*  Revision History:                                                        */
-/*                                                                           */
-/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
-/*         08 01 2008   Ittiam          Draft                                */
-/*                                                                           */
-/*****************************************************************************/
-
-s32 ParseResponse(u8 *resp, tstrWID *pstrWIDcfgResult)
-{
-       u16 u16RespLen = 0;
-       u16 u16WIDid  = 0;
-       u16 cfg_len  = 0;
-       tenuWIDtype enuWIDtype = WID_UNDEF;
-       bool num_wid_processed = false;
-       u32 cnt = 0;
-       u32 idx = 0;
-       u32 ResCnt = 0;
-       /* Check whether the received frame is a valid response */
-       if (RESP_MSG_TYPE != resp[0]) {
-               PRINT_INFO(CORECONFIG_DBG, "Received Message format incorrect.\n");
-               return -1;
-       }
-
-       /* Extract Response Length */
-       u16RespLen = MAKE_WORD16(resp[2], resp[3]);
-       Res_Len = u16RespLen;
-
-       for (idx = MSG_HEADER_LEN; idx < u16RespLen; ) {
-               u16WIDid = MAKE_WORD16(resp[idx], resp[idx + 1]);
-               cfg_len = resp[idx + 2];
-               /* Incase of Bin Type Wid, the length is given by two byte field      */
-               enuWIDtype = get_wid_type(u16WIDid);
-               if (WID_BIN_DATA == enuWIDtype) {
-                       cfg_len |= ((u16)resp[idx + 3] << 8) & 0xFF00;
-                       idx++;
-               }
-               idx += 3;
-               if ((u16WIDid == g_wid_num) && (!num_wid_processed)) {
-                       num_wid_processed = true;
-
-                       if (-2 == further_process_response(&resp[idx], u16WIDid, cfg_len, true, 0, &pstrWIDcfgResult[ResCnt])) {
-                               return -2;
-                       }
-                       ResCnt++;
-               } else {
-                       for (cnt = 0; cnt < g_num_total_switches; cnt++) {
-                               if (gastrWIDs[cnt].u16WIDid == u16WIDid) {
-                                       if (-2 == further_process_response(&resp[idx], u16WIDid, cfg_len, false, cnt,
-                                                                          &pstrWIDcfgResult[ResCnt])) {
-                                               return -2;
-                                       }
-                                       ResCnt++;
-                               }
-                       }
-               }
-               idx += cfg_len;
-               /* In case if BIN type Wid, The last byte of the Cfg packet is the    */
-               /* Checksum. The WID Length field does not accounts for the checksum. */
-               /* The Checksum is discarded.                                         */
-               if (WID_BIN_DATA == enuWIDtype) {
-                       idx++;
-               }
-       }
-
-       return 0;
-}
-
-/**
- *  @brief              parses the write response [just detects its status: success or failure]
- *  @details
- *  @param[in]  pu8RespBuffer The Response to be parsed
- *  @return     Error code indicating Write Operation status:
- *                            WRITE_RESP_SUCCESS (1) => Write Success.
- *                            WILC_FAIL (-100)               => Write Failure.
- *  @note
- *  @author            Ittiam
- *  @date              11 Aug 2009
- *  @version   1.0
- */
-
-s32 ParseWriteResponse(u8 *pu8RespBuffer)
-{
-       s32 s32Error = WILC_FAIL;
-       u16 u16WIDtype = (u16)WID_NIL;
-
-       /* Check whether the received frame is a valid response */
-       if (RESP_MSG_TYPE != pu8RespBuffer[0]) {
-               PRINT_ER("Received Message format incorrect.\n");
-               return WILC_FAIL;
-       }
-
-       u16WIDtype = MAKE_WORD16(pu8RespBuffer[4], pu8RespBuffer[5]);
-
-       /* Check for WID_STATUS ID and then check the length and status value */
-       if ((u16WIDtype == WID_STATUS) &&
-           (pu8RespBuffer[6] == 1) &&
-           (pu8RespBuffer[7] == WRITE_RESP_SUCCESS)) {
-               s32Error = WRITE_RESP_SUCCESS;
-               return s32Error;
-       }
-
-       /* If the length or status are not as expected return failure    */
-       s32Error = WILC_FAIL;
-       return s32Error;
-
-}
-
-/**
- *  @brief                      creates the header of the Configuration Packet
- *  @details
- *  @param[in,out] pcpacket The Configuration Packet
- *  @param[in,out] ps32PacketLength Length of the Configuration Packet
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            aismail
- *  @date              18 Feb 2012
- *  @version           1.0
- */
-
-s32 CreatePacketHeader(char *pcpacket, s32 *ps32PacketLength)
-{
-       s32 s32Error = WILC_SUCCESS;
-       u16 u16MsgLen = (u16)(*ps32PacketLength);
-       u16 u16MsgInd = 0;
-
-       /* The format of the message is:                                         */
-       /* +-------------------------------------------------------------------+ */
-       /* | Message Type | Message ID |  Message Length |Message body         | */
-       /* +-------------------------------------------------------------------+ */
-       /* |     1 Byte   |   1 Byte   |     2 Bytes     | Message Length - 4  | */
-       /* +-------------------------------------------------------------------+ */
-
-       /* The format of a message body of a message type 'W' is:                */
-       /* +-------------------------------------------------------------------+ */
-       /* | WID0      | WID0 Length | WID0 Value  | ......................... | */
-       /* +-------------------------------------------------------------------+ */
-       /* | 2 Bytes   | 1 Byte      | WID0 Length | ......................... | */
-       /* +-------------------------------------------------------------------+ */
-
-
-
-       /* Message Type */
-       if (g_oper_mode == SET_CFG)
-               pcpacket[u16MsgInd++] = WRITE_MSG_TYPE;
-       else
-               pcpacket[u16MsgInd++] = QUERY_MSG_TYPE;
-
-       /* Sequence Number */
-       pcpacket[u16MsgInd++] = g_seqno++;
-
-       /* Message Length */
-       pcpacket[u16MsgInd++] = (u8)(u16MsgLen & 0xFF);
-       pcpacket[u16MsgInd++] = (u8)((u16MsgLen >> 8) & 0xFF);
-
-       *ps32PacketLength = u16MsgLen;
-
-       return s32Error;
-}
-
-/**
- *  @brief              creates Configuration packet based on the Input WIDs
- *  @details
- *  @param[in]  pstrWIDs WIDs to be sent in the configuration packet
- *  @param[in]  u32WIDsCount number of WIDs to be sent in the configuration packet
- *  @param[out]         ps8packet The created Configuration Packet
- *  @param[out]         ps32PacketLength Length of the created Configuration Packet
- *  @return     Error code indicating success/failure
- *  @note
- *  @author
- *  @date              1 Mar 2012
- *  @version   1.0
- */
-
-s32 CreateConfigPacket(s8 *ps8packet, s32 *ps32PacketLength,
-                              tstrWID *pstrWIDs, u32 u32WIDsCount)
-{
-       s32 s32Error = WILC_SUCCESS;
-       u32 u32idx = 0;
-       *ps32PacketLength = MSG_HEADER_LEN;
-       for (u32idx = 0; u32idx < u32WIDsCount; u32idx++) {
-               switch (pstrWIDs[u32idx].enuWIDtype) {
-               case WID_CHAR:
-                       ProcessCharWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
-                                      pstrWIDs[u32idx].ps8WidVal);
-                       break;
-
-               case WID_SHORT:
-                       ProcessShortWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
-                                       pstrWIDs[u32idx].ps8WidVal);
-                       break;
-
-               case WID_INT:
-                       ProcessIntWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
-                                     pstrWIDs[u32idx].ps8WidVal);
-                       break;
-
-               case WID_STR:
-                       ProcessStrWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
-                                     pstrWIDs[u32idx].ps8WidVal, pstrWIDs[u32idx].s32ValueSize);
-                       break;
-
-               case WID_IP:
-                       ProcessIPwid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
-                                    pstrWIDs[u32idx].ps8WidVal);
-                       break;
-
-               case WID_BIN_DATA:
-                       ProcessBinWid(ps8packet, ps32PacketLength, &pstrWIDs[u32idx],
-                                     pstrWIDs[u32idx].ps8WidVal, pstrWIDs[u32idx].s32ValueSize);
-                       break;
-
-               default:
-                       PRINT_ER("ERROR: Check Config database\n");
-               }
-       }
-
-       CreatePacketHeader(ps8packet, ps32PacketLength);
-
-       return s32Error;
-}
-
-s32 ConfigWaitResponse(char *pcRespBuffer, s32 s32MaxRespBuffLen, s32 *ps32BytesRead,
-                              bool bRespRequired)
-{
-       s32 s32Error = WILC_SUCCESS;
-       /*bug 3878*/
-       /*removed to caller function*/
-       /*gstrConfigPktInfo.pcRespBuffer = pcRespBuffer;
-        * gstrConfigPktInfo.s32MaxRespBuffLen = s32MaxRespBuffLen;
-        * gstrConfigPktInfo.bRespRequired = bRespRequired;*/
-
-
-       if (gstrConfigPktInfo.bRespRequired) {
-               down(&SemHandlePktResp);
-
-               *ps32BytesRead = gstrConfigPktInfo.s32BytesRead;
-       }
-
-       memset((void *)(&gstrConfigPktInfo), 0, sizeof(tstrConfigPktInfo));
-
-       return s32Error;
-}
-
-s32 ConfigProvideResponse(char *pcRespBuffer, s32 s32RespLen)
-{
-       s32 s32Error = WILC_SUCCESS;
-
-       if (gstrConfigPktInfo.bRespRequired) {
-               if (s32RespLen <= gstrConfigPktInfo.s32MaxRespBuffLen) {
-                       memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, s32RespLen);
-                       gstrConfigPktInfo.s32BytesRead = s32RespLen;
-               } else {
-                       memcpy(gstrConfigPktInfo.pcRespBuffer, pcRespBuffer, gstrConfigPktInfo.s32MaxRespBuffLen);
-                       gstrConfigPktInfo.s32BytesRead = gstrConfigPktInfo.s32MaxRespBuffLen;
-                       PRINT_ER("BusProvideResponse() Response greater than the prepared Buffer Size\n");
-               }
-
-               up(&SemHandlePktResp);
-       }
-
-       return s32Error;
-}
-
-/**
- *  @brief              writes the received packet pu8RxPacket in the global Rx FIFO buffer
- *  @details
- *  @param[in]  pu8RxPacket The received packet
- *  @param[in]  s32RxPacketLen Length of the received packet
- *  @return     Error code indicating success/failure
- *  @note
- *
- *  @author    mabubakr
- *  @date              1 Mar 2012
- *  @version   1.0
- */
-
-s32 ConfigPktReceived(u8 *pu8RxPacket, s32 s32RxPacketLen)
-{
-       s32 s32Error = WILC_SUCCESS;
-       u8 u8MsgType = 0;
-
-       u8MsgType = pu8RxPacket[0];
-
-       switch (u8MsgType) {
-       case 'R':
-               ConfigProvideResponse(pu8RxPacket, s32RxPacketLen);
-
-               break;
-
-       case 'N':
-               PRINT_INFO(CORECONFIG_DBG, "NetworkInfo packet received\n");
-               NetworkInfoReceived(pu8RxPacket, s32RxPacketLen);
-               break;
-
-       case 'I':
-               GnrlAsyncInfoReceived(pu8RxPacket, s32RxPacketLen);
-               break;
-
-       case 'S':
-               host_int_ScanCompleteReceived(pu8RxPacket, s32RxPacketLen);
-               break;
-
-       default:
-               PRINT_ER("ConfigPktReceived(): invalid received msg type at the Core Configurator\n");
-               break;
-       }
-
-       return s32Error;
-}
-
-/**
- *  @brief              Deinitializes the Core Configurator
- *  @details
- *  @return     Error code indicating success/failure
- *  @note
- *  @author    mabubakr
- *  @date              1 Mar 2012
- *  @version   1.0
- */
-
-s32 CoreConfiguratorDeInit(void)
-{
-       s32 s32Error = WILC_SUCCESS;
-
-       PRINT_D(CORECONFIG_DBG, "CoreConfiguratorDeInit()\n");
-
-
-       return s32Error;
-}
-
-/*Using the global handle of the driver*/
-extern wilc_wlan_oup_t *gpstrWlanOps;
 /**
  *  @brief              sends certain Configuration Packet based on the input WIDs pstrWIDs
  *  using driver config layer
@@ -1976,52 +586,40 @@ extern wilc_wlan_oup_t *gpstrWlanOps;
  *  @date              1 Mar 2012
  *  @version   1.0
  */
-s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
-                         u32 u32WIDsCount, bool bRespRequired, u32 drvHandler)
+s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv)
 {
        s32 counter = 0, ret = 0;
-       if (gpstrWlanOps == NULL) {
-               PRINT_D(CORECONFIG_DBG, "Net Dev is still not initialized\n");
-               return 1;
-       } else {
-               PRINT_D(CORECONFIG_DBG, "Net Dev is initialized\n");
-       }
-       if (gpstrWlanOps->wlan_cfg_set == NULL ||
-           gpstrWlanOps->wlan_cfg_get == NULL) {
-               PRINT_D(CORECONFIG_DBG, "Set and Get is still not initialized\n");
-               return 1;
-       } else {
-               PRINT_D(CORECONFIG_DBG, "SET is initialized\n");
-       }
-       if (u8Mode == GET_CFG) {
-               for (counter = 0; counter < u32WIDsCount; counter++) {
+
+       if (mode == GET_CFG) {
+               for (counter = 0; counter < count; counter++) {
                        PRINT_INFO(CORECONFIG_DBG, "Sending CFG packet [%d][%d]\n", !counter,
-                                  (counter == u32WIDsCount - 1));
-                       if (!gpstrWlanOps->wlan_cfg_get(!counter,
-                                                       pstrWIDs[counter].u16WIDid,
-                                                       (counter == u32WIDsCount - 1), drvHandler)) {
+                                  (counter == count - 1));
+                       if (!wilc_wlan_cfg_get(!counter,
+                                              wids[counter].id,
+                                              (counter == count - 1),
+                                              drv)) {
                                ret = -1;
                                printk("[Sendconfigpkt]Get Timed out\n");
                                break;
                        }
                }
-               /**
-                *      get the value
-                **/
                counter = 0;
-               for (counter = 0; counter < u32WIDsCount; counter++) {
-                       pstrWIDs[counter].s32ValueSize = gpstrWlanOps->wlan_cfg_get_value(
-                                       pstrWIDs[counter].u16WIDid,
-                                       pstrWIDs[counter].ps8WidVal, pstrWIDs[counter].s32ValueSize);
+               for (counter = 0; counter < count; counter++) {
+                       wids[counter].size = wilc_wlan_cfg_get_val(
+                                       wids[counter].id,
+                                       wids[counter].val,
+                                       wids[counter].size);
 
                }
-       } else if (u8Mode == SET_CFG) {
-               for (counter = 0; counter < u32WIDsCount; counter++) {
-                       PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", pstrWIDs[counter].u16WIDid);
-                       if (!gpstrWlanOps->wlan_cfg_set(!counter,
-                                                       pstrWIDs[counter].u16WIDid, pstrWIDs[counter].ps8WidVal,
-                                                       pstrWIDs[counter].s32ValueSize,
-                                                       (counter == u32WIDsCount - 1), drvHandler)) {
+       } else if (mode == SET_CFG) {
+               for (counter = 0; counter < count; counter++) {
+                       PRINT_D(CORECONFIG_DBG, "Sending config SET PACKET WID:%x\n", wids[counter].id);
+                       if (!wilc_wlan_cfg_set(!counter,
+                                              wids[counter].id,
+                                              wids[counter].val,
+                                              wids[counter].size,
+                                              (counter == count - 1),
+                                              drv)) {
                                ret = -1;
                                printk("[Sendconfigpkt]Set Timed out\n");
                                break;
index 3af193543cdbae0f1775a867c0eddbfda71ca7bd..6294d929a800ce3532836fbfe0ac7a28f48203ef 100644 (file)
 #define CORECONFIGURATOR_H
 
 #include "wilc_wlan_if.h"
-/*****************************************************************************/
-/* Constants                                                                 */
-/*****************************************************************************/
-/* Number of WID Options Supported */
+
 #define NUM_BASIC_SWITCHES      45
 #define NUM_FHSS_SWITCHES       0
 
 #ifdef MAC_802_11N
 #define NUM_11N_BASIC_SWITCHES  25
 #define NUM_11N_HUT_SWITCHES    47
-#else /* MAC_802_11N */
+#else
 #define NUM_11N_BASIC_SWITCHES  0
 #define NUM_11N_HUT_SWITCHES    0
-#endif /* MAC_802_11N */
-
-extern u16 g_num_total_switches;
+#endif
 
-#define MAC_HDR_LEN             24          /* No Address4 - non-ESS         */
+#define MAC_HDR_LEN             24
 #define MAX_SSID_LEN            33
 #define FCS_LEN                 4
 #define TIME_STAMP_LEN          8
@@ -41,32 +36,20 @@ extern u16 g_num_total_switches;
 #define AID_LEN                 2
 #define IE_HDR_LEN              2
 
-/* Operating Mode: SET */
 #define SET_CFG              0
-/* Operating Mode: GET */
 #define GET_CFG              1
 
-#define MAX_PACKET_BUFF_SIZE 1596
-
 #define MAX_STRING_LEN               256
 #define MAX_SURVEY_RESULT_FRAG_SIZE  MAX_STRING_LEN
 #define SURVEY_RESULT_LENGTH         44
 #define MAX_ASSOC_RESP_FRAME_SIZE    MAX_STRING_LEN
 
-#define STATUS_MSG_LEN               12
 #define MAC_CONNECTED                1
 #define MAC_DISCONNECTED             0
 
-/*****************************************************************************/
-/* Function Macros                                                           */
-/*****************************************************************************/
 #define MAKE_WORD16(lsb, msb) ((((u16)(msb) << 8) & 0xFF00) | (lsb))
 #define MAKE_WORD32(lsw, msw) ((((u32)(msw) << 16) & 0xFFFF0000) | (lsw))
 
-/*****************************************************************************/
-/* Type Definitions                                                                                                                       */
-/*****************************************************************************/
-/* Status Codes for Authentication and Association Frames */
 typedef enum {
        SUCCESSFUL_STATUSCODE    = 0,
        UNSPEC_FAIL              = 1,
@@ -87,20 +70,19 @@ typedef enum {
        CONNECT_STS_FORCE_16_BIT = 0xFFFF
 } tenuConnectSts;
 
-typedef struct {
-       u16 u16WIDid;
-       tenuWIDtype enuWIDtype;
-       s32 s32ValueSize;
-       s8      *ps8WidVal;
-
-} tstrWID;
+struct wid {
+       u16 id;
+       enum WID_TYPE type;
+       s32 size;
+       s8 *val;
+};
 
 typedef struct {
        u8 u8Full;
        u8 u8Index;
        s8 as8RSSI[NUM_RSSI];
 } tstrRSSI;
-/* This structure is used to support parsing of the received 'N' message */
+
 typedef struct {
        s8 s8rssi;
        u16 u16CapInfo;
@@ -110,23 +92,18 @@ typedef struct {
        u16 u16BeaconPeriod;
        u8 u8DtimPeriod;
        u8 u8channel;
-       unsigned long u32TimeRcvdInScanCached; /* of type unsigned long to be accepted by the linux kernel macro time_after() */
+       unsigned long u32TimeRcvdInScanCached;
        unsigned long u32TimeRcvdInScan;
        bool bNewNetwork;
-#ifdef AGING_ALG
        u8 u8Found;
-#endif
-#ifdef WILC_P2P
-       u32 u32Tsf; /* time-stamp [Low only 32 bit] */
-#endif
+       u32 u32Tsf;
        u8 *pu8IEs;
        u16 u16IEsLen;
        void *pJoinParams;
        tstrRSSI strRssi;
-       u64 u64Tsf; /* time-stamp [Low and High 64 bit] */
+       u64 u64Tsf;
 } tstrNetworkInfo;
 
-/* This structure is used to support parsing of the received Association Response frame */
 typedef struct {
        u16 u16capability;
        u16 u16ConnectStatus;
@@ -150,39 +127,14 @@ typedef struct {
        size_t ie_len;
 } tstrDisconnectNotifInfo;
 
-#ifndef CONNECT_DIRECT
-typedef struct wid_site_survey_reslts {
-       char SSID[MAX_SSID_LEN];
-       u8 BssType;
-       u8 Channel;
-       u8 SecurityStatus;
-       u8 BSSID[6];
-       char RxPower;
-       u8 Reserved;
-
-} wid_site_survey_reslts_s;
-#endif
-
-s32 CoreConfiguratorInit(void);
-s32 CoreConfiguratorDeInit(void);
-
-s32 SendConfigPkt(u8 u8Mode, tstrWID *pstrWIDs,
-                 u32 u32WIDsCount, bool bRespRequired, u32 drvHandler);
-s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo);
+s32 send_config_pkt(u8 mode, struct wid *wids, u32 count, u32 drv);
+s32 parse_network_info(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo);
 s32 DeallocateNetworkInfo(tstrNetworkInfo *pstrNetworkInfo);
 
 s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
                       tstrConnectRespInfo **ppstrConnectRespInfo);
 s32 DeallocateAssocRespInfo(tstrConnectRespInfo *pstrConnectRespInfo);
 
-#ifndef CONNECT_DIRECT
-s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
-                      wid_site_survey_reslts_s **ppstrSurveyResults,
-                      u32 *pu32SurveyResultsCount);
-s32 DeallocateSurveyResults(wid_site_survey_reslts_s *pstrSurveyResults);
-#endif
-
-s32 SendRawPacket(s8 *pspacket, s32 s32PacketLen);
 void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length);
 void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length);
 void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length);
index 66fa677015db43e5224eef679b60a690708a7297..dbbe72c7e25572918d4aea2e8c44c00026c790a3 100644 (file)
@@ -1,21 +1,20 @@
+#include <linux/slab.h>
+#include <linux/time.h>
+#include <linux/kthread.h>
+#include <linux/delay.h>
 #include "host_interface.h"
 #include "coreconfigurator.h"
+#include "wilc_wlan_if.h"
+#include "wilc_msgqueue.h"
+#include <linux/etherdevice.h>
+#include "wilc_wfi_netdevice.h"
 
-extern s32 TransportInit(void);
-extern s32 TransportDeInit(void);
 extern u8 connecting;
 
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 extern struct timer_list hDuringIpTimer;
-#endif
 
-/*BugID_5137*/
 extern u8 g_wilc_initialized;
-/*****************************************************************************/
-/*                                                             Macros                                       */
-/*****************************************************************************/
 
-/* Message types of the Host IF Message Queue*/
 #define HOST_IF_MSG_SCAN                        0
 #define HOST_IF_MSG_CONNECT                     1
 #define HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO        2
@@ -62,432 +61,155 @@ extern u8 g_wilc_initialized;
 #define BA_SESSION_DEFAULT_BUFFER_SIZE          16
 #define BA_SESSION_DEFAULT_TIMEOUT              1000
 #define BLOCK_ACK_REQ_SIZE                      0x14
-/*****************************************************************************/
-/*                                                             Type Definitions                                                         */
-/*****************************************************************************/
-
-/*!
- *  @struct             tstrHostIFCfgParamAttr
- *  @brief             Structure to hold Host IF CFG Params Attributes
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              02 April 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFCfgParamAttr {
-       tstrCfgParamVal pstrCfgParamVal;
-
-} tstrHostIFCfgParamAttr;
-
-/*!
- *  @struct             tstrHostIFwpaAttr
- *  @brief             Structure to hold Host IF Scan Attributes
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFwpaAttr {
-       u8 *pu8key;
-       const u8 *pu8macaddr;
-       u8 *pu8seq;
-       u8 u8seqlen;
-       u8 u8keyidx;
-       u8 u8Keylen;
-       u8 u8Ciphermode;
-} tstrHostIFwpaAttr;
-
-
-/*!
- *  @struct             tstrHostIFwepAttr
- *  @brief             Structure to hold Host IF Scan Attributes
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFwepAttr {
-       u8 *pu8WepKey;
-       u8 u8WepKeylen;
-       u8 u8Wepidx;
-       u8 u8mode;
-       AUTHTYPE_T tenuAuth_type;
-
-} tstrHostIFwepAttr;
-
-/*!
- *  @struct             tuniHostIFkeyAttr
- *  @brief             Structure to hold Host IF Scan Attributes
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef union _tuniHostIFkeyAttr {
-       tstrHostIFwepAttr strHostIFwepAttr;
-       tstrHostIFwpaAttr strHostIFwpaAttr;
-       tstrHostIFpmkidAttr strHostIFpmkidAttr;
-} tuniHostIFkeyAttr;
-
-/*!
- *  @struct             tstrHostIFkeyAttr
- *  @brief             Structure to hold Host IF Scan Attributes
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFkeyAttr {
-       tenuKeyType enuKeyType;
-       u8 u8KeyAction;
-       tuniHostIFkeyAttr uniHostIFkeyAttr;
-} tstrHostIFkeyAttr;
-
-
-
-
-/*!
- *  @struct             tstrHostIFscanAttr
- *  @brief             Structure to hold Host IF Scan Attributes
- *  @details
- *  @todo
- *  @sa
- *  @author            Mostafa Abu Bakr
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFscanAttr {
-       u8 u8ScanSource;
-       u8 u8ScanType;
-       u8 *pu8ChnlFreqList;
-       u8 u8ChnlListLen;
-       u8 *pu8IEs;
-       size_t IEsLen;
-       tWILCpfScanResult pfScanResult;
-       void *pvUserArg;
-       /*BugID_4189*/
-       tstrHiddenNetwork strHiddenNetwork;
-
-} tstrHostIFscanAttr;
-
-/*!
- *  @struct             tstrHostIFconnectAttr
- *  @brief             Structure to hold Host IF Connect Attributes
- *  @details
- *  @todo
- *  @sa
- *  @author            Mostafa Abu Bakr
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFconnectAttr {
-       u8 *pu8bssid;
-       u8 *pu8ssid;
-       size_t ssidLen;
-       u8 *pu8IEs;
-       size_t IEsLen;
-       u8 u8security;
-       tWILCpfConnectResult pfConnectResult;
-       void *pvUserArg;
-       AUTHTYPE_T tenuAuth_type;
-       u8 u8channel;
-       void *pJoinParams;
-} tstrHostIFconnectAttr;
-
-/*!
- *  @struct             tstrRcvdGnrlAsyncInfo
- *  @brief             Structure to hold Received General Asynchronous info
- *  @details
- *  @todo
- *  @sa
- *  @author            Mostafa Abu Bakr
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrRcvdGnrlAsyncInfo {
-       u8 *pu8Buffer;
-       u32 u32Length;
-} tstrRcvdGnrlAsyncInfo;
-
-/*!
- *  @struct             tstrHostIFSetChan
- *  @brief             Set Channel  message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFSetChan {
-       u8 u8SetChan;
-} tstrHostIFSetChan;
-
-/*!
- *  @struct             tstrHostIFSetChan
- *  @brief             Get Channel  message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              01 Jule 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFGetChan {
-       u8 u8GetChan;
-} tstrHostIFGetChan;
-
-/*bug3819: Add Scan acomplete notification to host*/
-/*!
- *  @struct             tstrScanComplete
- *  @brief                     hold received Async. Scan Complete message body
- *  @details
- *  @todo
- *  @sa
- *  @author            zsalah
- *  @date              25 March 2012
- *  @version           1.0
- */
-/*typedef struct _tstrScanComplete
- * {
- *      u8* pu8Buffer;
- *      u32 u32Length;
- * } tstrScanComplete;*/
-
-/*!
- *  @struct             tstrHostIFSetBeacon
- *  @brief             Set Beacon  message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Adham Abozaeid
- *  @date              10 July 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFSetBeacon {
-       u32 u32Interval;                        /*!< Beacon Interval. Period between two successive beacons on air  */
-       u32 u32DTIMPeriod;              /*!< DTIM Period. Indicates how many Beacon frames
-                                                                                       *                              (including the current frame) appear before the next DTIM                */
-       u32 u32HeadLen;                         /*!< Length of the head buffer in bytes         */
-       u8 *pu8Head;                    /*!< Pointer to the beacon's head buffer. Beacon's head is the part
-                                                                                       *              from the beacon's start till the TIM element, NOT including the TIM              */
-       u32 u32TailLen;                         /*!< Length of the tail buffer in bytes */
-       u8 *pu8Tail;                    /*!< Pointer to the beacon's tail buffer. Beacon's tail starts just
-                                                                                       *                              after the TIM inormation element */
-} tstrHostIFSetBeacon;
-
-
-
-/*!
- *  @struct             tstrHostIFDelBeacon
- *  @brief             Del Beacon  message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Adham Abozaeid
- *  @date              15 July 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFDelBeacon {
-       u8 u8dummy;
-} tstrHostIFDelBeacon;
-
-/*!
- *  @struct             tstrHostIFSetMulti
- *  @brief             set Multicast filter Address
- *  @details
- *  @todo
- *  @sa
- *  @author            Abdelrahman Sobhy
- *  @date              30 August 2013
- *  @version           1.0 Description
- */
-
-typedef struct {
-       bool bIsEnabled;
-       u32 u32count;
-} tstrHostIFSetMulti;
-
-/*!
- *  @struct             tstrHostIFDelAllSta
- *  @brief             Deauth station message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Mai Daftedar
- *  @date              09 April 2014
- *  @version           1.0 Description
- */
-
-typedef struct {
-       u8 au8Sta_DelAllSta[MAX_NUM_STA][ETH_ALEN];
-       u8 u8Num_AssocSta;
-} tstrHostIFDelAllSta;
-
-/*!
- *  @struct             tstrHostIFDelSta
- *  @brief             Delete station message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Adham Abozaeid
- *  @date              15 July 2012
- *  @version           1.0 Description
- */
-
-typedef struct {
-       u8 au8MacAddr[ETH_ALEN];
-} tstrHostIFDelSta;
-
-/*!
- *  @struct             tstrTimerCb
- *  @brief             Timer callback message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Mostafa Abu Bakr
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrTimerCb {
-       void *pvUsrArg;                 /*!< Private data passed at timer start */
-} tstrTimerCb;
-
-/*!
- *  @struct     tstrHostIfPowerMgmtParam
- *  @brief             Power management message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Adham Abozaeid
- *  @date              24 November 2012
- *  @version           1.0
- */
-typedef struct {
-
-       bool bIsEnabled;
-       u32 u32Timeout;
-} tstrHostIfPowerMgmtParam;
-
-/*!
- *  @struct             tstrHostIFSetIPAddr
- *  @brief             set IP Address message body
- *  @details
- *  @todo
- *  @sa
- *  @author            Abdelrahman Sobhy
- *  @date              30 August 2013
- *  @version           1.0 Description
- */
-
-typedef struct {
-       u8 *au8IPAddr;
+#define FALSE_FRMWR_CHANNEL                    100
+
+struct cfg_param_attr {
+       struct cfg_param_val cfg_attr_info;
+};
+
+struct host_if_wpa_attr {
+       u8 *key;
+       const u8 *mac_addr;
+       u8 *seq;
+       u8 seq_len;
+       u8 index;
+       u8 key_len;
+       u8 mode;
+};
+
+struct host_if_wep_attr {
+       u8 *key;
+       u8 key_len;
+       u8 index;
+       u8 mode;
+       enum AUTHTYPE auth_type;
+};
+
+union host_if_key_attr {
+       struct host_if_wep_attr wep;
+       struct host_if_wpa_attr wpa;
+       struct host_if_pmkid_attr pmkid;
+};
+
+struct key_attr {
+       enum KEY_TYPE type;
+       u8 action;
+       union host_if_key_attr attr;
+};
+
+struct scan_attr {
+       u8 src;
+       u8 type;
+       u8 *ch_freq_list;
+       u8 ch_list_len;
+       u8 *ies;
+       size_t ies_len;
+       wilc_scan_result result;
+       void *arg;
+       struct hidden_network hidden_network;
+};
+
+struct connect_attr {
+       u8 *bssid;
+       u8 *ssid;
+       size_t ssid_len;
+       u8 *ies;
+       size_t ies_len;
+       u8 security;
+       wilc_connect_result result;
+       void *arg;
+       enum AUTHTYPE auth_type;
+       u8 ch;
+       void *params;
+};
+
+struct rcvd_async_info {
+       u8 *buffer;
+       u32 len;
+};
+
+struct channel_attr {
+       u8 set_ch;
+};
+
+struct beacon_attr {
+       u32 interval;
+       u32 dtim_period;
+       u32 head_len;
+       u8 *head;
+       u32 tail_len;
+       u8 *tail;
+};
+
+struct set_multicast {
+       bool enabled;
+       u32 cnt;
+};
+
+struct del_all_sta {
+       u8 del_all_sta[MAX_NUM_STA][ETH_ALEN];
+       u8 assoc_sta;
+};
+
+struct del_sta {
+       u8 mac_addr[ETH_ALEN];
+};
+
+struct power_mgmt_param {
+       bool enabled;
+       u32 timeout;
+};
+
+struct set_ip_addr {
+       u8 *ip_addr;
        u8 idx;
-} tstrHostIFSetIPAddr;
-
-/*!
- *  @struct     tstrHostIfStaInactiveT
- *  @brief             Get station message body
- *  @details
- *  @todo
- *  @sa
- *  @author        Mai Daftedar
- *  @date              16 April 2013
- *  @version           1.0
- */
-typedef struct {
-       u8 mac[6];
+};
 
-} tstrHostIfStaInactiveT;
-/**/
-/*!
- *  @union              tuniHostIFmsgBody
- *  @brief             Message body for the Host Interface message_q
- *  @details
- *  @todo
- *  @sa
- *  @author            Mostafa Abu Bakr
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef union _tuniHostIFmsgBody {
-       tstrHostIFscanAttr strHostIFscanAttr;                           /*!< Host IF Scan Request Attributes message body */
-       tstrHostIFconnectAttr strHostIFconnectAttr;     /*!< Host IF Connect Request Attributes message body */
-       tstrRcvdNetworkInfo strRcvdNetworkInfo;                 /*!< Received Asynchronous Network Info message body */
-       tstrRcvdGnrlAsyncInfo strRcvdGnrlAsyncInfo;     /*!< Received General Asynchronous Info message body */
-       tstrHostIFkeyAttr strHostIFkeyAttr;                             /*!<>*/
-       tstrHostIFCfgParamAttr strHostIFCfgParamAttr;            /*! <CFG Parameter message Body> */
-       tstrHostIFSetChan strHostIFSetChan;
-       tstrHostIFGetChan strHostIFGetChan;
-       tstrHostIFSetBeacon strHostIFSetBeacon;                 /*!< Set beacon message body */
-       tstrHostIFDelBeacon strHostIFDelBeacon;                 /*!< Del beacon message body */
-       tstrWILC_AddStaParam strAddStaParam;                    /*!< Add station message body */
-       tstrHostIFDelSta strDelStaParam;                                /*!< Del Station message body */
-       tstrWILC_AddStaParam strEditStaParam;                           /*!< Edit station message body */
-       /* tstrScanComplete             strScanComplete;                / *Received Async. Scan Complete message body* / */
-       tstrTimerCb strTimerCb;                                                 /*!< Timer callback message body */
-       tstrHostIfPowerMgmtParam strPowerMgmtparam;     /*!< Power Management message body */
-       tstrHostIfStaInactiveT strHostIfStaInactiveT;
-       tstrHostIFSetIPAddr strHostIfSetIP;
-       tstrHostIfSetDrvHandler strHostIfSetDrvHandler;
-       tstrHostIFSetMulti strHostIfSetMulti;
-       tstrHostIfSetOperationMode strHostIfSetOperationMode;
-       tstrHostIfSetMacAddress strHostIfSetMacAddress;
-       tstrHostIfGetMacAddress strHostIfGetMacAddress;
-       tstrHostIfBASessionInfo strHostIfBASessionInfo;
-       #ifdef WILC_P2P
-       tstrHostIfRemainOnChan strHostIfRemainOnChan;
-       tstrHostIfRegisterFrame strHostIfRegisterFrame;
-       #endif
-       char *pUserData;
-       tstrHostIFDelAllSta strHostIFDelAllSta;
-} tuniHostIFmsgBody;
-
-/*!
- *  @struct             tstrHostIFmsg
- *  @brief             Host Interface message
- *  @details
- *  @todo
- *  @sa
- *  @author            Mostafa Abu Bakr
- *  @date              25 March 2012
- *  @version           1.0
- */
-typedef struct _tstrHostIFmsg {
-       u16 u16MsgId;                                           /*!< Message ID */
-       tuniHostIFmsgBody uniHostIFmsgBody;             /*!< Message body */
-       tstrWILC_WFIDrv *drvHandler;
-} tstrHostIFmsg;
-
-#ifdef CONNECT_DIRECT
-typedef struct _tstrWidJoinReqExt {
-       char SSID[MAX_SSID_LEN];
-       u8 u8channel;
-       u8 BSSID[6];
-} tstrWidJoinReqExt;
-#endif
-
-/*Bug4218: Parsing Join Param*/
-#ifdef WILC_PARSE_SCAN_IN_HOST
-/*Struct containg joinParam of each AP*/
-typedef struct _tstrJoinBssParam {
+struct sta_inactive_t {
+       u8 mac[6];
+};
+
+union message_body {
+       struct scan_attr scan_info;
+       struct connect_attr con_info;
+       struct rcvd_net_info net_info;
+       struct rcvd_async_info async_info;
+       struct key_attr key_info;
+       struct cfg_param_attr cfg_info;
+       struct channel_attr channel_info;
+       struct beacon_attr beacon_info;
+       struct add_sta_param add_sta_info;
+       struct del_sta del_sta_info;
+       struct add_sta_param edit_sta_info;
+       struct power_mgmt_param pwr_mgmt_info;
+       struct sta_inactive_t mac_info;
+       struct set_ip_addr ip_info;
+       struct drv_handler drv;
+       struct set_multicast multicast_info;
+       struct op_mode mode;
+       struct set_mac_addr set_mac_info;
+       struct get_mac_addr get_mac_info;
+       struct ba_session_info session_info;
+       struct remain_ch remain_on_ch;
+       struct reg_frame reg_frame;
+       char *data;
+       struct del_all_sta del_all_sta_info;
+};
+
+struct host_if_msg {
+       u16 id;
+       union message_body body;
+       struct host_if_drv *drv;
+};
+
+struct join_bss_param {
        BSSTYPE_T bss_type;
        u8 dtim_period;
        u16 beacon_period;
        u16 cap_info;
        u8 au8bssid[6];
        char ssid[MAX_SSID_LEN];
-       u8 ssidLen;
+       u8 ssid_len;
        u8 supp_rates[MAX_RATES_SUPPORTED + 1];
        u8 ht_capable;
        u8 wmm_cap;
@@ -498,1398 +220,949 @@ typedef struct _tstrJoinBssParam {
        u8 rsn_pcip_policy[3];
        u8 rsn_auth_policy[3];
        u8 rsn_cap[2];
-       struct _tstrJoinParam *nextJoinBss;
-       #ifdef WILC_P2P
        u32 tsf;
-       u8 u8NoaEnbaled;
-       u8 u8OppEnable;
-       u8 u8CtWindow;
-       u8 u8Count;
-       u8 u8Index;
-       u8 au8Duration[4];
-       u8 au8Interval[4];
-       u8 au8StartTime[4];
-       #endif
-} tstrJoinBssParam;
-/*Bug4218: Parsing Join Param*/
-/*a linked list table containing needed join parameters entries for each AP found in most recent scan*/
-typedef struct _tstrBssTable {
-       u8 u8noBssEntries;
-       tstrJoinBssParam *head;
-       tstrJoinBssParam *tail;
-} tstrBssTable;
-#endif /*WILC_PARSE_SCAN_IN_HOST*/
-
-typedef enum {
-       SCAN_TIMER = 0,
-       CONNECT_TIMER   = 1,
-       SCAN_CONNECT_TIMER_FORCE_32BIT = 0xFFFFFFFF
-} tenuScanConnTimer;
-
-/*****************************************************************************/
-/*                                                                                                                                                      */
-/*                                                     Global Variabls                                                                  */
-/*                                                                                                                                                      */
-/*****************************************************************************/
-
-
-tstrWILC_WFIDrv *terminated_handle;
-tstrWILC_WFIDrv *gWFiDrvHandle;
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
-bool g_obtainingIP = false;
-#endif
+       u8 noa_enabled;
+       u8 opp_enabled;
+       u8 ct_window;
+       u8 cnt;
+       u8 idx;
+       u8 duration[4];
+       u8 interval[4];
+       u8 start_time[4];
+};
+
+static struct host_if_drv *wfidrv_list[NUM_CONCURRENT_IFC + 1];
+struct host_if_drv *terminated_handle;
+bool g_obtainingIP;
 u8 P2P_LISTEN_STATE;
-static struct task_struct *HostIFthreadHandler;
-static WILC_MsgQueueHandle gMsgQHostIF;
-static struct semaphore hSemHostIFthrdEnd;
+static struct task_struct *hif_thread_handler;
+static WILC_MsgQueueHandle hif_msg_q;
+static struct semaphore hif_sema_thread;
+static struct semaphore hif_sema_driver;
+static struct semaphore hif_sema_wait_response;
+static struct semaphore hif_sema_deinit;
+static struct timer_list periodic_rssi;
 
-struct semaphore hSemDeinitDrvHandle;
-static struct semaphore hWaitResponse;
-struct semaphore hSemHostIntDeinit;
-struct timer_list g_hPeriodicRSSI;
+u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
 
+static u8 rcv_assoc_resp[MAX_ASSOC_RESP_FRAME_SIZE];
 
+static bool scan_while_connected;
 
-u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
+static s8 rssi;
+static s8 link_speed;
+static u8 ch_no;
+static u8 set_ip[2][4];
+static u8 get_ip[2][4];
+static u32 inactive_time;
+static u8 del_beacon;
+static u32 clients_count;
 
-#ifndef CONNECT_DIRECT
-static u8 gapu8RcvdSurveyResults[2][MAX_SURVEY_RESULT_FRAG_SIZE];
-#endif
-
-static u8 gapu8RcvdAssocResp[MAX_ASSOC_RESP_FRAME_SIZE];
-
-bool gbScanWhileConnected = false;
-
-static s8 gs8Rssi;
-static s8 gs8lnkspd;
-static u8 gu8Chnl;
-static u8 gs8SetIP[2][4];
-static u8 gs8GetIP[2][4];
-#ifdef WILC_AP_EXTERNAL_MLME
-static u32 gu32InactiveTime;
-static u8 gu8DelBcn;
-#endif
-static u32 gu32WidConnRstHack;
-
-/*BugID_5137*/
-u8 *gu8FlushedJoinReq;
-u8 *gu8FlushedInfoElemAsoc;
-u8 gu8Flushed11iMode;
-u8 gu8FlushedAuthType;
-u32 gu32FlushedJoinReqSize;
-u32 gu32FlushedInfoElemAsocSize;
-u32 gu8FlushedJoinReqDrvHandler;
+static u8 *join_req;
+u8 *info_element;
+static u8 mode_11i;
+u8 auth_type;
+u32 join_req_size;
+static u32 info_element_size;
+static struct host_if_drv *join_req_drv;
 #define REAL_JOIN_REQ 0
 #define FLUSHED_JOIN_REQ 1
-#define FLUSHED_BYTE_POS 79     /* Position the byte indicating flushing in the flushed request */
+#define FLUSHED_BYTE_POS 79
 
-/*Bug4218: Parsing Join Param*/
-#ifdef WILC_PARSE_SCAN_IN_HOST
-/*Bug4218: Parsing Join Param*/
 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo);
-#endif /*WILC_PARSE_SCAN_IN_HOST*/
 
 extern void chip_sleep_manually(u32 u32SleepTime);
 extern int linux_wlan_get_num_conn_ifcs(void);
 
-/**
- *  @brief Handle_SetChannel
- *  @details    Sending config packet to firmware to set channel
- *  @param[in]   tstrHostIFSetChan* pstrHostIFSetChan
- *  @return     Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_SetChannel(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetChan *pstrHostIFSetChan)
+static int add_handler_in_list(struct host_if_drv *handler)
 {
+       int i;
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
+               if (!wfidrv_list[i]) {
+                       wfidrv_list[i] = handler;
+                       return 0;
+               }
+       }
 
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_CURRENT_CHANNEL;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = (char *)&(pstrHostIFSetChan->u8SetChan);
-       strWID.s32ValueSize = sizeof(char);
+       return -ENOBUFS;
+}
 
-       PRINT_D(HOSTINF_DBG, "Setting channel\n");
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
-               PRINT_ER("Failed to set channel\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       }
-       WILC_CATCH(s32Error)
-       {
+static int remove_handler_in_list(struct host_if_drv *handler)
+{
+       int i;
 
+       for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
+               if (wfidrv_list[i] == handler) {
+                       wfidrv_list[i] = NULL;
+                       return 0;
+               }
        }
 
-       return s32Error;
+       return -EINVAL;
 }
-/**
- *  @brief Handle_SetWfiDrvHandler
- *  @details    Sending config packet to firmware to set driver handler
- *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
- *  @return     Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_SetWfiDrvHandler(tstrHostIfSetDrvHandler *pstrHostIfSetDrvHandler)
-{
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)((pstrHostIfSetDrvHandler->u32Address));
+static int get_id_from_handler(struct host_if_drv *handler)
+{
+       int i;
 
+       if (!handler)
+               return 0;
 
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_SET_DRV_HANDLER;
-       strWID.enuWIDtype = WID_INT;
-       strWID.ps8WidVal = (s8 *)&(pstrHostIfSetDrvHandler->u32Address);
-       strWID.s32ValueSize = sizeof(u32);
+       for (i = 1; i < ARRAY_SIZE(wfidrv_list); i++) {
+               if (wfidrv_list[i] == handler)
+                       return i;
+       }
 
-       /*Sending Cfg*/
+       return 0;
+}
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+static struct host_if_drv *get_handler_from_id(int id)
+{
+       if (id <= 0 || id >= ARRAY_SIZE(wfidrv_list))
+               return NULL;
+       return wfidrv_list[id];
+}
 
+static s32 Handle_SetChannel(struct host_if_drv *hif_drv,
+                            struct channel_attr *pstrHostIFSetChan)
+{
+       s32 result = 0;
+       struct wid wid;
 
-       if ((pstrHostIfSetDrvHandler->u32Address) == (u32)NULL)
-               up(&hSemDeinitDrvHandle);
+       wid.id = (u16)WID_CURRENT_CHANNEL;
+       wid.type = WID_CHAR;
+       wid.val = (char *)&pstrHostIFSetChan->set_ch;
+       wid.size = sizeof(char);
 
+       PRINT_D(HOSTINF_DBG, "Setting channel\n");
 
-       if (s32Error) {
-               PRINT_ER("Failed to set driver handler\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       }
-       WILC_CATCH(s32Error)
-       {
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
+       if (result) {
+               PRINT_ER("Failed to set channel\n");
+               return -EINVAL;
        }
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief Handle_SetWfiAPDrvHandler
- *  @details    Sending config packet to firmware to set driver handler
- *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
- *  @return     Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_SetOperationMode(tstrWILC_WFIDrv *drvHandler, tstrHostIfSetOperationMode *pstrHostIfSetOperationMode)
+static s32 Handle_SetWfiDrvHandler(struct host_if_drv *hif_drv,
+                                  struct drv_handler *pstrHostIfSetDrvHandler)
 {
+       s32 result = 0;
+       struct wid wid;
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       wid.id = (u16)WID_SET_DRV_HANDLER;
+       wid.type = WID_INT;
+       wid.val = (s8 *)&pstrHostIfSetDrvHandler->handler;
+       wid.size = sizeof(u32);
 
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                pstrHostIfSetDrvHandler->handler);
 
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_SET_OPERATION_MODE;
-       strWID.enuWIDtype = WID_INT;
-       strWID.ps8WidVal = (s8 *)&(pstrHostIfSetOperationMode->u32Mode);
-       strWID.s32ValueSize = sizeof(u32);
+       if (!hif_drv)
+               up(&hif_sema_driver);
 
-       /*Sending Cfg*/
-       PRINT_INFO(HOSTINF_DBG, "pstrWFIDrv= %p\n", pstrWFIDrv);
+       if (result) {
+               PRINT_ER("Failed to set driver handler\n");
+               return -EINVAL;
+       }
+
+       return result;
+}
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+static s32 Handle_SetOperationMode(struct host_if_drv *hif_drv,
+                                  struct op_mode *pstrHostIfSetOperationMode)
+{
+       s32 result = 0;
+       struct wid wid;
 
+       wid.id = (u16)WID_SET_OPERATION_MODE;
+       wid.type = WID_INT;
+       wid.val = (s8 *)&pstrHostIfSetOperationMode->mode;
+       wid.size = sizeof(u32);
 
-       if ((pstrHostIfSetOperationMode->u32Mode) == (u32)NULL)
-               up(&hSemDeinitDrvHandle);
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
+       if ((pstrHostIfSetOperationMode->mode) == IDLE_MODE)
+               up(&hif_sema_driver);
 
-       if (s32Error) {
+       if (result) {
                PRINT_ER("Failed to set driver handler\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       }
-       WILC_CATCH(s32Error)
-       {
-
+               return -EINVAL;
        }
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief host_int_set_IPAddress
- *  @details       Setting IP address params in message queue
- *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u8* pu8IPAddr
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 Handle_set_IPAddress(tstrWILC_WFIDrv *drvHandler, u8 *pu8IPAddr, u8 idx)
+s32 Handle_set_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx)
 {
-
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        char firmwareIPAddress[4] = {0};
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
        if (pu8IPAddr[0] < 192)
                pu8IPAddr[0] = 0;
 
        PRINT_INFO(HOSTINF_DBG, "Indx = %d, Handling set  IP = %pI4\n", idx, pu8IPAddr);
 
-       memcpy(gs8SetIP[idx], pu8IPAddr, IP_ALEN);
-
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_IP_ADDRESS;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = (u8 *)pu8IPAddr;
-       strWID.s32ValueSize = IP_ALEN;
+       memcpy(set_ip[idx], pu8IPAddr, IP_ALEN);
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       wid.id = (u16)WID_IP_ADDRESS;
+       wid.type = WID_STR;
+       wid.val = (u8 *)pu8IPAddr;
+       wid.size = IP_ALEN;
 
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
+       host_int_get_ipaddress(hif_drv, firmwareIPAddress, idx);
 
-       host_int_get_ipaddress(drvHandler, firmwareIPAddress, idx);
-
-       if (s32Error) {
-               PRINT_D(HOSTINF_DBG, "Failed to set IP address\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       } else {
-               PRINT_INFO(HOSTINF_DBG, "IP address set\n");
+       if (result) {
+               PRINT_ER("Failed to set IP address\n");
+               return -EINVAL;
        }
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
+       PRINT_INFO(HOSTINF_DBG, "IP address set\n");
 
-       return s32Error;
+       return result;
 }
 
-
-/**
- *  @brief Handle_get_IPAddress
- *  @details       Setting IP address params in message queue
- *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u8* pu8IPAddr
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 Handle_get_IPAddress(tstrWILC_WFIDrv *drvHandler, u8 *pu8IPAddr, u8 idx)
+s32 Handle_get_IPAddress(struct host_if_drv *hif_drv, u8 *pu8IPAddr, u8 idx)
 {
+       s32 result = 0;
+       struct wid wid;
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       wid.id = (u16)WID_IP_ADDRESS;
+       wid.type = WID_STR;
+       wid.val = kmalloc(IP_ALEN, GFP_KERNEL);
+       wid.size = IP_ALEN;
 
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_IP_ADDRESS;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = WILC_MALLOC(IP_ALEN);
-       strWID.s32ValueSize = IP_ALEN;
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+       PRINT_INFO(HOSTINF_DBG, "%pI4\n", wid.val);
 
-       PRINT_INFO(HOSTINF_DBG, "%pI4\n", strWID.ps8WidVal);
+       memcpy(get_ip[idx], wid.val, IP_ALEN);
 
-       memcpy(gs8GetIP[idx], strWID.ps8WidVal, IP_ALEN);
+       kfree(wid.val);
 
-       /*get the value by searching the local copy*/
-       kfree(strWID.ps8WidVal);
+       if (memcmp(get_ip[idx], set_ip[idx], IP_ALEN) != 0)
+               host_int_setup_ipaddress(hif_drv, set_ip[idx], idx);
 
-       if (memcmp(gs8GetIP[idx], gs8SetIP[idx], IP_ALEN) != 0)
-               host_int_setup_ipaddress(pstrWFIDrv, gs8SetIP[idx], idx);
-
-       if (s32Error != WILC_SUCCESS) {
+       if (result != 0) {
                PRINT_ER("Failed to get IP address\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       } else {
-               PRINT_INFO(HOSTINF_DBG, "IP address retrieved:: u8IfIdx = %d\n", idx);
-               PRINT_INFO(HOSTINF_DBG, "%pI4\n", gs8GetIP[idx]);
-               PRINT_INFO(HOSTINF_DBG, "\n");
+               return -EINVAL;
        }
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
+       PRINT_INFO(HOSTINF_DBG, "IP address retrieved:: u8IfIdx = %d\n", idx);
+       PRINT_INFO(HOSTINF_DBG, "%pI4\n", get_ip[idx]);
+       PRINT_INFO(HOSTINF_DBG, "\n");
 
-       return s32Error;
+       return result;
 }
 
-
-/*BugId_5077*/
-/**
- *  @brief Handle_SetMacAddress
- *  @details    Setting mac address
- *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
- *  @return     Error code.
- *  @author    Amr Abdel-Moghny
- *  @date              November 2013
- *  @version   7.0
- */
-static s32 Handle_SetMacAddress(tstrWILC_WFIDrv *drvHandler, tstrHostIfSetMacAddress *pstrHostIfSetMacAddress)
+static s32 Handle_SetMacAddress(struct host_if_drv *hif_drv,
+                               struct set_mac_addr *pstrHostIfSetMacAddress)
 {
+       s32 result = 0;
+       struct wid wid;
+       u8 *mac_buf = kmalloc(ETH_ALEN, GFP_KERNEL);
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-       u8 *mac_buf = WILC_MALLOC(ETH_ALEN);
-
-       if (mac_buf == NULL) {
+       if (!mac_buf) {
                PRINT_ER("No buffer to send mac address\n");
-               return WILC_FAIL;
-       }
-       memcpy(mac_buf, pstrHostIfSetMacAddress->u8MacAddress, ETH_ALEN);
-
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_MAC_ADDR;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = mac_buf;
-       strWID.s32ValueSize = ETH_ALEN;
-       PRINT_D(GENERIC_DBG, "mac addr = :%x:%x:%x:%x:%x:%x\n", strWID.ps8WidVal[0], strWID.ps8WidVal[1], strWID.ps8WidVal[2], strWID.ps8WidVal[3], strWID.ps8WidVal[4], strWID.ps8WidVal[5]);
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
-               PRINT_ER("Failed to set mac address\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+               return -EFAULT;
        }
+       memcpy(mac_buf, pstrHostIfSetMacAddress->mac_addr, ETH_ALEN);
 
-       WILC_CATCH(s32Error)
-       {
+       wid.id = (u16)WID_MAC_ADDR;
+       wid.type = WID_STR;
+       wid.val = mac_buf;
+       wid.size = ETH_ALEN;
+       PRINT_D(GENERIC_DBG, "mac addr = :%pM\n", wid.val);
 
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result) {
+               PRINT_ER("Failed to set mac address\n");
+               result = -EFAULT;
        }
+
        kfree(mac_buf);
-       return s32Error;
+       return result;
 }
 
-
-/*BugID_5213*/
-/**
- *  @brief Handle_GetMacAddress
- *  @details    Getting mac address
- *  @param[in]   void * drvHandler,tstrHostIfSetDrvHandler* pstrHostIfSetDrvHandler
- *  @return     Error code.
- *  @author    Amr Abdel-Moghny
- *  @date              JAN 2013
- *  @version   8.0
- */
-static s32 Handle_GetMacAddress(tstrWILC_WFIDrv *drvHandler, tstrHostIfGetMacAddress *pstrHostIfGetMacAddress)
+static s32 Handle_GetMacAddress(struct host_if_drv *hif_drv,
+                               struct get_mac_addr *pstrHostIfGetMacAddress)
 {
+       s32 result = 0;
+       struct wid wid;
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       wid.id = (u16)WID_MAC_ADDR;
+       wid.type = WID_STR;
+       wid.val = pstrHostIfGetMacAddress->mac_addr;
+       wid.size = ETH_ALEN;
 
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_MAC_ADDR;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = pstrHostIfGetMacAddress->u8MacAddress;
-       strWID.s32ValueSize = ETH_ALEN;
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, false, (u32)drvHandler);
-       if (s32Error) {
+       if (result) {
                PRINT_ER("Failed to get mac address\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+               result = -EFAULT;
        }
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       up(&hWaitResponse);
+       up(&hif_sema_wait_response);
 
-       return s32Error;
+       return result;
 }
 
-
-/**
- *  @brief Handle_CfgParam
- *  @details    Sending config packet to firmware to set CFG params
- *  @param[in]   tstrHostIFCfgParamAttr* strHostIFCfgParamAttr
- *  @return     Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_CfgParam(tstrWILC_WFIDrv *drvHandler, tstrHostIFCfgParamAttr *strHostIFCfgParamAttr)
+static s32 Handle_CfgParam(struct host_if_drv *hif_drv,
+                          struct cfg_param_attr *strHostIFCfgParamAttr)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWIDList[32];
+       s32 result = 0;
+       struct wid strWIDList[32];
        u8 u8WidCnt = 0;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
-
-       down(&(pstrWFIDrv->gtOsCfgValuesSem));
 
+       down(&hif_drv->gtOsCfgValuesSem);
 
        PRINT_D(HOSTINF_DBG, "Setting CFG params\n");
 
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & BSS_TYPE) {
-               /*----------------------------------------------------------*/
-               /*Input Value:  INFRASTRUCTURE = 1,                                                     */
-               /*                              INDEPENDENT= 2,                                                         */
-               /*                              ANY_BSS= 3                                                                      */
-               /*----------------------------------------------------------*/
-               /* validate input then copy>> need to check value 4 and 5 */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.bss_type < 6) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_BSS_TYPE;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.bss_type;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.bss_type = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.bss_type;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & BSS_TYPE) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.bss_type < 6) {
+                       strWIDList[u8WidCnt].id = WID_BSS_TYPE;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.bss_type;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.bss_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.bss_type;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("check value 6 over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & AUTH_TYPE) {
-               /*------------------------------------------------------*/
-               /*Input Values: OPEN_SYSTEM     = 0,                                    */
-               /*                              SHARED_KEY      = 1,                                    */
-               /*                              ANY             = 2                                             */
-               /*------------------------------------------------------*/
-               /*validate Possible values*/
-               if ((strHostIFCfgParamAttr->pstrCfgParamVal.auth_type) == 1 || (strHostIFCfgParamAttr->pstrCfgParamVal.auth_type) == 2 || (strHostIFCfgParamAttr->pstrCfgParamVal.auth_type) == 5) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_AUTH_TYPE;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.auth_type;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.auth_type = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.auth_type;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTH_TYPE) {
+               if ((strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 1 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 2 || (strHostIFCfgParamAttr->cfg_attr_info.auth_type) == 5) {
+                       strWIDList[u8WidCnt].id = WID_AUTH_TYPE;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_type;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.auth_type = (u8)strHostIFCfgParamAttr->cfg_attr_info.auth_type;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Impossible value \n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & AUTHEN_TIMEOUT) {
-               /* range is 1 to 65535. */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout < 65536) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_AUTH_TIMEOUT;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.auth_timeout = strHostIFCfgParamAttr->pstrCfgParamVal.auth_timeout;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & AUTHEN_TIMEOUT) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.auth_timeout > 0 && strHostIFCfgParamAttr->cfg_attr_info.auth_timeout < 65536) {
+                       strWIDList[u8WidCnt].id = WID_AUTH_TIMEOUT;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.auth_timeout;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.auth_timeout = strHostIFCfgParamAttr->cfg_attr_info.auth_timeout;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Range(1 ~ 65535) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & POWER_MANAGEMENT) {
-               /*-----------------------------------------------------------*/
-               /*Input Values: NO_POWERSAVE     = 0,                                           */
-               /*                              MIN_FAST_PS      = 1,                                           */
-               /*                              MAX_FAST_PS      = 2,                                           */
-               /*                              MIN_PSPOLL_PS    = 3,                                           */
-               /*                              MAX_PSPOLL_PS    = 4                                            */
-               /*----------------------------------------------------------*/
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.power_mgmt_mode < 5) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_POWER_MANAGEMENT;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.power_mgmt_mode;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.power_mgmt_mode = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.power_mgmt_mode;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & POWER_MANAGEMENT) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode < 5) {
+                       strWIDList[u8WidCnt].id = WID_POWER_MANAGEMENT;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.power_mgmt_mode = (u8)strHostIFCfgParamAttr->cfg_attr_info.power_mgmt_mode;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Invalide power mode\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & RETRY_SHORT) {
-               /* range from 1 to 256 */
-               if ((strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit > 0) && (strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit < 256)) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_SHORT_RETRY_LIMIT;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.short_retry_limit = strHostIFCfgParamAttr->pstrCfgParamVal.short_retry_limit;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_SHORT) {
+               if ((strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit < 256))     {
+                       strWIDList[u8WidCnt].id = WID_SHORT_RETRY_LIMIT;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.short_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.short_retry_limit;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Range(1~256) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & RETRY_LONG) {
-               /* range from 1 to 256 */
-               if ((strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit > 0) && (strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit < 256)) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_LONG_RETRY_LIMIT;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & RETRY_LONG) {
+               if ((strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit > 0) && (strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit < 256)) {
+                       strWIDList[u8WidCnt].id = WID_LONG_RETRY_LIMIT;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit;
 
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.long_retry_limit = strHostIFCfgParamAttr->pstrCfgParamVal.long_retry_limit;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.long_retry_limit = strHostIFCfgParamAttr->cfg_attr_info.long_retry_limit;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Range(1~256) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & FRAG_THRESHOLD) {
-
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold > 255 && strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold < 7937) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_FRAG_THRESHOLD;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.frag_threshold = strHostIFCfgParamAttr->pstrCfgParamVal.frag_threshold;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & FRAG_THRESHOLD) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.frag_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.frag_threshold < 7937) {
+                       strWIDList[u8WidCnt].id = WID_FRAG_THRESHOLD;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.frag_threshold;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.frag_threshold = strHostIFCfgParamAttr->cfg_attr_info.frag_threshold;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Threshold Range fail\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & RTS_THRESHOLD) {
-               /* range 256 to 65535 */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold > 255 && strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold < 65536) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_RTS_THRESHOLD;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.rts_threshold = strHostIFCfgParamAttr->pstrCfgParamVal.rts_threshold;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & RTS_THRESHOLD) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.rts_threshold > 255 && strHostIFCfgParamAttr->cfg_attr_info.rts_threshold < 65536)     {
+                       strWIDList[u8WidCnt].id = WID_RTS_THRESHOLD;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.rts_threshold;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.rts_threshold = strHostIFCfgParamAttr->cfg_attr_info.rts_threshold;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Threshold Range fail\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & PREAMBLE) {
-               /*-----------------------------------------------------*/
-               /*Input Values: Short= 0,                                                               */
-               /*                              Long= 1,                                */
-               /*                              Auto= 2                                                                 */
-               /*------------------------------------------------------*/
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.preamble_type < 3) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_PREAMBLE;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.preamble_type;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.preamble_type = strHostIFCfgParamAttr->pstrCfgParamVal.preamble_type;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & PREAMBLE) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.preamble_type < 3) {
+                       strWIDList[u8WidCnt].id = WID_PREAMBLE;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.preamble_type;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.preamble_type = strHostIFCfgParamAttr->cfg_attr_info.preamble_type;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Preamle Range(0~2) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & SHORT_SLOT_ALLOWED) {
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.short_slot_allowed < 2) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_SHORT_SLOT_ALLOWED;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.short_slot_allowed;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.short_slot_allowed = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.short_slot_allowed;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & SHORT_SLOT_ALLOWED) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed < 2) {
+                       strWIDList[u8WidCnt].id = WID_SHORT_SLOT_ALLOWED;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.short_slot_allowed = (u8)strHostIFCfgParamAttr->cfg_attr_info.short_slot_allowed;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Short slot(2) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & TXOP_PROT_DISABLE) {
-               /*Description:  used to Disable RTS-CTS protection for TXOP burst*/
-               /*transmission when the acknowledgement policy is No-Ack or Block-Ack   */
-               /* this information is useful for external supplicant                                   */
-               /*Input Values: 1 for enable and 0 for disable.                                                 */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.txop_prot_disabled < 2) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_11N_TXOP_PROT_DISABLE;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.txop_prot_disabled;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.txop_prot_disabled = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.txop_prot_disabled;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & TXOP_PROT_DISABLE) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled < 2) {
+                       strWIDList[u8WidCnt].id = WID_11N_TXOP_PROT_DISABLE;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.txop_prot_disabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.txop_prot_disabled;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("TXOP prot disable\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & BEACON_INTERVAL) {
-               /* range is 1 to 65535. */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval < 65536) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_BEACON_INTERVAL;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.beacon_interval = strHostIFCfgParamAttr->pstrCfgParamVal.beacon_interval;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & BEACON_INTERVAL) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.beacon_interval > 0 && strHostIFCfgParamAttr->cfg_attr_info.beacon_interval < 65536) {
+                       strWIDList[u8WidCnt].id = WID_BEACON_INTERVAL;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.beacon_interval;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.beacon_interval = strHostIFCfgParamAttr->cfg_attr_info.beacon_interval;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Beacon interval(1~65535) fail\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & DTIM_PERIOD) {
-               /* range is 1 to 255. */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period < 256) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_DTIM_PERIOD;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.dtim_period = strHostIFCfgParamAttr->pstrCfgParamVal.dtim_period;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & DTIM_PERIOD) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.dtim_period > 0 && strHostIFCfgParamAttr->cfg_attr_info.dtim_period < 256) {
+                       strWIDList[u8WidCnt].id = WID_DTIM_PERIOD;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.dtim_period;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.dtim_period = strHostIFCfgParamAttr->cfg_attr_info.dtim_period;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("DTIM range(1~255) fail\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & SITE_SURVEY) {
-               /*----------------------------------------------------------------------*/
-               /*Input Values: SITE_SURVEY_1CH    = 0, i.e.: currently set channel             */
-               /*                              SITE_SURVEY_ALL_CH = 1,                                                                 */
-               /*                              SITE_SURVEY_OFF    = 2                                                                  */
-               /*----------------------------------------------------------------------*/
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_enabled < 3) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_SITE_SURVEY;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_enabled;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_CHAR;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(char);
-                       pstrWFIDrv->strCfgValues.site_survey_enabled = (u8)strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_enabled;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled < 3) {
+                       strWIDList[u8WidCnt].id = WID_SITE_SURVEY;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled;
+                       strWIDList[u8WidCnt].type = WID_CHAR;
+                       strWIDList[u8WidCnt].size = sizeof(char);
+                       hif_drv->strCfgValues.site_survey_enabled = (u8)strHostIFCfgParamAttr->cfg_attr_info.site_survey_enabled;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Site survey disable\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & SITE_SURVEY_SCAN_TIME) {
-               /* range is 1 to 65535. */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time < 65536) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_SITE_SURVEY_SCAN_TIME;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.site_survey_scan_time = strHostIFCfgParamAttr->pstrCfgParamVal.site_survey_scan_time;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & SITE_SURVEY_SCAN_TIME) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time < 65536) {
+                       strWIDList[u8WidCnt].id = WID_SITE_SURVEY_SCAN_TIME;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.site_survey_scan_time = strHostIFCfgParamAttr->cfg_attr_info.site_survey_scan_time;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Site survey scan time(1~65535) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & ACTIVE_SCANTIME) {
-               /* range is 1 to 65535. */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time < 65536) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_ACTIVE_SCAN_TIME;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.active_scan_time = strHostIFCfgParamAttr->pstrCfgParamVal.active_scan_time;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & ACTIVE_SCANTIME) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.active_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.active_scan_time < 65536) {
+                       strWIDList[u8WidCnt].id = WID_ACTIVE_SCAN_TIME;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.active_scan_time;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.active_scan_time = strHostIFCfgParamAttr->cfg_attr_info.active_scan_time;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Active scan time(1~65535) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & PASSIVE_SCANTIME) {
-               /* range is 1 to 65535. */
-               if (strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time > 0 && strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time < 65536) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_PASSIVE_SCAN_TIME;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.passive_scan_time = strHostIFCfgParamAttr->pstrCfgParamVal.passive_scan_time;
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & PASSIVE_SCANTIME) {
+               if (strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time > 0 && strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time < 65536) {
+                       strWIDList[u8WidCnt].id = WID_PASSIVE_SCAN_TIME;
+                       strWIDList[u8WidCnt].val = (s8 *)&strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.passive_scan_time = strHostIFCfgParamAttr->cfg_attr_info.passive_scan_time;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("Passive scan time(1~65535) over\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       if (strHostIFCfgParamAttr->pstrCfgParamVal.u32SetCfgFlag & CURRENT_TX_RATE) {
-               CURRENT_TX_RATE_T curr_tx_rate = strHostIFCfgParamAttr->pstrCfgParamVal.curr_tx_rate;
-               /*----------------------------------------------------------------------*/
-               /*Rates:                1   2   5.5   11   6  9  12  18  24  36  48   54  Auto  */
-               /*InputValues:  1   2     3    4   5  6   7   8   9  10  11   12  0             */
-               /*----------------------------------------------------------------------*/
-               /* validate rate */
+       if (strHostIFCfgParamAttr->cfg_attr_info.flag & CURRENT_TX_RATE) {
+               enum CURRENT_TXRATE curr_tx_rate = strHostIFCfgParamAttr->cfg_attr_info.curr_tx_rate;
+
                if (curr_tx_rate == AUTORATE || curr_tx_rate == MBPS_1
                    || curr_tx_rate == MBPS_2 || curr_tx_rate == MBPS_5_5
                    || curr_tx_rate == MBPS_11 || curr_tx_rate == MBPS_6
                    || curr_tx_rate == MBPS_9 || curr_tx_rate == MBPS_12
                    || curr_tx_rate == MBPS_18 || curr_tx_rate == MBPS_24
                    || curr_tx_rate == MBPS_36 || curr_tx_rate == MBPS_48 || curr_tx_rate == MBPS_54) {
-                       strWIDList[u8WidCnt].u16WIDid = WID_CURRENT_TX_RATE;
-                       strWIDList[u8WidCnt].ps8WidVal = (s8 *)&curr_tx_rate;
-                       strWIDList[u8WidCnt].enuWIDtype = WID_SHORT;
-                       strWIDList[u8WidCnt].s32ValueSize = sizeof(u16);
-                       pstrWFIDrv->strCfgValues.curr_tx_rate = (u8)curr_tx_rate;
+                       strWIDList[u8WidCnt].id = WID_CURRENT_TX_RATE;
+                       strWIDList[u8WidCnt].val = (s8 *)&curr_tx_rate;
+                       strWIDList[u8WidCnt].type = WID_SHORT;
+                       strWIDList[u8WidCnt].size = sizeof(u16);
+                       hif_drv->strCfgValues.curr_tx_rate = (u8)curr_tx_rate;
                } else {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+                       PRINT_ER("out of TX rate\n");
+                       result = -EINVAL;
+                       goto ERRORHANDLER;
                }
                u8WidCnt++;
        }
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u8WidCnt, false, (u32)pstrWFIDrv);
 
-       if (s32Error)
+       result = send_config_pkt(SET_CFG, strWIDList, u8WidCnt,
+                                get_id_from_handler(hif_drv));
+
+       if (result)
                PRINT_ER("Error in setting CFG params\n");
 
-       WILC_CATCH(s32Error)
-       {
-       }
-       up(&(pstrWFIDrv->gtOsCfgValuesSem));
-       return s32Error;
+ERRORHANDLER:
+       up(&hif_drv->gtOsCfgValuesSem);
+       return result;
 }
 
-
-/**
- *  @brief Handle_wait_msg_q_empty
- *  @details       this should be the last msg and then the msg Q becomes idle
- *  @param[in]    tstrHostIFscanAttr* pstrHostIFscanAttr
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
 static s32 Handle_wait_msg_q_empty(void)
 {
-       s32 s32Error = WILC_SUCCESS;
-
        g_wilc_initialized = 0;
-       up(&hWaitResponse);
-       return s32Error;
+       up(&hif_sema_wait_response);
+       return 0;
 }
 
-/**
- *  @brief Handle_Scan
- *  @details       Sending config packet to firmware to set the scan params
- *  @param[in]    tstrHostIFscanAttr* pstrHostIFscanAttr
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_Scan(tstrWILC_WFIDrv *drvHandler, tstrHostIFscanAttr *pstrHostIFscanAttr)
+static s32 Handle_Scan(struct host_if_drv *hif_drv,
+                      struct scan_attr *pstrHostIFscanAttr)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWIDList[5];
+       s32 result = 0;
+       struct wid strWIDList[5];
        u32 u32WidsCount = 0;
        u32 i;
        u8 *pu8Buffer;
        u8 valuesize = 0;
        u8 *pu8HdnNtwrksWidVal = NULL;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
 
        PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
-       PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state\n", pstrWFIDrv->enuHostIFstate);
+       PRINT_D(HOSTINF_DBG, "Scanning: In [%d] state\n", hif_drv->enuHostIFstate);
 
-       pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = pstrHostIFscanAttr->pfScanResult;
-       pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid = pstrHostIFscanAttr->pvUserArg;
+       hif_drv->usr_scan_req.pfUserScanResult = pstrHostIFscanAttr->result;
+       hif_drv->usr_scan_req.u32UserScanPvoid = pstrHostIFscanAttr->arg;
 
-       #ifdef WILC_P2P
-       #endif
-
-       if ((pstrWFIDrv->enuHostIFstate >= HOST_IF_SCANNING) && (pstrWFIDrv->enuHostIFstate < HOST_IF_CONNECTED)) {
-               /* here we either in HOST_IF_SCANNING, HOST_IF_WAITING_CONN_REQ or HOST_IF_WAITING_CONN_RESP */
-               PRINT_D(GENERIC_DBG, "Don't scan we are already in [%d] state\n", pstrWFIDrv->enuHostIFstate);
-               WILC_ERRORREPORT(s32Error, WILC_BUSY);
+       if ((hif_drv->enuHostIFstate >= HOST_IF_SCANNING) && (hif_drv->enuHostIFstate < HOST_IF_CONNECTED)) {
+               PRINT_D(GENERIC_DBG, "Don't scan we are already in [%d] state\n", hif_drv->enuHostIFstate);
+               PRINT_ER("Already scan\n");
+               result = -EBUSY;
+               goto ERRORHANDLER;
        }
 
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
        if (g_obtainingIP || connecting) {
                PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
-               WILC_ERRORREPORT(s32Error, WILC_BUSY);
+               PRINT_ER("Don't do obss scan\n");
+               result = -EBUSY;
+               goto ERRORHANDLER;
        }
-       #endif
 
        PRINT_D(HOSTINF_DBG, "Setting SCAN params\n");
 
+       hif_drv->usr_scan_req.u32RcvdChCount = 0;
 
-       pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount = 0;
-
-       /*BugID_4189*/
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_SSID_PROBE_REQ;
-       strWIDList[u32WidsCount].enuWIDtype = WID_STR;
+       strWIDList[u32WidsCount].id = (u16)WID_SSID_PROBE_REQ;
+       strWIDList[u32WidsCount].type = WID_STR;
 
-       for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++)
-               valuesize += ((pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen) + 1);
-       pu8HdnNtwrksWidVal = WILC_MALLOC(valuesize + 1);
-       strWIDList[u32WidsCount].ps8WidVal = pu8HdnNtwrksWidVal;
-       if (strWIDList[u32WidsCount].ps8WidVal != NULL) {
-               pu8Buffer = strWIDList[u32WidsCount].ps8WidVal;
+       for (i = 0; i < pstrHostIFscanAttr->hidden_network.u8ssidnum; i++)
+               valuesize += ((pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen) + 1);
+       pu8HdnNtwrksWidVal = kmalloc(valuesize + 1, GFP_KERNEL);
+       strWIDList[u32WidsCount].val = pu8HdnNtwrksWidVal;
+       if (strWIDList[u32WidsCount].val) {
+               pu8Buffer = strWIDList[u32WidsCount].val;
 
-               *pu8Buffer++ = pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum;
+               *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.u8ssidnum;
 
-               PRINT_D(HOSTINF_DBG, "In Handle_ProbeRequest number of ssid %d\n", pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum);
+               PRINT_D(HOSTINF_DBG, "In Handle_ProbeRequest number of ssid %d\n", pstrHostIFscanAttr->hidden_network.u8ssidnum);
 
-               for (i = 0; i < pstrHostIFscanAttr->strHiddenNetwork.u8ssidnum; i++) {
-                       *pu8Buffer++ = pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen;
-                       memcpy(pu8Buffer, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen);
-                       pu8Buffer += pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen;
+               for (i = 0; i < pstrHostIFscanAttr->hidden_network.u8ssidnum; i++) {
+                       *pu8Buffer++ = pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen;
+                       memcpy(pu8Buffer, pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].pu8ssid, pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen);
+                       pu8Buffer += pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo[i].u8ssidlen;
                }
 
-
-
-               strWIDList[u32WidsCount].s32ValueSize =  (s32)(valuesize + 1);
+               strWIDList[u32WidsCount].size = (s32)(valuesize + 1);
                u32WidsCount++;
        }
 
-       /*filling cfg param array*/
-
-       /* if((pstrHostIFscanAttr->pu8IEs != NULL) && (pstrHostIFscanAttr->IEsLen != 0)) */
        {
-               /* IEs to be inserted in Probe Request */
-               strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_PROBE;
-               strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
-               strWIDList[u32WidsCount].ps8WidVal = pstrHostIFscanAttr->pu8IEs;
-               strWIDList[u32WidsCount].s32ValueSize = pstrHostIFscanAttr->IEsLen;
+               strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_PROBE;
+               strWIDList[u32WidsCount].type = WID_BIN_DATA;
+               strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ies;
+               strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ies_len;
                u32WidsCount++;
        }
 
-       /*Scan Type*/
-       strWIDList[u32WidsCount].u16WIDid = WID_SCAN_TYPE;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrHostIFscanAttr->u8ScanType));
+       strWIDList[u32WidsCount].id = WID_SCAN_TYPE;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)&pstrHostIFscanAttr->type;
        u32WidsCount++;
 
-       /*list of channels to be scanned*/
-       strWIDList[u32WidsCount].u16WIDid = WID_SCAN_CHANNEL_LIST;
-       strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
+       strWIDList[u32WidsCount].id = WID_SCAN_CHANNEL_LIST;
+       strWIDList[u32WidsCount].type = WID_BIN_DATA;
 
-       /* Bug 4648: Convert channel numbers to start from 0 not 1. */
-       if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL && pstrHostIFscanAttr->u8ChnlListLen > 0) {
+       if (pstrHostIFscanAttr->ch_freq_list &&
+           pstrHostIFscanAttr->ch_list_len > 0) {
                int i;
 
-               for (i = 0; i < pstrHostIFscanAttr->u8ChnlListLen; i++) {
-                       if (pstrHostIFscanAttr->pu8ChnlFreqList[i] > 0)
-                               pstrHostIFscanAttr->pu8ChnlFreqList[i] = pstrHostIFscanAttr->pu8ChnlFreqList[i] - 1;
+               for (i = 0; i < pstrHostIFscanAttr->ch_list_len; i++)   {
+                       if (pstrHostIFscanAttr->ch_freq_list[i] > 0)
+                               pstrHostIFscanAttr->ch_freq_list[i] = pstrHostIFscanAttr->ch_freq_list[i] - 1;
                }
        }
 
-       strWIDList[u32WidsCount].ps8WidVal = pstrHostIFscanAttr->pu8ChnlFreqList;
-       strWIDList[u32WidsCount].s32ValueSize = pstrHostIFscanAttr->u8ChnlListLen;
+       strWIDList[u32WidsCount].val = pstrHostIFscanAttr->ch_freq_list;
+       strWIDList[u32WidsCount].size = pstrHostIFscanAttr->ch_list_len;
        u32WidsCount++;
 
-       /*Scan Request*/
-       strWIDList[u32WidsCount].u16WIDid = WID_START_SCAN_REQ;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrHostIFscanAttr->u8ScanSource));
+       strWIDList[u32WidsCount].id = WID_START_SCAN_REQ;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)&pstrHostIFscanAttr->src;
        u32WidsCount++;
 
-       /*keep the state as is , no need to change it*/
-       /* gWFiDrvHandle->enuHostIFstate = HOST_IF_SCANNING; */
-
-       if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED)
-               gbScanWhileConnected = true;
-       else if (pstrWFIDrv->enuHostIFstate == HOST_IF_IDLE)
-               gbScanWhileConnected = false;
+       if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)
+               scan_while_connected = true;
+       else if (hif_drv->enuHostIFstate == HOST_IF_IDLE)
+               scan_while_connected = false;
 
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
+       result = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
+                                get_id_from_handler(hif_drv));
 
-       if (s32Error) {
+       if (result)
                PRINT_ER("Failed to send scan paramters config packet\n");
-               WILC_ERRORREPORT(s32Error, s32Error);
-       } else {
+       else
                PRINT_D(HOSTINF_DBG, "Successfully sent SCAN params config packet\n");
-       }
-
-       WILC_CATCH(s32Error)
-       {
-               del_timer(&pstrWFIDrv->hScanTimer);
-               /*if there is an ongoing scan request*/
-               Handle_ScanDone(drvHandler, SCAN_EVENT_ABORTED);
-       }
 
-       /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */
-       if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) {
-               kfree(pstrHostIFscanAttr->pu8ChnlFreqList);
-               pstrHostIFscanAttr->pu8ChnlFreqList = NULL;
+ERRORHANDLER:
+       if (result) {
+               del_timer(&hif_drv->hScanTimer);
+               Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED);
        }
 
-       /* Deallocate pstrHostIFscanAttr->pu8IEs which was previously allocated by the sending thread */
-       if (pstrHostIFscanAttr->pu8IEs != NULL) {
-               kfree(pstrHostIFscanAttr->pu8IEs);
-               pstrHostIFscanAttr->pu8IEs = NULL;
-       }
-       if (pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo != NULL) {
-               kfree(pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo);
-               pstrHostIFscanAttr->strHiddenNetwork.pstrHiddenNetworkInfo = NULL;
-       }
+       kfree(pstrHostIFscanAttr->ch_freq_list);
+       pstrHostIFscanAttr->ch_freq_list = NULL;
 
-       /* Deallocate pstrHostIFscanAttr->u8ChnlListLen which was prevoisuly allocated by the sending thread */
-       if (pstrHostIFscanAttr->pu8ChnlFreqList != NULL) {
-               kfree(pstrHostIFscanAttr->pu8ChnlFreqList);
-               pstrHostIFscanAttr->pu8ChnlFreqList = NULL;
-       }
+       kfree(pstrHostIFscanAttr->ies);
+       pstrHostIFscanAttr->ies = NULL;
+       kfree(pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo);
+       pstrHostIFscanAttr->hidden_network.pstrHiddenNetworkInfo = NULL;
 
-       if (pu8HdnNtwrksWidVal != NULL)
-               kfree(pu8HdnNtwrksWidVal);
+       kfree(pu8HdnNtwrksWidVal);
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief Handle_ScanDone
- *  @details       Call scan notification callback function
- *  @param[in]    NONE
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_ScanDone(tstrWILC_WFIDrv *drvHandler, tenuScanEvent enuEvent)
+static s32 Handle_ScanDone(struct host_if_drv *hif_drv,
+                          enum scan_event enuEvent)
 {
-       s32 s32Error = WILC_SUCCESS;
-
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
-
+       s32 result = 0;
        u8 u8abort_running_scan;
-       tstrWID strWID;
-
+       struct wid wid;
 
        PRINT_D(HOSTINF_DBG, "in Handle_ScanDone()\n");
 
-       /*BugID_4978*/
-       /*Ask FW to abort the running scan, if any*/
        if (enuEvent == SCAN_EVENT_ABORTED) {
                PRINT_D(GENERIC_DBG, "Abort running scan\n");
                u8abort_running_scan = 1;
-               strWID.u16WIDid = (u16)WID_ABORT_RUNNING_SCAN;
-               strWID.enuWIDtype       = WID_CHAR;
-               strWID.ps8WidVal = (s8 *)&u8abort_running_scan;
-               strWID.s32ValueSize = sizeof(char);
-
-               /*Sending Cfg*/
-               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-               if (s32Error != WILC_SUCCESS) {
+               wid.id = (u16)WID_ABORT_RUNNING_SCAN;
+               wid.type = WID_CHAR;
+               wid.val = (s8 *)&u8abort_running_scan;
+               wid.size = sizeof(char);
+
+               result = send_config_pkt(SET_CFG, &wid, 1,
+                                        get_id_from_handler(hif_drv));
+
+               if (result) {
                        PRINT_ER("Failed to set abort running scan\n");
-                       WILC_ERRORREPORT(s32Error, WILC_FAIL);
-               }
-               WILC_CATCH(s32Error)
-               {
+                       result = -EFAULT;
                }
        }
 
-       if (pstrWFIDrv == NULL) {
+       if (!hif_drv) {
                PRINT_ER("Driver handler is NULL\n");
-               return s32Error;
+               return result;
        }
 
-       /*if there is an ongoing scan request*/
-       if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
-               pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(enuEvent, NULL,
-                                                               pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
-               /*delete current scan request*/
-               pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL;
+       if (hif_drv->usr_scan_req.pfUserScanResult) {
+               hif_drv->usr_scan_req.pfUserScanResult(enuEvent, NULL,
+                                                      hif_drv->usr_scan_req.u32UserScanPvoid, NULL);
+               hif_drv->usr_scan_req.pfUserScanResult = NULL;
        }
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief Handle_Connect
- *  @details       Sending config packet to firmware to starting connection
- *  @param[in]    tstrHostIFconnectAttr* pstrHostIFconnectAttr
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
 u8 u8ConnectedSSID[6] = {0};
-static s32 Handle_Connect(tstrWILC_WFIDrv *drvHandler, tstrHostIFconnectAttr *pstrHostIFconnectAttr)
+static s32 Handle_Connect(struct host_if_drv *hif_drv,
+                         struct connect_attr *pstrHostIFconnectAttr)
 {
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWIDList[8];
+       s32 result = 0;
+       struct wid strWIDList[8];
        u32 u32WidsCount = 0, dummyval = 0;
-       /* char passphrase[] = "12345678"; */
-       #ifndef CONNECT_DIRECT
-       s32 s32Err = WILC_SUCCESS;
-       u32 i;
-       u8 u8bssDscListIndex;
-       wid_site_survey_reslts_s *pstrSurveyResults = NULL;
-       #else
        u8 *pu8CurrByte = NULL;
-       /*Bug4218: Parsing Join Param*/
-       #ifdef WILC_PARSE_SCAN_IN_HOST
-       tstrJoinBssParam *ptstrJoinBssParam;
-       #endif /*WILC_PARSE_SCAN_IN_HOST*/
-
-       #endif
+       struct join_bss_param *ptstrJoinBssParam;
 
        PRINT_D(GENERIC_DBG, "Handling connect request\n");
 
-       #ifndef CONNECT_DIRECT
-       memset(gapu8RcvdSurveyResults[0], 0, MAX_SURVEY_RESULT_FRAG_SIZE);
-       memset(gapu8RcvdSurveyResults[1], 0, MAX_SURVEY_RESULT_FRAG_SIZE);
-
-
-       PRINT_D(HOSTINF_DBG, "Getting site survey results\n");
-       s32Err = host_int_get_site_survey_results(pstrWFIDrv,
-                                                 gapu8RcvdSurveyResults,
-                                                 MAX_SURVEY_RESULT_FRAG_SIZE);
-       if (s32Err) {
-               PRINT_ER("Failed to get site survey results\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-
-       }
-       s32Err = ParseSurveyResults(gapu8RcvdSurveyResults, &pstrSurveyResults,
-                                   &pstrWFIDrv->u32SurveyResultsCount);
-
-
-       if (s32Err == WILC_SUCCESS) {
-               /* use the parsed info in pstrSurveyResults, then deallocate it */
-               PRINT_D(HOSTINF_DBG, "Copying site survey results in global structure, then deallocate\n");
-               for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) {
-                       memcpy(&pstrWFIDrv->astrSurveyResults[i], &pstrSurveyResults[i],
-                                   sizeof(wid_site_survey_reslts_s));
-               }
-
-               DeallocateSurveyResults(pstrSurveyResults);
-       } else {
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-               PRINT_ER("ParseSurveyResults() Error(%d)\n", s32Err);
-       }
-
-
-       for (i = 0; i < pstrWFIDrv->u32SurveyResultsCount; i++) {
-               if (memcmp(pstrWFIDrv->astrSurveyResults[i].SSID,
-                               pstrHostIFconnectAttr->pu8ssid,
-                               pstrHostIFconnectAttr->ssidLen) == 0) {
-                       PRINT_INFO(HOSTINF_DBG, "Network with required SSID is found %s\n", pstrHostIFconnectAttr->pu8ssid);
-                       if (pstrHostIFconnectAttr->pu8bssid == NULL) {
-                               /* BSSID is not passed from the user, so decision of matching
-                                * is done by SSID only */
-                               PRINT_INFO(HOSTINF_DBG, "BSSID is not passed from the user\n");
-                               break;
-                       } else {
-                               /* BSSID is also passed from the user, so decision of matching
-                                * should consider also this passed BSSID */
-
-                               if (memcmp(pstrWFIDrv->astrSurveyResults[i].BSSID,
-                                               pstrHostIFconnectAttr->pu8bssid,
-                                               6) == 0) {
-                                       PRINT_INFO(HOSTINF_DBG, "BSSID is passed from the user and matched\n");
-                                       break;
-                               }
-                       }
-               }
-       }
-
-       if (i < pstrWFIDrv->u32SurveyResultsCount) {
-               u8bssDscListIndex = i;
-
-               PRINT_INFO(HOSTINF_DBG, "Connecting to network of Bss Idx%d and SSID %s and channel%d\n",
-                          u8bssDscListIndex, pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].SSID,
-                          pstrWFIDrv->astrSurveyResults[u8bssDscListIndex].Channel);
-
-               PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n");
-
-               if (pstrHostIFconnectAttr->pu8bssid != NULL) {
-                       pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = WILC_MALLOC(6);
-                       memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
-               }
-
-               pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen;
-               if (pstrHostIFconnectAttr->pu8ssid != NULL) {
-                       pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1);
-                       memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid,
-                                   pstrHostIFconnectAttr->ssidLen);
-                       pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0';
-               }
-
-               pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen;
-               if (pstrHostIFconnectAttr->pu8IEs != NULL) {
-                       pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
-                       memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs,
-                                   pstrHostIFconnectAttr->IEsLen);
-               }
-
-               pstrWFIDrv->strWILC_UsrConnReq.u8security = pstrHostIFconnectAttr->u8security;
-               pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type = pstrHostIFconnectAttr->tenuAuth_type;
-               pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult = pstrHostIFconnectAttr->pfConnectResult;
-               pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid = pstrHostIFconnectAttr->pvUserArg;
-
-
-               /* if((gWFiDrvHandle->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) && */
-               /* (gWFiDrvHandle->strWILC_UsrConnReq.ConnReqIEsLen != 0)) */
-               {
-                       /* IEs to be inserted in Association Request */
-                       strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_ASSOCIATE;
-                       strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
-                       strWIDList[u32WidsCount].ps8WidVal = pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs;
-                       strWIDList[u32WidsCount].s32ValueSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
-                       u32WidsCount++;
-               }
-               strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_MODE;
-               strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-               strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-               strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrWFIDrv->strWILC_UsrConnReq.u8security));
-               u32WidsCount++;
-
-               PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", pstrWFIDrv->strWILC_UsrConnReq.u8security);
-
-               strWIDList[u32WidsCount].u16WIDid = (u16)WID_AUTH_TYPE;
-               strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-               strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-               strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
-               u32WidsCount++;
-
-               PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
-               /*
-                * strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_PSK;
-                * strWIDList[u32WidsCount].enuWIDtype = WID_STR;
-                * strWIDList[u32WidsCount].s32ValueSize = sizeof(passphrase);
-                * strWIDList[u32WidsCount].ps8WidVal = (s8*)(passphrase);
-                * u32WidsCount++;
-                */
-
-               strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ;
-               strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-               strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-               strWIDList[u32WidsCount].ps8WidVal = (s8 *)&u8bssDscListIndex;
-               u32WidsCount++;
-
-               /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the
-                *   firmware at chip reset when processing the WIDs of the Connect Request.
-                *   (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */
-               /* ////////////////////// */
-               gu32WidConnRstHack = 0;
-               /* ////////////////////// */
-
-               s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
-               if (s32Error) {
-                       PRINT_ER("Handle_Connect()] failed to send config packet\n");
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-               } else {
-                       pstrWFIDrv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
-               }
-
-       } else {
-               PRINT_ER("Required BSSID not found\n");
-               WILC_ERRORREPORT(s32Error, WILC_NOT_FOUND);
-       }
-
-       #else
-
-       /* if we try to connect to an already connected AP then discard the request */
-
-       if (memcmp(pstrHostIFconnectAttr->pu8bssid, u8ConnectedSSID, ETH_ALEN) == 0) {
-
-               s32Error = WILC_SUCCESS;
+       if (memcmp(pstrHostIFconnectAttr->bssid, u8ConnectedSSID, ETH_ALEN) == 0) {
+               result = 0;
                PRINT_ER("Trying to connect to an already connected AP, Discard connect request\n");
-               return s32Error;
+               return result;
        }
 
        PRINT_INFO(HOSTINF_DBG, "Saving connection parameters in global structure\n");
 
-       /*Bug4218: Parsing Join Param*/
-       #ifdef WILC_PARSE_SCAN_IN_HOST
-       ptstrJoinBssParam = (tstrJoinBssParam *)pstrHostIFconnectAttr->pJoinParams;
-       if (ptstrJoinBssParam == NULL) {
+       ptstrJoinBssParam = (struct join_bss_param *)pstrHostIFconnectAttr->params;
+       if (!ptstrJoinBssParam) {
                PRINT_ER("Required BSSID not found\n");
-               WILC_ERRORREPORT(s32Error, WILC_NOT_FOUND);
+               result = -ENOENT;
+               goto ERRORHANDLER;
        }
-       #endif /*WILC_PARSE_SCAN_IN_HOST*/
 
-       if (pstrHostIFconnectAttr->pu8bssid != NULL) {
-               pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = WILC_MALLOC(6);
-               memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
+       if (pstrHostIFconnectAttr->bssid) {
+               hif_drv->usr_conn_req.pu8bssid = kmalloc(6, GFP_KERNEL);
+               memcpy(hif_drv->usr_conn_req.pu8bssid, pstrHostIFconnectAttr->bssid, 6);
        }
 
-       pstrWFIDrv->strWILC_UsrConnReq.ssidLen = pstrHostIFconnectAttr->ssidLen;
-       if (pstrHostIFconnectAttr->pu8ssid != NULL) {
-               pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = WILC_MALLOC(pstrHostIFconnectAttr->ssidLen + 1);
-               memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->pu8ssid,
-                           pstrHostIFconnectAttr->ssidLen);
-               pstrWFIDrv->strWILC_UsrConnReq.pu8ssid[pstrHostIFconnectAttr->ssidLen] = '\0';
+       hif_drv->usr_conn_req.ssidLen = pstrHostIFconnectAttr->ssid_len;
+       if (pstrHostIFconnectAttr->ssid) {
+               hif_drv->usr_conn_req.pu8ssid = kmalloc(pstrHostIFconnectAttr->ssid_len + 1, GFP_KERNEL);
+               memcpy(hif_drv->usr_conn_req.pu8ssid,
+                      pstrHostIFconnectAttr->ssid,
+                      pstrHostIFconnectAttr->ssid_len);
+               hif_drv->usr_conn_req.pu8ssid[pstrHostIFconnectAttr->ssid_len] = '\0';
        }
 
-       pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = pstrHostIFconnectAttr->IEsLen;
-       if (pstrHostIFconnectAttr->pu8IEs != NULL) {
-               pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
-               memcpy(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs, pstrHostIFconnectAttr->pu8IEs,
-                           pstrHostIFconnectAttr->IEsLen);
+       hif_drv->usr_conn_req.ConnReqIEsLen = pstrHostIFconnectAttr->ies_len;
+       if (pstrHostIFconnectAttr->ies) {
+               hif_drv->usr_conn_req.pu8ConnReqIEs = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
+               memcpy(hif_drv->usr_conn_req.pu8ConnReqIEs,
+                      pstrHostIFconnectAttr->ies,
+                      pstrHostIFconnectAttr->ies_len);
        }
 
-       pstrWFIDrv->strWILC_UsrConnReq.u8security = pstrHostIFconnectAttr->u8security;
-       pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type = pstrHostIFconnectAttr->tenuAuth_type;
-       pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult = pstrHostIFconnectAttr->pfConnectResult;
-       pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid = pstrHostIFconnectAttr->pvUserArg;
+       hif_drv->usr_conn_req.u8security = pstrHostIFconnectAttr->security;
+       hif_drv->usr_conn_req.tenuAuth_type = pstrHostIFconnectAttr->auth_type;
+       hif_drv->usr_conn_req.pfUserConnectResult = pstrHostIFconnectAttr->result;
+       hif_drv->usr_conn_req.u32UserConnectPvoid = pstrHostIFconnectAttr->arg;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_SUCCESS_FRAME_COUNT;
-       strWIDList[u32WidsCount].enuWIDtype = WID_INT;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(dummyval));
+       strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
+       strWIDList[u32WidsCount].type = WID_INT;
+       strWIDList[u32WidsCount].size = sizeof(u32);
+       strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
        u32WidsCount++;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_RECEIVED_FRAGMENT_COUNT;
-       strWIDList[u32WidsCount].enuWIDtype = WID_INT;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(dummyval));
+       strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
+       strWIDList[u32WidsCount].type = WID_INT;
+       strWIDList[u32WidsCount].size = sizeof(u32);
+       strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
        u32WidsCount++;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_FAILED_COUNT;
-       strWIDList[u32WidsCount].enuWIDtype = WID_INT;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(dummyval));
+       strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
+       strWIDList[u32WidsCount].type = WID_INT;
+       strWIDList[u32WidsCount].size = sizeof(u32);
+       strWIDList[u32WidsCount].val = (s8 *)(&(dummyval));
        u32WidsCount++;
 
-       /* if((gWFiDrvHandle->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) && */
-       /* (gWFiDrvHandle->strWILC_UsrConnReq.ConnReqIEsLen != 0)) */
        {
-               /* IEs to be inserted in Association Request */
-               strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_ASSOCIATE;
-               strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
-               strWIDList[u32WidsCount].ps8WidVal = pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs;
-               strWIDList[u32WidsCount].s32ValueSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
+               strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
+               strWIDList[u32WidsCount].type = WID_BIN_DATA;
+               strWIDList[u32WidsCount].val = hif_drv->usr_conn_req.pu8ConnReqIEs;
+               strWIDList[u32WidsCount].size = hif_drv->usr_conn_req.ConnReqIEsLen;
                u32WidsCount++;
 
-               /*BugID_5137*/
-               if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
-
-                       gu32FlushedInfoElemAsocSize = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
-                       gu8FlushedInfoElemAsoc =  WILC_MALLOC(gu32FlushedInfoElemAsocSize);
-                       memcpy(gu8FlushedInfoElemAsoc, pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
-                              gu32FlushedInfoElemAsocSize);
+               if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
+                       info_element_size = hif_drv->usr_conn_req.ConnReqIEsLen;
+                       info_element = kmalloc(info_element_size, GFP_KERNEL);
+                       memcpy(info_element, hif_drv->usr_conn_req.pu8ConnReqIEs,
+                              info_element_size);
                }
        }
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_MODE;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrWFIDrv->strWILC_UsrConnReq.u8security));
+       strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)&hif_drv->usr_conn_req.u8security;
        u32WidsCount++;
 
-       /*BugID_5137*/
-       if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
-               gu8Flushed11iMode = pstrWFIDrv->strWILC_UsrConnReq.u8security;
+       if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
+               mode_11i = hif_drv->usr_conn_req.u8security;
 
-       PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", pstrWFIDrv->strWILC_UsrConnReq.u8security);
+       PRINT_INFO(HOSTINF_DBG, "Encrypt Mode = %x\n", hif_drv->usr_conn_req.u8security);
 
-
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_AUTH_TYPE;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
+       strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)(&hif_drv->usr_conn_req.tenuAuth_type);
        u32WidsCount++;
 
-       /*BugID_5137*/
-       if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7))
-               gu8FlushedAuthType = (u8)pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type;
-
-       PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", pstrWFIDrv->strWILC_UsrConnReq.tenuAuth_type);
-       /*
-        * strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_PSK;
-        * strWIDList[u32WidsCount].enuWIDtype = WID_STR;
-        * strWIDList[u32WidsCount].s32ValueSize = sizeof(passphrase);
-        * strWIDList[u32WidsCount].ps8WidVal = (s8*)(passphrase);
-        * u32WidsCount++;
-        */
+       if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7))
+               auth_type = (u8)hif_drv->usr_conn_req.tenuAuth_type;
 
+       PRINT_INFO(HOSTINF_DBG, "Authentication Type = %x\n", hif_drv->usr_conn_req.tenuAuth_type);
        PRINT_D(HOSTINF_DBG, "Connecting to network of SSID %s on channel %d\n",
-               pstrWFIDrv->strWILC_UsrConnReq.pu8ssid, pstrHostIFconnectAttr->u8channel);
-
-
-#ifndef WILC_PARSE_SCAN_IN_HOST
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ_EXTENDED;
-       strWIDList[u32WidsCount].enuWIDtype = WID_STR;
-       strWIDList[u32WidsCount].s32ValueSize = MAX_SSID_LEN + 7;
-       strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize);
+               hif_drv->usr_conn_req.pu8ssid, pstrHostIFconnectAttr->ch);
 
-       if (strWIDList[u32WidsCount].ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
+       strWIDList[u32WidsCount].type = WID_STR;
+       strWIDList[u32WidsCount].size = 112;
+       strWIDList[u32WidsCount].val = kmalloc(strWIDList[u32WidsCount].size, GFP_KERNEL);
 
-       pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
-
-       if (pstrHostIFconnectAttr->pu8ssid != NULL) {
-               memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen);
-               pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0';
-       }
-       pu8CurrByte += MAX_SSID_LEN;
-       if ((pstrHostIFconnectAttr->u8channel >= 1) && (pstrHostIFconnectAttr->u8channel <= 14)) {
-               *(pu8CurrByte++) = pstrHostIFconnectAttr->u8channel;
-       } else {
-               PRINT_ER("Channel out of range\n");
-               *(pu8CurrByte++) = 0xFF;
+       if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
+               join_req_size = strWIDList[u32WidsCount].size;
+               join_req = kmalloc(join_req_size, GFP_KERNEL);
        }
-       if (pstrHostIFconnectAttr->pu8bssid != NULL)
-               memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
-       pu8CurrByte += 6;
-
-       /* keep the buffer at the start of the allocated pointer to use it with the free*/
-       pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
-
-       #else
-
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ_EXTENDED;
-       strWIDList[u32WidsCount].enuWIDtype = WID_STR;
-
-       /*Sending NoA attributes during connection*/
-       strWIDList[u32WidsCount].s32ValueSize = 112; /* 79; */
-       strWIDList[u32WidsCount].ps8WidVal = WILC_MALLOC(strWIDList[u32WidsCount].s32ValueSize);
-
-       /*BugID_5137*/
-       if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
-               gu32FlushedJoinReqSize = strWIDList[u32WidsCount].s32ValueSize;
-               gu8FlushedJoinReq = WILC_MALLOC(gu32FlushedJoinReqSize);
+       if (!strWIDList[u32WidsCount].val) {
+               result = -EFAULT;
+               goto ERRORHANDLER;
        }
-       if (strWIDList[u32WidsCount].ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
 
-       pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
+       pu8CurrByte = strWIDList[u32WidsCount].val;
 
-
-       if (pstrHostIFconnectAttr->pu8ssid != NULL) {
-               memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8ssid, pstrHostIFconnectAttr->ssidLen);
-               pu8CurrByte[pstrHostIFconnectAttr->ssidLen] = '\0';
+       if (pstrHostIFconnectAttr->ssid) {
+               memcpy(pu8CurrByte, pstrHostIFconnectAttr->ssid, pstrHostIFconnectAttr->ssid_len);
+               pu8CurrByte[pstrHostIFconnectAttr->ssid_len] = '\0';
        }
        pu8CurrByte += MAX_SSID_LEN;
-
-       /* BSS type*/
        *(pu8CurrByte++) = INFRASTRUCTURE;
-       /* Channel*/
-       if ((pstrHostIFconnectAttr->u8channel >= 1) && (pstrHostIFconnectAttr->u8channel <= 14)) {
-               *(pu8CurrByte++) = pstrHostIFconnectAttr->u8channel;
+
+       if ((pstrHostIFconnectAttr->ch >= 1) && (pstrHostIFconnectAttr->ch <= 14)) {
+               *(pu8CurrByte++) = pstrHostIFconnectAttr->ch;
        } else {
                PRINT_ER("Channel out of range\n");
                *(pu8CurrByte++) = 0xFF;
        }
-       /* Cap Info*/
        *(pu8CurrByte++)  = (ptstrJoinBssParam->cap_info) & 0xFF;
        *(pu8CurrByte++)  = ((ptstrJoinBssParam->cap_info) >> 8) & 0xFF;
        PRINT_D(HOSTINF_DBG, "* Cap Info %0x*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
 
-       /* sa*/
-       if (pstrHostIFconnectAttr->pu8bssid != NULL)
-               memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
+       if (pstrHostIFconnectAttr->bssid)
+               memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
        pu8CurrByte += 6;
 
-       /* bssid*/
-       if (pstrHostIFconnectAttr->pu8bssid != NULL)
-               memcpy(pu8CurrByte, pstrHostIFconnectAttr->pu8bssid, 6);
+       if (pstrHostIFconnectAttr->bssid)
+               memcpy(pu8CurrByte, pstrHostIFconnectAttr->bssid, 6);
        pu8CurrByte += 6;
 
-       /* Beacon Period*/
        *(pu8CurrByte++)  = (ptstrJoinBssParam->beacon_period) & 0xFF;
        *(pu8CurrByte++)  = ((ptstrJoinBssParam->beacon_period) >> 8) & 0xFF;
        PRINT_D(HOSTINF_DBG, "* Beacon Period %d*\n", (*(pu8CurrByte - 2) | ((*(pu8CurrByte - 1)) << 8)));
-       /* DTIM Period*/
        *(pu8CurrByte++)  =  ptstrJoinBssParam->dtim_period;
        PRINT_D(HOSTINF_DBG, "* DTIM Period %d*\n", (*(pu8CurrByte - 1)));
-       /* Supported rates*/
+
        memcpy(pu8CurrByte, ptstrJoinBssParam->supp_rates, MAX_RATES_SUPPORTED + 1);
        pu8CurrByte += (MAX_RATES_SUPPORTED + 1);
 
-       /* wmm cap*/
        *(pu8CurrByte++)  =  ptstrJoinBssParam->wmm_cap;
        PRINT_D(HOSTINF_DBG, "* wmm cap%d*\n", (*(pu8CurrByte - 1)));
-       /* uapsd cap*/
        *(pu8CurrByte++)  = ptstrJoinBssParam->uapsd_cap;
 
-       /* ht cap*/
        *(pu8CurrByte++)  = ptstrJoinBssParam->ht_capable;
-       /* copy this information to the user request */
-       pstrWFIDrv->strWILC_UsrConnReq.IsHTCapable = ptstrJoinBssParam->ht_capable;
+       hif_drv->usr_conn_req.IsHTCapable = ptstrJoinBssParam->ht_capable;
 
-       /* rsn found*/
        *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_found;
        PRINT_D(HOSTINF_DBG, "* rsn found %d*\n", *(pu8CurrByte - 1));
-       /* rsn group policy*/
        *(pu8CurrByte++)  =  ptstrJoinBssParam->rsn_grp_policy;
        PRINT_D(HOSTINF_DBG, "* rsn group policy %0x*\n", (*(pu8CurrByte - 1)));
-       /* mode_802_11i*/
        *(pu8CurrByte++) =  ptstrJoinBssParam->mode_802_11i;
        PRINT_D(HOSTINF_DBG, "* mode_802_11i %d*\n", (*(pu8CurrByte - 1)));
-       /* rsn pcip policy*/
+
        memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_pcip_policy, sizeof(ptstrJoinBssParam->rsn_pcip_policy));
        pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_pcip_policy);
 
-       /* rsn auth policy*/
        memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_auth_policy, sizeof(ptstrJoinBssParam->rsn_auth_policy));
        pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_auth_policy);
 
-       /* rsn auth policy*/
        memcpy(pu8CurrByte, ptstrJoinBssParam->rsn_cap, sizeof(ptstrJoinBssParam->rsn_cap));
        pu8CurrByte += sizeof(ptstrJoinBssParam->rsn_cap);
 
-       /*BugID_5137*/
        *(pu8CurrByte++) = REAL_JOIN_REQ;
+       *(pu8CurrByte++) = ptstrJoinBssParam->noa_enabled;
 
-               #ifdef WILC_P2P
-       *(pu8CurrByte++) = ptstrJoinBssParam->u8NoaEnbaled;
-       if (ptstrJoinBssParam->u8NoaEnbaled) {
+       if (ptstrJoinBssParam->noa_enabled) {
                PRINT_D(HOSTINF_DBG, "NOA present\n");
 
                *(pu8CurrByte++) = (ptstrJoinBssParam->tsf) & 0xFF;
@@ -1897,105 +1170,83 @@ static s32 Handle_Connect(tstrWILC_WFIDrv *drvHandler, tstrHostIFconnectAttr *ps
                *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 16) & 0xFF;
                *(pu8CurrByte++) = ((ptstrJoinBssParam->tsf) >> 24) & 0xFF;
 
-               *(pu8CurrByte++) = ptstrJoinBssParam->u8Index;
-
-               *(pu8CurrByte++) = ptstrJoinBssParam->u8OppEnable;
-
-               if (ptstrJoinBssParam->u8OppEnable)
-                       *(pu8CurrByte++) = ptstrJoinBssParam->u8CtWindow;
-
-               *(pu8CurrByte++) = ptstrJoinBssParam->u8Count;
+               *(pu8CurrByte++) = ptstrJoinBssParam->opp_enabled;
+               *(pu8CurrByte++) = ptstrJoinBssParam->idx;
 
-               memcpy(pu8CurrByte, ptstrJoinBssParam->au8Duration, sizeof(ptstrJoinBssParam->au8Duration));
+               if (ptstrJoinBssParam->opp_enabled)
+                       *(pu8CurrByte++) = ptstrJoinBssParam->ct_window;
 
-               pu8CurrByte += sizeof(ptstrJoinBssParam->au8Duration);
+               *(pu8CurrByte++) = ptstrJoinBssParam->cnt;
 
-               memcpy(pu8CurrByte, ptstrJoinBssParam->au8Interval, sizeof(ptstrJoinBssParam->au8Interval));
+               memcpy(pu8CurrByte, ptstrJoinBssParam->duration, sizeof(ptstrJoinBssParam->duration));
+               pu8CurrByte += sizeof(ptstrJoinBssParam->duration);
 
-               pu8CurrByte += sizeof(ptstrJoinBssParam->au8Interval);
-
-               memcpy(pu8CurrByte, ptstrJoinBssParam->au8StartTime, sizeof(ptstrJoinBssParam->au8StartTime));
-
-               pu8CurrByte += sizeof(ptstrJoinBssParam->au8StartTime);
+               memcpy(pu8CurrByte, ptstrJoinBssParam->interval, sizeof(ptstrJoinBssParam->interval));
+               pu8CurrByte += sizeof(ptstrJoinBssParam->interval);
 
+               memcpy(pu8CurrByte, ptstrJoinBssParam->start_time, sizeof(ptstrJoinBssParam->start_time));
+               pu8CurrByte += sizeof(ptstrJoinBssParam->start_time);
        } else
                PRINT_D(HOSTINF_DBG, "NOA not present\n");
-       #endif
-
-
-       /* keep the buffer at the start of the allocated pointer to use it with the free*/
-       pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
 
-
-       #endif /* #ifdef WILC_PARSE_SCAN_IN_HOST*/
+       pu8CurrByte = strWIDList[u32WidsCount].val;
        u32WidsCount++;
 
-       /* A temporary workaround to avoid handling the misleading MAC_DISCONNECTED raised from the
-        *   firmware at chip reset when processing the WIDs of the Connect Request.
-        *   (This workaround should be removed in the future when the Chip reset of the Connect WIDs is disabled) */
-       /* ////////////////////// */
-       gu32WidConnRstHack = 0;
-       /* ////////////////////// */
-
-       /*BugID_5137*/
-       if (memcmp("DIRECT-", pstrHostIFconnectAttr->pu8ssid, 7)) {
-               memcpy(gu8FlushedJoinReq, pu8CurrByte, gu32FlushedJoinReqSize);
-               gu8FlushedJoinReqDrvHandler = (u32)pstrWFIDrv;
+       if (memcmp("DIRECT-", pstrHostIFconnectAttr->ssid, 7)) {
+               memcpy(join_req, pu8CurrByte, join_req_size);
+               join_req_drv = hif_drv;
        }
 
        PRINT_D(GENERIC_DBG, "send HOST_IF_WAITING_CONN_RESP\n");
 
-       if (pstrHostIFconnectAttr->pu8bssid != NULL) {
-               memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->pu8bssid, ETH_ALEN);
+       if (pstrHostIFconnectAttr->bssid) {
+               memcpy(u8ConnectedSSID, pstrHostIFconnectAttr->bssid, ETH_ALEN);
 
-               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]));
-               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]));
+               PRINT_D(GENERIC_DBG, "save Bssid = %pM\n", pstrHostIFconnectAttr->bssid);
+               PRINT_D(GENERIC_DBG, "save bssid = %pM\n", u8ConnectedSSID);
        }
 
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, (u32)pstrWFIDrv);
-       if (s32Error) {
-               PRINT_ER("Handle_Connect()] failed to send config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
+       result = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
+                                get_id_from_handler(hif_drv));
+       if (result) {
+               PRINT_ER("failed to send config packet\n");
+               result = -EFAULT;
+               goto ERRORHANDLER;
        } else {
                PRINT_D(GENERIC_DBG, "set HOST_IF_WAITING_CONN_RESP\n");
-               pstrWFIDrv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
+               hif_drv->enuHostIFstate = HOST_IF_WAITING_CONN_RESP;
        }
-       #endif
 
-       WILC_CATCH(s32Error)
-       {
+ERRORHANDLER:
+       if (result) {
                tstrConnectInfo strConnectInfo;
 
-               del_timer(&pstrWFIDrv->hConnectTimer);
+               del_timer(&hif_drv->hConnectTimer);
 
                PRINT_D(HOSTINF_DBG, "could not start connecting to the required network\n");
 
                memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
 
-               if (pstrHostIFconnectAttr->pfConnectResult != NULL) {
-                       if (pstrHostIFconnectAttr->pu8bssid != NULL)
-                               memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->pu8bssid, 6);
+               if (pstrHostIFconnectAttr->result) {
+                       if (pstrHostIFconnectAttr->bssid)
+                               memcpy(strConnectInfo.au8bssid, pstrHostIFconnectAttr->bssid, 6);
 
-                       if (pstrHostIFconnectAttr->pu8IEs != NULL) {
-                               strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->IEsLen;
-                               strConnectInfo.pu8ReqIEs = WILC_MALLOC(pstrHostIFconnectAttr->IEsLen);
+                       if (pstrHostIFconnectAttr->ies) {
+                               strConnectInfo.ReqIEsLen = pstrHostIFconnectAttr->ies_len;
+                               strConnectInfo.pu8ReqIEs = kmalloc(pstrHostIFconnectAttr->ies_len, GFP_KERNEL);
                                memcpy(strConnectInfo.pu8ReqIEs,
-                                           pstrHostIFconnectAttr->pu8IEs,
-                                           pstrHostIFconnectAttr->IEsLen);
+                                      pstrHostIFconnectAttr->ies,
+                                      pstrHostIFconnectAttr->ies_len);
                        }
 
-                       pstrHostIFconnectAttr->pfConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
+                       pstrHostIFconnectAttr->result(CONN_DISCONN_EVENT_CONN_RESP,
                                                               &strConnectInfo,
                                                               MAC_DISCONNECTED,
                                                               NULL,
-                                                              pstrHostIFconnectAttr->pvUserArg);
-                       /*Change state to idle*/
-                       pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
-                       /* Deallocation */
-                       if (strConnectInfo.pu8ReqIEs != NULL) {
-                               kfree(strConnectInfo.pu8ReqIEs);
-                               strConnectInfo.pu8ReqIEs = NULL;
-                       }
+                                                              pstrHostIFconnectAttr->arg);
+                       hif_drv->enuHostIFstate = HOST_IF_IDLE;
+                       kfree(strConnectInfo.pu8ReqIEs);
+                       strConnectInfo.pu8ReqIEs = NULL;
 
                } else {
                        PRINT_ER("Connect callback function pointer is NULL\n");
@@ -2003,259 +1254,174 @@ static s32 Handle_Connect(tstrWILC_WFIDrv *drvHandler, tstrHostIFconnectAttr *ps
        }
 
        PRINT_D(HOSTINF_DBG, "Deallocating connection parameters\n");
-       /* Deallocate pstrHostIFconnectAttr->pu8bssid which was prevoisuly allocated by the sending thread */
-       if (pstrHostIFconnectAttr->pu8bssid != NULL) {
-               kfree(pstrHostIFconnectAttr->pu8bssid);
-               pstrHostIFconnectAttr->pu8bssid = NULL;
-       }
+       kfree(pstrHostIFconnectAttr->bssid);
+       pstrHostIFconnectAttr->bssid = NULL;
 
-       /* Deallocate pstrHostIFconnectAttr->pu8ssid which was prevoisuly allocated by the sending thread */
-       if (pstrHostIFconnectAttr->pu8ssid != NULL) {
-               kfree(pstrHostIFconnectAttr->pu8ssid);
-               pstrHostIFconnectAttr->pu8ssid = NULL;
-       }
+       kfree(pstrHostIFconnectAttr->ssid);
+       pstrHostIFconnectAttr->ssid = NULL;
 
-       /* Deallocate pstrHostIFconnectAttr->pu8IEs which was prevoisuly allocated by the sending thread */
-       if (pstrHostIFconnectAttr->pu8IEs != NULL) {
-               kfree(pstrHostIFconnectAttr->pu8IEs);
-               pstrHostIFconnectAttr->pu8IEs = NULL;
-       }
+       kfree(pstrHostIFconnectAttr->ies);
+       pstrHostIFconnectAttr->ies = NULL;
 
-       if (pu8CurrByte != NULL)
-               kfree(pu8CurrByte);
-       return s32Error;
+       kfree(pu8CurrByte);
+       return result;
 }
 
-/**
- *  @brief                      Handle_FlushConnect
- *  @details            Sending config packet to firmware to flush an old connection
- *                              after switching FW from station one to hybrid one
- *  @param[in]          void * drvHandler
- *  @return             Error code.
- *  @author            Amr Abdel-Moghny
- *  @date                      19 DEC 2013
- *  @version           8.0
- */
-
-static s32 Handle_FlushConnect(tstrWILC_WFIDrv *drvHandler)
+static s32 Handle_FlushConnect(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWIDList[5];
+       s32 result = 0;
+       struct wid strWIDList[5];
        u32 u32WidsCount = 0;
        u8 *pu8CurrByte = NULL;
 
-
-       /* IEs to be inserted in Association Request */
-       strWIDList[u32WidsCount].u16WIDid = WID_INFO_ELEMENT_ASSOCIATE;
-       strWIDList[u32WidsCount].enuWIDtype = WID_BIN_DATA;
-       strWIDList[u32WidsCount].ps8WidVal = gu8FlushedInfoElemAsoc;
-       strWIDList[u32WidsCount].s32ValueSize = gu32FlushedInfoElemAsocSize;
+       strWIDList[u32WidsCount].id = WID_INFO_ELEMENT_ASSOCIATE;
+       strWIDList[u32WidsCount].type = WID_BIN_DATA;
+       strWIDList[u32WidsCount].val = info_element;
+       strWIDList[u32WidsCount].size = info_element_size;
        u32WidsCount++;
 
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_11I_MODE;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(gu8Flushed11iMode));
+       strWIDList[u32WidsCount].id = (u16)WID_11I_MODE;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)(&(mode_11i));
        u32WidsCount++;
 
-
-
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_AUTH_TYPE;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&gu8FlushedAuthType);
+       strWIDList[u32WidsCount].id = (u16)WID_AUTH_TYPE;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)(&auth_type);
        u32WidsCount++;
 
-
-       #ifdef WILC_PARSE_SCAN_IN_HOST
-       strWIDList[u32WidsCount].u16WIDid = (u16)WID_JOIN_REQ_EXTENDED;
-       strWIDList[u32WidsCount].enuWIDtype = WID_STR;
-       strWIDList[u32WidsCount].s32ValueSize = gu32FlushedJoinReqSize;
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)gu8FlushedJoinReq;
-       pu8CurrByte = strWIDList[u32WidsCount].ps8WidVal;
+       strWIDList[u32WidsCount].id = (u16)WID_JOIN_REQ_EXTENDED;
+       strWIDList[u32WidsCount].type = WID_STR;
+       strWIDList[u32WidsCount].size = join_req_size;
+       strWIDList[u32WidsCount].val = (s8 *)join_req;
+       pu8CurrByte = strWIDList[u32WidsCount].val;
 
        pu8CurrByte += FLUSHED_BYTE_POS;
        *(pu8CurrByte) = FLUSHED_JOIN_REQ;
 
        u32WidsCount++;
 
-       #endif
-
-       s32Error = SendConfigPkt(SET_CFG, strWIDList, u32WidsCount, false, gu8FlushedJoinReqDrvHandler);
-       if (s32Error) {
-               PRINT_ER("Handle_Flush_Connect()] failed to send config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       }
-
-       WILC_CATCH(s32Error)
-       {
-
+       result = send_config_pkt(SET_CFG, strWIDList, u32WidsCount,
+                                get_id_from_handler(join_req_drv));
+       if (result) {
+               PRINT_ER("failed to send config packet\n");
+               result = -EINVAL;
        }
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief                 Handle_ConnectTimeout
- *  @details       Call connect notification callback function indicating connection failure
- *  @param[in]    NONE
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_ConnectTimeout(tstrWILC_WFIDrv *drvHandler)
+static s32 Handle_ConnectTimeout(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
+       s32 result = 0;
        tstrConnectInfo strConnectInfo;
-       tstrWID strWID;
+       struct wid wid;
        u16 u16DummyReasonCode = 0;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
 
-       if (pstrWFIDrv == NULL) {
+       if (!hif_drv) {
                PRINT_ER("Driver handler is NULL\n");
-               return s32Error;
+               return result;
        }
 
-       pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
-
-       gbScanWhileConnected = false;
+       hif_drv->enuHostIFstate = HOST_IF_IDLE;
 
+       scan_while_connected = false;
 
        memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
 
-
-       /* First, we will notify the upper layer with the Connection failure {through the Connect Callback function},
-        *   then we will notify our firmware also with the Connection failure {through sending to it Cfg packet carrying
-        *   WID_DISCONNECT} */
-       if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) {
-               if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
+       if (hif_drv->usr_conn_req.pfUserConnectResult) {
+               if (hif_drv->usr_conn_req.pu8bssid) {
                        memcpy(strConnectInfo.au8bssid,
-                                   pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6);
+                              hif_drv->usr_conn_req.pu8bssid, 6);
                }
 
-               if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
-                       strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
-                       strConnectInfo.pu8ReqIEs = WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
+               if (hif_drv->usr_conn_req.pu8ConnReqIEs) {
+                       strConnectInfo.ReqIEsLen = hif_drv->usr_conn_req.ConnReqIEsLen;
+                       strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->usr_conn_req.ConnReqIEsLen, GFP_KERNEL);
                        memcpy(strConnectInfo.pu8ReqIEs,
-                                   pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
-                                   pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
+                              hif_drv->usr_conn_req.pu8ConnReqIEs,
+                              hif_drv->usr_conn_req.ConnReqIEsLen);
                }
 
-               pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
-                                                                  &strConnectInfo,
-                                                                  MAC_DISCONNECTED,
-                                                                  NULL,
-                                                                  pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
+               hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
+                                                         &strConnectInfo,
+                                                         MAC_DISCONNECTED,
+                                                         NULL,
+                                                         hif_drv->usr_conn_req.u32UserConnectPvoid);
 
-               /* Deallocation of strConnectInfo.pu8ReqIEs */
-               if (strConnectInfo.pu8ReqIEs != NULL) {
-                       kfree(strConnectInfo.pu8ReqIEs);
-                       strConnectInfo.pu8ReqIEs = NULL;
-               }
+               kfree(strConnectInfo.pu8ReqIEs);
+               strConnectInfo.pu8ReqIEs = NULL;
        } else {
                PRINT_ER("Connect callback function pointer is NULL\n");
        }
 
-       /* Here we will notify our firmware also with the Connection failure {through sending to it Cfg packet carrying
-        *   WID_DISCONNECT} */
-       strWID.u16WIDid = (u16)WID_DISCONNECT;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = (s8 *)&u16DummyReasonCode;
-       strWID.s32ValueSize = sizeof(char);
+       wid.id = (u16)WID_DISCONNECT;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)&u16DummyReasonCode;
+       wid.size = sizeof(char);
 
        PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
-       if (s32Error)
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send dissconect config packet\n");
 
-       /* Deallocation of the Saved Connect Request in the global Handle */
-       pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
-       if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
-               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
-               pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
-       }
+       hif_drv->usr_conn_req.ssidLen = 0;
+       kfree(hif_drv->usr_conn_req.pu8ssid);
+       kfree(hif_drv->usr_conn_req.pu8bssid);
+       hif_drv->usr_conn_req.ConnReqIEsLen = 0;
+       kfree(hif_drv->usr_conn_req.pu8ConnReqIEs);
 
-       if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
-               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
-               pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
-       }
+       eth_zero_addr(u8ConnectedSSID);
 
-       pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
-       if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
-               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
-               pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
+       if (join_req && join_req_drv == hif_drv) {
+               kfree(join_req);
+               join_req = NULL;
        }
 
-       memset(u8ConnectedSSID, 0, ETH_ALEN);
-       /*BugID_5213*/
-       /*Freeing flushed join request params on connect timeout*/
-       if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
-               kfree(gu8FlushedJoinReq);
-               gu8FlushedJoinReq = NULL;
-       }
-       if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
-               kfree(gu8FlushedInfoElemAsoc);
-               gu8FlushedInfoElemAsoc = NULL;
+       if (info_element && join_req_drv == hif_drv) {
+               kfree(info_element);
+               info_element = NULL;
        }
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief Handle_RcvdNtwrkInfo
- *  @details       Handling received network information
- *  @param[in]    tstrRcvdNetworkInfo* pstrRcvdNetworkInfo
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_RcvdNtwrkInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdNetworkInfo *pstrRcvdNetworkInfo)
+static s32 Handle_RcvdNtwrkInfo(struct host_if_drv *hif_drv,
+                               struct rcvd_net_info *pstrRcvdNetworkInfo)
 {
        u32 i;
        bool bNewNtwrkFound;
-
-
-
-       s32 s32Error = WILC_SUCCESS;
+       s32 result = 0;
        tstrNetworkInfo *pstrNetworkInfo = NULL;
        void *pJoinParams = NULL;
 
-       tstrWILC_WFIDrv *pstrWFIDrv  = (tstrWILC_WFIDrv *)drvHandler;
-
-
-
        bNewNtwrkFound = true;
        PRINT_INFO(HOSTINF_DBG, "Handling received network info\n");
 
-       /*if there is a an ongoing scan request*/
-       if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
+       if (hif_drv->usr_scan_req.pfUserScanResult) {
                PRINT_D(HOSTINF_DBG, "State: Scanning, parsing network information received\n");
-               ParseNetworkInfo(pstrRcvdNetworkInfo->pu8Buffer, &pstrNetworkInfo);
-               if ((pstrNetworkInfo == NULL)
-                   || (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult == NULL)) {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+               parse_network_info(pstrRcvdNetworkInfo->buffer, &pstrNetworkInfo);
+               if ((!pstrNetworkInfo) ||
+                   (!hif_drv->usr_scan_req.pfUserScanResult)) {
+                       PRINT_ER("driver is null\n");
+                       result = -EINVAL;
+                       goto done;
                }
 
-               /* check whether this network is discovered before */
-               for (i = 0; i < pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount; i++) {
-
-                       if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid != NULL) &&
-                           (pstrNetworkInfo->au8bssid != NULL)) {
-                               if (memcmp(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].au8bssid,
-                                               pstrNetworkInfo->au8bssid, 6) == 0) {
-                                       if (pstrNetworkInfo->s8rssi <= pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi) {
-                                               /*we have already found this network with better rssi, so keep the old cached one and don't
-                                                *  send anything to the upper layer */
+               for (i = 0; i < hif_drv->usr_scan_req.u32RcvdChCount; i++) {
+                       if ((hif_drv->usr_scan_req.astrFoundNetworkInfo[i].au8bssid) &&
+                           (pstrNetworkInfo->au8bssid)) {
+                               if (memcmp(hif_drv->usr_scan_req.astrFoundNetworkInfo[i].au8bssid,
+                                          pstrNetworkInfo->au8bssid, 6) == 0) {
+                                       if (pstrNetworkInfo->s8rssi <= hif_drv->usr_scan_req.astrFoundNetworkInfo[i].s8rssi) {
                                                PRINT_D(HOSTINF_DBG, "Network previously discovered\n");
                                                goto done;
                                        } else {
-                                               /* here the same already found network is found again but with a better rssi, so just update
-                                                *   the rssi for this cached network and send this updated network to the upper layer but
-                                                *   don't add a new record for it */
-                                               pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[i].s8rssi = pstrNetworkInfo->s8rssi;
+                                               hif_drv->usr_scan_req.astrFoundNetworkInfo[i].s8rssi = pstrNetworkInfo->s8rssi;
                                                bNewNtwrkFound = false;
                                                break;
                                        }
@@ -2263,82 +1429,52 @@ static s32 Handle_RcvdNtwrkInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdNetworkInfo
                        }
                }
 
-               if (bNewNtwrkFound == true) {
-                       /* here it is confirmed that it is a new discovered network,
-                        * so add its record then call the User CallBack function */
-
+               if (bNewNtwrkFound) {
                        PRINT_D(HOSTINF_DBG, "New network found\n");
 
-                       if (pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) {
-                               pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].s8rssi = pstrNetworkInfo->s8rssi;
+                       if (hif_drv->usr_scan_req.u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) {
+                               hif_drv->usr_scan_req.astrFoundNetworkInfo[hif_drv->usr_scan_req.u32RcvdChCount].s8rssi = pstrNetworkInfo->s8rssi;
 
-                               if ((pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid != NULL)
-                                   && (pstrNetworkInfo->au8bssid != NULL)) {
-                                       memcpy(pstrWFIDrv->strWILC_UsrScanReq.astrFoundNetworkInfo[pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount].au8bssid,
-                                                   pstrNetworkInfo->au8bssid, 6);
+                               if (hif_drv->usr_scan_req.astrFoundNetworkInfo[hif_drv->usr_scan_req.u32RcvdChCount].au8bssid &&
+                                   pstrNetworkInfo->au8bssid) {
+                                       memcpy(hif_drv->usr_scan_req.astrFoundNetworkInfo[hif_drv->usr_scan_req.u32RcvdChCount].au8bssid,
+                                              pstrNetworkInfo->au8bssid, 6);
 
-                                       pstrWFIDrv->strWILC_UsrScanReq.u32RcvdChCount++;
+                                       hif_drv->usr_scan_req.u32RcvdChCount++;
 
                                        pstrNetworkInfo->bNewNetwork = true;
-                                       /*Bug4218: Parsing Join Param*/
-                                       /* add new BSS to JoinBssTable */
-                               #ifdef WILC_PARSE_SCAN_IN_HOST
                                        pJoinParams = host_int_ParseJoinBssParam(pstrNetworkInfo);
-                               #endif /*WILC_PARSE_SCAN_IN_HOST*/
-
-                                       pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
-                                                                                       pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid,
-                                                                                       pJoinParams);
-
 
+                                       hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
+                                                                              hif_drv->usr_scan_req.u32UserScanPvoid,
+                                                                              pJoinParams);
                                }
                        } else {
                                PRINT_WRN(HOSTINF_DBG, "Discovered networks exceeded max. limit\n");
                        }
                } else {
                        pstrNetworkInfo->bNewNetwork = false;
-                       /* just call the User CallBack function to send the same discovered network with its updated RSSI */
-                       pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
-                                                                       pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
+                       hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_NETWORK_FOUND, pstrNetworkInfo,
+                                                              hif_drv->usr_scan_req.u32UserScanPvoid, NULL);
                }
        }
 
-
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
 done:
-       /* Deallocate pstrRcvdNetworkInfo->pu8Buffer which was prevoisuly allocated by the sending thread */
-       if (pstrRcvdNetworkInfo->pu8Buffer != NULL) {
-               kfree(pstrRcvdNetworkInfo->pu8Buffer);
-               pstrRcvdNetworkInfo->pu8Buffer = NULL;
-       }
+       kfree(pstrRcvdNetworkInfo->buffer);
+       pstrRcvdNetworkInfo->buffer = NULL;
 
-       /*free structure allocated*/
-       if (pstrNetworkInfo != NULL) {
+       if (pstrNetworkInfo) {
                DeallocateNetworkInfo(pstrNetworkInfo);
                pstrNetworkInfo = NULL;
        }
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief Handle_RcvdGnrlAsyncInfo
- *  @details       Handling received asynchrous general network information
- *  @param[in]    tstrRcvdGnrlAsyncInfo* pstrRcvdGnrlAsyncInfo
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_RcvdGnrlAsyncInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdGnrlAsyncInfo *pstrRcvdGnrlAsyncInfo)
+static s32 Handle_RcvdGnrlAsyncInfo(struct host_if_drv *hif_drv,
+                                   struct rcvd_async_info *pstrRcvdGnrlAsyncInfo)
 {
-       /* TODO: mostafa: till now, this function just handles only the received mac status msg, */
-       /*                               which carries only 1 WID which have WID ID = WID_STATUS */
-       s32 s32Error = WILC_SUCCESS;
+       s32 result = 0;
        u8 u8MsgType = 0;
        u8 u8MsgID = 0;
        u16 u16MsgLen = 0;
@@ -2349,49 +1485,40 @@ static s32 Handle_RcvdGnrlAsyncInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdGnrlAsy
        u8 u8MacStatusAdditionalInfo;
        tstrConnectInfo strConnectInfo;
        tstrDisconnectNotifInfo strDisconnectNotifInfo;
-       s32 s32Err = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
+       s32 s32Err = 0;
 
-       if (pstrWFIDrv == NULL)
+       if (!hif_drv) {
                PRINT_ER("Driver handler is NULL\n");
-       PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", pstrWFIDrv->enuHostIFstate,
-               pstrRcvdGnrlAsyncInfo->pu8Buffer[7]);
-
-       if ((pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) ||
-           (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) ||
-           pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
-               if ((pstrRcvdGnrlAsyncInfo->pu8Buffer == NULL) ||
-                   (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult == NULL)) {
-                       WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+               return -ENODEV;
+       }
+       PRINT_D(GENERIC_DBG, "Current State = %d,Received state = %d\n", hif_drv->enuHostIFstate,
+               pstrRcvdGnrlAsyncInfo->buffer[7]);
+
+       if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) ||
+           (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) ||
+           hif_drv->usr_scan_req.pfUserScanResult) {
+               if (!pstrRcvdGnrlAsyncInfo->buffer ||
+                   !hif_drv->usr_conn_req.pfUserConnectResult) {
+                       PRINT_ER("driver is null\n");
+                       return -EINVAL;
                }
 
-               u8MsgType = pstrRcvdGnrlAsyncInfo->pu8Buffer[0];
+               u8MsgType = pstrRcvdGnrlAsyncInfo->buffer[0];
 
-               /* Check whether the received message type is 'I' */
                if ('I' != u8MsgType) {
                        PRINT_ER("Received Message format incorrect.\n");
-                       WILC_ERRORREPORT(s32Error, WILC_FAIL);
+                       return -EFAULT;
                }
 
-               /* Extract message ID */
-               u8MsgID = pstrRcvdGnrlAsyncInfo->pu8Buffer[1];
-
-               /* Extract message Length */
-               u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[2], pstrRcvdGnrlAsyncInfo->pu8Buffer[3]);
-
-               /* Extract WID ID [expected to be = WID_STATUS] */
-               u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->pu8Buffer[4], pstrRcvdGnrlAsyncInfo->pu8Buffer[5]);
-
-               /* Extract WID Length [expected to be = 1] */
-               u8WidLen = pstrRcvdGnrlAsyncInfo->pu8Buffer[6];
-
-               /* get the WID value [expected to be one of two values: either MAC_CONNECTED = (1) or MAC_DISCONNECTED = (0)] */
-               u8MacStatus  = pstrRcvdGnrlAsyncInfo->pu8Buffer[7];
-               u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->pu8Buffer[8];
-               u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->pu8Buffer[9];
+               u8MsgID = pstrRcvdGnrlAsyncInfo->buffer[1];
+               u16MsgLen = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[2], pstrRcvdGnrlAsyncInfo->buffer[3]);
+               u16WidID = MAKE_WORD16(pstrRcvdGnrlAsyncInfo->buffer[4], pstrRcvdGnrlAsyncInfo->buffer[5]);
+               u8WidLen = pstrRcvdGnrlAsyncInfo->buffer[6];
+               u8MacStatus  = pstrRcvdGnrlAsyncInfo->buffer[7];
+               u8MacStatusReasonCode = pstrRcvdGnrlAsyncInfo->buffer[8];
+               u8MacStatusAdditionalInfo = pstrRcvdGnrlAsyncInfo->buffer[9];
                PRINT_INFO(HOSTINF_DBG, "Recieved MAC status = %d with Reason = %d , Info = %d\n", u8MacStatus, u8MacStatusReasonCode, u8MacStatusAdditionalInfo);
-               if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
-                       /* our station had sent Association Request frame, so here it will get the Association Response frame then parse it */
+               if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
                        u32 u32RcvdAssocRespInfoLen;
                        tstrConnectRespInfo *pstrConnectRespInfo = NULL;
 
@@ -2400,40 +1527,35 @@ static s32 Handle_RcvdGnrlAsyncInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdGnrlAsy
                        memset(&strConnectInfo, 0, sizeof(tstrConnectInfo));
 
                        if (u8MacStatus == MAC_CONNECTED) {
-                               memset(gapu8RcvdAssocResp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
+                               memset(rcv_assoc_resp, 0, MAX_ASSOC_RESP_FRAME_SIZE);
 
-                               host_int_get_assoc_res_info(pstrWFIDrv,
-                                                           gapu8RcvdAssocResp,
+                               host_int_get_assoc_res_info(hif_drv,
+                                                           rcv_assoc_resp,
                                                            MAX_ASSOC_RESP_FRAME_SIZE,
                                                            &u32RcvdAssocRespInfoLen);
 
                                PRINT_INFO(HOSTINF_DBG, "Received association response with length = %d\n", u32RcvdAssocRespInfoLen);
 
                                if (u32RcvdAssocRespInfoLen != 0) {
-
                                        PRINT_D(HOSTINF_DBG, "Parsing association response\n");
-                                       s32Err = ParseAssocRespInfo(gapu8RcvdAssocResp, u32RcvdAssocRespInfoLen,
+                                       s32Err = ParseAssocRespInfo(rcv_assoc_resp, u32RcvdAssocRespInfoLen,
                                                                    &pstrConnectRespInfo);
                                        if (s32Err) {
                                                PRINT_ER("ParseAssocRespInfo() returned error %d\n", s32Err);
                                        } else {
-                                               /* use the necessary parsed Info from the Received Association Response */
                                                strConnectInfo.u16ConnectStatus = pstrConnectRespInfo->u16ConnectStatus;
 
                                                if (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE) {
                                                        PRINT_INFO(HOSTINF_DBG, "Association response received : Successful connection status\n");
-                                                       if (pstrConnectRespInfo->pu8RespIEs != NULL) {
+                                                       if (pstrConnectRespInfo->pu8RespIEs) {
                                                                strConnectInfo.u16RespIEsLen = pstrConnectRespInfo->u16RespIEsLen;
-
-
-                                                               strConnectInfo.pu8RespIEs = WILC_MALLOC(pstrConnectRespInfo->u16RespIEsLen);
+                                                               strConnectInfo.pu8RespIEs = kmalloc(pstrConnectRespInfo->u16RespIEsLen, GFP_KERNEL);
                                                                memcpy(strConnectInfo.pu8RespIEs, pstrConnectRespInfo->pu8RespIEs,
                                                                            pstrConnectRespInfo->u16RespIEsLen);
                                                        }
                                                }
 
-                                               /* deallocate the Assoc. Resp. parsed structure as it is not needed anymore */
-                                               if (pstrConnectRespInfo != NULL) {
+                                               if (pstrConnectRespInfo) {
                                                        DeallocateAssocRespInfo(pstrConnectRespInfo);
                                                        pstrConnectRespInfo = NULL;
                                                }
@@ -2441,623 +1563,430 @@ static s32 Handle_RcvdGnrlAsyncInfo(tstrWILC_WFIDrv *drvHandler, tstrRcvdGnrlAsy
                                }
                        }
 
-                       /* The station has just received mac status and it also received assoc. response which
-                        *   it was waiting for.
-                        *   So check first the matching between the received mac status and the received status code in Asoc Resp */
                        if ((u8MacStatus == MAC_CONNECTED) &&
                            (strConnectInfo.u16ConnectStatus != SUCCESSFUL_STATUSCODE)) {
                                PRINT_ER("Received MAC status is MAC_CONNECTED while the received status code in Asoc Resp is not SUCCESSFUL_STATUSCODE\n");
-                               memset(u8ConnectedSSID, 0, ETH_ALEN);
+                               eth_zero_addr(u8ConnectedSSID);
 
                        } else if (u8MacStatus == MAC_DISCONNECTED)    {
                                PRINT_ER("Received MAC status is MAC_DISCONNECTED\n");
-                               memset(u8ConnectedSSID, 0, ETH_ALEN);
+                               eth_zero_addr(u8ConnectedSSID);
                        }
 
-                       /* TODO: mostafa: correct BSSID should be retrieved from actual BSSID received from AP */
-                       /*               through a structure of type tstrConnectRespInfo */
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
+                       if (hif_drv->usr_conn_req.pu8bssid) {
                                PRINT_D(HOSTINF_DBG, "Retrieving actual BSSID from AP\n");
-                               memcpy(strConnectInfo.au8bssid, pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, 6);
+                               memcpy(strConnectInfo.au8bssid, hif_drv->usr_conn_req.pu8bssid, 6);
 
                                if ((u8MacStatus == MAC_CONNECTED) &&
                                    (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
-                                       memcpy(pstrWFIDrv->au8AssociatedBSSID,
-                                                   pstrWFIDrv->strWILC_UsrConnReq.pu8bssid, ETH_ALEN);
+                                       memcpy(hif_drv->au8AssociatedBSSID,
+                                              hif_drv->usr_conn_req.pu8bssid, ETH_ALEN);
                                }
                        }
 
-
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
-                               strConnectInfo.ReqIEsLen = pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen;
-                               strConnectInfo.pu8ReqIEs = WILC_MALLOC(pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
+                       if (hif_drv->usr_conn_req.pu8ConnReqIEs) {
+                               strConnectInfo.ReqIEsLen = hif_drv->usr_conn_req.ConnReqIEsLen;
+                               strConnectInfo.pu8ReqIEs = kmalloc(hif_drv->usr_conn_req.ConnReqIEsLen, GFP_KERNEL);
                                memcpy(strConnectInfo.pu8ReqIEs,
-                                           pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs,
-                                           pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen);
+                                      hif_drv->usr_conn_req.pu8ConnReqIEs,
+                                      hif_drv->usr_conn_req.ConnReqIEsLen);
                        }
 
+                       del_timer(&hif_drv->hConnectTimer);
+                       hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
+                                                                 &strConnectInfo,
+                                                                 u8MacStatus,
+                                                                 NULL,
+                                                                 hif_drv->usr_conn_req.u32UserConnectPvoid);
 
-                       del_timer(&pstrWFIDrv->hConnectTimer);
-                       pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_CONN_RESP,
-                                                                          &strConnectInfo,
-                                                                          u8MacStatus,
-                                                                          NULL,
-                                                                          pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
-
-
-                       /* if received mac status is MAC_CONNECTED and
-                        *  received status code in Asoc Resp is SUCCESSFUL_STATUSCODE, change state to CONNECTED
-                        *  else change state to IDLE */
                        if ((u8MacStatus == MAC_CONNECTED) &&
                            (strConnectInfo.u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
-                               #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
-
-                               host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
-                               #endif
+                               host_int_set_power_mgmt(hif_drv, 0, 0);
 
                                PRINT_D(HOSTINF_DBG, "MAC status : CONNECTED and Connect Status : Successful\n");
-                               pstrWFIDrv->enuHostIFstate = HOST_IF_CONNECTED;
+                               hif_drv->enuHostIFstate = HOST_IF_CONNECTED;
 
-                               #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
                                PRINT_D(GENERIC_DBG, "Obtaining an IP, Disable Scan\n");
                                g_obtainingIP = true;
                                mod_timer(&hDuringIpTimer,
                                          jiffies + msecs_to_jiffies(10000));
-                               #endif
-
-                               #ifdef WILC_PARSE_SCAN_IN_HOST
-                               /* open a BA session if possible */
-                               /* if(pstrWFIDrv->strWILC_UsrConnReq.IsHTCapable) */
-
-                               #endif
-
-                               /* host_int_addBASession(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid,0, */
-                               /* BA_SESSION_DEFAULT_BUFFER_SIZE,BA_SESSION_DEFAULT_TIMEOUT); */
                        } else {
                                PRINT_D(HOSTINF_DBG, "MAC status : %d and Connect Status : %d\n", u8MacStatus, strConnectInfo.u16ConnectStatus);
-                               pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
-                               gbScanWhileConnected = false;
-                       }
-
-                       /* Deallocation */
-                       if (strConnectInfo.pu8RespIEs != NULL) {
-                               kfree(strConnectInfo.pu8RespIEs);
-                               strConnectInfo.pu8RespIEs = NULL;
-                       }
-
-                       if (strConnectInfo.pu8ReqIEs != NULL) {
-                               kfree(strConnectInfo.pu8ReqIEs);
-                               strConnectInfo.pu8ReqIEs = NULL;
+                               hif_drv->enuHostIFstate = HOST_IF_IDLE;
+                               scan_while_connected = false;
                        }
 
+                       kfree(strConnectInfo.pu8RespIEs);
+                       strConnectInfo.pu8RespIEs = NULL;
 
-                       pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
-                               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
-                               pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
-                       }
-
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
-                               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
-                               pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
-                       }
-
-                       pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
-                               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
-                               pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
-                       }
-
+                       kfree(strConnectInfo.pu8ReqIEs);
+                       strConnectInfo.pu8ReqIEs = NULL;
+                       hif_drv->usr_conn_req.ssidLen = 0;
+                       kfree(hif_drv->usr_conn_req.pu8ssid);
+                       kfree(hif_drv->usr_conn_req.pu8bssid);
+                       hif_drv->usr_conn_req.ConnReqIEsLen = 0;
+                       kfree(hif_drv->usr_conn_req.pu8ConnReqIEs);
                } else if ((u8MacStatus == MAC_DISCONNECTED) &&
-                          (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED)) {
-                       /* Disassociation or Deauthentication frame has been received */
+                          (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)) {
                        PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW\n");
 
                        memset(&strDisconnectNotifInfo, 0, sizeof(tstrDisconnectNotifInfo));
 
-                       if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
+                       if (hif_drv->usr_scan_req.pfUserScanResult) {
                                PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running OBSS Scan >>\n\n");
-                               del_timer(&pstrWFIDrv->hScanTimer);
-                               Handle_ScanDone((void *)pstrWFIDrv, SCAN_EVENT_ABORTED);
+                               del_timer(&hif_drv->hScanTimer);
+                               Handle_ScanDone((void *)hif_drv, SCAN_EVENT_ABORTED);
                        }
 
                        strDisconnectNotifInfo.u16reason = 0;
                        strDisconnectNotifInfo.ie = NULL;
                        strDisconnectNotifInfo.ie_len = 0;
 
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) {
-                               #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
-
+                       if (hif_drv->usr_conn_req.pfUserConnectResult) {
                                g_obtainingIP = false;
-                               host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
-                               #endif
-
-                               pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF,
-                                                                                  NULL,
-                                                                                  0,
-                                                                                  &strDisconnectNotifInfo,
-                                                                                  pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
+                               host_int_set_power_mgmt(hif_drv, 0, 0);
 
+                               hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF,
+                                                                         NULL,
+                                                                         0,
+                                                                         &strDisconnectNotifInfo,
+                                                                         hif_drv->usr_conn_req.u32UserConnectPvoid);
                        } else {
                                PRINT_ER("Connect result callback function is NULL\n");
                        }
 
-                       memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN);
-
-
-                       /* Deallocation */
+                       eth_zero_addr(hif_drv->au8AssociatedBSSID);
 
-                       /* if Information Elements were retrieved from the Received deauth/disassoc frame, then they
-                        *  should be deallocated here */
-                       /*
-                        * if(strDisconnectNotifInfo.ie != NULL)
-                        * {
-                        *      kfree(strDisconnectNotifInfo.ie);
-                        *      strDisconnectNotifInfo.ie = NULL;
-                        * }
-                        */
-
-                       pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
-                               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
-                               pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
-                       }
-
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
-                               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
-                               pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
-                       }
+                       hif_drv->usr_conn_req.ssidLen = 0;
+                       kfree(hif_drv->usr_conn_req.pu8ssid);
+                       kfree(hif_drv->usr_conn_req.pu8bssid);
+                       hif_drv->usr_conn_req.ConnReqIEsLen = 0;
+                       kfree(hif_drv->usr_conn_req.pu8ConnReqIEs);
 
-                       pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
-                       if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
-                               kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
-                               pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
+                       if (join_req && join_req_drv == hif_drv) {
+                               kfree(join_req);
+                               join_req = NULL;
                        }
 
-                       /*BugID_5213*/
-                       /*Freeing flushed join request params on receiving*/
-                       /*MAC_DISCONNECTED while connected*/
-                       if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
-                               kfree(gu8FlushedJoinReq);
-                               gu8FlushedJoinReq = NULL;
-                       }
-                       if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
-                               kfree(gu8FlushedInfoElemAsoc);
-                               gu8FlushedInfoElemAsoc = NULL;
+                       if (info_element && join_req_drv == hif_drv) {
+                               kfree(info_element);
+                               info_element = NULL;
                        }
 
-                       pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
-                       gbScanWhileConnected = false;
+                       hif_drv->enuHostIFstate = HOST_IF_IDLE;
+                       scan_while_connected = false;
 
                } else if ((u8MacStatus == MAC_DISCONNECTED) &&
-                          (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL)) {
+                          (hif_drv->usr_scan_req.pfUserScanResult)) {
                        PRINT_D(HOSTINF_DBG, "Received MAC_DISCONNECTED from the FW while scanning\n");
                        PRINT_D(HOSTINF_DBG, "\n\n<< Abort the running Scan >>\n\n");
-                       /*Abort the running scan*/
-                       del_timer(&pstrWFIDrv->hScanTimer);
-                       if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult)
-                               Handle_ScanDone(pstrWFIDrv, SCAN_EVENT_ABORTED);
 
+                       del_timer(&hif_drv->hScanTimer);
+                       if (hif_drv->usr_scan_req.pfUserScanResult)
+                               Handle_ScanDone(hif_drv, SCAN_EVENT_ABORTED);
                }
-
-       }
-
-       WILC_CATCH(s32Error)
-       {
-
        }
 
-       /* Deallocate pstrRcvdGnrlAsyncInfo->pu8Buffer which was prevoisuly allocated by the sending thread */
-       if (pstrRcvdGnrlAsyncInfo->pu8Buffer != NULL) {
-               kfree(pstrRcvdGnrlAsyncInfo->pu8Buffer);
-               pstrRcvdGnrlAsyncInfo->pu8Buffer = NULL;
-       }
+       kfree(pstrRcvdGnrlAsyncInfo->buffer);
+       pstrRcvdGnrlAsyncInfo->buffer = NULL;
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief Handle_Key
- *  @details       Sending config packet to firmware to set key
- *  @param[in]    tstrHostIFkeyAttr* pstrHostIFkeyAttr
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-static int Handle_Key(tstrWILC_WFIDrv *drvHandler, tstrHostIFkeyAttr *pstrHostIFkeyAttr)
+static int Handle_Key(struct host_if_drv *hif_drv,
+                     struct key_attr *pstrHostIFkeyAttr)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       #ifdef WILC_AP_EXTERNAL_MLME
-       tstrWID strWIDList[5];
-       #endif
+       s32 result = 0;
+       struct wid wid;
+       struct wid strWIDList[5];
        u8 i;
        u8 *pu8keybuf;
        s8 s8idxarray[1];
        s8 ret = 0;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
+       switch (pstrHostIFkeyAttr->type) {
+       case WEP:
 
-       switch (pstrHostIFkeyAttr->enuKeyType) {
-
-
-       case WEP:
-
-#ifdef WILC_AP_EXTERNAL_MLME
-               if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
-
+               if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
                        PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
-                       PRINT_D(GENERIC_DBG, "ID Hostint is %d\n", (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx));
-                       strWIDList[0].u16WIDid = (u16)WID_11I_MODE;
-                       strWIDList[0].enuWIDtype = WID_CHAR;
-                       strWIDList[0].s32ValueSize = sizeof(char);
-                       strWIDList[0].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8mode));
-
-                       strWIDList[1].u16WIDid     = WID_AUTH_TYPE;
-                       strWIDList[1].enuWIDtype  = WID_CHAR;
-                       strWIDList[1].s32ValueSize = sizeof(char);
-                       strWIDList[1].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.tenuAuth_type));
+                       PRINT_D(GENERIC_DBG, "ID Hostint is %d\n", pstrHostIFkeyAttr->attr.wep.index);
+                       strWIDList[0].id = (u16)WID_11I_MODE;
+                       strWIDList[0].type = WID_CHAR;
+                       strWIDList[0].size = sizeof(char);
+                       strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wep.mode;
 
-                       strWIDList[2].u16WIDid  = (u16)WID_KEY_ID;
-                       strWIDList[2].enuWIDtype        = WID_CHAR;
+                       strWIDList[1].id = WID_AUTH_TYPE;
+                       strWIDList[1].type = WID_CHAR;
+                       strWIDList[1].size = sizeof(char);
+                       strWIDList[1].val = (s8 *)&pstrHostIFkeyAttr->attr.wep.auth_type;
 
-                       strWIDList[2].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx));
-                       strWIDList[2].s32ValueSize = sizeof(char);
+                       strWIDList[2].id = (u16)WID_KEY_ID;
+                       strWIDList[2].type = WID_CHAR;
 
+                       strWIDList[2].val = (s8 *)&pstrHostIFkeyAttr->attr.wep.index;
+                       strWIDList[2].size = sizeof(char);
 
-                       pu8keybuf = WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
-
+                       pu8keybuf = kmemdup(pstrHostIFkeyAttr->attr.wep.key,
+                                           pstrHostIFkeyAttr->attr.wep.key_len,
+                                           GFP_KERNEL);
 
                        if (pu8keybuf == NULL) {
                                PRINT_ER("No buffer to send Key\n");
-                               return -1;
+                               return -ENOMEM;
                        }
 
-                       memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
-                                   pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
-
+                       kfree(pstrHostIFkeyAttr->attr.wep.key);
 
-                       kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey);
+                       strWIDList[3].id = (u16)WID_WEP_KEY_VALUE;
+                       strWIDList[3].type = WID_STR;
+                       strWIDList[3].size = pstrHostIFkeyAttr->attr.wep.key_len;
+                       strWIDList[3].val = (s8 *)pu8keybuf;
 
-                       strWIDList[3].u16WIDid = (u16)WID_WEP_KEY_VALUE;
-                       strWIDList[3].enuWIDtype = WID_STR;
-                       strWIDList[3].s32ValueSize = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen;
-                       strWIDList[3].ps8WidVal = (s8 *)pu8keybuf;
-
-
-                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 4, true, (u32)pstrWFIDrv);
+                       result = send_config_pkt(SET_CFG, strWIDList, 4,
+                                                get_id_from_handler(hif_drv));
                        kfree(pu8keybuf);
-
-
                }
-#endif
 
-               if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
+               if (pstrHostIFkeyAttr->action & ADDKEY) {
                        PRINT_D(HOSTINF_DBG, "Handling WEP key\n");
-                       pu8keybuf = WILC_MALLOC(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2);
-                       if (pu8keybuf == NULL) {
+                       pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len + 2, GFP_KERNEL);
+                       if (!pu8keybuf) {
                                PRINT_ER("No buffer to send Key\n");
-                               return -1;
+                               return -ENOMEM;
                        }
-                       pu8keybuf[0] = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx;
-
-                       memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen, 1);
-
-                       memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
-                                   pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
-
-                       kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey);
-
-                       strWID.u16WIDid = (u16)WID_ADD_WEP_KEY;
-                       strWID.enuWIDtype       = WID_STR;
-                       strWID.ps8WidVal        = (s8 *)pu8keybuf;
-                       strWID.s32ValueSize = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen + 2;
-
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       pu8keybuf[0] = pstrHostIFkeyAttr->attr.wep.index;
+                       memcpy(pu8keybuf + 1, &pstrHostIFkeyAttr->attr.wep.key_len, 1);
+                       memcpy(pu8keybuf + 2, pstrHostIFkeyAttr->attr.wep.key,
+                              pstrHostIFkeyAttr->attr.wep.key_len);
+                       kfree(pstrHostIFkeyAttr->attr.wep.key);
+
+                       wid.id = (u16)WID_ADD_WEP_KEY;
+                       wid.type = WID_STR;
+                       wid.val = (s8 *)pu8keybuf;
+                       wid.size = pstrHostIFkeyAttr->attr.wep.key_len + 2;
+
+                       result = send_config_pkt(SET_CFG, &wid, 1,
+                                                get_id_from_handler(hif_drv));
                        kfree(pu8keybuf);
-               } else if (pstrHostIFkeyAttr->u8KeyAction & REMOVEKEY)    {
-
+               } else if (pstrHostIFkeyAttr->action & REMOVEKEY) {
                        PRINT_D(HOSTINF_DBG, "Removing key\n");
-                       strWID.u16WIDid = (u16)WID_REMOVE_WEP_KEY;
-                       strWID.enuWIDtype       = WID_STR;
+                       wid.id = (u16)WID_REMOVE_WEP_KEY;
+                       wid.type = WID_STR;
 
-                       s8idxarray[0] = (s8)pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx;
-                       strWID.ps8WidVal = s8idxarray;
-                       strWID.s32ValueSize = 1;
+                       s8idxarray[0] = (s8)pstrHostIFkeyAttr->attr.wep.index;
+                       wid.val = s8idxarray;
+                       wid.size = 1;
 
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       result = send_config_pkt(SET_CFG, &wid, 1,
+                                                get_id_from_handler(hif_drv));
                } else {
-                       strWID.u16WIDid = (u16)WID_KEY_ID;
-                       strWID.enuWIDtype       = WID_CHAR;
-                       strWID.ps8WidVal        = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx));
-                       strWID.s32ValueSize = sizeof(char);
+                       wid.id = (u16)WID_KEY_ID;
+                       wid.type = WID_CHAR;
+                       wid.val = (s8 *)&pstrHostIFkeyAttr->attr.wep.index;
+                       wid.size = sizeof(char);
 
                        PRINT_D(HOSTINF_DBG, "Setting default key index\n");
 
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       result = send_config_pkt(SET_CFG, &wid, 1,
+                                                get_id_from_handler(hif_drv));
                }
-               up(&(pstrWFIDrv->hSemTestKeyBlock));
+               up(&hif_drv->hSemTestKeyBlock);
                break;
 
        case WPARxGtk:
-                       #ifdef WILC_AP_EXTERNAL_MLME
-               if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
-                       pu8keybuf = WILC_MALLOC(RX_MIC_KEY_MSG_LEN);
-                       if (pu8keybuf == NULL) {
+               if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
+                       pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
+                       if (!pu8keybuf) {
                                PRINT_ER("No buffer to send RxGTK Key\n");
-                               ret = -1;
+                               ret = -ENOMEM;
                                goto _WPARxGtk_end_case_;
                        }
 
-                       memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
-
-
-                       /*|----------------------------------------------------------------------------|
-                        * |Sta Address | Key RSC | KeyID | Key Length | Temporal Key   | Rx Michael Key |
-                        * |------------|---------|-------|------------|---------------|----------------|
-                        |      6 bytes  | 8 byte  |1 byte |  1 byte    |   16 bytes    |         8 bytes        |*/
-
-
+                       if (pstrHostIFkeyAttr->attr.wpa.seq)
+                               memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
 
-                       if (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq != NULL)
-                               memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8);
+                       memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
+                       memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
+                       memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
+                              pstrHostIFkeyAttr->attr.wpa.key_len);
 
+                       strWIDList[0].id = (u16)WID_11I_MODE;
+                       strWIDList[0].type = WID_CHAR;
+                       strWIDList[0].size = sizeof(char);
+                       strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wpa.mode;
 
-                       memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
+                       strWIDList[1].id = (u16)WID_ADD_RX_GTK;
+                       strWIDList[1].type = WID_STR;
+                       strWIDList[1].val = (s8 *)pu8keybuf;
+                       strWIDList[1].size = RX_MIC_KEY_MSG_LEN;
 
-                       memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
-
-                       memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
-                                   pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
-                       /* pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode =  0X51; */
-                       strWIDList[0].u16WIDid = (u16)WID_11I_MODE;
-                       strWIDList[0].enuWIDtype = WID_CHAR;
-                       strWIDList[0].s32ValueSize = sizeof(char);
-                       strWIDList[0].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode));
-
-                       strWIDList[1].u16WIDid  = (u16)WID_ADD_RX_GTK;
-                       strWIDList[1].enuWIDtype        = WID_STR;
-                       strWIDList[1].ps8WidVal = (s8 *)pu8keybuf;
-                       strWIDList[1].s32ValueSize = RX_MIC_KEY_MSG_LEN;
-
-                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
+                       result = send_config_pkt(SET_CFG, strWIDList, 2,
+                                                get_id_from_handler(hif_drv));
 
                        kfree(pu8keybuf);
-
-                       /* ////////////////////////// */
-                       up(&(pstrWFIDrv->hSemTestKeyBlock));
-                       /* ///////////////////////// */
+                       up(&hif_drv->hSemTestKeyBlock);
                }
 
-                       #endif
-               if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
+               if (pstrHostIFkeyAttr->action & ADDKEY) {
                        PRINT_D(HOSTINF_DBG, "Handling group key(Rx) function\n");
 
-                       pu8keybuf = WILC_MALLOC(RX_MIC_KEY_MSG_LEN);
+                       pu8keybuf = kzalloc(RX_MIC_KEY_MSG_LEN, GFP_KERNEL);
                        if (pu8keybuf == NULL) {
                                PRINT_ER("No buffer to send RxGTK Key\n");
-                               ret = -1;
+                               ret = -ENOMEM;
                                goto _WPARxGtk_end_case_;
                        }
 
-                       memset(pu8keybuf, 0, RX_MIC_KEY_MSG_LEN);
-
-
-                       /*|----------------------------------------------------------------------------|
-                        * |Sta Address | Key RSC | KeyID | Key Length | Temporal Key   | Rx Michael Key |
-                        * |------------|---------|-------|------------|---------------|----------------|
-                        |      6 bytes  | 8 byte  |1 byte |  1 byte    |   16 bytes    |         8 bytes        |*/
-
-                       if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED)
-                               memcpy(pu8keybuf, pstrWFIDrv->au8AssociatedBSSID, ETH_ALEN);
+                       if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED)
+                               memcpy(pu8keybuf, hif_drv->au8AssociatedBSSID, ETH_ALEN);
                        else
                                PRINT_ER("Couldn't handle WPARxGtk while enuHostIFstate is not HOST_IF_CONNECTED\n");
 
-                       memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq, 8);
-
-                       memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
+                       memcpy(pu8keybuf + 6, pstrHostIFkeyAttr->attr.wpa.seq, 8);
+                       memcpy(pu8keybuf + 14, &pstrHostIFkeyAttr->attr.wpa.index, 1);
+                       memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
+                       memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->attr.wpa.key,
+                              pstrHostIFkeyAttr->attr.wpa.key_len);
 
-                       memcpy(pu8keybuf + 15, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
-                       memcpy(pu8keybuf + 16, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
-                                   pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
+                       wid.id = (u16)WID_ADD_RX_GTK;
+                       wid.type = WID_STR;
+                       wid.val = (s8 *)pu8keybuf;
+                       wid.size = RX_MIC_KEY_MSG_LEN;
 
-                       strWID.u16WIDid = (u16)WID_ADD_RX_GTK;
-                       strWID.enuWIDtype       = WID_STR;
-                       strWID.ps8WidVal        = (s8 *)pu8keybuf;
-                       strWID.s32ValueSize = RX_MIC_KEY_MSG_LEN;
-
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       result = send_config_pkt(SET_CFG, &wid, 1,
+                                                get_id_from_handler(hif_drv));
 
                        kfree(pu8keybuf);
-
-                       /* ////////////////////////// */
-                       up(&(pstrWFIDrv->hSemTestKeyBlock));
-                       /* ///////////////////////// */
+                       up(&hif_drv->hSemTestKeyBlock);
                }
 _WPARxGtk_end_case_:
-               kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key);
-               kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq);
-               if (ret == -1)
+               kfree(pstrHostIFkeyAttr->attr.wpa.key);
+               kfree(pstrHostIFkeyAttr->attr.wpa.seq);
+               if (ret)
                        return ret;
 
                break;
 
        case WPAPtk:
-               #ifdef WILC_AP_EXTERNAL_MLME
-               if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY_AP) {
-
-
-                       pu8keybuf = WILC_MALLOC(PTK_KEY_MSG_LEN + 1);
-
-
-
-                       if (pu8keybuf == NULL) {
+               if (pstrHostIFkeyAttr->action & ADDKEY_AP) {
+                       pu8keybuf = kmalloc(PTK_KEY_MSG_LEN + 1, GFP_KERNEL);
+                       if (!pu8keybuf) {
                                PRINT_ER("No buffer to send PTK Key\n");
-                               ret = -1;
+                               ret = -ENOMEM;
                                goto _WPAPtk_end_case_;
-
                        }
 
-                       /*|-----------------------------------------------------------------------------|
-                        * |Station address |   keyidx     |Key Length    |Temporal Key  | Rx Michael Key |Tx Michael Key |
-                        * |----------------|------------  |--------------|----------------|---------------|
-                        |      6 bytes    |    1 byte    |   1byte      |   16 bytes    |        8 bytes         |        8 bytes        |
-                        |-----------------------------------------------------------------------------|*/
-
-                       memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6);  /*1 bytes Key Length */
-
-                       memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx, 1);
-                       memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
-                       /*16 byte TK*/
-                       memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
-                                   pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
-
+                       memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
+                       memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.index, 1);
+                       memcpy(pu8keybuf + 7, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
+                       memcpy(pu8keybuf + 8, pstrHostIFkeyAttr->attr.wpa.key,
+                              pstrHostIFkeyAttr->attr.wpa.key_len);
 
-                       strWIDList[0].u16WIDid = (u16)WID_11I_MODE;
-                       strWIDList[0].enuWIDtype = WID_CHAR;
-                       strWIDList[0].s32ValueSize = sizeof(char);
-                       strWIDList[0].ps8WidVal = (s8 *)(&(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode));
+                       strWIDList[0].id = (u16)WID_11I_MODE;
+                       strWIDList[0].type = WID_CHAR;
+                       strWIDList[0].size = sizeof(char);
+                       strWIDList[0].val = (s8 *)&pstrHostIFkeyAttr->attr.wpa.mode;
 
-                       strWIDList[1].u16WIDid  = (u16)WID_ADD_PTK;
-                       strWIDList[1].enuWIDtype        = WID_STR;
-                       strWIDList[1].ps8WidVal = (s8 *)pu8keybuf;
-                       strWIDList[1].s32ValueSize = PTK_KEY_MSG_LEN + 1;
+                       strWIDList[1].id = (u16)WID_ADD_PTK;
+                       strWIDList[1].type = WID_STR;
+                       strWIDList[1].val = (s8 *)pu8keybuf;
+                       strWIDList[1].size = PTK_KEY_MSG_LEN + 1;
 
-                       s32Error = SendConfigPkt(SET_CFG, strWIDList, 2, true, (u32)pstrWFIDrv);
+                       result = send_config_pkt(SET_CFG, strWIDList, 2,
+                                                get_id_from_handler(hif_drv));
                        kfree(pu8keybuf);
-
-                       /* ////////////////////////// */
-                       up(&(pstrWFIDrv->hSemTestKeyBlock));
-                       /* ///////////////////////// */
+                       up(&hif_drv->hSemTestKeyBlock);
                }
-               #endif
-               if (pstrHostIFkeyAttr->u8KeyAction & ADDKEY) {
-
-
-                       pu8keybuf = WILC_MALLOC(PTK_KEY_MSG_LEN);
-
-
-
-                       if (pu8keybuf == NULL) {
+               if (pstrHostIFkeyAttr->action & ADDKEY) {
+                       pu8keybuf = kmalloc(PTK_KEY_MSG_LEN, GFP_KERNEL);
+                       if (!pu8keybuf) {
                                PRINT_ER("No buffer to send PTK Key\n");
-                               ret = -1;
+                               ret = -ENOMEM;
                                goto _WPAPtk_end_case_;
-
                        }
 
-                       /*|-----------------------------------------------------------------------------|
-                        * |Station address | Key Length |      Temporal Key | Rx Michael Key |Tx Michael Key |
-                        * |----------------|------------|--------------|----------------|---------------|
-                        |      6 bytes          |      1byte     |   16 bytes   |        8 bytes         |        8 bytes        |
-                        |-----------------------------------------------------------------------------|*/
+                       memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wpa.mac_addr, 6);
+                       memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->attr.wpa.key_len, 1);
+                       memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->attr.wpa.key,
+                              pstrHostIFkeyAttr->attr.wpa.key_len);
 
-                       memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr, 6);  /*1 bytes Key Length */
+                       wid.id = (u16)WID_ADD_PTK;
+                       wid.type = WID_STR;
+                       wid.val = (s8 *)pu8keybuf;
+                       wid.size = PTK_KEY_MSG_LEN;
 
-                       memcpy(pu8keybuf + 6, &pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen, 1);
-                       /*16 byte TK*/
-                       memcpy(pu8keybuf + 7, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
-                                   pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen);
-
-
-                       strWID.u16WIDid = (u16)WID_ADD_PTK;
-                       strWID.enuWIDtype       = WID_STR;
-                       strWID.ps8WidVal        = (s8 *)pu8keybuf;
-                       strWID.s32ValueSize = PTK_KEY_MSG_LEN;
-
-                       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+                       result = send_config_pkt(SET_CFG, &wid, 1,
+                                                get_id_from_handler(hif_drv));
                        kfree(pu8keybuf);
-
-                       /* ////////////////////////// */
-                       up(&(pstrWFIDrv->hSemTestKeyBlock));
-                       /* ///////////////////////// */
+                       up(&hif_drv->hSemTestKeyBlock);
                }
 
 _WPAPtk_end_case_:
-               kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwpaAttr.pu8key);
-               if (ret == -1)
+               kfree(pstrHostIFkeyAttr->attr.wpa.key);
+               if (ret)
                        return ret;
 
                break;
 
-
        case PMKSA:
 
                PRINT_D(HOSTINF_DBG, "Handling PMKSA key\n");
 
-               pu8keybuf = WILC_MALLOC((pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid * PMKSA_KEY_LEN) + 1);
-               if (pu8keybuf == NULL) {
+               pu8keybuf = kmalloc((pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1, GFP_KERNEL);
+               if (!pu8keybuf) {
                        PRINT_ER("No buffer to send PMKSA Key\n");
-                       return -1;
+                       return -ENOMEM;
                }
 
-               pu8keybuf[0] = pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid;
-
-               for (i = 0; i < pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid; i++) {
+               pu8keybuf[0] = pstrHostIFkeyAttr->attr.pmkid.numpmkid;
 
-                       memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, ETH_ALEN);
-                       memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, PMKID_LEN);
+               for (i = 0; i < pstrHostIFkeyAttr->attr.pmkid.numpmkid; i++) {
+                       memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].bssid, ETH_ALEN);
+                       memcpy(pu8keybuf + ((PMKSA_KEY_LEN * i) + ETH_ALEN + 1), pstrHostIFkeyAttr->attr.pmkid.pmkidlist[i].pmkid, PMKID_LEN);
                }
 
-               strWID.u16WIDid = (u16)WID_PMKID_INFO;
-               strWID.enuWIDtype = WID_STR;
-               strWID.ps8WidVal = (s8 *)pu8keybuf;
-               strWID.s32ValueSize = (pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFpmkidAttr.numpmkid * PMKSA_KEY_LEN) + 1;
+               wid.id = (u16)WID_PMKID_INFO;
+               wid.type = WID_STR;
+               wid.val = (s8 *)pu8keybuf;
+               wid.size = (pstrHostIFkeyAttr->attr.pmkid.numpmkid * PMKSA_KEY_LEN) + 1;
 
-               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
+               result = send_config_pkt(SET_CFG, &wid, 1,
+                                        get_id_from_handler(hif_drv));
 
                kfree(pu8keybuf);
                break;
        }
 
-       if (s32Error)
+       if (result)
                PRINT_ER("Failed to send key config packet\n");
 
-
-       return s32Error;
+       return result;
 }
 
-
-/**
- *  @brief Handle_Disconnect
- *  @details       Sending config packet to firmware to disconnect
- *  @param[in]    NONE
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_Disconnect(tstrWILC_WFIDrv *drvHandler)
+static void Handle_Disconnect(struct host_if_drv *hif_drv)
 {
-       tstrWID strWID;
+       struct wid wid;
 
-       s32 s32Error = WILC_SUCCESS;
+       s32 result = 0;
        u16 u16DummyReasonCode = 0;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
-
-       strWID.u16WIDid = (u16)WID_DISCONNECT;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = (s8 *)&u16DummyReasonCode;
-       strWID.s32ValueSize = sizeof(char);
-
 
+       wid.id = (u16)WID_DISCONNECT;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)&u16DummyReasonCode;
+       wid.size = sizeof(char);
 
        PRINT_D(HOSTINF_DBG, "Sending disconnect request\n");
 
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
-
        g_obtainingIP = false;
-       host_int_set_power_mgmt(pstrWFIDrv, 0, 0);
-       #endif
+       host_int_set_power_mgmt(hif_drv, 0, 0);
 
-       memset(u8ConnectedSSID, 0, ETH_ALEN);
+       eth_zero_addr(u8ConnectedSSID);
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
-       if (s32Error) {
+       if (result) {
                PRINT_ER("Failed to send dissconect config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
        } else {
                tstrDisconnectNotifInfo strDisconnectNotifInfo;
 
@@ -3067,486 +1996,304 @@ static void Handle_Disconnect(tstrWILC_WFIDrv *drvHandler)
                strDisconnectNotifInfo.ie = NULL;
                strDisconnectNotifInfo.ie_len = 0;
 
-               if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
-                       del_timer(&pstrWFIDrv->hScanTimer);
-                       pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
-                                                                       pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
+               if (hif_drv->usr_scan_req.pfUserScanResult) {
+                       del_timer(&hif_drv->hScanTimer);
+                       hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
+                                                              hif_drv->usr_scan_req.u32UserScanPvoid, NULL);
 
-                       pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL;
+                       hif_drv->usr_scan_req.pfUserScanResult = NULL;
                }
 
-               if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult != NULL) {
-
-                       /*BugID_5193*/
-                       /*Stop connect timer, if connection in progress*/
-                       if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
+               if (hif_drv->usr_conn_req.pfUserConnectResult) {
+                       if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
                                PRINT_D(HOSTINF_DBG, "Upper layer requested termination of connection\n");
-                               del_timer(&pstrWFIDrv->hConnectTimer);
+                               del_timer(&hif_drv->hConnectTimer);
                        }
 
-                       pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
-                                                                          0, &strDisconnectNotifInfo, pstrWFIDrv->strWILC_UsrConnReq.u32UserConnectPvoid);
+                       hif_drv->usr_conn_req.pfUserConnectResult(CONN_DISCONN_EVENT_DISCONN_NOTIF, NULL,
+                                                                 0, &strDisconnectNotifInfo, hif_drv->usr_conn_req.u32UserConnectPvoid);
                } else {
-                       PRINT_ER("strWILC_UsrConnReq.pfUserConnectResult = NULL\n");
+                       PRINT_ER("usr_conn_req.pfUserConnectResult = NULL\n");
                }
 
-               gbScanWhileConnected = false;
-
-               pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
+               scan_while_connected = false;
 
-               memset(pstrWFIDrv->au8AssociatedBSSID, 0, ETH_ALEN);
+               hif_drv->enuHostIFstate = HOST_IF_IDLE;
 
+               eth_zero_addr(hif_drv->au8AssociatedBSSID);
 
-               /* Deallocation */
-               pstrWFIDrv->strWILC_UsrConnReq.ssidLen = 0;
-               if (pstrWFIDrv->strWILC_UsrConnReq.pu8ssid != NULL) {
-                       kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ssid);
-                       pstrWFIDrv->strWILC_UsrConnReq.pu8ssid = NULL;
-               }
-
-               if (pstrWFIDrv->strWILC_UsrConnReq.pu8bssid != NULL) {
-                       kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8bssid);
-                       pstrWFIDrv->strWILC_UsrConnReq.pu8bssid = NULL;
-               }
+               hif_drv->usr_conn_req.ssidLen = 0;
+               kfree(hif_drv->usr_conn_req.pu8ssid);
+               kfree(hif_drv->usr_conn_req.pu8bssid);
+               hif_drv->usr_conn_req.ConnReqIEsLen = 0;
+               kfree(hif_drv->usr_conn_req.pu8ConnReqIEs);
 
-               pstrWFIDrv->strWILC_UsrConnReq.ConnReqIEsLen = 0;
-               if (pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs != NULL) {
-                       kfree(pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs);
-                       pstrWFIDrv->strWILC_UsrConnReq.pu8ConnReqIEs = NULL;
+               if (join_req && join_req_drv == hif_drv) {
+                       kfree(join_req);
+                       join_req = NULL;
                }
 
-
-               /*BugID_5137*/
-               if (gu8FlushedJoinReq != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
-                       kfree(gu8FlushedJoinReq);
-                       gu8FlushedJoinReq = NULL;
+               if (info_element && join_req_drv == hif_drv) {
+                       kfree(info_element);
+                       info_element = NULL;
                }
-               if (gu8FlushedInfoElemAsoc != NULL && gu8FlushedJoinReqDrvHandler == (u32)drvHandler) {
-                       kfree(gu8FlushedInfoElemAsoc);
-                       gu8FlushedInfoElemAsoc = NULL;
-               }
-
        }
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
-       /* ////////////////////////// */
-       up(&(pstrWFIDrv->hSemTestDisconnectBlock));
-       /* ///////////////////////// */
-
+       up(&hif_drv->hSemTestDisconnectBlock);
 }
 
-
-void resolve_disconnect_aberration(tstrWILC_WFIDrv *drvHandler)
+void resolve_disconnect_aberration(struct host_if_drv *hif_drv)
 {
-       tstrWILC_WFIDrv *pstrWFIDrv;
-
-       pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-       if (pstrWFIDrv  == NULL)
+       if (!hif_drv)
                return;
-       if ((pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTING)) {
+       if ((hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) || (hif_drv->enuHostIFstate == HOST_IF_CONNECTING)) {
                PRINT_D(HOSTINF_DBG, "\n\n<< correcting Supplicant state machine >>\n\n");
-               host_int_disconnect(pstrWFIDrv, 1);
-       }
-}
-static s32 Switch_Log_Terminal(tstrWILC_WFIDrv *drvHandler)
-{
-
-
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       static char dummy = 9;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
-       strWID.u16WIDid = (u16)WID_LOGTerminal_Switch;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = &dummy;
-       strWID.s32ValueSize = sizeof(char);
-
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-
-
-       if (s32Error) {
-               PRINT_D(HOSTINF_DBG, "Failed to switch log terminal\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       } else {
-               PRINT_INFO(HOSTINF_DBG, "MAC address set ::\n");
-
-
-       }
-
-       WILC_CATCH(s32Error)
-       {
-
+               host_int_disconnect(hif_drv, 1);
        }
-
-       return s32Error;
 }
 
-/**
- *  @brief Handle_GetChnl
- *  @details       Sending config packet to get channel
- *  @param[in]    NONE
- *  @return         NONE
- *
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_GetChnl(tstrWILC_WFIDrv *drvHandler)
+static s32 Handle_GetChnl(struct host_if_drv *hif_drv)
 {
+       s32 result = 0;
+       struct wid wid;
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
-       strWID.u16WIDid = (u16)WID_CURRENT_CHANNEL;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = (s8 *)&gu8Chnl;
-       strWID.s32ValueSize = sizeof(char);
+       wid.id = (u16)WID_CURRENT_CHANNEL;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)&ch_no;
+       wid.size = sizeof(char);
 
        PRINT_D(HOSTINF_DBG, "Getting channel value\n");
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       /*get the value by searching the local copy*/
-       if (s32Error) {
-               PRINT_ER("Failed to get channel number\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
-
-
-       WILC_CATCH(s32Error)
-       {
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
+       if (result) {
+               PRINT_ER("Failed to get channel number\n");
+               result = -EFAULT;
        }
-       up(&(pstrWFIDrv->hSemGetCHNL));
-
-       return s32Error;
-
 
+       up(&hif_drv->hSemGetCHNL);
 
+       return result;
 }
 
-
-/**
- *  @brief Handle_GetRssi
- *  @details       Sending config packet to get RSSI
- *  @param[in]    NONE
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_GetRssi(tstrWILC_WFIDrv *drvHandler)
+static void Handle_GetRssi(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       s32 result = 0;
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_RSSI;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = &gs8Rssi;
-       strWID.s32ValueSize = sizeof(char);
+       wid.id = (u16)WID_RSSI;
+       wid.type = WID_CHAR;
+       wid.val = &rssi;
+       wid.size = sizeof(char);
 
-       /*Sending Cfg*/
        PRINT_D(HOSTINF_DBG, "Getting RSSI value\n");
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result) {
                PRINT_ER("Failed to get RSSI value\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
-
-       WILC_CATCH(s32Error)
-       {
-
+               result = -EFAULT;
        }
-       up(&(pstrWFIDrv->hSemGetRSSI));
-
 
+       up(&hif_drv->hSemGetRSSI);
 }
 
-
-static void Handle_GetLinkspeed(tstrWILC_WFIDrv *drvHandler)
+static void Handle_GetLinkspeed(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       s32 result = 0;
+       struct wid wid;
 
-       gs8lnkspd = 0;
+       link_speed = 0;
+
+       wid.id = (u16)WID_LINKSPEED;
+       wid.type = WID_CHAR;
+       wid.val = &link_speed;
+       wid.size = sizeof(char);
 
-       strWID.u16WIDid = (u16)WID_LINKSPEED;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = &gs8lnkspd;
-       strWID.s32ValueSize = sizeof(char);
-       /*Sending Cfg*/
        PRINT_D(HOSTINF_DBG, "Getting LINKSPEED value\n");
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result) {
                PRINT_ER("Failed to get LINKSPEED value\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
-
-       WILC_CATCH(s32Error)
-       {
-
+               result = -EFAULT;
        }
-       up(&(pstrWFIDrv->hSemGetLINKSPEED));
-
 
+       up(&hif_drv->hSemGetLINKSPEED);
 }
 
-s32 Handle_GetStatistics(tstrWILC_WFIDrv *drvHandler, tstrStatistics *pstrStatistics)
+s32 Handle_GetStatistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
 {
-       tstrWID strWIDList[5];
-       uint32_t u32WidsCount = 0, s32Error = 0;
+       struct wid strWIDList[5];
+       u32 u32WidsCount = 0, result = 0;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_LINKSPEED;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u8LinkSpeed));
+       strWIDList[u32WidsCount].id = WID_LINKSPEED;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u8LinkSpeed;
        u32WidsCount++;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_RSSI;
-       strWIDList[u32WidsCount].enuWIDtype = WID_CHAR;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(char);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->s8RSSI));
+       strWIDList[u32WidsCount].id = WID_RSSI;
+       strWIDList[u32WidsCount].type = WID_CHAR;
+       strWIDList[u32WidsCount].size = sizeof(char);
+       strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->s8RSSI;
        u32WidsCount++;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_SUCCESS_FRAME_COUNT;
-       strWIDList[u32WidsCount].enuWIDtype = WID_INT;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u32TxCount));
+       strWIDList[u32WidsCount].id = WID_SUCCESS_FRAME_COUNT;
+       strWIDList[u32WidsCount].type = WID_INT;
+       strWIDList[u32WidsCount].size = sizeof(u32);
+       strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u32TxCount;
        u32WidsCount++;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_RECEIVED_FRAGMENT_COUNT;
-       strWIDList[u32WidsCount].enuWIDtype = WID_INT;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u32RxCount));
+       strWIDList[u32WidsCount].id = WID_RECEIVED_FRAGMENT_COUNT;
+       strWIDList[u32WidsCount].type = WID_INT;
+       strWIDList[u32WidsCount].size = sizeof(u32);
+       strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u32RxCount;
        u32WidsCount++;
 
-       strWIDList[u32WidsCount].u16WIDid = WID_FAILED_COUNT;
-       strWIDList[u32WidsCount].enuWIDtype = WID_INT;
-       strWIDList[u32WidsCount].s32ValueSize = sizeof(u32);
-       strWIDList[u32WidsCount].ps8WidVal = (s8 *)(&(pstrStatistics->u32TxFailureCount));
+       strWIDList[u32WidsCount].id = WID_FAILED_COUNT;
+       strWIDList[u32WidsCount].type = WID_INT;
+       strWIDList[u32WidsCount].size = sizeof(u32);
+       strWIDList[u32WidsCount].val = (s8 *)&pstrStatistics->u32TxFailureCount;
        u32WidsCount++;
 
-       s32Error = SendConfigPkt(GET_CFG, strWIDList, u32WidsCount, false, (u32)drvHandler);
+       result = send_config_pkt(GET_CFG, strWIDList, u32WidsCount,
+                                get_id_from_handler(hif_drv));
 
-       if (s32Error) {
+       if (result)
                PRINT_ER("Failed to send scan paramters config packet\n");
-               /* WILC_ERRORREPORT(s32Error, s32Error); */
-       }
-       up(&hWaitResponse);
-       return 0;
 
+       up(&hif_sema_wait_response);
+       return 0;
 }
 
-
-#ifdef WILC_AP_EXTERNAL_MLME
-
-
-/**
- *  @brief Handle_Get_InActiveTime
- *  @details       Sending config packet to set mac adddress for station and
- *                 get inactive time
- *  @param[in]    NONE
- *  @return         NONE
- *
- *  @author
- *  @date
- *  @version   1.0
- */
-static s32 Handle_Get_InActiveTime(tstrWILC_WFIDrv *drvHandler, tstrHostIfStaInactiveT *strHostIfStaInactiveT)
+static s32 Handle_Get_InActiveTime(struct host_if_drv *hif_drv,
+                                  struct sta_inactive_t *strHostIfStaInactiveT)
 {
-
-       s32 s32Error = WILC_SUCCESS;
+       s32 result = 0;
        u8 *stamac;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
-       strWID.enuWIDtype = WID_STR;
-       strWID.s32ValueSize = ETH_ALEN;
-       strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
+       wid.id = (u16)WID_SET_STA_MAC_INACTIVE_TIME;
+       wid.type = WID_STR;
+       wid.size = ETH_ALEN;
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
 
-
-       stamac = strWID.ps8WidVal;
+       stamac = wid.val;
        memcpy(stamac, strHostIfStaInactiveT->mac, ETH_ALEN);
 
-
        PRINT_D(CFG80211_DBG, "SETING STA inactive time\n");
 
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       /*get the value by searching the local copy*/
-       if (s32Error) {
+       if (result) {
                PRINT_ER("Failed to SET incative time\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+               return -EFAULT;
        }
 
+       wid.id = (u16)WID_GET_INACTIVE_TIME;
+       wid.type = WID_INT;
+       wid.val = (s8 *)&inactive_time;
+       wid.size = sizeof(u32);
 
-       strWID.u16WIDid = (u16)WID_GET_INACTIVE_TIME;
-       strWID.enuWIDtype = WID_INT;
-       strWID.ps8WidVal = (s8 *)&gu32InactiveTime;
-       strWID.s32ValueSize = sizeof(u32);
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
-
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       /*get the value by searching the local copy*/
-       if (s32Error) {
+       if (result) {
                PRINT_ER("Failed to get incative time\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
-
-
-       PRINT_D(CFG80211_DBG, "Getting inactive time : %d\n", gu32InactiveTime);
-
-       up(&(pstrWFIDrv->hSemInactiveTime));
-       WILC_CATCH(s32Error)
-       {
-
+               return -EFAULT;
        }
 
+       PRINT_D(CFG80211_DBG, "Getting inactive time : %d\n", inactive_time);
 
-       return s32Error;
-
-
+       up(&hif_drv->hSemInactiveTime);
 
+       return result;
 }
 
-
-/**
- *  @brief Handle_AddBeacon
- *  @details       Sending config packet to add beacon
- *  @param[in]    tstrHostIFSetBeacon* pstrSetBeaconParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_AddBeacon(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetBeacon *pstrSetBeaconParam)
+static void Handle_AddBeacon(struct host_if_drv *hif_drv,
+                            struct beacon_attr *pstrSetBeaconParam)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
        PRINT_D(HOSTINF_DBG, "Adding BEACON\n");
 
-       strWID.u16WIDid = (u16)WID_ADD_BEACON;
-       strWID.enuWIDtype = WID_BIN;
-       strWID.s32ValueSize = pstrSetBeaconParam->u32HeadLen + pstrSetBeaconParam->u32TailLen + 16;
-       strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
-
-       pu8CurrByte = strWID.ps8WidVal;
-       *pu8CurrByte++ = (pstrSetBeaconParam->u32Interval & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 8) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 16) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32Interval >> 24) & 0xFF);
-
-       *pu8CurrByte++ = (pstrSetBeaconParam->u32DTIMPeriod & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 8) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 16) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32DTIMPeriod >> 24) & 0xFF);
-
-       *pu8CurrByte++ = (pstrSetBeaconParam->u32HeadLen & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 8) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 16) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32HeadLen >> 24) & 0xFF);
-
-       memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Head, pstrSetBeaconParam->u32HeadLen);
-       pu8CurrByte += pstrSetBeaconParam->u32HeadLen;
-
-       *pu8CurrByte++ = (pstrSetBeaconParam->u32TailLen & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 8) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 16) & 0xFF);
-       *pu8CurrByte++ = ((pstrSetBeaconParam->u32TailLen >> 24) & 0xFF);
-
-       /* Bug 4599 : if tail length = 0 skip copying */
-       if (pstrSetBeaconParam->pu8Tail > 0)
-               memcpy(pu8CurrByte, pstrSetBeaconParam->pu8Tail, pstrSetBeaconParam->u32TailLen);
-       pu8CurrByte += pstrSetBeaconParam->u32TailLen;
-
-
-
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
-       if (s32Error) {
+       wid.id = (u16)WID_ADD_BEACON;
+       wid.type = WID_BIN;
+       wid.size = pstrSetBeaconParam->head_len + pstrSetBeaconParam->tail_len + 16;
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               goto ERRORHANDLER;
+
+       pu8CurrByte = wid.val;
+       *pu8CurrByte++ = (pstrSetBeaconParam->interval & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 8) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 16) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->interval >> 24) & 0xFF);
+
+       *pu8CurrByte++ = (pstrSetBeaconParam->dtim_period & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 8) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 16) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->dtim_period >> 24) & 0xFF);
+
+       *pu8CurrByte++ = (pstrSetBeaconParam->head_len & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 8) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 16) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->head_len >> 24) & 0xFF);
+
+       memcpy(pu8CurrByte, pstrSetBeaconParam->head, pstrSetBeaconParam->head_len);
+       pu8CurrByte += pstrSetBeaconParam->head_len;
+
+       *pu8CurrByte++ = (pstrSetBeaconParam->tail_len & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 8) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 16) & 0xFF);
+       *pu8CurrByte++ = ((pstrSetBeaconParam->tail_len >> 24) & 0xFF);
+
+       if (pstrSetBeaconParam->tail > 0)
+               memcpy(pu8CurrByte, pstrSetBeaconParam->tail, pstrSetBeaconParam->tail_len);
+       pu8CurrByte += pstrSetBeaconParam->tail_len;
+
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send add beacon config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
 
-       WILC_CATCH(s32Error)
-       {
-       }
-       kfree(strWID.ps8WidVal);
-       kfree(pstrSetBeaconParam->pu8Head);
-       kfree(pstrSetBeaconParam->pu8Tail);
+ERRORHANDLER:
+       kfree(wid.val);
+       kfree(pstrSetBeaconParam->head);
+       kfree(pstrSetBeaconParam->tail);
 }
 
-
-/**
- *  @brief Handle_AddBeacon
- *  @details       Sending config packet to delete beacon
- *  @param[in]   tstrHostIFDelBeacon* pstrDelBeacon
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_DelBeacon(tstrWILC_WFIDrv *drvHandler, tstrHostIFDelBeacon *pstrDelBeacon)
+static void Handle_DelBeacon(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
-       strWID.u16WIDid = (u16)WID_DEL_BEACON;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.s32ValueSize = sizeof(char);
-       strWID.ps8WidVal = &gu8DelBcn;
+       wid.id = (u16)WID_DEL_BEACON;
+       wid.type = WID_CHAR;
+       wid.size = sizeof(char);
+       wid.val = &del_beacon;
 
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       if (!wid.val)
+               return;
 
-       pu8CurrByte = strWID.ps8WidVal;
+       pu8CurrByte = wid.val;
 
        PRINT_D(HOSTINF_DBG, "Deleting BEACON\n");
-       /* TODO: build del beacon message*/
-
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
-       if (s32Error) {
 
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send delete beacon config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
-
-       WILC_CATCH(s32Error)
-       {
-       }
 }
 
-
-/**
- *  @brief WILC_HostIf_PackStaParam
- *  @details       Handling packing of the station params in a buffer
- *  @param[in]   u8* pu8Buffer, tstrWILC_AddStaParam* pstrStationParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer, tstrWILC_AddStaParam *pstrStationParam)
+static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer,
+                                   struct add_sta_param *pstrStationParam)
 {
        u8 *pu8CurrByte;
 
@@ -3591,534 +2338,376 @@ static u32 WILC_HostIf_PackStaParam(u8 *pu8Buffer, tstrWILC_AddStaParam *pstrSta
        return pu8CurrByte - pu8Buffer;
 }
 
-/**
- *  @brief Handle_AddStation
- *  @details       Sending config packet to add station
- *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_AddStation(tstrWILC_WFIDrv *drvHandler, tstrWILC_AddStaParam *pstrStationParam)
+static void Handle_AddStation(struct host_if_drv *hif_drv,
+                             struct add_sta_param *pstrStationParam)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
        PRINT_D(HOSTINF_DBG, "Handling add station\n");
-       strWID.u16WIDid = (u16)WID_ADD_STA;
-       strWID.enuWIDtype = WID_BIN;
-       strWID.s32ValueSize = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
+       wid.id = (u16)WID_ADD_STA;
+       wid.type = WID_BIN;
+       wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
 
-       strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               goto ERRORHANDLER;
 
-       pu8CurrByte = strWID.ps8WidVal;
+       pu8CurrByte = wid.val;
        pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
 
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
-       if (s32Error != WILC_SUCCESS) {
-
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result != 0)
                PRINT_ER("Failed to send add station config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
 
-       WILC_CATCH(s32Error)
-       {
-       }
+ERRORHANDLER:
        kfree(pstrStationParam->pu8Rates);
-       kfree(strWID.ps8WidVal);
+       kfree(wid.val);
 }
 
-/**
- *  @brief Handle_DelAllSta
- *  @details        Sending config packet to delete station
- *  @param[in]   tstrHostIFDelSta* pstrDelStaParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_DelAllSta(tstrWILC_WFIDrv *drvHandler, tstrHostIFDelAllSta *pstrDelAllStaParam)
+static void Handle_DelAllSta(struct host_if_drv *hif_drv,
+                            struct del_all_sta *pstrDelAllStaParam)
 {
-       s32 s32Error = WILC_SUCCESS;
-
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
        u8 i;
        u8 au8Zero_Buff[6] = {0};
 
-       strWID.u16WIDid = (u16)WID_DEL_ALL_STA;
-       strWID.enuWIDtype = WID_STR;
-       strWID.s32ValueSize = (pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1;
+       wid.id = (u16)WID_DEL_ALL_STA;
+       wid.type = WID_STR;
+       wid.size = (pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1;
 
        PRINT_D(HOSTINF_DBG, "Handling delete station\n");
 
-       strWID.ps8WidVal = WILC_MALLOC((pstrDelAllStaParam->u8Num_AssocSta * ETH_ALEN) + 1);
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       wid.val = kmalloc((pstrDelAllStaParam->assoc_sta * ETH_ALEN) + 1, GFP_KERNEL);
+       if (!wid.val)
+               goto ERRORHANDLER;
 
-       pu8CurrByte = strWID.ps8WidVal;
+       pu8CurrByte = wid.val;
 
-       *(pu8CurrByte++) = pstrDelAllStaParam->u8Num_AssocSta;
+       *(pu8CurrByte++) = pstrDelAllStaParam->assoc_sta;
 
        for (i = 0; i < MAX_NUM_STA; i++) {
-               if (memcmp(pstrDelAllStaParam->au8Sta_DelAllSta[i], au8Zero_Buff, ETH_ALEN))
-                       memcpy(pu8CurrByte, pstrDelAllStaParam->au8Sta_DelAllSta[i], ETH_ALEN);
+               if (memcmp(pstrDelAllStaParam->del_all_sta[i], au8Zero_Buff, ETH_ALEN))
+                       memcpy(pu8CurrByte, pstrDelAllStaParam->del_all_sta[i], ETH_ALEN);
                else
                        continue;
 
                pu8CurrByte += ETH_ALEN;
        }
 
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
-
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send add station config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
 
-       WILC_CATCH(s32Error)
-       {
-       }
-       kfree(strWID.ps8WidVal);
+ERRORHANDLER:
+       kfree(wid.val);
 
-       up(&hWaitResponse);
+       up(&hif_sema_wait_response);
 }
 
-
-/**
- *  @brief Handle_DelStation
- *  @details        Sending config packet to delete station
- *  @param[in]   tstrHostIFDelSta* pstrDelStaParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_DelStation(tstrWILC_WFIDrv *drvHandler, tstrHostIFDelSta *pstrDelStaParam)
+static void Handle_DelStation(struct host_if_drv *hif_drv,
+                             struct del_sta *pstrDelStaParam)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
-       strWID.u16WIDid = (u16)WID_REMOVE_STA;
-       strWID.enuWIDtype = WID_BIN;
-       strWID.s32ValueSize = ETH_ALEN;
+       wid.id = (u16)WID_REMOVE_STA;
+       wid.type = WID_BIN;
+       wid.size = ETH_ALEN;
 
        PRINT_D(HOSTINF_DBG, "Handling delete station\n");
 
-       strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               goto ERRORHANDLER;
 
-       pu8CurrByte = strWID.ps8WidVal;
+       pu8CurrByte = wid.val;
 
-       memcpy(pu8CurrByte, pstrDelStaParam->au8MacAddr, ETH_ALEN);
-
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
-       if (s32Error) {
+       memcpy(pu8CurrByte, pstrDelStaParam->mac_addr, ETH_ALEN);
 
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send add station config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
 
-       WILC_CATCH(s32Error)
-       {
-       }
-       kfree(strWID.ps8WidVal);
+ERRORHANDLER:
+       kfree(wid.val);
 }
 
-
-/**
- *  @brief Handle_EditStation
- *  @details        Sending config packet to edit station
- *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_EditStation(tstrWILC_WFIDrv *drvHandler, tstrWILC_AddStaParam *pstrStationParam)
+static void Handle_EditStation(struct host_if_drv *hif_drv,
+                              struct add_sta_param *pstrStationParam)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
-       strWID.u16WIDid = (u16)WID_EDIT_STA;
-       strWID.enuWIDtype = WID_BIN;
-       strWID.s32ValueSize = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
+       wid.id = (u16)WID_EDIT_STA;
+       wid.type = WID_BIN;
+       wid.size = WILC_ADD_STA_LENGTH + pstrStationParam->u8NumRates;
 
        PRINT_D(HOSTINF_DBG, "Handling edit station\n");
-       strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               goto ERRORHANDLER;
 
-       pu8CurrByte = strWID.ps8WidVal;
+       pu8CurrByte = wid.val;
        pu8CurrByte += WILC_HostIf_PackStaParam(pu8CurrByte, pstrStationParam);
 
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)pstrWFIDrv);
-       if (s32Error) {
-
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send edit station config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
 
-       WILC_CATCH(s32Error)
-       {
-       }
+ERRORHANDLER:
        kfree(pstrStationParam->pu8Rates);
-       kfree(strWID.ps8WidVal);
+       kfree(wid.val);
 }
-#endif /*WILC_AP_EXTERNAL_MLME*/
-
-#ifdef WILC_P2P
-/**
- *  @brief Handle_RemainOnChan
- *  @details        Sending config packet to edit station
- *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static int Handle_RemainOnChan(tstrWILC_WFIDrv *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan)
+
+static int Handle_RemainOnChan(struct host_if_drv *hif_drv,
+                              struct remain_ch *pstrHostIfRemainOnChan)
 {
-       s32 s32Error = WILC_SUCCESS;
+       s32 result = 0;
        u8 u8remain_on_chan_flag;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
-
-       /*If it's a pendig remain-on-channel, don't overwrite gWFiDrvHandle values (since incoming msg is garbbage)*/
-       if (!pstrWFIDrv->u8RemainOnChan_pendingreq) {
-               pstrWFIDrv->strHostIfRemainOnChan.pVoid = pstrHostIfRemainOnChan->pVoid;
-               pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanExpired = pstrHostIfRemainOnChan->pRemainOnChanExpired;
-               pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady = pstrHostIfRemainOnChan->pRemainOnChanReady;
-               pstrWFIDrv->strHostIfRemainOnChan.u16Channel = pstrHostIfRemainOnChan->u16Channel;
-               pstrWFIDrv->strHostIfRemainOnChan.u32ListenSessionID = pstrHostIfRemainOnChan->u32ListenSessionID;
+       struct wid wid;
+
+       if (!hif_drv->remain_on_ch_pending) {
+               hif_drv->remain_on_ch.pVoid = pstrHostIfRemainOnChan->pVoid;
+               hif_drv->remain_on_ch.pRemainOnChanExpired = pstrHostIfRemainOnChan->pRemainOnChanExpired;
+               hif_drv->remain_on_ch.pRemainOnChanReady = pstrHostIfRemainOnChan->pRemainOnChanReady;
+               hif_drv->remain_on_ch.u16Channel = pstrHostIfRemainOnChan->u16Channel;
+               hif_drv->remain_on_ch.u32ListenSessionID = pstrHostIfRemainOnChan->u32ListenSessionID;
        } else {
-               /*Set the channel to use it as a wid val*/
-               pstrHostIfRemainOnChan->u16Channel = pstrWFIDrv->strHostIfRemainOnChan.u16Channel;
+               pstrHostIfRemainOnChan->u16Channel = hif_drv->remain_on_ch.u16Channel;
        }
 
-       if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
+       if (hif_drv->usr_scan_req.pfUserScanResult) {
                PRINT_INFO(GENERIC_DBG, "Required to remain on chan while scanning return\n");
-               pstrWFIDrv->u8RemainOnChan_pendingreq = 1;
-               WILC_ERRORREPORT(s32Error, WILC_BUSY);
+               hif_drv->remain_on_ch_pending = 1;
+               result = -EBUSY;
+               goto ERRORHANDLER;
        }
-       if (pstrWFIDrv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
+       if (hif_drv->enuHostIFstate == HOST_IF_WAITING_CONN_RESP) {
                PRINT_INFO(GENERIC_DBG, "Required to remain on chan while connecting return\n");
-               WILC_ERRORREPORT(s32Error, WILC_BUSY);
+               result = -EBUSY;
+               goto ERRORHANDLER;
        }
 
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
        if (g_obtainingIP || connecting) {
                PRINT_D(GENERIC_DBG, "[handle_scan]: Don't do obss scan until IP adresss is obtained\n");
-               WILC_ERRORREPORT(s32Error, WILC_BUSY);
+               result = -EBUSY;
+               goto ERRORHANDLER;
        }
-       #endif
 
        PRINT_D(HOSTINF_DBG, "Setting channel :%d\n", pstrHostIfRemainOnChan->u16Channel);
 
        u8remain_on_chan_flag = true;
-       strWID.u16WIDid = (u16)WID_REMAIN_ON_CHAN;
-       strWID.enuWIDtype       = WID_STR;
-       strWID.s32ValueSize = 2;
-       strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
-
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       wid.id = (u16)WID_REMAIN_ON_CHAN;
+       wid.type = WID_STR;
+       wid.size = 2;
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val) {
+               result = -ENOMEM;
+               goto ERRORHANDLER;
+       }
 
-       strWID.ps8WidVal[0] = u8remain_on_chan_flag;
-       strWID.ps8WidVal[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
+       wid.val[0] = u8remain_on_chan_flag;
+       wid.val[1] = (s8)pstrHostIfRemainOnChan->u16Channel;
 
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error != WILC_SUCCESS)
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result != 0)
                PRINT_ER("Failed to set remain on channel\n");
 
-       WILC_CATCH(-1)
+ERRORHANDLER:
        {
                P2P_LISTEN_STATE = 1;
-               pstrWFIDrv->hRemainOnChannel.data = (unsigned long)pstrWFIDrv;
-               mod_timer(&pstrWFIDrv->hRemainOnChannel,
+               hif_drv->hRemainOnChannel.data = (unsigned long)hif_drv;
+               mod_timer(&hif_drv->hRemainOnChannel,
                          jiffies +
                          msecs_to_jiffies(pstrHostIfRemainOnChan->u32duration));
 
-               /*Calling CFG ready_on_channel*/
-               if (pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady)
-                       pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanReady(pstrWFIDrv->strHostIfRemainOnChan.pVoid);
+               if (hif_drv->remain_on_ch.pRemainOnChanReady)
+                       hif_drv->remain_on_ch.pRemainOnChanReady(hif_drv->remain_on_ch.pVoid);
 
-               if (pstrWFIDrv->u8RemainOnChan_pendingreq)
-                       pstrWFIDrv->u8RemainOnChan_pendingreq = 0;
+               if (hif_drv->remain_on_ch_pending)
+                       hif_drv->remain_on_ch_pending = 0;
        }
-       return s32Error;
+
+       return result;
 }
 
-/**
- *  @brief Handle_RegisterFrame
- *  @details
- *  @param[in]
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static int Handle_RegisterFrame(tstrWILC_WFIDrv *drvHandler, tstrHostIfRegisterFrame *pstrHostIfRegisterFrame)
+static int Handle_RegisterFrame(struct host_if_drv *hif_drv,
+                               struct reg_frame *pstrHostIfRegisterFrame)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
        PRINT_D(HOSTINF_DBG, "Handling frame register Flag : %d FrameType: %d\n", pstrHostIfRegisterFrame->bReg, pstrHostIfRegisterFrame->u16FrameType);
 
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_REGISTER_FRAME;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = WILC_MALLOC(sizeof(u16) + 2);
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
+       wid.id = (u16)WID_REGISTER_FRAME;
+       wid.type = WID_STR;
+       wid.val = kmalloc(sizeof(u16) + 2, GFP_KERNEL);
+       if (!wid.val)
+               return -ENOMEM;
 
-       pu8CurrByte = strWID.ps8WidVal;
+       pu8CurrByte = wid.val;
 
        *pu8CurrByte++ = pstrHostIfRegisterFrame->bReg;
        *pu8CurrByte++ = pstrHostIfRegisterFrame->u8Regid;
-       memcpy(pu8CurrByte, &(pstrHostIfRegisterFrame->u16FrameType), sizeof(u16));
-
+       memcpy(pu8CurrByte, &pstrHostIfRegisterFrame->u16FrameType,
+              sizeof(u16));
 
-       strWID.s32ValueSize = sizeof(u16) + 2;
+       wid.size = sizeof(u16) + 2;
 
-
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result) {
                PRINT_ER("Failed to frame register config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       }
-
-
-       WILC_CATCH(s32Error)
-       {
+               result = -EINVAL;
        }
 
-       return s32Error;
-
+       return result;
 }
 
-/**
- *  @brief                      Handle_ListenStateExpired
- *  @details            Handle of listen state expiration
- *  @param[in]          NONE
- *  @return             Error code.
- *  @author
- *  @date
- *  @version           1.0
- */
-#define FALSE_FRMWR_CHANNEL 100
-static u32 Handle_ListenStateExpired(tstrWILC_WFIDrv *drvHandler, tstrHostIfRemainOnChan *pstrHostIfRemainOnChan)
+static u32 Handle_ListenStateExpired(struct host_if_drv *hif_drv,
+                                    struct remain_ch *pstrHostIfRemainOnChan)
 {
        u8 u8remain_on_chan_flag;
-       tstrWID strWID;
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *) drvHandler;
+       struct wid wid;
+       s32 result = 0;
 
        PRINT_D(HOSTINF_DBG, "CANCEL REMAIN ON CHAN\n");
 
-       /*BugID_5477*/
-       /*Make sure we are already in listen state*/
-       /*This is to handle duplicate expiry messages (listen timer fired and supplicant called cancel_remain_on_channel())*/
        if (P2P_LISTEN_STATE) {
                u8remain_on_chan_flag = false;
-               strWID.u16WIDid = (u16)WID_REMAIN_ON_CHAN;
-               strWID.enuWIDtype       = WID_STR;
-               strWID.s32ValueSize = 2;
-               strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
+               wid.id = (u16)WID_REMAIN_ON_CHAN;
+               wid.type = WID_STR;
+               wid.size = 2;
+               wid.val = kmalloc(wid.size, GFP_KERNEL);
 
-               if (strWID.ps8WidVal == NULL)
+               if (!wid.val)
                        PRINT_ER("Failed to allocate memory\n");
 
-               strWID.ps8WidVal[0] = u8remain_on_chan_flag;
-               strWID.ps8WidVal[1] = FALSE_FRMWR_CHANNEL;
+               wid.val[0] = u8remain_on_chan_flag;
+               wid.val[1] = FALSE_FRMWR_CHANNEL;
 
-               /*Sending Cfg*/
-               s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-               if (s32Error != WILC_SUCCESS) {
+               result = send_config_pkt(SET_CFG, &wid, 1,
+                                        get_id_from_handler(hif_drv));
+               if (result != 0) {
                        PRINT_ER("Failed to set remain on channel\n");
                        goto _done_;
                }
 
-               if (pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanExpired) {
-                       pstrWFIDrv->strHostIfRemainOnChan.pRemainOnChanExpired(pstrWFIDrv->strHostIfRemainOnChan.pVoid
-                                                                              , pstrHostIfRemainOnChan->u32ListenSessionID);
+               if (hif_drv->remain_on_ch.pRemainOnChanExpired) {
+                       hif_drv->remain_on_ch.pRemainOnChanExpired(hif_drv->remain_on_ch.pVoid,
+                                                                  pstrHostIfRemainOnChan->u32ListenSessionID);
                }
                P2P_LISTEN_STATE = 0;
        } else {
                PRINT_D(GENERIC_DBG, "Not in listen state\n");
-               s32Error = WILC_FAIL;
+               result = -EFAULT;
        }
 
 _done_:
-       return s32Error;
+       return result;
 }
 
-
-/**
- *  @brief                      ListenTimerCB
- *  @details            Callback function of remain-on-channel timer
- *  @param[in]          NONE
- *  @return             Error code.
- *  @author
- *  @date
- *  @version           1.0
- */
 static void ListenTimerCB(unsigned long arg)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)arg;
-       /*Stopping remain-on-channel timer*/
-       del_timer(&pstrWFIDrv->hRemainOnChannel);
-
-       /* prepare the Timer Callback message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED;
-       strHostIFmsg.drvHandler = pstrWFIDrv;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = pstrWFIDrv->strHostIfRemainOnChan.u32ListenSessionID;
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
 
-       }
+       del_timer(&hif_drv->hRemainOnChannel);
+
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
+       msg.drv = hif_drv;
+       msg.body.remain_on_ch.u32ListenSessionID = hif_drv->remain_on_ch.u32ListenSessionID;
+
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
 }
-#endif
-
-
-/**
- *  @brief Handle_EditStation
- *  @details        Sending config packet to edit station
- *  @param[in]   tstrWILC_AddStaParam* pstrStationParam
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
-static void Handle_PowerManagement(tstrWILC_WFIDrv *drvHandler, tstrHostIfPowerMgmtParam *strPowerMgmtParam)
+
+static void Handle_PowerManagement(struct host_if_drv *hif_drv,
+                                  struct power_mgmt_param *strPowerMgmtParam)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        s8 s8PowerMode;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
-       strWID.u16WIDid = (u16)WID_POWER_MANAGEMENT;
+       wid.id = (u16)WID_POWER_MANAGEMENT;
 
-       if (strPowerMgmtParam->bIsEnabled == true)
+       if (strPowerMgmtParam->enabled)
                s8PowerMode = MIN_FAST_PS;
        else
                s8PowerMode = NO_POWERSAVE;
        PRINT_D(HOSTINF_DBG, "Handling power mgmt to %d\n", s8PowerMode);
-       strWID.ps8WidVal = &s8PowerMode;
-       strWID.s32ValueSize = sizeof(char);
+       wid.val = &s8PowerMode;
+       wid.size = sizeof(char);
 
        PRINT_D(HOSTINF_DBG, "Handling Power Management\n");
 
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send power management config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       }
-
-       WILC_CATCH(s32Error)
-       {
-
-       }
 }
 
-/**
- *  @brief Handle_SetMulticastFilter
- *  @details        Set Multicast filter in firmware
- *  @param[in]   tstrHostIFSetMulti* strHostIfSetMulti
- *  @return         NONE
- *  @author            asobhy
- *  @date
- *  @version   1.0
- */
-static void Handle_SetMulticastFilter(tstrWILC_WFIDrv *drvHandler, tstrHostIFSetMulti *strHostIfSetMulti)
+static void Handle_SetMulticastFilter(struct host_if_drv *hif_drv,
+                                     struct set_multicast *strHostIfSetMulti)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        u8 *pu8CurrByte;
 
        PRINT_D(HOSTINF_DBG, "Setup Multicast Filter\n");
 
-       strWID.u16WIDid = (u16)WID_SETUP_MULTICAST_FILTER;
-       strWID.enuWIDtype = WID_BIN;
-       strWID.s32ValueSize = sizeof(tstrHostIFSetMulti) + ((strHostIfSetMulti->u32count) * ETH_ALEN);
-       strWID.ps8WidVal = WILC_MALLOC(strWID.s32ValueSize);
-       if (strWID.ps8WidVal == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
-
-       pu8CurrByte = strWID.ps8WidVal;
-       *pu8CurrByte++ = (strHostIfSetMulti->bIsEnabled & 0xFF);
-       *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 8) & 0xFF);
-       *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 16) & 0xFF);
-       *pu8CurrByte++ = ((strHostIfSetMulti->bIsEnabled >> 24) & 0xFF);
-
-       *pu8CurrByte++ = (strHostIfSetMulti->u32count & 0xFF);
-       *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 8) & 0xFF);
-       *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 16) & 0xFF);
-       *pu8CurrByte++ = ((strHostIfSetMulti->u32count >> 24) & 0xFF);
-
-       if ((strHostIfSetMulti->u32count) > 0)
-               memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->u32count) * ETH_ALEN));
-
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, false, (u32)drvHandler);
-       if (s32Error) {
+       wid.id = (u16)WID_SETUP_MULTICAST_FILTER;
+       wid.type = WID_BIN;
+       wid.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->cnt) * ETH_ALEN);
+       wid.val = kmalloc(wid.size, GFP_KERNEL);
+       if (!wid.val)
+               goto ERRORHANDLER;
+
+       pu8CurrByte = wid.val;
+       *pu8CurrByte++ = (strHostIfSetMulti->enabled & 0xFF);
+       *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 8) & 0xFF);
+       *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 16) & 0xFF);
+       *pu8CurrByte++ = ((strHostIfSetMulti->enabled >> 24) & 0xFF);
+
+       *pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
+       *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
+       *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 16) & 0xFF);
+       *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 24) & 0xFF);
+
+       if ((strHostIfSetMulti->cnt) > 0)
+               memcpy(pu8CurrByte, gau8MulticastMacAddrList, ((strHostIfSetMulti->cnt) * ETH_ALEN));
+
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_ER("Failed to send setup multicast config packet\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
-
-       WILC_CATCH(s32Error)
-       {
-       }
-       kfree(strWID.ps8WidVal);
 
+ERRORHANDLER:
+       kfree(wid.val);
 }
 
-
-/*BugID_5222*/
-/**
- *  @brief                      Handle_AddBASession
- *  @details            Add block ack session
- *  @param[in]          tstrHostIFSetMulti* strHostIfSetMulti
- *  @return             NONE
- *  @author            Amr Abdel-Moghny
- *  @date                      Feb. 2014
- *  @version           9.0
- */
-static s32 Handle_AddBASession(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
+static s32 Handle_AddBASession(struct host_if_drv *hif_drv,
+                              struct ba_session_info *strHostIfBASessionInfo)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        int AddbaTimeout = 100;
        char *ptr = NULL;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
        PRINT_D(HOSTINF_DBG, "Opening Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\nBufferSize == %d\nSessionTimeOut = %d\n",
                strHostIfBASessionInfo->au8Bssid[0],
@@ -4128,154 +2717,60 @@ static s32 Handle_AddBASession(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASessionI
                strHostIfBASessionInfo->u16SessionTimeout,
                strHostIfBASessionInfo->u8Ted);
 
-       strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
-       strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
-       ptr = strWID.ps8WidVal;
-       /* *ptr++ = 0x14; */
+       wid.id = (u16)WID_11E_P_ACTION_REQ;
+       wid.type = WID_STR;
+       wid.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
+       wid.size = BLOCK_ACK_REQ_SIZE;
+       ptr = wid.val;
        *ptr++ = 0x14;
        *ptr++ = 0x3;
        *ptr++ = 0x0;
        memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
        ptr += ETH_ALEN;
        *ptr++ = strHostIfBASessionInfo->u8Ted;
-       /* BA Policy*/
        *ptr++ = 1;
-       /* Buffer size*/
        *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
        *ptr++ = ((strHostIfBASessionInfo->u16BufferSize >> 16) & 0xFF);
-       /* BA timeout*/
        *ptr++ = (strHostIfBASessionInfo->u16SessionTimeout & 0xFF);
        *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
-       /* ADDBA timeout*/
        *ptr++ = (AddbaTimeout & 0xFF);
        *ptr++ = ((AddbaTimeout >> 16) & 0xFF);
-       /* Group Buffer Max Frames*/
        *ptr++ = 8;
-       /* Group Buffer Timeout */
        *ptr++ = 0;
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error)
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_D(HOSTINF_DBG, "Couldn't open BA Session\n");
 
-
-       strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
-       strWID.enuWIDtype = WID_STR;
-       strWID.s32ValueSize = 15;
-       ptr = strWID.ps8WidVal;
-       /* *ptr++ = 0x14; */
+       wid.id = (u16)WID_11E_P_ACTION_REQ;
+       wid.type = WID_STR;
+       wid.size = 15;
+       ptr = wid.val;
        *ptr++ = 15;
        *ptr++ = 7;
        *ptr++ = 0x2;
        memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
        ptr += ETH_ALEN;
-       /* TID*/
        *ptr++ = strHostIfBASessionInfo->u8Ted;
-       /* Max Num MSDU */
        *ptr++ = 8;
-       /* BA timeout*/
        *ptr++ = (strHostIfBASessionInfo->u16BufferSize & 0xFF);
        *ptr++ = ((strHostIfBASessionInfo->u16SessionTimeout >> 16) & 0xFF);
-       /*Ack-Policy */
        *ptr++ = 3;
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-
-       if (strWID.ps8WidVal != NULL)
-               kfree(strWID.ps8WidVal);
-
-       return s32Error;
-
-}
-
-
-/*BugID_5222*/
-/**
- *  @brief                      Handle_DelBASession
- *  @details            Delete block ack session
- *  @param[in]          tstrHostIFSetMulti* strHostIfSetMulti
- *  @return             NONE
- *  @author            Amr Abdel-Moghny
- *  @date                      Feb. 2013
- *  @version           9.0
- */
-static s32 Handle_DelBASession(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
-{
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       char *ptr = NULL;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
-       PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n",
-               strHostIfBASessionInfo->au8Bssid[0],
-               strHostIfBASessionInfo->au8Bssid[1],
-               strHostIfBASessionInfo->au8Bssid[2],
-               strHostIfBASessionInfo->u8Ted);
-
-       strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
-       strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
-       ptr = strWID.ps8WidVal;
-       /* *ptr++ = 0x14; */
-       *ptr++ = 0x14;
-       *ptr++ = 0x3;
-       *ptr++ = 0x2;
-       memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
-       ptr += ETH_ALEN;
-       *ptr++ = strHostIfBASessionInfo->u8Ted;
-       /* BA direction = recipent*/
-       *ptr++ = 0;
-       /* Delba Reason */
-       *ptr++ = 32; /* Unspecific QOS reason */
-
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error)
-               PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
-
-
-       strWID.u16WIDid = (u16)WID_11E_P_ACTION_REQ;
-       strWID.enuWIDtype = WID_STR;
-       strWID.s32ValueSize = 15;
-       ptr = strWID.ps8WidVal;
-       /* *ptr++ = 0x14; */
-       *ptr++ = 15;
-       *ptr++ = 7;
-       *ptr++ = 0x3;
-       memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
-       ptr += ETH_ALEN;
-       /* TID*/
-       *ptr++ = strHostIfBASessionInfo->u8Ted;
-
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-
-       if (strWID.ps8WidVal != NULL)
-               kfree(strWID.ps8WidVal);
-
-       /*BugID_5222*/
-       up(&hWaitResponse);
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
 
-       return s32Error;
+       kfree(wid.val);
 
+       return result;
 }
 
-
-/**
- *  @brief                      Handle_DelAllRxBASessions
- *  @details            Delete all Rx BA sessions
- *  @param[in]          tstrHostIFSetMulti* strHostIfSetMulti
- *  @return             NONE
- *  @author            Abdelrahman Sobhy
- *  @date                      Feb. 2013
- *  @version           9.0
- */
-static s32 Handle_DelAllRxBASessions(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASessionInfo *strHostIfBASessionInfo)
+static s32 Handle_DelAllRxBASessions(struct host_if_drv *hif_drv,
+                                    struct ba_session_info *strHostIfBASessionInfo)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       s32 result = 0;
+       struct wid wid;
        char *ptr = NULL;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
 
        PRINT_D(GENERIC_DBG, "Delete Block Ack session with\nBSSID = %.2x:%.2x:%.2x\nTID=%d\n",
                strHostIfBASessionInfo->au8Bssid[0],
@@ -4283,256 +2778,230 @@ static s32 Handle_DelAllRxBASessions(tstrWILC_WFIDrv *drvHandler, tstrHostIfBASe
                strHostIfBASessionInfo->au8Bssid[2],
                strHostIfBASessionInfo->u8Ted);
 
-       strWID.u16WIDid = (u16)WID_DEL_ALL_RX_BA;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = WILC_MALLOC(BLOCK_ACK_REQ_SIZE);
-       strWID.s32ValueSize = BLOCK_ACK_REQ_SIZE;
-       ptr = strWID.ps8WidVal;
+       wid.id = (u16)WID_DEL_ALL_RX_BA;
+       wid.type = WID_STR;
+       wid.val = kmalloc(BLOCK_ACK_REQ_SIZE, GFP_KERNEL);
+       wid.size = BLOCK_ACK_REQ_SIZE;
+       ptr = wid.val;
        *ptr++ = 0x14;
        *ptr++ = 0x3;
        *ptr++ = 0x2;
        memcpy(ptr, strHostIfBASessionInfo->au8Bssid, ETH_ALEN);
        ptr += ETH_ALEN;
        *ptr++ = strHostIfBASessionInfo->u8Ted;
-       /* BA direction = recipent*/
        *ptr++ = 0;
-       /* Delba Reason */
-       *ptr++ = 32; /* Unspecific QOS reason */
+       *ptr++ = 32;
 
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error)
+       result = send_config_pkt(SET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result)
                PRINT_D(HOSTINF_DBG, "Couldn't delete BA Session\n");
 
+       kfree(wid.val);
 
-       if (strWID.ps8WidVal != NULL)
-               kfree(strWID.ps8WidVal);
-
-       /*BugID_5222*/
-       up(&hWaitResponse);
-
-       return s32Error;
+       up(&hif_sema_wait_response);
 
+       return result;
 }
 
-/**
- *  @brief hostIFthread
- *  @details        Main thread to handle message queue requests
- *  @param[in]   void* pvArg
- *  @return         NONE
- *  @author
- *  @date
- *  @version   1.0
- */
 static int hostIFthread(void *pvArg)
 {
        u32 u32Ret;
-       tstrHostIFmsg strHostIFmsg;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct host_if_msg msg;
+       struct host_if_drv *hif_drv;
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
        while (1) {
-               WILC_MsgQueueRecv(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg), &u32Ret);
-               pstrWFIDrv = (tstrWILC_WFIDrv *)strHostIFmsg.drvHandler;
-               if (strHostIFmsg.u16MsgId == HOST_IF_MSG_EXIT) {
+               wilc_mq_recv(&hif_msg_q, &msg, sizeof(struct host_if_msg), &u32Ret);
+               hif_drv = (struct host_if_drv *)msg.drv;
+               if (msg.id == HOST_IF_MSG_EXIT) {
                        PRINT_D(GENERIC_DBG, "THREAD: Exiting HostIfThread\n");
                        break;
                }
 
-
-               /*Re-Queue HIF message*/
                if ((!g_wilc_initialized)) {
                        PRINT_D(GENERIC_DBG, "--WAIT--");
                        usleep_range(200 * 1000, 200 * 1000);
-                       WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
+                       wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
                        continue;
                }
 
-               if (strHostIFmsg.u16MsgId == HOST_IF_MSG_CONNECT && pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult != NULL) {
+               if (msg.id == HOST_IF_MSG_CONNECT &&
+                   hif_drv->usr_scan_req.pfUserScanResult) {
                        PRINT_D(HOSTINF_DBG, "Requeue connect request till scan done received\n");
-                       WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
+                       wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
                        usleep_range(2 * 1000, 2 * 1000);
                        continue;
                }
 
-               switch (strHostIFmsg.u16MsgId) {
+               switch (msg.id) {
                case HOST_IF_MSG_Q_IDLE:
                        Handle_wait_msg_q_empty();
                        break;
 
                case HOST_IF_MSG_SCAN:
-                       Handle_Scan(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr);
+                       Handle_Scan(msg.drv, &msg.body.scan_info);
                        break;
 
                case HOST_IF_MSG_CONNECT:
-                       Handle_Connect(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr);
+                       Handle_Connect(msg.drv, &msg.body.con_info);
                        break;
 
-               /*BugID_5137*/
                case HOST_IF_MSG_FLUSH_CONNECT:
-                       Handle_FlushConnect(strHostIFmsg.drvHandler);
+                       Handle_FlushConnect(msg.drv);
                        break;
 
                case HOST_IF_MSG_RCVD_NTWRK_INFO:
-                       Handle_RcvdNtwrkInfo(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo);
+                       Handle_RcvdNtwrkInfo(msg.drv, &msg.body.net_info);
                        break;
 
                case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
-                       Handle_RcvdGnrlAsyncInfo(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo);
+                       Handle_RcvdGnrlAsyncInfo(msg.drv, &msg.body.async_info);
                        break;
 
                case HOST_IF_MSG_KEY:
-                       Handle_Key(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr);
+                       Handle_Key(msg.drv, &msg.body.key_info);
                        break;
 
                case HOST_IF_MSG_CFG_PARAMS:
 
-                       Handle_CfgParam(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFCfgParamAttr);
+                       Handle_CfgParam(msg.drv, &msg.body.cfg_info);
                        break;
 
                case HOST_IF_MSG_SET_CHANNEL:
-                       Handle_SetChannel(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFSetChan);
+                       Handle_SetChannel(msg.drv, &msg.body.channel_info);
                        break;
 
                case HOST_IF_MSG_DISCONNECT:
-                       Handle_Disconnect(strHostIFmsg.drvHandler);
+                       Handle_Disconnect(msg.drv);
                        break;
 
                case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
-                       del_timer(&pstrWFIDrv->hScanTimer);
+                       del_timer(&hif_drv->hScanTimer);
                        PRINT_D(HOSTINF_DBG, "scan completed successfully\n");
 
-                       /*BugID_5213*/
-                       /*Allow chip sleep, only if both interfaces are not connected*/
                        if (!linux_wlan_get_num_conn_ifcs())
                                chip_sleep_manually(INFINITE_SLEEP_TIME);
 
-                       Handle_ScanDone(strHostIFmsg.drvHandler, SCAN_EVENT_DONE);
+                       Handle_ScanDone(msg.drv, SCAN_EVENT_DONE);
 
-                               #ifdef WILC_P2P
-                       if (pstrWFIDrv->u8RemainOnChan_pendingreq)
-                               Handle_RemainOnChan(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan);
-                               #endif
+                       if (hif_drv->remain_on_ch_pending)
+                               Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
 
                        break;
 
                case HOST_IF_MSG_GET_RSSI:
-                       Handle_GetRssi(strHostIFmsg.drvHandler);
+                       Handle_GetRssi(msg.drv);
                        break;
 
                case HOST_IF_MSG_GET_LINKSPEED:
-                       Handle_GetLinkspeed(strHostIFmsg.drvHandler);
+                       Handle_GetLinkspeed(msg.drv);
                        break;
 
                case HOST_IF_MSG_GET_STATISTICS:
-                       Handle_GetStatistics(strHostIFmsg.drvHandler, (tstrStatistics *)strHostIFmsg.uniHostIFmsgBody.pUserData);
+                       Handle_GetStatistics(msg.drv, (struct rf_info *)msg.body.data);
                        break;
 
                case HOST_IF_MSG_GET_CHNL:
-                       Handle_GetChnl(strHostIFmsg.drvHandler);
+                       Handle_GetChnl(msg.drv);
                        break;
 
-#ifdef WILC_AP_EXTERNAL_MLME
                case HOST_IF_MSG_ADD_BEACON:
-                       Handle_AddBeacon(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFSetBeacon);
+                       Handle_AddBeacon(msg.drv, &msg.body.beacon_info);
                        break;
 
                case HOST_IF_MSG_DEL_BEACON:
-                       Handle_DelBeacon(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFDelBeacon);
+                       Handle_DelBeacon(msg.drv);
                        break;
 
                case HOST_IF_MSG_ADD_STATION:
-                       Handle_AddStation(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strAddStaParam);
+                       Handle_AddStation(msg.drv, &msg.body.add_sta_info);
                        break;
 
                case HOST_IF_MSG_DEL_STATION:
-                       Handle_DelStation(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strDelStaParam);
+                       Handle_DelStation(msg.drv, &msg.body.del_sta_info);
                        break;
 
                case HOST_IF_MSG_EDIT_STATION:
-                       Handle_EditStation(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strEditStaParam);
+                       Handle_EditStation(msg.drv, &msg.body.edit_sta_info);
                        break;
 
                case HOST_IF_MSG_GET_INACTIVETIME:
-                       Handle_Get_InActiveTime(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfStaInactiveT);
+                       Handle_Get_InActiveTime(msg.drv, &msg.body.mac_info);
                        break;
 
-#endif /*WILC_AP_EXTERNAL_MLME*/
                case HOST_IF_MSG_SCAN_TIMER_FIRED:
                        PRINT_D(HOSTINF_DBG, "Scan Timeout\n");
 
-                       Handle_ScanDone(strHostIFmsg.drvHandler, SCAN_EVENT_ABORTED);
+                       Handle_ScanDone(msg.drv, SCAN_EVENT_ABORTED);
                        break;
 
                case HOST_IF_MSG_CONNECT_TIMER_FIRED:
                        PRINT_D(HOSTINF_DBG, "Connect Timeout\n");
-                       Handle_ConnectTimeout(strHostIFmsg.drvHandler);
+                       Handle_ConnectTimeout(msg.drv);
                        break;
 
                case HOST_IF_MSG_POWER_MGMT:
-                       Handle_PowerManagement(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strPowerMgmtparam);
+                       Handle_PowerManagement(msg.drv, &msg.body.pwr_mgmt_info);
                        break;
 
                case HOST_IF_MSG_SET_WFIDRV_HANDLER:
-                       Handle_SetWfiDrvHandler(&strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler);
+                       Handle_SetWfiDrvHandler(msg.drv,
+                                               &msg.body.drv);
                        break;
 
                case HOST_IF_MSG_SET_OPERATION_MODE:
-                       Handle_SetOperationMode(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfSetOperationMode);
+                       Handle_SetOperationMode(msg.drv, &msg.body.mode);
                        break;
 
                case HOST_IF_MSG_SET_IPADDRESS:
                        PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
-                       Handle_set_IPAddress(strHostIFmsg.drvHandler, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx);
+                       Handle_set_IPAddress(msg.drv, msg.body.ip_info.ip_addr, msg.body.ip_info.idx);
                        break;
 
                case HOST_IF_MSG_GET_IPADDRESS:
                        PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_IPADDRESS\n");
-                       Handle_get_IPAddress(strHostIFmsg.drvHandler, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr, strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx);
+                       Handle_get_IPAddress(msg.drv, msg.body.ip_info.ip_addr, msg.body.ip_info.idx);
                        break;
 
-               /*BugID_5077*/
                case HOST_IF_MSG_SET_MAC_ADDRESS:
-                       Handle_SetMacAddress(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMacAddress);
+                       Handle_SetMacAddress(msg.drv, &msg.body.set_mac_info);
                        break;
 
-               /*BugID_5213*/
                case HOST_IF_MSG_GET_MAC_ADDRESS:
-                       Handle_GetMacAddress(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfGetMacAddress);
+                       Handle_GetMacAddress(msg.drv, &msg.body.get_mac_info);
                        break;
 
-#ifdef WILC_P2P
                case HOST_IF_MSG_REMAIN_ON_CHAN:
                        PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REMAIN_ON_CHAN\n");
-                       Handle_RemainOnChan(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan);
+                       Handle_RemainOnChan(msg.drv, &msg.body.remain_on_ch);
                        break;
 
                case HOST_IF_MSG_REGISTER_FRAME:
                        PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_REGISTER_FRAME\n");
-                       Handle_RegisterFrame(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame);
+                       Handle_RegisterFrame(msg.drv, &msg.body.reg_frame);
                        break;
 
                case HOST_IF_MSG_LISTEN_TIMER_FIRED:
-                       Handle_ListenStateExpired(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan);
+                       Handle_ListenStateExpired(msg.drv, &msg.body.remain_on_ch);
                        break;
 
-                       #endif
                case HOST_IF_MSG_SET_MULTICAST_FILTER:
                        PRINT_D(HOSTINF_DBG, "HOST_IF_MSG_SET_MULTICAST_FILTER\n");
-                       Handle_SetMulticastFilter(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMulti);
+                       Handle_SetMulticastFilter(msg.drv, &msg.body.multicast_info);
                        break;
 
-               /*BugID_5222*/
                case HOST_IF_MSG_ADD_BA_SESSION:
-                       Handle_AddBASession(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo);
+                       Handle_AddBASession(msg.drv, &msg.body.session_info);
                        break;
 
                case HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS:
-                       Handle_DelAllRxBASessions(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo);
+                       Handle_DelAllRxBASessions(msg.drv, &msg.body.session_info);
                        break;
 
                case HOST_IF_MSG_DEL_ALL_STA:
-                       Handle_DelAllSta(strHostIFmsg.drvHandler, &strHostIFmsg.uniHostIFmsgBody.strHostIFDelAllSta);
+                       Handle_DelAllSta(msg.drv, &msg.body.del_all_sta_info);
                        break;
 
                default:
@@ -4542,2900 +3011,1727 @@ static int hostIFthread(void *pvArg)
        }
 
        PRINT_D(HOSTINF_DBG, "Releasing thread exit semaphore\n");
-       up(&hSemHostIFthrdEnd);
+       up(&hif_sema_thread);
        return 0;
 }
 
 static void TimerCB_Scan(unsigned long arg)
 {
        void *pvArg = (void *)arg;
-       tstrHostIFmsg strHostIFmsg;
+       struct host_if_msg msg;
 
-       /* prepare the Timer Callback message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.drvHandler = pvArg;
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN_TIMER_FIRED;
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.drv = pvArg;
+       msg.id = HOST_IF_MSG_SCAN_TIMER_FIRED;
 
-       /* send the message */
-       WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
+       wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
 }
 
 static void TimerCB_Connect(unsigned long arg)
 {
        void *pvArg = (void *)arg;
-       tstrHostIFmsg strHostIFmsg;
+       struct host_if_msg msg;
 
-       /* prepare the Timer Callback message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.drvHandler = pvArg;
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT_TIMER_FIRED;
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.drv = pvArg;
+       msg.id = HOST_IF_MSG_CONNECT_TIMER_FIRED;
 
-       /* send the message */
-       WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
+       wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
 }
 
-
-/**
- *  @brief              removes wpa/wpa2 keys
- *  @details    only in BSS STA mode if External Supplicant support is enabled.
- *                              removes all WPA/WPA2 station key entries from MAC hardware.
- *  @param[in,out] handle to the wifi driver
- *  @param[in]  6 bytes of Station Adress in the station entry table
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-/* Check implementation in core adding 9 bytes to the input! */
-s32 host_int_remove_key(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8StaAddress)
+s32 host_int_remove_key(struct host_if_drv *hif_drv, const u8 *pu8StaAddress)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
-
-       strWID.u16WIDid = (u16)WID_REMOVE_KEY;
-       strWID.enuWIDtype       = WID_STR;
-       strWID.ps8WidVal        = (s8 *)pu8StaAddress;
-       strWID.s32ValueSize = 6;
+       struct wid wid;
 
-       return s32Error;
+       wid.id = (u16)WID_REMOVE_KEY;
+       wid.type = WID_STR;
+       wid.val = (s8 *)pu8StaAddress;
+       wid.size = 6;
 
+       return 0;
 }
 
-/**
- *  @brief              removes WEP key
- *  @details    valid only in BSS STA mode if External Supplicant support is enabled.
- *                              remove a WEP key entry from MAC HW.
- *                              The BSS Station automatically finds the index of the entry using its
- *                              BSS ID and removes that entry from the MAC hardware.
- *  @param[in,out] handle to the wifi driver
- *  @param[in]  6 bytes of Station Adress in the station entry table
- *  @return             Error code indicating success/failure
- *  @note               NO need for the STA add since it is not used for processing
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_remove_wep_key(tstrWILC_WFIDrv *hWFIDrv, u8 u8keyIdx)
+int host_int_remove_wep_key(struct host_if_drv *hif_drv, u8 index)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       int result = 0;
+       struct host_if_msg msg;
 
+       if (!hif_drv) {
+               result = -EFAULT;
+               PRINT_ER("Failed to send setup multicast config packet\n");
+               return result;
+       }
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the Remove Wep Key Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       msg.id = HOST_IF_MSG_KEY;
+       msg.body.key_info.type = WEP;
+       msg.body.key_info.action = REMOVEKEY;
+       msg.drv = hif_drv;
+       msg.body.key_info.attr.wep.index = index;
 
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("Error in sending message queue : Request to remove WEP key\n");
+       down(&hif_drv->hSemTestKeyBlock);
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = REMOVEKEY;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       return result;
+}
 
+int host_int_set_wep_default_key(struct host_if_drv *hif_drv, u8 index)
+{
+       int result = 0;
+       struct host_if_msg msg;
 
+       if (!hif_drv) {
+               result = -EFAULT;
+               PRINT_ER("driver is null\n");
+               return result;
+       }
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8keyIdx;
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               PRINT_ER("Error in sending message queue : Request to remove WEP key\n");
-       down(&(pstrWFIDrv->hSemTestKeyBlock));
+       msg.id = HOST_IF_MSG_KEY;
+       msg.body.key_info.type = WEP;
+       msg.body.key_info.action = DEFAULTKEY;
+       msg.drv = hif_drv;
+       msg.body.key_info.attr.wep.index = index;
 
-       WILC_CATCH(s32Error)
-       {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("Error in sending message queue : Default key index\n");
+       down(&hif_drv->hSemTestKeyBlock);
 
-       }
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              sets WEP default key
- *  @details    Sets the index of the WEP encryption key in use,
- *                              in the key table
- *  @param[in,out] handle to the wifi driver
- *  @param[in]  key index ( 0, 1, 2, 3)
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_set_WEPDefaultKeyID(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index)
+int host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv,
+                                const u8 *key,
+                                u8 len,
+                                u8 index)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       /* prepare the Key Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = DEFAULTKEY;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Index;
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               PRINT_ER("Error in sending message queue : Default key index\n");
-       down(&(pstrWFIDrv->hSemTestKeyBlock));
-
-       WILC_CATCH(s32Error)
-       {
+       int result = 0;
+       struct host_if_msg msg;
 
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
-       return s32Error;
-}
-
-/**
- *  @brief              sets WEP deafault key
- *  @details    valid only in BSS STA mode if External Supplicant support is enabled.
- *                              sets WEP key entry into MAC hardware when it receives the
- *                              corresponding request from NDIS.
- *  @param[in,out] handle to the wifi driver
- *  @param[in]  message containing WEP Key in the following format
- *|---------------------------------------|
- *|Key ID Value | Key Length | Key             |
- *|-------------|------------|------------|
- |     1byte     |             1byte  | Key Length     |
- ||---------------------------------------|
- |
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_add_wep_key_bss_sta(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx)
-{
-
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-
-       /* prepare the Key Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_KEY;
+       msg.body.key_info.type = WEP;
+       msg.body.key_info.action = ADDKEY;
+       msg.drv = hif_drv;
+       msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
+       if (!msg.body.key_info.attr.wep.key)
+               return -ENOMEM;
 
+       msg.body.key_info.attr.wep.key_len = len;
+       msg.body.key_info.attr.wep.index = index;
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = WILC_MALLOC(u8WepKeylen);
-
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
-                   pu8WepKey, u8WepKeylen);
-
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen = (u8WepKeylen);
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Keyidx;
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
                PRINT_ER("Error in sending message queue :WEP Key\n");
-       down(&(pstrWFIDrv->hSemTestKeyBlock));
-
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       return s32Error;
+       down(&hif_drv->hSemTestKeyBlock);
 
+       return result;
 }
 
-#ifdef WILC_AP_EXTERNAL_MLME
-/**
- *
- *  @brief              host_int_add_wep_key_bss_ap
- *  @details    valid only in BSS AP mode if External Supplicant support is enabled.
- *                              sets WEP key entry into MAC hardware when it receives the
- *
- *                              corresponding request from NDIS.
- *  @param[in,out] handle to the wifi driver
- *
- *
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            mdaftedar
- *  @date              28 FEB 2013
- *  @version           1.0
- */
-s32 host_int_add_wep_key_bss_ap(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx, u8 u8mode, AUTHTYPE_T tenuAuth_type)
+int host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv,
+                               const u8 *key,
+                               u8 len,
+                               u8 index,
+                               u8 mode,
+                               enum AUTHTYPE auth_type)
 {
+       int result = 0;
+       struct host_if_msg msg;
+       int i;
 
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       u8 i;
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       /* prepare the Key Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
        if (INFO) {
-               for (i = 0; i < u8WepKeylen; i++)
-                       PRINT_INFO(HOSTAPD_DBG, "KEY is %x\n", pu8WepKey[i]);
+               for (i = 0; i < len; i++)
+                       PRINT_INFO(HOSTAPD_DBG, "KEY is %x\n", key[i]);
        }
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WEP;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY_AP;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey = WILC_MALLOC((u8WepKeylen));
-
-
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
-                   pu8WepKey, (u8WepKeylen));
-
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen = (u8WepKeylen);
+       msg.id = HOST_IF_MSG_KEY;
+       msg.body.key_info.type = WEP;
+       msg.body.key_info.action = ADDKEY_AP;
+       msg.drv = hif_drv;
+       msg.body.key_info.attr.wep.key = kmemdup(key, len, GFP_KERNEL);
+       if (!msg.body.key_info.attr.wep.key)
+               return -ENOMEM;
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.u8Wepidx = u8Keyidx;
+       msg.body.key_info.attr.wep.key_len = len;
+       msg.body.key_info.attr.wep.index = index;
+       msg.body.key_info.attr.wep.mode = mode;
+       msg.body.key_info.attr.wep.auth_type = auth_type;
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.u8mode = u8mode;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwepAttr.tenuAuth_type = tenuAuth_type;
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-
-       if (s32Error)
+       if (result)
                PRINT_ER("Error in sending message queue :WEP Key\n");
-       down(&(pstrWFIDrv->hSemTestKeyBlock));
-
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       return s32Error;
+       down(&hif_drv->hSemTestKeyBlock);
 
+       return result;
 }
-#endif
-/**
- *  @brief              adds ptk Key
- *  @details
- *  @param[in,out] handle to the wifi driver
- *  @param[in]  message containing PTK Key in the following format
- *|-----------------------------------------------------------------------------|
- *|Station address | Key Length |      Temporal Key | Rx Michael Key |Tx Michael Key |
- *|----------------|------------|--------------|----------------|---------------|
- |     6 bytes          |      1byte     |   16 bytes   |        8 bytes         |        8 bytes        |
- ||-----------------------------------------------------------------------------|
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_add_ptk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen,
-                            const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx)
+
+s32 host_int_add_ptk(struct host_if_drv *hif_drv, const u8 *pu8Ptk,
+                    u8 u8PtkKeylen, const u8 *mac_addr,
+                    const u8 *pu8RxMic, const u8 *pu8TxMic,
+                    u8 mode, u8 u8Ciphermode, u8 u8Idx)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
        u8 u8KeyLen = u8PtkKeylen;
        u32 i;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-       if (pu8RxMic != NULL)
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
+
+       if (pu8RxMic)
                u8KeyLen += RX_MIC_KEY_LEN;
-       if (pu8TxMic != NULL)
-               u8KeyLen += TX_MIC_KEY_LEN;
 
-       /* prepare the Key Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       if (pu8TxMic)
+               u8KeyLen += TX_MIC_KEY_LEN;
 
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WPAPtk;
-       #ifdef WILC_AP_EXTERNAL_MLME
+       msg.id = HOST_IF_MSG_KEY;
+       msg.body.key_info.type = WPAPtk;
        if (mode == AP_MODE) {
-               strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY_AP;
-               strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-               uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx = u8Idx;
+               msg.body.key_info.action = ADDKEY_AP;
+               msg.body.key_info.attr.wpa.index = u8Idx;
        }
-       #endif
        if (mode == STATION_MODE)
-               strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
-
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = WILC_MALLOC(u8PtkKeylen);
+               msg.body.key_info.action = ADDKEY;
 
+       msg.body.key_info.attr.wpa.key = kmalloc(u8PtkKeylen, GFP_KERNEL);
+       memcpy(msg.body.key_info.attr.wpa.key, pu8Ptk, u8PtkKeylen);
 
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
-                   pu8Ptk, u8PtkKeylen);
-
-       if (pu8RxMic != NULL) {
-
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16,
-                           pu8RxMic, RX_MIC_KEY_LEN);
+       if (pu8RxMic) {
+               memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic, RX_MIC_KEY_LEN);
                if (INFO) {
                        for (i = 0; i < RX_MIC_KEY_LEN; i++)
                                PRINT_INFO(CFG80211_DBG, "PairwiseRx[%d] = %x\n", i, pu8RxMic[i]);
                }
        }
-       if (pu8TxMic != NULL) {
-
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24,
-                           pu8TxMic, TX_MIC_KEY_LEN);
+       if (pu8TxMic) {
+               memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic, TX_MIC_KEY_LEN);
                if (INFO) {
                        for (i = 0; i < TX_MIC_KEY_LEN; i++)
                                PRINT_INFO(CFG80211_DBG, "PairwiseTx[%d] = %x\n", i, pu8TxMic[i]);
                }
        }
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen = u8KeyLen;
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode = u8Ciphermode;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.pu8macaddr = mac_addr;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.body.key_info.attr.wpa.key_len = u8KeyLen;
+       msg.body.key_info.attr.wpa.mac_addr = mac_addr;
+       msg.body.key_info.attr.wpa.mode = u8Ciphermode;
+       msg.drv = hif_drv;
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
 
-       if (s32Error)
+       if (result)
                PRINT_ER("Error in sending message queue:  PTK Key\n");
 
-       /* ////////////// */
-       down(&(pstrWFIDrv->hSemTestKeyBlock));
-       /* /////// */
+       down(&hif_drv->hSemTestKeyBlock);
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              adds Rx GTk Key
- *  @details
- *  @param[in,out] handle to the wifi driver
- *  @param[in]  pu8RxGtk : contains temporal key | Rx Mic | Tx Mic
- *                              u8GtkKeylen :The total key length
- *
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_add_rx_gtk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen,
-                               u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC,
-                               const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode)
+s32 host_int_add_rx_gtk(struct host_if_drv *hif_drv, const u8 *pu8RxGtk,
+                       u8 u8GtkKeylen, u8 u8KeyIdx,
+                       u32 u32KeyRSClen, const u8 *KeyRSC,
+                       const u8 *pu8RxMic, const u8 *pu8TxMic,
+                       u8 mode, u8 u8Ciphermode)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
        u8 u8KeyLen = u8GtkKeylen;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-       /* prepare the Key Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       if (pu8RxMic != NULL)
+       if (pu8RxMic)
                u8KeyLen += RX_MIC_KEY_LEN;
-       if (pu8TxMic != NULL)
+
+       if (pu8TxMic)
                u8KeyLen += TX_MIC_KEY_LEN;
-       if (KeyRSC != NULL) {
-               strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-               uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq = WILC_MALLOC(u32KeyRSClen);
 
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8seq,
-                           KeyRSC, u32KeyRSClen);
+       if (KeyRSC) {
+               msg.body.key_info.attr.wpa.seq = kmalloc(u32KeyRSClen, GFP_KERNEL);
+               memcpy(msg.body.key_info.attr.wpa.seq, KeyRSC, u32KeyRSClen);
        }
 
+       msg.id = HOST_IF_MSG_KEY;
+       msg.body.key_info.type = WPARxGtk;
+       msg.drv = hif_drv;
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = WPARxGtk;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-    #ifdef WILC_AP_EXTERNAL_MLME
        if (mode == AP_MODE) {
-               strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY_AP;
-               strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.u8Ciphermode = u8Ciphermode;
+               msg.body.key_info.action = ADDKEY_AP;
+               msg.body.key_info.attr.wpa.mode = u8Ciphermode;
        }
-    #endif
        if (mode == STATION_MODE)
-               strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
-
+               msg.body.key_info.action = ADDKEY;
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.pu8key = WILC_MALLOC(u8KeyLen);
+       msg.body.key_info.attr.wpa.key = kmalloc(u8KeyLen, GFP_KERNEL);
+       memcpy(msg.body.key_info.attr.wpa.key, pu8RxGtk, u8GtkKeylen);
 
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key,
-                   pu8RxGtk, u8GtkKeylen);
+       if (pu8RxMic)
+               memcpy(msg.body.key_info.attr.wpa.key + 16, pu8RxMic,
+                      RX_MIC_KEY_LEN);
 
-       if (pu8RxMic != NULL) {
+       if (pu8TxMic)
+               memcpy(msg.body.key_info.attr.wpa.key + 24, pu8TxMic,
+                      TX_MIC_KEY_LEN);
 
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 16,
-                           pu8RxMic, RX_MIC_KEY_LEN);
+       msg.body.key_info.attr.wpa.index = u8KeyIdx;
+       msg.body.key_info.attr.wpa.key_len = u8KeyLen;
+       msg.body.key_info.attr.wpa.seq_len = u32KeyRSClen;
 
-       }
-       if (pu8TxMic != NULL) {
-
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFwpaAttr.pu8key + 24,
-                           pu8TxMic, TX_MIC_KEY_LEN);
-
-       }
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.u8keyidx = u8KeyIdx;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.u8Keylen = u8KeyLen;
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.
-       uniHostIFkeyAttr.strHostIFwpaAttr.u8seqlen = u32KeyRSClen;
-
-
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
                PRINT_ER("Error in sending message queue:  RX GTK\n");
-       /* ////////////// */
-       down(&(pstrWFIDrv->hSemTestKeyBlock));
-       /* /////// */
 
-       WILC_CATCH(s32Error)
-       {
+       down(&hif_drv->hSemTestKeyBlock);
 
-       }
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              host_int_set_pmkid_info
- *  @details    caches the pmkid valid only in BSS STA mode if External Supplicant
- *                              support is enabled. This Function sets the PMKID in firmware
- *                              when host drivr receives the corresponding request from NDIS.
- *                              The firmware then includes theset PMKID in the appropriate
- *                              management frames
- *  @param[in,out] handle to the wifi driver
- *  @param[in]  message containing PMKID Info in the following format
- *|-----------------------------------------------------------------|
- *|NumEntries |        BSSID[1] | PMKID[1] |  ...      | BSSID[K] | PMKID[K] |
- *|-----------|------------|----------|-------|----------|----------|
- |        1    |               6        |   16         |  ...  |        6         |    16        |
- ||-----------------------------------------------------------------|
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_set_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, tstrHostIFpmkidAttr *pu8PmkidInfoArray)
+s32 host_int_set_pmkid_info(struct host_if_drv *hif_drv, struct host_if_pmkid_attr *pu8PmkidInfoArray)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
        u32 i;
 
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       /* prepare the Key Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_KEY;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.enuKeyType = PMKSA;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.u8KeyAction = ADDKEY;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_KEY;
+       msg.body.key_info.type = PMKSA;
+       msg.body.key_info.action = ADDKEY;
+       msg.drv = hif_drv;
 
        for (i = 0; i < pu8PmkidInfoArray->numpmkid; i++) {
-
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].bssid, &pu8PmkidInfoArray->pmkidlist[i].bssid,
-                           ETH_ALEN);
-
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFkeyAttr.uniHostIFkeyAttr.strHostIFpmkidAttr.pmkidlist[i].pmkid, &pu8PmkidInfoArray->pmkidlist[i].pmkid,
-                           PMKID_LEN);
+               memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].bssid,
+                      &pu8PmkidInfoArray->pmkidlist[i].bssid, ETH_ALEN);
+               memcpy(msg.body.key_info.attr.pmkid.pmkidlist[i].pmkid,
+                      &pu8PmkidInfoArray->pmkidlist[i].pmkid, PMKID_LEN);
        }
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
                PRINT_ER(" Error in sending messagequeue: PMKID Info\n");
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              gets the cached the pmkid info
- *  @details    valid only in BSS STA mode if External Supplicant
- *                              support is enabled. This Function sets the PMKID in firmware
- *                              when host drivr receives the corresponding request from NDIS.
- *                              The firmware then includes theset PMKID in the appropriate
- *                              management frames
- *  @param[in,out] handle to the wifi driver,
- *                                message containing PMKID Info in the following format
- *|-----------------------------------------------------------------|
- *|NumEntries |        BSSID[1] | PMKID[1] |  ...      | BSSID[K] | PMKID[K] |
- *|-----------|------------|----------|-------|----------|----------|
- |        1    |               6        |   16         |  ...  |        6         |    16        |
- ||-----------------------------------------------------------------|
- *  @param[in]
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_get_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PmkidInfoArray,
-                                   u32 u32PmkidInfoLen)
+s32 host_int_get_pmkid_info(struct host_if_drv *hif_drv,
+                           u8 *pu8PmkidInfoArray,
+                           u32 u32PmkidInfoLen)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_PMKID_INFO;
-       strWID.enuWIDtype       = WID_STR;
-       strWID.s32ValueSize = u32PmkidInfoLen;
-       strWID.ps8WidVal = pu8PmkidInfoArray;
+       wid.id = (u16)WID_PMKID_INFO;
+       wid.type = WID_STR;
+       wid.size = u32PmkidInfoLen;
+       wid.val = pu8PmkidInfoArray;
 
-       return s32Error;
+       return 0;
 }
 
-/**
- *  @brief              sets the pass phrase
- *  @details    AP/STA mode. This function gives the pass phrase used to
- *                              generate the Pre-Shared Key when WPA/WPA2 is enabled
- *                              The length of the field can vary from 8 to 64 bytes,
- *                              the lower layer should get the
- *  @param[in,out] handle to the wifi driver,
- *  @param[in]   String containing PSK
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_set_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PassPhrase,
-                                                u8 u8Psklength)
+s32 host_int_set_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
+                                        u8 *pu8PassPhrase,
+                                        u8 u8Psklength)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
+       struct wid wid;
 
-       /*validating psk length*/
        if ((u8Psklength > 7) && (u8Psklength < 65)) {
-               strWID.u16WIDid = (u16)WID_11I_PSK;
-               strWID.enuWIDtype       = WID_STR;
-               strWID.ps8WidVal        = pu8PassPhrase;
-               strWID.s32ValueSize = u8Psklength;
+               wid.id = (u16)WID_11I_PSK;
+               wid.type = WID_STR;
+               wid.val = pu8PassPhrase;
+               wid.size = u8Psklength;
        }
 
-       return s32Error;
+       return 0;
 }
-/**
- *  @brief              host_int_get_MacAddress
- *  @details   gets mac address
- *  @param[in,out] handle to the wifi driver,
- *
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            mdaftedar
- *  @date              19 April 2012
- *  @version           1.0
- */
-s32 host_int_get_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress)
+
+s32 host_int_get_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       msg.id = HOST_IF_MSG_GET_MAC_ADDRESS;
+       msg.body.get_mac_info.mac_addr = pu8MacAddress;
+       msg.drv = hif_drv;
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_MAC_ADDRESS;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfGetMacAddress.u8MacAddress = pu8MacAddress;
-       strHostIFmsg.drvHandler = hWFIDrv;
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
                PRINT_ER("Failed to send get mac address\n");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
-       down(&hWaitResponse);
-       return s32Error;
+       down(&hif_sema_wait_response);
+       return result;
 }
 
-/**
- *  @brief              host_int_set_MacAddress
- *  @details   sets mac address
- *  @param[in,out] handle to the wifi driver,
- *
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            mabubakr
- *  @date              16 July 2012
- *  @version           1.0
- */
-s32 host_int_set_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress)
+s32 host_int_set_MacAddress(struct host_if_drv *hif_drv, u8 *pu8MacAddress)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
        PRINT_D(GENERIC_DBG, "mac addr = %x:%x:%x\n", pu8MacAddress[0], pu8MacAddress[1], pu8MacAddress[2]);
 
-       /* prepare setting mac address message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_MAC_ADDRESS;
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfSetMacAddress.u8MacAddress, pu8MacAddress, ETH_ALEN);
-       strHostIFmsg.drvHandler = hWFIDrv;
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_SET_MAC_ADDRESS;
+       memcpy(msg.body.set_mac_info.mac_addr, pu8MacAddress, ETH_ALEN);
+       msg.drv = hif_drv;
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
                PRINT_ER("Failed to send message queue: Set mac address\n");
-               WILC_ERRORREPORT(s32Error, s32Error);
-       }
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
-       return s32Error;
 
+       return result;
 }
 
-/**
- *  @brief              host_int_get_RSNAConfigPSKPassPhrase
- *  @details    gets the pass phrase:AP/STA mode. This function gets the pass phrase used to
- *                              generate the Pre-Shared Key when WPA/WPA2 is enabled
- *                              The length of the field can vary from 8 to 64 bytes,
- *                              the lower layer should get the
- *  @param[in,out] handle to the wifi driver,
- *                                String containing PSK
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_get_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv,
-                                                u8 *pu8PassPhrase, u8 u8Psklength)
+s32 host_int_get_RSNAConfigPSKPassPhrase(struct host_if_drv *hif_drv,
+                                        u8 *pu8PassPhrase, u8 u8Psklength)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_11I_PSK;
-       strWID.enuWIDtype       = WID_STR;
-       strWID.s32ValueSize = u8Psklength;
-       strWID.ps8WidVal        = pu8PassPhrase;
+       wid.id = (u16)WID_11I_PSK;
+       wid.type = WID_STR;
+       wid.size = u8Psklength;
+       wid.val = pu8PassPhrase;
 
-       return s32Error;
+       return 0;
 }
 
-/**
- *  @brief                      host_int_get_site_survey_results
- *  @details            gets the site survey results
- *  @param[in,out] handle to the wifi driver,
- *                                Message containing  site survey results in the
- *                                following format
- *|---------------------------------------------------|
- | MsgLength | fragNo. | MsgBodyLength | MsgBody       |
- ||-----------|-----------|---------------|-----------|
- |      1              |         1             |               1               |        1              |
- | -----------------------------------------    |  ----------------
- |
- ||---------------------------------------|
- | Network1 | Netweork2 | ... | Network5 |
- ||---------------------------------------|
- |     44         |    44         | ... |       44             |
- | -------------------------- | ---------------------------------------
- |
- ||---------------------------------------------------------------------|
- | SSID | BSS Type | Channel | Security Status| BSSID | RSSI |Reserved |
- |
- |
- ||------|----------|---------|----------------|-------|------|---------|
- |  33  |       1        |       1             |               1                |        6      |       1      |        1        |
- ||---------------------------------------------------------------------|
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-#ifndef CONNECT_DIRECT
-s32 host_int_get_site_survey_results(tstrWILC_WFIDrv *hWFIDrv,
-                                            u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
-                                            u32 u32MaxSiteSrvyFragLen)
-{
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID astrWIDList[2];
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-
-       astrWIDList[0].u16WIDid = (u16)WID_SITE_SURVEY_RESULTS;
-       astrWIDList[0].enuWIDtype = WID_STR;
-       astrWIDList[0].ps8WidVal = ppu8RcvdSiteSurveyResults[0];
-       astrWIDList[0].s32ValueSize = u32MaxSiteSrvyFragLen;
-
-       astrWIDList[1].u16WIDid = (u16)WID_SITE_SURVEY_RESULTS;
-       astrWIDList[1].enuWIDtype = WID_STR;
-       astrWIDList[1].ps8WidVal = ppu8RcvdSiteSurveyResults[1];
-       astrWIDList[1].s32ValueSize = u32MaxSiteSrvyFragLen;
-
-       s32Error = SendConfigPkt(GET_CFG, astrWIDList, 2, true, (u32)pstrWFIDrv);
-
-       /*get the value by searching the local copy*/
-       if (s32Error) {
-               PRINT_ER("Failed to send config packet to get survey results\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       }
-
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
-       return s32Error;
-}
-#endif
-
-/**
- *  @brief              sets a start scan request
- *  @details
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Scan Source one of the following values
- *                              DEFAULT_SCAN        0
- *                              USER_SCAN           BIT0
- *                              OBSS_PERIODIC_SCAN  BIT1
- *                              OBSS_ONETIME_SCAN   BIT2
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_set_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 scanSource)
+s32 host_int_set_start_scan_req(struct host_if_drv *hif_drv, u8 scanSource)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_START_SCAN_REQ;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = (s8 *)&scanSource;
-       strWID.s32ValueSize = sizeof(char);
+       wid.id = (u16)WID_START_SCAN_REQ;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)&scanSource;
+       wid.size = sizeof(char);
 
-       return s32Error;
+       return 0;
 }
 
-/**
- *  @brief                      host_int_get_start_scan_req
- *  @details            gets a start scan request
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Scan Source one of the following values
- *                              DEFAULT_SCAN        0
- *                              USER_SCAN           BIT0
- *                              OBSS_PERIODIC_SCAN  BIT1
- *                              OBSS_ONETIME_SCAN   BIT2
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-
-s32 host_int_get_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ScanSource)
+s32 host_int_get_start_scan_req(struct host_if_drv *hif_drv, u8 *pu8ScanSource)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_START_SCAN_REQ;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = (s8 *)pu8ScanSource;
-       strWID.s32ValueSize = sizeof(char);
+       wid.id = (u16)WID_START_SCAN_REQ;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)pu8ScanSource;
+       wid.size = sizeof(char);
 
-       return s32Error;
+       return 0;
 }
 
-/**
- *  @brief                      host_int_set_join_req
- *  @details            sets a join request
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Index of the bss descriptor
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_set_join_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8bssid,
-                                 const u8 *pu8ssid, size_t ssidLen,
-                                 const u8 *pu8IEs, size_t IEsLen,
-                                 tWILCpfConnectResult pfConnectResult, void *pvUserArg,
-                                 u8 u8security, AUTHTYPE_T tenuAuth_type,
-                                 u8 u8channel,
-                                 void *pJoinParams)
+s32 host_int_set_join_req(struct host_if_drv *hif_drv, u8 *pu8bssid,
+                         const u8 *pu8ssid, size_t ssidLen,
+                         const u8 *pu8IEs, size_t IEsLen,
+                         wilc_connect_result pfConnectResult, void *pvUserArg,
+                         u8 u8security, enum AUTHTYPE tenuAuth_type,
+                         u8 u8channel, void *pJoinParams)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tenuScanConnTimer enuScanConnTimer;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       if (pstrWFIDrv == NULL || pfConnectResult == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       if (hWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: gWFiDrvHandle = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+       if (!hif_drv || !pfConnectResult) {
+               PRINT_ER("Driver is null\n");
+               return -EFAULT;
        }
 
-       if (pJoinParams == NULL) {
+       if (!pJoinParams) {
                PRINT_ER("Unable to Join - JoinParams is NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-
+               return -EFAULT;
        }
-/*
- *      if(gWFiDrvHandle->strWILC_UsrScanReq.u32RcvdChCount == 0)
- *      {
- *              PRINT_ER("No scan results exist: Scanning should be done\n");
- *              WILC_ERRORREPORT(s32Error, WILC_FAIL);
- *      }
- */
-       /* prepare the Connect Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_CONNECT;
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.u8security = u8security;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.tenuAuth_type = tenuAuth_type;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.u8channel = u8channel;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pfConnectResult = pfConnectResult;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pvUserArg = pvUserArg;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pJoinParams = pJoinParams;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_CONNECT;
 
-       if (pu8bssid != NULL) {
-               strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid = WILC_MALLOC(6); /* will be deallocated by the receiving thread */
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8bssid,
-                           pu8bssid, 6);
-       }
+       msg.body.con_info.security = u8security;
+       msg.body.con_info.auth_type = tenuAuth_type;
+       msg.body.con_info.ch = u8channel;
+       msg.body.con_info.result = pfConnectResult;
+       msg.body.con_info.arg = pvUserArg;
+       msg.body.con_info.params = pJoinParams;
+       msg.drv = hif_drv ;
 
-       if (pu8ssid != NULL) {
-               strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.ssidLen = ssidLen;
-               strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid = WILC_MALLOC(ssidLen); /* will be deallocated by the receiving thread */
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8ssid,
+       if (pu8bssid) {
+               msg.body.con_info.bssid = kmalloc(6, GFP_KERNEL);
+               memcpy(msg.body.con_info.bssid, pu8bssid, 6);
+       }
 
-                           pu8ssid, ssidLen);
+       if (pu8ssid) {
+               msg.body.con_info.ssid_len = ssidLen;
+               msg.body.con_info.ssid = kmalloc(ssidLen, GFP_KERNEL);
+               memcpy(msg.body.con_info.ssid, pu8ssid, ssidLen);
        }
 
-       if (pu8IEs != NULL) {
-               strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.IEsLen = IEsLen;
-               strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs = WILC_MALLOC(IEsLen); /* will be deallocated by the receiving thread */
-               memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFconnectAttr.pu8IEs,
-                           pu8IEs, IEsLen);
+       if (pu8IEs) {
+               msg.body.con_info.ies_len = IEsLen;
+               msg.body.con_info.ies = kmalloc(IEsLen, GFP_KERNEL);
+               memcpy(msg.body.con_info.ies, pu8IEs, IEsLen);
        }
-       if (pstrWFIDrv->enuHostIFstate < HOST_IF_CONNECTING)
-               pstrWFIDrv->enuHostIFstate = HOST_IF_CONNECTING;
+       if (hif_drv->enuHostIFstate < HOST_IF_CONNECTING)
+               hif_drv->enuHostIFstate = HOST_IF_CONNECTING;
        else
-               PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", pstrWFIDrv->enuHostIFstate);
+               PRINT_D(GENERIC_DBG, "Don't set state to 'connecting' as state is %d\n", hif_drv->enuHostIFstate);
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
                PRINT_ER("Failed to send message queue: Set join request\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+               return -EFAULT;
        }
 
-       enuScanConnTimer = CONNECT_TIMER;
-       pstrWFIDrv->hConnectTimer.data = (unsigned long)hWFIDrv;
-       mod_timer(&pstrWFIDrv->hConnectTimer,
+       hif_drv->hConnectTimer.data = (unsigned long)hif_drv;
+       mod_timer(&hif_drv->hConnectTimer,
                  jiffies + msecs_to_jiffies(HOST_IF_CONNECT_TIMEOUT));
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              Flush a join request parameters to FW, but actual connection
- *  @details    The function is called in situation where WILC is connected to AP and
- *                      required to switch to hybrid FW for P2P connection
- *  @param[in] handle to the wifi driver,
- *  @return     Error code indicating success/failure
- *  @note
- *  @author    Amr Abdel-Moghny
- *  @date              19 DEC 2013
- *  @version   8.0
- */
-
-s32 host_int_flush_join_req(tstrWILC_WFIDrv *hWFIDrv)
+s32 host_int_flush_join_req(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
-
-       if (!gu8FlushedJoinReq) {
-               s32Error = WILC_FAIL;
-               return s32Error;
-       }
-
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       if (hWFIDrv  == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!join_req)
+               return -EFAULT;
 
+       if (!hif_drv) {
+               PRINT_ER("Driver is null\n");
+               return -EFAULT;
+       }
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_FLUSH_CONNECT;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_FLUSH_CONNECT;
+       msg.drv = hif_drv;
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
                PRINT_ER("Failed to send message queue: Flush join request\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+               return -EFAULT;
        }
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief                      host_int_disconnect
- *  @details            disconnects from the currently associated network
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Reason Code of the Disconnection
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_disconnect(tstrWILC_WFIDrv *hWFIDrv, u16 u16ReasonCode)
+s32 host_int_disconnect(struct host_if_drv *hif_drv, u16 u16ReasonCode)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("Driver is null\n");
+               return -EFAULT;
        }
 
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("gWFiDrvHandle = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
-       }
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the Disconnect Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       msg.id = HOST_IF_MSG_DISCONNECT;
+       msg.drv = hif_drv;
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_DISCONNECT;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
                PRINT_ER("Failed to send message queue: disconnect\n");
-       /* ////////////// */
-       down(&(pstrWFIDrv->hSemTestDisconnectBlock));
-       /* /////// */
-
-       WILC_CATCH(s32Error)
-       {
 
-       }
+       down(&hif_drv->hSemTestDisconnectBlock);
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              host_int_disconnect_station
- *  @details     disconnects a sta
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Association Id of the station to be disconnected
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_disconnect_station(tstrWILC_WFIDrv *hWFIDrv, u8 assoc_id)
+s32 host_int_disconnect_station(struct host_if_drv *hif_drv, u8 assoc_id)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_DISCONNECT;
-       strWID.enuWIDtype = WID_CHAR;
-       strWID.ps8WidVal = (s8 *)&assoc_id;
-       strWID.s32ValueSize = sizeof(char);
+       wid.id = (u16)WID_DISCONNECT;
+       wid.type = WID_CHAR;
+       wid.val = (s8 *)&assoc_id;
+       wid.size = sizeof(char);
 
-       return s32Error;
+       return 0;
 }
 
-/**
- *  @brief                      host_int_get_assoc_req_info
- *  @details            gets a Association request info
- *  @param[in,out] handle to the wifi driver,
- *                              Message containg assoc. req info in the following format
- * ------------------------------------------------------------------------
- |                        Management Frame Format                    |
- ||-------------------------------------------------------------------|
- ||Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS |
- ||-------------|--------|--|--|-----|----------------|----------|----|
- | 2           |2       |6 |6 |6    |          2       |0 - 2312  | 4  |
- ||-------------------------------------------------------------------|
- |                                                                   |
- |             Association Request Frame - Frame Body                |
- ||-------------------------------------------------------------------|
- | Capability Information | Listen Interval | SSID | Supported Rates |
- ||------------------------|-----------------|------|-----------------|
- |                     2            |           2         | 2-34 |             3-10        |
- | ---------------------------------------------------------------------
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-
-s32 host_int_get_assoc_req_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocReqInfo,
-                                       u32 u32AssocReqInfoLen)
+s32 host_int_get_assoc_req_info(struct host_if_drv *hif_drv,
+                               u8 *pu8AssocReqInfo,
+                               u32 u32AssocReqInfoLen)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
-
-       strWID.u16WIDid = (u16)WID_ASSOC_REQ_INFO;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = pu8AssocReqInfo;
-       strWID.s32ValueSize = u32AssocReqInfoLen;
+       struct wid wid;
 
+       wid.id = (u16)WID_ASSOC_REQ_INFO;
+       wid.type = WID_STR;
+       wid.val = pu8AssocReqInfo;
+       wid.size = u32AssocReqInfoLen;
 
-       return s32Error;
+       return 0;
 }
 
-/**
- *  @brief              gets a Association Response info
- *  @details
- *  @param[in,out] handle to the wifi driver,
- *                              Message containg assoc. resp info
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_get_assoc_res_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocRespInfo,
-                                       u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen)
+s32 host_int_get_assoc_res_info(struct host_if_drv *hif_drv,
+                               u8 *pu8AssocRespInfo,
+                               u32 u32MaxAssocRespInfoLen,
+                               u32 *pu32RcvdAssocRespInfoLen)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
+       s32 result = 0;
+       struct wid wid;
 
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("Driver is null\n");
+               return -EFAULT;
        }
 
-       strWID.u16WIDid = (u16)WID_ASSOC_RES_INFO;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = pu8AssocRespInfo;
-       strWID.s32ValueSize = u32MaxAssocRespInfoLen;
-
+       wid.id = (u16)WID_ASSOC_RES_INFO;
+       wid.type = WID_STR;
+       wid.val = pu8AssocRespInfo;
+       wid.size = u32MaxAssocRespInfoLen;
 
-       /* Sending Configuration packet */
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
-               PRINT_ER("Failed to send association response config packet\n");
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+       if (result) {
                *pu32RcvdAssocRespInfoLen = 0;
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
+               PRINT_ER("Failed to send association response config packet\n");
+               return -EINVAL;
        } else {
-               *pu32RcvdAssocRespInfoLen = strWID.s32ValueSize;
+               *pu32RcvdAssocRespInfoLen = wid.size;
        }
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              gets a Association Response info
- *  @details    Valid only in STA mode. This function gives the RSSI
- *                              values observed in all the channels at the time of scanning.
- *                              The length of the field is 1 greater that the total number of
- *                              channels supported. Byte 0 contains the number of channels while
- *                              each of Byte N contains        the observed RSSI value for the channel index N.
- *  @param[in,out] handle to the wifi driver,
- *                              array of scanned channels' RSSI
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_get_rx_power_level(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8RxPowerLevel,
-                                       u32 u32RxPowerLevelLen)
+s32 host_int_get_rx_power_level(struct host_if_drv *hif_drv,
+                               u8 *pu8RxPowerLevel,
+                               u32 u32RxPowerLevelLen)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       /* tstrWILC_WFIDrv * pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv; */
+       struct wid wid;
 
-       strWID.u16WIDid = (u16)WID_RX_POWER_LEVEL;
-       strWID.enuWIDtype = WID_STR;
-       strWID.ps8WidVal = pu8RxPowerLevel;
-       strWID.s32ValueSize = u32RxPowerLevelLen;
+       wid.id = (u16)WID_RX_POWER_LEVEL;
+       wid.type = WID_STR;
+       wid.val = pu8RxPowerLevel;
+       wid.size = u32RxPowerLevelLen;
 
-
-       return s32Error;
+       return 0;
 }
 
-/**
- *  @brief              sets a channel
- *  @details
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Index of the channel to be set
- *|-------------------------------------------------------------------|
- |          CHANNEL1      CHANNEL2 ....                             CHANNEL14  |
- |  Input:         1             2                                                 14  |
- ||-------------------------------------------------------------------|
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_set_mac_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 u8ChNum)
+int host_int_set_mac_chnl_num(struct host_if_drv *hif_drv, u8 channel)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       /* prepare the set channel message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_CHANNEL;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFSetChan.u8SetChan = u8ChNum;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       int result;
+       struct host_if_msg msg;
 
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
-       return s32Error;
-}
-
-
-s32 host_int_wait_msg_queue_idle(void)
-{
-       s32 s32Error = WILC_SUCCESS;
-
-       tstrHostIFmsg strHostIFmsg;
-
-       /* prepare the set driver handler message */
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_Q_IDLE;
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_SET_CHANNEL;
+       msg.body.channel_info.set_ch = channel;
+       msg.drv = hif_drv;
 
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
+               PRINT_ER("wilc mq send fail\n");
+               return -EINVAL;
        }
 
-       /* wait untill MSG Q is empty */
-       down(&hWaitResponse);
-
-       return s32Error;
-
+       return 0;
 }
 
-s32 host_int_set_wfi_drv_handler(tstrWILC_WFIDrv *u32address)
+int host_int_wait_msg_queue_idle(void)
 {
-       s32 s32Error = WILC_SUCCESS;
-
-       tstrHostIFmsg strHostIFmsg;
-
-
-       /* prepare the set driver handler message */
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_WFIDRV_HANDLER;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfSetDrvHandler.u32Address = u32address;
-       /* strHostIFmsg.drvHandler=hWFIDrv; */
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       int result = 0;
+       struct host_if_msg msg;
 
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_Q_IDLE;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
+               PRINT_ER("wilc mq send fail\n");
+               result = -EINVAL;
        }
 
-       return s32Error;
-}
-
+       down(&hif_sema_wait_response);
 
+       return result;
+}
 
-s32 host_int_set_operation_mode(tstrWILC_WFIDrv *hWFIDrv, u32 u32mode)
+int host_int_set_wfi_drv_handler(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
-
-       tstrHostIFmsg strHostIFmsg;
-
+       int result = 0;
+       struct host_if_msg msg;
 
-       /* prepare the set driver handler message */
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_OPERATION_MODE;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfSetOperationMode.u32Mode = u32mode;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_SET_WFIDRV_HANDLER;
+       msg.body.drv.handler = get_id_from_handler(hif_drv);
+       msg.drv = hif_drv;
 
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
+               PRINT_ER("wilc mq send fail\n");
+               result = -EINVAL;
        }
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              gets the current channel index
- *  @details
- *  @param[in,out] handle to the wifi driver,
- *                              current channel index
- *|-----------------------------------------------------------------------|
- |          CHANNEL1      CHANNEL2 ....                     CHANNEL14  |
- |  Input:         1             2                                 14  |
- ||-----------------------------------------------------------------------|
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_get_host_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ChNo)
+int host_int_set_operation_mode(struct host_if_drv *hif_drv, u32 mode)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-       }
-
-       /* prepare the Get Channel Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       int result = 0;
+       struct host_if_msg msg;
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_CHNL;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_SET_OPERATION_MODE;
+       msg.body.mode.mode = mode;
+       msg.drv = hif_drv;
 
-       /* send the message */
-       s32Error =      WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               PRINT_ER("Failed to send get host channel param's message queue ");
-       down(&(pstrWFIDrv->hSemGetCHNL));
-       /* gu8Chnl = 11; */
-
-       *pu8ChNo = gu8Chnl;
-
-       WILC_CATCH(s32Error)
-       {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
+               PRINT_ER("wilc mq send fail\n");
+               result = -EINVAL;
        }
 
-       return s32Error;
-
-
+       return result;
 }
 
-
-/**
- *  @brief                       host_int_test_set_int_wid
- *  @details             Test function for setting wids
- *  @param[in,out]   WILC_WFIDrvHandle hWFIDrv, u32 u32TestMemAddr
- *  @return              Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_test_set_int_wid(tstrWILC_WFIDrv *hWFIDrv, u32 u32TestMemAddr)
+s32 host_int_get_host_chnl_num(struct host_if_drv *hif_drv, u8 *pu8ChNo)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
-       /*prepare configuration packet*/
-       strWID.u16WIDid = (u16)WID_MEMORY_ADDRESS;
-       strWID.enuWIDtype = WID_INT;
-       strWID.ps8WidVal = (char *)&u32TestMemAddr;
-       strWID.s32ValueSize = sizeof(u32);
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /*Sending Cfg*/
-       s32Error = SendConfigPkt(SET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       if (s32Error) {
-               PRINT_ER("Test Function: Failed to set wid value\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
-       } else {
-               PRINT_D(HOSTINF_DBG, "Successfully set wid value\n");
+       msg.id = HOST_IF_MSG_GET_CHNL;
+       msg.drv = hif_drv;
 
-       }
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc mq send fail\n");
+       down(&hif_drv->hSemGetCHNL);
 
-       WILC_CATCH(s32Error)
-       {
+       *pu8ChNo = ch_no;
 
-       }
-       return s32Error;
+       return result;
 }
 
-#ifdef WILC_AP_EXTERNAL_MLME
-/**
- *  @brief              host_int_get_inactive_time
- *  @details
- *  @param[in,out] handle to the wifi driver,
- *                              current sta macaddress, inactive_time
- *  @return
- *  @note
- *  @author
- *  @date
- *  @version           1.0
- */
-s32 host_int_get_inactive_time(tstrWILC_WFIDrv *hWFIDrv, const u8 *mac, u32 *pu32InactiveTime)
+s32 host_int_get_inactive_time(struct host_if_drv *hif_drv,
+                              const u8 *mac, u32 *pu32InactiveTime)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       memcpy(msg.body.mac_info.mac, mac, ETH_ALEN);
 
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIfStaInactiveT.mac,
-                   mac, ETH_ALEN);
+       msg.id = HOST_IF_MSG_GET_INACTIVETIME;
+       msg.drv = hif_drv;
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_INACTIVETIME;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
                PRINT_ER("Failed to send get host channel param's message queue ");
 
-       down(&(pstrWFIDrv->hSemInactiveTime));
-
-       *pu32InactiveTime = gu32InactiveTime;
+       down(&hif_drv->hSemInactiveTime);
 
-       WILC_CATCH(s32Error)
-       {
-       }
+       *pu32InactiveTime = inactive_time;
 
-       return s32Error;
+       return result;
 }
-#endif
-/**
- *  @brief              host_int_test_get_int_wid
- *  @details    Test function for getting wids
- *  @param[in,out] WILC_WFIDrvHandle hWFIDrv, u32* pu32TestMemAddr
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_test_get_int_wid(tstrWILC_WFIDrv *hWFIDrv, u32 *pu32TestMemAddr)
-{
-
-       s32 s32Error = WILC_SUCCESS;
-       tstrWID strWID;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
 
+s32 host_int_test_get_int_wid(struct host_if_drv *hif_drv, u32 *pu32TestMemAddr)
+{
+       s32 result = 0;
+       struct wid wid;
 
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
-       strWID.u16WIDid = (u16)WID_MEMORY_ADDRESS;
-       strWID.enuWIDtype = WID_INT;
-       strWID.ps8WidVal = (s8 *)pu32TestMemAddr;
-       strWID.s32ValueSize = sizeof(u32);
+       wid.id = (u16)WID_MEMORY_ADDRESS;
+       wid.type = WID_INT;
+       wid.val = (s8 *)pu32TestMemAddr;
+       wid.size = sizeof(u32);
 
-       s32Error = SendConfigPkt(GET_CFG, &strWID, 1, true, (u32)pstrWFIDrv);
-       /*get the value by searching the local copy*/
-       if (s32Error) {
-               PRINT_ER("Test Function: Failed to get wid value\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_STATE);
+       result = send_config_pkt(GET_CFG, &wid, 1,
+                                get_id_from_handler(hif_drv));
+
+       if (result) {
+               PRINT_ER("Failed to get wid value\n");
+               return -EINVAL;
        } else {
                PRINT_D(HOSTINF_DBG, "Successfully got wid value\n");
-
        }
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       return s32Error;
+       return result;
 }
 
-
-/**
- *  @brief              host_int_get_rssi
- *  @details    gets the currently maintained RSSI value for the station.
- *                              The received signal strength value in dB.
- *                              The range of valid values is -128 to 0.
- *  @param[in,out] handle to the wifi driver,
- *                              rssi value in dB
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_get_rssi(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8Rssi)
+s32 host_int_get_rssi(struct host_if_drv *hif_drv, s8 *ps8Rssi)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
+       s32 result = 0;
+       struct host_if_msg msg;
 
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_GET_RSSI;
+       msg.drv = hif_drv;
 
-       /* prepare the Get RSSI Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
                PRINT_ER("Failed to send get host channel param's message queue ");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
-       down(&(pstrWFIDrv->hSemGetRSSI));
-
+       down(&hif_drv->hSemGetRSSI);
 
-       if (ps8Rssi == NULL) {
+       if (!ps8Rssi) {
                PRINT_ER("RSS pointer value is null");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
+       *ps8Rssi = rssi;
 
-       *ps8Rssi = gs8Rssi;
-
-
-       return s32Error;
+       return result;
 }
 
-s32 host_int_get_link_speed(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8lnkspd)
+s32 host_int_get_link_speed(struct host_if_drv *hif_drv, s8 *ps8lnkspd)
 {
-       tstrHostIFmsg strHostIFmsg;
-       s32 s32Error = WILC_SUCCESS;
-
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
+       struct host_if_msg msg;
+       s32 result = 0;
 
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_GET_LINKSPEED;
+       msg.drv = hif_drv;
 
-
-       /* prepare the Get LINKSPEED Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_LINKSPEED;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
                PRINT_ER("Failed to send GET_LINKSPEED to message queue ");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
-       down(&(pstrWFIDrv->hSemGetLINKSPEED));
+       down(&hif_drv->hSemGetLINKSPEED);
 
-
-       if (ps8lnkspd == NULL) {
+       if (!ps8lnkspd) {
                PRINT_ER("LINKSPEED pointer value is null");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
+       *ps8lnkspd = link_speed;
 
-       *ps8lnkspd = gs8lnkspd;
-
-
-       return s32Error;
+       return result;
 }
 
-s32 host_int_get_statistics(tstrWILC_WFIDrv *hWFIDrv, tstrStatistics *pstrStatistics)
+s32 host_int_get_statistics(struct host_if_drv *hif_drv, struct rf_info *pstrStatistics)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_GET_STATISTICS;
+       msg.body.data = (char *)pstrStatistics;
+       msg.drv = hif_drv;
 
-       /* prepare the Get RSSI Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_STATISTICS;
-       strHostIFmsg.uniHostIFmsgBody.pUserData = (char *)pstrStatistics;
-       strHostIFmsg.drvHandler = hWFIDrv;
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
                PRINT_ER("Failed to send get host channel param's message queue ");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
-       down(&hWaitResponse);
-       return s32Error;
+       down(&hif_sema_wait_response);
+       return result;
 }
 
-
-/**
- *  @brief              host_int_scan
- *  @details    scans a set of channels
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Scan source
- *                              Scan Type      PASSIVE_SCAN = 0,
- *                                                      ACTIVE_SCAN  = 1
- *                              Channels Array
- *                              Channels Array length
- *                              Scan Callback function
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 host_int_scan(tstrWILC_WFIDrv *hWFIDrv, u8 u8ScanSource,
-                         u8 u8ScanType, u8 *pu8ChnlFreqList,
-                         u8 u8ChnlListLen, const u8 *pu8IEs,
-                         size_t IEsLen, tWILCpfScanResult ScanResult,
-                         void *pvUserArg, tstrHiddenNetwork  *pstrHiddenNetwork)
+s32 host_int_scan(struct host_if_drv *hif_drv, u8 u8ScanSource,
+                 u8 u8ScanType, u8 *pu8ChnlFreqList,
+                 u8 u8ChnlListLen, const u8 *pu8IEs,
+                 size_t IEsLen, wilc_scan_result ScanResult,
+                 void *pvUserArg, struct hidden_network *pstrHiddenNetwork)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tenuScanConnTimer enuScanConnTimer;
-
-       if (pstrWFIDrv == NULL || ScanResult == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       s32 result = 0;
+       struct host_if_msg msg;
 
+       if (!hif_drv || !ScanResult) {
+               PRINT_ER("hif_drv or ScanResult = NULL\n");
+               return -EFAULT;
+       }
 
-       /* prepare the Scan Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SCAN;
+       msg.id = HOST_IF_MSG_SCAN;
 
-       if (pstrHiddenNetwork != NULL) {
-               strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.strHiddenNetwork.pstrHiddenNetworkInfo = pstrHiddenNetwork->pstrHiddenNetworkInfo;
-               strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.strHiddenNetwork.u8ssidnum = pstrHiddenNetwork->u8ssidnum;
+       if (pstrHiddenNetwork) {
+               msg.body.scan_info.hidden_network.pstrHiddenNetworkInfo = pstrHiddenNetwork->pstrHiddenNetworkInfo;
+               msg.body.scan_info.hidden_network.u8ssidnum = pstrHiddenNetwork->u8ssidnum;
 
        } else
                PRINT_D(HOSTINF_DBG, "pstrHiddenNetwork IS EQUAL TO NULL\n");
 
-       strHostIFmsg.drvHandler = hWFIDrv;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ScanSource = u8ScanSource;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ScanType = u8ScanType;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pfScanResult = ScanResult;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pvUserArg = pvUserArg;
+       msg.drv = hif_drv;
+       msg.body.scan_info.src = u8ScanSource;
+       msg.body.scan_info.type = u8ScanType;
+       msg.body.scan_info.result = ScanResult;
+       msg.body.scan_info.arg = pvUserArg;
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.u8ChnlListLen = u8ChnlListLen;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList = WILC_MALLOC(u8ChnlListLen);        /* will be deallocated by the receiving thread */
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8ChnlFreqList,
-                   pu8ChnlFreqList, u8ChnlListLen);
+       msg.body.scan_info.ch_list_len = u8ChnlListLen;
+       msg.body.scan_info.ch_freq_list = kmalloc(u8ChnlListLen, GFP_KERNEL);
+       memcpy(msg.body.scan_info.ch_freq_list, pu8ChnlFreqList, u8ChnlListLen);
 
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.IEsLen = IEsLen;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs = WILC_MALLOC(IEsLen);        /* will be deallocated by the receiving thread */
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strHostIFscanAttr.pu8IEs,
-                   pu8IEs, IEsLen);
+       msg.body.scan_info.ies_len = IEsLen;
+       msg.body.scan_info.ies = kmalloc(IEsLen, GFP_KERNEL);
+       memcpy(msg.body.scan_info.ies, pu8IEs, IEsLen);
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error) {
-               PRINT_ER("Error in sending message queue scanning parameters: Error(%d)\n", s32Error);
-               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result) {
+               PRINT_ER("Error in sending message queue\n");
+               return -EINVAL;
        }
 
-       enuScanConnTimer = SCAN_TIMER;
        PRINT_D(HOSTINF_DBG, ">> Starting the SCAN timer\n");
-       pstrWFIDrv->hScanTimer.data = (unsigned long)hWFIDrv;
-       mod_timer(&pstrWFIDrv->hScanTimer,
+       hif_drv->hScanTimer.data = (unsigned long)hif_drv;
+       mod_timer(&hif_drv->hScanTimer,
                  jiffies + msecs_to_jiffies(HOST_IF_SCAN_TIMEOUT));
 
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       return s32Error;
-
+       return result;
 }
-/**
- *  @brief                      hif_set_cfg
- *  @details            sets configuration wids values
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] WID, WID value
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 hif_set_cfg(tstrWILC_WFIDrv *hWFIDrv, tstrCfgParamVal *pstrCfgParamVal)
-{
-
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-
-       tstrHostIFmsg strHostIFmsg;
-
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-       /* prepare the WiphyParams Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_CFG_PARAMS;
-       strHostIFmsg.uniHostIFmsgBody.strHostIFCfgParamAttr.pstrCfgParamVal = *pstrCfgParamVal;
-       strHostIFmsg.drvHandler = hWFIDrv;
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
+s32 hif_set_cfg(struct host_if_drv *hif_drv,
+               struct cfg_param_val *pstrCfgParamVal)
+{
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       WILC_CATCH(s32Error)
-       {
+       if (!hif_drv) {
+               PRINT_ER("hif_drv NULL\n");
+               return -EFAULT;
        }
 
-       return s32Error;
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_CFG_PARAMS;
+       msg.body.cfg_info.cfg_attr_info = *pstrCfgParamVal;
+       msg.drv = hif_drv;
 
-}
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
 
+       return result;
+}
 
-/**
- *  @brief              hif_get_cfg
- *  @details    gets configuration wids values
- *  @param[in,out] handle to the wifi driver,
- *                              WID value
- *  @param[in] WID,
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *
- *  @date              8 March 2012
- *  @version           1.0
- */
-s32 hif_get_cfg(tstrWILC_WFIDrv *hWFIDrv, u16 u16WID, u16 *pu16WID_Value)
+s32 hif_get_cfg(struct host_if_drv *hif_drv, u16 u16WID, u16 *pu16WID_Value)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
+       s32 result = 0;
 
-       down(&(pstrWFIDrv->gtOsCfgValuesSem));
+       down(&hif_drv->gtOsCfgValuesSem);
 
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("Driver not initialized: pstrWFIDrv = NULL\n");
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("hif_drv NULL\n");
+               return -EFAULT;
        }
        PRINT_D(HOSTINF_DBG, "Getting configuration parameters\n");
        switch (u16WID) {
-
        case WID_BSS_TYPE:
-               *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.bss_type;
+               *pu16WID_Value = (u16)hif_drv->strCfgValues.bss_type;
                break;
 
        case WID_AUTH_TYPE:
-               *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.auth_type;
+               *pu16WID_Value = (u16)hif_drv->strCfgValues.auth_type;
                break;
 
        case WID_AUTH_TIMEOUT:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.auth_timeout;
+               *pu16WID_Value = hif_drv->strCfgValues.auth_timeout;
                break;
 
        case WID_POWER_MANAGEMENT:
-               *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.power_mgmt_mode;
+               *pu16WID_Value = (u16)hif_drv->strCfgValues.power_mgmt_mode;
                break;
 
        case WID_SHORT_RETRY_LIMIT:
-               *pu16WID_Value =       pstrWFIDrv->strCfgValues.short_retry_limit;
+               *pu16WID_Value =       hif_drv->strCfgValues.short_retry_limit;
                break;
 
        case WID_LONG_RETRY_LIMIT:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.long_retry_limit;
+               *pu16WID_Value = hif_drv->strCfgValues.long_retry_limit;
                break;
 
        case WID_FRAG_THRESHOLD:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.frag_threshold;
+               *pu16WID_Value = hif_drv->strCfgValues.frag_threshold;
                break;
 
        case WID_RTS_THRESHOLD:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.rts_threshold;
+               *pu16WID_Value = hif_drv->strCfgValues.rts_threshold;
                break;
 
        case WID_PREAMBLE:
-               *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.preamble_type;
+               *pu16WID_Value = (u16)hif_drv->strCfgValues.preamble_type;
                break;
 
        case WID_SHORT_SLOT_ALLOWED:
-               *pu16WID_Value = (u16) pstrWFIDrv->strCfgValues.short_slot_allowed;
+               *pu16WID_Value = (u16) hif_drv->strCfgValues.short_slot_allowed;
                break;
 
        case WID_11N_TXOP_PROT_DISABLE:
-               *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.txop_prot_disabled;
+               *pu16WID_Value = (u16)hif_drv->strCfgValues.txop_prot_disabled;
                break;
 
        case WID_BEACON_INTERVAL:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.beacon_interval;
+               *pu16WID_Value = hif_drv->strCfgValues.beacon_interval;
                break;
 
        case WID_DTIM_PERIOD:
-               *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.dtim_period;
+               *pu16WID_Value = (u16)hif_drv->strCfgValues.dtim_period;
                break;
 
        case WID_SITE_SURVEY:
-               *pu16WID_Value = (u16)pstrWFIDrv->strCfgValues.site_survey_enabled;
+               *pu16WID_Value = (u16)hif_drv->strCfgValues.site_survey_enabled;
                break;
 
        case WID_SITE_SURVEY_SCAN_TIME:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.site_survey_scan_time;
+               *pu16WID_Value = hif_drv->strCfgValues.site_survey_scan_time;
                break;
 
        case WID_ACTIVE_SCAN_TIME:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.active_scan_time;
+               *pu16WID_Value = hif_drv->strCfgValues.active_scan_time;
                break;
 
        case WID_PASSIVE_SCAN_TIME:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.passive_scan_time;
+               *pu16WID_Value = hif_drv->strCfgValues.passive_scan_time;
                break;
 
        case WID_CURRENT_TX_RATE:
-               *pu16WID_Value = pstrWFIDrv->strCfgValues.curr_tx_rate;
+               *pu16WID_Value = hif_drv->strCfgValues.curr_tx_rate;
                break;
 
        default:
                break;
        }
 
-       up(&(pstrWFIDrv->gtOsCfgValuesSem));
+       up(&hif_drv->gtOsCfgValuesSem);
 
-       WILC_CATCH(s32Error)
-       {
-       }
-       return s32Error;
-
-}
-
-/*****************************************************************************/
-/*                                                     Notification Functions                                                   */
-/*****************************************************************************/
-/**
- *  @brief              notifies host with join and leave requests
- *  @details    This function prepares an Information frame having the
- *                              information about a joining/leaving station.
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] 6 byte Sta Adress
- *                              Join or leave flag:
- *                              Join = 1,
- *                              Leave =0
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-void host_int_send_join_leave_info_to_host
-       (u16 assocId, u8 *stationAddr, bool joining)
-{
+       return result;
 }
-/**
- *  @brief              notifies host with stations found in scan
- *  @details    sends the beacon/probe response from scan
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Sta Address,
- *                              Frame length,
- *                              Rssi of the Station found
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
 
 static void GetPeriodicRSSI(unsigned long arg)
 {
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)arg;
+       struct host_if_drv *hif_drv = (struct host_if_drv *)arg;
 
-       if (pstrWFIDrv == NULL) {
+       if (!hif_drv)   {
                PRINT_ER("Driver handler is NULL\n");
                return;
        }
 
-       if (pstrWFIDrv->enuHostIFstate == HOST_IF_CONNECTED) {
-               s32 s32Error = WILC_SUCCESS;
-               tstrHostIFmsg strHostIFmsg;
+       if (hif_drv->enuHostIFstate == HOST_IF_CONNECTED) {
+               s32 result = 0;
+               struct host_if_msg msg;
 
-               /* prepare the Get RSSI Message */
-               memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+               memset(&msg, 0, sizeof(struct host_if_msg));
 
-               strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_RSSI;
-               strHostIFmsg.drvHandler = pstrWFIDrv;
+               msg.id = HOST_IF_MSG_GET_RSSI;
+               msg.drv = hif_drv;
 
-               /* send the message */
-               s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-               if (s32Error) {
+               result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+               if (result) {
                        PRINT_ER("Failed to send get host channel param's message queue ");
                        return;
                }
        }
-       g_hPeriodicRSSI.data = (unsigned long)pstrWFIDrv;
-       mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
+       periodic_rssi.data = (unsigned long)hif_drv;
+       mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
 }
 
-
-void host_int_send_network_info_to_host
-       (u8 *macStartAddress, u16 u16RxFrameLen, s8 s8Rssi)
+s32 host_int_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
 {
-}
-/**
- *  @brief              host_int_init
- *  @details    host interface initialization function
- *  @param[in,out] handle to the wifi driver,
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-static u32 u32Intialized;
-static u32 msgQ_created;
-static u32 clients_count;
-
-s32 host_int_init(tstrWILC_WFIDrv **phWFIDrv)
-{
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv;
-
-       /*if(u32Intialized == 1)
-        * {
-        *      PRINT_D(HOSTINF_DBG,"Host interface is previously initialized\n");
-        * *phWFIDrv = (WILC_WFIDrvHandle)gWFiDrvHandle; //Will be adjusted later for P2P
-        *      return 0;
-        * }    */
-       PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1);
+       s32 result = 0;
+       struct host_if_drv *hif_drv;
+       int err;
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
 
-       gbScanWhileConnected = false;
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
-       sema_init(&hWaitResponse, 0);
+       PRINT_D(HOSTINF_DBG, "Initializing host interface for client %d\n", clients_count + 1);
 
+       scan_while_connected = false;
 
+       sema_init(&hif_sema_wait_response, 0);
 
-       /*Allocate host interface private structure*/
-       pstrWFIDrv  = WILC_MALLOC(sizeof(tstrWILC_WFIDrv));
-       if (pstrWFIDrv == NULL) {
-               /* WILC_ERRORREPORT(s32Error,WILC_NO_MEM); */
-               s32Error = WILC_NO_MEM;
-               PRINT_ER("Failed to allocate memory\n");
+       hif_drv  = kzalloc(sizeof(struct host_if_drv), GFP_KERNEL);
+       if (!hif_drv) {
+               result = -ENOMEM;
+               goto _fail_;
+       }
+       *hif_drv_handler = hif_drv;
+       err = add_handler_in_list(hif_drv);
+       if (err) {
+               result = -EFAULT;
                goto _fail_timer_2;
        }
-       memset(pstrWFIDrv, 0, sizeof(tstrWILC_WFIDrv));
-       /*return driver handle to user*/
-       *phWFIDrv = pstrWFIDrv;
-       /*save into globl handle*/
-
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 
        g_obtainingIP = false;
-       #endif
 
-       PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", pstrWFIDrv);
-       /* /////////////////////////////////////// */
+       PRINT_D(HOSTINF_DBG, "Global handle pointer value=%p\n", hif_drv);
        if (clients_count == 0) {
-               sema_init(&hSemHostIFthrdEnd, 0);
-               sema_init(&hSemDeinitDrvHandle, 0);
-               /*BugID_5348*/
-               sema_init(&hSemHostIntDeinit, 1);
+               sema_init(&hif_sema_thread, 0);
+               sema_init(&hif_sema_driver, 0);
+               sema_init(&hif_sema_deinit, 1);
        }
 
-       sema_init(&(pstrWFIDrv->hSemTestKeyBlock), 0);
-       sema_init(&(pstrWFIDrv->hSemTestDisconnectBlock), 0);
-       sema_init(&(pstrWFIDrv->hSemGetRSSI), 0);
-       sema_init(&(pstrWFIDrv->hSemGetLINKSPEED), 0);
-       sema_init(&(pstrWFIDrv->hSemGetCHNL), 0);
-       sema_init(&(pstrWFIDrv->hSemInactiveTime), 0);
-
-       /* /////////////////////////////////////// */
-
-
+       sema_init(&hif_drv->hSemTestKeyBlock, 0);
+       sema_init(&hif_drv->hSemTestDisconnectBlock, 0);
+       sema_init(&hif_drv->hSemGetRSSI, 0);
+       sema_init(&hif_drv->hSemGetLINKSPEED, 0);
+       sema_init(&hif_drv->hSemGetCHNL, 0);
+       sema_init(&hif_drv->hSemInactiveTime, 0);
 
        PRINT_D(HOSTINF_DBG, "INIT: CLIENT COUNT %d\n", clients_count);
 
        if (clients_count == 0) {
-               s32Error = WILC_MsgQueueCreate(&gMsgQHostIF);
+               result = wilc_mq_create(&hif_msg_q);
 
-               if (s32Error < 0) {
+               if (result < 0) {
                        PRINT_ER("Failed to creat MQ\n");
                        goto _fail_;
                }
-               msgQ_created = 1;
-               HostIFthreadHandler = kthread_run(hostIFthread, NULL, "WILC_kthread");
-               if (IS_ERR(HostIFthreadHandler)) {
+
+               hif_thread_handler = kthread_run(hostIFthread, wilc,
+                                                "WILC_kthread");
+
+               if (IS_ERR(hif_thread_handler)) {
                        PRINT_ER("Failed to creat Thread\n");
-                       s32Error = WILC_FAIL;
+                       result = -EFAULT;
                        goto _fail_mq_;
                }
-               setup_timer(&g_hPeriodicRSSI, GetPeriodicRSSI,
-                           (unsigned long)pstrWFIDrv);
-               mod_timer(&g_hPeriodicRSSI, jiffies + msecs_to_jiffies(5000));
+               setup_timer(&periodic_rssi, GetPeriodicRSSI,
+                           (unsigned long)hif_drv);
+               mod_timer(&periodic_rssi, jiffies + msecs_to_jiffies(5000));
        }
 
+       setup_timer(&hif_drv->hScanTimer, TimerCB_Scan, 0);
 
-       setup_timer(&pstrWFIDrv->hScanTimer, TimerCB_Scan, 0);
-
-       setup_timer(&pstrWFIDrv->hConnectTimer, TimerCB_Connect, 0);
+       setup_timer(&hif_drv->hConnectTimer, TimerCB_Connect, 0);
 
-       #ifdef WILC_P2P
-       /*Remain on channel timer*/
-       setup_timer(&pstrWFIDrv->hRemainOnChannel, ListenTimerCB, 0);
-       #endif
+       setup_timer(&hif_drv->hRemainOnChannel, ListenTimerCB, 0);
 
-       sema_init(&(pstrWFIDrv->gtOsCfgValuesSem), 1);
-       down(&(pstrWFIDrv->gtOsCfgValuesSem));
+       sema_init(&hif_drv->gtOsCfgValuesSem, 1);
+       down(&hif_drv->gtOsCfgValuesSem);
 
-       pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
-       /* gWFiDrvHandle->bPendingConnRequest = false; */
+       hif_drv->enuHostIFstate = HOST_IF_IDLE;
+       hif_drv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF;
+       hif_drv->strCfgValues.scan_source = DEFAULT_SCAN;
+       hif_drv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME;
+       hif_drv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME;
+       hif_drv->strCfgValues.curr_tx_rate = AUTORATE;
 
-       /*Initialize CFG WIDS Defualt Values*/
-
-       pstrWFIDrv->strCfgValues.site_survey_enabled = SITE_SURVEY_OFF;
-       pstrWFIDrv->strCfgValues.scan_source = DEFAULT_SCAN;
-       pstrWFIDrv->strCfgValues.active_scan_time = ACTIVE_SCAN_TIME;
-       pstrWFIDrv->strCfgValues.passive_scan_time = PASSIVE_SCAN_TIME;
-       pstrWFIDrv->strCfgValues.curr_tx_rate = AUTORATE;
-
-
-       #ifdef WILC_P2P
-
-       pstrWFIDrv->u64P2p_MgmtTimeout = 0;
-
-       #endif
+       hif_drv->u64P2p_MgmtTimeout = 0;
 
        PRINT_INFO(HOSTINF_DBG, "Initialization values, Site survey value: %d\n Scan source: %d\n Active scan time: %d\n Passive scan time: %d\nCurrent tx Rate = %d\n",
 
-                  pstrWFIDrv->strCfgValues.site_survey_enabled, pstrWFIDrv->strCfgValues.scan_source,
-                  pstrWFIDrv->strCfgValues.active_scan_time, pstrWFIDrv->strCfgValues.passive_scan_time,
-                  pstrWFIDrv->strCfgValues.curr_tx_rate);
-
+                  hif_drv->strCfgValues.site_survey_enabled, hif_drv->strCfgValues.scan_source,
+                  hif_drv->strCfgValues.active_scan_time, hif_drv->strCfgValues.passive_scan_time,
+                  hif_drv->strCfgValues.curr_tx_rate);
 
-       up(&(pstrWFIDrv->gtOsCfgValuesSem));
+       up(&hif_drv->gtOsCfgValuesSem);
 
-       /*TODO Code to setup simulation to be removed later*/
-       /*Intialize configurator module*/
-       s32Error = CoreConfiguratorInit();
-       if (s32Error < 0) {
-               PRINT_ER("Failed to initialize core configurator\n");
-               goto _fail_mem_;
-       }
-
-       u32Intialized = 1;
-       clients_count++; /* increase number of created entities */
-
-       return s32Error;
+       clients_count++;
 
+       return result;
 
-_fail_mem_:
-       if (pstrWFIDrv != NULL)
-               kfree(pstrWFIDrv);
-#ifdef WILC_P2P
-       del_timer_sync(&pstrWFIDrv->hRemainOnChannel);
-#endif
 _fail_timer_2:
-       up(&(pstrWFIDrv->gtOsCfgValuesSem));
-       del_timer_sync(&pstrWFIDrv->hConnectTimer);
-       del_timer_sync(&pstrWFIDrv->hScanTimer);
-       kthread_stop(HostIFthreadHandler);
+       up(&hif_drv->gtOsCfgValuesSem);
+       del_timer_sync(&hif_drv->hConnectTimer);
+       del_timer_sync(&hif_drv->hScanTimer);
+       kthread_stop(hif_thread_handler);
 _fail_mq_:
-       WILC_MsgQueueDestroy(&gMsgQHostIF);
+       wilc_mq_destroy(&hif_msg_q);
 _fail_:
-       return s32Error;
-
-
+       return result;
 }
-/**
- *  @brief              host_int_deinit
- *  @details    host interface initialization function
- *  @param[in,out] handle to the wifi driver,
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-
-s32 host_int_deinit(tstrWILC_WFIDrv *hWFIDrv)
-{
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
 
+s32 host_int_deinit(struct host_if_drv *hif_drv)
+{
+       s32 result = 0;
+       struct host_if_msg msg;
+       int ret;
 
-       /*obtain driver handle*/
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       /*if(u32Intialized == 0)
-        * {
-        *      PRINT_ER("Host Interface is not initialized\n");
-        *      return 0;
-        * }*/
-
-       /*BugID_5348*/
-
-       if (pstrWFIDrv == NULL) {
-               PRINT_ER("pstrWFIDrv = NULL\n");
+       if (!hif_drv)   {
+               PRINT_ER("hif_drv = NULL\n");
                return 0;
        }
 
-       down(&hSemHostIntDeinit);
+       down(&hif_sema_deinit);
 
-       terminated_handle = pstrWFIDrv;
+       terminated_handle = hif_drv;
        PRINT_D(HOSTINF_DBG, "De-initializing host interface for client %d\n", clients_count);
 
-       /*BugID_5348*/
-       /*Destroy all timers before acquiring hSemDeinitDrvHandle*/
-       /*to guarantee handling all messages befor proceeding*/
-       if (del_timer_sync(&pstrWFIDrv->hScanTimer)) {
+       if (del_timer_sync(&hif_drv->hScanTimer))
                PRINT_D(HOSTINF_DBG, ">> Scan timer is active\n");
-               /* msleep(HOST_IF_SCAN_TIMEOUT+1000); */
-       }
 
-       if (del_timer_sync(&pstrWFIDrv->hConnectTimer)) {
+       if (del_timer_sync(&hif_drv->hConnectTimer))
                PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
-               /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
-       }
-
 
-       if (del_timer_sync(&g_hPeriodicRSSI)) {
+       if (del_timer_sync(&periodic_rssi))
                PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
-               /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
-       }
 
-       #ifdef WILC_P2P
-       /*Destroy Remain-onchannel Timer*/
-       del_timer_sync(&pstrWFIDrv->hRemainOnChannel);
-       #endif
+       del_timer_sync(&hif_drv->hRemainOnChannel);
 
        host_int_set_wfi_drv_handler(NULL);
-       down(&hSemDeinitDrvHandle);
+       down(&hif_sema_driver);
 
+       if (hif_drv->usr_scan_req.pfUserScanResult) {
+               hif_drv->usr_scan_req.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
+                                                      hif_drv->usr_scan_req.u32UserScanPvoid, NULL);
 
-       /*Calling the CFG80211 scan done function with the abort flag set to true*/
-       if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
-               pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult(SCAN_EVENT_ABORTED, NULL,
-                                                               pstrWFIDrv->strWILC_UsrScanReq.u32UserScanPvoid, NULL);
-
-               pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult = NULL;
+               hif_drv->usr_scan_req.pfUserScanResult = NULL;
        }
-       /*deinit configurator and simulator*/
-       CoreConfiguratorDeInit();
 
-       pstrWFIDrv->enuHostIFstate = HOST_IF_IDLE;
+       hif_drv->enuHostIFstate = HOST_IF_IDLE;
 
-       gbScanWhileConnected = false;
+       scan_while_connected = false;
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
        if (clients_count == 1) {
-               if (del_timer_sync(&g_hPeriodicRSSI)) {
+               if (del_timer_sync(&periodic_rssi))
                        PRINT_D(HOSTINF_DBG, ">> Connect timer is active\n");
-                       /* msleep(HOST_IF_CONNECT_TIMEOUT+1000); */
-               }
-               strHostIFmsg.u16MsgId = HOST_IF_MSG_EXIT;
-               strHostIFmsg.drvHandler = hWFIDrv;
 
+               msg.id = HOST_IF_MSG_EXIT;
+               msg.drv = hif_drv;
 
-               s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-               if (s32Error != WILC_SUCCESS)
-                       PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", s32Error);
+               result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+               if (result != 0)
+                       PRINT_ER("Error in sending deinit's message queue message function: Error(%d)\n", result);
 
-               down(&hSemHostIFthrdEnd);
+               down(&hif_sema_thread);
 
-               WILC_MsgQueueDestroy(&gMsgQHostIF);
-               msgQ_created = 0;
+               wilc_mq_destroy(&hif_msg_q);
        }
 
-       down(&(pstrWFIDrv->gtOsCfgValuesSem));
+       down(&hif_drv->gtOsCfgValuesSem);
 
-       /*Setting the gloabl driver handler with NULL*/
-       u32Intialized = 0;
-       /* gWFiDrvHandle = NULL; */
-       if (pstrWFIDrv != NULL) {
-               kfree(pstrWFIDrv);
-               /* pstrWFIDrv=NULL; */
+       ret = remove_handler_in_list(hif_drv);
+       if (ret)
+               result = -ENOENT;
 
-       }
+       kfree(hif_drv);
 
-       clients_count--; /* Decrease number of created entities */
+       clients_count--;
        terminated_handle = NULL;
-       up(&hSemHostIntDeinit);
-       return s32Error;
+       up(&hif_sema_deinit);
+       return result;
 }
 
-
-/**
- *  @brief              NetworkInfoReceived
- *  @details    function to to be called when network info packet is received
- *  @param[in] pu8Buffer the received packet
- *  @param[in]   u32Length  length of the received packet
- *  @return             none
- *  @note
- *  @author
- *  @date              1 Mar 2012
- *  @version           1.0
- */
 void NetworkInfoReceived(u8 *pu8Buffer, u32 u32Length)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
-       u32 drvHandler;
-       tstrWILC_WFIDrv *pstrWFIDrv = NULL;
-
-       drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
-       pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
-
+       s32 result = 0;
+       struct host_if_msg msg;
+       int id;
+       struct host_if_drv *hif_drv = NULL;
 
+       id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
+       hif_drv = get_handler_from_id(id);
 
-
-       if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle)      {
-               PRINT_ER("NetworkInfo received but driver not init[%p]\n", pstrWFIDrv);
+       if (!hif_drv || hif_drv == terminated_handle)   {
+               PRINT_ER("NetworkInfo received but driver not init[%p]\n", hif_drv);
                return;
        }
 
-       /* prepare the Asynchronous Network Info message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_NTWRK_INFO;
-       strHostIFmsg.drvHandler = pstrWFIDrv;
+       msg.id = HOST_IF_MSG_RCVD_NTWRK_INFO;
+       msg.drv = hif_drv;
 
-       strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.u32Length = u32Length;
-       strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer = WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdNetworkInfo.pu8Buffer,
-                   pu8Buffer, u32Length);
+       msg.body.net_info.len = u32Length;
+       msg.body.net_info.buffer = kmalloc(u32Length, GFP_KERNEL);
+       memcpy(msg.body.net_info.buffer, pu8Buffer, u32Length);
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", s32Error);
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("Error in sending network info message queue message parameters: Error(%d)\n", result);
 }
 
-/**
- *  @brief              GnrlAsyncInfoReceived
- *  @details    function to be called when general Asynchronous info packet is received
- *  @param[in] pu8Buffer the received packet
- *  @param[in]   u32Length  length of the received packet
- *  @return             none
- *  @note
- *  @author
- *  @date              15 Mar 2012
- *  @version           1.0
- */
 void GnrlAsyncInfoReceived(u8 *pu8Buffer, u32 u32Length)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
-       u32 drvHandler;
-       tstrWILC_WFIDrv *pstrWFIDrv = NULL;
+       s32 result = 0;
+       struct host_if_msg msg;
+       int id;
+       struct host_if_drv *hif_drv = NULL;
 
-       /*BugID_5348*/
-       down(&hSemHostIntDeinit);
+       down(&hif_sema_deinit);
 
-       drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
-       pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
+       hif_drv = get_handler_from_id(id);
        PRINT_D(HOSTINF_DBG, "General asynchronous info packet received\n");
 
-
-       if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle) {
+       if (!hif_drv || hif_drv == terminated_handle) {
                PRINT_D(HOSTINF_DBG, "Wifi driver handler is equal to NULL\n");
-               /*BugID_5348*/
-               up(&hSemHostIntDeinit);
+               up(&hif_sema_deinit);
                return;
        }
 
-       if (pstrWFIDrv->strWILC_UsrConnReq.pfUserConnectResult == NULL) {
-               /* received mac status is not needed when there is no current Connect Request */
+       if (!hif_drv->usr_conn_req.pfUserConnectResult) {
                PRINT_ER("Received mac status is not needed when there is no current Connect Reques\n");
-               /*BugID_5348*/
-               up(&hSemHostIntDeinit);
+               up(&hif_sema_deinit);
                return;
        }
 
-       /* prepare the General Asynchronous Info message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
-       strHostIFmsg.drvHandler = pstrWFIDrv;
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
+       msg.id = HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO;
+       msg.drv = hif_drv;
 
-       strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.u32Length = u32Length;
-       strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer = WILC_MALLOC(u32Length); /* will be deallocated by the receiving thread */
-       memcpy(strHostIFmsg.uniHostIFmsgBody.strRcvdGnrlAsyncInfo.pu8Buffer,
-                   pu8Buffer, u32Length);
+       msg.body.async_info.len = u32Length;
+       msg.body.async_info.buffer = kmalloc(u32Length, GFP_KERNEL);
+       memcpy(msg.body.async_info.buffer, pu8Buffer, u32Length);
 
-       /* send the message */
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", s32Error);
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("Error in sending message queue asynchronous message info: Error(%d)\n", result);
 
-       /*BugID_5348*/
-       up(&hSemHostIntDeinit);
+       up(&hif_sema_deinit);
 }
 
-/**
- *  @brief host_int_ScanCompleteReceived
- *  @details        Setting scan complete received notifcation in message queue
- *  @param[in]     u8* pu8Buffer, u32 u32Length
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
 void host_int_ScanCompleteReceived(u8 *pu8Buffer, u32 u32Length)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrHostIFmsg strHostIFmsg;
-       u32 drvHandler;
-       tstrWILC_WFIDrv *pstrWFIDrv = NULL;
+       s32 result = 0;
+       struct host_if_msg msg;
+       int id;
+       struct host_if_drv *hif_drv = NULL;
 
-       drvHandler = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
-       pstrWFIDrv = (tstrWILC_WFIDrv *)drvHandler;
+       id = ((pu8Buffer[u32Length - 4]) | (pu8Buffer[u32Length - 3] << 8) | (pu8Buffer[u32Length - 2] << 16) | (pu8Buffer[u32Length - 1] << 24));
+       hif_drv = get_handler_from_id(id);
 
+       PRINT_D(GENERIC_DBG, "Scan notification received %p\n", hif_drv);
 
-       PRINT_D(GENERIC_DBG, "Scan notification received %p\n", pstrWFIDrv);
-
-       if (pstrWFIDrv == NULL || pstrWFIDrv == terminated_handle)
+       if (!hif_drv || hif_drv == terminated_handle)
                return;
 
-       /*if there is an ongoing scan request*/
-       if (pstrWFIDrv->strWILC_UsrScanReq.pfUserScanResult) {
-               /* prepare theScan Done message */
-               memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       if (hif_drv->usr_scan_req.pfUserScanResult) {
+               memset(&msg, 0, sizeof(struct host_if_msg));
 
-               strHostIFmsg.u16MsgId = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
-               strHostIFmsg.drvHandler = pstrWFIDrv;
+               msg.id = HOST_IF_MSG_RCVD_SCAN_COMPLETE;
+               msg.drv = hif_drv;
 
+               result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+               if (result)
+                       PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", result);
+       }
 
-               /* will be deallocated by the receiving thread */
-               /*no need to send message body*/
+       return;
+}
 
-               /*strHostIFmsg.uniHostIFmsgBody.strScanComplete.u32Length = u32Length;
-                * strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer  = (u8*)WILC_MALLOC(u32Length);
-                * memcpy(strHostIFmsg.uniHostIFmsgBody.strScanComplete.pu8Buffer,
-                *                        pu8Buffer, u32Length); */
+s32 host_int_remain_on_channel(struct host_if_drv *hif_drv, u32 u32SessionID,
+                              u32 u32duration, u16 chan,
+                              wilc_remain_on_chan_expired RemainOnChanExpired,
+                              wilc_remain_on_chan_ready RemainOnChanReady,
+                              void *pvUserArg)
+{
+       s32 result = 0;
+       struct host_if_msg msg;
 
-               /* send the message */
-               s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-               if (s32Error)
-                       PRINT_ER("Error in sending message queue scan complete parameters: Error(%d)\n", s32Error);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       return;
+       msg.id = HOST_IF_MSG_REMAIN_ON_CHAN;
+       msg.body.remain_on_ch.u16Channel = chan;
+       msg.body.remain_on_ch.pRemainOnChanExpired = RemainOnChanExpired;
+       msg.body.remain_on_ch.pRemainOnChanReady = RemainOnChanReady;
+       msg.body.remain_on_ch.pVoid = pvUserArg;
+       msg.body.remain_on_ch.u32duration = u32duration;
+       msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
+       msg.drv = hif_drv;
 
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc mq send fail\n");
+
+       return result;
 }
 
-#ifdef WILC_P2P
-/**
- *  @brief              host_int_remain_on_channel
- *  @details
- *  @param[in]          Handle to wifi driver
- *                              Duration to remain on channel
- *                              Channel to remain on
- *                              Pointer to fn to be called on receive frames in listen state
- *                              Pointer to remain-on-channel expired fn
- *                              Priv
- *  @return             Error code.
- *  @author
- *  @date
- *  @version           1.0
- */
-s32 host_int_remain_on_channel(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, tWILCpfRemainOnChanExpired RemainOnChanExpired, tWILCpfRemainOnChanReady RemainOnChanReady, void *pvUserArg)
+s32 host_int_ListenStateExpired(struct host_if_drv *hif_drv, u32 u32SessionID)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       /* prepare the remainonchan Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_REMAIN_ON_CHAN;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u16Channel = chan;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.pRemainOnChanExpired = RemainOnChanExpired;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.pRemainOnChanReady = RemainOnChanReady;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.pVoid = pvUserArg;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32duration = u32duration;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       s32 result = 0;
+       struct host_if_msg msg;
 
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
-       return s32Error;
-}
+       del_timer(&hif_drv->hRemainOnChannel);
 
-/**
- *  @brief              host_int_ListenStateExpired
- *  @details
- *  @param[in]          Handle to wifi driver
- *                              Duration to remain on channel
- *                              Channel to remain on
- *                              Pointer to fn to be called on receive frames in listen state
- *                              Pointer to remain-on-channel expired fn
- *                              Priv
- *  @return             Error code.
- *  @author
- *  @date
- *  @version           1.0
- */
-s32 host_int_ListenStateExpired(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID)
-{
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       /*Stopping remain-on-channel timer*/
-       del_timer(&pstrWFIDrv->hRemainOnChannel);
-
-       /* prepare the timer fire Message */
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_LISTEN_TIMER_FIRED;
-       strHostIFmsg.drvHandler = hWFIDrv;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRemainOnChan.u32ListenSessionID = u32SessionID;
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       memset(&msg, 0, sizeof(struct host_if_msg));
+       msg.id = HOST_IF_MSG_LISTEN_TIMER_FIRED;
+       msg.drv = hif_drv;
+       msg.body.remain_on_ch.u32ListenSessionID = u32SessionID;
 
-       }
-       return s32Error;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc mq send fail\n");
+
+       return result;
 }
 
-/**
- *  @brief              host_int_frame_register
- *  @details
- *  @param[in]          Handle to wifi driver
- *  @return             Error code.
- *  @author
- *  @date
- *  @version           1.0*/
-s32 host_int_frame_register(tstrWILC_WFIDrv *hWFIDrv, u16 u16FrameType, bool bReg)
+s32 host_int_frame_register(struct host_if_drv *hif_drv, u16 u16FrameType, bool bReg)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_REGISTER_FRAME;
+       msg.id = HOST_IF_MSG_REGISTER_FRAME;
        switch (u16FrameType) {
        case ACTION:
                PRINT_D(HOSTINF_DBG, "ACTION\n");
-               strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.u8Regid = ACTION_FRM_IDX;
+               msg.body.reg_frame.u8Regid = ACTION_FRM_IDX;
                break;
 
        case PROBE_REQ:
                PRINT_D(HOSTINF_DBG, "PROBE REQ\n");
-               strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.u8Regid = PROBE_REQ_IDX;
+               msg.body.reg_frame.u8Regid = PROBE_REQ_IDX;
                break;
 
        default:
                PRINT_D(HOSTINF_DBG, "Not valid frame type\n");
                break;
        }
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.u16FrameType = u16FrameType;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfRegisterFrame.bReg = bReg;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
-
-       }
-
-       return s32Error;
+       msg.body.reg_frame.u16FrameType = u16FrameType;
+       msg.body.reg_frame.bReg = bReg;
+       msg.drv = hif_drv;
 
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc mq send fail\n");
 
+       return result;
 }
-#endif
-
-#ifdef WILC_AP_EXTERNAL_MLME
-/**
- *  @brief host_int_add_beacon
- *  @details       Setting add beacon params in message queue
- *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,
- *                         u32 u32DTIMPeriod,u32 u32HeadLen, u8* pu8Head,
- *                         u32 u32TailLen, u8* pu8Tail
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 host_int_add_beacon(tstrWILC_WFIDrv *hWFIDrv, u32 u32Interval,
-                               u32 u32DTIMPeriod,
-                               u32 u32HeadLen, u8 *pu8Head,
-                               u32 u32TailLen, u8 *pu8Tail)
+
+s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval,
+                       u32 u32DTIMPeriod, u32 u32HeadLen, u8 *pu8Head,
+                       u32 u32TailLen, u8 *pu8Tail)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIFSetBeacon *pstrSetBeaconParam = &strHostIFmsg.uniHostIFmsgBody.strHostIFSetBeacon;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct beacon_attr *pstrSetBeaconParam = &msg.body.beacon_info;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
        PRINT_D(HOSTINF_DBG, "Setting adding beacon message queue params\n");
 
+       msg.id = HOST_IF_MSG_ADD_BEACON;
+       msg.drv = hif_drv;
+       pstrSetBeaconParam->interval = u32Interval;
+       pstrSetBeaconParam->dtim_period = u32DTIMPeriod;
+       pstrSetBeaconParam->head_len = u32HeadLen;
+       pstrSetBeaconParam->head = kmemdup(pu8Head, u32HeadLen, GFP_KERNEL);
+       if (!pstrSetBeaconParam->head) {
+               result = -ENOMEM;
+               goto ERRORHANDLER;
+       }
+       pstrSetBeaconParam->tail_len = u32TailLen;
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_BEACON;
-       strHostIFmsg.drvHandler = hWFIDrv;
-       pstrSetBeaconParam->u32Interval = u32Interval;
-       pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod;
-       pstrSetBeaconParam->u32HeadLen = u32HeadLen;
-       pstrSetBeaconParam->pu8Head = WILC_MALLOC(u32HeadLen);
-       if (pstrSetBeaconParam->pu8Head == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
-       memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
-       pstrSetBeaconParam->u32TailLen = u32TailLen;
-
-       /* Bug 4599 : if tail length = 0 skip allocating & copying */
        if (u32TailLen > 0) {
-               pstrSetBeaconParam->pu8Tail = WILC_MALLOC(u32TailLen);
-               if (pstrSetBeaconParam->pu8Tail == NULL)
-                       WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
-               memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
+               pstrSetBeaconParam->tail = kmemdup(pu8Tail, u32TailLen,
+                                                  GFP_KERNEL);
+               if (!pstrSetBeaconParam->tail) {
+                       result = -ENOMEM;
+                       goto ERRORHANDLER;
+               }
        } else {
-               pstrSetBeaconParam->pu8Tail = NULL;
+               pstrSetBeaconParam->tail = NULL;
        }
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc mq send fail\n");
 
-       WILC_CATCH(s32Error)
-       {
-               if (pstrSetBeaconParam->pu8Head != NULL)
-                       kfree(pstrSetBeaconParam->pu8Head);
+ERRORHANDLER:
+       if (result) {
+               kfree(pstrSetBeaconParam->head);
 
-               if (pstrSetBeaconParam->pu8Tail != NULL)
-                       kfree(pstrSetBeaconParam->pu8Tail);
+               kfree(pstrSetBeaconParam->tail);
        }
 
-       return s32Error;
-
+       return result;
 }
 
-
-/**
- *  @brief host_int_del_beacon
- *  @details       Setting add beacon params in message queue
- *  @param[in]    WILC_WFIDrvHandle hWFIDrv
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 host_int_del_beacon(tstrWILC_WFIDrv *hWFIDrv)
+s32 host_int_del_beacon(struct host_if_drv *hif_drv)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BEACON;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_DEL_BEACON;
+       msg.drv = hif_drv;
        PRINT_D(HOSTINF_DBG, "Setting deleting beacon message queue params\n");
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       WILC_ERRORCHECK(s32Error);
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
 
-       WILC_CATCH(s32Error)
-       {
-       }
-       return s32Error;
+       return result;
 }
 
-
-/**
- *  @brief host_int_add_station
- *  @details       Setting add station params in message queue
- *  @param[in]    WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam* pstrStaParams
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 host_int_add_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams)
+s32 host_int_add_station(struct host_if_drv *hif_drv,
+                        struct add_sta_param *pstrStaParams)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
 
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
        PRINT_D(HOSTINF_DBG, "Setting adding station message queue params\n");
 
+       msg.id = HOST_IF_MSG_ADD_STATION;
+       msg.drv = hif_drv;
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_STATION;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam));
+       memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
        if (pstrAddStationMsg->u8NumRates > 0) {
-               u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates);
+               u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
 
-               WILC_NULLCHECK(s32Error, rates);
+               if (!rates)
+                       return -ENOMEM;
 
                memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
                pstrAddStationMsg->pu8Rates = rates;
        }
 
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-
-       WILC_CATCH(s32Error)
-       {
-       }
-       return s32Error;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
+       return result;
 }
 
-/**
- *  @brief host_int_del_station
- *  @details       Setting delete station params in message queue
- *  @param[in]    WILC_WFIDrvHandle hWFIDrv, u8* pu8MacAddr
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 host_int_del_station(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8MacAddr)
+s32 host_int_del_station(struct host_if_drv *hif_drv, const u8 *pu8MacAddr)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIFDelSta *pstrDelStationMsg = &strHostIFmsg.uniHostIFmsgBody.strDelStaParam;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct del_sta *pstrDelStationMsg = &msg.body.del_sta_info;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
        PRINT_D(HOSTINF_DBG, "Setting deleting station message queue params\n");
 
+       msg.id = HOST_IF_MSG_DEL_STATION;
+       msg.drv = hif_drv;
 
-
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_STATION;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       /*BugID_4795: Handling situation of deleting all stations*/
-       if (pu8MacAddr == NULL)
-               memset(pstrDelStationMsg->au8MacAddr, 255, ETH_ALEN);
+       if (!pu8MacAddr)
+               eth_broadcast_addr(pstrDelStationMsg->mac_addr);
        else
-               memcpy(pstrDelStationMsg->au8MacAddr, pu8MacAddr, ETH_ALEN);
+               memcpy(pstrDelStationMsg->mac_addr, pu8MacAddr, ETH_ALEN);
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-
-       WILC_CATCH(s32Error)
-       {
-       }
-       return s32Error;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
+       return result;
 }
-/**
- *  @brief      host_int_del_allstation
- *  @details    Setting del station params in message queue
- *  @param[in]  WILC_WFIDrvHandle hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]s
- *  @return        Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 host_int_del_allstation(tstrWILC_WFIDrv *hWFIDrv, u8 pu8MacAddr[][ETH_ALEN])
+
+s32 host_int_del_allstation(struct host_if_drv *hif_drv,
+                           u8 pu8MacAddr[][ETH_ALEN])
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIFDelAllSta *pstrDelAllStationMsg = &strHostIFmsg.uniHostIFmsgBody.strHostIFDelAllSta;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct del_all_sta *pstrDelAllStationMsg = &msg.body.del_all_sta_info;
        u8 au8Zero_Buff[ETH_ALEN] = {0};
        u32 i;
        u8 u8AssocNumb = 0;
 
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
        PRINT_D(HOSTINF_DBG, "Setting deauthenticating station message queue params\n");
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_ALL_STA;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_DEL_ALL_STA;
+       msg.drv = hif_drv;
 
-       /* Handling situation of deauthenticing all associated stations*/
        for (i = 0; i < MAX_NUM_STA; i++) {
                if (memcmp(pu8MacAddr[i], au8Zero_Buff, ETH_ALEN)) {
-                       memcpy(pstrDelAllStationMsg->au8Sta_DelAllSta[i], pu8MacAddr[i], ETH_ALEN);
-                       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],
-                               pstrDelAllStationMsg->au8Sta_DelAllSta[i][5]);
+                       memcpy(pstrDelAllStationMsg->del_all_sta[i], pu8MacAddr[i], ETH_ALEN);
+                       PRINT_D(CFG80211_DBG, "BSSID = %x%x%x%x%x%x\n",
+                               pstrDelAllStationMsg->del_all_sta[i][0],
+                               pstrDelAllStationMsg->del_all_sta[i][1],
+                               pstrDelAllStationMsg->del_all_sta[i][2],
+                               pstrDelAllStationMsg->del_all_sta[i][3],
+                               pstrDelAllStationMsg->del_all_sta[i][4],
+                               pstrDelAllStationMsg->del_all_sta[i][5]);
                        u8AssocNumb++;
                }
        }
        if (!u8AssocNumb) {
                PRINT_D(CFG80211_DBG, "NO ASSOCIATED STAS\n");
-               return s32Error;
+               return result;
        }
 
-       pstrDelAllStationMsg->u8Num_AssocSta = u8AssocNumb;
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
+       pstrDelAllStationMsg->assoc_sta = u8AssocNumb;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
 
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
 
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-
-       WILC_CATCH(s32Error)
-       {
-
-       }
-       down(&hWaitResponse);
-
-       return s32Error;
+       down(&hif_sema_wait_response);
 
+       return result;
 }
 
-/**
- *  @brief host_int_edit_station
- *  @details       Setting edit station params in message queue
- *  @param[in]    WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam* pstrStaParams
- *  @return         Error code.
- *  @author
- *  @date
- *  @version   1.0
- */
-s32 host_int_edit_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams)
+s32 host_int_edit_station(struct host_if_drv *hif_drv,
+                         struct add_sta_param *pstrStaParams)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrWILC_AddStaParam *pstrAddStationMsg = &strHostIFmsg.uniHostIFmsgBody.strAddStaParam;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct add_sta_param *pstrAddStationMsg = &msg.body.add_sta_info;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
        PRINT_D(HOSTINF_DBG, "Setting editing station message queue params\n");
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_EDIT_STATION;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_EDIT_STATION;
+       msg.drv = hif_drv;
 
-       memcpy(pstrAddStationMsg, pstrStaParams, sizeof(tstrWILC_AddStaParam));
+       memcpy(pstrAddStationMsg, pstrStaParams, sizeof(struct add_sta_param));
        if (pstrAddStationMsg->u8NumRates > 0) {
-               u8 *rates = WILC_MALLOC(pstrAddStationMsg->u8NumRates);
+               u8 *rates = kmalloc(pstrAddStationMsg->u8NumRates, GFP_KERNEL);
+
+               if (!rates)
+                       return -ENOMEM;
 
-               WILC_NULLCHECK(s32Error, rates);
                memcpy(rates, pstrStaParams->pu8Rates, pstrAddStationMsg->u8NumRates);
                pstrAddStationMsg->pu8Rates = rates;
        }
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
-       }
-       return s32Error;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
+
+       return result;
 }
-#endif /*WILC_AP_EXTERNAL_MLME*/
-uint32_t wilc_get_chipid(uint8_t);
 
-s32 host_int_set_power_mgmt(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32Timeout)
+s32 host_int_set_power_mgmt(struct host_if_drv *hif_drv,
+                           bool bIsEnabled,
+                           u32 u32Timeout)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIfPowerMgmtParam *pstrPowerMgmtParam = &strHostIFmsg.uniHostIFmsgBody.strPowerMgmtparam;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct power_mgmt_param *pstrPowerMgmtParam = &msg.body.pwr_mgmt_info;
 
        PRINT_INFO(HOSTINF_DBG, "\n\n>> Setting PS to %d <<\n\n", bIsEnabled);
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
        PRINT_D(HOSTINF_DBG, "Setting Power management message queue params\n");
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_POWER_MGMT;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_POWER_MGMT;
+       msg.drv = hif_drv;
 
-       pstrPowerMgmtParam->bIsEnabled = bIsEnabled;
-       pstrPowerMgmtParam->u32Timeout = u32Timeout;
+       pstrPowerMgmtParam->enabled = bIsEnabled;
+       pstrPowerMgmtParam->timeout = u32Timeout;
 
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
-       }
-       return s32Error;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
+       return result;
 }
 
-s32 host_int_setup_multicast_filter(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32count)
+s32 host_int_setup_multicast_filter(struct host_if_drv *hif_drv,
+                                   bool bIsEnabled,
+                                   u32 u32count)
 {
-       s32 s32Error = WILC_SUCCESS;
-
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIFSetMulti *pstrMulticastFilterParam = &strHostIFmsg.uniHostIFmsgBody.strHostIfSetMulti;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct set_multicast *pstrMulticastFilterParam = &msg.body.multicast_info;
 
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
        PRINT_D(HOSTINF_DBG, "Setting Multicast Filter params\n");
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_MULTICAST_FILTER;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.id = HOST_IF_MSG_SET_MULTICAST_FILTER;
+       msg.drv = hif_drv;
 
-       pstrMulticastFilterParam->bIsEnabled = bIsEnabled;
-       pstrMulticastFilterParam->u32count = u32count;
+       pstrMulticastFilterParam->enabled = bIsEnabled;
+       pstrMulticastFilterParam->cnt = u32count;
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
-       }
-       return s32Error;
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
+       return result;
 }
 
-
-
-/*Bug4218: Parsing Join Param*/
-#ifdef WILC_PARSE_SCAN_IN_HOST
-
-/*Bug4218: Parsing Join Param*/
-/**
- *  @brief              host_int_ParseJoinBssParam
- *  @details            Parse Needed Join Parameters and save it in a new JoinBssParam entry
- *  @param[in]          tstrNetworkInfo* ptstrNetworkInfo
- *  @return
- *  @author            zsalah
- *  @date
- *  @version           1.0**/
 static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
 {
-       tstrJoinBssParam *pNewJoinBssParam = NULL;
+       struct join_bss_param *pNewJoinBssParam = NULL;
        u8 *pu8IEs;
        u16 u16IEsLen;
        u16 index = 0;
@@ -7451,388 +4747,259 @@ static void *host_int_ParseJoinBssParam(tstrNetworkInfo *ptstrNetworkInfo)
        pu8IEs = ptstrNetworkInfo->pu8IEs;
        u16IEsLen = ptstrNetworkInfo->u16IEsLen;
 
-       pNewJoinBssParam = WILC_MALLOC(sizeof(tstrJoinBssParam));
-       if (pNewJoinBssParam != NULL) {
-               memset(pNewJoinBssParam, 0, sizeof(tstrJoinBssParam));
+       pNewJoinBssParam = kzalloc(sizeof(struct join_bss_param), GFP_KERNEL);
+       if (pNewJoinBssParam) {
                pNewJoinBssParam->dtim_period = ptstrNetworkInfo->u8DtimPeriod;
                pNewJoinBssParam->beacon_period = ptstrNetworkInfo->u16BeaconPeriod;
                pNewJoinBssParam->cap_info = ptstrNetworkInfo->u16CapInfo;
                memcpy(pNewJoinBssParam->au8bssid, ptstrNetworkInfo->au8bssid, 6);
-               /*for(i=0; i<6;i++)
-                *      PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->au8bssid[i]);*/
                memcpy((u8 *)pNewJoinBssParam->ssid, ptstrNetworkInfo->au8ssid, ptstrNetworkInfo->u8SsidLen + 1);
-               pNewJoinBssParam->ssidLen = ptstrNetworkInfo->u8SsidLen;
+               pNewJoinBssParam->ssid_len = ptstrNetworkInfo->u8SsidLen;
                memset(pNewJoinBssParam->rsn_pcip_policy, 0xFF, 3);
                memset(pNewJoinBssParam->rsn_auth_policy, 0xFF, 3);
-               /*for(i=0; i<pNewJoinBssParam->ssidLen;i++)
-                *      PRINT_D(HOSTINF_DBG,"%c",pNewJoinBssParam->ssid[i]);*/
 
-               /* parse supported rates: */
                while (index < u16IEsLen) {
-                       /* supportedRates IE */
                        if (pu8IEs[index] == SUPP_RATES_IE) {
-                               /* PRINT_D(HOSTINF_DBG, "Supported Rates\n"); */
                                suppRatesNo = pu8IEs[index + 1];
                                pNewJoinBssParam->supp_rates[0] = suppRatesNo;
-                               index += 2; /* skipping ID and length bytes; */
+                               index += 2;
 
-                               for (i = 0; i < suppRatesNo; i++) {
+                               for (i = 0; i < suppRatesNo; i++)
                                        pNewJoinBssParam->supp_rates[i + 1] = pu8IEs[index + i];
-                                       /* PRINT_D(HOSTINF_DBG,"%0x ",pNewJoinBssParam->supp_rates[i+1]); */
-                               }
+
                                index += suppRatesNo;
                                continue;
-                       }
-                       /* Ext SupportedRates IE */
-                       else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
-                               /* PRINT_D(HOSTINF_DBG, "Extended Supported Rates\n"); */
-                               /* checking if no of ext. supp and supp rates < max limit */
+                       } else if (pu8IEs[index] == EXT_SUPP_RATES_IE) {
                                extSuppRatesNo = pu8IEs[index + 1];
                                if (extSuppRatesNo > (MAX_RATES_SUPPORTED - suppRatesNo))
                                        pNewJoinBssParam->supp_rates[0] = MAX_RATES_SUPPORTED;
                                else
                                        pNewJoinBssParam->supp_rates[0] += extSuppRatesNo;
                                index += 2;
-                               /* pNewJoinBssParam.supp_rates[0] contains now old number not the ext. no */
-                               for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++) {
+                               for (i = 0; i < (pNewJoinBssParam->supp_rates[0] - suppRatesNo); i++)
                                        pNewJoinBssParam->supp_rates[suppRatesNo + i + 1] = pu8IEs[index + i];
-                                       /* PRINT_D(HOSTINF_DBG,"%0x ",pNewJoinBssParam->supp_rates[suppRatesNo+i+1]); */
-                               }
+
                                index += extSuppRatesNo;
                                continue;
-                       }
-                       /* HT Cap. IE */
-                       else if (pu8IEs[index] == HT_CAPABILITY_IE) {
-                               /* if IE found set the flag */
+                       } else if (pu8IEs[index] == HT_CAPABILITY_IE) {
                                pNewJoinBssParam->ht_capable = true;
-                               index += pu8IEs[index + 1] + 2; /* ID,Length bytes and IE body */
-                               /* PRINT_D(HOSTINF_DBG,"HT_CAPABALE\n"); */
+                               index += pu8IEs[index + 1] + 2;
                                continue;
-                       } else if ((pu8IEs[index] == WMM_IE) && /* WMM Element ID */
+                       } else if ((pu8IEs[index] == WMM_IE) &&
                                   (pu8IEs[index + 2] == 0x00) && (pu8IEs[index + 3] == 0x50) &&
-                                  (pu8IEs[index + 4] == 0xF2) && /* OUI */
-                                  (pu8IEs[index + 5] == 0x02) && /* OUI Type     */
-                                  ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) && /* OUI Sub Type */
+                                  (pu8IEs[index + 4] == 0xF2) &&
+                                  (pu8IEs[index + 5] == 0x02) &&
+                                  ((pu8IEs[index + 6] == 0x00) || (pu8IEs[index + 6] == 0x01)) &&
                                   (pu8IEs[index + 7] == 0x01)) {
-                               /* Presence of WMM Info/Param element indicates WMM capability */
                                pNewJoinBssParam->wmm_cap = true;
 
-                               /* Check if Bit 7 is set indicating U-APSD capability */
-                               if (pu8IEs[index + 8] & (1 << 7))
+                               if (pu8IEs[index + 8] & BIT(7))
                                        pNewJoinBssParam->uapsd_cap = true;
                                index += pu8IEs[index + 1] + 2;
                                continue;
-                       }
-                       #ifdef WILC_P2P
-                       else if ((pu8IEs[index] == P2P_IE) && /* P2P Element ID */
+                       } else if ((pu8IEs[index] == P2P_IE) &&
                                 (pu8IEs[index + 2] == 0x50) && (pu8IEs[index + 3] == 0x6f) &&
-                                (pu8IEs[index + 4] == 0x9a) && /* OUI */
-                                (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) { /* OUI Type     */
+                                (pu8IEs[index + 4] == 0x9a) &&
+                                (pu8IEs[index + 5] == 0x09) && (pu8IEs[index + 6] == 0x0c)) {
                                u16 u16P2P_count;
 
                                pNewJoinBssParam->tsf = ptstrNetworkInfo->u32Tsf;
-                               pNewJoinBssParam->u8NoaEnbaled = 1;
-                               pNewJoinBssParam->u8Index = pu8IEs[index + 9];
-
-                               /* Check if Bit 7 is set indicating Opss capability */
-                               if (pu8IEs[index + 10] & (1 << 7)) {
-                                       pNewJoinBssParam->u8OppEnable = 1;
-                                       pNewJoinBssParam->u8CtWindow = pu8IEs[index + 10];
-                               } else
-                                       pNewJoinBssParam->u8OppEnable = 0;
-                               /* HOSTINF_DBG */
+                               pNewJoinBssParam->noa_enabled = 1;
+                               pNewJoinBssParam->idx = pu8IEs[index + 9];
+
+                               if (pu8IEs[index + 10] & BIT(7)) {
+                                       pNewJoinBssParam->opp_enabled = 1;
+                                       pNewJoinBssParam->ct_window = pu8IEs[index + 10];
+                               } else {
+                                       pNewJoinBssParam->opp_enabled = 0;
+                               }
+
                                PRINT_D(GENERIC_DBG, "P2P Dump\n");
                                for (i = 0; i < pu8IEs[index + 7]; i++)
                                        PRINT_D(GENERIC_DBG, " %x\n", pu8IEs[index + 9 + i]);
 
-                               pNewJoinBssParam->u8Count = pu8IEs[index + 11];
+                               pNewJoinBssParam->cnt = pu8IEs[index + 11];
                                u16P2P_count = index + 12;
 
-                               memcpy(pNewJoinBssParam->au8Duration, pu8IEs + u16P2P_count, 4);
+                               memcpy(pNewJoinBssParam->duration, pu8IEs + u16P2P_count, 4);
                                u16P2P_count += 4;
 
-                               memcpy(pNewJoinBssParam->au8Interval, pu8IEs + u16P2P_count, 4);
+                               memcpy(pNewJoinBssParam->interval, pu8IEs + u16P2P_count, 4);
                                u16P2P_count += 4;
 
-                               memcpy(pNewJoinBssParam->au8StartTime, pu8IEs + u16P2P_count, 4);
+                               memcpy(pNewJoinBssParam->start_time, pu8IEs + u16P2P_count, 4);
 
                                index += pu8IEs[index + 1] + 2;
                                continue;
 
-                       }
-                       #endif
-                       else if ((pu8IEs[index] == RSN_IE) ||
+                       } else if ((pu8IEs[index] == RSN_IE) ||
                                 ((pu8IEs[index] == WPA_IE) && (pu8IEs[index + 2] == 0x00) &&
                                  (pu8IEs[index + 3] == 0x50) && (pu8IEs[index + 4] == 0xF2) &&
                                  (pu8IEs[index + 5] == 0x01))) {
                                u16 rsnIndex = index;
-                               /*PRINT_D(HOSTINF_DBG,"RSN IE Length:%d\n",pu8IEs[rsnIndex+1]);
-                                * for(i=0; i<pu8IEs[rsnIndex+1]; i++)
-                                * {
-                                *      PRINT_D(HOSTINF_DBG,"%0x ",pu8IEs[rsnIndex+2+i]);
-                                * }*/
+
                                if (pu8IEs[rsnIndex] == RSN_IE) {
                                        pNewJoinBssParam->mode_802_11i = 2;
-                                       /* PRINT_D(HOSTINF_DBG,"\nRSN_IE\n"); */
-                               } else { /* check if rsn was previously parsed */
+                               } else {
                                        if (pNewJoinBssParam->mode_802_11i == 0)
                                                pNewJoinBssParam->mode_802_11i = 1;
-                                       /* PRINT_D(HOSTINF_DBG,"\nWPA_IE\n"); */
                                        rsnIndex += 4;
                                }
-                               rsnIndex += 7; /* skipping id, length, version(2B) and first 3 bytes of gcipher */
+
+                               rsnIndex += 7;
                                pNewJoinBssParam->rsn_grp_policy = pu8IEs[rsnIndex];
                                rsnIndex++;
-                               /* PRINT_D(HOSTINF_DBG,"Group Policy: %0x\n",pNewJoinBssParam->rsn_grp_policy); */
-                               /* initialize policies with invalid values */
-
-                               jumpOffset = pu8IEs[rsnIndex] * 4; /* total no.of bytes of pcipher field (count*4) */
-
-                               /*parsing pairwise cipher*/
-
-                               /* saving 3 pcipher max. */
+                               jumpOffset = pu8IEs[rsnIndex] * 4;
                                pcipherCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
-                               rsnIndex += 2; /* jump 2 bytes of pcipher count */
+                               rsnIndex += 2;
 
-                               /* PRINT_D(HOSTINF_DBG,"\npcipher:%d\n",pcipherCount); */
-                               for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++) {
-                                       /* each count corresponds to 4 bytes, only last byte is saved */
+                               for (i = pcipherTotalCount, j = 0; i < pcipherCount + pcipherTotalCount && i < 3; i++, j++)
                                        pNewJoinBssParam->rsn_pcip_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
-                                       /* PRINT_D(HOSTINF_DBG,"PAIR policy = [%0x,%0x]\n",pNewJoinBssParam->rsn_pcip_policy[i],i); */
-                               }
+
                                pcipherTotalCount += pcipherCount;
                                rsnIndex += jumpOffset;
 
                                jumpOffset = pu8IEs[rsnIndex] * 4;
 
-                               /*parsing AKM suite (auth_policy)*/
-                               /* saving 3 auth policies max. */
                                authCount = (pu8IEs[rsnIndex] > 3) ? 3 : pu8IEs[rsnIndex];
-                               rsnIndex += 2; /* jump 2 bytes of pcipher count */
+                               rsnIndex += 2;
 
-                               for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++) {
-                                       /* each count corresponds to 4 bytes, only last byte is saved */
+                               for (i = authTotalCount, j = 0; i < authTotalCount + authCount; i++, j++)
                                        pNewJoinBssParam->rsn_auth_policy[i] = pu8IEs[rsnIndex + ((j + 1) * 4) - 1];
-                               }
+
                                authTotalCount += authCount;
                                rsnIndex += jumpOffset;
-                               /*pasring rsn cap. only if rsn IE*/
+
                                if (pu8IEs[index] == RSN_IE) {
                                        pNewJoinBssParam->rsn_cap[0] = pu8IEs[rsnIndex];
                                        pNewJoinBssParam->rsn_cap[1] = pu8IEs[rsnIndex + 1];
                                        rsnIndex += 2;
                                }
                                pNewJoinBssParam->rsn_found = true;
-                               index += pu8IEs[index + 1] + 2; /* ID,Length bytes and IE body */
+                               index += pu8IEs[index + 1] + 2;
                                continue;
                        } else
-                               index += pu8IEs[index + 1] + 2;  /* ID,Length bytes and IE body */
-
+                               index += pu8IEs[index + 1] + 2;
                }
-
-
        }
 
        return (void *)pNewJoinBssParam;
-
 }
 
 void host_int_freeJoinParams(void *pJoinParams)
 {
-       if ((tstrJoinBssParam *)pJoinParams != NULL)
-               kfree((tstrJoinBssParam *)pJoinParams);
+       if ((struct bss_param *)pJoinParams)
+               kfree((struct bss_param *)pJoinParams);
        else
                PRINT_ER("Unable to FREE null pointer\n");
 }
-#endif  /*WILC_PARSE_SCAN_IN_HOST*/
 
-
-/**
- *  @brief              host_int_addBASession
- *  @details            Open a block Ack session with the given parameters
- *  @param[in]          tstrNetworkInfo* ptstrNetworkInfo
- *  @return
- *  @author            anoureldin
- *  @date
- *  @version           1.0**/
-
-static int host_int_addBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID, short int BufferSize,
-                                short int SessionTimeout, void *drvHandler)
+s32 host_int_delBASession(struct host_if_drv *hif_drv, char *pBSSID, char TID)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
-
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_ADD_BA_SESSION;
-
-       memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
-       pBASessionInfo->u8Ted = TID;
-       pBASessionInfo->u16BufferSize = BufferSize;
-       pBASessionInfo->u16SessionTimeout = SessionTimeout;
-       strHostIFmsg.drvHandler = hWFIDrv;
-
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct ba_session_info *pBASessionInfo = &msg.body.session_info;
 
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
        }
 
-       return s32Error;
-}
-
-
-s32 host_int_delBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID)
-{
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_BA_SESSION;
+       msg.id = HOST_IF_MSG_DEL_BA_SESSION;
 
        memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
        pBASessionInfo->u8Ted = TID;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.drv = hif_drv;
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
 
-       }
-
-       /*BugID_5222*/
-       down(&hWaitResponse);
+       down(&hif_sema_wait_response);
 
-       return s32Error;
+       return result;
 }
 
-s32 host_int_del_All_Rx_BASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID)
+s32 host_int_del_All_Rx_BASession(struct host_if_drv *hif_drv,
+                                 char *pBSSID,
+                                 char TID)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
-       tstrHostIfBASessionInfo *pBASessionInfo = &strHostIFmsg.uniHostIFmsgBody.strHostIfBASessionInfo;
+       s32 result = 0;
+       struct host_if_msg msg;
+       struct ba_session_info *pBASessionInfo = &msg.body.session_info;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
+       msg.id = HOST_IF_MSG_DEL_ALL_RX_BA_SESSIONS;
 
        memcpy(pBASessionInfo->au8Bssid, pBSSID, ETH_ALEN);
        pBASessionInfo->u8Ted = TID;
-       strHostIFmsg.drvHandler = hWFIDrv;
+       msg.drv = hif_drv;
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
-
-       }
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
 
-       /*BugID_5222*/
-       down(&hWaitResponse);
+       down(&hif_sema_wait_response);
 
-       return s32Error;
+       return result;
 }
 
-/**
- *  @brief              host_int_setup_ipaddress
- *  @details            setup IP in firmware
- *  @param[in]          Handle to wifi driver
- *  @return             Error code.
- *  @author            Abdelrahman Sobhy
- *  @date
- *  @version           1.0*/
-s32 host_int_setup_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *u16ipadd, u8 idx)
+s32 host_int_setup_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       /* TODO: Enable This feature on softap firmware */
        return 0;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_SET_IPADDRESS;
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr = u16ipadd;
-       strHostIFmsg.drvHandler = hWFIDrv;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx = idx;
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       }
+       msg.id = HOST_IF_MSG_SET_IPADDRESS;
 
-       return s32Error;
+       msg.body.ip_info.ip_addr = u16ipadd;
+       msg.drv = hif_drv;
+       msg.body.ip_info.idx = idx;
 
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
 
+       return result;
 }
 
-/**
- *  @brief              host_int_get_ipaddress
- *  @details            Get IP from firmware
- *  @param[in]          Handle to wifi driver
- *  @return             Error code.
- *  @author            Abdelrahman Sobhy
- *  @date
- *  @version           1.0*/
-s32 host_int_get_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *u16ipadd, u8 idx)
+s32 host_int_get_ipaddress(struct host_if_drv *hif_drv, u8 *u16ipadd, u8 idx)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv = (tstrWILC_WFIDrv *)hWFIDrv;
-       tstrHostIFmsg strHostIFmsg;
+       s32 result = 0;
+       struct host_if_msg msg;
 
-       if (pstrWFIDrv == NULL)
-               WILC_ERRORREPORT(s32Error, WILC_INVALID_ARGUMENT);
-
-       memset(&strHostIFmsg, 0, sizeof(tstrHostIFmsg));
-
-       /* prepare the WiphyParams Message */
-       strHostIFmsg.u16MsgId = HOST_IF_MSG_GET_IPADDRESS;
-
-       strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.au8IPAddr = u16ipadd;
-       strHostIFmsg.drvHandler = hWFIDrv;
-       strHostIFmsg.uniHostIFmsgBody.strHostIfSetIP.idx = idx;
+       if (!hif_drv) {
+               PRINT_ER("driver is null\n");
+               return -EFAULT;
+       }
 
-       s32Error = WILC_MsgQueueSend(&gMsgQHostIF, &strHostIFmsg, sizeof(tstrHostIFmsg));
-       if (s32Error)
-               WILC_ERRORREPORT(s32Error, s32Error);
-       WILC_CATCH(s32Error)
-       {
+       memset(&msg, 0, sizeof(struct host_if_msg));
 
-       }
+       msg.id = HOST_IF_MSG_GET_IPADDRESS;
 
-       return s32Error;
+       msg.body.ip_info.ip_addr = u16ipadd;
+       msg.drv = hif_drv;
+       msg.body.ip_info.idx = idx;
 
+       result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+       if (result)
+               PRINT_ER("wilc_mq_send fail\n");
 
+       return result;
 }
index e66dee9af5da6b2529889f5505f0cb49b2814836..b854db5ac932cb859f3e8e455aa01d0c90719cc9 100644 (file)
 #define HOST_INT_H
 
 #include "coreconfigurator.h"
-/*****************************************************************************/
-/*                                                             Macros                                       */
-/*****************************************************************************/
-#define FAIL           0x0000
-#define SUCCESS                0x0001
 
 #define IP_ALEN  4
 
-#define BIT2                    ((u32)(1 << 2))
-#define BIT1                    ((u32)(1 << 1))
-#define BIT0                    ((u32)(1 << 0))
-
+#define IDLE_MODE      0x00
 #define AP_MODE                0x01
 #define STATION_MODE   0x02
-#define GO_MODE        0x03
+#define GO_MODE                0x03
 #define CLIENT_MODE    0x04
 
 
-#define MAX_NUM_STA                 9
+#define MAX_NUM_STA                            9
 #define ACTIVE_SCAN_TIME                       10
 #define PASSIVE_SCAN_TIME                      1200
 #define MIN_SCAN_TIME                          10
 #define MAX_SCAN_TIME                          1200
 #define DEFAULT_SCAN                           0
-#define USER_SCAN                                      BIT0
-#define OBSS_PERIODIC_SCAN                     BIT1
-#define OBSS_ONETIME_SCAN                      BIT2
+#define USER_SCAN                              BIT(0)
+#define OBSS_PERIODIC_SCAN                     BIT(1)
+#define OBSS_ONETIME_SCAN                      BIT(2)
 #define GTK_RX_KEY_BUFF_LEN                    24
-#define ADDKEY                                         0x1
-#define REMOVEKEY                                      0x2
-#define DEFAULTKEY                                     0x4
-#define ADDKEY_AP                                      0x8
-#define MAX_NUM_SCANNED_NETWORKS       100 /* 30               // rachel */
-#define MAX_NUM_SCANNED_NETWORKS_SHADOW        130
-#define MAX_NUM_PROBED_SSID            10  /*One more than the number of scanned ssids*/
-#define CHANNEL_SCAN_TIME                      250 /* 250 */
+#define ADDKEY                                 0x1
+#define REMOVEKEY                              0x2
+#define DEFAULTKEY                             0x4
+#define ADDKEY_AP                              0x8
+#define MAX_NUM_SCANNED_NETWORKS               100
+#define MAX_NUM_SCANNED_NETWORKS_SHADOW                130
+#define MAX_NUM_PROBED_SSID                    10
+#define CHANNEL_SCAN_TIME                      250
 
 #define TX_MIC_KEY_LEN                         8
 #define RX_MIC_KEY_LEN                         8
-#define PTK_KEY_LEN                                    16
+#define PTK_KEY_LEN                            16
 
 #define TX_MIC_KEY_MSG_LEN                     26
 #define RX_MIC_KEY_MSG_LEN                     48
 #define PTK_KEY_MSG_LEN                                39
 
 #define PMKSA_KEY_LEN                          22
-#define ETH_ALEN  6
-#define PMKID_LEN                                      16
-#define WILC_MAX_NUM_PMKIDS  16
-#define WILC_SUPP_MCS_SET_SIZE 16
-#define WILC_ADD_STA_LENGTH    40 /* Not including the rates field cause it has variable length*/
+#define ETH_ALEN                               6
+#define PMKID_LEN                              16
+#define WILC_MAX_NUM_PMKIDS                    16
+#define WILC_SUPP_MCS_SET_SIZE                 16
+#define WILC_ADD_STA_LENGTH                    40
 #define SCAN_EVENT_DONE_ABORTED
-/*****************************************************************************/
-/* Data Types                                                                */
-/*****************************************************************************/
-/* typedef unsigned char       uint8; */
-/* typedef signed char     int8; */
-/* typedef unsigned short      uint16; */
-/* typedef unsigned long   uint32; */
-/* typedef uint32   Bool; */
-
-typedef struct {
-       u16 cfg_wid;
-       WID_TYPE_T cfg_type;
-       s8     *pu8Para;
-} cfg_param_t;
-
-typedef struct _tstrStatistics {
+#define NUM_CONCURRENT_IFC                     2
+
+struct rf_info {
        u8 u8LinkSpeed;
        s8 s8RSSI;
        u32 u32TxCount;
        u32 u32RxCount;
        u32 u32TxFailureCount;
+};
 
-} tstrStatistics;
-
-
-typedef enum {
-       HOST_IF_IDLE                                    = 0,
-       HOST_IF_SCANNING                                = 1,
-       HOST_IF_CONNECTING                              = 2,
-       HOST_IF_WAITING_CONN_RESP               = 3,
-       HOST_IF_CONNECTED                               = 4,
-       HOST_IF_P2P_LISTEN                              = 5,
-       HOST_IF_FORCE_32BIT                     = 0xFFFFFFFF
-} tenuHostIFstate;
+enum host_if_state {
+       HOST_IF_IDLE                    = 0,
+       HOST_IF_SCANNING                = 1,
+       HOST_IF_CONNECTING              = 2,
+       HOST_IF_WAITING_CONN_RESP       = 3,
+       HOST_IF_CONNECTED               = 4,
+       HOST_IF_P2P_LISTEN              = 5,
+       HOST_IF_FORCE_32BIT             = 0xFFFFFFFF
+};
 
-typedef struct _tstrHostIFpmkid {
+struct host_if_pmkid {
        u8 bssid[ETH_ALEN];
        u8 pmkid[PMKID_LEN];
-} tstrHostIFpmkid;
+};
 
-typedef struct _tstrHostIFpmkidAttr {
+struct host_if_pmkid_attr {
        u8 numpmkid;
-       tstrHostIFpmkid pmkidlist[WILC_MAX_NUM_PMKIDS];
-} tstrHostIFpmkidAttr;
-
-typedef enum {
-       AUTORATE         = 0,
-       MBPS_1       = 1,
-       MBPS_2       = 2,
-       MBPS_5_5             = 5,
-       MBPS_11      = 11,
-       MBPS_6       = 6,
-       MBPS_9       = 9,
-       MBPS_12      = 12,
-       MBPS_18      = 18,
-       MBPS_24      = 24,
-       MBPS_36      = 36,
-       MBPS_48      = 48,
-       MBPS_54      = 54
-} CURRENT_TX_RATE_T;
-
-typedef struct {
-       u32 u32SetCfgFlag;
+       struct host_if_pmkid pmkidlist[WILC_MAX_NUM_PMKIDS];
+};
+
+enum CURRENT_TXRATE {
+       AUTORATE        = 0,
+       MBPS_1          = 1,
+       MBPS_2          = 2,
+       MBPS_5_5        = 5,
+       MBPS_11         = 11,
+       MBPS_6          = 6,
+       MBPS_9          = 9,
+       MBPS_12         = 12,
+       MBPS_18         = 18,
+       MBPS_24         = 24,
+       MBPS_36         = 36,
+       MBPS_48         = 48,
+       MBPS_54         = 54
+};
+
+struct cfg_param_val {
+       u32 flag;
        u8 ht_enable;
        u8 bss_type;
        u8 auth_type;
@@ -140,84 +117,79 @@ typedef struct {
        u8 txop_prot_disabled;
        u16 beacon_interval;
        u16 dtim_period;
-       SITE_SURVEY_T site_survey_enabled;
+       enum SITESURVEY site_survey_enabled;
        u16 site_survey_scan_time;
        u8 scan_source;
        u16 active_scan_time;
        u16 passive_scan_time;
-       CURRENT_TX_RATE_T curr_tx_rate;
-
-} tstrCfgParamVal;
-
-typedef enum {
-       RETRY_SHORT             = 1 << 0,
-       RETRY_LONG              = 1 << 1,
-       FRAG_THRESHOLD  = 1 << 2,
-       RTS_THRESHOLD   = 1 << 3,
-       BSS_TYPE  = 1 << 4,
-       AUTH_TYPE = 1 << 5,
-       AUTHEN_TIMEOUT = 1 << 6,
-       POWER_MANAGEMENT = 1 << 7,
-       PREAMBLE = 1 << 8,
-       SHORT_SLOT_ALLOWED = 1 << 9,
-       TXOP_PROT_DISABLE = 1 << 10,
-       BEACON_INTERVAL = 1 << 11,
-       DTIM_PERIOD = 1 << 12,
-       SITE_SURVEY = 1 << 13,
-       SITE_SURVEY_SCAN_TIME = 1 << 14,
-       ACTIVE_SCANTIME = 1 << 15,
-       PASSIVE_SCANTIME = 1 << 16,
-       CURRENT_TX_RATE = 1 << 17,
-       HT_ENABLE = 1 << 18,
-} tenuCfgParam;
-
-typedef struct {
+       enum CURRENT_TXRATE curr_tx_rate;
+
+};
+
+enum cfg_param {
+       RETRY_SHORT             = BIT(0),
+       RETRY_LONG              = BIT(1),
+       FRAG_THRESHOLD          = BIT(2),
+       RTS_THRESHOLD           = BIT(3),
+       BSS_TYPE                = BIT(4),
+       AUTH_TYPE               = BIT(5),
+       AUTHEN_TIMEOUT          = BIT(6),
+       POWER_MANAGEMENT        = BIT(7),
+       PREAMBLE                = BIT(8),
+       SHORT_SLOT_ALLOWED      = BIT(9),
+       TXOP_PROT_DISABLE       = BIT(10),
+       BEACON_INTERVAL         = BIT(11),
+       DTIM_PERIOD             = BIT(12),
+       SITE_SURVEY             = BIT(13),
+       SITE_SURVEY_SCAN_TIME   = BIT(14),
+       ACTIVE_SCANTIME         = BIT(15),
+       PASSIVE_SCANTIME        = BIT(16),
+       CURRENT_TX_RATE         = BIT(17),
+       HT_ENABLE               = BIT(18),
+};
+
+struct found_net_info {
        u8 au8bssid[6];
        s8 s8rssi;
-} tstrFoundNetworkInfo;
+};
 
-typedef enum {SCAN_EVENT_NETWORK_FOUND  = 0,
-             SCAN_EVENT_DONE = 1,
-             SCAN_EVENT_ABORTED = 2,
-             SCAN_EVENT_FORCE_32BIT  = 0xFFFFFFFF} tenuScanEvent;
+enum scan_event {
+       SCAN_EVENT_NETWORK_FOUND        = 0,
+       SCAN_EVENT_DONE                 = 1,
+       SCAN_EVENT_ABORTED              = 2,
+       SCAN_EVENT_FORCE_32BIT          = 0xFFFFFFFF
+};
 
-typedef enum {
+enum conn_event {
        CONN_DISCONN_EVENT_CONN_RESP            = 0,
        CONN_DISCONN_EVENT_DISCONN_NOTIF        = 1,
-       CONN_DISCONN_EVENT_FORCE_32BIT   = 0xFFFFFFFF
-} tenuConnDisconnEvent;
+       CONN_DISCONN_EVENT_FORCE_32BIT          = 0xFFFFFFFF
+};
 
-typedef enum {
+enum KEY_TYPE {
        WEP,
        WPARxGtk,
-       /* WPATxGtk, */
        WPAPtk,
        PMKSA,
-} tenuKeyType;
+};
 
 
 /*Scan callBack function definition*/
-typedef void (*tWILCpfScanResult)(tenuScanEvent, tstrNetworkInfo *, void *, void *);
+typedef void (*wilc_scan_result)(enum scan_event, tstrNetworkInfo *,
+                                 void *, void *);
 
 /*Connect callBack function definition*/
-typedef void (*tWILCpfConnectResult)(tenuConnDisconnEvent,
+typedef void (*wilc_connect_result)(enum conn_event,
                                     tstrConnectInfo *,
                                     u8,
                                     tstrDisconnectNotifInfo *,
                                     void *);
 
-#ifdef WILC_P2P
-typedef void (*tWILCpfRemainOnChanExpired)(void *, u32);  /*Remain on channel expiration callback function*/
-typedef void (*tWILCpfRemainOnChanReady)(void *); /*Remain on channel callback function*/
-#endif
-
-/* typedef u32 WILC_WFIDrvHandle; */
-typedef struct {
-       s32 s32Dummy;
-} *WILC_WFIDrvHandle;
+typedef void (*wilc_remain_on_chan_expired)(void *, u32);  /*Remain on channel expiration callback function*/
+typedef void (*wilc_remain_on_chan_ready)(void *); /*Remain on channel callback function*/
 
 /*!
- *  @struct             tstrRcvdNetworkInfo
+ *  @struct             rcvd_net_info
  *  @brief             Structure to hold Received Asynchronous Network info
  *  @details
  *  @todo
@@ -226,102 +198,91 @@ typedef struct {
  *  @date              25 March 2012
  *  @version           1.0
  */
-typedef struct _tstrRcvdNetworkInfo {
-       u8 *pu8Buffer;
-       u32 u32Length;
-} tstrRcvdNetworkInfo;
+struct rcvd_net_info {
+       u8 *buffer;
+       u32 len;
+};
 
-/*BugID_4156*/
-typedef struct _tstrHiddenNetworkInfo {
+struct hidden_net_info {
        u8  *pu8ssid;
        u8 u8ssidlen;
+};
 
-} tstrHiddenNetworkInfo;
-
-typedef struct _tstrHiddenNetwork {
-       /* MAX_SSID_LEN */
-       tstrHiddenNetworkInfo *pstrHiddenNetworkInfo;
+struct hidden_network {
+       struct hidden_net_info *pstrHiddenNetworkInfo;
        u8 u8ssidnum;
+};
 
-} tstrHiddenNetwork;
-
-typedef struct {
+struct user_scan_req {
        /* Scan user call back function */
-       tWILCpfScanResult pfUserScanResult;
+       wilc_scan_result pfUserScanResult;
 
        /* User specific parameter to be delivered through the Scan User Callback function */
        void *u32UserScanPvoid;
 
        u32 u32RcvdChCount;
-       tstrFoundNetworkInfo astrFoundNetworkInfo[MAX_NUM_SCANNED_NETWORKS];
-} tstrWILC_UsrScanReq;
+       struct found_net_info astrFoundNetworkInfo[MAX_NUM_SCANNED_NETWORKS];
+};
 
-typedef struct {
+struct user_conn_req {
        u8 *pu8bssid;
        u8 *pu8ssid;
        u8 u8security;
-       AUTHTYPE_T tenuAuth_type;
+       enum AUTHTYPE tenuAuth_type;
        size_t ssidLen;
        u8 *pu8ConnReqIEs;
        size_t ConnReqIEsLen;
        /* Connect user call back function */
-       tWILCpfConnectResult pfUserConnectResult;
+       wilc_connect_result pfUserConnectResult;
        bool IsHTCapable;
        /* User specific parameter to be delivered through the Connect User Callback function */
        void *u32UserConnectPvoid;
-} tstrWILC_UsrConnReq;
+};
 
-typedef struct {
-       u32 u32Address;
-} tstrHostIfSetDrvHandler;
+struct drv_handler {
+       u32 handler;
+};
 
-typedef struct {
-       u32 u32Mode;
-} tstrHostIfSetOperationMode;
+struct op_mode {
+       u32 mode;
+};
 
-/*BugID_5077*/
-typedef struct {
-       u8 u8MacAddress[ETH_ALEN];
-} tstrHostIfSetMacAddress;
+struct set_mac_addr {
+       u8 mac_addr[ETH_ALEN];
+};
 
-/*BugID_5213*/
-typedef struct {
-       u8 *u8MacAddress;
-} tstrHostIfGetMacAddress;
+struct get_mac_addr {
+       u8 *mac_addr;
+};
 
-/*BugID_5222*/
-typedef struct {
+struct ba_session_info {
        u8 au8Bssid[ETH_ALEN];
        u8 u8Ted;
        u16 u16BufferSize;
        u16 u16SessionTimeout;
-} tstrHostIfBASessionInfo;
+};
 
-#ifdef WILC_P2P
-typedef struct {
+struct remain_ch {
        u16 u16Channel;
        u32 u32duration;
-       tWILCpfRemainOnChanExpired pRemainOnChanExpired;
-       tWILCpfRemainOnChanReady pRemainOnChanReady;
+       wilc_remain_on_chan_expired pRemainOnChanExpired;
+       wilc_remain_on_chan_ready pRemainOnChanReady;
        void *pVoid;
        u32 u32ListenSessionID;
-} tstrHostIfRemainOnChan;
-
-typedef struct {
+};
 
+struct reg_frame {
        bool bReg;
        u16 u16FrameType;
        u8 u8Regid;
+};
 
 
-} tstrHostIfRegisterFrame;
-
-
-#define   ACTION         0xD0
-#define   PROBE_REQ   0x40
-#define   PROBE_RESP  0x50
-#define   ACTION_FRM_IDX   0
-#define   PROBE_REQ_IDX     1
+#define ACTION                 0xD0
+#define PROBE_REQ              0x40
+#define PROBE_RESP             0x50
+#define ACTION_FRM_IDX         0
+#define PROBE_REQ_IDX          1
 
 
 enum p2p_listen_state {
@@ -330,33 +291,18 @@ enum p2p_listen_state {
        P2P_GRP_FORMATION
 };
 
-#endif
-typedef struct {
-       /* Scan user structure */
-       tstrWILC_UsrScanReq strWILC_UsrScanReq;
-
-       /* Connect User structure */
-       tstrWILC_UsrConnReq strWILC_UsrConnReq;
-
-       #ifdef WILC_P2P
-       /*Remain on channel struvture*/
-       tstrHostIfRemainOnChan strHostIfRemainOnChan;
-       u8 u8RemainOnChan_pendingreq;
+struct host_if_drv {
+       struct user_scan_req usr_scan_req;
+       struct user_conn_req usr_conn_req;
+       struct remain_ch remain_on_ch;
+       u8 remain_on_ch_pending;
        u64 u64P2p_MgmtTimeout;
        u8 u8P2PConnect;
-       #endif
 
-       tenuHostIFstate enuHostIFstate;
-
-       /* bool bPendingConnRequest; */
-
-       #ifndef CONNECT_DIRECT
-       u32 u32SurveyResultsCount;
-       wid_site_survey_reslts_s astrSurveyResults[MAX_NUM_SCANNED_NETWORKS];
-       #endif
+       enum host_if_state enuHostIFstate;
 
        u8 au8AssociatedBSSID[ETH_ALEN];
-       tstrCfgParamVal strCfgValues;
+       struct cfg_param_val strCfgValues;
 /* semaphores */
        struct semaphore gtOsCfgValuesSem;
        struct semaphore hSemTestKeyBlock;
@@ -369,34 +315,12 @@ typedef struct {
 /* timer handlers */
        struct timer_list hScanTimer;
        struct timer_list hConnectTimer;
-       #ifdef WILC_P2P
        struct timer_list hRemainOnChannel;
-       #endif
 
        bool IFC_UP;
-} tstrWILC_WFIDrv;
-
-/*!
- *  @enum               tenuWILC_StaFlag
- *  @brief                     Used to decode the station flag set and mask in tstrWILC_AddStaParam
- *  @details
- *  @todo
- *  @sa                        tstrWILC_AddStaParam, enum nl80211_sta_flags
- *  @author            Enumeraion's creator
- *  @date                      12 July 2012
- *  @version           1.0 Description
- */
-
-typedef enum {
-       WILC_STA_FLAG_INVALID = 0,
-       WILC_STA_FLAG_AUTHORIZED,                       /*!<  station is authorized (802.1X)*/
-       WILC_STA_FLAG_SHORT_PREAMBLE,   /*!< station is capable of receiving frames     with short barker preamble*/
-       WILC_STA_FLAG_WME,                              /*!< station is WME/QoS capable*/
-       WILC_STA_FLAG_MFP,                                      /*!< station uses management frame protection*/
-       WILC_STA_FLAG_AUTHENTICATED             /*!< station is authenticated*/
-} tenuWILC_StaFlag;
+};
 
-typedef struct {
+struct add_sta_param {
        u8 au8BSSID[ETH_ALEN];
        u16 u16AssocID;
        u8 u8NumRates;
@@ -410,9 +334,7 @@ typedef struct {
        u8 u8ASELCap;
        u16 u16FlagsMask;               /*<! Determines which of u16FlagsSet were changed>*/
        u16 u16FlagsSet;                /*<! Decoded according to tenuWILC_StaFlag */
-} tstrWILC_AddStaParam;
-
-/* extern void CfgDisconnected(void* pUserVoid, u16 u16reason, u8 * ie, size_t ie_len); */
+};
 
 /*****************************************************************************/
 /*                                                                                                                                                      */
@@ -432,7 +354,7 @@ typedef struct {
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_remove_key(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8StaAddress);
+s32 host_int_remove_key(struct host_if_drv *hWFIDrv, const u8 *pu8StaAddress);
 /**
  *  @brief              removes WEP key
  *  @details    valid only in BSS STA mode if External Supplicant support is enabled.
@@ -447,7 +369,7 @@ s32 host_int_remove_key(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8StaAddress);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_remove_wep_key(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index);
+int host_int_remove_wep_key(struct host_if_drv *wfi_drv, u8 index);
 /**
  *  @brief              sets WEP deafault key
  *  @details    Sets the index of the WEP encryption key in use,
@@ -460,7 +382,7 @@ s32 host_int_remove_wep_key(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_set_WEPDefaultKeyID(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index);
+int host_int_set_wep_default_key(struct host_if_drv *hif_drv, u8 index);
 
 /**
  *  @brief              sets WEP deafault key
@@ -481,7 +403,8 @@ s32 host_int_set_WEPDefaultKeyID(tstrWILC_WFIDrv *hWFIDrv, u8 u8Index);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_add_wep_key_bss_sta(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx);
+int host_int_add_wep_key_bss_sta(struct host_if_drv *hif_drv,
+                                const u8 *key, u8 len, u8 index);
 /**
  *  @brief              host_int_add_wep_key_bss_ap
  *  @details    valid only in AP mode if External Supplicant support is enabled.
@@ -496,7 +419,9 @@ s32 host_int_add_wep_key_bss_sta(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey,
  *  @date              28 Feb 2013
  *  @version           1.0
  */
-s32 host_int_add_wep_key_bss_ap(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u8 u8WepKeylen, u8 u8Keyidx, u8 u8mode, AUTHTYPE_T tenuAuth_type);
+int host_int_add_wep_key_bss_ap(struct host_if_drv *hif_drv,
+                               const u8 *key, u8 len, u8 index, u8 mode,
+                               enum AUTHTYPE auth_type);
 
 /**
  *  @brief              adds ptk Key
@@ -514,7 +439,7 @@ s32 host_int_add_wep_key_bss_ap(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8WepKey, u
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_add_ptk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen,
+s32 host_int_add_ptk(struct host_if_drv *hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen,
                             const u8 *mac_addr, const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode, u8 u8Idx);
 
 /**
@@ -529,7 +454,7 @@ s32 host_int_add_ptk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8Ptk, u8 u8PtkKeylen,
  *  @date              15 April 2013
  *  @version           1.0
  */
-s32 host_int_get_inactive_time(tstrWILC_WFIDrv *hWFIDrv, const u8 *mac, u32 *pu32InactiveTime);
+s32 host_int_get_inactive_time(struct host_if_drv *hWFIDrv, const u8 *mac, u32 *pu32InactiveTime);
 
 /**
  *  @brief              adds Rx GTk Key
@@ -547,7 +472,7 @@ s32 host_int_get_inactive_time(tstrWILC_WFIDrv *hWFIDrv, const u8 *mac, u32 *pu3
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_add_rx_gtk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen,
+s32 host_int_add_rx_gtk(struct host_if_drv *hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKeylen,
                                u8 u8KeyIdx, u32 u32KeyRSClen, const u8 *KeyRSC,
                                const u8 *pu8RxMic, const u8 *pu8TxMic, u8 mode, u8 u8Ciphermode);
 
@@ -568,7 +493,7 @@ s32 host_int_add_rx_gtk(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8RxGtk, u8 u8GtkKe
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_add_tx_gtk(tstrWILC_WFIDrv *hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8 u8KeyIdx);
+s32 host_int_add_tx_gtk(struct host_if_drv *hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8 u8KeyIdx);
 
 /**
  *  @brief              caches the pmkid
@@ -591,7 +516,7 @@ s32 host_int_add_tx_gtk(tstrWILC_WFIDrv *hWFIDrv, u8 u8KeyLen, u8 *pu8TxGtk, u8
  *  @version           1.0
  */
 
-s32 host_int_set_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, tstrHostIFpmkidAttr *pu8PmkidInfoArray);
+s32 host_int_set_pmkid_info(struct host_if_drv *hWFIDrv, struct host_if_pmkid_attr *pu8PmkidInfoArray);
 /**
  *  @brief              gets the cached the pmkid info
  *  @details    valid only in BSS STA mode if External Supplicant
@@ -615,7 +540,7 @@ s32 host_int_set_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, tstrHostIFpmkidAttr *pu8Pm
  *  @version           1.0
  */
 
-s32 host_int_get_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PmkidInfoArray,
+s32 host_int_get_pmkid_info(struct host_if_drv *hWFIDrv, u8 *pu8PmkidInfoArray,
                                    u32 u32PmkidInfoLen);
 
 /**
@@ -632,7 +557,7 @@ s32 host_int_get_pmkid_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PmkidInfoArray,
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_set_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PassPhrase,
+s32 host_int_set_RSNAConfigPSKPassPhrase(struct host_if_drv *hWFIDrv, u8 *pu8PassPhrase,
                                                 u8 u8Psklength);
 /**
  *  @brief              gets the pass phrase
@@ -648,7 +573,7 @@ s32 host_int_set_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8PassPh
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_get_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv,
+s32 host_int_get_RSNAConfigPSKPassPhrase(struct host_if_drv *hWFIDrv,
                                                 u8 *pu8PassPhrase, u8 u8Psklength);
 
 /**
@@ -662,7 +587,7 @@ s32 host_int_get_RSNAConfigPSKPassPhrase(tstrWILC_WFIDrv *hWFIDrv,
  *  @date              19 April 2012
  *  @version           1.0
  */
-s32 host_int_get_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress);
+s32 host_int_get_MacAddress(struct host_if_drv *hWFIDrv, u8 *pu8MacAddress);
 
 /**
  *  @brief              sets mac address
@@ -675,7 +600,7 @@ s32 host_int_get_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress);
  *  @date              16 July 2012
  *  @version           1.0
  */
-s32 host_int_set_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress);
+s32 host_int_set_MacAddress(struct host_if_drv *hWFIDrv, u8 *pu8MacAddress);
 
 /**
  *  @brief              wait until msg q is empty
@@ -688,42 +613,7 @@ s32 host_int_set_MacAddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8MacAddress);
  *  @date              19 march 2014
  *  @version           1.0
  */
-s32 host_int_wait_msg_queue_idle(void);
-
-/**
- *  @brief              gets the site survey results
- *  @details
- *  @param[in,out] handle to the wifi driver,
- *                                Message containing  site survey results in the
- *                                following formate
- *|---------------------------------------------------|
- | MsgLength | fragNo. | MsgBodyLength | MsgBody       |
- ||-----------|-----------|---------------|-----------|
- |      1              |         1             |               1               |        1              |
- | -----------------------------------------    |  ----------------
- |
- ||---------------------------------------|
- | Network1 | Netweork2 | ... | Network5 |
- ||---------------------------------------|
- |     44         |    44         | ... |       44             |
- | -------------------------- | ---------------------------------------
- |
- ||---------------------------------------------------------------------|
- | SSID | BSS Type | Channel | Security Status| BSSID | RSSI |Reserved |
- ||------|----------|---------|----------------|-------|------|---------|
- |  33  |       1        |       1             |               1                |        6      |       1      |        1        |
- ||---------------------------------------------------------------------|
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-#ifndef CONNECT_DIRECT
-s32 host_int_get_site_survey_results(tstrWILC_WFIDrv *hWFIDrv,
-                                            u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZE],
-                                            u32 u32MaxSiteSrvyFragLen);
-#endif
+int host_int_wait_msg_queue_idle(void);
 
 /**
  *  @brief              sets a start scan request
@@ -741,7 +631,7 @@ s32 host_int_get_site_survey_results(tstrWILC_WFIDrv *hWFIDrv,
  *  @version           1.0
  */
 
-s32 host_int_set_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 scanSource);
+s32 host_int_set_start_scan_req(struct host_if_drv *hWFIDrv, u8 scanSource);
 /**
  *  @brief              gets scan source of the last scan
  *  @details
@@ -757,7 +647,7 @@ s32 host_int_set_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 scanSource);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_get_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ScanSource);
+s32 host_int_get_start_scan_req(struct host_if_drv *hWFIDrv, u8 *pu8ScanSource);
 
 /**
  *  @brief              sets a join request
@@ -771,11 +661,11 @@ s32 host_int_get_start_scan_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ScanSource);
  *  @version           1.0
  */
 
-s32 host_int_set_join_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8bssid,
+s32 host_int_set_join_req(struct host_if_drv *hWFIDrv, u8 *pu8bssid,
                                  const u8 *pu8ssid, size_t ssidLen,
                                  const u8 *pu8IEs, size_t IEsLen,
-                                 tWILCpfConnectResult pfConnectResult, void *pvUserArg,
-                                 u8 u8security, AUTHTYPE_T tenuAuth_type,
+                                 wilc_connect_result pfConnectResult, void *pvUserArg,
+                                 u8 u8security, enum AUTHTYPE tenuAuth_type,
                                  u8 u8channel,
                                  void *pJoinParams);
 
@@ -791,7 +681,7 @@ s32 host_int_set_join_req(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8bssid,
  *  @version           8.0
  */
 
-s32 host_int_flush_join_req(tstrWILC_WFIDrv *hWFIDrv);
+s32 host_int_flush_join_req(struct host_if_drv *hWFIDrv);
 
 
 /**
@@ -805,7 +695,7 @@ s32 host_int_flush_join_req(tstrWILC_WFIDrv *hWFIDrv);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_disconnect(tstrWILC_WFIDrv *hWFIDrv, u16 u16ReasonCode);
+s32 host_int_disconnect(struct host_if_drv *hWFIDrv, u16 u16ReasonCode);
 
 /**
  *  @brief              disconnects a sta
@@ -818,7 +708,7 @@ s32 host_int_disconnect(tstrWILC_WFIDrv *hWFIDrv, u16 u16ReasonCode);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_disconnect_station(tstrWILC_WFIDrv *hWFIDrv, u8 assoc_id);
+s32 host_int_disconnect_station(struct host_if_drv *hWFIDrv, u8 assoc_id);
 /**
  *  @brief              gets a Association request info
  *  @details
@@ -845,7 +735,7 @@ s32 host_int_disconnect_station(tstrWILC_WFIDrv *hWFIDrv, u8 assoc_id);
  *  @version           1.0
  */
 
-s32 host_int_get_assoc_req_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocReqInfo,
+s32 host_int_get_assoc_req_info(struct host_if_drv *hWFIDrv, u8 *pu8AssocReqInfo,
                                        u32 u32AssocReqInfoLen);
 /**
  *  @brief              gets a Association Response info
@@ -859,7 +749,7 @@ s32 host_int_get_assoc_req_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocReqInfo,
  *  @version           1.0
  */
 
-s32 host_int_get_assoc_res_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocRespInfo,
+s32 host_int_get_assoc_res_info(struct host_if_drv *hWFIDrv, u8 *pu8AssocRespInfo,
                                        u32 u32MaxAssocRespInfoLen, u32 *pu32RcvdAssocRespInfoLen);
 /**
  *  @brief              gets a Association Response info
@@ -876,7 +766,7 @@ s32 host_int_get_assoc_res_info(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8AssocRespInfo,
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_get_rx_power_level(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8RxPowerLevel,
+s32 host_int_get_rx_power_level(struct host_if_drv *hWFIDrv, u8 *pu8RxPowerLevel,
                                        u32 u32RxPowerLevelLen);
 
 /**
@@ -894,7 +784,7 @@ s32 host_int_get_rx_power_level(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8RxPowerLevel,
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_set_mac_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 u8ChNum);
+int host_int_set_mac_chnl_num(struct host_if_drv *wfi_drv, u8 channel);
 
 /**
  *  @brief              gets the current channel index
@@ -911,7 +801,7 @@ s32 host_int_set_mac_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 u8ChNum);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_get_host_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ChNo);
+s32 host_int_get_host_chnl_num(struct host_if_drv *hWFIDrv, u8 *pu8ChNo);
 /**
  *  @brief              gets the sta rssi
  *  @details    gets the currently maintained RSSI value for the station.
@@ -925,8 +815,8 @@ s32 host_int_get_host_chnl_num(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8ChNo);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_get_rssi(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8Rssi);
-s32 host_int_get_link_speed(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8lnkspd);
+s32 host_int_get_rssi(struct host_if_drv *hWFIDrv, s8 *ps8Rssi);
+s32 host_int_get_link_speed(struct host_if_drv *hWFIDrv, s8 *ps8lnkspd);
 /**
  *  @brief              scans a set of channels
  *  @details
@@ -944,11 +834,12 @@ s32 host_int_get_link_speed(tstrWILC_WFIDrv *hWFIDrv, s8 *ps8lnkspd);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_scan(tstrWILC_WFIDrv *hWFIDrv, u8 u8ScanSource,
+s32 host_int_scan(struct host_if_drv *hWFIDrv, u8 u8ScanSource,
                          u8 u8ScanType, u8 *pu8ChnlFreqList,
                          u8 u8ChnlListLen, const u8 *pu8IEs,
-                         size_t IEsLen, tWILCpfScanResult ScanResult,
-                         void *pvUserArg, tstrHiddenNetwork *pstrHiddenNetwork);
+                         size_t IEsLen, wilc_scan_result ScanResult,
+                         void *pvUserArg,
+                         struct hidden_network *pstrHiddenNetwork);
 /**
  *  @brief              sets configuration wids values
  *  @details
@@ -960,7 +851,7 @@ s32 host_int_scan(tstrWILC_WFIDrv *hWFIDrv, u8 u8ScanSource,
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 hif_set_cfg(tstrWILC_WFIDrv *hWFIDrv, tstrCfgParamVal *pstrCfgParamVal);
+s32 hif_set_cfg(struct host_if_drv *hWFIDrv, struct cfg_param_val *pstrCfgParamVal);
 
 /**
  *  @brief              gets configuration wids values
@@ -974,44 +865,10 @@ s32 hif_set_cfg(tstrWILC_WFIDrv *hWFIDrv, tstrCfgParamVal *pstrCfgParamVal);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 hif_get_cfg(tstrWILC_WFIDrv *hWFIDrv, u16 u16WID, u16 *pu16WID_Value);
+s32 hif_get_cfg(struct host_if_drv *hWFIDrv, u16 u16WID, u16 *pu16WID_Value);
 /*****************************************************************************/
 /*                                                     Notification Functions                                                   */
 /*****************************************************************************/
-/**
- *  @brief              notifies host with join and leave requests
- *  @details    This function prepares an Information frame having the
- *                              information about a joining/leaving station.
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] 6 byte Sta Adress
- *                              Join or leave flag:
- *                              Join = 1,
- *                              Leave =0
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-void host_int_send_join_leave_info_to_host
-       (u16 assocId, u8 *stationAddr, bool joining);
-
-/**
- *  @brief              notifies host with stations found in scan
- *  @details    sends the beacon/probe response from scan
- *  @param[in,out] handle to the wifi driver,
- *  @param[in] Sta Address,
- *                              Frame length,
- *                              Rssi of the Station found
- *  @return             Error code indicating success/failure
- *  @note
- *  @author            zsalah
- *  @date              8 March 2012
- *  @version           1.0
- */
-void host_int_send_network_info_to_host
-       (u8 *macStartAddress, u16 u16RxFrameLen, s8 s8Rssi);
-
 /**
  *  @brief              host interface initialization function
  *  @details
@@ -1021,7 +878,7 @@ void host_int_send_network_info_to_host
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_init(tstrWILC_WFIDrv **phWFIDrv);
+s32 host_int_init(struct net_device *dev, struct host_if_drv **phWFIDrv);
 
 /**
  *  @brief              host interface initialization function
@@ -1032,7 +889,7 @@ s32 host_int_init(tstrWILC_WFIDrv **phWFIDrv);
  *  @date              8 March 2012
  *  @version           1.0
  */
-s32 host_int_deinit(tstrWILC_WFIDrv *hWFIDrv);
+s32 host_int_deinit(struct host_if_drv *hWFIDrv);
 
 
 /*!
@@ -1057,7 +914,7 @@ s32 host_int_deinit(tstrWILC_WFIDrv *hWFIDrv);
  *  @version           1.0 Description
  *
  */
-s32 host_int_add_beacon(tstrWILC_WFIDrv *hWFIDrv, u32 u32Interval,
+s32 host_int_add_beacon(struct host_if_drv *hWFIDrv, u32 u32Interval,
                                u32 u32DTIMPeriod,
                                u32 u32HeadLen, u8 *pu8Head,
                                u32 u32TailLen, u8 *pu8tail);
@@ -1075,10 +932,11 @@ s32 host_int_add_beacon(tstrWILC_WFIDrv *hWFIDrv, u32 u32Interval,
  *  @date              10 Julys 2012
  *  @version           1.0 Description
  */
-s32 host_int_del_beacon(tstrWILC_WFIDrv *hWFIDrv);
+s32 host_int_del_beacon(struct host_if_drv *hWFIDrv);
 
 /*!
- *  @fn                s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam strStaParams)
+ *  @fn                s32 host_int_add_station(WILC_WFIDrvHandle hWFIDrv,
+ *                                      struct add_sta_param *pstrStaParams)
  *  @brief             Notifies the firmware with a new associated stations
  *  @details
  *  @param[in,out]     hWFIDrv         handle to the wifi driver
@@ -1090,7 +948,8 @@ s32 host_int_del_beacon(tstrWILC_WFIDrv *hWFIDrv);
  *  @date              12 July 2012
  *  @version           1.0 Description
  */
-s32 host_int_add_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams);
+s32 host_int_add_station(struct host_if_drv *hWFIDrv,
+                        struct add_sta_param *pstrStaParams);
 
 /*!
  *  @fn                s32 host_int_del_allstation(WILC_WFIDrvHandle hWFIDrv, const u8* pu8MacAddr)
@@ -1105,7 +964,7 @@ s32 host_int_add_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrSta
  *  @date              09 April 2014
  *  @version           1.0 Description
  */
-s32 host_int_del_allstation(tstrWILC_WFIDrv *hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]);
+s32 host_int_del_allstation(struct host_if_drv *hWFIDrv, u8 pu8MacAddr[][ETH_ALEN]);
 
 /*!
  *  @fn                s32 host_int_del_station(WILC_WFIDrvHandle hWFIDrv, u8* pu8MacAddr)
@@ -1120,10 +979,11 @@ s32 host_int_del_allstation(tstrWILC_WFIDrv *hWFIDrv, u8 pu8MacAddr[][ETH_ALEN])
  *  @date              15 July 2012
  *  @version           1.0 Description
  */
-s32 host_int_del_station(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8MacAddr);
+s32 host_int_del_station(struct host_if_drv *hWFIDrv, const u8 *pu8MacAddr);
 
 /*!
- *  @fn                s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv, tstrWILC_AddStaParam strStaParams)
+ *  @fn                s32 host_int_edit_station(WILC_WFIDrvHandle hWFIDrv,
+ *                                       struct add_sta_param *pstrStaParams)
  *  @brief             Notifies the firmware with new parameters of an already associated station
  *  @details
  *  @param[in,out]     hWFIDrv         handle to the wifi driver
@@ -1135,7 +995,8 @@ s32 host_int_del_station(tstrWILC_WFIDrv *hWFIDrv, const u8 *pu8MacAddr);
  *  @date              15 July 2012
  *  @version           1.0 Description
  */
-s32 host_int_edit_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrStaParams);
+s32 host_int_edit_station(struct host_if_drv *hWFIDrv,
+                         struct add_sta_param *pstrStaParams);
 
 /*!
  *  @fn                s32 host_int_set_power_mgmt(WILC_WFIDrvHandle hWFIDrv, bool bIsEnabled, u32 u32Timeout)
@@ -1152,7 +1013,7 @@ s32 host_int_edit_station(tstrWILC_WFIDrv *hWFIDrv, tstrWILC_AddStaParam *pstrSt
  *  @date              24 November 2012
  *  @version           1.0 Description
  */
-s32 host_int_set_power_mgmt(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32Timeout);
+s32 host_int_set_power_mgmt(struct host_if_drv *hWFIDrv, bool bIsEnabled, u32 u32Timeout);
 /*  @param[in,out]     hWFIDrv         handle to the wifi driver
  *  @param[in] bIsEnabled      TRUE if enabled, FALSE otherwise
  *  @param[in] u8count         count of mac address entries in the filter table
@@ -1164,7 +1025,7 @@ s32 host_int_set_power_mgmt(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32Ti
  *  @date              24 November 2012
  *  @version           1.0 Description
  */
-s32 host_int_setup_multicast_filter(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u32 u32count);
+s32 host_int_setup_multicast_filter(struct host_if_drv *hWFIDrv, bool bIsEnabled, u32 u32count);
 /**
  *  @brief           host_int_setup_ipaddress
  *  @details       set IP address on firmware
@@ -1174,7 +1035,7 @@ s32 host_int_setup_multicast_filter(tstrWILC_WFIDrv *hWFIDrv, bool bIsEnabled, u
  *  @date
  *  @version   1.0
  */
-s32 host_int_setup_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
+s32 host_int_setup_ipaddress(struct host_if_drv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
 
 
 /**
@@ -1186,7 +1047,7 @@ s32 host_int_setup_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
  *  @date
  *  @version   1.0
  */
-s32 host_int_delBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID);
+s32 host_int_delBASession(struct host_if_drv *hWFIDrv, char *pBSSID, char TID);
 
 /**
  *  @brief           host_int_delBASession
@@ -1197,7 +1058,7 @@ s32 host_int_delBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID);
  *  @date
  *  @version   1.0
  */
-s32 host_int_del_All_Rx_BASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID);
+s32 host_int_del_All_Rx_BASession(struct host_if_drv *hWFIDrv, char *pBSSID, char TID);
 
 
 /**
@@ -1209,9 +1070,8 @@ s32 host_int_del_All_Rx_BASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char T
  *  @date
  *  @version   1.0
  */
-s32 host_int_get_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
+s32 host_int_get_ipaddress(struct host_if_drv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
 
-#ifdef WILC_P2P
 /**
  *  @brief           host_int_remain_on_channel
  *  @details
@@ -1221,7 +1081,7 @@ s32 host_int_get_ipaddress(tstrWILC_WFIDrv *hWFIDrv, u8 *pu8IPAddr, u8 idx);
  *  @date
  *  @version   1.0
  */
-s32 host_int_remain_on_channel(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, tWILCpfRemainOnChanExpired RemainOnChanExpired, tWILCpfRemainOnChanReady RemainOnChanReady, void *pvUserArg);
+s32 host_int_remain_on_channel(struct host_if_drv *hWFIDrv, u32 u32SessionID, u32 u32duration, u16 chan, wilc_remain_on_chan_expired RemainOnChanExpired, wilc_remain_on_chan_ready RemainOnChanReady, void *pvUserArg);
 
 /**
  *  @brief              host_int_ListenStateExpired
@@ -1237,7 +1097,7 @@ s32 host_int_remain_on_channel(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID, u32 u
  *  @date
  *  @version           1.0
  */
-s32 host_int_ListenStateExpired(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID);
+s32 host_int_ListenStateExpired(struct host_if_drv *hWFIDrv, u32 u32SessionID);
 
 /**
  *  @brief           host_int_frame_register
@@ -1248,8 +1108,7 @@ s32 host_int_ListenStateExpired(tstrWILC_WFIDrv *hWFIDrv, u32 u32SessionID);
  *  @date
  *  @version   1.0
  */
-s32 host_int_frame_register(tstrWILC_WFIDrv *hWFIDrv, u16 u16FrameType, bool bReg);
-#endif
+s32 host_int_frame_register(struct host_if_drv *hWFIDrv, u16 u16FrameType, bool bReg);
 /**
  *  @brief           host_int_set_wfi_drv_handler
  *  @details
@@ -1259,22 +1118,13 @@ s32 host_int_frame_register(tstrWILC_WFIDrv *hWFIDrv, u16 u16FrameType, bool bRe
  *  @date
  *  @version   1.0
  */
-s32 host_int_set_wfi_drv_handler(tstrWILC_WFIDrv *u32address);
-s32 host_int_set_operation_mode(tstrWILC_WFIDrv *hWFIDrv, u32 u32mode);
-
-static s32 Handle_ScanDone(tstrWILC_WFIDrv *drvHandler, tenuScanEvent enuEvent);
-
-static int host_int_addBASession(tstrWILC_WFIDrv *hWFIDrv, char *pBSSID, char TID, short int BufferSize,
-                                short int SessionTimeout, void *drvHandler);
+int host_int_set_wfi_drv_handler(struct host_if_drv *address);
+int host_int_set_operation_mode(struct host_if_drv *wfi_drv, u32 mode);
 
+static s32 Handle_ScanDone(struct host_if_drv *drvHandler, enum scan_event enuEvent);
 
 void host_int_freeJoinParams(void *pJoinParams);
 
-s32 host_int_get_statistics(tstrWILC_WFIDrv *hWFIDrv, tstrStatistics *pstrStatistics);
+s32 host_int_get_statistics(struct host_if_drv *hWFIDrv, struct rf_info *pstrStatistics);
 
-/*****************************************************************************/
-/*                                                                                                                                                      */
-/*                                                                     EOF                                                                              */
-/*                                                                                                                                                      */
-/*****************************************************************************/
 #endif
index b8d7d048439b2025d6594e66e414722ab4f8cd66..450af1b77f991369fea3a8262d7566fba3c7a58e 100644 (file)
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
 
-#ifdef WILC_FULLY_HOSTING_AP
-#include "wilc_host_ap.h"
-#endif
-#ifdef WILC_AP_EXTERNAL_MLME
 
 struct wilc_wfi_radiotap_hdr {
        struct ieee80211_radiotap_header hdr;
        u8 rate;
-       /* u32 channel; */
 } __attribute__((packed));
 
 struct wilc_wfi_radiotap_cb_hdr {
@@ -27,16 +22,11 @@ struct wilc_wfi_radiotap_cb_hdr {
        u8 rate;
        u8 dump;
        u16 tx_flags;
-       /* u32 channel; */
 } __attribute__((packed));
 
-extern linux_wlan_t *g_linux_wlan;
-
 static struct net_device *wilc_wfi_mon; /* global monitor netdev */
 
-#if USE_WIRELESS
 extern int  mac_xmit(struct sk_buff *skb, struct net_device *dev);
-#endif
 
 
 u8 srcAdd[6];
@@ -59,20 +49,15 @@ u8 broadcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 #define IS_MGMT_STATUS_SUCCES                  0x040
 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
 
-void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size)
+void WILC_WFI_monitor_rx(u8 *buff, u32 size)
 {
-       uint32_t header, pkt_offset;
+       u32 header, pkt_offset;
        struct sk_buff *skb = NULL;
        struct wilc_wfi_radiotap_hdr *hdr;
        struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
 
        PRINT_INFO(HOSTAPD_DBG, "In monitor interface receive function\n");
 
-       /*   struct WILC_WFI_priv *priv = netdev_priv(dev); */
-
-       /*   priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy); */
-
-       /* Bug 4601 */
        if (wilc_wfi_mon == NULL)
                return;
 
@@ -129,30 +114,19 @@ void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size)
                        return;
                }
 
-               /* skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC); */
-               /* if (skb == NULL) */
-               /*      return; */
-
                memcpy(skb_put(skb, size), buff, size);
                hdr = (struct wilc_wfi_radiotap_hdr *) skb_push(skb, sizeof(*hdr));
                memset(hdr, 0, sizeof(struct wilc_wfi_radiotap_hdr));
                hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
-               /* hdr->hdr.it_pad = 0; */
                hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_hdr));
                PRINT_INFO(HOSTAPD_DBG, "Radiotap len %d\n", hdr->hdr.it_len);
                hdr->hdr.it_present = cpu_to_le32
                                (1 << IEEE80211_RADIOTAP_RATE);                   /* | */
-               /* (1 << IEEE80211_RADIOTAP_CHANNEL)); */
                PRINT_INFO(HOSTAPD_DBG, "Presentflags %d\n", hdr->hdr.it_present);
                hdr->rate = 5; /* txrate->bitrate / 5; */
 
        }
 
-/*     if(INFO || if(skb->data[9] == 0x00 || skb->data[9] == 0xb0))
- *      {
- *              for(i=0;i<skb->len;i++)
- *                      PRINT_INFO(HOSTAPD_DBG,"Mon RxData[%d] = %02x\n",i,skb->data[i]);
- *      }*/
 
 
        skb->dev = wilc_wfi_mon;
@@ -175,9 +149,6 @@ struct tx_complete_mon_data {
 static void mgmt_tx_complete(void *priv, int status)
 {
 
-       /* struct sk_buff *skb2; */
-       /* struct wilc_wfi_radiotap_cb_hdr *cb_hdr; */
-
        struct tx_complete_mon_data *pv_data = (struct tx_complete_mon_data *)priv;
        u8 *buf =  pv_data->buff;
 
@@ -191,42 +162,11 @@ static void mgmt_tx_complete(void *priv, int status)
        }
 
 
-/*                     //(skb->data[9] == 0x00 || skb->data[9] == 0xb0 || skb->data[9] == 0x40 ||  skb->data[9] == 0xd0 )
- *      {
- *              skb2 = dev_alloc_skb(pv_data->size+sizeof(struct wilc_wfi_radiotap_cb_hdr));
- *
- *              memcpy(skb_put(skb2,pv_data->size),pv_data->buff, pv_data->size);
- *
- *              cb_hdr = (struct wilc_wfi_radiotap_cb_hdr *) skb_push(skb2, sizeof(*cb_hdr));
- *              memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr));
- *
- *               cb_hdr->hdr.it_version = 0;//PKTHDR_RADIOTAP_VERSION;
- *
- *              cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr));
- *
- *       cb_hdr->hdr.it_present = cpu_to_le32(
- *                                        (1 << IEEE80211_RADIOTAP_RATE) |
- *                                       (1 << IEEE80211_RADIOTAP_TX_FLAGS));
- *
- *              cb_hdr->rate = 5;//txrate->bitrate / 5;
- *              cb_hdr->tx_flags = 0x0004;
- *
- *              skb2->dev = wilc_wfi_mon;
- *              skb_set_mac_header(skb2, 0);
- *              skb2->ip_summed = CHECKSUM_UNNECESSARY;
- *              skb2->pkt_type = PACKET_OTHERHOST;
- *              skb2->protocol = htons(ETH_P_802_2);
- *              memset(skb2->cb, 0, sizeof(skb2->cb));
- *
- *              netif_rx(skb2);
- *      }*/
 
        /* incase of fully hosting mode, the freeing will be done in response to the cfg packet */
-       #ifndef WILC_FULLY_HOSTING_AP
        kfree(pv_data->buff);
 
        kfree(pv_data);
-       #endif
 }
 static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len)
 {
@@ -234,44 +174,29 @@ static int mon_mgmt_tx(struct net_device *dev, const u8 *buf, size_t len)
 
        if (dev == NULL) {
                PRINT_D(HOSTAPD_DBG, "ERROR: dev == NULL\n");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
        netif_stop_queue(dev);
        mgmt_tx = kmalloc(sizeof(struct tx_complete_mon_data), GFP_ATOMIC);
        if (mgmt_tx == NULL) {
                PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
-       #ifdef WILC_FULLY_HOSTING_AP
-       /* add space for the pointer to tx_complete_mon_data */
-       len += sizeof(struct tx_complete_mon_data *);
-       #endif
-
        mgmt_tx->buff = kmalloc(len, GFP_ATOMIC);
        if (mgmt_tx->buff == NULL) {
                PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
-               return WILC_FAIL;
+               kfree(mgmt_tx);
+               return -EFAULT;
 
        }
 
        mgmt_tx->size = len;
 
-       #ifndef WILC_FULLY_HOSTING_AP
        memcpy(mgmt_tx->buff, buf, len);
-       #else
-       memcpy(mgmt_tx->buff, buf, len - sizeof(struct tx_complete_mon_data *));
-       memcpy((mgmt_tx->buff) + (len - sizeof(struct tx_complete_mon_data *)), &mgmt_tx, sizeof(struct tx_complete_mon_data *));
-
-       /* filter data frames to handle it's PS */
-       if (filter_monitor_data_frames((mgmt_tx->buff), len) == true) {
-               return;
-       }
-
-       #endif /* WILC_FULLY_HOSTING_AP */
-
-       g_linux_wlan->oup.wlan_add_mgmt_to_tx_que(mgmt_tx, mgmt_tx->buff, mgmt_tx->size, mgmt_tx_complete);
+       wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff, mgmt_tx->size,
+                                  mgmt_tx_complete);
 
        netif_wake_queue(dev);
        return 0;
@@ -295,17 +220,14 @@ static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb,
        struct sk_buff *skb2;
        struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
 
-       /* Bug 4601 */
        if (wilc_wfi_mon == NULL)
-               return WILC_FAIL;
-
-       /* if(skb->data[3] == 0x10 || skb->data[3] == 0xb0) */
+               return -EFAULT;
 
        mon_priv = netdev_priv(wilc_wfi_mon);
 
        if (mon_priv == NULL) {
                PRINT_ER("Monitor interface private structure is NULL\n");
-               return WILC_FAIL;
+               return -EFAULT;
        }
 
 
@@ -367,7 +289,6 @@ static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb,
        PRINT_INFO(HOSTAPD_DBG, "SKB netdevice name = %s\n", skb->dev->name);
        PRINT_INFO(HOSTAPD_DBG, "MONITOR real dev name = %s\n", mon_priv->real_ndev->name);
 
-       #if USE_WIRELESS
        /* Identify if Ethernet or MAC header (data or mgmt) */
        memcpy(srcAdd, &skb->data[10], 6);
        memcpy(bssid, &skb->data[16], 6);
@@ -378,9 +299,7 @@ static netdev_tx_t WILC_WFI_mon_xmit(struct sk_buff *skb,
                dev_kfree_skb(skb);
        } else
                ret = mac_xmit(skb, mon_priv->real_ndev);
-       #endif
 
-       /* return NETDEV_TX_OK; */
        return ret;
 }
 
@@ -389,117 +308,6 @@ static const struct net_device_ops wilc_wfi_netdev_ops = {
 
 };
 
-#ifdef WILC_FULLY_HOSTING_AP
-/*
- *  @brief                      WILC_mgm_HOSTAPD_ACK
- *  @details            report the status of transmitted mgmt frames to HOSTAPD
- *  @param[in]          priv : pointer to tx_complete_mon_data struct
- *                             bStatus : status of transmission
- *  @author            Abd Al-Rahman Diab
- *  @date                      9 May 2013
- *  @version           1.0
- */
-void WILC_mgm_HOSTAPD_ACK(void *priv, bool bStatus)
-{
-       struct sk_buff *skb;
-       struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
-
-       struct tx_complete_mon_data *pv_data = (struct tx_complete_mon_data *)priv;
-       u8 *buf =  pv_data->buff;
-
-       /* len of the original frame without the added pointer at the tail */
-       u16 u16len = (pv_data->size) - sizeof(struct tx_complete_mon_data *);
-
-
-       /*if(bStatus == 1){
-        *      if(INFO || buf[0] == 0x10 || buf[0] == 0xb0)
-        *      PRINT_D(HOSTAPD_DBG,"Packet sent successfully - Size = %d - Address = %p.\n",u16len,pv_data->buff);
-        * }else{
-        *              PRINT_D(HOSTAPD_DBG,"Couldn't send packet - Size = %d - Address = %p.\n",u16len,pv_data->buff);
-        *      }
-        */
-
-       /* (skb->data[9] == 0x00 || skb->data[9] == 0xb0 || skb->data[9] == 0x40 ||  skb->data[9] == 0xd0 ) */
-       {
-               skb = dev_alloc_skb(u16len + sizeof(struct wilc_wfi_radiotap_cb_hdr));
-
-               memcpy(skb_put(skb, u16len), pv_data->buff, u16len);
-
-               cb_hdr = (struct wilc_wfi_radiotap_cb_hdr *) skb_push(skb, sizeof(*cb_hdr));
-               memset(cb_hdr, 0, sizeof(struct wilc_wfi_radiotap_cb_hdr));
-
-               cb_hdr->hdr.it_version = 0; /* PKTHDR_RADIOTAP_VERSION; */
-
-               cb_hdr->hdr.it_len = cpu_to_le16(sizeof(struct wilc_wfi_radiotap_cb_hdr));
-
-               cb_hdr->hdr.it_present = cpu_to_le32(
-                               (1 << IEEE80211_RADIOTAP_RATE) |
-                               (1 << IEEE80211_RADIOTAP_TX_FLAGS));
-
-               cb_hdr->rate = 5; /* txrate->bitrate / 5; */
-
-
-               if (bStatus) {
-                       /* success */
-                       cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_RTS;
-               } else {
-                       cb_hdr->tx_flags = IEEE80211_RADIOTAP_F_TX_FAIL;
-               }
-
-               skb->dev = wilc_wfi_mon;
-               skb_set_mac_header(skb, 0);
-               skb->ip_summed = CHECKSUM_UNNECESSARY;
-               skb->pkt_type = PACKET_OTHERHOST;
-               skb->protocol = htons(ETH_P_802_2);
-               memset(skb->cb, 0, sizeof(skb->cb));
-
-               netif_rx(skb);
-       }
-
-       /* incase of fully hosting mode, the freeing will be done in response to the cfg packet */
-       kfree(pv_data->buff);
-
-       kfree(pv_data);
-
-}
-#endif /* WILC_FULLY_HOSTING_AP */
-
-/**
- *  @brief      WILC_WFI_mon_setup
- *  @details
- *  @param[in]
- *  @return     int : Return 0 on Success
- *  @author    mdaftedar
- *  @date      12 JUL 2012
- *  @version   1.0
- */
-static void WILC_WFI_mon_setup(struct net_device *dev)
-{
-
-       dev->netdev_ops = &wilc_wfi_netdev_ops;
-       /* dev->destructor = free_netdev; */
-       PRINT_INFO(CORECONFIG_DBG, "In Ethernet setup function\n");
-       ether_setup(dev);
-       dev->priv_flags |= IFF_NO_QUEUE;
-       dev->type = ARPHRD_IEEE80211_RADIOTAP;
-       eth_zero_addr(dev->dev_addr);
-
-       #ifdef USE_WIRELESS
-       {
-               /* u8 * mac_add; */
-               unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x8f};
-               /* priv = wiphy_priv(priv->dev->ieee80211_ptr->wiphy); */
-               /* mac_add = (u8*)WILC_MALLOC(ETH_ALEN); */
-               /* status = host_int_get_MacAddress(priv->hWILCWFIDrv,mac_add); */
-               /* mac_add[ETH_ALEN-1]+=1; */
-               memcpy(dev->dev_addr, mac_add, ETH_ALEN);
-       }
-       #else
-       dev->dev_addr[0] = 0x12;
-       #endif
-
-}
-
 /**
  *  @brief      WILC_WFI_init_mon_interface
  *  @details
@@ -513,7 +321,7 @@ struct net_device *WILC_WFI_init_mon_interface(const char *name, struct net_devi
 {
 
 
-       u32 ret = WILC_SUCCESS;
+       u32 ret = 0;
        struct WILC_WFI_mon_priv *priv;
 
        /*If monitor interface is already initialized, return it*/
@@ -571,7 +379,6 @@ int WILC_WFI_deinit_mon_interface(void)
                }
                PRINT_D(HOSTAPD_DBG, "Unregister netdev\n");
                unregister_netdev(wilc_wfi_mon);
-               /* free_netdev(wilc_wfi_mon); */
 
                if (rollback_lock) {
                        rtnl_lock();
@@ -579,7 +386,6 @@ int WILC_WFI_deinit_mon_interface(void)
                }
                wilc_wfi_mon = NULL;
        }
-       return WILC_SUCCESS;
+       return 0;
 
 }
-#endif /* WILC_AP_EXTERNAL_MLME */
index b3cc9f5c7937c2834999dc172749c34ecc404ed1..2a5b36fd8b4804460dc91f33178fadae64cd50ee 100644 (file)
@@ -2,11 +2,6 @@
 #include "linux_wlan_common.h"
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
-#ifdef USE_WIRELESS
-#include "wilc_wfi_cfgoperations.h"
-#endif
-
-#include "linux_wlan_common.h"
 
 #include <linux/slab.h>
 #include <linux/sched.h>
@@ -22,9 +17,7 @@
 
 #include <linux/init.h>
 #include <linux/netdevice.h>
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 #include <linux/inetdevice.h>
-#endif
 #include <linux/etherdevice.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include "linux_wlan_spi.h"
 #endif
 
-#ifdef WILC_FULLY_HOSTING_AP
-#include "wilc_host_ap.h"
-#endif
-
-#ifdef STATIC_MACADDRESS /* brandy_0724 [[ */
-#include <linux/vmalloc.h>
-#include <linux/fs.h>
-struct task_struct *wilc_mac_thread;
-unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xb2};
-#endif /* brandy_0724 ]] */
-
 #if defined(CUSTOMER_PLATFORM)
 /*
  TODO : Write power control functions as customer platform.
@@ -63,16 +45,10 @@ unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xb2};
  #define _linux_wlan_device_removal()          {}
 #endif
 
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 extern bool g_obtainingIP;
-#endif
-extern u16 Set_machw_change_vir_if(bool bValue);
 extern void resolve_disconnect_aberration(void *drvHandler);
 extern u8 gau8MulticastMacAddrList[WILC_MULTICAST_TABLE_SIZE][ETH_ALEN];
-void wilc1000_wlan_deinit(linux_wlan_t *nic);
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 extern struct timer_list hDuringIpTimer;
-#endif
 
 static int linux_wlan_device_power(int on_off)
 {
@@ -102,35 +78,11 @@ static int linux_wlan_device_detection(int on_off)
        return 0;
 }
 
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr);
 
 static struct notifier_block g_dev_notifier = {
        .notifier_call = dev_state_ev_handler
 };
-#endif
-
-#define wilc_wlan_deinit(nic)  { if (&g_linux_wlan->oup != NULL)        \
-               if (g_linux_wlan->oup.wlan_cleanup != NULL) \
-                       g_linux_wlan->oup.wlan_cleanup(); }
-
-#ifndef STA_FIRMWARE
-#define STA_FIRMWARE   "wifi_firmware.bin"
-#endif
-
-#ifndef AP_FIRMWARE
-#define AP_FIRMWARE            "wifi_firmware_ap.bin"
-#endif
-
-#ifndef P2P_CONCURRENCY_FIRMWARE
-#define P2P_CONCURRENCY_FIRMWARE       "wifi_firmware_p2p_concurrency.bin"
-#endif
-
-typedef struct android_wifi_priv_cmd {
-       char *buf;
-       int used_len;
-       int total_len;
-} android_wifi_priv_cmd;
 
 #define IRQ_WAIT       1
 #define IRQ_NO_WAIT    0
@@ -141,20 +93,13 @@ typedef struct android_wifi_priv_cmd {
  *      deinitialized from mdoule_exit
  */
 static struct semaphore close_exit_sync;
-unsigned int int_rcvdU;
-unsigned int int_rcvdB;
-unsigned int int_clrd;
-
-static int wlan_deinit_locks(linux_wlan_t *nic);
-static void wlan_deinitialize_threads(linux_wlan_t *nic);
-static void linux_wlan_lock(void *vp);
-void linux_wlan_unlock(void *vp);
-extern void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size);
-extern void WILC_WFI_p2p_rx(struct net_device *dev, uint8_t *buff, uint32_t size);
-
-static void *internal_alloc(uint32_t size, uint32_t flag);
+
+static int wlan_deinit_locks(struct net_device *dev);
+static void wlan_deinitialize_threads(struct net_device *dev);
+extern void WILC_WFI_monitor_rx(u8 *buff, u32 size);
+extern void WILC_WFI_p2p_rx(struct net_device *dev, u8 *buff, u32 size);
+
 static void linux_wlan_tx_complete(void *priv, int status);
-void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset);
 static int  mac_init_fn(struct net_device *ndev);
 int  mac_xmit(struct sk_buff *skb, struct net_device *dev);
 int  mac_open(struct net_device *ndev);
@@ -167,8 +112,7 @@ static void wilc_set_multicast_list(struct net_device *dev);
  * for now - in frmw_to_linux there should be private data to be passed to it
  * and this data should be pointer to net device
  */
-linux_wlan_t *g_linux_wlan;
-wilc_wlan_oup_t *gpstrWlanOps;
+struct wilc *g_linux_wlan;
 bool bEnablePS = true;
 
 static const struct net_device_ops wilc_netdev_ops = {
@@ -182,65 +126,11 @@ static const struct net_device_ops wilc_netdev_ops = {
 
 };
 
-#ifdef DEBUG_MODE
-
-extern volatile int timeNo;
-
-#define DEGUG_BUFFER_LENGTH 1000
-volatile int WatchDogdebuggerCounter;
-char DebugBuffer[DEGUG_BUFFER_LENGTH + 20] = {0};
-static char *ps8current = DebugBuffer;
-
-void printk_later(const char *format, ...)
-{
-       va_list args;
-       va_start(args, format);
-       ps8current += vsprintf(ps8current, format, args);
-       va_end(args);
-       if ((ps8current - DebugBuffer) > DEGUG_BUFFER_LENGTH)
-               ps8current = DebugBuffer;
-
-}
-
-void dump_logs(void)
-{
-       if (DebugBuffer[0]) {
-               DebugBuffer[DEGUG_BUFFER_LENGTH] = 0;
-               PRINT_INFO(GENERIC_DBG, "early printed\n");
-               PRINT_D(GENERIC_DBG, ps8current + 1);
-               ps8current[1] = 0;
-               PRINT_INFO(GENERIC_DBG, "latest printed\n");
-               PRINT_D(GENERIC_DBG, DebugBuffer);
-               DebugBuffer[0] = 0;
-               ps8current = DebugBuffer;
-       }
-}
-
-void Reset_WatchDogdebugger(void)
-{
-       WatchDogdebuggerCounter = 0;
-}
-
-static int DebuggingThreadTask(void *vp)
-{
-       while (1) {
-               while (!WatchDogdebuggerCounter) {
-                       PRINT_D(GENERIC_DBG, "Debug Thread Running %d\n", timeNo);
-                       WatchDogdebuggerCounter = 1;
-                       msleep(10000);
-               }
-               dump_logs();
-               WatchDogdebuggerCounter = 0;
-       }
-}
-#endif
-
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 static int dev_state_ev_handler(struct notifier_block *this, unsigned long event, void *ptr)
 {
        struct in_ifaddr *dev_iface = (struct in_ifaddr *)ptr;
-       struct WILC_WFI_priv *priv;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct wilc_priv *priv;
+       struct host_if_drv *pstrWFIDrv;
        struct net_device *dev;
        u8 *pIP_Add_buff;
        perInterface_wlan_t *nic;
@@ -267,7 +157,7 @@ static int dev_state_ev_handler(struct notifier_block *this, unsigned long event
                PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
                return NOTIFY_DONE;
        }
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
        nic = netdev_priv(dev);
        if (nic == NULL || pstrWFIDrv == NULL) {
                PRINT_D(GENERIC_DBG, "No Wireless Priv\n");
@@ -334,136 +224,56 @@ static int dev_state_ev_handler(struct notifier_block *this, unsigned long event
        return NOTIFY_DONE;
 
 }
-#endif
-
-/*
- *     Interrupt initialization and handling functions
- */
-
-void linux_wlan_enable_irq(void)
-{
-
-#if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
-#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
-       PRINT_D(INT_DBG, "Enabling IRQ ...\n");
-       enable_irq(g_linux_wlan->dev_irq_num);
-#endif
-#endif
-}
-
-void linux_wlan_disable_irq(int wait)
-{
-#if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
-       if (wait) {
-               PRINT_D(INT_DBG, "Disabling IRQ ...\n");
-               disable_irq(g_linux_wlan->dev_irq_num);
-       } else {
-               PRINT_D(INT_DBG, "Disabling IRQ ...\n");
-               disable_irq_nosync(g_linux_wlan->dev_irq_num);
-       }
-#endif
-}
 
 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
 static irqreturn_t isr_uh_routine(int irq, void *user_data)
 {
-       int_rcvdU++;
-#if (RX_BH_TYPE != RX_BH_THREADED_IRQ)
-       linux_wlan_disable_irq(IRQ_NO_WAIT);
-#endif
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+       struct net_device *dev = (struct net_device *)user_data;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
        PRINT_D(INT_DBG, "Interrupt received UH\n");
 
        /*While mac is closing cacncel the handling of any interrupts received*/
-       if (g_linux_wlan->close) {
+       if (wilc->close) {
                PRINT_ER("Driver is CLOSING: Can't handle UH interrupt\n");
-       #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
                return IRQ_HANDLED;
-       #else
-               return IRQ_NONE;
-       #endif
-
        }
-#if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
-       schedule_work(&g_linux_wlan->rx_work_queue);
-       return IRQ_HANDLED;
-#elif (RX_BH_TYPE == RX_BH_KTHREAD)
-       linux_wlan_unlock(&g_linux_wlan->rx_sem);
-       return IRQ_HANDLED;
-#elif (RX_BH_TYPE == RX_BH_THREADED_IRQ)
        return IRQ_WAKE_THREAD;
-#endif
-
 }
 #endif
 
-#if (RX_BH_TYPE == RX_BH_WORK_QUEUE || RX_BH_TYPE == RX_BH_THREADED_IRQ)
-
-#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
 irqreturn_t isr_bh_routine(int irq, void *userdata)
-{
-       linux_wlan_t *nic;
-       nic = (linux_wlan_t *)userdata;
-#else
-static void isr_bh_routine(struct work_struct *work)
 {
        perInterface_wlan_t *nic;
-       nic = (perInterface_wlan_t *)container_of(work, linux_wlan_t, rx_work_queue);
-#endif
+       struct wilc *wilc;
+
+       nic = netdev_priv(userdata);
+       wilc = nic->wilc;
 
        /*While mac is closing cacncel the handling of any interrupts received*/
-       if (g_linux_wlan->close) {
+       if (wilc->close) {
                PRINT_ER("Driver is CLOSING: Can't handle BH interrupt\n");
-       #if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
                return IRQ_HANDLED;
-       #else
-               return;
-       #endif
        }
 
-       int_rcvdB++;
        PRINT_D(INT_DBG, "Interrupt received BH\n");
-       if (g_linux_wlan->oup.wlan_handle_rx_isr != 0)
-               g_linux_wlan->oup.wlan_handle_rx_isr();
-       else
-               PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
+       wilc_handle_isr(wilc);
 
-#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
        return IRQ_HANDLED;
-#endif
-}
-#elif (RX_BH_TYPE == RX_BH_KTHREAD)
-static int isr_bh_routine(void *vp)
-{
-       linux_wlan_t *nic;
-
-       nic = (linux_wlan_t *)vp;
-
-       while (1) {
-               linux_wlan_lock(&nic->rx_sem);
-               if (g_linux_wlan->close) {
-
-                       while (!kthread_should_stop())
-                               schedule();
-
-                       break;
-               }
-               int_rcvdB++;
-               PRINT_D(INT_DBG, "Interrupt received BH\n");
-               if (g_linux_wlan->oup.wlan_handle_rx_isr != 0)
-                       g_linux_wlan->oup.wlan_handle_rx_isr();
-               else
-                       PRINT_ER("wlan_handle_rx_isr() hasn't been initialized\n");
-       }
-
-       return 0;
 }
-#endif
 
 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
-static int init_irq(linux_wlan_t *p_nic)
+static int init_irq(struct net_device *dev)
 {
        int ret = 0;
-       linux_wlan_t *nic = p_nic;
+       perInterface_wlan_t *nic;
+       struct wilc *wl;
+
+       nic = netdev_priv(dev);
+       wl = nic->wilc;
 
        /*initialize GPIO and register IRQ num*/
        /*GPIO request*/
@@ -475,49 +285,42 @@ static int init_irq(linux_wlan_t *p_nic)
  *
  * ex) nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
  */
-#elif defined(NM73131_0_BOARD)
-               nic->dev_irq_num = IRQ_WILC1000;
-#elif defined(PANDA_BOARD)
-               gpio_export(GPIO_NUM, 1);
-               nic->dev_irq_num = OMAP_GPIO_IRQ(GPIO_NUM);
-               irq_set_irq_type(nic->dev_irq_num, IRQ_TYPE_LEVEL_LOW);
 #else
-               nic->dev_irq_num = gpio_to_irq(GPIO_NUM);
+               wl->dev_irq_num = gpio_to_irq(GPIO_NUM);
 #endif
        } else {
                ret = -1;
                PRINT_ER("could not obtain gpio for WILC_INTR\n");
        }
 
-#if (RX_BH_TYPE == RX_BH_THREADED_IRQ)
-       if ((ret != -1) && (request_threaded_irq(nic->dev_irq_num, isr_uh_routine, isr_bh_routine,
+       if ((ret != -1) && (request_threaded_irq(wl->dev_irq_num, isr_uh_routine, isr_bh_routine,
                                                  IRQF_TRIGGER_LOW | IRQF_ONESHOT,               /*Without IRQF_ONESHOT the uh will remain kicked in and dont gave a chance to bh*/
-                                                 "WILC_IRQ", nic)) < 0) {
-
-#else
-       /*Request IRQ*/
-       if ((ret != -1) && (request_irq(nic->dev_irq_num, isr_uh_routine,
-                                       IRQF_TRIGGER_LOW, "WILC_IRQ", nic) < 0)) {
+                                                 "WILC_IRQ", dev)) < 0) {
 
-#endif
                PRINT_ER("Failed to request IRQ for GPIO: %d\n", GPIO_NUM);
                ret = -1;
        } else {
 
                PRINT_D(INIT_DBG, "IRQ request succeeded IRQ-NUM= %d on GPIO: %d\n",
-                       nic->dev_irq_num, GPIO_NUM);
+                       wl->dev_irq_num, GPIO_NUM);
        }
 
        return ret;
 }
 #endif
 
-static void deinit_irq(linux_wlan_t *nic)
+static void deinit_irq(struct net_device *dev)
 {
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
+
 #if (defined WILC_SPI) || (defined WILC_SDIO_IRQ_GPIO)
        /* Deintialize IRQ */
-       if (&nic->dev_irq_num != 0) {
-               free_irq(nic->dev_irq_num, g_linux_wlan);
+       if (&wilc->dev_irq_num != 0) {
+               free_irq(wilc->dev_irq_num, wilc);
 
                gpio_free(GPIO_NUM);
        }
@@ -527,83 +330,15 @@ static void deinit_irq(linux_wlan_t *nic)
 /*
  *      OS functions
  */
-static void linux_wlan_msleep(uint32_t msc)
-{
-       if (msc <= 4000000) {
-               u32 u32Temp = msc * 1000;
-               usleep_range(u32Temp, u32Temp);
-       } else {
-               msleep(msc);
-       }
-}
-
-static void linux_wlan_atomic_msleep(uint32_t msc)
-{
-       mdelay(msc);
-}
-static void linux_wlan_dbg(uint8_t *buff)
+void linux_wlan_dbg(u8 *buff)
 {
        PRINT_D(INIT_DBG, "%d\n", *buff);
 }
 
-static void *linux_wlan_malloc_atomic(uint32_t sz)
-{
-       char *pntr = NULL;
-       pntr = kmalloc(sz, GFP_ATOMIC);
-       PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
-       return (void *)pntr;
-
-}
-static void *linux_wlan_malloc(uint32_t sz)
-{
-       char *pntr = NULL;
-       pntr = kmalloc(sz, GFP_KERNEL);
-       PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", sz, pntr);
-       return (void *)pntr;
-}
-
-void linux_wlan_free(void *vp)
-{
-       if (vp != NULL) {
-               PRINT_D(MEM_DBG, "Freeing %p\n", vp);
-               kfree(vp);
-       }
-}
-
-static void *internal_alloc(uint32_t size, uint32_t flag)
-{
-       char *pntr = NULL;
-       pntr = kmalloc(size, flag);
-       PRINT_D(MEM_DBG, "Allocating %d bytes at address %p\n", size, pntr);
-       return (void *)pntr;
-}
-
-static void linux_wlan_init_lock(char *lockName, void *plock, int count)
-{
-       sema_init((struct semaphore *)plock, count);
-       PRINT_D(LOCK_DBG, "Initializing [%s][%p]\n", lockName, plock);
-
-}
-
-static void linux_wlan_deinit_lock(void *plock)
-{
-       /* mutex_destroy((struct mutex*)plock); */
-}
-
-static void linux_wlan_lock(void *vp)
-{
-       PRINT_D(LOCK_DBG, "Locking %p\n", vp);
-       if (vp != NULL) {
-               while (down_interruptible((struct semaphore *) vp))
-                       ;
-       } else {
-               PRINT_ER("Failed, mutex is NULL\n");
-       }
-}
-
-static int linux_wlan_lock_timeout(void *vp, u32 timeout)
+int linux_wlan_lock_timeout(void *vp, u32 timeout)
 {
        int error = -1;
+
        PRINT_D(LOCK_DBG, "Locking %p\n", vp);
        if (vp != NULL)
                error = down_timeout((struct semaphore *)vp, msecs_to_jiffies(timeout));
@@ -612,113 +347,23 @@ static int linux_wlan_lock_timeout(void *vp, u32 timeout)
        return error;
 }
 
-void linux_wlan_unlock(void *vp)
-{
-       PRINT_D(LOCK_DBG, "Unlocking %p\n", vp);
-       if (vp != NULL)
-               up((struct semaphore *)vp);
-       else
-               PRINT_ER("Failed, mutex is NULL\n");
-}
-
-static void linux_wlan_init_mutex(char *lockName, void *plock, int count)
-{
-       mutex_init((struct mutex *)plock);
-       PRINT_D(LOCK_DBG, "Initializing mutex [%s][%p]\n", lockName, plock);
-
-}
-
-static void linux_wlan_deinit_mutex(void *plock)
-{
-       mutex_destroy((struct mutex *)plock);
-}
-
-static void linux_wlan_lock_mutex(void *vp)
-{
-       PRINT_D(LOCK_DBG, "Locking mutex %p\n", vp);
-       if (vp != NULL) {
-               /*
-                *      if(mutex_is_locked((struct mutex*)vp))
-                *      {
-                *              //PRINT_ER("Mutex already locked - %p \n",vp);
-                *      }
-                */
-               mutex_lock((struct mutex *)vp);
-
-       } else {
-               PRINT_ER("Failed, mutex is NULL\n");
-       }
-}
-
-static void linux_wlan_unlock_mutex(void *vp)
-{
-       PRINT_D(LOCK_DBG, "Unlocking mutex %p\n", vp);
-       if (vp != NULL) {
-
-               if (mutex_is_locked((struct mutex *)vp)) {
-                       mutex_unlock((struct mutex *)vp);
-               } else {
-                       /* PRINT_ER("Mutex already unlocked  - %p\n",vp); */
-               }
-
-       } else {
-               PRINT_ER("Failed, mutex is NULL\n");
-       }
-}
-
-/*Added by Amr - BugID_4720*/
-static void linux_wlan_init_spin_lock(char *lockName, void *plock, int count)
-{
-       spin_lock_init((spinlock_t *)plock);
-       PRINT_D(SPIN_DEBUG, "Initializing mutex [%s][%p]\n", lockName, plock);
-
-}
-
-static void linux_wlan_deinit_spin_lock(void *plock)
-{
-
-}
-static void linux_wlan_spin_lock(void *vp, unsigned long *flags)
-{
-       unsigned long lflags;
-       PRINT_D(SPIN_DEBUG, "Lock spin %p\n", vp);
-       if (vp != NULL) {
-               spin_lock_irqsave((spinlock_t *)vp, lflags);
-               *flags = lflags;
-       } else {
-               PRINT_ER("Failed, spin lock is NULL\n");
-       }
-}
-static void linux_wlan_spin_unlock(void *vp, unsigned long *flags)
-{
-       unsigned long lflags = *flags;
-       PRINT_D(SPIN_DEBUG, "Unlock spin %p\n", vp);
-       if (vp != NULL) {
-               spin_unlock_irqrestore((spinlock_t *)vp, lflags);
-               *flags = lflags;
-       } else {
-               PRINT_ER("Failed, spin lock is NULL\n");
-       }
-}
-
-static void linux_wlan_mac_indicate(int flag)
+void linux_wlan_mac_indicate(struct wilc *wilc, int flag)
 {
        /*I have to do it that way becuase there is no mean to encapsulate device pointer
         * as a parameter
         */
-       linux_wlan_t *pd = g_linux_wlan;
        int status;
 
        if (flag == WILC_MAC_INDICATE_STATUS) {
-               pd->oup.wlan_cfg_get_value(WID_STATUS, (unsigned char *)&status, 4);
-               if (pd->mac_status == WILC_MAC_STATUS_INIT) {
-                       pd->mac_status = status;
-                       linux_wlan_unlock(&pd->sync_event);
+               wilc_wlan_cfg_get_val(WID_STATUS, (unsigned char *)&status, 4);
+               if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
+                       wilc->mac_status = status;
+                       up(&wilc->sync_event);
                } else {
-                       pd->mac_status = status;
+                       wilc->mac_status = status;
                }
 
-               if (pd->mac_status == WILC_MAC_STATUS_CONNECT) {        /* Connect */
+               if (wilc->mac_status == WILC_MAC_STATUS_CONNECT) {        /* Connect */
                }
 
        } else if (flag == WILC_MAC_INDICATE_SCAN) {
@@ -728,92 +373,65 @@ static void linux_wlan_mac_indicate(int flag)
 
 }
 
-struct net_device *GetIfHandler(uint8_t *pMacHeader)
+struct net_device *GetIfHandler(struct wilc *wilc, u8 *pMacHeader)
 {
-       uint8_t *Bssid, *Bssid1;
+       u8 *Bssid, *Bssid1;
        int i = 0;
 
        Bssid  = pMacHeader + 10;
        Bssid1 = pMacHeader + 4;
 
-       for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
-               if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
-                   !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
-                       return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
-               }
-       }
+       for (i = 0; i < wilc->vif_num; i++)
+               if (!memcmp(Bssid1, wilc->vif[i].bssid, ETH_ALEN) ||
+                   !memcmp(Bssid, wilc->vif[i].bssid, ETH_ALEN))
+                       return wilc->vif[i].ndev;
+
        PRINT_INFO(INIT_DBG, "Invalide handle\n");
        for (i = 0; i < 25; i++)
                PRINT_D(INIT_DBG, "%02x ", pMacHeader[i]);
        Bssid  = pMacHeader + 18;
        Bssid1 = pMacHeader + 12;
-       for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
-               if (!memcmp(Bssid1, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN) ||
-                   !memcmp(Bssid, g_linux_wlan->strInterfaceInfo[i].aBSSID, ETH_ALEN)) {
-                       PRINT_D(INIT_DBG, "Ctx [%p]\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
-                       return g_linux_wlan->strInterfaceInfo[i].wilc_netdev;
-               }
-       }
+       for (i = 0; i < wilc->vif_num; i++)
+               if (!memcmp(Bssid1, wilc->vif[i].bssid, ETH_ALEN) ||
+                   !memcmp(Bssid, wilc->vif[i].bssid, ETH_ALEN))
+                       return wilc->vif[i].ndev;
+
        PRINT_INFO(INIT_DBG, "\n");
        return NULL;
 }
 
-int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID)
+int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID)
 {
        int i = 0;
        int ret = -1;
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
 
-       PRINT_D(INIT_DBG, "set bssid on[%p]\n", wilc_netdev);
-       for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
-               if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev == wilc_netdev) {
-                       PRINT_D(INIT_DBG, "set bssid [%x][%x][%x]\n", pBSSID[0], pBSSID[1], pBSSID[2]);
-                       memcpy(g_linux_wlan->strInterfaceInfo[i].aBSSID, pBSSID, 6);
+       nic = netdev_priv(wilc_netdev);
+       wilc = nic->wilc;
+
+       for (i = 0; i < wilc->vif_num; i++)
+               if (wilc->vif[i].ndev == wilc_netdev) {
+                       memcpy(wilc->vif[i].bssid, pBSSID, 6);
                        ret = 0;
                        break;
                }
-       }
+
        return ret;
 }
 
-/*BugID_5213*/
 /*Function to get number of connected interfaces*/
 int linux_wlan_get_num_conn_ifcs(void)
 {
-       uint8_t i = 0;
-       uint8_t null_bssid[6] = {0};
-       uint8_t ret_val = 0;
+       u8 i = 0;
+       u8 null_bssid[6] = {0};
+       u8 ret_val = 0;
 
-       for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
-               if (memcmp(g_linux_wlan->strInterfaceInfo[i].aBSSID, null_bssid, 6))
+       for (i = 0; i < g_linux_wlan->vif_num; i++)
+               if (memcmp(g_linux_wlan->vif[i].bssid, null_bssid, 6))
                        ret_val++;
-       }
-       return ret_val;
-}
-
-static int linux_wlan_rxq_task(void *vp)
-{
-
-       /* inform wilc1000_wlan_init that RXQ task is started. */
-       linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
-       while (1) {
-               linux_wlan_lock(&g_linux_wlan->rxq_event);
-               /* wait_for_completion(&g_linux_wlan->rxq_event); */
-
-               if (g_linux_wlan->close) {
-                       /*Unlock the mutex in the mac_close function to indicate the exiting of the RX thread */
-                       linux_wlan_unlock(&g_linux_wlan->rxq_thread_started);
 
-                       while (!kthread_should_stop())
-                               schedule();
-
-                       PRINT_D(RX_DBG, " RX thread stopped\n");
-                       break;
-               }
-               PRINT_D(RX_DBG, "Calling wlan_handle_rx_que()\n");
-
-               g_linux_wlan->oup.wlan_handle_rx_que();
-       }
-       return 0;
+       return ret_val;
 }
 
 #define USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
@@ -821,7 +439,9 @@ static int linux_wlan_rxq_task(void *vp)
 static int linux_wlan_txq_task(void *vp)
 {
        int ret, txq_count;
-
+       perInterface_wlan_t *nic;
+       struct wilc *wl;
+       struct net_device *dev = vp;
 #if defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
 #define TX_BACKOFF_WEIGHT_INCR_STEP (1)
 #define TX_BACKOFF_WEIGHT_DECR_STEP (1)
@@ -831,18 +451,21 @@ static int linux_wlan_txq_task(void *vp)
        int backoff_weight = TX_BACKOFF_WEIGHT_MIN;
 #endif
 
+       nic = netdev_priv(dev);
+       wl = nic->wilc;
+
        /* inform wilc1000_wlan_init that TXQ task is started. */
-       linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
+       up(&wl->txq_thread_started);
        while (1) {
 
                PRINT_D(TX_DBG, "txq_task Taking a nap :)\n");
-               linux_wlan_lock(&g_linux_wlan->txq_event);
+               down(&wl->txq_event);
                /* wait_for_completion(&pd->txq_event); */
                PRINT_D(TX_DBG, "txq_task Who waked me up :$\n");
 
-               if (g_linux_wlan->close) {
+               if (wl->close) {
                        /*Unlock the mutex in the mac_close function to indicate the exiting of the TX thread */
-                       linux_wlan_unlock(&g_linux_wlan->txq_thread_started);
+                       up(&wl->txq_thread_started);
 
                        while (!kthread_should_stop())
                                schedule();
@@ -852,17 +475,17 @@ static int linux_wlan_txq_task(void *vp)
                }
                PRINT_D(TX_DBG, "txq_task handle the sending packet and let me go to sleep.\n");
 #if !defined USE_TX_BACKOFF_DELAY_IF_NO_BUFFERS
-               g_linux_wlan->oup.wlan_handle_tx_que();
+               ret = wilc_wlan_handle_txq(dev, &txq_count);
 #else
                do {
-                       ret = g_linux_wlan->oup.wlan_handle_tx_que(&txq_count);
+                       ret = wilc_wlan_handle_txq(dev, &txq_count);
                        if (txq_count < FLOW_CONTROL_LOWER_THRESHOLD /* && netif_queue_stopped(pd->wilc_netdev)*/) {
                                PRINT_D(TX_DBG, "Waking up queue\n");
                                /* netif_wake_queue(pd->wilc_netdev); */
-                               if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[0].wilc_netdev))
-                                       netif_wake_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
-                               if (netif_queue_stopped(g_linux_wlan->strInterfaceInfo[1].wilc_netdev))
-                                       netif_wake_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
+                               if (netif_queue_stopped(wl->vif[0].ndev))
+                                       netif_wake_queue(wl->vif[0].ndev);
+                               if (netif_queue_stopped(wl->vif[1].ndev))
+                                       netif_wake_queue(wl->vif[1].ndev);
                        }
 
                        if (ret == WILC_TX_ERR_NO_BUF) { /* failed to allocate buffers in chip. */
@@ -884,13 +507,13 @@ static int linux_wlan_txq_task(void *vp)
                                }
                        }
                        /*TODO: drop packets after a certain time/number of retry count. */
-               } while (ret == WILC_TX_ERR_NO_BUF && !g_linux_wlan->close); /* retry sending packets if no more buffers in chip. */
+               } while (ret == WILC_TX_ERR_NO_BUF && !wl->close); /* retry sending packets if no more buffers in chip. */
 #endif
        }
        return 0;
 }
 
-static void linux_wlan_rx_complete(void)
+void linux_wlan_rx_complete(void)
 {
        PRINT_D(RX_DBG, "RX completed\n");
 }
@@ -908,7 +531,6 @@ int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
        else if (nic->iftype == STATION_MODE)
                firmware = STA_FIRMWARE;
 
-       /*BugID_5137*/
        else {
                PRINT_D(INIT_DBG, "Get P2P_CONCURRENCY_FIRMWARE\n");
                firmware = P2P_CONCURRENCY_FIRMWARE;
@@ -940,7 +562,7 @@ int linux_wlan_get_firmware(perInterface_wlan_t *p_nic)
                goto _fail_;
        }
 #endif
-       g_linux_wlan->wilc_firmware = wilc_firmware; /* Bug 4703 */
+       g_linux_wlan->firmware = wilc_firmware;
 
 _fail_:
 
@@ -948,17 +570,13 @@ _fail_:
 
 }
 
-#ifdef COMPLEMENT_BOOT
-int repeat_power_cycle(perInterface_wlan_t *nic);
-#endif
-
 static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
 {
 
        int ret = 0;
        /* start firmware */
        PRINT_D(INIT_DBG, "Starting Firmware ...\n");
-       ret = g_linux_wlan->oup.wlan_start();
+       ret = wilc_wlan_start();
        if (ret < 0) {
                PRINT_ER("Failed to start Firmware\n");
                goto _fail_;
@@ -968,18 +586,6 @@ static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
        PRINT_D(INIT_DBG, "Waiting for Firmware to get ready ...\n");
        ret = linux_wlan_lock_timeout(&g_linux_wlan->sync_event, 5000);
        if (ret) {
-#ifdef COMPLEMENT_BOOT
-               static int timeout = 5;
-
-               if (timeout--) {
-                       PRINT_D(INIT_DBG, "repeat power cycle[%d]", timeout);
-                       ret = repeat_power_cycle(nic);
-               } else {
-                       timeout = 5;
-                       ret = -1;
-                       goto _fail_;
-               }
-#endif
                PRINT_D(INIT_DBG, "Firmware start timed out");
                goto _fail_;
        }
@@ -992,12 +598,12 @@ static int linux_wlan_start_firmware(perInterface_wlan_t *nic)
 _fail_:
        return ret;
 }
-static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
+static int linux_wlan_firmware_download(struct wilc *p_nic)
 {
 
        int ret = 0;
 
-       if (g_linux_wlan->wilc_firmware == NULL) {
+       if (!g_linux_wlan->firmware) {
                PRINT_ER("Firmware buffer is NULL\n");
                ret = -ENOBUFS;
                goto _FAIL_;
@@ -1006,15 +612,15 @@ static int linux_wlan_firmware_download(linux_wlan_t *p_nic)
         *      do the firmware download
         **/
        PRINT_D(INIT_DBG, "Downloading Firmware ...\n");
-       ret = g_linux_wlan->oup.wlan_firmware_download(g_linux_wlan->wilc_firmware->data, g_linux_wlan->wilc_firmware->size);
+       ret = wilc_wlan_firmware_download(g_linux_wlan->firmware->data,
+                                         g_linux_wlan->firmware->size);
        if (ret < 0)
                goto _FAIL_;
 
        /* Freeing FW buffer */
        PRINT_D(INIT_DBG, "Freeing FW buffer ...\n");
        PRINT_D(INIT_DBG, "Releasing firmware\n");
-       release_firmware(g_linux_wlan->wilc_firmware);
-       g_linux_wlan->wilc_firmware = NULL;
+       release_firmware(g_linux_wlan->firmware);
 
        PRINT_D(INIT_DBG, "Download Succeeded\n");
 
@@ -1023,90 +629,74 @@ _FAIL_:
 }
 
 /* startup configuration - could be changed later using iconfig*/
-static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_nic)
+static int linux_wlan_init_test_config(struct net_device *dev, struct wilc *p_nic)
 {
 
        unsigned char c_val[64];
-       #ifndef STATIC_MACADDRESS
        unsigned char mac_add[] = {0x00, 0x80, 0xC2, 0x5E, 0xa2, 0xff};
-       #endif
 
-       /*BugID_5077*/
-       struct WILC_WFI_priv *priv;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct wilc_priv *priv;
+       struct host_if_drv *pstrWFIDrv;
 
        PRINT_D(TX_DBG, "Start configuring Firmware\n");
-       #ifndef STATIC_MACADDRESS
        get_random_bytes(&mac_add[5], 1);
        get_random_bytes(&mac_add[4], 1);
-       #endif
        priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
        PRINT_D(INIT_DBG, "Host = %p\n", pstrWFIDrv);
 
        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]);
        wilc_get_chipid(0);
 
-       if (g_linux_wlan->oup.wlan_cfg_set == NULL) {
-               PRINT_D(INIT_DBG, "Null p[ointer\n");
-               goto _fail_;
-       }
-
-       *(int *)c_val = (u32)pstrWFIDrv;
+       *(int *)c_val = 1;
 
-       if (!g_linux_wlan->oup.wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
+       if (!wilc_wlan_cfg_set(1, WID_SET_DRV_HANDLER, c_val, 4, 0, 0))
                goto _fail_;
 
        /*to tell fw that we are going to use PC test - WILC specific*/
        c_val[0] = 0;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_PC_TEST_MODE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = INFRASTRUCTURE;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_BSS_TYPE, c_val, 1, 0, 0))
                goto _fail_;
 
-       /* c_val[0] = RATE_AUTO; / * bug 4275: Enable autorate and limit it to 24Mbps * / */
+       /* c_val[0] = RATE_AUTO; */
        c_val[0] = RATE_AUTO;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_CURRENT_TX_RATE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = G_MIXED_11B_2_MODE;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11G_OPERATING_MODE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 1;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_CURRENT_CHANNEL, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = G_SHORT_PREAMBLE;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_PREAMBLE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = AUTO_PROT;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_PROT_MECH, c_val, 1, 0, 0))
                goto _fail_;
 
-#ifdef SWITCH_LOG_TERMINAL
-       c_val[0] = AUTO_PROT;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LOGTerminal_Switch, c_val, 1, 0, 0))
-               goto _fail_;
-#endif
-
        c_val[0] = ACTIVE_SCAN;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_SCAN_TYPE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = SITE_SURVEY_OFF;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_SITE_SURVEY, c_val, 1, 0, 0))
                goto _fail_;
 
        *((int *)c_val) = 0xffff; /* Never use RTS-CTS */
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_RTS_THRESHOLD, c_val, 2, 0, 0))
                goto _fail_;
 
        *((int *)c_val) = 2346;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_FRAG_THRESHOLD, c_val, 2, 0, 0))
                goto _fail_;
 
        /*  SSID                                                                 */
@@ -1116,30 +706,24 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        /*                    ( In BSS Station Set SSID to "" (null string)      */
        /*                      to enable Broadcast SSID suppport )              */
        /*  --------------------------------------------------------------       */
-#ifndef USE_WIRELESS
-       strcpy(c_val, "nwifi");
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SSID, c_val, (strlen(c_val) + 1), 0, 0))
-               goto _fail_;
-#endif
-
        c_val[0] = 0;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_BCAST_SSID, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 1;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_QOS_ENABLE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = NO_POWERSAVE;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_POWER_MANAGEMENT, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = NO_ENCRYPT; /* NO_ENCRYPT, 0x79 */
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11I_MODE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = OPEN_SYSTEM;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_AUTH_TYPE, c_val, 1, 0, 0))
                goto _fail_;
 
        /*  WEP/802 11I Configuration                                            */
@@ -1151,7 +735,7 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        /*  ------------------------------------------------------------------   */
 
        strcpy(c_val, "123456790abcdef1234567890");
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_WEP_KEY_VALUE, c_val, (strlen(c_val) + 1), 0, 0))
                goto _fail_;
 
        /*  WEP/802 11I Configuration                                            */
@@ -1161,7 +745,7 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        /*                  and less than 64 bytes                               */
        /*  ------------------------------------------------------------------   */
        strcpy(c_val, "12345678");
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11I_PSK, c_val, (strlen(c_val)), 0, 0))
                goto _fail_;
 
        /*  IEEE802.1X Key Configuration                                         */
@@ -1171,7 +755,7 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        /*                  and less than 65 bytes                               */
        /*  ------------------------------------------------------------------   */
        strcpy(c_val, "password");
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_1X_KEY, c_val, (strlen(c_val) + 1), 0, 0))
                goto _fail_;
 
        /*   IEEE802.1X Server Address Configuration                             */
@@ -1183,31 +767,31 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        c_val[1] = 168;
        c_val[2] = 1;
        c_val[3] = 112;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_1X_SERV_ADDR, c_val, 4, 0, 0))
                goto _fail_;
 
        c_val[0] = 3;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_LISTEN_INTERVAL, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 3;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_DTIM_PERIOD, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = NORMAL_ACK;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_ACK_POLICY, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 0;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_USER_CONTROL_ON_TX_POWER, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 48;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11A, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 28;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_TX_POWER_LEVEL_11B, c_val, 1, 0, 0))
                goto _fail_;
 
        /*  Beacon Interval                                                      */
@@ -1217,11 +801,11 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        /*  -------------------------------------------------------------------- */
 
        *((int *)c_val) = 100;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_BEACON_INTERVAL, c_val, 2, 0, 0))
                goto _fail_;
 
        c_val[0] = REKEY_DISABLE;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_REKEY_POLICY, c_val, 1, 0, 0))
                goto _fail_;
 
        /*  Rekey Time (s) (Used only when the Rekey policy is 2 or 4)           */
@@ -1230,7 +814,7 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        /*  Values to set : 32-bit value                                         */
        /*  -------------------------------------------------------------------- */
        *((int *)c_val) = 84600;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_REKEY_PERIOD, c_val, 4, 0, 0))
                goto _fail_;
 
        /*  Rekey Packet Count (in 1000s; used when Rekey Policy is 3)           */
@@ -1239,59 +823,59 @@ static int linux_wlan_init_test_config(struct net_device *dev, linux_wlan_t *p_n
        /*  Values to set : 32-bit Value                                         */
        /*  -------------------------------------------------------------------- */
        *((int *)c_val) = 500;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_REKEY_PACKET_COUNT, c_val, 4, 0, 0))
                goto _fail_;
 
        c_val[0] = 1;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_SHORT_SLOT_ALLOWED, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = G_SELF_CTS_PROT;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_ERP_PROT_TYPE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 1;  /* Enable N */
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_ENABLE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = HT_MIXED_MODE;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_OPERATING_MODE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 1;   /* TXOP Prot disable in N mode: No RTS-CTS on TX A-MPDUs to save air-time. */
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_TXOP_PROT_DISABLE, c_val, 1, 0, 0))
                goto _fail_;
 
        memcpy(c_val, mac_add, 6);
 
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_MAC_ADDR, c_val, 6, 0, 0))
                goto _fail_;
 
        /**
         *      AP only
         **/
        c_val[0] = DETECT_PROTECT_REPORT;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_OBSS_NONHT_DETECTION, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = RTS_CTS_NONHT_PROT;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_HT_PROT_TYPE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 0;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_RIFS_PROT_ENABLE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = MIMO_MODE;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_SMPS_MODE, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 7;
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
+       if (!wilc_wlan_cfg_set(0, WID_11N_CURRENT_TX_MCS, c_val, 1, 0, 0))
                goto _fail_;
 
        c_val[0] = 1; /* Enable N with immediate block ack. */
-       if (!g_linux_wlan->oup.wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, (u32)pstrWFIDrv))
+       if (!wilc_wlan_cfg_set(0, WID_11N_IMMEDIATE_BA_ENABLED, c_val, 1, 1, 1))
                goto _fail_;
 
        return 0;
@@ -1301,17 +885,21 @@ _fail_:
 }
 
 /**************************/
-void wilc1000_wlan_deinit(linux_wlan_t *nic)
+void wilc1000_wlan_deinit(struct net_device *dev)
 {
+       perInterface_wlan_t *nic;
+       struct wilc *wl;
 
-       if (g_linux_wlan->wilc1000_initialized) {
+       nic = netdev_priv(dev);
+       wl = nic->wilc;
 
-               printk("Deinitializing wilc1000  ...\n");
+       if (!wl) {
+               netdev_err(dev, "wl is NULL\n");
+               return;
+       }
 
-               if (nic == NULL) {
-                       PRINT_ER("nic is NULL\n");
-                       return;
-               }
+       if (wl->initialized)    {
+               netdev_info(dev, "Deinitializing wilc1000...\n");
 
 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
                /* johnny : remove */
@@ -1321,64 +909,40 @@ void wilc1000_wlan_deinit(linux_wlan_t *nic)
 #endif
 
                PRINT_D(INIT_DBG, "Disabling IRQ\n");
-               #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
-               linux_wlan_disable_irq(IRQ_WAIT);
-               #else
-                 #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
-
-                 #else
-               linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
+#ifdef WILC_SDIO
+               mutex_lock(&wl->hif_cs);
                disable_sdio_interrupt();
-               linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
-                 #endif
-               #endif
-
-               /* not sure if the following unlocks are needed or not*/
-               if (&g_linux_wlan->rxq_event != NULL)
-                       linux_wlan_unlock(&g_linux_wlan->rxq_event);
-
-               if (&g_linux_wlan->txq_event != NULL)
-                       linux_wlan_unlock(&g_linux_wlan->txq_event);
-
-       #if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
-               /*Removing the work struct from the linux kernel workqueue*/
-               if (&g_linux_wlan->rx_work_queue != NULL)
-                       flush_work(&g_linux_wlan->rx_work_queue);
-
-       #elif (RX_BH_TYPE == RX_BH_KTHREAD)
-               /* if(&nic->rx_sem != NULL) */
-               /* linux_wlan_unlock(&nic->rx_sem); */
-       #endif
+               mutex_unlock(&wl->hif_cs);
+#endif
+               if (&wl->txq_event != NULL)
+                       up(&wl->txq_event);
 
                PRINT_D(INIT_DBG, "Deinitializing Threads\n");
-               wlan_deinitialize_threads(nic);
+               wlan_deinitialize_threads(dev);
 
                PRINT_D(INIT_DBG, "Deinitializing IRQ\n");
-               deinit_irq(g_linux_wlan);
+               deinit_irq(dev);
 
-               if (&g_linux_wlan->oup != NULL) {
-                       if (g_linux_wlan->oup.wlan_stop != NULL)
-                               g_linux_wlan->oup.wlan_stop();
-               }
+               wilc_wlan_stop();
 
                PRINT_D(INIT_DBG, "Deinitializing WILC Wlan\n");
-               wilc_wlan_deinit(nic);
+               wilc_wlan_cleanup(dev);
 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
   #if defined(PLAT_ALLWINNER_A20) || defined(PLAT_ALLWINNER_A23) || defined(PLAT_ALLWINNER_A31)
                PRINT_D(INIT_DBG, "Disabling IRQ 2\n");
 
-               linux_wlan_lock_mutex((void *)&g_linux_wlan->hif_cs);
+               mutex_lock(&wl->hif_cs);
                disable_sdio_interrupt();
-               linux_wlan_unlock_mutex((void *)&g_linux_wlan->hif_cs);
+               mutex_unlock(&wl->hif_cs);
   #endif
 #endif
 
                /*De-Initialize locks*/
                PRINT_D(INIT_DBG, "Deinitializing Locks\n");
-               wlan_deinit_locks(g_linux_wlan);
+               wlan_deinit_locks(dev);
 
                /* announce that wilc1000 is not initialized */
-               g_linux_wlan->wilc1000_initialized = 0;
+               wl->initialized = false;
 
                PRINT_D(INIT_DBG, "wilc1000 deinitialization Done\n");
 
@@ -1387,120 +951,56 @@ void wilc1000_wlan_deinit(linux_wlan_t *nic)
        }
 }
 
-int wlan_init_locks(linux_wlan_t *p_nic)
+int wlan_init_locks(struct net_device *dev)
 {
+       perInterface_wlan_t *nic;
+       struct wilc *wl;
 
-       PRINT_D(INIT_DBG, "Initializing Locks ...\n");
-
-       /*initialize mutexes*/
-       linux_wlan_init_mutex("hif_lock/hif_cs", &g_linux_wlan->hif_cs, 1);
-       linux_wlan_init_mutex("rxq_lock/rxq_cs", &g_linux_wlan->rxq_cs, 1);
-       linux_wlan_init_mutex("txq_lock/txq_cs", &g_linux_wlan->txq_cs, 1);
+       nic = netdev_priv(dev);
+       wl = nic->wilc;
 
-       /*Added by Amr - BugID_4720*/
-       linux_wlan_init_spin_lock("txq_spin_lock/txq_cs", &g_linux_wlan->txq_spinlock, 1);
+       PRINT_D(INIT_DBG, "Initializing Locks ...\n");
 
-       /*Added by Amr - BugID_4720*/
-       linux_wlan_init_lock("txq_add_to_head_lock/txq_cs", &g_linux_wlan->txq_add_to_head_cs, 1);
+       mutex_init(&wl->hif_cs);
+       mutex_init(&wl->rxq_cs);
 
-       linux_wlan_init_lock("txq_wait/txq_event", &g_linux_wlan->txq_event, 0);
-       linux_wlan_init_lock("rxq_wait/rxq_event", &g_linux_wlan->rxq_event, 0);
+       spin_lock_init(&wl->txq_spinlock);
+       sema_init(&wl->txq_add_to_head_cs, 1);
 
-       linux_wlan_init_lock("cfg_wait/cfg_event", &g_linux_wlan->cfg_event, 0);
-       linux_wlan_init_lock("sync_event", &g_linux_wlan->sync_event, 0);
+       sema_init(&wl->txq_event, 0);
 
-       linux_wlan_init_lock("rxq_lock/rxq_started", &g_linux_wlan->rxq_thread_started, 0);
-       linux_wlan_init_lock("rxq_lock/txq_started", &g_linux_wlan->txq_thread_started, 0);
+       sema_init(&wl->cfg_event, 0);
+       sema_init(&wl->sync_event, 0);
 
-       #if (RX_BH_TYPE == RX_BH_KTHREAD)
-       linux_wlan_init_lock("BH_SEM", &g_linux_wlan->rx_sem, 0);
-       #endif
+       sema_init(&wl->txq_thread_started, 0);
 
        return 0;
 }
 
-static int wlan_deinit_locks(linux_wlan_t *nic)
+static int wlan_deinit_locks(struct net_device *dev)
 {
-       PRINT_D(INIT_DBG, "De-Initializing Locks\n");
-
-       if (&g_linux_wlan->hif_cs != NULL)
-               linux_wlan_deinit_mutex(&g_linux_wlan->hif_cs);
-
-       if (&g_linux_wlan->rxq_cs != NULL)
-               linux_wlan_deinit_mutex(&g_linux_wlan->rxq_cs);
-
-       if (&g_linux_wlan->txq_cs != NULL)
-               linux_wlan_deinit_mutex(&g_linux_wlan->txq_cs);
-
-       /*Added by Amr - BugID_4720*/
-       if (&g_linux_wlan->txq_spinlock != NULL)
-               linux_wlan_deinit_spin_lock(&g_linux_wlan->txq_spinlock);
-
-       if (&g_linux_wlan->rxq_event != NULL)
-               linux_wlan_deinit_lock(&g_linux_wlan->rxq_event);
-
-       if (&g_linux_wlan->txq_event != NULL)
-               linux_wlan_deinit_lock(&g_linux_wlan->txq_event);
-
-       /*Added by Amr - BugID_4720*/
-       if (&g_linux_wlan->txq_add_to_head_cs != NULL)
-               linux_wlan_deinit_lock(&g_linux_wlan->txq_add_to_head_cs);
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
 
-       if (&g_linux_wlan->rxq_thread_started != NULL)
-               linux_wlan_deinit_lock(&g_linux_wlan->rxq_thread_started);
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
-       if (&g_linux_wlan->txq_thread_started != NULL)
-               linux_wlan_deinit_lock(&g_linux_wlan->txq_thread_started);
+       PRINT_D(INIT_DBG, "De-Initializing Locks\n");
 
-       if (&g_linux_wlan->cfg_event != NULL)
-               linux_wlan_deinit_lock(&g_linux_wlan->cfg_event);
+       if (&wilc->hif_cs != NULL)
+               mutex_destroy(&wilc->hif_cs);
 
-       if (&g_linux_wlan->sync_event != NULL)
-               linux_wlan_deinit_lock(&g_linux_wlan->sync_event);
+       if (&wilc->rxq_cs != NULL)
+               mutex_destroy(&wilc->rxq_cs);
 
        return 0;
 }
-void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
+void linux_to_wlan(wilc_wlan_inp_t *nwi, struct wilc *nic)
 {
 
        PRINT_D(INIT_DBG, "Linux to Wlan services ...\n");
 
-       nwi->os_context.hif_critical_section = (void *)&g_linux_wlan->hif_cs;
        nwi->os_context.os_private = (void *)nic;
-       nwi->os_context.tx_buffer_size = LINUX_TX_SIZE;
-       nwi->os_context.txq_critical_section = (void *)&g_linux_wlan->txq_cs;
-
-       /*Added by Amr - BugID_4720*/
-       nwi->os_context.txq_add_to_head_critical_section = (void *)&g_linux_wlan->txq_add_to_head_cs;
-
-       /*Added by Amr - BugID_4720*/
-       nwi->os_context.txq_spin_lock = (void *)&g_linux_wlan->txq_spinlock;
-
-       nwi->os_context.txq_wait_event = (void *)&g_linux_wlan->txq_event;
-
-#if defined(MEMORY_STATIC)
-       nwi->os_context.rx_buffer_size = LINUX_RX_SIZE;
-#endif
-       nwi->os_context.rxq_critical_section = (void *)&g_linux_wlan->rxq_cs;
-       nwi->os_context.rxq_wait_event = (void *)&g_linux_wlan->rxq_event;
-       nwi->os_context.cfg_wait_event = (void *)&g_linux_wlan->cfg_event;
-
-       nwi->os_func.os_sleep = linux_wlan_msleep;
-       nwi->os_func.os_atomic_sleep = linux_wlan_atomic_msleep;
-       nwi->os_func.os_debug = linux_wlan_dbg;
-       nwi->os_func.os_malloc = linux_wlan_malloc;
-       nwi->os_func.os_malloc_atomic = linux_wlan_malloc_atomic;
-       nwi->os_func.os_free = linux_wlan_free;
-       nwi->os_func.os_lock = linux_wlan_lock;
-       nwi->os_func.os_unlock = linux_wlan_unlock;
-       nwi->os_func.os_wait = linux_wlan_lock_timeout;
-       nwi->os_func.os_signal = linux_wlan_unlock;
-       nwi->os_func.os_enter_cs = linux_wlan_lock_mutex;
-       nwi->os_func.os_leave_cs = linux_wlan_unlock_mutex;
-
-       /*Added by Amr - BugID_4720*/
-       nwi->os_func.os_spin_lock = linux_wlan_spin_lock;
-       nwi->os_func.os_spin_unlock = linux_wlan_spin_unlock;
 
 #ifdef WILC_SDIO
        nwi->io_func.io_type = HIF_SDIO;
@@ -1519,331 +1019,95 @@ void linux_to_wlan(wilc_wlan_inp_t *nwi, linux_wlan_t *nic)
        nwi->io_func.u.spi.spi_trx = linux_spi_write_read;
        nwi->io_func.u.spi.spi_max_speed = linux_spi_set_max_speed;
 #endif
-
-       /*for now - to be revised*/
-       #ifdef WILC_FULLY_HOSTING_AP
-       /* incase of Fully hosted AP, all non cfg pkts are processed here*/
-       nwi->net_func.rx_indicate = WILC_Process_rx_frame;
-       #else
-       nwi->net_func.rx_indicate = frmw_to_linux;
-       #endif
-       nwi->net_func.rx_complete = linux_wlan_rx_complete;
-       nwi->indicate_func.mac_indicate = linux_wlan_mac_indicate;
 }
 
-int wlan_initialize_threads(perInterface_wlan_t *nic)
+int wlan_initialize_threads(struct net_device *dev)
 {
-
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
        int ret = 0;
-       PRINT_D(INIT_DBG, "Initializing Threads ...\n");
-
-#if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
-       /*Initialize rx work queue task*/
-       INIT_WORK(&g_linux_wlan->rx_work_queue, isr_bh_routine);
-#elif (RX_BH_TYPE == RX_BH_KTHREAD)
-       PRINT_D(INIT_DBG, "Creating kthread for Rxq BH\n");
-       g_linux_wlan->rx_bh_thread = kthread_run(isr_bh_routine, (void *)g_linux_wlan, "K_RXQ_BH");
-       if (g_linux_wlan->rx_bh_thread == 0) {
-               PRINT_ER("couldn't create RX BH thread\n");
-               ret = -ENOBUFS;
-               goto _fail_;
-       }
-#endif
-
-#ifndef TCP_ENHANCEMENTS
-       /* create rx task */
-       PRINT_D(INIT_DBG, "Creating kthread for reception\n");
-       g_linux_wlan->rxq_thread = kthread_run(linux_wlan_rxq_task, (void *)g_linux_wlan, "K_RXQ_TASK");
-       if (g_linux_wlan->rxq_thread == 0) {
-               PRINT_ER("couldn't create RXQ thread\n");
-               ret = -ENOBUFS;
-               goto _fail_1;
-       }
 
-       /* wait for RXQ task to start. */
-       linux_wlan_lock(&g_linux_wlan->rxq_thread_started);
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
-#endif
+       PRINT_D(INIT_DBG, "Initializing Threads ...\n");
 
        /* create tx task */
        PRINT_D(INIT_DBG, "Creating kthread for transmission\n");
-       g_linux_wlan->txq_thread = kthread_run(linux_wlan_txq_task, (void *)g_linux_wlan, "K_TXQ_TASK");
-       if (g_linux_wlan->txq_thread == 0) {
-               PRINT_ER("couldn't create TXQ thread\n");
-               ret = -ENOBUFS;
-               goto _fail_2;
-       }
-#ifdef DEBUG_MODE
-       PRINT_D(INIT_DBG, "Creating kthread for Debugging\n");
-       g_linux_wlan->txq_thread = kthread_run(DebuggingThreadTask, (void *)g_linux_wlan, "DebugThread");
-       if (g_linux_wlan->txq_thread == 0) {
+       wilc->txq_thread = kthread_run(linux_wlan_txq_task, (void *)dev,
+                                    "K_TXQ_TASK");
+       if (!wilc->txq_thread) {
                PRINT_ER("couldn't create TXQ thread\n");
                ret = -ENOBUFS;
                goto _fail_2;
        }
-#endif
        /* wait for TXQ task to start. */
-       linux_wlan_lock(&g_linux_wlan->txq_thread_started);
+       down(&wilc->txq_thread_started);
 
        return 0;
 
 _fail_2:
        /*De-Initialize 2nd thread*/
-       g_linux_wlan->close = 1;
-       linux_wlan_unlock(&g_linux_wlan->rxq_event);
-       kthread_stop(g_linux_wlan->rxq_thread);
-
-#ifndef TCP_ENHANCEMENTS
-_fail_1:
-#endif
-       #if (RX_BH_TYPE == RX_BH_KTHREAD)
-       /*De-Initialize 1st thread*/
-       g_linux_wlan->close = 1;
-       linux_wlan_unlock(&g_linux_wlan->rx_sem);
-       kthread_stop(g_linux_wlan->rx_bh_thread);
-_fail_:
-       #endif
-       g_linux_wlan->close = 0;
+       wilc->close = 0;
        return ret;
 }
 
-static void wlan_deinitialize_threads(linux_wlan_t *nic)
-{
-
-       g_linux_wlan->close = 1;
-       PRINT_D(INIT_DBG, "Deinitializing Threads\n");
-       if (&g_linux_wlan->rxq_event != NULL)
-               linux_wlan_unlock(&g_linux_wlan->rxq_event);
-
-       if (g_linux_wlan->rxq_thread != NULL) {
-               kthread_stop(g_linux_wlan->rxq_thread);
-               g_linux_wlan->rxq_thread = NULL;
-       }
-
-       if (&g_linux_wlan->txq_event != NULL)
-               linux_wlan_unlock(&g_linux_wlan->txq_event);
-
-       if (g_linux_wlan->txq_thread != NULL) {
-               kthread_stop(g_linux_wlan->txq_thread);
-               g_linux_wlan->txq_thread = NULL;
-       }
-
-       #if (RX_BH_TYPE == RX_BH_KTHREAD)
-       if (&g_linux_wlan->rx_sem != NULL)
-               linux_wlan_unlock(&g_linux_wlan->rx_sem);
-
-       if (g_linux_wlan->rx_bh_thread != NULL) {
-               kthread_stop(g_linux_wlan->rx_bh_thread);
-               g_linux_wlan->rx_bh_thread = NULL;
-       }
-       #endif
-}
-
-#ifdef STATIC_MACADDRESS
-const char *path_string[] = {
-       "/etc/wlan",
-       "/data/wlan",
-};
-
-static int linux_wlan_read_mac_addr(void *vp)
+static void wlan_deinitialize_threads(struct net_device *dev)
 {
-       int ret = 0;
-       struct file *fp = (struct file *)-ENOENT;
-       mm_segment_t old_fs;
-       loff_t pos = 0;
-       int index;
-       int array_size = ARRAY_SIZE(path_string);
-
-       /* change to KERNEL_DS address limit */
-       old_fs = get_fs();
-       set_fs(KERNEL_DS);
-
-       for (index = 0; index < array_size; index++) {
-               fp = filp_open(path_string[index], O_WRONLY, 0640);
-               if (!fp) {
-                       ret = -1;
-                       goto exit;
-               }
-
-               /*No such file or directory */
-               if (IS_ERR(fp) || !fp->f_op) {
-                       get_random_bytes(&mac_add[3], 3);
-                       /* open file to write */
-                       fp = filp_open(path_string[index], O_WRONLY | O_CREAT, 0640);
-
-                       if (!fp || IS_ERR(fp)) {
-                               ret = -1;
-                               continue;
-                       } else {
-                               /* write buf to file */
-                               fp->f_op->write(fp, mac_add, 6, &pos);
-                               break;
-                       }
-               } else {
-                       /* read file to buf */
-                       fp->f_op->read(fp, mac_add, 6, &pos);
-                       break;
-               }
-       }
-
-       if (index == array_size)
-               PRINT_ER("random MAC\n");
-
-exit:
-       if (fp && !IS_ERR(fp))
-               filp_close(fp, NULL);
-
-       set_fs(old_fs);
-
-       return ret;
-}
-#endif
-
-#ifdef COMPLEMENT_BOOT
-
-extern volatile int probe;
-extern uint8_t core_11b_ready(void);
-
-#define READY_CHECK_THRESHOLD          30
-extern void wilc_wlan_global_reset(void);
-uint8_t wilc1000_prepare_11b_core(wilc_wlan_inp_t *nwi,        wilc_wlan_oup_t *nwo, linux_wlan_t *nic)
-{
-       uint8_t trials = 0;
-       while ((core_11b_ready() && (READY_CHECK_THRESHOLD > (trials++)))) {
-               PRINT_D(INIT_DBG, "11b core not ready yet: %u\n", trials);
-               wilc_wlan_deinit(nic);
-               wilc_wlan_global_reset();
-               sdio_unregister_driver(&wilc_bus);
-
-               linux_wlan_device_detection(0);
-
-               mdelay(100);
-
-               linux_wlan_device_detection(1);
-
-               sdio_register_driver(&wilc_bus);
-
-               while (!probe)
-                       msleep(100);
-               probe = 0;
-               g_linux_wlan->wilc_sdio_func = local_sdio_func;
-               linux_to_wlan(nwi, nic);
-               wilc_wlan_init(nwi, nwo);
-       }
-
-       if (READY_CHECK_THRESHOLD <= trials)
-               return 1;
-       else
-               return 0;
-
-}
-
-int repeat_power_cycle(perInterface_wlan_t *nic)
-{
-       int ret = 0;
-       wilc_wlan_inp_t nwi;
-       wilc_wlan_oup_t nwo;
-       sdio_unregister_driver(&wilc_bus);
-
-       linux_wlan_device_detection(0);
-       linux_wlan_device_power(0);
-       msleep(100);
-       linux_wlan_device_power(1);
-       msleep(80);
-       linux_wlan_device_detection(1);
-       msleep(20);
-
-       sdio_register_driver(&wilc_bus);
+       perInterface_wlan_t *nic;
+       struct wilc *wl;
 
-       /* msleep(1000); */
-       while (!probe)
-               msleep(100);
-       probe = 0;
-       g_linux_wlan->wilc_sdio_func = local_sdio_func;
-       linux_to_wlan(&nwi, g_linux_wlan);
-       ret = wilc_wlan_init(&nwi, &nwo);
+       nic = netdev_priv(dev);
+       wl = nic->wilc;
 
-       g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
-       #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
-       enable_sdio_interrupt();
-       #endif
+       wl->close = 1;
+       PRINT_D(INIT_DBG, "Deinitializing Threads\n");
 
-       if (linux_wlan_get_firmware(nic)) {
-               PRINT_ER("Can't get firmware\n");
-               ret = -1;
-               goto __fail__;
-       }
+       if (&wl->txq_event != NULL)
+               up(&wl->txq_event);
 
-       /*Download firmware*/
-       ret = linux_wlan_firmware_download(g_linux_wlan);
-       if (ret < 0) {
-               PRINT_ER("Failed to download firmware\n");
-               goto __fail__;
+       if (wl->txq_thread != NULL) {
+               kthread_stop(wl->txq_thread);
+               wl->txq_thread = NULL;
        }
-       /* Start firmware*/
-       ret = linux_wlan_start_firmware(nic);
-       if (ret < 0)
-               PRINT_ER("Failed to start firmware\n");
-__fail__:
-       return ret;
 }
-#endif
 
 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
 {
        wilc_wlan_inp_t nwi;
-       wilc_wlan_oup_t nwo;
        perInterface_wlan_t *nic = p_nic;
        int ret = 0;
+       struct wilc *wl = nic->wilc;
 
-       if (!g_linux_wlan->wilc1000_initialized) {
-               g_linux_wlan->mac_status = WILC_MAC_STATUS_INIT;
-               g_linux_wlan->close = 0;
-               g_linux_wlan->wilc1000_initialized = 0;
+       if (!wl->initialized) {
+               wl->mac_status = WILC_MAC_STATUS_INIT;
+               wl->close = 0;
 
-               wlan_init_locks(g_linux_wlan);
+               wlan_init_locks(dev);
 
-#ifdef STATIC_MACADDRESS
-               wilc_mac_thread = kthread_run(linux_wlan_read_mac_addr, NULL, "wilc_mac_thread");
-               if (wilc_mac_thread < 0)
-                       PRINT_ER("couldn't create Mac addr thread\n");
-#endif
+               linux_to_wlan(&nwi, wl);
 
-               linux_to_wlan(&nwi, g_linux_wlan);
-
-               ret = wilc_wlan_init(&nwi, &nwo);
+               ret = wilc_wlan_init(&nwi);
                if (ret < 0) {
                        PRINT_ER("Initializing WILC_Wlan FAILED\n");
                        ret = -EIO;
                        goto _fail_locks_;
                }
-               memcpy(&g_linux_wlan->oup, &nwo, sizeof(wilc_wlan_oup_t));
-
-               /*Save the oup structre into global pointer*/
-               gpstrWlanOps = &g_linux_wlan->oup;
-
-               ret = wlan_initialize_threads(nic);
-               if (ret < 0) {
-                       PRINT_ER("Initializing Threads FAILED\n");
-                       ret = -EIO;
-                       goto _fail_wilc_wlan_;
-               }
 
-#if (defined WILC_SDIO) && (defined COMPLEMENT_BOOT)
-               if (wilc1000_prepare_11b_core(&nwi, &nwo, g_linux_wlan)) {
-                       PRINT_ER("11b Core is not ready\n");
+#if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
+               if (init_irq(dev)) {
+                       PRINT_ER("couldn't initialize IRQ\n");
                        ret = -EIO;
-                       goto _fail_threads_;
+                       goto _fail_locks_;
                }
 #endif
 
-#if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
-               if (init_irq(g_linux_wlan)) {
-                       PRINT_ER("couldn't initialize IRQ\n");
+               ret = wlan_initialize_threads(dev);
+               if (ret < 0) {
+                       PRINT_ER("Initializing Threads FAILED\n");
                        ret = -EIO;
-                       goto _fail_threads_;
+                       goto _fail_wilc_wlan_;
                }
-#endif
 
 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
                if (enable_sdio_interrupt()) {
@@ -1860,7 +1124,7 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
                }
 
                /*Download firmware*/
-               ret = linux_wlan_firmware_download(g_linux_wlan);
+               ret = linux_wlan_firmware_download(wl);
                if (ret < 0) {
                        PRINT_ER("Failed to download firmware\n");
                        ret = -EIO;
@@ -1877,17 +1141,18 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
 
                wilc_bus_set_max_speed();
 
-               if (g_linux_wlan->oup.wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
+               if (wilc_wlan_cfg_get(1, WID_FIRMWARE_VERSION, 1, 0)) {
                        int size;
                        char Firmware_ver[20];
-                       size = g_linux_wlan->oup.wlan_cfg_get_value(
+
+                       size = wilc_wlan_cfg_get_val(
                                        WID_FIRMWARE_VERSION,
                                        Firmware_ver, sizeof(Firmware_ver));
                        Firmware_ver[size] = '\0';
                        PRINT_D(INIT_DBG, "***** Firmware Ver = %s  *******\n", Firmware_ver);
                }
                /* Initialize firmware with default configuration */
-               ret = linux_wlan_init_test_config(dev, g_linux_wlan);
+               ret = linux_wlan_init_test_config(dev, wl);
 
                if (ret < 0) {
                        PRINT_ER("Failed to configure firmware\n");
@@ -1895,14 +1160,11 @@ int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic)
                        goto _fail_fw_start_;
                }
 
-               g_linux_wlan->wilc1000_initialized = 1;
+               wl->initialized = true;
                return 0; /*success*/
 
 _fail_fw_start_:
-               if (&g_linux_wlan->oup != NULL) {
-                       if (g_linux_wlan->oup.wlan_stop != NULL)
-                               g_linux_wlan->oup.wlan_stop();
-               }
+               wilc_wlan_stop();
 
 _fail_irq_enable_:
 #if (defined WILC_SDIO) && (!defined WILC_SDIO_IRQ_GPIO)
@@ -1910,15 +1172,14 @@ _fail_irq_enable_:
 _fail_irq_init_:
 #endif
 #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
-               deinit_irq(g_linux_wlan);
+               deinit_irq(dev);
 
 #endif
-_fail_threads_:
-               wlan_deinitialize_threads(g_linux_wlan);
+               wlan_deinitialize_threads(dev);
 _fail_wilc_wlan_:
-               wilc_wlan_deinit(g_linux_wlan);
+               wilc_wlan_cleanup(dev);
 _fail_locks_:
-               wlan_deinit_locks(g_linux_wlan);
+               wlan_deinit_locks(dev);
                PRINT_ER("WLAN Iinitialization FAILED\n");
        } else {
                PRINT_D(INIT_DBG, "wilc1000 already initialized\n");
@@ -1930,7 +1191,6 @@ _fail_locks_:
  *      - this function will be called automatically by OS when module inserted.
  */
 
-#if !defined(NM73131_0_BOARD)
 int mac_init_fn(struct net_device *ndev)
 {
 
@@ -1940,79 +1200,65 @@ int mac_init_fn(struct net_device *ndev)
 
        return 0;
 }
-#else
-int mac_init_fn(struct net_device *ndev)
-{
-
-       unsigned char mac_add[] = {0x00, 0x50, 0xc2, 0x5e, 0x10, 0x00};
-       /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
-       memcpy(ndev->dev_addr, mac_add, 6);
-
-       if (!is_valid_ether_addr(ndev->dev_addr)) {
-               PRINT_ER("Error: Wrong MAC address\n");
-               return -EINVAL;
-       }
-
-       return 0;
-}
-#endif
-
-void    WILC_WFI_frame_register(struct wiphy *wiphy, struct net_device *dev,
-                               u16 frame_type, bool reg);
 
 /* This fn is called, when this device is setup using ifconfig */
-#if !defined(NM73131_0_BOARD)
 int mac_open(struct net_device *ndev)
 {
        perInterface_wlan_t *nic;
 
-       /*BugID_5213*/
        /*No need for setting mac address here anymore,*/
        /*Just set it in init_test_config()*/
        unsigned char mac_add[ETH_ALEN] = {0};
        int ret = 0;
        int i = 0;
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
+       struct wilc *wl;
+
+       nic = netdev_priv(ndev);
+       wl = nic->wilc;
 
+#ifdef WILC_SPI
+       if (!wl|| !wl->wilc_spidev) {
+               netdev_err(ndev, "wilc1000: SPI device not ready\n");
+               return -ENODEV;
+       }
+#endif
        nic = netdev_priv(ndev);
        priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
        PRINT_D(INIT_DBG, "MAC OPEN[%p]\n", ndev);
 
-       #ifdef USE_WIRELESS
-       ret = WILC_WFI_InitHostInt(ndev);
+       ret = wilc_init_host_int(ndev);
        if (ret < 0) {
                PRINT_ER("Failed to initialize host interface\n");
 
                return ret;
        }
-       #endif
 
        /*initialize platform*/
        PRINT_D(INIT_DBG, "*** re-init ***\n");
        ret = wilc1000_wlan_init(ndev, nic);
        if (ret < 0) {
                PRINT_ER("Failed to initialize wilc1000\n");
-               WILC_WFI_DeInitHostInt(ndev);
+               wilc_deinit_host_int(ndev);
                return ret;
        }
 
-       Set_machw_change_vir_if(false);
+       Set_machw_change_vir_if(ndev, false);
 
        host_int_get_MacAddress(priv->hWILCWFIDrv, mac_add);
-       PRINT_D(INIT_DBG, "Mac address: %x:%x:%x:%x:%x:%x\n", mac_add[0], mac_add[1], mac_add[2],
-               mac_add[3], mac_add[4], mac_add[5]);
+       PRINT_D(INIT_DBG, "Mac address: %pM\n", mac_add);
 
        /* loop through the NUM of supported devices and set the MAC address */
-       for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
-               if (ndev == g_linux_wlan->strInterfaceInfo[i].wilc_netdev) {
-                       memcpy(g_linux_wlan->strInterfaceInfo[i].aSrcAddress, mac_add, ETH_ALEN);
-                       g_linux_wlan->strInterfaceInfo[i].drvHandler = priv->hWILCWFIDrv;
+       for (i = 0; i < wl->vif_num; i++) {
+               if (ndev == wl->vif[i].ndev) {
+                       memcpy(wl->vif[i].src_addr, mac_add, ETH_ALEN);
+                       wl->vif[i].hif_drv = priv->hWILCWFIDrv;
                        break;
                }
        }
 
        /* TODO: get MAC address whenever the source is EPROM - hardcoded and copy it to ndev*/
-       memcpy(ndev->dev_addr, g_linux_wlan->strInterfaceInfo[i].aSrcAddress, ETH_ALEN);
+       memcpy(ndev->dev_addr, wl->vif[i].src_addr, ETH_ALEN);
 
        if (!is_valid_ether_addr(ndev->dev_addr)) {
                PRINT_ER("Error: Wrong MAC address\n");
@@ -2020,39 +1266,20 @@ int mac_open(struct net_device *ndev)
                goto _err_;
        }
 
-       WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
-                               nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
-       WILC_WFI_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev,
-                               nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
+       wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr,
+                                nic->g_struct_frame_reg[0].frame_type, nic->g_struct_frame_reg[0].reg);
+       wilc_mgmt_frame_register(nic->wilc_netdev->ieee80211_ptr->wiphy, nic->wilc_netdev->ieee80211_ptr,
+                                nic->g_struct_frame_reg[1].frame_type, nic->g_struct_frame_reg[1].reg);
        netif_wake_queue(ndev);
-       g_linux_wlan->open_ifcs++;
+       wl->open_ifcs++;
        nic->mac_opened = 1;
        return 0;
 
 _err_:
-       WILC_WFI_DeInitHostInt(ndev);
-       wilc1000_wlan_deinit(g_linux_wlan);
+       wilc_deinit_host_int(ndev);
+       wilc1000_wlan_deinit(ndev);
        return ret;
 }
-#else
-int mac_open(struct net_device *ndev)
-{
-
-       linux_wlan_t *nic;
-       nic = netdev_priv(ndev);
-
-       /*initialize platform*/
-       if (wilc1000_wlan_init(nic)) {
-               PRINT_ER("Failed to initialize platform\n");
-               return 1;
-       }
-       /* Start the network interface queue for this device */
-       PRINT_D(INIT_DBG, "Starting netifQ\n");
-       netif_start_queue(ndev);
-/*     linux_wlan_lock(&close_exit_sync); */
-       return 0;
-}
-#endif
 
 struct net_device_stats *mac_stats(struct net_device *dev)
 {
@@ -2066,11 +1293,12 @@ static void wilc_set_multicast_list(struct net_device *dev)
 {
 
        struct netdev_hw_addr *ha;
-       struct WILC_WFI_priv *priv;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct wilc_priv *priv;
+       struct host_if_drv *pstrWFIDrv;
        int i = 0;
+
        priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
 
        if (!dev)
                return;
@@ -2120,13 +1348,14 @@ static void linux_wlan_tx_complete(void *priv, int status)
 {
 
        struct tx_complete_data *pv_data = (struct tx_complete_data *)priv;
+
        if (status == 1)
                PRINT_D(TX_DBG, "Packet sent successfully - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
        else
                PRINT_D(TX_DBG, "Couldn't send packet - Size = %d - Address = %p - SKB = %p\n", pv_data->size, pv_data->buff, pv_data->skb);
        /* Free the SK Buffer, its work is done */
        dev_kfree_skb(pv_data->skb);
-       linux_wlan_free(pv_data);
+       kfree(pv_data);
 }
 
 int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
@@ -2137,9 +1366,11 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
        char *pu8UdpBuffer;
        struct iphdr *ih;
        struct ethhdr *eth_h;
+       struct wilc *wilc;
+
        nic = netdev_priv(ndev);
+       wilc = nic->wilc;
 
-       PRINT_D(INT_DBG, "\n========\n IntUH: %d - IntBH: %d - IntCld: %d\n========\n", int_rcvdU, int_rcvdB, int_clrd);
        PRINT_D(TX_DBG, "Sending packet just received from TCP/IP\n");
 
        /* Stop the network interface queue */
@@ -2148,7 +1379,7 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
                return 0;
        }
 
-       tx_data = (struct tx_complete_data *)internal_alloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
+       tx_data = kmalloc(sizeof(struct tx_complete_data), GFP_ATOMIC);
        if (tx_data == NULL) {
                PRINT_ER("Failed to allocate memory for tx_data structure\n");
                dev_kfree_skb(skb);
@@ -2181,19 +1412,14 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
        PRINT_D(TX_DBG, "Adding tx packet to TX Queue\n");
        nic->netstats.tx_packets++;
        nic->netstats.tx_bytes += tx_data->size;
-       tx_data->pBssid = g_linux_wlan->strInterfaceInfo[nic->u8IfIdx].aBSSID;
-       #ifndef WILC_FULLY_HOSTING_AP
-       QueueCount = g_linux_wlan->oup.wlan_add_to_tx_que((void *)tx_data,
-                                                         tx_data->buff,
-                                                         tx_data->size,
-                                                         linux_wlan_tx_complete);
-       #else
-       QueueCount = WILC_Xmit_data((void *)tx_data, HOST_TO_WLAN);
-       #endif /* WILC_FULLY_HOSTING_AP */
+       tx_data->pBssid = wilc->vif[nic->u8IfIdx].bssid;
+       QueueCount = wilc_wlan_txq_add_net_pkt(ndev, (void *)tx_data,
+                                              tx_data->buff, tx_data->size,
+                                              linux_wlan_tx_complete);
 
        if (QueueCount > FLOW_CONTROL_UPPER_THRESHOLD) {
-               netif_stop_queue(g_linux_wlan->strInterfaceInfo[0].wilc_netdev);
-               netif_stop_queue(g_linux_wlan->strInterfaceInfo[1].wilc_netdev);
+               netif_stop_queue(wilc->vif[0].ndev);
+               netif_stop_queue(wilc->vif[1].ndev);
        }
 
        return 0;
@@ -2201,9 +1427,10 @@ int mac_xmit(struct sk_buff *skb, struct net_device *ndev)
 
 int mac_close(struct net_device *ndev)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        perInterface_wlan_t *nic;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct host_if_drv *pstrWFIDrv;
+       struct wilc *wl;
 
        nic = netdev_priv(ndev);
 
@@ -2213,18 +1440,19 @@ int mac_close(struct net_device *ndev)
        }
 
        priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
+       wl = nic->wilc;
 
        if (priv == NULL) {
                PRINT_ER("priv = NULL\n");
                return 0;
        }
 
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
 
        PRINT_D(GENERIC_DBG, "Mac close\n");
 
-       if (g_linux_wlan == NULL) {
-               PRINT_ER("g_linux_wlan = NULL\n");
+       if (!wl) {
+               PRINT_ER("wl = NULL\n");
                return 0;
        }
 
@@ -2233,8 +1461,8 @@ int mac_close(struct net_device *ndev)
                return 0;
        }
 
-       if ((g_linux_wlan->open_ifcs) > 0) {
-               g_linux_wlan->open_ifcs--;
+       if ((wl->open_ifcs) > 0) {
+               wl->open_ifcs--;
        } else {
                PRINT_ER("ERROR: MAC close called while number of opened interfaces is zero\n");
                return 0;
@@ -2244,23 +1472,17 @@ int mac_close(struct net_device *ndev)
                /* Stop the network interface queue */
                netif_stop_queue(nic->wilc_netdev);
 
-               #ifdef USE_WIRELESS
-               WILC_WFI_DeInitHostInt(nic->wilc_netdev);
-               #endif
+               wilc_deinit_host_int(nic->wilc_netdev);
        }
 
-       if (g_linux_wlan->open_ifcs == 0) {
+       if (wl->open_ifcs == 0) {
                PRINT_D(GENERIC_DBG, "Deinitializing wilc1000\n");
-               g_linux_wlan->close = 1;
-               wilc1000_wlan_deinit(g_linux_wlan);
-               #ifdef USE_WIRELESS
-               #ifdef WILC_AP_EXTERNAL_MLME
+               wl->close = 1;
+               wilc1000_wlan_deinit(ndev);
                WILC_WFI_deinit_mon_interface();
-               #endif
-               #endif
        }
 
-       linux_wlan_unlock(&close_exit_sync);
+       up(&close_exit_sync);
        nic->mac_opened = 0;
 
        return 0;
@@ -2273,18 +1495,17 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
        s8 rssi;
        u32 size = 0, length = 0;
        perInterface_wlan_t *nic;
-       struct WILC_WFI_priv *priv;
-       s32 s32Error = WILC_SUCCESS;
+       struct wilc_priv *priv;
+       s32 s32Error = 0;
+       struct wilc *wilc;
 
        /* struct iwreq *wrq = (struct iwreq *) req;    // tony moved to case SIOCSIWPRIV */
-       #ifdef USE_WIRELESS
        nic = netdev_priv(ndev);
+       wilc = nic->wilc;
 
-       if (!g_linux_wlan->wilc1000_initialized)
+       if (!wilc->initialized)
                return 0;
 
-       #endif
-
        switch (cmd) {
 
        /* ]] 2013-06-24 */
@@ -2297,19 +1518,14 @@ int mac_ioctl(struct net_device *ndev, struct ifreq *req, int cmd)
                if (size && wrq->u.data.pointer) {
 
                        buff = memdup_user(wrq->u.data.pointer, wrq->u.data.length);
-                       if (IS_ERR(buff)) {
-                               s32Error = PTR_ERR(buff);
-                               goto done;
-                       }
+                       if (IS_ERR(buff))
+                               return PTR_ERR(buff);
 
                        if (strncasecmp(buff, "RSSI", length) == 0) {
-
-                                       #ifdef USE_WIRELESS
                                priv = wiphy_priv(nic->wilc_netdev->ieee80211_ptr->wiphy);
                                s32Error = host_int_get_rssi(priv->hWILCWFIDrv, &(rssi));
                                if (s32Error)
                                        PRINT_ER("Failed to send get rssi param's message queue ");
-                                       #endif
                                PRINT_INFO(GENERIC_DBG, "RSSI :%d\n", rssi);
 
                                /*Rounding up the rssi negative value*/
@@ -2342,21 +1558,17 @@ done:
        return s32Error;
 }
 
-void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
+void frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset)
 {
 
        unsigned int frame_len = 0;
        int stats;
        unsigned char *buff_to_send = NULL;
        struct sk_buff *skb;
-#ifndef TCP_ENHANCEMENTS
-       char *pu8UdpBuffer;
-       struct iphdr *ih;
-#endif
        struct net_device *wilc_netdev;
        perInterface_wlan_t *nic;
 
-       wilc_netdev = GetIfHandler(buff);
+       wilc_netdev = GetIfHandler(wilc, buff);
        if (wilc_netdev == NULL)
                return;
 
@@ -2375,10 +1587,8 @@ void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
                        return;
                }
 
-               skb_reserve(skb, (unsigned int)skb->data & 0x3);
-
-               if (g_linux_wlan == NULL || wilc_netdev == NULL)
-                       PRINT_ER("wilc_netdev in g_linux_wlan is NULL");
+               if (wilc == NULL || wilc_netdev == NULL)
+                       PRINT_ER("wilc_netdev in wilc is NULL");
                skb->dev = wilc_netdev;
 
                if (skb->dev == NULL)
@@ -2399,24 +1609,7 @@ void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
 
                /* nic = netdev_priv(wilc_netdev); */
 
-#ifdef USE_WIRELESS
-               /*      if(nic->monitor_flag)
-                *      {
-                *              WILC_WFI_monitor_rx(nic->wilc_netdev,skb);
-                *              return;
-                *      }*/
-#endif
                skb->protocol = eth_type_trans(skb, wilc_netdev);
-                       #ifndef TCP_ENHANCEMENTS
-               /*get source and dest ip addresses*/
-               ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
-
-               pu8UdpBuffer = (char *)ih + sizeof(struct iphdr);
-               if (buff_to_send[35] == 67 && buff_to_send[37] == 68)
-                       PRINT_D(RX_DBG, "DHCP Message received\n");
-               if (buff_to_send[12] == 0x88 && buff_to_send[13] == 0x8e)
-                       PRINT_D(GENERIC_DBG, "eapol received\n");
-                       #endif
                /* Send the packet to the stack by giving it to the bridge */
                nic->netstats.rx_packets++;
                nic->netstats.rx_bytes += frame_len;
@@ -2424,56 +1617,86 @@ void frmw_to_linux(uint8_t *buff, uint32_t size, uint32_t pkt_offset)
                stats = netif_rx(skb);
                PRINT_D(RX_DBG, "netif_rx ret value is: %d\n", stats);
        }
-               #ifndef TCP_ENHANCEMENTS
-       else
-               PRINT_ER("Discard sending packet with len = %d\n", size);
-               #endif
 }
 
-void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size)
+void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
 {
        int i = 0;
        perInterface_wlan_t *nic;
 
-       /*BugID_5450*/
        /*Pass the frame on the monitor interface, if any.*/
        /*Otherwise, pass it on p2p0 netdev, if registered on it*/
-       for (i = 0; i < g_linux_wlan->u8NoIfcs; i++) {
-               nic = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
+       for (i = 0; i < wilc->vif_num; i++) {
+               nic = netdev_priv(wilc->vif[i].ndev);
                if (nic->monitor_flag) {
                        WILC_WFI_monitor_rx(buff, size);
                        return;
                }
        }
 
-       #ifdef WILC_P2P
-       nic = netdev_priv(g_linux_wlan->strInterfaceInfo[1].wilc_netdev); /* p2p0 */
+       nic = netdev_priv(wilc->vif[1].ndev); /* p2p0 */
        if ((buff[0] == nic->g_struct_frame_reg[0].frame_type && nic->g_struct_frame_reg[0].reg) ||
            (buff[0] == nic->g_struct_frame_reg[1].frame_type && nic->g_struct_frame_reg[1].reg))
-               WILC_WFI_p2p_rx(g_linux_wlan->strInterfaceInfo[1].wilc_netdev, buff, size);
-       #endif
+               WILC_WFI_p2p_rx(wilc->vif[1].ndev, buff, size);
 }
 
-int wilc_netdev_init(void)
+void wl_wlan_cleanup(void)
 {
+       int i = 0;
+       perInterface_wlan_t *nic[NUM_CONCURRENT_IFC];
 
+       if (g_linux_wlan &&
+          (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) {
+               unregister_inetaddr_notifier(&g_dev_notifier);
+
+               for (i = 0; i < NUM_CONCURRENT_IFC; i++)
+                       nic[i] = netdev_priv(g_linux_wlan->vif[i].ndev);
+       }
+
+       if (g_linux_wlan && g_linux_wlan->firmware)
+               release_firmware(g_linux_wlan->firmware);
+
+       if (g_linux_wlan &&
+          (g_linux_wlan->vif[0].ndev || g_linux_wlan->vif[1].ndev)) {
+               linux_wlan_lock_timeout(&close_exit_sync, 12 * 1000);
+
+               for (i = 0; i < NUM_CONCURRENT_IFC; i++)
+                       if (g_linux_wlan->vif[i].ndev)
+                               if (nic[i]->mac_opened)
+                                       mac_close(g_linux_wlan->vif[i].ndev);
+
+               for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
+                       unregister_netdev(g_linux_wlan->vif[i].ndev);
+                       wilc_free_wiphy(g_linux_wlan->vif[i].ndev);
+                       free_netdev(g_linux_wlan->vif[i].ndev);
+               }
+       }
+
+       kfree(g_linux_wlan);
+
+#if defined(WILC_DEBUGFS)
+       wilc_debugfs_remove();
+#endif
+       linux_wlan_device_detection(0);
+       linux_wlan_device_power(0);
+}
+
+int wilc_netdev_init(struct wilc **wilc)
+{
        int i;
        perInterface_wlan_t *nic;
        struct net_device *ndev;
 
-       linux_wlan_init_lock("close_exit_sync", &close_exit_sync, 0);
+       sema_init(&close_exit_sync, 0);
 
        /*create the common structure*/
-       g_linux_wlan = WILC_MALLOC(sizeof(linux_wlan_t));
-       memset(g_linux_wlan, 0, sizeof(linux_wlan_t));
-
-       /*Reset interrupt count debug*/
-       int_rcvdU = 0;
-       int_rcvdB = 0;
-       int_clrd = 0;
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
+       g_linux_wlan = kzalloc(sizeof(*g_linux_wlan), GFP_KERNEL);
+       if (!g_linux_wlan)
+               return -ENOMEM;
+
+       *wilc = g_linux_wlan;
+
        register_inetaddr_notifier(&g_dev_notifier);
-       #endif
 
        for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
                /*allocate first ethernet device with perinterface_wlan_t as its private data*/
@@ -2498,17 +1721,17 @@ int wilc_netdev_init(void)
                } else
                        strcpy(ndev->name, "p2p%d");
 
-               nic->u8IfIdx = g_linux_wlan->u8NoIfcs;
+               nic->u8IfIdx = g_linux_wlan->vif_num;
                nic->wilc_netdev = ndev;
-               g_linux_wlan->strInterfaceInfo[g_linux_wlan->u8NoIfcs].wilc_netdev = ndev;
-               g_linux_wlan->u8NoIfcs++;
+               nic->wilc = *wilc;
+               g_linux_wlan->vif[g_linux_wlan->vif_num].ndev = ndev;
+               g_linux_wlan->vif_num++;
                ndev->netdev_ops = &wilc_netdev_ops;
 
-               #ifdef USE_WIRELESS
                {
                        struct wireless_dev *wdev;
                        /*Register WiFi*/
-                       wdev = WILC_WFI_WiphyRegister(ndev);
+                       wdev = wilc_create_wiphy(ndev);
 
                        #ifdef WILC_SDIO
                        /* set netdev, tony */
@@ -2530,7 +1753,6 @@ int wilc_netdev_init(void)
                        nic->netstats.tx_bytes = 0;
 
                }
-               #endif
 
                if (register_netdev(ndev)) {
                        PRINT_ER("Device couldn't be registered - %s\n", ndev->name);
@@ -2558,6 +1780,10 @@ int wilc_netdev_init(void)
 /*The 1st function called after module inserted*/
 static int __init init_wilc_driver(void)
 {
+#ifdef WILC_SPI
+       struct wilc *wilc;
+#endif
+
 #if defined(WILC_DEBUGFS)
        if (wilc_debugfs_init() < 0) {
                PRINT_D(GENERIC_DBG, "fail to create debugfs for wilc driver\n");
@@ -2584,7 +1810,7 @@ static int __init init_wilc_driver(void)
        }
 #else
        PRINT_D(INIT_DBG, "Initializing netdev\n");
-       if (wilc_netdev_init())
+       if (wilc_netdev_init(&wilc))
                PRINT_ER("Couldn't initialize netdev\n");
        return 0;
 #endif
@@ -2593,84 +1819,13 @@ late_initcall(init_wilc_driver);
 
 static void __exit exit_wilc_driver(void)
 {
-       int i = 0;
-       perInterface_wlan_t *nic[NUM_CONCURRENT_IFC] = {NULL,};
-       #define CLOSE_TIMEOUT (12 * 1000)
-
-       if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
-                                      || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
-               unregister_inetaddr_notifier(&g_dev_notifier);
-       #endif
-
-               for (i = 0; i < NUM_CONCURRENT_IFC; i++)
-                       nic[i] = netdev_priv(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
-       }
-
-       if ((g_linux_wlan != NULL) && g_linux_wlan->wilc_firmware != NULL) {
-               release_firmware(g_linux_wlan->wilc_firmware);
-               g_linux_wlan->wilc_firmware = NULL;
-       }
-
-       if ((g_linux_wlan != NULL) && (((g_linux_wlan->strInterfaceInfo[0].wilc_netdev) != NULL)
-                                      || ((g_linux_wlan->strInterfaceInfo[1].wilc_netdev) != NULL))) {
-               PRINT_D(INIT_DBG, "Waiting for mac_close ....\n");
-
-               if (linux_wlan_lock_timeout(&close_exit_sync, CLOSE_TIMEOUT) < 0)
-                       PRINT_D(INIT_DBG, "Closed TimedOUT\n");
-               else
-                       PRINT_D(INIT_DBG, "mac_closed\n");
-
-               for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
-                       /* close all opened interfaces */
-                       if (g_linux_wlan->strInterfaceInfo[i].wilc_netdev != NULL) {
-                               if (nic[i]->mac_opened)
-                                       mac_close(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
-                       }
-               }
-               for (i = 0; i < NUM_CONCURRENT_IFC; i++) {
-                       PRINT_D(INIT_DBG, "Unregistering netdev %p\n", g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
-                       unregister_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
-                       #ifdef USE_WIRELESS
-                       PRINT_D(INIT_DBG, "Freeing Wiphy...\n");
-                       WILC_WFI_WiphyFree(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
-                       #endif
-                       PRINT_D(INIT_DBG, "Freeing netdev...\n");
-                       free_netdev(g_linux_wlan->strInterfaceInfo[i].wilc_netdev);
-               }
-       }
-
-#ifdef USE_WIRELESS
-#ifdef WILC_AP_EXTERNAL_MLME
-       /* Bug 4600 : WILC_WFI_deinit_mon_interface was already called at mac_close */
-       /* WILC_WFI_deinit_mon_interface(); */
-#endif
-#endif
-
-       /* if(g_linux_wlan->open_ifcs==0) */
-       {
-       #ifndef WILC_SDIO
-               PRINT_D(INIT_DBG, "SPI unregsiter...\n");
-               spi_unregister_driver(&wilc_bus);
-       #else
-               PRINT_D(INIT_DBG, "SDIO unregsiter...\n");
-               sdio_unregister_driver(&wilc_bus);
-       #endif
-
-               linux_wlan_deinit_lock(&close_exit_sync);
-               if (g_linux_wlan != NULL) {
-                       kfree(g_linux_wlan);
-                       g_linux_wlan = NULL;
-               }
-               printk("Module_exit Done.\n");
-
-#if defined(WILC_DEBUGFS)
-               wilc_debugfs_remove();
+#ifndef WILC_SDIO
+       PRINT_D(INIT_DBG, "SPI unregister...\n");
+       spi_unregister_driver(&wilc_bus);
+#else
+       PRINT_D(INIT_DBG, "SDIO unregister...\n");
+       sdio_unregister_driver(&wilc_bus);
 #endif
-
-               linux_wlan_device_detection(0);
-               linux_wlan_device_power(0);
-       }
 }
 module_exit(exit_wilc_driver);
 
index e6ebf3e89129eaf82d4059c856e0ac7571d192da..2b76e41ebd4d506ec0fc85002b51acaa6a98b5ed 100644 (file)
@@ -12,7 +12,6 @@ enum debug_region {
        RX_debug,
        Lock_debug,
        Tcp_enhance,
-       /*Added by amr - BugID_4720*/
        Spin_debug,
 
        Init_debug,
@@ -45,10 +44,10 @@ void wilc_debugfs_remove(void);
 extern atomic_t REGION;
 extern atomic_t DEBUG_LEVEL;
 
-#define DEBUG           (1 << 0)
-#define INFO            (1 << 1)
-#define WRN             (1 << 2)
-#define ERR             (1 << 3)
+#define DEBUG           BIT(0)
+#define INFO            BIT(1)
+#define WRN             BIT(2)
+#define ERR             BIT(3)
 
 #define PRINT_D(region, ...)                                           \
        do {                                                            \
@@ -135,12 +134,7 @@ extern atomic_t DEBUG_LEVEL;
 
 #define WILC_MULTICAST_TABLE_SIZE      8
 
-#if defined (NM73131_0_BOARD)
-
-#define MODALIAS "wilc_spi"
-#define GPIO_NUM       IRQ_WILC1000_GPIO
-
-#elif defined (BEAGLE_BOARD)
+#if defined (BEAGLE_BOARD)
        #define SPI_CHANNEL     4
 
        #if SPI_CHANNEL == 4
@@ -150,9 +144,6 @@ extern atomic_t DEBUG_LEVEL;
                #define MODALIAS        "wilc_spi3"
                #define GPIO_NUM        133
        #endif
-#elif defined(PANDA_BOARD)
-       #define MODALIAS        "WILC_SPI"
-       #define GPIO_NUM        139
 #elif defined(PLAT_WMS8304)             /* rachel */
        #define MODALIAS        "wilc_spi"
        #define GPIO_NUM        139
@@ -176,7 +167,4 @@ extern atomic_t DEBUG_LEVEL;
        #define MODALIAS        "WILC_SPI"
        #define GPIO_NUM        0x44
 #endif
-
-
-void linux_wlan_enable_irq(void);
 #endif
index 37f31f4558b5cb3b4325f0d1a9405d124c5a367c..4aff953a88f167880959ee12973bc11deecec734 100644 (file)
@@ -8,15 +8,9 @@
 
 
 
-#if defined (NM73131_0_BOARD)
-#define SDIO_MODALIAS "wilc_sdio"
-#else
 #define SDIO_MODALIAS "wilc1000_sdio"
-#endif
 
-#if defined (NM73131_0_BOARD)
- #define MAX_SPEED 50000000
-#elif defined(CUSTOMER_PLATFORM)
+#if defined(CUSTOMER_PLATFORM)
 /* TODO : User have to stable bus clock as user's environment. */
  #ifdef MAX_BUS_SPEED
  #define MAX_SPEED MAX_BUS_SPEED
  #define MAX_SPEED (6 * 1000000) /* Max 50M */
 #endif
 
+struct wilc_sdio {
+       struct sdio_func *func;
+       struct wilc *wilc;
+};
 
 struct sdio_func *local_sdio_func;
-extern linux_wlan_t *g_linux_wlan;
-extern int wilc_netdev_init(void);
-extern void wilc_handle_isr(void);
 
 static unsigned int sdio_default_speed;
 
@@ -40,14 +35,19 @@ static unsigned int sdio_default_speed;
 
 static const struct sdio_device_id wilc_sdio_ids[] = {
        { SDIO_DEVICE(SDIO_VENDOR_ID_WILC, SDIO_DEVICE_ID_WILC) },
+       { },
 };
 
 
 static void wilc_sdio_interrupt(struct sdio_func *func)
 {
+       struct wilc_sdio *wl_sdio;
+
+       wl_sdio = sdio_get_drvdata(func);
+
 #ifndef WILC_SDIO_IRQ_GPIO
        sdio_release_host(func);
-       wilc_handle_isr();
+       wilc_handle_isr(wl_sdio->wilc);
        sdio_claim_host(func);
 #endif
 }
@@ -116,25 +116,26 @@ int linux_sdio_cmd53(sdio_cmd53_t *cmd)
        return 1;
 }
 
-volatile int probe; /* COMPLEMENT_BOOT */
 static int linux_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id)
 {
+       struct wilc_sdio *wl_sdio;
+       struct wilc *wilc;
+
        PRINT_D(INIT_DBG, "probe function\n");
+       wl_sdio = kzalloc(sizeof(struct wilc_sdio), GFP_KERNEL);
+       if (!wl_sdio)
+               return -ENOMEM;
 
-#ifdef COMPLEMENT_BOOT
-       if (local_sdio_func != NULL) {
-               local_sdio_func = func;
-               probe = 1;
-               PRINT_D(INIT_DBG, "local_sdio_func isn't NULL\n");
-               return 0;
-       }
-#endif
        PRINT_D(INIT_DBG, "Initializing netdev\n");
        local_sdio_func = func;
-       if (wilc_netdev_init()) {
+       if (wilc_netdev_init(&wilc)) {
                PRINT_ER("Couldn't initialize netdev\n");
+               kfree(wl_sdio);
                return -1;
        }
+       wl_sdio->func = func;
+       wl_sdio->wilc = wilc;
+       sdio_set_drvdata(func, wl_sdio);
 
        printk("Driver Initializing success\n");
        return 0;
@@ -142,10 +143,11 @@ static int linux_sdio_probe(struct sdio_func *func, const struct sdio_device_id
 
 static void linux_sdio_remove(struct sdio_func *func)
 {
-       /**
-        *      TODO
-        **/
+       struct wilc_sdio *wl_sdio;
 
+       wl_sdio = sdio_get_drvdata(func);
+       wl_wlan_cleanup();
+       kfree(wl_sdio);
 }
 
 struct sdio_driver wilc_bus = {
@@ -194,6 +196,7 @@ void disable_sdio_interrupt(void)
 static int linux_sdio_set_speed(int speed)
 {
        struct mmc_ios ios;
+
        sdio_claim_host(local_sdio_func);
 
        memcpy((void *)&ios, (void *)&local_sdio_func->card->host->ios, sizeof(struct mmc_ios));
index 236669cfcd3aed93e1eb190b8f4675979b11d2f8..039d06192d6b1af853e97207a1a11ccb642cb828 100644 (file)
@@ -5,11 +5,12 @@
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/cdev.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include <linux/device.h>
 #include <linux/spi/spi.h>
 
 #include "linux_wlan_common.h"
+#include "linux_wlan_spi.h"
 
 #define USE_SPI_DMA     0       /* johnny add */
 
@@ -38,7 +39,7 @@
  #define MAX_SPEED 6000000
 #endif /* WILC_ASIC_A0 */
 
-static uint32_t SPEED = MIN_SPEED;
+static u32 SPEED = MIN_SPEED;
 
 struct spi_device *wilc_spi_dev;
 void linux_spi_deinit(void *vp);
@@ -113,57 +114,20 @@ int linux_spi_init(void *vp)
 #define TXRX_PHASE_SIZE (4096)
 #endif
 
-#if defined (NM73131_0_BOARD)
+#if defined(TXRX_PHASE_SIZE)
 
-int linux_spi_write(uint8_t *b, uint32_t len)
+int linux_spi_write(u8 *b, u32 len)
 {
-
        int ret;
 
-       if (len > 0 && b != NULL) {
-               struct spi_message msg;
-               PRINT_D(BUS_DBG, "Request writing %d bytes\n", len);
-               struct spi_transfer tr = {
-                       .tx_buf = b,
-                       .len = len,
-                       .speed_hz = SPEED,
-                       .delay_usecs = 0,
-               };
-
-               spi_message_init(&msg);
-               spi_message_add_tail(&tr, &msg);
-               ret = spi_sync(wilc_spi_dev, &msg);
-               if (ret < 0) {
-                       PRINT_ER("SPI transaction failed\n");
-               }
-
-       } else {
-               PRINT_ER("can't write data with the following length: %d\n", len);
-               PRINT_ER("FAILED due to NULL buffer or ZERO length check the following length: %d\n", len);
-               ret = -1;
-       }
-
-       /* change return value to match WILC interface */
-       (ret < 0) ? (ret = 0) : (ret = 1);
-
-
-       return ret;
-}
-
-#elif defined(TXRX_PHASE_SIZE)
-
-int linux_spi_write(uint8_t *b, uint32_t len)
-{
-       int ret;
        if (len > 0 && b != NULL) {
                int i = 0;
                int blk = len / TXRX_PHASE_SIZE;
                int remainder = len % TXRX_PHASE_SIZE;
 
                char *r_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL);
-               if (!r_buffer) {
-                       PRINT_ER("Failed to allocate memory for r_buffer\n");
-               }
+               if (!r_buffer)
+                       return -ENOMEM;
 
                if (blk) {
                        while (i < blk) {
@@ -229,7 +193,7 @@ int linux_spi_write(uint8_t *b, uint32_t len)
 }
 
 #else
-int linux_spi_write(uint8_t *b, uint32_t len)
+int linux_spi_write(u8 *b, u32 len)
 {
 
        int ret;
@@ -243,9 +207,9 @@ int linux_spi_write(uint8_t *b, uint32_t len)
                        .delay_usecs = 0,
                };
                char *r_buffer = kzalloc(len, GFP_KERNEL);
-               if (!r_buffer) {
-                       PRINT_ER("Failed to allocate memory for r_buffer\n");
-               }
+               if (!r_buffer)
+                       return -ENOMEM;
+
                tr.rx_buf = r_buffer;
                PRINT_D(BUS_DBG, "Request writing %d bytes\n", len);
 
@@ -278,42 +242,9 @@ int linux_spi_write(uint8_t *b, uint32_t len)
 
 #endif
 
-#if defined (NM73131_0_BOARD)
+#if defined(TXRX_PHASE_SIZE)
 
-int linux_spi_read(unsigned char *rb, unsigned long rlen)
-{
-
-       int ret;
-
-       if (rlen > 0) {
-               struct spi_message msg;
-               struct spi_transfer tr = {
-                       .rx_buf = rb,
-                       .len = rlen,
-                       .speed_hz = SPEED,
-                       .delay_usecs = 0,
-
-               };
-
-               spi_message_init(&msg);
-               spi_message_add_tail(&tr, &msg);
-               ret = spi_sync(wilc_spi_dev, &msg);
-               if (ret < 0) {
-                       PRINT_ER("SPI transaction failed\n");
-               }
-       } else {
-               PRINT_ER("can't read data with the following length: %ld\n", rlen);
-               ret = -1;
-       }
-       /* change return value to match WILC interface */
-       (ret < 0) ? (ret = 0) : (ret = 1);
-
-       return ret;
-}
-
-#elif defined(TXRX_PHASE_SIZE)
-
-int linux_spi_read(unsigned char *rb, unsigned long rlen)
+int linux_spi_read(u8 *rb, u32 rlen)
 {
        int ret;
 
@@ -324,9 +255,8 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
                int remainder = rlen % TXRX_PHASE_SIZE;
 
                char *t_buffer = kzalloc(TXRX_PHASE_SIZE, GFP_KERNEL);
-               if (!t_buffer) {
-                       PRINT_ER("Failed to allocate memory for t_buffer\n");
-               }
+               if (!t_buffer)
+                       return -ENOMEM;
 
                if (blk) {
                        while (i < blk) {
@@ -378,7 +308,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
 
                kfree(t_buffer);
        } else {
-               PRINT_ER("can't read data with the following length: %ld\n", rlen);
+               PRINT_ER("can't read data with the following length: %u\n", rlen);
                ret = -1;
        }
        /* change return value to match WILC interface */
@@ -388,7 +318,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
 }
 
 #else
-int linux_spi_read(unsigned char *rb, unsigned long rlen)
+int linux_spi_read(u8 *rb, u32 rlen)
 {
 
        int ret;
@@ -403,9 +333,9 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
 
                };
                char *t_buffer = kzalloc(rlen, GFP_KERNEL);
-               if (!t_buffer) {
-                       PRINT_ER("Failed to allocate memory for t_buffer\n");
-               }
+               if (!t_buffer)
+                       return -ENOMEM;
+
                tr.tx_buf = t_buffer;
 
                memset(&msg, 0, sizeof(msg));
@@ -422,7 +352,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
                }
                kfree(t_buffer);
        } else {
-               PRINT_ER("can't read data with the following length: %ld\n", rlen);
+               PRINT_ER("can't read data with the following length: %u\n", rlen);
                ret = -1;
        }
        /* change return value to match WILC interface */
@@ -433,7 +363,7 @@ int linux_spi_read(unsigned char *rb, unsigned long rlen)
 
 #endif
 
-int linux_spi_write_read(unsigned char *wb, unsigned char *rb, unsigned int rlen)
+int linux_spi_write_read(u8 *wb, u8 *rb, u32 rlen)
 {
 
        int ret;
@@ -461,7 +391,7 @@ int linux_spi_write_read(unsigned char *wb, unsigned char *rb, unsigned int rlen
                        PRINT_ER("SPI transaction failed\n");
                }
        } else {
-               PRINT_ER("can't read data with the following length: %d\n", rlen);
+               PRINT_ER("can't read data with the following length: %u\n", rlen);
                ret = -1;
        }
        /* change return value to match WILC interface */
index 0ecad477de1c5f72126b68923a6515dc04a20890..7356785296f9fff8c5fa12c35b9c9d96088edde0 100644 (file)
@@ -7,8 +7,8 @@ extern struct spi_driver wilc_bus;
 
 int linux_spi_init(void *vp);
 void linux_spi_deinit(void *vp);
-int linux_spi_write(uint8_t *b, uint32_t len);
-int linux_spi_read(uint8_t *rb, uint32_t rlen);
-int linux_spi_write_read(unsigned char *wb, unsigned char *rb, unsigned int rlen);
+int linux_spi_write(u8 *b, u32 len);
+int linux_spi_read(u8 *rb, u32 rlen);
+int linux_spi_write_read(u8 *wb, u8 *rb, u32 rlen);
 int linux_spi_set_max_speed(void);
 #endif
diff --git a/drivers/staging/wilc1000/wilc_errorsupport.h b/drivers/staging/wilc1000/wilc_errorsupport.h
deleted file mode 100644 (file)
index b9517dc..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-#ifndef __WILC_ERRORSUPPORT_H__
-#define __WILC_ERRORSUPPORT_H__
-
-/*!
- *  @file              wilc_errorsupport.h
- *  @brief             Error reporting and handling support
- *  @author            syounan
- *  @sa                        wilc_oswrapper.h top level OS wrapper file
- *  @date              10 Aug 2010
- *  @version           1.0
- */
-
-#include "linux_wlan_common.h"
-
-/* Psitive Numbers to indicate sucess with special status */
-#define WILC_ALREADY_EXSIT     (+100)    /** The requested object already exists */
-
-/* Generic success will return 0 */
-#define WILC_SUCCESS   0       /** Generic success */
-
-/* Negative numbers to indicate failures */
-#define WILC_FAIL                      -100 /** Generic Fail */
-#define WILC_BUSY                      -101 /** Busy with another operation*/
-#define WILC_INVALID_ARGUMENT          -102 /** A given argument is invalid*/
-#define WILC_INVALID_STATE             -103 /** An API request would violate the Driver state machine (i.e. to start PID while not camped)*/
-#define WILC_BUFFER_OVERFLOW           -104 /** In copy operations if the copied data is larger than the allocated buffer*/
-#define WILC_NULL_PTR                  -105 /** null pointer is passed or used */
-#define WILC_EMPTY                     -107
-#define WILC_FULL                      -108
-#define WILC_TIMEOUT                   -109
-#define WILC_CANCELED                  -110 /** The required operation have been canceled by the user*/
-#define WILC_INVALID_FILE              -112 /** The Loaded file is corruped or having an invalid format */
-#define WILC_NOT_FOUND                 -113 /** Cant find the file to load */
-#define WILC_NO_MEM                    -114
-#define WILC_UNSUPPORTED_VERSION       -115
-#define WILC_FILE_EOF                  -116
-
-
-/* Error type */
-typedef s32 WILC_ErrNo;
-
-#define WILC_IS_ERR(__status__) (__status__ < WILC_SUCCESS)
-
-#define WILC_ERRORCHECK(__status__) do { \
-               if (WILC_IS_ERR(__status__)) { \
-                       PRINT_ER("PRINT_ER(%d)\n", __status__); \
-                       goto ERRORHANDLER; \
-               } \
-} while (0)
-
-#define WILC_ERRORREPORT(__status__, __err__) do { \
-               PRINT_ER("PRINT_ER(%d)\n", __err__); \
-               __status__ = __err__; \
-               goto ERRORHANDLER; \
-} while (0)
-
-#define  WILC_NULLCHECK(__status__, __ptr__)   do { \
-               if (__ptr__ == NULL) { \
-                       WILC_ERRORREPORT(__status__, WILC_NULL_PTR); \
-               } \
-} while (0)
-
-#define WILC_CATCH(__status__) \
-ERRORHANDLER: \
-       if (WILC_IS_ERR(__status__)) \
-
-#endif
diff --git a/drivers/staging/wilc1000/wilc_exported_buf.c b/drivers/staging/wilc1000/wilc_exported_buf.c
deleted file mode 100644 (file)
index c3f6a0a..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/slab.h>
-
-#define LINUX_RX_SIZE  (96 * 1024)
-#define LINUX_TX_SIZE  (64 * 1024)
-#define WILC1000_FW_SIZE (4 * 1024)
-
-#define MALLOC_WILC_BUFFER(name, size) \
-       exported_ ## name = kmalloc(size, GFP_KERNEL);    \
-       if (!exported_ ## name) {   \
-               printk("fail to alloc: %s memory\n", exported_ ## name);  \
-               return -ENOBUFS;        \
-       }
-
-#define FREE_WILC_BUFFER(name) \
-       kfree(exported_ ## name);
-
-/*
- * Add necessary buffer pointers
- */
-void *exported_g_tx_buf;
-void *exported_g_rx_buf;
-void *exported_g_fw_buf;
-
-void *get_tx_buffer(void)
-{
-       return exported_g_tx_buf;
-}
-EXPORT_SYMBOL(get_tx_buffer);
-
-void *get_rx_buffer(void)
-{
-       return exported_g_rx_buf;
-}
-EXPORT_SYMBOL(get_rx_buffer);
-
-void *get_fw_buffer(void)
-{
-       return exported_g_fw_buf;
-}
-EXPORT_SYMBOL(get_fw_buffer);
-
-static int __init wilc_module_init(void)
-{
-       printk("wilc_module_init\n");
-       /*
-        * alloc necessary memory
-        */
-       MALLOC_WILC_BUFFER(g_tx_buf, LINUX_TX_SIZE)
-       MALLOC_WILC_BUFFER(g_rx_buf, LINUX_RX_SIZE)
-       MALLOC_WILC_BUFFER(g_fw_buf, WILC1000_FW_SIZE)
-
-       return 0;
-}
-
-static void __exit wilc_module_deinit(void)
-{
-       printk("wilc_module_deinit\n");
-       FREE_WILC_BUFFER(g_tx_buf)
-       FREE_WILC_BUFFER(g_rx_buf)
-       FREE_WILC_BUFFER(g_fw_buf)
-}
-
-MODULE_LICENSE("Dual BSD/GPL");
-MODULE_AUTHOR("Tony Cho");
-MODULE_DESCRIPTION("WILC1xxx Memory Manager");
-pure_initcall(wilc_module_init);
-module_exit(wilc_module_deinit);
diff --git a/drivers/staging/wilc1000/wilc_memory.c b/drivers/staging/wilc1000/wilc_memory.c
deleted file mode 100644 (file)
index e90a957..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-
-#include "wilc_memory.h"
-
-/*!
- *  @author    syounan
- *  @date      18 Aug 2010
- *  @version   1.0
- */
-void *WILC_MemoryAlloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
-                      char *pcFileName, u32 u32LineNo)
-{
-       if (u32Size > 0)
-               return kmalloc(u32Size, GFP_ATOMIC);
-       else
-               return NULL;
-}
diff --git a/drivers/staging/wilc1000/wilc_memory.h b/drivers/staging/wilc1000/wilc_memory.h
deleted file mode 100644 (file)
index f19cec1..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-#ifndef __WILC_MEMORY_H__
-#define __WILC_MEMORY_H__
-
-/*!
- *  @file      wilc_memory.h
- *  @brief     Memory OS wrapper functionality
- *  @author    syounan
- *  @sa                wilc_oswrapper.h top level OS wrapper file
- *  @date      16 Aug 2010
- *  @version   1.0
- */
-
-#include <linux/types.h>
-#include <linux/slab.h>
-
-/*!
- *  @struct             tstrWILC_MemoryAttrs
- *  @brief             Memory API options
- *  @author            syounan
- *  @date              16 Aug 2010
- *  @version           1.0
- */
-typedef struct {
-} tstrWILC_MemoryAttrs;
-
-/*!
- *  @brief     Allocates a given size of bytes
- *  @param[in] u32Size size of memory in bytes to be allocated
- *  @param[in] strAttrs Optional attributes, NULL for default
- *              if not NULL, pAllocationPool should point to the pool to use for
- *              this allocation. if NULL memory will be allocated directly from
- *              the system
- *  @param[in] pcFileName file name of the calling code for debugging
- *  @param[in] u32LineNo line number of the calling code for debugging
- *  @return    The new allocated block, NULL if allocation fails
- *  @note      It is recommended to use of of the wrapper macros instead of
- *              calling this function directly
- *  @sa                sttrWILC_MemoryAttrs
- *  @sa                WILC_MALLOC
- *  @sa                WILC_MALLOC_EX
- *  @author    syounan
- *  @date      16 Aug 2010
- *  @version   1.0
- */
-void *WILC_MemoryAlloc(u32 u32Size, tstrWILC_MemoryAttrs *strAttrs,
-                      char *pcFileName, u32 u32LineNo);
-
-/*!
- * @brief      standrad malloc wrapper with custom attributes
- */
-       #define WILC_MALLOC_EX(__size__, __attrs__) \
-       (WILC_MemoryAlloc( \
-                (__size__), __attrs__, NULL, 0))
-
-
-/*!
- * @brief      standrad malloc wrapper with default attributes
- */
-#define WILC_MALLOC(__size__) \
-       WILC_MALLOC_EX(__size__, NULL)
-
-
-
-
-
-#endif
index 70e4fa6a07a65969af35529745d5c38d56399c81..0eff121b8291eeefaa7773eb8970d39d959880f3 100644 (file)
@@ -1,6 +1,9 @@
 
 #include "wilc_msgqueue.h"
 #include <linux/spinlock.h>
+#include "linux_wlan_common.h"
+#include <linux/errno.h>
+#include <linux/slab.h>
 
 /*!
  *  @author            syounan
  *  @note              copied from FLO glue implementatuion
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle)
+int wilc_mq_create(WILC_MsgQueueHandle *pHandle)
 {
        spin_lock_init(&pHandle->strCriticalSection);
        sema_init(&pHandle->hSem, 0);
        pHandle->pstrMessageList = NULL;
        pHandle->u32ReceiversCount = 0;
        pHandle->bExiting = false;
-       return WILC_SUCCESS;
+       return 0;
 }
 
 /*!
@@ -24,24 +27,24 @@ WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle)
  *  @note              copied from FLO glue implementatuion
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle)
+int wilc_mq_destroy(WILC_MsgQueueHandle *pHandle)
 {
-
        pHandle->bExiting = true;
 
        /* Release any waiting receiver thread. */
        while (pHandle->u32ReceiversCount > 0) {
-               up(&(pHandle->hSem));
+               up(&pHandle->hSem);
                pHandle->u32ReceiversCount--;
        }
 
-       while (pHandle->pstrMessageList != NULL) {
+       while (pHandle->pstrMessageList) {
                Message *pstrMessge = pHandle->pstrMessageList->pstrNext;
+
                kfree(pHandle->pstrMessageList);
                pHandle->pstrMessageList = pstrMessge;
        }
 
-       return WILC_SUCCESS;
+       return 0;
 }
 
 /*!
@@ -50,41 +53,47 @@ WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle)
  *  @note              copied from FLO glue implementatuion
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
+int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
                             const void *pvSendBuffer, u32 u32SendBufferSize)
 {
-       WILC_ErrNo s32RetStatus = WILC_SUCCESS;
        unsigned long flags;
        Message *pstrMessage = NULL;
 
-       if ((pHandle == NULL) || (u32SendBufferSize == 0) || (pvSendBuffer == NULL)) {
-               WILC_ERRORREPORT(s32RetStatus, WILC_INVALID_ARGUMENT);
+       if ((!pHandle) || (u32SendBufferSize == 0) || (!pvSendBuffer)) {
+               PRINT_ER("pHandle or pvSendBuffer is null\n");
+               return -EFAULT;
        }
 
-       if (pHandle->bExiting == true) {
-               WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
+       if (pHandle->bExiting) {
+               PRINT_ER("pHandle fail\n");
+               return -EFAULT;
        }
 
-       spin_lock_irqsave(&pHandle->strCriticalSection, flags);
-
        /* construct a new message */
        pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC);
-       WILC_NULLCHECK(s32RetStatus, pstrMessage);
+       if (!pstrMessage)
+               return -ENOMEM;
+
        pstrMessage->u32Length = u32SendBufferSize;
        pstrMessage->pstrNext = NULL;
-       pstrMessage->pvBuffer = WILC_MALLOC(u32SendBufferSize);
-       WILC_NULLCHECK(s32RetStatus, pstrMessage->pvBuffer);
-       memcpy(pstrMessage->pvBuffer, pvSendBuffer, u32SendBufferSize);
+       pstrMessage->pvBuffer = kmemdup(pvSendBuffer, u32SendBufferSize,
+                                       GFP_ATOMIC);
+       if (!pstrMessage->pvBuffer) {
+               kfree(pstrMessage);
+               return -ENOMEM;
+       }
 
+       spin_lock_irqsave(&pHandle->strCriticalSection, flags);
 
        /* add it to the message queue */
-       if (pHandle->pstrMessageList == NULL) {
+       if (!pHandle->pstrMessageList) {
                pHandle->pstrMessageList  = pstrMessage;
        } else {
                Message *pstrTailMsg = pHandle->pstrMessageList;
-               while (pstrTailMsg->pstrNext != NULL) {
+
+               while (pstrTailMsg->pstrNext)
                        pstrTailMsg = pstrTailMsg->pstrNext;
-               }
+
                pstrTailMsg->pstrNext = pstrMessage;
        }
 
@@ -92,95 +101,78 @@ WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
 
        up(&pHandle->hSem);
 
-       WILC_CATCH(s32RetStatus)
-       {
-               /* error occured, free any allocations */
-               if (pstrMessage != NULL) {
-                       if (pstrMessage->pvBuffer != NULL) {
-                               kfree(pstrMessage->pvBuffer);
-                       }
-                       kfree(pstrMessage);
-               }
-       }
-
-       return s32RetStatus;
+       return 0;
 }
 
-
-
 /*!
  *  @author            syounan
  *  @date              1 Sep 2010
  *  @note              copied from FLO glue implementatuion
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle,
+int wilc_mq_recv(WILC_MsgQueueHandle *pHandle,
                             void *pvRecvBuffer, u32 u32RecvBufferSize,
                             u32 *pu32ReceivedLength)
 {
-
        Message *pstrMessage;
-       WILC_ErrNo s32RetStatus = WILC_SUCCESS;
+       int result = 0;
        unsigned long flags;
-       if ((pHandle == NULL) || (u32RecvBufferSize == 0)
-           || (pvRecvBuffer == NULL) || (pu32ReceivedLength == NULL)) {
-               WILC_ERRORREPORT(s32RetStatus, WILC_INVALID_ARGUMENT);
+
+       if ((!pHandle) || (u32RecvBufferSize == 0)
+           || (!pvRecvBuffer) || (!pu32ReceivedLength)) {
+               PRINT_ER("pHandle or pvRecvBuffer is null\n");
+               return -EINVAL;
        }
 
-       if (pHandle->bExiting == true) {
-               WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
+       if (pHandle->bExiting) {
+               PRINT_ER("pHandle fail\n");
+               return -EFAULT;
        }
 
        spin_lock_irqsave(&pHandle->strCriticalSection, flags);
        pHandle->u32ReceiversCount++;
        spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
 
-       down(&(pHandle->hSem));
+       down(&pHandle->hSem);
 
-       if (s32RetStatus == WILC_TIMEOUT) {
-               /* timed out, just exit without consumeing the message */
-               spin_lock_irqsave(&pHandle->strCriticalSection, flags);
-               pHandle->u32ReceiversCount--;
-               spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
-       } else {
-               /* other non-timeout scenarios */
-               WILC_ERRORCHECK(s32RetStatus);
-
-               if (pHandle->bExiting) {
-                       WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
-               }
-
-               spin_lock_irqsave(&pHandle->strCriticalSection, flags);
-
-               pstrMessage = pHandle->pstrMessageList;
-               if (pstrMessage == NULL) {
-                       spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
-                       WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
-               }
-               /* check buffer size */
-               if (u32RecvBufferSize < pstrMessage->u32Length) {
-                       spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
-                       up(&pHandle->hSem);
-                       WILC_ERRORREPORT(s32RetStatus, WILC_BUFFER_OVERFLOW);
-               }
-
-               /* consume the message */
-               pHandle->u32ReceiversCount--;
-               memcpy(pvRecvBuffer, pstrMessage->pvBuffer, pstrMessage->u32Length);
-               *pu32ReceivedLength = pstrMessage->u32Length;
+       /* other non-timeout scenarios */
+       if (result) {
+               PRINT_ER("Non-timeout\n");
+               return result;
+       }
 
-               pHandle->pstrMessageList = pstrMessage->pstrNext;
+       if (pHandle->bExiting) {
+               PRINT_ER("pHandle fail\n");
+               return -EFAULT;
+       }
 
-               kfree(pstrMessage->pvBuffer);
-               kfree(pstrMessage);
+       spin_lock_irqsave(&pHandle->strCriticalSection, flags);
 
+       pstrMessage = pHandle->pstrMessageList;
+       if (!pstrMessage) {
                spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
-
+               PRINT_ER("pstrMessage is null\n");
+               return -EFAULT;
        }
-
-       WILC_CATCH(s32RetStatus)
-       {
+       /* check buffer size */
+       if (u32RecvBufferSize < pstrMessage->u32Length) {
+               spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
+               up(&pHandle->hSem);
+               PRINT_ER("u32RecvBufferSize overflow\n");
+               return -EOVERFLOW;
        }
 
-       return s32RetStatus;
+       /* consume the message */
+       pHandle->u32ReceiversCount--;
+       memcpy(pvRecvBuffer, pstrMessage->pvBuffer, pstrMessage->u32Length);
+       *pu32ReceivedLength = pstrMessage->u32Length;
+
+       pHandle->pstrMessageList = pstrMessage->pstrNext;
+
+       kfree(pstrMessage->pvBuffer);
+       kfree(pstrMessage);
+
+       spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
+
+       return result;
 }
index ef1d2fa20c50a835f4a8c61ecbea1906d68b52b5..d231c334ed93316063cdecb86c3720545e798505 100644 (file)
  *  @version   1.0
  */
 
-#include "wilc_platform.h"
-#include "wilc_errorsupport.h"
-#include "wilc_memory.h"
+#include <linux/semaphore.h>
+
+/* Message Queue type is a structure */
+typedef struct __Message_struct {
+       void *pvBuffer;
+       u32 u32Length;
+       struct __Message_struct *pstrNext;
+} Message;
+
+typedef struct __MessageQueue_struct {
+       struct semaphore hSem;
+       spinlock_t strCriticalSection;
+       bool bExiting;
+       u32 u32ReceiversCount;
+       Message *pstrMessageList;
+} WILC_MsgQueueHandle;
 
 /*!
  *  @brief             Creates a new Message queue
@@ -27,7 +40,7 @@
  *  @date              30 Aug 2010
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle);
+int wilc_mq_create(WILC_MsgQueueHandle *pHandle);
 
 /*!
  *  @brief             Sends a message
@@ -44,7 +57,7 @@ WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle);
  *  @date              30 Aug 2010
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
+int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
                             const void *pvSendBuffer, u32 u32SendBufferSize);
 
 /*!
@@ -63,7 +76,7 @@ WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
  *  @date              30 Aug 2010
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle,
+int wilc_mq_recv(WILC_MsgQueueHandle *pHandle,
                             void *pvRecvBuffer, u32 u32RecvBufferSize,
                             u32 *pu32ReceivedLength);
 
@@ -76,6 +89,6 @@ WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle,
  *  @date              30 Aug 2010
  *  @version           1.0
  */
-WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle);
+int wilc_mq_destroy(WILC_MsgQueueHandle *pHandle);
 
 #endif
diff --git a/drivers/staging/wilc1000/wilc_oswrapper.h b/drivers/staging/wilc1000/wilc_oswrapper.h
deleted file mode 100644 (file)
index cb48325..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-#ifndef __WILC_OSWRAPPER_H__
-#define __WILC_OSWRAPPER_H__
-
-/*!
- *  @file      wilc_oswrapper.h
- *  @brief     Top level OS Wrapper, include this file and it will include all
- *              other files as necessary
- *  @author    syounan
- *  @date      10 Aug 2010
- *  @version   1.0
- */
-
-/* OS Wrapper interface version */
-#define WILC_OSW_INTERFACE_VER 2
-
-/* Os Configuration File */
-#include "wilc_platform.h"
-
-/* Error reporting and handling support */
-#include "wilc_errorsupport.h"
-
-/* Memory support */
-#include "wilc_memory.h"
-
-
-/* Message Queue */
-#include "wilc_msgqueue.h"
-
-#endif
diff --git a/drivers/staging/wilc1000/wilc_platform.h b/drivers/staging/wilc1000/wilc_platform.h
deleted file mode 100644 (file)
index 1e56973..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef __WILC_platform_H__
-#define __WILC_platform_H__
-
-#include <linux/kthread.h>
-#include <linux/semaphore.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/stat.h>
-#include <linux/time.h>
-#include <linux/version.h>
-#include "linux/string.h"
-/******************************************************************
- *      OS specific types
- *******************************************************************/
-
-/* Message Queue type is a structure */
-typedef struct __Message_struct {
-       void *pvBuffer;
-       u32 u32Length;
-       struct __Message_struct *pstrNext;
-} Message;
-
-typedef struct __MessageQueue_struct {
-       struct semaphore hSem;
-       spinlock_t strCriticalSection;
-       bool bExiting;
-       u32 u32ReceiversCount;
-       Message *pstrMessageList;
-} WILC_MsgQueueHandle;
-
-
-
-/*Time represented in 64 bit format*/
-typedef time_t WILC_Time;
-
-
-/*******************************************************************
- *      others
- ********************************************************************/
-
-/* Generic printf function */
-#define __WILC_FILE__          __FILE__
-#define __WILC_FUNCTION__      __func__
-#define __WILC_LINE__          __LINE__
-#endif
index 5a18148a593e3f2b6416138b6fee4a95bc6b78cc..300c571e4e2d17d876e757a0e5c433b77cd2ae44 100644 (file)
@@ -7,6 +7,7 @@
 /*  */
 /* //////////////////////////////////////////////////////////////////////////// */
 
+#include <linux/string.h>
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
 
@@ -14,8 +15,7 @@
 
 typedef struct {
        void *os_context;
-       wilc_wlan_os_func_t os_func;
-       uint32_t block_size;
+       u32 block_size;
        int (*sdio_cmd52)(sdio_cmd52_t *);
        int (*sdio_cmd53)(sdio_cmd53_t *);
        int (*sdio_set_max_speed)(void);
@@ -29,10 +29,9 @@ typedef struct {
 static wilc_sdio_t g_sdio;
 
 #ifdef WILC_SDIO_IRQ_GPIO
-static int sdio_write_reg(uint32_t addr, uint32_t data);
-static int sdio_read_reg(uint32_t addr, uint32_t *data);
+static int sdio_write_reg(u32 addr, u32 data);
+static int sdio_read_reg(u32 addr, u32 *data);
 #endif
-extern unsigned int int_clrd;
 
 /********************************************
  *
@@ -40,7 +39,7 @@ extern unsigned int int_clrd;
  *
  ********************************************/
 
-static int sdio_set_func0_csa_address(uint32_t adr)
+static int sdio_set_func0_csa_address(u32 adr)
 {
        sdio_cmd52_t cmd;
 
@@ -51,21 +50,21 @@ static int sdio_set_func0_csa_address(uint32_t adr)
        cmd.function = 0;
        cmd.raw = 0;
        cmd.address = 0x10c;
-       cmd.data = (uint8_t)adr;
+       cmd.data = (u8)adr;
        if (!g_sdio.sdio_cmd52(&cmd)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10c data...\n");
                goto _fail_;
        }
 
        cmd.address = 0x10d;
-       cmd.data = (uint8_t)(adr >> 8);
+       cmd.data = (u8)(adr >> 8);
        if (!g_sdio.sdio_cmd52(&cmd)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10d data...\n");
                goto _fail_;
        }
 
        cmd.address = 0x10e;
-       cmd.data = (uint8_t)(adr >> 16);
+       cmd.data = (u8)(adr >> 16);
        if (!g_sdio.sdio_cmd52(&cmd)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10e data...\n");
                goto _fail_;
@@ -76,29 +75,7 @@ _fail_:
        return 0;
 }
 
-static int sdio_set_func0_csa_address_byte0(uint32_t adr)
-{
-       sdio_cmd52_t cmd;
-
-       /**
-        *      Review: BIG ENDIAN
-        **/
-       cmd.read_write = 1;
-       cmd.function = 0;
-       cmd.raw = 0;
-       cmd.address = 0x10c;
-       cmd.data = (uint8_t)adr;
-       if (!g_sdio.sdio_cmd52(&cmd)) {
-               g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10c data...\n");
-               goto _fail_;
-       }
-
-       return 1;
-_fail_:
-       return 0;
-}
-
-static int sdio_set_func0_block_size(uint32_t block_size)
+static int sdio_set_func0_block_size(u32 block_size)
 {
        sdio_cmd52_t cmd;
 
@@ -106,14 +83,14 @@ static int sdio_set_func0_block_size(uint32_t block_size)
        cmd.function = 0;
        cmd.raw = 0;
        cmd.address = 0x10;
-       cmd.data = (uint8_t)block_size;
+       cmd.data = (u8)block_size;
        if (!g_sdio.sdio_cmd52(&cmd)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x10 data...\n");
                goto _fail_;
        }
 
        cmd.address = 0x11;
-       cmd.data = (uint8_t)(block_size >> 8);
+       cmd.data = (u8)(block_size >> 8);
        if (!g_sdio.sdio_cmd52(&cmd)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x11 data...\n");
                goto _fail_;
@@ -130,7 +107,7 @@ _fail_:
  *
  ********************************************/
 
-static int sdio_set_func1_block_size(uint32_t block_size)
+static int sdio_set_func1_block_size(u32 block_size)
 {
        sdio_cmd52_t cmd;
 
@@ -138,13 +115,13 @@ static int sdio_set_func1_block_size(uint32_t block_size)
        cmd.function = 0;
        cmd.raw = 0;
        cmd.address = 0x110;
-       cmd.data = (uint8_t)block_size;
+       cmd.data = (u8)block_size;
        if (!g_sdio.sdio_cmd52(&cmd)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x110 data...\n");
                goto _fail_;
        }
        cmd.address = 0x111;
-       cmd.data = (uint8_t)(block_size >> 8);
+       cmd.data = (u8)(block_size >> 8);
        if (!g_sdio.sdio_cmd52(&cmd)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed cmd52, set 0x111 data...\n");
                goto _fail_;
@@ -158,7 +135,7 @@ _fail_:
 static int sdio_clear_int(void)
 {
 #ifndef WILC_SDIO_IRQ_GPIO
-       /* uint32_t sts; */
+       /* u32 sts; */
        sdio_cmd52_t cmd;
 
        cmd.read_write = 0;
@@ -167,11 +144,10 @@ static int sdio_clear_int(void)
        cmd.address = 0x4;
        cmd.data = 0;
        g_sdio.sdio_cmd52(&cmd);
-       int_clrd++;
 
        return cmd.data;
 #else
-       uint32_t reg;
+       u32 reg;
 
        if (!sdio_read_reg(WILC_HOST_RX_CTRL_0, &reg)) {
                g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_HOST_RX_CTRL_0);
@@ -179,15 +155,14 @@ static int sdio_clear_int(void)
        }
        reg &= ~0x1;
        sdio_write_reg(WILC_HOST_RX_CTRL_0, reg);
-       int_clrd++;
        return 1;
 #endif
 
 }
 
-uint32_t sdio_xfer_cnt(void)
+u32 sdio_xfer_cnt(void)
 {
-       uint32_t cnt = 0;
+       u32 cnt = 0;
        sdio_cmd52_t cmd;
 
        cmd.read_write = 0;
@@ -246,7 +221,7 @@ _fail_:
        return 0;
 }
 
-static int sdio_write_reg(uint32_t addr, uint32_t data)
+static int sdio_write_reg(u32 addr, u32 data)
 {
 #ifdef BIG_ENDIAN
        data = BYTE_SWAP(data);
@@ -279,7 +254,7 @@ static int sdio_write_reg(uint32_t addr, uint32_t data)
                cmd.block_mode = 0;
                cmd.increment = 1;
                cmd.count = 4;
-               cmd.buffer = (uint8_t *)&data;
+               cmd.buffer = (u8 *)&data;
                cmd.block_size = g_sdio.block_size; /* johnny : prevent it from setting unexpected value */
 
                if (!g_sdio.sdio_cmd53(&cmd)) {
@@ -295,9 +270,9 @@ _fail_:
        return 0;
 }
 
-static int sdio_write(uint32_t addr, uint8_t *buf, uint32_t size)
+static int sdio_write(u32 addr, u8 *buf, u32 size)
 {
-       uint32_t block_size = g_sdio.block_size;
+       u32 block_size = g_sdio.block_size;
        sdio_cmd53_t cmd;
        int nblk, nleft;
 
@@ -379,7 +354,7 @@ _fail_:
        return 0;
 }
 
-static int sdio_read_reg(uint32_t addr, uint32_t *data)
+static int sdio_read_reg(u32 addr, u32 *data)
 {
        if ((addr >= 0xf0) && (addr <= 0xff)) {
                sdio_cmd52_t cmd;
@@ -405,7 +380,7 @@ static int sdio_read_reg(uint32_t addr, uint32_t *data)
                cmd.block_mode = 0;
                cmd.increment = 1;
                cmd.count = 4;
-               cmd.buffer = (uint8_t *)data;
+               cmd.buffer = (u8 *)data;
 
                cmd.block_size = g_sdio.block_size; /* johnny : prevent it from setting unexpected value */
 
@@ -426,9 +401,9 @@ _fail_:
        return 0;
 }
 
-static int sdio_read(uint32_t addr, uint8_t *buf, uint32_t size)
+static int sdio_read(u32 addr, u8 *buf, u32 size)
 {
-       uint32_t block_size = g_sdio.block_size;
+       u32 block_size = g_sdio.block_size;
        sdio_cmd53_t cmd;
        int nblk, nleft;
 
@@ -523,7 +498,7 @@ static int sdio_deinit(void *pv)
 
 static int sdio_sync(void)
 {
-       uint32_t reg;
+       u32 reg;
 
        /**
         *      Disable power sequencer
@@ -533,7 +508,7 @@ static int sdio_sync(void)
                return 0;
        }
 
-       reg &= ~(1 << 8);
+       reg &= ~BIT(8);
        if (!sdio_write_reg(WILC_MISC, reg)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write misc reg...\n");
                return 0;
@@ -541,7 +516,7 @@ static int sdio_sync(void)
 
 #ifdef WILC_SDIO_IRQ_GPIO
        {
-               uint32_t reg;
+               u32 reg;
                int ret;
 
                /**
@@ -552,7 +527,7 @@ static int sdio_sync(void)
                        g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0);
                        return 0;
                }
-               reg |= (1 << 8);
+               reg |= BIT(8);
                ret = sdio_write_reg(WILC_PIN_MUX_0, reg);
                if (!ret) {
                        g_sdio.dPrint(N_ERR, "[wilc spi]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0);
@@ -567,7 +542,7 @@ static int sdio_sync(void)
                        g_sdio.dPrint(N_ERR, "[wilc spi]: Failed read reg (%08x)...\n", WILC_INTR_ENABLE);
                        return 0;
                }
-               reg |= (1 << 16);
+               reg |= BIT(16);
                ret = sdio_write_reg(WILC_INTR_ENABLE, reg);
                if (!ret) {
                        g_sdio.dPrint(N_ERR, "[wilc spi]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE);
@@ -583,13 +558,12 @@ static int sdio_init(wilc_wlan_inp_t *inp, wilc_debug_func func)
 {
        sdio_cmd52_t cmd;
        int loop;
-       uint32_t chipid;
+       u32 chipid;
 
        memset(&g_sdio, 0, sizeof(wilc_sdio_t));
 
        g_sdio.dPrint = func;
        g_sdio.os_context = inp->os_context.os_private;
-       memcpy((void *)&g_sdio.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
 
        if (inp->io_func.io_init) {
                if (!inp->io_func.io_init(g_sdio.os_context)) {
@@ -715,10 +689,10 @@ static void sdio_set_default_speed(void)
        g_sdio.sdio_set_default_speed();
 }
 
-static int sdio_read_size(uint32_t *size)
+static int sdio_read_size(u32 *size)
 {
 
-       uint32_t tmp;
+       u32 tmp;
        sdio_cmd52_t cmd;
 
        /**
@@ -744,10 +718,10 @@ static int sdio_read_size(uint32_t *size)
        return 1;
 }
 
-static int sdio_read_int(uint32_t *int_status)
+static int sdio_read_int(u32 *int_status)
 {
 
-       uint32_t tmp;
+       u32 tmp;
        sdio_cmd52_t cmd;
 
        sdio_read_size(&tmp);
@@ -756,24 +730,22 @@ static int sdio_read_int(uint32_t *int_status)
         *      Read IRQ flags
         **/
 #ifndef WILC_SDIO_IRQ_GPIO
-       /* cmd.read_write = 0; */
        cmd.function = 1;
-       /* cmd.raw = 0; */
        cmd.address = 0x04;
        cmd.data = 0;
        g_sdio.sdio_cmd52(&cmd);
 
-       if (cmd.data & (1 << 0))
+       if (cmd.data & BIT(0))
                tmp |= INT_0;
-       if (cmd.data & (1 << 2))
+       if (cmd.data & BIT(2))
                tmp |= INT_1;
-       if (cmd.data & (1 << 3))
+       if (cmd.data & BIT(3))
                tmp |= INT_2;
-       if (cmd.data & (1 << 4))
+       if (cmd.data & BIT(4))
                tmp |= INT_3;
-       if (cmd.data & (1 << 5))
+       if (cmd.data & BIT(5))
                tmp |= INT_4;
-       if (cmd.data & (1 << 6))
+       if (cmd.data & BIT(6))
                tmp |= INT_5;
        {
                int i;
@@ -787,7 +759,7 @@ static int sdio_read_int(uint32_t *int_status)
        }
 #else
        {
-               uint32_t irq_flags;
+               u32 irq_flags;
 
                cmd.read_write = 0;
                cmd.function = 0;
@@ -806,18 +778,18 @@ static int sdio_read_int(uint32_t *int_status)
        return 1;
 }
 
-static int sdio_clear_int_ext(uint32_t val)
+static int sdio_clear_int_ext(u32 val)
 {
        int ret;
 
        if (g_sdio.has_thrpt_enh3) {
-               uint32_t reg;
+               u32 reg;
 
 #ifdef WILC_SDIO_IRQ_GPIO
                {
-                       uint32_t flags;
+                       u32 flags;
 
-                       flags = val & ((1 << MAX_NUN_INT_THRPT_ENH2) - 1);
+                       flags = val & (BIT(MAX_NUN_INT_THRPT_ENH2) - 1);
                        reg = flags;
                }
 #else
@@ -825,13 +797,13 @@ static int sdio_clear_int_ext(uint32_t val)
 #endif
                /* select VMM table 0 */
                if ((val & SEL_VMM_TBL0) == SEL_VMM_TBL0)
-                       reg |= (1 << 5);
+                       reg |= BIT(5);
                /* select VMM table 1 */
                if ((val & SEL_VMM_TBL1) == SEL_VMM_TBL1)
-                       reg |= (1 << 6);
+                       reg |= BIT(6);
                /* enable VMM */
                if ((val & EN_VMM) == EN_VMM)
-                       reg |= (1 << 7);
+                       reg |= BIT(7);
                if (reg) {
                        sdio_cmd52_t cmd;
 
@@ -853,9 +825,9 @@ static int sdio_clear_int_ext(uint32_t val)
                {
                        /* see below. has_thrpt_enh2 uses register 0xf8 to clear interrupts. */
                        /* Cannot clear multiple interrupts. Must clear each interrupt individually */
-                       uint32_t flags;
+                       u32 flags;
 
-                       flags = val & ((1 << MAX_NUM_INT) - 1);
+                       flags = val & (BIT(MAX_NUM_INT) - 1);
                        if (flags) {
                                int i;
 
@@ -868,7 +840,7 @@ static int sdio_clear_int_ext(uint32_t val)
                                                cmd.function = 0;
                                                cmd.raw = 0;
                                                cmd.address = 0xf8;
-                                               cmd.data = (1 << i);
+                                               cmd.data = BIT(i);
 
                                                ret = g_sdio.sdio_cmd52(&cmd);
                                                if (!ret) {
@@ -893,18 +865,18 @@ static int sdio_clear_int_ext(uint32_t val)
 #endif /* WILC_SDIO_IRQ_GPIO */
 
                {
-                       uint32_t vmm_ctl;
+                       u32 vmm_ctl;
 
                        vmm_ctl = 0;
                        /* select VMM table 0 */
                        if ((val & SEL_VMM_TBL0) == SEL_VMM_TBL0)
-                               vmm_ctl |= (1 << 0);
+                               vmm_ctl |= BIT(0);
                        /* select VMM table 1 */
                        if ((val & SEL_VMM_TBL1) == SEL_VMM_TBL1)
-                               vmm_ctl |= (1 << 1);
+                               vmm_ctl |= BIT(1);
                        /* enable VMM */
                        if ((val & EN_VMM) == EN_VMM)
-                               vmm_ctl |= (1 << 2);
+                               vmm_ctl |= BIT(2);
 
                        if (vmm_ctl) {
                                sdio_cmd52_t cmd;
@@ -930,7 +902,7 @@ _fail_:
 
 static int sdio_sync_ext(int nint /*  how mant interrupts to enable. */)
 {
-       uint32_t reg;
+       u32 reg;
 
        if (nint > MAX_NUM_INT) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Too many interupts (%d)...\n", nint);
@@ -951,7 +923,7 @@ static int sdio_sync_ext(int nint /*  how mant interrupts to enable. */)
                return 0;
        }
 
-       reg &= ~(1 << 8);
+       reg &= ~BIT(8);
        if (!sdio_write_reg(WILC_MISC, reg)) {
                g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write misc reg...\n");
                return 0;
@@ -959,7 +931,7 @@ static int sdio_sync_ext(int nint /*  how mant interrupts to enable. */)
 
 #ifdef WILC_SDIO_IRQ_GPIO
        {
-               uint32_t reg;
+               u32 reg;
                int ret, i;
 
                /**
@@ -970,7 +942,7 @@ static int sdio_sync_ext(int nint /*  how mant interrupts to enable. */)
                        g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0);
                        return 0;
                }
-               reg |= (1 << 8);
+               reg |= BIT(8);
                ret = sdio_write_reg(WILC_PIN_MUX_0, reg);
                if (!ret) {
                        g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0);
@@ -987,7 +959,7 @@ static int sdio_sync_ext(int nint /*  how mant interrupts to enable. */)
                }
 
                for (i = 0; (i < 5) && (nint > 0); i++, nint--)
-                       reg |= (1 << (27 + i));
+                       reg |= BIT((27 + i));
                ret = sdio_write_reg(WILC_INTR_ENABLE, reg);
                if (!ret) {
                        g_sdio.dPrint(N_ERR, "[wilc sdio]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE);
@@ -1001,7 +973,7 @@ static int sdio_sync_ext(int nint /*  how mant interrupts to enable. */)
                        }
 
                        for (i = 0; (i < 3) && (nint > 0); i++, nint--)
-                               reg |= (1 << i);
+                               reg |= BIT(i);
 
                        ret = sdio_read_reg(WILC_INTR2_ENABLE, &reg);
                        if (!ret) {
index 1bf7d314ae342ed3cbe6237b75b1686e604be1be..599508beabf8b45445f38e5b2d17e656289c6f69 100644 (file)
@@ -7,20 +7,15 @@
 /*  */
 /* //////////////////////////////////////////////////////////////////////////// */
 
+#include <linux/string.h>
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
 
-extern unsigned int int_clrd;
-
-/*
- * #include <linux/kernel.h>
- * #include <linux/string.h>
- */
 typedef struct {
        void *os_context;
-       int (*spi_tx)(uint8_t *, uint32_t);
-       int (*spi_rx)(uint8_t *, uint32_t);
-       int (*spi_trx)(uint8_t *, uint8_t *, uint32_t);
+       int (*spi_tx)(u8 *, u32);
+       int (*spi_rx)(u8 *, u32);
+       int (*spi_trx)(u8 *, u8 *, u32);
        int (*spi_max_speed)(void);
        wilc_debug_func dPrint;
        int crc_off;
@@ -30,8 +25,8 @@ typedef struct {
 
 static wilc_spi_t g_spi;
 
-static int spi_read(uint32_t, uint8_t *, uint32_t);
-static int spi_write(uint32_t, uint8_t *, uint32_t);
+static int spi_read(u32, u8 *, u32);
+static int spi_write(u32, u8 *, u32);
 
 /********************************************
  *
@@ -39,7 +34,7 @@ static int spi_write(uint32_t, uint8_t *, uint32_t);
  *
  ********************************************/
 
-static const uint8_t crc7_syndrome_table[256] = {
+static const u8 crc7_syndrome_table[256] = {
        0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f,
        0x48, 0x41, 0x5a, 0x53, 0x6c, 0x65, 0x7e, 0x77,
        0x19, 0x10, 0x0b, 0x02, 0x3d, 0x34, 0x2f, 0x26,
@@ -74,12 +69,12 @@ static const uint8_t crc7_syndrome_table[256] = {
        0x46, 0x4f, 0x54, 0x5d, 0x62, 0x6b, 0x70, 0x79
 };
 
-static uint8_t crc7_byte(uint8_t crc, uint8_t data)
+static u8 crc7_byte(u8 crc, u8 data)
 {
        return crc7_syndrome_table[(crc << 1) ^ data];
 }
 
-static uint8_t crc7(uint8_t crc, const uint8_t *buffer, uint32_t len)
+static u8 crc7(u8 crc, const u8 *buffer, u32 len)
 {
        while (len--)
                crc = crc7_byte(crc, *buffer++);
@@ -116,26 +111,26 @@ static uint8_t crc7(uint8_t crc, const uint8_t *buffer, uint32_t len)
 #define DATA_PKT_SZ_8K                         (8 * 1024)
 #define DATA_PKT_SZ                                    DATA_PKT_SZ_8K
 
-static int spi_cmd(uint8_t cmd, uint32_t adr, uint32_t data, uint32_t sz, uint8_t clockless)
+static int spi_cmd(u8 cmd, u32 adr, u32 data, u32 sz, u8 clockless)
 {
-       uint8_t bc[9];
+       u8 bc[9];
        int len = 5;
        int result = N_OK;
 
        bc[0] = cmd;
        switch (cmd) {
        case CMD_SINGLE_READ:                           /* single word (4 bytes) read */
-               bc[1] = (uint8_t)(adr >> 16);
-               bc[2] = (uint8_t)(adr >> 8);
-               bc[3] = (uint8_t)adr;
+               bc[1] = (u8)(adr >> 16);
+               bc[2] = (u8)(adr >> 8);
+               bc[3] = (u8)adr;
                len = 5;
                break;
 
        case CMD_INTERNAL_READ:                 /* internal register read */
-               bc[1] = (uint8_t)(adr >> 8);
+               bc[1] = (u8)(adr >> 8);
                if (clockless)
-                       bc[1] |= (1 << 7);
-               bc[2] = (uint8_t)adr;
+                       bc[1] |= BIT(7);
+               bc[2] = (u8)adr;
                bc[3] = 0x00;
                len = 5;
                break;
@@ -163,45 +158,45 @@ static int spi_cmd(uint8_t cmd, uint32_t adr, uint32_t data, uint32_t sz, uint8_
 
        case CMD_DMA_WRITE:                                     /* dma write */
        case CMD_DMA_READ:                                      /* dma read */
-               bc[1] = (uint8_t)(adr >> 16);
-               bc[2] = (uint8_t)(adr >> 8);
-               bc[3] = (uint8_t)adr;
-               bc[4] = (uint8_t)(sz >> 8);
-               bc[5] = (uint8_t)(sz);
+               bc[1] = (u8)(adr >> 16);
+               bc[2] = (u8)(adr >> 8);
+               bc[3] = (u8)adr;
+               bc[4] = (u8)(sz >> 8);
+               bc[5] = (u8)(sz);
                len = 7;
                break;
 
        case CMD_DMA_EXT_WRITE:         /* dma extended write */
        case CMD_DMA_EXT_READ:                  /* dma extended read */
-               bc[1] = (uint8_t)(adr >> 16);
-               bc[2] = (uint8_t)(adr >> 8);
-               bc[3] = (uint8_t)adr;
-               bc[4] = (uint8_t)(sz >> 16);
-               bc[5] = (uint8_t)(sz >> 8);
-               bc[6] = (uint8_t)(sz);
+               bc[1] = (u8)(adr >> 16);
+               bc[2] = (u8)(adr >> 8);
+               bc[3] = (u8)adr;
+               bc[4] = (u8)(sz >> 16);
+               bc[5] = (u8)(sz >> 8);
+               bc[6] = (u8)(sz);
                len = 8;
                break;
 
        case CMD_INTERNAL_WRITE:                /* internal register write */
-               bc[1] = (uint8_t)(adr >> 8);
+               bc[1] = (u8)(adr >> 8);
                if (clockless)
-                       bc[1] |= (1 << 7);
-               bc[2] = (uint8_t)(adr);
-               bc[3] = (uint8_t)(data >> 24);
-               bc[4] = (uint8_t)(data >> 16);
-               bc[5] = (uint8_t)(data >> 8);
-               bc[6] = (uint8_t)(data);
+                       bc[1] |= BIT(7);
+               bc[2] = (u8)(adr);
+               bc[3] = (u8)(data >> 24);
+               bc[4] = (u8)(data >> 16);
+               bc[5] = (u8)(data >> 8);
+               bc[6] = (u8)(data);
                len = 8;
                break;
 
        case CMD_SINGLE_WRITE:                  /* single word write */
-               bc[1] = (uint8_t)(adr >> 16);
-               bc[2] = (uint8_t)(adr >> 8);
-               bc[3] = (uint8_t)(adr);
-               bc[4] = (uint8_t)(data >> 24);
-               bc[5] = (uint8_t)(data >> 16);
-               bc[6] = (uint8_t)(data >> 8);
-               bc[7] = (uint8_t)(data);
+               bc[1] = (u8)(adr >> 16);
+               bc[2] = (u8)(adr >> 8);
+               bc[3] = (u8)(adr);
+               bc[4] = (u8)(data >> 24);
+               bc[5] = (u8)(data >> 16);
+               bc[6] = (u8)(data >> 8);
+               bc[7] = (u8)(data);
                len = 9;
                break;
 
@@ -212,7 +207,7 @@ static int spi_cmd(uint8_t cmd, uint32_t adr, uint32_t data, uint32_t sz, uint8_
 
        if (result) {
                if (!g_spi.crc_off)
-                       bc[len - 1] = (crc7(0x7f, (const uint8_t *)&bc[0], len - 1)) << 1;
+                       bc[len - 1] = (crc7(0x7f, (const u8 *)&bc[0], len - 1)) << 1;
                else
                        len -= 1;
 
@@ -225,9 +220,9 @@ static int spi_cmd(uint8_t cmd, uint32_t adr, uint32_t data, uint32_t sz, uint8_
        return result;
 }
 
-static int spi_cmd_rsp(uint8_t cmd)
+static int spi_cmd_rsp(u8 cmd)
 {
-       uint8_t rsp;
+       u8 rsp;
        int result = N_OK;
 
        /**
@@ -273,29 +268,29 @@ _fail_:
        return result;
 }
 
-static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz, uint8_t clockless)
+static int spi_cmd_complete(u8 cmd, u32 adr, u8 *b, u32 sz, u8 clockless)
 {
-       uint8_t wb[32], rb[32];
-       uint8_t wix, rix;
-       uint32_t len2;
-       uint8_t rsp;
+       u8 wb[32], rb[32];
+       u8 wix, rix;
+       u32 len2;
+       u8 rsp;
        int len = 0;
        int result = N_OK;
 
        wb[0] = cmd;
        switch (cmd) {
        case CMD_SINGLE_READ:                           /* single word (4 bytes) read */
-               wb[1] = (uint8_t)(adr >> 16);
-               wb[2] = (uint8_t)(adr >> 8);
-               wb[3] = (uint8_t)adr;
+               wb[1] = (u8)(adr >> 16);
+               wb[2] = (u8)(adr >> 8);
+               wb[3] = (u8)adr;
                len = 5;
                break;
 
        case CMD_INTERNAL_READ:                 /* internal register read */
-               wb[1] = (uint8_t)(adr >> 8);
+               wb[1] = (u8)(adr >> 8);
                if (clockless == 1)
-                       wb[1] |= (1 << 7);
-               wb[2] = (uint8_t)adr;
+                       wb[1] |= BIT(7);
+               wb[2] = (u8)adr;
                wb[3] = 0x00;
                len = 5;
                break;
@@ -323,30 +318,30 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
 
        case CMD_DMA_WRITE:                                     /* dma write */
        case CMD_DMA_READ:                                      /* dma read */
-               wb[1] = (uint8_t)(adr >> 16);
-               wb[2] = (uint8_t)(adr >> 8);
-               wb[3] = (uint8_t)adr;
-               wb[4] = (uint8_t)(sz >> 8);
-               wb[5] = (uint8_t)(sz);
+               wb[1] = (u8)(adr >> 16);
+               wb[2] = (u8)(adr >> 8);
+               wb[3] = (u8)adr;
+               wb[4] = (u8)(sz >> 8);
+               wb[5] = (u8)(sz);
                len = 7;
                break;
 
        case CMD_DMA_EXT_WRITE:         /* dma extended write */
        case CMD_DMA_EXT_READ:                  /* dma extended read */
-               wb[1] = (uint8_t)(adr >> 16);
-               wb[2] = (uint8_t)(adr >> 8);
-               wb[3] = (uint8_t)adr;
-               wb[4] = (uint8_t)(sz >> 16);
-               wb[5] = (uint8_t)(sz >> 8);
-               wb[6] = (uint8_t)(sz);
+               wb[1] = (u8)(adr >> 16);
+               wb[2] = (u8)(adr >> 8);
+               wb[3] = (u8)adr;
+               wb[4] = (u8)(sz >> 16);
+               wb[5] = (u8)(sz >> 8);
+               wb[6] = (u8)(sz);
                len = 8;
                break;
 
        case CMD_INTERNAL_WRITE:                /* internal register write */
-               wb[1] = (uint8_t)(adr >> 8);
+               wb[1] = (u8)(adr >> 8);
                if (clockless == 1)
-                       wb[1] |= (1 << 7);
-               wb[2] = (uint8_t)(adr);
+                       wb[1] |= BIT(7);
+               wb[2] = (u8)(adr);
                wb[3] = b[3];
                wb[4] = b[2];
                wb[5] = b[1];
@@ -355,9 +350,9 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
                break;
 
        case CMD_SINGLE_WRITE:                  /* single word write */
-               wb[1] = (uint8_t)(adr >> 16);
-               wb[2] = (uint8_t)(adr >> 8);
-               wb[3] = (uint8_t)(adr);
+               wb[1] = (u8)(adr >> 16);
+               wb[2] = (u8)(adr >> 8);
+               wb[3] = (u8)(adr);
                wb[4] = b[3];
                wb[5] = b[2];
                wb[6] = b[1];
@@ -375,7 +370,7 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
        }
 
        if (!g_spi.crc_off)
-               wb[len - 1] = (crc7(0x7f, (const uint8_t *)&wb[0], len - 1)) << 1;
+               wb[len - 1] = (crc7(0x7f, (const u8 *)&wb[0], len - 1)) << 1;
        else
                len -= 1;
 
@@ -402,9 +397,9 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
        }
 #undef NUM_DUMMY_BYTES
 
-       if (len2 > (sizeof(wb) / sizeof(wb[0]))) {
+       if (len2 > ARRAY_SIZE(wb)) {
                PRINT_ER("[wilc spi]: spi buffer size too small (%d) (%zu)\n",
-                        len2, (sizeof(wb) / sizeof(wb[0])));
+                        len2, ARRAY_SIZE(wb));
                result = N_FAIL;
                return result;
        }
@@ -455,8 +450,8 @@ static int spi_cmd_complete(uint8_t cmd, uint32_t adr, uint8_t *b, uint32_t sz,
        if ((cmd == CMD_INTERNAL_READ) || (cmd == CMD_SINGLE_READ)
            || (cmd == CMD_DMA_READ) || (cmd == CMD_DMA_EXT_READ)) {
                int retry;
-               /* uint16_t crc1, crc2; */
-               uint8_t crc[2];
+               /* u16 crc1, crc2; */
+               u8 crc[2];
                /**
                 * Data Respnose header
                 **/
@@ -612,12 +607,12 @@ _error_:
        return result;
 }
 
-static int spi_data_read(uint8_t *b, uint32_t sz)
+static int spi_data_read(u8 *b, u32 sz)
 {
        int retry, ix, nbytes;
        int result = N_OK;
-       uint8_t crc[2];
-       uint8_t rsp;
+       u8 crc[2];
+       u8 rsp;
 
        /**
         *      Data
@@ -680,12 +675,12 @@ static int spi_data_read(uint8_t *b, uint32_t sz)
        return result;
 }
 
-static int spi_data_write(uint8_t *b, uint32_t sz)
+static int spi_data_write(u8 *b, u32 sz)
 {
        int ix, nbytes;
        int result = 1;
-       uint8_t cmd, order, crc[2] = {0};
-       /* uint8_t rsp; */
+       u8 cmd, order, crc[2] = {0};
+       /* u8 rsp; */
 
        /**
         *      Data
@@ -757,71 +752,30 @@ static int spi_data_write(uint8_t *b, uint32_t sz)
  *
  ********************************************/
 
-static int spi_internal_write(uint32_t adr, uint32_t dat)
+static int spi_internal_write(u32 adr, u32 dat)
 {
        int result;
 
-#if defined USE_OLD_SPI_SW
-       /**
-        *      Command
-        **/
-       result = spi_cmd(CMD_INTERNAL_WRITE, adr, dat, 4, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed internal write cmd...\n");
-               return 0;
-       }
-
-       result = spi_cmd_rsp(CMD_INTERNAL_WRITE, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed internal write cmd response...\n");
-       }
-#else
-
 #ifdef BIG_ENDIAN
        dat = BYTE_SWAP(dat);
 #endif
-       result = spi_cmd_complete(CMD_INTERNAL_WRITE, adr, (uint8_t *)&dat, 4, 0);
+       result = spi_cmd_complete(CMD_INTERNAL_WRITE, adr, (u8 *)&dat, 4, 0);
        if (result != N_OK) {
                PRINT_ER("[wilc spi]: Failed internal write cmd...\n");
        }
 
-#endif
        return result;
 }
 
-static int spi_internal_read(uint32_t adr, uint32_t *data)
+static int spi_internal_read(u32 adr, u32 *data)
 {
        int result;
 
-#if defined USE_OLD_SPI_SW
-       result = spi_cmd(CMD_INTERNAL_READ, adr, 0, 4, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed internal read cmd...\n");
-               return 0;
-       }
-
-       result = spi_cmd_rsp(CMD_INTERNAL_READ, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed internal read cmd response...\n");
-               return 0;
-       }
-
-       /**
-        *      Data
-        **/
-       result = spi_data_read((uint8_t *)data, 4);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed internal read data...\n");
-               return 0;
-       }
-#else
-       result = spi_cmd_complete(CMD_INTERNAL_READ, adr, (uint8_t *)data, 4, 0);
+       result = spi_cmd_complete(CMD_INTERNAL_READ, adr, (u8 *)data, 4, 0);
        if (result != N_OK) {
                PRINT_ER("[wilc spi]: Failed internal read cmd...\n");
                return 0;
        }
-#endif
-
 
 #ifdef BIG_ENDIAN
        *data = BYTE_SWAP(*data);
@@ -836,30 +790,12 @@ static int spi_internal_read(uint32_t adr, uint32_t *data)
  *
  ********************************************/
 
-static int spi_write_reg(uint32_t addr, uint32_t data)
+static int spi_write_reg(u32 addr, u32 data)
 {
        int result = N_OK;
-       uint8_t cmd = CMD_SINGLE_WRITE;
-       uint8_t clockless = 0;
-
-
-#if defined USE_OLD_SPI_SW
-       {
-               result = spi_cmd(cmd, addr, data, 4, 0);
-               if (result != N_OK) {
-                       PRINT_ER("[wilc spi]: Failed cmd, write reg (%08x)...\n", addr);
-                       return 0;
-               }
+       u8 cmd = CMD_SINGLE_WRITE;
+       u8 clockless = 0;
 
-               result = spi_cmd_rsp(cmd, 0);
-               if (result != N_OK) {
-                       PRINT_ER("[wilc spi]: Failed cmd response, write reg (%08x)...\n", addr);
-                       return 0;
-               }
-
-               return 1;
-       }
-#else
 #ifdef BIG_ENDIAN
        data = BYTE_SWAP(data);
 #endif
@@ -869,20 +805,18 @@ static int spi_write_reg(uint32_t addr, uint32_t data)
                clockless = 1;
        }
 
-       result = spi_cmd_complete(cmd, addr, (uint8_t *)&data, 4, clockless);
+       result = spi_cmd_complete(cmd, addr, (u8 *)&data, 4, clockless);
        if (result != N_OK) {
                PRINT_ER("[wilc spi]: Failed cmd, write reg (%08x)...\n", addr);
        }
 
        return result;
-#endif
-
 }
 
-static int spi_write(uint32_t addr, uint8_t *buf, uint32_t size)
+static int spi_write(u32 addr, u8 *buf, u32 size)
 {
        int result;
-       uint8_t cmd = CMD_DMA_EXT_WRITE;
+       u8 cmd = CMD_DMA_EXT_WRITE;
 
        /**
         *      has to be greated than 4
@@ -890,28 +824,11 @@ static int spi_write(uint32_t addr, uint8_t *buf, uint32_t size)
        if (size <= 4)
                return 0;
 
-#if defined USE_OLD_SPI_SW
-       /**
-        *      Command
-        **/
-       result = spi_cmd(cmd, addr, 0, size, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed cmd, write block (%08x)...\n", addr);
-               return 0;
-       }
-
-       result = spi_cmd_rsp(cmd, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi ]: Failed cmd response, write block (%08x)...\n", addr);
-               return 0;
-       }
-#else
        result = spi_cmd_complete(cmd, addr, NULL, size, 0);
        if (result != N_OK) {
                PRINT_ER("[wilc spi]: Failed cmd, write block (%08x)...\n", addr);
                return 0;
        }
-#endif
 
        /**
         *      Data
@@ -924,30 +841,12 @@ static int spi_write(uint32_t addr, uint8_t *buf, uint32_t size)
        return 1;
 }
 
-static int spi_read_reg(uint32_t addr, uint32_t *data)
+static int spi_read_reg(u32 addr, u32 *data)
 {
        int result = N_OK;
-       uint8_t cmd = CMD_SINGLE_READ;
-       uint8_t clockless = 0;
-
-#if defined USE_OLD_SPI_SW
-       result = spi_cmd(cmd, addr, 0, 4, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed cmd, read reg (%08x)...\n", addr);
-               return 0;
-       }
-       result = spi_cmd_rsp(cmd, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed cmd response, read reg (%08x)...\n", addr);
-               return 0;
-       }
+       u8 cmd = CMD_SINGLE_READ;
+       u8 clockless = 0;
 
-       result = spi_data_read((uint8_t *)data, 4);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed data read...\n");
-               return 0;
-       }
-#else
        if (addr < 0x30) {
                /* PRINT_ER("***** read addr %d\n\n", addr); */
                /* Clockless register*/
@@ -955,13 +854,11 @@ static int spi_read_reg(uint32_t addr, uint32_t *data)
                clockless = 1;
        }
 
-       result = spi_cmd_complete(cmd, addr, (uint8_t *)data, 4, clockless);
+       result = spi_cmd_complete(cmd, addr, (u8 *)data, 4, clockless);
        if (result != N_OK) {
                PRINT_ER("[wilc spi]: Failed cmd, read reg (%08x)...\n", addr);
                return 0;
        }
-#endif
-
 
 #ifdef BIG_ENDIAN
        *data = BYTE_SWAP(*data);
@@ -970,46 +867,19 @@ static int spi_read_reg(uint32_t addr, uint32_t *data)
        return 1;
 }
 
-static int spi_read(uint32_t addr, uint8_t *buf, uint32_t size)
+static int spi_read(u32 addr, u8 *buf, u32 size)
 {
-       uint8_t cmd = CMD_DMA_EXT_READ;
+       u8 cmd = CMD_DMA_EXT_READ;
        int result;
 
        if (size <= 4)
                return 0;
 
-#if defined USE_OLD_SPI_SW
-       /**
-        *      Command
-        **/
-       result = spi_cmd(cmd, addr, 0, size, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed cmd, read block (%08x)...\n", addr);
-               return 0;
-       }
-
-       result = spi_cmd_rsp(cmd, 0);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed cmd response, read block (%08x)...\n", addr);
-               return 0;
-       }
-
-       /**
-        *      Data
-        **/
-       result = spi_data_read(buf, size);
-       if (result != N_OK) {
-               PRINT_ER("[wilc spi]: Failed block data read...\n");
-               return 0;
-       }
-#else
        result = spi_cmd_complete(cmd, addr, buf, size, 0);
        if (result != N_OK) {
                PRINT_ER("[wilc spi]: Failed cmd, read block (%08x)...\n", addr);
                return 0;
        }
-#endif
-
 
        return 1;
 }
@@ -1022,14 +892,14 @@ static int spi_read(uint32_t addr, uint8_t *buf, uint32_t size)
 
 static int spi_clear_int(void)
 {
-       uint32_t reg;
+       u32 reg;
+
        if (!spi_read_reg(WILC_HOST_RX_CTRL_0, &reg)) {
                PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_HOST_RX_CTRL_0);
                return 0;
        }
        reg &= ~0x1;
        spi_write_reg(WILC_HOST_RX_CTRL_0, reg);
-       int_clrd++;
        return 1;
 }
 
@@ -1043,7 +913,7 @@ static int spi_deinit(void *pv)
 
 static int spi_sync(void)
 {
-       uint32_t reg;
+       u32 reg;
        int ret;
 
        /**
@@ -1054,7 +924,7 @@ static int spi_sync(void)
                PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0);
                return 0;
        }
-       reg |= (1 << 8);
+       reg |= BIT(8);
        ret = spi_write_reg(WILC_PIN_MUX_0, reg);
        if (!ret) {
                PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0);
@@ -1069,7 +939,7 @@ static int spi_sync(void)
                PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_INTR_ENABLE);
                return 0;
        }
-       reg |= (1 << 16);
+       reg |= BIT(16);
        ret = spi_write_reg(WILC_INTR_ENABLE, reg);
        if (!ret) {
                PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_INTR_ENABLE);
@@ -1081,8 +951,8 @@ static int spi_sync(void)
 
 static int spi_init(wilc_wlan_inp_t *inp, wilc_debug_func func)
 {
-       uint32_t reg;
-       uint32_t chipid;
+       u32 reg;
+       u32 chipid;
 
        static int isinit;
 
@@ -1167,15 +1037,16 @@ static void spi_default_bus_speed(void)
 {
 }
 
-static int spi_read_size(uint32_t *size)
+static int spi_read_size(u32 *size)
 {
        int ret;
+
        if (g_spi.has_thrpt_enh) {
                ret = spi_internal_read(0xe840 - WILC_SPI_REG_BASE, size);
                *size = *size  & IRQ_DMA_WD_CNT_MASK;
        } else {
-               uint32_t tmp;
-               uint32_t byte_cnt;
+               u32 tmp;
+               u32 byte_cnt;
 
                ret = spi_read_reg(WILC_VMM_TO_HOST_SIZE, &byte_cnt);
                if (!ret) {
@@ -1194,14 +1065,15 @@ _fail_:
 
 
 
-static int spi_read_int(uint32_t *int_status)
+static int spi_read_int(u32 *int_status)
 {
        int ret;
+
        if (g_spi.has_thrpt_enh) {
                ret = spi_internal_read(0xe840 - WILC_SPI_REG_BASE, int_status);
        } else {
-               uint32_t tmp;
-               uint32_t byte_cnt;
+               u32 tmp;
+               u32 byte_cnt;
 
                ret = spi_read_reg(WILC_VMM_TO_HOST_SIZE, &byte_cnt);
                if (!ret) {
@@ -1215,7 +1087,7 @@ static int spi_read_int(uint32_t *int_status)
 
                        j = 0;
                        do {
-                               uint32_t irq_flags;
+                               u32 irq_flags;
 
                                happended = 0;
 
@@ -1228,7 +1100,7 @@ static int spi_read_int(uint32_t *int_status)
                                }
 
                                {
-                                       uint32_t unkmown_mask;
+                                       u32 unkmown_mask;
 
                                        unkmown_mask = ~((1ul << g_spi.nint) - 1);
 
@@ -1249,15 +1121,16 @@ _fail_:
        return ret;
 }
 
-static int spi_clear_int_ext(uint32_t val)
+static int spi_clear_int_ext(u32 val)
 {
        int ret;
 
        if (g_spi.has_thrpt_enh) {
                ret = spi_internal_write(0xe844 - WILC_SPI_REG_BASE, val);
        } else {
-               uint32_t flags;
-               flags = val & ((1 << MAX_NUM_INT) - 1);
+               u32 flags;
+
+               flags = val & (BIT(MAX_NUM_INT) - 1);
                if (flags) {
                        int i;
 
@@ -1282,15 +1155,15 @@ static int spi_clear_int_ext(uint32_t val)
                }
 
                {
-                       uint32_t tbl_ctl;
+                       u32 tbl_ctl;
 
                        tbl_ctl = 0;
                        /* select VMM table 0 */
                        if ((val & SEL_VMM_TBL0) == SEL_VMM_TBL0)
-                               tbl_ctl |= (1 << 0);
+                               tbl_ctl |= BIT(0);
                        /* select VMM table 1 */
                        if ((val & SEL_VMM_TBL1) == SEL_VMM_TBL1)
-                               tbl_ctl |= (1 << 1);
+                               tbl_ctl |= BIT(1);
 
                        ret = spi_write_reg(WILC_VMM_TBL_CTL, tbl_ctl);
                        if (!ret) {
@@ -1316,7 +1189,7 @@ _fail_:
 
 static int spi_sync_ext(int nint /*  how mant interrupts to enable. */)
 {
-       uint32_t reg;
+       u32 reg;
        int ret, i;
 
        if (nint > MAX_NUM_INT) {
@@ -1334,7 +1207,7 @@ static int spi_sync_ext(int nint /*  how mant interrupts to enable. */)
                PRINT_ER("[wilc spi]: Failed read reg (%08x)...\n", WILC_PIN_MUX_0);
                return 0;
        }
-       reg |= (1 << 8);
+       reg |= BIT(8);
        ret = spi_write_reg(WILC_PIN_MUX_0, reg);
        if (!ret) {
                PRINT_ER("[wilc spi]: Failed write reg (%08x)...\n", WILC_PIN_MUX_0);
@@ -1351,7 +1224,7 @@ static int spi_sync_ext(int nint /*  how mant interrupts to enable. */)
        }
 
        for (i = 0; (i < 5) && (nint > 0); i++, nint--) {
-               reg |= (1 << (27 + i));
+               reg |= (BIT((27 + i)));
        }
        ret = spi_write_reg(WILC_INTR_ENABLE, reg);
        if (!ret) {
@@ -1366,7 +1239,7 @@ static int spi_sync_ext(int nint /*  how mant interrupts to enable. */)
                }
 
                for (i = 0; (i < 3) && (nint > 0); i++, nint--) {
-                       reg |= (1 << i);
+                       reg |= BIT(i);
                }
 
                ret = spi_read_reg(WILC_INTR2_ENABLE, &reg);
index a6edc973f636babacc4fd8f51956bd197958610e..3e9501727812c589ba986304cb4689eb87bb4146 100644 (file)
  */
 
 #include "wilc_wfi_cfgoperations.h"
-#include "wilc_wlan.c"
 #ifdef WILC_SDIO
-#include "linux_wlan_sdio.h"    /* tony : for set_wiphy_dev() */
+#include "linux_wlan_sdio.h"
 #endif
-
+#include <linux/errno.h>
 
 #define IS_MANAGMEMENT                         0x100
 #define IS_MANAGMEMENT_CALLBACK                        0x080
 #define GET_PKT_OFFSET(a) (((a) >> 22) & 0x1ff)
 
 extern int linux_wlan_get_firmware(perInterface_wlan_t *p_nic);
-extern void linux_wlan_unlock(void *vp);
-extern u16 Set_machw_change_vir_if(bool bValue);
 
 extern int mac_open(struct net_device *ndev);
 extern int mac_close(struct net_device *ndev);
 
 tstrNetworkInfo astrLastScannedNtwrksShadow[MAX_NUM_SCANNED_NETWORKS_SHADOW];
 u32 u32LastScannedNtwrksCountShadow;
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 struct timer_list hDuringIpTimer;
-#endif
 struct timer_list hAgingTimer;
 static u8 op_ifcs;
 extern u8 u8ConnectedSSID[6];
 
-/*BugID_5137*/
 u8 g_wilc_initialized = 1;
-extern linux_wlan_t *g_linux_wlan;
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 extern bool g_obtainingIP;
-#endif
 
 #define CHAN2G(_channel, _freq, _flags) {       \
                .band             = IEEE80211_BAND_2GHZ, \
@@ -95,7 +86,6 @@ static struct ieee80211_rate WILC_WFI_rates[] = {
        RATETAB_ENT(540, 12, 0),
 };
 
-#ifdef WILC_P2P
 struct p2p_mgmt_data {
        int size;
        u8 *buff;
@@ -104,15 +94,13 @@ struct p2p_mgmt_data {
 /*Global variable used to state the current  connected STA channel*/
 u8 u8WLANChannel = INVALID_CHANNEL;
 
-/*BugID_5442*/
-u8 u8CurrChannel;
+u8 curr_channel;
 
 u8 u8P2P_oui[] = {0x50, 0x6f, 0x9A, 0x09};
 u8 u8P2Plocalrandom = 0x01;
 u8 u8P2Precvrandom = 0x00;
 u8 u8P2P_vendorspec[] = {0xdd, 0x05, 0x00, 0x08, 0x40, 0x03};
 bool bWilc_ie;
-#endif
 
 static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
        .channels = WILC_WFI_2ghz_channels,
@@ -122,7 +110,6 @@ static struct ieee80211_supported_band WILC_WFI_band_2ghz = {
 };
 
 
-/*BugID_5137*/
 struct add_key_params {
        u8 key_idx;
        bool pairwise;
@@ -133,7 +120,6 @@ struct wilc_wfi_key g_key_gtk_params;
 struct add_key_params g_add_ptk_key_params;
 struct wilc_wfi_key g_key_ptk_params;
 struct wilc_wfi_wep_key g_key_wep_params;
-u8 g_flushing_in_progress;
 bool g_ptk_keys_saved;
 bool g_gtk_keys_saved;
 bool g_wep_keys_saved;
@@ -144,6 +130,7 @@ bool g_wep_keys_saved;
 void clear_shadow_scan(void *pUserVoid)
 {
        int i;
+
        if (op_ifcs == 0) {
                del_timer_sync(&hAgingTimer);
                PRINT_INFO(CORECONFIG_DBG, "destroy aging timer\n");
@@ -162,11 +149,11 @@ void clear_shadow_scan(void *pUserVoid)
 
 }
 
-uint32_t get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
+u32 get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
 {
-       uint8_t i;
+       u8 i;
        int rssi_v = 0;
-       uint8_t num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
+       u8 num_rssi = (pstrNetworkInfo->strRssi.u8Full) ? NUM_RSSI : (pstrNetworkInfo->strRssi.u8Index);
 
        for (i = 0; i < num_rssi; i++)
                rssi_v += pstrNetworkInfo->strRssi.as8RSSI[i];
@@ -175,19 +162,20 @@ uint32_t get_rssi_avg(tstrNetworkInfo *pstrNetworkInfo)
        return rssi_v;
 }
 
-void refresh_scan(void *pUserVoid, uint8_t all, bool bDirectScan)
+void refresh_scan(void *pUserVoid, u8 all, bool bDirectScan)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        struct wiphy *wiphy;
        struct cfg80211_bss *bss = NULL;
        int i;
        int rssi = 0;
 
-       priv = (struct WILC_WFI_priv *)pUserVoid;
+       priv = (struct wilc_priv *)pUserVoid;
        wiphy = priv->dev->ieee80211_ptr->wiphy;
 
        for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
                tstrNetworkInfo *pstrNetworkInfo;
+
                pstrNetworkInfo = &(astrLastScannedNtwrksShadow[i]);
 
 
@@ -217,6 +205,7 @@ void refresh_scan(void *pUserVoid, uint8_t all, bool bDirectScan)
 void reset_shadow_found(void *pUserVoid)
 {
        int i;
+
        for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
                astrLastScannedNtwrksShadow[i].u8Found = 0;
 
@@ -226,6 +215,7 @@ void reset_shadow_found(void *pUserVoid)
 void update_scan_time(void *pUserVoid)
 {
        int i;
+
        for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
                astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan = jiffies;
        }
@@ -241,10 +231,8 @@ static void remove_network_from_shadow(unsigned long arg)
                if (time_after(now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long)(SCAN_RESULT_EXPIRE))) {
                        PRINT_D(CFG80211_DBG, "Network expired in ScanShadow: %s\n", astrLastScannedNtwrksShadow[i].au8ssid);
 
-                       if (astrLastScannedNtwrksShadow[i].pu8IEs != NULL) {
-                               kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
-                               astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
-                       }
+                       kfree(astrLastScannedNtwrksShadow[i].pu8IEs);
+                       astrLastScannedNtwrksShadow[i].pu8IEs = NULL;
 
                        host_int_freeJoinParams(astrLastScannedNtwrksShadow[i].pJoinParams);
 
@@ -264,17 +252,15 @@ static void remove_network_from_shadow(unsigned long arg)
        }
 }
 
-#ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
 static void clear_duringIP(unsigned long arg)
 {
        PRINT_D(GENERIC_DBG, "GO:IP Obtained , enable scan\n");
        g_obtainingIP = false;
 }
-#endif
 
-int8_t is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
+int is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
 {
-       int8_t state = -1;
+       int state = -1;
        int i;
 
        if (u32LastScannedNtwrksCountShadow == 0) {
@@ -297,9 +283,9 @@ int8_t is_network_in_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid)
 
 void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
 {
-       int8_t ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
-       uint32_t ap_index = 0;
-       uint8_t rssi_index = 0;
+       int ap_found = is_network_in_shadow(pstrNetworkInfo, pUserVoid);
+       u32 ap_index = 0;
+       u8 rssi_index = 0;
 
        if (u32LastScannedNtwrksCountShadow >= MAX_NUM_SCANNED_NETWORKS_SHADOW) {
                PRINT_D(CFG80211_DBG, "Shadow network reached its maximum limit\n");
@@ -339,7 +325,7 @@ void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, vo
        if (ap_found != -1)
                kfree(astrLastScannedNtwrksShadow[ap_index].pu8IEs);
        astrLastScannedNtwrksShadow[ap_index].pu8IEs =
-               WILC_MALLOC(pstrNetworkInfo->u16IEsLen);        /* will be deallocated by the WILC_WFI_CfgScan() function */
+               kmalloc(pstrNetworkInfo->u16IEsLen, GFP_KERNEL);        /* will be deallocated by the WILC_WFI_CfgScan() function */
        memcpy(astrLastScannedNtwrksShadow[ap_index].pu8IEs,
                    pstrNetworkInfo->pu8IEs, pstrNetworkInfo->u16IEsLen);
 
@@ -366,40 +352,44 @@ void add_network_to_shadow(tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, vo
  *  @date
  *  @version   1.0
  */
-static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
+static void CfgScanResult(enum scan_event enuScanEvent, tstrNetworkInfo *pstrNetworkInfo, void *pUserVoid, void *pJoinParams)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        struct wiphy *wiphy;
        s32 s32Freq;
        struct ieee80211_channel *channel;
-       s32 s32Error = WILC_SUCCESS;
        struct cfg80211_bss *bss = NULL;
 
-       priv = (struct WILC_WFI_priv *)pUserVoid;
-       if (priv->bCfgScanning == true) {
+       priv = (struct wilc_priv *)pUserVoid;
+       if (priv->bCfgScanning) {
                if (enuScanEvent == SCAN_EVENT_NETWORK_FOUND) {
                        wiphy = priv->dev->ieee80211_ptr->wiphy;
-                       WILC_NULLCHECK(s32Error, wiphy);
+
+                       if (!wiphy)
+                               return;
+
                        if (wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC
                            &&
                            ((((s32)pstrNetworkInfo->s8rssi) * 100) < 0
                             ||
                             (((s32)pstrNetworkInfo->s8rssi) * 100) > 100)
                            ) {
-                               WILC_ERRORREPORT(s32Error, WILC_FAIL);
+                               PRINT_ER("wiphy signal type fial\n");
+                               return;
                        }
 
                        if (pstrNetworkInfo != NULL) {
                                s32Freq = ieee80211_channel_to_frequency((s32)pstrNetworkInfo->u8channel, IEEE80211_BAND_2GHZ);
                                channel = ieee80211_get_channel(wiphy, s32Freq);
 
-                               WILC_NULLCHECK(s32Error, channel);
+                               if (!channel)
+                                       return;
 
                                PRINT_INFO(CFG80211_DBG, "Network Info:: CHANNEL Frequency: %d, RSSI: %d, CapabilityInfo: %d,"
                                           "BeaconPeriod: %d\n", channel->center_freq, (((s32)pstrNetworkInfo->s8rssi) * 100),
                                           pstrNetworkInfo->u16CapInfo, pstrNetworkInfo->u16BeaconPeriod);
 
-                               if (pstrNetworkInfo->bNewNetwork == true) {
+                               if (pstrNetworkInfo->bNewNetwork) {
                                        if (priv->u32RcvdChCount < MAX_NUM_SCANNED_NETWORKS) { /* TODO: mostafa: to be replaced by */
                                                /*               max_scan_ssids */
                                                PRINT_D(CFG80211_DBG, "Network %s found\n", pstrNetworkInfo->au8ssid);
@@ -479,11 +469,6 @@ static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetwo
                        up(&(priv->hSemScanReq));
                }
        }
-
-
-       WILC_CATCH(s32Error)
-       {
-       }
 }
 
 
@@ -496,10 +481,10 @@ static void CfgScanResult(tenuScanEvent enuScanEvent, tstrNetworkInfo *pstrNetwo
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-int WILC_WFI_Set_PMKSA(u8 *bssid, struct WILC_WFI_priv *priv)
+int WILC_WFI_Set_PMKSA(u8 *bssid, struct wilc_priv *priv)
 {
        u32 i;
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
 
 
        for (i = 0; i < priv->pmkid_list.numpmkid; i++) {
@@ -511,7 +496,7 @@ int WILC_WFI_Set_PMKSA(u8 *bssid, struct WILC_WFI_priv *priv)
                        /*If bssid is found, set the values*/
                        s32Error = host_int_set_pmkid_info(priv->hWILCWFIDrv, &priv->pmkid_list);
 
-                       if (s32Error != WILC_SUCCESS)
+                       if (s32Error != 0)
                                PRINT_ER("Error in pmkid\n");
 
                        break;
@@ -522,7 +507,7 @@ int WILC_WFI_Set_PMKSA(u8 *bssid, struct WILC_WFI_priv *priv)
 
 
 }
-int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID);
+int linux_wlan_set_bssid(struct net_device *wilc_netdev, u8 *pBSSID);
 
 
 /**
@@ -541,29 +526,30 @@ int linux_wlan_set_bssid(struct net_device *wilc_netdev, uint8_t *pBSSID);
  */
 int connecting;
 
-static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
+static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
                             tstrConnectInfo *pstrConnectInfo,
                             u8 u8MacStatus,
                             tstrDisconnectNotifInfo *pstrDisconnectNotifInfo,
                             void *pUserVoid)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        struct net_device *dev;
-       #ifdef WILC_P2P
-       tstrWILC_WFIDrv *pstrWFIDrv;
-       #endif
+       struct host_if_drv *pstrWFIDrv;
        u8 NullBssid[ETH_ALEN] = {0};
+       struct wilc *wl;
+       perInterface_wlan_t *nic;
+
        connecting = 0;
 
-       priv = (struct WILC_WFI_priv *)pUserVoid;
+       priv = (struct wilc_priv *)pUserVoid;
        dev = priv->dev;
-       #ifdef WILC_P2P
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
-       #endif
+       nic = netdev_priv(dev);
+       wl = nic->wilc;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
 
        if (enuConnDisconnEvent == CONN_DISCONN_EVENT_CONN_RESP) {
                /*Initialization*/
-               u16 u16ConnectStatus = WLAN_STATUS_SUCCESS;
+               u16 u16ConnectStatus;
 
                u16ConnectStatus = pstrConnectInfo->u16ConnectStatus;
 
@@ -575,14 +561,11 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
                         *  = SUCCESSFUL_STATUSCODE, while mac status is MAC_DISCONNECTED (which means something wrong happened) */
                        u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
                        linux_wlan_set_bssid(priv->dev, NullBssid);
-                       memset(u8ConnectedSSID, 0, ETH_ALEN);
+                       eth_zero_addr(u8ConnectedSSID);
 
-                       /*BugID_5457*/
                        /*Invalidate u8WLANChannel value on wlan0 disconnect*/
-                       #ifdef WILC_P2P
                        if (!pstrWFIDrv->u8P2PConnect)
                                u8WLANChannel = INVALID_CHANNEL;
-                       #endif
 
                        PRINT_ER("Unspecified failure: Connection status %d : MAC status = %d\n", u16ConnectStatus, u8MacStatus);
                }
@@ -595,9 +578,6 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
                                   pstrConnectInfo->au8bssid[1], pstrConnectInfo->au8bssid[2], pstrConnectInfo->au8bssid[3], pstrConnectInfo->au8bssid[4], pstrConnectInfo->au8bssid[5]);
                        memcpy(priv->au8AssociatedBss, pstrConnectInfo->au8bssid, ETH_ALEN);
 
-                       /* BugID_4209: if this network has expired in the scan results in the above nl80211 layer, refresh them here by calling
-                        *  cfg80211_inform_bss() with the last Scan results before calling cfg80211_connect_result() to avoid
-                        *  Linux kernel warning generated at the nl80211 layer */
 
                        for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
                                if (memcmp(astrLastScannedNtwrksShadow[i].au8bssid,
@@ -614,7 +594,6 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
                        }
 
                        if (bNeedScanRefresh) {
-                               /*BugID_5418*/
                                /*Also, refrsh DIRECT- results if */
                                refresh_scan(priv, 1, true);
 
@@ -633,34 +612,27 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
                                        u16ConnectStatus, GFP_KERNEL);                         /* TODO: mostafa: u16ConnectStatus to */
                /* be replaced by pstrConnectInfo->u16ConnectStatus */
        } else if (enuConnDisconnEvent == CONN_DISCONN_EVENT_DISCONN_NOTIF)    {
-               #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
                g_obtainingIP = false;
-               #endif
                PRINT_ER("Received MAC_DISCONNECTED from firmware with reason %d on dev [%p]\n",
                         pstrDisconnectNotifInfo->u16reason, priv->dev);
                u8P2Plocalrandom = 0x01;
                u8P2Precvrandom = 0x00;
                bWilc_ie = false;
-               memset(priv->au8AssociatedBss, 0, ETH_ALEN);
+               eth_zero_addr(priv->au8AssociatedBss);
                linux_wlan_set_bssid(priv->dev, NullBssid);
-               memset(u8ConnectedSSID, 0, ETH_ALEN);
+               eth_zero_addr(u8ConnectedSSID);
 
-               /*BugID_5457*/
                /*Invalidate u8WLANChannel value on wlan0 disconnect*/
-               #ifdef WILC_P2P
                if (!pstrWFIDrv->u8P2PConnect)
                        u8WLANChannel = INVALID_CHANNEL;
-               #endif
-               /*BugID_5315*/
                /*Incase "P2P CLIENT Connected" send deauthentication reason by 3 to force the WPA_SUPPLICANT to directly change
                 *      virtual interface to station*/
-               if ((pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->strInterfaceInfo[1].wilc_netdev)) {
+               if ((pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
                        pstrDisconnectNotifInfo->u16reason = 3;
                }
-               /*BugID_5315*/
                /*Incase "P2P CLIENT during connection(not connected)" send deauthentication reason by 1 to force the WPA_SUPPLICANT
                 *      to scan again and retry the connection*/
-               else if ((!pstrWFIDrv->IFC_UP) && (dev == g_linux_wlan->strInterfaceInfo[1].wilc_netdev)) {
+               else if ((!pstrWFIDrv->IFC_UP) && (dev == wl->vif[1].ndev)) {
                        pstrDisconnectNotifInfo->u16reason = 1;
                }
                cfg80211_disconnected(dev, pstrDisconnectNotifInfo->u16reason, pstrDisconnectNotifInfo->ie,
@@ -673,7 +645,7 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
 
 
 /**
- *  @brief      WILC_WFI_CfgSetChannel
+ *  @brief      set_channel
  *  @details    Set channel for a given wireless interface. Some devices
  *                      may support multi-channel operation (by channel hopping) so cfg80211
  *                      doesn't verify much. Note, however, that the passed netdev may be
@@ -685,29 +657,29 @@ static void CfgConnectResult(tenuConnDisconnEvent enuConnDisconnEvent,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_CfgSetChannel(struct wiphy *wiphy,
-                                 struct cfg80211_chan_def *chandef)
+static int set_channel(struct wiphy *wiphy,
+                      struct cfg80211_chan_def *chandef)
 {
-
        u32 channelnum = 0;
-       struct WILC_WFI_priv *priv;
-       s32 s32Error = WILC_SUCCESS;
+       struct wilc_priv *priv;
+       int result = 0;
+
        priv = wiphy_priv(wiphy);
 
        channelnum = ieee80211_frequency_to_channel(chandef->chan->center_freq);
        PRINT_D(CFG80211_DBG, "Setting channel %d with frequency %d\n", channelnum, chandef->chan->center_freq);
 
-       u8CurrChannel = channelnum;
-       s32Error   = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
+       curr_channel = channelnum;
+       result = host_int_set_mac_chnl_num(priv->hWILCWFIDrv, channelnum);
 
-       if (s32Error != WILC_SUCCESS)
+       if (result != 0)
                PRINT_ER("Error in setting channel %d\n", channelnum);
 
-       return s32Error;
+       return result;
 }
 
 /**
- *  @brief      WILC_WFI_CfgScan
+ *  @brief      scan
  *  @details    Request to do a scan. If returning zero, the scan request is given
  *                      the driver, and will be valid until passed to cfg80211_scan_done().
  *                      For scan results, call cfg80211_inform_bss(); you can call this outside
@@ -719,17 +691,13 @@ static int WILC_WFI_CfgSetChannel(struct wiphy *wiphy,
  *  @version   1.0
  */
 
-/*
- *     kernel version 3.8.8 supported
- *     tony, sswd, WILC-KR, 2013-10-29
- */
-static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
+static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        u32 i;
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
        u8 au8ScanChanList[MAX_NUM_SCANNED_NETWORKS];
-       tstrHiddenNetwork strHiddenNetwork;
+       struct hidden_network strHiddenNetwork;
 
        priv = wiphy_priv(wiphy);
 
@@ -758,15 +726,14 @@ static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *r
                if (request->n_ssids >= 1) {
 
 
-                       strHiddenNetwork.pstrHiddenNetworkInfo = WILC_MALLOC(request->n_ssids * sizeof(tstrHiddenNetwork));
+                       strHiddenNetwork.pstrHiddenNetworkInfo = kmalloc(request->n_ssids * sizeof(struct hidden_network), GFP_KERNEL);
                        strHiddenNetwork.u8ssidnum = request->n_ssids;
 
 
-                       /*BugID_4156*/
                        for (i = 0; i < request->n_ssids; i++) {
 
                                if (request->ssids[i].ssid != NULL && request->ssids[i].ssid_len != 0) {
-                                       strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = WILC_MALLOC(request->ssids[i].ssid_len);
+                                       strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid = kmalloc(request->ssids[i].ssid_len, GFP_KERNEL);
                                        memcpy(strHiddenNetwork.pstrHiddenNetworkInfo[i].pu8ssid, request->ssids[i].ssid, request->ssids[i].ssid_len);
                                        strHiddenNetwork.pstrHiddenNetworkInfo[i].u8ssidlen = request->ssids[i].ssid_len;
                                } else {
@@ -792,7 +759,7 @@ static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *r
                         " channels\n");
        }
 
-       if (s32Error != WILC_SUCCESS) {
+       if (s32Error != 0) {
                s32Error = -EBUSY;
                PRINT_WRN(CFG80211_DBG, "Device is busy: Error(%d)\n", s32Error);
        }
@@ -801,7 +768,7 @@ static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *r
 }
 
 /**
- *  @brief      WILC_WFI_CfgConnect
+ *  @brief      connect
  *  @details    Connect to the ESS with the specified parameters. When connected,
  *                      call cfg80211_connect_result() with status code %WLAN_STATUS_SUCCESS.
  *                      If the connection fails for some reason, call cfg80211_connect_result()
@@ -812,36 +779,34 @@ static int WILC_WFI_CfgScan(struct wiphy *wiphy, struct cfg80211_scan_request *r
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
-                              struct cfg80211_connect_params *sme)
+static int connect(struct wiphy *wiphy, struct net_device *dev,
+                  struct cfg80211_connect_params *sme)
 {
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
        u32 i;
        u8 u8security = NO_ENCRYPT;
-       AUTHTYPE_T tenuAuth_type = ANY;
+       enum AUTHTYPE tenuAuth_type = ANY;
        char *pcgroup_encrypt_val = NULL;
        char *pccipher_group = NULL;
        char *pcwpa_version = NULL;
 
-       struct WILC_WFI_priv *priv;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct wilc_priv *priv;
+       struct host_if_drv *pstrWFIDrv;
        tstrNetworkInfo *pstrNetworkInfo = NULL;
 
 
        connecting = 1;
        priv = wiphy_priv(wiphy);
-       pstrWFIDrv = (tstrWILC_WFIDrv *)(priv->hWILCWFIDrv);
+       pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
 
        host_int_set_wfi_drv_handler(priv->hWILCWFIDrv);
 
        PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv);
-       #ifdef WILC_P2P
        if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
                PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
                pstrWFIDrv->u8P2PConnect = 1;
        } else
                pstrWFIDrv->u8P2PConnect = 0;
-       #endif
        PRINT_INFO(CFG80211_DBG, "Required SSID = %s\n , AuthType = %d\n", sme->ssid, sme->auth_type);
 
        for (i = 0; i < u32LastScannedNtwrksCountShadow; i++) {
@@ -920,14 +885,13 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
                        priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
                        memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
 
-                       /*BugID_5137*/
                        g_key_wep_params.key_len = sme->key_len;
-                       g_key_wep_params.key = WILC_MALLOC(sme->key_len);
+                       g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
                        memcpy(g_key_wep_params.key, sme->key, sme->key_len);
                        g_key_wep_params.key_idx = sme->key_idx;
                        g_wep_keys_saved = true;
 
-                       host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
+                       host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
                        host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
                } else if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104)   {
                        u8security = ENCRYPT_ENABLED | WEP | WEP_EXTENDED;
@@ -938,14 +902,13 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
                        priv->WILC_WFI_wep_key_len[sme->key_idx] = sme->key_len;
                        memcpy(priv->WILC_WFI_wep_key[sme->key_idx], sme->key, sme->key_len);
 
-                       /*BugID_5137*/
                        g_key_wep_params.key_len = sme->key_len;
-                       g_key_wep_params.key = WILC_MALLOC(sme->key_len);
+                       g_key_wep_params.key = kmalloc(sme->key_len, GFP_KERNEL);
                        memcpy(g_key_wep_params.key, sme->key, sme->key_len);
                        g_key_wep_params.key_idx = sme->key_idx;
                        g_wep_keys_saved = true;
 
-                       host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, sme->key_idx);
+                       host_int_set_wep_default_key(priv->hWILCWFIDrv, sme->key_idx);
                        host_int_add_wep_key_bss_sta(priv->hWILCWFIDrv, sme->key, sme->key_len, sme->key_idx);
                } else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)   {
                        if (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_TKIP) {
@@ -1032,8 +995,7 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
        PRINT_INFO(CFG80211_DBG, "Group encryption value = %s\n Cipher Group = %s\n WPA version = %s\n",
                   pcgroup_encrypt_val, pccipher_group, pcwpa_version);
 
-       /*BugID_5442*/
-       u8CurrChannel = pstrNetworkInfo->u8channel;
+       curr_channel = pstrNetworkInfo->u8channel;
 
        if (!pstrWFIDrv->u8P2PConnect) {
                u8WLANChannel = pstrNetworkInfo->u8channel;
@@ -1046,7 +1008,7 @@ static int WILC_WFI_CfgConnect(struct wiphy *wiphy, struct net_device *dev,
                                         CfgConnectResult, (void *)priv, u8security,
                                         tenuAuth_type, pstrNetworkInfo->u8channel,
                                         pstrNetworkInfo->pJoinParams);
-       if (s32Error != WILC_SUCCESS) {
+       if (s32Error != 0) {
                PRINT_ER("host_int_set_join_req(): Error(%d)\n", s32Error);
                s32Error = -ENOENT;
                goto done;
@@ -1059,7 +1021,7 @@ done:
 
 
 /**
- *  @brief      WILC_WFI_disconnect
+ *  @brief      disconnect
  *  @details    Disconnect from the BSS/ESS.
  *  @param[in]
  *  @return     int : Return 0 on Success
@@ -1067,24 +1029,20 @@ done:
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
+static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_code)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
-       #ifdef WILC_P2P
-       tstrWILC_WFIDrv *pstrWFIDrv;
-       #endif
-       uint8_t NullBssid[ETH_ALEN] = {0};
+       s32 s32Error = 0;
+       struct wilc_priv *priv;
+       struct host_if_drv *pstrWFIDrv;
+       u8 NullBssid[ETH_ALEN] = {0};
+
        connecting = 0;
        priv = wiphy_priv(wiphy);
 
-       /*BugID_5457*/
        /*Invalidate u8WLANChannel value on wlan0 disconnect*/
-       #ifdef WILC_P2P
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
        if (!pstrWFIDrv->u8P2PConnect)
                u8WLANChannel = INVALID_CHANNEL;
-       #endif
        linux_wlan_set_bssid(priv->dev, NullBssid);
 
        PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
@@ -1092,12 +1050,10 @@ static int WILC_WFI_disconnect(struct wiphy *wiphy, struct net_device *dev, u16
        u8P2Plocalrandom = 0x01;
        u8P2Precvrandom = 0x00;
        bWilc_ie = false;
-       #ifdef WILC_P2P
        pstrWFIDrv->u64P2p_MgmtTimeout = 0;
-       #endif
 
        s32Error = host_int_disconnect(priv->hWILCWFIDrv, reason_code);
-       if (s32Error != WILC_SUCCESS) {
+       if (s32Error != 0) {
                PRINT_ER("Error in disconnecting: Error(%d)\n", s32Error);
                s32Error = -EINVAL;
        }
@@ -1106,7 +1062,7 @@ static int WILC_WFI_disconnect(struct wiphy *wiphy, struct net_device *dev, u16
 }
 
 /**
- *  @brief      WILC_WFI_add_key
+ *  @brief      add_key
  *  @details    Add a key with the given parameters. @mac_addr will be %NULL
  *                      when adding a group key.
  *  @param[in] key : key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 8-byte Rx Mic Key
@@ -1115,28 +1071,29 @@ static int WILC_WFI_disconnect(struct wiphy *wiphy, struct net_device *dev, u16
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
-                           bool pairwise,
-                           const u8 *mac_addr, struct key_params *params)
+static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
+                  bool pairwise,
+                  const u8 *mac_addr, struct key_params *params)
 
 {
-       s32 s32Error = WILC_SUCCESS, KeyLen = params->key_len;
+       s32 s32Error = 0, KeyLen = params->key_len;
        u32 i;
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        const u8 *pu8RxMic = NULL;
        const u8 *pu8TxMic = NULL;
        u8 u8mode = NO_ENCRYPT;
-       #ifdef WILC_AP_EXTERNAL_MLME
        u8 u8gmode = NO_ENCRYPT;
        u8 u8pmode = NO_ENCRYPT;
-       AUTHTYPE_T tenuAuth_type = ANY;
-       #endif
+       enum AUTHTYPE tenuAuth_type = ANY;
+       struct wilc *wl;
+       perInterface_wlan_t *nic;
 
        priv = wiphy_priv(wiphy);
+       nic = netdev_priv(netdev);
+       wl = nic->wilc;
 
        PRINT_D(CFG80211_DBG, "Adding key with cipher suite = %x\n", params->cipher);
 
-       /*BugID_5137*/
        PRINT_D(CFG80211_DBG, "%p %p %d\n", wiphy, netdev, key_index);
 
        PRINT_D(CFG80211_DBG, "key %x %x %x\n", params->key[0],
@@ -1147,7 +1104,6 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
        switch (params->cipher) {
        case WLAN_CIPHER_SUITE_WEP40:
        case WLAN_CIPHER_SUITE_WEP104:
-                               #ifdef WILC_AP_EXTERNAL_MLME
                if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
 
                        priv->WILC_WFI_wep_default = key_index;
@@ -1170,7 +1126,6 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
                        host_int_add_wep_key_bss_ap(priv->hWILCWFIDrv, params->key, params->key_len, key_index, u8mode, tenuAuth_type);
                        break;
                }
-                               #endif
                if (memcmp(params->key, priv->WILC_WFI_wep_key[key_index], params->key_len)) {
                        priv->WILC_WFI_wep_default = key_index;
                        priv->WILC_WFI_wep_key_len[key_index] = params->key_len;
@@ -1189,17 +1144,16 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
 
        case WLAN_CIPHER_SUITE_TKIP:
        case WLAN_CIPHER_SUITE_CCMP:
-                               #ifdef WILC_AP_EXTERNAL_MLME
                if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
 
                        if (priv->wilc_gtk[key_index] == NULL) {
-                               priv->wilc_gtk[key_index] = WILC_MALLOC(sizeof(struct wilc_wfi_key));
+                               priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
                                priv->wilc_gtk[key_index]->key = NULL;
                                priv->wilc_gtk[key_index]->seq = NULL;
 
                        }
                        if (priv->wilc_ptk[key_index] == NULL) {
-                               priv->wilc_ptk[key_index] = WILC_MALLOC(sizeof(struct wilc_wfi_key));
+                               priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
                                priv->wilc_ptk[key_index]->key = NULL;
                                priv->wilc_ptk[key_index]->seq = NULL;
                        }
@@ -1221,18 +1175,16 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
                                        KeyLen = params->key_len - 16;
                                }
                                /* if there has been previous allocation for the same index through its key, free that memory and allocate again*/
-                               if (priv->wilc_gtk[key_index]->key)
-                                       kfree(priv->wilc_gtk[key_index]->key);
+                               kfree(priv->wilc_gtk[key_index]->key);
 
-                               priv->wilc_gtk[key_index]->key = WILC_MALLOC(params->key_len);
+                               priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
                                memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
 
                                /* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/
-                               if (priv->wilc_gtk[key_index]->seq)
-                                       kfree(priv->wilc_gtk[key_index]->seq);
+                               kfree(priv->wilc_gtk[key_index]->seq);
 
                                if ((params->seq_len) > 0) {
-                                       priv->wilc_gtk[key_index]->seq = WILC_MALLOC(params->seq_len);
+                                       priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
                                        memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
                                }
 
@@ -1267,16 +1219,14 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
                                        KeyLen = params->key_len - 16;
                                }
 
-                               if (priv->wilc_ptk[key_index]->key)
-                                       kfree(priv->wilc_ptk[key_index]->key);
+                               kfree(priv->wilc_ptk[key_index]->key);
 
-                               priv->wilc_ptk[key_index]->key = WILC_MALLOC(params->key_len);
+                               priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
 
-                               if (priv->wilc_ptk[key_index]->seq)
-                                       kfree(priv->wilc_ptk[key_index]->seq);
+                               kfree(priv->wilc_ptk[key_index]->seq);
 
                                if ((params->seq_len) > 0)
-                                       priv->wilc_ptk[key_index]->seq = WILC_MALLOC(params->seq_len);
+                                       priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
 
                                if (INFO) {
                                        for (i = 0; i < params->key_len; i++)
@@ -1300,7 +1250,6 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
                        }
                        break;
                }
-                               #endif
 
                {
                        u8mode = 0;
@@ -1312,23 +1261,22 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
                                        KeyLen = params->key_len - 16;
                                }
 
-                               /*BugID_5137*/
                                /*save keys only on interface 0 (wifi interface)*/
-                               if (!g_gtk_keys_saved && netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
+                               if (!g_gtk_keys_saved && netdev == wl->vif[0].ndev) {
                                        g_add_gtk_key_params.key_idx = key_index;
                                        g_add_gtk_key_params.pairwise = pairwise;
                                        if (!mac_addr) {
                                                g_add_gtk_key_params.mac_addr = NULL;
                                        } else {
-                                               g_add_gtk_key_params.mac_addr = WILC_MALLOC(ETH_ALEN);
+                                               g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
                                                memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
                                        }
                                        g_key_gtk_params.key_len = params->key_len;
                                        g_key_gtk_params.seq_len = params->seq_len;
-                                       g_key_gtk_params.key =  WILC_MALLOC(params->key_len);
+                                       g_key_gtk_params.key =  kmalloc(params->key_len, GFP_KERNEL);
                                        memcpy(g_key_gtk_params.key, params->key, params->key_len);
                                        if (params->seq_len > 0) {
-                                               g_key_gtk_params.seq =  WILC_MALLOC(params->seq_len);
+                                               g_key_gtk_params.seq =  kmalloc(params->seq_len, GFP_KERNEL);
                                                memcpy(g_key_gtk_params.seq, params->seq, params->seq_len);
                                        }
                                        g_key_gtk_params.cipher = params->cipher;
@@ -1349,23 +1297,22 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
                                        KeyLen = params->key_len - 16;
                                }
 
-                               /*BugID_5137*/
                                /*save keys only on interface 0 (wifi interface)*/
-                               if (!g_ptk_keys_saved && netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
+                               if (!g_ptk_keys_saved && netdev == wl->vif[0].ndev) {
                                        g_add_ptk_key_params.key_idx = key_index;
                                        g_add_ptk_key_params.pairwise = pairwise;
                                        if (!mac_addr) {
                                                g_add_ptk_key_params.mac_addr = NULL;
                                        } else {
-                                               g_add_ptk_key_params.mac_addr = WILC_MALLOC(ETH_ALEN);
+                                               g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
                                                memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
                                        }
                                        g_key_ptk_params.key_len = params->key_len;
                                        g_key_ptk_params.seq_len = params->seq_len;
-                                       g_key_ptk_params.key =  WILC_MALLOC(params->key_len);
+                                       g_key_ptk_params.key =  kmalloc(params->key_len, GFP_KERNEL);
                                        memcpy(g_key_ptk_params.key, params->key, params->key_len);
                                        if (params->seq_len > 0) {
-                                               g_key_ptk_params.seq =  WILC_MALLOC(params->seq_len);
+                                               g_key_ptk_params.seq =  kmalloc(params->seq_len, GFP_KERNEL);
                                                memcpy(g_key_ptk_params.seq, params->seq, params->seq_len);
                                        }
                                        g_key_ptk_params.cipher = params->cipher;
@@ -1397,7 +1344,7 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
 }
 
 /**
- *  @brief      WILC_WFI_del_key
+ *  @brief      del_key
  *  @details    Remove a key given the @mac_addr (%NULL for a group key)
  *                      and @key_index, return -ENOENT if the key doesn't exist.
  *  @param[in]
@@ -1406,44 +1353,37 @@ static int WILC_WFI_add_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
-                           u8 key_index,
-                           bool pairwise,
-                           const u8 *mac_addr)
+static int del_key(struct wiphy *wiphy, struct net_device *netdev,
+                  u8 key_index,
+                  bool pairwise,
+                  const u8 *mac_addr)
 {
-       struct WILC_WFI_priv *priv;
-       s32 s32Error = WILC_SUCCESS;
+       struct wilc_priv *priv;
+       struct wilc *wl;
+       perInterface_wlan_t *nic;
 
        priv = wiphy_priv(wiphy);
+       nic = netdev_priv(netdev);
+       wl = nic->wilc;
 
-       /*BugID_5137*/
        /*delete saved keys, if any*/
-       if (netdev == g_linux_wlan->strInterfaceInfo[0].wilc_netdev) {
+       if (netdev == wl->vif[0].ndev) {
                g_ptk_keys_saved = false;
                g_gtk_keys_saved = false;
                g_wep_keys_saved = false;
 
                /*Delete saved WEP keys params, if any*/
-               if (g_key_wep_params.key != NULL) {
-                       kfree(g_key_wep_params.key);
-                       g_key_wep_params.key = NULL;
-               }
+               kfree(g_key_wep_params.key);
+               g_key_wep_params.key = NULL;
 
                /*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/
 
-       #ifdef WILC_AP_EXTERNAL_MLME
                if ((priv->wilc_gtk[key_index]) != NULL) {
 
-                       if (priv->wilc_gtk[key_index]->key != NULL) {
-
-                               kfree(priv->wilc_gtk[key_index]->key);
-                               priv->wilc_gtk[key_index]->key = NULL;
-                       }
-                       if (priv->wilc_gtk[key_index]->seq) {
-
-                               kfree(priv->wilc_gtk[key_index]->seq);
-                               priv->wilc_gtk[key_index]->seq = NULL;
-                       }
+                       kfree(priv->wilc_gtk[key_index]->key);
+                       priv->wilc_gtk[key_index]->key = NULL;
+                       kfree(priv->wilc_gtk[key_index]->seq);
+                       priv->wilc_gtk[key_index]->seq = NULL;
 
                        kfree(priv->wilc_gtk[key_index]);
                        priv->wilc_gtk[key_index] = NULL;
@@ -1452,42 +1392,27 @@ static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
 
                if ((priv->wilc_ptk[key_index]) != NULL) {
 
-                       if (priv->wilc_ptk[key_index]->key) {
-
-                               kfree(priv->wilc_ptk[key_index]->key);
-                               priv->wilc_ptk[key_index]->key = NULL;
-                       }
-                       if (priv->wilc_ptk[key_index]->seq) {
-
-                               kfree(priv->wilc_ptk[key_index]->seq);
-                               priv->wilc_ptk[key_index]->seq = NULL;
-                       }
+                       kfree(priv->wilc_ptk[key_index]->key);
+                       priv->wilc_ptk[key_index]->key = NULL;
+                       kfree(priv->wilc_ptk[key_index]->seq);
+                       priv->wilc_ptk[key_index]->seq = NULL;
                        kfree(priv->wilc_ptk[key_index]);
                        priv->wilc_ptk[key_index] = NULL;
                }
-       #endif
 
                /*Delete saved PTK and GTK keys params, if any*/
-               if (g_key_ptk_params.key != NULL) {
-                       kfree(g_key_ptk_params.key);
-                       g_key_ptk_params.key = NULL;
-               }
-               if (g_key_ptk_params.seq != NULL) {
-                       kfree(g_key_ptk_params.seq);
-                       g_key_ptk_params.seq = NULL;
-               }
+               kfree(g_key_ptk_params.key);
+               g_key_ptk_params.key = NULL;
+               kfree(g_key_ptk_params.seq);
+               g_key_ptk_params.seq = NULL;
 
-               if (g_key_gtk_params.key != NULL) {
-                       kfree(g_key_gtk_params.key);
-                       g_key_gtk_params.key = NULL;
-               }
-               if (g_key_gtk_params.seq != NULL) {
-                       kfree(g_key_gtk_params.seq);
-                       g_key_gtk_params.seq = NULL;
-               }
+               kfree(g_key_gtk_params.key);
+               g_key_gtk_params.key = NULL;
+               kfree(g_key_gtk_params.seq);
+               g_key_gtk_params.seq = NULL;
 
                /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
-               Set_machw_change_vir_if(false);
+               Set_machw_change_vir_if(netdev, false);
        }
 
        if (key_index >= 0 && key_index <= 3) {
@@ -1501,11 +1426,11 @@ static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
                host_int_remove_key(priv->hWILCWFIDrv, mac_addr);
        }
 
-       return s32Error;
+       return 0;
 }
 
 /**
- *  @brief      WILC_WFI_get_key
+ *  @brief      get_key
  *  @details    Get information about the key with the given parameters.
  *                      @mac_addr will be %NULL when requesting information for a group
  *                      key. All pointers given to the @callback function need not be valid
@@ -1517,21 +1442,18 @@ static int WILC_WFI_del_key(struct wiphy *wiphy, struct net_device *netdev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
-                           bool pairwise,
-                           const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
+static int get_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
+                  bool pairwise,
+                  const u8 *mac_addr, void *cookie, void (*callback)(void *cookie, struct key_params *))
 {
-
-       s32 s32Error = WILC_SUCCESS;
-
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        struct  key_params key_params;
        u32 i;
+
        priv = wiphy_priv(wiphy);
 
 
-       if (!pairwise)
-       {
+       if (!pairwise) {
                PRINT_D(CFG80211_DBG, "Getting group key idx: %x\n", key_index);
 
                key_params.key = priv->wilc_gtk[key_index]->key;
@@ -1555,11 +1477,11 @@ static int WILC_WFI_get_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
 
        callback(cookie, &key_params);
 
-       return s32Error;        /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
+       return 0;        /* priv->wilc_gtk->key_len ?0 : -ENOENT; */
 }
 
 /**
- *  @brief      WILC_WFI_set_default_key
+ *  @brief      set_default_key
  *  @details    Set the default management frame key on an interface
  *  @param[in]
  *  @return     int : Return 0 on Success.
@@ -1567,11 +1489,10 @@ static int WILC_WFI_get_key(struct wiphy *wiphy, struct net_device *netdev, u8 k
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
-                                   bool unicast, bool multicast)
+static int set_default_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
+                          bool unicast, bool multicast)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
 
 
        priv = wiphy_priv(wiphy);
@@ -1580,39 +1501,14 @@ static int WILC_WFI_set_default_key(struct wiphy *wiphy, struct net_device *netd
 
        if (key_index != priv->WILC_WFI_wep_default) {
 
-               host_int_set_WEPDefaultKeyID(priv->hWILCWFIDrv, key_index);
+               host_int_set_wep_default_key(priv->hWILCWFIDrv, key_index);
        }
 
-       return s32Error;
-}
-
-/**
- *  @brief      WILC_WFI_dump_survey
- *  @details    Get site survey information
- *  @param[in]
- *  @return     int : Return 0 on Success.
- *  @author    mdaftedar
- *  @date      01 MAR 2012
- *  @version   1.0
- */
-static int WILC_WFI_dump_survey(struct wiphy *wiphy, struct net_device *netdev,
-                               int idx, struct survey_info *info)
-{
-       s32 s32Error = WILC_SUCCESS;
-
-
-       if (idx != 0) {
-               s32Error = -ENOENT;
-               PRINT_ER("Error Idx value doesn't equal zero: Error(%d)\n", s32Error);
-
-       }
-
-       return s32Error;
+       return 0;
 }
 
-
 /**
- *  @brief      WILC_WFI_get_station
+ *  @brief      get_station
  *  @details    Get station information for the station identified by @mac
  *  @param[in]   NONE
  *  @return     int : Return 0 on Success.
@@ -1621,21 +1517,17 @@ static int WILC_WFI_dump_survey(struct wiphy *wiphy, struct net_device *netdev,
  *  @version   1.0
  */
 
-static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
-                               const u8 *mac, struct station_info *sinfo)
+static int get_station(struct wiphy *wiphy, struct net_device *dev,
+                      const u8 *mac, struct station_info *sinfo)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        perInterface_wlan_t *nic;
-       #ifdef WILC_AP_EXTERNAL_MLME
        u32 i = 0;
        u32 associatedsta = 0;
        u32 inactive_time = 0;
-       #endif
        priv = wiphy_priv(wiphy);
        nic = netdev_priv(dev);
 
-       #ifdef WILC_AP_EXTERNAL_MLME
        if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
                PRINT_D(HOSTAPD_DBG, "Getting station parameters\n");
 
@@ -1651,10 +1543,8 @@ static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
                }
 
                if (associatedsta == -1) {
-                       s32Error = -ENOENT;
-                       PRINT_ER("Station required is not associated : Error(%d)\n", s32Error);
-
-                       return s32Error;
+                       PRINT_ER("Station required is not associated\n");
+                       return -ENOENT;
                }
 
                sinfo->filled |= BIT(NL80211_STA_INFO_INACTIVE_TIME);
@@ -1664,17 +1554,12 @@ static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
                PRINT_D(CFG80211_DBG, "Inactive time %d\n", sinfo->inactive_time);
 
        }
-       #endif
 
        if (nic->iftype == STATION_MODE) {
-               tstrStatistics strStatistics;
+               struct rf_info strStatistics;
+
                host_int_get_statistics(priv->hWILCWFIDrv, &strStatistics);
 
-               /*
-                * tony: 2013-11-13
-                * tx_failed introduced more than
-                * kernel version 3.0.0
-                */
                sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL) |
                                                BIT(NL80211_STA_INFO_RX_PACKETS) |
                                                BIT(NL80211_STA_INFO_TX_PACKETS) |
@@ -1687,22 +1572,20 @@ static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
                sinfo->tx_failed        =  strStatistics.u32TxFailureCount;
                sinfo->txrate.legacy = strStatistics.u8LinkSpeed * 10;
 
-#ifdef TCP_ENHANCEMENTS
                if ((strStatistics.u8LinkSpeed > TCP_ACK_FILTER_LINK_SPEED_THRESH) && (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED))
                        Enable_TCP_ACK_Filter(true);
                else if (strStatistics.u8LinkSpeed != DEFAULT_LINK_SPEED)
                        Enable_TCP_ACK_Filter(false);
-#endif
 
                PRINT_D(CORECONFIG_DBG, "*** stats[%d][%d][%d][%d][%d]\n", sinfo->signal, sinfo->rx_packets, sinfo->tx_packets,
                        sinfo->tx_failed, sinfo->txrate.legacy);
        }
-       return s32Error;
+       return 0;
 }
 
 
 /**
- *  @brief      WILC_WFI_change_bss
+ *  @brief      change_bss
  *  @details    Modify parameters for a given BSS.
  *  @param[in]
  *   -use_cts_prot: Whether to use CTS protection
@@ -1722,79 +1605,15 @@ static int WILC_WFI_get_station(struct wiphy *wiphy, struct net_device *dev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int  WILC_WFI_change_bss(struct wiphy *wiphy, struct net_device *dev,
-                               struct bss_parameters *params)
+static int change_bss(struct wiphy *wiphy, struct net_device *dev,
+                     struct bss_parameters *params)
 {
        PRINT_D(CFG80211_DBG, "Changing Bss parametrs\n");
        return 0;
 }
 
 /**
- *  @brief      WILC_WFI_auth
- *  @details    Request to authenticate with the specified peer
- *  @param[in]
- *  @return     int : Return 0 on Success.
- *  @author    mdaftedar
- *  @date      01 MAR 2012
- *  @version   1.0
- */
-static int WILC_WFI_auth(struct wiphy *wiphy, struct net_device *dev,
-                        struct cfg80211_auth_request *req)
-{
-       PRINT_D(CFG80211_DBG, "In Authentication Function\n");
-       return 0;
-}
-
-/**
- *  @brief      WILC_WFI_assoc
- *  @details    Request to (re)associate with the specified peer
- *  @param[in]
- *  @return     int : Return 0 on Success.
- *  @author    mdaftedar
- *  @date      01 MAR 2012
- *  @version   1.0
- */
-static int WILC_WFI_assoc(struct wiphy *wiphy, struct net_device *dev,
-                         struct cfg80211_assoc_request *req)
-{
-       PRINT_D(CFG80211_DBG, "In Association Function\n");
-       return 0;
-}
-
-/**
- *  @brief      WILC_WFI_deauth
- *  @details    Request to deauthenticate from the specified peer
- *  @param[in]
- *  @return     int : Return 0 on Success.
- *  @author    mdaftedar
- *  @date      01 MAR 2012
- *  @version   1.0
- */
-static int  WILC_WFI_deauth(struct wiphy *wiphy, struct net_device *dev,
-                           struct cfg80211_deauth_request *req, void *cookie)
-{
-       PRINT_D(CFG80211_DBG, "In De-authentication Function\n");
-       return 0;
-}
-
-/**
- *  @brief      WILC_WFI_disassoc
- *  @details    Request to disassociate from the specified peer
- *  @param[in]
- *  @return     int : Return 0 on Success
- *  @author    mdaftedar
- *  @date      01 MAR 2012
- *  @version   1.0
- */
-static int  WILC_WFI_disassoc(struct wiphy *wiphy, struct net_device *dev,
-                             struct cfg80211_disassoc_request *req, void *cookie)
-{
-       PRINT_D(CFG80211_DBG, "In Disassociation Function\n");
-       return 0;
-}
-
-/**
- *  @brief      WILC_WFI_set_wiphy_params
+ *  @brief      set_wiphy_params
  *  @details    Notify that wiphy parameters have changed;
  *  @param[in]   Changed bitfield (see &enum wiphy_params_flags) describes which values
  *                      have changed.
@@ -1803,33 +1622,33 @@ static int  WILC_WFI_disassoc(struct wiphy *wiphy, struct net_device *dev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_set_wiphy_params(struct wiphy *wiphy, u32 changed)
+static int set_wiphy_params(struct wiphy *wiphy, u32 changed)
 {
-       s32 s32Error = WILC_SUCCESS;
-       tstrCfgParamVal pstrCfgParamVal;
-       struct WILC_WFI_priv *priv;
+       s32 s32Error = 0;
+       struct cfg_param_val pstrCfgParamVal;
+       struct wilc_priv *priv;
 
        priv = wiphy_priv(wiphy);
 
-       pstrCfgParamVal.u32SetCfgFlag = 0;
+       pstrCfgParamVal.flag = 0;
        PRINT_D(CFG80211_DBG, "Setting Wiphy params\n");
 
        if (changed & WIPHY_PARAM_RETRY_SHORT) {
                PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_SHORT %d\n",
                        priv->dev->ieee80211_ptr->wiphy->retry_short);
-               pstrCfgParamVal.u32SetCfgFlag  |= RETRY_SHORT;
+               pstrCfgParamVal.flag  |= RETRY_SHORT;
                pstrCfgParamVal.short_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_short;
        }
        if (changed & WIPHY_PARAM_RETRY_LONG) {
 
                PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RETRY_LONG %d\n", priv->dev->ieee80211_ptr->wiphy->retry_long);
-               pstrCfgParamVal.u32SetCfgFlag |= RETRY_LONG;
+               pstrCfgParamVal.flag |= RETRY_LONG;
                pstrCfgParamVal.long_retry_limit = priv->dev->ieee80211_ptr->wiphy->retry_long;
 
        }
        if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
                PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_FRAG_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->frag_threshold);
-               pstrCfgParamVal.u32SetCfgFlag |= FRAG_THRESHOLD;
+               pstrCfgParamVal.flag |= FRAG_THRESHOLD;
                pstrCfgParamVal.frag_threshold = priv->dev->ieee80211_ptr->wiphy->frag_threshold;
 
        }
@@ -1837,7 +1656,7 @@ static int WILC_WFI_set_wiphy_params(struct wiphy *wiphy, u32 changed)
        if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
                PRINT_D(CFG80211_DBG, "Setting WIPHY_PARAM_RTS_THRESHOLD %d\n", priv->dev->ieee80211_ptr->wiphy->rts_threshold);
 
-               pstrCfgParamVal.u32SetCfgFlag |= RTS_THRESHOLD;
+               pstrCfgParamVal.flag |= RTS_THRESHOLD;
                pstrCfgParamVal.rts_threshold = priv->dev->ieee80211_ptr->wiphy->rts_threshold;
 
        }
@@ -1852,27 +1671,7 @@ static int WILC_WFI_set_wiphy_params(struct wiphy *wiphy, u32 changed)
 }
 
 /**
- *  @brief      WILC_WFI_set_bitrate_mask
- *  @details    set the bitrate mask configuration
- *  @param[in]
- *  @return     int : Return 0 on Success
- *  @author    mdaftedar
- *  @date      01 MAR 2012
- *  @version   1.0
- */
-static int WILC_WFI_set_bitrate_mask(struct wiphy *wiphy,
-                                    struct net_device *dev, const u8 *peer,
-                                    const struct cfg80211_bitrate_mask *mask)
-{
-       s32 s32Error = WILC_SUCCESS;
-
-       PRINT_D(CFG80211_DBG, "Setting Bitrate mask function\n");
-       return s32Error;
-
-}
-
-/**
- *  @brief      WILC_WFI_set_pmksa
+ *  @brief      set_pmksa
  *  @details    Cache a PMKID for a BSSID. This is mostly useful for fullmac
  *                      devices running firmwares capable of generating the (re) association
  *                      RSN IE. It allows for faster roaming between WPA2 BSSIDs.
@@ -1882,14 +1681,14 @@ static int WILC_WFI_set_bitrate_mask(struct wiphy *wiphy,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
-                             struct cfg80211_pmksa *pmksa)
+static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
+                    struct cfg80211_pmksa *pmksa)
 {
        u32 i;
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
        u8 flag = 0;
 
-       struct WILC_WFI_priv *priv = wiphy_priv(wiphy);
+       struct wilc_priv *priv = wiphy_priv(wiphy);
 
        PRINT_D(CFG80211_DBG, "Setting PMKSA\n");
 
@@ -1924,7 +1723,7 @@ static int WILC_WFI_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 }
 
 /**
- *  @brief      WILC_WFI_del_pmksa
+ *  @brief      del_pmksa
  *  @details    Delete a cached PMKID.
  *  @param[in]
  *  @return     int : Return 0 on Success
@@ -1932,15 +1731,14 @@ static int WILC_WFI_set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
-                             struct cfg80211_pmksa *pmksa)
+static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
+                    struct cfg80211_pmksa *pmksa)
 {
 
        u32 i;
-       u8 flag = 0;
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
 
-       struct WILC_WFI_priv *priv = wiphy_priv(wiphy);
+       struct wilc_priv *priv = wiphy_priv(wiphy);
 
        PRINT_D(CFG80211_DBG, "Deleting PMKSA keys\n");
 
@@ -1949,8 +1747,7 @@ static int WILC_WFI_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
                                 ETH_ALEN)) {
                        /*If bssid is found, reset the values*/
                        PRINT_D(CFG80211_DBG, "Reseting PMKID values\n");
-                       memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(tstrHostIFpmkid));
-                       flag = PMKID_FOUND;
+                       memset(&priv->pmkid_list.pmkidlist[i], 0, sizeof(struct host_if_pmkid));
                        break;
                }
        }
@@ -1973,7 +1770,7 @@ static int WILC_WFI_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
 }
 
 /**
- *  @brief      WILC_WFI_flush_pmksa
+ *  @brief      flush_pmksa
  *  @details    Flush all cached PMKIDs.
  *  @param[in]
  *  @return     int : Return 0 on Success
@@ -1981,19 +1778,18 @@ static int WILC_WFI_del_pmksa(struct wiphy *wiphy, struct net_device *netdev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int  WILC_WFI_flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
+static int flush_pmksa(struct wiphy *wiphy, struct net_device *netdev)
 {
-       struct WILC_WFI_priv *priv = wiphy_priv(wiphy);
+       struct wilc_priv *priv = wiphy_priv(wiphy);
 
        PRINT_D(CFG80211_DBG,  "Flushing  PMKID key values\n");
 
        /*Get cashed Pmkids and set all with zeros*/
-       memset(&priv->pmkid_list, 0, sizeof(tstrHostIFpmkidAttr));
+       memset(&priv->pmkid_list, 0, sizeof(struct host_if_pmkid_attr));
 
        return 0;
 }
 
-#ifdef WILC_P2P
 
 /**
  *  @brief      WILC_WFI_CfgParseRxAction
@@ -2014,51 +1810,13 @@ void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
        u32 index = 0;
        u32 i = 0, j = 0;
 
-       /*BugID_5460*/
-       #ifdef USE_SUPPLICANT_GO_INTENT
-       u8 intent;
-       u8 tie_breaker;
-       bool is_wilc_go = true;
-       #endif
        u8 op_channel_attr_index = 0;
        u8 channel_list_attr_index = 0;
 
        while (index < len) {
                if (buf[index] == GO_INTENT_ATTR_ID) {
-                       #ifdef USE_SUPPLICANT_GO_INTENT
-                       /*BugID_5460*/
-                       /*Case 1: If we are going to be p2p client, no need to modify channels attributes*/
-                       /*In negotiation frames, go intent attr value determines who will be GO*/
-                       intent = GET_GO_INTENT(buf[index + 3]);
-                       tie_breaker = GET_TIE_BREAKER(buf[index + 3]);
-                       if (intent > SUPPLICANT_GO_INTENT
-                           || (intent == SUPPLICANT_GO_INTENT && tie_breaker == 1)) {
-                               PRINT_D(GENERIC_DBG, "WILC will be client (intent %d tie breaker %d)\n", intent, tie_breaker);
-                               is_wilc_go = false;
-                       } else {
-                               PRINT_D(GENERIC_DBG, "WILC will be GO (intent %d tie breaker %d)\n", intent, tie_breaker);
-                               is_wilc_go = true;
-                       }
-
-                       #else   /* USE_SUPPLICANT_GO_INTENT */
-                       #ifdef FORCE_P2P_CLIENT
-                       buf[index + 3] = (buf[index + 3]  & 0x01) | (0x0f << 1);
-                       #else
                        buf[index + 3] = (buf[index + 3]  & 0x01) | (0x00 << 1);
-                       #endif
-                       #endif  /* USE_SUPPLICANT_GO_INTENT */
-               }
-
-               #ifdef USE_SUPPLICANT_GO_INTENT
-               /*Case 2: If group bssid attribute is present, no need to modify channels attributes*/
-               /*In invitation req and rsp, group bssid attr presence determines who will be GO*/
-               if (buf[index] == GROUP_BSSID_ATTR_ID) {
-                       PRINT_D(GENERIC_DBG, "Group BSSID: %2x:%2x:%2x\n", buf[index + 3]
-                               , buf[index + 4]
-                               , buf[index + 5]);
-                       is_wilc_go = false;
                }
-               #endif  /* USE_SUPPLICANT_GO_INTENT */
 
                if (buf[index] ==  CHANLIST_ATTR_ID)
                        channel_list_attr_index = index;
@@ -2066,13 +1824,8 @@ void WILC_WFI_CfgParseRxAction(u8 *buf, u32 len)
                        op_channel_attr_index = index;
                index += buf[index + 1] + 3; /* ID,Length byte */
        }
+       if (u8WLANChannel != INVALID_CHANNEL) {
 
-       #ifdef USE_SUPPLICANT_GO_INTENT
-       if (u8WLANChannel != INVALID_CHANNEL && is_wilc_go)
-       #else
-       if (u8WLANChannel != INVALID_CHANNEL)
-       #endif
-       {
                /*Modify channel list attribute*/
                if (channel_list_attr_index) {
                        PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
@@ -2111,39 +1864,13 @@ void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
 
        u8 op_channel_attr_index = 0;
        u8 channel_list_attr_index = 0;
-       #ifdef USE_SUPPLICANT_GO_INTENT
-       bool is_wilc_go = false;
-
-       /*BugID_5460*/
-       /*Case 1: If we are already p2p client, no need to modify channels attributes*/
-       /*This to handle the case of inviting a p2p peer to join an existing group which we are a member in*/
-       if (iftype == CLIENT_MODE)
-               return;
-       #endif
 
        while (index < len) {
-               #ifdef USE_SUPPLICANT_GO_INTENT
-               /*Case 2: If group bssid attribute is present, no need to modify channels attributes*/
-               /*In invitation req and rsp, group bssid attr presence determines who will be GO*/
-               /*Note: If we are already p2p client, group bssid attr may also be present (handled in Case 1)*/
-               if (buf[index] == GROUP_BSSID_ATTR_ID) {
-                       PRINT_D(GENERIC_DBG, "Group BSSID: %2x:%2x:%2x\n", buf[index + 3]
-                               , buf[index + 4]
-                               , buf[index + 5]);
-                       is_wilc_go = true;
-               }
-
-               #else   /* USE_SUPPLICANT_GO_INTENT */
                if (buf[index] == GO_INTENT_ATTR_ID) {
-                       #ifdef FORCE_P2P_CLIENT
-                       buf[index + 3] = (buf[index + 3]  & 0x01) | (0x00 << 1);
-                       #else
                        buf[index + 3] = (buf[index + 3]  & 0x01) | (0x0f << 1);
-                       #endif
 
                        break;
                }
-               #endif
 
                if (buf[index] ==  CHANLIST_ATTR_ID)
                        channel_list_attr_index = index;
@@ -2151,14 +1878,8 @@ void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
                        op_channel_attr_index = index;
                index += buf[index + 1] + 3; /* ID,Length byte */
        }
+       if (u8WLANChannel != INVALID_CHANNEL && bOperChan) {
 
-       #ifdef USE_SUPPLICANT_GO_INTENT
-       /*No need to check bOperChan since only transmitted invitation frames are parsed*/
-       if (u8WLANChannel != INVALID_CHANNEL && is_wilc_go)
-       #else
-       if (u8WLANChannel != INVALID_CHANNEL && bOperChan)
-       #endif
-       {
                /*Modify channel list attribute*/
                if (channel_list_attr_index) {
                        PRINT_D(GENERIC_DBG, "Modify channel list attribute\n");
@@ -2190,16 +1911,17 @@ void WILC_WFI_CfgParseTxAction(u8 *buf, u32 len, bool bOperChan, u8 iftype)
  *  @version           1.0
  */
 
-void WILC_WFI_p2p_rx (struct net_device *dev, uint8_t *buff, uint32_t size)
+void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
 {
 
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        u32 header, pkt_offset;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct host_if_drv *pstrWFIDrv;
        u32 i = 0;
        s32 s32Freq;
+
        priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
 
        /* Get WILC header */
        memcpy(&header, (buff - HOST_HDR_OFFSET), HOST_HDR_OFFSET);
@@ -2229,14 +1951,13 @@ void WILC_WFI_p2p_rx (struct net_device *dev, uint8_t *buff, uint32_t size)
 
                PRINT_D(GENERIC_DBG, "Rx Frame Type:%x\n", buff[FRAME_TYPE_ID]);
 
-               /*BugID_5442*/
                /*Upper layer is informed that the frame is received on this freq*/
-               s32Freq = ieee80211_channel_to_frequency(u8CurrChannel, IEEE80211_BAND_2GHZ);
+               s32Freq = ieee80211_channel_to_frequency(curr_channel, IEEE80211_BAND_2GHZ);
 
                if (ieee80211_is_action(buff[FRAME_TYPE_ID])) {
                        PRINT_D(GENERIC_DBG, "Rx Action Frame Type: %x %x\n", buff[ACTION_SUBTYPE_ID], buff[P2P_PUB_ACTION_SUBTYPE]);
 
-                       if (priv->bCfgScanning == true && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
+                       if (priv->bCfgScanning && time_after_eq(jiffies, (unsigned long)pstrWFIDrv->u64P2p_MgmtTimeout)) {
                                PRINT_D(GENERIC_DBG, "Receiving action frames from wrong channels\n");
                                return;
                        }
@@ -2332,8 +2053,9 @@ static void WILC_WFI_mgmt_tx_complete(void *priv, int status)
 
 static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
 {
-       struct WILC_WFI_priv *priv;
-       priv = (struct WILC_WFI_priv *)pUserVoid;
+       struct wilc_priv *priv;
+
+       priv = (struct wilc_priv *)pUserVoid;
 
        PRINT_D(HOSTINF_DBG, "Remain on channel ready\n");
 
@@ -2358,10 +2080,10 @@ static void WILC_WFI_RemainOnChannelReady(void *pUserVoid)
 
 static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
 {
-       struct WILC_WFI_priv *priv;
-       priv = (struct WILC_WFI_priv *)pUserVoid;
+       struct wilc_priv *priv;
+
+       priv = (struct wilc_priv *)pUserVoid;
 
-       /*BugID_5477*/
        if (u32SessionID == priv->strRemainOnChanParams.u32ListenSessionID) {
                PRINT_D(GENERIC_DBG, "Remain on channel expired\n");
 
@@ -2380,7 +2102,7 @@ static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
 
 
 /**
- *  @brief      WILC_WFI_remain_on_channel
+ *  @brief      remain_on_channel
  *  @details    Request the driver to remain awake on the specified
  *                      channel for the specified duration to complete an off-channel
  *                      operation (e.g., public action frame exchange). When the driver is
@@ -2392,27 +2114,25 @@ static void WILC_WFI_RemainOnChannelExpired(void *pUserVoid, u32 u32SessionID)
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int  WILC_WFI_remain_on_channel(struct wiphy *wiphy,
-                                      struct wireless_dev *wdev,
-                                      struct ieee80211_channel *chan,
-                                      unsigned int duration, u64 *cookie)
+static int remain_on_channel(struct wiphy *wiphy,
+                            struct wireless_dev *wdev,
+                            struct ieee80211_channel *chan,
+                            unsigned int duration, u64 *cookie)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
+       s32 s32Error = 0;
+       struct wilc_priv *priv;
+
        priv = wiphy_priv(wiphy);
 
        PRINT_D(GENERIC_DBG, "Remaining on channel %d\n", chan->hw_value);
 
-       /*BugID_4800: if in AP mode, return.*/
-       /*This check is to handle the situation when user*/
-       /*requests "create group" during a running scan*/
 
        if (wdev->iftype == NL80211_IFTYPE_AP) {
                PRINT_D(GENERIC_DBG, "Required remain-on-channel while in AP mode");
                return s32Error;
        }
 
-       u8CurrChannel = chan->hw_value;
+       curr_channel = chan->hw_value;
 
        /*Setting params needed by WILC_WFI_RemainOnChannelExpired()*/
        priv->strRemainOnChanParams.pstrListenChan = chan;
@@ -2432,7 +2152,7 @@ static int  WILC_WFI_remain_on_channel(struct wiphy *wiphy,
 }
 
 /**
- *  @brief      WILC_WFI_cancel_remain_on_channel
+ *  @brief      cancel_remain_on_channel
  *  @details    Cancel an on-going remain-on-channel operation.
  *                      This allows the operation to be terminated prior to timeout based on
  *                      the duration value.
@@ -2444,12 +2164,13 @@ static int  WILC_WFI_remain_on_channel(struct wiphy *wiphy,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int   WILC_WFI_cancel_remain_on_channel(struct wiphy *wiphy,
-                                              struct wireless_dev *wdev,
-                                              u64 cookie)
+static int cancel_remain_on_channel(struct wiphy *wiphy,
+                                   struct wireless_dev *wdev,
+                                   u64 cookie)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
+       s32 s32Error = 0;
+       struct wilc_priv *priv;
+
        priv = wiphy_priv(wiphy);
 
        PRINT_D(CFG80211_DBG, "Cancel remain on channel\n");
@@ -2457,20 +2178,6 @@ static int   WILC_WFI_cancel_remain_on_channel(struct wiphy *wiphy,
        s32Error = host_int_ListenStateExpired(priv->hWILCWFIDrv, priv->strRemainOnChanParams.u32ListenSessionID);
        return s32Error;
 }
-/**
- *  @brief       WILC_WFI_add_wilcvendorspec
- *  @details    Adding WILC information elemet to allow two WILC devices to
- *                              identify each other and connect
- *  @param[in]   u8 * buf
- *  @return     void
- *  @author    mdaftedar
- *  @date      01 JAN 2014
- *  @version   1.0
- */
-void WILC_WFI_add_wilcvendorspec(u8 *buff)
-{
-       memcpy(buff, u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
-}
 /**
  *  @brief      WILC_WFI_mgmt_tx_frame
  *  @details
@@ -2481,12 +2188,11 @@ void WILC_WFI_add_wilcvendorspec(u8 *buff)
  *  @date      01 JUL 2012
  *  @version
  */
-extern linux_wlan_t *g_linux_wlan;
 extern bool bEnablePS;
-int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
-                       struct wireless_dev *wdev,
-                       struct cfg80211_mgmt_tx_params *params,
-                       u64 *cookie)
+static int mgmt_tx(struct wiphy *wiphy,
+                  struct wireless_dev *wdev,
+                  struct cfg80211_mgmt_tx_params *params,
+                  u64 *cookie)
 {
        struct ieee80211_channel *chan = params->chan;
        unsigned int wait = params->wait;
@@ -2494,16 +2200,15 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
        size_t len = params->len;
        const struct ieee80211_mgmt *mgmt;
        struct p2p_mgmt_data *mgmt_tx;
-       struct WILC_WFI_priv *priv;
-       s32 s32Error = WILC_SUCCESS;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct wilc_priv *priv;
+       struct host_if_drv *pstrWFIDrv;
        u32 i;
        perInterface_wlan_t *nic;
        u32 buf_len = len + sizeof(u8P2P_vendorspec) + sizeof(u8P2Plocalrandom);
 
        nic = netdev_priv(wdev->netdev);
        priv = wiphy_priv(wiphy);
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
 
        *cookie = (unsigned long)buf;
        priv->u64tx_cookie = *cookie;
@@ -2512,15 +2217,16 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
        if (ieee80211_is_mgmt(mgmt->frame_control)) {
 
                /*mgmt frame allocation*/
-               mgmt_tx = WILC_MALLOC(sizeof(struct p2p_mgmt_data));
+               mgmt_tx = kmalloc(sizeof(struct p2p_mgmt_data), GFP_KERNEL);
                if (mgmt_tx == NULL) {
                        PRINT_ER("Failed to allocate memory for mgmt_tx structure\n");
-                       return WILC_FAIL;
+                       return -EFAULT;
                }
-               mgmt_tx->buff = WILC_MALLOC(buf_len);
+               mgmt_tx->buff = kmalloc(buf_len, GFP_KERNEL);
                if (mgmt_tx->buff == NULL) {
                        PRINT_ER("Failed to allocate memory for mgmt_tx buff\n");
-                       return WILC_FAIL;
+                       kfree(mgmt_tx);
+                       return -EFAULT;
                }
                memcpy(mgmt_tx->buff, buf, len);
                mgmt_tx->size = len;
@@ -2531,14 +2237,12 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
                        PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
                        host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
                        /*Save the current channel after we tune to it*/
-                       u8CurrChannel = chan->hw_value;
+                       curr_channel = chan->hw_value;
                } else if (ieee80211_is_action(mgmt->frame_control))   {
                        PRINT_D(GENERIC_DBG, "ACTION FRAME:%x\n", (u16)mgmt->frame_control);
 
 
-                       /*BugID_4847*/
                        if (buf[ACTION_CAT_ID] == PUB_ACTION_ATTR_ID) {
-                               /*BugID_4847*/
                                /*Only set the channel, if not a negotiation confirmation frame
                                 * (If Negotiation confirmation frame, force it
                                 * to be transmitted on the same negotiation channel)*/
@@ -2548,7 +2252,7 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
                                        PRINT_D(GENERIC_DBG, "Setting channel: %d\n", chan->hw_value);
                                        host_int_set_mac_chnl_num(priv->hWILCWFIDrv, chan->hw_value);
                                        /*Save the current channel after we tune to it*/
-                                       u8CurrChannel = chan->hw_value;
+                                       curr_channel = chan->hw_value;
                                }
                                switch (buf[ACTION_SUBTYPE_ID]) {
                                case GAS_INTIAL_REQ:
@@ -2588,19 +2292,20 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
                                                                                if (buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_REQ || buf[P2P_PUB_ACTION_SUBTYPE] == P2P_INV_RSP)
                                                                                        WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), true, nic->iftype);
 
-                                                                               /*BugID_5460*/
                                                                                /*If using supplicant go intent, no need at all*/
                                                                                /*to parse transmitted negotiation frames*/
-                                                                                       #ifndef USE_SUPPLICANT_GO_INTENT
                                                                                else
                                                                                        WILC_WFI_CfgParseTxAction(&mgmt_tx->buff[i + 6], len - (i + 6), false, nic->iftype);
-                                                                                       #endif
                                                                                break;
                                                                        }
                                                                }
 
                                                                if (buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_REQ && buf[P2P_PUB_ACTION_SUBTYPE] != P2P_INV_RSP) {
-                                                                       WILC_WFI_add_wilcvendorspec(&mgmt_tx->buff[len]);
+                                                                       /*
+                                                                        * Adding WILC information element to allow two WILC devices to
+                                                                        * identify each other and connect
+                                                                        */
+                                                                       memcpy(&mgmt_tx->buff[len], u8P2P_vendorspec, sizeof(u8P2P_vendorspec));
                                                                        mgmt_tx->buff[len + sizeof(u8P2P_vendorspec)] = u8P2Plocalrandom;
                                                                        mgmt_tx->size = buf_len;
                                                                }
@@ -2631,29 +2336,30 @@ int WILC_WFI_mgmt_tx(struct wiphy *wiphy,
 
                }
 
-               g_linux_wlan->oup.wlan_add_mgmt_to_tx_que(mgmt_tx, mgmt_tx->buff, mgmt_tx->size, WILC_WFI_mgmt_tx_complete);
+               wilc_wlan_txq_add_mgmt_pkt(mgmt_tx, mgmt_tx->buff,
+                                          mgmt_tx->size,
+                                          WILC_WFI_mgmt_tx_complete);
        } else {
                PRINT_D(GENERIC_DBG, "This function transmits only management frames\n");
        }
-       return s32Error;
+       return 0;
 }
 
-int   WILC_WFI_mgmt_tx_cancel_wait(struct wiphy *wiphy,
-                                  struct wireless_dev *wdev,
-                                  u64 cookie)
+static int mgmt_tx_cancel_wait(struct wiphy *wiphy,
+                              struct wireless_dev *wdev,
+                              u64 cookie)
 {
-       struct WILC_WFI_priv *priv;
-       tstrWILC_WFIDrv *pstrWFIDrv;
+       struct wilc_priv *priv;
+       struct host_if_drv *pstrWFIDrv;
+
        priv = wiphy_priv(wiphy);
-       pstrWFIDrv = (tstrWILC_WFIDrv *)priv->hWILCWFIDrv;
+       pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
 
 
        PRINT_D(GENERIC_DBG, "Tx Cancel wait :%lu\n", jiffies);
        pstrWFIDrv->u64P2p_MgmtTimeout = jiffies;
 
-       if (priv->bInP2PlistenState == false) {
-               /* Bug 5504: This is just to avoid connection failure when getting stuck when the supplicant
-                *                      considers the driver falsely that it is in Listen state */
+       if (!priv->bInP2PlistenState) {
                cfg80211_remain_on_channel_expired(priv->wdev,
                                                   priv->strRemainOnChanParams.u64ListenCookie,
                                                   priv->strRemainOnChanParams.pstrListenChan,
@@ -2664,7 +2370,7 @@ int   WILC_WFI_mgmt_tx_cancel_wait(struct wiphy *wiphy,
 }
 
 /**
- *  @brief      WILC_WFI_frame_register
+ *  @brief      wilc_mgmt_frame_register
  *  @details Notify driver that a management frame type was
  *              registered. Note that this callback may not sleep, and cannot run
  *                      concurrently with itself.
@@ -2674,21 +2380,18 @@ int   WILC_WFI_mgmt_tx_cancel_wait(struct wiphy *wiphy,
  *  @date      01 JUL 2012
  *  @version
  */
-void    WILC_WFI_frame_register(struct wiphy *wiphy,
-                               struct wireless_dev *wdev,
-                               u16 frame_type, bool reg)
+void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
+                             u16 frame_type, bool reg)
 {
 
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        perInterface_wlan_t *nic;
-
+       struct wilc *wl;
 
        priv = wiphy_priv(wiphy);
        nic = netdev_priv(priv->wdev->netdev);
+       wl = nic->wilc;
 
-
-
-       /*BugID_5137*/
        if (!frame_type)
                return;
 
@@ -2715,7 +2418,7 @@ void    WILC_WFI_frame_register(struct wiphy *wiphy,
 
        }
        /*If mac is closed, then return*/
-       if (!g_linux_wlan->wilc1000_initialized) {
+       if (!wl->initialized) {
                PRINT_D(GENERIC_DBG, "Return since mac is closed\n");
                return;
        }
@@ -2723,10 +2426,9 @@ void    WILC_WFI_frame_register(struct wiphy *wiphy,
 
 
 }
-#endif /*WILC_P2P*/
 
 /**
- *  @brief      WILC_WFI_set_cqm_rssi_config
+ *  @brief      set_cqm_rssi_config
  *  @details    Configure connection quality monitor RSSI threshold.
  *  @param[in]   struct wiphy *wiphy:
  *  @param[in] struct net_device *dev:
@@ -2737,15 +2439,15 @@ void    WILC_WFI_frame_register(struct wiphy *wiphy,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int    WILC_WFI_set_cqm_rssi_config(struct wiphy *wiphy,
-                                          struct net_device *dev,  s32 rssi_thold, u32 rssi_hyst)
+static int set_cqm_rssi_config(struct wiphy *wiphy, struct net_device *dev,
+                              s32 rssi_thold, u32 rssi_hyst)
 {
        PRINT_D(CFG80211_DBG, "Setting CQM RSSi Function\n");
        return 0;
 
 }
 /**
- *  @brief      WILC_WFI_dump_station
+ *  @brief      dump_station
  *  @details    Configure connection quality monitor RSSI threshold.
  *  @param[in]   struct wiphy *wiphy:
  *  @param[in] struct net_device *dev
@@ -2757,10 +2459,11 @@ static int    WILC_WFI_set_cqm_rssi_config(struct wiphy *wiphy,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_dump_station(struct wiphy *wiphy, struct net_device *dev,
-                                int idx, u8 *mac, struct station_info *sinfo)
+static int dump_station(struct wiphy *wiphy, struct net_device *dev,
+                       int idx, u8 *mac, struct station_info *sinfo)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
+
        PRINT_D(CFG80211_DBG, "Dumping station information\n");
 
        if (idx != 0)
@@ -2778,18 +2481,19 @@ static int WILC_WFI_dump_station(struct wiphy *wiphy, struct net_device *dev,
 
 
 /**
- *  @brief      WILC_WFI_set_power_mgmt
+ *  @brief      set_power_mgmt
  *  @details
  *  @param[in]
  *  @return     int : Return 0 on Success.
  *  @author    mdaftedar
  *  @date      01 JUL 2012
- *  @version   1.0WILC_WFI_set_cqmWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_config_rssi_config
+ *  @version   1.0
  */
-int WILC_WFI_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
-                           bool enabled, int timeout)
+static int set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
+                         bool enabled, int timeout)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
+
        PRINT_D(CFG80211_DBG, " Power save Enabled= %d , TimeOut = %d\n", enabled, timeout);
 
        if (wiphy == NULL)
@@ -2805,12 +2509,12 @@ int WILC_WFI_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
                host_int_set_power_mgmt(priv->hWILCWFIDrv, enabled, timeout);
 
 
-       return WILC_SUCCESS;
+       return 0;
 
 }
-#ifdef WILC_AP_EXTERNAL_MLME
+
 /**
- *  @brief      WILC_WFI_change_virt_intf
+ *  @brief      change_virtual_intf
  *  @details    Change type/configuration of virtual interface,
  *                      keep the struct wireless_dev's iftype updated.
  *  @param[in]   NONE
@@ -2819,23 +2523,21 @@ int WILC_WFI_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-void wilc1000_wlan_deinit(linux_wlan_t *nic);
 int wilc1000_wlan_init(struct net_device *dev, perInterface_wlan_t *p_nic);
 
-static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev,
-                                    enum nl80211_iftype type, u32 *flags, struct vif_params *params)
+static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
+                              enum nl80211_iftype type, u32 *flags, struct vif_params *params)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        perInterface_wlan_t *nic;
        u8 interface_type;
        u16 TID = 0;
-       #ifdef WILC_P2P
        u8 i;
-       #endif
+       struct wilc *wl;
 
        nic = netdev_priv(dev);
        priv = wiphy_priv(wiphy);
+       wl = nic->wilc;
 
        PRINT_D(HOSTAPD_DBG, "In Change virtual interface function\n");
        PRINT_D(HOSTAPD_DBG, "Wireless interface name =%s\n", dev->name);
@@ -2844,15 +2546,12 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
 
        bWilc_ie = false;
 
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
        g_obtainingIP = false;
        del_timer(&hDuringIpTimer);
        PRINT_D(GENERIC_DBG, "Changing virtual interface, enable scan\n");
-       #endif
-       /*BugID_5137*/
        /*Set WILC_CHANGING_VIR_IF register to disallow adding futrue keys to CE H/W*/
        if (g_ptk_keys_saved && g_gtk_keys_saved) {
-               Set_machw_change_vir_if(true);
+               Set_machw_change_vir_if(dev, true);
        }
 
        switch (type) {
@@ -2870,35 +2569,34 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
 
                /*Remove the enteries of the previously connected clients*/
                memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
-               #ifdef WILC_P2P
                interface_type = nic->iftype;
                nic->iftype = STATION_MODE;
 
-               if (g_linux_wlan->wilc1000_initialized) {
-                       host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
+               if (wl->initialized) {
+                       host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
+                                                     wl->vif[0].bssid, TID);
                        /* ensure that the message Q is empty */
                        host_int_wait_msg_queue_idle();
 
-                       /*BugID_5213*/
                        /*Eliminate host interface blocking state*/
-                       linux_wlan_unlock((void *)&g_linux_wlan->cfg_event);
+                       up(&wl->cfg_event);
 
-                       wilc1000_wlan_deinit(g_linux_wlan);
+                       wilc1000_wlan_deinit(dev);
                        wilc1000_wlan_init(dev, nic);
                        g_wilc_initialized = 1;
                        nic->iftype = interface_type;
 
                        /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
-                       host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
-                       host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
-                                               g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
+                       host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
+                       host_int_set_MacAddress(wl->vif[0].hif_drv,
+                                               wl->vif[0].src_addr);
                        host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
 
                        /*Add saved WEP keys, if any*/
                        if (g_wep_keys_saved) {
-                               host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
+                               host_int_set_wep_default_key(wl->vif[0].hif_drv,
                                                             g_key_wep_params.key_idx);
-                               host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
+                               host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
                                                             g_key_wep_params.key,
                                                             g_key_wep_params.key_len,
                                                             g_key_wep_params.key_idx);
@@ -2916,24 +2614,22 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                                PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
                                        g_key_gtk_params.key[1],
                                        g_key_gtk_params.key[2]);
-                               WILC_WFI_add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
-                                                g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
-                                                g_add_ptk_key_params.key_idx,
-                                                g_add_ptk_key_params.pairwise,
-                                                g_add_ptk_key_params.mac_addr,
-                                                (struct key_params *)(&g_key_ptk_params));
-
-                               WILC_WFI_add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
-                                                g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
-                                                g_add_gtk_key_params.key_idx,
-                                                g_add_gtk_key_params.pairwise,
-                                                g_add_gtk_key_params.mac_addr,
-                                                (struct key_params *)(&g_key_gtk_params));
+                               add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
+                                       wl->vif[0].ndev,
+                                       g_add_ptk_key_params.key_idx,
+                                       g_add_ptk_key_params.pairwise,
+                                       g_add_ptk_key_params.mac_addr,
+                                       (struct key_params *)(&g_key_ptk_params));
+
+                               add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
+                                       wl->vif[0].ndev,
+                                       g_add_gtk_key_params.key_idx,
+                                       g_add_gtk_key_params.pairwise,
+                                       g_add_gtk_key_params.mac_addr,
+                                       (struct key_params *)(&g_key_gtk_params));
                        }
 
-                       /*BugID_4847: registered frames in firmware are now*/
-                       /*lost due to mac close. So re-register those frames*/
-                       if (g_linux_wlan->wilc1000_initialized) {
+                       if (wl->initialized)    {
                                for (i = 0; i < num_reg_frame; i++) {
                                        PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
                                                nic->g_struct_frame_reg[i].reg);
@@ -2946,7 +2642,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                        bEnablePS = true;
                        host_int_set_power_mgmt(priv->hWILCWFIDrv, 1, 0);
                }
-               #endif
                break;
 
        case NL80211_IFTYPE_P2P_CLIENT:
@@ -2955,36 +2650,35 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                connecting = 0;
                PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
 
-               host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
+               host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
+                                             wl->vif[0].bssid, TID);
 
                dev->ieee80211_ptr->iftype = type;
                priv->wdev->iftype = type;
                nic->monitor_flag = 0;
 
-               #ifdef WILC_P2P
-
                PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
                nic->iftype = CLIENT_MODE;
 
 
-               if (g_linux_wlan->wilc1000_initialized) {
+               if (wl->initialized)    {
                        /* ensure that the message Q is empty */
                        host_int_wait_msg_queue_idle();
 
-                       wilc1000_wlan_deinit(g_linux_wlan);
+                       wilc1000_wlan_deinit(dev);
                        wilc1000_wlan_init(dev, nic);
                        g_wilc_initialized = 1;
 
-                       host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
-                       host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
-                                               g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
+                       host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
+                       host_int_set_MacAddress(wl->vif[0].hif_drv,
+                                               wl->vif[0].src_addr);
                        host_int_set_operation_mode(priv->hWILCWFIDrv, STATION_MODE);
 
                        /*Add saved WEP keys, if any*/
                        if (g_wep_keys_saved) {
-                               host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
+                               host_int_set_wep_default_key(wl->vif[0].hif_drv,
                                                             g_key_wep_params.key_idx);
-                               host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
+                               host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
                                                             g_key_wep_params.key,
                                                             g_key_wep_params.key_len,
                                                             g_key_wep_params.key_idx);
@@ -3002,28 +2696,26 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                                PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
                                        g_key_gtk_params.key[1],
                                        g_key_gtk_params.key[2]);
-                               WILC_WFI_add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
-                                                g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
-                                                g_add_ptk_key_params.key_idx,
-                                                g_add_ptk_key_params.pairwise,
-                                                g_add_ptk_key_params.mac_addr,
-                                                (struct key_params *)(&g_key_ptk_params));
-
-                               WILC_WFI_add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
-                                                g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
-                                                g_add_gtk_key_params.key_idx,
-                                                g_add_gtk_key_params.pairwise,
-                                                g_add_gtk_key_params.mac_addr,
-                                                (struct key_params *)(&g_key_gtk_params));
+                               add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
+                                       wl->vif[0].ndev,
+                                       g_add_ptk_key_params.key_idx,
+                                       g_add_ptk_key_params.pairwise,
+                                       g_add_ptk_key_params.mac_addr,
+                                       (struct key_params *)(&g_key_ptk_params));
+
+                               add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
+                                       wl->vif[0].ndev,
+                                       g_add_gtk_key_params.key_idx,
+                                       g_add_gtk_key_params.pairwise,
+                                       g_add_gtk_key_params.mac_addr,
+                                       (struct key_params *)(&g_key_gtk_params));
                        }
 
                        /*Refresh scan, to refresh the scan results to the wpa_supplicant. Set MachHw to false to enable further key installments*/
                        refresh_scan(priv, 1, true);
-                       Set_machw_change_vir_if(false);
+                       Set_machw_change_vir_if(dev, false);
 
-                       /*BugID_4847: registered frames in firmware are now lost
-                        *  due to mac close. So re-register those frames */
-                       if (g_linux_wlan->wilc1000_initialized) {
+                       if (wl->initialized)    {
                                for (i = 0; i < num_reg_frame; i++) {
                                        PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
                                                nic->g_struct_frame_reg[i].reg);
@@ -3033,7 +2725,6 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                                }
                        }
                }
-               #endif
                break;
 
        case NL80211_IFTYPE_AP:
@@ -3046,16 +2737,12 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
 
                PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
                linux_wlan_get_firmware(nic);
-               #ifdef WILC_P2P
                /*If wilc is running, then close-open to actually get new firmware running (serves P2P)*/
-               if (g_linux_wlan->wilc1000_initialized) {
+               if (wl->initialized)    {
                        nic->iftype = AP_MODE;
-                       g_linux_wlan->wilc1000_initialized = 1;
                        mac_close(dev);
                        mac_open(dev);
 
-                       /*BugID_4847: registered frames in firmware are now lost
-                        * due to mac close. So re-register those frames */
                        for (i = 0; i < num_reg_frame; i++) {
                                PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
                                        nic->g_struct_frame_reg[i].reg);
@@ -3064,23 +2751,20 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                                                        nic->g_struct_frame_reg[i].reg);
                        }
                }
-               #endif
                break;
 
        case NL80211_IFTYPE_P2P_GO:
                PRINT_D(GENERIC_DBG, "start duringIP timer\n");
 
-               #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
                g_obtainingIP = true;
                mod_timer(&hDuringIpTimer, jiffies + msecs_to_jiffies(duringIP_TIME));
-               #endif
                host_int_set_power_mgmt(priv->hWILCWFIDrv, 0, 0);
-               /*BugID_5222*/
                /*Delete block ack has to be the latest config packet*/
                /*sent before downloading new FW. This is because it blocks on*/
                /*hWaitResponse semaphore, which allows previous config*/
                /*packets to actually take action on old FW*/
-               host_int_del_All_Rx_BASession(priv->hWILCWFIDrv, g_linux_wlan->strInterfaceInfo[0].aBSSID, TID);
+               host_int_del_All_Rx_BASession(priv->hWILCWFIDrv,
+                                             wl->vif[0].bssid, TID);
                bEnablePS = false;
                PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
                dev->ieee80211_ptr->iftype = type;
@@ -3088,31 +2772,29 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
 
                PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
 
-               #ifdef WILC_P2P
                PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
 
 
-               #if 1
                nic->iftype = GO_MODE;
 
                /* ensure that the message Q is empty */
                host_int_wait_msg_queue_idle();
-               wilc1000_wlan_deinit(g_linux_wlan);
+               wilc1000_wlan_deinit(dev);
                wilc1000_wlan_init(dev, nic);
                g_wilc_initialized = 1;
 
 
                /*Setting interface 1 drv handler and mac address in newly downloaded FW*/
-               host_int_set_wfi_drv_handler(g_linux_wlan->strInterfaceInfo[0].drvHandler);
-               host_int_set_MacAddress(g_linux_wlan->strInterfaceInfo[0].drvHandler,
-                                       g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
+               host_int_set_wfi_drv_handler(wl->vif[0].hif_drv);
+               host_int_set_MacAddress(wl->vif[0].hif_drv,
+                                       wl->vif[0].src_addr);
                host_int_set_operation_mode(priv->hWILCWFIDrv, AP_MODE);
 
                /*Add saved WEP keys, if any*/
                if (g_wep_keys_saved) {
-                       host_int_set_WEPDefaultKeyID(g_linux_wlan->strInterfaceInfo[0].drvHandler,
+                       host_int_set_wep_default_key(wl->vif[0].hif_drv,
                                                     g_key_wep_params.key_idx);
-                       host_int_add_wep_key_bss_sta(g_linux_wlan->strInterfaceInfo[0].drvHandler,
+                       host_int_add_wep_key_bss_sta(wl->vif[0].hif_drv,
                                                     g_key_wep_params.key,
                                                     g_key_wep_params.key_len,
                                                     g_key_wep_params.key_idx);
@@ -3132,27 +2814,22 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                                g_key_gtk_params.key[1],
                                g_key_gtk_params.key[2],
                                g_key_gtk_params.cipher);
-                       #if 1
-                       WILC_WFI_add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
-                                        g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
-                                        g_add_ptk_key_params.key_idx,
-                                        g_add_ptk_key_params.pairwise,
-                                        g_add_ptk_key_params.mac_addr,
-                                        (struct key_params *)(&g_key_ptk_params));
-
-                       WILC_WFI_add_key(g_linux_wlan->strInterfaceInfo[0].wilc_netdev->ieee80211_ptr->wiphy,
-                                        g_linux_wlan->strInterfaceInfo[0].wilc_netdev,
-                                        g_add_gtk_key_params.key_idx,
-                                        g_add_gtk_key_params.pairwise,
-                                        g_add_gtk_key_params.mac_addr,
-                                        (struct key_params *)(&g_key_gtk_params));
-                       #endif
+                       add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
+                               wl->vif[0].ndev,
+                               g_add_ptk_key_params.key_idx,
+                               g_add_ptk_key_params.pairwise,
+                               g_add_ptk_key_params.mac_addr,
+                               (struct key_params *)(&g_key_ptk_params));
+
+                       add_key(wl->vif[0].ndev->ieee80211_ptr->wiphy,
+                               wl->vif[0].ndev,
+                               g_add_gtk_key_params.key_idx,
+                               g_add_gtk_key_params.pairwise,
+                               g_add_gtk_key_params.mac_addr,
+                               (struct key_params *)(&g_key_gtk_params));
                }
-               #endif
 
-               /*BugID_4847: registered frames in firmware are now*/
-               /*lost due to mac close. So re-register those frames*/
-               if (g_linux_wlan->wilc1000_initialized) {
+               if (wl->initialized)    {
                        for (i = 0; i < num_reg_frame; i++) {
                                PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", nic->g_struct_frame_reg[i].frame_type,
                                        nic->g_struct_frame_reg[i].reg);
@@ -3161,17 +2838,14 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
                                                        nic->g_struct_frame_reg[i].reg);
                        }
                }
-               #endif
                break;
 
        default:
                PRINT_ER("Unknown interface type= %d\n", type);
-               s32Error = -EINVAL;
-               return s32Error;
-               break;
+               return -EINVAL;
        }
 
-       return s32Error;
+       return 0;
 }
 
 /* (austin.2013-07-23)
@@ -3189,7 +2863,7 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
  */
 
 /**
- *  @brief      WILC_WFI_start_ap
+ *  @brief      start_ap
  *  @details    Add a beacon with given parameters, @head, @interval
  *                      and @dtim_period will be valid, @tail is optional.
  *  @param[in]   wiphy
@@ -3200,45 +2874,41 @@ static int WILC_WFI_change_virt_intf(struct wiphy *wiphy, struct net_device *dev
  *  @date      23 JUL 2013
  *  @version   1.0
  */
-static int WILC_WFI_start_ap(struct wiphy *wiphy, struct net_device *dev,
-                            struct cfg80211_ap_settings *settings)
+static int start_ap(struct wiphy *wiphy, struct net_device *dev,
+                   struct cfg80211_ap_settings *settings)
 {
        struct cfg80211_beacon_data *beacon = &(settings->beacon);
-       struct WILC_WFI_priv *priv;
-       s32 s32Error = WILC_SUCCESS;
+       struct wilc_priv *priv;
+       s32 s32Error = 0;
+       struct wilc *wl;
+       perInterface_wlan_t *nic;
 
        priv = wiphy_priv(wiphy);
+       nic = netdev_priv(dev);
+       wl = nic->wilc;
        PRINT_D(HOSTAPD_DBG, "Starting ap\n");
 
        PRINT_D(HOSTAPD_DBG, "Interval = %d\n DTIM period = %d\n Head length = %zu Tail length = %zu\n",
                settings->beacon_interval, settings->dtim_period, beacon->head_len, beacon->tail_len);
 
-       s32Error = WILC_WFI_CfgSetChannel(wiphy, &settings->chandef);
+       s32Error = set_channel(wiphy, &settings->chandef);
 
-       if (s32Error != WILC_SUCCESS)
+       if (s32Error != 0)
                PRINT_ER("Error in setting channel\n");
 
-       linux_wlan_set_bssid(dev, g_linux_wlan->strInterfaceInfo[0].aSrcAddress);
+       linux_wlan_set_bssid(dev, wl->vif[0].src_addr);
 
-       #ifndef WILC_FULLY_HOSTING_AP
        s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
                                        settings->beacon_interval,
                                        settings->dtim_period,
                                        beacon->head_len, (u8 *)beacon->head,
                                        beacon->tail_len, (u8 *)beacon->tail);
-       #else
-       s32Error = host_add_beacon(priv->hWILCWFIDrv,
-                                       settings->beacon_interval,
-                                       settings->dtim_period,
-                                       beacon->head_len, (u8 *)beacon->head,
-                                       beacon->tail_len, (u8 *)beacon->tail);
-       #endif
 
        return s32Error;
 }
 
 /**
- *  @brief      WILC_WFI_change_beacon
+ *  @brief      change_beacon
  *  @details    Add a beacon with given parameters, @head, @interval
  *                      and @dtim_period will be valid, @tail is optional.
  *  @param[in]   wiphy
@@ -3249,35 +2919,27 @@ static int WILC_WFI_start_ap(struct wiphy *wiphy, struct net_device *dev,
  *  @date      23 JUL 2013
  *  @version   1.0
  */
-static int  WILC_WFI_change_beacon(struct wiphy *wiphy, struct net_device *dev,
-                                  struct cfg80211_beacon_data *beacon)
+static int change_beacon(struct wiphy *wiphy, struct net_device *dev,
+                        struct cfg80211_beacon_data *beacon)
 {
-       struct WILC_WFI_priv *priv;
-       s32 s32Error = WILC_SUCCESS;
+       struct wilc_priv *priv;
+       s32 s32Error = 0;
 
        priv = wiphy_priv(wiphy);
        PRINT_D(HOSTAPD_DBG, "Setting beacon\n");
 
 
-#ifndef WILC_FULLY_HOSTING_AP
        s32Error = host_int_add_beacon(priv->hWILCWFIDrv,
                                        0,
                                        0,
                                        beacon->head_len, (u8 *)beacon->head,
                                        beacon->tail_len, (u8 *)beacon->tail);
-#else
-       s32Error = host_add_beacon(priv->hWILCWFIDrv,
-                                       0,
-                                       0,
-                                       beacon->head_len, (u8 *)beacon->head,
-                                       beacon->tail_len, (u8 *)beacon->tail);
-#endif
 
        return s32Error;
 }
 
 /**
- *  @brief      WILC_WFI_stop_ap
+ *  @brief      stop_ap
  *  @details    Remove beacon configuration and stop sending the beacon.
  *  @param[in]
  *  @return     int : Return 0 on Success.
@@ -3285,38 +2947,31 @@ static int  WILC_WFI_change_beacon(struct wiphy *wiphy, struct net_device *dev,
  *  @date      23 JUL 2013
  *  @version   1.0
  */
-static int  WILC_WFI_stop_ap(struct wiphy *wiphy, struct net_device *dev)
+static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
+       s32 s32Error = 0;
+       struct wilc_priv *priv;
        u8 NullBssid[ETH_ALEN] = {0};
 
-
-       WILC_NULLCHECK(s32Error, wiphy);
+       if (!wiphy)
+               return -EFAULT;
 
        priv = wiphy_priv(wiphy);
 
        PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
 
-       /*BugID_5188*/
        linux_wlan_set_bssid(dev, NullBssid);
 
-       #ifndef WILC_FULLY_HOSTING_AP
        s32Error = host_int_del_beacon(priv->hWILCWFIDrv);
-       #else
-       s32Error = host_del_beacon(priv->hWILCWFIDrv);
-       #endif
 
-       WILC_ERRORCHECK(s32Error);
+       if (s32Error)
+               PRINT_ER("Host delete beacon fail\n");
 
-       WILC_CATCH(s32Error)
-       {
-       }
        return s32Error;
 }
 
 /**
- *  @brief      WILC_WFI_add_station
+ *  @brief      add_station
  *  @details    Add a new station.
  *  @param[in]
  *  @return     int : Return 0 on Success.
@@ -3324,23 +2979,21 @@ static int  WILC_WFI_stop_ap(struct wiphy *wiphy, struct net_device *dev)
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int  WILC_WFI_add_station(struct wiphy *wiphy, struct net_device *dev,
-                                const u8 *mac, struct station_parameters *params)
+static int add_station(struct wiphy *wiphy, struct net_device *dev,
+                      const u8 *mac, struct station_parameters *params)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
-       tstrWILC_AddStaParam strStaParams = { {0} };
+       s32 s32Error = 0;
+       struct wilc_priv *priv;
+       struct add_sta_param strStaParams = { {0} };
        perInterface_wlan_t *nic;
 
-
-       WILC_NULLCHECK(s32Error, wiphy);
+       if (!wiphy)
+               return -EFAULT;
 
        priv = wiphy_priv(wiphy);
        nic = netdev_priv(dev);
 
        if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
-               #ifndef WILC_FULLY_HOSTING_AP
-
                memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
                memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
                strStaParams.u16AssocID = params->aid;
@@ -3379,29 +3032,15 @@ static int  WILC_WFI_add_station(struct wiphy *wiphy, struct net_device *dev,
                PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
 
                s32Error = host_int_add_station(priv->hWILCWFIDrv, &strStaParams);
-               WILC_ERRORCHECK(s32Error);
-
-               #else
-               PRINT_D(CFG80211_DBG, "Adding station parameters %d\n", params->aid);
-               memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
-
-               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],
-                       priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid][5]);
-
-               WILC_AP_AddSta(mac, params);
-               WILC_ERRORCHECK(s32Error);
-               #endif /* WILC_FULLY_HOSTING_AP */
-
+               if (s32Error)
+                       PRINT_ER("Host add station fail\n");
        }
 
-       WILC_CATCH(s32Error)
-       {
-       }
        return s32Error;
 }
 
 /**
- *  @brief      WILC_WFI_del_station
+ *  @brief      del_station
  *  @details    Remove a station; @mac may be NULL to remove all stations.
  *  @param[in]
  *  @return     int : Return 0 on Success.
@@ -3409,14 +3048,16 @@ static int  WILC_WFI_add_station(struct wiphy *wiphy, struct net_device *dev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_del_station(struct wiphy *wiphy, struct net_device *dev,
-                               struct station_del_parameters *params)
+static int del_station(struct wiphy *wiphy, struct net_device *dev,
+                      struct station_del_parameters *params)
 {
        const u8 *mac = params->mac;
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
+       s32 s32Error = 0;
+       struct wilc_priv *priv;
        perInterface_wlan_t *nic;
-       WILC_NULLCHECK(s32Error, wiphy);
+
+       if (!wiphy)
+               return -EFAULT;
 
        priv = wiphy_priv(wiphy);
        nic = netdev_priv(dev);
@@ -3432,22 +3073,16 @@ static int WILC_WFI_del_station(struct wiphy *wiphy, struct net_device *dev,
                        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]);
                }
 
-               #ifndef WILC_FULLY_HOSTING_AP
                s32Error = host_int_del_station(priv->hWILCWFIDrv, mac);
-               #else
-               WILC_AP_RemoveSta(mac);
-               #endif /* WILC_FULLY_HOSTING_AP */
 
-               WILC_ERRORCHECK(s32Error);
-       }
-       WILC_CATCH(s32Error)
-       {
+               if (s32Error)
+                       PRINT_ER("Host delete station fail\n");
        }
        return s32Error;
 }
 
 /**
- *  @brief      WILC_WFI_change_station
+ *  @brief      change_station
  *  @details    Modify a given station.
  *  @param[in]
  *  @return     int : Return 0 on Success.
@@ -3455,25 +3090,24 @@ static int WILC_WFI_del_station(struct wiphy *wiphy, struct net_device *dev,
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-static int WILC_WFI_change_station(struct wiphy *wiphy, struct net_device *dev,
-                                  const u8 *mac, struct station_parameters *params)
+static int change_station(struct wiphy *wiphy, struct net_device *dev,
+                         const u8 *mac, struct station_parameters *params)
 {
-       s32 s32Error = WILC_SUCCESS;
-       struct WILC_WFI_priv *priv;
-       tstrWILC_AddStaParam strStaParams = { {0} };
+       s32 s32Error = 0;
+       struct wilc_priv *priv;
+       struct add_sta_param strStaParams = { {0} };
        perInterface_wlan_t *nic;
 
 
        PRINT_D(HOSTAPD_DBG, "Change station paramters\n");
 
-       WILC_NULLCHECK(s32Error, wiphy);
+       if (!wiphy)
+               return -EFAULT;
 
        priv = wiphy_priv(wiphy);
        nic = netdev_priv(dev);
 
        if (nic->iftype == AP_MODE || nic->iftype == GO_MODE) {
-               #ifndef WILC_FULLY_HOSTING_AP
-
                memcpy(strStaParams.au8BSSID, mac, ETH_ALEN);
                strStaParams.u16AssocID = params->aid;
                strStaParams.u8NumRates = params->supported_rates_len;
@@ -3510,23 +3144,15 @@ static int WILC_WFI_change_station(struct wiphy *wiphy, struct net_device *dev,
                PRINT_D(HOSTAPD_DBG, "Flag Set = %d\n", strStaParams.u16FlagsSet);
 
                s32Error = host_int_edit_station(priv->hWILCWFIDrv, &strStaParams);
-               WILC_ERRORCHECK(s32Error);
-
-               #else
-               WILC_AP_EditSta(mac, params);
-               WILC_ERRORCHECK(s32Error);
-               #endif /* WILC_FULLY_HOSTING_AP */
-
-       }
-       WILC_CATCH(s32Error)
-       {
+               if (s32Error)
+                       PRINT_ER("Host edit station fail\n");
        }
        return s32Error;
 }
 
 
 /**
- *  @brief      WILC_WFI_add_virt_intf
+ *  @brief      add_virtual_intf
  *  @details
  *  @param[in]
  *  @return     int : Return 0 on Success.
@@ -3534,14 +3160,17 @@ static int WILC_WFI_change_station(struct wiphy *wiphy, struct net_device *dev,
  *  @date      01 JUL 2012
  *  @version   1.0
  */
-struct wireless_dev *WILC_WFI_add_virt_intf(struct wiphy *wiphy, const char *name,
-                                               unsigned char name_assign_type,
-                                               enum nl80211_iftype type, u32 *flags,
-                                               struct vif_params *params)
+static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
+                                            const char *name,
+                                            unsigned char name_assign_type,
+                                            enum nl80211_iftype type,
+                                            u32 *flags,
+                                            struct vif_params *params)
 {
        perInterface_wlan_t *nic;
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        struct net_device *new_ifc = NULL;
+
        priv = wiphy_priv(wiphy);
 
 
@@ -3566,7 +3195,7 @@ struct wireless_dev *WILC_WFI_add_virt_intf(struct wiphy *wiphy, const char *nam
 }
 
 /**
- *  @brief      WILC_WFI_del_virt_intf
+ *  @brief      del_virtual_intf
  *  @details
  *  @param[in]
  *  @return     int : Return 0 on Success.
@@ -3574,56 +3203,47 @@ struct wireless_dev *WILC_WFI_add_virt_intf(struct wiphy *wiphy, const char *nam
  *  @date      01 JUL 2012
  *  @version   1.0
  */
-int WILC_WFI_del_virt_intf(struct wiphy *wiphy, struct wireless_dev *wdev)      /* tony for v3.8 support */
+static int del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
 {
        PRINT_D(HOSTAPD_DBG, "Deleting virtual interface\n");
-       return WILC_SUCCESS;
+       return 0;
 }
 
-
-
-#endif /*WILC_AP_EXTERNAL_MLME*/
-static struct cfg80211_ops WILC_WFI_cfg80211_ops = {
-
-       .set_monitor_channel = WILC_WFI_CfgSetChannel,
-       .scan = WILC_WFI_CfgScan,
-       .connect = WILC_WFI_CfgConnect,
-       .disconnect = WILC_WFI_disconnect,
-       .add_key = WILC_WFI_add_key,
-       .del_key = WILC_WFI_del_key,
-       .get_key = WILC_WFI_get_key,
-       .set_default_key = WILC_WFI_set_default_key,
-       #ifdef WILC_AP_EXTERNAL_MLME
-       .add_virtual_intf = WILC_WFI_add_virt_intf,
-       .del_virtual_intf = WILC_WFI_del_virt_intf,
-       .change_virtual_intf = WILC_WFI_change_virt_intf,
-
-       .start_ap = WILC_WFI_start_ap,
-       .change_beacon = WILC_WFI_change_beacon,
-       .stop_ap = WILC_WFI_stop_ap,
-       .add_station = WILC_WFI_add_station,
-       .del_station = WILC_WFI_del_station,
-       .change_station = WILC_WFI_change_station,
-       #endif /* WILC_AP_EXTERNAL_MLME*/
-       #ifndef WILC_FULLY_HOSTING_AP
-       .get_station = WILC_WFI_get_station,
-       #endif
-       .dump_station = WILC_WFI_dump_station,
-       .change_bss = WILC_WFI_change_bss,
-       .set_wiphy_params = WILC_WFI_set_wiphy_params,
-
-       .set_pmksa = WILC_WFI_set_pmksa,
-       .del_pmksa = WILC_WFI_del_pmksa,
-       .flush_pmksa = WILC_WFI_flush_pmksa,
-#ifdef WILC_P2P
-       .remain_on_channel = WILC_WFI_remain_on_channel,
-       .cancel_remain_on_channel = WILC_WFI_cancel_remain_on_channel,
-       .mgmt_tx_cancel_wait = WILC_WFI_mgmt_tx_cancel_wait,
-       .mgmt_tx = WILC_WFI_mgmt_tx,
-       .mgmt_frame_register = WILC_WFI_frame_register,
-       .set_power_mgmt = WILC_WFI_set_power_mgmt,
-       .set_cqm_rssi_config = WILC_WFI_set_cqm_rssi_config,
-#endif
+static struct cfg80211_ops wilc_cfg80211_ops = {
+
+       .set_monitor_channel = set_channel,
+       .scan = scan,
+       .connect = connect,
+       .disconnect = disconnect,
+       .add_key = add_key,
+       .del_key = del_key,
+       .get_key = get_key,
+       .set_default_key = set_default_key,
+       .add_virtual_intf = add_virtual_intf,
+       .del_virtual_intf = del_virtual_intf,
+       .change_virtual_intf = change_virtual_intf,
+
+       .start_ap = start_ap,
+       .change_beacon = change_beacon,
+       .stop_ap = stop_ap,
+       .add_station = add_station,
+       .del_station = del_station,
+       .change_station = change_station,
+       .get_station = get_station,
+       .dump_station = dump_station,
+       .change_bss = change_bss,
+       .set_wiphy_params = set_wiphy_params,
+
+       .set_pmksa = set_pmksa,
+       .del_pmksa = del_pmksa,
+       .flush_pmksa = flush_pmksa,
+       .remain_on_channel = remain_on_channel,
+       .cancel_remain_on_channel = cancel_remain_on_channel,
+       .mgmt_tx_cancel_wait = mgmt_tx_cancel_wait,
+       .mgmt_tx = mgmt_tx,
+       .mgmt_frame_register = wilc_mgmt_frame_register,
+       .set_power_mgmt = set_power_mgmt,
+       .set_cqm_rssi_config = set_cqm_rssi_config,
 
 };
 
@@ -3638,15 +3258,14 @@ static struct cfg80211_ops WILC_WFI_cfg80211_ops = {
  *  @return     int : Return 0 on Success.
  *  @author    mdaftedar
  *  @date      01 MAR 2012
- *  @version   1.0WILC_WFI_set_cqmWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_configWILC_WFI_set_cqm_rssi_config_rssi_config
+ *  @version   1.0
  */
 int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
 {
 
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
 
        priv = wiphy_priv(wiphy);
-#if 1
        switch (changed) {
 
        case WILC_WFI_RX_PKT:
@@ -3669,7 +3288,6 @@ int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed)
        default:
                break;
        }
-#endif
        return 0;
 }
 
@@ -3698,21 +3316,19 @@ struct wireless_dev *WILC_WFI_CfgAlloc(void)
        }
 
        /*Creating a new wiphy, linking wireless structure with the wiphy structure*/
-       wdev->wiphy = wiphy_new(&WILC_WFI_cfg80211_ops, sizeof(struct WILC_WFI_priv));
+       wdev->wiphy = wiphy_new(&wilc_cfg80211_ops, sizeof(struct wilc_priv));
        if (!wdev->wiphy) {
                PRINT_ER("Cannot allocate wiphy\n");
                goto _fail_mem_;
 
        }
 
-       #ifdef WILC_AP_EXTERNAL_MLME
        /* enable 802.11n HT */
        WILC_WFI_band_2ghz.ht_cap.ht_supported = 1;
        WILC_WFI_band_2ghz.ht_cap.cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
        WILC_WFI_band_2ghz.ht_cap.mcs.rx_mask[0] = 0xff;
        WILC_WFI_band_2ghz.ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K;
        WILC_WFI_band_2ghz.ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
-       #endif
 
        /*wiphy bands*/
        wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &WILC_WFI_band_2ghz;
@@ -3726,7 +3342,7 @@ _fail_:
 
 }
 /**
- *  @brief      WILC_WFI_WiphyRegister
+ *  @brief      wilc_create_wiphy
  *  @details    Registering of the wiphy structure and interface modes
  *  @param[in]   NONE
  *  @return     NONE
@@ -3734,11 +3350,11 @@ _fail_:
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-struct wireless_dev *WILC_WFI_WiphyRegister(struct net_device *net)
+struct wireless_dev *wilc_create_wiphy(struct net_device *net)
 {
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
        struct wireless_dev *wdev;
-       s32 s32Error = WILC_SUCCESS;
+       s32 s32Error = 0;
 
        PRINT_D(CFG80211_DBG, "Registering wifi device\n");
 
@@ -3773,15 +3389,11 @@ struct wireless_dev *WILC_WFI_WiphyRegister(struct net_device *net)
        /*Setting default managment types: for register action frame:  */
        wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
 
-#ifdef WILC_P2P
        wdev->wiphy->max_remain_on_channel_duration = 500;
        /*Setting the wiphy interfcae mode and type before registering the wiphy*/
        wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) |
                BIT(NL80211_IFTYPE_P2P_CLIENT);
        wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
-#else
-       wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR);
-#endif
        wdev->iftype = NL80211_IFTYPE_STATION;
 
 
@@ -3791,7 +3403,7 @@ struct wireless_dev *WILC_WFI_WiphyRegister(struct net_device *net)
                   wdev->wiphy->interface_modes, wdev->iftype);
 
        #ifdef WILC_SDIO
-       set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev); /* tony */
+       set_wiphy_dev(wdev->wiphy, &local_sdio_func->dev);
        #endif
 
        /*Register wiphy structure*/
@@ -3817,20 +3429,18 @@ struct wireless_dev *WILC_WFI_WiphyRegister(struct net_device *net)
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-int WILC_WFI_InitHostInt(struct net_device *net)
+int wilc_init_host_int(struct net_device *net)
 {
 
-       s32 s32Error = WILC_SUCCESS;
+       int s32Error = 0;
 
-       struct WILC_WFI_priv *priv;
+       struct wilc_priv *priv;
 
        PRINT_D(INIT_DBG, "Host[%p][%p]\n", net, net->ieee80211_ptr);
        priv = wdev_priv(net->ieee80211_ptr);
        if (op_ifcs == 0) {
                setup_timer(&hAgingTimer, remove_network_from_shadow, 0);
-               #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
                setup_timer(&hDuringIpTimer, clear_duringIP, 0);
-               #endif
        }
        op_ifcs++;
        if (s32Error < 0) {
@@ -3843,10 +3453,10 @@ int WILC_WFI_InitHostInt(struct net_device *net)
        priv->bInP2PlistenState = false;
 
        sema_init(&(priv->hSemScanReq), 1);
-       s32Error = host_int_init(&priv->hWILCWFIDrv);
-       if (s32Error) {
+       s32Error = host_int_init(net, &priv->hWILCWFIDrv);
+       if (s32Error)
                PRINT_ER("Error while initializing hostinterface\n");
-       }
+
        return s32Error;
 }
 
@@ -3859,11 +3469,12 @@ int WILC_WFI_InitHostInt(struct net_device *net)
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-int WILC_WFI_DeInitHostInt(struct net_device *net)
+int wilc_deinit_host_int(struct net_device *net)
 {
-       s32 s32Error = WILC_SUCCESS;
+       int s32Error = 0;
+
+       struct wilc_priv *priv;
 
-       struct WILC_WFI_priv *priv;
        priv = wdev_priv(net->ieee80211_ptr);
 
        priv->gbAutoRateAdjusted = false;
@@ -3876,16 +3487,14 @@ int WILC_WFI_DeInitHostInt(struct net_device *net)
 
        /* Clear the Shadow scan */
        clear_shadow_scan(priv);
-       #ifdef DISABLE_PWRSAVE_AND_SCAN_DURING_IP
        if (op_ifcs == 0) {
                PRINT_D(CORECONFIG_DBG, "destroy during ip\n");
                del_timer_sync(&hDuringIpTimer);
        }
-       #endif
 
-       if (s32Error) {
+       if (s32Error)
                PRINT_ER("Error while deintializing host interface\n");
-       }
+
        return s32Error;
 }
 
@@ -3899,22 +3508,21 @@ int WILC_WFI_DeInitHostInt(struct net_device *net)
  *  @date      01 MAR 2012
  *  @version   1.0
  */
-void WILC_WFI_WiphyFree(struct net_device *net)
+void wilc_free_wiphy(struct net_device *net)
 {
-
        PRINT_D(CFG80211_DBG, "Unregistering wiphy\n");
 
-       if (net == NULL) {
+       if (!net) {
                PRINT_D(INIT_DBG, "net_device is NULL\n");
                return;
        }
 
-       if (net->ieee80211_ptr == NULL) {
+       if (!net->ieee80211_ptr) {
                PRINT_D(INIT_DBG, "ieee80211_ptr is NULL\n");
                return;
        }
 
-       if (net->ieee80211_ptr->wiphy == NULL) {
+       if (!net->ieee80211_ptr->wiphy) {
                PRINT_D(INIT_DBG, "wiphy is NULL\n");
                return;
        }
@@ -3924,5 +3532,4 @@ void WILC_WFI_WiphyFree(struct net_device *net)
        PRINT_D(INIT_DBG, "Freeing wiphy\n");
        wiphy_free(net->ieee80211_ptr->wiphy);
        kfree(net->ieee80211_ptr);
-
 }
index 97b663b7fd1496952097ddab1d053342c33298bf..39cd8e1b567567efc8ad161b42a14820a3fcf224 100644 (file)
 #define NM_WFI_CFGOPERATIONS
 #include "wilc_wfi_netdevice.h"
 
-#ifdef WILC_FULLY_HOSTING_AP
-#include "wilc_host_ap.h"
-#endif
-
-
 /* The following macros describe the bitfield map used by the firmware to determine its 11i mode */
-#define NO_ENCRYPT                     0
-#define ENCRYPT_ENABLED        (1 << 0)
-#define WEP                                    (1 << 1)
-#define WEP_EXTENDED           (1 << 2)
-#define WPA                                    (1 << 3)
-#define WPA2                           (1 << 4)
-#define AES                                    (1 << 5)
-#define TKIP                                   (1 << 6)
-
-#ifdef WILC_P2P
-/* #define     USE_SUPPLICANT_GO_INTENT */
+#define NO_ENCRYPT             0
+#define ENCRYPT_ENABLED                BIT(0)
+#define WEP                    BIT(1)
+#define WEP_EXTENDED           BIT(2)
+#define WPA                    BIT(3)
+#define WPA2                   BIT(4)
+#define AES                    BIT(5)
+#define TKIP                   BIT(6)
 
 /*Public action frame index IDs*/
-#define                FRAME_TYPE_ID                                   0
-#define                ACTION_CAT_ID                                   24
-#define                ACTION_SUBTYPE_ID                               25
-#define                P2P_PUB_ACTION_SUBTYPE          30
+#define FRAME_TYPE_ID                  0
+#define ACTION_CAT_ID                  24
+#define ACTION_SUBTYPE_ID              25
+#define P2P_PUB_ACTION_SUBTYPE         30
 
 /*Public action frame Attribute IDs*/
-#define                ACTION_FRAME                                    0xd0
-#define                GO_INTENT_ATTR_ID                       0x04
-#define                CHANLIST_ATTR_ID                0x0b
-#define                OPERCHAN_ATTR_ID                0x11
-#ifdef USE_SUPPLICANT_GO_INTENT
-#define        GROUP_BSSID_ATTR_ID                     0x07
-#endif
-#define                PUB_ACTION_ATTR_ID                      0x04
-#define                P2PELEM_ATTR_ID                     0xdd
+#define ACTION_FRAME                   0xd0
+#define GO_INTENT_ATTR_ID              0x04
+#define CHANLIST_ATTR_ID               0x0b
+#define OPERCHAN_ATTR_ID               0x11
+#define PUB_ACTION_ATTR_ID             0x04
+#define P2PELEM_ATTR_ID                        0xdd
 
 /*Public action subtype values*/
-#define                GO_NEG_REQ                                      0x00
-#define                GO_NEG_RSP                                      0x01
-#define                GO_NEG_CONF                                     0x02
-#define                P2P_INV_REQ                         0x03
-#define                P2P_INV_RSP                             0x04
-#define                PUBLIC_ACT_VENDORSPEC           0x09
-#define                GAS_INTIAL_REQ                                  0x0a
-#define                GAS_INTIAL_RSP                                  0x0b
+#define GO_NEG_REQ                     0x00
+#define GO_NEG_RSP                     0x01
+#define GO_NEG_CONF                    0x02
+#define P2P_INV_REQ                    0x03
+#define P2P_INV_RSP                    0x04
+#define PUBLIC_ACT_VENDORSPEC          0x09
+#define GAS_INTIAL_REQ                 0x0a
+#define GAS_INTIAL_RSP                 0x0b
 
-#define                INVALID_CHANNEL                                 0
-#ifdef USE_SUPPLICANT_GO_INTENT
-#define                SUPPLICANT_GO_INTENT                    6
-#define                GET_GO_INTENT(a)                                (((a) >> 1) & 0x0f)
-#define                GET_TIE_BREAKER(a)                      (((a)) & 0x01)
-#else
-/* #define FORCE_P2P_CLIENT */
-#endif
-#endif
+#define INVALID_CHANNEL                        0
 
 #define nl80211_SCAN_RESULT_EXPIRE     (3 * HZ)
-#define SCAN_RESULT_EXPIRE                             (40 * HZ)
+#define SCAN_RESULT_EXPIRE             (40 * HZ)
 
 static const u32 cipher_suites[] = {
        WLAN_CIPHER_SUITE_WEP40,
@@ -99,7 +80,6 @@ static const struct ieee80211_txrx_stypes
                        BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
                        BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
                        BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
-                       BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
                        BIT(IEEE80211_STYPE_DISASSOC >> 4) |
                        BIT(IEEE80211_STYPE_AUTH >> 4) |
                        BIT(IEEE80211_STYPE_DEAUTH >> 4)
@@ -111,19 +91,19 @@ static const struct ieee80211_txrx_stypes
 #define WILC_WFI_DWELL_ACTIVE  40
 
 struct wireless_dev *WILC_WFI_CfgAlloc(void);
-struct wireless_dev *WILC_WFI_WiphyRegister(struct net_device *net);
-void WILC_WFI_WiphyFree(struct net_device *net);
+struct wireless_dev *wilc_create_wiphy(struct net_device *net);
+void wilc_free_wiphy(struct net_device *net);
 int WILC_WFI_update_stats(struct wiphy *wiphy, u32 pktlen, u8 changed);
-int WILC_WFI_DeInitHostInt(struct net_device *net);
-int WILC_WFI_InitHostInt(struct net_device *net);
-void WILC_WFI_monitor_rx(uint8_t *buff, uint32_t size);
+int wilc_deinit_host_int(struct net_device *net);
+int wilc_init_host_int(struct net_device *net);
+void WILC_WFI_monitor_rx(u8 *buff, u32 size);
 int WILC_WFI_deinit_mon_interface(void);
 struct net_device *WILC_WFI_init_mon_interface(const char *name, struct net_device *real_dev);
+void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
+                             u16 frame_type, bool reg);
 
-#ifdef TCP_ENHANCEMENTS
-#define TCP_ACK_FILTER_LINK_SPEED_THRESH 54
-#define DEFAULT_LINK_SPEED 72
+#define TCP_ACK_FILTER_LINK_SPEED_THRESH       54
+#define DEFAULT_LINK_SPEED                     72
 void Enable_TCP_ACK_Filter(bool value);
-#endif
 
 #endif
index 77f320d125e8b6cf151998063c43b1b1e54d8b76..0bfe7626ad2d22a5f0db9007d3700b6e8511c5ed 100644 (file)
@@ -8,12 +8,10 @@
 #ifndef WILC_WFI_NETDEVICE
 #define WILC_WFI_NETDEVICE
 
-/* These are the flags in the statusword */
 #define WILC_WFI_RX_INTR 0x0001
 #define WILC_WFI_TX_INTR 0x0002
 
-/* Default timeout period */
-#define WILC_WFI_TIMEOUT 5   /* In jiffies */
+#define WILC_WFI_TIMEOUT 5
 #define WILC_MAX_NUM_PMKIDS  16
 #define PMKID_LEN  16
 #define PMKID_FOUND 1
 #include <linux/moduleparam.h>
 #include <linux/sched.h>
 #include <linux/kernel.h>
-#include <linux/slab.h> /* kmalloc() */
-#include <linux/errno.h>  /* error codes */
-#include <linux/types.h>  /* size_t */
-#include <linux/interrupt.h> /* mark_bh */
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
 #include <linux/time.h>
 #include <linux/in.h>
-#include <linux/netdevice.h>   /* struct device, and other headers */
-#include <linux/etherdevice.h> /* eth_type_trans */
-#include <linux/ip.h>          /* struct iphdr */
-#include <linux/tcp.h>         /* struct tcphdr */
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
 #include <linux/skbuff.h>
 #include <linux/ieee80211.h>
 #include <net/cfg80211.h>
 #include <asm/checksum.h>
 #include "host_interface.h"
 #include "wilc_wlan.h"
-#include <linux/wireless.h>     /* tony, 2013-06-12 */
+#include <linux/wireless.h>
 
 #define FLOW_CONTROL_LOWER_THRESHOLD   128
 #define FLOW_CONTROL_UPPER_THRESHOLD   256
 
-/*iftype*/
 enum stats_flags {
-       WILC_WFI_RX_PKT = 1 << 0,
-       WILC_WFI_TX_PKT = 1 << 1,
+       WILC_WFI_RX_PKT = BIT(0),
+       WILC_WFI_TX_PKT = BIT(1),
 };
 
 struct WILC_WFI_stats {
@@ -71,22 +68,7 @@ struct WILC_WFI_stats {
  * packets in and out, so there is place for a packet
  */
 
-#define RX_BH_KTHREAD 0
-#define RX_BH_WORK_QUEUE 1
-#define RX_BH_THREADED_IRQ 2
 #define num_reg_frame 2
-/*
- * If you use RX_BH_WORK_QUEUE on LPC3131: You may lose the first interrupt on
- * LPC3131 which is important to get the MAC start status when you are blocked
- * inside linux_wlan_firmware_download() which blocks mac_open().
- */
-#if defined(NM73131_0_BOARD)
- #define RX_BH_TYPE  RX_BH_KTHREAD
-#elif defined(PANDA_BOARD)
- #define RX_BH_TYPE  RX_BH_THREADED_IRQ
-#else
- #define RX_BH_TYPE  RX_BH_KTHREAD
-#endif
 
 struct wilc_wfi_key {
        u8 *key;
@@ -106,7 +88,6 @@ struct sta_info {
        u8 au8Sta_AssociatedBss[MAX_NUM_STA][ETH_ALEN];
 };
 
-#ifdef WILC_P2P
 /*Parameters needed for host interface for  remaining on channel*/
 struct wilc_wfi_p2pListenParams {
        struct ieee80211_channel *pstrListenChan;
@@ -116,16 +97,12 @@ struct wilc_wfi_p2pListenParams {
        u32 u32ListenSessionID;
 };
 
-#endif  /*WILC_P2P*/
-
-struct WILC_WFI_priv {
+struct wilc_priv {
        struct wireless_dev *wdev;
        struct cfg80211_scan_request *pstrScanReq;
 
-       #ifdef WILC_P2P
        struct wilc_wfi_p2pListenParams strRemainOnChanParams;
        u64 u64tx_cookie;
-       #endif
 
        bool bCfgScanning;
        u32 u32RcvdChCount;
@@ -144,9 +121,8 @@ struct WILC_WFI_priv {
        spinlock_t lock;
        struct net_device *dev;
        struct napi_struct napi;
-       tstrWILC_WFIDrv *hWILCWFIDrv;
-       WILC_WFIDrvHandle hWILCWFIDrv_2;
-       tstrHostIFpmkidAttr pmkid_list;
+       struct host_if_drv *hWILCWFIDrv;
+       struct host_if_pmkid_attr pmkid_list;
        struct WILC_WFI_stats netstats;
        u8 WILC_WFI_wep_default;
        u8 WILC_WFI_wep_key[4][WLAN_KEY_LEN_WEP104];
@@ -172,85 +148,74 @@ typedef struct {
 
 } struct_frame_reg;
 
-#define NUM_CONCURRENT_IFC 2
-typedef struct {
-       uint8_t aSrcAddress[ETH_ALEN];
-       uint8_t aBSSID[ETH_ALEN];
-       tstrWILC_WFIDrv *drvHandler;
-       struct net_device *wilc_netdev;
-} tstrInterfaceInfo;
-typedef struct {
+struct wilc_vif {
+       u8 src_addr[ETH_ALEN];
+       u8 bssid[ETH_ALEN];
+       struct host_if_drv *hif_drv;
+       struct net_device *ndev;
+};
+
+struct wilc {
        int mac_status;
-       int wilc1000_initialized;
+       bool initialized;
        #if (!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO)
        unsigned short dev_irq_num;
        #endif
-       wilc_wlan_oup_t oup;
        int close;
-       uint8_t u8NoIfcs;
-       tstrInterfaceInfo strInterfaceInfo[NUM_CONCURRENT_IFC];
-       uint8_t open_ifcs;
-       struct mutex txq_cs;
+       u8 vif_num;
+       struct wilc_vif vif[NUM_CONCURRENT_IFC];
+       u8 open_ifcs;
 
-       /*Added by Amr - BugID_4720*/
-       struct mutex txq_add_to_head_cs;
+       struct semaphore txq_add_to_head_cs;
        spinlock_t txq_spinlock;
 
        struct mutex rxq_cs;
        struct mutex hif_cs;
 
-       /* struct mutex txq_event; */
-       struct semaphore rxq_event;
        struct semaphore cfg_event;
        struct semaphore sync_event;
-
        struct semaphore txq_event;
-       /* struct completion txq_event; */
 
-#if (RX_BH_TYPE == RX_BH_WORK_QUEUE)
-       struct work_struct rx_work_queue;
-#elif (RX_BH_TYPE == RX_BH_KTHREAD)
-       struct task_struct *rx_bh_thread;
-       struct semaphore rx_sem;
-#endif
-       struct semaphore rxq_thread_started;
        struct semaphore txq_thread_started;
 
-       struct task_struct *rxq_thread;
        struct task_struct *txq_thread;
 
        unsigned char eth_src_address[NUM_CONCURRENT_IFC][6];
-       /* unsigned char eth_dst_address[6]; */
 
-       const struct firmware *wilc_firmware; /* Bug 4703 */
+       const struct firmware *firmware;
 
-       struct net_device *real_ndev;
 #ifdef WILC_SDIO
-       int already_claim;
        struct sdio_func *wilc_sdio_func;
 #else
        struct spi_device *wilc_spidev;
 #endif
-
-} linux_wlan_t;
+};
 
 typedef struct {
-       uint8_t u8IfIdx;
+       u8 u8IfIdx;
        u8 iftype;
        int monitor_flag;
        int mac_opened;
-       #ifdef WILC_P2P
        struct_frame_reg g_struct_frame_reg[num_reg_frame];
-       #endif
        struct net_device *wilc_netdev;
        struct net_device_stats netstats;
-
+       struct wilc *wilc;
 } perInterface_wlan_t;
 
 struct WILC_WFI_mon_priv {
        struct net_device *real_ndev;
 };
 
+extern struct wilc *g_linux_wlan;
 extern struct net_device *WILC_WFI_devs[];
-
+void frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
+void linux_wlan_mac_indicate(struct wilc *wilc, int flag);
+void linux_wlan_rx_complete(void);
+void linux_wlan_dbg(u8 *buff);
+int linux_wlan_lock_timeout(void *vp, u32 timeout);
+void wl_wlan_cleanup(void);
+int wilc_netdev_init(struct wilc **wilc);
+void wilc1000_wlan_deinit(struct net_device *dev);
+void WILC_WFI_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size);
+u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue);
 #endif
index 7c53a2bd03812dd0d8026351216234d23f76de47..c0266574770521860aff9db94f70b882a66feb49 100644 (file)
@@ -8,8 +8,8 @@
 /* //////////////////////////////////////////////////////////////////////////// */
 
 #include "wilc_wlan_if.h"
-#include "wilc_wlan.h"
-#define INLINE static __inline
+#include "wilc_wfi_netdevice.h"
+#include "wilc_wlan_cfg.h"
 
 /********************************************
  *
  ********************************************/
 extern wilc_hif_func_t hif_sdio;
 extern wilc_hif_func_t hif_spi;
-extern wilc_cfg_func_t mac_cfg;
-#if defined(PLAT_RK3026_TCHIP)
-extern u8 g_wilc_initialized; /* AMR : 0422 RK3026 Crash issue */
-#endif
-extern void WILC_WFI_mgmt_rx(uint8_t *buff, uint32_t size);
-uint32_t wilc_get_chipid(uint8_t update);
-u16 Set_machw_change_vir_if(bool bValue);
+u32 wilc_get_chipid(u8 update);
 
 
 
@@ -34,66 +28,51 @@ typedef struct {
        /**
         *      input interface functions
         **/
-       wilc_wlan_os_func_t os_func;
        wilc_wlan_io_func_t io_func;
-       wilc_wlan_net_func_t net_func;
-       wilc_wlan_indicate_func_t indicate_func;
 
        /**
         *      host interface functions
         **/
        wilc_hif_func_t hif_func;
-       void *hif_lock;
 
        /**
         *      configuration interface functions
         **/
-       wilc_cfg_func_t cif_func;
        int cfg_frame_in_use;
        wilc_cfg_frame_t cfg_frame;
-       uint32_t cfg_frame_offset;
+       u32 cfg_frame_offset;
        int cfg_seq_no;
-       void *cfg_wait;
 
        /**
         *      RX buffer
         **/
        #ifdef MEMORY_STATIC
-       uint32_t rx_buffer_size;
-       uint8_t *rx_buffer;
-       uint32_t rx_buffer_offset;
+       u8 *rx_buffer;
+       u32 rx_buffer_offset;
        #endif
        /**
         *      TX buffer
         **/
-       uint32_t tx_buffer_size;
-       uint8_t *tx_buffer;
-       uint32_t tx_buffer_offset;
+       u8 *tx_buffer;
+       u32 tx_buffer_offset;
 
        /**
         *      TX queue
         **/
-       void *txq_lock;
 
-       /*Added by Amr - BugID_4720*/
-       void *txq_add_to_head_lock;
-       void *txq_spinlock;
        unsigned long txq_spinlock_flags;
 
        struct txq_entry_t *txq_head;
        struct txq_entry_t *txq_tail;
        int txq_entries;
-       void *txq_wait;
        int txq_exit;
 
        /**
         *      RX queue
         **/
-       void *rxq_lock;
        struct rxq_entry_t *rxq_head;
        struct rxq_entry_t *rxq_tail;
        int rxq_entries;
-       void *rxq_wait;
        int rxq_exit;
 
 
@@ -101,17 +80,17 @@ typedef struct {
 
 static wilc_wlan_dev_t g_wlan;
 
-INLINE void chip_allow_sleep(void);
-INLINE void chip_wakeup(void);
+static inline void chip_allow_sleep(void);
+static inline void chip_wakeup(void);
 /********************************************
  *
  *      Debug
  *
  ********************************************/
 
-static uint32_t dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
+static u32 dbgflag = N_INIT | N_ERR | N_INTR | N_TXQ | N_RXQ;
 
-static void wilc_debug(uint32_t flag, char *fmt, ...)
+static void wilc_debug(u32 flag, char *fmt, ...)
 {
        char buf[256];
        va_list args;
@@ -121,21 +100,19 @@ static void wilc_debug(uint32_t flag, char *fmt, ...)
                vsprintf(buf, fmt, args);
                va_end(args);
 
-               if (g_wlan.os_func.os_debug)
-                       g_wlan.os_func.os_debug(buf);
+               linux_wlan_dbg(buf);
        }
 }
 
 static CHIP_PS_STATE_T genuChipPSstate = CHIP_WAKEDUP;
 
-/*BugID_5213*/
-/*acquire_bus() and release_bus() are made INLINE functions*/
+/*acquire_bus() and release_bus() are made static inline functions*/
 /*as a temporary workaround to fix a problem of receiving*/
 /*unknown interrupt from FW*/
-INLINE void acquire_bus(BUS_ACQUIRE_T acquire)
+static inline void acquire_bus(BUS_ACQUIRE_T acquire)
 {
 
-       g_wlan.os_func.os_enter_cs(g_wlan.hif_lock);
+       mutex_lock(&g_linux_wlan->hif_cs);
        #ifndef WILC_OPTIMIZE_SLEEP_INT
        if (genuChipPSstate != CHIP_WAKEDUP)
        #endif
@@ -145,13 +122,13 @@ INLINE void acquire_bus(BUS_ACQUIRE_T acquire)
        }
 
 }
-INLINE void release_bus(BUS_RELEASE_T release)
+static inline void release_bus(BUS_RELEASE_T release)
 {
        #ifdef WILC_OPTIMIZE_SLEEP_INT
        if (release == RELEASE_ALLOW_SLEEP)
                chip_allow_sleep();
        #endif
-       g_wlan.os_func.os_leave_cs(g_wlan.hif_lock);
+       mutex_unlock(&g_linux_wlan->hif_cs);
 }
 /********************************************
  *
@@ -162,8 +139,7 @@ INLINE void release_bus(BUS_RELEASE_T release)
 static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
 {
 
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       /* unsigned long flags; */
+       wilc_wlan_dev_t *p = &g_wlan;
        if (tqe == p->txq_head) {
 
                p->txq_head = tqe->next;
@@ -186,34 +162,33 @@ static void wilc_wlan_txq_remove(struct txq_entry_t *tqe)
 static struct txq_entry_t *wilc_wlan_txq_remove_from_head(void)
 {
        struct txq_entry_t *tqe;
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
-       p->os_func.os_spin_lock(p->txq_spinlock, &flags);
+
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
        if (p->txq_head) {
                tqe = p->txq_head;
                p->txq_head = tqe->next;
-               if (p->txq_head) {
+               if (p->txq_head)
                        p->txq_head->prev = NULL;
-               }
+
                p->txq_entries -= 1;
 
-               /*Added by Amr - BugID_4720*/
 
 
 
        } else {
                tqe = NULL;
        }
-       p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
        return tqe;
 }
 
 static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_spin_lock(p->txq_spinlock, &flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
 
        if (p->txq_head == NULL) {
                tqe->next = NULL;
@@ -229,28 +204,25 @@ static void wilc_wlan_txq_add_to_tail(struct txq_entry_t *tqe)
        p->txq_entries += 1;
        PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
 
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
 
        /**
         *      wake up TX queue
         **/
        PRINT_D(TX_DBG, "Wake the txq_handling\n");
 
-       p->os_func.os_signal(p->txq_wait);
-
-
+       up(&g_linux_wlan->txq_event);
 }
 
 static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
-       /*Added by Amr - BugID_4720*/
-       if (p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT))
+       if (linux_wlan_lock_timeout(&g_linux_wlan->txq_add_to_head_cs,
+                                   CFG_PKTS_TIMEOUT))
                return -1;
 
-       p->os_func.os_spin_lock(p->txq_spinlock, &flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
 
        if (p->txq_head == NULL) {
                tqe->next = NULL;
@@ -266,37 +238,35 @@ static int wilc_wlan_txq_add_to_head(struct txq_entry_t *tqe)
        p->txq_entries += 1;
        PRINT_D(TX_DBG, "Number of entries in TxQ = %d\n", p->txq_entries);
 
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
-       p->os_func.os_signal(p->txq_add_to_head_lock);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
+       up(&g_linux_wlan->txq_add_to_head_cs);
 
 
        /**
         *      wake up TX queue
         **/
-       p->os_func.os_signal(p->txq_wait);
+       up(&g_linux_wlan->txq_event);
        PRINT_D(TX_DBG, "Wake up the txq_handler\n");
 
-       /*Added by Amr - BugID_4720*/
        return 0;
 
 }
 
-uint32_t Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
+u32 Statisitcs_totalAcks = 0, Statisitcs_DroppedAcks = 0;
 
 #ifdef TCP_ACK_FILTER
 struct Ack_session_info;
 struct Ack_session_info {
-       uint32_t Ack_seq_num;
-       uint32_t Bigger_Ack_num;
-       uint16_t src_port;
-       uint16_t dst_port;
-       uint16_t status;
+       u32 Ack_seq_num;
+       u32 Bigger_Ack_num;
+       u16 src_port;
+       u16 dst_port;
+       u16 status;
 };
 
 typedef struct {
-       uint32_t ack_num;
-       uint32_t Session_index;
+       u32 ack_num;
+       u32 Session_index;
        struct txq_entry_t  *txqe;
 } Pending_Acks_info_t /*Ack_info_t*/;
 
@@ -306,9 +276,6 @@ typedef struct {
 struct Ack_session_info *Free_head;
 struct Ack_session_info *Alloc_head;
 
-#define TCP_FIN_MASK           (1 << 0)
-#define TCP_SYN_MASK           (1 << 1)
-#define TCP_Ack_MASK           (1 << 4)
 #define NOT_TCP_ACK                    (-1)
 
 #define MAX_TCP_SESSION                25
@@ -316,19 +283,19 @@ struct Ack_session_info *Alloc_head;
 struct Ack_session_info Acks_keep_track_info[2 * MAX_TCP_SESSION];
 Pending_Acks_info_t Pending_Acks_info[MAX_PENDING_ACKS];
 
-uint32_t PendingAcks_arrBase;
-uint32_t Opened_TCP_session;
-uint32_t Pending_Acks;
+u32 PendingAcks_arrBase;
+u32 Opened_TCP_session;
+u32 Pending_Acks;
 
 
 
-static __inline int Init_TCP_tracking(void)
+static inline int Init_TCP_tracking(void)
 {
 
        return 0;
 
 }
-static __inline int add_TCP_track_session(uint32_t src_prt, uint32_t dst_prt, uint32_t seq)
+static inline int add_TCP_track_session(u32 src_prt, u32 dst_prt, u32 seq)
 {
        Acks_keep_track_info[Opened_TCP_session].Ack_seq_num = seq;
        Acks_keep_track_info[Opened_TCP_session].Bigger_Ack_num = 0;
@@ -340,16 +307,15 @@ static __inline int add_TCP_track_session(uint32_t src_prt, uint32_t dst_prt, ui
        return 0;
 }
 
-static __inline int Update_TCP_track_session(uint32_t index, uint32_t Ack)
+static inline int Update_TCP_track_session(u32 index, u32 Ack)
 {
 
-       if (Ack > Acks_keep_track_info[index].Bigger_Ack_num) {
+       if (Ack > Acks_keep_track_info[index].Bigger_Ack_num)
                Acks_keep_track_info[index].Bigger_Ack_num = Ack;
-       }
        return 0;
 
 }
-static __inline int add_TCP_Pending_Ack(uint32_t Ack, uint32_t Session_index, struct txq_entry_t  *txqe)
+static inline int add_TCP_Pending_Ack(u32 Ack, u32 Session_index, struct txq_entry_t  *txqe)
 {
        Statisitcs_totalAcks++;
        if (Pending_Acks < MAX_PENDING_ACKS) {
@@ -364,49 +330,58 @@ static __inline int add_TCP_Pending_Ack(uint32_t Ack, uint32_t Session_index, st
        }
        return 0;
 }
-static __inline int remove_TCP_related(void)
+static inline int remove_TCP_related(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
-       p->os_func.os_spin_lock(p->txq_spinlock, &flags);
 
-       p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
+
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
        return 0;
 }
 
-static __inline int tcp_process(struct txq_entry_t *tqe)
+static inline int tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
 {
        int ret;
-       uint8_t *eth_hdr_ptr;
-       uint8_t *buffer = tqe->buffer;
+       u8 *eth_hdr_ptr;
+       u8 *buffer = tqe->buffer;
        unsigned short h_proto;
        int i;
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        unsigned long flags;
-       p->os_func.os_spin_lock(p->txq_spinlock, &flags);
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
+
+       spin_lock_irqsave(&wilc->txq_spinlock, flags);
 
        eth_hdr_ptr = &buffer[0];
        h_proto = ntohs(*((unsigned short *)&eth_hdr_ptr[12]));
        if (h_proto == 0x0800) { /* IP */
-               uint8_t *ip_hdr_ptr;
-               uint8_t protocol;
+               u8 *ip_hdr_ptr;
+               u8 protocol;
 
                ip_hdr_ptr = &buffer[ETHERNET_HDR_LEN];
                protocol = ip_hdr_ptr[9];
 
 
                if (protocol == 0x06) {
-                       uint8_t *tcp_hdr_ptr;
-                       uint32_t IHL, Total_Length, Data_offset;
+                       u8 *tcp_hdr_ptr;
+                       u32 IHL, Total_Length, Data_offset;
+
                        tcp_hdr_ptr = &ip_hdr_ptr[IP_HDR_LEN];
                        IHL = (ip_hdr_ptr[0] & 0xf) << 2;
-                       Total_Length = (((uint32_t)ip_hdr_ptr[2]) << 8) + ((uint32_t)ip_hdr_ptr[3]);
-                       Data_offset = (((uint32_t)tcp_hdr_ptr[12] & 0xf0) >> 2);
+                       Total_Length = (((u32)ip_hdr_ptr[2]) << 8) + ((u32)ip_hdr_ptr[3]);
+                       Data_offset = (((u32)tcp_hdr_ptr[12] & 0xf0) >> 2);
                        if (Total_Length == (IHL + Data_offset)) { /*we want to recognize the clear Acks(packet only carry Ack infos not with data) so data size must be equal zero*/
-                               uint32_t seq_no, Ack_no;
-                               seq_no  = (((uint32_t)tcp_hdr_ptr[4]) << 24) + (((uint32_t)tcp_hdr_ptr[5]) << 16) + (((uint32_t)tcp_hdr_ptr[6]) << 8) + ((uint32_t)tcp_hdr_ptr[7]);
+                               u32 seq_no, Ack_no;
+
+                               seq_no  = (((u32)tcp_hdr_ptr[4]) << 24) + (((u32)tcp_hdr_ptr[5]) << 16) + (((u32)tcp_hdr_ptr[6]) << 8) + ((u32)tcp_hdr_ptr[7]);
 
-                               Ack_no  = (((uint32_t)tcp_hdr_ptr[8]) << 24) + (((uint32_t)tcp_hdr_ptr[9]) << 16) + (((uint32_t)tcp_hdr_ptr[10]) << 8) + ((uint32_t)tcp_hdr_ptr[11]);
+                               Ack_no  = (((u32)tcp_hdr_ptr[8]) << 24) + (((u32)tcp_hdr_ptr[9]) << 16) + (((u32)tcp_hdr_ptr[10]) << 8) + ((u32)tcp_hdr_ptr[11]);
 
 
                                for (i = 0; i < Opened_TCP_session; i++) {
@@ -415,9 +390,9 @@ static __inline int tcp_process(struct txq_entry_t *tqe)
                                                break;
                                        }
                                }
-                               if (i == Opened_TCP_session) {
+                               if (i == Opened_TCP_session)
                                        add_TCP_track_session(0, 0, seq_no);
-                               }
+
                                add_TCP_Pending_Ack(Ack_no, i, tqe);
 
 
@@ -429,22 +404,27 @@ static __inline int tcp_process(struct txq_entry_t *tqe)
        } else {
                ret = 0;
        }
-       p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
+       spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
        return ret;
 }
 
 
-static int wilc_wlan_txq_filter_dup_tcp_ack(void)
+static int wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
 {
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+       u32 i = 0;
+       u32 Dropped = 0;
+       wilc_wlan_dev_t *p = &g_wlan;
 
-       uint32_t i = 0;
-       uint32_t Dropped = 0;
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
-       p->os_func.os_spin_lock(p->txq_spinlock, &p->txq_spinlock_flags);
+       spin_lock_irqsave(&wilc->txq_spinlock, p->txq_spinlock_flags);
        for (i = PendingAcks_arrBase; i < (PendingAcks_arrBase + Pending_Acks); i++) {
                if (Pending_Acks_info[i].ack_num < Acks_keep_track_info[Pending_Acks_info[i].Session_index].Bigger_Ack_num) {
                        struct txq_entry_t *tqe;
+
                        PRINT_D(TCP_ENH, "DROP ACK: %u\n", Pending_Acks_info[i].ack_num);
                        tqe = Pending_Acks_info[i].txqe;
                        if (tqe) {
@@ -453,7 +433,7 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
                                tqe->status = 1;                                /* mark the packet send */
                                if (tqe->tx_complete_func)
                                        tqe->tx_complete_func(tqe->priv, tqe->status);
-                               p->os_func.os_free(tqe);
+                               kfree(tqe);
                                Dropped++;
                        }
                }
@@ -467,11 +447,11 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
                PendingAcks_arrBase = 0;
 
 
-       p->os_func.os_spin_unlock(p->txq_spinlock, &p->txq_spinlock_flags);
+       spin_unlock_irqrestore(&wilc->txq_spinlock, p->txq_spinlock_flags);
 
        while (Dropped > 0) {
                /*consume the semaphore count of the removed packet*/
-               p->os_func.os_wait(p->txq_wait, 1);
+               linux_wlan_lock_timeout(&wilc->txq_event, 1);
                Dropped--;
        }
 
@@ -479,7 +459,6 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(void)
 }
 #endif
 
-#ifdef TCP_ENHANCEMENTS
 bool EnableTCPAckFilter = false;
 
 void Enable_TCP_ACK_Filter(bool value)
@@ -491,21 +470,20 @@ bool is_TCP_ACK_Filter_Enabled(void)
 {
        return EnableTCPAckFilter;
 }
-#endif
 
-static int wilc_wlan_txq_add_cfg_pkt(uint8_t *buffer, uint32_t buffer_size)
+static int wilc_wlan_txq_add_cfg_pkt(u8 *buffer, u32 buffer_size)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
 
        PRINT_D(TX_DBG, "Adding config packet ...\n");
        if (p->quit) {
                PRINT_D(TX_DBG, "Return due to clear function\n");
-               p->os_func.os_signal(p->cfg_wait);
+               up(&g_linux_wlan->cfg_event);
                return 0;
        }
 
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
+       tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
        if (tqe == NULL) {
                PRINT_ER("Failed to allocate memory\n");
                return 0;
@@ -524,21 +502,21 @@ static int wilc_wlan_txq_add_cfg_pkt(uint8_t *buffer, uint32_t buffer_size)
         **/
        PRINT_D(TX_DBG, "Adding the config packet at the Queue tail\n");
 
-       /*Edited by Amr - BugID_4720*/
        if (wilc_wlan_txq_add_to_head(tqe))
                return 0;
        return 1;
 }
 
-static int wilc_wlan_txq_add_net_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size, wilc_tx_complete_func_t func)
+int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
+                             u32 buffer_size, wilc_tx_complete_func_t func)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
 
        if (p->quit)
                return 0;
 
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
+       tqe = kmalloc(sizeof(struct txq_entry_t), GFP_ATOMIC);
 
        if (tqe == NULL)
                return 0;
@@ -551,27 +529,24 @@ static int wilc_wlan_txq_add_net_pkt(void *priv, uint8_t *buffer, uint32_t buffe
        PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
 #ifdef TCP_ACK_FILTER
        tqe->tcp_PendingAck_index = NOT_TCP_ACK;
-#ifdef TCP_ENHANCEMENTS
        if (is_TCP_ACK_Filter_Enabled())
-#endif
-       tcp_process(tqe);
+               tcp_process(dev, tqe);
 #endif
        wilc_wlan_txq_add_to_tail(tqe);
        /*return number of itemes in the queue*/
        return p->txq_entries;
 }
-/*Bug3959: transmitting mgmt frames received from host*/
-#if defined(WILC_AP_EXTERNAL_MLME) || defined(WILC_P2P)
-int wilc_wlan_txq_add_mgmt_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size, wilc_tx_complete_func_t func)
+
+int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size, wilc_tx_complete_func_t func)
 {
 
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
 
        if (p->quit)
                return 0;
 
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
+       tqe = kmalloc(sizeof(struct txq_entry_t), GFP_KERNEL);
 
        if (tqe == NULL)
                return 0;
@@ -588,72 +563,43 @@ int wilc_wlan_txq_add_mgmt_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size
        return 1;
 }
 
-#ifdef WILC_FULLY_HOSTING_AP
-int wilc_FH_wlan_txq_add_net_pkt(void *priv, uint8_t *buffer, uint32_t buffer_size, wilc_tx_complete_func_t func)
-{
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       struct txq_entry_t *tqe;
-
-       if (p->quit)
-               return 0;
-
-       tqe = (struct txq_entry_t *)p->os_func.os_malloc_atomic(sizeof(struct txq_entry_t));
-
-       if (tqe == NULL)
-               return 0;
-       tqe->type = WILC_FH_DATA_PKT;
-       tqe->buffer = buffer;
-       tqe->buffer_size = buffer_size;
-       tqe->tx_complete_func = func;
-       tqe->priv = priv;
-       PRINT_D(TX_DBG, "Adding mgmt packet at the Queue tail\n");
-       wilc_wlan_txq_add_to_tail(tqe);
-       /*return number of itemes in the queue*/
-       return p->txq_entries;
-}
-#endif  /* WILC_FULLY_HOSTING_AP*/
-#endif /*WILC_AP_EXTERNAL_MLME*/
 static struct txq_entry_t *wilc_wlan_txq_get_first(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
        unsigned long flags;
 
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_spin_lock(p->txq_spinlock, &flags);
+       spin_lock_irqsave(&g_linux_wlan->txq_spinlock, flags);
 
        tqe = p->txq_head;
 
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
+       spin_unlock_irqrestore(&g_linux_wlan->txq_spinlock, flags);
 
 
        return tqe;
 }
 
-static struct txq_entry_t *wilc_wlan_txq_get_next(struct txq_entry_t *tqe)
+static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
+                                                 struct txq_entry_t *tqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        unsigned long flags;
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_spin_lock(p->txq_spinlock, &flags);
+       spin_lock_irqsave(&wilc->txq_spinlock, flags);
 
        tqe = tqe->next;
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_spin_unlock(p->txq_spinlock, &flags);
+       spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 
 
        return tqe;
 }
 
-static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
+static int wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
 
        if (p->quit)
                return 0;
 
-       p->os_func.os_enter_cs(p->rxq_lock);
+       mutex_lock(&wilc->rxq_cs);
        if (p->rxq_head == NULL) {
                PRINT_D(RX_DBG, "Add to Queue head\n");
                rqe->next = NULL;
@@ -667,24 +613,24 @@ static int wilc_wlan_rxq_add(struct rxq_entry_t *rqe)
        }
        p->rxq_entries += 1;
        PRINT_D(RX_DBG, "Number of queue entries: %d\n", p->rxq_entries);
-       p->os_func.os_leave_cs(p->rxq_lock);
+       mutex_unlock(&wilc->rxq_cs);
        return p->rxq_entries;
 }
 
-static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
+static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
 
        PRINT_D(RX_DBG, "Getting rxQ element\n");
        if (p->rxq_head) {
                struct rxq_entry_t *rqe;
 
-               p->os_func.os_enter_cs(p->rxq_lock);
+               mutex_lock(&wilc->rxq_cs);
                rqe = p->rxq_head;
                p->rxq_head = p->rxq_head->next;
                p->rxq_entries -= 1;
                PRINT_D(RX_DBG, "RXQ entries decreased\n");
-               p->os_func.os_leave_cs(p->rxq_lock);
+               mutex_unlock(&wilc->rxq_cs);
                return rqe;
        }
        PRINT_D(RX_DBG, "Nothing to get from Q\n");
@@ -702,38 +648,38 @@ static struct rxq_entry_t *wilc_wlan_rxq_remove(void)
 
 #ifdef WILC_OPTIMIZE_SLEEP_INT
 
-INLINE void chip_allow_sleep(void)
+static inline void chip_allow_sleep(void)
 {
-       uint32_t reg = 0;
+       u32 reg = 0;
 
        /* Clear bit 1 */
        g_wlan.hif_func.hif_read_reg(0xf0, &reg);
 
-       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
+       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
 }
 
-INLINE void chip_wakeup(void)
+static inline void chip_wakeup(void)
 {
-       uint32_t reg, clk_status_reg, trials = 0;
-       uint32_t sleep_time;
+       u32 reg, clk_status_reg, trials = 0;
+       u32 sleep_time;
 
        if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
                do {
                        g_wlan.hif_func.hif_read_reg(1, &reg);
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
 
                        /* Clear bit 1*/
-                       g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
 
                        do {
                                /* Wait for the chip to stabilize*/
                                usleep_range(2 * 1000, 2 * 1000);
                                /* Make sure chip is awake. This is an extra step that can be removed */
                                /* later to avoid the bus access overhead */
-                               if ((wilc_get_chipid(true) == 0)) {
+                               if ((wilc_get_chipid(true) == 0))
                                        wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
-                               }
+
                        } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
 
                } while (wilc_get_chipid(true) == 0);
@@ -741,7 +687,7 @@ INLINE void chip_wakeup(void)
                g_wlan.hif_func.hif_read_reg(0xf0, &reg);
                do {
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
 
                        /* Check the clock status */
                        g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
@@ -757,14 +703,15 @@ INLINE void chip_wakeup(void)
                                /* later to avoid the bus access overhead */
                                g_wlan.hif_func.hif_read_reg(0xf1, &clk_status_reg);
 
-                               if ((clk_status_reg & 0x1) == 0) {
+                               if ((clk_status_reg & 0x1) == 0)
                                        wilc_debug(N_ERR, "clocks still OFF. Wake up failed\n");
-                               }
+
                        }
                        /* in case of failure, Reset the wakeup bit to introduce a new edge on the next loop */
                        if ((clk_status_reg & 0x1) == 0) {
                                /* Reset bit 0 */
-                               g_wlan.hif_func.hif_write_reg(0xf0, reg & (~(1 << 0)));
+                               g_wlan.hif_func.hif_write_reg(0xf0, reg &
+                                                             (~BIT(0)));
                        }
                } while ((clk_status_reg & 0x1) == 0);
        }
@@ -772,44 +719,46 @@ INLINE void chip_wakeup(void)
 
        if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
                g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
-               reg &= ~(1 << 0);
+               reg &= ~BIT(0);
                g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
 
                if (wilc_get_chipid(false) >= 0x1002b0) {
                        /* Enable PALDO back right after wakeup */
-                       uint32_t val32;
+                       u32 val32;
+
                        g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
 
                        g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
                }
        }
        genuChipPSstate = CHIP_WAKEDUP;
 }
 #else
-INLINE void chip_wakeup(void)
+static inline void chip_wakeup(void)
 {
-       uint32_t reg, trials = 0;
+       u32 reg, trials = 0;
+
        do {
                if ((g_wlan.io_func.io_type & 0x1) == HIF_SPI) {
                        g_wlan.hif_func.hif_read_reg(1, &reg);
                        /* Make sure bit 1 is 0 before we start. */
-                       g_wlan.hif_func.hif_write_reg(1, reg & ~(1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg & ~BIT(1));
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(1, reg | (1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg | BIT(1));
                        /* Clear bit 1*/
-                       g_wlan.hif_func.hif_write_reg(1, reg  & ~(1 << 1));
+                       g_wlan.hif_func.hif_write_reg(1, reg  & ~BIT(1));
                } else if ((g_wlan.io_func.io_type & 0x1) == HIF_SDIO)   {
                        /* Make sure bit 0 is 0 before we start. */
                        g_wlan.hif_func.hif_read_reg(0xf0, &reg);
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~(1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg & ~BIT(0));
                        /* Set bit 1 */
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg | (1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg | BIT(0));
                        /* Clear bit 1 */
-                       g_wlan.hif_func.hif_write_reg(0xf0, reg  & ~(1 << 0));
+                       g_wlan.hif_func.hif_write_reg(0xf0, reg  & ~BIT(0));
                }
 
                do {
@@ -818,27 +767,28 @@ INLINE void chip_wakeup(void)
 
                        /* Make sure chip is awake. This is an extra step that can be removed */
                        /* later to avoid the bus access overhead */
-                       if ((wilc_get_chipid(true) == 0)) {
+                       if ((wilc_get_chipid(true) == 0))
                                wilc_debug(N_ERR, "Couldn't read chip id. Wake up failed\n");
-                       }
+
                } while ((wilc_get_chipid(true) == 0) && ((++trials % 3) == 0));
 
        } while (wilc_get_chipid(true) == 0);
 
        if (genuChipPSstate == CHIP_SLEEPING_MANUAL) {
                g_wlan.hif_func.hif_read_reg(0x1C0C, &reg);
-               reg &= ~(1 << 0);
+               reg &= ~BIT(0);
                g_wlan.hif_func.hif_write_reg(0x1C0C, reg);
 
                if (wilc_get_chipid(false) >= 0x1002b0) {
                        /* Enable PALDO back right after wakeup */
-                       uint32_t val32;
+                       u32 val32;
+
                        g_wlan.hif_func.hif_read_reg(0x1e1c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e1c, val32);
 
                        g_wlan.hif_func.hif_read_reg(0x1e9c, &val32);
-                       val32 |= (1 << 6);
+                       val32 |= BIT(6);
                        g_wlan.hif_func.hif_write_reg(0x1e9c, val32);
                }
        }
@@ -871,29 +821,35 @@ void chip_sleep_manually(u32 u32SleepTime)
  *      Tx, Rx queue handle functions
  *
  ********************************************/
-static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
+int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount)
 {
        wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        int i, entries = 0;
-       uint32_t sum;
-       uint32_t reg;
-       uint8_t *txb = p->tx_buffer;
-       uint32_t offset = 0;
+       u32 sum;
+       u32 reg;
+       u8 *txb = p->tx_buffer;
+       u32 offset = 0;
        int vmm_sz = 0;
        struct txq_entry_t *tqe;
        int ret = 0;
        int counter;
        int timeout;
-       uint32_t vmm_table[WILC_VMM_TBL_SIZE];
+       u32 vmm_table[WILC_VMM_TBL_SIZE];
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
+
        p->txq_exit = 0;
        do {
                if (p->quit)
                        break;
 
-               /*Added by Amr - BugID_4720*/
-               p->os_func.os_wait(p->txq_add_to_head_lock, CFG_PKTS_TIMEOUT);
+               linux_wlan_lock_timeout(&wilc->txq_add_to_head_cs,
+                                       CFG_PKTS_TIMEOUT);
 #ifdef TCP_ACK_FILTER
-               wilc_wlan_txq_filter_dup_tcp_ack();
+               wilc_wlan_txq_filter_dup_tcp_ack(dev);
 #endif
                /**
                 *      build the vmm list
@@ -903,43 +859,31 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                i = 0;
                sum = 0;
                do {
-                       /* if ((tqe != NULL) && (i < (8)) && */
-                       /* if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE-1)) && */
                        if ((tqe != NULL) && (i < (WILC_VMM_TBL_SIZE - 1)) /* reserve last entry to 0 */) {
 
-                               if (tqe->type == WILC_CFG_PKT) {
+                               if (tqe->type == WILC_CFG_PKT)
                                        vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
-                               }
-                               /*Bug3959: transmitting mgmt frames received from host*/
-                               /*vmm_sz will only be equal to tqe->buffer_size + 4 bytes (HOST_HDR_OFFSET)*/
-                               /* in other cases WILC_MGMT_PKT and WILC_DATA_PKT_MAC_HDR*/
-                               else if (tqe->type == WILC_NET_PKT) {
+
+                               else if (tqe->type == WILC_NET_PKT)
                                        vmm_sz = ETH_ETHERNET_HDR_OFFSET;
-                               }
-#ifdef WILC_FULLY_HOSTING_AP
-                               else if (tqe->type == WILC_FH_DATA_PKT) {
-                                       vmm_sz = FH_TX_HOST_HDR_OFFSET;
-                               }
-#endif
-#ifdef WILC_AP_EXTERNAL_MLME
-                               else {
+
+                               else
                                        vmm_sz = HOST_HDR_OFFSET;
-                               }
-#endif
+
                                vmm_sz += tqe->buffer_size;
                                PRINT_D(TX_DBG, "VMM Size before alignment = %d\n", vmm_sz);
                                if (vmm_sz & 0x3) {                                                                                                     /* has to be word aligned */
                                        vmm_sz = (vmm_sz + 4) & ~0x3;
                                }
-                               if ((sum + vmm_sz) > p->tx_buffer_size) {
+                               if ((sum + vmm_sz) > LINUX_TX_SIZE)
                                        break;
-                               }
+
                                PRINT_D(TX_DBG, "VMM Size AFTER alignment = %d\n", vmm_sz);
                                vmm_table[i] = vmm_sz / 4;                                                                                /* table take the word size */
                                PRINT_D(TX_DBG, "VMMTable entry size = %d\n", vmm_table[i]);
 
                                if (tqe->type == WILC_CFG_PKT) {
-                                       vmm_table[i] |= (1 << 10);
+                                       vmm_table[i] |= BIT(10);
                                        PRINT_D(TX_DBG, "VMMTable entry changed for CFG packet = %d\n", vmm_table[i]);
                                }
 #ifdef BIG_ENDIAN
@@ -949,7 +893,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                i++;
                                sum += vmm_sz;
                                PRINT_D(TX_DBG, "sum = %d\n", sum);
-                               tqe = wilc_wlan_txq_get_next(tqe);
+                               tqe = wilc_wlan_txq_get_next(wilc, tqe);
                        } else {
                                break;
                        }
@@ -991,14 +935,13 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                 **/
                                PRINT_WRN(GENERIC_DBG, "[wilc txq]: warn, vmm table not clear yet, wait...\n");
                                release_bus(RELEASE_ALLOW_SLEEP);
-                               p->os_func.os_sleep(3); /* wait 3 ms */
+                               usleep_range(3000, 3000);
                                acquire_bus(ACQUIRE_AND_WAKEUP);
                        }
                } while (!p->quit);
 
-               if (!ret) {
+               if (!ret)
                        goto _end_;
-               }
 
                timeout = 200;
                do {
@@ -1006,7 +949,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                        /**
                         * write to vmm table
                         **/
-                       ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (uint8_t *)vmm_table, ((i + 1) * 4)); /* Bug 4477 fix */
+                       ret = p->hif_func.hif_block_tx(WILC_VMM_TBL_RX_SHADOW_BASE, (u8 *)vmm_table, ((i + 1) * 4));
                        if (!ret) {
                                wilc_debug(N_ERR, "ERR block TX of VMM table.\n");
                                break;
@@ -1037,11 +980,10 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                         *      Get the entries
                                         **/
                                        entries = ((reg >> 3) & 0x3f);
-                                       /* entries = ((reg>>3)&0x2f); */
                                        break;
                                } else {
                                        release_bus(RELEASE_ALLOW_SLEEP);
-                                       p->os_func.os_sleep(3); /* wait 3 ms */
+                                       usleep_range(3000, 3000);
                                        acquire_bus(ACQUIRE_AND_WAKEUP);
                                        PRINT_WRN(GENERIC_DBG, "Can't get VMM entery - reg = %2x\n", reg);
                                }
@@ -1051,9 +993,8 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                break;
                        }
 
-                       if (!ret) {
+                       if (!ret)
                                break;
-                       }
 
                        if (entries == 0) {
                                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]);
@@ -1064,7 +1005,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                        wilc_debug(N_ERR, "[wilc txq]: fail can't read reg WILC_HOST_TX_CTRL..\n");
                                        break;
                                }
-                               reg &= ~(1ul << 0);
+                               reg &= ~BIT(0);
                                ret = p->hif_func.hif_write_reg(WILC_HOST_TX_CTRL, reg);
                                if (!ret) {
                                        wilc_debug(N_ERR, "[wilc txq]: fail can't write reg WILC_HOST_TX_CTRL..\n");
@@ -1076,9 +1017,9 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                        }
                } while (1);
 
-               if (!ret) {
+               if (!ret)
                        goto _end_;
-               }
+
                if (entries == 0) {
                        ret = WILC_TX_ERR_NO_BUF;
                        goto _end_;
@@ -1096,7 +1037,7 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                do {
                        tqe = wilc_wlan_txq_remove_from_head();
                        if (tqe != NULL && (vmm_table[i] != 0)) {
-                               uint32_t header, buffer_offset;
+                               u32 header, buffer_offset;
 
 #ifdef BIG_ENDIAN
                                vmm_table[i] = BYTE_SWAP(vmm_table[i]);
@@ -1104,14 +1045,10 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                vmm_sz = (vmm_table[i] & 0x3ff);        /* in word unit */
                                vmm_sz *= 4;
                                header = (tqe->type << 31) | (tqe->buffer_size << 15) | vmm_sz;
-                               /*Bug3959: transmitting mgmt frames received from host*/
-                               /*setting bit 30 in the host header to indicate mgmt frame*/
-#ifdef WILC_AP_EXTERNAL_MLME
                                if (tqe->type == WILC_MGMT_PKT)
-                                       header |= (1 << 30);
+                                       header |= BIT(30);
                                else
-                                       header &= ~(1 << 30);
-#endif
+                                       header &= ~BIT(30);
 
 #ifdef BIG_ENDIAN
                                header = BYTE_SWAP(header);
@@ -1120,20 +1057,13 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                if (tqe->type == WILC_CFG_PKT) {
                                        buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
                                }
-                               /*Bug3959: transmitting mgmt frames received from host*/
-                               /*buffer offset = HOST_HDR_OFFSET in other cases: WILC_MGMT_PKT*/
-                               /* and WILC_DATA_PKT_MAC_HDR*/
                                else if (tqe->type == WILC_NET_PKT) {
                                        char *pBSSID = ((struct tx_complete_data *)(tqe->priv))->pBssid;
+
                                        buffer_offset = ETH_ETHERNET_HDR_OFFSET;
                                        /* copy the bssid at the sart of the buffer */
                                        memcpy(&txb[offset + 4], pBSSID, 6);
                                }
-#ifdef WILC_FULLY_HOSTING_AP
-                               else if (tqe->type == WILC_FH_DATA_PKT) {
-                                       buffer_offset = FH_TX_HOST_HDR_OFFSET;
-                               }
-#endif
                                else {
                                        buffer_offset = HOST_HDR_OFFSET;
                                }
@@ -1145,11 +1075,10 @@ static int wilc_wlan_handle_txq(uint32_t *pu32TxqCount)
                                if (tqe->tx_complete_func)
                                        tqe->tx_complete_func(tqe->priv, tqe->status);
                                #ifdef TCP_ACK_FILTER
-                               if (tqe->tcp_PendingAck_index != NOT_TCP_ACK) {
+                               if (tqe->tcp_PendingAck_index != NOT_TCP_ACK)
                                        Pending_Acks_info[tqe->tcp_PendingAck_index].txqe = NULL;
-                               }
                                #endif
-                               p->os_func.os_free(tqe);
+                               kfree(tqe);
                        } else {
                                break;
                        }
@@ -1181,8 +1110,7 @@ _end_:
                if (ret != 1)
                        break;
        } while (0);
-       /*Added by Amr - BugID_4720*/
-       p->os_func.os_signal(p->txq_add_to_head_lock);
+       up(&wilc->txq_add_to_head_cs);
 
        p->txq_exit = 1;
        PRINT_D(TX_DBG, "THREAD: Exiting txq\n");
@@ -1191,11 +1119,11 @@ _end_:
        return ret;
 }
 
-static void wilc_wlan_handle_rxq(void)
+static void wilc_wlan_handle_rxq(struct wilc *wilc)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        int offset = 0, size, has_packet = 0;
-       uint8_t *buffer;
+       u8 *buffer;
        struct rxq_entry_t *rqe;
 
        p->rxq_exit = 0;
@@ -1206,10 +1134,10 @@ static void wilc_wlan_handle_rxq(void)
        do {
                if (p->quit) {
                        PRINT_D(RX_DBG, "exit 1st do-while due to Clean_UP function\n");
-                       p->os_func.os_signal(p->cfg_wait);
+                       up(&wilc->cfg_event);
                        break;
                }
-               rqe = wilc_wlan_rxq_remove();
+               rqe = wilc_wlan_rxq_remove(wilc);
                if (rqe == NULL) {
                        PRINT_D(RX_DBG, "nothing in the queue - exit 1st do-while\n");
                        break;
@@ -1222,9 +1150,10 @@ static void wilc_wlan_handle_rxq(void)
 
 
                do {
-                       uint32_t header;
-                       uint32_t pkt_len, pkt_offset, tp_len;
+                       u32 header;
+                       u32 pkt_len, pkt_offset, tp_len;
                        int is_cfg_packet;
+
                        PRINT_D(RX_DBG, "In the 2nd do-while\n");
                        memcpy(&header, &buffer[offset], 4);
 #ifdef BIG_ENDIAN
@@ -1244,8 +1173,6 @@ static void wilc_wlan_handle_rxq(void)
                                break;
                        }
 
-/*bug 3887: [AP] Allow Management frames to be passed to the host*/
-                       #if defined(WILC_AP_EXTERNAL_MLME) || defined(WILC_P2P)
                        #define IS_MANAGMEMENT                          0x100
                        #define IS_MANAGMEMENT_CALLBACK                 0x080
                        #define IS_MGMT_STATUS_SUCCES                   0x040
@@ -1255,50 +1182,40 @@ static void wilc_wlan_handle_rxq(void)
                                /* reset mgmt indicator bit, to use pkt_offeset in furthur calculations */
                                pkt_offset &= ~(IS_MANAGMEMENT | IS_MANAGMEMENT_CALLBACK | IS_MGMT_STATUS_SUCCES);
 
-#ifdef USE_WIRELESS
-                               WILC_WFI_mgmt_rx(&buffer[offset + HOST_HDR_OFFSET], pkt_len);
-
-#endif
-
+                               WILC_WFI_mgmt_rx(wilc, &buffer[offset + HOST_HDR_OFFSET], pkt_len);
                        }
-                       /* BUG4530 fix */
                        else
-                       #endif
                        {
 
                                if (!is_cfg_packet) {
-
-                                       if (p->net_func.rx_indicate) {
-                                               if (pkt_len > 0) {
-                                                       p->net_func.rx_indicate(&buffer[offset], pkt_len, pkt_offset);
-                                                       has_packet = 1;
-                                               }
+                                       if (pkt_len > 0) {
+                                               frmw_to_linux(wilc,
+                                                             &buffer[offset],
+                                                             pkt_len,
+                                                             pkt_offset);
+                                               has_packet = 1;
                                        }
                                } else {
                                        wilc_cfg_rsp_t rsp;
 
 
 
-                                       p->cif_func.rx_indicate(&buffer[pkt_offset + offset], pkt_len, &rsp);
+                                       wilc_wlan_cfg_indicate_rx(&buffer[pkt_offset + offset], pkt_len, &rsp);
                                        if (rsp.type == WILC_CFG_RSP) {
                                                /**
                                                 *      wake up the waiting task...
                                                 **/
                                                PRINT_D(RX_DBG, "p->cfg_seq_no = %d - rsp.seq_no = %d\n", p->cfg_seq_no, rsp.seq_no);
-                                               if (p->cfg_seq_no == rsp.seq_no) {
-                                                       p->os_func.os_signal(p->cfg_wait);
-                                               }
+                                               if (p->cfg_seq_no == rsp.seq_no)
+                                                       up(&wilc->cfg_event);
                                        } else if (rsp.type == WILC_CFG_RSP_STATUS) {
                                                /**
                                                 *      Call back to indicate status...
                                                 **/
-                                               if (p->indicate_func.mac_indicate) {
-                                                       p->indicate_func.mac_indicate(WILC_MAC_INDICATE_STATUS);
-                                               }
+                                               linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_STATUS);
 
                                        } else if (rsp.type == WILC_CFG_RSP_SCAN) {
-                                               if (p->indicate_func.mac_indicate)
-                                                       p->indicate_func.mac_indicate(WILC_MAC_INDICATE_SCAN);
+                                               linux_wlan_mac_indicate(wilc, WILC_MAC_INDICATE_SCAN);
                                        }
                                }
                        }
@@ -1309,16 +1226,13 @@ static void wilc_wlan_handle_rxq(void)
 
 
 #ifndef MEMORY_STATIC
-               if (buffer != NULL)
-                       p->os_func.os_free((void *)buffer);
+               kfree(buffer);
 #endif
-               if (rqe != NULL)
-                       p->os_func.os_free((void *)rqe);
+               kfree(rqe);
+
+               if (has_packet)
+                       linux_wlan_rx_complete();
 
-               if (has_packet) {
-                       if (p->net_func.rx_complete)
-                               p->net_func.rx_complete();
-               }
        } while (1);
 
        p->rxq_exit = 1;
@@ -1334,7 +1248,7 @@ static void wilc_unknown_isr_ext(void)
 {
        g_wlan.hif_func.hif_clear_int_ext(0);
 }
-static void wilc_pllupdate_isr_ext(uint32_t int_stats)
+static void wilc_pllupdate_isr_ext(u32 int_stats)
 {
 
        int trials = 10;
@@ -1342,16 +1256,16 @@ static void wilc_pllupdate_isr_ext(uint32_t int_stats)
        g_wlan.hif_func.hif_clear_int_ext(PLL_INT_CLR);
 
        /* Waiting for PLL */
-       g_wlan.os_func.os_atomic_sleep(WILC_PLL_TO);
+       mdelay(WILC_PLL_TO);
 
        /* poll till read a valid data */
        while (!(ISWILC1000(wilc_get_chipid(true)) && --trials)) {
                PRINT_D(TX_DBG, "PLL update retrying\n");
-               g_wlan.os_func.os_atomic_sleep(1);
+               mdelay(1);
        }
 }
 
-static void wilc_sleeptimer_isr_ext(uint32_t int_stats1)
+static void wilc_sleeptimer_isr_ext(u32 int_stats1)
 {
        g_wlan.hif_func.hif_clear_int_ext(SLEEP_INT_CLR);
 #ifndef WILC_OPTIMIZE_SLEEP_INT
@@ -1359,15 +1273,15 @@ static void wilc_sleeptimer_isr_ext(uint32_t int_stats1)
 #endif
 }
 
-static void wilc_wlan_handle_isr_ext(uint32_t int_status)
+static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
 #ifdef MEMORY_STATIC
-       uint32_t offset = p->rx_buffer_offset;
+       u32 offset = p->rx_buffer_offset;
 #endif
-       uint8_t *buffer = NULL;
-       uint32_t size;
-       uint32_t retries = 0;
+       u8 *buffer = NULL;
+       u32 size;
+       u32 retries = 0;
        int ret = 0;
        struct rxq_entry_t *rqe;
 
@@ -1379,7 +1293,7 @@ static void wilc_wlan_handle_isr_ext(uint32_t int_status)
        size = ((int_status & 0x7fff) << 2);
 
        while (!size && retries < 10) {
-               uint32_t time = 0;
+               u32 time = 0;
                /*looping more secure*/
                /*zero size make a crashe because the dma will not happen and that will block the firmware*/
                wilc_debug(N_ERR, "RX Size equal zero ... Trying to read it again for %d time\n", time++);
@@ -1391,7 +1305,7 @@ static void wilc_wlan_handle_isr_ext(uint32_t int_status)
 
        if (size > 0) {
 #ifdef MEMORY_STATIC
-               if (p->rx_buffer_size - offset < size)
+               if (LINUX_RX_SIZE - offset < size)
                        offset = 0;
 
                if (p->rx_buffer)
@@ -1402,7 +1316,7 @@ static void wilc_wlan_handle_isr_ext(uint32_t int_status)
                }
 
 #else
-               buffer = p->os_func.os_malloc(size);
+               buffer = kmalloc(size, GFP_KERNEL);
                if (buffer == NULL) {
                        wilc_debug(N_ERR, "[wilc isr]: fail alloc host memory...drop the packets (%d)\n", size);
                        usleep_range(100 * 1000, 100 * 1000);
@@ -1436,46 +1350,41 @@ _end_:
                        /**
                         *      add to rx queue
                         **/
-                       rqe = (struct rxq_entry_t *)p->os_func.os_malloc(sizeof(struct rxq_entry_t));
+                       rqe = kmalloc(sizeof(struct rxq_entry_t), GFP_KERNEL);
                        if (rqe != NULL) {
                                rqe->buffer = buffer;
                                rqe->buffer_size = size;
                                PRINT_D(RX_DBG, "rxq entery Size= %d - Address = %p\n", rqe->buffer_size, rqe->buffer);
-                               wilc_wlan_rxq_add(rqe);
-                               p->os_func.os_signal(p->rxq_wait);
+                               wilc_wlan_rxq_add(wilc, rqe);
                        }
                } else {
 #ifndef MEMORY_STATIC
-                       if (buffer != NULL)
-                               p->os_func.os_free(buffer);
+                       kfree(buffer);
 #endif
                }
        }
-#ifdef TCP_ENHANCEMENTS
-       wilc_wlan_handle_rxq();
-#endif
+       wilc_wlan_handle_rxq(wilc);
 }
 
-void wilc_handle_isr(void)
+void wilc_handle_isr(void *wilc)
 {
-       uint32_t int_status;
+       u32 int_status;
 
        acquire_bus(ACQUIRE_AND_WAKEUP);
        g_wlan.hif_func.hif_read_int(&int_status);
 
-       if (int_status & PLL_INT_EXT) {
+       if (int_status & PLL_INT_EXT)
                wilc_pllupdate_isr_ext(int_status);
-       }
+
        if (int_status & DATA_INT_EXT) {
-               wilc_wlan_handle_isr_ext(int_status);
+               wilc_wlan_handle_isr_ext(wilc, int_status);
        #ifndef WILC_OPTIMIZE_SLEEP_INT
                /* Chip is up and talking*/
                genuChipPSstate = CHIP_WAKEDUP;
        #endif
        }
-       if (int_status & SLEEP_INT_EXT) {
+       if (int_status & SLEEP_INT_EXT)
                wilc_sleeptimer_isr_ext(int_status);
-       }
 
        if (!(int_status & (ALL_INT_EXT))) {
 #ifdef WILC_SDIO
@@ -1483,9 +1392,6 @@ void wilc_handle_isr(void)
 #endif
                wilc_unknown_isr_ext();
        }
-#if ((!defined WILC_SDIO) || (defined WILC_SDIO_IRQ_GPIO))
-       linux_wlan_enable_irq();
-#endif
        release_bus(RELEASE_ALLOW_SLEEP);
 }
 
@@ -1494,26 +1400,18 @@ void wilc_handle_isr(void)
  *      Firmware download
  *
  ********************************************/
-static int wilc_wlan_firmware_download(const uint8_t *buffer, uint32_t buffer_size)
+int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       uint32_t offset;
-       uint32_t addr, size, size2, blksz;
-       uint8_t *dma_buffer;
+       wilc_wlan_dev_t *p = &g_wlan;
+       u32 offset;
+       u32 addr, size, size2, blksz;
+       u8 *dma_buffer;
        int ret = 0;
 
-       blksz = (1ul << 12); /* Bug 4703: 4KB Good enough size for most platforms = PAGE_SIZE. */
+       blksz = BIT(12);
        /* Allocate a DMA coherent  buffer. */
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-       {
-               extern void *get_fw_buffer(void);
-               dma_buffer = (uint8_t *)get_fw_buffer();
-               PRINT_D(TX_DBG, "fw_buffer = 0x%x\n", dma_buffer);
-       }
-#else
-       dma_buffer = (uint8_t *)g_wlan.os_func.os_malloc(blksz);
-#endif
+       dma_buffer = kmalloc(blksz, GFP_KERNEL);
        if (dma_buffer == NULL) {
                /*EIO   5*/
                ret = -5;
@@ -1563,12 +1461,7 @@ static int wilc_wlan_firmware_download(const uint8_t *buffer, uint32_t buffer_si
 
 _fail_:
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-
-#else
-       if (dma_buffer)
-               g_wlan.os_func.os_free(dma_buffer);
-#endif
+       kfree(dma_buffer);
 
 _fail_1:
 
@@ -1580,35 +1473,19 @@ _fail_1:
  *      Common
  *
  ********************************************/
-static int wilc_wlan_start(void)
+int wilc_wlan_start(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       uint32_t reg = 0;
+       wilc_wlan_dev_t *p = &g_wlan;
+       u32 reg = 0;
        int ret;
-       uint32_t chipid;
+       u32 chipid;
 
        /**
         *      Set the host interface
         **/
-#ifdef OLD_FPGA_BITFILE
-       acquire_bus(ACQUIRE_ONLY);
-       ret = p->hif_func.hif_read_reg(WILC_VMM_CORE_CTL, &reg);
-       if (!ret) {
-               wilc_debug(N_ERR, "[wilc start]: fail read reg vmm_core_ctl...\n");
-               release_bus(RELEASE_ALLOW_SLEEP);
-               return ret;
-       }
-       reg |= (p->io_func.io_type << 2);
-       ret = p->hif_func.hif_write_reg(WILC_VMM_CORE_CTL, reg);
-       if (!ret) {
-               wilc_debug(N_ERR, "[wilc start]: fail write reg vmm_core_ctl...\n");
-               release_bus(RELEASE_ONLY);
-               return ret;
-       }
-#else
        if (p->io_func.io_type == HIF_SDIO) {
                reg = 0;
-               reg |= (1 << 3); /* bug 4456 and 4557 */
+               reg |= BIT(3); /* bug 4456 and 4557 */
        } else if (p->io_func.io_type == HIF_SPI) {
                reg = 1;
        }
@@ -1644,13 +1521,11 @@ static int wilc_wlan_start(void)
        reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
 
 
-/*BugID_5257*/
 /*Set oscillator frequency*/
 #ifdef XTAL_24
        reg |= WILC_HAVE_XTAL_24;
 #endif
 
-/*BugID_5271*/
 /*Enable/Disable GPIO configuration for FW logs*/
 #ifdef DISABLE_WILC_UART
        reg |= WILC_HAVE_DISABLE_WILC_UART;
@@ -1664,8 +1539,6 @@ static int wilc_wlan_start(void)
                ret = -5;
                return ret;
        }
-#endif
-
 
        /**
         *      Bus related
@@ -1687,13 +1560,13 @@ static int wilc_wlan_start(void)
 
 
        p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
-       if ((reg & (1ul << 10)) == (1ul << 10)) {
-               reg &= ~(1ul << 10);
+       if ((reg & BIT(10)) == BIT(10)) {
+               reg &= ~BIT(10);
                p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
                p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
        }
 
-       reg |= (1ul << 10);
+       reg |= BIT(10);
        ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
        p->hif_func.hif_read_reg(WILC_GLB_RESET_0, &reg);
        release_bus(RELEASE_ONLY);
@@ -1704,17 +1577,18 @@ static int wilc_wlan_start(void)
 void wilc_wlan_global_reset(void)
 {
 
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
+
        acquire_bus(ACQUIRE_AND_WAKEUP);
        p->hif_func.hif_write_reg(WILC_GLB_RESET_0, 0x0);
        release_bus(RELEASE_ONLY);
 }
-static int wilc_wlan_stop(void)
+int wilc_wlan_stop(void)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       uint32_t reg = 0;
+       wilc_wlan_dev_t *p = &g_wlan;
+       u32 reg = 0;
        int ret;
-       uint8_t timeout = 10;
+       u8 timeout = 10;
        /**
         *      TODO: stop the firmware, need a re-download
         **/
@@ -1727,7 +1601,7 @@ static int wilc_wlan_stop(void)
                return ret;
        }
 
-       reg &= ~(1 << 10);
+       reg &= ~BIT(10);
 
 
        ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
@@ -1748,9 +1622,9 @@ static int wilc_wlan_stop(void)
                }
                PRINT_D(GENERIC_DBG, "Read RESET Reg %x : Retry%d\n", reg, timeout);
                /*Workaround to ensure that the chip is actually reset*/
-               if ((reg & (1 << 10))) {
+               if ((reg & BIT(10))) {
                        PRINT_D(GENERIC_DBG, "Bit 10 not reset : Retry %d\n", timeout);
-                       reg &= ~(1 << 10);
+                       reg &= ~BIT(10);
                        ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
                        timeout--;
                } else {
@@ -1766,31 +1640,31 @@ static int wilc_wlan_stop(void)
                }
 
        } while (timeout);
-#if 1
-/******************************************************************************/
-/* This was add at Bug 4595 to reset the chip while maintaining the bus state */
-/******************************************************************************/
-       reg = ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 8) | (1 << 9) | (1 << 26) | (1 << 29) | (1 << 30) | (1 << 31)); /**/
-       /**/
-       p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);                                 /**/
-       reg = ~(1 << 10);                                                                                               /**/
-       /**/
-       ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);                                 /**/
-/******************************************************************************/
-#endif
+       reg = (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(8) | BIT(9) | BIT(26) |
+              BIT(29) | BIT(30) | BIT(31));
+
+       p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
+       reg = (u32)~BIT(10);
+
+       ret = p->hif_func.hif_write_reg(WILC_GLB_RESET_0, reg);
 
        release_bus(RELEASE_ALLOW_SLEEP);
 
        return ret;
 }
 
-static void wilc_wlan_cleanup(void)
+void wilc_wlan_cleanup(struct net_device *dev)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        struct txq_entry_t *tqe;
        struct rxq_entry_t *rqe;
-       uint32_t reg = 0;
+       u32 reg = 0;
        int ret;
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
        p->quit = 1;
        do {
@@ -1799,37 +1673,28 @@ static void wilc_wlan_cleanup(void)
                        break;
                if (tqe->tx_complete_func)
                        tqe->tx_complete_func(tqe->priv, 0);
-               p->os_func.os_free((void *)tqe);
+               kfree(tqe);
        } while (1);
 
        do {
-               rqe = wilc_wlan_rxq_remove();
+               rqe = wilc_wlan_rxq_remove(wilc);
                if (rqe == NULL)
                        break;
-#ifdef MEMORY_DYNAMIC
-               p->os_func.os_free((void *)tqe->buffer);
+#ifndef MEMORY_STATIC
+               kfree(rqe->buffer);
 #endif
-               p->os_func.os_free((void *)rqe);
+               kfree(rqe);
        } while (1);
 
        /**
         *      clean up buffer
         **/
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-
-#else
        #ifdef MEMORY_STATIC
-       if (p->rx_buffer) {
-               p->os_func.os_free(p->rx_buffer);
-               p->rx_buffer = NULL;
-       }
+       kfree(p->rx_buffer);
+       p->rx_buffer = NULL;
        #endif
-       if (p->tx_buffer) {
-               p->os_func.os_free(p->tx_buffer);
-               p->tx_buffer = NULL;
-       }
-#endif
+       kfree(p->tx_buffer);
 
        acquire_bus(ACQUIRE_AND_WAKEUP);
 
@@ -1853,9 +1718,9 @@ static void wilc_wlan_cleanup(void)
 
 }
 
-static int wilc_wlan_cfg_commit(int type, uint32_t drvHandler)
+static int wilc_wlan_cfg_commit(int type, u32 drvHandler)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
+       wilc_wlan_dev_t *p = &g_wlan;
        wilc_cfg_frame_t *cfg = &p->cfg_frame;
        int total_len = p->cfg_frame_offset + 4 + DRIVER_HANDLER_SIZE;
        int seq_no = p->cfg_seq_no % 256;
@@ -1871,29 +1736,29 @@ static int wilc_wlan_cfg_commit(int type, uint32_t drvHandler)
                cfg->wid_header[0] = 'Q';
        }
        cfg->wid_header[1] = seq_no;    /* sequence number */
-       cfg->wid_header[2] = (uint8_t)total_len;
-       cfg->wid_header[3] = (uint8_t)(total_len >> 8);
-       cfg->wid_header[4] = (uint8_t)driver_handler;
-       cfg->wid_header[5] = (uint8_t)(driver_handler >> 8);
-       cfg->wid_header[6] = (uint8_t)(driver_handler >> 16);
-       cfg->wid_header[7] = (uint8_t)(driver_handler >> 24);
+       cfg->wid_header[2] = (u8)total_len;
+       cfg->wid_header[3] = (u8)(total_len >> 8);
+       cfg->wid_header[4] = (u8)driver_handler;
+       cfg->wid_header[5] = (u8)(driver_handler >> 8);
+       cfg->wid_header[6] = (u8)(driver_handler >> 16);
+       cfg->wid_header[7] = (u8)(driver_handler >> 24);
        p->cfg_seq_no = seq_no;
 
        /**
         *      Add to TX queue
         **/
 
-       /*Edited by Amr - BugID_4720*/
        if (!wilc_wlan_txq_add_cfg_pkt(&cfg->wid_header[0], total_len))
                return -1;
 
        return 0;
 }
 
-static int wilc_wlan_cfg_set(int start, uint32_t wid, uint8_t *buffer, uint32_t buffer_size, int commit, uint32_t drvHandler)
+int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
+                     int commit, u32 drvHandler)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       uint32_t offset;
+       wilc_wlan_dev_t *p = &g_wlan;
+       u32 offset;
        int ret_size;
 
 
@@ -1904,7 +1769,8 @@ static int wilc_wlan_cfg_set(int start, uint32_t wid, uint8_t *buffer, uint32_t
                p->cfg_frame_offset = 0;
 
        offset = p->cfg_frame_offset;
-       ret_size = p->cif_func.cfg_wid_set(p->cfg_frame.frame, offset, (uint16_t)wid, buffer, buffer_size);
+       ret_size = wilc_wlan_cfg_set_wid(p->cfg_frame.frame, offset, (u16)wid,
+                                        buffer, buffer_size);
        offset += ret_size;
        p->cfg_frame_offset = offset;
 
@@ -1913,11 +1779,11 @@ static int wilc_wlan_cfg_set(int start, uint32_t wid, uint8_t *buffer, uint32_t
                PRINT_D(RX_DBG, "Processing cfg_set()\n");
                p->cfg_frame_in_use = 1;
 
-               /*Edited by Amr - BugID_4720*/
                if (wilc_wlan_cfg_commit(WILC_CFG_SET, drvHandler))
-                       ret_size = 0;   /* BugID_5213 */
+                       ret_size = 0;
 
-               if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
+               if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
+                                           CFG_PKTS_TIMEOUT)) {
                        PRINT_D(TX_DBG, "Set Timed Out\n");
                        ret_size = 0;
                }
@@ -1929,10 +1795,10 @@ static int wilc_wlan_cfg_set(int start, uint32_t wid, uint8_t *buffer, uint32_t
 
        return ret_size;
 }
-static int wilc_wlan_cfg_get(int start, uint32_t wid, int commit, uint32_t drvHandler)
+int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
-       uint32_t offset;
+       wilc_wlan_dev_t *p = &g_wlan;
+       u32 offset;
        int ret_size;
 
 
@@ -1943,19 +1809,19 @@ static int wilc_wlan_cfg_get(int start, uint32_t wid, int commit, uint32_t drvHa
                p->cfg_frame_offset = 0;
 
        offset = p->cfg_frame_offset;
-       ret_size = p->cif_func.cfg_wid_get(p->cfg_frame.frame, offset, (uint16_t)wid);
+       ret_size = wilc_wlan_cfg_get_wid(p->cfg_frame.frame, offset, (u16)wid);
        offset += ret_size;
        p->cfg_frame_offset = offset;
 
        if (commit) {
                p->cfg_frame_in_use = 1;
 
-               /*Edited by Amr - BugID_4720*/
                if (wilc_wlan_cfg_commit(WILC_CFG_QUERY, drvHandler))
-                       ret_size = 0;   /* BugID_5213 */
+                       ret_size = 0;
 
 
-               if (p->os_func.os_wait(p->cfg_wait, CFG_PKTS_TIMEOUT)) {
+               if (linux_wlan_lock_timeout(&g_linux_wlan->cfg_event,
+                                           CFG_PKTS_TIMEOUT)) {
                        PRINT_D(TX_DBG, "Get Timed Out\n");
                        ret_size = 0;
                }
@@ -1968,12 +1834,11 @@ static int wilc_wlan_cfg_get(int start, uint32_t wid, int commit, uint32_t drvHa
        return ret_size;
 }
 
-static int wilc_wlan_cfg_get_val(uint32_t wid, uint8_t *buffer, uint32_t buffer_size)
+int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size)
 {
-       wilc_wlan_dev_t *p = (wilc_wlan_dev_t *)&g_wlan;
        int ret;
 
-       ret = p->cif_func.cfg_wid_get_val((uint16_t)wid, buffer, buffer_size);
+       ret = wilc_wlan_cfg_get_wid_value((u16)wid, buffer, buffer_size);
 
        return ret;
 }
@@ -1991,16 +1856,12 @@ void wilc_bus_set_default_speed(void)
        /* Restore bus speed to default.  */
        g_wlan.hif_func.hif_set_default_bus_speed();
 }
-uint32_t init_chip(void)
+u32 init_chip(void)
 {
-       uint32_t chipid;
-       uint32_t reg, ret = 0;
+       u32 chipid;
+       u32 reg, ret = 0;
 
-#if defined(PLAT_RK3026_TCHIP)
-       acquire_bus(ACQUIRE_AND_WAKEUP); /* AMR : 0422 RK3026 Crash issue */
-#else
        acquire_bus(ACQUIRE_ONLY);
-#endif
 
        chipid = wilc_get_chipid(true);
 
@@ -2017,7 +1878,7 @@ uint32_t init_chip(void)
                        wilc_debug(N_ERR, "[wilc start]: fail read reg 0x1118 ...\n");
                        return ret;
                }
-               reg |= (1 << 0);
+               reg |= BIT(0);
                ret = g_wlan.hif_func.hif_write_reg(0x1118, reg);
                if (!ret) {
                        wilc_debug(N_ERR, "[wilc start]: fail write reg 0x1118 ...\n");
@@ -2040,13 +1901,13 @@ uint32_t init_chip(void)
 
 }
 
-uint32_t wilc_get_chipid(uint8_t update)
+u32 wilc_get_chipid(u8 update)
 {
-       static uint32_t chipid;
+       static u32 chipid;
        /* SDIO can't read into global variables */
        /* Use this variable as a temp, then copy to the global */
-       uint32_t tempchipid = 0;
-       uint32_t rfrevid;
+       u32 tempchipid = 0;
+       u32 rfrevid;
 
        if (chipid == 0 || update != 0) {
                g_wlan.hif_func.hif_read_reg(0x1000, &tempchipid);
@@ -2076,25 +1937,7 @@ _fail_:
        return chipid;
 }
 
-#ifdef COMPLEMENT_BOOT
-uint8_t core_11b_ready(void)
-{
-       uint32_t reg_val;
-
-       acquire_bus(ACQUIRE_ONLY);
-       g_wlan.hif_func.hif_write_reg(0x16082c, 1);
-       g_wlan.hif_func.hif_write_reg(0x161600, 0x90);
-       g_wlan.hif_func.hif_read_reg(0x161600, &reg_val);
-       release_bus(RELEASE_ONLY);
-
-       if (reg_val == 0x90)
-               return 0;
-       else
-               return 1;
-}
-#endif
-
-int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
+int wilc_wlan_init(wilc_wlan_inp_t *inp)
 {
 
        int ret = 0;
@@ -2106,37 +1949,10 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        /**
         *      store the input
         **/
-       memcpy((void *)&g_wlan.os_func, (void *)&inp->os_func, sizeof(wilc_wlan_os_func_t));
        memcpy((void *)&g_wlan.io_func, (void *)&inp->io_func, sizeof(wilc_wlan_io_func_t));
-       memcpy((void *)&g_wlan.net_func, (void *)&inp->net_func, sizeof(wilc_wlan_net_func_t));
-       memcpy((void *)&g_wlan.indicate_func, (void *)&inp->indicate_func, sizeof(wilc_wlan_net_func_t));
-       g_wlan.hif_lock = inp->os_context.hif_critical_section;
-       g_wlan.txq_lock = inp->os_context.txq_critical_section;
-
-       /*Added by Amr - BugID_4720*/
-       g_wlan.txq_add_to_head_lock = inp->os_context.txq_add_to_head_critical_section;
-
-       /*Added by Amr - BugID_4720*/
-       g_wlan.txq_spinlock = inp->os_context.txq_spin_lock;
-
-       g_wlan.rxq_lock = inp->os_context.rxq_critical_section;
-       g_wlan.txq_wait = inp->os_context.txq_wait_event;
-       g_wlan.rxq_wait = inp->os_context.rxq_wait_event;
-       g_wlan.cfg_wait = inp->os_context.cfg_wait_event;
-       g_wlan.tx_buffer_size = inp->os_context.tx_buffer_size;
-#if defined (MEMORY_STATIC)
-       g_wlan.rx_buffer_size = inp->os_context.rx_buffer_size;
-#endif
        /***
         *      host interface init
         **/
-#if defined(PLAT_RK3026_TCHIP) /* AMR : 0422 RK3026 Crash issue */
-       if (!g_wilc_initialized) {
-               custom_lock_bus(g_mac_open);
-               custom_wakeup(g_mac_open);
-       }
-#endif
-
        if ((inp->io_func.io_type & 0x1) == HIF_SDIO) {
                if (!hif_sdio.hif_init(inp, wilc_debug)) {
                        /* EIO  5 */
@@ -2165,32 +1981,17 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        /***
         *      mac interface init
         **/
-       if (!mac_cfg.cfg_init(wilc_debug)) {
+       if (!wilc_wlan_cfg_init(wilc_debug)) {
                /* ENOBUFS      105 */
                ret = -105;
                goto _fail_;
        }
-       memcpy((void *)&g_wlan.cif_func, &mac_cfg, sizeof(wilc_cfg_func_t));
-
 
        /**
         *      alloc tx, rx buffer
         **/
-#if (defined WILC_PREALLOC_AT_BOOT)
-       extern void *get_tx_buffer(void);
-       extern void *get_rx_buffer(void);
-
-       PRINT_D(TX_DBG, "malloc before, g_wlan.tx_buffer = 0x%x, g_wlan.rx_buffer = 0x%x\n", g_wlan.tx_buffer, g_wlan.rx_buffer);
-#endif
-
-
-
        if (g_wlan.tx_buffer == NULL)
-#if (defined WILC_PREALLOC_AT_BOOT)
-               g_wlan.tx_buffer = (uint8_t *)get_tx_buffer();
-#else
-               g_wlan.tx_buffer = (uint8_t *)g_wlan.os_func.os_malloc(g_wlan.tx_buffer_size);
-#endif
+               g_wlan.tx_buffer = kmalloc(LINUX_TX_SIZE, GFP_KERNEL);
        PRINT_D(TX_DBG, "g_wlan.tx_buffer = %p\n", g_wlan.tx_buffer);
 
        if (g_wlan.tx_buffer == NULL) {
@@ -2203,11 +2004,7 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
 /* rx_buffer is not used unless we activate USE_MEM STATIC which is not applicable, allocating such memory is useless*/
 #if defined (MEMORY_STATIC)
        if (g_wlan.rx_buffer == NULL)
-  #if (defined WILC_PREALLOC_AT_BOOT)
-               g_wlan.rx_buffer = (uint8_t *)get_rx_buffer();
-  #else
-               g_wlan.rx_buffer = (uint8_t *)g_wlan.os_func.os_malloc(g_wlan.rx_buffer_size);
-  #endif
+               g_wlan.rx_buffer = kmalloc(LINUX_RX_SIZE, GFP_KERNEL);
        PRINT_D(TX_DBG, "g_wlan.rx_buffer =%p\n", g_wlan.rx_buffer);
        if (g_wlan.rx_buffer == NULL) {
                /* ENOBUFS      105 */
@@ -2217,30 +2014,6 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        }
 #endif
 
-       /**
-        *      export functions
-        **/
-       oup->wlan_firmware_download = wilc_wlan_firmware_download;
-       oup->wlan_start = wilc_wlan_start;
-       oup->wlan_stop = wilc_wlan_stop;
-       oup->wlan_add_to_tx_que = wilc_wlan_txq_add_net_pkt;
-       oup->wlan_handle_tx_que = wilc_wlan_handle_txq;
-       oup->wlan_handle_rx_que = wilc_wlan_handle_rxq;
-       oup->wlan_handle_rx_isr = wilc_handle_isr;
-       oup->wlan_cleanup = wilc_wlan_cleanup;
-       oup->wlan_cfg_set = wilc_wlan_cfg_set;
-       oup->wlan_cfg_get = wilc_wlan_cfg_get;
-       oup->wlan_cfg_get_value = wilc_wlan_cfg_get_val;
-
-       /*Bug3959: transmitting mgmt frames received from host*/
-       #if defined(WILC_AP_EXTERNAL_MLME) || defined(WILC_P2P)
-       oup->wlan_add_mgmt_to_tx_que = wilc_wlan_txq_add_mgmt_pkt;
-
-       #ifdef WILC_FULLY_HOSTING_AP
-       oup->wlan_add_data_to_tx_que = wilc_FH_wlan_txq_add_net_pkt;
-       #endif
-       #endif
-
        if (!init_chip()) {
                /* EIO  5 */
                ret = -5;
@@ -2250,72 +2023,48 @@ int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup)
        Init_TCP_tracking();
 #endif
 
-#if defined(PLAT_RK3026_TCHIP) /* AMR : 0422 RK3026 Crash issue */
-       if (!g_wilc_initialized)
-               custom_unlock_bus(g_mac_open);
-#endif
-
        return 1;
 
 _fail_:
 
-#if (defined WILC_PREALLOC_AT_BOOT)
-
-#else
   #ifdef MEMORY_STATIC
-       if (g_wlan.rx_buffer) {
-               g_wlan.os_func.os_free(g_wlan.rx_buffer);
-               g_wlan.rx_buffer = NULL;
-       }
+       kfree(g_wlan.rx_buffer);
+       g_wlan.rx_buffer = NULL;
   #endif
-       if (g_wlan.tx_buffer) {
-               g_wlan.os_func.os_free(g_wlan.tx_buffer);
-               g_wlan.tx_buffer = NULL;
-       }
-#endif
-
-#if defined(PLAT_RK3026_TCHIP) /* AMR : 0422 RK3026 Crash issue */
-       if (!g_wilc_initialized)
-               custom_unlock_bus(g_mac_open);
-#endif
+       kfree(g_wlan.tx_buffer);
+       g_wlan.tx_buffer = NULL;
 
        return ret;
 
 }
 
-#define BIT31 (1 << 31)
-u16 Set_machw_change_vir_if(bool bValue)
+u16 Set_machw_change_vir_if(struct net_device *dev, bool bValue)
 {
        u16 ret;
        u32 reg;
+       perInterface_wlan_t *nic;
+       struct wilc *wilc;
+
+       nic = netdev_priv(dev);
+       wilc = nic->wilc;
 
        /*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/
-       (&g_wlan)->os_func.os_enter_cs((&g_wlan)->hif_lock);
+       mutex_lock(&wilc->hif_cs);
        ret = (&g_wlan)->hif_func.hif_read_reg(WILC_CHANGING_VIR_IF, &reg);
-       if (!ret) {
+       if (!ret)
                PRINT_ER("Error while Reading reg WILC_CHANGING_VIR_IF\n");
-       }
 
        if (bValue)
-               reg |= (BIT31);
+               reg |= BIT(31);
        else
-               reg &= ~(BIT31);
+               reg &= ~BIT(31);
 
        ret = (&g_wlan)->hif_func.hif_write_reg(WILC_CHANGING_VIR_IF, reg);
 
-       if (!ret) {
+       if (!ret)
                PRINT_ER("Error while writing reg WILC_CHANGING_VIR_IF\n");
-       }
-       (&g_wlan)->os_func.os_leave_cs((&g_wlan)->hif_lock);
 
-       return ret;
-}
+       mutex_unlock(&wilc->hif_cs);
 
-#ifdef WILC_FULLY_HOSTING_AP
-wilc_wlan_dev_t *Get_wlan_context(u16 *pu16size)
-{
-       *pu16size = sizeof(wilc_wlan_dev_t);
-       return &g_wlan;
+       return ret;
 }
-#endif
-
index 244f7108ae92a153172864c77d8d30683ac1e1ca..57e1d51740502ea6f3c97d9331540c6ab30bd32e 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef WILC_WLAN_H
 #define WILC_WLAN_H
 
-#include "wilc_oswrapper.h"
 
 
 #define ISWILC1000(id)   (((id & 0xfffff000) == 0x100000) ? 1 : 0)
@@ -22,7 +21,6 @@
 #define ETH_ETHERNET_HDR_OFFSET   (MAX_MAC_HDR_LEN + SUB_MSDU_HEADER_LENGTH + \
                                   SNAP_HDR_LEN - ETHERNET_HDR_LEN + WORD_ALIGNMENT_PAD)
 
-/*Bug3959: transmitting mgmt frames received from host*/
 #define HOST_HDR_OFFSET                4
 #define ETHERNET_HDR_LEN          14
 #define IP_HDR_LEN                20
 
 #define ETH_CONFIG_PKT_HDR_OFFSET (ETH_ETHERNET_HDR_OFFSET + \
                                   ETH_CONFIG_PKT_HDR_LEN)
-#define   ACTION         0xD0
-#define   PROBE_REQ   0x40
-#ifdef WILC_FULLY_HOSTING_AP
-#define        FH_TX_HOST_HDR_OFFSET   24
-#endif
 
 /********************************************
  *
@@ -57,7 +50,6 @@
  *
  ********************************************/
 #define WILC_PERIPH_REG_BASE 0x1000
-/*BugID_5137*/
 #define WILC_CHANGING_VIR_IF                     (0x108c)
 #define WILC_CHIPID    (WILC_PERIPH_REG_BASE)
 #define WILC_GLB_RESET_0 (WILC_PERIPH_REG_BASE + 0x400)
 #define WILC_AHB_DATA_MEM_BASE 0x30000
 #define WILC_AHB_SHARE_MEM_BASE 0xd0000
 
-#define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE /* Bug 4477 fix */
-#define WILC_VMM_TBL_RX_SHADOW_SIZE (256) /* Bug 4477 fix */
+#define WILC_VMM_TBL_RX_SHADOW_BASE WILC_AHB_SHARE_MEM_BASE
+#define WILC_VMM_TBL_RX_SHADOW_SIZE (256)
 
 #define WILC_GP_REG_0   0x149c
 #define WILC_GP_REG_1   0x14a0
  ********************************************/
 #define WILC_CFG_PKT   1
 #define WILC_NET_PKT 0
-/*Bug3959: transmitting mgmt frames received from host*/
-#ifdef WILC_AP_EXTERNAL_MLME
 #define WILC_MGMT_PKT 2
 
-#ifdef WILC_FULLY_HOSTING_AP
-#define WILC_FH_DATA_PKT 4
-#endif
-
-#endif /*WILC_AP_EXTERNAL_MLME*/
 #define WILC_CFG_SET 1
 #define WILC_CFG_QUERY 0
 
 #endif
 
 
-#define ABORT_INT   (1 << 31)
+#define ABORT_INT   BIT(31)
 
 /*******************************************/
 /*        E0 and later Interrupt flags.    */
 /* 7: Select VMM table 2                   */
 /* 8: Enable VMM                           */
 /*******************************************/
-#define CLR_INT0             (1 << 0)
-#define CLR_INT1             (1 << 1)
-#define CLR_INT2             (1 << 2)
-#define CLR_INT3             (1 << 3)
-#define CLR_INT4             (1 << 4)
-#define CLR_INT5             (1 << 5)
-#define SEL_VMM_TBL0         (1 << 6)
-#define SEL_VMM_TBL1         (1 << 7)
-#define EN_VMM               (1 << 8)
+#define CLR_INT0             BIT(0)
+#define CLR_INT1             BIT(1)
+#define CLR_INT2             BIT(2)
+#define CLR_INT3             BIT(3)
+#define CLR_INT4             BIT(4)
+#define CLR_INT5             BIT(5)
+#define SEL_VMM_TBL0         BIT(6)
+#define SEL_VMM_TBL1         BIT(7)
+#define EN_VMM               BIT(8)
 
 #define DATA_INT_EXT   INT_0
 #define PLL_INT_EXT         INT_1
  *      Debug Type
  *
  ********************************************/
-typedef void (*wilc_debug_func)(uint32_t, char *, ...);
+typedef void (*wilc_debug_func)(u32, char *, ...);
 
 /********************************************
  *
@@ -247,7 +232,7 @@ struct txq_entry_t {
        struct txq_entry_t *prev;
        int type;
        int tcp_PendingAck_index;
-       uint8_t *buffer;
+       u8 *buffer;
        int buffer_size;
        void *priv;
        int status;
@@ -256,7 +241,7 @@ struct txq_entry_t {
 
 struct rxq_entry_t {
        struct rxq_entry_t *next;
-       uint8_t *buffer;
+       u8 *buffer;
        int buffer_size;
 };
 
@@ -269,17 +254,17 @@ struct rxq_entry_t {
 typedef struct {
        int (*hif_init)(wilc_wlan_inp_t *, wilc_debug_func);
        int (*hif_deinit)(void *);
-       int (*hif_read_reg)(uint32_t, uint32_t *);
-       int (*hif_write_reg)(uint32_t, uint32_t);
-       int (*hif_block_rx)(uint32_t, uint8_t *, uint32_t);
-       int (*hif_block_tx)(uint32_t, uint8_t *, uint32_t);
+       int (*hif_read_reg)(u32, u32 *);
+       int (*hif_write_reg)(u32, u32);
+       int (*hif_block_rx)(u32, u8 *, u32);
+       int (*hif_block_tx)(u32, u8 *, u32);
        int (*hif_sync)(void);
        int (*hif_clear_int)(void);
-       int (*hif_read_int)(uint32_t *);
-       int (*hif_clear_int_ext)(uint32_t);
-       int (*hif_read_size)(uint32_t *);
-       int (*hif_block_tx_ext)(uint32_t, uint8_t *, uint32_t);
-       int (*hif_block_rx_ext)(uint32_t, uint8_t *, uint32_t);
+       int (*hif_read_int)(u32 *);
+       int (*hif_clear_int_ext)(u32);
+       int (*hif_read_size)(u32 *);
+       int (*hif_block_tx_ext)(u32, u8 *, u32);
+       int (*hif_block_rx_ext)(u32, u8 *, u32);
        int (*hif_sync_ext)(int);
        void (*hif_set_max_bus_speed)(void);
        void (*hif_set_default_bus_speed)(void);
@@ -294,28 +279,34 @@ typedef struct {
 #define MAX_CFG_FRAME_SIZE 1468
 
 typedef struct {
-       uint8_t ether_header[14];
-       uint8_t ip_header[20];
-       uint8_t udp_header[8];
-       uint8_t wid_header[8];
-       uint8_t frame[MAX_CFG_FRAME_SIZE];
+       u8 ether_header[14];
+       u8 ip_header[20];
+       u8 udp_header[8];
+       u8 wid_header[8];
+       u8 frame[MAX_CFG_FRAME_SIZE];
 } wilc_cfg_frame_t;
 
 typedef struct {
-       int (*wlan_tx)(uint8_t *, uint32_t, wilc_tx_complete_func_t);
+       int (*wlan_tx)(u8 *, u32, wilc_tx_complete_func_t);
 } wilc_wlan_cfg_func_t;
 
 typedef struct {
        int type;
-       uint32_t seq_no;
+       u32 seq_no;
 } wilc_cfg_rsp_t;
 
-typedef struct {
-       int (*cfg_wid_set)(uint8_t *, uint32_t, uint16_t, uint8_t *, int);
-       int (*cfg_wid_get)(uint8_t *, uint32_t, uint16_t);
-       int (*cfg_wid_get_val)(uint16_t, uint8_t *, uint32_t);
-       int (*rx_indicate)(uint8_t *, int, wilc_cfg_rsp_t *);
-       int (*cfg_init)(wilc_debug_func);
-} wilc_cfg_func_t;
-
+int wilc_wlan_firmware_download(const u8 *buffer, u32 buffer_size);
+int wilc_wlan_start(void);
+int wilc_wlan_stop(void);
+int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
+                             u32 buffer_size, wilc_tx_complete_func_t func);
+int wilc_wlan_handle_txq(struct net_device *dev, u32 *pu32TxqCount);
+void wilc_handle_isr(void *wilc);
+void wilc_wlan_cleanup(struct net_device *dev);
+int wilc_wlan_cfg_set(int start, u32 wid, u8 *buffer, u32 buffer_size,
+                     int commit, u32 drvHandler);
+int wilc_wlan_cfg_get(int start, u32 wid, int commit, u32 drvHandler);
+int wilc_wlan_cfg_get_val(u32 wid, u8 *buffer, u32 buffer_size);
+int wilc_wlan_txq_add_mgmt_pkt(void *priv, u8 *buffer, u32 buffer_size,
+                              wilc_tx_complete_func_t func);
 #endif
index e2842d37b07826000ec1bbb773157ecd346af71d..a34a81cdeb5e1042d39ea28a3f058c2f1cc8a4c5 100644 (file)
@@ -7,16 +7,12 @@
 /*  */
 /* ///////////////////////////////////////////////////////////////////////// */
 
+#include <linux/string.h>
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
 #include "wilc_wlan_cfg.h"
 #include "coreconfigurator.h"
 
-#ifdef WILC_FULLY_HOSTING_AP
-#include "wilc_host_ap.h"
-void WILC_mgm_HOSTAPD_ACK(void *priv, bool bStatus);
-#endif
-
 /********************************************
  *
  *      Global Data
@@ -27,23 +23,23 @@ typedef struct {
        wilc_debug_func dPrint;
 
        int mac_status;
-       uint8_t mac_address[7];
-       uint8_t ip_address[5];
-       uint8_t bssid[7];
-       uint8_t ssid[34];
-       uint8_t firmware_version[129];
-       uint8_t supp_rate[24];
-       uint8_t wep_key[28];
-       uint8_t i_psk[66];
-       uint8_t hardwareProductVersion[33];
-       uint8_t phyversion[17];
-       uint8_t supp_username[21];
-       uint8_t supp_password[64];
-       uint8_t assoc_req[256];
-       uint8_t assoc_rsp[256];
-       uint8_t firmware_info[8];
-       uint8_t scan_result[256];
-       uint8_t scan_result1[256];
+       u8 mac_address[7];
+       u8 ip_address[5];
+       u8 bssid[7];
+       u8 ssid[34];
+       u8 firmware_version[129];
+       u8 supp_rate[24];
+       u8 wep_key[28];
+       u8 i_psk[66];
+       u8 hardwareProductVersion[33];
+       u8 phyversion[17];
+       u8 supp_username[21];
+       u8 supp_password[64];
+       u8 assoc_req[256];
+       u8 assoc_rsp[256];
+       u8 firmware_info[8];
+       u8 scan_result[256];
+       u8 scan_result1[256];
 } wilc_mac_cfg_t;
 
 static wilc_mac_cfg_t g_mac;
@@ -165,72 +161,72 @@ static wilc_cfg_str_t g_cfg_str[] = {
  *
  ********************************************/
 
-static int wilc_wlan_cfg_set_byte(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t val8)
+static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
 {
-       uint8_t *buf;
+       u8 *buf;
 
        if ((offset + 4) >= MAX_CFG_FRAME_SIZE)
                return 0;
 
        buf = &frame[offset];
 
-       buf[0] = (uint8_t)id;
-       buf[1] = (uint8_t)(id >> 8);
+       buf[0] = (u8)id;
+       buf[1] = (u8)(id >> 8);
        buf[2] = 1;
        buf[3] = val8;
        return 4;
 }
 
-static int wilc_wlan_cfg_set_hword(uint8_t *frame, uint32_t offset, uint16_t id, uint16_t val16)
+static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
 {
-       uint8_t *buf;
+       u8 *buf;
 
        if ((offset + 5) >= MAX_CFG_FRAME_SIZE)
                return 0;
 
        buf = &frame[offset];
 
-       buf[0] = (uint8_t)id;
-       buf[1] = (uint8_t)(id >> 8);
+       buf[0] = (u8)id;
+       buf[1] = (u8)(id >> 8);
        buf[2] = 2;
-       buf[3] = (uint8_t)val16;
-       buf[4] = (uint8_t)(val16 >> 8);
+       buf[3] = (u8)val16;
+       buf[4] = (u8)(val16 >> 8);
 
        return 5;
 }
 
-static int wilc_wlan_cfg_set_word(uint8_t *frame, uint32_t offset, uint16_t id, uint32_t val32)
+static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
 {
-       uint8_t *buf;
+       u8 *buf;
 
        if ((offset + 7) >= MAX_CFG_FRAME_SIZE)
                return 0;
 
        buf = &frame[offset];
 
-       buf[0] = (uint8_t)id;
-       buf[1] = (uint8_t)(id >> 8);
+       buf[0] = (u8)id;
+       buf[1] = (u8)(id >> 8);
        buf[2] = 4;
-       buf[3] = (uint8_t)val32;
-       buf[4] = (uint8_t)(val32 >> 8);
-       buf[5] = (uint8_t)(val32 >> 16);
-       buf[6] = (uint8_t)(val32 >> 24);
+       buf[3] = (u8)val32;
+       buf[4] = (u8)(val32 >> 8);
+       buf[5] = (u8)(val32 >> 16);
+       buf[6] = (u8)(val32 >> 24);
 
        return 7;
 }
 
-static int wilc_wlan_cfg_set_str(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *str, uint32_t size)
+static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str, u32 size)
 {
-       uint8_t *buf;
+       u8 *buf;
 
        if ((offset + size + 3) >= MAX_CFG_FRAME_SIZE)
                return 0;
 
        buf = &frame[offset];
 
-       buf[0] = (uint8_t)id;
-       buf[1] = (uint8_t)(id >> 8);
-       buf[2] = (uint8_t)size;
+       buf[0] = (u8)id;
+       buf[1] = (u8)(id >> 8);
+       buf[2] = (u8)size;
 
        if ((str != NULL) && (size != 0))
                memcpy(&buf[3], str, size);
@@ -238,20 +234,20 @@ static int wilc_wlan_cfg_set_str(uint8_t *frame, uint32_t offset, uint16_t id, u
        return (size + 3);
 }
 
-static int wilc_wlan_cfg_set_bin(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *b, uint32_t size)
+static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
 {
-       uint8_t *buf;
-       uint32_t i;
-       uint8_t checksum = 0;
+       u8 *buf;
+       u32 i;
+       u8 checksum = 0;
 
        if ((offset + size + 5) >= MAX_CFG_FRAME_SIZE)
                return 0;
 
        buf = &frame[offset];
-       buf[0] = (uint8_t)id;
-       buf[1] = (uint8_t)(id >> 8);
-       buf[2] = (uint8_t)size;
-       buf[3] = (uint8_t)(size >> 8);
+       buf[0] = (u8)id;
+       buf[1] = (u8)(id >> 8);
+       buf[2] = (u8)size;
+       buf[3] = (u8)(size >> 8);
 
        if ((b != NULL) && (size != 0)) {
                memcpy(&buf[4], b, size);
@@ -271,9 +267,9 @@ static int wilc_wlan_cfg_set_bin(uint8_t *frame, uint32_t offset, uint16_t id, u
  *
  ********************************************/
 
-static void wilc_wlan_parse_response_frame(uint8_t *info, int size)
+static void wilc_wlan_parse_response_frame(u8 *info, int size)
 {
-       uint32_t wid, len = 0, i = 0;
+       u32 wid, len = 0, i = 0;
        static int seq;
 
        while (size > 0) {
@@ -342,6 +338,7 @@ static void wilc_wlan_parse_response_frame(uint8_t *info, int size)
                                if (g_cfg_str[i].id == wid) {
                                        if (wid == WID_SITE_SURVEY_RESULTS) {
                                                static int toggle;
+
                                                PRINT_INFO(GENERIC_DBG, "Site survey results received[%d]\n",
                                                           size);
 
@@ -365,10 +362,10 @@ static void wilc_wlan_parse_response_frame(uint8_t *info, int size)
        }
 }
 
-static int wilc_wlan_parse_info_frame(uint8_t *info, int size)
+static int wilc_wlan_parse_info_frame(u8 *info, int size)
 {
-       wilc_mac_cfg_t *pd = (wilc_mac_cfg_t *)&g_mac;
-       uint32_t wid, len;
+       wilc_mac_cfg_t *pd = &g_mac;
+       u32 wid, len;
        int type = WILC_CFG_RSP_STATUS;
 
        wid = info[0] | (info[1] << 8);
@@ -389,9 +386,9 @@ static int wilc_wlan_parse_info_frame(uint8_t *info, int size)
  *
  ********************************************/
 
-static int wilc_wlan_cfg_set_wid(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *buf, int size)
+int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
 {
-       uint8_t type = (id >> 12) & 0xf;
+       u8 type = (id >> 12) & 0xf;
        int ret = 0;
 
        if (type == 0) {                                        /* byte command */
@@ -399,10 +396,10 @@ static int wilc_wlan_cfg_set_wid(uint8_t *frame, uint32_t offset, uint16_t id, u
                        ret = wilc_wlan_cfg_set_byte(frame, offset, id, *buf);
        } else if (type == 1) {                 /* half word command */
                if (size >= 2)
-                       ret = wilc_wlan_cfg_set_hword(frame, offset, id, *((uint16_t *)buf));
+                       ret = wilc_wlan_cfg_set_hword(frame, offset, id, *((u16 *)buf));
        } else if (type == 2) {                 /* word command */
                if (size >= 4)
-                       ret = wilc_wlan_cfg_set_word(frame, offset, id, *((uint32_t *)buf));
+                       ret = wilc_wlan_cfg_set_word(frame, offset, id, *((u32 *)buf));
        } else if (type == 3) {                 /* string command */
                ret = wilc_wlan_cfg_set_str(frame, offset, id, buf, size);
        } else if (type == 4) {                 /* binary command */
@@ -414,28 +411,28 @@ static int wilc_wlan_cfg_set_wid(uint8_t *frame, uint32_t offset, uint16_t id, u
        return ret;
 }
 
-static int wilc_wlan_cfg_get_wid(uint8_t *frame, uint32_t offset, uint16_t id)
+int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
 {
-       uint8_t *buf;
+       u8 *buf;
 
        if ((offset + 2) >= MAX_CFG_FRAME_SIZE)
                return 0;
 
        buf = &frame[offset];
 
-       buf[0] = (uint8_t)id;
-       buf[1] = (uint8_t)(id >> 8);
+       buf[0] = (u8)id;
+       buf[1] = (u8)(id >> 8);
 
        return 2;
 }
 
-static int wilc_wlan_cfg_get_wid_value(uint16_t wid, uint8_t *buffer, uint32_t buffer_size)
+int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
 {
-       uint32_t type = (wid >> 12) & 0xf;
+       u32 type = (wid >> 12) & 0xf;
        int i, ret = 0;
 
        if (wid == WID_STATUS) {
-               *((uint32_t *)buffer) = g_mac.mac_status;
+               *((u32 *)buffer) = g_mac.mac_status;
                return 4;
        }
 
@@ -482,10 +479,12 @@ static int wilc_wlan_cfg_get_wid_value(uint16_t wid, uint8_t *buffer, uint32_t b
                                break;
 
                        if (g_cfg_str[i].id == wid) {
-                               uint32_t size =  g_cfg_str[i].str[0];
+                               u32 size =  g_cfg_str[i].str[0];
+
                                if (buffer_size >= size) {
                                        if (g_cfg_str[i].id == WID_SITE_SURVEY_RESULTS) {
                                                static int toggle;
+
                                                PRINT_INFO(GENERIC_DBG, "Site survey results value[%d]\n",
                                                           size);
                                                i += toggle;
@@ -506,22 +505,11 @@ static int wilc_wlan_cfg_get_wid_value(uint16_t wid, uint8_t *buffer, uint32_t b
        return ret;
 }
 
-static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *rsp)
+int wilc_wlan_cfg_indicate_rx(u8 *frame, int size, wilc_cfg_rsp_t *rsp)
 {
        int ret = 1;
-       uint8_t msg_type;
-       uint8_t msg_id;
-       #ifdef WILC_FULLY_HOSTING_AP
-       u32 *ptru32Frame;
-       bool bStatus = frame[2];
-
-       #ifdef BIG_ENDIAN
-       ptru32Frame = (frame[4] << 24) | (frame[5] << 16) | (frame[6] << 8) | frame[7];
-       #else
-       ptru32Frame = (frame[7] << 24) | (frame[6] << 16) | (frame[5] << 8) | frame[4];
-       #endif  /* BIG_ENDIAN */
-
-       #endif  /* WILC_FULLY_HOSTING_AP */
+       u8 msg_type;
+       u8 msg_id;
 
        msg_type = frame[0];
        msg_id = frame[1];      /* seq no */
@@ -547,39 +535,16 @@ static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *r
                GnrlAsyncInfoReceived(frame - 4, size + 4);
                break;
 
-       case 'L':
-#ifndef SWITCH_LOG_TERMINAL
-               PRINT_ER("Unexpected firmware log message received\n");
-#else
-               PRINT_D(FIRM_DBG, "\nFIRMWARE LOGS :\n<<\n%s\n>>\n", frame);
-               break;
-
-#endif
-#if 1
        case 'N':
                NetworkInfoReceived(frame - 4, size + 4);
                rsp->type = 0;
                break;
 
-#endif
-/*bug3819:*/
        case 'S':
                PRINT_INFO(RX_DBG, "Scan Notification Received\n");
                host_int_ScanCompleteReceived(frame - 4, size + 4);
                break;
 
-#ifdef WILC_FULLY_HOSTING_AP
-       case 'T':
-               PRINT_INFO(RX_DBG, "TBTT Notification Received\n");
-               process_tbtt_isr();
-               break;
-
-       case 'A':
-               PRINT_INFO(RX_DBG, "HOSTAPD ACK Notification Received\n");
-               WILC_mgm_HOSTAPD_ACK(ptru32Frame, bStatus);
-               break;
-#endif
-
        default:
                PRINT_INFO(RX_DBG, "Receive unknown message type[%d-%d-%d-%d-%d-%d-%d-%d]\n",
                           frame[0], frame[1], frame[2], frame[3], frame[4],
@@ -593,17 +558,9 @@ static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *r
        return ret;
 }
 
-static int wilc_wlan_cfg_init(wilc_debug_func func)
+int wilc_wlan_cfg_init(wilc_debug_func func)
 {
        memset((void *)&g_mac, 0, sizeof(wilc_mac_cfg_t));
        g_mac.dPrint = func;
        return 1;
 }
-
-wilc_cfg_func_t mac_cfg = {
-       wilc_wlan_cfg_set_wid,
-       wilc_wlan_cfg_get_wid,
-       wilc_wlan_cfg_get_wid_value,
-       wilc_wlan_cfg_indicate_rx,
-       wilc_wlan_cfg_init,
-};
index 8906611b29304c2454c1783ee4d2a61c15b9b8cf..30e60ec4d29f7d56f8163a20dc28feb858470dc5 100644 (file)
 #define WILC_WLAN_CFG_H
 
 typedef struct {
-       uint16_t id;
-       uint16_t val;
+       u16 id;
+       u16 val;
 } wilc_cfg_byte_t;
 
 typedef struct {
-       uint16_t id;
-       uint16_t val;
+       u16 id;
+       u16 val;
 } wilc_cfg_hword_t;
 
 typedef struct {
-       uint32_t id;
-       uint32_t val;
+       u32 id;
+       u32 val;
 } wilc_cfg_word_t;
 
 typedef struct {
-       uint32_t id;
-       uint8_t *str;
+       u32 id;
+       u8 *str;
 } wilc_cfg_str_t;
 
+int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size);
+int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id);
+int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size);
+int wilc_wlan_cfg_indicate_rx(u8 *frame, int size, wilc_cfg_rsp_t *rsp);
+int wilc_wlan_cfg_init(wilc_debug_func func);
+
 #endif
index 5cf74e4c4a708c40b947049a76a4f3b3b4143522..be972afe6e620f0f32df1c65048cc40d59c0cedc 100644 (file)
@@ -1,4 +1,4 @@
-/* ////////////////////////////////////////////////////////////////////////// */
+/* ///////////////////////////////////////////////////////////////////////// */
 /*  */
 /* Copyright (c) Atmel Corporation.  All rights reserved. */
 /*  */
@@ -7,34 +7,23 @@
 /*  */
 /* ///////////////////////////////////////////////////////////////////////// */
 
-
 #ifndef WILC_WLAN_IF_H
 #define WILC_WLAN_IF_H
 
-/*bug 3887: [AP] Allow Management frames to be passed to the host*/
-#define WILC_AP_EXTERNAL_MLME
-#define WILC_P2P
-#define TCP_ENHANCEMENTS
-/* #define MEMORY_STATIC */
-/* #define WILC_FULLY_HOSTING_AP */
-/* #define USE_OLD_SPI_SW */
-
-
-#include "wilc_oswrapper.h"
+#include <linux/semaphore.h>
 #include "linux_wlan_common.h"
 
-
 /********************************************
  *
  *      Debug Flags
  *
  ********************************************/
 
-#define N_INIT         0x00000001
-#define N_ERR          0x00000002
-#define N_TXQ          0x00000004
-#define N_INTR         0x00000008
-#define N_RXQ          0x00000010
+#define N_INIT                 0x00000001
+#define N_ERR                  0x00000002
+#define N_TXQ                  0x00000004
+#define N_INTR                 0x00000008
+#define N_RXQ                  0x00000010
 
 /********************************************
  *
  *
  ********************************************/
 
-#define HIF_SDIO           (0)
-#define HIF_SPI            BIT(0)
-#define HIF_SDIO_GPIO_IRQ  BIT(2)
-
+#define HIF_SDIO               (0)
+#define HIF_SPI                        BIT(0)
+#define HIF_SDIO_GPIO_IRQ      BIT(2)
 
 /********************************************
  *
@@ -53,8 +41,8 @@
  *
  ********************************************/
 
-#define CE_TX_BUFFER_SIZE (64 * 1024)
-#define CE_RX_BUFFER_SIZE (384 * 1024)
+#define CE_TX_BUFFER_SIZE      (64 * 1024)
+#define CE_RX_BUFFER_SIZE      (384 * 1024)
 
 /********************************************
  *
  ********************************************/
 
 typedef struct {
-       uint32_t read_write: 1;
-       uint32_t function: 3;
-       uint32_t raw: 1;
-       uint32_t address: 17;
-       uint32_t data: 8;
+       u32 read_write:         1;
+       u32 function:           3;
+       u32 raw:                1;
+       u32 address:            17;
+       u32 data:               8;
 } sdio_cmd52_t;
 
 typedef struct {
        /* struct { */
-       uint32_t read_write: 1;
-       uint32_t function: 3;
-       uint32_t block_mode: 1;
-       uint32_t increment: 1;
-       uint32_t address: 17;
-       uint32_t count: 9;
+       u32 read_write:         1;
+       u32 function:           3;
+       u32 block_mode:         1;
+       u32 increment:          1;
+       u32 address:            17;
+       u32 count:              9;
        /* } bit; */
-       uint8_t *buffer;
-       uint32_t block_size;
+       u8 *buffer;
+       u32 block_size;
 } sdio_cmd53_t;
 
-typedef struct {
-       void (*os_sleep)(uint32_t);
-       void (*os_atomic_sleep)(uint32_t);
-       void (*os_debug)(uint8_t *);
-       void *(*os_malloc)(uint32_t);
-       void *(*os_malloc_atomic)(uint32_t);
-       void (*os_free)(void *);
-       void (*os_lock)(void *);
-       void (*os_unlock)(void *);
-       int (*os_wait)(void *, u32);
-       void (*os_signal)(void *);
-       void (*os_enter_cs)(void *);
-       void (*os_leave_cs)(void *);
-
-       /*Added by Amr - BugID_4720*/
-       void (*os_spin_lock)(void *, unsigned long *);
-       void (*os_spin_unlock)(void *, unsigned long *);
-
-} wilc_wlan_os_func_t;
-
 typedef struct {
        int io_type;
        int (*io_init)(void *);
@@ -116,96 +84,39 @@ typedef struct {
                } sdio;
                struct {
                        int (*spi_max_speed)(void);
-                       int (*spi_tx)(uint8_t *, uint32_t);
-                       int (*spi_rx)(uint8_t *, uint32_t);
-                       int (*spi_trx)(uint8_t *, uint8_t *, uint32_t);
+                       int (*spi_tx)(u8 *, u32);
+                       int (*spi_rx)(u8 *, u32);
+                       int (*spi_trx)(u8 *, u8 *, u32);
                } spi;
        } u;
 } wilc_wlan_io_func_t;
 
-typedef struct {
-       void (*rx_indicate)(uint8_t *, uint32_t, uint32_t);
-       void (*rx_complete)(void);
-} wilc_wlan_net_func_t;
-
-typedef struct {
-       void (*mac_indicate)(int);
-} wilc_wlan_indicate_func_t;
-#define WILC_MAC_INDICATE_STATUS               0x1
-#define WILC_MAC_STATUS_INIT   -1
-#define WILC_MAC_STATUS_READY 0
-#define WILC_MAC_STATUS_CONNECT 1
+#define WILC_MAC_INDICATE_STATUS       0x1
+#define WILC_MAC_STATUS_INIT           -1
+#define WILC_MAC_STATUS_READY          0
+#define WILC_MAC_STATUS_CONNECT                1
 
 #define WILC_MAC_INDICATE_SCAN         0x2
 
 typedef struct {
        void *os_private;
-
-       void *hif_critical_section;
-
-       uint32_t tx_buffer_size;
-       void *txq_critical_section;
-
-       /*Added by Amr - BugID_4720*/
-       void *txq_add_to_head_critical_section;
-       void *txq_spin_lock;
-
-       void *txq_wait_event;
-
-#if defined(MEMORY_STATIC)
-       uint32_t rx_buffer_size;
-#endif
-       void *rxq_critical_section;
-       void *rxq_wait_event;
-
-       void *cfg_wait_event;
 } wilc_wlan_os_context_t;
 
 typedef struct {
        wilc_wlan_os_context_t os_context;
-       wilc_wlan_os_func_t os_func;
        wilc_wlan_io_func_t io_func;
-       wilc_wlan_net_func_t net_func;
-       wilc_wlan_indicate_func_t indicate_func;
 } wilc_wlan_inp_t;
 
 struct tx_complete_data {
-       #ifdef WILC_FULLY_HOSTING_AP
-       struct tx_complete_data *next;
-       #endif
        int size;
        void *buff;
-       uint8_t *pBssid;
+       u8 *pBssid;
        struct sk_buff *skb;
 };
 
-
 typedef void (*wilc_tx_complete_func_t)(void *, int);
 
-#define WILC_TX_ERR_NO_BUF (-2)
-
-typedef struct {
-       int (*wlan_firmware_download)(const uint8_t *, uint32_t);
-       int (*wlan_start)(void);
-       int (*wlan_stop)(void);
-       int (*wlan_add_to_tx_que)(void *, uint8_t *, uint32_t, wilc_tx_complete_func_t);
-       int (*wlan_handle_tx_que)(uint32_t *);
-       void (*wlan_handle_rx_que)(void);
-       void (*wlan_handle_rx_isr)(void);
-       void (*wlan_cleanup)(void);
-       int (*wlan_cfg_set)(int, uint32_t, uint8_t *, uint32_t, int, uint32_t);
-       int (*wlan_cfg_get)(int, uint32_t, int, uint32_t);
-       int (*wlan_cfg_get_value)(uint32_t, uint8_t *, uint32_t);
-       /*Bug3959: transmitting mgmt frames received from host*/
-       #if defined(WILC_AP_EXTERNAL_MLME) || defined(WILC_P2P)
-       int (*wlan_add_mgmt_to_tx_que)(void *, uint8_t *, uint32_t, wilc_tx_complete_func_t);
-
-       #ifdef WILC_FULLY_HOSTING_AP
-       int (*wlan_add_data_to_tx_que)(void *, uint8_t *, uint32_t, wilc_tx_complete_func_t);
-       #endif
-
-       #endif
-} wilc_wlan_oup_t;
+#define WILC_TX_ERR_NO_BUF     (-2)
 
 /********************************************
  *
@@ -216,156 +127,152 @@ typedef struct {
 #define MAX_SSID_LEN            33
 #define MAX_RATES_SUPPORTED     12
 
-#define INFINITE_SLEEP_TIME            ((u32)0xFFFFFFFF)
+#define INFINITE_SLEEP_TIME    ((u32)0xFFFFFFFF)
 
-#ifdef WILC_PARSE_SCAN_IN_HOST
 typedef enum {
-       SUPP_RATES_IE = 1,
-       EXT_SUPP_RATES_IE = 50,
-       HT_CAPABILITY_IE = 45,
-       RSN_IE = 48,
-       WPA_IE = 221,
-       WMM_IE = 221,
-       #ifdef WILC_P2P
-       P2P_IE = 221,
-       #endif
+       SUPP_RATES_IE           = 1,
+       EXT_SUPP_RATES_IE       = 50,
+       HT_CAPABILITY_IE        = 45,
+       RSN_IE                  = 48,
+       WPA_IE                  = 221,
+       WMM_IE                  = 221,
+       P2P_IE                  = 221,
 } BEACON_IE;
-#endif
+
 typedef enum {
-       INFRASTRUCTURE = 0,
+       INFRASTRUCTURE          = 0,
        INDEPENDENT,
        AP,
 } BSSTYPE_T;
 
 typedef enum {
-       RATE_AUTO = 0,
-       RATE_1MB = 1,
-       RATE_2MB = 2,
-       RATE_5MB = 5,
-       RATE_6MB = 6,
-       RATE_9MB = 9,
-       RATE_11MB = 11,
-       RATE_12MB = 12,
-       RATE_18MB = 18,
-       RATE_24MB = 24,
-       RATE_26MB = 36,
-       RATE_48MB = 48,
-       RATE_54MB = 54
+       RATE_AUTO               = 0,
+       RATE_1MB                = 1,
+       RATE_2MB                = 2,
+       RATE_5MB                = 5,
+       RATE_6MB                = 6,
+       RATE_9MB                = 9,
+       RATE_11MB               = 11,
+       RATE_12MB               = 12,
+       RATE_18MB               = 18,
+       RATE_24MB               = 24,
+       RATE_26MB               = 36,
+       RATE_48MB               = 48,
+       RATE_54MB               = 54
 } TX_RATE_T;
 
 typedef enum {
-       B_ONLY_MODE = 0,                                /* basic rate: 1, 2 Mbps, otherwise: 5, 11 Mbps */
-       G_ONLY_MODE,                                    /* basic rate: 6, 12, 24 Mbps, otherwise: 9, 18, 36, 48, 54 Mbps */
-       G_MIXED_11B_1_MODE,             /* basic rate: 1, 2, 5.5, 11 Mbps, otherwise: all on */
-       G_MIXED_11B_2_MODE,             /* basic rate: 1, 2, 5, 11, 6, 12, 24 Mbps, otherwise: all on */
+       B_ONLY_MODE             = 0,    /* 1, 2 M, otherwise 5, 11 M */
+       G_ONLY_MODE,                    /* 6,12,24 otherwise 9,18,36,48,54 */
+       G_MIXED_11B_1_MODE,             /* 1,2,5.5,11 otherwise all on */
+       G_MIXED_11B_2_MODE,             /* 1,2,5,11,6,12,24 otherwise all on */
 } G_OPERATING_MODE_T;
 
 typedef enum {
-       G_SHORT_PREAMBLE = 0,   /* Short Preamble          */
-       G_LONG_PREAMBLE  = 1,           /* Long Preamble           */
-       G_AUTO_PREAMBLE  = 2,           /* Auto Preamble Selection */
+       G_SHORT_PREAMBLE        = 0,    /* Short Preamble */
+       G_LONG_PREAMBLE         = 1,    /* Long Preamble */
+       G_AUTO_PREAMBLE         = 2,    /* Auto Preamble Selection */
 } G_PREAMBLE_T;
 
-#define MAC_CONNECTED    1
-#define MAC_DISCONNECTED 0
+#define MAC_CONNECTED          1
+#define MAC_DISCONNECTED       0
 
-/*bug3819: */
 #define SCAN_DONE              TRUE
 typedef enum {
-       PASSIVE_SCAN = 0,
-       ACTIVE_SCAN  = 1,
+       PASSIVE_SCAN            = 0,
+       ACTIVE_SCAN             = 1,
 } SCANTYPE_T;
 
 typedef enum {
-       NO_POWERSAVE     = 0,
-       MIN_FAST_PS      = 1,
-       MAX_FAST_PS      = 2,
-       MIN_PSPOLL_PS    = 3,
-       MAX_PSPOLL_PS    = 4
+       NO_POWERSAVE            = 0,
+       MIN_FAST_PS             = 1,
+       MAX_FAST_PS             = 2,
+       MIN_PSPOLL_PS           = 3,
+       MAX_PSPOLL_PS           = 4
 } USER_PS_MODE_T;
 
 typedef enum {
-       CHIP_WAKEDUP                    = 0,
+       CHIP_WAKEDUP            = 0,
        CHIP_SLEEPING_AUTO      = 1,
-       CHIP_SLEEPING_MANUAL  = 2
+       CHIP_SLEEPING_MANUAL    = 2
 } CHIP_PS_STATE_T;
 
 typedef enum {
-       ACQUIRE_ONLY                             = 0,
+       ACQUIRE_ONLY            = 0,
        ACQUIRE_AND_WAKEUP      = 1,
 } BUS_ACQUIRE_T;
 
 typedef enum {
-       RELEASE_ONLY                            = 0,
-       RELEASE_ALLOW_SLEEP             = 1,
+       RELEASE_ONLY            = 0,
+       RELEASE_ALLOW_SLEEP     = 1,
 } BUS_RELEASE_T;
 
 typedef enum {
-       NO_SECURITY = 0,
-       WEP_40 = 0x3,
-       WEP_104 = 0x7,
-       WPA_AES = 0x29,
-       WPA_TKIP = 0x49,
-       WPA_AES_TKIP = 0x69,            /* Aes or Tkip */
-       WPA2_AES = 0x31,
-       WPA2_TKIP = 0x51,
-       WPA2_AES_TKIP = 0x71,   /* Aes or Tkip */
+       NO_SECURITY             = 0,
+       WEP_40                  = 0x3,
+       WEP_104                 = 0x7,
+       WPA_AES                 = 0x29,
+       WPA_TKIP                = 0x49,
+       WPA_AES_TKIP            = 0x69, /* Aes or Tkip */
+       WPA2_AES                = 0x31,
+       WPA2_TKIP               = 0x51,
+       WPA2_AES_TKIP           = 0x71, /* Aes or Tkip */
 } SECURITY_T;
 
-typedef enum {
-       OPEN_SYSTEM     = 1,
-       SHARED_KEY      = 2,
-       ANY                             = 3,
-       IEEE8021 = 5
-} AUTHTYPE_T;
+enum AUTHTYPE {
+       OPEN_SYSTEM             = 1,
+       SHARED_KEY              = 2,
+       ANY                     = 3,
+       IEEE8021                = 5
+};
 
-typedef enum {
-       SITE_SURVEY_1CH    = 0,
-       SITE_SURVEY_ALL_CH = 1,
-       SITE_SURVEY_OFF    = 2
-} SITE_SURVEY_T;
+enum SITESURVEY {
+       SITE_SURVEY_1CH         = 0,
+       SITE_SURVEY_ALL_CH      = 1,
+       SITE_SURVEY_OFF         = 2
+};
 
 typedef enum {
-       NORMAL_ACK = 0,
+       NORMAL_ACK              = 0,
        NO_ACK,
 } ACK_POLICY_T;
 
 typedef enum {
-       DONT_RESET = 0,
-       DO_RESET   = 1,
-       NO_REQUEST = 2,
+       DONT_RESET              = 0,
+       DO_RESET                = 1,
+       NO_REQUEST              = 2,
 } RESET_REQ_T;
 
 typedef enum {
-       REKEY_DISABLE = 1,
+       REKEY_DISABLE           = 1,
        REKEY_TIME_BASE,
        REKEY_PKT_BASE,
        REKEY_TIME_PKT_BASE
 } RSNA_REKEY_POLICY_T;
 
 typedef enum {
-       FILTER_NO       = 0x00,
-       FILTER_AP_ONLY  = 0x01,
-       FILTER_STA_ONLY = 0x02
+       FILTER_NO               = 0x00,
+       FILTER_AP_ONLY          = 0x01,
+       FILTER_STA_ONLY         = 0x02
 } SCAN_CLASS_FITLER_T;
 
 typedef enum {
-       PRI_HIGH_RSSI    = 0x00,
-       PRI_LOW_RSSI     = 0x04,
-       PRI_DETECT       = 0x08
+       PRI_HIGH_RSSI           = 0x00,
+       PRI_LOW_RSSI            = 0x04,
+       PRI_DETECT              = 0x08
 } SCAN_PRI_T;
 
 typedef enum {
-       CH_FILTER_OFF    = 0x00,
-       CH_FILTER_ON     = 0x10
+       CH_FILTER_OFF           = 0x00,
+       CH_FILTER_ON            = 0x10
 } CH_FILTER_T;
 
 typedef enum {
-       AUTO_PROT = 0,  /* Auto */
-       NO_PROT,                        /* Do not use any protection       */
-       ERP_PROT,                       /* Protect all ERP frame exchanges */
-       HT_PROT,                        /* Protect all HT frame exchanges  */
-       GF_PROT,                        /* Protect all GF frame exchanges  */
+       AUTO_PROT               = 0,    /* Auto */
+       NO_PROT,                        /* Do not use any protection */
+       ERP_PROT,                       /* Protect all ERP frame exchanges */
+       HT_PROT,                        /* Protect all HT frame exchanges  */
+       GF_PROT,                        /* Protect all GF frame exchanges  */
 } N_PROTECTION_MODE_T;
 
 typedef enum {
@@ -374,29 +281,29 @@ typedef enum {
 } G_PROTECTION_MODE_T;
 
 typedef enum {
-       HT_MIXED_MODE = 1,
+       HT_MIXED_MODE           = 1,
        HT_ONLY_20MHZ_MODE,
        HT_ONLY_20_40MHZ_MODE,
 } N_OPERATING_MODE_T;
 
 typedef enum {
-       NO_DETECT             = 0,
-       DETECT_ONLY           = 1,
-       DETECT_PROTECT        = 2,
-       DETECT_PROTECT_REPORT = 3,
+       NO_DETECT               = 0,
+       DETECT_ONLY             = 1,
+       DETECT_PROTECT          = 2,
+       DETECT_PROTECT_REPORT   = 3,
 } N_OBSS_DETECTION_T;
 
 typedef enum {
-       RTS_CTS_NONHT_PROT = 0,                 /* RTS-CTS at non-HT rate      */
-       FIRST_FRAME_NONHT_PROT,         /* First frame at non-HT rate  */
-       LSIG_TXOP_PROT,                                 /* LSIG TXOP Protection        */
-       FIRST_FRAME_MIXED_PROT,         /* First frame at Mixed format */
+       RTS_CTS_NONHT_PROT      = 0,    /* RTS-CTS at non-HT rate */
+       FIRST_FRAME_NONHT_PROT,         /* First frame at non-HT rate */
+       LSIG_TXOP_PROT,                 /* LSIG TXOP Protection */
+       FIRST_FRAME_MIXED_PROT,         /* First frame at Mixed format */
 } N_PROTECTION_TYPE_T;
 
 typedef enum {
-       STATIC_MODE   = 1,
-       DYNAMIC_MODE  = 2,
-       MIMO_MODE     = 3,              /* power save disable */
+       STATIC_MODE             = 1,
+       DYNAMIC_MODE            = 2,
+       MIMO_MODE               = 3,    /* power save disable */
 } N_SMPS_MODE_T;
 
 typedef enum {
@@ -408,562 +315,632 @@ typedef enum {
        SW_TRIGGER_ABORT,
 } TX_ABORT_OPTION_T;
 
-typedef enum {
-       WID_CHAR     = 0,
-       WID_SHORT    = 1,
-       WID_INT      = 2,
-       WID_STR      = 3,
-       WID_BIN_DATA = 4,
-       WID_BIN   = 5,
-       WID_IP    = 6,
-       WID_ADR   = 7,
-       WID_UNDEF = 8,
-       WID_TYPE_FORCE_32BIT  = 0xFFFFFFFF
-
-} WID_TYPE_T, tenuWIDtype;
+enum WID_TYPE {
+       WID_CHAR                = 0,
+       WID_SHORT               = 1,
+       WID_INT                 = 2,
+       WID_STR                 = 3,
+       WID_BIN_DATA            = 4,
+       WID_BIN                 = 5,
+       WID_IP                  = 6,
+       WID_ADR                 = 7,
+       WID_UNDEF               = 8,
+       WID_TYPE_FORCE_32BIT    = 0xFFFFFFFF
+};
 
 typedef enum {
-       WID_NIL                            = 0xffff,
-
-
-       /*  BSS Type                                                                                                                                                                            */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :  Infrastructure    Independent   Access Point                                                                               */
-       /*  Values to set :         0               1            2                                                                                                                      */
-       /*  --------------------------------------------------------------      */
-       WID_BSS_TYPE                                            = 0x0000,
-
-       /*  Transmit Rate                                                                                                                                                                       */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :  1  2  5.5  11  6  9  12  18  24  36  48  54                                                                                */
-       /*  Values to set :  1  2  5  11  6  9  12  18  24  36  48  54                                                                                  */
-       /*  --------------------------------------------------------------      */
-       WID_CURRENT_TX_RATE                     = 0x0001,
-
-       /*  Channel                                                                                                                                                                                                     */
-       /*  -------------------------------------------------------------------         */
-       /*  Configuration(g) :  1  2  3  4  5  6  7  8   9   10  11  12  13  14                                                                                         */
-       /*  Values to set    :  1  2  3  4  5  6  7  8   9   10  11  12  13  14                                                                                         */
-       /*  --------------------------------------------------------------------        */
-       WID_CURRENT_CHANNEL                     = 0x0002,
-
-       /*  Preamble                                                                                                                                                                            */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :    short    long   Auto                                                                                                                             */
-       /*  Values to set :       0         1         2                                                                                                                                 */
-       /*  --------------------------------------------------------------      */
-       WID_PREAMBLE                                            = 0x0003,
-
-       /*  11g operating mode (ignored if 11g not present)                                                                                                     */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :   HighPerf  Compat(RSet #1) Compat(RSet #2)                                                                 */
-       /*  Values to set :          1               2               3                                                                                                                  */
-       /*  --------------------------------------------------------------      */
-       WID_11G_OPERATING_MODE            = 0x0004,
-
-       /*  Mac status (response only)                                                                                                                                                                  */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :   disconnect  connect                                                                                                                                               */
-       /*  Values to get :          0               1                                                                                                                                          */
-       /*  --------------------------------------------------------------      */
-       WID_STATUS                                              = 0x0005,
-
-       /*  Scan type                                                                                                                                                                           */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :   Passive Scanning   Active Scanning                                                                                        */
-       /*  Values to set :                  0                 1                                                                                                                                */
-       /*  --------------------------------------------------------------      */
-       WID_SCAN_TYPE                      = 0x0007,
-
-       /*  Key Id (WEP default key Id)                                                                                                                                                 */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :   Any value between 0 to 3                                                                                                                  */
-       /*  Values to set :     Same value. Default is 0                                                                                                                                */
-       /*  --------------------------------------------------------------      */
-       WID_KEY_ID                         = 0x0009,
-
-       /*  QoS Enable                                                                                                                                                                          */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration :   QoS Disable   WMM Enable                                                                                                          */
-       /*  Values to set :   0             1                                                                                                                                                   */
-       /*  --------------------------------------------------------------      */
-       WID_QOS_ENABLE                     = 0x000A,
-
-       /*  Power Management                                                                                                                                                                    */
-       /*  ------------------------------------------------------------------  */
-       /*  Configuration :   NO_POWERSAVE   MIN_POWERSAVE   MAX_POWERSAVE                                              */
-       /*  Values to set :   0              1               2                                                                                                                                  */
-       /*  ------------------------------------------------------------------   */
-       WID_POWER_MANAGEMENT               = 0x000B,
-
-       /*  WEP/802 11I Configuration                                            */
-       /*  ------------------------------------------------------------------  */
-       /*  Configuration : Disable WP40 WP104 WPA-AES WPA-TKIP RSN-AES RSN-TKIP                                */
-       /*  Values (0x)   :   00                03    07        29                      49                      31                      51                                      */
-       /*                                                                                                                                                                                                              */
-       /*  Configuration : WPA-AES+TKIP RSN-AES+TKIP                                                                                                                   */
-       /*  Values (0x)   :      69                             71                                                                                                                              */
-       /*  ------------------------------------------------------------------   */
-       WID_11I_MODE                       = 0x000C,
-
-       /*  WEP Configuration: Used in BSS STA mode only when WEP is enabled     */
-       /*  ------------------------------------------------------------------   */
-       /*  Configuration : Open System  Shared Key  Any Type  |   802.1x Auth   */
-       /*  Values (0x)   :    01             02         03    |      BIT2       */
-       /*  ------------------------------------------------------------------   */
-       WID_AUTH_TYPE                      = 0x000D,
-
-       /*  Site Survey Type                                                                                                                                                                    */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration       :  Values to set                                                                                                                                */
-       /*  Survey 1 Channel    :  0                                                                                                                                                    */
-       /*  survey all Channels :  1                                                                                                                                                    */
-       /*  Disable Site Survey :  2                                                                                                                                                    */
-       /*  --------------------------------------------------------------      */
-       WID_SITE_SURVEY                    = 0x000E,
-
-       /*  Listen Interval                                                      */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :   Any value between 1 to 255                         */
-       /*  Values to set :   Same value. Default is 3                           */
-       /*  --------------------------------------------------------------       */
-       WID_LISTEN_INTERVAL                = 0x000F,
-
-       /*  DTIM Period                                                          */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :   Any value between 1 to 255                         */
-       /*  Values to set :   Same value. Default is 3                           */
-       /*  --------------------------------------------------------------       */
-       WID_DTIM_PERIOD                    = 0x0010,
-
-       /*  ACK Policy                                                           */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :   Normal Ack            No Ack                       */
-       /*  Values to set :       0                   1                          */
-       /*  --------------------------------------------------------------       */
-       WID_ACK_POLICY                     = 0x0011,
-
-       /*  Reset MAC (Set only)                                                           */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :   Don't Reset       Reset   No Request                       */
-       /*  Values to set :       0                   1                 2                          */
-       /*  --------------------------------------------------------------       */
-       WID_RESET                          = 0x0012,
-
-       /*  Broadcast SSID Option: Setting this will adhere to "" SSID element   */
-       /*  ------------------------------------------------------------------   */
-       /*  Configuration :   Enable             Disable                         */
-       /*  Values to set :   1                  0                               */
-       /*  ------------------------------------------------------------------   */
-       WID_BCAST_SSID                     = 0x0015,
-
-       /*  Disconnect (Station)                                                                                                                                                                                                                */
-       /*  ------------------------------------------------------------------  */
-       /*  Configuration :   Association ID                                                                                                                                                    */
-       /*  Values to set :   Association ID                                                                                                                                                    */
-       /*  ------------------------------------------------------------------  */
-       WID_DISCONNECT                     = 0x0016,
-
-       /*  11a Tx Power Level                                                   */
-       /*  -------------------------------------------------------------------- */
-       /*  Configuration : Sets TX Power (Higher the value greater the power)   */
-       /*  Values to set : Any value between 0 and 63 (inclusive; Default is 48)*/
-       /*  -------------------------------------------------------------------- */
-       WID_TX_POWER_LEVEL_11A             = 0x0018,
-
-       /*  Group Key Update Policy Selection                                    */
-       /*  -------------------------------------------------------------------- */
-       /*  Configuration : Disabled  timeBased  packetBased   timePacketBased   */
-       /*  Values to set :   1            2          3               4          */
-       /*  -------------------------------------------------------------------- */
-       WID_REKEY_POLICY                   = 0x0019,
-
-       /*  Allow Short Slot                                                     */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration : Disallow Short Slot      Allow Short Slot            */
-       /*              (Enable Only Long Slot) (Enable Short Slot if applicable)*/
-       /*  Values to set :    0         1                                       */
-       /*  --------------------------------------------------------------       */
-       WID_SHORT_SLOT_ALLOWED             = 0x001A,
-
-       WID_PHY_ACTIVE_REG                 = 0x001B,
-
-       /*  11b Tx Power Level                                                   */
-       /*  -------------------------------------------------------------------- */
-       /*  Configuration : Sets TX Power (Higher the value greater the power)   */
-       /*  Values to set : Any value between 0 and 63 (inclusive; Default is 48)*/
-       /*  -------------------------------------------------------------------- */
-       WID_TX_POWER_LEVEL_11B             = 0x001D,
-
-       /*  Scan Request                                                                                                                                                                                        */
-       /*  --------------------------------------------------------------------        */
-       /*  Configuration : Request default scan                                                                                                                                                                        */
-       /*  Values to set : 0                                                                                                                                                                                                                                   */
-       /*  -------------------------------------------------------------------- */
-       WID_START_SCAN_REQ                 = 0x001E,
-
-       /*  Rssi (get only)                                                                                                                                                                                     */
-       /*  --------------------------------------------------------------------        */
-       /*  Configuration :                                                                                                                                                                     */
-       /*  Values to get : Rssi value                                                                                                                                                                                                                                  */
-       /*  -------------------------------------------------------------------- */
-       WID_RSSI                           = 0x001F,
-
-       /*  Join Request                                                                                                                                                                                        */
-       /*  --------------------------------------------------------------------        */
-       /*  Configuration : Request to join                                                                                                                                                                     */
-       /*  Values to set : index of scan result                                                                                                                                                                        */
-       /*  -------------------------------------------------------------------- */
-       WID_JOIN_REQ                       = 0x0020,
-
-       WID_LINKSPEED                                                           = 0x0026,
-
-       /*  Enable User Control of TX Power                                      */
-       /*  -------------------------------------------------------------------- */
-       /*  Configuration : Disable                  Enable                      */
-       /*  Values to set :    0                       1                         */
-       /*  -------------------------------------------------------------------- */
-       WID_USER_CONTROL_ON_TX_POWER       = 0x0027,
-
-       WID_MEMORY_ACCESS_8BIT             = 0x0029,
-
-       /*  Enable Auto RX Sensitivity feature                                                                                                                                                          */
-       /*  --------------------------------------------------------------------        */
-       /*  Configuration : Disable                  Enable                                                                                                                                     */
-       /*  Values to set :    0                       1                                                                                                                                                        */
-       /*  --------------------------------------------------------------------        */
-       WID_AUTO_RX_SENSITIVITY            = 0x0032,
-
-       /*  Receive Buffer Based Ack                                                                                                                                                                            */
-       /*  --------------------------------------------------------------------        */
-       /*  Configuration : Disable                  Enable                                                                                                                                     */
-       /*  Values to set :    0                       1                                                                                                                                                        */
-       /*  --------------------------------------------------------------------        */
-       WID_DATAFLOW_CONTROL               = 0x0033,
-
-       /*  Scan Filter                                                                                                                                                                                 */
-       /*  --------------------------------------------------------------------        */
-       /*  Configuration : Class               No filter       AP only                 Station Only                                                                            */
-       /*  Values to set :                                     0                     1                     2                                                                                           */
-       /*  Configuration : Priority    High Rssi       Low Rssi                Detect                                                                                                  */
-       /*  Values to set :                                     0                  0x4                  0x08                                                                                    */
-       /*  Configuration : Channel     filter off              filter on                                                                                                                                       */
-       /*  Values to set :                                     0                  0x10                                                                                                                 */
-       /*  --------------------------------------------------------------------        */
-       WID_SCAN_FILTER                    = 0x0036,
-
-       /*  Link Loss Threshold (measure in the beacon period)                                                                          */
-       /*  --------------------------------------------------------------------        */
-       /*  Configuration : Any value between 10 and 254 (Set to 255 to disable it)                                                             */
-       /*  Values to set : Same value. Default is 10                                                                                                                                                           */
-       /*  --------------------------------------------------------------------        */
-       WID_LINK_LOSS_THRESHOLD            = 0x0037,
-
-       /*BugID_4978*/
-       WID_ABORT_RUNNING_SCAN = 0x003E,
+       WID_NIL                         = 0xffff,
+
+       /*
+        *  BSS Type
+        *  -----------------------------------------------------------
+        *  Configuration : Infrastructure   Independent   Access Point
+        *  Values to set :         0               1            2
+        *  -----------------------------------------------------------
+        */
+       WID_BSS_TYPE                    = 0x0000,
+
+       /*
+        *  Transmit Rate
+        *  -----------------------------------------------------------
+        *  Configuration : 1  2  5.5  11  6  9  12  18  24  36  48  54
+        *  Values to set : 1  2    5  11  6  9  12  18  24  36  48  54
+        *  -----------------------------------------------------------
+        */
+       WID_CURRENT_TX_RATE             = 0x0001,
+
+       /*
+        *  Channel
+        *  -----------------------------------------------------------
+        *  Configuration(g) : 1  2  3  4  5  6  7  8  9 10 11 12 13 14
+        *  Values to set    : 1  2  3  4  5  6  7  8  9 10 11 12 13 14
+        *  -----------------------------------------------------------
+        */
+       WID_CURRENT_CHANNEL             = 0x0002,
+
+       /*
+        *  Preamble
+        *  -----------------------------------------------------------
+        *  Configuration :    short    long      Auto
+        *  Values to set :       0       1         2
+        *  -----------------------------------------------------------
+        */
+       WID_PREAMBLE                    = 0x0003,
+
+       /*
+        * 11g operating mode (ignored if 11g not present)
+        *  -----------------------------------------------------------
+        *  Configuration :   HighPerf  Compat(RSet #1) Compat(RSet #2)
+        *  Values to set :          1               2               3
+        *  -----------------------------------------------------------
+        */
+       WID_11G_OPERATING_MODE          = 0x0004,
+
+       /*
+        *  Mac status (response only)
+        *  -----------------------------------------------------------
+        *  Configuration :   disconnect  connect
+        *  Values to get :          0       1
+        *  -----------------------------------------------------------
+        */
+       WID_STATUS                      = 0x0005,
+
+       /*
+        *  Scan type
+        *  -----------------------------------------------------------
+        *  Configuration :   Passive Scanning   Active Scanning
+        *  Values to set :                  0                 1
+        *  -----------------------------------------------------------
+        */
+       WID_SCAN_TYPE                   = 0x0007,
+
+       /*
+        *  Key Id (WEP default key Id)
+        *  -----------------------------------------------------------
+        *  Configuration :   Any value between 0 to 3
+        *  Values to set :   Same value. Default is 0
+        *  -----------------------------------------------------------
+        */
+       WID_KEY_ID                      = 0x0009,
+
+       /*
+        *  QoS Enable
+        *  -----------------------------------------------------------
+        *  Configuration :   QoS Disable   WMM Enable
+        *  Values to set :   0             1
+        *  -----------------------------------------------------------
+        */
+       WID_QOS_ENABLE                  = 0x000A,
+
+       /*
+        *  Power Management
+        *  -----------------------------------------------------------
+        *  Configuration : NO_POWERSAVE MIN_POWERSAVE MAX_POWERSAVE
+        *  Values to set : 0            1             2
+        *  -----------------------------------------------------------
+        */
+       WID_POWER_MANAGEMENT            = 0x000B,
+
+       /*
+        *  WEP/802 11I Configuration
+        *  -----------------------------------------------------------
+        *  Configuration:Disable WP40 WP104 WPA-AES WPA-TKIP RSN-AES RSN-TKIP
+        *  Values (0x)  :   00     03   07     29       49       31      51
+        *  Configuration:WPA-AES+TKIP RSN-AES+TKIP
+        *  Values (0x)  :      69        71
+        *  -----------------------------------------------------------
+        */
+       WID_11I_MODE                    = 0x000C,
+
+       /*
+        *  WEP Configuration: Used in BSS STA mode only when WEP is enabled
+        *  -----------------------------------------------------------
+        *  Configuration : Open System Shared Key Any Type | 802.1x Auth
+        *  Values (0x)   :    01             02         03 |    BIT2
+        *  -----------------------------------------------------------
+        */
+       WID_AUTH_TYPE                   = 0x000D,
+
+       /*
+        *  Site Survey Type
+        *  -----------------------------------------------------------
+        *  Configuration       :  Values to set
+        *  Survey 1 Channel    :  0
+        *  survey all Channels :  1
+        *  Disable Site Survey :  2
+        *  -----------------------------------------------------------
+        */
+       WID_SITE_SURVEY                 = 0x000E,
+
+       /*
+        *  Listen Interval
+        *  -----------------------------------------------------------
+        *  Configuration :   Any value between 1 to 255
+        *  Values to set :   Same value. Default is 3
+        *  -----------------------------------------------------------
+        */
+       WID_LISTEN_INTERVAL             = 0x000F,
+
+       /*
+        *  DTIM Period
+        *  -----------------------------------------------------------
+        *  Configuration :   Any value between 1 to 255
+        *  Values to set :   Same value. Default is 3
+        *  -----------------------------------------------------------
+        */
+       WID_DTIM_PERIOD                 = 0x0010,
+
+       /*
+        *  ACK Policy
+        *  -----------------------------------------------------------
+        *  Configuration :   Normal Ack            No Ack
+        *  Values to set :       0                   1
+        *  -----------------------------------------------------------
+        */
+       WID_ACK_POLICY                  = 0x0011,
+
+       /*
+        *  Reset MAC (Set only)
+        *  -----------------------------------------------------------
+        *  Configuration :   Don't Reset       Reset   No Request
+        *  Values to set :       0               1         2
+        *  -----------------------------------------------------------
+        */
+       WID_RESET                       = 0x0012,
+
+       /*
+        *  Broadcast SSID Option: Setting this will adhere to "" SSID element
+        *  -----------------------------------------------------------
+        *  Configuration :   Enable             Disable
+        *  Values to set :   1                  0
+        *  -----------------------------------------------------------
+        */
+       WID_BCAST_SSID                  = 0x0015,
+
+       /*
+        *  Disconnect (Station)
+        *  -----------------------------------------------------------
+        *  Configuration :   Association ID
+        *  Values to set :   Association ID
+        *  -----------------------------------------------------------
+        */
+       WID_DISCONNECT                  = 0x0016,
+
+       /*
+        *  11a Tx Power Level
+        *  -----------------------------------------------------------
+        *  Configuration : Sets TX Power (Higher the value greater the power)
+        *  Values to set : Any value between 0 and 63 (inclusive Default 48)
+        *  -----------------------------------------------------------
+        */
+       WID_TX_POWER_LEVEL_11A          = 0x0018,
+
+       /*
+        *  Group Key Update Policy Selection
+        *  -----------------------------------------------------------
+        *  Configuration : Disabled timeBased packetBased timePacketBased
+        *  Values to set :   1            2          3              4
+        *  -----------------------------------------------------------
+        */
+       WID_REKEY_POLICY                = 0x0019,
+
+       /*
+        *  Allow Short Slot
+        *  -----------------------------------------------------------
+        *  Configuration : Disallow Short Slot      Allow Short Slot
+        *          (Enable Only Long Slot) (Enable Short Slot if applicable)
+        *  Values to set :    0         1
+        *  -----------------------------------------------------------
+        */
+       WID_SHORT_SLOT_ALLOWED          = 0x001A,
+
+       WID_PHY_ACTIVE_REG              = 0x001B,
+
+       /*
+        *  11b Tx Power Level
+        *  -----------------------------------------------------------
+        *  Configuration : Sets TX Power (Higher the value greater the power)
+        *  Values to set : Any value between 0 and 63 (inclusive Default 48)
+        *  -----------------------------------------------------------
+        */
+       WID_TX_POWER_LEVEL_11B          = 0x001D,
+
+       /*
+        *  Scan Request
+        *  -----------------------------------------------------------
+        *  Configuration : Request default scan
+        *  Values to set : 0
+        *  -----------------------------------------------------------
+        */
+       WID_START_SCAN_REQ              = 0x001E,
+
+       /*
+        *  Rssi (get only)
+        *  -----------------------------------------------------------
+        *  Configuration :
+        *  Values to get : Rssi value
+        *  -----------------------------------------------------------
+        */
+       WID_RSSI                        = 0x001F,
+
+       /*
+        * Join Request
+        *  -----------------------------------------------------------
+        *  Configuration : Request to join
+        *  Values to set : index of scan result
+        *  -----------------------------------------------------------
+        */
+       WID_JOIN_REQ                    = 0x0020,
+
+       WID_LINKSPEED                   = 0x0026,
+
+       /*
+        *  Enable User Control of TX Power
+        *  -----------------------------------------------------------
+        *  Configuration : Disable                  Enable
+        *  Values to set :    0                       1
+        *  -----------------------------------------------------------
+        */
+       WID_USER_CONTROL_ON_TX_POWER    = 0x0027,
+
+       WID_MEMORY_ACCESS_8BIT          = 0x0029,
+
+       /*
+        *  Enable Auto RX Sensitivity feature
+        *  -----------------------------------------------------------
+        *  Configuration : Disable                  Enable
+        *  Values to set :    0                       1
+        *  -----------------------------------------------------------
+        */
+       WID_AUTO_RX_SENSITIVITY         = 0x0032,
+
+       /*
+        *  Receive Buffer Based Ack
+        *  -----------------------------------------------------------
+        *  Configuration : Disable                  Enable
+        *  Values to set :    0                       1
+        *  -----------------------------------------------------------
+        */
+       WID_DATAFLOW_CONTROL            = 0x0033,
+
+       /*
+        *  Scan Filter
+        *  -----------------------------------------------------------
+        *  Configuration : Class       No filter   AP only   Station Only
+        *  Values to set :                0           1           2
+        *  Configuration : Priority    High Rssi   Low Rssi     Detect
+        *  Values to set :                0          0x4         0x0
+        *  Configuration : Channel     filter off  filter on
+        *  Values to set :                0          0x10
+        *  -----------------------------------------------------------
+        */
+       WID_SCAN_FILTER                 = 0x0036,
+
+       /*
+        *  Link Loss Threshold (measure in the beacon period)
+        *  -----------------------------------------------------------
+        *  Configuration : Any value between 10 and 254(Set to 255 disable)
+        *  Values to set : Same value. Default is 10
+        *  -----------------------------------------------------------
+        */
+       WID_LINK_LOSS_THRESHOLD         = 0x0037,
+
+       WID_ABORT_RUNNING_SCAN          = 0x003E,
 
        /* NMAC Character WID list */
-       WID_WPS_START                      = 0x0043,
-
-       /*  Protection mode for MAC                                              */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Auto  No protection  ERP    HT    GF                */
-       /*  Values to set :  0     1              2      3     4                 */
-       /*  --------------------------------------------------------------       */
-       WID_11N_PROT_MECH                  = 0x0080,
-
-       /*  ERP Protection type for MAC                                          */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Self-CTS   RTS-CTS                                  */
-       /*  Values to set :  0          1                                        */
-       /*  --------------------------------------------------------------       */
-       WID_11N_ERP_PROT_TYPE              = 0x0081,
-
-       /*  HT Option Enable                                                     */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :   HT Enable          HT Disable                       */
-       /*  Values to set :   1                  0                               */
-       /*  --------------------------------------------------------------       */
-       WID_11N_ENABLE                     = 0x0082,
-
-       /*  11n Operating mode (Note that 11g operating mode will also be        */
-       /*  used in addition to this, if this is set to HT Mixed mode)           */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  HT Mixed  HT Only-20MHz   HT Only-20/40MHz          */
-       /*  Values to set :     1         2               3                         */
-       /*  --------------------------------------------------------------       */
-       WID_11N_OPERATING_MODE             = 0x0083,
-
-       /*  11n OBSS non-HT STA Detection flag                                   */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Do not detect                                       */
-       /*  Values to set :  0                                                   */
-       /*  Configuration :  Detect, do not protect or report                    */
-       /*  Values to set :  1                                                   */
-       /*  Configuration :  Detect, protect and do not report                   */
-       /*  Values to set :  2                                                   */
-       /*  Configuration :  Detect, protect and report to other BSS             */
-       /*  Values to set :  3                                                   */
-       /*  --------------------------------------------------------------       */
-       WID_11N_OBSS_NONHT_DETECTION       = 0x0084,
-
-       /*  11n HT Protection Type                                               */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  RTS-CTS   First Frame Exchange at non-HT-rate       */
-       /*  Values to set :  0         1                                         */
-       /*  Configuration :  LSIG TXOP First Frame Exchange in Mixed Fmt         */
-       /*  Values to set :  2         3                                         */
-       /*  --------------------------------------------------------------       */
-       WID_11N_HT_PROT_TYPE               = 0x0085,
-
-       /*  11n RIFS Protection Enable Flag                                      */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Disable    Enable                                   */
-       /*  Values to set :  0          1                                        */
-       /*  --------------------------------------------------------------       */
-       WID_11N_RIFS_PROT_ENABLE           = 0x0086,
-
-       /*  SMPS Mode                                                            */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Static   Dynamic   MIMO (Power Save Disabled)       */
-       /*  Values to set :  1        2         3                                */
-       /*  --------------------------------------------------------------       */
-       WID_11N_SMPS_MODE                  = 0x0087,
-
-       /*  Current transmit MCS                                                 */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  MCS Index for data rate                                                                                                                    */
-       /*  Values to set :  0 to 7                                                                                                                                                     */
-       /*  --------------------------------------------------------------       */
-       WID_11N_CURRENT_TX_MCS             = 0x0088,
-
-       WID_11N_PRINT_STATS                = 0x0089,
-
-       /*  11n Short GI Enable Flag                                                                                                                                                    */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Disable    Enable                                                                                                                                  */
-       /*  Values to set :  0          1                                                                                                                                                       */
-       /*  --------------------------------------------------------------       */
-       WID_11N_SHORT_GI_ENABLE            = 0x008D,
-
-       /*  11n RIFS Enable Flag                                                                                                                                                */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Disable    Enable                                                                                                                                  */
-       /*  Values to set :  0          1                                                                                                                                                       */
-       /*  --------------------------------------------------------------       */
-       WID_RIFS_MODE                      = 0x0094,
-
-       /*  TX Abort Feature                                                                                                                                                    */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :  Disable Self CTS    Enable Self CTS                                                                                                        */
-       /*  Values to set :             0                                       1                                                                                                                               */
-       /*  Configuration :  Disable TX Abort    Enable TX Abort                                                                                                        */
-       /*  Values to set :             2                                       3                                                                                                                               */
-       /*  Configuration :  Enable HW TX Abort Enable SW TX Abort                                                                                              */
-       /*  Values to set :             4                                       5                                                                                                                               */
-       /*  --------------------------------------------------------------       */
-       WID_TX_ABORT_CONFIG                = 0x00A1,
-
-       WID_REG_TSSI_11B_VALUE             = 0x00A6,
-       WID_REG_TSSI_11G_VALUE             = 0x00A7,
-       WID_REG_TSSI_11N_VALUE             = 0x00A8,
-       WID_TX_CALIBRATION                 = 0x00A9,
-       WID_DSCR_TSSI_11B_VALUE            = 0x00AA,
-       WID_DSCR_TSSI_11G_VALUE            = 0x00AB,
-       WID_DSCR_TSSI_11N_VALUE            = 0x00AC,
-
-       /*  Immediate Block-Ack Support                                          */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration : Disable                  Enable                      */
-       /*  Values to set :    0                       1                         */
-       /*  --------------------------------------------------------------       */
-       WID_11N_IMMEDIATE_BA_ENABLED       = 0x00AF,
-
-       /*  TXOP Disable Flag                                                                                                                                                                   */
-       /*  --------------------------------------------------------------      */
-       /*  Configuration : Disable                  Enable                                                                                                                     */
-       /*  Values to set :    1                        0                                                                                                                               */
-       /*  --------------------------------------------------------------      */
-       WID_11N_TXOP_PROT_DISABLE          = 0x00B0,
-
-
-       WID_TX_POWER_LEVEL_11N             = 0x00B1,
+       WID_WPS_START                   = 0x0043,
+
+       /*
+        *  Protection mode for MAC
+        *  -----------------------------------------------------------
+        *  Configuration :  Auto  No protection  ERP    HT    GF
+        *  Values to set :  0     1              2      3     4
+        *  -----------------------------------------------------------
+        */
+       WID_11N_PROT_MECH               = 0x0080,
+
+       /*
+        *  ERP Protection type for MAC
+        *  -----------------------------------------------------------
+        *  Configuration :  Self-CTS   RTS-CTS
+        *  Values to set :  0          1
+        *  -----------------------------------------------------------
+        */
+       WID_11N_ERP_PROT_TYPE           = 0x0081,
+
+       /*
+        *  HT Option Enable
+        *  -----------------------------------------------------------
+        *  Configuration :   HT Enable          HT Disable
+        *  Values to set :   1                  0
+        *  -----------------------------------------------------------
+        */
+       WID_11N_ENABLE                  = 0x0082,
+
+       /*
+        *  11n Operating mode (Note that 11g operating mode will also be
+        *  used in addition to this, if this is set to HT Mixed mode)
+        *  -----------------------------------------------------------
+        *   Configuration :  HT Mixed  HT Only-20MHz   HT Only-20/40MHz
+        *  Values to set :     1         2               3
+        *  -----------------------------------------------------------
+        */
+       WID_11N_OPERATING_MODE          = 0x0083,
+
+       /*
+        *  11n OBSS non-HT STA Detection flag
+        *  -----------------------------------------------------------
+        *  Configuration :  Do not detect
+        *  Values to set :  0
+        *  Configuration :  Detect, do not protect or report
+        *  Values to set :  1
+        *  Configuration :  Detect, protect and do not report
+        *  Values to set :  2
+        *  Configuration :  Detect, protect and report to other BSS
+        *  Values to set :  3
+        *  -----------------------------------------------------------
+        */
+       WID_11N_OBSS_NONHT_DETECTION    = 0x0084,
+
+       /*
+        *  11n HT Protection Type
+        *  -----------------------------------------------------------
+        *  Configuration :  RTS-CTS   First Frame Exchange at non-HT-rate
+        *  Values to set :  0         1
+        *  Configuration :  LSIG TXOP First Frame Exchange in Mixed Fmt
+        *  Values to set :  2         3
+        *  -----------------------------------------------------------
+        */
+       WID_11N_HT_PROT_TYPE            = 0x0085,
+
+       /*
+        *  11n RIFS Protection Enable Flag
+        *  -----------------------------------------------------------
+        *  Configuration :  Disable    Enable
+        *  Values to set :  0          1
+        *  -----------------------------------------------------------
+        */
+       WID_11N_RIFS_PROT_ENABLE        = 0x0086,
+
+       /*
+        *  SMPS Mode
+        *  -----------------------------------------------------------
+        *  Configuration :  Static   Dynamic   MIMO (Power Save Disabled)
+        *  Values to set :  1        2         3
+        *  -----------------------------------------------------------
+        */
+       WID_11N_SMPS_MODE               = 0x0087,
+
+       /*
+        *  Current transmit MCS
+        *  -----------------------------------------------------------
+        *  Configuration :  MCS Index for data rate
+        *  Values to set :  0 to 7
+        *  -----------------------------------------------------------
+        */
+       WID_11N_CURRENT_TX_MCS          = 0x0088,
+
+       WID_11N_PRINT_STATS             = 0x0089,
+
+       /*
+        *  11n Short GI Enable Flag
+        *  -----------------------------------------------------------
+        *  Configuration :  Disable    Enable
+        *  Values to set :  0          1
+        *  -----------------------------------------------------------
+        */
+       WID_11N_SHORT_GI_ENABLE         = 0x008D,
+
+       /*
+        *  11n RIFS Enable Flag
+        *  -----------------------------------------------------------
+        *  Configuration :  Disable    Enable
+        *  Values to set :  0          1
+        *  -----------------------------------------------------------
+        */
+       WID_RIFS_MODE                   = 0x0094,
+
+       /*
+        *  TX Abort Feature
+        *  -----------------------------------------------------------
+        *  Configuration :  Disable Self CTS    Enable Self CTS
+        *  Values to set :             0                      1
+        *  Configuration :  Disable TX Abort    Enable TX Abort
+        *  Values to set :             2                      3
+        *  Configuration :  Enable HW TX Abort Enable SW TX Abort
+        *  Values to set :             4                      5
+        *  -----------------------------------------------------------
+        */
+       WID_TX_ABORT_CONFIG             = 0x00A1,
+
+       WID_REG_TSSI_11B_VALUE          = 0x00A6,
+       WID_REG_TSSI_11G_VALUE          = 0x00A7,
+       WID_REG_TSSI_11N_VALUE          = 0x00A8,
+       WID_TX_CALIBRATION              = 0x00A9,
+       WID_DSCR_TSSI_11B_VALUE         = 0x00AA,
+       WID_DSCR_TSSI_11G_VALUE         = 0x00AB,
+       WID_DSCR_TSSI_11N_VALUE         = 0x00AC,
+
+       /*
+        *  Immediate Block-Ack Support
+        *  -----------------------------------------------------------
+        *  Configuration : Disable                  Enable
+        *  Values to set :    0                       1
+        *  -----------------------------------------------------------
+        */
+       WID_11N_IMMEDIATE_BA_ENABLED    = 0x00AF,
+
+       /*
+        *  TXOP Disable Flag
+        *  -----------------------------------------------------------
+        *  Configuration : Disable                  Enable
+        *  Values to set :    1                        0
+        *  -----------------------------------------------------------
+        */
+       WID_11N_TXOP_PROT_DISABLE       = 0x00B0,
+
+       WID_TX_POWER_LEVEL_11N          = 0x00B1,
 
        /* Custom Character WID list */
-       WID_PC_TEST_MODE          = 0x00C8,
-       /*bug3819: */
+       WID_PC_TEST_MODE                = 0x00C8,
        /* SCAN Complete notification WID*/
        WID_SCAN_COMPLETE               = 0x00C9,
 
-#ifdef WILC_AP_EXTERNAL_MLME
-       WID_DEL_BEACON                                  = 0x00CA,
-#endif
-
-       WID_LOGTerminal_Switch                                  = 0x00CD,
-       /* EMAC Short WID list */
-       /*  RTS Threshold                                                        */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :   Any value between 256 to 2347                      */
-       /*  Values to set :   Same value. Default is 2347                        */
-       /*  --------------------------------------------------------------       */
-       WID_RTS_THRESHOLD                  = 0x1000,
-
-       /*  Fragmentation Threshold                                              */
-       /*  --------------------------------------------------------------       */
-       /*  Configuration :   Any value between 256 to 2346                      */
-       /*  Values to set :   Same value. Default is 2346                        */
-       /*  --------------------------------------------------------------       */
-       WID_FRAG_THRESHOLD                 = 0x1001,
-
-       WID_SHORT_RETRY_LIMIT              = 0x1002,
-       WID_LONG_RETRY_LIMIT               = 0x1003,
-       WID_BEACON_INTERVAL                = 0x1006,
-       WID_MEMORY_ACCESS_16BIT            = 0x1008,
-       WID_RX_SENSE                       = 0x100B,
-       WID_ACTIVE_SCAN_TIME               = 0x100C,
-       WID_PASSIVE_SCAN_TIME              = 0x100D,
-
-       WID_SITE_SURVEY_SCAN_TIME          = 0x100E,
-       WID_JOIN_START_TIMEOUT             = 0x100F,
-       WID_AUTH_TIMEOUT                   = 0x1010,
-       WID_ASOC_TIMEOUT                   = 0x1011,
-       WID_11I_PROTOCOL_TIMEOUT           = 0x1012,
-       WID_EAPOL_RESPONSE_TIMEOUT         = 0x1013,
+       WID_DEL_BEACON                  = 0x00CA,
+
+       WID_LOGTerminal_Switch          = 0x00CD,
+       /*  EMAC Short WID list */
+       /*  RTS Threshold */
+       /*
+        *  -----------------------------------------------------------
+        *  Configuration :   Any value between 256 to 2347
+        *  Values to set :   Same value. Default is 2347
+        *  -----------------------------------------------------------
+        */
+       WID_RTS_THRESHOLD               = 0x1000,
+
+       /*
+        *  Fragmentation Threshold
+        *  -----------------------------------------------------------
+        *  Configuration :   Any value between 256 to 2346
+        *  Values to set :   Same value. Default is 2346
+        *  -----------------------------------------------------------
+        */
+       WID_FRAG_THRESHOLD              = 0x1001,
+
+       WID_SHORT_RETRY_LIMIT           = 0x1002,
+       WID_LONG_RETRY_LIMIT            = 0x1003,
+       WID_BEACON_INTERVAL             = 0x1006,
+       WID_MEMORY_ACCESS_16BIT         = 0x1008,
+       WID_RX_SENSE                    = 0x100B,
+       WID_ACTIVE_SCAN_TIME            = 0x100C,
+       WID_PASSIVE_SCAN_TIME           = 0x100D,
+
+       WID_SITE_SURVEY_SCAN_TIME       = 0x100E,
+       WID_JOIN_START_TIMEOUT          = 0x100F,
+       WID_AUTH_TIMEOUT                = 0x1010,
+       WID_ASOC_TIMEOUT                = 0x1011,
+       WID_11I_PROTOCOL_TIMEOUT        = 0x1012,
+       WID_EAPOL_RESPONSE_TIMEOUT      = 0x1013,
 
        /* NMAC Short WID list */
-       WID_11N_SIG_QUAL_VAL               = 0x1085,
-       WID_CCA_THRESHOLD                  = 0x1087,
+       WID_11N_SIG_QUAL_VAL            = 0x1085,
+       WID_CCA_THRESHOLD               = 0x1087,
 
        /* Custom Short WID list */
 
        /* EMAC Integer WID list */
-       WID_FAILED_COUNT                   = 0x2000,
-       WID_RETRY_COUNT                    = 0x2001,
-       WID_MULTIPLE_RETRY_COUNT           = 0x2002,
-       WID_FRAME_DUPLICATE_COUNT          = 0x2003,
-       WID_ACK_FAILURE_COUNT              = 0x2004,
-       WID_RECEIVED_FRAGMENT_COUNT        = 0x2005,
-       WID_MCAST_RECEIVED_FRAME_COUNT     = 0x2006,
-       WID_FCS_ERROR_COUNT                = 0x2007,
-       WID_SUCCESS_FRAME_COUNT            = 0x2008,
-       WID_HUT_TX_COUNT                   = 0x200A,
-       WID_TX_FRAGMENT_COUNT              = 0x200B,
-       WID_TX_MULTICAST_FRAME_COUNT       = 0x200C,
-       WID_RTS_SUCCESS_COUNT              = 0x200D,
-       WID_RTS_FAILURE_COUNT              = 0x200E,
-       WID_WEP_UNDECRYPTABLE_COUNT        = 0x200F,
-       WID_REKEY_PERIOD                   = 0x2010,
-       WID_REKEY_PACKET_COUNT             = 0x2011,
-       WID_1X_SERV_ADDR                   = 0x2012,
-       WID_STACK_IP_ADDR                  = 0x2013,
-       WID_STACK_NETMASK_ADDR             = 0x2014,
-       WID_HW_RX_COUNT                    = 0x2015,
-       WID_MEMORY_ADDRESS                 = 0x201E,
-       WID_MEMORY_ACCESS_32BIT            = 0x201F,
-       WID_RF_REG_VAL                     = 0x2021,
-
+       WID_FAILED_COUNT                = 0x2000,
+       WID_RETRY_COUNT                 = 0x2001,
+       WID_MULTIPLE_RETRY_COUNT        = 0x2002,
+       WID_FRAME_DUPLICATE_COUNT       = 0x2003,
+       WID_ACK_FAILURE_COUNT           = 0x2004,
+       WID_RECEIVED_FRAGMENT_COUNT     = 0x2005,
+       WID_MCAST_RECEIVED_FRAME_COUNT  = 0x2006,
+       WID_FCS_ERROR_COUNT             = 0x2007,
+       WID_SUCCESS_FRAME_COUNT         = 0x2008,
+       WID_HUT_TX_COUNT                = 0x200A,
+       WID_TX_FRAGMENT_COUNT           = 0x200B,
+       WID_TX_MULTICAST_FRAME_COUNT    = 0x200C,
+       WID_RTS_SUCCESS_COUNT           = 0x200D,
+       WID_RTS_FAILURE_COUNT           = 0x200E,
+       WID_WEP_UNDECRYPTABLE_COUNT     = 0x200F,
+       WID_REKEY_PERIOD                = 0x2010,
+       WID_REKEY_PACKET_COUNT          = 0x2011,
+       WID_1X_SERV_ADDR                = 0x2012,
+       WID_STACK_IP_ADDR               = 0x2013,
+       WID_STACK_NETMASK_ADDR          = 0x2014,
+       WID_HW_RX_COUNT                 = 0x2015,
+       WID_MEMORY_ADDRESS              = 0x201E,
+       WID_MEMORY_ACCESS_32BIT         = 0x201F,
+       WID_RF_REG_VAL                  = 0x2021,
 
        /* NMAC Integer WID list */
-       WID_11N_PHY_ACTIVE_REG_VAL         = 0x2080,
+       WID_11N_PHY_ACTIVE_REG_VAL      = 0x2080,
 
        /* Custom Integer WID list */
-       WID_GET_INACTIVE_TIME     = 0x2084,
-       WID_SET_DRV_HANDLER =            0X2085,
-       WID_SET_OPERATION_MODE =         0X2086,
+       WID_GET_INACTIVE_TIME           = 0x2084,
+       WID_SET_DRV_HANDLER             = 0X2085,
+       WID_SET_OPERATION_MODE          = 0X2086,
        /* EMAC String WID list */
-       WID_SSID                           = 0x3000,
-       WID_FIRMWARE_VERSION               = 0x3001,
-       WID_OPERATIONAL_RATE_SET           = 0x3002,
-       WID_BSSID                          = 0x3003,
-       WID_WEP_KEY_VALUE                  = 0x3004,
-       WID_11I_PSK                        = 0x3008,
-       WID_11E_P_ACTION_REQ               = 0x3009,
-       WID_1X_KEY                         = 0x300A,
-       WID_HARDWARE_VERSION               = 0x300B,
-       WID_MAC_ADDR                       = 0x300C,
-       WID_HUT_DEST_ADDR                  = 0x300D,
-       WID_PHY_VERSION                    = 0x300F,
-       WID_SUPP_USERNAME                  = 0x3010,
-       WID_SUPP_PASSWORD                  = 0x3011,
-       WID_SITE_SURVEY_RESULTS            = 0x3012,
-       WID_RX_POWER_LEVEL                 = 0x3013,
-       WID_DEL_ALL_RX_BA                               = 0x3014,
-       WID_SET_STA_MAC_INACTIVE_TIME   = 0x3017,
-       WID_ADD_WEP_KEY                    = 0x3019,
-       WID_REMOVE_WEP_KEY                 = 0x301A,
-       WID_ADD_PTK                        = 0x301B,
-       WID_ADD_RX_GTK                     = 0x301C,
-       WID_ADD_TX_GTK                     = 0x301D,
-       WID_REMOVE_KEY                     = 0x301E,
-       WID_ASSOC_REQ_INFO                 = 0x301F,
-       WID_ASSOC_RES_INFO                 = 0x3020,
-       WID_MANUFACTURER                   = 0x3026, /*Added for CAPI tool */
-       WID_MODEL_NAME                                     = 0x3027, /*Added for CAPI tool */
-       WID_MODEL_NUM                      = 0x3028, /*Added for CAPI tool */
-       WID_DEVICE_NAME                                     = 0x3029, /*Added for CAPI tool */
+       WID_SSID                        = 0x3000,
+       WID_FIRMWARE_VERSION            = 0x3001,
+       WID_OPERATIONAL_RATE_SET        = 0x3002,
+       WID_BSSID                       = 0x3003,
+       WID_WEP_KEY_VALUE               = 0x3004,
+       WID_11I_PSK                     = 0x3008,
+       WID_11E_P_ACTION_REQ            = 0x3009,
+       WID_1X_KEY                      = 0x300A,
+       WID_HARDWARE_VERSION            = 0x300B,
+       WID_MAC_ADDR                    = 0x300C,
+       WID_HUT_DEST_ADDR               = 0x300D,
+       WID_PHY_VERSION                 = 0x300F,
+       WID_SUPP_USERNAME               = 0x3010,
+       WID_SUPP_PASSWORD               = 0x3011,
+       WID_SITE_SURVEY_RESULTS         = 0x3012,
+       WID_RX_POWER_LEVEL              = 0x3013,
+       WID_DEL_ALL_RX_BA               = 0x3014,
+       WID_SET_STA_MAC_INACTIVE_TIME   = 0x3017,
+       WID_ADD_WEP_KEY                 = 0x3019,
+       WID_REMOVE_WEP_KEY              = 0x301A,
+       WID_ADD_PTK                     = 0x301B,
+       WID_ADD_RX_GTK                  = 0x301C,
+       WID_ADD_TX_GTK                  = 0x301D,
+       WID_REMOVE_KEY                  = 0x301E,
+       WID_ASSOC_REQ_INFO              = 0x301F,
+       WID_ASSOC_RES_INFO              = 0x3020,
+       WID_MANUFACTURER                = 0x3026, /*Added for CAPI tool */
+       WID_MODEL_NAME                  = 0x3027, /*Added for CAPI tool */
+       WID_MODEL_NUM                   = 0x3028, /*Added for CAPI tool */
+       WID_DEVICE_NAME                 = 0x3029, /*Added for CAPI tool */
 
        /* NMAC String WID list */
-       WID_11N_P_ACTION_REQ               = 0x3080,
-       WID_HUT_TEST_ID                    = 0x3081,
-       WID_PMKID_INFO                     = 0x3082,
-       WID_FIRMWARE_INFO                  = 0x3083,
-       #ifdef WILC_P2P
-       WID_REGISTER_FRAME                = 0x3084,
-       #endif
-       WID_DEL_ALL_STA          = 0x3085,
-        #ifdef WILC_P2P
-       WID_REMAIN_ON_CHAN  = 0x3996,
-       #endif
-       /*BugID_4156*/
-       WID_SSID_PROBE_REQ = 0x3997,
-       /*BugID_4124 WID to trigger modified Join Request using SSID and BSSID instead of bssListIdx (used by WID_JOIN_REQ)*/
-       WID_JOIN_REQ_EXTENDED            = 0x3998,
-
-       /* BugID 4951: WID toset IP address in firmware */
-       WID_IP_ADDRESS                                  = 0x3999,
-
-
+       WID_11N_P_ACTION_REQ            = 0x3080,
+       WID_HUT_TEST_ID                 = 0x3081,
+       WID_PMKID_INFO                  = 0x3082,
+       WID_FIRMWARE_INFO               = 0x3083,
+       WID_REGISTER_FRAME              = 0x3084,
+       WID_DEL_ALL_STA                 = 0x3085,
+       WID_REMAIN_ON_CHAN              = 0x3996,
+       WID_SSID_PROBE_REQ              = 0x3997,
+       WID_JOIN_REQ_EXTENDED           = 0x3998,
+
+       WID_IP_ADDRESS                  = 0x3999,
 
        /* Custom String WID list */
 
        /* EMAC Binary WID list */
-       WID_UAPSD_CONFIG                   = 0x4001,
-       WID_UAPSD_STATUS                   = 0x4002,
-       WID_WMM_AP_AC_PARAMS               = 0x4003,
-       WID_WMM_STA_AC_PARAMS              = 0x4004,
-       WID_NETWORK_INFO                   = 0x4005,
-       WID_STA_JOIN_INFO                  = 0x4006,
-       WID_CONNECTED_STA_LIST             = 0x4007,
+       WID_UAPSD_CONFIG                = 0x4001,
+       WID_UAPSD_STATUS                = 0x4002,
+       WID_WMM_AP_AC_PARAMS            = 0x4003,
+       WID_WMM_STA_AC_PARAMS           = 0x4004,
+       WID_NETWORK_INFO                = 0x4005,
+       WID_STA_JOIN_INFO               = 0x4006,
+       WID_CONNECTED_STA_LIST          = 0x4007,
 
        /* NMAC Binary WID list */
-       WID_11N_AUTORATE_TABLE             = 0x4080,
+       WID_11N_AUTORATE_TABLE          = 0x4080,
 
+       WID_SCAN_CHANNEL_LIST           = 0x4084,
 
-       /*Added here by Amr - BugID 4134*/
-       WID_SCAN_CHANNEL_LIST                      = 0x4084,
+       WID_INFO_ELEMENT_PROBE          = 0x4085,
+       WID_INFO_ELEMENT_ASSOCIATE      = 0x4086,
+       WID_ADD_STA                     = 0X4087,
+       WID_REMOVE_STA                  = 0X4088,
+       WID_EDIT_STA                    = 0X4089,
+       WID_ADD_BEACON                  = 0x408a,
 
-       /*BugID_3746 WID to add IE to be added in next probe request*/
-       WID_INFO_ELEMENT_PROBE   = 0x4085,
-       /*BugID_3746 WID to add IE to be added in next associate request*/
-       WID_INFO_ELEMENT_ASSOCIATE       = 0x4086,
-       WID_ADD_STA                                      = 0X4087,
-       WID_REMOVE_STA                           = 0X4088,
-       WID_EDIT_STA                                     = 0X4089,
-       WID_ADD_BEACON                          = 0x408a,
-
-       /* BugID 5108 */
        WID_SETUP_MULTICAST_FILTER      = 0x408b,
 
        /* Miscellaneous WIDs */
-       WID_ALL                            = 0x7FFE,
-       WID_MAX                            = 0xFFFF
+       WID_ALL                         = 0x7FFE,
+       WID_MAX                         = 0xFFFF
 } WID_T;
 
-int wilc_wlan_init(wilc_wlan_inp_t *inp, wilc_wlan_oup_t *oup);
+int wilc_wlan_init(wilc_wlan_inp_t *inp);
 
 void wilc_bus_set_max_speed(void);
 void wilc_bus_set_default_speed(void);
-uint32_t wilc_get_chipid(uint8_t update);
-
+u32 wilc_get_chipid(u8 update);
 
 #endif
index 342e2b30c48f92a5a1b98541e4af9cf2d2c40432..8c1e3f06a215675df58d1fee29ece48946a7a3a3 100644 (file)
@@ -2,7 +2,6 @@
 #include "hfa384x.h"
 #include "prism2mgmt.h"
 
-
 /* Prism2 channel/frequency/bitrate declarations */
 static const struct ieee80211_channel prism2_channels[] = {
        { .center_freq = 2412 },
@@ -34,7 +33,6 @@ static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = {
        WLAN_CIPHER_SUITE_WEP104
 };
 
-
 /* prism2 device private data */
 struct prism2_wiphy_private {
        wlandevice_t *wlandev;
@@ -48,7 +46,6 @@ struct prism2_wiphy_private {
 
 static const void * const prism2_wiphy_privid = &prism2_wiphy_privid;
 
-
 /* Helper Functions */
 static int prism2_result2err(int prism2_result)
 {
@@ -100,7 +97,6 @@ static int prism2_domibset_pstr32(wlandevice_t *wlandev,
        return p80211req_dorequest(wlandev, (u8 *) &msg);
 }
 
-
 /* The interface functions, called by the cfg80211 layer */
 static int prism2_change_virtual_intf(struct wiphy *wiphy,
                                      struct net_device *dev,
@@ -298,7 +294,6 @@ static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
        return err;
 }
 
-
 static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
                              const u8 *mac, struct station_info *sinfo)
 {
@@ -322,7 +317,6 @@ static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
 
        result = wlandev->mlmerequest(wlandev, (struct p80211msg *) &quality);
 
-
        if (result == 0) {
                sinfo->txrate.legacy = quality.txrate.data;
                sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
@@ -623,7 +617,6 @@ static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
        int result;
        int err = 0;
 
-
        /* Do a join, with a bogus ssid. Thats the only way I can think of */
        msg_join.msgcode = DIDmsg_lnxreq_autojoin;
 
@@ -638,7 +631,6 @@ static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
        return err;
 }
 
-
 static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev,
                            struct cfg80211_ibss_params *params)
 {
@@ -650,7 +642,6 @@ static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
        return -EOPNOTSUPP;
 }
 
-
 static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
                               enum nl80211_tx_power_setting type, int mbm)
 {
@@ -706,9 +697,6 @@ exit:
        return err;
 }
 
-
-
-
 /* Interface callback functions, passing data back up to the cfg80211 layer */
 void prism2_connect_result(wlandevice_t *wlandev, u8 failed)
 {
@@ -731,7 +719,6 @@ void prism2_roamed(wlandevice_t *wlandev)
                NULL, 0, NULL, 0, GFP_KERNEL);
 }
 
-
 /* Structures for declaring wiphy interface */
 static const struct cfg80211_ops prism2_usb_cfg_ops = {
        .change_virtual_intf = prism2_change_virtual_intf,
@@ -750,7 +737,6 @@ static const struct cfg80211_ops prism2_usb_cfg_ops = {
        .get_tx_power = prism2_get_tx_power,
 };
 
-
 /* Functions to create/free wiphy interface */
 static struct wiphy *wlan_create_wiphy(struct device *dev, wlandevice_t *wlandev)
 {
@@ -788,7 +774,6 @@ static struct wiphy *wlan_create_wiphy(struct device *dev, wlandevice_t *wlandev
        return wiphy;
 }
 
-
 static void wlan_free_wiphy(struct wiphy *wiphy)
 {
        wiphy_unregister(wiphy);
index e109a7fd422ffe387f0457c695eb39518472d956..444ebed7313a4320e0b8667b61a1cdda071b178e 100644 (file)
@@ -1194,7 +1194,7 @@ int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
 ----------------------------------------------------------------*/
 int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
 {
-       int result = 0;
+       int result;
 
        result = usb_reset_device(hw->usb);
        if (result < 0) {
index 49f2ef88929d30c12270ef08fffc7a802d39e606..1b02cdf9d1fa8eeeb8813c776f64987e2778add2 100644 (file)
@@ -135,7 +135,7 @@ int skb_ether_to_p80211(wlandevice_t *wlandev, u32 ethconv,
                        /* it's 802.3, pass ether payload unchanged,  */
 
                        /* trim off ethernet header */
-                       skb_pull(skb, WLAN_ETHHDR_LEN);
+                       skb_pull(skb, ETH_HLEN);
 
                        /*   leave off any PAD octets.  */
                        skb_trim(skb, proto);
@@ -144,7 +144,7 @@ int skb_ether_to_p80211(wlandevice_t *wlandev, u32 ethconv,
                        /* it's DIXII, time for some conversion */
 
                        /* trim off ethernet header */
-                       skb_pull(skb, WLAN_ETHHDR_LEN);
+                       skb_pull(skb, ETH_HLEN);
 
                        /* tack on SNAP */
                        e_snap =
@@ -281,8 +281,8 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
        u16 fc;
        unsigned int payload_length;
        unsigned int payload_offset;
-       u8 daddr[WLAN_ETHADDR_LEN];
-       u8 saddr[WLAN_ETHADDR_LEN];
+       u8 daddr[ETH_ALEN];
+       u8 saddr[ETH_ALEN];
        union p80211_hdr *w_hdr;
        struct wlan_ethhdr *e_hdr;
        struct wlan_llc *e_llc;
@@ -298,16 +298,16 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
        /* setup some vars for convenience */
        fc = le16_to_cpu(w_hdr->a3.fc);
        if ((WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 0)) {
-               memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN);
-               memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN);
+               ether_addr_copy(daddr, w_hdr->a3.a1);
+               ether_addr_copy(saddr, w_hdr->a3.a2);
        } else if ((WLAN_GET_FC_TODS(fc) == 0)
                        && (WLAN_GET_FC_FROMDS(fc) == 1)) {
-               memcpy(daddr, w_hdr->a3.a1, WLAN_ETHADDR_LEN);
-               memcpy(saddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN);
+               ether_addr_copy(daddr, w_hdr->a3.a1);
+               ether_addr_copy(saddr, w_hdr->a3.a3);
        } else if ((WLAN_GET_FC_TODS(fc) == 1)
                        && (WLAN_GET_FC_FROMDS(fc) == 0)) {
-               memcpy(daddr, w_hdr->a3.a3, WLAN_ETHADDR_LEN);
-               memcpy(saddr, w_hdr->a3.a2, WLAN_ETHADDR_LEN);
+               ether_addr_copy(daddr, w_hdr->a3.a3);
+               ether_addr_copy(saddr, w_hdr->a3.a2);
        } else {
                payload_offset = WLAN_HDR_A4_LEN;
                if (payload_length < WLAN_HDR_A4_LEN - WLAN_HDR_A3_LEN) {
@@ -315,8 +315,8 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
                        return 1;
                }
                payload_length -= (WLAN_HDR_A4_LEN - WLAN_HDR_A3_LEN);
-               memcpy(daddr, w_hdr->a4.a3, WLAN_ETHADDR_LEN);
-               memcpy(saddr, w_hdr->a4.a4, WLAN_ETHADDR_LEN);
+               ether_addr_copy(daddr, w_hdr->a4.a3);
+               ether_addr_copy(saddr, w_hdr->a4.a4);
        }
 
        /* perform de-wep if necessary.. */
@@ -360,16 +360,16 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
        /* Test for the various encodings */
        if ((payload_length >= sizeof(struct wlan_ethhdr)) &&
            (e_llc->dsap != 0xaa || e_llc->ssap != 0xaa) &&
-           ((memcmp(daddr, e_hdr->daddr, WLAN_ETHADDR_LEN) == 0) ||
-            (memcmp(saddr, e_hdr->saddr, WLAN_ETHADDR_LEN) == 0))) {
+           ((!ether_addr_equal_unaligned(daddr, e_hdr->daddr)) ||
+            (!ether_addr_equal_unaligned(saddr, e_hdr->saddr)))) {
                pr_debug("802.3 ENCAP len: %d\n", payload_length);
                /* 802.3 Encapsulated */
                /* Test for an overlength frame */
-               if (payload_length > (netdev->mtu + WLAN_ETHHDR_LEN)) {
+               if (payload_length > (netdev->mtu + ETH_HLEN)) {
                        /* A bogus length ethfrm has been encap'd. */
                        /* Is someone trying an oflow attack? */
                        netdev_err(netdev, "ENCAP frame too large (%d > %d)\n",
-                              payload_length, netdev->mtu + WLAN_ETHHDR_LEN);
+                              payload_length, netdev->mtu + ETH_HLEN);
                        return 1;
                }
 
@@ -406,9 +406,9 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
                skb_pull(skb, payload_offset);
 
                /* create 802.3 header at beginning of skb. */
-               e_hdr = (struct wlan_ethhdr *) skb_push(skb, WLAN_ETHHDR_LEN);
-               memcpy(e_hdr->daddr, daddr, WLAN_ETHADDR_LEN);
-               memcpy(e_hdr->saddr, saddr, WLAN_ETHADDR_LEN);
+               e_hdr = (struct wlan_ethhdr *)skb_push(skb, ETH_HLEN);
+               ether_addr_copy(e_hdr->daddr, daddr);
+               ether_addr_copy(e_hdr->saddr, saddr);
                e_hdr->type = htons(payload_length);
 
                /* chop off the 802.11 CRC */
@@ -446,10 +446,10 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
                skb_pull(skb, sizeof(struct wlan_snap));
 
                /* create 802.3 header at beginning of skb. */
-               e_hdr = (struct wlan_ethhdr *) skb_push(skb, WLAN_ETHHDR_LEN);
+               e_hdr = (struct wlan_ethhdr *)skb_push(skb, ETH_HLEN);
                e_hdr->type = e_snap->type;
-               memcpy(e_hdr->daddr, daddr, WLAN_ETHADDR_LEN);
-               memcpy(e_hdr->saddr, saddr, WLAN_ETHADDR_LEN);
+               ether_addr_copy(e_hdr->daddr, daddr);
+               ether_addr_copy(e_hdr->saddr, saddr);
 
                /* chop off the 802.11 CRC */
                skb_trim(skb, skb->len - WLAN_CRC_LEN);
@@ -473,9 +473,9 @@ int skb_p80211_to_ether(wlandevice_t *wlandev, u32 ethconv,
                skb_pull(skb, payload_offset);
 
                /* create 802.3 header at beginning of skb. */
-               e_hdr = (struct wlan_ethhdr *) skb_push(skb, WLAN_ETHHDR_LEN);
-               memcpy(e_hdr->daddr, daddr, WLAN_ETHADDR_LEN);
-               memcpy(e_hdr->saddr, saddr, WLAN_ETHADDR_LEN);
+               e_hdr = (struct wlan_ethhdr *)skb_push(skb, ETH_HLEN);
+               ether_addr_copy(e_hdr->daddr, daddr);
+               ether_addr_copy(e_hdr->saddr, saddr);
                e_hdr->type = htons(payload_length);
 
                /* chop off the 802.11 CRC */
index e031a74d2ad44aa5a11746927af892977f70e4b5..8c10357bedf0f51dda4212964c8959a33c91c59e 100644 (file)
 #ifndef _LINUX_P80211CONV_H
 #define _LINUX_P80211CONV_H
 
-#define WLAN_ETHADDR_LEN       6
 #define WLAN_IEEE_OUI_LEN      3
 
 #define WLAN_ETHCONV_ENCAP     1
 #define WLAN_ETHCONV_8021h     3
 
-#define WLAN_ETHHDR_LEN                14
-
 #define P80211CAPTURE_VERSION  0x80211001
 
 #define        P80211_FRMMETA_MAGIC    0x802110
@@ -131,8 +128,8 @@ struct p80211_metawep {
 
 /* local ether header type */
 struct wlan_ethhdr {
-       u8 daddr[WLAN_ETHADDR_LEN];
-       u8 saddr[WLAN_ETHADDR_LEN];
+       u8 daddr[ETH_ALEN];
+       u8 saddr[ETH_ALEN];
        u16 type;
 } __packed;
 
diff --git a/drivers/staging/wlan-ng/p80211meta.h b/drivers/staging/wlan-ng/p80211meta.h
deleted file mode 100644 (file)
index c5f1a63..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/* p80211meta.h
-*
-* Macros, constants, types, and funcs for p80211 metadata
-*
-* Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
-* --------------------------------------------------------------------
-*
-* linux-wlan
-*
-*   The contents of this file are subject to the Mozilla Public
-*   License Version 1.1 (the "License"); you may not use this file
-*   except in compliance with the License. You may obtain a copy of
-*   the License at http://www.mozilla.org/MPL/
-*
-*   Software distributed under the License is distributed on an "AS
-*   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
-*   implied. See the License for the specific language governing
-*   rights and limitations under the License.
-*
-*   Alternatively, the contents of this file may be used under the
-*   terms of the GNU Public License version 2 (the "GPL"), in which
-*   case the provisions of the GPL are applicable instead of the
-*   above.  If you wish to allow the use of your version of this file
-*   only under the terms of the GPL and not to allow others to use
-*   your version of this file under the MPL, indicate your decision
-*   by deleting the provisions above and replace them with the notice
-*   and other provisions required by the GPL.  If you do not delete
-*   the provisions above, a recipient may use your version of this
-*   file under either the MPL or the GPL.
-*
-* --------------------------------------------------------------------
-*
-* Inquiries regarding the linux-wlan Open Source project can be
-* made directly to:
-*
-* AbsoluteValue Systems Inc.
-* info@linux-wlan.com
-* http://www.linux-wlan.com
-*
-* --------------------------------------------------------------------
-*
-* Portions of the development of this software were funded by
-* Intersil Corporation as part of PRISM(R) chipset product development.
-*
-* --------------------------------------------------------------------
-*
-* This file declares some of the constants and types used in various
-* parts of the linux-wlan system.
-*
-* Notes:
-*   - Constant values are always in HOST byte order.
-*
-* All functions and statics declared here are implemented in p80211types.c
-*   --------------------------------------------------------------------
-*/
-
-#ifndef _P80211META_H
-#define _P80211META_H
-
-/*----------------------------------------------------------------*/
-/* The following structure types are used for the metadata */
-/* representation of category list metadata, group list metadata, */
-/* and data item metadata for both Mib and Messages. */
-
-struct p80211meta {
-       char *name;             /* data item name */
-       u32 did;                /* partial did */
-       u32 flags;              /* set of various flag bits */
-       u32 min;                /* min value of a BOUNDEDint */
-       u32 max;                /* max value of a BOUNDEDint */
-
-       u32 maxlen;             /* maxlen of a OCTETSTR or DISPLAYSTR */
-       u32 minlen;             /* minlen of a OCTETSTR or DISPLAYSTR */
-       p80211enum_t *enumptr;  /* ptr to the enum type for ENUMint */
-       p80211_totext_t totextptr;      /* ptr to totext conversion function */
-       p80211_fromtext_t fromtextptr;  /* ptr to totext conversion function */
-       p80211_valid_t validfunptr;     /* ptr to totext conversion function */
-};
-
-struct grplistitem {
-       char *name;
-       struct p80211meta *itemlist;
-};
-
-struct catlistitem {
-       char *name;
-       struct grplistitem *grplist;
-};
-
-#endif /* _P80211META_H */
index fe36613589ae4c03d01ea6ddeb4f60aac1732a16..8fc80df0b53ef59735f9ff0417522efb0d4f2d46 100644 (file)
@@ -584,13 +584,12 @@ static int mkimage(struct imgchunk *clist, unsigned int *ccnt)
 ----------------------------------------------------------------*/
 static int mkpdrlist(struct pda *pda)
 {
-       int result = 0;
        u16 *pda16 = (u16 *) pda->buf;
        int curroff;            /* in 'words' */
 
        pda->nrec = 0;
        curroff = 0;
-       while (curroff < (HFA384x_PDA_LEN_MAX / 2) &&
+       while (curroff < (HFA384x_PDA_LEN_MAX / 2 - 1) &&
               le16_to_cpu(pda16[curroff + 1]) != HFA384x_PDR_END_OF_PDA) {
                pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
 
@@ -626,16 +625,14 @@ static int mkpdrlist(struct pda *pda)
                curroff += le16_to_cpu(pda16[curroff]) + 1;
 
        }
-       if (curroff >= (HFA384x_PDA_LEN_MAX / 2)) {
+       if (curroff >= (HFA384x_PDA_LEN_MAX / 2 - 1)) {
                pr_err("no end record found or invalid lengths in PDR data, exiting. %x %d\n",
                       curroff, pda->nrec);
                return 1;
        }
-       if (le16_to_cpu(pda16[curroff + 1]) == HFA384x_PDR_END_OF_PDA) {
-               pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
-               (pda->nrec)++;
-       }
-       return result;
+       pda->rec[pda->nrec] = (hfa384x_pdrec_t *) &(pda16[curroff]);
+       (pda->nrec)++;
+       return 0;
 }
 
 /*----------------------------------------------------------------
index 0329c521d17c5c0ee5baa237c81383021daefe24..c57f48a1d8df756169116305f5cca6495fad413e 100644 (file)
@@ -1,54 +1,54 @@
 /* src/prism2/driver/prism2sta.c
-*
-* Implements the station functionality for prism2
-*
-* Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
-* --------------------------------------------------------------------
-*
-* linux-wlan
-*
-*   The contents of this file are subject to the Mozilla Public
-*   License Version 1.1 (the "License"); you may not use this file
-*   except in compliance with the License. You may obtain a copy of
-*   the License at http://www.mozilla.org/MPL/
-*
-*   Software distributed under the License is distributed on an "AS
-*   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
-*   implied. See the License for the specific language governing
-*   rights and limitations under the License.
-*
-*   Alternatively, the contents of this file may be used under the
-*   terms of the GNU Public License version 2 (the "GPL"), in which
-*   case the provisions of the GPL are applicable instead of the
-*   above.  If you wish to allow the use of your version of this file
-*   only under the terms of the GPL and not to allow others to use
-*   your version of this file under the MPL, indicate your decision
-*   by deleting the provisions above and replace them with the notice
-*   and other provisions required by the GPL.  If you do not delete
-*   the provisions above, a recipient may use your version of this
-*   file under either the MPL or the GPL.
-*
-* --------------------------------------------------------------------
-*
-* Inquiries regarding the linux-wlan Open Source project can be
-* made directly to:
-*
-* AbsoluteValue Systems Inc.
-* info@linux-wlan.com
-* http://www.linux-wlan.com
-*
-* --------------------------------------------------------------------
-*
-* Portions of the development of this software were funded by
-* Intersil Corporation as part of PRISM(R) chipset product development.
-*
-* --------------------------------------------------------------------
-*
-* This file implements the module and linux pcmcia routines for the
-* prism2 driver.
-*
-* --------------------------------------------------------------------
-*/
+ *
+ * Implements the station functionality for prism2
+ *
+ * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
+ * --------------------------------------------------------------------
+ *
+ * linux-wlan
+ *
+ *   The contents of this file are subject to the Mozilla Public
+ *   License Version 1.1 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.mozilla.org/MPL/
+ *
+ *   Software distributed under the License is distributed on an "AS
+ *   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ *   implied. See the License for the specific language governing
+ *   rights and limitations under the License.
+ *
+ *   Alternatively, the contents of this file may be used under the
+ *   terms of the GNU Public License version 2 (the "GPL"), in which
+ *   case the provisions of the GPL are applicable instead of the
+ *   above.  If you wish to allow the use of your version of this file
+ *   only under the terms of the GPL and not to allow others to use
+ *   your version of this file under the MPL, indicate your decision
+ *   by deleting the provisions above and replace them with the notice
+ *   and other provisions required by the GPL.  If you do not delete
+ *   the provisions above, a recipient may use your version of this
+ *   file under either the MPL or the GPL.
+ *
+ * --------------------------------------------------------------------
+ *
+ * Inquiries regarding the linux-wlan Open Source project can be
+ * made directly to:
+ *
+ * AbsoluteValue Systems Inc.
+ * info@linux-wlan.com
+ * http://www.linux-wlan.com
+ *
+ * --------------------------------------------------------------------
+ *
+ * Portions of the development of this software were funded by
+ * Intersil Corporation as part of PRISM(R) chipset product development.
+ *
+ * --------------------------------------------------------------------
+ *
+ * This file implements the module and linux pcmcia routines for the
+ * prism2 driver.
+ *
+ * --------------------------------------------------------------------
+ */
 
 #include <linux/module.h>
 #include <linux/kernel.h>
@@ -130,27 +130,27 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
                                    hfa384x_InfFrame_t *inf);
 
-/*----------------------------------------------------------------
-* prism2sta_open
-*
-* WLAN device open method.  Called from p80211netdev when kernel
-* device open (start) method is called in response to the
-* SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
-* from clear to set.
-*
-* Arguments:
-     wlandev         wlan device structure
-*
-* Returns:
-     0       success
-     >0      f/w reported error
-     <0      driver reported error
-*
-* Side effects:
-*
-* Call context:
-     process thread
-----------------------------------------------------------------*/
+/*
+ * prism2sta_open
+ *
+ * WLAN device open method.  Called from p80211netdev when kernel
+ * device open (start) method is called in response to the
+ * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
+ * from clear to set.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *
+ * Returns:
+ *     0       success
+ *     >0      f/w reported error
+ *     <0      driver reported error
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     process thread
+ */
 static int prism2sta_open(wlandevice_t *wlandev)
 {
        /* We don't currently have to do anything else.
@@ -164,27 +164,27 @@ static int prism2sta_open(wlandevice_t *wlandev)
        return 0;
 }
 
-/*----------------------------------------------------------------
-* prism2sta_close
-*
-* WLAN device close method.  Called from p80211netdev when kernel
-* device close method is called in response to the
-* SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
-* from set to clear.
-*
-* Arguments:
-     wlandev         wlan device structure
-*
-* Returns:
-     0       success
-     >0      f/w reported error
-     <0      driver reported error
-*
-* Side effects:
-*
-* Call context:
-     process thread
-----------------------------------------------------------------*/
+/*
+ * prism2sta_close
+ *
+ * WLAN device close method.  Called from p80211netdev when kernel
+ * device close method is called in response to the
+ * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP
+ * from set to clear.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *
+ * Returns:
+ *     0       success
+ *     >0      f/w reported error
+ *     <0      driver reported error
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     process thread
+ */
 static int prism2sta_close(wlandevice_t *wlandev)
 {
        /* We don't currently have to do anything else.
@@ -196,48 +196,48 @@ static int prism2sta_close(wlandevice_t *wlandev)
        return 0;
 }
 
-/*----------------------------------------------------------------
-* prism2sta_reset
-*
-* Currently not implemented.
-*
-* Arguments:
-     wlandev         wlan device structure
-     none
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     process thread
-----------------------------------------------------------------*/
+/*
+ * prism2sta_reset
+ *
+ * Currently not implemented.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     none
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     process thread
+ */
 static void prism2sta_reset(wlandevice_t *wlandev)
 {
 }
 
-/*----------------------------------------------------------------
-* prism2sta_txframe
-*
-* Takes a frame from p80211 and queues it for transmission.
-*
-* Arguments:
-     wlandev         wlan device structure
-     pb              packet buffer struct.  Contains an 802.11
-                     data frame.
-*       p80211_hdr      points to the 802.11 header for the packet.
-* Returns:
-     0               Success and more buffs available
-     1               Success but no more buffs
-     2               Allocation failure
-     4               Buffer full or queue busy
-*
-* Side effects:
-*
-* Call context:
-     process thread
-----------------------------------------------------------------*/
+/*
+ * prism2sta_txframe
+ *
+ * Takes a frame from p80211 and queues it for transmission.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     pb              packet buffer struct.  Contains an 802.11
+ *                     data frame.
+ *       p80211_hdr      points to the 802.11 header for the packet.
+ * Returns:
+ *     0               Success and more buffs available
+ *     1               Success but no more buffs
+ *     2               Allocation failure
+ *     4               Buffer full or queue busy
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     process thread
+ */
 static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
                             union p80211_hdr *p80211_hdr,
                             struct p80211_metawep *p80211_wep)
@@ -253,30 +253,30 @@ static int prism2sta_txframe(wlandevice_t *wlandev, struct sk_buff *skb,
        return hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep);
 }
 
-/*----------------------------------------------------------------
-* prism2sta_mlmerequest
-*
-* wlan command message handler.  All we do here is pass the message
-* over to the prism2sta_mgmt_handler.
-*
-* Arguments:
-     wlandev         wlan device structure
-     msg             wlan command message
-* Returns:
-     0               success
-     <0              successful acceptance of message, but we're
-                     waiting for an async process to finish before
-                     we're done with the msg.  When the asynch
-                     process is done, we'll call the p80211
-                     function p80211req_confirm() .
-     >0              An error occurred while we were handling
-                     the message.
-*
-* Side effects:
-*
-* Call context:
-     process thread
-----------------------------------------------------------------*/
+/*
+ * prism2sta_mlmerequest
+ *
+ * wlan command message handler.  All we do here is pass the message
+ * over to the prism2sta_mgmt_handler.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     msg             wlan command message
+ * Returns:
+ *     0               success
+ *     <0              successful acceptance of message, but we're
+ *                     waiting for an async process to finish before
+ *                     we're done with the msg.  When the asynch
+ *                     process is done, we'll call the p80211
+ *                     function p80211req_confirm() .
+ *     >0              An error occurred while we were handling
+ *                     the message.
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     process thread
+ */
 static int prism2sta_mlmerequest(wlandevice_t *wlandev, struct p80211msg *msg)
 {
        hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
@@ -386,27 +386,27 @@ static int prism2sta_mlmerequest(wlandevice_t *wlandev, struct p80211msg *msg)
        return result;
 }
 
-/*----------------------------------------------------------------
-* prism2sta_ifstate
-*
-* Interface state.  This is the primary WLAN interface enable/disable
-* handler.  Following the driver/load/deviceprobe sequence, this
-* function must be called with a state of "enable" before any other
-* commands will be accepted.
-*
-* Arguments:
-     wlandev         wlan device structure
-     msgp            ptr to msg buffer
-*
-* Returns:
-     A p80211 message resultcode value.
-*
-* Side effects:
-*
-* Call context:
-     process thread  (usually)
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_ifstate
+ *
+ * Interface state.  This is the primary WLAN interface enable/disable
+ * handler.  Following the driver/load/deviceprobe sequence, this
+ * function must be called with a state of "enable" before any other
+ * commands will be accepted.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     msgp            ptr to msg buffer
+ *
+ * Returns:
+ *     A p80211 message resultcode value.
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     process thread  (usually)
+ *     interrupt
+ */
 u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
 {
        hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
@@ -561,25 +561,25 @@ u32 prism2sta_ifstate(wlandevice_t *wlandev, u32 ifstate)
        return result;
 }
 
-/*----------------------------------------------------------------
-* prism2sta_getcardinfo
-*
-* Collect the NICID, firmware version and any other identifiers
-* we'd like to have in host-side data structures.
-*
-* Arguments:
-     wlandev         wlan device structure
-*
-* Returns:
-     0       success
-     >0      f/w reported error
-     <0      driver reported error
-*
-* Side effects:
-*
-* Call context:
-     Either.
-----------------------------------------------------------------*/
+/*
+ * prism2sta_getcardinfo
+ *
+ * Collect the NICID, firmware version and any other identifiers
+ * we'd like to have in host-side data structures.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *
+ * Returns:
+ *     0       success
+ *     >0      f/w reported error
+ *     <0      driver reported error
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     Either.
+ */
 static int prism2sta_getcardinfo(wlandevice_t *wlandev)
 {
        int result = 0;
@@ -677,7 +677,8 @@ static int prism2sta_getcardinfo(wlandevice_t *wlandev)
        }
 
        /* get all the Compatibility range, modem interface supplier
-          fields in byte order */
+        * fields in byte order
+        */
        hw->cap_sup_mfi.role = le16_to_cpu(hw->cap_sup_mfi.role);
        hw->cap_sup_mfi.id = le16_to_cpu(hw->cap_sup_mfi.id);
        hw->cap_sup_mfi.variant = le16_to_cpu(hw->cap_sup_mfi.variant);
@@ -700,7 +701,8 @@ static int prism2sta_getcardinfo(wlandevice_t *wlandev)
        }
 
        /* get all the Compatibility range, controller interface supplier
-          fields in byte order */
+        * fields in byte order
+        */
        hw->cap_sup_cfi.role = le16_to_cpu(hw->cap_sup_cfi.role);
        hw->cap_sup_cfi.id = le16_to_cpu(hw->cap_sup_cfi.id);
        hw->cap_sup_cfi.variant = le16_to_cpu(hw->cap_sup_cfi.variant);
@@ -723,7 +725,8 @@ static int prism2sta_getcardinfo(wlandevice_t *wlandev)
        }
 
        /* get all the Compatibility range, primary firmware supplier
-          fields in byte order */
+        * fields in byte order
+        */
        hw->cap_sup_pri.role = le16_to_cpu(hw->cap_sup_pri.role);
        hw->cap_sup_pri.id = le16_to_cpu(hw->cap_sup_pri.id);
        hw->cap_sup_pri.variant = le16_to_cpu(hw->cap_sup_pri.variant);
@@ -746,7 +749,8 @@ static int prism2sta_getcardinfo(wlandevice_t *wlandev)
        }
 
        /* get all the Compatibility range, station firmware supplier
-          fields in byte order */
+        * fields in byte order
+        */
        hw->cap_sup_sta.role = le16_to_cpu(hw->cap_sup_sta.role);
        hw->cap_sup_sta.id = le16_to_cpu(hw->cap_sup_sta.id);
        hw->cap_sup_sta.variant = le16_to_cpu(hw->cap_sup_sta.variant);
@@ -777,7 +781,8 @@ static int prism2sta_getcardinfo(wlandevice_t *wlandev)
        }
 
        /* get all the Compatibility range, primary f/w actor, CFI supplier
-          fields in byte order */
+        * fields in byte order
+        */
        hw->cap_act_pri_cfi.role = le16_to_cpu(hw->cap_act_pri_cfi.role);
        hw->cap_act_pri_cfi.id = le16_to_cpu(hw->cap_act_pri_cfi.id);
        hw->cap_act_pri_cfi.variant = le16_to_cpu(hw->cap_act_pri_cfi.variant);
@@ -800,7 +805,8 @@ static int prism2sta_getcardinfo(wlandevice_t *wlandev)
        }
 
        /* get all the Compatibility range, station f/w actor, CFI supplier
-          fields in byte order */
+        * fields in byte order
+        */
        hw->cap_act_sta_cfi.role = le16_to_cpu(hw->cap_act_sta_cfi.role);
        hw->cap_act_sta_cfi.id = le16_to_cpu(hw->cap_act_sta_cfi.id);
        hw->cap_act_sta_cfi.variant = le16_to_cpu(hw->cap_act_sta_cfi.variant);
@@ -823,7 +829,8 @@ static int prism2sta_getcardinfo(wlandevice_t *wlandev)
        }
 
        /* get all the Compatibility range, station f/w actor, MFI supplier
-          fields in byte order */
+        * fields in byte order
+        */
        hw->cap_act_sta_mfi.role = le16_to_cpu(hw->cap_act_sta_mfi.role);
        hw->cap_act_sta_mfi.id = le16_to_cpu(hw->cap_act_sta_mfi.id);
        hw->cap_act_sta_mfi.variant = le16_to_cpu(hw->cap_act_sta_mfi.variant);
@@ -884,24 +891,24 @@ done:
        return result;
 }
 
-/*----------------------------------------------------------------
-* prism2sta_globalsetup
-*
-* Set any global RIDs that we want to set at device activation.
-*
-* Arguments:
-     wlandev         wlan device structure
-*
-* Returns:
-     0       success
-     >0      f/w reported error
-     <0      driver reported error
-*
-* Side effects:
-*
-* Call context:
-     process thread
-----------------------------------------------------------------*/
+/*
+ * prism2sta_globalsetup
+ *
+ * Set any global RIDs that we want to set at device activation.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *
+ * Returns:
+ *     0       success
+ *     >0      f/w reported error
+ *     <0      driver reported error
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     process thread
+ */
 static int prism2sta_globalsetup(wlandevice_t *wlandev)
 {
        hfa384x_t *hw = (hfa384x_t *) wlandev->priv;
@@ -934,47 +941,47 @@ exit:
        return result;
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_handover
-*
-* Handles the receipt of a Handover info frame. Should only be present
-* in APs only.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_handover
+ *
+ * Handles the receipt of a Handover info frame. Should only be present
+ * in APs only.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_handover(wlandevice_t *wlandev,
                                   hfa384x_InfFrame_t *inf)
 {
        pr_debug("received infoframe:HANDOVER (unhandled)\n");
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_tallies
-*
-* Handles the receipt of a CommTallies info frame.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_tallies
+ *
+ * Handles the receipt of a CommTallies info frame.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_tallies(wlandevice_t *wlandev,
                                  hfa384x_InfFrame_t *inf)
 {
@@ -986,8 +993,8 @@ static void prism2sta_inf_tallies(wlandevice_t *wlandev,
        int cnt;
 
        /*
-        ** Determine if these are 16-bit or 32-bit tallies, based on the
-        ** record length of the info record.
+        * Determine if these are 16-bit or 32-bit tallies, based on the
+        * record length of the info record.
         */
 
        cnt = sizeof(hfa384x_CommTallies32_t) / sizeof(u32);
@@ -1004,23 +1011,23 @@ static void prism2sta_inf_tallies(wlandevice_t *wlandev,
        }
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_scanresults
-*
-* Handles the receipt of a Scan Results info frame.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_scanresults
+ *
+ * Handles the receipt of a Scan Results info frame.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
                                      hfa384x_InfFrame_t *inf)
 {
@@ -1060,23 +1067,23 @@ static void prism2sta_inf_scanresults(wlandevice_t *wlandev,
        }
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_hostscanresults
-*
-* Handles the receipt of a Scan Results info frame.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_hostscanresults
+ *
+ * Handles the receipt of a Scan Results info frame.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
                                          hfa384x_InfFrame_t *inf)
 {
@@ -1101,23 +1108,23 @@ static void prism2sta_inf_hostscanresults(wlandevice_t *wlandev,
        wake_up_interruptible(&hw->cmdq);
 };
 
-/*----------------------------------------------------------------
-* prism2sta_inf_chinforesults
-*
-* Handles the receipt of a Channel Info Results info frame.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_chinforesults
+ *
+ * Handles the receipt of a Channel Info Results info frame.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_chinforesults(wlandevice_t *wlandev,
                                        hfa384x_InfFrame_t *inf)
 {
@@ -1414,23 +1421,23 @@ void prism2sta_processing_defer(struct work_struct *data)
        wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED);
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_linkstatus
-*
-* Handles the receipt of a Link Status info frame.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_linkstatus
+ *
+ * Handles the receipt of a Link Status info frame.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
                                     hfa384x_InfFrame_t *inf)
 {
@@ -1441,24 +1448,24 @@ static void prism2sta_inf_linkstatus(wlandevice_t *wlandev,
        schedule_work(&hw->link_bh);
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_assocstatus
-*
-* Handles the receipt of an Association Status info frame. Should
-* be present in APs only.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_assocstatus
+ *
+ * Handles the receipt of an Association Status info frame. Should
+ * be present in APs only.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
                                      hfa384x_InfFrame_t *inf)
 {
@@ -1471,19 +1478,19 @@ static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
        rec.reason = le16_to_cpu(rec.reason);
 
        /*
-        ** Find the address in the list of authenticated stations.
-        ** If it wasn't found, then this address has not been previously
-        ** authenticated and something weird has happened if this is
-        ** anything other than an "authentication failed" message.
-        ** If the address was found, then set the "associated" flag for
-        ** that station, based on whether the station is associating or
-        ** losing its association.  Something weird has also happened
-        ** if we find the address in the list of authenticated stations
-        ** but we are getting an "authentication failed" message.
+        * Find the address in the list of authenticated stations.
+        * If it wasn't found, then this address has not been previously
+        * authenticated and something weird has happened if this is
+        * anything other than an "authentication failed" message.
+        * If the address was found, then set the "associated" flag for
+        * that station, based on whether the station is associating or
+        * losing its association.  Something weird has also happened
+        * if we find the address in the list of authenticated stations
+        * but we are getting an "authentication failed" message.
         */
 
        for (i = 0; i < hw->authlist.cnt; i++)
-               if (memcmp(rec.sta_addr, hw->authlist.addr[i], ETH_ALEN) == 0)
+               if (ether_addr_equal(rec.sta_addr, hw->authlist.addr[i]))
                        break;
 
        if (i >= hw->authlist.cnt) {
@@ -1501,25 +1508,25 @@ static void prism2sta_inf_assocstatus(wlandevice_t *wlandev,
        }
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_authreq
-*
-* Handles the receipt of an Authentication Request info frame. Should
-* be present in APs only.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-*
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_authreq
+ *
+ * Handles the receipt of an Authentication Request info frame. Should
+ * be present in APs only.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ *
+ */
 static void prism2sta_inf_authreq(wlandevice_t *wlandev,
                                  hfa384x_InfFrame_t *inf)
 {
@@ -1545,28 +1552,28 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
        u8 *addr;
 
        /*
-        ** Build the AuthenticateStation record.  Initialize it for denying
-        ** authentication.
+        * Build the AuthenticateStation record.  Initialize it for denying
+        * authentication.
         */
 
        ether_addr_copy(rec.address, inf->info.authreq.sta_addr);
        rec.status = P80211ENUM_status_unspec_failure;
 
        /*
-        ** Authenticate based on the access mode.
+        * Authenticate based on the access mode.
         */
 
        switch (hw->accessmode) {
        case WLAN_ACCESS_NONE:
 
                /*
-                ** Deny all new authentications.  However, if a station
-                ** is ALREADY authenticated, then accept it.
+                * Deny all new authentications.  However, if a station
+                * is ALREADY authenticated, then accept it.
                 */
 
                for (i = 0; i < hw->authlist.cnt; i++)
-                       if (memcmp(rec.address, hw->authlist.addr[i],
-                                  ETH_ALEN) == 0) {
+                       if (ether_addr_equal(rec.address,
+                                            hw->authlist.addr[i])) {
                                rec.status = P80211ENUM_status_successful;
                                break;
                        }
@@ -1576,7 +1583,7 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
        case WLAN_ACCESS_ALL:
 
                /*
-                ** Allow all authentications.
+                * Allow all authentications.
                 */
 
                rec.status = P80211ENUM_status_successful;
@@ -1585,13 +1592,13 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
        case WLAN_ACCESS_ALLOW:
 
                /*
-                ** Only allow the authentication if the MAC address
-                ** is in the list of allowed addresses.
-                **
-                ** Since this is the interrupt handler, we may be here
-                ** while the access list is in the middle of being
-                ** updated.  Choose the list which is currently okay.
-                ** See "prism2mib_priv_accessallow()" for details.
+                * Only allow the authentication if the MAC address
+                * is in the list of allowed addresses.
+                *
+                * Since this is the interrupt handler, we may be here
+                * while the access list is in the middle of being
+                * updated.  Choose the list which is currently okay.
+                * See "prism2mib_priv_accessallow()" for details.
                 */
 
                if (hw->allow.modify == 0) {
@@ -1603,7 +1610,7 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
                }
 
                for (i = 0; i < cnt; i++, addr += ETH_ALEN)
-                       if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
+                       if (ether_addr_equal(rec.address, addr)) {
                                rec.status = P80211ENUM_status_successful;
                                break;
                        }
@@ -1613,13 +1620,13 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
        case WLAN_ACCESS_DENY:
 
                /*
-                ** Allow the authentication UNLESS the MAC address is
-                ** in the list of denied addresses.
-                **
-                ** Since this is the interrupt handler, we may be here
-                ** while the access list is in the middle of being
-                ** updated.  Choose the list which is currently okay.
-                ** See "prism2mib_priv_accessdeny()" for details.
+                * Allow the authentication UNLESS the MAC address is
+                * in the list of denied addresses.
+                *
+                * Since this is the interrupt handler, we may be here
+                * while the access list is in the middle of being
+                * updated.  Choose the list which is currently okay.
+                * See "prism2mib_priv_accessdeny()" for details.
                 */
 
                if (hw->deny.modify == 0) {
@@ -1633,7 +1640,7 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
                rec.status = P80211ENUM_status_successful;
 
                for (i = 0; i < cnt; i++, addr += ETH_ALEN)
-                       if (memcmp(rec.address, addr, ETH_ALEN) == 0) {
+                       if (ether_addr_equal(rec.address, addr)) {
                                rec.status = P80211ENUM_status_unspec_failure;
                                break;
                        }
@@ -1642,20 +1649,20 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
        }
 
        /*
-        ** If the authentication is okay, then add the MAC address to the
-        ** list of authenticated stations.  Don't add the address if it
-        ** is already in the list. (802.11b does not seem to disallow
-        ** a station from issuing an authentication request when the
-        ** station is already authenticated. Does this sort of thing
-        ** ever happen?  We might as well do the check just in case.)
+        * If the authentication is okay, then add the MAC address to the
+        * list of authenticated stations.  Don't add the address if it
+        * is already in the list. (802.11b does not seem to disallow
+        * a station from issuing an authentication request when the
+        * station is already authenticated. Does this sort of thing
+        * ever happen?  We might as well do the check just in case.)
         */
 
        added = 0;
 
        if (rec.status == P80211ENUM_status_successful) {
                for (i = 0; i < hw->authlist.cnt; i++)
-                       if (memcmp(rec.address, hw->authlist.addr[i], ETH_ALEN)
-                           == 0)
+                       if (ether_addr_equal(rec.address,
+                                            hw->authlist.addr[i]))
                                break;
 
                if (i >= hw->authlist.cnt) {
@@ -1672,9 +1679,9 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
        }
 
        /*
-        ** Send back the results of the authentication.  If this doesn't work,
-        ** then make sure to remove the address from the authenticated list if
-        ** it was added.
+        * Send back the results of the authentication.  If this doesn't work,
+        * then make sure to remove the address from the authenticated list if
+        * it was added.
         */
 
        rec.status = cpu_to_le16(rec.status);
@@ -1691,24 +1698,24 @@ static void prism2sta_inf_authreq_defer(wlandevice_t *wlandev,
        }
 }
 
-/*----------------------------------------------------------------
-* prism2sta_inf_psusercnt
-*
-* Handles the receipt of a PowerSaveUserCount info frame. Should
-* be present in APs only.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to info frame (contents in hfa384x order)
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_inf_psusercnt
+ *
+ * Handles the receipt of a PowerSaveUserCount info frame. Should
+ * be present in APs only.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to info frame (contents in hfa384x order)
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
                                    hfa384x_InfFrame_t *inf)
 {
@@ -1717,23 +1724,23 @@ static void prism2sta_inf_psusercnt(wlandevice_t *wlandev,
        hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt);
 }
 
-/*----------------------------------------------------------------
-* prism2sta_ev_info
-*
-* Handles the Info event.
-*
-* Arguments:
-     wlandev         wlan device structure
-     inf             ptr to a generic info frame
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_ev_info
+ *
+ * Handles the Info event.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     inf             ptr to a generic info frame
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
 {
        inf->infotype = le16_to_cpu(inf->infotype);
@@ -1782,46 +1789,46 @@ void prism2sta_ev_info(wlandevice_t *wlandev, hfa384x_InfFrame_t *inf)
        }
 }
 
-/*----------------------------------------------------------------
-* prism2sta_ev_txexc
-*
-* Handles the TxExc event.  A Transmit Exception event indicates
-* that the MAC's TX process was unsuccessful - so the packet did
-* not get transmitted.
-*
-* Arguments:
-     wlandev         wlan device structure
-     status          tx frame status word
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_ev_txexc
+ *
+ * Handles the TxExc event.  A Transmit Exception event indicates
+ * that the MAC's TX process was unsuccessful - so the packet did
+ * not get transmitted.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     status          tx frame status word
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 void prism2sta_ev_txexc(wlandevice_t *wlandev, u16 status)
 {
        pr_debug("TxExc status=0x%x.\n", status);
 }
 
-/*----------------------------------------------------------------
-* prism2sta_ev_tx
-*
-* Handles the Tx event.
-*
-* Arguments:
-     wlandev         wlan device structure
-     status          tx frame status word
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_ev_tx
+ *
+ * Handles the Tx event.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *     status          tx frame status word
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
 {
        pr_debug("Tx Complete, status=0x%04x\n", status);
@@ -1829,49 +1836,49 @@ void prism2sta_ev_tx(wlandevice_t *wlandev, u16 status)
        wlandev->netdev->stats.tx_packets++;
 }
 
-/*----------------------------------------------------------------
-* prism2sta_ev_rx
-*
-* Handles the Rx event.
-*
-* Arguments:
-     wlandev         wlan device structure
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_ev_rx
+ *
+ * Handles the Rx event.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 void prism2sta_ev_rx(wlandevice_t *wlandev, struct sk_buff *skb)
 {
        p80211netdev_rx(wlandev, skb);
 }
 
-/*----------------------------------------------------------------
-* prism2sta_ev_alloc
-*
-* Handles the Alloc event.
-*
-* Arguments:
-     wlandev         wlan device structure
-*
-* Returns:
-     nothing
-*
-* Side effects:
-*
-* Call context:
-     interrupt
-----------------------------------------------------------------*/
+/*
+ * prism2sta_ev_alloc
+ *
+ * Handles the Alloc event.
+ *
+ * Arguments:
+ *     wlandev         wlan device structure
+ *
+ * Returns:
+ *     nothing
+ *
+ * Side effects:
+ *
+ * Call context:
+ *     interrupt
+ */
 void prism2sta_ev_alloc(wlandevice_t *wlandev)
 {
        netif_wake_queue(wlandev->netdev);
 }
 
-/*----------------------------------------------------------------
+/*
 * create_wlan
 *
 * Called at module init time.  This creates the wlandevice_t structure
@@ -1889,7 +1896,7 @@ void prism2sta_ev_alloc(wlandevice_t *wlandev)
 * Call context:
 *      process thread
 *
-----------------------------------------------------------------*/
+*/
 static wlandevice_t *create_wlan(void)
 {
        wlandevice_t *wlandev = NULL;
index e92bbc12bb0649f26b03b2d4368e5b755b448043..8abf3f87a2d553efd8c769970107f5861c804006 100644 (file)
@@ -6,7 +6,7 @@
 
 #define PRISM_DEV(vid, pid, name)              \
        { USB_DEVICE(vid, pid),                 \
-       .driver_info = (unsigned long) name }
+       .driver_info = (unsigned long)name }
 
 static struct usb_device_id usb_prism_tbl[] = {
        PRISM_DEV(0x04bb, 0x0922, "IOData AirPort WN-B11/USBS"),
@@ -136,7 +136,7 @@ static void prism2sta_disconnect_usb(struct usb_interface *interface)
 {
        wlandevice_t *wlandev;
 
-       wlandev = (wlandevice_t *) usb_get_intfdata(interface);
+       wlandev = (wlandevice_t *)usb_get_intfdata(interface);
        if (wlandev != NULL) {
                LIST_HEAD(cleanlist);
                struct list_head *entry;
@@ -229,7 +229,7 @@ static int prism2sta_suspend(struct usb_interface *interface,
        hfa384x_t *hw = NULL;
        wlandevice_t *wlandev;
 
-       wlandev = (wlandevice_t *) usb_get_intfdata(interface);
+       wlandev = (wlandevice_t *)usb_get_intfdata(interface);
        if (!wlandev)
                return -ENODEV;
 
@@ -252,7 +252,7 @@ static int prism2sta_resume(struct usb_interface *interface)
        hfa384x_t *hw = NULL;
        wlandevice_t *wlandev;
 
-       wlandev = (wlandevice_t *) usb_get_intfdata(interface);
+       wlandev = (wlandevice_t *)usb_get_intfdata(interface);
        if (!wlandev)
                return -ENODEV;
 
index 5a6251a4511246756d2c6105fd9a382df51c1b42..89f5b55ed546161e378f7871dd34a33910ac5b58 100644 (file)
@@ -1548,7 +1548,7 @@ static void XGIfb_detect_VB(struct xgifb_video_info *xgifb_info)
        }
 }
 
-static int XGIfb_has_VB(struct xgifb_video_info *xgifb_info)
+static bool XGIfb_has_VB(struct xgifb_video_info *xgifb_info)
 {
        u8 vb_chipid;
 
@@ -1562,9 +1562,9 @@ static int XGIfb_has_VB(struct xgifb_video_info *xgifb_info)
                break;
        default:
                xgifb_info->hasVB = HASVB_NONE;
-               return 0;
+               return false;
        }
-       return 1;
+       return true;
 }
 
 static void XGIfb_get_VB_type(struct xgifb_video_info *xgifb_info)
index 2b233af8eb80dcb3813c2e12bd9a02a7ec8e6fc7..879a7e6751ac90e726999d52e127b9c0e01d2a51 100644 (file)
@@ -51,7 +51,7 @@ XGINew_GetXG20DRAMType(struct xgi_hw_device_info *HwDeviceExtension,
        } else if (HwDeviceExtension->jChipType == XG21) {
                /* Independent GPIO control */
                xgifb_reg_and(pVBInfo->P3d4, 0xB4, ~0x02);
-               udelay(800);
+               usleep_range(800, 1800);
                xgifb_reg_or(pVBInfo->P3d4, 0x4A, 0x80); /* Enable GPIOH read */
                /* GPIOF 0:DVI 1:DVO */
                data = xgifb_reg_get(pVBInfo->P3d4, 0x48);
@@ -80,20 +80,20 @@ static void XGINew_DDR1x_MRS_340(unsigned long P3c4,
        xgifb_reg_set(P3c4, 0x16, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x80);
 
-       mdelay(3);
+       usleep_range(3, 1003);
        xgifb_reg_set(P3c4, 0x18, 0x00);
        xgifb_reg_set(P3c4, 0x19, 0x20);
        xgifb_reg_set(P3c4, 0x16, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x80);
 
-       udelay(60);
+       usleep_range(60, 1060);
        xgifb_reg_set(P3c4, 0x18, pVBInfo->SR18[pVBInfo->ram_type]); /* SR18 */
        xgifb_reg_set(P3c4, 0x19, 0x01);
        xgifb_reg_set(P3c4, 0x16, 0x03);
        xgifb_reg_set(P3c4, 0x16, 0x83);
-       mdelay(1);
+       usleep_range(1, 1001);
        xgifb_reg_set(P3c4, 0x1B, 0x03);
-       udelay(500);
+       usleep_range(500, 1500);
        xgifb_reg_set(P3c4, 0x18, pVBInfo->SR18[pVBInfo->ram_type]); /* SR18 */
        xgifb_reg_set(P3c4, 0x19, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x03);
@@ -136,66 +136,65 @@ static void XGINew_DDRII_Bootup_XG27(
        /* Set Double Frequency */
        xgifb_reg_set(P3d4, 0x97, pVBInfo->XGINew_CR97); /* CR97 */
 
-       udelay(200);
+       usleep_range(200, 1200);
 
        xgifb_reg_set(P3c4, 0x18, 0x00); /* Set SR18 */ /* EMRS2 */
        xgifb_reg_set(P3c4, 0x19, 0x80); /* Set SR19 */
        xgifb_reg_set(P3c4, 0x16, 0x20); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
        xgifb_reg_set(P3c4, 0x16, 0xA0); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
 
        xgifb_reg_set(P3c4, 0x18, 0x00); /* Set SR18 */ /* EMRS3 */
        xgifb_reg_set(P3c4, 0x19, 0xC0); /* Set SR19 */
        xgifb_reg_set(P3c4, 0x16, 0x20); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
        xgifb_reg_set(P3c4, 0x16, 0xA0); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
 
        xgifb_reg_set(P3c4, 0x18, 0x00); /* Set SR18 */ /* EMRS1 */
        xgifb_reg_set(P3c4, 0x19, 0x40); /* Set SR19 */
        xgifb_reg_set(P3c4, 0x16, 0x20); /* Set SR16 */
-       udelay(30);
+       usleep_range(30, 1030);
        xgifb_reg_set(P3c4, 0x16, 0xA0); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
 
        xgifb_reg_set(P3c4, 0x18, 0x42); /* Set SR18 */ /* MRS, DLL Enable */
        xgifb_reg_set(P3c4, 0x19, 0x0A); /* Set SR19 */
        xgifb_reg_set(P3c4, 0x16, 0x00); /* Set SR16 */
-       udelay(30);
+       usleep_range(30, 1030);
        xgifb_reg_set(P3c4, 0x16, 0x00); /* Set SR16 */
        xgifb_reg_set(P3c4, 0x16, 0x80); /* Set SR16 */
 
        xgifb_reg_set(P3c4, 0x1B, 0x04); /* Set SR1B */
-       udelay(60);
+       usleep_range(60, 1060);
        xgifb_reg_set(P3c4, 0x1B, 0x00); /* Set SR1B */
 
        xgifb_reg_set(P3c4, 0x18, 0x42); /* Set SR18 */ /* MRS, DLL Reset */
        xgifb_reg_set(P3c4, 0x19, 0x08); /* Set SR19 */
        xgifb_reg_set(P3c4, 0x16, 0x00); /* Set SR16 */
 
-       udelay(30);
+       usleep_range(30, 1030);
        xgifb_reg_set(P3c4, 0x16, 0x83); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
 
        xgifb_reg_set(P3c4, 0x18, 0x80); /* Set SR18 */ /* MRS, ODT */
        xgifb_reg_set(P3c4, 0x19, 0x46); /* Set SR19 */
        xgifb_reg_set(P3c4, 0x16, 0x20); /* Set SR16 */
-       udelay(30);
+       usleep_range(30, 1030);
        xgifb_reg_set(P3c4, 0x16, 0xA0); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
 
        xgifb_reg_set(P3c4, 0x18, 0x00); /* Set SR18 */ /* EMRS */
        xgifb_reg_set(P3c4, 0x19, 0x40); /* Set SR19 */
        xgifb_reg_set(P3c4, 0x16, 0x20); /* Set SR16 */
-       udelay(30);
+       usleep_range(30, 1030);
        xgifb_reg_set(P3c4, 0x16, 0xA0); /* Set SR16 */
-       udelay(15);
+       usleep_range(15, 1015);
 
        /* Set SR1B refresh control 000:close; 010:open */
        xgifb_reg_set(P3c4, 0x1B, 0x04);
-       udelay(200);
-
+       usleep_range(200, 1200);
 }
 
 static void XGINew_DDR2_MRS_XG20(struct xgi_hw_device_info *HwDeviceExtension,
@@ -208,7 +207,7 @@ static void XGINew_DDR2_MRS_XG20(struct xgi_hw_device_info *HwDeviceExtension,
 
        xgifb_reg_set(P3d4, 0x97, 0x11); /* CR97 */
 
-       udelay(200);
+       usleep_range(200, 1200);
        xgifb_reg_set(P3c4, 0x18, 0x00); /* EMRS2 */
        xgifb_reg_set(P3c4, 0x19, 0x80);
        xgifb_reg_set(P3c4, 0x16, 0x05);
@@ -229,18 +228,18 @@ static void XGINew_DDR2_MRS_XG20(struct xgi_hw_device_info *HwDeviceExtension,
        xgifb_reg_set(P3c4, 0x16, 0x05);
        xgifb_reg_set(P3c4, 0x16, 0x85);
 
-       udelay(15);
+       usleep_range(15, 1015);
        xgifb_reg_set(P3c4, 0x1B, 0x04); /* SR1B */
-       udelay(30);
+       usleep_range(30, 1030);
        xgifb_reg_set(P3c4, 0x1B, 0x00); /* SR1B */
-       udelay(100);
+       usleep_range(100, 1100);
 
        xgifb_reg_set(P3c4, 0x18, 0x42); /* MRS1 */
        xgifb_reg_set(P3c4, 0x19, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x05);
        xgifb_reg_set(P3c4, 0x16, 0x85);
 
-       udelay(200);
+       usleep_range(200, 1200);
 }
 
 static void XGINew_DDR1x_MRS_XG20(unsigned long P3c4,
@@ -250,20 +249,20 @@ static void XGINew_DDR1x_MRS_XG20(unsigned long P3c4,
        xgifb_reg_set(P3c4, 0x19, 0x40);
        xgifb_reg_set(P3c4, 0x16, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x80);
-       udelay(60);
+       usleep_range(60, 1060);
 
        xgifb_reg_set(P3c4, 0x18, 0x00);
        xgifb_reg_set(P3c4, 0x19, 0x40);
        xgifb_reg_set(P3c4, 0x16, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x80);
-       udelay(60);
+       usleep_range(60, 1060);
        xgifb_reg_set(P3c4, 0x18, pVBInfo->SR18[pVBInfo->ram_type]); /* SR18 */
        xgifb_reg_set(P3c4, 0x19, 0x01);
        xgifb_reg_set(P3c4, 0x16, 0x03);
        xgifb_reg_set(P3c4, 0x16, 0x83);
-       mdelay(1);
+       usleep_range(1, 1001);
        xgifb_reg_set(P3c4, 0x1B, 0x03);
-       udelay(500);
+       usleep_range(500, 1500);
        xgifb_reg_set(P3c4, 0x18, pVBInfo->SR18[pVBInfo->ram_type]); /* SR18 */
        xgifb_reg_set(P3c4, 0x19, 0x00);
        xgifb_reg_set(P3c4, 0x16, 0x03);
@@ -499,7 +498,6 @@ static void XGINew_SetDRAMDefaultRegister340(
        xgifb_reg_set(P3c4, 0x1B, 0x03); /* SR1B */
 }
 
-
 static unsigned short XGINew_SetDRAMSize20Reg(
                unsigned short dram_size,
                struct vb_device_info *pVBInfo)
@@ -533,7 +531,7 @@ static unsigned short XGINew_SetDRAMSize20Reg(
                              0x14,
                              (xgifb_reg_get(pVBInfo->P3c4, 0x14) & 0x0F) |
                                (data & 0xF0));
-               udelay(15);
+               usleep_range(15, 1015);
        }
        return memsize;
 }
@@ -552,7 +550,7 @@ static int XGINew_ReadWriteRest(unsigned short StopAddr,
                writel(Position, fbaddr + Position);
        }
 
-       udelay(500); /* Fix #1759 Memory Size error in Multi-Adapter. */
+       usleep_range(500, 1500); /* Fix #1759 Memory Size error in Multi-Adapter. */
 
        Position = 0;
 
@@ -597,12 +595,11 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
 
                        if ((HwDeviceExtension->ulVideoMemorySize - 1)
                                        > 0x1000000) {
-
                                pVBInfo->ram_bus = 32; /* 32 bits */
                                /* 22bit + 2 rank + 32bit */
                                xgifb_reg_set(pVBInfo->P3c4, 0x13, 0xB1);
                                xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x52);
-                               udelay(15);
+                               usleep_range(15, 1015);
 
                                if (XGINew_ReadWriteRest(24, 23, pVBInfo) == 1)
                                        return;
@@ -616,7 +613,7 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
                                        xgifb_reg_set(pVBInfo->P3c4,
                                                      0x14,
                                                      0x42);
-                                       udelay(15);
+                                       usleep_range(15, 1015);
 
                                        if (XGINew_ReadWriteRest(23,
                                                                 23,
@@ -631,14 +628,14 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
                                /* 22bit + 2 rank + 16bit */
                                xgifb_reg_set(pVBInfo->P3c4, 0x13, 0xB1);
                                xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x41);
-                               udelay(15);
+                               usleep_range(15, 1015);
 
                                if (XGINew_ReadWriteRest(23, 22, pVBInfo) == 1)
                                        return;
                                xgifb_reg_set(pVBInfo->P3c4,
                                              0x13,
                                              0x31);
-                               udelay(15);
+                               usleep_range(15, 1015);
                        }
 
                } else { /* Dual_16_8 */
@@ -649,7 +646,7 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
                                xgifb_reg_set(pVBInfo->P3c4, 0x13, 0xB1);
                                /* 0x41:16Mx16 bit*/
                                xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x41);
-                               udelay(15);
+                               usleep_range(15, 1015);
 
                                if (XGINew_ReadWriteRest(23, 22, pVBInfo) == 1)
                                        return;
@@ -664,7 +661,7 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
                                        xgifb_reg_set(pVBInfo->P3c4,
                                                      0x14,
                                                      0x31);
-                                       udelay(15);
+                                       usleep_range(15, 1015);
 
                                        if (XGINew_ReadWriteRest(22,
                                                                 22,
@@ -680,7 +677,7 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
                                xgifb_reg_set(pVBInfo->P3c4, 0x13, 0xB1);
                                /* 0x30:8Mx8 bit*/
                                xgifb_reg_set(pVBInfo->P3c4, 0x14, 0x30);
-                               udelay(15);
+                               usleep_range(15, 1015);
 
                                if (XGINew_ReadWriteRest(22, 21, pVBInfo) == 1)
                                        return;
@@ -689,7 +686,7 @@ static void XGINew_CheckChannel(struct xgi_hw_device_info *HwDeviceExtension,
                                xgifb_reg_set(pVBInfo->P3c4,
                                              0x13,
                                              0x31);
-                               udelay(15);
+                               usleep_range(15, 1015);
                        }
                }
                break;
@@ -808,7 +805,7 @@ static int XGINew_DDRSizing340(struct xgi_hw_device_info *HwDeviceExtension,
        for (i = 0; i < size; i++) {
                /* SetDRAMSizingType */
                xgifb_reg_and_or(pVBInfo->P3c4, 0x13, 0x80, dram_table[i][1]);
-               udelay(15); /* should delay 50 ns */
+               usleep_range(50, 1050); /* should delay 50 ns */
 
                memsize = XGINew_SetDRAMSize20Reg(dram_table[i][0], pVBInfo);
 
@@ -817,7 +814,7 @@ static int XGINew_DDRSizing340(struct xgi_hw_device_info *HwDeviceExtension,
 
                memsize += (pVBInfo->ram_channel - 2) + 20;
                if ((HwDeviceExtension->ulVideoMemorySize - 1) <
-                       (unsigned long) (1 << memsize))
+                       (unsigned long)(1 << memsize))
                        continue;
 
                if (XGINew_ReadWriteRest(memsize, start_addr, pVBInfo) == 1)
@@ -838,13 +835,13 @@ static void XGINew_SetDRAMSize_340(struct xgifb_video_info *xgifb_info,
 
        data = xgifb_reg_get(pVBInfo->P3c4, 0x21);
        /* disable read cache */
-       xgifb_reg_set(pVBInfo->P3c4, 0x21, (unsigned short) (data & 0xDF));
+       xgifb_reg_set(pVBInfo->P3c4, 0x21, (unsigned short)(data & 0xDF));
        XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
 
        XGINew_DDRSizing340(HwDeviceExtension, pVBInfo);
        data = xgifb_reg_get(pVBInfo->P3c4, 0x21);
        /* enable read cache */
-       xgifb_reg_set(pVBInfo->P3c4, 0x21, (unsigned short) (data | 0x20));
+       xgifb_reg_set(pVBInfo->P3c4, 0x21, (unsigned short)(data | 0x20));
 }
 
 static u8 *xgifb_copy_rom(struct pci_dev *dev, size_t *rom_size)
@@ -853,11 +850,11 @@ static u8 *xgifb_copy_rom(struct pci_dev *dev, size_t *rom_size)
        u8 *rom_copy;
 
        rom_address = pci_map_rom(dev, rom_size);
-       if (rom_address == NULL)
+       if (!rom_address)
                return NULL;
 
        rom_copy = vzalloc(XGIFB_ROM_SIZE);
-       if (rom_copy == NULL)
+       if (!rom_copy)
                goto done;
 
        *rom_size = min_t(size_t, *rom_size, XGIFB_ROM_SIZE);
@@ -879,7 +876,7 @@ static bool xgifb_read_vbios(struct pci_dev *pdev)
        int entry;
 
        vbios = xgifb_copy_rom(pdev, &vbios_size);
-       if (vbios == NULL) {
+       if (!vbios) {
                dev_err(&pdev->dev, "Video BIOS not available\n");
                return false;
        }
@@ -1059,7 +1056,6 @@ static void XGINew_SetModeScratch(struct vb_device_info *pVBInfo)
        CR38Data &= ~SetYPbPr;
        CR38Data |= tempch;
        xgifb_reg_set(pVBInfo->P3d4, 0x38, CR38Data);
-
 }
 
 static unsigned short XGINew_SenseLCD(struct xgi_hw_device_info
@@ -1134,7 +1130,6 @@ static void XGINew_GetXG27Sense(struct vb_device_info *pVBInfo)
                xgifb_reg_and_or(pVBInfo->P3d4, 0x38, ~0xE0, 0xA0);
        }
        xgifb_reg_or(pVBInfo->P3d4, 0x32, LCDSense);
-
 }
 
 static unsigned char GetXG21FPBits(struct vb_device_info *pVBInfo)
@@ -1191,7 +1186,7 @@ unsigned char XGIInitNew(struct pci_dev *pdev)
 
        pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress;
 
-       if (pVBInfo->FBAddr == NULL) {
+       if (!pVBInfo->FBAddr) {
                dev_dbg(&pdev->dev, "pVBInfo->FBAddr == 0\n");
                return 0;
        }
@@ -1329,14 +1324,12 @@ unsigned char XGIInitNew(struct pci_dev *pdev)
        XGI_SenseCRT1(pVBInfo);
 
        if (HwDeviceExtension->jChipType == XG21) {
-
                xgifb_reg_and_or(pVBInfo->P3d4,
                                 0x32,
                                 ~Monitor1Sense,
                                 Monitor1Sense); /* Z9 default has CRT */
                temp = GetXG21FPBits(pVBInfo);
                xgifb_reg_and_or(pVBInfo->P3d4, 0x37, ~0x01, temp);
-
        }
        if (HwDeviceExtension->jChipType == XG27) {
                xgifb_reg_and_or(pVBInfo->P3d4,
index 7bd395fb31b2816137332f6899bf5a9ec31e1a1b..f613f54d522fe610e9b2b1a245335177d84fab58 100644 (file)
@@ -18,7 +18,7 @@ static inline void xgifb_reg_and_or(unsigned long port, u8 index,
        u8 temp;
 
        temp = xgifb_reg_get(port, index);
-       temp = (temp & data_and) | data_or;
+       temp = (u8) ((temp & data_and) | data_or);
        xgifb_reg_set(port, index, temp);
 }
 
@@ -27,7 +27,7 @@ static inline void xgifb_reg_and(unsigned long port, u8 index, unsigned data_and
        u8 temp;
 
        temp = xgifb_reg_get(port, index);
-       temp &= data_and;
+       temp = (u8) (temp & data_and);
        xgifb_reg_set(port, index, temp);
 }
 
index f692efcf683fc7a9a6150b4962cc218bf26148f4..b79a74a98a23573763ed6023d068eab184ef9611 100644 (file)
@@ -204,8 +204,7 @@ static int ca91cx42_irq_init(struct vme_bridge *ca91cx42_bridge)
        /* Need pdev */
        pdev = container_of(ca91cx42_bridge->parent, struct pci_dev, dev);
 
-       /* Initialise list for VME bus errors */
-       INIT_LIST_HEAD(&ca91cx42_bridge->vme_errors);
+       INIT_LIST_HEAD(&ca91cx42_bridge->vme_error_handlers);
 
        mutex_init(&ca91cx42_bridge->irq_mtx);
 
@@ -554,7 +553,7 @@ static int ca91cx42_alloc_resource(struct vme_master_resource *image,
        image->bus_resource.flags = IORESOURCE_MEM;
 
        retval = pci_bus_alloc_resource(pdev->bus,
-               &image->bus_resource, size, size, PCIBIOS_MIN_MEM,
+               &image->bus_resource, size, 0x10000, PCIBIOS_MIN_MEM,
                0, NULL, NULL);
        if (retval) {
                dev_err(ca91cx42_bridge->parent, "Failed to allocate mem "
index fb1e7ad272ec4ed3f92c7649adbb906423d60b66..60524834dba31b82237b92990f80c30868b33253 100644 (file)
@@ -169,7 +169,7 @@ static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge)
        unsigned int error_addr_high, error_addr_low;
        unsigned long long error_addr;
        u32 error_attrib;
-       struct vme_bus_error *error = NULL;
+       int error_am;
        struct tsi148_driver *bridge;
 
        bridge = tsi148_bridge->driver_priv;
@@ -177,6 +177,7 @@ static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge)
        error_addr_high = ioread32be(bridge->base + TSI148_LCSR_VEAU);
        error_addr_low = ioread32be(bridge->base + TSI148_LCSR_VEAL);
        error_attrib = ioread32be(bridge->base + TSI148_LCSR_VEAT);
+       error_am = (error_attrib & TSI148_LCSR_VEAT_AM_M) >> 8;
 
        reg_join(error_addr_high, error_addr_low, &error_addr);
 
@@ -186,23 +187,12 @@ static u32 tsi148_VERR_irqhandler(struct vme_bridge *tsi148_bridge)
                        "Occurred\n");
        }
 
-       if (err_chk) {
-               error = kmalloc(sizeof(struct vme_bus_error), GFP_ATOMIC);
-               if (error) {
-                       error->address = error_addr;
-                       error->attributes = error_attrib;
-                       list_add_tail(&error->list, &tsi148_bridge->vme_errors);
-               } else {
-                       dev_err(tsi148_bridge->parent,
-                               "Unable to alloc memory for VMEbus Error reporting\n");
-               }
-       }
-
-       if (!error) {
+       if (err_chk)
+               vme_bus_error_handler(tsi148_bridge, error_addr, error_am);
+       else
                dev_err(tsi148_bridge->parent,
                        "VME Bus Error at address: 0x%llx, attributes: %08x\n",
                        error_addr, error_attrib);
-       }
 
        /* Clear Status */
        iowrite32be(TSI148_LCSR_VEAT_VESCL, bridge->base + TSI148_LCSR_VEAT);
@@ -324,8 +314,7 @@ static int tsi148_irq_init(struct vme_bridge *tsi148_bridge)
 
        bridge = tsi148_bridge->driver_priv;
 
-       /* Initialise list for VME bus errors */
-       INIT_LIST_HEAD(&tsi148_bridge->vme_errors);
+       INIT_LIST_HEAD(&tsi148_bridge->vme_error_handlers);
 
        mutex_init(&tsi148_bridge->irq_mtx);
 
@@ -482,73 +471,6 @@ static int tsi148_irq_generate(struct vme_bridge *tsi148_bridge, int level,
        return 0;
 }
 
-/*
- * Find the first error in this address range
- */
-static struct vme_bus_error *tsi148_find_error(struct vme_bridge *tsi148_bridge,
-       u32 aspace, unsigned long long address, size_t count)
-{
-       struct list_head *err_pos;
-       struct vme_bus_error *vme_err, *valid = NULL;
-       unsigned long long bound;
-
-       bound = address + count;
-
-       /*
-        * XXX We are currently not looking at the address space when parsing
-        *     for errors. This is because parsing the Address Modifier Codes
-        *     is going to be quite resource intensive to do properly. We
-        *     should be OK just looking at the addresses and this is certainly
-        *     much better than what we had before.
-        */
-       err_pos = NULL;
-       /* Iterate through errors */
-       list_for_each(err_pos, &tsi148_bridge->vme_errors) {
-               vme_err = list_entry(err_pos, struct vme_bus_error, list);
-               if ((vme_err->address >= address) &&
-                       (vme_err->address < bound)) {
-
-                       valid = vme_err;
-                       break;
-               }
-       }
-
-       return valid;
-}
-
-/*
- * Clear errors in the provided address range.
- */
-static void tsi148_clear_errors(struct vme_bridge *tsi148_bridge,
-       u32 aspace, unsigned long long address, size_t count)
-{
-       struct list_head *err_pos, *temp;
-       struct vme_bus_error *vme_err;
-       unsigned long long bound;
-
-       bound = address + count;
-
-       /*
-        * XXX We are currently not looking at the address space when parsing
-        *     for errors. This is because parsing the Address Modifier Codes
-        *     is going to be quite resource intensive to do properly. We
-        *     should be OK just looking at the addresses and this is certainly
-        *     much better than what we had before.
-        */
-       err_pos = NULL;
-       /* Iterate through errors */
-       list_for_each_safe(err_pos, temp, &tsi148_bridge->vme_errors) {
-               vme_err = list_entry(err_pos, struct vme_bus_error, list);
-
-               if ((vme_err->address >= address) &&
-                       (vme_err->address < bound)) {
-
-                       list_del(err_pos);
-                       kfree(vme_err);
-               }
-       }
-}
-
 /*
  * Initialize a slave window with the requested attributes.
  */
@@ -846,7 +768,7 @@ static int tsi148_alloc_resource(struct vme_master_resource *image,
        image->bus_resource.flags = IORESOURCE_MEM;
 
        retval = pci_bus_alloc_resource(pdev->bus,
-               &image->bus_resource, size, size, PCIBIOS_MIN_MEM,
+               &image->bus_resource, size, 0x10000, PCIBIOS_MIN_MEM,
                0, NULL, NULL);
        if (retval) {
                dev_err(tsi148_bridge->parent, "Failed to allocate mem "
@@ -1264,7 +1186,7 @@ static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
        int retval, enabled;
        unsigned long long vme_base, size;
        u32 aspace, cycle, dwidth;
-       struct vme_bus_error *vme_err = NULL;
+       struct vme_error_handler *handler = NULL;
        struct vme_bridge *tsi148_bridge;
        void __iomem *addr = image->kern_base + offset;
        unsigned int done = 0;
@@ -1274,6 +1196,17 @@ static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
 
        spin_lock(&image->lock);
 
+       if (err_chk) {
+               __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace,
+                                   &cycle, &dwidth);
+               handler = vme_register_error_handler(tsi148_bridge, aspace,
+                                                    vme_base + offset, count);
+               if (!handler) {
+                       spin_unlock(&image->lock);
+                       return -ENOMEM;
+               }
+       }
+
        /* The following code handles VME address alignment. We cannot use
         * memcpy_xxx here because it may cut data transfers in to 8-bit
         * cycles when D16 or D32 cycles are required on the VME bus.
@@ -1317,24 +1250,16 @@ static ssize_t tsi148_master_read(struct vme_master_resource *image, void *buf,
 out:
        retval = count;
 
-       if (!err_chk)
-               goto skip_chk;
-
-       __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace, &cycle,
-               &dwidth);
-
-       vme_err = tsi148_find_error(tsi148_bridge, aspace, vme_base + offset,
-               count);
-       if (vme_err != NULL) {
-               dev_err(image->parent->parent, "First VME read error detected "
-                       "an at address 0x%llx\n", vme_err->address);
-               retval = vme_err->address - (vme_base + offset);
-               /* Clear down save errors in this address range */
-               tsi148_clear_errors(tsi148_bridge, aspace, vme_base + offset,
-                       count);
+       if (err_chk) {
+               if (handler->num_errors) {
+                       dev_err(image->parent->parent,
+                               "First VME read error detected an at address 0x%llx\n",
+                               handler->first_error);
+                       retval = handler->first_error - (vme_base + offset);
+               }
+               vme_unregister_error_handler(handler);
        }
 
-skip_chk:
        spin_unlock(&image->lock);
 
        return retval;
@@ -1351,7 +1276,7 @@ static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
        unsigned int done = 0;
        unsigned int count32;
 
-       struct vme_bus_error *vme_err = NULL;
+       struct vme_error_handler *handler = NULL;
        struct vme_bridge *tsi148_bridge;
        struct tsi148_driver *bridge;
 
@@ -1361,6 +1286,17 @@ static ssize_t tsi148_master_write(struct vme_master_resource *image, void *buf,
 
        spin_lock(&image->lock);
 
+       if (err_chk) {
+               __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace,
+                                   &cycle, &dwidth);
+               handler = vme_register_error_handler(tsi148_bridge, aspace,
+                                                    vme_base + offset, count);
+               if (!handler) {
+                       spin_unlock(&image->lock);
+                       return -ENOMEM;
+               }
+       }
+
        /* Here we apply for the same strategy we do in master_read
         * function in order to assure the correct cycles.
         */
@@ -1410,30 +1346,18 @@ out:
         * We check for saved errors in the written address range/space.
         */
 
-       if (!err_chk)
-               goto skip_chk;
-
-       /*
-        * Get window info first, to maximise the time that the buffers may
-        * fluch on their own
-        */
-       __tsi148_master_get(image, &enabled, &vme_base, &size, &aspace, &cycle,
-               &dwidth);
-
-       ioread16(bridge->flush_image->kern_base + 0x7F000);
+       if (err_chk) {
+               ioread16(bridge->flush_image->kern_base + 0x7F000);
 
-       vme_err = tsi148_find_error(tsi148_bridge, aspace, vme_base + offset,
-               count);
-       if (vme_err != NULL) {
-               dev_warn(tsi148_bridge->parent, "First VME write error detected"
-                       " an at address 0x%llx\n", vme_err->address);
-               retval = vme_err->address - (vme_base + offset);
-               /* Clear down save errors in this address range */
-               tsi148_clear_errors(tsi148_bridge, aspace, vme_base + offset,
-                       count);
+               if (handler->num_errors) {
+                       dev_warn(tsi148_bridge->parent,
+                                "First VME write error detected an at address 0x%llx\n",
+                                handler->first_error);
+                       retval = handler->first_error - (vme_base + offset);
+               }
+               vme_unregister_error_handler(handler);
        }
 
-skip_chk:
        spin_unlock(&image->lock);
 
        return retval;
index 56708915ebbe38e27dd97c818f53d2a10c43457d..72924b0632b79c8eda73b06c51e2bdcc1b73634e 100644 (file)
@@ -223,6 +223,39 @@ int vme_check_window(u32 aspace, unsigned long long vme_base,
 }
 EXPORT_SYMBOL(vme_check_window);
 
+static u32 vme_get_aspace(int am)
+{
+       switch (am) {
+       case 0x29:
+       case 0x2D:
+               return VME_A16;
+       case 0x38:
+       case 0x39:
+       case 0x3A:
+       case 0x3B:
+       case 0x3C:
+       case 0x3D:
+       case 0x3E:
+       case 0x3F:
+               return VME_A24;
+       case 0x8:
+       case 0x9:
+       case 0xA:
+       case 0xB:
+       case 0xC:
+       case 0xD:
+       case 0xE:
+       case 0xF:
+               return VME_A32;
+       case 0x0:
+       case 0x1:
+       case 0x3:
+               return VME_A64;
+       }
+
+       return 0;
+}
+
 /*
  * Request a slave image with specific attributes, return some unique
  * identifier.
@@ -990,6 +1023,63 @@ int vme_dma_free(struct vme_resource *resource)
 }
 EXPORT_SYMBOL(vme_dma_free);
 
+void vme_bus_error_handler(struct vme_bridge *bridge,
+                          unsigned long long address, int am)
+{
+       struct list_head *handler_pos = NULL;
+       struct vme_error_handler *handler;
+       int handler_triggered = 0;
+       u32 aspace = vme_get_aspace(am);
+
+       list_for_each(handler_pos, &bridge->vme_error_handlers) {
+               handler = list_entry(handler_pos, struct vme_error_handler,
+                                    list);
+               if ((aspace == handler->aspace) &&
+                   (address >= handler->start) &&
+                   (address < handler->end)) {
+                       if (!handler->num_errors)
+                               handler->first_error = address;
+                       if (handler->num_errors != UINT_MAX)
+                               handler->num_errors++;
+                       handler_triggered = 1;
+               }
+       }
+
+       if (!handler_triggered)
+               dev_err(bridge->parent,
+                       "Unhandled VME access error at address 0x%llx\n",
+                       address);
+}
+EXPORT_SYMBOL(vme_bus_error_handler);
+
+struct vme_error_handler *vme_register_error_handler(
+       struct vme_bridge *bridge, u32 aspace,
+       unsigned long long address, size_t len)
+{
+       struct vme_error_handler *handler;
+
+       handler = kmalloc(sizeof(*handler), GFP_KERNEL);
+       if (!handler)
+               return NULL;
+
+       handler->aspace = aspace;
+       handler->start = address;
+       handler->end = address + len;
+       handler->num_errors = 0;
+       handler->first_error = 0;
+       list_add_tail(&handler->list, &bridge->vme_error_handlers);
+
+       return handler;
+}
+EXPORT_SYMBOL(vme_register_error_handler);
+
+void vme_unregister_error_handler(struct vme_error_handler *handler)
+{
+       list_del(&handler->list);
+       kfree(handler);
+}
+EXPORT_SYMBOL(vme_unregister_error_handler);
+
 void vme_irq_handler(struct vme_bridge *bridge, int level, int statid)
 {
        void (*call)(int, int, void *);
index 934949abd7457c8072c47844f7ea555c05e5bb4e..397578a738839756f7787d9b39556fd32b1277e1 100644 (file)
@@ -75,10 +75,13 @@ struct vme_lm_resource {
        int monitors;
 };
 
-struct vme_bus_error {
+struct vme_error_handler {
        struct list_head list;
-       unsigned long long address;
-       u32 attributes;
+       unsigned long long start;       /* Beginning of error window */
+       unsigned long long end;         /* End of error window */
+       unsigned long long first_error; /* Address of the first error */
+       u32 aspace;                     /* Address space of error window*/
+       unsigned num_errors;            /* Number of errors */
 };
 
 struct vme_callback {
@@ -106,8 +109,10 @@ struct vme_bridge {
        struct list_head dma_resources;
        struct list_head lm_resources;
 
-       struct list_head vme_errors;    /* List for errors generated on VME */
-       struct list_head devices;       /* List of devices on this bridge */
+       /* List for registered errors handlers */
+       struct list_head vme_error_handlers;
+       /* List of devices on this bridge */
+       struct list_head devices;
 
        /* Bridge Info - XXX Move to private structure? */
        struct device *parent;  /* Parent device (eg. pdev->dev for PCI) */
@@ -166,9 +171,15 @@ struct vme_bridge {
                void *vaddr, dma_addr_t dma);
 };
 
+void vme_bus_error_handler(struct vme_bridge *bridge,
+                          unsigned long long address, int am);
 void vme_irq_handler(struct vme_bridge *, int, int);
 
 int vme_register_bridge(struct vme_bridge *);
 void vme_unregister_bridge(struct vme_bridge *);
+struct vme_error_handler *vme_register_error_handler(
+       struct vme_bridge *bridge, u32 aspace,
+       unsigned long long address, size_t len);
+void vme_unregister_error_handler(struct vme_error_handler *handler);
 
 #endif /* _VME_BRIDGE_H_ */
index be40dbaed11e06a93eedd67ccff968d7e1aa39fa..3d003805aac32ab1880c432cf556da8c5c29e14c 100644 (file)
@@ -483,7 +483,10 @@ struct fb_info {
 #ifdef CONFIG_FB_TILEBLITTING
        struct fb_tile_ops *tileops;    /* Tile Blitting */
 #endif
-       char __iomem *screen_base;      /* Virtual address */
+       union {
+               char __iomem *screen_base;      /* Virtual address */
+               char *screen_buffer;
+       };
        unsigned long screen_size;      /* Amount of ioremapped VRAM or 0 */ 
        void *pseudo_palette;           /* Fake palette of 16 colors */ 
 #define FBINFO_STATE_RUNNING   0
index 3c17cd7fdf06f08b9c8a85c502f592e4124e6053..2fe939c73cd241c6a24eabea83abf8761fb1de0a 100644 (file)
@@ -271,6 +271,10 @@ void st_sensors_power_enable(struct iio_dev *indio_dev);
 
 void st_sensors_power_disable(struct iio_dev *indio_dev);
 
+int st_sensors_debugfs_reg_access(struct iio_dev *indio_dev,
+                                 unsigned reg, unsigned writeval,
+                                 unsigned *readval);
+
 int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
 
 int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);
index 7bb7f673cb3faeb55c911e4c4d75d538f61ac787..19c94c9acc816ab17ab8822240d0169c68670b22 100644 (file)
@@ -294,6 +294,7 @@ static inline s64 iio_get_time_ns(void)
 #define INDIO_BUFFER_TRIGGERED         0x02
 #define INDIO_BUFFER_SOFTWARE          0x04
 #define INDIO_BUFFER_HARDWARE          0x08
+#define INDIO_EVENT_TRIGGERED          0x10
 
 #define INDIO_ALL_BUFFER_MODES                                 \
        (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE | INDIO_BUFFER_SOFTWARE)
@@ -457,6 +458,7 @@ struct iio_buffer_setup_ops {
  * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  * @trig:              [INTERN] current device trigger (buffer modes)
  * @pollfunc:          [DRIVER] function run on trigger being received
+ * @pollfunc_event:    [DRIVER] function run on events trigger being received
  * @channels:          [DRIVER] channel specification structure table
  * @num_channels:      [DRIVER] number of channels specified in @channels.
  * @channel_attr_list: [INTERN] keep track of automatically created channel
@@ -495,6 +497,7 @@ struct iio_dev {
        unsigned                        scan_index_timestamp;
        struct iio_trigger              *trig;
        struct iio_poll_func            *pollfunc;
+       struct iio_poll_func            *pollfunc_event;
 
        struct iio_chan_spec const      *channels;
        int                             num_channels;
diff --git a/include/linux/iio/triggered_event.h b/include/linux/iio/triggered_event.h
new file mode 100644 (file)
index 0000000..8fe8537
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _LINUX_IIO_TRIGGERED_EVENT_H_
+#define _LINUX_IIO_TRIGGERED_EVENT_H_
+
+#include <linux/interrupt.h>
+
+int iio_triggered_event_setup(struct iio_dev *indio_dev,
+       irqreturn_t (*h)(int irq, void *p),
+       irqreturn_t (*thread)(int irq, void *p));
+void iio_triggered_event_cleanup(struct iio_dev *indio_dev);
+
+#endif
index 2f8b11722204dcc6528dfab601961ef6834f3e13..7c63bd67c36e274f933a857b23ee00e5e1c2daed 100644 (file)
@@ -35,6 +35,8 @@ enum iio_chan_type {
        IIO_ENERGY,
        IIO_DISTANCE,
        IIO_VELOCITY,
+       IIO_CONCENTRATION,
+       IIO_RESISTANCE,
 };
 
 enum iio_modifier {
@@ -72,6 +74,8 @@ enum iio_modifier {
        IIO_MOD_ROOT_SUM_SQUARED_X_Y_Z,
        IIO_MOD_I,
        IIO_MOD_Q,
+       IIO_MOD_CO2,
+       IIO_MOD_VOC,
 };
 
 enum iio_event_type {
index 78c442fbf263d088629ec6d8c2e9cc327c49191f..599562fe5d574b857512c34a54b34498030ac083 100644 (file)
@@ -88,7 +88,7 @@
 #define HFI1_CAP_SDMA_AHG         (1UL <<  2) /* Enable SDMA AHG support */
 #define HFI1_CAP_EXTENDED_PSN     (1UL <<  3) /* Enable Extended PSN support */
 #define HFI1_CAP_HDRSUPP          (1UL <<  4) /* Enable Header Suppression */
-/* 1UL << 5 reserved */
+/* 1UL << 5 unused */
 #define HFI1_CAP_USE_SDMA_HEAD    (1UL <<  6) /* DMA Hdr Q tail vs. use CSR */
 #define HFI1_CAP_MULTI_PKT_EGR    (1UL <<  7) /* Enable multi-packet Egr buffs*/
 #define HFI1_CAP_NODROP_RHQ_FULL  (1UL <<  8) /* Don't drop on Hdr Q full */
@@ -99,7 +99,7 @@
 #define HFI1_CAP_NO_INTEGRITY     (1UL << 13) /* Enable ctxt integrity checks */
 #define HFI1_CAP_PKEY_CHECK       (1UL << 14) /* Enable ctxt PKey checking */
 #define HFI1_CAP_STATIC_RATE_CTRL (1UL << 15) /* Allow PBC.StaticRateControl */
-#define HFI1_CAP_QSFP_ENABLED     (1UL << 16) /* Enable QSFP check during LNI */
+/* 1UL << 16 unused */
 #define HFI1_CAP_SDMA_HEAD_CHECK  (1UL << 17) /* SDMA head checking */
 #define HFI1_CAP_EARLY_CREDIT_RETURN (1UL << 18) /* early credit return */
 
index 9f7b85bf6ada3e3cdf43508ab9b3589daf14325a..01c4f67801e0e0d6ce865f7a4f241e7425645860 100644 (file)
@@ -328,6 +328,15 @@ int main(int argc, char **argv)
                        "diag %s\n", dev_dir_name);
                goto error_free_triggername;
        }
+       if (!num_channels) {
+               fprintf(stderr,
+                       "No channels are enabled, we have nothing to scan.\n");
+               fprintf(stderr, "Enable channels manually in "
+                       FORMAT_SCAN_ELEMENTS_DIR
+                       "/*_en and try again.\n", dev_dir_name);
+               ret = -ENOENT;
+               goto error_free_triggername;
+       }
 
        /*
         * Construct the directory name for the associated buffer.
index cd3fd41b481dc111406e89c4ad65dd59c4dd334c..d51eb04202e915558a7a638ed6ca79a1ab8741e1 100644 (file)
@@ -284,7 +284,11 @@ int main(int argc, char **argv)
        ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
        if (ret == -1 || event_fd == -1) {
                ret = -errno;
-               fprintf(stderr, "Failed to retrieve event fd\n");
+               if (ret == -ENODEV)
+                       fprintf(stderr,
+                               "This device does not support events\n");
+               else
+                       fprintf(stderr, "Failed to retrieve event fd\n");
                if (close(fd) == -1)
                        perror("Failed to close character device file");